ProductBelongMapper.xml 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  3. <mapper namespace="com.hcloud.microserver.bank.dao.ProductBelongMapper">
  4. <resultMap id="BaseResultMap" type="com.hcloud.microserver.facade.carbon.entity.ProductBelong">
  5. <id column="guid" jdbcType="CHAR" property="guid"/>
  6. <result column="fk_product_guid" jdbcType="CHAR" property="fkProductGuid"/>
  7. <result column="fk_farmer_guid" jdbcType="CHAR" property="fkFarmerGuid"/>
  8. <result column="fk_collective_guid" jdbcType="CHAR" property="fkCollectiveGuid"/>
  9. <result column="farmer_name" jdbcType="VARCHAR" property="farmerName"/>
  10. <result column="farmer_village" jdbcType="VARCHAR" property="farmerVillage"/>
  11. <result column="farmer_num" jdbcType="INTEGER" property="farmerNum"/>
  12. <result column="state" jdbcType="INTEGER" property="state"/>
  13. <result column="create_time" jdbcType="TIMESTAMP" property="createTime"/>
  14. <result column="modified_time" jdbcType="TIMESTAMP" property="modifiedTime"/>
  15. <result column="belong_type" jdbcType="INTEGER" property="belongType"/>
  16. <discriminator javaType="int" column="belong_type">
  17. <case value="1" resultMap="farmerMap"></case>
  18. <case value="2" resultMap="collectiveMap"></case>
  19. </discriminator>
  20. </resultMap>
  21. <resultMap id="collectiveMap" type="com.hcloud.microserver.facade.carbon.entity.CollectiveProductBelong" extends="BaseResultMap">
  22. <association property="collectiveFarmer" select="com.hcloud.microserver.bank.dao.CollectiveFarmerMapper.selectByPrimaryKey" column="fk_farmer_guid"/>
  23. </resultMap>
  24. <resultMap id="farmerMap" type="com.hcloud.microserver.facade.carbon.entity.FarmerProductBelong" extends="BaseResultMap">
  25. <association property="farmerInfo" select="com.hcloud.microserver.bank.dao.FarmerInfoMapper.selectByPrimaryKey" column="fk_farmer_guid"/>
  26. </resultMap>
  27. <sql id="Base_Column_List">
  28. guid, fk_product_guid, fk_farmer_guid, fk_collective_guid, farmer_name, farmer_village, farmer_num, state,
  29. create_time, modified_time, belong_type
  30. </sql>
  31. <select id="selectByPrimaryKey" parameterType="java.lang.String" resultMap="BaseResultMap">
  32. select
  33. <include refid="Base_Column_List"/>
  34. from t_product_belong
  35. where guid = #{guid,jdbcType=CHAR}
  36. </select>
  37. <delete id="deleteByPrimaryKey" parameterType="java.lang.String">
  38. delete from t_product_belong
  39. where guid = #{guid,jdbcType=CHAR}
  40. </delete>
  41. <insert id="insert" parameterType="com.hcloud.microserver.facade.carbon.entity.ProductBelong">
  42. insert into t_product_belong (guid, fk_product_guid, fk_farmer_guid, fk_collective_guid
  43. farmer_name, farmer_village, farmer_num,
  44. state, create_time, modified_time, belong_type
  45. )
  46. values (#{guid,jdbcType=CHAR}, #{fkProductGuid,jdbcType=CHAR}, #{fkFarmerGuid,jdbcType=CHAR}, #{fkCollectiveGuid,jdbcType=VARCHAR},
  47. #{farmerName,jdbcType=VARCHAR}, #{farmerVillage,jdbcType=VARCHAR}, #{farmerNum,jdbcType=INTEGER},
  48. #{state,jdbcType=INTEGER}, #{createTime,jdbcType=TIMESTAMP}, #{modifiedTime,jdbcType=TIMESTAMP}, #{belongType,jdbcType=INTEGER}
  49. )
  50. </insert>
  51. <insert id="insertSelective" parameterType="com.hcloud.microserver.facade.carbon.entity.ProductBelong">
  52. insert into t_product_belong
  53. <trim prefix="(" suffix=")" suffixOverrides=",">
  54. <if test="guid != null">
  55. guid,
  56. </if>
  57. <if test="fkProductGuid != null">
  58. fk_product_guid,
  59. </if>
  60. <if test="fkFarmerGuid != null">
  61. fk_farmer_guid,
  62. </if>
  63. <if test="fkCollectiveGuid != null and fkCollectiveGuid != ''">
  64. fk_collective_guid,
  65. </if>
  66. <if test="farmerName != null">
  67. farmer_name,
  68. </if>
  69. <if test="farmerVillage != null">
  70. farmer_village,
  71. </if>
  72. <if test="farmerNum != null">
  73. farmer_num,
  74. </if>
  75. <if test="state != null">
  76. state,
  77. </if>
  78. <if test="createTime != null">
  79. create_time,
  80. </if>
  81. <if test="modifiedTime != null">
  82. modified_time,
  83. </if>
  84. <if test="belongType != null">
  85. belong_type,
  86. </if>
  87. </trim>
  88. <trim prefix="values (" suffix=")" suffixOverrides=",">
  89. <if test="guid != null">
  90. #{guid,jdbcType=CHAR},
  91. </if>
  92. <if test="fkProductGuid != null">
  93. #{fkProductGuid,jdbcType=CHAR},
  94. </if>
  95. <if test="fkFarmerGuid != null">
  96. #{fkFarmerGuid,jdbcType=CHAR},
  97. </if>
  98. <if test="fkCollectiveGuid != null and fkCollectiveGuid != ''">
  99. #{fkCollectiveGuid,jdbcType=VARCHAR},
  100. </if>
  101. <if test="farmerName != null">
  102. #{farmerName,jdbcType=VARCHAR},
  103. </if>
  104. <if test="farmerVillage != null">
  105. #{farmerVillage,jdbcType=VARCHAR},
  106. </if>
  107. <if test="farmerNum != null">
  108. #{farmerNum,jdbcType=INTEGER},
  109. </if>
  110. <if test="state != null">
  111. #{state,jdbcType=INTEGER},
  112. </if>
  113. <if test="createTime != null">
  114. #{createTime,jdbcType=TIMESTAMP},
  115. </if>
  116. <if test="modifiedTime != null">
  117. #{modifiedTime,jdbcType=TIMESTAMP},
  118. </if>
  119. <if test="belongType != null">
  120. #{belongType,jdbcType=INTEGER},
  121. </if>
  122. </trim>
  123. </insert>
  124. <update id="updateByPrimaryKeySelective" parameterType="com.hcloud.microserver.facade.carbon.entity.ProductBelong">
  125. update t_product_belong
  126. <set>
  127. <if test="fkProductGuid != null">
  128. fk_product_guid = #{fkProductGuid,jdbcType=CHAR},
  129. </if>
  130. <if test="fkFarmerGuid != null">
  131. fk_farmer_guid = #{fkFarmerGuid,jdbcType=CHAR},
  132. </if>
  133. <if test="fkCollectiveGuid != null and fkCollectiveGuid != ''">
  134. fk_collective_guid = #{fkCollectiveGuid,jdbcType=VARCHAR},
  135. </if>
  136. <if test="farmerName != null">
  137. farmer_name = #{farmerName,jdbcType=VARCHAR},
  138. </if>
  139. <if test="farmerVillage != null">
  140. farmer_village = #{farmerVillage,jdbcType=VARCHAR},
  141. </if>
  142. <if test="farmerNum != null">
  143. farmer_num = #{farmerNum,jdbcType=INTEGER},
  144. </if>
  145. <if test="state != null">
  146. state = #{state,jdbcType=INTEGER},
  147. </if>
  148. <if test="createTime != null">
  149. create_time = #{createTime,jdbcType=TIMESTAMP},
  150. </if>
  151. <if test="modifiedTime != null">
  152. modified_time = #{modifiedTime,jdbcType=TIMESTAMP},
  153. </if>
  154. <if test="belongType != null">
  155. belong_type = #{belongType,jdbcType=INTEGER},
  156. </if>
  157. </set>
  158. where guid = #{guid,jdbcType=CHAR}
  159. </update>
  160. <update id="updateByPrimaryKey" parameterType="com.hcloud.microserver.facade.carbon.entity.ProductBelong">
  161. update t_product_belong
  162. set fk_product_guid = #{fkProductGuid,jdbcType=CHAR},
  163. fk_farmer_guid = #{fkFarmerGuid,jdbcType=CHAR},
  164. fk_collective_guid = #{fkCollectiveGuid,jdbcType=VARCHAR},
  165. farmer_name = #{farmerName,jdbcType=VARCHAR},
  166. farmer_village = #{farmerVillage,jdbcType=VARCHAR},
  167. farmer_num = #{farmerNum,jdbcType=INTEGER},
  168. state = #{state,jdbcType=INTEGER},
  169. create_time = #{createTime,jdbcType=TIMESTAMP},
  170. modified_time = #{modifiedTime,jdbcType=TIMESTAMP},
  171. belong_type = #{belongType,jdbcType=INTEGER}
  172. where guid = #{guid,jdbcType=CHAR}
  173. </update>
  174. <insert id="batchInsert" parameterType="java.util.List">
  175. insert into t_product_belong (<include refid="Base_Column_List"/>)
  176. values
  177. <foreach collection="list" item="item" index="index" separator=",">
  178. (
  179. #{item.guid,jdbcType=VARCHAR},
  180. #{item.fkProductGuid,jdbcType=VARCHAR},
  181. #{item.fkFarmerGuid,jdbcType=VARCHAR},
  182. #{item.fkCollectiveGuid,jdbcType=VARCHAR},
  183. #{item.farmerName,jdbcType=VARCHAR},
  184. #{item.farmerVillage,jdbcType=VARCHAR},
  185. #{item.farmerNum,jdbcType=INTEGER},
  186. #{item.state,jdbcType=INTEGER},
  187. #{item.createTime,jdbcType=TIMESTAMP},
  188. #{item.modifiedTime,jdbcType=TIMESTAMP},
  189. #{item.belongType,jdbcType=INTEGER}
  190. )
  191. </foreach>
  192. </insert>
  193. <delete id="deleteByProductInfoGuid" parameterType="string">
  194. delete from t_product_belong where fk_product_guid = #{productInfoGuid,jdbcType=VARCHAR}
  195. </delete>
  196. <select id="selectByProductGuid" parameterType="string" resultMap="BaseResultMap">
  197. select guid, fk_product_guid, fk_farmer_guid, fk_collective_guid,
  198. (CASE belong_type WHEN 1 THEN farmer_name ELSE farmer_village END ) AS farmer_name,
  199. farmer_village, farmer_num, state, create_time, modified_time, belong_type
  200. from t_product_belong
  201. where fk_product_guid = #{productInfoGuid,jdbcType=CHAR}
  202. </select>
  203. <delete id="deleteByProductInfoGuids" parameterType="list">
  204. delete from t_product_belong where fk_product_guid in
  205. <foreach collection="list" item="item" open="(" close=")" separator=",">
  206. #{item}
  207. </foreach>
  208. </delete>
  209. </mapper>