btyjj-inspection/src/main/resources/mybatis/mapper/enterpriseofgridoperator/enterpriseofgridoperator-mapper.xml

717 lines
26 KiB
XML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?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.cm.inspection.dao.enterpriseofgridoperator.IEnterpriseOfGridOperatorDao">
<resultMap id="enterpriseOfGridOperatorDTO" type="com.cm.inspection.pojo.dtos.enterpriseofgridoperator.EnterpriseOfGridOperatorDTO">
<id column="enterprise_of_grid_operator_id" property="enterpriseOfGridOperatorId"/>
<result column="user_id" property="userId"/>
<result column="user_count" property="userCount"/>
<result column="enterprise_id" property="enterpriseId"/>
<result column="name_join_by_enterprise_id" property="nameJoinByEnterpriseId"/>
<result column="type_join_by_enterprise_id" property="typeJoinByEnterpriseId"/>
<result column="type_dictionary_name" property="typeDictionaryName"/>
<result column="area1_join_by_enterprise_id" property="area1JoinByEnterpriseId"/>
<result column="area1_dictionary_name" property="area1DictionaryName"/>
<result column="area2_join_by_enterprise_id" property="area2JoinByEnterpriseId"/>
<result column="area2_dictionary_name" property="area2DictionaryName"/>
<result column="area3_join_by_enterprise_id" property="area3JoinByEnterpriseId"/>
<result column="area3_dictionary_name" property="area3DictionaryName"/>
<result column="area4_join_by_enterprise_id" property="area4JoinByEnterpriseId"/>
<result column="area4_dictionary_name" property="area4DictionaryName"/>
<result column="area5_join_by_enterprise_id" property="area5JoinByEnterpriseId"/>
<result column="area5_dictionary_name" property="area5DictionaryName"/>
<result column="address_join_by_enterprise_id" property="addressJoinByEnterpriseId"/>
<result column="industry_join_by_enterprise_id" property="industryJoinByEnterpriseId"/>
<result column="engaged_count_join_by_enterprise_id" property="engagedCountJoinByEnterpriseId"/>
<result column="risk_operation_join_by_enterprise_id" property="riskOperationJoinByEnterpriseId"/>
<result column="master_join_by_enterprise_id" property="masterJoinByEnterpriseId"/>
<result column="phone_join_by_enterprise_id" property="phoneJoinByEnterpriseId"/>
<result column="industry_dictionary_name" property="industryDictionaryName"/>
<result column="risk_operation_dictionary_name" property="riskOperationDictionaryName"/>
<result column="industry_type_join_by_enterprise_id" property="industryTypeJoinByEnterpriseId"/>
<result column="industry_type_dictionary_name" property="industryTypeDictionaryName"/>
<result column="legal_person" property="legalPerson"/>
<result column="classify_by_enterprise_id" property="classifyJoinByEnterpriseId"/>
<result column="classify_dictionary_name" property="classifyDictionaryName"/>
<result column="nature_by_enterprise_id" property="natureJoinByEnterpriseId"/>
<result column="nature_dictionary_name" property="natureDictionaryName"/>
<result column="is_log_off_by_enterprise_id" property="isLogOffByEnterpriseId"/>
</resultMap>
<resultMap id="gridPersonnelDTO" type="com.cm.inspection.pojo.dtos.gridpersonnel.GridPersonnelDTO">
<id column="grid_personnel_id" property="gridPersonnelId"/>
<result column="user_id" property="userId"/>
<result column="user_name" property="userName"/>
<result column="area1" property="area1"/>
<result column="area1_dictionary_name" property="area1DictionaryName"/>
<result column="area2" property="area2"/>
<result column="area2_dictionary_name" property="area2DictionaryName"/>
<result column="area3" property="area3"/>
<result column="area3_dictionary_name" property="area3DictionaryName"/>
<result column="area4" property="area4"/>
<result column="area4_dictionary_name" property="area4DictionaryName"/>
<result column="area5" property="area5"/>
<result column="area5_dictionary_name" property="area5DictionaryName"/>
<result column="leader_user_id" property="leaderUserId"/>
<result column="user_id_join_by_leader_user_id" property="userIdJoinByLeaderUserId"/>
<result column="area1_join_by_leader_user_id" property="area1JoinByLeaderUserId"/>
<result column="area2_join_by_leader_user_id" property="area2JoinByLeaderUserId"/>
<result column="area3_join_by_leader_user_id" property="area3JoinByLeaderUserId"/>
<result column="area4_join_by_leader_user_id" property="area4JoinByLeaderUserId"/>
<result column="area5_join_by_leader_user_id" property="area5JoinByLeaderUserId"/>
<result column="leader_user_id_join_by_leader_user_id" property="leaderUserIdJoinByLeaderUserId"/>
<result column="is_grid_operator_join_by_leader_user_id" property="isGridOperatorJoinByLeaderUserId"/>
<result column="level_join_by_leader_user_id" property="levelJoinByLeaderUserId"/>
<result column="is_grid_operator" property="isGridOperator"/>
<result column="level" property="level"/>
</resultMap>
<!-- 新增网格员的企业 -->
<insert id="saveEnterpriseOfGridOperator" parameterType="map" flushCache="true">
INSERT INTO gen_enterprise_of_grid_operator(
enterprise_of_grid_operator_id,
user_id,
enterprise_id,
creator,
gmt_create,
modifier,
gmt_modified,
is_delete
) VALUES(
#{enterpriseOfGridOperatorId},
#{userId},
#{enterpriseId},
#{creator},
#{gmtCreate},
#{modifier},
#{gmtModified},
#{isDelete}
)
</insert>
<!-- 删除网格员的企业 -->
<update id="removeEnterpriseOfGridOperator" parameterType="map" flushCache="true">
UPDATE
gen_enterprise_of_grid_operator
SET
is_delete = 1,
modifier = #{modifier},
gmt_modified = #{gmtModified}
WHERE
enterprise_of_grid_operator_id IN
<foreach collection="enterpriseOfGridOperatorIds" index="index" open="(" separator="," close=")">
#{enterpriseOfGridOperatorIds[${index}]}
</foreach>
</update>
<!-- 删除网格员的企业(物理删除) -->
<delete id="deleteEnterpriseOfGridOperator" flushCache="true">
DELETE FROM
gen_enterprise_of_grid_operator
WHERE
<if test="enterpriseOfGridOperatorIds != null and enterpriseOfGridOperatorIds.size > 0">
enterprise_of_grid_operator_id IN
<foreach collection="enterpriseOfGridOperatorIds" index="index" open="(" separator="," close=")">
#{enterpriseOfGridOperatorIds[${index}]}
</foreach>
</if>
<if test="enterpriseId != null and enterpriseId != '' and userId != null and userId != ''">
enterprise_id = #{enterpriseId}
AND
user_id = #{userId}
</if>
</delete>
<!-- 修改网格员的企业 -->
<update id="updateEnterpriseOfGridOperator" parameterType="map" flushCache="true">
UPDATE
gen_enterprise_of_grid_operator
SET
<if test="userId != null and userId != ''">
user_id = #{userId},
</if>
<if test="enterpriseId != null and enterpriseId != ''">
enterprise_id = #{enterpriseId},
</if>
modifier = #{modifier},
gmt_modified = #{gmtModified}
WHERE
enterprise_of_grid_operator_id = #{enterpriseOfGridOperatorId}
</update>
<!-- 网格员的企业详情 -->
<select id="getEnterpriseOfGridOperator" parameterType="map" resultMap="enterpriseOfGridOperatorDTO">
SELECT
t1.user_id,
t1.enterprise_id,
t1.enterprise_of_grid_operator_id
FROM
gen_enterprise_of_grid_operator t1
WHERE
t1.is_delete = 0
<if test="enterpriseOfGridOperatorId != null and enterpriseOfGridOperatorId != ''">
AND
t1.enterprise_of_grid_operator_id = #{enterpriseOfGridOperatorId}
</if>
</select>
<!-- 网格员的企业列表 -->
<select id="listEnterpriseOfGridOperator" parameterType="map" resultMap="enterpriseOfGridOperatorDTO">
SELECT
t1.user_id,
t1.enterprise_id,
jt1.name name_join_by_enterprise_id,
jt1.type type_join_by_enterprise_id,
jt1.address address_join_by_enterprise_id,
jt1.master master_join_by_enterprise_id,
jt1.phone phone_join_by_enterprise_id,
jt1.industry industry_join_by_enterprise_id,
jt1.engaged_count engaged_count_join_by_enterprise_id,
jt1.risk_operation risk_operation_join_by_enterprise_id,
jt1.area1_dictionary_name,
jt1.area2_dictionary_name,
jt1.area3_dictionary_name,
jt1.area4_dictionary_name,
jt1.area5_dictionary_name,
jt1.classify classify_by_enterprise_id,
jt1.classify_dictionary_name,
jt1.nature nature_by_enterprise_id,
jt1.nature_dictionary_name,
jt1.is_log_off is_log_off_by_enterprise_id,
jt1.legal_person,
t1.enterprise_of_grid_operator_id
FROM
gen_enterprise_of_grid_operator t1
INNER JOIN
gen_enterprise jt1
ON
t1.enterprise_id = jt1.enterprise_id
AND
jt1.is_delete = 0
WHERE
t1.is_delete = 0
<if test="keywords != null and keywords != ''">
AND
jt1.name LIKE CONCAT('%', #{keywords}, '%')
</if>
<if test="startTime != null and startTime != ''">
AND
LEFT(t1.gmt_create, 10) <![CDATA[ >= ]]> #{startTime}
</if>
<if test="endTime != null and endTime != ''">
AND
LEFT(t1.gmt_create, 10) <![CDATA[ <= ]]> #{endTime}
</if>
<if test="enterpriseOfGridOperatorIds != null and enterpriseOfGridOperatorIds.size > 0">
AND
t1.enterprise_of_grid_operator_id IN
<foreach collection="enterpriseOfGridOperatorIds" index="index" open="(" separator="," close=")">
#{enterpriseOfGridOperatorIds[${index}]}
</foreach>
</if>
<if test="userId != null and userId != ''">
AND
t1.user_id = #{userId}
</if>
<if test="withOutLogOff != null and withOutLogOff == 'withOutLogOff'">
AND
jt1.is_log_off = 0
</if>
<if test="type != null and type != ''">
AND
jt1.type = #{type}
</if>
<if test="area1 != null and area1 != ''">
AND
jt1.area1 = #{area1}
</if>
<if test="area2 != null and area2 != ''">
AND
jt1.area2 = #{area2}
</if>
<if test="area3 != null and area3 != ''">
AND
jt1.area3 = #{area3}
</if>
<if test="area4 != null and area4 != ''">
AND
jt1.area4 = #{area4}
</if>
<if test="area5 != null and area5 != ''">
AND
jt1.area5 = #{area5}
</if>
</select>
<!-- 网格员的企业列表通过用户ID,性能问题废弃 -->
<select id="listEnterpriseOfGridOperatorByUserIdDiscard" parameterType="map" resultMap="enterpriseOfGridOperatorDTO">
SELECT
t1.enterprise_id,
t1.name name_join_by_enterprise_id,
t1.type type_join_by_enterprise_id,
t1.type_dictionary_name,
t1.area1 area1_join_by_enterprise_id,
t1.area1_dictionary_name,
t1.area2 area2_join_by_enterprise_id,
t1.area2_dictionary_name,
t1.area3 area3_join_by_enterprise_id,
t1.area3_dictionary_name,
t1.area4 area4_join_by_enterprise_id,
t1.area4_dictionary_name,
t1.area5 area5_join_by_enterprise_id,
t1.area5_dictionary_name,
t1.address address_join_by_enterprise_id,
t1.industry_type industry_type_join_by_enterprise_id,
t1.industry_type_dictionary_name,
t1.industry industry_join_by_enterprise_id,
t1.industry_dictionary_name,
t1.engaged_count engaged_count_join_by_enterprise_id,
t1.risk_operation risk_operation_join_by_enterprise_id,
t1.risk_operation_dictionary_name,
t1.legal_person,
t1.master master_join_by_enterprise_id,
t1.phone phone_join_by_enterprise_id,
t1.classify classify_by_enterprise_id,
t1.classify_dictionary_name,
t1.nature nature_by_enterprise_id,
t1.nature_dictionary_name,
t1.is_log_off is_log_off_by_enterprise_id,
jt1.user_id,
jt1.enterprise_of_grid_operator_id
FROM
gen_enterprise t1
LEFT JOIN
gen_enterprise_of_grid_operator jt1
ON
t1.enterprise_id = jt1.enterprise_id
WHERE
t1.is_delete = 0
AND (
jt1.user_id IS NULL
OR
jt1.user_id = #{userId}
)
<if test="area1 != null and area1 != ''">
AND
t1.area1 = #{area1}
</if>
<if test="area2 != null and area2 != ''">
AND
t1.area2 = #{area2}
</if>
<if test="area3 != null and area3 != ''">
AND
t1.area3 = #{area3}
</if>
<if test="area4 != null and area4 != ''">
AND
t1.area4 = #{area4}
</if>
<if test="area5 != null and area5 != ''">
AND
t1.area5 = #{area5}
</if>
<if test="keywords != null and keywords != ''">
AND
t1.name LIKE CONCAT('%', #{keywords}, '%')
</if>
<if test="type != null and type != ''">
AND
t1.type = #{type}
</if>
</select>
<!-- 网格员的企业列表通过用户ID -->
<select id="listEnterpriseOfGridOperatorByUserId" parameterType="map" resultMap="enterpriseOfGridOperatorDTO">
SELECT
t1.enterprise_id,
t1.name name_join_by_enterprise_id,
t1.type type_join_by_enterprise_id,
t1.type_dictionary_name,
t1.area1 area1_join_by_enterprise_id,
t1.area1_dictionary_name,
t1.area2 area2_join_by_enterprise_id,
t1.area2_dictionary_name,
t1.area3 area3_join_by_enterprise_id,
t1.area3_dictionary_name,
t1.area4 area4_join_by_enterprise_id,
t1.area4_dictionary_name,
t1.area5 area5_join_by_enterprise_id,
t1.area5_dictionary_name,
t1.address address_join_by_enterprise_id,
t1.industry_type indzustry_type_join_by_enterprise_id,
t1.industry_type_dictionary_name,
t1.industry industry_join_by_enterprise_id,
t1.industry_dictionary_name,
t1.engaged_count engaged_count_join_by_enterprise_id,
t1.risk_operation risk_operation_join_by_enterprise_id,
t1.risk_operation_dictionary_name,
t1.legal_person,
t1.master master_join_by_enterprise_id,
t1.phone phone_join_by_enterprise_id,
t1.classify classify_by_enterprise_id,
t1.classify_dictionary_name,
t1.nature nature_by_enterprise_id,
t1.nature_dictionary_name,
t1.is_log_off is_log_off_by_enterprise_id,
(
SELECT
COUNT(*)
FROM
gen_enterprise_of_grid_operator st1
WHERE
st1.user_id = #{userId}
AND
t1.enterprise_id = st1.enterprise_id
) user_count
FROM
gen_enterprise t1
WHERE
t1.is_delete = 0
AND (
t1.enterprise_id IN (
SELECT
wt1.enterprise_id
FROM
gen_enterprise_of_grid_operator wt1
WHERE
wt1.user_id = #{userId}
) OR t1.enterprise_id NOT IN (
SELECT
wt2.enterprise_id
FROM
gen_enterprise_of_grid_operator wt2
GROUP BY
wt2.enterprise_id
)
)
<if test="area1 != null and area1 != ''">
AND
t1.area1 = #{area1}
</if>
<if test="area2 != null and area2 != ''">
AND
t1.area2 = #{area2}
</if>
<if test="area3 != null and area3 != ''">
AND
t1.area3 = #{area3}
</if>
<if test="area4 != null and area4 != ''">
AND
t1.area4 = #{area4}
</if>
<if test="area5 != null and area5 != ''">
AND
t1.area5 = #{area5}
</if>
<if test="keywords != null and keywords != ''">
AND
t1.name LIKE CONCAT('%', #{keywords}, '%')
</if>
<if test="type != null and type != ''">
AND
t1.type = #{type}
</if>
</select>
<!-- 网格员的企业列表通过用户ID和企业ID -->
<select id="listEnterpriseOfGridOperatorByUserIdAndEnterpriseId" parameterType="map" resultMap="enterpriseOfGridOperatorDTO">
SELECT
user_id
enterprise_id
FROM
gen_enterprise_of_grid_operator
WHERE
user_id = #{userId}
AND
enterprise_id = #{enterpriseId}
</select>
<!-- 统计绑定的企业 -->
<select id="countEnterpriseOfGridOperator" parameterType="map" resultType="Integer">
SELECT
COUNT(*)
FROM
gen_enterprise_of_grid_operator t1
INNER JOIN
gen_enterprise t2
ON
t1.enterprise_id = t2.enterprise_id
AND
t2.is_delete = 0
WHERE
t1.is_delete = 0
<if test="userId != null and userId != ''">
AND
t1.user_id = #{userId}
</if>
</select>
<!-- 网格员列表 -->
<select id="listGridPersonnel" parameterType="map" resultMap="gridPersonnelDTO">
SELECT
jt1.user_id,
jt1.area1,
jt1.area2,
jt1.area3,
jt1.area4,
jt1.area5,
jt1.leader_user_id,
jt1.is_grid_operator,
jt1.level,
jt1.grid_personnel_id
FROM
gen_enterprise_of_grid_operator t1
INNER JOIN
gen_grid_personnel jt1
ON
t1.user_id = LEFT(jt1.user_id, 36)
AND
jt1.is_delete = 0
WHERE
t1.is_delete = 0
<if test="enterpriseId != null and enterpriseId != ''">
AND
t1.enterprise_id = #{enterpriseId}
</if>
</select>
<!-- 未认领企业列表 -->
<select id="listUnclaimedEnterprise" parameterType="map" resultMap="enterpriseOfGridOperatorDTO">
SELECT
t1.enterprise_id,
t1.name name_join_by_enterprise_id,
t1.type type_join_by_enterprise_id,
t1.type_dictionary_name,
t1.area1 area1_join_by_enterprise_id,
t1.area1_dictionary_name,
t1.area2 area2_join_by_enterprise_id,
t1.area2_dictionary_name,
t1.area3 area3_join_by_enterprise_id,
t1.area3_dictionary_name,
t1.area4 area4_join_by_enterprise_id,
t1.area4_dictionary_name,
t1.area5 area5_join_by_enterprise_id,
t1.area5_dictionary_name,
t1.address address_join_by_enterprise_id,
t1.industry_type indzustry_type_join_by_enterprise_id,
t1.industry_type_dictionary_name,
t1.industry industry_join_by_enterprise_id,
t1.industry_dictionary_name,
t1.engaged_count engaged_count_join_by_enterprise_id,
t1.risk_operation risk_operation_join_by_enterprise_id,
t1.risk_operation_dictionary_name,
t1.legal_person,
t1.master master_join_by_enterprise_id,
t1.phone phone_join_by_enterprise_id,
t1.classify classify_by_enterprise_id,
t1.classify_dictionary_name,
t1.nature nature_by_enterprise_id,
t1.nature_dictionary_name,
t1.is_log_off is_log_off_by_enterprise_id
FROM
gen_enterprise t1
WHERE
t1.is_delete = 0
AND
t1.enterprise_id NOT IN (
SELECT
wt1.enterprise_id
FROM
gen_enterprise_of_grid_operator wt1
GROUP BY
wt1.enterprise_id
)
<if test="area1 != null and area1 != ''">
AND
t1.area1 = #{area1}
</if>
<if test="area2 != null and area2 != ''">
AND
t1.area2 = #{area2}
</if>
<if test="area3 != null and area3 != ''">
AND
t1.area3 = #{area3}
</if>
<if test="area4 != null and area4 != ''">
AND
t1.area4 = #{area4}
</if>
<if test="area5 != null and area5 != ''">
AND
t1.area5 = #{area5}
</if>
<if test="keywords != null and keywords != ''">
AND
t1.name LIKE CONCAT('%', #{keywords}, '%')
</if>
</select>
<!-- 统计未认领企业 -->
<select id="countUnclaimedEnterprise" parameterType="map" resultType="java.lang.Integer">
SELECT
COUNT(*)
FROM
gen_enterprise t1
WHERE
t1.is_delete = 0
AND
t1.enterprise_id NOT IN (
SELECT
wt1.enterprise_id
FROM
gen_enterprise_of_grid_operator wt1
GROUP BY
wt1.enterprise_id
)
<if test="area1 != null and area1 != ''">
AND
t1.area1 = #{area1}
</if>
<if test="area2 != null and area2 != ''">
AND
t1.area2 = #{area2}
</if>
<if test="area3 != null and area3 != ''">
AND
t1.area3 = #{area3}
</if>
<if test="area4 != null and area4 != ''">
AND
t1.area4 = #{area4}
</if>
<if test="area5 != null and area5 != ''">
AND
t1.area5 = #{area5}
</if>
<if test="keywords != null and keywords != ''">
AND
t1.name LIKE CONCAT('%', #{keywords}, '%')
</if>
<if test="year != null and year != ''">
AND
LEFT(t1.gmt_create, 4) <![CDATA[ <= ]]> #{year}
</if>
</select>
<!-- 统计认领企业 -->
<select id="countClaimedEnterprise" parameterType="map" resultType="java.lang.Integer">
SELECT
COUNT(*)
FROM
gen_enterprise t1
WHERE
t1.is_delete = 0
AND
t1.enterprise_id IN (
SELECT
wt1.enterprise_id
FROM
gen_enterprise_of_grid_operator wt1
GROUP BY
wt1.enterprise_id
)
<if test="area1 != null and area1 != ''">
AND
t1.area1 = #{area1}
</if>
<if test="area2 != null and area2 != ''">
AND
t1.area2 = #{area2}
</if>
<if test="area3 != null and area3 != ''">
AND
t1.area3 = #{area3}
</if>
<if test="area4 != null and area4 != ''">
AND
t1.area4 = #{area4}
</if>
<if test="area5 != null and area5 != ''">
AND
t1.area5 = #{area5}
</if>
<if test="keywords != null and keywords != ''">
AND
t1.name LIKE CONCAT('%', #{keywords}, '%')
</if>
<if test="year != null and year != ''">
AND
LEFT(t1.gmt_create, 4) <![CDATA[ <= ]]> #{year}
</if>
</select>
<!-- 统计企业 -->
<select id="countEnterpriseOfGridOperatorSimple" parameterType="map" resultType="java.lang.Integer">
SELECT
COUNT(*)
FROM
gen_enterprise_of_grid_operator t1
WHERE
t1.is_delete = 0
<if test="userId != null and userId != ''">
AND
t1.creator = #{userId}
</if>
<if test="yearMonth != null and yearMonth != ''">
AND
LEFT(t1.gmt_create, 7) <![CDATA[ <= ]]> #{yearMonth}
</if>
<if test="dateYearMonth != null and dateYearMonth != ''">
AND
LEFT(t1.gmt_create, 7) = #{dateYearMonth}
</if>
</select>
<!-- 企业网格员列表(简单格式) -->
<select id="listSimple" parameterType="map" resultMap="enterpriseOfGridOperatorDTO">
SELECT
enterprise_of_grid_operator_id,
user_id,
enterprise_id
FROM
gen_enterprise_of_grid_operator
WHERE
is_delete = 0
<if test="enterpriseIds != null and enterpriseIds.size > 0">
AND
enterprise_id IN
<foreach collection="enterpriseIds" index="index" open="(" separator="," close=")">
#{enterpriseIds[${index}]}
</foreach>
</if>
</select>
<!-- 企业ID列表 -->
<select id="listEnterpriseId" parameterType="map" resultType="java.lang.String">
SELECT
enterprise_id
FROM
gen_enterprise_of_grid_operator
WHERE
is_delete = 0
<if test="userId != null and userId != ''">
AND
user_id = #{userId}
</if>
<if test="userIds != null and userIds.size > 0">
AND
user_id IN
<foreach collection="userIds" index="index" open="(" separator="," close=")">
#{userIds[${index}]}
</foreach>
</if>
<if test="enterpriseIds != null and enterpriseIds.size > 0">
AND
enterprise_id IN
<foreach collection="enterpriseIds" index="index" open="(" separator="," close=")">
#{enterpriseIds[${index}]}
</foreach>
</if>
GROUP BY
enterprise_id
</select>
</mapper>