Commit 115ccbdf by xiongjiangtao

Merge remote-tracking branch 'origin/feature-2024-08-喜好洞察优化' into feature-2024-08-喜好洞察优化

parents b61a1803 5250e36d
package com.gic.haoban.manage.web.controller.data;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.gic.api.base.commons.Page;
import com.gic.clerk.api.dto.ClerkListDTO;
import com.gic.clerk.api.service.ClerkService;
import com.gic.commons.util.DataApiUtils;
import com.gic.commons.webapi.reponse.RestResponse;
import com.gic.haoban.manage.api.service.StaffApiService;
import com.gic.haoban.manage.web.qo.data.goodsanalysis.GoodsAnalysisClerkDetailQO;
import com.gic.haoban.manage.web.qo.data.goodsanalysis.GoodsAnalysisOverviewQO;
import com.gic.haoban.manage.web.utils.StoreAuthUtils;
import com.gic.haoban.manage.web.vo.data.ClerkDateTrendVO;
import com.gic.haoban.manage.web.vo.data.ClerkUseDetailVO;
import com.gic.haoban.manage.web.vo.data.GoodsAnalysisDateTrendVO;
import com.gic.haoban.manage.web.vo.data.GoodsAnalysisOverviewVO;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
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.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
* 看数据-商品洞察
*/
@Controller
@RequestMapping("data-goods-analysis")
@Slf4j
public class GoodsAnalysisController {
@Autowired
private StaffApiService staffApiService;
@Autowired
private StoreAuthUtils storeAuthUtils;
@Autowired
private ClerkService clerkService;
/**
* 商品洞察看板(店长、区经)
* @param qo
* @return
*/
@RequestMapping(value = "get-overview-of-manager")
@ResponseBody
public RestResponse<GoodsAnalysisOverviewVO> getOverviewOfManager(@RequestBody GoodsAnalysisOverviewQO qo) {
// boolean isManager = staffApiService.isManager(qo.getClerkId());
JSONObject jsonObject = (JSONObject) JSONObject.toJSON(qo);
jsonObject.put("days", storeAuthUtils.getDays(qo.getStartDate(), qo.getEndDate()));
return RestResponse.successResult(storeAuthUtils.getPageOverview(jsonObject, "data_pro_pref_ent_overview", GoodsAnalysisOverviewVO.class));
}
/**
* 导购明细(店长、区经)
* @param qo
* @return
*/
@RequestMapping(value = "get-clerk-detail-of-manager")
@ResponseBody
public RestResponse<Page<ClerkUseDetailVO>> getClerkDetailOfManager(@RequestBody GoodsAnalysisClerkDetailQO qo) {
boolean isFirstPage = qo.getPageNum() == 1;
List<ClerkListDTO> clerkList = clerkService.getClerkByStoreIdOfAllStatus(qo.getStoreId(), qo.getStoreId());
List<String> deleteList = new ArrayList<>();
List<String> normalList = new ArrayList<>();
List<String> allList = new ArrayList<>();
if (CollectionUtils.isNotEmpty(clerkList)) {
for (ClerkListDTO dto : clerkList) {
Integer status = dto.getStatus();
allList.add(dto.getClerkId());
if (status != null && status == 0) {
deleteList.add(dto.getClerkId());
} else {
normalList.add(dto.getClerkId());
}
}
}
if (CollectionUtils.isEmpty(deleteList)) {
deleteList.add("no_delete_clerk_id");
}
if (CollectionUtils.isEmpty(normalList)) {
normalList.add("no_normal_clerk_id");
}
if (CollectionUtils.isEmpty(allList)) {
allList.add("no_clerk_id");
}
JSONObject jsonObject = (JSONObject) JSONObject.toJSON(qo);
jsonObject.put("clerkId", normalList.stream().collect(Collectors.joining(",")));
//8:合计 非8:列表
jsonObject.put("storeGroup", "1");
Map<String, Object> res = DataApiUtils.http(jsonObject.toJSONString(), "data_pro_pref_clerk_use_detail");
Page page = DataApiUtils.getPageData(res);
List<JSONObject> pageList = page.getResult();
if (pageList == null) {
pageList = new ArrayList<>();
}
if (isFirstPage) {
jsonObject.put("clerkId", allList.stream().collect(Collectors.joining(",")));
JSONObject allTotal = storeAuthUtils.getTotalJson(jsonObject, "data_pro_pref_clerk_use_detail");
if (allTotal != null) {
allTotal.put("clerkName", "门店");
pageList.add(0, allTotal);
}
}
int totalPage = page.getTotalCount() % page.getPageSize() != 0 ? page.getTotalCount() / page.getPageSize() + 1 : page.getTotalCount() / page.getPageSize();
boolean isLastPage = totalPage == qo.getPageNum();
if (isLastPage) {
// 最后一页添加离职导购数据
jsonObject.put("clerkId", deleteList.stream().collect(Collectors.joining(",")));
JSONObject deleteTotal = storeAuthUtils.getTotalJson(jsonObject, "data_pro_pref_clerk_use_detail");
if (deleteTotal != null) {
deleteTotal.put("clerkName", "离职导购(汇总)");
pageList.add(deleteTotal);
}
}
page.setResult(JSONArray.parseArray(JSON.toJSONString(pageList), ClerkUseDetailVO.class));
return RestResponse.successResult(page);
}
/**
* 时间趋势(店长)
* @param qo
* @return
*/
@RequestMapping(value = "get-date-trend-of-manager")
@ResponseBody
public RestResponse<Page<GoodsAnalysisDateTrendVO>> getDateTrendOfManager(@RequestBody GoodsAnalysisClerkDetailQO qo) {
JSONObject jsonObject = (JSONObject) JSONObject.toJSON(qo);
Map<String, Object> res = DataApiUtils.http(jsonObject.toJSONString(), "data_pro_pref_ent_date_overview");
Page page = DataApiUtils.getPageData(res);
List<JSONObject> pageList = page.getResult();
page.setResult(JSONArray.parseArray(JSON.toJSONString(pageList), GoodsAnalysisDateTrendVO.class));
return RestResponse.successResult(page);
}
/**
* 导购商品看板
* @param qo
* @return
*/
@RequestMapping(value = "get-overview-of-clerk")
@ResponseBody
public RestResponse<ClerkUseDetailVO> getOverviewOfClerk(@RequestBody GoodsAnalysisOverviewQO qo) {
JSONObject jsonObject = (JSONObject) JSONObject.toJSON(qo);
jsonObject.put("clerkId", qo.getClerkId());
jsonObject.put("storeGroup", "1");
return RestResponse.successResult(storeAuthUtils.getPageOverview(jsonObject, "data_pro_pref_clerk_use_detail", ClerkUseDetailVO.class));
}
/**
* 导购趋势
* @param qo
* @return
*/
@RequestMapping(value = "get-date-trend-of-clerk")
@ResponseBody
public RestResponse<Page<ClerkDateTrendVO>> getDateTrendOfClerk(@RequestBody GoodsAnalysisClerkDetailQO qo) {
JSONObject jsonObject = (JSONObject) JSONObject.toJSON(qo);
Map<String, Object> res = DataApiUtils.http(jsonObject.toJSONString(), "data_pro_pref_clerk_date_overview");
Page page = DataApiUtils.getPageData(res);
List<JSONObject> pageList = page.getResult();
page.setResult(JSONArray.parseArray(JSON.toJSONString(pageList), ClerkDateTrendVO.class));
return RestResponse.successResult(page);
}
}
package com.gic.haoban.manage.web.qo.data.goodsanalysis;
import com.alibaba.fastjson.annotation.JSONField;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.Data;
import java.io.Serializable;
@Data
@JsonIgnoreProperties(ignoreUnknown = true)
public class GoodsAnalysisClerkDetailQO implements Serializable {
/**
* 排序字段
*/
private Integer orderByFields;
/**
* 排序类型 1升序 2降序
*/
private Integer orderByType;
private String startDate;
private String endDate;
private Integer pageNum;
private Integer pageSize;
private String storeId;
@JSONField(serialize = false)
private String clerkId;
private String enterpriseId;
public Integer getPageNum() {
return pageNum == null ? 1 : pageNum;
}
public Integer getPageSize() {
return pageSize == null ? 10 : pageSize;
}
public Integer getOrderByFields() {
//12转化金额
return orderByFields == null ? 12 : orderByFields;
}
public Integer getOrderByType() {
return orderByType == null ? 2 : orderByType;
}
}
package com.gic.haoban.manage.web.qo.data.goodsanalysis;
import com.alibaba.fastjson.annotation.JSONField;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.Data;
import java.io.Serializable;
@Data
@JsonIgnoreProperties(ignoreUnknown = true)
public class GoodsAnalysisOverviewQO implements Serializable {
private String storeId;
/**
*
*/
@JSONField(serialize = false)
private String clerkId;
private String startDate;
private String endDate;
private String enterpriseId;
}
package com.gic.haoban.manage.web.utils; package com.gic.haoban.manage.web.utils;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.gic.commons.util.DataApiUtils;
import com.gic.commons.util.DateUtil;
import com.gic.haoban.manage.api.service.StaffApiService; import com.gic.haoban.manage.api.service.StaffApiService;
import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
...@@ -8,8 +13,10 @@ import org.slf4j.LoggerFactory; ...@@ -8,8 +13,10 @@ import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.text.SimpleDateFormat;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Map;
/** /**
* @Author guojx * @Author guojx
...@@ -22,6 +29,16 @@ public class StoreAuthUtils { ...@@ -22,6 +29,16 @@ public class StoreAuthUtils {
@Autowired @Autowired
private StaffApiService staffApiService; private StaffApiService staffApiService;
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;
}
/** /**
* 查询区经角色下管辖的门店权限 * 查询区经角色下管辖的门店权限
* @param clerkId * @param clerkId
...@@ -41,4 +58,43 @@ public class StoreAuthUtils { ...@@ -41,4 +58,43 @@ public class StoreAuthUtils {
} }
return storeIds; return storeIds;
} }
public <T> T getPageOverview(JSONObject jsonParam, String apolloKey, Class clazz) {
List<T> list = getPageTrend(jsonParam, apolloKey, clazz, null);
if (list != null) {
return list.get(0);
}
return null;
}
public <T> List<T> getPageTrend(JSONObject jsonParam, String apolloKey, Class clazz, Integer pageSize) {
if (jsonParam == null) {
jsonParam = new JSONObject();
}
jsonParam.put("pageNum", 1);
jsonParam.put("orderByFields", 1);
jsonParam.put("orderByType", 1);
jsonParam.put("pageSize", pageSize == null ? 1 : pageSize);
if (!jsonParam.containsKey("storeGroup")) {
jsonParam.put("storeGroup", 8);
}
Map<String, Object> res = DataApiUtils.http(jsonParam.toJSONString(), apolloKey);
List<JSONObject> list = DataApiUtils.getPageList(res);
if (CollectionUtils.isNotEmpty(list)) {
return (List<T>) JSONArray.parseArray(JSON.toJSONString(list), clazz);
}
return null;
}
public Integer getDays(String startDate, String endDate) {
if (StringUtils.isNotBlank(startDate) && StringUtils.isNotBlank(endDate)) {
try {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
return DateUtil.daysBetween(sdf.parse(startDate), sdf.parse(endDate)) + 1;
} catch (Exception e) {
}
}
return null;
}
} }
package com.gic.haoban.manage.web.vo.data;
import lombok.Data;
import java.io.Serializable;
/**
* @Author guojx
* @Date 2024/6/26 13:36
*/
@Data
public class ClerkDateTrendVO implements Serializable {
/**
* 1人找货次数
*/
private Long perToProCnt;
/**
* 2货找人次数
*/
private Long proToPerCnt;
/**
* 3使用天数
*/
private Long useDay;
/**
* 4推荐商品数量
*/
private Long shareProCnt;
/**
* 5触达客户数
*/
private Long touchNum;
/**
* 6商城转化客户数
*/
private Long onlineConvsNum;
/**
* 7商城转化金额
*/
private Double onlineConvsPayAmt;
/**
* 8线下转化客户数
*/
private Long offlineConvsNum;
/**
* 9线下转化金额
*/
private Double offlineConvsPayAmt;
/**
* 10商城转化商品数
*/
private Long onlineConvsProCnt;
/**
* 11线下转化商品数
*/
private Long offlineConvsProCnt;
/**
* 12转化金额
*/
private Double convsPayAmt;
/**
* 13转化客户数
*/
private Long convsNum;
/**
* 14转化商品数
*/
private Long convsProCnt;
/**
* 15点击客户数
*/
private Double clickNum;
/**
* 16点击率
*/
private Double clickRate;
/**
* 17转化率
*/
private Double convsRate;
/**
*
*/
private String clerkCode;
private String clerkName;
private String storeName;
private String storeCode;
/**
* 日期
*/
private String bizDate;
}
package com.gic.haoban.manage.web.vo.data;
import lombok.Data;
import java.io.Serializable;
/**
* @Author guojx
* @Date 2024/6/26 13:36
*/
@Data
public class ClerkUseDetailVO implements Serializable {
/**
* 1人找货次数
*/
private Long perToProCnt;
/**
* 2货找人次数
*/
private Long proToPerCnt;
/**
* 3使用天数
*/
private Long useDay;
/**
* 4推荐商品数量
*/
private Long shareProCnt;
/**
* 5触达客户数
*/
private Long touchNum;
/**
* 6商城转化客户数
*/
private Long onlineConvsNum;
/**
* 7商城转化金额
*/
private Double onlineConvsPayAmt;
/**
* 8线下转化客户数
*/
private Long offlineConvsNum;
/**
* 9线下转化金额
*/
private Double offlineConvsPayAmt;
/**
* 10商城转化商品数
*/
private Long onlineConvsProCnt;
/**
* 11线下转化商品数
*/
private Long offlineConvsProCnt;
/**
* 12转化金额
*/
private Double convsPayAmt;
/**
* 13转化客户数
*/
private Long convsNum;
/**
* 14转化商品数
*/
private Long convsProCnt;
/**
* 15点击客户数
*/
private Double clickNum;
/**
*
*/
private String clerkCode;
private String clerkName;
private String storeName;
private String storeCode;
}
package com.gic.haoban.manage.web.vo.data;
import lombok.Data;
import java.io.Serializable;
@Data
public class GoodsAnalysisDateTrendVO implements Serializable {
/**
* 1推荐商品数
*/
private Long shareProCnt;
/**
* 2转化商品数
*/
private Long convsProCnt;
/**
* 3转化金额
*/
private Double convsPayAmt;
/**
* 4商城转化商品数
*/
private Long onlineConvsProCnt;
/**
* 5商城转化客户数
*/
private Long onlineConvsNum;
/**
* 6商城转化金额
*/
private Double onlineConvsPayAmt;
/**
* 7线下转化商品数
*/
private Long offlineConvsProCnt;
/**
* 8线下转化客户数
*/
private Long offlineConvsNum;
/**
* 9线下转化金额
*/
private Double offlineConvsPayAmt;
/**
* 10日均访问导购数
*/
private Long avgVisitNum;
/**
* 11日均使用导购数
*/
private Long avgUseNum;
/**
* 12日均使用率
*/
private Double avgUseRate;
/**
* 13触达客户数
*/
private Long touchNum;
/**
* 14点击客户数
*/
private Long clickNum;
/**
* 15点击率
*/
private Double clickRate;
/**
* 16转化客户数
*/
private Long convsNum;
/**
* 17转化率
*/
private Double convsRate;
/**
* 18人找货次数
*/
private Long perToProCnt;
/**
* 20分享商品转化数
*/
private Long proToPerCnt;
/**
* 20分享商品转化数
*/
private Long shareConvsProCnt;
/**
* 日期
*/
private String bizDate;
}
package com.gic.haoban.manage.web.vo.data;
import lombok.Data;
import java.io.Serializable;
/**
* @Author guojx
* @Date 2024/9/02 09:30
*/
@Data
public class GoodsAnalysisOverviewVO implements Serializable {
/**
* 1推荐商品数
*/
private Long shareProCnt;
/**
* 2转化商品数
*/
private Long convsProCnt;
/**
* 3转化金额
*/
private Double convsPayAmt;
/**
* 10日均访问导购数
*/
private Long avgVisitNum;
/**
* 11日均使用导购数
*/
private Long avgUseNum;
/**
* 13触达客户数
*/
private Long touchNum;
/**
* 16转化客户数
*/
private Long convsNum;
}
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