OrderMapper.xml 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  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. <!--
  4. 这个文件是自动生成的。
  5. 不要修改此文件。所有改动将在下次重新自动生成时丢失。
  6. -->
  7. <mapper namespace="com.ym.mec.collectfee.dao.OrderDao">
  8. <resultMap type="com.ym.mec.collectfee.entity.Order" id="Order">
  9. <result column="id" property="id"/>
  10. <result column="oid" property="oid"/>
  11. <result column="branch_id" property="branchId"/>
  12. <result column="group_id" property="groupId"/>
  13. <result column="order_no" property="orderNo"/>
  14. <result column="user_id" property="userId"/>
  15. <result column="user_name" property="userName"/>
  16. <result column="amount" property="amount"/>
  17. <result column="type" property="type"/>
  18. <result column="pay" property="pay"/>
  19. <result column="bank" property="bank"/>
  20. <result column="account" property="account"/>
  21. <result column="u_account" property="uAccount"/>
  22. <result column="pay_id" property="payId"/>
  23. <result column="pay_time" property="payTime"/>
  24. <result column="remark" property="remark"/>
  25. <result column="class_id" property="classId"/>
  26. <result column="status" property="status"/>
  27. <result column="create_time" property="createTime"/>
  28. <result column="po_name" property="poName"/>
  29. <result column="voicy_part" property="voicyPart"/>
  30. <result column="balance" property="balance"/>
  31. <result column="batch_num" property="batchNum"/>
  32. <result column="tui_fee" property="tuiFee"/>
  33. <result column="goods_fee" property="goodsFee"/>
  34. <result column="sd_name" property="sdName"/>
  35. <result column="sd_fee" property="sdFee"/>
  36. <result column="promotion_type" property="promotionType" />
  37. </resultMap>
  38. <!-- 根据主键查询一条记录 -->
  39. <select id="get" resultMap="Order">
  40. SELECT * FROM `order` WHERE `id` = #{id}
  41. </select>
  42. <!-- 全查询 -->
  43. <select id="findAll" resultMap="Order">
  44. SELECT *
  45. FROM `order`
  46. ORDER BY id
  47. </select>
  48. <!-- 向数据库增加一条记录 -->
  49. <insert id="insert" parameterType="com.ym.mec.collectfee.entity.Order" useGeneratedKeys="true" keyColumn="id"
  50. keyProperty="id">
  51. <!--
  52. <selectKey resultClass="int" keyProperty="id" >
  53. SELECT SEQ_WSDEFINITION_ID.nextval AS ID FROM DUAL
  54. </selectKey>
  55. -->
  56. INSERT INTO `order`
  57. (id,oid,order_no,branch_id,group_id,user_id,user_name,amount,type,pay,bank,account,u_account,pay_id,pay_time,remark,class_id,status,create_time,po_name,voicy_part,balance,batch_num,tui_fee,goods_fee,sd_name,sd_fee,promotion_type)
  58. VALUES(#{id},#{oid},#{orderNo},#{branchId},#{groupId},#{userId},#{userName},#{amount},#{type},#{pay},#{bank},#{account},#{uAccount},#{payId},#{payTime},#{remark},#{classId},#{status},#{createTime},#{poName},#{voicyPart},#{balance},#{batchNum},#{tuiFee},#{goodsFee},#{sdName},#{sdFee},#{promotionType})
  59. </insert>
  60. <!-- 根据主键查询一条记录 -->
  61. <update id="update" parameterType="com.ym.mec.collectfee.entity.Order">
  62. UPDATE `order`
  63. <set>
  64. <if test="tuiFee != null">
  65. tui_fee = #{tuiFee},
  66. </if>
  67. <if test="goodsFee != null">
  68. goods_fee = #{goodsFee},
  69. </if>
  70. <if test="sdName != null">
  71. sd_name = #{sdName},
  72. </if>
  73. <if test="sdFee != null">
  74. sd_fee = #{sdFee},
  75. </if>
  76. <if test="amount != null">
  77. amount = #{amount},
  78. </if>
  79. <if test="classId != null">
  80. class_id = #{classId},
  81. </if>
  82. <if test="pay != null">
  83. pay = #{pay},
  84. </if>
  85. <if test="uAccount != null">
  86. u_account = #{uAccount},
  87. </if>
  88. <if test="remark != null">
  89. remark = #{remark},
  90. </if>
  91. <if test="oid != null">
  92. oid = #{oid},
  93. </if>
  94. <if test="batchNum != null">
  95. batch_num = #{batchNum},
  96. </if>
  97. <if test="payTime != null">
  98. pay_time = #{payTime},
  99. </if>
  100. <if test="bank != null">
  101. bank = #{bank},
  102. </if>
  103. <if test="balance != null">
  104. balance = #{balance},
  105. </if>
  106. <if test="userId != null">
  107. user_id = #{userId},
  108. </if>
  109. <if test="voicyPart != null">
  110. voicy_part = #{voicyPart},
  111. </if>
  112. <if test="poName != null">
  113. po_name = #{poName},
  114. </if>
  115. <if test="account != null">
  116. account = #{account},
  117. </if>
  118. <if test="payId != null">
  119. pay_id = #{payId},
  120. </if>
  121. <if test="status != null">
  122. status = #{status},
  123. </if>
  124. </set>
  125. WHERE id = #{id}
  126. </update>
  127. <!-- 根据主键删除一条记录 -->
  128. <delete id="delete">
  129. DELETE FROM `order` WHERE id = #{id}
  130. </delete>
  131. <!-- 分页查询 -->
  132. <select id="queryPage" resultMap="Order" parameterType="map">
  133. SELECT * FROM `order` ORDER BY id
  134. <include refid="global.limit"/>
  135. </select>
  136. <!-- 查询当前表的总记录数 -->
  137. <select id="queryCount" resultType="int">
  138. SELECT COUNT(*)
  139. FROM `order`
  140. </select>
  141. <select id="getOrderByUserId" resultMap="Order">
  142. SELECT * FROM `order` WHERE user_id = #{userId}
  143. </select>
  144. <select id="getOrderByClassId" resultMap="Order">
  145. SELECT * FROM `order` WHERE status=2
  146. <if test="classId != null">
  147. and class_id = #{classId}
  148. </if>
  149. <if test="type != null">
  150. and type = #{type}
  151. </if>
  152. <if test="branchId != null">
  153. and branch_id = #{branchId}
  154. </if>
  155. <if test="voicyPart != null">
  156. and voicy_part like '%${voicyPart}%'
  157. </if>
  158. <if test="account != null">
  159. and account = #{account}
  160. </if>
  161. <if test="startTime != null and startTime != ''">
  162. <![CDATA[ and pay_time >= ]]>#{startTime}
  163. </if>
  164. <if test="endTime != null and endTime != ''">
  165. <![CDATA[ and pay_time <= ]]>#{endTime}
  166. </if>
  167. </select>
  168. <select id="getOrderByBatch" resultMap="Order">
  169. SELECT * FROM `order` WHERE `batch_num` = #{batchNum}
  170. </select>
  171. <select id="countOrder" resultType="java.lang.Integer">
  172. SELECT COUNT(DISTINCT user_id) num FROM `order` WHERE `po_name` = #{poName} AND `voicy_part` = #{voicePort} AND
  173. `status` >= 1
  174. </select>
  175. <select id="getPromotionCount" resultType="java.lang.Integer">
  176. SELECT count(DISTINCT user_id) num FROM `order` WHERE `branch_id` = #{branchId} AND `promotion_type` = 1 and `status` =2
  177. </select>
  178. <select id="getUserPromotionCount" resultType="java.lang.Integer">
  179. SELECT count(id) num FROM `order` WHERE `user_id` = #{userId} AND `promotion_type` = 1 and `status` =2
  180. </select>
  181. <select id="getOrderByOrderNo" resultMap="Order">
  182. SELECT * FROM `order` WHERE `order_no` = #{orderNo} AND `status` = 1
  183. </select>
  184. <select id="findOrderByStatus" resultMap="Order">
  185. SELECT * FROM `order` WHERE `user_id` = #{userId} AND `status` = #{status}
  186. </select>
  187. <!-- 获取支付中和成功的订单数-->
  188. <select id="getPayOrderNums" resultType="java.lang.Integer">
  189. SELECT COUNT(*)
  190. FROM `order`
  191. WHERE `status` >= 1
  192. </select>
  193. <!-- 获取支付中的订单-->
  194. <select id="findPayingOrders" resultMap="Order">
  195. SELECT *
  196. FROM `order`
  197. WHERE `status` = 1
  198. </select>
  199. <!-- 获取支付中和成功的订单数-->
  200. <select id="getPayingOrderNums" resultType="java.lang.Integer" parameterType="java.lang.Integer">
  201. SELECT COUNT(*) FROM `order` WHERE `group_id`= #{groupId} AND `status` = 1
  202. </select>
  203. <!-- 根据id和status更新订单 -->
  204. <update id="updateByIdAndStatus" parameterType="map">
  205. UPDATE `order`
  206. <set>
  207. <if test="pay != null">
  208. pay = #{pay},
  209. </if>
  210. <if test="payTime != null">
  211. pay_time = #{payTime},
  212. </if>
  213. <if test="bank != null">
  214. bank = #{bank},
  215. </if>
  216. <if test="payId != null">
  217. pay_id = #{payId},
  218. </if>
  219. <if test="status != null">
  220. status = #{status}
  221. </if>
  222. </set>
  223. WHERE id = #{id} AND `status` = #{oldStatus}
  224. </update>
  225. <!-- 查询支付中超过30分钟的订单 -->
  226. <select id="findPayingOrdersOver" resultMap="Order" parameterType="map">
  227. SELECT * FROM `order` WHERE `order_no` IN
  228. <foreach collection="orderNoList" item="orderNo" index="index" open="(" close=")" separator=",">
  229. #{orderNo}
  230. </foreach>
  231. <![CDATA[ AND `status`=1 AND `create_time` <= ]]> #{beforeTime}
  232. </select>
  233. <!-- 乐团报名缴费订单 -->
  234. <select id="findRegOrderByStatus" resultMap="Order">
  235. SELECT * FROM `order` WHERE `user_id` = #{userId} AND `type`=1 AND `status` = #{status}
  236. </select>
  237. <sql id="orderPage">
  238. <if test="account != null">
  239. and FIND_IN_SET(account,#{account})
  240. </if>
  241. <if test="classId != null">
  242. and class_id = #{classId}
  243. </if>
  244. <if test="type != null">
  245. and type = #{type}
  246. </if>
  247. <if test="branchId != null">
  248. and branch_id = #{branchId}
  249. </if>
  250. <if test="voicyPart != null">
  251. and voicy_part like '%${voicyPart}%'
  252. </if>
  253. <if test="startTime != null and startTime != ''">
  254. <![CDATA[ and pay_time >= ]]>#{startTime}
  255. </if>
  256. <if test="endTime != null and endTime != ''">
  257. <![CDATA[ and pay_time <= ]]>#{endTime}
  258. </if>
  259. <if test="promotionType != null and promotionType!=0">
  260. and promotion_type = #{promotionType}
  261. </if>
  262. </sql>
  263. <!-- 查询当前表的总记录数 -->
  264. <select id="queryOrderCount" resultType="java.lang.Integer">
  265. SELECT COUNT(*) FROM `order` WHERE status=2
  266. <include refid="orderPage"/>
  267. </select>
  268. <!-- 查询当前表的总记录数 -->
  269. <select id="queryFeeAmount" resultType="map">
  270. SELECT SUM(amount) AS amount,SUM(tui_fee) as tuiFeeAmount,SUM(goods_fee) AS goodsFeeAmount,SUM(sd_Fee) AS
  271. sdFeeAmount, SUM(ROUND(amount*0.28/100,2)) as commissionAmount FROM `order` WHERE status=2
  272. <include refid="orderPage"/>
  273. </select>
  274. <select id="queryOrderPage" resultMap="Order" parameterType="map">
  275. SELECT * FROM `order` WHERE status=2
  276. <include refid="orderPage"/>
  277. <include refid="global.limit"/>
  278. </select>
  279. <select id="getOrderStatusByOrderNo" resultMap="Order">
  280. SELECT * FROM `order` WHERE `order_no` = #{orderNo}
  281. </select>
  282. </mapper>