FsExternalOrderMapper.xml 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  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.fs.his.mapper.FsExternalOrderMapper">
  6. <resultMap type="FsExternalOrder" id="FsExternalOrderResult">
  7. <result property="orderId" column="order_id" />
  8. <result property="orderCode" column="order_code" />
  9. <result property="source" column="source" />
  10. <result property="userId" column="user_id" />
  11. <result property="userName" column="user_name" />
  12. <result property="userPhone" column="user_phone" />
  13. <result property="userAddress" column="user_address" />
  14. <result property="totalNum" column="total_num" />
  15. <result property="totalPrice" column="total_price" />
  16. <result property="payPrice" column="pay_price" />
  17. <result property="freightPrice" column="freight_price" />
  18. <result property="isPay" column="is_pay" />
  19. <result property="payTime" column="pay_time" />
  20. <result property="payType" column="pay_type" />
  21. <result property="status" column="status" />
  22. <result property="deliveryCode" column="delivery_code" />
  23. <result property="deliveryName" column="delivery_name" />
  24. <result property="deliverySn" column="delivery_sn" />
  25. <result property="deliveryTime" column="delivery_time" />
  26. <result property="shippingType" column="shipping_type" />
  27. <result property="companyId" column="company_id" />
  28. <result property="companyUserId" column="company_user_id" />
  29. <result property="remark" column="remark" />
  30. <result property="externalCreateTime" column="external_create_time" />
  31. <result property="isSync" column="is_sync" />
  32. <result property="syncMsg" column="sync_msg" />
  33. <result property="createTime" column="create_time" />
  34. <result property="updateTime" column="update_time" />
  35. <result property="extendOrderId" column="extend_order_id" />
  36. <result property="storeId" column="store_id" />
  37. </resultMap>
  38. <sql id="selectFsExternalOrderVo">
  39. select order_id, order_code, source, user_id, user_name, user_phone, user_address, total_num, total_price, pay_price, freight_price, is_pay, pay_time, pay_type, status, delivery_code, delivery_name, delivery_sn, delivery_time, shipping_type, company_id, company_user_id, remark, external_create_time, is_sync, sync_msg, create_time, update_time, extend_order_id,store_id from fs_external_order
  40. </sql>
  41. <select id="selectFsExternalOrderList" parameterType="FsExternalOrder" resultMap="FsExternalOrderResult">
  42. <include refid="selectFsExternalOrderVo"/>
  43. <where>
  44. <if test="orderCode != null and orderCode != ''"> and order_code = #{orderCode}</if>
  45. <if test="source != null and source != ''"> and source = #{source}</if>
  46. <if test="userId != null "> and user_id = #{userId}</if>
  47. <if test="userName != null and userName != ''"> and user_name like concat('%', #{userName}, '%')</if>
  48. <if test="userPhone != null and userPhone != ''"> and user_phone = #{userPhone}</if>
  49. <if test="isPay != null "> and is_pay = #{isPay}</if>
  50. <if test="status != null "> and status = #{status}</if>
  51. <if test="companyId != null "> and company_id = #{companyId}</if>
  52. <if test="isSync != null "> and is_sync = #{isSync}</if>
  53. </where>
  54. order by create_time desc
  55. </select>
  56. <select id="selectFsExternalOrderByOrderId" parameterType="Long" resultMap="FsExternalOrderResult">
  57. <include refid="selectFsExternalOrderVo"/>
  58. where order_id = #{orderId}
  59. </select>
  60. <select id="selectFsExternalOrderByOrderCode" parameterType="String" resultMap="FsExternalOrderResult">
  61. <include refid="selectFsExternalOrderVo"/>
  62. where order_code = #{orderCode}
  63. </select>
  64. <insert id="insertFsExternalOrder" parameterType="FsExternalOrder" useGeneratedKeys="true" keyProperty="orderId">
  65. insert into fs_external_order
  66. <trim prefix="(" suffix=")" suffixOverrides=",">
  67. <if test="orderCode != null and orderCode != ''">order_code,</if>
  68. <if test="source != null and source != ''">source,</if>
  69. <if test="userId != null">user_id,</if>
  70. <if test="userName != null and userName != ''">user_name,</if>
  71. <if test="userPhone != null and userPhone != ''">user_phone,</if>
  72. <if test="userAddress != null and userAddress != ''">user_address,</if>
  73. <if test="totalNum != null">total_num,</if>
  74. <if test="totalPrice != null">total_price,</if>
  75. <if test="payPrice != null">pay_price,</if>
  76. <if test="freightPrice != null">freight_price,</if>
  77. <if test="isPay != null">is_pay,</if>
  78. <if test="payTime != null">pay_time,</if>
  79. <if test="payType != null">pay_type,</if>
  80. <if test="status != null">status,</if>
  81. <if test="deliveryCode != null and deliveryCode != ''">delivery_code,</if>
  82. <if test="deliveryName != null and deliveryName != ''">delivery_name,</if>
  83. <if test="deliverySn != null and deliverySn != ''">delivery_sn,</if>
  84. <if test="deliveryTime != null">delivery_time,</if>
  85. <if test="shippingType != null">shipping_type,</if>
  86. <if test="companyId != null">company_id,</if>
  87. <if test="companyUserId != null">company_user_id,</if>
  88. <if test="remark != null and remark != ''">remark,</if>
  89. <if test="externalCreateTime != null">external_create_time,</if>
  90. <if test="isSync != null">is_sync,</if>
  91. <if test="syncMsg != null and syncMsg != ''">sync_msg,</if>
  92. <if test="extendOrderId !=null and extendOrderId !=''">extend_order_id,</if>
  93. <if test="storeId != null">store_id,</if>
  94. create_time
  95. </trim>
  96. <trim prefix="values (" suffix=")" suffixOverrides=",">
  97. <if test="orderCode != null and orderCode != ''">#{orderCode},</if>
  98. <if test="source != null and source != ''">#{source},</if>
  99. <if test="userId != null">#{userId},</if>
  100. <if test="userName != null and userName != ''">#{userName},</if>
  101. <if test="userPhone != null and userPhone != ''">#{userPhone},</if>
  102. <if test="userAddress != null and userAddress != ''">#{userAddress},</if>
  103. <if test="totalNum != null">#{totalNum},</if>
  104. <if test="totalPrice != null">#{totalPrice},</if>
  105. <if test="payPrice != null">#{payPrice},</if>
  106. <if test="freightPrice != null">#{freightPrice},</if>
  107. <if test="isPay != null">#{isPay},</if>
  108. <if test="payTime != null">#{payTime},</if>
  109. <if test="payType != null">#{payType},</if>
  110. <if test="status != null">#{status},</if>
  111. <if test="deliveryCode != null and deliveryCode != ''">#{deliveryCode},</if>
  112. <if test="deliveryName != null and deliveryName != ''">#{deliveryName},</if>
  113. <if test="deliverySn != null and deliverySn != ''">#{deliverySn},</if>
  114. <if test="deliveryTime != null">#{deliveryTime},</if>
  115. <if test="shippingType != null">#{shippingType},</if>
  116. <if test="companyId != null">#{companyId},</if>
  117. <if test="companyUserId != null">#{companyUserId},</if>
  118. <if test="remark != null and remark != ''">#{remark},</if>
  119. <if test="externalCreateTime != null">#{externalCreateTime},</if>
  120. <if test="isSync != null">#{isSync},</if>
  121. <if test="syncMsg != null and syncMsg != ''">#{syncMsg},</if>
  122. <if test="extendOrderId !=null and extendOrderId !=''">#{extendOrderId},</if>
  123. <if test="storeId != null">#{storeId},</if>
  124. sysdate()
  125. </trim>
  126. </insert>
  127. <update id="updateFsExternalOrder" parameterType="FsExternalOrder">
  128. update fs_external_order
  129. <trim prefix="SET" suffixOverrides=",">
  130. <if test="orderCode != null and orderCode != ''">order_code = #{orderCode},</if>
  131. <if test="source != null and source != ''">source = #{source},</if>
  132. <if test="userId != null">user_id = #{userId},</if>
  133. <if test="userName != null and userName != ''">user_name = #{userName},</if>
  134. <if test="userPhone != null and userPhone != ''">user_phone = #{userPhone},</if>
  135. <if test="userAddress != null and userAddress != ''">user_address = #{userAddress},</if>
  136. <if test="totalNum != null">total_num = #{totalNum},</if>
  137. <if test="totalPrice != null">total_price = #{totalPrice},</if>
  138. <if test="payPrice != null">pay_price = #{payPrice},</if>
  139. <if test="freightPrice != null">freight_price = #{freightPrice},</if>
  140. <if test="isPay != null">is_pay = #{isPay},</if>
  141. <if test="payTime != null">pay_time = #{payTime},</if>
  142. <if test="payType != null">pay_type = #{payType},</if>
  143. <if test="status != null">status = #{status},</if>
  144. <if test="deliveryCode != null and deliveryCode != ''">delivery_code = #{deliveryCode},</if>
  145. <if test="deliveryName != null and deliveryName != ''">delivery_name = #{deliveryName},</if>
  146. <if test="deliverySn != null and deliverySn != ''">delivery_sn = #{deliverySn},</if>
  147. <if test="deliveryTime != null">delivery_time = #{deliveryTime},</if>
  148. <if test="shippingType != null">shipping_type = #{shippingType},</if>
  149. <if test="companyId != null">company_id = #{companyId},</if>
  150. <if test="companyUserId != null">company_user_id = #{companyUserId},</if>
  151. <if test="remark != null and remark != ''">remark = #{remark},</if>
  152. <if test="externalCreateTime != null">external_create_time = #{externalCreateTime},</if>
  153. <if test="isSync != null">is_sync = #{isSync},</if>
  154. <if test="syncMsg != null and syncMsg != ''">sync_msg = #{syncMsg},</if>
  155. <if test="extendOrderId !=null and extendOrderId !=''">extend_order_id = #{extendOrderId},</if>
  156. <if test="storeId != null">store_id = #{storeId},</if>
  157. update_time = sysdate()
  158. </trim>
  159. where order_id = #{orderId}
  160. </update>
  161. <delete id="deleteFsExternalOrderByOrderId" parameterType="Long">
  162. delete from fs_external_order where order_id = #{orderId}
  163. </delete>
  164. <delete id="deleteFsExternalOrderByOrderIds" parameterType="String">
  165. delete from fs_external_order where order_id in
  166. <foreach item="orderId" collection="array" open="(" separator="," close=")">
  167. #{orderId}
  168. </foreach>
  169. </delete>
  170. <select id="selectExternalOrderListVO" parameterType="FsExternalOrder" resultType="com.fs.his.domain.vo.FsExternalOrderListVO">
  171. SELECT
  172. o.order_id,
  173. o.order_code,
  174. c.company_name AS companyName,
  175. cu.user_name AS companyUserName,
  176. o.user_name AS userName,
  177. o.user_phone AS userPhone,
  178. GROUP_CONCAT(oi.product_name SEPARATOR ',') AS productNames,
  179. SUM(oi.price) AS receivablePrice,
  180. o.pay_price AS payPrice,
  181. o.pay_type AS payType,
  182. o.external_create_time AS externalCreateTime,
  183. o.status,
  184. CASE o.status
  185. WHEN 1 THEN '待审核'
  186. WHEN 2 THEN '待发货'
  187. WHEN 3 THEN '待收货'
  188. WHEN 4 THEN '已完成'
  189. WHEN -3 THEN '已取消'
  190. ELSE '未知'
  191. END AS statusDesc,
  192. IF(fa.id IS NOT NULL AND fa.audit_status = 0, true, false) AS isApplyAudit
  193. FROM fs_external_order o
  194. LEFT JOIN company c ON o.company_id = c.company_id
  195. LEFT JOIN company_user cu ON o.company_user_id = cu.user_id
  196. LEFT JOIN fs_external_order_item oi ON o.order_id = oi.order_id
  197. LEFT JOIN fs_store_order_finance_audit fa ON fa.order_id = o.order_id AND fa.order_type = 0 AND fa.audit_status = 0
  198. <where>
  199. <if test="orderCode != null and orderCode != ''"> AND o.order_code = #{orderCode}</if>
  200. <if test="userId != null"> AND o.user_id = #{userId}</if>
  201. <if test="userName != null and userName != ''"> AND o.user_name LIKE CONCAT('%', #{userName}, '%')</if>
  202. <if test="userPhone != null and userPhone != ''"> AND o.user_phone = #{userPhone}</if>
  203. <if test="isPay != null"> AND o.is_pay = #{isPay}</if>
  204. <if test="status != null"> AND o.status = #{status}</if>
  205. <if test="companyId != null"> AND o.company_id = #{companyId}</if>
  206. <if test="companyUserId != null"> AND o.company_user_id = #{companyUserId}</if>
  207. <if test="isSync != null"> AND o.is_sync = #{isSync}</if>
  208. ${params.dataScope}
  209. </where>
  210. GROUP BY o.order_id
  211. ORDER BY o.create_time DESC
  212. </select>
  213. <select id="selectExternalOrderDetailVO" parameterType="Long" resultType="com.fs.his.vo.FsExternalOrderDetailVO">
  214. SELECT
  215. o.order_id AS orderId,
  216. o.order_code AS orderCode,
  217. o.source,
  218. o.user_id AS userId,
  219. o.user_name AS userName,
  220. o.user_phone AS userPhone,
  221. o.user_address AS userAddress,
  222. o.total_num AS totalNum,
  223. o.total_price AS totalPrice,
  224. o.pay_price AS payPrice,
  225. o.freight_price AS freightPrice,
  226. o.is_pay AS isPay,
  227. o.pay_time AS payTime,
  228. o.pay_type AS payType,
  229. o.status,
  230. o.delivery_code AS deliveryCode,
  231. o.delivery_name AS deliveryName,
  232. o.delivery_sn AS deliverySn,
  233. o.delivery_time AS deliveryTime,
  234. o.shipping_type AS shippingType,
  235. o.remark,
  236. o.external_create_time AS externalCreateTime,
  237. o.create_time AS createTime,
  238. c.company_name AS companyName,
  239. cu.nick_name AS companyUserName
  240. FROM fs_external_order o
  241. LEFT JOIN company c ON o.company_id = c.company_id
  242. LEFT JOIN company_user cu ON o.company_user_id = cu.user_id
  243. WHERE o.order_id = #{orderId}
  244. </select>
  245. </mapper>