TDetectorUserMapper.xml 16.8 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
<?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.zehong.system.mapper.TDetectorUserMapper">

    <resultMap type="TDetectorUser" id="TDetectorUserResult">
        <result property="userId"    column="user_id"    />
        <result property="username"    column="username"    />
        <result property="nickName"    column="nick_name"    />
        <result property="beyondEnterpriseId"    column="beyond_enterprise_id"    />
        <result property="userType"    column="user_type"    />
        <result property="address"    column="address"    />
        <result property="longitude"    column="longitude"    />
        <result property="latitude"    column="latitude"    />
        <result property="linkman"    column="linkman"    />
        <result property="phone"    column="phone"    />
        <result property="email"    column="email"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateTime"    column="update_time"    />
        <result property="isDel"    column="is_del"    />
        <result property="remarks"    column="remarks"    />
        <result property="beyondEnterpriseName"    column="enterprise_name"    />
    </resultMap>

    <resultMap type="TDetectorUserInspectVo" id="TDetectorUserInspectResult">
        <result property="userId"    column="user_id"    />
        <result property="nickName"    column="nick_name"    />
        <result property="beyondEnterpriseId"    column="beyond_enterprise_id"    />
        <result property="userType"    column="user_type"    />
        <result property="address"    column="address"    />
        <result property="linkman"    column="linkman"    />
        <result property="phone"    column="phone"    />
        <result property="beyondEnterpriseName"    column="enterprise_name"    />
        <result property="isInspect"    column="is_inspect"    />
        <result property="inspector"    column="inspector"    />
        <result property="inspectDate"    column="inspect_date"    />
    </resultMap>

    <sql id="selectTDetectorUserVo">
        select user_id, username, nick_name, user_type, address, longitude, latitude, linkman, phone, email, create_time, update_time, is_del, remarks from t_detector_user
    </sql>

    <select id="selectTDetectorUserList" parameterType="TDetectorUser" resultMap="TDetectorUserResult">
        select a.user_id, a.username, a.nick_name,  (CASE a.user_type WHEN '1' THEN '居民用户' WHEN '2' THEN '商业用户'WHEN '3' THEN '工业用户'WHEN '4' THEN '煤改气用户'end) as   user_type , a.address, a.longitude, a.latitude, a.linkman, a.phone, a.email, a.create_time, a.update_time, a.is_del, a.remarks,
        b.enterprise_name
        from t_detector_user a left join t_enterprise_info b on a.beyond_enterprise_id=b.enterprise_id
        <where> a.is_del = '0'
            <if test="beyondEnterpriseId != null  and beyondEnterpriseId != -2"> and a.beyond_enterprise_id =#{beyondEnterpriseId}</if>
            <if test="username != null  and username != ''"> and a.username like concat('%', #{username}, '%')</if>
            <if test="nickName != null  and nickName != ''"> and (a.nick_name like concat('%', #{nickName}, '%') or a.username like concat('%', #{nickName}, '%'))</if>
            <if test="isInspect != null  and isInspect == 0">
             and a.user_id not in
                <foreach item="hasInspectUser" collection="hasInspectUser" open="(" separator="," close=")">
                    #{hasInspectUser}
                </foreach>
            </if>
            <if test="isInspect != null and isInspect == 1">
                and a.user_id in
                <foreach item="hasInspectUser" collection="hasInspectUser" open="(" separator="," close=")">
                    #{hasInspectUser}
                </foreach>
            </if>
        </where>
65
        order by a.user_id desc
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
    </select>
    <select id="selectTDetectorListstatus" parameterType="TDetectorUser" resultMap="TDetectorUserResult">
        SELECT a.user_id, a.username, a.nick_name , a.address,
        a.longitude, a.latitude, a.linkman, a.phone, a.email, a.create_time,
        a.update_time, a.is_del, a.remarks,IF(inspect.status IS NULL,0,inspect.`status`) AS taskId

        FROM t_detector_user a
        LEFT JOIN (
        SELECT * FROM (SELECT MAX(inspect_id) AS inId  FROM t_work_task_inspect
        WHERE task_id = #{taskId} GROUP BY receive_id) t1
        LEFT JOIN t_work_task_inspect t ON t1.inId = t.inspect_id
        ) inspect  ON inspect.receive_id = a.user_id
        <where> a.is_del = '0'
            <if test="beyondEnterpriseId != null  and beyondEnterpriseId != -2"> and a.beyond_enterprise_id =#{beyondEnterpriseId}</if>
            <if test="username != null  and username != ''"> and a.username like concat('%', #{username}, '%')</if>
            <if test="nickName != null  and nickName != ''"> and (a.nick_name like concat('%', #{nickName}, '%') or a.username like concat('%', #{nickName}, '%'))</if>
        </where>

    </select>
    <select id="selectTDetectorUser" parameterType="TDetectorUser" resultMap="TDetectorUserResult">
        select a.user_id, a.beyond_enterprise_id,a.username, a.nick_name,  (CASE a.user_type WHEN '1' THEN '居民用户' WHEN '2' THEN '商业用户'WHEN '3' THEN '工业用户'WHEN '4' THEN '煤改气用户'end) as   user_type , a.address, a.longitude, a.latitude, a.linkman, a.phone, a.email, a.create_time, a.update_time, a.is_del, a.remarks,
        b.enterprise_name
        from t_detector_user a left join t_enterprise_info b on a.beyond_enterprise_id=b.enterprise_id
        <where>
            <if test="isDel != null  and isDel != ''"> and a.is_del = #{isDel}</if>
            <if test="username != null  and username != ''"> and a.username = #{username}</if>
            <if test="nickName != null  and nickName != ''"> and a.nick_name = #{nickName}</if>
        </where>
94 95
        group by a.user_id
        order by a.user_id desc
96 97 98 99 100 101 102 103 104
    </select>

    <select id="selectTDetectorUserById" parameterType="Long" resultMap="TDetectorUserResult">
       select a.user_id, a.beyond_enterprise_id,a.username, a.nick_name,  (CASE a.user_type WHEN '1' THEN '居民用户' WHEN '2' THEN '商业用户'WHEN '3' THEN '工业用户'WHEN '4' THEN '煤改气用户'end) as   user_type , a.address, a.longitude, a.latitude, a.linkman, a.phone, a.email, a.create_time, a.update_time, a.is_del, a.remarks,
        b.enterprise_name
        from t_detector_user a left join t_enterprise_info b on a.beyond_enterprise_id=b.enterprise_id
        where a.user_id = #{userId}
    </select>

105 106 107 108 109 110 111 112 113 114 115 116
    <select id="countTDetectorUserForMassMarks" resultType="TDetectorUserVO" parameterType="TDetectorUser">
        select a.user_id AS userId,
               a.nick_name AS nickName,
               a.user_type AS userType,
               a.address AS address,
               a.longitude AS longitude,
               a.latitude AS latitude,
               a.linkman AS linkman,
               a.phone AS phone,
               a.email AS email
        from(select   a2.* from  t_detector_user a2) a
    </select>
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140
    <select id="countTDetectorUser" resultType="TDetectorUserVO" parameterType="TDetectorUser">
        select t1.*,
			 IFNULL(t2.historyAlarmNum,0) AS historyAlarmNum,
			 IFNULL(t2.processingAlarmNum,0) AS processingAlarmNum,
			 IFNULL(t2.cancelAlarmNum,0) AS cancelAlarmNum
        from(

            select a.user_id AS userId,
                   a.detector_id AS detectorId,
                   a.detector_status AS detectorStatus,
                   a.nick_name AS nickName,
                   a.user_type AS userType,
                   a.address AS address,
                   a.longitude AS longitude,
                   a.latitude AS latitude,
                   a.linkman AS linkman,
                   a.phone AS phone,
                   a.email AS email,
                   CASE a.detector_type
                   WHEN '1' THEN '家用探测器'
                   WHEN '2' THEN '工业探测器' END AS detectorType,
                   COUNT(a.detector_id) AS detectorCount,
                   SUM(CASE a.detector_status WHEN '0' THEN 1 ELSE 0 END) AS onLineNum,
                   SUM(CASE a.detector_status WHEN '1' THEN 1 ELSE 0 END) AS offLineNum
141 142 143 144 145 146 147 148
            from(select
                    a1.* ,
                    a2.detector_id,
                    a2.detector_type,
                    a2.detector_status FROM t_detector_user a1
                    LEFT JOIN t_detector_info a2 ON a1.user_id = a2.user_id  AND a2.is_del = '0'
                <where> a1.is_del = '0'
                    <if test="userId != null  and userId != ''"> and a1.user_id = #{userId}</if>
149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317
                </where>) a
		    group by a.user_id,a.detector_type

        ) t1 left join (

            select b.user_id AS userId,
                   COUNT(b.id) AS historyAlarmNum,
                   SUM(CASE b.is_cancel_alarm WHEN '0' THEN 1 ELSE 0 END) AS processingAlarmNum,
                   COUNT(b.id) - SUM(CASE b.is_cancel_alarm WHEN '0' THEN 1 ELSE 0 END) AS cancelAlarmNum
            from(select b1.id,b1.is_cancel_alarm,b2.*
                 from t_detector_report_data b1
				 left join t_detector_info b2 on b1.detector_code = b2.detector_code
				 right join t_detector_user b3 on b2.user_id = b3.user_id
				 <where> b2.is_del = '0' and b3.is_del = '0'
                    <if test="userId != null  and userId != ''"> and b3.user_id = #{userId}</if>
				 </where>) b
		    group by b.user_id,b.detector_type

        ) t2 on t2.userId = t1.userId
    </select>

    <select id="getDetectorUserAlarmList" resultType="Map">
        select a2.user_id as userId
        from t_detector_info a1
        right join t_detector_user a2 on a1.user_id = a2.user_id
        where a1.is_del = '0' and a2.is_del = '0' and a1.detector_status = '2'
    </select>

    <insert id="insertTDetectorUser" parameterType="TDetectorUser" useGeneratedKeys="true" keyProperty="userId">
        insert into t_detector_user
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="username != null">username,</if>
            <if test="nickName != null">nick_name,</if>
            <if test="userType != null">user_type,</if>
            <if test="address != null">address,</if>
            <if test="longitude != null">longitude,</if>
            <if test="latitude != null">latitude,</if>
            <if test="beyondEnterpriseId != null">beyond_enterprise_id,</if>
            <if test="linkman != null">linkman,</if>
            <if test="phone != null">phone,</if>
            <if test="email != null">email,</if>
            <if test="isDel != null">is_del,</if>
            <if test="remarks != null">remarks,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="username != null">#{username},</if>
            <if test="nickName != null">#{nickName},</if>
            <if test="userType != null">#{userType},</if>
            <if test="address != null">#{address},</if>
            <if test="longitude != null">#{longitude},</if>
            <if test="latitude != null">#{latitude},</if>
            <if test="beyondEnterpriseId != null">#{beyondEnterpriseId},</if>
            <if test="linkman != null">#{linkman},</if>
            <if test="phone != null">#{phone},</if>
            <if test="email != null">#{email},</if>
            <if test="isDel != null">#{isDel},</if>
            <if test="remarks != null">#{remarks},</if>
         </trim>
    </insert>

    <update id="updateTDetectorUser" parameterType="TDetectorUser">
        update t_detector_user
        <trim prefix="SET" suffixOverrides=",">
            <if test="username != null">username = #{username},</if>
            <if test="nickName != null">nick_name = #{nickName},</if>
            <if test="userType != null">user_type = #{userType},</if>
            <if test="address != null">address = #{address},</if>
            <if test="longitude != null">longitude = #{longitude},</if>
            <if test="beyondEnterpriseId != null">beyond_enterprise_id = #{beyondEnterpriseId},</if>
            <if test="latitude != null">latitude = #{latitude},</if>
            <if test="linkman != null">linkman = #{linkman},</if>
            <if test="phone != null">phone = #{phone},</if>
            <if test="email != null">email = #{email},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="isDel != null">is_del = #{isDel},</if>
            <if test="remarks != null">remarks = #{remarks},</if>
        </trim>
        where user_id = #{userId}
    </update>

    <delete id="deleteTDetectorUserById" parameterType="Long">
        delete from t_detector_user where user_id = #{userId}
    </delete>

    <delete id="deleteTDetectorUserByIds" parameterType="String">
        delete from t_detector_user where user_id in
        <foreach item="userId" collection="array" open="(" separator="," close=")">
            #{userId}
        </foreach>
    </delete>
    <select id="selectUserNum" resultType="java.util.HashMap">
        SELECT IFNULL(SUM(IF(user_type=1,1,0)),0) AS juminNum,IFNULL(SUM(IF(user_type=2,1,0)),0) AS shangNum,
        IFNULL(SUM(IF(user_type=3,1,0)),0) AS gongNum FROM t_detector_user WHERE is_del = 0
    </select>

    <!--查询用户统计信息-->
    <select id="userStatistics" resultType="com.zehong.system.domain.TDetectorUserCount">
    SELECT
      (select count(user_id) from t_detector_user   where  is_del='0'   <if test="id != -2"> and beyond_enterprise_id = #{id}</if>)as totalNumberUsers,
      (select count(user_id) from t_detector_user   where user_type=1 and is_del='0'  <if test="id != -2"> and beyond_enterprise_id = #{id}</if>)as residentUsers,
      (select count(user_id) from t_detector_user   where user_type=2 and is_del='0'  <if test="id != -2"> and beyond_enterprise_id = #{id}</if>)as businessUser,
      (select count(user_id) from t_detector_user   where user_type=3 and is_del='0'  <if test="id != -2"> and beyond_enterprise_id = #{id}</if>)as industrialUsers
       FROM `t_detector_user` limit 0,1
    </select>

    <select id="getDetectorUserInspectInfo" parameterType="TDetectorUserInspectVo" resultMap="TDetectorUserInspectResult">
        SELECT
            a.user_id,
            a.username,
            a.nick_name,
            (
                CASE a.user_type
                WHEN '1' THEN
                    '居民用户'
                WHEN '2' THEN
                    '商业用户'
                WHEN '3' THEN
                    '工业用户'
                WHEN '4' THEN
                    '煤改气用户'
                END
            ) AS user_type,
            a.address,
            a.longitude,
            a.latitude,
            a.linkman,
            a.phone,
            b.enterprise_name,
            if(ISNULL(recent.inspect_id),'0',recent.status)as is_inspect,
            person.person_name as inspector,
            recent.create_time as inspect_date
        FROM
            t_detector_user a
        LEFT JOIN t_enterprise_info b ON a.beyond_enterprise_id = b.enterprise_id
        LEFT JOIN (
         SELECT
          task.*
         FROM t_work_task_inspect task,(SELECT max(inspect_id)as inspect_id FROM t_work_task_inspect WHERE task_id = #{taskId} group by receive_id)last
         WHERE task.inspect_id = last.inspect_id
        )recent ON a.user_id = recent.receive_id
        LEFT JOIN t_line_patrol_person person ON person.person_id = recent.member_id
        <where> a.is_del = '0'
            <if test="beyondEnterpriseId != null  and beyondEnterpriseId != -2"> and a.beyond_enterprise_id =#{beyondEnterpriseId}</if>
            <if test="username != null  and username != ''"> and a.username like concat('%', #{username}, '%')</if>
            <if test="nickName != null  and nickName != ''"> and a.nick_name like concat('%', #{nickName}, '%')</if>
            <if test="linkman != null  and linkman != ''"> and a.linkman = #{linkman}</if>
            <if test="isInspect != null  and isInspect == 0">
                and recent.inspect_id is null
            </if>
            <if test="isInspect != null and isInspect == 1">
                and recent.status  = 1
            </if>
            <if test="isInspect != null and isInspect == 2">
                and recent.status  = 2
            </if>
            <if test="inspectBeginTime != null and inspectEndTime != null">
                AND recent.create_time BETWEEN #{inspectBeginTime} and #{inspectEndTime}
            </if>
            <if test="inspector != null and inspector != ''">
                AND person.person_name like concat('%', #{inspector}, '%')
            </if>
            <if test="address != null and address != ''">
                AND a.address like concat('%', #{address}, '%')
            </if>
        </where>
        ORDER BY a.create_time DESC
</select>
</mapper>