Commit 194e9060 by guojx

趋势图

parent e89082f9
......@@ -5,19 +5,27 @@ import com.alibaba.fastjson.JSONObject;
import com.ctrip.framework.apollo.Config;
import com.ctrip.framework.apollo.ConfigService;
import com.gic.api.base.commons.Page;
import com.gic.api.base.commons.ServiceResponse;
import com.gic.commons.util.DataApiUtils;
import com.gic.commons.util.EntityUtil;
import com.gic.commons.util.GlobalVar;
import com.gic.commons.util.HttpClient;
import com.gic.commons.webapi.reponse.RestResponse;
import com.gic.enterprise.api.dto.EnterpriseSettingDTO;
import com.gic.enterprise.api.dto.EnterpriseSourceChannelDTO;
import com.gic.enterprise.api.dto.data.DataIndexEvaluateLogDTO;
import com.gic.enterprise.api.dto.data.DataIndexExplainDTO;
import com.gic.enterprise.api.enums.PlatformChannelEnum;
import com.gic.enterprise.api.enums.PlatformEnum;
import com.gic.enterprise.api.service.EnterpriseChannelApiService;
import com.gic.enterprise.api.service.EnterpriseService;
import com.gic.enterprise.api.service.data.DataIndexApiService;
import com.gic.enterprise.service.CustomSettingApiService;
import com.gic.haoban.manage.web.qo.data.DataIndexExplainVO;
import com.gic.haoban.manage.web.qo.data.DataIndexQO;
import com.gic.haoban.manage.web.qo.data.DataMemberExtendQO;
import com.gic.haoban.manage.web.qo.data.HandleQO;
import com.gic.haoban.manage.web.utils.DateFillUtils;
import com.gic.haoban.manage.web.utils.StoreAuthUtils;
import com.gic.haoban.manage.web.vo.data.DataMemberExtendVO;
import org.apache.commons.collections.CollectionUtils;
......@@ -45,6 +53,10 @@ public class DataController {
private DataIndexApiService dataIndexApiService;
@Autowired
private CustomSettingApiService customSettingApiService;
@Autowired
private EnterpriseChannelApiService enterpriseChannelApiService;
@Autowired
private EnterpriseService enterpriseService;
private String isProd() {
Config config = ConfigService.getConfig("COMMON.gic-properties");
......@@ -138,6 +150,43 @@ public class DataController {
jsonObject.put("storeId", storeIdList.stream().collect(Collectors.joining(",")));
}
Map<String, Object> res = DataApiUtils.http(jsonObject.toJSONString(), qo.getApolloKey());
String apolloKey = qo.getApolloKey();
boolean isNeedFill = (apolloKey.contains("custom")
|| apolloKey.contains("month") || apolloKey.contains("day") ||
apolloKey.contains("week"))
&& jsonObject.containsKey("storeGroup") &&
(jsonObject.getInteger("storeGroup") == 3 || jsonObject.getInteger("storeGroup") == 4
|| jsonObject.getInteger("storeGroup") == 2);
if (isNeedFill) {
List<JSONObject> resultList = DataApiUtils.getDataList(res);
List<String> dateTypeList = null;
if (apolloKey.contains("day")) {
dateTypeList = DateFillUtils.getDay(jsonObject.getString("bizDate"));
} else if (apolloKey.contains("month")) {
dateTypeList = DateFillUtils.getMonth(jsonObject.getString("startDate").substring(0, 7));
} else if (apolloKey.contains("week")) {
dateTypeList = DateFillUtils.getWeek(jsonObject.getString("startDate"));
} else if (apolloKey.contains("custom")) {
dateTypeList = DateFillUtils.getCustom(jsonObject.getString("startDate"), jsonObject.getString("endDate"));
}
if (CollectionUtils.isNotEmpty(dateTypeList)) {
List<JSONObject> fillList = new ArrayList<>();
Map<String, JSONObject> fillMap = resultList.stream().collect(Collectors.toMap(e -> e.getString("bizDate"), e -> e));
for (String dateTemp : dateTypeList) {
if (fillMap.get(dateTemp) != null) {
fillList.add(fillMap.get(dateTemp));
} else {
JSONObject fillJson = new JSONObject();
fillJson.put("bizDate", dateTemp);
fillList.add(fillJson);
}
}
return RestResponse.successResult(fillList);
}
}
return RestResponse.successResult(res.get("data"));
}
......@@ -185,12 +234,42 @@ public class DataController {
public RestResponse listChannelData(String enterpriseId) {
Page<JSONObject> page = customSettingApiService
.page("tab_gic_channel_platform_dict", "", 1, 1000).getResult();
PlatformChannelEnum[] values = PlatformChannelEnum.values();
Set<String> hasAuthSet = new HashSet<>();
for (PlatformChannelEnum value : values) {
boolean enable = true;
// 微信渠道,pos渠道,其他渠道默认开通
if(PlatformEnum.WECHAT.equals(value.getBelongPlatform()) || PlatformEnum.POS.equals(value.getBelongPlatform()) || PlatformEnum.OTHER.equals(value.getBelongPlatform())){
continue;
}else if(PlatformChannelEnum.C_WEIMOB==value){
//渠道查询判断是否开通
EnterpriseSettingDTO enterpriseSettingDTO = enterpriseService.getEnterpriseSettingByEnterpriseId(enterpriseId);
if (enterpriseSettingDTO == null || enterpriseSettingDTO.getEnterpriseSettingId() == null) {
enable = false;
}
//没开通微盟
if (enterpriseSettingDTO.getBackgroundMode() == 0) {
enable = false;
}
}else{
// 抖音天猫渠道
ServiceResponse<EnterpriseSourceChannelDTO> response = enterpriseChannelApiService.getEnterpriseSourceChannel(enterpriseId, value.getChannelCodeOld(), 1);
if(!response.isSuccess() || response.getResult()==null){
enable = false;
}
}
if (enable) {
hasAuthSet.add(value.getChannelCode());
}
}
if (page != null) {
List<JSONObject> list = page.getResult();
List<JSONObject> result = new ArrayList<>();
for (JSONObject json : list) {
if ("c_wechat_work".equals(json.getString("channelCode"))
|| "c_wechat_gh".equals(json.getString("channelCode"))) {
|| "c_wechat_gh".equals(json.getString("channelCode"))
|| !hasAuthSet.contains(json.getString("channelCode"))) {
continue;
}
json.put("dataChannelPre", channelMap().get(json.getString("channelCode")));
......
package com.gic.haoban.manage.web.utils;
import com.alibaba.fastjson.JSONObject;
import com.gic.commons.util.DataApiUtils;
import lombok.extern.slf4j.Slf4j;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
import java.util.Map;
/**
* @Author guojx
* @Date 2023/11/29 10:49
*/
@Slf4j
public class DateFillUtils {
public static List<String> getDay(String date) {
List<String> dateList = new ArrayList<>();
try {
Calendar calendar = Calendar.getInstance();
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
calendar.setTime(df.parse(date));
calendar.add(Calendar.DATE, -29);
String temp = df.format(calendar.getTime());
while (temp.compareTo(date) <= 0) {
dateList.add(temp.substring(5));
calendar.add(Calendar.DATE, 1);
temp = df.format(calendar.getTime());
}
} catch (Exception e) {
log.error("时间匹配调整:{}", e.getMessage(), e);
}
return dateList;
}
public static List<String> getCustom(String start, String end) {
List<String> dateList = new ArrayList<>();
try {
Calendar calendar = Calendar.getInstance();
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
calendar.setTime(df.parse(start));
String temp = df.format(calendar.getTime());
while (temp.compareTo(end) <= 0) {
dateList.add(temp.substring(5));
calendar.add(Calendar.DATE, 1);
temp = df.format(calendar.getTime());
}
} catch (Exception e) {
log.error("时间匹配调整:{}", e.getMessage(), e);
}
return dateList;
}
public static List<String> getWeek(String date) {
List<String> dateList = new ArrayList<>();
try {
Calendar calendar = Calendar.getInstance();
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
calendar.setTime(df.parse(date));
calendar.add(Calendar.WEEK_OF_YEAR, -11);
String temp = df.format(calendar.getTime());
JSONObject jsonObject = new JSONObject();
jsonObject.put("pageNum", 1);
jsonObject.put("pageSize", 20);
jsonObject.put("startDate", temp);
jsonObject.put("endDate", date);
Map<String, Object> res = DataApiUtils.http(jsonObject.toJSONString(), "data_pub_date_week");
List<JSONObject> list = DataApiUtils.getPageList(res);
for (JSONObject json : list) {
dateList.add(json.getString("weekYear"));
}
log.info("week data:{}", list);
} catch (Exception e) {
log.error("时间匹配调整:{}", e.getMessage(), e);
}
return dateList;
}
public static List<String> getYear(String date) {
List<String> dateList = new ArrayList<>();
Integer year = Integer.parseInt(date);
Integer min = year - 11;
for (int i = min; i <= year; i++) {
dateList.add(i + "");
}
return dateList;
}
public static List<String> getMonth(String date) {
List<String> dateList = new ArrayList<>();
try {
Calendar calendar = Calendar.getInstance();
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM");
calendar.setTime(df.parse(date));
calendar.add(Calendar.MONTH, -11);
String temp = df.format(calendar.getTime());
while (temp.compareTo(date) <= 0) {
dateList.add(temp);
calendar.add(Calendar.MONTH, 1);
temp = df.format(calendar.getTime());
}
} catch (Exception e) {
log.error("时间匹配调整:{}", e.getMessage(), e);
}
return dateList;
}
public static void main(String[] args) {
log.info("" + JSONObject.toJSONString(getWeek("2023-11-27")));
}
}
......@@ -162,4 +162,7 @@
timeout="10000" retries="0" check="false"/>
<dubbo:reference id="dataIndexApiService" interface="com.gic.enterprise.api.service.data.DataIndexApiService" timeout="10000" retries="0" check="false" />
<dubbo:reference id="enterpriseChannelApiService" interface="com.gic.enterprise.api.service.EnterpriseChannelApiService" timeout="10000" retries="0" check="false"/>
</beans>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment