CustomerCouponMapper.xml 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361
  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.ygj.yuemum.dao.customer.CustomerCouponDao" >
  4. <resultMap id="BaseResultMap" type="com.ygj.yuemum.domain.customer.CustomerCoupon" >
  5. <id column="id" property="id" jdbcType="INTEGER" />
  6. <result column="cm_code" property="cm_code" jdbcType="VARCHAR" />
  7. <result column="cm_phone" property="cm_phone" jdbcType="VARCHAR" />
  8. <result column="cb_code" property="cb_code" jdbcType="VARCHAR" />
  9. <result column="cc_code" property="cc_code" jdbcType="VARCHAR" />
  10. <result column="cp_status" property="cp_status" jdbcType="INTEGER" />
  11. <result column="cc_getdate" property="cc_getdate" jdbcType="DATE" />
  12. <result column="cc_getchannel" property="cc_getchannel" jdbcType="INTEGER" />
  13. <result column="cc_usedate" property="cc_usedate" jdbcType="DATE" />
  14. <result column="cc_usebillno" property="cc_usebillno" jdbcType="VARCHAR" />
  15. <result column="cb_name" property="cb_name" jdbcType="VARCHAR" />
  16. <result column="cb_rule" property="cb_rule" jdbcType="VARCHAR" />
  17. <result column="cb_packages" property="cb_packages" jdbcType="VARCHAR" />
  18. <result column="cb_citys" property="cb_citys" jdbcType="VARCHAR" />
  19. <result column="cp_enddate" property="cp_enddate" jdbcType="VARCHAR" />
  20. <result column="cp_amount" property="cp_amount" jdbcType="INTEGER" />
  21. <result column="cc_quantity" property="cc_quantity" jdbcType="INTEGER" />
  22. </resultMap>
  23. <sql id="Base_Column_List" >
  24. id, cm_code,cm_phone,cb_code,cc_code,cp_status,cc_getdate,cc_getchannel,cc_usedate,cc_usebillno
  25. </sql>
  26. <!--获取所有数据-->
  27. <select id="getCount" resultType="java.lang.Integer" >
  28. select
  29. count(1)
  30. from customer_coupon
  31. </select>
  32. <select id="getAll" resultMap="BaseResultMap" >
  33. select
  34. id, cm_code,cm_phone,cb_code,cc_code,cp_status,cc_getdate,cc_getchannel,cc_usedate,cc_usebillno
  35. from customer_coupon
  36. order by id desc
  37. </select>
  38. <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
  39. select
  40. <include refid="Base_Column_List" />
  41. from customer_coupon
  42. where id = #{id,jdbcType=INTEGER}
  43. </select>
  44. <select id="getCouponSum" resultMap="BaseResultMap" parameterType="com.ygj.yuemum.domain.customer.CustomerCouponQuery" >
  45. SELECT
  46. cm_phone,
  47. count(1) cc_quantity,
  48. sum(cp_amount) cp_amount
  49. FROM
  50. (
  51. SELECT
  52. ta.cm_phone,
  53. ta.cc_code,
  54. tb.cb_packages,
  55. tb.cb_citys
  56. FROM
  57. customer_coupon ta
  58. LEFT JOIN coupon_batch tb ON ta.cb_code = tb.cb_code
  59. where ta.cp_status = 2
  60. <if test="cm_phone != null and cm_phone != ''" >
  61. and ta.cm_phone = #{cm_phone,jdbcType=VARCHAR}
  62. </if>
  63. <if test="cb_packages != null and cb_packages != ''">
  64. and tb.cb_packages like "%"#{cb_packages,jdbcType=VARCHAR}"%"
  65. </if>
  66. <if test="cb_citys != null and cb_citys != ''">
  67. and tb.cb_citys like "%"#{cb_citys,jdbcType=VARCHAR}"%"
  68. </if>
  69. ) tta,
  70. coupon ttb
  71. WHERE
  72. tta.cc_code = ttb.cp_code
  73. group by tta.cm_phone
  74. </select>
  75. <select id="getCustomerCoupons" resultMap="BaseResultMap" parameterType="com.ygj.yuemum.domain.customer.CustomerCouponQuery" >
  76. SELECT
  77. ta.cc_code,
  78. tb.cb_name,
  79. tb.cb_rule,
  80. fgetpackages(tb.id) cb_packages,
  81. fgetmoretcityname(tb.id) cb_citys,
  82. tc.cp_startdate,
  83. tc.cp_enddate,
  84. tc.cp_amount,
  85. cc_getdate,
  86. ta.cp_status
  87. FROM
  88. customer_coupon ta
  89. LEFT JOIN coupon_batch tb ON ta.cb_code = tb.cb_code
  90. left JOIN coupon tc on ta.cc_code = tc.cp_code
  91. where
  92. 1=1
  93. <if test="cm_phone != null and cm_phone != ''" >
  94. and ta.cm_phone = #{cm_phone,jdbcType=VARCHAR}
  95. </if>
  96. <if test="cb_packages != null and cb_packages != ''">
  97. and tb.cb_packages like "%"#{cb_packages,jdbcType=VARCHAR}"%"
  98. </if>
  99. <if test="cb_citys != null and cb_citys != ''">
  100. and tb.cb_citys like "%"#{cb_citys,jdbcType=VARCHAR}"%"
  101. </if>
  102. and ta.cp_status = 2
  103. order by ta.cb_code ,tc.cp_amount desc
  104. </select>
  105. <select id="getWXCustomerCoupons" resultMap="BaseResultMap" parameterType="java.lang.String" >
  106. SELECT
  107. ta.cc_code,
  108. tb.cb_name,
  109. tb.cb_rule,
  110. fgetpackages(tb.id) cb_packages,
  111. fgetmoretcityname(tb.id) cb_citys,
  112. DATE_FORMAT(tc.cp_startdate,'%Y.%m.%d') cp_startdate,
  113. DATE_FORMAT(tc.cp_enddate,'%Y.%m.%d') cp_enddate,
  114. tc.cp_amount,
  115. cc_getdate,
  116. ta.cp_status
  117. FROM
  118. customer_coupon ta
  119. LEFT JOIN coupon_batch tb ON ta.cb_code = tb.cb_code
  120. left JOIN coupon tc on ta.cc_code = tc.cp_code
  121. where
  122. ta.cm_phone = #{cm_phone,jdbcType=VARCHAR}
  123. order by ta.cb_code ,tc.cp_amount desc
  124. </select>
  125. <select id="getCustomerCouponsCount" resultType="java.lang.Integer" parameterType="com.ygj.yuemum.domain.customer.CustomerCouponQuery" >
  126. SELECT
  127. count(1)
  128. FROM
  129. customer_coupon ta
  130. LEFT JOIN coupon_batch tb ON ta.cb_code = tb.cb_code
  131. left JOIN coupon tc on ta.cc_code = tc.cp_code
  132. where
  133. 1=1
  134. <if test="cm_phone != null and cm_phone != ''" >
  135. and ta.cm_phone = #{cm_phone,jdbcType=VARCHAR}
  136. </if>
  137. <if test="cb_packages != null and cb_packages != ''">
  138. and tb.cb_packages like "%"#{cb_packages,jdbcType=VARCHAR}"%"
  139. </if>
  140. <if test="cb_citys != null and cb_citys != ''">
  141. and tb.cb_citys like "%"#{cb_citys,jdbcType=VARCHAR}"%"
  142. </if>
  143. and ta.cp_status = 2
  144. order by ta.cb_code ,tc.cp_amount desc
  145. </select>
  146. <select id="checkCustomerCoupon" resultType="java.lang.Integer" parameterType="com.ygj.yuemum.domain.customer.CustomerCoupon" >
  147. SELECT
  148. count(1)
  149. FROM
  150. customer_coupon
  151. WHERE
  152. 1=1
  153. <if test="_parameter != null" >
  154. and cm_phone = #{cm_phone,jdbcType=VARCHAR}
  155. </if>
  156. <if test="cb_code != null" >
  157. and cb_code = #{cb_code,jdbcType=VARCHAR}
  158. </if>
  159. </select>
  160. <select id="checkSumCustomerCoupon" resultType="java.lang.Integer" parameterType="java.lang.String" >
  161. SELECT
  162. ifnull(sum(tb.cp_amount), 0)
  163. FROM
  164. customer_coupon ta,
  165. coupon tb
  166. WHERE
  167. ta.cc_code = tb.cp_code
  168. <if test="_parameter != null" >
  169. and cm_phone = #{cm_phone,jdbcType=VARCHAR}
  170. </if>
  171. AND ta.cp_status = 1
  172. AND tb.cc_code IN (
  173. 'PVP2018051297451',
  174. 'PVP2018051273883',
  175. 'PVP2018051211608',
  176. 'PVP2018051263016'
  177. )
  178. </select>
  179. <delete id="deleteByPrimaryKey" parameterType="java.lang.String" >
  180. delete from customer_coupon
  181. where cb_code = #{cb_code,jdbcType=VARCHAR}
  182. </delete>
  183. <!-- 插入一条培训信息 -->
  184. <insert id="insertSelective" parameterType="com.ygj.yuemum.domain.customer.CustomerCoupon" >
  185. insert into customer_coupon
  186. <trim prefix="(" suffix=")" suffixOverrides="," >
  187. <if test="cm_code != null" >
  188. cm_code,
  189. </if>
  190. <if test="cm_phone != null" >
  191. cm_phone,
  192. </if>
  193. <if test="cb_code != null" >
  194. cb_code,
  195. </if>
  196. <if test="cc_code != null" >
  197. cc_code,
  198. </if>
  199. <if test="cp_status != null" >
  200. cp_status,
  201. </if>
  202. <if test="cc_getdate != null" >
  203. cc_getdate,
  204. </if>
  205. <if test="cc_getchannel != null" >
  206. cc_getchannel,
  207. </if>
  208. <if test="cc_usedate != null" >
  209. cc_usedate,
  210. </if>
  211. <if test="cc_usebillno != null" >
  212. cc_usebillno
  213. </if>
  214. </trim>
  215. <trim prefix="values (" suffix=")" suffixOverrides="," >
  216. <if test="cm_code != null" >
  217. #{cm_code,jdbcType=VARCHAR},
  218. </if>
  219. <if test="cm_phone != null" >
  220. #{cm_phone,jdbcType=VARCHAR},
  221. </if>
  222. <if test="cb_code != null" >
  223. #{cb_code,jdbcType=VARCHAR},
  224. </if>
  225. <if test="cc_code != null" >
  226. #{cc_code,jdbcType=VARCHAR},
  227. </if>
  228. <if test="cp_status != null" >
  229. #{cp_status,jdbcType=INTEGER},
  230. </if>
  231. <if test="cc_getdate != null" >
  232. #{cc_getdate,jdbcType=DATE},
  233. </if>
  234. <if test="cc_getchannel != null" >
  235. #{cc_getchannel,jdbcType=INTEGER},
  236. </if>
  237. <if test="cc_usedate != null" >
  238. #{cc_usedate,jdbcType=DATE},
  239. </if>
  240. <if test="cc_usebillno != null" >
  241. #{cc_usebillno,jdbcType=VARCHAR}
  242. </if>
  243. </trim>
  244. </insert>
  245. <!-- 根据id更新一条培训信息 -->
  246. <update id="updateByPrimaryKeySelective" parameterType="com.ygj.yuemum.domain.customer.CustomerCoupon" >
  247. update customer_coupon
  248. <set >
  249. <if test="cm_code != null" >
  250. cm_code = #{cm_code,jdbcType=VARCHAR},
  251. </if>
  252. <if test="cm_phone != null" >
  253. cm_phone = #{cm_phone,jdbcType=VARCHAR},
  254. </if>
  255. <if test="cb_rule != null" >
  256. cb_rule = #{cb_rule,jdbcType=VARCHAR},
  257. </if>
  258. <if test="cb_packages != null" >
  259. cb_packages = #{cb_packages,jdbcType=VARCHAR},
  260. </if>
  261. <if test="cb_citys != null" >
  262. cb_citys = #{cb_citys,jdbcType=VARCHAR}
  263. </if>
  264. <if test="cb_citys != null" >
  265. cb_citys = #{cb_citys,jdbcType=VARCHAR}
  266. </if>
  267. <if test="cb_citys != null" >
  268. cb_citys = #{cb_citys,jdbcType=VARCHAR}
  269. </if>
  270. <if test="cb_citys != null" >
  271. cb_citys = #{cb_citys,jdbcType=VARCHAR}
  272. </if>
  273. </set>
  274. where id = #{id,jdbcType=INTEGER}
  275. </update>
  276. <select id="getQCouponBatchconut" resultType="java.lang.Integer" parameterType="com.ygj.yuemum.domain.customer.CustomerCoupon">
  277. select
  278. count(1)
  279. from customer_coupon
  280. where 1=1
  281. <if test="id != null and id != ''">
  282. and id = #{id,jdbcType=INTEGER}
  283. </if>
  284. <if test="cb_code != null and cb_code != ''">
  285. and cb_code = #{cb_code,jdbcType=INTEGER}
  286. </if>
  287. <if test="cb_name != null and cb_name != ''">
  288. and cb_name like "%"#{cb_name,jdbcType=VARCHAR}"%"
  289. </if>
  290. <if test="cb_rule != null and cb_rule != ''">
  291. and cb_rule like "%"#{cb_rule,jdbcType=VARCHAR}"%"
  292. </if>
  293. <if test="cb_packages != null and cb_packages != ''">
  294. and cb_packages like "%"#{cb_packages,jdbcType=VARCHAR}"%"
  295. </if>
  296. <if test="cb_citys != null and cb_citys != ''">
  297. and cb_citys like "%"#{cb_citys,jdbcType=VARCHAR}"%"
  298. </if>
  299. </select>
  300. <select id="getQCouponBatch" resultMap="BaseResultMap" parameterType="com.ygj.yuemum.domain.customer.CustomerCoupon">
  301. select
  302. id, cb_code,cb_name,cb_rule,fgetpackages(id) cb_packages,fgetmoretcityname(id) cb_citys
  303. from customer_coupon
  304. where 1=1
  305. <if test="id != null and id != ''">
  306. and id = #{id,jdbcType=INTEGER}
  307. </if>
  308. <if test="cb_code != null and cb_code != ''">
  309. and cb_code = #{cb_code,jdbcType=INTEGER}
  310. </if>
  311. <if test="cb_name != null and cb_name != ''">
  312. and cb_name like "%"#{cb_name,jdbcType=VARCHAR}"%"
  313. </if>
  314. <if test="cb_rule != null and cb_rule != ''">
  315. and cb_rule like "%"#{cb_rule,jdbcType=VARCHAR}"%"
  316. </if>
  317. <if test="cb_packages != null and cb_packages != ''">
  318. and cb_packages like "%"#{cb_packages,jdbcType=VARCHAR}"%"
  319. </if>
  320. <if test="cb_citys != null and cb_citys != ''">
  321. and cb_citys like "%"#{cb_citys,jdbcType=VARCHAR}"%"
  322. </if>
  323. </select>
  324. <update id="updateCustomerUseCoupon" parameterType="com.ygj.yuemum.domain.customer.CustomerCoupon" >
  325. update customer_coupon
  326. <set >
  327. <if test="cp_status != null" >
  328. cp_status = #{cp_status,jdbcType=VARCHAR},
  329. </if>
  330. </set>
  331. where cc_code = #{cc_code,jdbcType=INTEGER}
  332. </update>
  333. </mapper>