Commit 83af7f4d by guojx

Merge branch 'feature-2024-05-wechat-work' into 'master'

Feature 2024 05 wechat work

See merge request !1826
parents 4b2731a5 53a1c02a
package com.gic.haoban.manage.web.controller;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.gic.api.base.commons.JSONResponse;
import com.gic.api.base.commons.Page;
import com.gic.commons.util.DataApiUtils;
import com.gic.commons.webapi.reponse.RestResponse;
import com.gic.haoban.base.api.common.pojo.dto.WebLoginDTO;
import com.gic.haoban.common.utils.AuthWebRequestUtil;
import com.gic.haoban.manage.web.handle.WechatEventTrackingClerkDetailHandle;
import com.gic.haoban.manage.web.handle.WechatEventTrackingStoreGroupHandle;
import com.gic.haoban.manage.web.qo.eventtracking.WechatEventTrackingClerkDetailQO;
import com.gic.haoban.manage.web.qo.eventtracking.WechatEventTrackingStoreGroupQO;
import com.gic.haoban.manage.web.qo.eventtracking.WechatOverviewQO;
import com.gic.haoban.manage.web.qo.wechatwork.StoreGroupCommonQO;
import com.gic.haoban.manage.web.utils.AuthorizedUserUtils;
import com.gic.haoban.manage.web.utils.data.ConcurrencyUtils;
import com.gic.haoban.manage.web.utils.data.MapThreadHandlerRequest;
import com.gic.haoban.manage.web.utils.data.StoreAuthUtils;
import com.gic.haoban.manage.web.utils.eventtracking.DateExpandUtils;
import com.gic.haoban.manage.web.vo.eventtracking.TrendVO;
import com.gic.haoban.manage.web.vo.eventtracking.ViewModuleVO;
import com.gic.haoban.manage.web.vo.eventtracking.WechatEventTrackingClerkVO;
import com.gic.haoban.manage.web.vo.eventtracking.WechatEventTrackingStoreGroupVO;
import com.gic.haoban.manage.web.vo.wechatwork.DataPageVO;
import com.gic.qcloud.BucketNameEnum;
import com.gic.web.common.controller.NewBaseController;
import com.gic.web.common.download.DownloadTask;
import com.gic.web.common.download.DownloadTaskUtil;
import com.gic.web.common.download.constants.TaskTypeEnum;
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.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
* 好办小程序埋点分析
* @Author guojx
* @Date 2024/5/30 9:06
*/
@RestController
@Slf4j
@RequestMapping("wechat-event-tracking")
public class EventTrackingController extends NewBaseController {
@Autowired
private StoreAuthUtils storeAuthUtils;
@Autowired
private WechatEventTrackingStoreGroupHandle wechatEventTrackingStoreGroupHandle;
@Autowired
private WechatEventTrackingClerkDetailHandle wechatEventTrackingClerkDetailHandle;
/**
* 概览
* @param qo
* @return
*/
@RequestMapping(value = "overview")
public RestResponse overview(@RequestBody WechatOverviewQO qo) {
Map<String, Object> res = DataApiUtils.http(getOverviewParam(qo).toJSONString(), "data_point_anal_hb_app_overview");
List<JSONObject> list = DataApiUtils.getDataList(res);
return RestResponse.successResult(CollectionUtils.isEmpty(list) ? null : list.get(0));
}
/**
* 趋势图
* @param qo
* @return
*/
@RequestMapping(value = "trend")
public RestResponse<List<TrendVO>> trend(@RequestBody WechatOverviewQO qo) {
Map<String, Object> res = DataApiUtils.http(getOverviewParam(qo).toJSONString(), "data_point_anal_hb_app_trend");
List<JSONObject> list = DataApiUtils.getDataList(res);
Map<String, JSONObject> map = new HashMap<>();
if (CollectionUtils.isNotEmpty(list)) {
map = list.stream().collect(Collectors.toMap(e ->e.getString("bizDate"), e -> e));
}
//日期补零
List<String> dateList = DateExpandUtils.getDateList(qo.getStartDate(), qo.getEndDate(), qo.getDateType());
List<TrendVO> voList = new ArrayList<>();
for (String date : dateList) {
TrendVO vo = null;
JSONObject temp = map.get(date);
if (temp == null) {
vo = new TrendVO();
} else {
vo = JSONObject.parseObject(temp.toJSONString(), TrendVO.class);
}
vo.setBizDate(date);
voList.add(vo);
}
return RestResponse.successResult(voList);
}
/**
* 模块访问统计
* @param qo
* @return
*/
@RequestMapping(value = "view-module")
public RestResponse<List<ViewModuleVO>> viewModule(@RequestBody WechatOverviewQO qo) {
JSONObject jsonParam = getOverviewParam(qo);
List<MapThreadHandlerRequest> list = new ArrayList<>();
// 1 访问次数 2 访问人数 3 访问时长
jsonParam.put("orderByField", 1);
list.add(new MapThreadHandlerRequest(jsonParam, "data_point_anal_hb_app_module", "1_visitCnt"));
jsonParam.put("orderByField", 2);
list.add(new MapThreadHandlerRequest(jsonParam, "data_point_anal_hb_app_module", "2_visitNum"));
jsonParam.put("orderByField", 3);
list.add(new MapThreadHandlerRequest(jsonParam, "data_point_anal_hb_app_module", "3_visitTime"));
Map<String, List<JSONObject>> map = ConcurrencyUtils.concurrencyDataForMap(list);
List<ViewModuleVO> voList = new ArrayList<>();
if (map != null && map.size() > 0) {
map.forEach((k,v) -> {
if (CollectionUtils.isNotEmpty(v)) {
String dataType = k.substring(0, 1);
String key = k.substring(2);
List<ViewModuleVO> tempList = new ArrayList<>();
for (JSONObject temp : v) {
ViewModuleVO vo = JSON.parseObject(temp.toJSONString(), ViewModuleVO.class);
vo.setDataType(Integer.parseInt(dataType));
vo.setData(temp.getLong(key));
tempList.add(vo);
}
voList.addAll(tempList);
}
});
}
return RestResponse.successResult(voList);
}
/**
* 门店分组下钻
* @param qo
* @return
*/
@RequestMapping(value = "store-group")
public RestResponse<DataPageVO<WechatEventTrackingStoreGroupVO>> storeGroup(@RequestBody WechatEventTrackingStoreGroupQO qo) {
JSONObject jsonObject = new JSONObject();
qo.dealWithParam(jsonObject);
storeAuthUtils.setStoreGroupJsonParam(jsonObject, qo);
jsonObject.put("apolloKey", "data_point_anal_hb_app_store");
DataPageVO vo = storeAuthUtils.getDataCommon(jsonObject.toJSONString(), qo.getPageNum(), "data_point_anal_hb_app_store", qo.getPageSize(), true);
storeAuthUtils.deleteTotalData(vo);
if (CollectionUtils.isNotEmpty(vo.getRows())) {
vo.setRows(JSONArray.parseArray(JSON.toJSONString(vo.getRows()), WechatEventTrackingStoreGroupVO.class));
}
return RestResponse.successResult(vo);
}
/**
* 门店明细导出
* @param qo
* @return
*/
@RequestMapping(value = "export-store-group")
public RestResponse exportStoreGroup(@RequestBody WechatEventTrackingStoreGroupQO qo) {
DownloadTask task = new DownloadTask();
task.setTaskTypeEnum(TaskTypeEnum.HAOBAN_WECHAT_EVENT_STORE);
task.setDataType(qo.getDataType());
task.setUser(AuthorizedUserUtils.getUserInfo());
task.setTotalCount(storeGroup(qo).getResult().getTotalNum());
JSONObject jsonObject = new JSONObject();
qo.dealWithParam(jsonObject);
storeAuthUtils.setStoreGroupJsonParam(jsonObject, qo);
jsonObject.put("apolloKey", "data_point_anal_hb_app_store");
//Excel的标题是字段进行计算
List<String> indexList = new ArrayList<>();
List<String> fieldList = new ArrayList<>();
Integer storeGroup = jsonObject.getInteger("storeGroup");
boolean isStore = storeGroup != null && storeGroup == 7;
if (isStore) {
indexList.add("门店名称");
fieldList.add("storeName");
indexList.add("门店code");
fieldList.add("storeCode");
} else {
indexList.add("分组名称");
fieldList.add("storeGroupName");
}
indexList.add("上级分组");
fieldList.add("parentStoreGroupName");
indexList.add("员工总人数");
fieldList.add("clerkNum");
indexList.add("绑定人数");
fieldList.add("bindingNum");
indexList.add("绑定率");
fieldList.add("bindingRate");
indexList.add("活跃人数");
fieldList.add("visitNum");
indexList.add("活跃率");
fieldList.add("visitRate");
task.setFileName( "门店明细数据-" + qo.getStartDate() + (StringUtils.isNotBlank(qo.getEndDate()) ? "_" + qo.getEndDate() : ""));
task.setChannelName("数据-登录数据-好办使用详情");
task.setBucketName(BucketNameEnum.REPORT_50000.getName());
jsonObject.put("indexList", indexList);
jsonObject.put("fieldList", fieldList);
task.setSearchDataParams(jsonObject.toJSONString());
task.setHandler(wechatEventTrackingStoreGroupHandle);
JSONResponse downloadTask = DownloadTaskUtil.createDownloadTask(task);
return RestResponse.successResult(downloadTask.getResult());
}
/**
* 导购明细
* @param qo
* @return
*/
@RequestMapping(value = "clerk")
public RestResponse<DataPageVO<WechatEventTrackingClerkVO>> clerk(@RequestBody WechatEventTrackingClerkDetailQO qo) {
JSONObject jsonObject = new JSONObject();
qo.dealWithParam(jsonObject);
storeAuthUtils.setStoreGroupJsonParam(jsonObject, new StoreGroupCommonQO()
.setStoreGroupId(qo.getStoreGroupId()).setStoreId(qo.getStoreId()));
Map<String, Object> res = DataApiUtils.http(jsonObject.toJSONString(), "data_point_anal_hb_app_clerk");
DataPageVO<WechatEventTrackingClerkVO> vo = new DataPageVO<>();
Page page = DataApiUtils.getPageData(res);
vo.setTotalNum(page.getTotalCount());
vo.setPageNum(page.getCurrentPage());
vo.setPageSize(page.getPageSize());
List<JSONObject> list = page.getResult();
if (CollectionUtils.isNotEmpty(list)) {
vo.setRows(JSONArray.parseArray(JSON.toJSONString(list), WechatEventTrackingClerkVO.class));
}
return RestResponse.successResult(vo);
}
/**
* 查询分组下的门店,即无归属门店
* @param storeGroupId
* @return
*/
@RequestMapping(value = "get-unaffiliated-store")
public RestResponse<List<String>> getUnaffiliatedStoreByStoreGroupId(String storeGroupId) {
WebLoginDTO login = AuthWebRequestUtil.getLoginUser();
return RestResponse.successResult(storeAuthUtils.getPreStoreIdList(storeGroupId, login.getEnterpriseId()));
}
/**
* 导购明细导出
* @param qo
* @return
*/
@RequestMapping(value = "export-clerk")
public RestResponse exportClerk(@RequestBody WechatEventTrackingClerkDetailQO qo) {
DownloadTask task = new DownloadTask();
task.setTaskTypeEnum(TaskTypeEnum.HAOBAN_WECHAT_EVENT_CLERK);
task.setDataType(qo.getDataType());
task.setUser(AuthorizedUserUtils.getUserInfo());
task.setTotalCount(clerk(qo).getResult().getTotalNum());
JSONObject jsonObject = new JSONObject();
qo.dealWithParam(jsonObject);
storeAuthUtils.setStoreGroupJsonParam(jsonObject, new StoreGroupCommonQO()
.setStoreGroupId(qo.getStoreGroupId()).setStoreId(qo.getStoreId()));
jsonObject.put("apolloKey", "data_point_anal_hb_app_clerk");
//Excel的标题是字段进行计算
List<String> indexList = new ArrayList<>();
List<String> fieldList = new ArrayList<>();
indexList.add("导购code");
fieldList.add("clerkCode");
indexList.add("导购名称");
fieldList.add("clerkName");
indexList.add("归属门店名称");
fieldList.add("storeName");
indexList.add("归属门店code");
fieldList.add("storeCode");
indexList.add("是否绑定");
fieldList.add("isBinding");
indexList.add("是否登陆");
fieldList.add("isLogin");
indexList.add("登陆次数");
fieldList.add("visitCnt");
indexList.add("日均访问时长");
fieldList.add("visitTimeStr");
indexList.add("最近一次登陆时间");
fieldList.add("lastVisitTime");
task.setFileName("导购明细数据-" + qo.getStartDate() + (StringUtils.isNotBlank(qo.getEndDate()) ? "_" + qo.getEndDate() : ""));
task.setChannelName("数据-登录数据-好办使用详情");
task.setBucketName(BucketNameEnum.REPORT_50000.getName());
jsonObject.put("indexList", indexList);
jsonObject.put("fieldList", fieldList);
task.setSearchDataParams(jsonObject.toJSONString());
task.setHandler(wechatEventTrackingClerkDetailHandle);
JSONResponse downloadTask = DownloadTaskUtil.createDownloadTask(task);
return RestResponse.successResult(downloadTask.getResult());
}
private JSONObject getOverviewParam(WechatOverviewQO qo) {
JSONObject jsonObject = (JSONObject) JSONObject.toJSON(qo);
jsonObject.remove("storeGroupId");
jsonObject.remove("storeId");
storeAuthUtils.setCommonParam(jsonObject, new StoreGroupCommonQO().setStoreGroupId(qo.getStoreGroupId()).setStoreId(qo.getStoreId()));
return jsonObject;
}
}
package com.gic.haoban.manage.web.controller;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.gic.api.base.commons.JSONResponse;
import com.gic.api.base.commons.Page;
import com.gic.clerk.api.dto.AuthorizedUser;
import com.gic.commons.util.DataApiUtils;
import com.gic.commons.util.DateUtil;
import com.gic.commons.webapi.reponse.RestResponse;
import com.gic.haoban.base.api.common.pojo.dto.WebLoginDTO;
import com.gic.haoban.common.utils.AuthWebRequestUtil;
import com.gic.haoban.manage.web.handle.WechatWorkLostClerkHandle;
import com.gic.haoban.manage.web.handle.WechatWorkLostDetailHandle;
import com.gic.haoban.manage.web.handle.WechatWorkLostStoreGroupHandle;
import com.gic.haoban.manage.web.qo.wechatwork.*;
import com.gic.haoban.manage.web.utils.AuthorizedUserUtils;
import com.gic.haoban.manage.web.utils.data.ConcurrencyUtils;
import com.gic.haoban.manage.web.utils.data.MapThreadHandlerRequest;
import com.gic.haoban.manage.web.utils.data.StoreAuthUtils;
import com.gic.haoban.manage.web.vo.wechatwork.*;
import com.gic.qcloud.BucketNameEnum;
import com.gic.web.common.controller.NewBaseController;
import com.gic.web.common.download.DownloadTask;
import com.gic.web.common.download.DownloadTaskUtil;
import com.gic.web.common.download.constants.TaskTypeEnum;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
* 企微流失接口
* @Author guojx
* @Date 2024/5/21 13:45
*/
@RestController
@Slf4j
@RequestMapping("wechat-work")
public class WechatWorkController extends NewBaseController {
@Autowired
private StoreAuthUtils storeAuthUtils;
@Autowired
private WechatWorkLostClerkHandle wechatWorkLostClerkHandle;
@Autowired
private WechatWorkLostStoreGroupHandle wechatWorkLostStoreGroupHandle;
@Autowired
private WechatWorkLostDetailHandle wechatWorkLostDetailHandle;
/**
* 流失数据概览
* @param qo
* @return
*/
@RequestMapping(value = "lost-overview")
public RestResponse<WechatWorkLostVO> lostOverview(@RequestBody WechatWorkLostOverviewQO qo) {
JSONObject jsonObject = (JSONObject) JSONObject.toJSON(qo);
storeAuthUtils.setCommonParam(jsonObject, new StoreGroupCommonQO().setStoreGroupId(qo.getStoreGroupId()));
Map<String, Object> res = DataApiUtils.http(jsonObject.toJSONString(), "data_mbr_scale_haoban_background_loss");
List<JSONObject> list = DataApiUtils.getDataList(res);
List<WechatWorkLostVO> voList = JSONArray.parseArray(JSON.toJSONString(list), WechatWorkLostVO.class);
return RestResponse.successResult(CollectionUtils.isEmpty(voList) ? null : voList.get(0));
}
/**
* 流失数据概览趋势图
* @param qo
* @return
* @throws ParseException
*/
@RequestMapping(value = "lost-overview-trend")
public RestResponse<List<WechatWorkLostVO>> lostOverviewTrend(@RequestBody WechatWorkLostOverviewQO qo) throws ParseException {
JSONObject jsonObject = (JSONObject) JSONObject.toJSON(qo);
storeAuthUtils.setCommonParam(jsonObject, new StoreGroupCommonQO().setStoreGroupId(qo.getStoreGroupId()));
List<MapThreadHandlerRequest> list = new ArrayList<>();
jsonObject.put("groupType", 1);
list.add(new MapThreadHandlerRequest(jsonObject, "data_mbr_scale_haoban_background_loss_date", "1_onewayFriendNum"));
jsonObject.put("groupType", 2);
list.add(new MapThreadHandlerRequest(jsonObject, "data_mbr_scale_haoban_background_loss_date", "2_totalLostNum"));
jsonObject.put("groupType", 3);
list.add(new MapThreadHandlerRequest(jsonObject, "data_mbr_scale_haoban_background_loss_date", "3_deleteSalesNum"));
jsonObject.put("groupType", 4);
list.add(new MapThreadHandlerRequest(jsonObject, "data_mbr_scale_haoban_background_loss_date", "4_salesDeleteNum"));
Map<String, List<JSONObject>> map = ConcurrencyUtils.concurrencyDataForMap(list);
List<JSONObject> resultList = new ArrayList<>();
if (map != null) {
map.forEach((k, v) -> {
if (CollectionUtils.isNotEmpty(v)) {
for (JSONObject tempJson : v) {
tempJson.put(k.substring(0, 1), tempJson.get(k.substring(2)));
}
resultList.addAll(v);
}
});
}
Map<String, List<JSONObject>> voMap = resultList.stream().collect(Collectors.groupingBy(e -> e.getString("bizDate")));
List<String> dateList = DateUtil.getBetweenDates(qo.getStartDate(), qo.getEndDate());
List<WechatWorkLostVO> voList = new ArrayList<>();
for (String date : dateList) {
WechatWorkLostVO vo = new WechatWorkLostVO();
vo.setBizDate(date);
List<JSONObject> mapValue = voMap.get(date);
if (CollectionUtils.isNotEmpty(mapValue)) {
for (JSONObject tempJson : mapValue) {
if (tempJson.containsKey("1")) {
vo.setOnewayFriendNum(tempJson.getInteger("1"));
}
if (tempJson.containsKey("2")) {
vo.setTotalLostNum(tempJson.getInteger("2"));
}
if (tempJson.containsKey("3")) {
vo.setDeleteSalesNum(tempJson.getInteger("3"));
}
if (tempJson.containsKey("4")) {
vo.setSalesDeleteNum(tempJson.getInteger("4"));
}
}
}
voList.add(vo);
}
return RestResponse.successResult(voList);
}
/**
* 流失数据统计-门店分组
* @param qo
* @return
*/
@RequestMapping(value = "lost-store-group")
public RestResponse<DataPageVO<WechatWorkLostStoreGroupVO>> lostStoreGroup(@RequestBody WechatWorkLostStoreGroupQO qo) {
JSONObject jsonObject = new JSONObject();
qo.dealWithParam(jsonObject);
storeAuthUtils.setStoreGroupJsonParam(jsonObject, qo);
jsonObject.put("apolloKey", "data_mbr_scale_haoban_background_loss_statisti");
jsonObject.put("groupType", 1);
DataPageVO vo = storeAuthUtils.getDataCommon(jsonObject.toJSONString(), qo.getPageNum(), "data_mbr_scale_haoban_background_loss_statisti", qo.getPageSize(), true);
if (CollectionUtils.isNotEmpty(vo.getRows())) {
vo.setRows(JSONArray.parseArray(JSON.toJSONString(vo.getRows()), WechatWorkLostStoreGroupVO.class));
}
return RestResponse.successResult(vo);
}
/**
* 流失数据统计-门店分组导出
* @param qo
* @return
*/
@RequestMapping(value = "export-lost-store-group")
public RestResponse exportLostStoreGroup(@RequestBody WechatWorkLostStoreGroupQO qo) {
DownloadTask task = new DownloadTask();
task.setTaskTypeEnum(TaskTypeEnum.WECHAT_WORK_STORE_GROUP);
task.setDataType(qo.getDataType());
task.setUser(getUserInfo());
task.setTotalCount(lostStoreGroup(qo).getResult().getTotalNum());
JSONObject jsonObject = new JSONObject();
qo.dealWithParam(jsonObject);
storeAuthUtils.setStoreGroupJsonParam(jsonObject, qo);
jsonObject.put("apolloKey", "data_mbr_scale_haoban_background_loss_statisti");
jsonObject.put("groupType", 1);
//Excel的标题是字段进行计算
List<String> indexList = new ArrayList<>();
List<String> fieldList = new ArrayList<>();
Integer storeGroup = jsonObject.getInteger("storeGroup");
boolean isStore = storeGroup != null && storeGroup == 7;
if (isStore) {
indexList.add("门店名称");
fieldList.add("storeName");
indexList.add("门店code");
fieldList.add("storeCode");
} else {
indexList.add("分组名称");
fieldList.add("storeGroupName");
}
indexList.add("上级分组");
fieldList.add("parentStoreGroupName");
indexList.add("删除导购人数");
fieldList.add("deleteSalesNum");
indexList.add("导购删除人数");
fieldList.add("salesDeleteNum");
indexList.add("单向好友人数");
fieldList.add("onewayFriendNum");
task.setFileName( "流失好友-门店维度数据统计-" + qo.getStartDate() + "_" + qo.getEndDate());
task.setChannelName("数据-企微数据-流失好友");
task.setBucketName(BucketNameEnum.REPORT_50000.getName());
jsonObject.put("indexList", indexList);
jsonObject.put("fieldList", fieldList);
task.setSearchDataParams(jsonObject.toJSONString());
task.setHandler(wechatWorkLostStoreGroupHandle);
JSONResponse downloadTask = DownloadTaskUtil.createDownloadTask(task);
return RestResponse.successResult(downloadTask.getResult());
}
/**
* 流失数据统计-导购
* @param qo
* @return
*/
@RequestMapping(value = "lost-clerk")
public RestResponse<DataPageVO<WechatWorkLostClerkVO>> lostClerk(@RequestBody WechatWorkLostClerkQO qo) {
JSONObject jsonObject = new JSONObject();
qo.dealWithParam(jsonObject);
storeAuthUtils.setCommonParam(jsonObject, new StoreGroupCommonQO());
jsonObject.put("groupType", 2);
Map<String, Object> res = DataApiUtils.http(jsonObject.toJSONString(), "data_mbr_scale_haoban_background_loss_statisti");
Page page = DataApiUtils.getPageData(res);
DataPageVO vo = new DataPageVO();
vo.setPageSize(page.getPageSize());
vo.setPageNum(page.getCurrentPage());
List<JSONObject> list = page.getResult();
vo.setTotalNum(page.getTotalCount());
jsonObject.put("groupType", 1);
jsonObject.put("storeGroup", 8);
JSONObject total = storeAuthUtils.getTotalJson(jsonObject, "data_mbr_scale_haoban_background_loss_statisti");
if (list == null) {
list = new ArrayList<>();
}
if (total != null) {
total.put("clerkName", "合计(" + list.size() + ")");
list.add(0, total);
}
vo.setRows(list);
if (CollectionUtils.isNotEmpty(vo.getRows())) {
vo.setRows(JSONArray.parseArray(JSON.toJSONString(vo.getRows()), WechatWorkLostClerkVO.class));
}
return RestResponse.successResult(vo);
}
/**
* 流失数据统计-导购导出
* @param qo
* @return
*/
@RequestMapping(value = "export-lost-clerk")
public RestResponse exportLostClerk(@RequestBody WechatWorkLostClerkQO qo) {
DownloadTask task = new DownloadTask();
task.setTaskTypeEnum(TaskTypeEnum.WECHAT_WORK_CLERK_DETAIL);
task.setDataType(qo.getDataType());
task.setUser(getUserInfo());
task.setTotalCount(lostClerk(qo).getResult().getTotalNum());
JSONObject jsonObject = new JSONObject();
qo.dealWithParam(jsonObject);
storeAuthUtils.setCommonParam(jsonObject, new StoreGroupCommonQO());
jsonObject.put("apolloKey", "data_mbr_scale_haoban_background_loss_statisti");
jsonObject.put("groupType", 2);
//Excel的标题是字段进行计算
List<String> indexList = new ArrayList<>();
List<String> fieldList = new ArrayList<>();
indexList.add("导购姓名");
fieldList.add("clerkName");
indexList.add("导购code");
fieldList.add("clerkCode");
indexList.add("所属门店名称");
fieldList.add("storeName");
indexList.add("所属门店code");
fieldList.add("storeCode");
indexList.add("所属分组");
fieldList.add("storeGroupName");
indexList.add("删除导购人数");
fieldList.add("deleteSalesNum");
indexList.add("导购删除人数");
fieldList.add("salesDeleteNum");
indexList.add("单向好友人数");
fieldList.add("onewayFriendNum");
task.setFileName( "流失好友-导购维度数据统计-" + qo.getStartDate() + "_" + qo.getEndDate());
task.setChannelName("数据-企微数据-流失好友");
task.setBucketName(BucketNameEnum.REPORT_50000.getName());
jsonObject.put("indexList", indexList);
jsonObject.put("fieldList", fieldList);
task.setSearchDataParams(jsonObject.toJSONString());
task.setHandler(wechatWorkLostClerkHandle);
JSONResponse downloadTask = DownloadTaskUtil.createDownloadTask(task);
return RestResponse.successResult(downloadTask.getResult());
}
/**
* 流失明细
* @param qo
* @return
*/
@RequestMapping(value = "lost-detail")
public RestResponse<DataPageVO<WechatWorkLostDetailVO>> lostDetail(@RequestBody WechatWorkLostDetailQO qo) {
JSONObject jsonObject = new JSONObject();
qo.dealWithParam(jsonObject);
storeAuthUtils.setCommonParam(jsonObject, new StoreGroupCommonQO());
Map<String, Object> res = DataApiUtils.http(jsonObject.toJSONString(), "data_mbr_scale_haoban_background_loss_detail");
Page page = DataApiUtils.getPageData(res);
DataPageVO<WechatWorkLostDetailVO> vo = new DataPageVO();
vo.setPageSize(page.getPageSize());
vo.setPageNum(page.getCurrentPage());
List<JSONObject> list = page.getResult();
if (CollectionUtils.isNotEmpty(list)) {
List<WechatWorkLostDetailVO> voList = JSONArray.parseArray(JSON.toJSONString(list), WechatWorkLostDetailVO.class);
vo.setRows(voList);
}
vo.setTotalNum(page.getTotalCount());
return RestResponse.successResult(vo);
}
/**
* 流失明细-导出
* @param qo
* @return
*/
@RequestMapping(value = "export-lost-detail")
public RestResponse exportLostDetail(@RequestBody WechatWorkLostDetailQO qo) {
DownloadTask task = new DownloadTask();
task.setTaskTypeEnum(TaskTypeEnum.WECHAT_WORK_MEMBER_DETAIL);
task.setDataType(qo.getDataType());
task.setUser(getUserInfo());
task.setTotalCount(lostDetail(qo).getResult().getTotalNum());
JSONObject jsonObject = new JSONObject();
qo.dealWithParam(jsonObject);
storeAuthUtils.setCommonParam(jsonObject, new StoreGroupCommonQO());
jsonObject.put("apolloKey", "data_mbr_scale_haoban_background_loss_detail");
//Excel的标题是字段进行计算
List<String> indexList = new ArrayList<>();
List<String> fieldList = new ArrayList<>();
indexList.add("客户姓名");
fieldList.add("memberName");
indexList.add("客户昵称");
fieldList.add("memberNick");
indexList.add("客户手机号");
fieldList.add("memberPhone");
indexList.add("导购姓名");
fieldList.add("clerkName");
indexList.add("导购code");
fieldList.add("clerkCode");
indexList.add("所属门店名称");
fieldList.add("storeName");
indexList.add("所属门店code");
fieldList.add("storeCode");
indexList.add("删除类型");
fieldList.add("deleteType");
indexList.add("留存天数");
fieldList.add("remainDays");
indexList.add("添加好友时间");
fieldList.add("addTime");
indexList.add("最近消费时间");
fieldList.add("lastCsmeDate");
indexList.add("删除时间");
fieldList.add("deleteTime");
task.setFileName( "流失好友-流失明细-" + qo.getStartDate() + "_" + qo.getEndDate());
task.setChannelName("数据-企微数据-流失好友");
task.setBucketName(BucketNameEnum.REPORT_50000.getName());
jsonObject.put("indexList", indexList);
jsonObject.put("fieldList", fieldList);
task.setSearchDataParams(jsonObject.toJSONString());
task.setHandler(wechatWorkLostDetailHandle);
JSONResponse downloadTask = DownloadTaskUtil.createDownloadTask(task);
return RestResponse.successResult(downloadTask.getResult());
}
private AuthorizedUser getUserInfo() {
return AuthorizedUserUtils.getUserInfo();
}
}
......@@ -169,4 +169,11 @@ public class GlobalExceptionHandler extends WebBaseController {
return RestResponse.failure(ex.getCode(), ex.getMessage());
}
@ResponseBody
@ExceptionHandler(com.gic.commons.exception.DataApiException.class)
public RestResponse dataApiExceptionCommon(HttpServletResponse response, com.gic.commons.exception.DataApiException ex) {
logger.info("DataApiException common异常信息:{}", ex);
return RestResponse.failure(ex.getCode(), ex.getMessage());
}
}
package com.gic.haoban.manage.web.handle;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.gic.commons.util.DataApiUtils;
import com.gic.enterprise.api.dto.security.DownloadReportDTO;
import com.gic.haoban.manage.web.vo.eventtracking.WechatEventTrackingClerkVO;
import com.gic.web.common.download.DownloadHandlerAbstract;
import com.gic.web.common.download.context.Context;
import org.apache.commons.collections.CollectionUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.stereotype.Component;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
/**
* 数据-登录数据-好办使用详情
*/
@Component
public class WechatEventTrackingClerkDetailHandle extends DownloadHandlerAbstract<WechatEventTrackingClerkVO> {
private static final Logger LOGGER = LogManager.getLogger(WechatEventTrackingClerkDetailHandle.class);
@Override
public List<WechatEventTrackingClerkVO> getData(Context context, String searchDataParams, Integer currentPage) {
boolean isFirst = currentPage != null && currentPage == 1;
if (isFirst) {
LOGGER.info("数据-登录数据-好办使用导购详情导出日志");
}
JSONObject jsonObject = JSON.parseObject(searchDataParams);
Map<String, Object> res = DataApiUtils.http(jsonObject.toJSONString(), "data_point_anal_hb_app_clerk");
List<JSONObject> list = DataApiUtils.getPageList(res);
if (CollectionUtils.isNotEmpty(list)) {
List<WechatEventTrackingClerkVO> result = JSONObject.parseArray(JSON.toJSONString(list), WechatEventTrackingClerkVO.class);
return result;
}
return Collections.EMPTY_LIST;
}
@Override
public List<String> getColumnNames() {
return Collections.EMPTY_LIST;
}
@Override
public List<String> getColumnNames(Context context){
DownloadReportDTO downloadReportDTO = context.getDownloadReportDTO();
String searchDataParams = downloadReportDTO.getSearchDataParams();
JSONObject jsonObject = JSONObject.parseObject(searchDataParams);
List<String> list = (List<String>) jsonObject.get("indexList");
return list;
}
@Override
public LinkedHashMap<String, List<String>> doubleColumnNames() {
return null;
}
@Override
public List<String> getColumns() {
return Collections.EMPTY_LIST;
}
@Override
public List<String> getColumns(Context context) {
DownloadReportDTO downloadReportDTO = context.getDownloadReportDTO();
String searchDataParams = downloadReportDTO.getSearchDataParams();
JSONObject jsonObject = JSONObject.parseObject(searchDataParams);
List<String> list = (List<String>) jsonObject.get("fieldList");
return list;
}
}
package com.gic.haoban.manage.web.handle;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.gic.enterprise.api.dto.security.DownloadReportDTO;
import com.gic.haoban.manage.web.utils.data.StoreAuthUtils;
import com.gic.haoban.manage.web.vo.eventtracking.WechatEventTrackingStoreGroupVO;
import com.gic.web.common.download.DownloadHandlerAbstract;
import com.gic.web.common.download.context.Context;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.List;
/**
* 数据-登录数据-好办使用详情
*/
@Component
public class WechatEventTrackingStoreGroupHandle extends DownloadHandlerAbstract<WechatEventTrackingStoreGroupVO> {
@Autowired
private StoreAuthUtils storeAuthUtils;
@Override
public List<WechatEventTrackingStoreGroupVO> getData(Context context, String searchDataParams, Integer currentPage) {
List<JSONObject> list = storeAuthUtils.getDataCommon(searchDataParams, currentPage,
"数据-登录数据-好办使用详情导出日志进来", getPageSize(), false).getRows();
list = storeAuthUtils.deleteTotalData(list);
if (CollectionUtils.isNotEmpty(list)) {
List<WechatEventTrackingStoreGroupVO> result = JSONObject.parseArray(JSON.toJSONString(list), WechatEventTrackingStoreGroupVO.class);
return result;
}
return Collections.EMPTY_LIST;
}
@Override
public List<String> getColumnNames() {
return Collections.EMPTY_LIST;
}
@Override
public List<String> getColumnNames(Context context){
DownloadReportDTO downloadReportDTO = context.getDownloadReportDTO();
String searchDataParams = downloadReportDTO.getSearchDataParams();
JSONObject jsonObject = JSONObject.parseObject(searchDataParams);
List<String> list = (List<String>) jsonObject.get("indexList");
return list;
}
@Override
public LinkedHashMap<String, List<String>> doubleColumnNames() {
return null;
}
@Override
public List<String> getColumns() {
return Collections.EMPTY_LIST;
}
@Override
public List<String> getColumns(Context context) {
DownloadReportDTO downloadReportDTO = context.getDownloadReportDTO();
String searchDataParams = downloadReportDTO.getSearchDataParams();
JSONObject jsonObject = JSONObject.parseObject(searchDataParams);
List<String> list = (List<String>) jsonObject.get("fieldList");
return list;
}
}
package com.gic.haoban.manage.web.handle;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.gic.commons.util.DataApiUtils;
import com.gic.enterprise.api.dto.security.DownloadReportDTO;
import com.gic.haoban.manage.web.utils.data.StoreAuthUtils;
import com.gic.haoban.manage.web.vo.wechatwork.WechatWorkLostClerkVO;
import com.gic.web.common.download.DownloadHandlerAbstract;
import com.gic.web.common.download.context.Context;
import org.apache.commons.collections.CollectionUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.*;
/**
* 数据-企微数据-流失好友-导购
*/
@Component
public class WechatWorkLostClerkHandle extends DownloadHandlerAbstract<WechatWorkLostClerkVO> {
private static final Logger LOGGER = LogManager.getLogger(WechatWorkLostClerkHandle.class);
@Autowired
private StoreAuthUtils storeAuthUtils;
@Override
public List<WechatWorkLostClerkVO> getData(Context context, String searchDataParams, Integer currentPage) {
boolean isFirst = currentPage != null && currentPage == 1;
if (isFirst) {
LOGGER.info("数据-企微数据-流失好友-导购导出日志");
}
JSONObject jsonObject = JSON.parseObject(searchDataParams);
Map<String, Object> res = DataApiUtils.http(jsonObject.toJSONString(), "data_mbr_scale_haoban_background_loss_statisti");
List<JSONObject> list = DataApiUtils.getPageList(res);
jsonObject.put("groupType", 1);
jsonObject.put("storeGroup", 8);
JSONObject total = storeAuthUtils.getTotalJson(jsonObject, "data_mbr_scale_haoban_background_loss_statisti");
if (list == null) {
list = new ArrayList<>();
}
if (total != null) {
total.put("clerkName", "合计(" + list.size() + ")");
list.add(0, total);
}
if (CollectionUtils.isNotEmpty(list)) {
List<WechatWorkLostClerkVO> result = JSONObject.parseArray(JSON.toJSONString(list), WechatWorkLostClerkVO.class);
return result;
}
return Collections.EMPTY_LIST;
}
@Override
public List<String> getColumnNames() {
return Collections.EMPTY_LIST;
}
@Override
public List<String> getColumnNames(Context context){
DownloadReportDTO downloadReportDTO = context.getDownloadReportDTO();
String searchDataParams = downloadReportDTO.getSearchDataParams();
JSONObject jsonObject = JSONObject.parseObject(searchDataParams);
List<String> list = (List<String>) jsonObject.get("indexList");
return list;
}
@Override
public LinkedHashMap<String, List<String>> doubleColumnNames() {
return null;
}
@Override
public List<String> getColumns() {
return Collections.EMPTY_LIST;
}
@Override
public List<String> getColumns(Context context) {
DownloadReportDTO downloadReportDTO = context.getDownloadReportDTO();
String searchDataParams = downloadReportDTO.getSearchDataParams();
JSONObject jsonObject = JSONObject.parseObject(searchDataParams);
List<String> list = (List<String>) jsonObject.get("fieldList");
return list;
}
}
package com.gic.haoban.manage.web.handle;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.gic.commons.util.DataApiUtils;
import com.gic.enterprise.api.dto.security.DownloadReportDTO;
import com.gic.haoban.manage.web.utils.data.StoreAuthUtils;
import com.gic.haoban.manage.web.vo.wechatwork.WechatWorkLostDetailVO;
import com.gic.web.common.download.DownloadHandlerAbstract;
import com.gic.web.common.download.context.Context;
import org.apache.commons.collections.CollectionUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
/**
* 数据-企微数据-流失好友-明细
*/
@Component
public class WechatWorkLostDetailHandle extends DownloadHandlerAbstract<WechatWorkLostDetailVO> {
private static final Logger LOGGER = LogManager.getLogger(WechatWorkLostDetailHandle.class);
@Autowired
private StoreAuthUtils storeAuthUtils;
@Override
public List<WechatWorkLostDetailVO> getData(Context context, String searchDataParams, Integer currentPage) {
boolean isFirst = currentPage != null && currentPage == 1;
if (isFirst) {
LOGGER.info("数据-企微数据-流失好友-明细导出日志");
}
JSONObject jsonObject = JSON.parseObject(searchDataParams);
Map<String, Object> res = DataApiUtils.http(jsonObject.toJSONString(), "data_mbr_scale_haoban_background_loss_detail");
List<JSONObject> list = DataApiUtils.getPageList(res);
if (CollectionUtils.isNotEmpty(list)) {
List<WechatWorkLostDetailVO> result = JSONObject.parseArray(JSON.toJSONString(list), WechatWorkLostDetailVO.class);
return result;
}
return Collections.EMPTY_LIST;
}
@Override
public List<String> getColumnNames() {
return Collections.EMPTY_LIST;
}
@Override
public List<String> getColumnNames(Context context){
DownloadReportDTO downloadReportDTO = context.getDownloadReportDTO();
String searchDataParams = downloadReportDTO.getSearchDataParams();
JSONObject jsonObject = JSONObject.parseObject(searchDataParams);
List<String> list = (List<String>) jsonObject.get("indexList");
return list;
}
@Override
public LinkedHashMap<String, List<String>> doubleColumnNames() {
return null;
}
@Override
public List<String> getColumns() {
return Collections.EMPTY_LIST;
}
@Override
public List<String> getColumns(Context context) {
DownloadReportDTO downloadReportDTO = context.getDownloadReportDTO();
String searchDataParams = downloadReportDTO.getSearchDataParams();
JSONObject jsonObject = JSONObject.parseObject(searchDataParams);
List<String> list = (List<String>) jsonObject.get("fieldList");
return list;
}
}
package com.gic.haoban.manage.web.handle;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.gic.enterprise.api.dto.security.DownloadReportDTO;
import com.gic.haoban.manage.web.utils.data.StoreAuthUtils;
import com.gic.haoban.manage.web.vo.wechatwork.WechatWorkLostStoreGroupVO;
import com.gic.web.common.download.DownloadHandlerAbstract;
import com.gic.web.common.download.context.Context;
import org.apache.commons.collections.CollectionUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.List;
/**
* 数据-企微数据-流失好友
*/
@Component
public class WechatWorkLostStoreGroupHandle extends DownloadHandlerAbstract<WechatWorkLostStoreGroupVO> {
private static final Logger LOGGER = LogManager.getLogger(WechatWorkLostStoreGroupHandle.class);
@Autowired
private StoreAuthUtils storeAuthUtils;
@Override
public List<WechatWorkLostStoreGroupVO> getData(Context context, String searchDataParams, Integer currentPage) {
List<JSONObject> list = storeAuthUtils.getDataCommon(searchDataParams, currentPage,
"数据-企微数据-流失好友导出日志进来", getPageSize(), false).getRows();
if (CollectionUtils.isNotEmpty(list)) {
List<WechatWorkLostStoreGroupVO> result = JSONObject.parseArray(JSON.toJSONString(list), WechatWorkLostStoreGroupVO.class);
return result;
}
return Collections.EMPTY_LIST;
}
@Override
public List<String> getColumnNames() {
return Collections.EMPTY_LIST;
}
@Override
public List<String> getColumnNames(Context context){
DownloadReportDTO downloadReportDTO = context.getDownloadReportDTO();
String searchDataParams = downloadReportDTO.getSearchDataParams();
JSONObject jsonObject = JSONObject.parseObject(searchDataParams);
List<String> list = (List<String>) jsonObject.get("indexList");
return list;
}
@Override
public LinkedHashMap<String, List<String>> doubleColumnNames() {
return null;
}
@Override
public List<String> getColumns() {
return Collections.EMPTY_LIST;
}
@Override
public List<String> getColumns(Context context) {
DownloadReportDTO downloadReportDTO = context.getDownloadReportDTO();
String searchDataParams = downloadReportDTO.getSearchDataParams();
JSONObject jsonObject = JSONObject.parseObject(searchDataParams);
List<String> list = (List<String>) jsonObject.get("fieldList");
return list;
}
}
package com.gic.haoban.manage.web.qo.eventtracking;
import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;
import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;
/**
* @Author guojx
* @Date 2024/5/21 14:12
*/
@Data
@JsonIgnoreProperties(ignoreUnknown = true)
public class WechatEventTrackingClerkDetailQO implements Serializable {
/**
* yyyy-MM-dd
*/
private String startDate;
/**
* yyyy-MM-dd
*/
private String endDate;
/**
* 导购名称/code
*/
private String vagueQueryClerk;
/**
* 数据类型 1天 2近7天 3近30天 4周 5月
*/
private Integer dateType;
/**
* 排序类型 1 正序 2 倒序
*/
private Integer orderByType;
/**
* 排序字段名称
*/
private String orderByFields;
/**
* 分组ID,可为空
*/
private String storeGroupId;
/**
* 0:未登录
*/
private Integer isLogin;
/**
* 门店ID。可为空
*/
private String storeId;
private Integer pageNum;
private Integer pageSize;
/**
* 下载导出参数:数据脱敏 1:脱敏 2:完整
*/
private Integer dataType = 1;
/**
* 下载导出参数:为了兼容前端传参
*/
private String requestProject;
public Integer getDataApiOrderField() {
Map<String, Integer> map = new HashMap<>(8);
map.put("avgVisitTime", 1);
map.put("lastVisitTime", 2);
return map.get(orderByFields) == null ? 1 : map.get(orderByFields);
}
public void dealWithParam(JSONObject jsonObject) {
if (jsonObject == null) {
jsonObject = new JSONObject();
}
if (StringUtils.isNotBlank(startDate)) {
jsonObject.put("startDate", startDate);
}
if (StringUtils.isNotBlank(endDate)) {
jsonObject.put("endDate", endDate);
}
if (dateType != null) {
jsonObject.put("dateType", dateType);
}
if (orderByType != null) {
jsonObject.put("orderByType", orderByType);
}
if (orderByFields != null) {
jsonObject.put("orderByFields", getDataApiOrderField());
}
if (isLogin != null) {
jsonObject.put("isLogin", isLogin);
}
jsonObject.put("pageNum", pageNum);
jsonObject.put("pageSize", pageSize);
if (StringUtils.isNotBlank(vagueQueryClerk)) {
jsonObject.put("vagueQueryClerk", vagueQueryClerk);
}
}
}
package com.gic.haoban.manage.web.qo.eventtracking;
import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.gic.haoban.manage.web.qo.wechatwork.StoreGroupCommonQO;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;
import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;
/**
* @Author guojx
* @Date 2024/5/22 9:27
*/
@Data
@JsonIgnoreProperties(ignoreUnknown = true)
public class WechatEventTrackingStoreGroupQO extends StoreGroupCommonQO implements Serializable {
/**
* 周期起始时间
*/
private String startDate;
/**
* 结束时间
*/
private String endDate;
/**
* 数据类型 1天 2近7天 3近30天 4周 5月
*/
private Integer dateType;
/**
* 排序类型 1 正序 2 倒序
*/
private Integer orderByType;
/**
* 排序字段名称
*/
private String orderByFields;
private Integer pageNum;
private Integer pageSize;
/**
* 下载导出参数:数据脱敏 1:脱敏 2:完整
*/
private Integer dataType = 1;
/**
* 下载导出参数:为了兼容前端传参
*/
private String requestProject;
public Integer getDataApiOrderField() {
Map<String, Integer> map = new HashMap<>(8);
map.put("clerkNum", 1);
map.put("bindingNum", 2);
map.put("bindingRate", 3);
map.put("visitNum", 4);
map.put("visitRate", 5);
map.put("visitCnt", 6);
return map.get(orderByFields) == null ? 1 : map.get(orderByFields);
}
public void dealWithParam(JSONObject jsonObject) {
if (jsonObject == null) {
jsonObject = new JSONObject();
}
if (StringUtils.isNotBlank(startDate)) {
jsonObject.put("startDate", startDate);
}
if (dateType != null) {
jsonObject.put("dateType", dateType);
}
if (orderByType != null) {
jsonObject.put("orderByType", orderByType);
}
if (orderByFields != null) {
jsonObject.put("orderByFields", getDataApiOrderField());
}
jsonObject.put("pageNum", pageNum);
jsonObject.put("pageSize", pageSize);
}
}
package com.gic.haoban.manage.web.qo.eventtracking;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.Data;
import java.io.Serializable;
/**
* @Author guojx
* @Date 2024/5/30 9:14
*/
@Data
@JsonIgnoreProperties(ignoreUnknown = true)
public class WechatOverviewQO implements Serializable {
/**
* yyyy-MM-dd
*/
private String startDate;
private String endDate;
/**
* 数据类型 1天 2近7天 3近30天 4周 5月
*/
private Integer dateType;
/**
* 分组ID,可为空
*/
private String storeGroupId;
/**
* 门店ID。可为空
*/
private String storeId;
}
package com.gic.haoban.manage.web.qo.wechatwork;
import lombok.Data;
import lombok.experimental.Accessors;
import java.io.Serializable;
/**
* @Author guojx
* @Date 2024/5/22 9:16
*/
@Data
@Accessors(chain = true)
public class StoreGroupCommonQO implements Serializable {
/**
* 门店code/名称
*/
private String storeSearchParam;
/**
* 可以多选,英文逗号隔开。优先级高于storeId
*/
private String storeGroupId;
/**
* 可以多选,英文逗号隔开
*/
private String storeId;
/**
* 分组下钻的时候,当前点击的分组id参数.如果是无归属,则值是-1
* @return
*/
private String nextStoreGroupId;
/**
* 因为存在nextStoreGroupId = -1的无归属分组。当下钻无归属,值为无归属上一层级的分组id。如果为空,说明上一层级是所有哦门店,否则必有值
*/
private String preStoreGroupId;
/**
* 分组维度查询,勾选展示门店 1:是
*/
private Integer showStore;
public boolean isRecycle() {
return "-3".equals(nextStoreGroupId);
}
public boolean isNoBelongStoreGroup() {
return "-1".equals(nextStoreGroupId);
}
public boolean isSelectStore() {
return showStore != null && showStore == 1;
}
}
package com.gic.haoban.manage.web.qo.wechatwork;
import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;
import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;
/**
* @Author guojx
* @Date 2024/5/21 14:12
*/
@Data
@JsonIgnoreProperties(ignoreUnknown = true)
public class WechatWorkLostClerkQO implements Serializable {
/**
* yyyy-MM-dd
*/
private String startDate;
/**
* yyyy-MM-dd
*/
private String endDate;
/**
* 门店名称/code
*/
private String vagueQueryStore;
/**
* 导购名称/code
*/
private String vagueQueryClerk;
/**
* 排序类型 1 正序 2 倒序
*/
private Integer orderByType;
/**
* 排序字段名称
*/
private String orderByFields;
private Integer pageNum;
private Integer pageSize;
/**
* 下载导出参数:数据脱敏 1:脱敏 2:完整
*/
private Integer dataType = 1;
/**
* 下载导出参数:为了兼容前端传参
*/
private String requestProject;
public Integer getDataApiOrderField() {
Map<String, Integer> map = new HashMap<>(8);
map.put("onewayFriendNum", 1);
map.put("totalLostNum", 2);
map.put("deleteSalesNum", 3);
map.put("salesDeleteNum", 4);
return map.get(orderByFields) == null ? 1 : map.get(orderByFields);
}
public void dealWithParam(JSONObject jsonObject) {
if (jsonObject == null) {
jsonObject = new JSONObject();
}
if (StringUtils.isNotBlank(startDate)) {
jsonObject.put("startDate", startDate);
}
if (StringUtils.isNotBlank(endDate)) {
jsonObject.put("endDate", endDate);
}
if (orderByType != null) {
jsonObject.put("orderByType", orderByType);
}
if (orderByFields != null) {
jsonObject.put("orderByFields", getDataApiOrderField());
}
jsonObject.put("pageNum", pageNum);
jsonObject.put("pageSize", pageSize);
if (StringUtils.isNotBlank(vagueQueryClerk)) {
jsonObject.put("vagueQueryClerk", vagueQueryClerk);
}
if (StringUtils.isNotBlank(vagueQueryStore)) {
jsonObject.put("vagueQueryStore", vagueQueryStore);
}
}
}
package com.gic.haoban.manage.web.qo.wechatwork;
import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;
import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;
/**
* @Author guojx
* @Date 2024/5/21 14:12
*/
@Data
@JsonIgnoreProperties(ignoreUnknown = true)
public class WechatWorkLostDetailQO implements Serializable {
/**
* yyyy-MM-dd
*/
private String startDate;
/**
* yyyy-MM-dd
*/
private String endDate;
/**
* 用户模糊
*/
private String vagueQueryUser;
/**
* 导购名称/code
*/
private String vagueQueryClerk;
/**
* 是/否
* 是否已解除双向好友
*/
private String isDelete;
/**
* 导购删除好友/好友删除导购
* 删除类型
*/
private String deleteType;
/**
* 排序类型 1 正序 2 倒序
*/
private Integer orderByType;
/**
* 排序字段名称
*/
private String orderByFields;
private Integer pageNum;
private Integer pageSize;
/**
* 下载导出参数:数据脱敏 1:脱敏 2:完整
*/
private Integer dataType = 1;
/**
* 下载导出参数:为了兼容前端传参
*/
private String requestProject;
public Integer getDataApiOrderField() {
Map<String, Integer> map = new HashMap<>(8);
map.put("remainDays", 9);
return map.get(orderByFields) == null ? 1 : map.get(orderByFields);
}
public void dealWithParam(JSONObject jsonObject) {
if (jsonObject == null) {
jsonObject = new JSONObject();
}
if (StringUtils.isNotBlank(startDate)) {
jsonObject.put("startDate", startDate);
}
if (StringUtils.isNotBlank(endDate)) {
jsonObject.put("endDate", endDate);
}
if (orderByType != null) {
jsonObject.put("orderByType", orderByType);
}
if (orderByFields != null) {
jsonObject.put("orderByFields", getDataApiOrderField());
}
jsonObject.put("pageNum", pageNum);
jsonObject.put("pageSize", pageSize);
if (StringUtils.isNotBlank(vagueQueryClerk)) {
jsonObject.put("vagueQueryClerk", vagueQueryClerk);
}
if (StringUtils.isNotBlank(vagueQueryUser)) {
jsonObject.put("vagueQueryUser", vagueQueryUser);
}
if (StringUtils.isNotBlank(isDelete)) {
jsonObject.put("isDelete", isDelete);
}
if (StringUtils.isNotBlank(deleteType)) {
jsonObject.put("deleteType", deleteType);
}
}
}
package com.gic.haoban.manage.web.qo.wechatwork;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.Data;
import java.io.Serializable;
/**
* @Author guojx
* @Date 2024/5/21 14:12
*/
@Data
@JsonIgnoreProperties(ignoreUnknown = true)
public class WechatWorkLostOverviewQO implements Serializable {
/**
* yyyy-MM-dd
*/
private String startDate;
/**
* yyyy-MM-dd
*/
private String endDate;
/**
* 分组ID,支持多选,英文逗号隔开
*/
private String storeGroupId;
}
package com.gic.haoban.manage.web.qo.wechatwork;
import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;
import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;
/**
* @Author guojx
* @Date 2024/5/22 9:27
*/
@Data
@JsonIgnoreProperties(ignoreUnknown = true)
public class WechatWorkLostStoreGroupQO extends StoreGroupCommonQO implements Serializable {
/**
* 开始日期, 非日类型的时候。根据数据组api文档
*/
private String startDate;
/**
* 结束日期, 非日类型的时候。根据数据组api文档
*/
private String endDate;
/**
* 排序类型 1 正序 2 倒序
*/
private Integer orderByType;
/**
* 排序字段名称
*/
private String orderByFields;
private Integer pageNum;
private Integer pageSize;
/**
* 下载导出参数:数据脱敏 1:脱敏 2:完整
*/
private Integer dataType = 1;
/**
* 下载导出参数:为了兼容前端传参
*/
private String requestProject;
public Integer getDataApiOrderField() {
Map<String, Integer> map = new HashMap<>(8);
map.put("onewayFriendNum", 1);
map.put("totalLostNum", 2);
map.put("deleteSalesNum", 3);
map.put("salesDeleteNum", 4);
return map.get(orderByFields) == null ? 1 : map.get(orderByFields);
}
public void dealWithParam(JSONObject jsonObject) {
if (jsonObject == null) {
jsonObject = new JSONObject();
}
if (StringUtils.isNotBlank(startDate)) {
jsonObject.put("startDate", startDate);
}
if (StringUtils.isNotBlank(endDate)) {
jsonObject.put("endDate", endDate);
}
if (orderByType != null) {
jsonObject.put("orderByType", orderByType);
}
if (orderByFields != null) {
jsonObject.put("orderByFields", getDataApiOrderField());
}
jsonObject.put("pageNum", pageNum);
jsonObject.put("pageSize", pageSize);
}
}
package com.gic.haoban.manage.web.utils;
import com.gic.clerk.api.dto.AuthorizedUser;
import com.gic.haoban.base.api.common.pojo.dto.WebLoginDTO;
import com.gic.haoban.common.utils.AuthWebRequestUtil;
/**
* @Author guojx
* @Date 2024/5/30 10:59
*/
public class AuthorizedUserUtils {
public static AuthorizedUser getUserInfo() {
WebLoginDTO loginUser = AuthWebRequestUtil.getLoginUser();
AuthorizedUser user = new AuthorizedUser();
user.setUserId(loginUser.getClerkId());
user.setEnterpriseId(loginUser.getEnterpriseId());
user.setRealName(loginUser.getClerkName());
return user;
}
}
package com.gic.haoban.manage.web.utils.data;
import com.alibaba.fastjson.JSONObject;
import com.gic.dubbo.entity.ProviderLocalTag;
import com.gic.web.common.utils.ExecutorPoolSingleton;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.Future;
/**
* @Author guojx
* @Date 2024/1/12 13:41
*/
@Slf4j
public class ConcurrencyUtils {
public static Map<String, List<JSONObject>> concurrencyDataForMap(List<MapThreadHandlerRequest> list) {
Map<String, List<JSONObject>> resultMap = new HashMap<>();
if (CollectionUtils.isEmpty(list)) {
return resultMap;
}
ProviderLocalTag providerLocalTag = ProviderLocalTag.tag.get();
String traceId = providerLocalTag.traceId;
for (MapThreadHandlerRequest temp : list) {
temp.setTraceId(traceId);
}
long startTime = System.currentTimeMillis();
try {
List<Future<Map<String, List<JSONObject>>>> futures2 = ExecutorPoolSingleton.getInstance().getExecutorService().invokeAll(list);
log.info("调用API耗时 : " + (System.currentTimeMillis() - startTime));
for (Future<Map<String, List<JSONObject>>> future : futures2) {
try {
Map<String, List<JSONObject>> map = future.get();
if (map != null) {
map.forEach((k, v) -> {
resultMap.put(k, v);
});
}
} catch (Exception e) {
log.warn("remote Api failed : {}", e.getCause().getMessage());
}
}
long endTime = System.currentTimeMillis();
log.info("耗时 : " + (endTime - startTime));
} catch (Exception e) {
log.warn("并发调用错误:{}", e.getMessage(), e);
}
return resultMap;
}
public static List<JSONObject> concurrencyData(List<ThreadHandlerRequest> list) {
List<JSONObject> resultList = new ArrayList<>();
if (CollectionUtils.isEmpty(list)) {
return resultList;
}
List<MapThreadHandlerRequest> mapParam = new ArrayList<>();
for (int i = 0, len = list.size(); i < len; i++) {
MapThreadHandlerRequest res = new MapThreadHandlerRequest(list.get(i).getJsonObject(),
list.get(i).getApolloKey(), "data" + i);
mapParam.add(res);
}
Map<String, List<JSONObject>> map = concurrencyDataForMap(mapParam);
if (map != null) {
map.forEach((k, v) -> {
if (CollectionUtils.isNotEmpty(v)) {
resultList.addAll(v);
}
});
}
return resultList;
}
}
package com.gic.haoban.manage.web.utils.data;
import com.alibaba.fastjson.JSONObject;
import com.gic.commons.exception.DataApiException;
import com.gic.commons.util.DataApiUtils;
import com.gic.dubbo.entity.ProviderLocalTag;
import lombok.extern.slf4j.Slf4j;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.Callable;
/**
* @Author guojx
* @Date 2024/1/11 15:33
*/
@Slf4j
public class MapThreadHandlerRequest implements Callable<Map<String, List<JSONObject>>> {
private JSONObject jsonObject;
private String apolloKey;
private String webObjName;
private String traceId;
public MapThreadHandlerRequest(JSONObject jsonObject, String apolloKey, String webObjName) {
this.jsonObject = JSONObject.parseObject(jsonObject.toJSONString());
this.apolloKey = apolloKey;
this.webObjName = webObjName;
}
@Override
public Map<String, List<JSONObject>> call() throws Exception {
try {
//log.info("并发调用入口:{}-{}", apolloKey, webObjName);
ProviderLocalTag providerLocalTag = ProviderLocalTag.tag.get();
providerLocalTag.traceId = traceId;
Map<String, Object> res = DataApiUtils.http(jsonObject.toJSONString(), apolloKey);
List<JSONObject> list = DataApiUtils.getDataList(res);
Map<String, List<JSONObject>> map = new HashMap<>(2);
map.put(webObjName, list);
return map;
} catch (DataApiException e) {
// if (DataApiException.OVER_HANDLE_ERROR.equals(e.getCode())) {
// throw new DataApiException(e.getCode(), e.getMessage());
// }
log.info("{}调用错误:{}", apolloKey, e.getMessage(), e);
} catch (Exception e) {
log.info("{}调用错误:{}", apolloKey, e.getMessage(), e);
}
return null;
}
public String getTraceId() {
return traceId;
}
public MapThreadHandlerRequest setTraceId(String traceId) {
this.traceId = traceId;
return this;
}
}
package com.gic.haoban.manage.web.utils.data;
import com.alibaba.fastjson.JSONObject;
import com.gic.api.base.commons.Page;
import com.gic.commons.util.DataApiUtils;
import com.gic.enterprise.api.dto.StoreDTO;
import com.gic.enterprise.api.dto.StoreGroupDTO;
import com.gic.enterprise.api.dto.StoreSearchDTO;
import com.gic.enterprise.api.service.StoreGroupService;
import com.gic.enterprise.api.service.StoreService;
import com.gic.haoban.base.api.common.pojo.dto.WebLoginDTO;
import com.gic.haoban.common.utils.AuthWebRequestUtil;
import com.gic.haoban.manage.api.service.StaffApiService;
import com.gic.haoban.manage.web.qo.wechatwork.StoreGroupCommonQO;
import com.gic.haoban.manage.web.vo.wechatwork.DataPageVO;
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.Component;
import java.util.*;
import java.util.stream.Collectors;
/**
* @Author guojx
* @Date 2024/5/22 9:44
*/
@Component
@Slf4j
public class StoreAuthUtils {
@Autowired
private StoreGroupService storeGroupService;
@Autowired
private StaffApiService staffApiService;
@Autowired
private StoreService storeService;
private static final String NO_EXIST_STORE_ID = "no_exist_store_id";
public void setCommonParam(JSONObject jsonObject, StoreGroupCommonQO storeCommonQO) {
List<String> storeIds = getAuthStoreId(storeCommonQO);
if (CollectionUtils.isNotEmpty(storeIds)) {
jsonObject.put("storeId", storeIds);
}
WebLoginDTO login = AuthWebRequestUtil.getLoginUser();
jsonObject.put("enterpriseId", login.getEnterpriseId());
jsonObject.put("wxEnterpriseId", login.getWxEnterpriseId());
}
public List<String> getAuthStoreId(StoreGroupCommonQO storeCommonQO) {
String storeGroupId = storeCommonQO.getStoreGroupId();
String storeSearchParam = storeCommonQO.getStoreSearchParam();
String storeId = storeCommonQO.getStoreId();
List<String> storeIdList = new ArrayList<>();
List<String> statusList = getAllStoreStatus();
if (StringUtils.isNotBlank(storeId)) {
storeIdList.addAll(Arrays.stream(storeId.split(",")).collect(Collectors.toList()));
}
String nextStoreGroupId = storeCommonQO.getNextStoreGroupId();
String preStoreGroupId = storeCommonQO.getPreStoreGroupId();
boolean isSelectStore = storeCommonQO.isSelectStore();
WebLoginDTO login = AuthWebRequestUtil.getLoginUser();
List<String> roleStoreIds = staffApiService.getHaoBanStoreIdsRolesByClerkId(login.getClerkId(), login.getWxEnterpriseId());
if (CollectionUtils.isEmpty(roleStoreIds)) {
log.info("登录人无门店权限");
return getNoExistStore();
}
List<String> groupIds = null;
List<String> storeGroupIds = new ArrayList<>();
if(StringUtils.isNotBlank(storeGroupId) || StringUtils.isNotBlank(nextStoreGroupId)) {
if (StringUtils.isNotBlank(storeGroupId)) {
storeGroupIds = Arrays.stream(storeGroupId.split(",")).collect(Collectors.toList());
} else if (StringUtils.isNotBlank(nextStoreGroupId)) {
if (storeCommonQO.isNoBelongStoreGroup()) {
storeIdList.addAll(getPreStoreIdList(preStoreGroupId, login.getEnterpriseId()));
} else if (storeCommonQO.isRecycle()) {
statusList.clear();
statusList.add("-3");
} else {
storeGroupIds.add(nextStoreGroupId);
}
}
if (CollectionUtils.isNotEmpty(storeGroupIds)) {
groupIds = storeGroupService.getStoreGroupIdsByParentGroupId(login.getEnterpriseId(), storeGroupIds);
}
}
List<String> searchStoreIdList = getStore(login.getEnterpriseId(), login.getClerkId(), storeSearchParam, groupIds, statusList, storeIdList);
if (isAllAuth(roleStoreIds)) {
return searchStoreIdList;
}
//交集
roleStoreIds.retainAll(searchStoreIdList);
if (CollectionUtils.isEmpty(roleStoreIds)) {
return getNoExistStore();
}
return roleStoreIds;
}
public void setStoreGroupJsonParam(JSONObject jsonObject, StoreGroupCommonQO qo) {
WebLoginDTO login = AuthWebRequestUtil.getLoginUser();
jsonObject.put("enterpriseId", login.getEnterpriseId());
Integer storeGroup = getStoreGroupLevel(qo);
jsonObject.put("storeGroup", storeGroup);
List<String> storeIds = getAuthStoreId(qo);
if (CollectionUtils.isNotEmpty(storeIds)) {
jsonObject.put("storeId", storeIds);
}
}
public boolean needRecycleStoreWhenAllStoreGroup(String enterpriseId, StoreGroupCommonQO qo) {
if (qo.isSelectStore()) {
return true;
}
return StringUtils.isBlank(qo.getStoreGroupId()) || qo.getStoreGroupId().contains(initGroupId(enterpriseId)) || qo.isRecycle();
}
public int getStoreGroupLevel(StoreGroupCommonQO qo) {
if (qo.isSelectStore()) {
return 7;
}
WebLoginDTO login = AuthWebRequestUtil.getLoginUser();
String enterpriseId = login.getEnterpriseId();
String storeGroupId = qo.getStoreGroupId();
if (StringUtils.isNotBlank(storeGroupId)) {
List<StoreGroupDTO> list = storeGroupService
.listStoreGroup(Arrays.stream(storeGroupId.split(",")).toArray(String[]::new), enterpriseId);
int min = list.stream().map(e -> e.getGroupLevel()).min(Integer::compareTo).get();
return min == 0 ? 1 : min;
}
//1:分组1,2:分组2,3:分组3,4:分组4,5:分组5,6:分组6,7:门店,8:区经)
String nextStoreGroupId = qo.getNextStoreGroupId();
if (StringUtils.isNotBlank(nextStoreGroupId)) {
if (qo.isNoBelongStoreGroup() || "-3".equals(nextStoreGroupId)) {
//无归属门店
return 7;
}
//如果是叶子结点的分组,下面没有层级了,就展示门店
List<StoreGroupDTO> childList = storeGroupService.getStoreGroupList(enterpriseId, null, nextStoreGroupId);
if (CollectionUtils.isEmpty(childList)) {
return 7;
}
StoreGroupDTO storeGroupDTO = storeGroupService.getStoreGroupById(nextStoreGroupId);
return storeGroupDTO.getGroupLevel() + 1;
}
//如果是门店筛选,则直接显示门店
if (StringUtils.isNotBlank(qo.getStoreId())) {
return 7;
}
return 1;
}
public DataPageVO getDataCommon(String searchDataParams, Integer currentPage, String logStr, Integer pageSize, boolean hasCountPerPage) {
boolean isFirst = currentPage != null && currentPage == 1;
if (isFirst) {
log.info(logStr);
}
DataPageVO vo = new DataPageVO();
vo.setPageNum(currentPage);
vo.setPageSize(pageSize);
JSONObject jsonObject = JSONObject.parseObject(searchDataParams);
Integer storeGroup = jsonObject.getInteger("storeGroup");
boolean isStore = storeGroup != null && storeGroup == 7;
jsonObject.put("pageNum", currentPage);
jsonObject.put("pageSize", pageSize);
String apolloKey = jsonObject.getString("apolloKey");
String allApolloKey = jsonObject.getString("allApolloKey");
Map<String, Object> res = DataApiUtils.http(jsonObject.toJSONString(), apolloKey);
Page page = DataApiUtils.getPageData(res);
List<JSONObject> list = DataApiUtils.getPageList(res);
Integer totalCount = page.getTotalCount();
vo.setTotalNum(totalCount);
//调用一次合计
if (hasCountPerPage || (isFirst && CollectionUtils.isNotEmpty(list))) {
if (hasCountPerPage && CollectionUtils.isEmpty(list)) {
list = new ArrayList<>();
}
jsonObject.put("pageNum", 1);
jsonObject.put("storeGroup", 8);
String totalApolloKey = apolloKey;
if (StringUtils.isNotBlank(allApolloKey)) {
totalApolloKey = allApolloKey;
}
JSONObject total = getTotalJson(jsonObject, totalApolloKey);
if (total == null) {
total = new JSONObject();
}
if (isStore) {
total.put("storeName", "合计(" + totalCount + ")");
} else {
total.put("storeGroupName", "合计(" + totalCount + ")");
}
total.put("storeGroupId", "all");
list.add(0, total);
}
vo.setRows(list);
return vo;
}
/**
* 删除合计的那条数据
* @param vo
*/
public void deleteTotalData(DataPageVO vo) {
deleteTotalData(vo.getRows());
}
public List<JSONObject> deleteTotalData(List<JSONObject> list) {
if (CollectionUtils.isNotEmpty(list)) {
if (list.size() == 1 && "all".equals(list.get(0).getString("storeGroupId"))) {
return Collections.EMPTY_LIST;
} else {
//删除合计的那条数据
list.remove(0);
}
}
return list;
}
private List<String> getStore(String enterpriseId, String userId, String search, List<String> storeGroupIdList, List<String> status, List<String> storeIdList) {
StoreSearchDTO storeSearchDTO = new StoreSearchDTO();
storeSearchDTO.setEnterpriseId(enterpriseId);
if (StringUtils.isNotBlank(search)) {
storeSearchDTO.setSearchName(search);
}
if (CollectionUtils.isNotEmpty(status)) {
storeSearchDTO.setStatusAnyIn(status);
if (status.contains("-3")) {
storeSearchDTO.setStatusIn("-3");
}
}
if (CollectionUtils.isNotEmpty(storeIdList)) {
storeSearchDTO.setStoreIdList(storeIdList);
}
storeSearchDTO.setUserId(userId);
if (CollectionUtils.isNotEmpty(storeGroupIdList)) {
storeSearchDTO.setStoreGroupIdList(storeGroupIdList);
}
Page pageStore = new Page<>();
//-1代表不分页
pageStore.setCurrentPage(-1);
Page resultPage = storeService.storeListPage(pageStore, storeSearchDTO);
List<StoreDTO> storeDTOList = resultPage.getResult();
if (CollectionUtils.isEmpty(storeDTOList)) {
return getNoExistStore();
}
return storeDTOList.stream().map(e -> e.getStoreId()).collect(Collectors.toList());
}
public List<String> getPreStoreIdList(String preStoreGroupId, String enterpriseId) {
preStoreGroupId = getPreStoreGroupId(preStoreGroupId, enterpriseId);
String[] queryArr = new String[]{preStoreGroupId};
List<String> storeIdList = storeService.getStoreIdListByGroupId(queryArr,
getAllStoreStatus().stream().mapToInt(e -> Integer.parseInt(e)).boxed().collect(Collectors.toList()));
if (CollectionUtils.isEmpty(storeIdList)) {
storeIdList.add(NO_EXIST_STORE_ID);
}
return storeIdList;
}
private String getPreStoreGroupId(String preStoreGroupId, String enterpriseId) {
if (isAllStoreGroup(preStoreGroupId)) {
return initGroupId(enterpriseId);
}
return preStoreGroupId;
}
private static boolean isAllStoreGroup(String preStoreGroupId) {
if (StringUtils.isBlank(preStoreGroupId) || "preStoreGroupId".equals(preStoreGroupId)) {
return true;
}
return false;
}
private static boolean isAllAuth(List<String> roleStoreIds) {
return roleStoreIds.size() == 1 && "-1".equals(roleStoreIds.get(0));
}
public String initGroupId(String enterpriseId) {
List<StoreGroupDTO> groups = storeGroupService.getStoreGroupList(enterpriseId, null, "0");
if (groups != null && groups.size() > 0 && groups.get(0) != null) {
return groups.get(0).getStoreGroupId();
} else {
return null;
}
}
private static List<String> getAllStoreStatus() {
List<String> list = new ArrayList<>();
list.add("2");
list.add("3");
list.add("4");
list.add("6");
list.add("7");
//好办不要回收站
//list.add("-3");
return list;
}
private static List<String> getNoExistStore() {
List<String> list = new ArrayList<>(1);
list.add(NO_EXIST_STORE_ID);
return list;
}
public 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;
}
}
package com.gic.haoban.manage.web.utils.data;
import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
/**
* @Author guojx
* @Date 2024/1/11 15:33
*/
@Slf4j
public class ThreadHandlerRequest {
private JSONObject jsonObject;
private String apolloKey;
public ThreadHandlerRequest(JSONObject jsonObject, String apolloKey) {
this.jsonObject = JSONObject.parseObject(jsonObject.toJSONString());
this.apolloKey = apolloKey;
}
public JSONObject getJsonObject() {
return jsonObject;
}
public ThreadHandlerRequest setJsonObject(JSONObject jsonObject) {
this.jsonObject = jsonObject;
return this;
}
public String getApolloKey() {
return apolloKey;
}
public ThreadHandlerRequest setApolloKey(String apolloKey) {
this.apolloKey = apolloKey;
return this;
}
}
package com.gic.haoban.manage.web.utils.eventtracking;
import com.alibaba.fastjson.JSONObject;
import com.gic.commons.util.DataApiUtils;
import com.gic.commons.util.DateUtil;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
* @Author guojx
* @Date 2024/5/30 15:34
*/
public class DateExpandUtils {
public static List<String> getDateList(String startDate, String endDate, Integer dateType) {
//数据类型 1天 2近7天 3近30天 4周 5月
List<String> list = new ArrayList<>();
if (dateType == null) {
dateType = 1;
}
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
Calendar calendar = Calendar.getInstance();
try {
switch (dateType) {
case 1:
case 2:
case 3:
calendar.setTime(dateType == 1 ? df.parse(startDate) : df.parse(endDate));
calendar.add(Calendar.DAY_OF_YEAR, -29);
list = DateUtil.getBetweenDates(df.format(calendar.getTime()), dateType == 1 ? startDate : endDate);
break;
case 4:
JSONObject jsonObject = new JSONObject();
jsonObject.put("startDate", startDate);
jsonObject.put("pageNum", 1);
jsonObject.put("pageSize", 100);
Map<String, Object> res = DataApiUtils.http(jsonObject.toJSONString(), "data_pub_date_week");
List<JSONObject> data = DataApiUtils.getPageList(res);
list = data.stream().map(e ->e.getString("weekYear")).collect(Collectors.toList());
break;
case 5:
//月
SimpleDateFormat monthFormat = new SimpleDateFormat("yyyy-MM");
calendar.setTime(df.parse(startDate));
calendar.add(Calendar.MONTH, -11);
for (int i = 1; i <= 12; i++) {
list.add(monthFormat.format(calendar.getTime()));
calendar.add(Calendar.MONTH, 1);
}
break;
default:
}
} catch (Exception e) {
}
return list;
}
}
package com.gic.haoban.manage.web.vo.eventtracking;
import lombok.Data;
import java.io.Serializable;
/**
* @Author guojx
* @Date 2024/5/30 9:24
*/
@Data
public class TrendVO implements Serializable {
/**
* 员工总人数
*/
private Integer clerkNum;
/**
* 绑定人数
*/
private Integer bindingNum;
/**
* 绑定率
*/
private Double bindingRate;
/**
* 活跃人数
*/
private Integer visitNum;
/**
* 活跃率
*/
private Double visitRate;
/**
* 访问次数
*/
private Integer visitCnt;
/**
* 业务日期
*/
private String bizDate;
}
package com.gic.haoban.manage.web.vo.eventtracking;
import lombok.Data;
import java.io.Serializable;
/**
* @Author guojx
* @Date 2024/5/30 9:44
*/
@Data
public class ViewModuleVO implements Serializable {
/**
* 模块code
*/
private String moduleCode;
/**
* 模块名称
*/
private String moduleName;
/**
* 数值
*/
private Long data;
/**
* 1:访问次数 2:访问人数 3:访问时长 (单位秒)
*/
private Integer dataType;
}
package com.gic.haoban.manage.web.vo.eventtracking;
import com.gic.haoban.manage.web.vo.wechatwork.StoreGroupCommonVO;
import lombok.Data;
import java.io.Serializable;
/**
* @Author guojx
* @Date 2024/5/21 15:56
*/
@Data
public class WechatEventTrackingClerkVO extends StoreGroupCommonVO implements Serializable {
/**
* 1访问时长 单位秒
*/
private Long avgVisitTime;
/**
* 访问时长 00:00:00格式
*/
private String visitTimeStr;
/**
* 2最后一次登陆时间
*/
private String lastVisitTime;
/**
* 是否绑定
*/
private String isBinding;
/**
* 是否登陆
*/
private String isLogin;
/**
* 登陆次数
*/
private Integer visitCnt;
/**
* 导购id
*/
private String clerkId;
private String clerkName;
private String clerkCode;
public String getVisitTimeStr() {
if (avgVisitTime != null) {
int hour = (int) (avgVisitTime / 3600);
String str = getTimeStr(hour);
if (hour > 0) {
avgVisitTime = avgVisitTime - (3600 * hour);
}
int minute = (int) (avgVisitTime / 60);
str = str + ":" + getTimeStr(minute);
if (minute > 0) {
avgVisitTime = avgVisitTime - (60 * minute);
}
str = str +":"+ getTimeStr(avgVisitTime.shortValue());
return str;
}
return visitTimeStr;
}
private static String getTimeStr(int time) {
String str = "";
if (time == 0) {
str = "00";
} else if (time < 10) {
str = "0" + time + "";
} else {
str = "" + time;
}
return str;
}
}
package com.gic.haoban.manage.web.vo.eventtracking;
import com.gic.haoban.manage.web.vo.wechatwork.StoreGroupCommonVO;
import lombok.Data;
import java.io.Serializable;
/**
* @Author guojx
* @Date 2024/5/21 15:56
*/
@Data
public class WechatEventTrackingStoreGroupVO extends StoreGroupCommonVO implements Serializable {
/**
* 1员工总人数
*/
private Integer clerkNum;
/**
* 2绑定人数
*/
private Integer bindingNum;
/**
* 3绑定率
*/
private Double bindingRate;
/**
* 4活跃人数
*/
private Integer visitNum;
/**
* 5活跃率
*/
private Double visitRate;
/**
* 6访问次数
*/
private Integer visitCnt;
}
package com.gic.haoban.manage.web.vo.wechatwork;
import lombok.Data;
import java.io.Serializable;
import java.util.List;
/**
* @Author guojx
* @Date 2024/1/11 14:22
*/
@Data
public class DataPageVO<T> implements Serializable {
private Integer pageNum;
private Integer pageSize;
private List<T> rows;
private Integer totalNum;
}
package com.gic.haoban.manage.web.vo.wechatwork;
import lombok.Data;
import java.io.Serializable;
/**
* @Author guojx
* @Date 2024/5/22 9:35
*/
@Data
public class StoreGroupCommonVO implements Serializable {
private String storeGroupId;
private String storeGroupName;
private String storeId;
private String storeName;
private String storeCode;
private String parentStoreGroupName;
}
package com.gic.haoban.manage.web.vo.wechatwork;
import lombok.Data;
import java.io.Serializable;
/**
* @Author guojx
* @Date 2024/5/21 15:56
*/
@Data
public class WechatWorkLostClerkVO extends StoreGroupCommonVO implements Serializable {
/**
* 单向好友人数
*/
private Integer onewayFriendNum;
/**
* 总流失人数
*/
private Integer totalLostNum;
/**
* 删除导购人数
*/
private Integer deleteSalesNum;
/**
* 导购删除好友人数
*/
private Integer salesDeleteNum;
private String clerkCode;
private String clerkName;
private String clerkId;
}
package com.gic.haoban.manage.web.vo.wechatwork;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.gic.web.common.jsonSeralizer.PhoneNumberJsonSeralizer;
import com.gic.web.common.jsonSeralizer.UserNameJsonSeralizer;
import lombok.Data;
import java.io.Serializable;
/**
* @Author guojx
* @Date 2024/5/21 15:56
*/
@Data
public class WechatWorkLostDetailVO extends StoreGroupCommonVO implements Serializable {
/**
* 删除类型
*/
private String deleteType;
/**
* 留存天数
*/
private Integer remainDays;
/**
* 是否已经解除双向好友
*/
private String isDelete;
/**
* 添加好友时间
*/
private String addTime;
/**
* 最近消费时间
*/
private String lastCsmeDate;
/**
* 删除时间
*/
private String deleteTime;
private String clerkCode;
private String clerkName;
private String clerkId;
/**
* 客户姓名
*/
@JsonSerialize(using = UserNameJsonSeralizer.class)
private String memberName;
/**
* 客户手机号
*/
@JsonSerialize(using = PhoneNumberJsonSeralizer.class)
private String memberPhone;
/**
* 会员昵称
*/
private String memberNick;
/**
* 会员id -1:不存在
*/
private String memberId;
private String staffCode;
private String staffName;
}
package com.gic.haoban.manage.web.vo.wechatwork;
import lombok.Data;
import java.io.Serializable;
/**
* @Author guojx
* @Date 2024/5/21 15:56
*/
@Data
public class WechatWorkLostStoreGroupVO extends StoreGroupCommonVO implements Serializable {
/**
* 单向好友人数
*/
private Integer onewayFriendNum;
/**
* 总流失人数
*/
private Integer totalLostNum;
/**
* 删除导购人数
*/
private Integer deleteSalesNum;
/**
* 导购删除好友人数
*/
private Integer salesDeleteNum;
}
package com.gic.haoban.manage.web.vo.wechatwork;
import lombok.Data;
import java.io.Serializable;
/**
* @Author guojx
* @Date 2024/5/21 15:56
*/
@Data
public class WechatWorkLostVO implements Serializable {
/**
* 单向好友数
*/
private Integer onewayFriendNum = 0;
/**
* 总流失人数
*/
private Integer totalLostNum = 0;
/**
* 删除导购人数
*/
private Integer deleteSalesNum = 0;
/**
* 导购删除好友人数
*/
private Integer salesDeleteNum = 0;
/**
*
*/
private String bizDate;
}
......@@ -11,7 +11,7 @@
http://www.springframework.org/schema/aop/spring-aop.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
<!-- 扫描注解包路径,多个包用逗号分隔,不填pacakge表示扫描当前ApplicationContext中所有的类 -->
<context:component-scan base-package="com.gic.haoban.*" />
<context:component-scan base-package="com.gic.haoban.*, com.gic.web.common.*" />
<!-- 启动对@AspectJ注解的支持 -->
<aop:aspectj-autoproxy />
......
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