BusiCardsMapper.xml 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388
  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.ruoyi.voluntary.mapper.BusiCardsMapper">
  6. <resultMap type="BusiCards" id="BusiCardsResult">
  7. <result property="cardId" column="card_id" />
  8. <result property="cardNo" column="card_no" />
  9. <result property="nickName" column="nick_name" />
  10. <result property="name" column="name" />
  11. <result property="mobile" column="mobile" />
  12. <result property="score" column="score" />
  13. <result property="groupId" column="group_id" />
  14. <result property="schoolId" column="school_id" />
  15. <result property="schoolName" column="school_name" />
  16. <result property="distributeType" column="distribute_type" />
  17. <result property="distributeLocation" column="distribute_location" />
  18. <result property="distributeSchoolId" column="distribute_school_id" />
  19. <result property="distributeSchoolName" column="distribute_school_name" />
  20. <result property="distributeExamType" column="distribute_exam_type" />
  21. <result property="customSchoolName" column="custom_school_name" />
  22. <result property="customClassName" column="custom_class_name" />
  23. <result property="gradeId" column="grade_id" />
  24. <result property="gradeName" column="grade_name" />
  25. <result property="classId" column="class_id" />
  26. <result property="className" column="class_name" />
  27. <result property="year" column="year" />
  28. <result property="endYear" column="end_year" />
  29. <result property="type" column="type" />
  30. <result property="agentId" column="agent_id" />
  31. <result property="agentName" column="agent_name" />
  32. <result property="password" column="password" />
  33. <result property="status" column="status" />
  34. <result property="payStatus" column="pay_status" />
  35. <result property="isPay" column="is_pay" />
  36. <result property="isRefund" column="is_refund" />
  37. <result property="isSettlement" column="is_settlement" />
  38. <result property="isUsed" column="is_used" />
  39. <result property="isSend" column="is_send" />
  40. <result property="closeId" column="close_id" />
  41. <result property="openId" column="open_id" />
  42. <result property="remark" column="remark" />
  43. <result property="distributeTime" column="distribute_time" />
  44. <result property="outDate" column="out_date" />
  45. <result property="payTime" column="pay_time" />
  46. <result property="activeTime" column="active_time" />
  47. <result property="refundTime" column="refund_time" />
  48. <result property="closeTime" column="close_time" />
  49. <result property="createTime" column="create_time" />
  50. <result property="updateTime" column="update_time" />
  51. </resultMap>
  52. <sql id="selectBusiCardsVo">
  53. select card_id, card_no, nick_name, school_id, distribute_type, distribute_location, distribute_school_id, distribute_exam_type, grade_id, class_id, year, type, agent_id, password, status, is_pay, is_refund, is_settlement, is_used, is_send, close_id, open_id, remark, distribute_time, out_date, pay_time, active_time, refund_time, close_time, create_time, update_time from b_busi_cards
  54. </sql>
  55. <select id="selectBusiCardsList" parameterType="BusiCards" resultMap="BusiCardsResult">
  56. select t1.card_id, t1.card_no, t1.nick_name,t1.school_id,t2.name school_name,
  57. t7.nick_name name,t7.phonenumber mobile,t7.score score,t7.group_id group_id,
  58. t1.distribute_type, t1.distribute_location, t1.distribute_school_id, t3.name distribute_school_name, t1.distribute_exam_type ,t1.grade_id, t4.name grade_name, t1.class_id, t5.name class_name,
  59. t1.year,t1.end_year,t1.type,t1.agent_id,t6.name agent_name,t1.password, t1.status,
  60. t1.pay_status,t1.is_pay,t1.is_refund, t1.is_settlement, t1.is_used, t1.is_send, t1.close_id, t1.open_id,
  61. t1.remark, t1.distribute_time,t1.out_date, t1.pay_time,
  62. t1.active_time, t1.refund_time, t1.close_time, t1.create_time, t1.update_time, t7.custom_school_name, t7.custom_class_name
  63. from b_busi_cards t1 left join b_busi_schools t2 on t1.school_id = t2.id
  64. left join b_busi_schools t3 on t1.distribute_school_id = t3.id
  65. left join b_busi_grade t4 on t1.grade_id = t4.id
  66. left join b_busi_classes t5 on t1.class_id=t5.class_id
  67. left join b_busi_agents t6 on t1.agent_id = t6.agent_id
  68. left join sys_user t7 on t7.card_id = t1.card_id
  69. <where>
  70. <if test="cardNo != null and cardNo != ''"> and t1.card_no like concat('%', #{cardNo}, '%')</if>
  71. <if test="nickName != null and nickName != ''"> and t1.nick_name like concat('%', #{nickName}, '%')</if>
  72. <if test="schoolId != null "> and t1.school_id = #{schoolId}</if>
  73. <if test="distributeType != null "> and t1.distribute_type = #{distributeType}</if>
  74. <if test="distributeLocation != null "> and t1.distribute_location = #{distributeLocation}</if>
  75. <if test="distributeSchoolId != null "> and t1.distribute_school_id = #{distributeSchoolId}</if>
  76. <if test="distributeExamType != null "> and t1.distribute_exam_type = #{distributeExamType}</if>
  77. <if test="gradeId != null "> and t1.grade_id = #{gradeId}</if>
  78. <if test="classId != null "> and t1.class_id = #{classId}</if>
  79. <if test="year != null "> and t1.year = #{year}</if>
  80. <if test="endYear != null "> and t1.end_year = #{endYear}</if>
  81. <if test="type != null "> and t1.type = #{type}</if>
  82. <if test="agentId != null "> and t1.agent_id = #{agentId}</if>
  83. <if test="password != null and password != ''"> and t1.password = #{password}</if>
  84. <choose>
  85. <when test="status != null and status == -1">
  86. and (t1.status =0 or t1.status = 1)
  87. </when>
  88. <otherwise>
  89. <if test="status != null "> and t1.status = #{status}</if>
  90. </otherwise>
  91. </choose>
  92. <if test="payStatus != null "> and t1.pay_status = #{payStatus}</if>
  93. <if test="isPay != null "> and t1.is_pay = #{isPay}</if>
  94. <if test="isRefund != null "> and t1.is_refund = #{isRefund}</if>
  95. <if test="isSettlement != null "> and t1.is_settlement = #{isSettlement}</if>
  96. <if test="isUsed != null "> and t1.is_used = #{isUsed}</if>
  97. <if test="isSend != null "> and t1.is_send = #{isSend}</if>
  98. <if test="closeId != null "> and t1.close_id = #{closeId}</if>
  99. <if test="openId != null "> and t1.open_id = #{openId}</if>
  100. <if test="distributeTime != null "> and t1.distribute_time = #{distributeTime}</if>
  101. <if test="outDate != null "> and t1.out_date = #{outDate}</if>
  102. <if test="payTime != null "> and t1.pay_time = #{payTime}</if>
  103. <if test="activeTime != null "> and t1.active_time = #{activeTime}</if>
  104. <if test="refundTime != null "> and t1.refund_time = #{refundTime}</if>
  105. <if test="closeTime != null "> and t1.close_time = #{closeTime}</if>
  106. <if test="params.beginDistributeTime != null and params.beginDistributeTime != ''">
  107. AND date_format(t1.distribute_time,'%y%m%d') &gt;= date_format(#{params.beginDistributeTime},'%y%m%d')
  108. </if>
  109. <if test="params.endDistributeTime != null and params.endDistributeTime != ''">
  110. AND date_format(t1.distribute_time,'%y%m%d') &lt;= date_format(#{params.endDistributeTime},'%y%m%d')
  111. </if>
  112. <if test="params.beginPayTime != null and params.beginPayTime != ''">
  113. AND date_format(t1.pay_time,'%y%m%d') &gt;= date_format(#{params.beginPayTime},'%y%m%d')
  114. </if>
  115. <if test="params.endPayTime != null and params.endPayTime != ''">
  116. AND date_format(t1.pay_time,'%y%m%d') &lt;= date_format(#{params.endPayTime},'%y%m%d')
  117. </if>
  118. <if test="pro != null and pro != ''"> and t2.pro = #{pro}</if>
  119. <if test="city != null and city != ''"> and t2.city = #{city}</if>
  120. <if test="area != null and area != ''"> and t2.area = #{area}</if>
  121. <if test="schoolName != null and schoolName != ''"> and t2.name like concat('%', #{schoolName} ,'%')</if>
  122. <if test="className != null and className != ''"> and t5.name like concat('%', #{className} ,'%')</if>
  123. <if test="agentName != null and agentName != ''"> and t6.name like concat('%', #{agentName} ,'%')</if>
  124. <if test="name != null and name != ''"> and t7.nick_name like concat('%', #{name} ,'%')</if>
  125. <if test="mobile != null and mobile != ''"> and t7.phonenumber like concat('%', #{mobile} ,'%')</if>
  126. <choose>
  127. <when test="startCard != null and startCard != '' and endCard != null and endCard != ''">
  128. and t1.card_no >= #{startCard} and #{endCard} >= t1.card_no
  129. </when>
  130. <when test="startCard != null and startCard != ''">
  131. and t1.card_no like concat('%', #{startCard},'%')
  132. </when>
  133. <when test="endCard != null and endCard != ''">
  134. and t1.card_no like concat('%', #{endCard} ,'%')
  135. </when>
  136. <otherwise>
  137. </otherwise>
  138. </choose>
  139. </where>
  140. order by t1.card_id desc
  141. </select>
  142. <select id="selectBusiCardsClosed" resultMap="BusiCardsResult">
  143. <include refid="selectBusiCardsVo"/>
  144. where status=10
  145. </select>
  146. <select id="selectBusiCardsByCardId" parameterType="Long" resultMap="BusiCardsResult">
  147. <include refid="selectBusiCardsVo"/>
  148. where card_id = #{cardId}
  149. </select>
  150. <select id="selectBusiCardsByCardNo" parameterType="String" resultMap="BusiCardsResult">
  151. <include refid="selectBusiCardsVo"/>
  152. where card_no = #{cardNo}
  153. </select>
  154. <select id="selectOneECard" resultMap="BusiCardsResult">
  155. SELECT * from b_busi_cards
  156. where is_send=0 and card_no like '0%'
  157. and (LENGTH(card_no)=6 or LENGTH(card_no)=8) limit 1
  158. </select>
  159. <select id="selectBusiCardsByCardNos" resultMap="BusiCardsResult">
  160. <include refid="selectBusiCardsVo"/>
  161. where 1=1 and card_no in
  162. <foreach collection="list" item="item" open="(" separator="," close=")">
  163. #{item}
  164. </foreach>
  165. </select>
  166. <select id="getMaxCardNo" parameterType="Integer" resultType="Integer">
  167. select IFNULL(max(card_no),0) from b_busi_cards where type = #{type}
  168. </select>
  169. <select id="selectBusiOutTimeCardsList" parameterType="BusiCards" resultMap="BusiCardsResult">
  170. select card_id, card_no, nick_name, school_id, distribute_type, distribute_location, distribute_school_id, distribute_exam_type, grade_id, class_id, year, type, agent_id, password, status, is_pay, is_refund, is_settlement, is_used, is_send, close_id, open_id, remark, distribute_time, out_date, pay_time, active_time, refund_time, close_time, create_time, update_time from b_busi_cards
  171. where 1=1 and (status=2)
  172. <if test="endOutTime != null and endOutTime != ''">
  173. and #{endOutTime} > out_date
  174. </if>
  175. </select>
  176. <insert id="updateBusiCardsBatch" parameterType="java.util.List" useGeneratedKeys="true" keyProperty="cardId">
  177. INSERT INTO b_busi_cards(
  178. card_id, distribute_type, distribute_location, distribute_school_id, distribute_exam_type, year, agent_id, status, is_pay, is_refund, is_settlement,
  179. close_id, open_id, distribute_time,
  180. out_date, pay_time, refund_time, close_time, update_time
  181. ) VALUES
  182. <foreach collection="list" item="item" index="index" separator=",">
  183. (#{item.cardId}, #{item.distributeType}, #{item.distributeLocation}, #{item.distributeSchoolId}, #{item.distributeExamType}, #{item.year}, #{item.agentId}, #{item.status},
  184. #{item.isPay}, #{item.isRefund}, #{item.isSettlement}, #{item.closeId}, #{item.openId}, #{item.distributeTime},
  185. #{item.outDate}, #{item.payTime}, #{item.refundTime}, #{item.closeTime}, #{item.updateTime})
  186. </foreach>
  187. ON DUPLICATE KEY UPDATE distribute_type = VALUES(distribute_type), distribute_location = VALUES(distribute_location), distribute_school_id = VALUES(distribute_school_id), distribute_exam_type = VALUES(distribute_exam_type), year = VALUES(year), agent_id = VALUES(agent_id),
  188. status = VALUES(status), is_pay = VALUES(is_pay), is_refund = VALUES(is_refund), is_settlement = VALUES(is_settlement),
  189. close_id = VALUES(close_id), open_id = VALUES(open_id), distribute_time = VALUES(distribute_time), out_date = VALUES(out_date),
  190. pay_time = VALUES(pay_time), refund_time = VALUES(refund_time), close_time = VALUES(close_time), update_time = VALUES(update_time)
  191. </insert>
  192. <select id="getIdsByCardAndRole" parameterType="java.util.Map" resultMap="BusiCardsResult">
  193. <include refid="selectBusiCardsVo"/>
  194. <!-- 莫:初始化时创建的卡status <=1,分配后status=1 0未分配,1已分配,2已激活 -->
  195. where status &lt;=#{status} and card_no>=#{startCard} and #{endCard} >= card_no
  196. <!--重新分配卡:只需要查询status=0的; 分配卡:status=0和agentId is null-->
  197. <if test="againDistributionCard == null or againDistributionCard == 0">
  198. and agent_id is null
  199. </if>
  200. </select>
  201. <select id="staticByAgent" resultType="java.util.Map">
  202. select t1.agent_id agentId,t2.name agentName,
  203. count(t1.distribute_time) opened,
  204. count(case when t1.pay_status = 1 then 1 end) payed,
  205. count(case when t1.pay_status = 0 then 1 end) nopay,
  206. count(case when t1.pay_status = 2 then 1 end) refund,
  207. count(case when t1.status = 2 then 1 end) active,
  208. count(case when t1.status = 1 then 1 end) inactive
  209. from b_busi_cards t1 left join b_busi_agents t2 on t1.agent_id = t2.agent_id
  210. <where>
  211. <if test="type != null "> and t1.type = #{type}</if>
  212. <if test="agentId != null "> and t1.agent_id = #{agentId}</if>
  213. <if test="params.beginDistributeTime != null and params.beginDistributeTime != ''">
  214. AND date_format(t1.distribute_time,'%y%m%d') &gt;= date_format(#{params.beginDistributeTime},'%y%m%d')
  215. </if>
  216. <if test="params.endDistributeTime != null and params.endDistributeTime != ''">
  217. AND date_format(t1.distribute_time,'%y%m%d') &lt;= date_format(#{params.endDistributeTime},'%y%m%d')
  218. </if>
  219. </where>
  220. group by t1.agent_id
  221. order by t1.agent_id
  222. </select>
  223. <insert id="insertBatchCardList" parameterType="java.util.List">
  224. insert into b_busi_cards(type,card_no,password,create_time, update_time)
  225. VALUES
  226. <foreach collection ="list" item="item" separator =",">
  227. (#{item.type},#{item.cardNo},#{item.password},#{item.createTime}, #{item.updateTime})
  228. </foreach>
  229. </insert>
  230. <insert id="insertBusiCards" parameterType="BusiCards" useGeneratedKeys="true" keyProperty="cardId">
  231. insert into b_busi_cards
  232. <trim prefix="(" suffix=")" suffixOverrides=",">
  233. <if test="cardNo != null">card_no,</if>
  234. <if test="nickName != null and nickName != ''">nick_name,</if>
  235. <if test="schoolId != null">school_id,</if>
  236. <if test="distributeType != null">distribute_type,</if>
  237. <if test="distributeLocation != null">distribute_location,</if>
  238. <if test="distributeSchoolId != null">distribute_school_id,</if>
  239. <if test="distributeExamType != null">distribute_exam_type,</if>
  240. <if test="gradeId != null">grade_id,</if>
  241. <if test="classId != null">class_id,</if>
  242. <if test="year != null">year,</if>
  243. <if test="type != null">type,</if>
  244. <if test="agentId != null">agent_id,</if>
  245. <if test="password != null">password,</if>
  246. <if test="status != null">status,</if>
  247. <if test="isPay != null">is_pay,</if>
  248. <if test="isRefund != null">is_refund,</if>
  249. <if test="isSettlement != null">is_settlement,</if>
  250. <if test="isUsed != null">is_used,</if>
  251. <if test="isSend != null">is_send,</if>
  252. <if test="closeId != null">close_id,</if>
  253. <if test="openId != null">open_id,</if>
  254. <if test="remark != null">remark,</if>
  255. <if test="distributeTime != null">distribute_time,</if>
  256. <if test="outDate != null">out_date,</if>
  257. <if test="payTime != null">pay_time,</if>
  258. <if test="activeTime != null">active_time,</if>
  259. <if test="refundTime != null">refund_time,</if>
  260. <if test="closeTime != null">close_time,</if>
  261. <if test="createTime != null">create_time,</if>
  262. <if test="updateTime != null">update_time,</if>
  263. </trim>
  264. <trim prefix="values (" suffix=")" suffixOverrides=",">
  265. <if test="cardNo != null">#{cardNo},</if>
  266. <if test="nickName != null and nickName != ''">#{nickName},</if>
  267. <if test="schoolId != null">#{schoolId},</if>
  268. <if test="distributeType != null">#{distributeType},</if>
  269. <if test="distributeLocation != null">#{distributeLocation},</if>
  270. <if test="distributeSchoolId != null">#{distributeSchoolId},</if>
  271. <if test="distributeExamType != null">#{distributeExamType},</if>
  272. <if test="gradeId != null">#{gradeId},</if>
  273. <if test="classId != null">#{classId},</if>
  274. <if test="year != null">#{year},</if>
  275. <if test="type != null">#{type},</if>
  276. <if test="agentId != null">#{agentId},</if>
  277. <if test="password != null">#{password},</if>
  278. <if test="status != null">#{status},</if>
  279. <if test="isPay != null">#{isPay},</if>
  280. <if test="isRefund != null">#{isRefund},</if>
  281. <if test="isSettlement != null">#{isSettlement},</if>
  282. <if test="isUsed != null">#{isUsed},</if>
  283. <if test="isSend != null">#{isSend},</if>
  284. <if test="closeId != null">#{closeId},</if>
  285. <if test="openId != null">#{openId},</if>
  286. <if test="remark != null">#{remark},</if>
  287. <if test="distributeTime != null">#{distributeTime},</if>
  288. <if test="outDate != null">#{outDate},</if>
  289. <if test="payTime != null">#{payTime},</if>
  290. <if test="activeTime != null">#{activeTime},</if>
  291. <if test="refundTime != null">#{refundTime},</if>
  292. <if test="closeTime != null">#{closeTime},</if>
  293. <if test="createTime != null">#{createTime},</if>
  294. <if test="updateTime != null">#{updateTime},</if>
  295. </trim>
  296. </insert>
  297. <update id="updateBusiCards" parameterType="BusiCards">
  298. update b_busi_cards
  299. <trim prefix="SET" suffixOverrides=",">
  300. <if test="cardNo != null">card_no = #{cardNo},</if>
  301. <if test="nickName != null and nickName != ''">nick_name = #{nickName},</if>
  302. <if test="schoolId != null">school_id = #{schoolId},</if>
  303. <if test="distributeType != null">distribute_type = #{distributeType},</if>
  304. <if test="distributeLocation != null">distribute_location = #{distributeLocation},</if>
  305. <if test="distributeSchoolId != null">distribute_school_id = #{distributeSchoolId},</if>
  306. <if test="distributeExamType != null">distribute_exam_type = #{distributeExamType},</if>
  307. <if test="gradeId != null">grade_id = #{gradeId},</if>
  308. <if test="classId != null">class_id = #{classId},</if>
  309. <if test="year != null">year = #{year},</if>
  310. <if test="endYear != null">end_year = #{endYear},</if>
  311. <if test="type != null">type = #{type},</if>
  312. <if test="agentId != null">agent_id = #{agentId},</if>
  313. <if test="password != null">password = #{password},</if>
  314. <if test="status != null">status = #{status},</if>
  315. <if test="isPay != null">is_pay = #{isPay},</if>
  316. <if test="isRefund != null">is_refund = #{isRefund},</if>
  317. <if test="isSettlement != null">is_settlement = #{isSettlement},</if>
  318. <if test="isUsed != null">is_used = #{isUsed},</if>
  319. <if test="isSend != null">is_send = #{isSend},</if>
  320. <if test="closeId != null">close_id = #{closeId},</if>
  321. <if test="openId != null">open_id = #{openId},</if>
  322. <if test="remark != null">remark = #{remark},</if>
  323. <if test="distributeTime != null">distribute_time = #{distributeTime},</if>
  324. <if test="outDate != null">out_date = #{outDate},</if>
  325. <if test="payTime != null">pay_time = #{payTime},</if>
  326. <if test="activeTime != null">active_time = #{activeTime},</if>
  327. <if test="refundTime != null">refund_time = #{refundTime},</if>
  328. <if test="closeTime != null">close_time = #{closeTime},</if>
  329. <if test="createTime != null">create_time = #{createTime},</if>
  330. <if test="updateTime != null">update_time = #{updateTime},</if>
  331. </trim>
  332. where card_id = #{cardId}
  333. </update>
  334. <update id="batchUpdate" parameterType="BusiCards">
  335. update b_busi_cards
  336. <trim prefix="SET" suffixOverrides=",">
  337. -- 已关卡的不能重新关闭
  338. <if test="params.custSet != null and params.custSet != ''">${params.custSet},</if>
  339. <if test="status != null">status = #{status},</if>
  340. <if test="payStatus != null">pay_status = #{payStatus},</if>
  341. <if test="isPay != null">is_pay = #{isPay},</if>
  342. <if test="isRefund != null">is_refund = #{isRefund},</if>
  343. <if test="closeId != null">close_id = #{closeId},</if>
  344. <if test="openId != null">open_id = #{openId},</if>
  345. <if test="distributeTime != null">distribute_time = #{distributeTime},</if>
  346. <if test="outDate != null">out_date = #{outDate},</if>
  347. <if test="payTime != null">pay_time = #{payTime},</if>
  348. <if test="refundTime != null">refund_time = #{refundTime},</if>
  349. <if test="closeTime != null">close_time = #{closeTime},</if>
  350. <if test="days != null">
  351. out_date=DATE_ADD(out_date,INTERVAL #{days} day),
  352. </if>
  353. </trim>
  354. where card_id in
  355. <foreach collection="cardIds" item="item" open="(" separator="," close=")">
  356. #{item}
  357. </foreach>
  358. <if test="params.custWhere != null and params.custWhere != ''">${params.custWhere}</if>
  359. </update>
  360. <delete id="deleteBusiCardsByCardId" parameterType="Long">
  361. delete from b_busi_cards where card_id = #{cardId}
  362. </delete>
  363. <delete id="deleteBusiCardsByCardIds" parameterType="String">
  364. delete from b_busi_cards where card_id in
  365. <foreach item="cardId" collection="array" open="(" separator="," close=")">
  366. #{cardId}
  367. </foreach>
  368. </delete>
  369. </mapper>