| <?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.ruoyi.dispatch.mapper.ArdDispatchPoliceMapper"> | 
|   | 
|     <resultMap type="ArdDispatchPolice" id="ArdDispatchPoliceResult"> | 
|         <result property="id" column="id"/> | 
|         <result property="name" column="name"/> | 
|         <result property="text" column="text"/> | 
|         <result property="longitude" column="longitude"/> | 
|         <result property="latitude" column="latitude"/> | 
|         <result property="deptId" column="dept_id"/> | 
|         <result property="userId" column="user_id"/> | 
|         <result property="createBy" column="create_by"/> | 
|         <result property="createTime" column="create_time"/> | 
|         <result property="updateBy" column="update_by"/> | 
|         <result property="updateTime" column="update_time"/> | 
|         <!-- 子查询,关联 ard_dispatch_police_user 表 --> | 
|         <collection property="sysUserList" ofType="java.util.List" select="getSysUserListByMainTableId" column="id"/> | 
|     </resultMap> | 
|     <select id="getSysUserListByMainTableId" resultType="SysUser"> | 
|         SELECT u.* | 
|         FROM ard_dispatch_police_user b | 
|                  left join sys_user u on b.user_id = u.user_id | 
|         WHERE dispatch_id = #{id} | 
|     </select> | 
|   | 
|   | 
|     <resultMap id="ArdDispatchPoliceArdDispatchPoliceUserResult" type="ArdDispatchPolice" | 
|                extends="ArdDispatchPoliceResult"> | 
|         <collection property="sysUserList" notNullColumn="sub_dispatch_id" javaType="java.util.List" | 
|                     resultMap="SysUserListResult"/> | 
|     </resultMap> | 
|   | 
|     <resultMap type="SysUser" id="SysUserListResult"> | 
|         <result property="userId" column="sub_user_id"/> | 
|         <result property="nickName" column="sub_nick_name"/> | 
|         <result property="deptId" column="sub_dept_id"/> | 
|     </resultMap> | 
|   | 
|     <sql id="selectArdDispatchPoliceVo"> | 
|         SELECT ID, | 
|                NAME, | 
|                text, | 
|                longitude, | 
|                latitude, | 
|                dept_id, | 
|                user_id, | 
|                create_by, | 
|                create_time, | 
|                update_by, | 
|                update_time | 
|         FROM ard_dispatch_police | 
|     </sql> | 
|   | 
|     <select id="selectArdDispatchPoliceList" parameterType="ArdDispatchPolice" resultMap="ArdDispatchPoliceResult"> | 
|         <include refid="selectArdDispatchPoliceVo"/> | 
|         <where> | 
|             <if test="name != null  and name != ''">and name like '%'||#{name}||'%'</if> | 
|             <if test="longitude != null ">and longitude = #{longitude}</if> | 
|             <if test="latitude != null ">and latitude = #{latitude}</if> | 
|             <if test="deptId != null ">and dept_id = #{deptId}</if> | 
|             <if test="userId != null  and userId != ''">and user_id = #{userId}</if> | 
|         </where> | 
|     </select> | 
|   | 
|     <select id="selectArdDispatchPoliceById" parameterType="String" | 
|             resultMap="ArdDispatchPoliceArdDispatchPoliceUserResult"> | 
|         select a.id, | 
|                a.name, | 
|                a.text, | 
|                a.longitude, | 
|                a.latitude, | 
|                a.dept_id, | 
|                a.user_id, | 
|                a.create_by, | 
|                a.create_time, | 
|                a.update_by, | 
|                a.update_time, | 
|                b.user_id   as sub_user_id, | 
|                b.nick_name as sub_nick_name, | 
|                b.dept_id   as sub_dept_id | 
|         from ard_dispatch_police a | 
|                  left join ard_dispatch_police_user b on b.dispatch_id = a.id | 
|         where a.id = #{id} | 
|     </select> | 
|   | 
|     <insert id="insertArdDispatchPolice" parameterType="ArdDispatchPolice"> | 
|         insert into ard_dispatch_police | 
|         <trim prefix="(" suffix=")" suffixOverrides=","> | 
|             <if test="id != null">id,</if> | 
|             <if test="name != null">name,</if> | 
|             <if test="text != null">text,</if> | 
|             <if test="longitude != null">longitude,</if> | 
|             <if test="latitude != null">latitude,</if> | 
|             <if test="deptId != null">dept_id,</if> | 
|             <if test="userId != null">user_id,</if> | 
|             <if test="createBy != null">create_by,</if> | 
|             <if test="createTime != null">create_time,</if> | 
|             <if test="updateBy != null">update_by,</if> | 
|             <if test="updateTime != null">update_time,</if> | 
|         </trim> | 
|         <trim prefix="values (" suffix=")" suffixOverrides=","> | 
|             <if test="id != null">#{id},</if> | 
|             <if test="name != null">#{name},</if> | 
|             <if test="text != null">#{text},</if> | 
|             <if test="longitude != null">#{longitude},</if> | 
|             <if test="latitude != null">#{latitude},</if> | 
|             <if test="deptId != null">#{deptId},</if> | 
|             <if test="userId != null">#{userId},</if> | 
|             <if test="createBy != null">#{createBy},</if> | 
|             <if test="createTime != null">#{createTime},</if> | 
|             <if test="updateBy != null">#{updateBy},</if> | 
|             <if test="updateTime != null">#{updateTime},</if> | 
|         </trim> | 
|     </insert> | 
|   | 
|     <update id="updateArdDispatchPolice" parameterType="ArdDispatchPolice"> | 
|         update ard_dispatch_police | 
|         <trim prefix="SET" suffixOverrides=","> | 
|             <if test="name != null">name = #{name},</if> | 
|             <if test="text != null">text = #{text},</if> | 
|             <if test="longitude != null">longitude = #{longitude},</if> | 
|             <if test="latitude != null">latitude = #{latitude},</if> | 
|             <if test="deptId != null">dept_id = #{deptId},</if> | 
|             <if test="userId != null">user_id = #{userId},</if> | 
|             <if test="createBy != null">create_by = #{createBy},</if> | 
|             <if test="createTime != null">create_time = #{createTime},</if> | 
|             <if test="updateBy != null">update_by = #{updateBy},</if> | 
|             <if test="updateTime != null">update_time = #{updateTime},</if> | 
|         </trim> | 
|         where id = #{id} | 
|     </update> | 
|   | 
|     <delete id="deleteArdDispatchPoliceById" parameterType="String"> | 
|         delete | 
|         from ard_dispatch_police | 
|         where id = #{id} | 
|     </delete> | 
|   | 
|     <delete id="deleteArdDispatchPoliceByIds" parameterType="String"> | 
|         delete from ard_dispatch_police where id in | 
|         <foreach item="id" collection="array" open="(" separator="," close=")"> | 
|             #{id} | 
|         </foreach> | 
|     </delete> | 
|   | 
|     <delete id="deleteArdDispatchPoliceUserByDispatchIds" parameterType="String"> | 
|         delete from ard_dispatch_police_user where dispatch_id in | 
|         <foreach item="dispatchId" collection="array" open="(" separator="," close=")"> | 
|             #{dispatchId} | 
|         </foreach> | 
|     </delete> | 
|   | 
|     <delete id="deleteArdDispatchPoliceUserByDispatchId" parameterType="String"> | 
|         delete | 
|         from ard_dispatch_police_user | 
|         where dispatch_id = #{dispatchId} | 
|     </delete> | 
|   | 
|     <insert id="batchArdDispatchPoliceUser"> | 
|         insert into ard_dispatch_police_user( dispatch_id, user_id) values | 
|         <foreach item="item" index="index" collection="list" separator=","> | 
|             ( #{item.dispatchId}, #{item.userId}) | 
|         </foreach> | 
|     </insert> | 
|   | 
| </mapper> |