| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- <?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.fs.watch.mapper.WatchCompanyMapper">
- <resultMap type="WatchCompany" id="WatchCompanyResult">
- <result property="deviceId" column="device_id" />
- <result property="companyId" column="company_id" />
- </resultMap>
- <sql id="selectWatchCompanyVo">
- select device_id, company_id from watch_company
- </sql>
- <select id="selectWatchCompanyList" parameterType="WatchCompany" resultMap="WatchCompanyResult">
- <include refid="selectWatchCompanyVo"/>
- <where>
- <if test="deviceId != null "> and device_id = #{deviceId}</if>
- <if test="companyId != null "> and company_id = #{companyId}</if>
- </where>
- </select>
- <select id="selectWatchCompanyById" parameterType="Long" resultMap="WatchCompanyResult">
- <include refid="selectWatchCompanyVo"/>
- where id = #{id}
- </select>
- <insert id="insertWatchCompany" parameterType="WatchCompany">
- insert into watch_company
- <trim prefix="(" suffix=")" suffixOverrides=",">
- <if test="deviceId != null">device_id,</if>
- <if test="companyId != null">company_id,</if>
- </trim>
- <trim prefix="values (" suffix=")" suffixOverrides=",">
- <if test="deviceId != null">#{deviceId},</if>
- <if test="companyId != null">#{companyId},</if>
- </trim>
- </insert>
- <insert id="insertBatchWatchCompany">
- INSERT INTO watch_company (device_id, company_id)
- SELECT device_id, company_id
- FROM (
- <foreach collection="list" separator="UNION ALL" item="watchCompany">
- SELECT #{watchCompany.deviceId,jdbcType=BIGINT} AS device_id,
- #{watchCompany.companyId,jdbcType=BIGINT} AS company_id
- </foreach>
- ) AS new_records
- WHERE NOT EXISTS (
- SELECT 1
- FROM watch_company wc
- WHERE wc.device_id = new_records.device_id
- AND wc.company_id = new_records.company_id
- )
- </insert>
- <delete id="deleteBatch">
- delete from watch_company where device_id = #{deviceId} and company_id in
- <foreach item="id" collection="list" open="(" separator="," close=")">
- #{id}
- </foreach>
- </delete>
- </mapper>
|