Commit 2d7d5fe7 by guojx

Merge branch 'feature-2023-11-cloud' into 'master'

Feature 2023 11 cloud

See merge request !1577
parents ac231f53 1107dc9c
...@@ -28,6 +28,8 @@ public enum NoticeMessageTypeEnum { ...@@ -28,6 +28,8 @@ public enum NoticeMessageTypeEnum {
TASK_TRANS(2010, "话务任务通知", NoticeMessageCategoryTypeEnum.TASK.getType(), "task_trans", "/pages/route/index?pageType=", "hbapp_task_list_new", "TelServiceTaskByStoreManage", "haobanNotice"), TASK_TRANS(2010, "话务任务通知", NoticeMessageCategoryTypeEnum.TASK.getType(), "task_trans", "/pages/route/index?pageType=", "hbapp_task_list_new", "TelServiceTaskByStoreManage", "haobanNotice"),
PERFORMANCE_TASK_UPDATE(2011, "指标任务变更通知", NoticeMessageCategoryTypeEnum.TASK.getType(), "performance_task_update", "/pages/route/index?pageType=", "hbapp_task_kpi_detail", "targetTaskByUpdate", "haobanNotice"),
STORE_ACCOUNT(3001, "账号申请", NoticeMessageCategoryTypeEnum.OTHER.getType(), "store_account", "/pages/route/index?pageType=", "store_relate_store_record_list", "accountApplication", "haobanNotice"), STORE_ACCOUNT(3001, "账号申请", NoticeMessageCategoryTypeEnum.OTHER.getType(), "store_account", "/pages/route/index?pageType=", "store_relate_store_record_list", "accountApplication", "haobanNotice"),
// //
......
package com.gic.haoban.manage.web.controller.data;
import com.alibaba.fastjson.JSON;
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.util.data.CrossDateUtils;
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 lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import java.util.*;
import java.util.stream.Collectors;
/**
* 数据调用通用接口
* @Author guojx
* @Date 2023/11/14 10:56
*/
@Controller
@RequestMapping("data")
@Slf4j
public class DataController {
@Autowired
private StoreAuthUtils storeAuthUtils;
@Autowired
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");
String env = config.getProperty("environment.value", "") ;
return env;
}
/**
* 会员封装数据
* @param qo
* @return
*/
@RequestMapping(value = "get-member-data")
@ResponseBody
public RestResponse<List<DataMemberExtendVO>> getMemberData(@RequestBody DataMemberExtendQO qo) {
if (StringUtils.isBlank(qo.getEnterpriseId())) {
return RestResponse.failure("-1", "企业id不能为空");
}
String params = qo.getParams();
JSONObject jsonObject = JSONObject.parseObject(params);
if (jsonObject == null) {
jsonObject = new JSONObject();
}
jsonObject.put("enterpriseId", qo.getEnterpriseId());
List<String> storeIdList = new ArrayList<>();
String storeId = qo.getStoreId();
if (StringUtils.isBlank(storeId)) {
storeIdList = storeAuthUtils.queryClerkStoreIds(qo.getClerkId(), qo.getWxEnterpriseId());
} else {
storeIdList.add(storeId);
}
if (CollectionUtils.isNotEmpty(storeIdList)) {
//区经有全部门店权限
jsonObject.put("storeId", storeIdList.stream().collect(Collectors.joining(",")));
}
qo.setParams(jsonObject.toJSONString());
Map<String, String> head = new HashMap<>();
head.put("Content-Type", "application/json");
String mainHost = GlobalVar.ctxPropertiesMap.get("gicweb_service_host");
mainHost = mainHost.replace("gicweb", "");
//是否是开发环境
boolean isDev = mainHost.contains("gicdev");
if (isDev) {
//http://gicdev.demogic.com/
mainHost = GlobalVar.ctxPropertiesMap.get("gicweb_service_host_old");
}
String url = mainHost + "api-report/data-extend/get-member-data";
JSONObject httpJson = new JSONObject();
httpJson.put("params", jsonObject.toJSONString());
httpJson.put("dateType", qo.getDateType());
httpJson.put("realFlag", qo.getRealFlag());
httpJson.put("totalMemberFlag", qo.getTotalMemberFlag());
httpJson.put("channelCodeList", qo.getChannelCodeList());
Map<String, Object> res = HttpClient.getWinxinResByJson(url, httpJson.toJSONString(), head);
RestResponse rest = JSONObject.parseObject(JSONObject.toJSONString(res), RestResponse.class);
if (isSuccess(rest)) {
List<DataMemberExtendVO> list = JSONObject.parseArray(JSON.toJSONString(rest.getResult()), DataMemberExtendVO.class);
rest.setResult(list);
}
return rest;
}
/**
* 数据统一调用接口
* 参数与返回字段查询数据组的yapi的对应文档
* @param qo
* @return
*/
@RequestMapping(value = "handle")
@ResponseBody
public RestResponse handle(@RequestBody HandleQO qo) {
String params = qo.getParams();
JSONObject jsonObject = JSONObject.parseObject(params);
if (jsonObject == null) {
jsonObject = new JSONObject();
}
if (StringUtils.isNotBlank(qo.getEnterpriseId())) {
jsonObject.put("enterpriseId", qo.getEnterpriseId());
}
String storeIdParam = jsonObject.getString("storeId");
boolean hasStoreId = StringUtils.isNotBlank(storeIdParam);
if (!hasStoreId) {
List<String> storeIdList = new ArrayList<>();
String storeId = qo.getStoreId();
if (StringUtils.isBlank(storeId)) {
storeIdList = storeAuthUtils.queryClerkStoreIds(qo.getClerkId(), qo.getWxEnterpriseId());
} else {
storeIdList.add(storeId);
}
if (CollectionUtils.isNotEmpty(storeIdList)) {
//区经有全部门店权限
jsonObject.put("storeId", storeIdList.stream().collect(Collectors.joining(",")));
}
}
String apolloKey = qo.getApolloKey();
String useApolloKey = CrossDateUtils.getUseApolloKey(jsonObject == null ? null : jsonObject.getString("startDate"), apolloKey);
//如果不一样,说明是3个月前的接口,需要
boolean needTransferField = !apolloKey.equals(useApolloKey);
Map<String, Object> res = DataApiUtils.http(jsonObject.toJSONString(), useApolloKey);
boolean isPageQuery = jsonObject != null && jsonObject.containsKey("pageNum");
boolean isNeedFill = (apolloKey.contains("data_mbr_scale_stat_new_custm_overview")
|| apolloKey.contains("data_sales_perf_anal_cont_custm_overview")
|| apolloKey.contains("month") || apolloKey.contains("day") ||
apolloKey.contains("week"))
&& jsonObject.containsKey("storeGroup") &&
((apolloKey.contains("data_sales") &&
(jsonObject.getInteger("storeGroup") == 3 || jsonObject.getInteger("storeGroup") == 4))
|| (apolloKey.contains("data_mbr") && jsonObject.getInteger("storeGroup") == 2));
if (isNeedFill) {
log.info("需要补零");
List<JSONObject> resultList = DataApiUtils.getDataList(res);
if (CollectionUtils.isEmpty(resultList)) {
resultList = new ArrayList<>();
}
if (needTransferField) {
resultList = CrossDateUtils.dealStdJson(resultList);
}
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("custm")) {
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);
}
}
Object dataObj = res.get("data");
if (dataObj instanceof JSONObject) {
JSONObject data = (JSONObject) res.get("data");
List<JSONObject> list = DataApiUtils.getPageList(res);
if (needTransferField) {
list = CrossDateUtils.dealStdJson(list);
data.put("rows", list);
}
return RestResponse.successResult(data);
} else {
List<JSONObject> resultList = DataApiUtils.getDataList(res);
if (needTransferField) {
resultList = CrossDateUtils.dealStdJson(resultList);
}
return RestResponse.successResult(resultList);
}
}
/**
* 指标字典列表
* @param indexCode 可以多个,英文逗号隔开
* @return
*/
@RequestMapping("list-data-index-explain")
@ResponseBody
public RestResponse<List<DataIndexExplainVO>> listDataIndexExplain(String indexCode) {
List<DataIndexExplainDTO> list = dataIndexApiService.listDataIndexExplain();
if (StringUtils.isNotBlank(indexCode)) {
List<String> indexCodeList = Arrays.stream(indexCode.split(",")).collect(Collectors.toList());
list = list.stream().filter(e -> indexCodeList.contains(e.getIndexCode())).collect(Collectors.toList());
}
return RestResponse.successResult(EntityUtil.changeEntityListNew(DataIndexExplainVO.class, list));
}
/**
* 评价指标
* @param qo
* @return
*/
@RequestMapping("evaluate-data-index")
@ResponseBody
public RestResponse saveDataIndexEvaluate(@RequestBody DataIndexQO qo) {
DataIndexEvaluateLogDTO log = EntityUtil.changeEntityNew(DataIndexEvaluateLogDTO.class, qo);
log.setAccountId(qo.getClerkId());
log.setSourceType(1);
dataIndexApiService.saveDataIndexEvaluateLog(log);
return RestResponse.successResult();
}
/**
* 渠道字典数据
* 说明:channelCode (渠道code,数据接口需要传的)
* channelNameIntegral 会员类型的名称
* channelNameOrder 订单业绩的名称
* @param enterpriseId
* @return
*/
@RequestMapping("list-channel-data")
@ResponseBody
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;
hasAuthSet.add(value.getChannelCode());
// 微信渠道,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.remove(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"))
|| !hasAuthSet.contains(json.getString("channelCode"))) {
continue;
}
json.put("dataChannelPre", channelMap().get(json.getString("channelCode")));
result.add(json);
}
return RestResponse.successResult(result);
}
return RestResponse.successResult(new ArrayList<>());
}
private static Map<String, String> channelMap() {
Map<String, String> map = new HashMap<>();
map.put("c_pos", "pos");
map.put("c_other", "else");
map.put("c_douyin_hyt", "dy");
map.put("c_tmall_hyt", "tmall");
map.put("c_wechat_mini", "wct");
map.put("c_weimob", "weimob");
return map;
}
private JSONObject getTotalJson(JSONObject param, String apolloKey) {
Map<String, Object> totalRes = DataApiUtils.http(param.toJSONString(), apolloKey);
List<JSONObject> totalList = DataApiUtils.getPageList(totalRes);
if (CollectionUtils.isEmpty(totalList)) {
return null;
}
JSONObject total = totalList.get(0);
return total;
}
protected boolean isSuccess(RestResponse response) {
if ("0".equals(response.getCode())) {
return true;
}
return false;
}
}
package com.gic.haoban.manage.web.qo.data;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;
import java.io.Serializable;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
/**
* @Author guojx
* @Date 2023/9/27 11:13
*/
@Data
public class DataIndexExplainVO implements Serializable {
private String id;
private String indexCode;
private String indexName;
private String indexExplain;
/**
* 前端使用:指标说明:若指标注释中有需要说明的
*/
private List<String> indexRemarkList;
/**
* 前端使用:指标例子
*/
private List<String> indexExampleList;
/**
* 指标说明:若指标注释中有需要说明的,英文分号隔开,可能多个。
*/
private String indexRemark;
/**
* 指标例子: 英文分号隔开,可能多个
*/
private String indexExample;
/**
* yapi文档上的驼峰字段名称
*/
private String apiColName;
public List<String> getIndexRemarkList() {
if (StringUtils.isNotBlank(indexRemark)) {
return Arrays.stream(indexRemark.split(";")).collect(Collectors.toList());
}
return indexRemarkList;
}
public List<String> getIndexExampleList() {
if (StringUtils.isNotBlank(indexExample)) {
return Arrays.stream(indexExample.split(";")).collect(Collectors.toList());
}
return indexExampleList;
}
}
package com.gic.haoban.manage.web.qo.data;
import lombok.Data;
import java.io.Serializable;
/**
* @Author guojx
* @Date 2023/9/27 11:06
*/
@Data
public class DataIndexQO implements Serializable {
/**
* 指标code
*/
private String indexCode;
/**
* 指标名称
*/
private String indexName;
/**
* 0:不满意 1:满意
*/
private Integer indexEvaluate;
/**
* 不满意原因
*/
private String reason;
/**
* 自定义原因
*/
private String customReason;
private String enterpriseId;
private String clerkId;
}
package com.gic.haoban.manage.web.qo.data;
import lombok.Data;
import java.io.Serializable;
import java.util.List;
/**
* @Author guojx
* @Date 2023/11/24 12:21
*/
@Data
public class DataMemberExtendQO implements Serializable {
/**
* 门店查询参数. 区经可以为空,查询所有管辖门店
*/
private String storeId;
/**
* 企业ID.
*/
private String enterpriseId;
/**
* 微信企业
*/
private String wxEnterpriseId;
/**
* 如果是区经,用于查询管辖门店权限
*/
private String clerkId;
private String params;
/**
* 1:日 2:周 3:月 :4:自定义
*/
private Integer dateType;
/**
* 1:实时 0:离线
*/
private Integer realFlag;
/**
* 1:会员总数 2:新增会员
*/
private Integer totalMemberFlag;
/**
* 权限渠道范围
*/
private List<String> channelCodeList;
public boolean isReal() {
return realFlag != null && realFlag == 1;
}
public boolean isTotalMember() {
return totalMemberFlag != null && totalMemberFlag == 1;
}
}
package com.gic.haoban.manage.web.qo.data;
import lombok.Data;
import java.io.Serializable;
/**
* @Author guojx
* @Date 2023/11/23 9:13
*/
@Data
public class HandleQO implements Serializable {
/**
* 组装的参数,JSON字符串.数据组提供的yapi文档上有.
* 注:门店参数storeId根据storeSelect参数计算
*/
private String params;
/**
* 数据组配置的接口key。数据组提供的yapi文档上有
*/
private String apolloKey;
/**
* 门店查询参数. 区经可以为空,查询所有管辖门店
*/
private String storeId;
/**
* 企业ID.
*/
private String enterpriseId;
/**
* 微信企业
*/
private String wxEnterpriseId;
/**
* 如果是区经,用于查询管辖门店权限
*/
private String clerkId;
}
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")));
}
}
package com.gic.haoban.manage.web.vo.data;
import lombok.Data;
import java.io.Serializable;
/**
* @Author guojx
* @Date 2023/11/24 13:54
*/
@Data
public class DataMemberExtendVO implements Serializable {
private String channelCode;
/**
* 开卡会员
*/
private Integer openMbrNum;
/**
* 昨日开卡会员
*/
private Integer lastOpenMbrNum;
/**
* 关联会员
*/
private Integer relMbrNum;
/**
* 昨日关联会员
*/
private Integer lastRelMbrNum;
/**
* 关联会员环比
*/
private Double relMbrNumRatio;
/**
* 关联会员同比
*/
private Double relMbrNumSply;
/**
* 开卡会员环比
*/
private Double openMbrNumRatio;
/**
* 开卡会员同比
*/
private Double openMbrNumSply;
/**
* 1:服务门店
*/
private Integer serviceFlag;
}
...@@ -161,4 +161,8 @@ ...@@ -161,4 +161,8 @@
<dubbo:reference interface="com.gic.enterprise.api.service.content.ValueAddedServicesOrderApiService" id="valueAddedServicesOrderApiService" <dubbo:reference interface="com.gic.enterprise.api.service.content.ValueAddedServicesOrderApiService" id="valueAddedServicesOrderApiService"
timeout="10000" retries="0" check="false"/> 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> </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