WatchCompanyMapper.xml 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?xml version="1.0" encoding="UTF-8" ?>
  2. <!DOCTYPE mapper
  3. PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
  4. "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  5. <mapper namespace="com.fs.watch.mapper.WatchCompanyMapper">
  6. <resultMap type="WatchCompany" id="WatchCompanyResult">
  7. <result property="deviceId" column="device_id" />
  8. <result property="companyId" column="company_id" />
  9. </resultMap>
  10. <sql id="selectWatchCompanyVo">
  11. select device_id, company_id from watch_company
  12. </sql>
  13. <select id="selectWatchCompanyList" parameterType="WatchCompany" resultMap="WatchCompanyResult">
  14. <include refid="selectWatchCompanyVo"/>
  15. <where>
  16. <if test="deviceId != null "> and device_id = #{deviceId}</if>
  17. <if test="companyId != null "> and company_id = #{companyId}</if>
  18. </where>
  19. </select>
  20. <select id="selectWatchCompanyById" parameterType="Long" resultMap="WatchCompanyResult">
  21. <include refid="selectWatchCompanyVo"/>
  22. where id = #{id}
  23. </select>
  24. <insert id="insertWatchCompany" parameterType="WatchCompany">
  25. insert into watch_company
  26. <trim prefix="(" suffix=")" suffixOverrides=",">
  27. <if test="deviceId != null">device_id,</if>
  28. <if test="companyId != null">company_id,</if>
  29. </trim>
  30. <trim prefix="values (" suffix=")" suffixOverrides=",">
  31. <if test="deviceId != null">#{deviceId},</if>
  32. <if test="companyId != null">#{companyId},</if>
  33. </trim>
  34. </insert>
  35. <insert id="insertBatchWatchCompany">
  36. INSERT INTO watch_company (device_id, company_id)
  37. SELECT device_id, company_id
  38. FROM (
  39. <foreach collection="list" separator="UNION ALL" item="watchCompany">
  40. SELECT #{watchCompany.deviceId,jdbcType=BIGINT} AS device_id,
  41. #{watchCompany.companyId,jdbcType=BIGINT} AS company_id
  42. </foreach>
  43. ) AS new_records
  44. WHERE NOT EXISTS (
  45. SELECT 1
  46. FROM watch_company wc
  47. WHERE wc.device_id = new_records.device_id
  48. AND wc.company_id = new_records.company_id
  49. )
  50. </insert>
  51. <delete id="deleteBatch">
  52. delete from watch_company where device_id = #{deviceId} and company_id in
  53. <foreach item="id" collection="list" open="(" separator="," close=")">
  54. #{id}
  55. </foreach>
  56. </delete>
  57. </mapper>