CustomerMapper.xml 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  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.zhyc.xps.sys.mapper.CustomerMapper">
  4. <!-- 通用查询映射结果 -->
  5. <resultMap id="CustomerResultMap" type="com.zhyc.xps.sys.dto.CustomerDto">
  6. <result column="oc_id" property="ocId" jdbcType="BIGINT" />
  7. <result column="customer_id" property="customerId" jdbcType="BIGINT" />
  8. <result column="customer_name" property="customerName" jdbcType="VARCHAR" />
  9. <result column="customer_code" property="customerCode" jdbcType="VARCHAR" />
  10. <result column="customer_card_no" property="customerCardNo" jdbcType="VARCHAR" />
  11. <result column="customer_phone" property="customerPhone" jdbcType="VARCHAR" />
  12. <result column="customer_remark" property="customerRemark" jdbcType="VARCHAR" />
  13. <result column="wx_id" property="wxId" jdbcType="VARCHAR" />
  14. </resultMap>
  15. <!-- 通用查询结果列 -->
  16. <sql id="CustomerDto_Cols">
  17. A.oc_id,
  18. A.customer_id,
  19. A.customer_name,
  20. A.customer_code,
  21. A.customer_card_no,
  22. A.wx_id,
  23. A.customer_remark
  24. </sql>
  25. <!--基于ID查询-->
  26. <select id="getById" resultMap="CustomerResultMap">
  27. SELECT
  28. <include refid="CustomerDto_Cols"/>
  29. FROM customer AS A
  30. WHERE A.deleted_flag = 0
  31. AND A.oc_id = #{ocId ,jdbcType=BIGINT}
  32. AND A.customer_id = #{customerId ,jdbcType=BIGINT}
  33. </select>
  34. <!--基于WxID查询-->
  35. <select id="getByWxId" resultMap="CustomerResultMap">
  36. SELECT
  37. <include refid="CustomerDto_Cols"/>
  38. FROM customer AS A
  39. WHERE A.deleted_flag = 0
  40. AND A.oc_id = #{ocId ,jdbcType=BIGINT}
  41. AND A.wx_id = #{wxId ,jdbcType=VARCHAR}
  42. </select>
  43. <!--基于Phone查询-->
  44. <select id="getByPhone" resultMap="CustomerResultMap">
  45. SELECT
  46. <include refid="CustomerDto_Cols"/>
  47. FROM customer AS A
  48. WHERE A.deleted_flag = 0
  49. AND A.oc_id = #{ocId ,jdbcType=BIGINT}
  50. AND A.customer_phone = #{customerPhone ,jdbcType=VARCHAR}
  51. </select>
  52. <!--分页查询-->
  53. <select id="getByPage" parameterType="java.util.Map" resultMap="CustomerResultMap" >
  54. SELECT
  55. <include refid="CustomerDto_Cols"/>
  56. FROM customer AS A
  57. WHERE A.deleted_flag = 0
  58. <if test="keywords != null and keywords != ''">
  59. AND A.customer_name like "%"#{keywords}"%"
  60. </if>
  61. ORDER BY A.oc_id, A.customer_id
  62. </select>
  63. <!--列表查询-->
  64. <select id="getByList" parameterType="java.util.Map" resultMap="CustomerResultMap">
  65. SELECT
  66. <include refid="CustomerDto_Cols"/>
  67. FROM customer AS A
  68. WHERE A.deleted_flag = 0
  69. <if test="keywords != null and keywords != ''">
  70. AND A.customer_name like "%"#{keywords}"%"
  71. </if>
  72. ORDER BY A.oc_id, A.customer_id
  73. </select>
  74. <insert id="create" parameterType="com.zhyc.xps.sys.entity.Customer">
  75. INSERT INTO customer
  76. <trim prefix="(" suffix=")" suffixOverrides=",">
  77. <if test="ocId != null">
  78. oc_id,
  79. </if>
  80. <if test="customerId != null">
  81. customer_id,
  82. </if>
  83. <if test="customerName != null and customerName != ''">
  84. customer_name,
  85. </if>
  86. <if test="customerCode != null and customerCode != ''">
  87. customer_code,
  88. </if>
  89. <if test="customerCardNo != null and customerCardNo != ''">
  90. customer_card_no,
  91. </if>
  92. <if test="customerPhone != null and customerPhone != ''">
  93. customer_phone,
  94. </if>
  95. <if test="customerRemark != null and customerRemark != ''">
  96. customer_remark,
  97. </if>
  98. <if test="wxId != null and wxId != ''">
  99. wx_id,
  100. </if>
  101. <if test="createdBy != null">
  102. created_by,
  103. </if>
  104. <if test="createdAt != null">
  105. created_at,
  106. </if>
  107. </trim>
  108. <trim prefix="values (" suffix=")" suffixOverrides=",">
  109. <if test="ocId != null">
  110. #{ocId,jdbcType=BIGINT},
  111. </if>
  112. <if test="customerId != null">
  113. #{customerId ,jdbcType=BIGINT},
  114. </if>
  115. <if test="customerName != null and customerName != ''">
  116. #{customerName ,jdbcType=VARCHAR},
  117. </if>
  118. <if test="customerCode != null and customerCode != ''">
  119. #{customerCode ,jdbcType=VARCHAR},
  120. </if>
  121. <if test="customerCardNo != null and customerCardNo != ''">
  122. #{customerCardNo ,jdbcType=VARCHAR},
  123. </if>
  124. <if test="customerPhone != null and customerPhone != ''">
  125. #{customerPhone ,jdbcType=VARCHAR},
  126. </if>
  127. <if test="customerRemark != null and customerRemark != ''">
  128. #{customerRemark ,jdbcType=VARCHAR},
  129. </if>
  130. <if test="wxId != null and wxId != ''">
  131. #{wxId ,jdbcType=VARCHAR},
  132. </if>
  133. <if test="createdBy != null">
  134. #{createdBy ,jdbcType=BIGINT},
  135. </if>
  136. <if test="createdAt != null">
  137. #{createdAt ,jdbcType=TIMESTAMP},
  138. </if>
  139. </trim>
  140. </insert>
  141. <!--更新-->
  142. <update id="update" parameterType="com.zhyc.xps.sys.entity.Customer">
  143. UPDATE customer
  144. <trim suffixOverrides=",">
  145. <set>
  146. <if test="customerName != null and customerName != ''">
  147. customer_name = #{customerName, jdbcType=VARCHAR},
  148. </if>
  149. <if test="customerCode != null and customerCode != ''">
  150. customer_code = #{customerCode ,jdbcType=VARCHAR},
  151. </if>
  152. <if test="customerCardNo != null">
  153. customer_card_no = #{customerCardNo ,jdbcType=VARCHAR},
  154. </if>
  155. <if test="customerPhone != null">
  156. customer_phone = #{customerPhone ,jdbcType=VARCHAR},
  157. </if>
  158. <if test="customerRemark != null">
  159. customer_remark = #{customerRemark, jdbcType=VARCHAR},
  160. </if>
  161. <if test="wxId != null">
  162. wx_id = #{wxId ,jdbcType=VARCHAR},
  163. </if>
  164. <if test="updatedBy != null ">
  165. updated_by = #{updatedBy ,jdbcType=BIGINT},
  166. </if>
  167. <if test="updatedAt != null">
  168. updated_at = #{updatedAt ,jdbcType=TIMESTAMP},
  169. </if>
  170. </set>
  171. </trim>
  172. WHERE oc_id = #{ocId ,jdbcType=BIGINT}
  173. AND customer_id = #{customerId ,jdbcType=BIGINT}
  174. </update>
  175. <!--删除-->
  176. <update id="delete" parameterType="java.util.Map">
  177. UPDATE customer
  178. <trim suffixOverrides=",">
  179. <set>
  180. <if test="deletedFlag != null">
  181. deleted_flag = #{deletedFlag,jdbcType=BIGINT},
  182. </if>
  183. <if test="deletedTime != null">
  184. deleted_time = #{deletedTime,jdbcType=TIMESTAMP},
  185. </if>
  186. <if test="deletedBy != null">
  187. deleted_by = #{deletedBy,jdbcType=BIGINT},
  188. </if>
  189. </set>
  190. </trim>
  191. WHERE 1 = 1
  192. <if test="ocId != null">
  193. AND oc_id = #{ocId,jdbcType=BIGINT}
  194. </if>
  195. <if test="customerId != null">
  196. AND customer_id = #{customerId ,jdbcType=BIGINT}
  197. </if>
  198. </update>
  199. </mapper>