Bläddra i källkod

派单分析api

shudonghui 1 år sedan
förälder
incheckning
1d590f8ef8

+ 169 - 0
sop-api/src/main/java/com/qmth/sop/server/api/CrmAnalyseController.java

@@ -0,0 +1,169 @@
+package com.qmth.sop.server.api;
+
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.qmth.boot.api.annotation.Aac;
+import com.qmth.boot.api.constant.ApiConstant;
+import com.qmth.sop.business.bean.result.CrmAnalyseResult;
+import com.qmth.sop.business.bean.result.TBCrmResult;
+import com.qmth.sop.business.service.CrmAnalyseService;
+import com.qmth.sop.common.contant.SystemConstant;
+import com.qmth.sop.common.enums.ProductTypeEnum;
+import com.qmth.sop.common.util.Result;
+import com.qmth.sop.common.util.ResultUtil;
+import io.swagger.annotations.*;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.RestController;
+
+import javax.annotation.Resource;
+import javax.validation.constraints.Max;
+import javax.validation.constraints.Min;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * 派单分析 控制器
+ *
+ * @author: shudonghui
+ * @date: 2023-08-14 15:55:18
+ * @version: 1.0
+ * @email: shudonghui@qmth.com.cn
+ * @Company: www.qmth.com.cn
+ */
+@Api(tags = "派单分析 Controller")
+@RestController
+@RequestMapping(ApiConstant.DEFAULT_URI_PREFIX + SystemConstant.PREFIX_URL_CRM + "/analyse")
+public class CrmAnalyseController {
+
+
+    @Resource
+    CrmAnalyseService crmAnalyseService;
+
+    @Aac(auth = false)
+    @ApiOperation(value = "客户类型分布接口")
+    @RequestMapping(value = "/custom/type", method = RequestMethod.POST)
+    @ApiResponses({@ApiResponse(code = 200, message = "客户类型分布", response = Map.class)})
+    public Result customType(@ApiParam(value = "年度", required = true) @RequestParam String year) {
+        Map<String, Object> map = crmAnalyseService.countCustomType(year);
+
+        return ResultUtil.ok(map);
+    }
+
+    @Aac(auth = false)
+    @ApiOperation(value = "客户类型分布下钻接口")
+    @RequestMapping(value = "/custom/type/detail", method = RequestMethod.POST)
+    @ApiResponses({@ApiResponse(code = 200, message = "客户类型分布下钻", response = TBCrmResult.class)})
+    public Result customTypeDetail(@ApiParam(value = "年度", required = true) @RequestParam String year,
+                                   @ApiParam(value = "客户类型", required = true) @RequestParam ProductTypeEnum type,
+                                   @ApiParam(value = "分页页码", required = true) @RequestParam @Min(SystemConstant.PAGE_NUMBER_MIN) Integer pageNumber,
+                                   @ApiParam(value = "分页数", required = true) @RequestParam @Min(SystemConstant.PAGE_SIZE_MIN) @Max(SystemConstant.PAGE_SIZE_MAX) Integer pageSize) {
+        IPage<TBCrmResult> resultIPage = crmAnalyseService.customTypeDetail(new Page<>(pageNumber, pageSize), year, type);
+
+        return ResultUtil.ok(resultIPage);
+    }
+
+
+    @Aac(auth = false)
+    @ApiOperation(value = "月度派单分布及对比接口")
+    @RequestMapping(value = "/monthly", method = RequestMethod.POST)
+    @ApiResponses({@ApiResponse(code = 200, message = "月度派单分布及对比接口", response = Map.class)})
+    public Result monthly(@ApiParam(value = "年度", required = true) @RequestParam String year,
+                          @ApiParam(value = "客户类型", required = true) @RequestParam ProductTypeEnum type) {
+        Map<String, List<Map<String,String>>> map = crmAnalyseService.monthly(year, type);
+        return ResultUtil.ok(map);
+    }
+
+
+    @Aac(auth = false)
+    @ApiOperation(value = "月度派单分布下钻接口")
+    @RequestMapping(value = "/monthly/detail", method = RequestMethod.POST)
+    @ApiResponses({@ApiResponse(code = 200, message = "月度派单分布下钻", response = TBCrmResult.class)})
+    public Result monthlyDetail(@ApiParam(value = "年度", required = true) @RequestParam String year,
+                                @ApiParam(value = "月份", required = true) @RequestParam String month,
+                                @ApiParam(value = "客户类型", required = true) @RequestParam ProductTypeEnum type,
+                                @ApiParam(value = "分页页码", required = true) @RequestParam @Min(SystemConstant.PAGE_NUMBER_MIN) Integer pageNumber,
+                                @ApiParam(value = "分页数", required = true) @RequestParam @Min(SystemConstant.PAGE_SIZE_MIN) @Max(SystemConstant.PAGE_SIZE_MAX) Integer pageSize) {
+        IPage<TBCrmResult> resultIPage = crmAnalyseService.monthlyDetail(new Page<>(pageNumber, pageSize), year,month, type);
+
+        return ResultUtil.ok(resultIPage);
+    }
+
+    //供应商派单分布
+    @Aac(auth = false)
+    @ApiOperation(value = "供应商派单分布接口")
+    @RequestMapping(value = "/supplier", method = RequestMethod.POST)
+    @ApiResponses({@ApiResponse(code = 200, message = "供应商派单分布", response = CrmAnalyseResult.class)})
+    public Result supplier(@ApiParam(value = "年度", required = true) @RequestParam String year) {
+        List<CrmAnalyseResult> list = crmAnalyseService.supplier(year);
+        return ResultUtil.ok(list);
+    }
+
+    @Aac(auth = false)
+    @ApiOperation(value = "供应商派单分布下钻接口")
+    @RequestMapping(value = "/supplier/detail", method = RequestMethod.POST)
+    @ApiResponses({@ApiResponse(code = 200, message = "供应商派单分布下钻", response = TBCrmResult.class)})
+    public Result supplierDetail(@ApiParam(value = "年度", required = true) @RequestParam String year,
+                                @ApiParam(value = "供应商", required = true) @RequestParam Long supplierId,
+                                @ApiParam(value = "分页页码", required = true) @RequestParam @Min(SystemConstant.PAGE_NUMBER_MIN) Integer pageNumber,
+                                @ApiParam(value = "分页数", required = true) @RequestParam @Min(SystemConstant.PAGE_SIZE_MIN) @Max(SystemConstant.PAGE_SIZE_MAX) Integer pageSize) {
+        IPage<TBCrmResult> resultIPage = crmAnalyseService.supplierDetail(new Page<>(pageNumber, pageSize), year,supplierId);
+
+        return ResultUtil.ok(resultIPage);
+    }
+    //大区在执行派单排名
+    @Aac(auth = false)
+    @ApiOperation(value = "大区在执行派单排名接口")
+    @RequestMapping(value = "/region", method = RequestMethod.POST)
+    @ApiResponses({@ApiResponse(code = 200, message = "大区在执行派单排名", response = CrmAnalyseResult.class)})
+    public Result region(@ApiParam(value = "年度", required = true) @RequestParam String year,
+                         @ApiParam(value = "客户类型", required = true) @RequestParam ProductTypeEnum type) {
+        Map<String, List<CrmAnalyseResult>> map = crmAnalyseService.region(year,type);
+        return ResultUtil.ok(map);
+    }
+
+
+    //大区在执行派单排名
+    @Aac(auth = false)
+    @ApiOperation(value = "大区在执行派单排名下钻接口")
+    @RequestMapping(value = "/region/detail", method = RequestMethod.POST)
+    @ApiResponses({@ApiResponse(code = 200, message = "大区在执行派单排名下钻", response = CrmAnalyseResult.class)})
+    public Result regionDetail(@ApiParam(value = "年度", required = true) @RequestParam String year,
+                         @ApiParam(value = "大区", required = true) @RequestParam Long regionId,
+                         @ApiParam(value = "客户类型", required = true) @RequestParam ProductTypeEnum type,
+                         @ApiParam(value = "分页页码", required = true) @RequestParam @Min(SystemConstant.PAGE_NUMBER_MIN) Integer pageNumber,
+                         @ApiParam(value = "分页数", required = true) @RequestParam @Min(SystemConstant.PAGE_SIZE_MIN) @Max(SystemConstant.PAGE_SIZE_MAX) Integer pageSize) {
+        IPage<TBCrmResult> resultIPage = crmAnalyseService.regionDetail(new Page<>(pageNumber, pageSize), year,regionId,type);
+
+        return ResultUtil.ok(resultIPage);
+    }
+
+
+    //项目派单完成率
+    @Aac(auth = false)
+    @ApiOperation(value = "项目派单完成率接口")
+    @RequestMapping(value = "/project", method = RequestMethod.POST)
+    @ApiResponses({@ApiResponse(code = 200, message = "项目派单完成率", response = CrmAnalyseResult.class)})
+    public Result project(@ApiParam(value = "年度", required = true) @RequestParam String year) {
+        List<CrmAnalyseResult> list = crmAnalyseService.project(year);
+        return ResultUtil.ok(list);
+    }
+
+    //项目派单完成率详细
+    @Aac(auth = false)
+    @ApiOperation(value = "项目派单完成率详细接口")
+    @RequestMapping(value = "/project/detail", method = RequestMethod.POST)
+    @ApiResponses({@ApiResponse(code = 200, message = "项目派单完成率详细", response = CrmAnalyseResult.class)})
+    public Result projectDetail(@ApiParam(value = "年度", required = true) @RequestParam String year,
+                          @ApiParam(value = "服务单元", required = true) @RequestParam Long serviceId,
+                          @ApiParam(value = "分页页码", required = true) @RequestParam @Min(SystemConstant.PAGE_NUMBER_MIN) Integer pageNumber,
+                          @ApiParam(value = "分页数", required = true) @RequestParam @Min(SystemConstant.PAGE_SIZE_MIN) @Max(SystemConstant.PAGE_SIZE_MAX) Integer pageSize) {
+        IPage<TBCrmResult> resultIPage = crmAnalyseService.projectDetail(new Page<>(pageNumber, pageSize), year,serviceId);
+
+        return ResultUtil.ok(resultIPage);
+    }
+
+
+
+}

+ 51 - 0
sop-business/src/main/java/com/qmth/sop/business/bean/result/CrmAnalyseResult.java

@@ -0,0 +1,51 @@
+package com.qmth.sop.business.bean.result;
+
+import com.fasterxml.jackson.databind.annotation.JsonSerialize;
+import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
+import io.swagger.annotations.ApiModelProperty;
+
+import java.io.Serializable;
+
+/**
+ * @Description:
+ * @Param:
+ * @return:
+ * @Author: dhshu
+ */
+public class CrmAnalyseResult implements Serializable {
+
+    @ApiModelProperty(value = "id")
+    @JsonSerialize(using = ToStringSerializer.class)
+    Long id;
+
+    @ApiModelProperty(value = "name")
+    String name;
+
+    @ApiModelProperty(value = "count")
+    String count;
+
+
+    public Long getId() {
+        return id;
+    }
+
+    public void setId(Long id) {
+        this.id = id;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public String getCount() {
+        return count;
+    }
+
+    public void setCount(String count) {
+        this.count = count;
+    }
+}

+ 22 - 0
sop-business/src/main/java/com/qmth/sop/business/bean/result/TBCrmResult.java

@@ -33,6 +33,12 @@ public class TBCrmResult extends TBCrm implements Serializable {
     @ApiModelProperty(value = "服务单元状态")
     private ServiceStatusEnum serviceUnitStatus;
 
+    @ApiModelProperty(value = "区域协调人")
+    private String regionCoordinator;
+
+    @ApiModelProperty(value = "供应商")
+    private String supplier;
+
     public String getService() {
         return service;
     }
@@ -96,4 +102,20 @@ public class TBCrmResult extends TBCrm implements Serializable {
     public void setServiceUnitStatus(ServiceStatusEnum serviceUnitStatus) {
         this.serviceUnitStatus = serviceUnitStatus;
     }
+
+    public String getRegionCoordinator() {
+        return regionCoordinator;
+    }
+
+    public void setRegionCoordinator(String regionCoordinator) {
+        this.regionCoordinator = regionCoordinator;
+    }
+
+    public String getSupplier() {
+        return supplier;
+    }
+
+    public void setSupplier(String supplier) {
+        this.supplier = supplier;
+    }
 }

+ 55 - 0
sop-business/src/main/java/com/qmth/sop/business/mapper/CrmAnalyseMapper.java

@@ -0,0 +1,55 @@
+package com.qmth.sop.business.mapper;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.qmth.sop.business.bean.result.CrmAnalyseResult;
+import com.qmth.sop.business.bean.result.TBCrmResult;
+import com.qmth.sop.business.entity.TBCrm;
+import org.apache.ibatis.annotations.Param;
+
+import java.util.List;
+import java.util.Map;
+
+/**
+ * <p>
+ * </p>
+ *
+ * @author dhshu
+ *
+ */
+public interface CrmAnalyseMapper extends BaseMapper<TBCrm> {
+
+
+    Map<String,Object> countCustomType(@Param("year") String year);
+
+    IPage<TBCrmResult> crmDetail(Page<Object> iPage, @Param("year") String year, @Param("month") String month, @Param("crmYear") String crmYear, @Param("type") String type,@Param("supplierId") Long supplierId,@Param("regionId") Long regionId,@Param("serviceId") Long serviceId);
+
+    default IPage<TBCrmResult> crmDetail(Page<Object> iPage,String year, String type) {
+        return crmDetail(iPage,year,null,null,type,null,null,null);
+    }
+
+    List<Map<String,String>> monthly(@Param("year") String year,@Param("type") String type);
+
+    default IPage<TBCrmResult> crmDetail(Page<Object> iPage, String year, String month, String type) {
+        return crmDetail(iPage,year,month,null,type,null,null,null);
+    }
+
+    List<CrmAnalyseResult> supplier(@Param("year") String year);
+
+    default IPage<TBCrmResult> crmDetail(Page<Object> iPage, String year,  Long supplierId) {
+        return crmDetail(iPage,null,null,year,null,supplierId,null,null);
+    }
+
+    List<CrmAnalyseResult> region(@Param("year") String year, @Param("type") String type);
+
+    default IPage<TBCrmResult> crmDetail(Page<Object> iPage,  String year, Long regionId, String type) {
+        return crmDetail(iPage,year,null,null,type,null,regionId,null);
+    }
+
+    default IPage<TBCrmResult> crmDetail(Page<Object> iPage, Long serviceId, String year) {
+        return crmDetail(iPage,year,null,null,null,null,null,serviceId);
+    }
+
+    List<CrmAnalyseResult> project(@Param("year") String year);
+}

+ 39 - 0
sop-business/src/main/java/com/qmth/sop/business/service/CrmAnalyseService.java

@@ -0,0 +1,39 @@
+package com.qmth.sop.business.service;
+
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.baomidou.mybatisplus.extension.service.IService;
+import com.qmth.sop.business.bean.result.TBCrmResult;
+import com.qmth.sop.business.bean.result.CrmAnalyseResult;
+import com.qmth.sop.business.entity.TBCrm;
+import com.qmth.sop.common.enums.ProductTypeEnum;
+
+import java.util.List;
+import java.util.Map;
+
+
+/**
+ * @author dhshu
+ * @date:
+ */
+public interface CrmAnalyseService extends IService<TBCrm> {
+    Map<String,Object> countCustomType(String year);
+
+    IPage<TBCrmResult> customTypeDetail(Page<Object> objectPage, String year, ProductTypeEnum type);
+
+    Map<String, List<Map<String,String>>> monthly(String year, ProductTypeEnum type);
+
+    IPage<TBCrmResult> monthlyDetail(Page<Object> objectPage, String year, String month, ProductTypeEnum type);
+
+    List<CrmAnalyseResult> supplier(String year);
+
+    IPage<TBCrmResult> supplierDetail(Page<Object> objectPage, String year, Long supplierId);
+
+    Map<String, List<CrmAnalyseResult>> region(String year, ProductTypeEnum type);
+
+    IPage<TBCrmResult> regionDetail(Page<Object> objectPage, String year, Long regionId, ProductTypeEnum type);
+
+    List<CrmAnalyseResult> project(String year);
+
+    IPage<TBCrmResult> projectDetail(Page<Object> objectPage, String year, Long serviceId);
+}

+ 83 - 0
sop-business/src/main/java/com/qmth/sop/business/service/impl/CrmAnalyseServiceImpl.java

@@ -0,0 +1,83 @@
+package com.qmth.sop.business.service.impl;
+
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.qmth.sop.business.bean.result.CrmAnalyseResult;
+import com.qmth.sop.business.bean.result.TBCrmResult;
+import com.qmth.sop.business.entity.TBCrm;
+import com.qmth.sop.business.mapper.CrmAnalyseMapper;
+import com.qmth.sop.business.service.CrmAnalyseService;
+import com.qmth.sop.common.enums.ProductTypeEnum;
+import org.springframework.stereotype.Service;
+
+import java.time.LocalDate;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+
+
+/**
+ * @author dhshu
+ * @date:
+ */
+@Service
+public class CrmAnalyseServiceImpl extends ServiceImpl<CrmAnalyseMapper, TBCrm> implements CrmAnalyseService {
+
+    @Override
+    public Map<String,Object> countCustomType(String year) {
+        return this.baseMapper.countCustomType(year);
+    }
+
+    @Override
+    public IPage<TBCrmResult> customTypeDetail(Page<Object> iPage, String year, ProductTypeEnum type) {
+        return this.baseMapper.crmDetail(iPage,year, Objects.nonNull(type) ? type.name() : null);
+    }
+
+    @Override
+    public  Map<String, List<Map<String,String>>> monthly(String year, ProductTypeEnum type) {
+        Map<String, List<Map<String,String>>> map=new HashMap<>();
+        map.put("year",this.baseMapper.monthly(year, Objects.nonNull(type) ? type.name() : null));
+        map.put("lastYear",this.baseMapper.monthly(String.valueOf(Integer.parseInt(year)-1), Objects.nonNull(type) ? type.name() : null));
+        return map;
+    }
+
+    @Override
+    public IPage<TBCrmResult> monthlyDetail(Page<Object> iPage, String year, String month, ProductTypeEnum type) {
+        return this.baseMapper.crmDetail(iPage,year,month, Objects.nonNull(type) ? type.name() : null);
+    }
+
+    @Override
+    public List<CrmAnalyseResult> supplier(String year) {
+        return this.baseMapper.supplier(year);
+    }
+
+    @Override
+    public IPage<TBCrmResult> supplierDetail(Page<Object> iPage, String year, Long supplierId) {
+        return this.baseMapper.crmDetail(iPage,year, supplierId);
+    }
+
+    @Override
+    public Map<String,  List<CrmAnalyseResult>> region(String year, ProductTypeEnum type) {
+        Map<String,  List<CrmAnalyseResult>> map=new HashMap<>();
+        map.put("day",this.baseMapper.region(year,Objects.nonNull(type) ? type.name() : null));
+        map.put("lastDay",this.baseMapper.region(String.valueOf(Integer.parseInt(year)-1),Objects.nonNull(type) ? type.name() : null));
+        return map;
+    }
+
+    @Override
+    public IPage<TBCrmResult> regionDetail(Page<Object> iPage, String year, Long regionId, ProductTypeEnum type) {
+        return this.baseMapper.crmDetail(iPage,year,regionId,Objects.nonNull(type) ? type.name() : null);
+    }
+
+    @Override
+    public List<CrmAnalyseResult> project(String year) {
+        return this.baseMapper.project(year);
+    }
+
+    @Override
+    public IPage<TBCrmResult> projectDetail(Page<Object> iPage, String year, Long serviceId) {
+        return this.baseMapper.crmDetail(iPage,serviceId,year);
+    }
+}

+ 162 - 0
sop-business/src/main/resources/mapper/CrmAnalyseMapper.xml

@@ -0,0 +1,162 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.qmth.sop.business.mapper.CrmAnalyseMapper">
+    <select id="region" resultType="com.qmth.sop.business.bean.result.CrmAnalyseResult">
+        SELECT
+        r.id,
+        d.province name,
+        count( c.id ) count
+        FROM
+        t_b_crm c
+        LEFT JOIN sys_custom cu ON cu.id = c.custom_id
+        LEFT JOIN t_b_service s ON c.service_id = s.id
+        left join t_b_service_region r on r.service_id=s.id
+        left join t_b_service_region_detail d on d.service_region_id=r.id
+        <where>
+            and s.`status`='PUBLISH' and c.service_id is not null and r.id is not null
+            <if test="type != null and type != ''">
+                and cu.type = #{type}
+            </if>
+            <if test="year != null and year != ''">
+                and YEAR ( FROM_UNIXTIME( s.start_time / 1000 ))=  #{year}
+            </if>
+        </where>
+        GROUP BY
+        r.id,
+        d.province
+        order by count( c.id )
+    </select>
+    <select id="project" resultType="com.qmth.sop.business.bean.result.CrmAnalyseResult">
+        SELECT
+        s.id,
+        s.`name`,
+        sum(case when c.`status`='FINISH' then 1 else 0 end)/count( c.id )  count
+        FROM
+        t_b_crm c
+        LEFT JOIN sys_custom cu ON cu.id = c.custom_id
+        LEFT JOIN t_b_service s ON c.service_id = s.id
+        <where>
+            s.`status` IN ( 'PUBLISH', 'FINISH' )
+            <if test="year != null and year != ''">
+                and YEAR ( FROM_UNIXTIME( s.start_time / 1000 ))=  #{year}
+            </if>
+        </where>
+        GROUP BY
+        s.id,
+        s.`name`
+    </select>
+
+    <select id="supplier" resultType="com.qmth.sop.business.bean.result.CrmAnalyseResult">
+        SELECT
+        su.id,
+        su.`name`,
+        count( c.id ) count
+        FROM
+        t_b_crm c
+        LEFT JOIN t_b_service s ON c.service_id = s.id
+        LEFT JOIN sys_user u ON u.id = c.region_coordinator_id
+        LEFT JOIN t_b_user_archives ua ON u.mobile_number = ua.mobile_number
+        LEFT JOIN t_b_user_archives_supplier us ON us.user_archives_id = ua.id
+        LEFT JOIN sys_supplier su ON su.id = us.supplier_id
+        <where>
+            and c.region_coordinator_id IS NOT NULL
+            <if test="year != null and year != ''">
+                and YEAR ( FROM_UNIXTIME( s.start_time / 1000 ))=  #{year}
+            </if>
+        </where>
+        GROUP BY
+        su.id,
+        su.`name`
+
+    </select>
+
+    <select id="monthly" resultType="java.util.Map">
+        SELECT MONTH ( FROM_UNIXTIME( s.start_time / 1000 )) month,
+        count( c.id ) count
+        FROM
+        t_b_crm c
+        LEFT JOIN t_b_service s ON c.service_id = s.id
+        LEFT JOIN sys_custom cu ON cu.id = c.custom_id
+        <where>
+            <if test="type != null and type != ''">
+                and cu.type = #{type}
+            </if>
+
+            <if test="year != null and year != ''">
+                and YEAR ( FROM_UNIXTIME( s.start_time / 1000 ))=  #{year}
+            </if>
+
+        </where>
+        GROUP BY MONTH ( FROM_UNIXTIME( s.start_time / 1000 ))
+        order BY MONTH ( FROM_UNIXTIME( s.start_time / 1000 ))
+    </select>
+
+
+    <select id="countCustomType" resultType="java.util.Map">
+        SELECT
+        sum(case when cu.type='OFFICE' then 1 else 0 end) as OFFICE,
+        sum(case when cu.type='CLOUD_MARK' then 1 else 0 end) as CLOUD_MARK
+        FROM
+        t_b_crm c
+        LEFT JOIN t_b_service s ON c.service_id = s.id
+        LEFT join sys_custom cu on cu.id=c.custom_id
+        WHERE
+        YEAR ( FROM_UNIXTIME( s.start_time / 1000 ))=  #{year}
+    </select>
+
+
+    <select id="crmDetail" resultType="com.qmth.sop.business.bean.result.TBCrmResult">
+        SELECT
+        a.*,
+        tbs.name service,
+        cru.real_name crm_user_name,
+        sc.NAME custom,
+        sc.type custom_type,
+        p.name product,
+        lu.real_name leadName,
+        cu.real_name createName,
+        tbs.status serviceUnitStatus,
+        u.real_name regionCoordinator,
+        su.name supplier
+        FROM
+        t_b_crm a
+        LEFT JOIN sys_user cru ON cru.id = a.crm_user_id
+        LEFT JOIN sys_user lu ON lu.id = a.lead_id
+        LEFT JOIN sys_user cu ON cu.id = a.create_id
+        LEFT JOIN t_b_product p ON p.id = a.product_id
+        LEFT JOIN t_b_service tbs ON a.service_id = tbs.id
+        left join t_b_service_region r on r.service_id=tbs.id
+        LEFT JOIN sys_custom sc ON sc.id = a.custom_id
+
+        LEFT JOIN sys_user u ON u.id = a.region_coordinator_id
+        LEFT JOIN t_b_user_archives ua ON u.mobile_number = ua.mobile_number
+        LEFT JOIN t_b_user_archives_supplier us ON us.user_archives_id = ua.id
+        LEFT JOIN sys_supplier su ON su.id = us.supplier_id
+        <where>
+            <if test="serviceId != null and serviceId != ''">
+                and a.service_id = #{serviceId}
+            </if>
+            <if test="regionId != null and regionId != ''">
+                and r.id = #{regionId}
+            </if>
+            <if test="type != null and type != ''">
+                and sc.type = #{type}
+            </if>
+            <if test="supplierId != null and supplierId != ''">
+                and su.id = #{supplierId}
+            </if>
+            <if test="year != null and year != ''">
+                and YEAR ( FROM_UNIXTIME( tbs.start_time / 1000 ))=  #{year}
+            </if>
+            <if test="crmYear != null and crmYear != ''">
+                and YEAR ( FROM_UNIXTIME( a.begin_time / 1000 ))=  #{crmYear}
+            </if>
+            <if test="month != null and month != ''">
+                and MONTH ( FROM_UNIXTIME( tbs.start_time / 1000 ))=  #{month}
+            </if>
+        </where>
+
+        ORDER BY
+        a.create_time DESC
+    </select>
+</mapper>