CustomerCouponMapper.xml 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357
  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="DATE" />
  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 concat ('%',#{cb_packages,jdbcType=VARCHAR},'%')
  65. </if>
  66. <if test="cb_citys != null and cb_citys != ''">
  67. and tb.cb_citys like concat ('%',#{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 concat ('%',#{cb_packages,jdbcType=VARCHAR},'%')
  98. </if>
  99. <if test="cb_citys != null and cb_citys != ''">
  100. and tb.cb_citys like concat ('%',#{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. ta.cb_code,
  109. tb.cb_name,
  110. tb.cb_rule,
  111. fgetpackages(tb.id) cb_packages,
  112. fgetmoretcityname(tb.id) cb_citys,
  113. DATE_FORMAT(tc.cp_startdate,'%Y-%m-%d') cp_startdate,
  114. DATE_FORMAT(tc.cp_enddate,'%Y-%m-%d') cp_enddate,
  115. tc.cp_amount,
  116. cc_getdate,
  117. ta.cp_status,
  118. IFNULL(td.no_amount,0) no_amount
  119. FROM
  120. customer_coupon ta
  121. LEFT JOIN coupon_batch tb ON ta.cb_code = tb.cb_code
  122. left JOIN coupon tc on ta.cc_code = tc.cp_code
  123. left join coupon_create td on ta.cb_code = td.cb_code
  124. where
  125. ta.cm_phone = #{cm_phone,jdbcType=VARCHAR}
  126. and ta.cp_status = 2
  127. order by ta.cb_code ,tc.cp_amount desc
  128. </select>
  129. <select id="getCustomerCouponsCount" resultType="java.lang.Integer" parameterType="com.ygj.yuemum.domain.customer.CustomerCouponQuery" >
  130. SELECT
  131. count(1)
  132. FROM
  133. customer_coupon ta
  134. LEFT JOIN coupon_batch tb ON ta.cb_code = tb.cb_code
  135. left JOIN coupon tc on ta.cc_code = tc.cp_code
  136. where
  137. 1=1
  138. <if test="cm_phone != null and cm_phone != ''" >
  139. and ta.cm_phone = #{cm_phone,jdbcType=VARCHAR}
  140. </if>
  141. <if test="cb_packages != null and cb_packages != ''">
  142. and tb.cb_packages like concat ('%',#{cb_packages,jdbcType=VARCHAR},'%')
  143. </if>
  144. <if test="cb_citys != null and cb_citys != ''">
  145. and tb.cb_citys like concat ('%',#{cb_citys,jdbcType=VARCHAR},'%')
  146. </if>
  147. and ta.cp_status = 2
  148. order by ta.cb_code ,tc.cp_amount desc
  149. </select>
  150. <select id="checkCustomerCoupon" resultType="java.lang.Integer" parameterType="com.ygj.yuemum.domain.customer.CustomerCoupon" >
  151. SELECT
  152. count(1)
  153. FROM
  154. customer_coupon
  155. WHERE
  156. 1=1
  157. <if test="_parameter != null" >
  158. and cm_phone = #{cm_phone,jdbcType=VARCHAR}
  159. </if>
  160. <if test="cb_code != null" >
  161. and cb_code = #{cb_code,jdbcType=VARCHAR}
  162. </if>
  163. </select>
  164. <select id="checkSumCustomerCoupon" resultType="java.lang.Integer" parameterType="java.lang.String" >
  165. SELECT
  166. ifnull(sum(tb.cp_amount), 0)
  167. FROM
  168. customer_coupon ta,
  169. coupon tb
  170. WHERE
  171. ta.cc_code = tb.cp_code
  172. <if test="_parameter != null" >
  173. and cm_phone = #{cm_phone,jdbcType=VARCHAR}
  174. </if>
  175. AND ta.cp_status = 1
  176. AND tb.cc_code IN (
  177. 'PVP2018051297451',
  178. 'PVP2018051273883',
  179. 'PVP2018051211608',
  180. 'PVP2018051263016'
  181. )
  182. </select>
  183. <delete id="deleteByPrimaryKey" parameterType="java.lang.String" >
  184. delete from customer_coupon
  185. where cb_code = #{cb_code,jdbcType=VARCHAR}
  186. </delete>
  187. <!-- 插入一条培训信息 -->
  188. <insert id="insertSelective" parameterType="com.ygj.yuemum.domain.customer.CustomerCoupon" >
  189. insert into customer_coupon
  190. <trim prefix="(" suffix=")" suffixOverrides="," >
  191. <if test="cm_code != null" >
  192. cm_code,
  193. </if>
  194. <if test="cm_phone != null" >
  195. cm_phone,
  196. </if>
  197. <if test="cb_code != null" >
  198. cb_code,
  199. </if>
  200. <if test="cc_code != null" >
  201. cc_code,
  202. </if>
  203. <if test="cp_status != null" >
  204. cp_status,
  205. </if>
  206. <if test="cc_getdate != null" >
  207. cc_getdate,
  208. </if>
  209. <if test="cc_getchannel != null" >
  210. cc_getchannel,
  211. </if>
  212. <if test="cc_usedate != null" >
  213. cc_usedate,
  214. </if>
  215. <if test="cc_usebillno != null" >
  216. cc_usebillno
  217. </if>
  218. </trim>
  219. <trim prefix="values (" suffix=")" suffixOverrides="," >
  220. <if test="cm_code != null" >
  221. #{cm_code,jdbcType=VARCHAR},
  222. </if>
  223. <if test="cm_phone != null" >
  224. #{cm_phone,jdbcType=VARCHAR},
  225. </if>
  226. <if test="cb_code != null" >
  227. #{cb_code,jdbcType=VARCHAR},
  228. </if>
  229. <if test="cc_code != null" >
  230. #{cc_code,jdbcType=VARCHAR},
  231. </if>
  232. <if test="cp_status != null" >
  233. #{cp_status,jdbcType=INTEGER},
  234. </if>
  235. <if test="cc_getdate != null" >
  236. #{cc_getdate,jdbcType=DATE},
  237. </if>
  238. <if test="cc_getchannel != null" >
  239. #{cc_getchannel,jdbcType=INTEGER},
  240. </if>
  241. <if test="cc_usedate != null" >
  242. #{cc_usedate,jdbcType=DATE},
  243. </if>
  244. <if test="cc_usebillno != null" >
  245. #{cc_usebillno,jdbcType=VARCHAR}
  246. </if>
  247. </trim>
  248. </insert>
  249. <!-- 根据id更新一条培训信息 -->
  250. <update id="updateByPrimaryKeySelective" parameterType="com.ygj.yuemum.domain.customer.CustomerCoupon" >
  251. update customer_coupon
  252. <set >
  253. <if test="cm_code != null" >
  254. cm_code = #{cm_code,jdbcType=VARCHAR},
  255. </if>
  256. <if test="cm_phone != null" >
  257. cm_phone = #{cm_phone,jdbcType=VARCHAR},
  258. </if>
  259. <if test="cb_rule != null" >
  260. cb_rule = #{cb_rule,jdbcType=VARCHAR},
  261. </if>
  262. <if test="cb_packages != null" >
  263. cb_packages = #{cb_packages,jdbcType=VARCHAR},
  264. </if>
  265. <if test="cb_citys != null" >
  266. cb_citys = #{cb_citys,jdbcType=VARCHAR}
  267. </if>
  268. </set>
  269. where id = #{id,jdbcType=INTEGER}
  270. </update>
  271. <select id="getQCouponBatchconut" resultType="java.lang.Integer" parameterType="com.ygj.yuemum.domain.customer.CustomerCoupon">
  272. select
  273. count(1)
  274. from customer_coupon
  275. where 1=1
  276. <if test="id != null and id != ''">
  277. and id = #{id,jdbcType=INTEGER}
  278. </if>
  279. <if test="cb_code != null and cb_code != ''">
  280. and cb_code = #{cb_code,jdbcType=INTEGER}
  281. </if>
  282. <if test="cb_name != null and cb_name != ''">
  283. and cb_name like concat ('%',#{cb_name,jdbcType=VARCHAR},'%')
  284. </if>
  285. <if test="cb_rule != null and cb_rule != ''">
  286. and cb_rule like concat ('%',#{cb_rule,jdbcType=VARCHAR},'%')
  287. </if>
  288. <if test="cb_packages != null and cb_packages != ''">
  289. and cb_packages like concat ('%',#{cb_packages,jdbcType=VARCHAR},'%')
  290. </if>
  291. <if test="cb_citys != null and cb_citys != ''">
  292. and cb_citys like concat ('%',#{cb_citys,jdbcType=VARCHAR},'%')
  293. </if>
  294. </select>
  295. <select id="getQCouponBatch" resultMap="BaseResultMap" parameterType="com.ygj.yuemum.domain.customer.CustomerCoupon">
  296. select
  297. id, cb_code,cb_name,cb_rule,fgetpackages(id) cb_packages,fgetmoretcityname(id) cb_citys
  298. from customer_coupon
  299. where 1=1
  300. <if test="id != null and id != ''">
  301. and id = #{id,jdbcType=INTEGER}
  302. </if>
  303. <if test="cb_code != null and cb_code != ''">
  304. and cb_code = #{cb_code,jdbcType=INTEGER}
  305. </if>
  306. <if test="cb_name != null and cb_name != ''">
  307. and cb_name like concat ('%',#{cb_name,jdbcType=VARCHAR},'%')
  308. </if>
  309. <if test="cb_rule != null and cb_rule != ''">
  310. and cb_rule like concat ('%',#{cb_rule,jdbcType=VARCHAR},'%')
  311. </if>
  312. <if test="cb_packages != null and cb_packages != ''">
  313. and cb_packages like concat ('%',#{cb_packages,jdbcType=VARCHAR},'%')
  314. </if>
  315. <if test="cb_citys != null and cb_citys != ''">
  316. and cb_citys like concat ('%',#{cb_citys,jdbcType=VARCHAR},'%')
  317. </if>
  318. </select>
  319. <update id="updateCustomerUseCoupon" parameterType="com.ygj.yuemum.domain.customer.CustomerCoupon" >
  320. update customer_coupon
  321. <set >
  322. <if test="cp_status != null" >
  323. cp_status = #{cp_status,jdbcType=VARCHAR},
  324. </if>
  325. </set>
  326. where cc_code = #{cc_code,jdbcType=INTEGER}
  327. </update>
  328. </mapper>