|
@@ -2,4 +2,193 @@
|
|
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
|
<!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.TBUserArchivesAllocationMapper">
|
|
<mapper namespace="com.qmth.sop.business.mapper.TBUserArchivesAllocationMapper">
|
|
|
|
|
|
|
|
+ <select id="findCrmAllocationPage"
|
|
|
|
+ resultType="com.qmth.sop.business.bean.result.UserArchivesAllocationResult">
|
|
|
|
+ SELECT
|
|
|
|
+ *,
|
|
|
|
+ (result.coordinatorUnDistributed + result.effectUnDistributed + result.assistantUnDistributed) AS unDistributed
|
|
|
|
+ FROM
|
|
|
|
+ (SELECT
|
|
|
|
+ tbs.id AS serviceUnitId,
|
|
|
|
+ tbs.name AS serviceUnitName,
|
|
|
|
+ tbc.id AS crmId,
|
|
|
|
+ tbc.crm_no AS crmNo,
|
|
|
|
+ su.id AS customId,
|
|
|
|
+ su.name AS customName,
|
|
|
|
+ su.type AS customType,
|
|
|
|
+ su.province AS province,
|
|
|
|
+ su.city AS city,
|
|
|
|
+ su.area AS area,
|
|
|
|
+ sl.id AS levelId,
|
|
|
|
+ sl.level AS level,
|
|
|
|
+ 1 AS coordinatorQuota,
|
|
|
|
+ IFNULL(effectQ.quota, 0) AS effectQuota,
|
|
|
|
+ IFNULL(assistantQ.quota, 0) AS assistantQuota,
|
|
|
|
+ IFNULL(coordinatorR.reality, 0) AS coordinatorDistributed,
|
|
|
|
+ IFNULL(effectR.reality, 0) AS effectDistributed,
|
|
|
|
+ IFNULL(assistantR.reality, 0) AS assistantDistributed,
|
|
|
|
+ 1 + IFNULL(effectQ.quota, 0) + IFNULL(assistantQ.quota, 0) AS quota,
|
|
|
|
+ IFNULL(coordinatorR.reality, 0) + IFNULL(effectR.reality, 0) + IFNULL(assistantR.reality, 0) AS distributed,
|
|
|
|
+ IF(1 - IFNULL(coordinatorR.reality, 0) < 0, 0, 1 - IFNULL(coordinatorR.reality, 0)) AS coordinatorUnDistributed,
|
|
|
|
+ IF(IFNULL(effectQ.quota, 0) - IFNULL(effectR.reality, 0) < 0, 0, IFNULL(effectQ.quota, 0) - IFNULL(effectR.reality, 0)) AS effectUnDistributed,
|
|
|
|
+ IF(IFNULL(assistantQ.quota, 0) - IFNULL(assistantR.reality, 0) < 0, 0, IFNULL(assistantQ.quota, 0) - IFNULL(assistantR.reality, 0)) AS assistantUnDistributed,
|
|
|
|
+ IFNULL(coordinatorR.publish, FALSE) AS publish
|
|
|
|
+ FROM
|
|
|
|
+ t_b_crm tbc
|
|
|
|
+ LEFT JOIN t_b_service tbs ON tbc.service_id = tbs.id
|
|
|
|
+ LEFT JOIN sys_custom su ON tbc.custom_id = su.id
|
|
|
|
+ LEFT JOIN sys_level sl ON su.level_id = sl.id
|
|
|
|
+ LEFT JOIN (SELECT
|
|
|
|
+ slr.quota, slr.level_id
|
|
|
|
+ FROM
|
|
|
|
+ sys_level_role slr
|
|
|
|
+ LEFT JOIN sys_role sr ON sr.id = slr.role_id
|
|
|
|
+ WHERE
|
|
|
|
+ sr.type = 'EFFECT_ENGINEER') effectQ ON effectQ.level_id = sl.id
|
|
|
|
+ LEFT JOIN (SELECT
|
|
|
|
+ slr.quota, slr.level_id
|
|
|
|
+ FROM
|
|
|
|
+ sys_level_role slr
|
|
|
|
+ LEFT JOIN sys_role sr ON sr.id = slr.role_id
|
|
|
|
+ WHERE
|
|
|
|
+ sr.type = 'ASSISTANT_ENGINEER') assistantQ ON assistantQ.level_id = sl.id
|
|
|
|
+ LEFT JOIN (SELECT
|
|
|
|
+ crm_no,
|
|
|
|
+ MAX(IF(region_user_id IS NULL, 0, 1)) AS reality,
|
|
|
|
+ MAX(IF(sop_no IS NULL, FALSE, TRUE)) AS publish
|
|
|
|
+ FROM
|
|
|
|
+ t_b_user_archives_allocation) coordinatorR ON coordinatorR.crm_no = tbc.crm_no
|
|
|
|
+ LEFT JOIN (SELECT
|
|
|
|
+ tbuaa.crm_no, COUNT(*) AS reality
|
|
|
|
+ FROM
|
|
|
|
+ t_b_user_archives_allocation tbuaa
|
|
|
|
+ LEFT JOIN sys_role sr ON sr.id = tbuaa.role_id
|
|
|
|
+ WHERE
|
|
|
|
+ sr.type = 'EFFECT_ENGINEER'
|
|
|
|
+ GROUP BY tbuaa.crm_no) effectR ON effectR.crm_no = tbc.crm_no
|
|
|
|
+ LEFT JOIN (SELECT
|
|
|
|
+ tbuaa.crm_no, COUNT(*) AS reality
|
|
|
|
+ FROM
|
|
|
|
+ t_b_user_archives_allocation tbuaa
|
|
|
|
+ LEFT JOIN sys_role sr ON sr.id = tbuaa.role_id
|
|
|
|
+ WHERE
|
|
|
|
+ sr.type = 'ASSISTANT_ENGINEER'
|
|
|
|
+ GROUP BY tbuaa.crm_no) assistantR ON assistantR.crm_no = tbc.crm_no
|
|
|
|
+ WHERE tbs.status != 'CANCEL') result
|
|
|
|
+ <where>
|
|
|
|
+ <if test="serviceUnitId != null">
|
|
|
|
+ AND result.serviceUnitId = #{serviceUnitId}
|
|
|
|
+ </if>
|
|
|
|
+ <if test="province != null and province != ''">
|
|
|
|
+ AND result.province CONCAT('%',#{province},'%')
|
|
|
|
+ </if>
|
|
|
|
+ <if test="city != null and city != ''">
|
|
|
|
+ AND result.city CONCAT('%',#{city},'%')
|
|
|
|
+ </if>
|
|
|
|
+ <if test="area != null and area != ''">
|
|
|
|
+ AND result.area CONCAT('%',#{area},'%')
|
|
|
|
+ </if>
|
|
|
|
+ <if test="customName != null and customName != ''">
|
|
|
|
+ AND result.customName CONCAT('%',#{customName}.'%')
|
|
|
|
+ </if>
|
|
|
|
+ <if test="gap != null">
|
|
|
|
+ AND (result.coordinatorUnDistributed + result.effectUnDistributed + result.assistantUnDistributed) <= #{gap}
|
|
|
|
+ </if>
|
|
|
|
+ </where>
|
|
|
|
+ ORDER BY result.serviceUnitId DESC, result.crmId DESC
|
|
|
|
+ </select>
|
|
|
|
+ <select id="findCrmAllocationSubTotal"
|
|
|
|
+ resultType="com.qmth.sop.business.bean.result.UserArchivesAllocationResult">
|
|
|
|
+ SELECT
|
|
|
|
+ *,
|
|
|
|
+ (result.coordinatorUnDistributed + result.effectUnDistributed + result.assistantUnDistributed) AS unDistributed
|
|
|
|
+ FROM
|
|
|
|
+ (SELECT
|
|
|
|
+ tbs.id AS serviceUnitId,
|
|
|
|
+ tbs.name AS serviceUnitName,
|
|
|
|
+ tbc.id AS crmId,
|
|
|
|
+ tbc.crm_no AS crmNo,
|
|
|
|
+ su.id AS customId,
|
|
|
|
+ su.name AS customName,
|
|
|
|
+ su.type AS customType,
|
|
|
|
+ su.province AS province,
|
|
|
|
+ su.city AS city,
|
|
|
|
+ su.area AS area,
|
|
|
|
+ sl.id AS levelId,
|
|
|
|
+ sl.level AS level,
|
|
|
|
+ 1 AS coordinatorQuota,
|
|
|
|
+ IFNULL(effectQ.quota, 0) AS effectQuota,
|
|
|
|
+ IFNULL(assistantQ.quota, 0) AS assistantQuota,
|
|
|
|
+ IFNULL(coordinatorR.reality, 0) AS coordinatorDistributed,
|
|
|
|
+ IFNULL(effectR.reality, 0) AS effectDistributed,
|
|
|
|
+ IFNULL(assistantR.reality, 0) AS assistantDistributed,
|
|
|
|
+ 1 + IFNULL(effectQ.quota, 0) + IFNULL(assistantQ.quota, 0) AS quota,
|
|
|
|
+ IFNULL(coordinatorR.reality, 0) + IFNULL(effectR.reality, 0) + IFNULL(assistantR.reality, 0) AS distributed,
|
|
|
|
+ IF(1 - IFNULL(coordinatorR.reality, 0) < 0, 0, 1 - IFNULL(coordinatorR.reality, 0)) AS coordinatorUnDistributed,
|
|
|
|
+ IF(IFNULL(effectQ.quota, 0) - IFNULL(effectR.reality, 0) < 0, 0, IFNULL(effectQ.quota, 0) - IFNULL(effectR.reality, 0)) AS effectUnDistributed,
|
|
|
|
+ IF(IFNULL(assistantQ.quota, 0) - IFNULL(assistantR.reality, 0) < 0, 0, IFNULL(assistantQ.quota, 0) - IFNULL(assistantR.reality, 0)) AS assistantUnDistributed,
|
|
|
|
+ IFNULL(coordinatorR.publish, FALSE) AS publish
|
|
|
|
+ FROM
|
|
|
|
+ t_b_crm tbc
|
|
|
|
+ LEFT JOIN t_b_service tbs ON tbc.service_id = tbs.id
|
|
|
|
+ LEFT JOIN sys_custom su ON tbc.custom_id = su.id
|
|
|
|
+ LEFT JOIN sys_level sl ON su.level_id = sl.id
|
|
|
|
+ LEFT JOIN (SELECT
|
|
|
|
+ slr.quota, slr.level_id
|
|
|
|
+ FROM
|
|
|
|
+ sys_level_role slr
|
|
|
|
+ LEFT JOIN sys_role sr ON sr.id = slr.role_id
|
|
|
|
+ WHERE
|
|
|
|
+ sr.type = 'EFFECT_ENGINEER') effectQ ON effectQ.level_id = sl.id
|
|
|
|
+ LEFT JOIN (SELECT
|
|
|
|
+ slr.quota, slr.level_id
|
|
|
|
+ FROM
|
|
|
|
+ sys_level_role slr
|
|
|
|
+ LEFT JOIN sys_role sr ON sr.id = slr.role_id
|
|
|
|
+ WHERE
|
|
|
|
+ sr.type = 'ASSISTANT_ENGINEER') assistantQ ON assistantQ.level_id = sl.id
|
|
|
|
+ LEFT JOIN (SELECT
|
|
|
|
+ crm_no,
|
|
|
|
+ MAX(IF(region_user_id IS NULL, 0, 1)) AS reality,
|
|
|
|
+ MAX(IF(sop_no IS NULL, FALSE, TRUE)) AS publish
|
|
|
|
+ FROM
|
|
|
|
+ t_b_user_archives_allocation) coordinatorR ON coordinatorR.crm_no = tbc.crm_no
|
|
|
|
+ LEFT JOIN (SELECT
|
|
|
|
+ tbuaa.crm_no, COUNT(*) AS reality
|
|
|
|
+ FROM
|
|
|
|
+ t_b_user_archives_allocation tbuaa
|
|
|
|
+ LEFT JOIN sys_role sr ON sr.id = tbuaa.role_id
|
|
|
|
+ WHERE
|
|
|
|
+ sr.type = 'EFFECT_ENGINEER'
|
|
|
|
+ GROUP BY tbuaa.crm_no) effectR ON effectR.crm_no = tbc.crm_no
|
|
|
|
+ LEFT JOIN (SELECT
|
|
|
|
+ tbuaa.crm_no, COUNT(*) AS reality
|
|
|
|
+ FROM
|
|
|
|
+ t_b_user_archives_allocation tbuaa
|
|
|
|
+ LEFT JOIN sys_role sr ON sr.id = tbuaa.role_id
|
|
|
|
+ WHERE
|
|
|
|
+ sr.type = 'ASSISTANT_ENGINEER'
|
|
|
|
+ GROUP BY tbuaa.crm_no) assistantR ON assistantR.crm_no = tbc.crm_no
|
|
|
|
+ WHERE tbs.status != 'CANCEL') result
|
|
|
|
+ <where>
|
|
|
|
+ <if test="serviceUnitId != null">
|
|
|
|
+ AND result.serviceUnitId = #{serviceUnitId}
|
|
|
|
+ </if>
|
|
|
|
+ <if test="province != null and province != ''">
|
|
|
|
+ AND result.province CONCAT('%',#{province},'%')
|
|
|
|
+ </if>
|
|
|
|
+ <if test="city != null and city != ''">
|
|
|
|
+ AND result.city CONCAT('%',#{city},'%')
|
|
|
|
+ </if>
|
|
|
|
+ <if test="area != null and area != ''">
|
|
|
|
+ AND result.area CONCAT('%',#{area},'%')
|
|
|
|
+ </if>
|
|
|
|
+ <if test="customName != null and customName != ''">
|
|
|
|
+ AND result.customName CONCAT('%',#{customName}.'%')
|
|
|
|
+ </if>
|
|
|
|
+ <if test="gap != null">
|
|
|
|
+ AND (result.coordinatorUnDistributed + result.effectUnDistributed + result.assistantUnDistributed) <= #{gap}
|
|
|
|
+ </if>
|
|
|
|
+ </where>
|
|
|
|
+ </select>
|
|
</mapper>
|
|
</mapper>
|