|
@@ -1,17 +1,27 @@
|
|
|
package com.jzlife.report.service.nurse.impl;
|
|
|
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
import com.github.pagehelper.PageHelper;
|
|
|
import com.github.pagehelper.PageInfo;
|
|
|
import com.jzlife.report.dao.reports.TTempClueMapper;
|
|
|
import com.jzlife.report.entity.reports.TTempClue;
|
|
|
import com.jzlife.report.service.nurse.SanSaoService;
|
|
|
+import com.jzlife.report.service.redis.RedisService;
|
|
|
+import com.jzlife.report.util.DateUtils;
|
|
|
+import com.jzlife.report.util.ResponseUtil;
|
|
|
+import com.jzlife.report.vo.NannyVo;
|
|
|
import com.jzlife.report.vo.SanSaoVo;
|
|
|
+import io.swagger.models.auth.In;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
-import java.util.List;
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.time.Duration;
|
|
|
+import java.time.LocalDateTime;
|
|
|
+import java.util.*;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
@Service
|
|
|
@Slf4j
|
|
@@ -21,6 +31,9 @@ public class SanSaoServiceImpl implements SanSaoService {
|
|
|
@Autowired
|
|
|
private TTempClueMapper tTempClueMapper;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private RedisService redisService;
|
|
|
+
|
|
|
@Override
|
|
|
public Object selectSanSaoContractList(SanSaoVo sanSaoVo) {
|
|
|
PageHelper.startPage(sanSaoVo.getPageNo(), sanSaoVo.getPageSize());
|
|
@@ -77,4 +90,325 @@ public class SanSaoServiceImpl implements SanSaoService {
|
|
|
transfer(sanSaoVo);
|
|
|
return tTempClueMapper.selectSanSaoContractList(sanSaoVo);
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Object getSanSaoData() {
|
|
|
+ String result= redisService.get("sansao:sumMoney");
|
|
|
+ if(StringUtils.isEmpty(result)) {
|
|
|
+ NannyVo nannyVo = new NannyVo();
|
|
|
+ nannyVo.setStartDate(DateUtils.getMonthFirstDay());
|
|
|
+ String monthEndDay = DateUtils.getMonthEndDay();
|
|
|
+ nannyVo.setEndDate(monthEndDay);
|
|
|
+ //当月数据(0线索量 1成单量 2销售额)
|
|
|
+ List<String> dyData = tTempClueMapper.getClueCountAndOrderCountAndMoney(nannyVo);
|
|
|
+ Map<String, Object> resultMap = new HashMap<>();
|
|
|
+ if (dyData != null && dyData.size() > 0) {
|
|
|
+ String xsCount = dyData.get(0);
|
|
|
+ String ddCount = dyData.get(1);
|
|
|
+ String yjMoney = dyData.get(2);
|
|
|
+ resultMap.put("dyXsCount", xsCount.substring(0, xsCount.indexOf(".")));
|
|
|
+ resultMap.put("dyDdCount", ddCount.substring(0, ddCount.indexOf(".")));
|
|
|
+ resultMap.put("dyYjMoney", yjMoney);
|
|
|
+ if (!"0".equals(resultMap.get("dyDdCount"))) {
|
|
|
+ resultMap.put("dyKdMoney", new BigDecimal(yjMoney).divide(new BigDecimal(ddCount), 2, BigDecimal.ROUND_HALF_UP));
|
|
|
+ } else {
|
|
|
+ resultMap.put("dyKdMoney", "0.00");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //同比数据
|
|
|
+ nannyVo.setStartDate(DateUtils.getdtqndrq(new Date()));
|
|
|
+ nannyVo.setEndDate(DateUtils.getqndrq(monthEndDay));
|
|
|
+ String orderMoney = tTempClueMapper.getOrderMoney(nannyVo); //销售额
|
|
|
+ BigDecimal dyMoney = new BigDecimal(resultMap.get("dyYjMoney").toString());
|
|
|
+ BigDecimal qnMoney = new BigDecimal(orderMoney);
|
|
|
+ Map<String, Object> dyTbData = getTbData(dyMoney, qnMoney);
|
|
|
+ resultMap.put("dyTbZb", dyTbData.get("zb"));
|
|
|
+ resultMap.put("dyTbZbType", dyTbData.get("type"));
|
|
|
+
|
|
|
+
|
|
|
+ //上月数据(0线索量 1成单量 2销售额)
|
|
|
+ nannyVo.setStartDate(DateUtils.getSydyt(new Date()));
|
|
|
+ nannyVo.setEndDate(DateUtils.getSyzhyt(new Date()));
|
|
|
+ List<String> syData = tTempClueMapper.getClueCountAndOrderCountAndMoney(nannyVo);
|
|
|
+ if (syData != null && syData.size() > 0) {
|
|
|
+ String syXsCount = syData.get(0);
|
|
|
+ String syDdCount = syData.get(1);
|
|
|
+ String syYjMoney = syData.get(2);
|
|
|
+ resultMap.put("syXsCount", syXsCount.substring(0, syXsCount.indexOf(".")));
|
|
|
+ resultMap.put("syDdCount", syDdCount.substring(0, syDdCount.indexOf(".")));
|
|
|
+ resultMap.put("syYjMoney", syYjMoney);
|
|
|
+ if (!"0".equals(resultMap.get("syDdCount"))) {
|
|
|
+ resultMap.put("syKdMoney", new BigDecimal(syYjMoney).divide(new BigDecimal(syDdCount), 2, BigDecimal.ROUND_HALF_UP));
|
|
|
+ } else {
|
|
|
+ resultMap.put("syKdMoney", "0.00");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //上月同比数据
|
|
|
+ nannyVo.setStartDate(DateUtils.getqndrq(nannyVo.getStartDate()));
|
|
|
+ nannyVo.setEndDate(DateUtils.getqndrq(nannyVo.getEndDate()));
|
|
|
+ String syOrderMoney = tTempClueMapper.getOrderMoney(nannyVo); //上月销售额
|
|
|
+ BigDecimal syMoney = new BigDecimal(resultMap.get("syYjMoney").toString());
|
|
|
+ BigDecimal syQnMoney = new BigDecimal(syOrderMoney);
|
|
|
+ Map<String, Object> syTbData = getTbData(syMoney, syQnMoney);
|
|
|
+ resultMap.put("syTbZb", syTbData.get("zb"));
|
|
|
+ resultMap.put("syTbZbType", syTbData.get("type"));
|
|
|
+
|
|
|
+
|
|
|
+ //今日数据
|
|
|
+ String day = DateUtils.format.format(new Date());
|
|
|
+ nannyVo.setStartDate(day);
|
|
|
+ nannyVo.setEndDate(day);
|
|
|
+ List<String> jtData = tTempClueMapper.getClueCountAndOrderCountAndMoney(nannyVo);
|
|
|
+ if (jtData != null && jtData.size() > 0) {
|
|
|
+ String jrXsCount = jtData.get(0);
|
|
|
+ String jrDdCount = jtData.get(1);
|
|
|
+ String jrYjMoney = jtData.get(2);
|
|
|
+ resultMap.put("jrXsCount", jrXsCount.substring(0, jrXsCount.indexOf(".")));
|
|
|
+ resultMap.put("jrDdCount", jrDdCount.substring(0, jrDdCount.indexOf(".")));
|
|
|
+ resultMap.put("jrYjMoney", jrYjMoney);
|
|
|
+ if (!"0".equals(resultMap.get("jrDdCount"))) {
|
|
|
+ //今日客单价
|
|
|
+ resultMap.put("jrKdMoney", new BigDecimal(jrYjMoney).divide(new BigDecimal(jrDdCount), 2, BigDecimal.ROUND_HALF_UP));
|
|
|
+ } else {
|
|
|
+ resultMap.put("jrKdMoney", "0.00");
|
|
|
+ }
|
|
|
+ if (!"0".equals(resultMap.get("jrXsCount"))) {
|
|
|
+ //今日线索转换率
|
|
|
+ resultMap.put("jrXszhl", new BigDecimal(jrDdCount).divide(new BigDecimal(jrXsCount), 2, BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal("100")));
|
|
|
+ } else {
|
|
|
+ resultMap.put("jrXszhl", "0");
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ //去年今日同比数据
|
|
|
+ String qnDay = DateUtils.getqndrq(day);
|
|
|
+ nannyVo.setStartDate(qnDay);
|
|
|
+ nannyVo.setEndDate(qnDay);
|
|
|
+ List<String> qnData = tTempClueMapper.getClueCountAndOrderCountAndMoney(nannyVo);
|
|
|
+ if (jtData != null && jtData.size() > 0) {
|
|
|
+ String qnJrXsCount = qnData.get(0);
|
|
|
+ String qnJrDdCount = qnData.get(1);
|
|
|
+ String qnJrYjMoney = qnData.get(2);
|
|
|
+ Map<String, Object> jrXsTbData = getTbData(new BigDecimal(resultMap.get("jrXsCount").toString()), new BigDecimal(qnJrXsCount));
|
|
|
+ resultMap.put("jrSxTbZb", jrXsTbData.get("zb"));
|
|
|
+ resultMap.put("jrSxTbType", jrXsTbData.get("type"));
|
|
|
+
|
|
|
+ Map<String, Object> jrDdCountTbData = getTbData(new BigDecimal(resultMap.get("jrDdCount").toString()), new BigDecimal(qnJrDdCount));
|
|
|
+ resultMap.put("jrDdCountTbZb", jrDdCountTbData.get("zb"));
|
|
|
+ resultMap.put("jrDdCountTbType", jrDdCountTbData.get("type"));
|
|
|
+
|
|
|
+ Map<String, Object> jrYjMoneyTbData = getTbData(new BigDecimal(resultMap.get("jrYjMoney").toString()), new BigDecimal(qnJrYjMoney));
|
|
|
+ resultMap.put("jrYjMoneyTbZb", jrYjMoneyTbData.get("zb"));
|
|
|
+ resultMap.put("jrYjMoneyTbType", jrYjMoneyTbData.get("type"));
|
|
|
+
|
|
|
+ BigDecimal qnJrKdMoney = new BigDecimal("0");
|
|
|
+ if (!"0.00".equals(qnJrDdCount)) {
|
|
|
+ //去年今日客单价
|
|
|
+ qnJrKdMoney = new BigDecimal(qnJrYjMoney).divide(new BigDecimal(qnJrDdCount), 2, BigDecimal.ROUND_HALF_UP);
|
|
|
+ }
|
|
|
+
|
|
|
+ Map<String, Object> jrKdMoneyTbData = getTbData(new BigDecimal(resultMap.get("jrKdMoney").toString()), qnJrKdMoney);
|
|
|
+ resultMap.put("jrKdMoneyTbZb", jrKdMoneyTbData.get("zb"));
|
|
|
+ resultMap.put("jrKdMoneyTbType", jrKdMoneyTbData.get("type"));
|
|
|
+
|
|
|
+
|
|
|
+ BigDecimal qnJrXszhl = new BigDecimal("0");
|
|
|
+ if (!"0.00".equals(qnJrXsCount)) {
|
|
|
+ //今日线索转换率
|
|
|
+ qnJrXszhl = new BigDecimal(qnJrDdCount).divide(new BigDecimal(qnJrXsCount), 2, BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal("100"));
|
|
|
+ }
|
|
|
+
|
|
|
+ Map<String, Object> jrXszhlTbData = getTbData(new BigDecimal(resultMap.get("jrXszhl").toString()), qnJrXszhl);
|
|
|
+ resultMap.put("jrXszhlTbZb", jrXszhlTbData.get("zb"));
|
|
|
+ resultMap.put("jrXszhlTbType", jrXszhlTbData.get("type"));
|
|
|
+
|
|
|
+ }
|
|
|
+ //缓存10分钟
|
|
|
+ Duration duration = Duration.between(LocalDateTime.now(), LocalDateTime.now().plusMinutes(10));
|
|
|
+ redisService.set("sansao:sumMoney", JSONObject.toJSONString(resultMap), duration);
|
|
|
+ return ResponseUtil.ok(resultMap);
|
|
|
+ } else {
|
|
|
+ return ResponseUtil.ok(JSONObject.parseObject(result));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Object getCityData(NannyVo nannyVo) {
|
|
|
+ int dataType=nannyVo.getDataType()!=null?nannyVo.getDataType():1;
|
|
|
+ int dateType=nannyVo.getDateType()!=null?nannyVo.getDateType():3;
|
|
|
+ int channelId = nannyVo.getChannelId() != null ? nannyVo.getChannelId() : 0;
|
|
|
+
|
|
|
+ String result2= redisService.get("sansao:cityData"+"_"+dataType+"_"+dateType+"_"+channelId);
|
|
|
+ if(StringUtils.isEmpty(result2)) {
|
|
|
+ getDate(nannyVo);
|
|
|
+ List<Map<String, Object>> result = null;
|
|
|
+ if (nannyVo.getDataType() == null || nannyVo.getDataType() == 1) {
|
|
|
+ result = tTempClueMapper.getOrderMoneyByCity(nannyVo);
|
|
|
+ } else if (nannyVo.getDataType() == 2) {
|
|
|
+ result = tTempClueMapper.getOrderCountByCity(nannyVo);
|
|
|
+ } else if (nannyVo.getDataType() == 3) {
|
|
|
+ result = tTempClueMapper.getOrderKdMoneyByCity(nannyVo);
|
|
|
+ } else if (nannyVo.getDataType() == 4) {
|
|
|
+ result = tTempClueMapper.getClueCountByCity(nannyVo);
|
|
|
+ }
|
|
|
+ List<String> cityList=new ArrayList<>();
|
|
|
+ List<String> data=new ArrayList<>();
|
|
|
+ String serviceCity = tTempClueMapper.getServiceCity("service_city");
|
|
|
+ String[] citys = serviceCity.split(",");
|
|
|
+ if (result!=null && result.size()>0) {
|
|
|
+ for (int i = 0; i < citys.length; i++) {
|
|
|
+ String city = citys[i];
|
|
|
+ for (int i1 = 0; i1 < result.size(); i1++) {
|
|
|
+
|
|
|
+ Map<String, Object> stringObjectMap = result.get(i1);
|
|
|
+ if(city.equals(stringObjectMap.get("cityName").toString())) {
|
|
|
+ cityList.add(city);
|
|
|
+ data.add(stringObjectMap.get("payAmount").toString());
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ if(i1==result.size()-1){
|
|
|
+ cityList.add(city);
|
|
|
+ data.add("0");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ for (int i = 0; i < citys.length; i++) {
|
|
|
+ cityList.add(citys[i]);
|
|
|
+ data.add("0");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ JSONObject jsonObject = new JSONObject();
|
|
|
+ jsonObject.put("cityList",cityList);
|
|
|
+ jsonObject.put("data",data);
|
|
|
+
|
|
|
+ Duration duration = Duration.between(LocalDateTime.now(), LocalDateTime.now().plusMinutes(10));
|
|
|
+ redisService.set("sansao:cityData"+"_"+dataType+"_"+dateType+"_"+channelId, JSONObject.toJSONString(jsonObject), duration);
|
|
|
+ return ResponseUtil.ok(jsonObject);
|
|
|
+ }else {
|
|
|
+ return ResponseUtil.ok(JSONObject.parseObject(result2));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Object getServiceModelData(NannyVo nannyVo) {
|
|
|
+ int dateType=nannyVo.getDateType()!=null?nannyVo.getDateType():3;
|
|
|
+ String result2= redisService.get("sansao:serviceModelData_"+dateType);
|
|
|
+ if(StringUtils.isEmpty(result2)) {
|
|
|
+ getDate(nannyVo);
|
|
|
+ JSONObject jsonObject = new JSONObject();
|
|
|
+ List<Map<String, Object>> result = tTempClueMapper.getOrderKdMoneyByServiceModel(nannyVo);
|
|
|
+ String serviceModel = tTempClueMapper.getServiceCity("service_model");// Arrays.asList("普通家务保姆", "育儿嫂","钟点工","月嫂","代班钟点工","代班保姆");
|
|
|
+ String[] serviceModellist = serviceModel.split(",");
|
|
|
+ List<Map<String, Object>> resultList=new ArrayList<>();
|
|
|
+
|
|
|
+ if(result !=null && result.size()>0) {
|
|
|
+ for (int i = 0; i < serviceModellist.length; i++) {
|
|
|
+ String serviceMode = serviceModellist[i];
|
|
|
+ for (int i1 = 0; i1 < result.size(); i1++) {
|
|
|
+ Map<String, Object> stringObjectMap = result.get(i1);
|
|
|
+ if (serviceMode.equals(stringObjectMap.get("serviceModel").toString())) {
|
|
|
+ resultList.add(stringObjectMap);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ if(i1==result.size()-1){
|
|
|
+ Map<String, Object> resultMap = new HashMap<>();
|
|
|
+ resultMap.put("kdj","0.00");
|
|
|
+ resultMap.put("serviceModel",serviceModellist[i]);
|
|
|
+ resultMap.put("payAmount","0.00");
|
|
|
+ resultMap.put("count","0");
|
|
|
+ resultList.add(resultMap);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }else {
|
|
|
+ for (int i = 0; i < serviceModellist.length; i++) {
|
|
|
+ Map<String, Object> resultMap = new HashMap<>();
|
|
|
+ resultMap.put("kdj","0.00");
|
|
|
+ resultMap.put("serviceModel",serviceModellist[i]);
|
|
|
+ resultMap.put("payAmount","0.00");
|
|
|
+ resultMap.put("count","0");
|
|
|
+ resultList.add(resultMap);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ List<Map<String, Object>> zbList = new ArrayList<>();
|
|
|
+ BigDecimal sumAmount = resultList.stream().map(res -> new BigDecimal(res.get("payAmount").toString())).reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
+ if (sumAmount.compareTo(new BigDecimal("0.00"))>0) {
|
|
|
+ for (Map<String, Object> obj : resultList) {
|
|
|
+ BigDecimal zb = new BigDecimal(obj.get("payAmount").toString()).divide(sumAmount, 2, BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal("100"));
|
|
|
+ Map<String, Object> zbMap = new HashMap<>();
|
|
|
+ zbMap.put("name", obj.get("serviceModel"));
|
|
|
+ zbMap.put("value", zb);
|
|
|
+ zbList.add(zbMap);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ for (int i = 0; i < serviceModellist.length; i++) {
|
|
|
+ Map<String, Object> zbMap = new HashMap<>();
|
|
|
+ zbMap.put("name",serviceModellist[i]);
|
|
|
+ zbMap.put("value","0");
|
|
|
+ zbList.add(zbMap);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ jsonObject.put("serviceModel", resultList);
|
|
|
+ jsonObject.put("serviceModelZb", zbList);
|
|
|
+ Duration duration = Duration.between(LocalDateTime.now(), LocalDateTime.now().plusMinutes(10));
|
|
|
+ redisService.set("sansao:serviceModelData_"+dateType, JSONObject.toJSONString(jsonObject), duration);
|
|
|
+
|
|
|
+ return ResponseUtil.ok(jsonObject);
|
|
|
+ }else {
|
|
|
+ return ResponseUtil.ok(JSONObject.parseObject(result2));
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ public Object getSource(){
|
|
|
+ return ResponseUtil.ok(tTempClueMapper.getSource());
|
|
|
+ }
|
|
|
+
|
|
|
+ private void getDate(NannyVo nannyVo){
|
|
|
+ if (nannyVo.getDateType()==null || nannyVo.getDateType()==3) {
|
|
|
+ //上月
|
|
|
+ nannyVo.setStartDate(DateUtils.getSydyt(new Date()));
|
|
|
+ nannyVo.setEndDate(DateUtils.getSyzhyt(new Date()));
|
|
|
+ }else if (nannyVo.getDateType()==2) {
|
|
|
+ //当月
|
|
|
+ nannyVo.setStartDate(DateUtils.getMonthFirstDay());
|
|
|
+ nannyVo.setEndDate(DateUtils.getMonthEndDay());
|
|
|
+ }else if (nannyVo.getDateType()==1) {
|
|
|
+ //当天
|
|
|
+ String day = DateUtils.format.format(new Date());
|
|
|
+ nannyVo.setStartDate(day);
|
|
|
+ nannyVo.setEndDate(day);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ private Map<String,Object> getTbData(BigDecimal money1, BigDecimal money2){
|
|
|
+ Map<String, Object> resultMap = new HashMap<>();
|
|
|
+ int result2 = money1.compareTo(money2);
|
|
|
+ if (result2<0) {
|
|
|
+ //下降
|
|
|
+ BigDecimal zb = getTb(money2,money1);
|
|
|
+ resultMap.put("zb",zb);
|
|
|
+ resultMap.put("type",0);
|
|
|
+ }else if(result2>0) {
|
|
|
+ //上升
|
|
|
+ BigDecimal zb = getTb(money1,money2);
|
|
|
+ resultMap.put("zb",zb);
|
|
|
+ resultMap.put("type",1);
|
|
|
+ } else {
|
|
|
+ resultMap.put("zb",0);
|
|
|
+ resultMap.put("type",0);
|
|
|
+ }
|
|
|
+ return resultMap;
|
|
|
+ }
|
|
|
+
|
|
|
+ private BigDecimal getTb(BigDecimal money1,BigDecimal money2){
|
|
|
+ return money1.subtract(money2).divide(money1,2, BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal("100"));
|
|
|
+ }
|
|
|
}
|