tyb пре 2 месеци
родитељ
комит
9ad7d9eb50

+ 39 - 0
src/main/java/com/jzlife/report/controller/NannyController.java

@@ -0,0 +1,39 @@
+package com.jzlife.report.controller;
+
+import com.jzlife.report.service.nurse.SanSaoService;
+import com.jzlife.report.vo.NannyVo;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.*;
+
+/**
+ * 三嫂业务报表
+ */
+@RestController
+@RequestMapping(value = "nanny")
+@Api(value = "nanny", description = "三嫂报表")
+public class NannyController {
+
+    @Autowired
+    private SanSaoService sanSaoService;
+
+    @ApiOperation("获取三嫂业务统计数据")
+    @GetMapping("getData")
+    public Object getData(){
+        return sanSaoService.getSanSaoData();
+    }
+
+    @ApiOperation("获取三嫂业务城市统计数据")
+    @PostMapping("getCityData")
+    public Object getCityData(@RequestBody NannyVo nannyVo){
+        return sanSaoService.getCityData(nannyVo);
+    }
+
+
+    @ApiOperation("获取三嫂服务模式统计数据")
+    @PostMapping("getServiceModelData")
+    public Object getServiceModelData(@RequestBody NannyVo nannyVo){
+        return sanSaoService.getServiceModelData(nannyVo);
+    }
+}

+ 17 - 0
src/main/java/com/jzlife/report/dao/reports/TTempClueMapper.java

@@ -1,10 +1,27 @@
 package com.jzlife.report.dao.reports;
 
 import com.jzlife.report.entity.reports.TTempClue;
+import com.jzlife.report.vo.NannyVo;
 import com.jzlife.report.vo.SanSaoVo;
 
 import java.util.List;
+import java.util.Map;
 
 public interface TTempClueMapper {
     List<TTempClue> selectSanSaoContractList(SanSaoVo sanSaoVo);
+
+    List<String> getClueCountAndOrderCountAndMoney(NannyVo NannyVo);
+
+    String getOrderMoney(NannyVo NannyVo);
+
+    List<Map<String,Object>> getClueCountByCity(NannyVo NannyVo);
+
+    List<Map<String,Object>> getOrderCountByCity(NannyVo NannyVo);
+
+    List<Map<String,Object>> getOrderMoneyByCity(NannyVo NannyVo);
+
+    List<Map<String,Object>> getOrderKdMoneyByCity(NannyVo NannyVo);
+
+
+    List<Map<String,Object>> getOrderKdMoneyByServiceModel(NannyVo NannyVo);
 }

+ 8 - 0
src/main/java/com/jzlife/report/service/nurse/SanSaoService.java

@@ -1,12 +1,20 @@
 package com.jzlife.report.service.nurse;
 
 import com.jzlife.report.entity.reports.TTempClue;
+import com.jzlife.report.vo.NannyVo;
 import com.jzlife.report.vo.SanSaoVo;
 
+
 import java.util.List;
 
 public interface SanSaoService {
     Object selectSanSaoContractList(SanSaoVo sanSaoVo);
 
     List<TTempClue> selectSanSaoContractListNoPage(SanSaoVo sanSaoVo);
+
+    Object getSanSaoData();
+
+    Object getCityData(NannyVo nannyVo);
+
+    Object getServiceModelData( NannyVo nannyVo);
 }

+ 266 - 1
src/main/java/com/jzlife/report/service/nurse/impl/SanSaoServiceImpl.java

@@ -1,17 +1,26 @@
 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.*;
 
 @Service
 @Slf4j
@@ -21,6 +30,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 +89,257 @@ 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<>();
+            for (Map<String, Object> stringObjectMap : result) {
+                cityList.add(stringObjectMap.get("cityName").toString());
+                data.add(stringObjectMap.get("payAmount").toString());
+            }
+            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);
+            BigDecimal sumAmount = result.stream().map(res -> new BigDecimal(res.get("payAmount").toString())).reduce(BigDecimal.ZERO, BigDecimal::add);
+            List<Map<String, Object>> zbList = new ArrayList<>();
+            for (Map<String, Object> obj : result) {
+                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("serviceModel", obj.get("serviceModel"));
+                zbMap.put("zb", zb);
+                zbList.add(zbMap);
+            }
+
+            jsonObject.put("serviceModel", result);
+            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));
+        }
+
+
+    }
+
+    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"));
+    }
 }

+ 71 - 14
src/main/java/com/jzlife/report/util/DateUtils.java

@@ -16,10 +16,10 @@ public class DateUtils {
 	public static String getCurrentDay() {
 		return format.format(new Date());
 	}
-	
+
 	/**
 	 * 获取前一天
-	 * 
+	 *
 	 * @param date 当前日期
 	 * @return
 	 */
@@ -51,7 +51,7 @@ public class DateUtils {
 
 	/**
 	 * 前一天的上月当日
-	 * 
+	 *
 	 * @return
 	 */
 	public static String getqytsydr(Date date) {
@@ -61,10 +61,10 @@ public class DateUtils {
 		c.add(Calendar.MONTH, -1);
 		return format.format(c.getTime());
 	}
-	
+
 	/**
 	 * 前多少天的上月当日
-	 * 
+	 *
 	 * @return
 	 */
 	public static String getqytsydr(Date date,Integer d) {
@@ -77,7 +77,7 @@ public class DateUtils {
 
 	/**
 	 * 前一天的上月第一天
-	 * 
+	 *
 	 * @return
 	 */
 	public static String getqytsydyt(Date date) {
@@ -95,7 +95,7 @@ public class DateUtils {
 //	 * @return
 //	 */
 //	public static String getqytnian() {
-//		Calendar c = Calendar.getInstance(); 
+//		Calendar c = Calendar.getInstance();
 //		c.add(Calendar.DATE, -1);
 //		c.set(Calendar.DAY_OF_MONTH, 1);
 //		c.set(Calendar.DAY_OF_YEAR, 1);
@@ -104,7 +104,7 @@ public class DateUtils {
 
 	/**
 	 * 获取前一天对应的去年的日期 所在月的第一天
-	 * 
+	 *
 	 * @return
 	 */
 	public static String getqytqndrq(Date date) {
@@ -118,7 +118,7 @@ public class DateUtils {
 
 	/**
 	 * 获取前一天对应的去年日期
-	 * 
+	 *
 	 * @return
 	 */
 	public static String getqytqn(Date date) {
@@ -150,7 +150,7 @@ public class DateUtils {
 	// ---------------------------------同比去年----------------------------------------------
 	/**
 	 * 获取当前月第一天
-	 * 
+	 *
 	 * @return
 	 */
 	public static String getMonthFirstDay() {
@@ -163,7 +163,7 @@ public class DateUtils {
 
 	/**
 	 * 获取当月的最后一天
-	 * 
+	 *
 	 * @return
 	 */
 	public static String getMonthEndDay() {
@@ -175,7 +175,7 @@ public class DateUtils {
 
 	/**
 	 * 获取某年某月的最后一天
-	 * 
+	 *
 	 * @param year
 	 * @param month
 	 * @return
@@ -192,7 +192,7 @@ public class DateUtils {
 
 	/**
 	 * 获取前一天的月份的最后一天
-	 * 
+	 *
 	 * @return
 	 */
 	public static String qytdydzhyt() {
@@ -209,7 +209,7 @@ public class DateUtils {
 		String last = format.format(c.getTime());
 		return last;
 	}
-	
+
 	// 判断是否当月
 	public static Boolean checkThisTime(String ym) {
 		String now = format3.format(new Date());// 当前时间
@@ -219,6 +219,63 @@ public class DateUtils {
 		 return false;
 	}
 
+	/**
+	 * 获取当天对应的去年的日期 所在月的第一天
+	 *
+	 * @return
+	 */
+	public static String getdtqndrq(Date date) {
+		Calendar c = Calendar.getInstance();
+		c.setTime(date);
+		c.add(Calendar.YEAR, -1);
+		c.set(Calendar.DAY_OF_MONTH, 1);
+		return format.format(c.getTime());
+	}
+
+	/**
+	 * 获取传入时间去年的日期
+	 *
+	 * @return
+	 */
+	public static String getqndrq(String date) {
+		Calendar c = Calendar.getInstance();
+		try {
+			c.setTime(format.parse(date));
+		} catch (ParseException e) {
+			e.printStackTrace();
+		}
+
+		c.add(Calendar.YEAR, -1);
+		return format.format(c.getTime());
+	}
+
+	/**
+	 * 获取传入时间上月第一天
+	 *
+	 * @return
+	 */
+	public static String getSydyt(Date date) {
+		Calendar c = Calendar.getInstance();
+		c.setTime(date);
+		c.add(Calendar.MONTH, -1);
+		c.set(Calendar.DAY_OF_MONTH, 1);
+		return format.format(c.getTime());
+	}
+
+	/**
+	 * 获取传入时间上月的最后一天
+	 *
+	 * @return
+	 */
+	public static String getSyzhyt(Date date) {
+		Calendar c = Calendar.getInstance();
+		c.setTime(date);
+		c.add(Calendar.MONTH, -1);
+		c.set(Calendar.DAY_OF_MONTH, 1);
+		c.set(Calendar.DAY_OF_MONTH, c.getActualMaximum(Calendar.DAY_OF_MONTH));
+		return format.format(c.getTime());
+	}
+
 	public static void main(String[] args) {
 		String yearMonth = "2022-02";
 		System.out.println(format.format(DateUtils.isThisTime(yearMonth)));

+ 23 - 0
src/main/java/com/jzlife/report/vo/NannyVo.java

@@ -0,0 +1,23 @@
+package com.jzlife.report.vo;
+
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+@Data
+public class NannyVo {
+
+    @ApiModelProperty(value = "日期类型,1昨日 2当月 3上月")
+    private Integer dateType;
+
+    @ApiModelProperty(value = "数据类型,1业绩 2订单量 3客单价 4线索量")
+    private Integer dataType;
+
+    @ApiModelProperty(value = "渠道id")
+    private Integer channelId;
+
+    @ApiModelProperty(value = "开始时间")
+    private String startDate;
+
+    @ApiModelProperty(value = "结束时间")
+    private String endDate;
+}

+ 190 - 0
src/main/resources/mybatis/mapper/reports/TTempClueMapper.xml

@@ -59,4 +59,194 @@
 
       </where>
   </select>
+
+
+    <select id="getClueCountAndOrderCountAndMoney" resultType="string" >
+        #线索量
+        select  count(1) from jlife_nurse.jzbm_lead where date(create_time) BETWEEN  #{startDate} and #{endDate}
+        union all
+        #成单量
+        SELECT
+            count(DISTINCT a.id)
+        FROM
+            jlife_nurse.jzbm_order a
+                Left JOIN jlife_nurse.jzbm_contract b ON a.order_no = b.order_no  AND b.contract_type IN ( 1, 2 )
+                Left join jlife_nurse.jzbm_order_service c on c.id=(select e.id from jlife_nurse.jzbm_order_service e where e.order_id=a.id order by e.id desc limit 1)
+                Left JOIN jlife_nurse.jzbm_contract d ON c.order_service_no = d.order_service_no AND d.contract_type IN ( 3, 4, 10)
+        WHERE
+            a.state = 2
+          AND b.review_state = 2
+          and d.review_state= 2
+          AND date( a.create_time ) BETWEEN #{startDate}
+            AND #{endDate}
+        union all
+        #销售额
+        SELECT
+            IFNULL(sum(e.pay_amount),0)
+        FROM
+            jlife_nurse.jzbm_order a
+                Left JOIN jlife_nurse.jzbm_contract b ON a.order_no = b.order_no AND b.contract_type IN ( 1, 2 )
+                Left join jlife_nurse.jzbm_order_service c on c.id=(select e.id from jlife_nurse.jzbm_order_service e where e.order_id=a.id order by e.id desc limit 1)
+                Left JOIN jlife_nurse.jzbm_contract d ON c.order_service_no = d.order_service_no AND d.contract_type IN ( 3, 4, 10)
+                left join jlife_nurse.jzbm_order_pay_file e on e.order_no=a.order_no and is_deleted=0
+        WHERE
+            a.state = 2
+          AND b.review_state = 2
+          and c.state in(2,4)
+          and d.review_state= 2
+          AND date( a.create_time ) BETWEEN #{startDate}
+            AND #{endDate}
+    </select>
+
+    <select id="getOrderMoney" resultType="string">
+        #销售额
+        SELECT
+            IFNULL(sum(e.pay_amount),0)
+        FROM
+            jlife_nurse.jzbm_order a
+                Left JOIN jlife_nurse.jzbm_contract b ON a.order_no = b.order_no AND b.contract_type IN ( 1, 2 )
+                Left join jlife_nurse.jzbm_order_service c on c.id=(select e.id from jlife_nurse.jzbm_order_service e where e.order_id=a.id order by e.id desc limit 1)
+                Left JOIN jlife_nurse.jzbm_contract d ON c.order_service_no = d.order_service_no AND d.contract_type IN ( 3, 4, 10)
+                left join jlife_nurse.jzbm_order_pay_file e on e.order_no=a.order_no and is_deleted=0
+        WHERE
+            a.state = 2
+          AND b.review_state = 2
+          and c.state in(2,4)
+          and d.review_state= 2
+          AND date( a.create_time ) BETWEEN #{startDate}
+            AND #{endDate}
+    </select>
+
+    <select id="getClueCountByCity" resultType="map">
+        #线索量
+        SELECT
+            service_city_name as cityName,
+            count( 1 ) AS payAmount
+        FROM
+            jlife_nurse.jzbm_lead a
+        WHERE
+            date( a.create_time ) BETWEEN #{startDate}
+                AND #{endDate}
+            <if test="channelId !=null">
+                and source_id=#{channelId}
+            </if>
+        GROUP BY
+            service_city_name
+        ORDER BY
+        payAmount DESC
+    </select>
+
+    <select id="getOrderCountByCity" resultType="map">
+        #订单量
+        SELECT
+            e.city_name as cityName,
+            count(DISTINCT a.id) as payAmount
+        FROM
+            jlife_nurse.jzbm_order a
+                Left JOIN jlife_nurse.jzbm_contract b ON a.order_no = b.order_no  AND b.contract_type IN ( 1, 2 )
+                Left join jlife_nurse.jzbm_order_service c on c.id=(select e.id from jlife_nurse.jzbm_order_service e where e.order_id=a.id order by e.id desc limit 1)
+                Left JOIN jlife_nurse.jzbm_contract d ON c.order_service_no = d.order_service_no AND d.contract_type IN ( 3, 4, 10)
+                Left join jlife_nurse.sys_city e on a.city_id = e.id
+                Left join jlife_nurse.jzbm_lead g on a.clue_id=g.id
+        WHERE
+            a.state = 2
+          AND b.review_state = 2
+          and d.review_state= 2
+          AND date( a.create_time ) BETWEEN #{startDate}
+            AND #{endDate}
+        <if test="channelId !=null">
+            and g.source_id=#{channelId}
+        </if>
+        GROUP BY e.city_name order by payAmount desc
+    </select>
+
+    <select id="getOrderMoneyByCity" resultType="map">
+        #订单量
+        SELECT
+            f.city_name as cityName,
+            IFNULL(sum(e.pay_amount),0) as payAmount
+        FROM
+            jlife_nurse.jzbm_order a
+                Left JOIN jlife_nurse.jzbm_contract b ON a.order_no = b.order_no AND b.contract_type IN ( 1, 2 )
+                Left join jlife_nurse.jzbm_order_service c on c.id=(select e.id from jlife_nurse.jzbm_order_service e where e.order_id=a.id order by e.id desc limit 1)
+                Left JOIN jlife_nurse.jzbm_contract d ON c.order_service_no = d.order_service_no AND d.contract_type IN ( 3, 4, 10)
+                left join jlife_nurse.jzbm_order_pay_file e on e.order_no=a.order_no and is_deleted=0
+                Left join jlife_nurse.sys_city f on a.city_id = f.id
+                Left join jlife_nurse.jzbm_lead g on a.clue_id=g.id
+        WHERE
+            a.state = 2
+          AND b.review_state = 2
+          and d.review_state= 2
+          and c.state in(2,4)
+          AND date( a.create_time ) BETWEEN #{startDate}
+            AND #{endDate}
+        <if test="channelId !=null">
+            and g.source_id=#{channelId}
+        </if>
+        group by f.city_name order by payAmount desc
+    </select>
+    <select id="getOrderKdMoneyByCity" resultType="map">
+        #客单价
+        SELECT
+        f.city_name as cityName,
+        IFNULL(sum(e.pay_amount)/count(DISTINCT a.id),0) as payAmount
+        FROM
+            jlife_nurse.jzbm_order a
+        Left JOIN jlife_nurse.jzbm_contract b ON a.order_no = b.order_no AND b.contract_type IN ( 1, 2 )
+        Left join jlife_nurse.jzbm_order_service c on c.id=(select e.id from jlife_nurse.jzbm_order_service e where e.order_id=a.id order by e.id desc limit 1)
+        Left JOIN jlife_nurse.jzbm_contract d ON c.order_service_no = d.order_service_no AND d.contract_type IN ( 3, 4, 10)
+        left join jlife_nurse.jzbm_order_pay_file e on e.order_no=a.order_no and is_deleted=0
+        Left join jlife_nurse.sys_city f on a.city_id = f.id
+        Left join jlife_nurse.jzbm_lead g on a.clue_id=g.id
+        WHERE
+        a.state = 2
+        AND b.review_state = 2
+        and d.review_state= 2
+        and c.state in(2,4)
+        AND date( a.create_time ) BETWEEN #{startDate}
+        AND #{endDate}
+        <if test="channelId !=null">
+            and g.source_id=#{channelId}
+        </if>
+        group by f.city_name order by payAmount desc
+
+    </select>
+
+    <select id="getOrderKdMoneyByServiceModel" resultType="map">
+        SELECT
+            CASE a.service_model
+                WHEN 10 THEN
+                    '钟点工'
+                WHEN 11 THEN
+                    '家务保姆'
+                WHEN 12 THEN
+                    '育儿嫂'
+                WHEN 20 THEN
+                    '月嫂'
+                WHEN 30 THEN
+                    '代班钟点工'
+                WHEN 31 THEN
+                    '代班保姆'
+                END  as serviceModel,
+            IFNULL(sum(e.pay_amount),0) as payAmount,
+            count(DISTINCT a.id) as count,
+            IFNULL(convert(sum(e.pay_amount)/count(DISTINCT a.id),decimal(10,2)),0) as kdj
+
+        FROM
+                jlife_nurse.jzbm_order a
+                Left JOIN jlife_nurse.jzbm_contract b ON a.order_no = b.order_no AND b.contract_type IN ( 1, 2 )
+                Left join jlife_nurse.jzbm_order_service c on c.id=(select e.id from jlife_nurse.jzbm_order_service e where e.order_id=a.id order by e.id desc limit 1)
+                Left JOIN jlife_nurse.jzbm_contract d ON c.order_service_no = d.order_service_no AND d.contract_type IN ( 3, 4, 10)
+                left join jlife_nurse.jzbm_order_pay_file e on e.order_no=a.order_no and is_deleted=0
+                Left join jlife_nurse.sys_city f on a.city_id = f.id
+        WHERE
+            a.state = 2
+          AND b.review_state = 2
+          and d.review_state= 2
+          and c.state in(2,4)
+          AND date( a.create_time ) BETWEEN #{startDate}
+          AND #{endDate}
+        group by a.service_model order by payAmount desc
+    </select>
+
 </mapper>