Commit 06d8e8dc by guojx

目标跟进数据组接口

parent d0f39e56
package com.gic.haoban.manage.web.controller.target;
import com.alibaba.fastjson.JSONObject;
import com.gic.clerk.api.dto.AuthorizedUser;
import com.gic.commons.util.EntityUtil;
import com.gic.commons.web.qo.PageQo;
import com.gic.commons.webapi.reponse.RestResponse;
import com.gic.haoban.manage.web.qo.target.QueryDataStatisticsCommonQO;
import com.gic.haoban.manage.web.utils.StoreAuthUtils;
import com.gic.haoban.manage.web.utils.target.DataTargetHttpUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
* 好办小程序-目标跟进
* @Author guojx
* @Date 2023/1/17 9:51
*/
@Controller
public class TargetController {
@Autowired
private StoreAuthUtils storeAuthUtils;
/**
* 目标跟进达成分析月份数据概览
* @param qo
* @return
*/
@RequestMapping(value = "get-target-attainment-analysis-overview")
@ResponseBody
public RestResponse getTargetAttainmentAnalysisOverview(QueryDataStatisticsCommonQO qo) {
JSONObject jsonObject = getCommon(qo, true);
Map<String, Object> res = DataTargetHttpUtils.http(DataTargetHttpUtils.getParamNoPage(jsonObject).toJSONString(),
qo.getTimeType() == 1 ? "data_mbr_target_attainment_analysis_year_overview" : "data_mbr_target_attainment_analysis_month_overview");
return DataTargetHttpUtils.responseOfOne(res, null);
}
/**
* 目标跟进核心目标达成概况
* @return
*/
@RequestMapping(value = "get-target-reach-overview")
@ResponseBody
public RestResponse getTargetReachOverview(QueryDataStatisticsCommonQO qo) {
JSONObject jsonObject = getCommon(qo, false);
Map<String, Object> res = DataTargetHttpUtils.http(DataTargetHttpUtils.getParamNoPage(jsonObject).toJSONString(),
"data_mbr_target_reach_overview");
return DataTargetHttpUtils.responseOfOne(res, null);
}
/**
* 目标跟进核心指标趋势分月/累计
* @param qo
* @param chartType 1:分月 2:累计
* @return
*/
@RequestMapping(value = "get-target-chart")
@ResponseBody
public RestResponse getTargetChart(QueryDataStatisticsCommonQO qo, Integer chartType) {
if (chartType == null) {
chartType = 1;
}
JSONObject jsonObject = new JSONObject();
jsonObject.put("enterpriseId", qo.getEnterpriseId());
Map<String, Object> res = DataTargetHttpUtils.http(DataTargetHttpUtils.getParamNoPage(jsonObject).toJSONString(),
chartType == 1 ? "data_mbr_target_chart" : "data_mbr_target_cumulate_chart");
return DataTargetHttpUtils.response(res);
}
/**
* 目标跟进达成分析门店明细数据
* @param qo
* @param pageQo
* @return
*/
@RequestMapping(value = "get-target-analysis-store-detail")
@ResponseBody
public RestResponse getTargetAnalysisStoreDetail(QueryDataStatisticsCommonQO qo, PageQo pageQo) {
JSONObject jsonObject = getCommon(qo, true);
Map<String, Object> res = DataTargetHttpUtils.http(DataTargetHttpUtils.getParam(pageQo, jsonObject).toJSONString(),
qo.getTimeType() == 1 ? "data_mbr_target_analysis_year_store_detail" : "data_mbr_target_analysis_month_store_detail");
return DataTargetHttpUtils.responsePageData(res);
}
/**
* 目标跟进门店会员分层明细数据
* @param qo
* @return
*/
@RequestMapping(value = "get-target-store-mbr-hierarchy-detail")
@ResponseBody
public RestResponse getTargetStoreMbrHierarchyDetail(QueryDataStatisticsCommonQO qo) {
JSONObject jsonObject = getCommon(qo, true);
Map<String, Object> res = DataTargetHttpUtils.http(DataTargetHttpUtils.getParamNoPage(jsonObject).toJSONString(),
"data_mbr_target_store_mbr_hierarchy_detail");
return DataTargetHttpUtils.responseOfOne(res, null);
}
/**
* 目标跟进门店会员631分层明细数据
* @param qo
* @return
*/
@RequestMapping(value = "get-target-store-mbr-631-detail")
@ResponseBody
public RestResponse getTargetStoreMbr631Detail(QueryDataStatisticsCommonQO qo) {
JSONObject jsonObject = getCommon(qo, true);
Map<String, Object> res = DataTargetHttpUtils.http(DataTargetHttpUtils.getParamNoPage(jsonObject).toJSONString(),
"data_mbr_target_store_mbr_631_detail");
return DataTargetHttpUtils.response(res);
}
private JSONObject getCommon(QueryDataStatisticsCommonQO qo, boolean app) {
JSONObject jsonObject = new JSONObject();
if (app) {
jsonObject.put("entId", qo.getEnterpriseId());
jsonObject.put("monthDate", qo.getTime());
} else {
jsonObject.put("enterpriseId", qo.getEnterpriseId());
if (qo.getTimeType() == 1) {
jsonObject.put("year", qo.getTime());
} else {
jsonObject.put("month", qo.getTime());
}
}
if (StringUtils.isBlank(qo.getStoreId())) {
List<String> storeIdList = storeAuthUtils.queryClerkStoreIds(qo.getClerkId(), qo.getWxEnterpriseId());
jsonObject.put("storeId", storeIdList.stream().collect(Collectors.joining(",")));
} else {
jsonObject.put("storeId", qo.getStoreId());
}
return jsonObject;
}
}
package com.gic.haoban.manage.web.qo.target;
import java.io.Serializable;
/**
* @Author guojx
* @Date 2023/1/15 17:49
*/
public class QueryDataStatisticsCommonQO implements Serializable {
/**
* 门店查询参数. 区经可以为空,查询所有管辖门店
*/
private String storeId;
/**
* 1:年 2:月
*/
private Integer timeType = 1;
/**
* 如果是年 yyyy 格式 如果是月 yyyy-MM格式
*/
private String time;
/**
* 企业ID.必传
*/
private String enterpriseId;
/**
* 微信企业
*/
private String wxEnterpriseId;
/**
* 如果是区经,用于查询管辖门店权限
*/
private String clerkId;
public String getWxEnterpriseId() {
return wxEnterpriseId;
}
public QueryDataStatisticsCommonQO setWxEnterpriseId(String wxEnterpriseId) {
this.wxEnterpriseId = wxEnterpriseId;
return this;
}
public String getClerkId() {
return clerkId;
}
public QueryDataStatisticsCommonQO setClerkId(String clerkId) {
this.clerkId = clerkId;
return this;
}
public String getStoreId() {
return storeId;
}
public QueryDataStatisticsCommonQO setStoreId(String storeId) {
this.storeId = storeId;
return this;
}
public Integer getTimeType() {
return timeType;
}
public QueryDataStatisticsCommonQO setTimeType(Integer timeType) {
this.timeType = timeType;
return this;
}
public String getTime() {
return time;
}
public QueryDataStatisticsCommonQO setTime(String time) {
this.time = time;
return this;
}
public String getEnterpriseId() {
return enterpriseId;
}
public QueryDataStatisticsCommonQO setEnterpriseId(String enterpriseId) {
this.enterpriseId = enterpriseId;
return this;
}
}
package com.gic.haoban.manage.web.utils;
import com.gic.haoban.manage.api.service.StaffApiService;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.Collections;
import java.util.List;
/**
* @Author guojx
* @Date 2023/1/17 10:59
*/
@Component
public class StoreAuthUtils {
private static final Logger log = LoggerFactory.getLogger(StoreAuthUtils.class);
@Autowired
private StaffApiService staffApiService;
/**
* 查询区经角色下管辖的门店权限
* @param clerkId
* @param wxEnterpriseId
* @return
*/
public List<String> queryClerkStoreIds(String clerkId, String wxEnterpriseId){
List<String> storeIds = staffApiService.getHaoBanStoreIdsRolesByClerkId(clerkId, wxEnterpriseId);
if (CollectionUtils.isEmpty(storeIds)){
log.info("根据区经id查询管辖的门店为空 {} {}", clerkId, wxEnterpriseId);
return Collections.singletonList("-100");
}
if (storeIds.size() == 1 && StringUtils.equals(storeIds.get(0), "-1")){
// 全部门店权限
log.info("区经有全部门店权限 {}", clerkId);
return Collections.emptyList();
}
return storeIds;
}
}
package com.gic.haoban.manage.web.utils.target;
import com.alibaba.fastjson.JSONObject;
import com.ctrip.framework.apollo.Config;
import com.ctrip.framework.apollo.ConfigService;
import com.gic.api.base.commons.Page;
import com.gic.commons.util.HttpClient;
import com.gic.commons.web.qo.PageQo;
import com.gic.commons.webapi.reponse.RestResponse;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* 目标配置调用数据组http接口工具类
* @Author guojx
* @Date 2023/1/17 9:51
*/
public class DataTargetHttpUtils {
private static final Logger LOGGER = LogManager.getLogger(DataTargetHttpUtils.class);
public static void main(String[] args) {
JSONObject jsonObject = new JSONObject();
jsonObject.put("enterpriseId", "ff8080815dacd3a2015dacd3ef5c0000");
//Map<String, Object> res = http(getParamNoPage(jsonObject).toJSONString(), "data_mbr_target_overview_targetActual");
//System.out.println(JSON.toJSONString(responseOfOne(res, null)));
System.out.println("年模板".equals("年模板"));
System.out.println();
}
public static JSONObject getCommonParam(String enterpriseId, String storeId, String startTime, String endTime) {
JSONObject resJson = new JSONObject();
JSONObject jsonObject = new JSONObject();
jsonObject.put("enterpriseId", enterpriseId);
jsonObject.put("storeId", storeId);
jsonObject.put("startTime", startTime);
jsonObject.put("endTime", endTime);
return resJson;
}
public static boolean isSuccess(Map<String, Object> res) {
return res.get("errorCode").toString().equals("1");
}
public static RestResponse responsePageData(Map<String, Object> res) {
if (res.get("errorCode").toString().equals("1")) {
//成功
Page page = new Page();
List<JSONObject> dataList = (List<JSONObject>) res.get("data");
JSONObject pageJson = (JSONObject) res.get("page");
page.setPageSize(pageJson.getIntValue("pageSize"));
page.setTotalCount(pageJson.getIntValue("totalCount"));
page.setCurrentPage(pageJson.getIntValue("currentPage"));
page.setTotalPage(pageJson.getIntValue("totalPage"));
page.setResult(dataList);
return RestResponse.successResult(page);
}
return RestResponse.failure((String) res.get("errorCode"), (String) res.get("errorInfo"));
}
public static RestResponse response(Map<String, Object> res) {
if (res.get("errorCode").toString().equals("1")) {
//成功
List<JSONObject> dataList = (List<JSONObject>) res.get("data");
return RestResponse.successResult(dataList);
}
return RestResponse.failure((String) res.get("errorCode"), (String) res.get("errorInfo"));
}
public static RestResponse responseOfOne(Map<String, Object> res, JSONObject defaultJson) {
if (res.get("errorCode").toString().equals("1")) {
//成功
List<JSONObject> dataList = (List<JSONObject>) res.get("data");
if (CollectionUtils.isNotEmpty(dataList)) {
return RestResponse.successResult(dataList.get(0));
}
if (defaultJson != null) {
return RestResponse.successResult(defaultJson);
}
return RestResponse.successResult(null);
}
return RestResponse.failure((String) res.get("errorCode"), (String) res.get("errorInfo"));
}
public static List<JSONObject> getDataList(Map<String, Object> res) {
if (res.get("errorCode").toString().equals("1")) {
//成功
List<JSONObject> dataList = (List<JSONObject>) res.get("data");
return dataList;
}
return Collections.EMPTY_LIST;
}
public static JSONObject getData(Map<String, Object> res) {
if (res.get("errorCode").toString().equals("1")) {
//成功
List<JSONObject> dataList = (List<JSONObject>) res.get("data");
if (CollectionUtils.isNotEmpty(dataList)) {
return dataList.get(0);
}
return null;
}
return null;
}
public static Map<String, Object> http(String jsonParam, String apolloKey) {
LOGGER.info("接口的key:{}", apolloKey);
Config config = ConfigService.getConfig("COMMON.data-api-config");
String value = config.getProperty(apolloKey, "");
if (StringUtils.isBlank(value)) {
throw new RuntimeException("配置有误!");
}
LOGGER.info("{}:Apollo查询的配置信息:{}", apolloKey, value);
String[] split = value.split("\\+\\+\\+\\+");
String url = split[0];
String token = split[1];
Map<String, String> head = new HashMap<>();
head.put("Content-Type", "application/json");
head.put("API-TOKEN", token);
Map<String, Object> res = HttpClient.getWinxinResByJson(url, jsonParam, head);
LOGGER.info("调用接口{},返回结果:{}", url, res);
return res;
}
public static JSONObject getParam(PageQo pageQo, JSONObject objParam) {
JSONObject jsonObject = new JSONObject();
jsonObject.put("pageNo", pageQo.getPageNum());
jsonObject.put("pageSize", pageQo.getPageSize());
if (objParam != null) {
if (objParam.containsKey("storeId")) {
Object storeId = objParam.get("storeId");
if (storeId == null || StringUtils.isBlank(storeId.toString())) {
objParam.remove("storeId");
}
}
}
jsonObject.put("inFields", objParam);
return jsonObject;
}
public static JSONObject getParamNoPage(JSONObject objParam) {
JSONObject jsonObject = new JSONObject();
if (objParam != null) {
if (objParam.containsKey("storeId")) {
Object storeId = objParam.get("storeId");
if (storeId == null || StringUtils.isBlank(storeId.toString())) {
objParam.remove("storeId");
}
}
}
jsonObject.put("inFields", objParam);
return jsonObject;
}
/**
* 保留2位小数 .元转万元
*
* @param a
* @return by wws
*/
public static Double transferTenThousand(Double a) {
BigDecimal bd = new BigDecimal(a / 10000);
bd = bd.setScale(2, BigDecimal.ROUND_HALF_UP);
return bd.doubleValue();
}
public static Double transferTenThousand(String a) {
BigDecimal bd = new BigDecimal(a);
bd = bd.divide(new BigDecimal("10000")).setScale(2, BigDecimal.ROUND_HALF_UP);
return bd.doubleValue();
}
public static Double transferTenThousand(Object a) {
if (a == null) {
return 0.00;
}
BigDecimal bd = new BigDecimal(a.toString());
bd = bd.divide(new BigDecimal("10000")).setScale(2, BigDecimal.ROUND_HALF_UP);
return bd.doubleValue();
}
public static Double parseDouble(Object a) {
if (a == null) {
return 0.00;
}
return Double.parseDouble(a.toString());
}
public static Double transferTenThousandNoDivide(Double a) {
if (a == null) {
return 0.00;
}
BigDecimal bd = new BigDecimal(a.toString());
bd = bd.setScale(2, BigDecimal.ROUND_HALF_UP);
return bd.doubleValue();
}
public static String formatToSepara(Double data) {
DecimalFormat df = new DecimalFormat("#,###.00");
return df.format(data);
}
public static String formatToSepara(Integer data) {
DecimalFormat df = new DecimalFormat("#,###");
return df.format(data);
}
public static String getContrast(String data) {
if ("--".equals(data)) {
return data;
}
Double dataDouble = Double.parseDouble(data);
if (dataDouble > 0) {
return "+" + data + "%";
} else {
return data + "%";
}
}
public static String getJsonOrDefault(Object a, Object object) {
if (a == null) {
return object.toString();
}
return a.toString();
}
public static Object getObjectOrDefault(Object a, Object object) {
if (a == null) {
return object;
}
return a;
}
public static String getContrastOrDefault(Object a, Object object) {
return getContrast(getJsonOrDefault(a, object));
}
public static String getRateOrDefault(Object a, Object object) {
String data = getJsonOrDefault(a, object);
if ("--".equals(data)) {
return data;
}
return data + "%";
}
}
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