Commit 5ced7b56 by guojx

销售结构接口

parent f757a0b4
...@@ -22,13 +22,11 @@ import com.gic.enterprise.api.service.EnterpriseChannelApiService; ...@@ -22,13 +22,11 @@ import com.gic.enterprise.api.service.EnterpriseChannelApiService;
import com.gic.enterprise.api.service.EnterpriseService; import com.gic.enterprise.api.service.EnterpriseService;
import com.gic.enterprise.api.service.data.DataIndexApiService; import com.gic.enterprise.api.service.data.DataIndexApiService;
import com.gic.enterprise.service.CustomSettingApiService; import com.gic.enterprise.service.CustomSettingApiService;
import com.gic.haoban.manage.web.qo.data.DataIndexExplainVO; import com.gic.haoban.manage.web.qo.data.*;
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.DateFillUtils;
import com.gic.haoban.manage.web.utils.StoreAuthUtils; import com.gic.haoban.manage.web.utils.StoreAuthUtils;
import com.gic.haoban.manage.web.vo.data.DataMemberExtendVO; import com.gic.haoban.manage.web.vo.data.DataMemberExtendVO;
import com.gic.haoban.manage.web.vo.data.SalesStructureVO;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
...@@ -38,6 +36,7 @@ import org.springframework.web.bind.annotation.RequestBody; ...@@ -38,6 +36,7 @@ import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.ResponseBody;
import java.math.BigDecimal;
import java.util.*; import java.util.*;
import java.util.stream.Collectors; import java.util.stream.Collectors;
...@@ -125,6 +124,91 @@ public class DataController { ...@@ -125,6 +124,91 @@ public class DataController {
} }
/** /**
* 销售结构接口
* @param qo
* @return
*/
@RequestMapping(value = "sales-structure")
@ResponseBody
public RestResponse<List<SalesStructureVO>> salesStructure(@RequestBody SalesStructureQO qo) {
Integer salesStructureType = qo.getSalesStructureType();
String apolloKey = "data_sales_perf_mbr_type_overview";
switch (salesStructureType) {
case 1:
apolloKey = "data_sales_perf_mbr_type_overview";
break;
case 2:
apolloKey = "data_sales_perf_birth_type_overview";
break;
case 3:
apolloKey = "data_sales_perf_grade_type_overview";
break;
default:
}
JSONObject jsonParam = new JSONObject();
jsonParam.put("enterpriseId", qo.getEnterpriseId());
getAuthStore(qo.getStoreId(), qo.getClerkId(), qo.getWxEnterpriseId(), jsonParam);
jsonParam.put("groupType", 1);
Map<String, Object> res = DataApiUtils.http(jsonParam.toJSONString(), apolloKey);
List<JSONObject> list = DataApiUtils.getDataList(res);
if (list == null) {
list = new ArrayList<>();
}
jsonParam.put("groupType", 2);
res = DataApiUtils.http(jsonParam.toJSONString(), apolloKey);
List<JSONObject> childList = DataApiUtils.getDataList(res);
if (CollectionUtils.isNotEmpty(childList)) {
list.addAll(childList);
}
List<SalesStructureVO> voList = JSONObject.parseArray(JSON.toJSONString(list), SalesStructureVO.class);
if (voList.size() > 1) {
SalesStructureVO total = voList.get(0);
Double payAmt = total.getPayAmt();
Integer csmeNum = total.getCsmeNum();
Integer effOrderCnt = total.getEffOrderCnt();
for (int i = 1; i < voList.size(); i ++) {
SalesStructureVO vo = voList.get(i);
if (payAmt != null && payAmt > 0) {
vo.setPayAmtRate(divide(vo.getPayAmt(),payAmt));
}
if (csmeNum != null && csmeNum > 0) {
vo.setCsmeNumRate(divide(vo.getCsmeNum(),csmeNum));
}
if (effOrderCnt != null && effOrderCnt > 0) {
vo.setEffOrderCntRate(divide(vo.getEffOrderCnt(),effOrderCnt));
}
}
}
return RestResponse.successResult(voList);
}
public static String divide(Object a, Object b) {
if (a == null) {
return "0.00";
}
BigDecimal bd = new BigDecimal(a.toString());
bd = bd.multiply(new BigDecimal(100));
bd = bd.divide(new BigDecimal(b.toString()));
bd = bd.setScale(2, BigDecimal.ROUND_HALF_UP);
return bd.toString();
}
private void getAuthStore(String storeId, String clerkId, String wxEnterpriseId, JSONObject jsonObject) {
List<String> storeIdList = new ArrayList<>();
if (StringUtils.isBlank(storeId)) {
storeIdList = storeAuthUtils.queryClerkStoreIds(clerkId, wxEnterpriseId);
} else {
storeIdList.add(storeId);
}
if (CollectionUtils.isNotEmpty(storeIdList)) {
//区经有全部门店权限
jsonObject.put("storeId", storeIdList.stream().collect(Collectors.joining(",")));
}
}
/**
* 数据统一调用接口 * 数据统一调用接口
* 参数与返回字段查询数据组的yapi的对应文档 * 参数与返回字段查询数据组的yapi的对应文档
* @param qo * @param qo
......
package com.gic.haoban.manage.web.qo.data;
import lombok.Data;
import java.io.Serializable;
/**
* @Author guojx
* @Date 2023/12/26 14:32
*/
@Data
public class SalesStructureQO implements Serializable {
/**
* 1:新老客维度 2:生日会员 3:等级
*/
private Integer salesStructureType = 1;
/**
* 开始时间
*/
private String startDate;
/**
* 结束时间
*/
private String endDate;
/**
* 门店查询参数. 区经可以为空,查询所有管辖门店
*/
private String storeId;
/**
* 企业ID.
*/
private String enterpriseId;
/**
* 微信企业
*/
private String wxEnterpriseId;
/**
* 如果是区经,用于查询管辖门店权限
*/
private String clerkId;
}
package com.gic.haoban.manage.web.vo.data;
import lombok.Data;
import java.io.Serializable;
/**
* @Author guojx
* @Date 2023/12/26 14:50
*/
@Data
public class SalesStructureVO implements Serializable {
/**
* 1:新老客维度 2:生日会员 3:等级
*/
private Integer salesStructureType = 1;
/**
* 实付金额
*/
private Double payAmt;
/**
* 消费人数
*/
private Integer csmeNum;
/**
* 有效订单数
*/
private Integer effOrderCnt;
/**
* 名称类型
*/
private String mbrType;
/**
* 实付金额占比
*/
private String payAmtRate;
/**
* 消费人数占比
*/
private String csmeNumRate;
/**
* 有效订单数占比
*/
private String effOrderCntRate;
}
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