TopOldOrderMapper.xml 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369
  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.zhongzheng.modules.top.goods.mapper.TopOldOrderMapper">
  6. <resultMap type="com.zhongzheng.modules.top.goods.domain.TopOldOrder" id="TopOrderResult">
  7. <result property="orderId" column="order_id"/>
  8. <result property="orderSn" column="order_sn"/>
  9. <result property="userId" column="user_id"/>
  10. <result property="orderPrice" column="order_price"/>
  11. <result property="orderGeneral" column="order_general"/>
  12. <result property="orderStatus" column="order_status"/>
  13. <result property="createTime" column="create_time"/>
  14. <result property="updateTime" column="update_time"/>
  15. <result property="payTime" column="pay_time"/>
  16. <result property="payType" column="pay_type"/>
  17. <result property="transid" column="transid"/>
  18. <result property="cancelTime" column="cancel_time"/>
  19. <result property="finishTime" column="finish_time"/>
  20. <result property="orderType" column="order_type"/>
  21. <result property="payPrice" column="pay_price"/>
  22. <result property="orderFrom" column="order_from"/>
  23. <result property="createUsername" column="create_username"/>
  24. <result property="status" column="status"/>
  25. <result property="createSysUserId" column="create_sys_user_id"/>
  26. <result property="inputOrderSn" column="input_order_sn"/>
  27. <result property="payStatus" column="pay_status"/>
  28. <result property="checkStatus" column="check_status"/>
  29. <result property="refundStatus" column="refund_status"/>
  30. <result property="creditStatus" column="credit_status"/>
  31. <result property="invoiceStatus" column="invoice_status"/>
  32. <result property="orderProfit" column="order_profit"/>
  33. <result property="orderCost" column="order_cost"/>
  34. <result property="orderRefund" column="order_refund"/>
  35. <result property="orderRefunded" column="order_refunded"/>
  36. <result property="orderUncollected" column="order_uncollected"/>
  37. <result property="orderReceived" column="order_received"/>
  38. <result property="remark" column="remark"/>
  39. <result property="costJson" column="cost_json"/>
  40. <result property="buyTime" column="buy_time"/>
  41. </resultMap>
  42. <select id="queryList" parameterType="com.zhongzheng.modules.top.goods.bo.TopOldOrderQueryBo" resultType="com.zhongzheng.modules.top.goods.vo.TopOldOrderVo">
  43. SELECT
  44. vto.*
  45. FROM
  46. ( SELECT DISTINCT order_sn
  47. <if test="businessFullName != null and businessFullName != '' and (userCard == null or userCard == '')">
  48. FROM `v_top_order_business` where business_full_name = #{businessFullName}
  49. </if>
  50. <if test="userCard != null and userCard != '' and (businessFullName == null and businessFullName == '')">
  51. FROM `v_top_order_card` where user_card = #{userCard,typeHandler=com.zhongzheng.common.type.EncryptHandler}
  52. </if>
  53. <if test="userCard != null and userCard != '' and businessFullName != null and businessFullName != ''">
  54. FROM (
  55. SELECT
  56. DISTINCT order_sn
  57. FROM
  58. ( SELECT order_sn FROM v_top_order_business WHERE business_full_name = #{businessFullName} UNION ALL SELECT order_sn FROM v_top_order_card
  59. WHERE user_card = #{userCard,typeHandler=com.zhongzheng.common.type.EncryptHandler}) b
  60. ) m
  61. </if>
  62. <if test="(userCard == null or userCard == '') and (businessFullName == null or businessFullName == '')">
  63. FROM (
  64. SELECT
  65. DISTINCT order_sn
  66. FROM
  67. ( SELECT order_sn FROM v_top_order_business UNION ALL SELECT order_sn FROM v_top_order_card) b
  68. ) m
  69. </if>
  70. ) a
  71. LEFT JOIN v_top_order vto ON a.order_sn = vto.order_sn
  72. WHERE vto.`status` = 1
  73. <if test="checkStatus != null and checkStatus != ''">
  74. AND vto.check_status = #{checkStatus}
  75. </if>
  76. <if test="refundStatusList != null and refundStatusList.size()!=0 ">
  77. AND vto.refund_status in
  78. <foreach collection="refundStatusList" item="item" index="index" open="(" close=")" separator=",">
  79. #{item}
  80. </foreach>
  81. </if>
  82. <if test="creditStatus != null and creditStatus != '' and creditStatus == 0">
  83. AND vto.order_received <![CDATA[ < ]]> vto.pay_price
  84. </if>
  85. <if test="creditStatus != null and creditStatus != '' and creditStatus == 1">
  86. AND vto.pay_price = vto.order_received
  87. </if>
  88. <if test="invoiceStatus != null and invoiceStatus != ''">
  89. AND vto.invoice_status = #{invoiceStatus}
  90. </if>
  91. <if test="startTime != null and startTime != ''">
  92. AND vto.create_time <![CDATA[ >= ]]> #{startTime}
  93. </if>
  94. <if test="endTime != null and endTime != ''">
  95. AND vto.create_time <![CDATA[ <= ]]> #{endTime}
  96. </if>
  97. <if test="orderSn != null and orderSn != ''">
  98. AND vto.order_sn = #{orderSn}
  99. </if>
  100. <if test="orderSnList != null and orderSnList.size()!=0 ">
  101. AND vto.order_sn in
  102. <foreach collection="orderSnList" item="item" index="index" open="(" close=")" separator=",">
  103. #{item}
  104. </foreach>
  105. </if>
  106. <if test="keyword != null and keyword != ''">
  107. AND (
  108. vto.create_org LIKE CONCAT( '%', #{keyword}, '%' )
  109. -- OR vto.course_org LIKE CONCAT( '%', #{keyword}, '%' )
  110. OR vto.order_org LIKE CONCAT( '%', #{keyword}, '%' ))
  111. </if>
  112. </select>
  113. <select id="queryList_COUNT" resultType="Long">
  114. SELECT
  115. ((SELECT
  116. COUNT( DISTINCT ot.order_sn ) AS num
  117. FROM
  118. top_old_order ot
  119. LEFT JOIN top_old_order_goods otg ON ot.order_sn = otg.order_sn
  120. WHERE
  121. 1 = 1
  122. <if test="businessFullName != null and businessFullName != ''">
  123. AND otg.business_full_name = #{businessFullName}
  124. </if>
  125. <if test="userCard != null and userCard != ''">
  126. AND otg.user_card = #{userCard,typeHandler=com.zhongzheng.common.type.EncryptHandler}
  127. </if>
  128. <if test="checkStatus != null and checkStatus != ''">
  129. AND ot.check_status = #{checkStatus}
  130. </if>
  131. <if test="refundStatusList != null and refundStatusList.size()!=0 ">
  132. AND ot.refund_status in
  133. <foreach collection="refundStatusList" item="item" index="index" open="(" close=")" separator=",">
  134. #{item}
  135. </foreach>
  136. </if>
  137. <if test="creditStatus != null and creditStatus != '' and creditStatus == 0">
  138. AND ot.order_received <![CDATA[ < ]]> ot.pay_price
  139. </if>
  140. <if test="creditStatus != null and creditStatus != '' and creditStatus == 1">
  141. AND ot.pay_price = ot.order_received
  142. </if>
  143. <if test="invoiceStatus != null and invoiceStatus != ''">
  144. AND ot.invoice_status = #{invoiceStatus}
  145. </if>
  146. <if test="startTime != null and startTime != ''">
  147. AND ot.create_time <![CDATA[ >= ]]> #{startTime}
  148. </if>
  149. <if test="endTime != null and endTime != ''">
  150. AND ot.create_time <![CDATA[ <= ]]> #{endTime}
  151. </if>
  152. <if test="keyword != null and keyword != ''">
  153. AND (
  154. ot.create_org LIKE CONCAT( '%', #{keyword}, '%' )
  155. OR ot.order_org LIKE CONCAT( '%', #{keyword}, '%' ))
  156. </if>
  157. ) + (SELECT
  158. COUNT( DISTINCT o.order_sn ) AS num
  159. FROM
  160. `order` o
  161. LEFT JOIN order_goods og ON o.order_sn = og.order_sn
  162. WHERE
  163. 1 = 1
  164. <if test="businessFullName != null and businessFullName != ''">
  165. AND (
  166. SELECT
  167. COUNT(g.goods_id)
  168. FROM
  169. goods g
  170. LEFT JOIN course_education_type cet ON g.education_type_id = cet.id
  171. LEFT JOIN course_project_type cpt ON g.project_id = cpt.id
  172. LEFT JOIN course_business cb ON g.business_id = cb.id
  173. WHERE
  174. og.goods_id = g.goods_id AND CONCAT('学校业务', cet.education_name, cb.business_name, cpt.project_name) = #{businessFullName}) > 0
  175. </if>
  176. <if test="userCard != null and userCard != ''">
  177. AND o.user_id = (SELECT user_id FROM `user` WHERE id_card = #{userCard,typeHandler=com.zhongzheng.common.type.EncryptHandler})
  178. </if>
  179. <if test="checkStatus != null and checkStatus != ''">
  180. AND o.check_status = #{checkStatus}
  181. </if>
  182. <if test="refundStatusList != null and refundStatusList.size()!=0 ">
  183. AND o.refund_status in
  184. <foreach collection="refundStatusList" item="item" index="index" open="(" close=")" separator=",">
  185. #{item}
  186. </foreach>
  187. </if>
  188. <if test="creditStatus != null and creditStatus != '' and creditStatus == 0">
  189. AND o.order_received <![CDATA[ < ]]> ot.pay_price
  190. </if>
  191. <if test="creditStatus != null and creditStatus != '' and creditStatus == 1">
  192. AND o.pay_price = ot.order_received
  193. </if>
  194. <if test="invoiceStatus != null and invoiceStatus != ''">
  195. AND o.invoice_status = #{invoiceStatus}
  196. </if>
  197. <if test="startTime != null and startTime != ''">
  198. AND o.create_time <![CDATA[ >= ]]> #{startTime}
  199. </if>
  200. <if test="endTime != null and endTime != ''">
  201. AND o.create_time <![CDATA[ <= ]]> #{endTime}
  202. </if>
  203. )) as number
  204. </select>
  205. <select id="queryById" parameterType="java.lang.String" resultType="com.zhongzheng.modules.top.goods.vo.TopOldOrderVo">
  206. SELECT * FROM v_top_order WHERE order_sn = #{orderSn}
  207. </select>
  208. <select id="queryBusinessBySn" parameterType="java.lang.String" resultType="java.lang.String">
  209. SELECT business_name FROM v_top_order_business WHERE order_sn = #{orderSn}
  210. </select>
  211. <select id="queryByOrderSns" parameterType="java.lang.String" resultType="com.zhongzheng.modules.top.goods.vo.TopOldOrderVo">
  212. SELECT * FROM v_top_order WHERE 1 =1
  213. <if test="orderSnList != null and orderSnList.size()!=0 ">
  214. AND order_sn in
  215. <foreach collection="orderSnList" item="item" index="index" open="(" close=")" separator=",">
  216. #{item}
  217. </foreach>
  218. </if>
  219. </select>
  220. <select id="queryReceiveList" parameterType="com.zhongzheng.modules.top.goods.bo.TopOldOrderQueryBo" resultType="com.zhongzheng.modules.top.goods.vo.TopOldOrderVo">
  221. SELECT
  222. too.*,
  223. st.tenant_name,
  224. rn.id as note_id,
  225. rn.note_type,
  226. rn.day_time,
  227. rn.week_time,
  228. rn.month_time,
  229. rn.last_time
  230. FROM
  231. top_old_order too
  232. LEFT JOIN sys_tenant st ON too.tenant_id = st.tenant_id
  233. LEFT JOIN top_order_rec_note rn ON too.tenant_id = rn.tenant_id and too.order_sn = rn.order_sn
  234. where 1=1
  235. <if test="startTime != null and startTime != ''">
  236. AND too.create_time <![CDATA[ >= ]]> #{startTime}
  237. </if>
  238. <if test="endTime != null and endTime != ''">
  239. AND too.create_time <![CDATA[ <= ]]> #{endTime}
  240. </if>
  241. <if test="keyNo != null and keyNo != ''">
  242. AND (too.tenant_id like concat('%', #{keyNo}, '%') or too.create_no like concat('%', #{keyNo}, '%'))
  243. </if>
  244. <if test="creditStatus != null and creditStatus != ''">
  245. AND too.credit_status = #{creditStatus}
  246. </if>
  247. ORDER BY too.order_id DESC
  248. </select>
  249. <select id="queryDivSellerList" parameterType="com.zhongzheng.modules.top.goods.bo.TopOldOrderQueryBo" resultType="com.zhongzheng.modules.top.goods.vo.TopOldOrderVo">
  250. SELECT
  251. too.*,
  252. st.tenant_name,
  253. r.role_name,
  254. cl.check_status as divide_check_status
  255. FROM
  256. v_top_order too
  257. LEFT JOIN sys_tenant st ON too.tenant_id = st.tenant_id
  258. LEFT JOIN top_old_order_check_log cl ON too.order_sn = cl.order_sn
  259. AND cl.check_sign = 1
  260. AND ( too.divide_model + 1 ) = cl.check_from
  261. LEFT JOIN top_sys_role r ON cl.role_id = r.role_id
  262. where 1=1 AND too.divide_model = 2
  263. <if test="startTime != null and startTime != ''">
  264. AND too.create_time <![CDATA[ >= ]]> #{startTime}
  265. </if>
  266. <if test="endTime != null and endTime != ''">
  267. AND too.create_time <![CDATA[ <= ]]> #{endTime}
  268. </if>
  269. <if test="keyNo != null and keyNo != ''">
  270. AND (too.tenant_id like concat('%', #{keyNo}, '%') or too.create_no like concat('%', #{keyNo}, '%'))
  271. </if>
  272. <if test="divideStatusList != null and divideStatusList.size()!=0 ">
  273. AND too.divide_status in
  274. <foreach collection="divideStatusList" item="item" index="index" open="(" close=")" separator=",">
  275. #{item}
  276. </foreach>
  277. </if>
  278. <if test="divideStatus != null and divideStatus != ''">
  279. AND too.divide_status = #{divideStatus}
  280. </if>
  281. <if test="roleId != null and roleId != ''">
  282. AND cl.role_id = #{roleId}
  283. </if>
  284. ORDER BY too.order_id DESC
  285. </select>
  286. <select id="queryTenantList" parameterType="com.zhongzheng.modules.top.goods.bo.TopOldOrderQueryBo" resultType="com.zhongzheng.modules.top.goods.vo.TopOldOrderVo">
  287. SELECT
  288. too.*,
  289. st.tenant_name,
  290. r.role_name,
  291. cl.check_status as divide_check_status
  292. FROM
  293. top_old_order too
  294. LEFT JOIN sys_tenant st ON too.tenant_id = st.tenant_id
  295. LEFT JOIN top_old_order_check_log cl ON too.order_sn = cl.order_sn
  296. AND cl.check_sign = 1
  297. AND ( too.divide_model + 1 ) = cl.check_from
  298. LEFT JOIN top_sys_role r ON cl.role_id = r.role_id
  299. where 1=1 AND too.divide_model = 1
  300. <if test="startTime != null and startTime != ''">
  301. AND too.create_time <![CDATA[ >= ]]> #{startTime}
  302. </if>
  303. <if test="endTime != null and endTime != ''">
  304. AND too.create_time <![CDATA[ <= ]]> #{endTime}
  305. </if>
  306. <if test="keyNo != null and keyNo != ''">
  307. AND (too.tenant_id like concat('%', #{keyNo}, '%') or too.create_no like concat('%', #{keyNo}, '%'))
  308. </if>
  309. <if test="divideStatusList != null and divideStatusList.size()!=0 ">
  310. AND too.divide_status in
  311. <foreach collection="divideStatusList" item="item" index="index" open="(" close=")" separator=",">
  312. #{item}
  313. </foreach>
  314. </if>
  315. <if test="divideStatus != null and divideStatus != ''">
  316. AND too.divide_status = #{divideStatus}
  317. </if>
  318. <if test="tenantId != null and tenantId != ''">
  319. AND too.tenant_id = #{tenantId}
  320. </if>
  321. <if test="roleId != null and roleId != ''">
  322. AND cl.role_id = #{roleId}
  323. </if>
  324. ORDER BY too.order_id DESC
  325. </select>
  326. <select id="tenantMoneyTotal" parameterType="com.zhongzheng.modules.top.goods.bo.TopOldOrderQueryBo" resultType="BigDecimal">
  327. SELECT
  328. IFNULL( SUM( too.divide_company_money ), 0 )
  329. FROM
  330. v_top_order too
  331. WHERE
  332. too.divide_model = 1
  333. AND too.divide_status = 5
  334. </select>
  335. <select id="tenantSellerTotal" parameterType="com.zhongzheng.modules.top.goods.bo.TopOldOrderQueryBo" resultType="BigDecimal">
  336. SELECT
  337. IFNULL( SUM( too.divide_seller_money ), 0 )
  338. FROM
  339. v_top_order too
  340. WHERE
  341. too.divide_model = 2
  342. AND too.divide_status = 5
  343. </select>
  344. <select id="queryListAll" resultType="com.zhongzheng.modules.top.goods.vo.TopOldOrderVo">
  345. SELECT * FROM v_top_order
  346. </select>
  347. <select id="getOrderBySn" parameterType="java.lang.String" resultType="com.zhongzheng.modules.top.goods.domain.TopOldOrder">
  348. SELECT * FROM v_top_order WHERE order_sn = #{orderSn}
  349. </select>
  350. <select id="logList" parameterType="com.zhongzheng.modules.top.financial.bo.TopOrderLogQueryBo" resultType="com.zhongzheng.modules.top.financial.vo.TopOrderLogVo">
  351. SELECT * FROM top_order_log WHERE order_sn = #{orderSn}
  352. </select>
  353. </mapper>