|
@@ -2,13 +2,13 @@ package space.apps.moudules.sys.services;
|
|
|
|
|
|
|
|
import java.io.IOException;
|
|
import java.io.IOException;
|
|
|
import java.text.SimpleDateFormat;
|
|
import java.text.SimpleDateFormat;
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
import java.util.HashMap;
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
import org.apache.commons.lang.ArrayUtils;
|
|
import org.apache.commons.lang.ArrayUtils;
|
|
|
|
|
|
|
|
-import apps.pojo.Website;
|
|
|
|
|
import space.apps.moudules.website.template.util.WebsiteUtil;
|
|
import space.apps.moudules.website.template.util.WebsiteUtil;
|
|
|
import space.apps.moudules.website.util.AppWebsiteManageUtil;
|
|
import space.apps.moudules.website.util.AppWebsiteManageUtil;
|
|
|
import space.core.apps.common.BaseTransaction;
|
|
import space.core.apps.common.BaseTransaction;
|
|
@@ -83,9 +83,15 @@ public class WebsiteStatisticsService extends BaseTransaction {
|
|
|
*/
|
|
*/
|
|
|
public void getHotArticle() throws Exception {
|
|
public void getHotArticle() throws Exception {
|
|
|
|
|
|
|
|
- Website website = getWebsite();
|
|
|
|
|
|
|
+ List<Map<String, Object>> websiteList = AppWebsiteManageUtil.getManageWebsiteListByAppUser(getGdbaInstance(),
|
|
|
|
|
+ getAppUser());
|
|
|
|
|
+
|
|
|
|
|
+ if (websiteList == null || websiteList.size() == 0) {
|
|
|
|
|
+ write(getResponseSuccessDataPackage(new ArrayList<Map<String, Object>>()).toJson());
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- String cacheKey = CACHE_KEY + website.getWebsiteid() + "_hotArticle";
|
|
|
|
|
|
|
+ String cacheKey = CACHE_KEY + websiteListIDToStr(websiteList) + "_hotArticle";
|
|
|
|
|
|
|
|
Object retMsgObj = JedisUtil.obj.get(cacheKey);
|
|
Object retMsgObj = JedisUtil.obj.get(cacheKey);
|
|
|
if (StringUtil.notNull(retMsgObj)) {
|
|
if (StringUtil.notNull(retMsgObj)) {
|
|
@@ -94,13 +100,31 @@ public class WebsiteStatisticsService extends BaseTransaction {
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- String sql = " Select articleid, title, a.`desc`, thumbnail, read_count, url, w.protocol, w.port, w.domains, w.catalog_uri from article a left join website w on a.websiteid = w.websiteid where a.dcode = 61 order by a.read_count desc, a.release_time asc ";
|
|
|
|
|
- SqlCommandImpl sqlCmd = new SqlCommandImpl(sql);
|
|
|
|
|
|
|
+ SqlCommandImpl sqlCmd = new SqlCommandImpl();
|
|
|
|
|
+ StringBuilder sqlBuilder = new StringBuilder();
|
|
|
|
|
+ sqlBuilder.append(
|
|
|
|
|
+ " Select articleid, title, a.`desc`, thumbnail, read_count, url, w.protocol, w.port, w.domains, w.catalog_uri ");
|
|
|
|
|
+ sqlBuilder.append(" from article a left join website w on a.websiteid = w.websiteid where a.dcode = 61 ");
|
|
|
|
|
+ GdbaQueryUtil.appendInFieldSql(sqlBuilder, sqlCmd, "a.websiteid",
|
|
|
|
|
+ AppWebsiteManageUtil.websiteListIDToAry(websiteList));
|
|
|
|
|
+ sqlBuilder.append(" order by a.read_count desc, a.release_time asc ");
|
|
|
|
|
+ sqlCmd.setExecuteSql(sqlBuilder);
|
|
|
List<Map<String, Object>> articleList = getGdbaInstance().selectAsMapList(sqlCmd, getAppsPageBean());
|
|
List<Map<String, Object>> articleList = getGdbaInstance().selectAsMapList(sqlCmd, getAppsPageBean());
|
|
|
|
|
|
|
|
for (Map<String, Object> map : articleList) {
|
|
for (Map<String, Object> map : articleList) {
|
|
|
String websiteUrl = WebsiteUtil.disposeWebsiteDomain(map);
|
|
String websiteUrl = WebsiteUtil.disposeWebsiteDomain(map);
|
|
|
- map.put("url", websiteUrl.substring(0, websiteUrl.length() - 1) + map.get("url").toString());
|
|
|
|
|
|
|
+ Object rawUrl = map.get("url");
|
|
|
|
|
+ String articleUrl = rawUrl == null ? "" : rawUrl.toString();
|
|
|
|
|
+ if (StringUtil.isNull(articleUrl)) {
|
|
|
|
|
+ map.put("url", "#");
|
|
|
|
|
+ } else if (StringUtil.notNull(websiteUrl)) {
|
|
|
|
|
+ if (websiteUrl.endsWith("/")) {
|
|
|
|
|
+ websiteUrl = websiteUrl.substring(0, websiteUrl.length() - 1);
|
|
|
|
|
+ }
|
|
|
|
|
+ map.put("url", websiteUrl + articleUrl);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ map.put("url", articleUrl);
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
ResponsePackage rsdp = getResponseSuccessDataPackage(articleList);
|
|
ResponsePackage rsdp = getResponseSuccessDataPackage(articleList);
|
|
@@ -159,9 +183,15 @@ public class WebsiteStatisticsService extends BaseTransaction {
|
|
|
*/
|
|
*/
|
|
|
public void getIssueDynamic() throws Exception {
|
|
public void getIssueDynamic() throws Exception {
|
|
|
|
|
|
|
|
- Website website = getWebsite();
|
|
|
|
|
|
|
+ List<Map<String, Object>> websiteList = AppWebsiteManageUtil.getManageWebsiteListByAppUser(getGdbaInstance(),
|
|
|
|
|
+ getAppUser());
|
|
|
|
|
+
|
|
|
|
|
+ if (websiteList == null || websiteList.size() == 0) {
|
|
|
|
|
+ write(getResponseSuccessDataPackage(new ArrayList<Map<String, Object>>()).toJson());
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- String cacheKey = CACHE_KEY + website.getWebsiteid() + "_IssueDynamic";
|
|
|
|
|
|
|
+ String cacheKey = CACHE_KEY + websiteListIDToStr(websiteList) + "_IssueDynamic";
|
|
|
|
|
|
|
|
Object retMsgObj = JedisUtil.obj.get(cacheKey);
|
|
Object retMsgObj = JedisUtil.obj.get(cacheKey);
|
|
|
if (StringUtil.notNull(retMsgObj)) {
|
|
if (StringUtil.notNull(retMsgObj)) {
|
|
@@ -170,12 +200,17 @@ public class WebsiteStatisticsService extends BaseTransaction {
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- String sql = "Select p.name as 'uname', d.name as 'dname', pt.name as 'pname', p.icon_path, a.title, date_format(a.release_time, '%Y-%m-%d %H:%i') as 'time', a.url from article a, department d, post pt, person p "
|
|
|
|
|
- + "where a.create_pid = p.personid and p.departmentid = d.departmentid and p.postid = pt.postid and a.dcode = 61 and p.dcode = 61 "
|
|
|
|
|
- + "and navigationid in ( Select navigationid from website_navigation where websiteid = :websiteid ) order by a.release_time desc ";
|
|
|
|
|
-
|
|
|
|
|
- SqlCommandImpl sqlCmd = new SqlCommandImpl(sql);
|
|
|
|
|
- sqlCmd.setString("websiteid", website.getWebsiteid());
|
|
|
|
|
|
|
+ SqlCommandImpl sqlCmd = new SqlCommandImpl();
|
|
|
|
|
+ StringBuilder sqlBuilder = new StringBuilder();
|
|
|
|
|
+ sqlBuilder.append(
|
|
|
|
|
+ "Select p.name as 'uname', d.name as 'dname', pt.name as 'pname', p.icon_path, a.title, date_format(a.release_time, '%Y-%m-%d %H:%i') as 'time', a.url from article a, department d, post pt, person p ");
|
|
|
|
|
+ sqlBuilder.append(
|
|
|
|
|
+ "where a.create_pid = p.personid and p.departmentid = d.departmentid and p.postid = pt.postid and a.dcode = 61 and p.dcode = 61 ");
|
|
|
|
|
+ sqlBuilder.append("and navigationid in ( Select navigationid from website_navigation where 1 = 1 ");
|
|
|
|
|
+ GdbaQueryUtil.appendInFieldSql(sqlBuilder, sqlCmd, "websiteid",
|
|
|
|
|
+ AppWebsiteManageUtil.websiteListIDToAry(websiteList));
|
|
|
|
|
+ sqlBuilder.append(" ) order by a.release_time desc ");
|
|
|
|
|
+ sqlCmd.setExecuteSql(sqlBuilder);
|
|
|
List<Map<String, Object>> articleList = getGdbaInstance().selectAsMapList(sqlCmd, getAppsPageBean());
|
|
List<Map<String, Object>> articleList = getGdbaInstance().selectAsMapList(sqlCmd, getAppsPageBean());
|
|
|
|
|
|
|
|
ResponsePackage rsdp = getResponseSuccessDataPackage(articleList);
|
|
ResponsePackage rsdp = getResponseSuccessDataPackage(articleList);
|
|
@@ -203,15 +238,10 @@ public class WebsiteStatisticsService extends BaseTransaction {
|
|
|
// 没有可管理的网站
|
|
// 没有可管理的网站
|
|
|
if (websiteList == null || websiteList.size() == 0) {
|
|
if (websiteList == null || websiteList.size() == 0) {
|
|
|
|
|
|
|
|
- String[] numberAry = new String[beforeSevenDay.length];
|
|
|
|
|
- for (int i = 0; i < beforeSevenDay.length; i++) {
|
|
|
|
|
- numberAry[i] = "0";
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
Map<String, String[]> retMap = new HashMap<String, String[]>();
|
|
Map<String, String[]> retMap = new HashMap<String, String[]>();
|
|
|
retMap.put("date", beforeSevenDay);
|
|
retMap.put("date", beforeSevenDay);
|
|
|
- retMap.put("normal", numberAry);
|
|
|
|
|
- retMap.put("error", numberAry);
|
|
|
|
|
|
|
+ retMap.put("normal", getZeroArray(beforeSevenDay.length));
|
|
|
|
|
+ retMap.put("error", getZeroArray(beforeSevenDay.length));
|
|
|
write(getResponseSuccessDataPackage(retMap).toJson());
|
|
write(getResponseSuccessDataPackage(retMap).toJson());
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
@@ -235,32 +265,33 @@ public class WebsiteStatisticsService extends BaseTransaction {
|
|
|
|
|
|
|
|
StringBuilder sqlBuilder = new StringBuilder();
|
|
StringBuilder sqlBuilder = new StringBuilder();
|
|
|
sqlBuilder.append(
|
|
sqlBuilder.append(
|
|
|
- " Select date, sum(data) as 'total', wstcode from ( Select data, date, wstcode from website_statistics where date_format(date, '%Y-%m-%d') in ( ");
|
|
|
|
|
|
|
+ " Select date, sum(data) as 'total', wstcode from ( Select data, date_format(date, '%Y-%m-%d') as date, wstcode from website_statistics where date_format(date, '%Y-%m-%d') in ( ");
|
|
|
sqlBuilder.append(dateStrs).append(" ) and (");
|
|
sqlBuilder.append(dateStrs).append(" ) and (");
|
|
|
sqlBuilder.append(GdbaQueryUtil.getInSql(sqlCmd, "websiteid", AppWebsiteManageUtil.websiteListIDToAry(websiteList)));
|
|
sqlBuilder.append(GdbaQueryUtil.getInSql(sqlCmd, "websiteid", AppWebsiteManageUtil.websiteListIDToAry(websiteList)));
|
|
|
- sqlBuilder.append(" or (websiteid is null and wstcode = 10010)) ) as tempTable group by `date`, `wstcode` ");
|
|
|
|
|
|
|
+ sqlBuilder.append(" or (websiteid is null and wstcode = 10010)) ) as tempTable group by `date`, `wstcode` order by `date` ");
|
|
|
|
|
|
|
|
sqlCmd.setExecuteSql(sqlBuilder);
|
|
sqlCmd.setExecuteSql(sqlBuilder);
|
|
|
List<Map<String, Object>> dataList = getGdbaInstance().selectAsMapList(sqlCmd);
|
|
List<Map<String, Object>> dataList = getGdbaInstance().selectAsMapList(sqlCmd);
|
|
|
|
|
|
|
|
- int nIndex = 0;
|
|
|
|
|
- int eIndex = 0;
|
|
|
|
|
- String[] normalAry = new String[7];
|
|
|
|
|
- String[] errorAry = new String[7];
|
|
|
|
|
|
|
+ String[] normalAry = getZeroArray(beforeSevenDay.length);
|
|
|
|
|
+ String[] errorAry = getZeroArray(beforeSevenDay.length);
|
|
|
|
|
|
|
|
for (Map<String, Object> map : dataList) {
|
|
for (Map<String, Object> map : dataList) {
|
|
|
|
|
|
|
|
- String total = map.get("total").toString();
|
|
|
|
|
- total = total.substring(0, total.lastIndexOf("."));
|
|
|
|
|
|
|
+ int dateIndex = getDateIndex(beforeSevenDay, map.get("date"));
|
|
|
|
|
+ if (dateIndex < 0) {
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+ String total = String.valueOf(getTotalByMap(map));
|
|
|
String wstcode = map.get("wstcode").toString();
|
|
String wstcode = map.get("wstcode").toString();
|
|
|
|
|
|
|
|
// 正常
|
|
// 正常
|
|
|
if ("10000".equals(wstcode)) {
|
|
if ("10000".equals(wstcode)) {
|
|
|
- normalAry[nIndex++] = total;
|
|
|
|
|
|
|
+ normalAry[dateIndex] = total;
|
|
|
}
|
|
}
|
|
|
// 异常
|
|
// 异常
|
|
|
else if ("10010".equals(wstcode)) {
|
|
else if ("10010".equals(wstcode)) {
|
|
|
- errorAry[eIndex++] = total;
|
|
|
|
|
|
|
+ errorAry[dateIndex] = total;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -343,6 +374,10 @@ public class WebsiteStatisticsService extends BaseTransaction {
|
|
|
List<Map<String, Object>> websiteList = AppWebsiteManageUtil.getManageWebsiteListByAppUser(getGdbaInstance(),
|
|
List<Map<String, Object>> websiteList = AppWebsiteManageUtil.getManageWebsiteListByAppUser(getGdbaInstance(),
|
|
|
getAppUser());
|
|
getAppUser());
|
|
|
|
|
|
|
|
|
|
+ if (websiteList == null || websiteList.size() == 0) {
|
|
|
|
|
+ return new ArrayList<Map<String, Object>>();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
SqlCommandImpl sqlCmd = new SqlCommandImpl();
|
|
SqlCommandImpl sqlCmd = new SqlCommandImpl();
|
|
|
StringBuilder sqlBuilder = new StringBuilder();
|
|
StringBuilder sqlBuilder = new StringBuilder();
|
|
|
|
|
|
|
@@ -379,12 +414,17 @@ public class WebsiteStatisticsService extends BaseTransaction {
|
|
|
String websiteName = getParameter("name");
|
|
String websiteName = getParameter("name");
|
|
|
String startDate = getParameter("startDate");
|
|
String startDate = getParameter("startDate");
|
|
|
String endDate = getParameter("endDate");
|
|
String endDate = getParameter("endDate");
|
|
|
- String dateTyep = getParameter("dateType");
|
|
|
|
|
|
|
+ String dateType = getParameter("dateType");
|
|
|
|
|
+
|
|
|
|
|
+ if (StringUtil.isNull(dateType)) {
|
|
|
|
|
+ dateType = "month";
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- if (dateTyep.equals("month")) { // 月
|
|
|
|
|
- if ("current".equals(startDate)) {
|
|
|
|
|
|
|
+ if (dateType.equals("month")) { // 月
|
|
|
|
|
+ if (StringUtil.isNull(startDate) || "current".equals(startDate)) {
|
|
|
startDate = DateTimeUtil.getMonth();
|
|
startDate = DateTimeUtil.getMonth();
|
|
|
}
|
|
}
|
|
|
|
|
+ startDate = startDate.replace("月", "");
|
|
|
String year = DateTimeUtil.getYear() + "-" + startDate;
|
|
String year = DateTimeUtil.getYear() + "-" + startDate;
|
|
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM");
|
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM");
|
|
|
int daysOfMonth = DateTimeUtil.getDaysOfMonth(sdf.parse(year));
|
|
int daysOfMonth = DateTimeUtil.getDaysOfMonth(sdf.parse(year));
|
|
@@ -392,11 +432,15 @@ public class WebsiteStatisticsService extends BaseTransaction {
|
|
|
write(getResponseSuccessDataPackage(getWebsiteIssueArticleCount(getGdbaInstance(), year + "-" + "01",
|
|
write(getResponseSuccessDataPackage(getWebsiteIssueArticleCount(getGdbaInstance(), year + "-" + "01",
|
|
|
year + "-" + daysOfMonth, websiteName)).toJson());
|
|
year + "-" + daysOfMonth, websiteName)).toJson());
|
|
|
|
|
|
|
|
- } else if (dateTyep.equals("custom")) { // 自定义时间
|
|
|
|
|
|
|
+ } else if (dateType.equals("custom")) { // 自定义时间
|
|
|
|
|
+ if (StringUtil.isNull(startDate) || StringUtil.isNull(endDate)) {
|
|
|
|
|
+ write(getResponseErrorMsgPackage("请选择开始日期和结束日期").toJson());
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
write(getResponseSuccessDataPackage(
|
|
write(getResponseSuccessDataPackage(
|
|
|
getWebsiteIssueArticleCount(getGdbaInstance(), startDate, endDate, websiteName)).toJson());
|
|
getWebsiteIssueArticleCount(getGdbaInstance(), startDate, endDate, websiteName)).toJson());
|
|
|
} else {
|
|
} else {
|
|
|
- write(getResponseErrorMsgPackage().toJson());
|
|
|
|
|
|
|
+ write(getResponseErrorMsgPackage("不支持的统计类型").toJson());
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
}
|
|
}
|
|
@@ -429,4 +473,25 @@ public class WebsiteStatisticsService extends BaseTransaction {
|
|
|
return iDBuilder.substring(0, iDBuilder.length() - 1);
|
|
return iDBuilder.substring(0, iDBuilder.length() - 1);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ private String[] getZeroArray(int length) {
|
|
|
|
|
+ String[] numberAry = new String[length];
|
|
|
|
|
+ for (int i = 0; i < length; i++) {
|
|
|
|
|
+ numberAry[i] = "0";
|
|
|
|
|
+ }
|
|
|
|
|
+ return numberAry;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private int getDateIndex(String[] dateAry, Object dateObj) {
|
|
|
|
|
+ if (dateObj == null) {
|
|
|
|
|
+ return -1;
|
|
|
|
|
+ }
|
|
|
|
|
+ String date = dateObj.toString();
|
|
|
|
|
+ for (int i = 0; i < dateAry.length; i++) {
|
|
|
|
|
+ if (dateAry[i].equals(date)) {
|
|
|
|
|
+ return i;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return -1;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
}
|
|
}
|