CmRelatedMapper.xml 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  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.caimei365.manager.dao.CmRelatedMapper">
  6. <resultMap type="CmRelated" id="CmRelatedResult">
  7. <result property="id" column="id" />
  8. <result property="type" column="type" />
  9. <result property="authorId" column="authorId" />
  10. <result property="relatedId" column="relatedId" />
  11. <result property="delFlag" column="delFlag" />
  12. <result property="updateTime" column="updateTime" />
  13. <result property="createTime" column="createTime" />
  14. <result property="sort" column="sort" />
  15. </resultMap>
  16. <sql id="selectCmRelatedVo">
  17. select
  18. cm_related.id,
  19. cm_related.type,
  20. cm_related.authorId,
  21. cm_related.relatedId,
  22. cm_related.delFlag,
  23. cm_related.updateTime,
  24. cm_related.createTime,
  25. cm_related.sort
  26. </sql>
  27. <select id="getByCmRelated" parameterType="CmRelated" resultMap="CmRelatedResult">
  28. <include refid="selectCmRelatedVo"/>
  29. from cm_related AS cm_related
  30. <where> cm_related.delFlag = 0
  31. <if test="id != null and id != ''"> and cm_related.id = #{id}</if>
  32. <if test="type != null and type != ''"> and cm_related.type = #{type}</if>
  33. <if test="authorId != null and authorId != ''"> and cm_related.authorId = #{authorId}</if>
  34. <if test="relatedId != null and relatedId != ''"> and cm_related.relatedId = #{relatedId}</if>
  35. <if test="sort != null "> and cm_related.sort = #{sort}</if>
  36. </where>
  37. group by cm_related.id
  38. limit 0,1
  39. </select>
  40. <select id="getCmRelatedList" parameterType="CmRelated" resultMap="CmRelatedResult">
  41. <include refid="selectCmRelatedVo"/>
  42. from cm_related AS cm_related
  43. <where> cm_related.delFlag = 0
  44. <if test="id != null and id != ''"> and cm_related.id = #{id}</if>
  45. <if test="type != null and type != ''">
  46. and cm_related.type
  47. <if test="type.toUpperCase().indexOf('=')==-1">
  48. = #{type}
  49. </if>
  50. <if test="type.toUpperCase().indexOf('=')!=-1">
  51. <if test="type.toUpperCase().indexOf('NOT')!=-1"> not </if>
  52. <if test="type.toUpperCase().indexOf('IN')!=-1"> in </if>
  53. <foreach item="typeIn" collection="type.substring(type.toUpperCase().indexOf('=')+1,type.length()).trim().split(',')" open="(" separator="," close=")">
  54. #{typeIn}
  55. </foreach>
  56. </if>
  57. </if>
  58. <if test="authorId != null and authorId != ''"> and cm_related.authorId = #{authorId}</if>
  59. <if test="relatedId != null and relatedId != ''"> and cm_related.relatedId = #{relatedId}</if>
  60. <if test="sort != null "> and cm_related.sort = #{sort}</if>
  61. </where>
  62. group by cm_related.id
  63. order by cm_related.createTime desc
  64. </select>
  65. <select id="getCount" parameterType="CmRelated" resultType="int">
  66. select count(1)
  67. from cm_related AS cm_related
  68. <where> cm_related.delFlag = 0
  69. <if test="id != null and id != ''"> and cm_related.id = #{id}</if>
  70. <if test="type != null and type != ''"> and cm_related.type = #{type}</if>
  71. <if test="authorId != null and authorId != ''"> and cm_related.authorId = #{authorId}</if>
  72. <if test="relatedId != null and relatedId != ''"> and cm_related.relatedId = #{relatedId}</if>
  73. <if test="sort != null "> and cm_related.sort = #{sort}</if>
  74. </where>
  75. </select>
  76. <select id="getCmRelatedById" parameterType="String" resultMap="CmRelatedResult">
  77. <include refid="selectCmRelatedVo"/>
  78. from cm_related AS cm_related
  79. where cm_related.delFlag = 0 and cm_related.id = #{id}
  80. </select>
  81. <select id="getById" parameterType="CmRelated" resultType="String">
  82. select id
  83. from cm_related AS cm_related
  84. <where> cm_related.delFlag = 0
  85. <if test="id != null and id != ''"> and cm_related.id = #{id}</if>
  86. <if test="type != null and type != ''"> and cm_related.type = #{type}</if>
  87. <if test="authorId != null and authorId != ''"> and cm_related.authorId = #{authorId}</if>
  88. <if test="relatedId != null and relatedId != ''"> and cm_related.relatedId = #{relatedId}</if>
  89. <if test="sort != null "> and cm_related.sort = #{sort}</if>
  90. </where>
  91. group by cm_related.id
  92. limit 0,1
  93. </select>
  94. <insert id="addCmRelated" parameterType="CmRelated" useGeneratedKeys="true" keyProperty="id">
  95. insert into cm_related
  96. <trim prefix="(" suffix=")" suffixOverrides=",">
  97. <if test="id != null and id != ''">id,</if>
  98. <if test="type != null and type != ''">type,</if>
  99. <if test="authorId != null and authorId != ''">authorId,</if>
  100. <if test="relatedId != null and relatedId != ''">relatedId,</if>
  101. <if test="delFlag != null">delFlag,</if>
  102. <if test="updateTime != null">updateTime,</if>
  103. <if test="createTime != null">createTime,</if>
  104. <if test="sort != null">sort,</if>
  105. </trim>
  106. <trim prefix="values (" suffix=")" suffixOverrides=",">
  107. <if test="id != null and id != ''">#{id},</if>
  108. <if test="type != null and type != ''">#{type},</if>
  109. <if test="authorId != null and authorId != ''">#{authorId},</if>
  110. <if test="relatedId != null and relatedId != ''">#{relatedId},</if>
  111. <if test="delFlag != null">#{delFlag},</if>
  112. <if test="updateTime != null">#{updateTime},</if>
  113. <if test="createTime != null">#{createTime},</if>
  114. <if test="sort != null">#{sort},</if>
  115. </trim>
  116. </insert>
  117. <update id="updateCmRelated" parameterType="CmRelated">
  118. update cm_related
  119. <trim prefix="SET" suffixOverrides=",">
  120. <if test="type != null and type != ''">type = #{type},</if>
  121. <if test="authorId != null and authorId != ''">authorId = #{authorId},</if>
  122. <if test="relatedId != null and relatedId != ''">relatedId = #{relatedId},</if>
  123. <if test="delFlag != null">delFlag = #{delFlag},</if>
  124. <if test="updateTime != null">updateTime = #{updateTime},</if>
  125. <if test="createTime != null">createTime = #{createTime},</if>
  126. <if test="sort != null">sort = #{sort},</if>
  127. </trim>
  128. where id = #{id}
  129. </update>
  130. <delete id="delCmRelatedById" parameterType="String">
  131. delete
  132. from cm_related where id = #{id}
  133. </delete>
  134. <delete id="delCmRelated" parameterType="CmRelated">
  135. delete
  136. from cm_related AS cm_related
  137. <where>
  138. <if test="id != null and id != ''"> and cm_related.id = #{id}</if>
  139. <if test="type != null and type != ''"> and cm_related.type = #{type}</if>
  140. <if test="authorId != null and authorId != ''"> and cm_related.authorId = #{authorId}</if>
  141. <if test="relatedId != null and relatedId != ''"> and cm_related.relatedId = #{relatedId}</if>
  142. <if test="sort != null "> and cm_related.sort = #{sort}</if>
  143. </where>
  144. </delete>
  145. </mapper>