shudonghui 1 年之前
父節點
當前提交
5634868036

+ 3 - 1
sop-api/src/main/java/com/qmth/sop/server/api/CrmAnalyseController.java

@@ -72,9 +72,11 @@ public class CrmAnalyseController {
     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 Long startTime,
+                                @ApiParam(value = "结束时间", required = true) @RequestParam Long endTime,
                                 @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) {
-        return ResultUtil.ok(crmAnalyseService.monthlyDetail(new Page<>(pageNumber, pageSize), year, month, type));
+        return ResultUtil.ok(crmAnalyseService.monthlyDetail(new Page<>(pageNumber, pageSize), year, month, type,startTime,endTime));
     }
 
     //供应商派单分布

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

@@ -30,10 +30,10 @@ public interface CrmAnalyseMapper extends BaseMapper<TBCrm> {
     }
 
     @SuppressWarnings("MybatisXMapperMethodInspection")
-    List<Map<String, String>> monthly(@Param("startTime") Long startTime, @Param("endTime") Long endTime, @Param("type") String type, @Param("dpr") DataPermissionDto dpr);
+    List<Map<String, Object>> monthly(@Param("startTime") Long startTime, @Param("endTime") Long endTime, @Param("type") String type, @Param("dpr") DataPermissionDto dpr);
 
-    default IPage<TBCrmResult> crmDetail(Page<Object> iPage, String year, String month, String type, DataPermissionDto dpr) {
-        return crmDetail(iPage, null, null, month, year, type, null, null, null, dpr);
+    default IPage<TBCrmResult> crmDetail(Page<Object> iPage, String year, String month, String type, Long startTime, Long endTime, DataPermissionDto dpr) {
+        return crmDetail(iPage, startTime, endTime, month, year, type, null, null, null, dpr);
     }
 
     List<CrmAnalyseResult> supplier(@Param("startTime") Long startTime, @Param("endTime") Long endTime, @Param("dpr") DataPermissionDto dpr);

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

@@ -21,9 +21,9 @@ public interface CrmAnalyseService extends IService<TBCrm> {
 
     IPage<TBCrmResult> customTypeDetail(Page<Object> objectPage, Long startTime, Long endTime, ProductTypeEnum type);
 
-    Map<String, List<Map<String, String>>> monthly(Long startTime, Long endTime, ProductTypeEnum type);
+    Map<String, List<Map<String, Object>>> monthly(Long startTime, Long endTime, ProductTypeEnum type);
 
-    IPage<TBCrmResult> monthlyDetail(Page<Object> objectPage, String year, String month, ProductTypeEnum type);
+    IPage<TBCrmResult> monthlyDetail(Page<Object> objectPage, String year, String month, ProductTypeEnum type, Long startTime, Long endTime);
 
     List<CrmAnalyseResult> supplier(Long startTime, Long endTime);
 

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

@@ -45,20 +45,20 @@ public class CrmAnalyseServiceImpl extends ServiceImpl<CrmAnalyseMapper, TBCrm>
     }
 
     @Override
-    public Map<String, List<Map<String, String>>> monthly(Long startTime, Long endTime, ProductTypeEnum type) {
+    public Map<String, List<Map<String, Object>>> monthly(Long startTime, Long endTime, ProductTypeEnum type) {
         SysUser requestUser = (SysUser) ServletUtil.getRequestUser();
         DataPermissionDto dpr = sysUserService.buildUserDataPermission(requestUser.getId());
-        Map<String, List<Map<String, String>>> map = new HashMap<>();
+        Map<String, List<Map<String, Object>>> map = new HashMap<>();
         map.put("year", this.baseMapper.monthly(startTime, endTime, Objects.nonNull(type) ? type.name() : null, dpr));
         map.put("lastYear", this.baseMapper.monthly(startTime - 365 * 24 * 60 * 60 * 1000L, endTime - 365 * 24 * 60 * 60 * 1000L, Objects.nonNull(type) ? type.name() : null, dpr));
         return map;
     }
 
     @Override
-    public IPage<TBCrmResult> monthlyDetail(Page<Object> iPage, String year, String month, ProductTypeEnum type) {
+    public IPage<TBCrmResult> monthlyDetail(Page<Object> iPage, String year, String month, ProductTypeEnum type, Long startTime, Long endTime) {
         SysUser requestUser = (SysUser) ServletUtil.getRequestUser();
         DataPermissionDto dpr = sysUserService.buildUserDataPermission(requestUser.getId());
-        return this.baseMapper.crmDetail(iPage, year, month, Objects.nonNull(type) ? type.name() : null, dpr);
+        return this.baseMapper.crmDetail(iPage, year, month, Objects.nonNull(type) ? type.name() : null,startTime,endTime, dpr);
     }
 
     @Override

+ 26 - 61
sop-business/src/main/resources/mapper/CrmAnalyseMapper.xml

@@ -41,7 +41,7 @@
         left join t_b_service_region r on r.service_id=s.id
         left join t_b_service_region_detail rd on rd.service_region_id=r.id
         <where>
-           and  s.`status` IN ( 'PUBLISH', 'FINISH' ) and c.service_id is not null and r.id is not null
+            and s.`status` IN ( 'PUBLISH', 'FINISH' ) and c.service_id is not null and r.id is not null
             <if test="type != null and type != ''">
                 and cu.type = #{type}
             </if>
@@ -66,35 +66,6 @@
         order by count(DISTINCT c.id ) desc
     </select>
     <select id="project" resultType="java.util.Map">
-        <!--        SELECT-->
-        <!--        s.id,-->
-        <!--        s.`name`,-->
-        <!--        sum(case when c.`status`='FINISH' then 1 else 0 end)/count( c.id ) count-->
-        <!--        FROM-->
-        <!--        t_b_service s-->
-        <!--        LEFT JOIN t_b_crm c ON c.service_id = s.id-->
-        <!--        LEFT JOIN sys_custom cu ON cu.id = c.custom_id-->
-        <!--        <where>-->
-        <!--            s.`status` IN ( 'PUBLISH', 'FINISH' ) and c.status is not null-->
-        <!--            &lt;!&ndash;            <if test="year != null and year != ''">&ndash;&gt;-->
-        <!--            &lt;!&ndash;                and YEAR ( FROM_UNIXTIME( s.start_time / 1000 ))=  #{year}&ndash;&gt;-->
-        <!--            &lt;!&ndash;            </if>&ndash;&gt;-->
-        <!--            <if test="startTime != null">-->
-        <!--                AND s.start_time <![CDATA[ >= ]]> #{startTime}-->
-        <!--            </if>-->
-        <!--            <if test="endTime != null">-->
-        <!--                AND s.start_time <![CDATA[ <= ]]> #{endTime}-->
-        <!--            </if>-->
-        <!--            <if test="dpr != null and !dpr.hasAdmin and !dpr.hasPmo">-->
-        <!--                <if test="dpr.hasBusiness">-->
-        <!--                    AND s.service_lead_id = #{dpr.requestUserId}-->
-        <!--                </if>-->
-        <!--            </if>-->
-        <!--        </where>-->
-        <!--        GROUP BY-->
-        <!--        s.id,-->
-        <!--        s.`name`-->
-
 
         SELECT
         s.id,
@@ -112,6 +83,7 @@
 
         <where>
             s.`status` IN ( 'PUBLISH', 'FINISH' ) and c.crm_no is not null
+            and c.service_id is not null and c.enable=1
             <!--            <if test="year != null and year != ''">-->
             <!--                and YEAR ( FROM_UNIXTIME( s.start_time / 1000 ))=  #{year}-->
             <!--            </if>-->
@@ -147,6 +119,7 @@
             <!--                and YEAR ( FROM_UNIXTIME( s.start_time / 1000 ))=  #{year}-->
             <!--            </if>-->
             and su.id is not null
+            and s.`status` IN ( 'PUBLISH', 'FINISH' ) and c.service_id is not null and c.enable=1
             <if test="startTime != null">
                 AND s.start_time >= #{startTime}
             </if>
@@ -166,25 +139,27 @@
     </select>
 
     <select id="monthly" resultType="java.util.Map">
-        SELECT YEAR
+        SELECT
+        a.year,
+        a.month ,
+        count(DISTINCT a.id) count
+        FROM
         (
-        FROM_UNIXTIME( c.begin_time / 1000 )) year,
+        SELECT DISTINCT
+        CAST( YEAR ( FROM_UNIXTIME( c.begin_time / 1000 )) AS CHAR ) YEAR,
         MONTH (
-        FROM_UNIXTIME( c.begin_time / 1000 )) month,
-        count(DISTINCT c.id ) count
+        FROM_UNIXTIME( c.begin_time / 1000 )) MONTH,
+        c.id
         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>
-            and s.`status` IN ( 'PUBLISH', 'FINISH' ) and c.service_id is not null
+            and s.`status` IN ( 'PUBLISH', 'FINISH' ) and c.service_id is not null and c.enable=1
             <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>-->
             <if test="startTime != null">
                 AND s.start_time >= #{startTime}
             </if>
@@ -197,16 +172,14 @@
                 </if>
             </if>
         </where>
+        ) a
         GROUP BY
-        YEAR (
-        FROM_UNIXTIME( c.begin_time / 1000 )),
-        MONTH (
-        FROM_UNIXTIME( c.begin_time / 1000 ))
+        a.YEAR,
+        a.MONTH
         ORDER BY
-        YEAR (
-        FROM_UNIXTIME( c.begin_time / 1000 )),
-        MONTH (
-        FROM_UNIXTIME( c.begin_time / 1000 ))
+        a.YEAR,
+        a.MONTH
+
     </select>
 
 
@@ -217,12 +190,10 @@
         FROM t_b_service s
         LEFT JOIN t_b_crm c 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}-->
+
         <where>
-            <!--            <if test="year != null and year != ''">-->
-            <!--                and YEAR ( FROM_UNIXTIME( s.start_time / 1000 ))=  #{year}-->
-            <!--            </if>-->
+
+            and s.`status` IN ( 'PUBLISH', 'FINISH' ) and c.service_id is not null and c.enable=1
             <if test="startTime != null">
                 AND s.start_time <![CDATA[ >= ]]> #{startTime}
             </if>
@@ -267,16 +238,16 @@
         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 tbs.`status` IN ( 'PUBLISH', 'FINISH' ) and a.service_id is not null and a.enable=1
             <if test="serviceId != null and serviceId != ''">
-                tbs.`status` IN ( 'PUBLISH', 'FINISH' ) and a.crm_no is not null
+                and a.crm_no is not null
                 and a.service_id = #{serviceId}
             </if>
             <!--            <if test="regionId != null and regionId != ''">-->
             <!--                and r.id = #{regionId}-->
             <!--            </if>-->
             <if test="province != null and province != ''">
-                and tbs.`status` IN ( 'PUBLISH', 'FINISH' ) and a.service_id is not null and r.id is not null
+                and r.id is not null
                 and rd.province = #{province}
             </if>
             <if test="type != null and type != ''">
@@ -285,12 +256,6 @@
             <if test="supplierId != null and supplierId != ''">
                 and su.id = #{supplierId}
             </if>
-            <!--            <if test="supplierId == null or supplierId = ''">-->
-            <!--                and su.id is null-->
-            <!--            </if>-->
-            <!--            <if test="year != null and year != ''">-->
-            <!--                and YEAR ( FROM_UNIXTIME( tbs.start_time / 1000 ))=  #{year}-->
-            <!--            </if>-->
             <if test="startTime != null">
                 AND tbs.start_time <![CDATA[ >= ]]> #{startTime}
             </if>
@@ -303,7 +268,6 @@
                 </if>
             </if>
             <if test="crmYear != null and crmYear != ''">
-                and tbs.`status` IN ( 'PUBLISH', 'FINISH' ) and a.service_id is not null
                 and YEAR (FROM_UNIXTIME( a.begin_time / 1000))= #{crmYear}
             </if>
             <if test="month != null and month != ''">
@@ -322,6 +286,7 @@
         LEFT JOIN t_b_crm c ON c.service_id = s.id
         LEFT JOIN t_b_user_archives_allocation a ON a.service_id = s.id
         <where>
+            and s.`status` IN ( 'PUBLISH', 'FINISH' ) and c.service_id is not null and c.enable=1
             <if test="startTime != null">
                 AND s.start_time >= #{startTime}
             </if>