KwoTradeOrderMapper.xml 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795
  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.sckw.order.dao.KwoTradeOrderMapper">
  4. <resultMap id="mainEntityMap" type="com.sckw.order.model.dto.OrderListResDTO">
  5. <id column="tOrderId" property="tOrderId"/>
  6. <result column="status" property="status"/>
  7. <result column="tOrderNo" property="tOrderNo"/>
  8. <result column="procureEntId" property="procureEntId"/>
  9. <result column="procureFirmName" property="procureFirmName"/>
  10. <result column="supplyEntId" property="supplyEntId"/>
  11. <result column="supplyFirmName" property="supplyFirmName"/>
  12. <result column="trading" property="trading"/>
  13. <result column="deliveryType" property="deliveryType"/>
  14. <result column="pickupType" property="pickupType"/>
  15. <result column="source" property="source"/>
  16. <result column="contractId" property="contractId"/>
  17. <result column="contractNo" property="contractNo"/>
  18. <result column="goodsId" property="goodsId"/>
  19. <result column="unitPrice" property="unitPrice"/>
  20. <result column="price" property="price"/>
  21. <result column="amount" property="amount"/>
  22. <result column="entrustAmount" property="entrustAmount"/>
  23. <result column="actualAmount" property="actualAmount"/>
  24. <result column="startTime" property="startTime"/>
  25. <result column="endTime" property="endTime"/>
  26. <result column="remark" property="remark"/>
  27. <result column="unit" property="unit"/>
  28. <result column="createBy" property="createBy"/>
  29. <result column="createTime" property="createTime"/>
  30. <collection property="loadAddresses" ofType="com.sckw.order.model.dto.LoadAddressDTO">
  31. <id column="loadAddressId" property="loadAddressId"/>
  32. <result column="loadName" property="loadName"/>
  33. <result column="loadCityName" property="loadCityName"/>
  34. <result column="loadDetailAddress" property="loadDetailAddress"/>
  35. </collection>
  36. <collection property="unloadAddresses" ofType="com.sckw.order.model.dto.UnloadAddressDTO">
  37. <id column="unloadAddressId" property="unloadAddressId"/>
  38. <result column="unloadName" property="unloadName"/>
  39. <result column="unloadCityName" property="unloadCityName"/>
  40. <result column="unloadDetailAddress" property="unloadDetailAddress"/>
  41. </collection>
  42. </resultMap>
  43. <sql id="Query_Column_List_Accept_Carriage">
  44. a.id AS tOrderId,
  45. a.status AS status,
  46. a.t_order_no AS tOrderNo,
  47. d.ent_id AS procureEntId,
  48. d.firm_name AS procureFirmName,
  49. e.ent_id AS supplyEntId,
  50. e.firm_name AS supplyFirmName,
  51. a.trading AS trading,
  52. a.delivery_type AS deliveryType,
  53. a.pickup_type AS pickupType,
  54. a.source AS source,
  55. f.contract_id AS contractId,
  56. f.contract_no AS contractNo,
  57. g.goods_id AS goodsId,
  58. g.unit_price AS unitPrice,
  59. a.price AS price,
  60. a.amount AS amount,
  61. a.entrust_amount AS entrustAmount,
  62. a.actual_amount AS actualAmount,
  63. a.start_time AS startTime,
  64. a.end_time AS endTime,
  65. a.remark AS remark,
  66. a.unit AS unit,
  67. a.create_by AS createBy,
  68. a.create_time AS createTime
  69. </sql>
  70. <select id="tradeOrderSelect" resultMap="mainEntityMap">
  71. SELECT
  72. <include refid="Query_Column_List_Accept_Carriage">
  73. </include>
  74. FROM kwo_trade_order a
  75. LEFT JOIN kwo_trade_order_unit d ON a.id = d.t_order_id AND d.unit_type = "1" AND d.del_flag = 0
  76. LEFT JOIN kwo_trade_order_unit e ON a.id = e.t_order_id AND e.unit_type = "2" AND e.del_flag = 0
  77. LEFT JOIN kwo_trade_order_goods g ON a.id = g.t_order_id AND g.del_flag = 0
  78. LEFT JOIN kwo_trade_order_contract f ON a.id = f.t_order_id AND f.del_flag = 0
  79. <where>
  80. a.del_flag = 0
  81. -- 数据权限匹配
  82. <choose>
  83. <when test="query.manager != null and !query.manager">
  84. <if test="query.isMain == 0">
  85. <if test="query.entList != null and query.entList.size() > 0">
  86. and (
  87. d.top_ent_id in
  88. <foreach collection="query.entList" item="authUserId" open="(" close=")" separator=",">
  89. #{authUserId}
  90. </foreach>
  91. )
  92. </if>
  93. </if>
  94. <if test="query.isMain == 1">
  95. <if test="query.entId != null">
  96. and (d.top_ent_id = #{query.entId}
  97. )
  98. </if>
  99. </if>
  100. </when>
  101. </choose>
  102. <if test="query.buyEntId !=null">
  103. and d.ent_id = #{query.buyEntId}
  104. </if>
  105. <if test="query.saleEntId !=null">
  106. and e.ent_id = #{query.saleEntId}
  107. </if>
  108. -- 状态匹配
  109. <if test="query.status != null">
  110. and a.status = #{query.status}
  111. <if test="query.status == 0">
  112. -- 草稿状态只能创建订单的人能看
  113. and a.create_by = #{query.userId}
  114. </if>
  115. </if>
  116. <if test="query.status == null">
  117. -- 非草稿状态or草稿状态且是当前人
  118. and (
  119. a.status != 0
  120. or (a.status = 0 and a.create_by = #{query.userId})
  121. )
  122. </if>
  123. -- 关键词匹配
  124. <if test="query.keywords != null and query.keywords != ''">
  125. and (
  126. a.t_order_no like concat('%', #{query.keywords}, '%')
  127. or d.firm_name like concat('%', #{query.keywords}, '%')
  128. or e.firm_name like concat('%', #{query.keywords}, '%')
  129. <if test="goodIds != null and goodIds.size() > 0">
  130. or g.goods_id in
  131. <foreach collection="goodIds" item="goodId" open="(" close=")" separator=",">
  132. #{goodId}
  133. </foreach>
  134. </if>
  135. )
  136. </if>
  137. <if test="query.startCreateTime != null">
  138. and a.create_time &gt;= #{query.startCreateTime}
  139. </if>
  140. <if test="query.endCreateTime != null">
  141. and a.create_time &lt;= #{query.endCreateTime}
  142. </if>
  143. <if test="(query.loadAddressCode != null and query.loadAddressCode != '') or (query.unloadAddressCode != null and query.unloadAddressCode != '')">
  144. and a.id in (
  145. SELECT t_order_id
  146. from kwo_trade_order_address where del_flag = 0
  147. <if test="query.loadAddressCode != null and query.loadAddressCode != ''">
  148. and address_type = 1
  149. and left(city_code, #{query.loadAddressLevel, jdbcType=INTEGER}) =
  150. left(#{query.loadAddressCode, jdbcType=INTEGER}, #{query.loadAddressLevel, jdbcType=INTEGER})
  151. </if>
  152. <if test="query.unloadAddressCode != null and query.unloadAddressCode != ''">
  153. and address_type = 2
  154. and left(city_code, #{query.unloadAddressLevel, jdbcType=INTEGER}) =
  155. left(#{query.unloadAddressCode, jdbcType=INTEGER},
  156. #{query.unloadAddressLevel, jdbcType=INTEGER})
  157. </if>
  158. )
  159. </if>
  160. <if test="query.trading != null and query.trading != ''">
  161. and a.trading = #{query.trading}
  162. </if>
  163. <if test="query.source != null and query.source != ''">
  164. and a.source = #{query.source}
  165. </if>
  166. <if test="query.deliveryType != null and query.deliveryType != ''">
  167. and a.delivery_type = #{query.deliveryType}
  168. </if>
  169. <if test="query.deliveryType != null and query.deliveryType != ''">
  170. and a.delivery_type = #{query.deliveryType}
  171. </if>
  172. <if test="query.pickupType != null and query.pickupType != ''">
  173. and a.pickup_type = #{query.pickupType}
  174. </if>
  175. </where>
  176. ORDER BY a.create_time DESC
  177. </select>
  178. <select id="tradeOrderExport" resultMap="mainEntityMap">
  179. SELECT
  180. <include refid="Query_Column_List_Accept_Carriage">
  181. </include>
  182. FROM kwo_trade_order a
  183. LEFT JOIN kwo_trade_order_unit d ON a.id = d.t_order_id AND d.unit_type = "1" AND d.del_flag = 0
  184. LEFT JOIN kwo_trade_order_unit e ON a.id = e.t_order_id AND e.unit_type = "2" AND e.del_flag = 0
  185. LEFT JOIN kwo_trade_order_goods g ON a.id = g.t_order_id AND g.del_flag = 0
  186. LEFT JOIN kwo_trade_order_contract f ON a.id = f.t_order_id AND f.del_flag = 0
  187. <where>
  188. a.del_flag = 0
  189. -- 数据权限匹配
  190. <if test="query.isMain == 0">
  191. and (
  192. <if test="query.orderType == 1">
  193. <if test="query.entId != null">
  194. d.top_ent_id = #{query.entId}
  195. </if>
  196. <if test="authUserIds != null and authUserIds.size() > 0">
  197. and d.contacts_id in
  198. <foreach collection="authUserIds" item="authUserId" open="(" close=")" separator=",">
  199. #{authUserId}
  200. </foreach>
  201. or d.create_by in
  202. <foreach collection="authUserIds" item="authUserId" open="(" close=")" separator=",">
  203. #{authUserId}
  204. </foreach>
  205. </if>
  206. </if>
  207. <if test="query.orderType == 2">
  208. <if test="query.entId != null">
  209. e.top_ent_id = #{query.entId}
  210. </if>
  211. <if test="authUserIds != null and authUserIds.size() > 0">
  212. and e.contacts_id in
  213. <foreach collection="authUserIds" item="authUserId" open="(" close=")" separator=",">
  214. #{authUserId}
  215. </foreach>
  216. or e.create_by in
  217. <foreach collection="authUserIds" item="authUserId" open="(" close=")" separator=",">
  218. #{authUserId}
  219. </foreach>
  220. </if>
  221. </if>
  222. )
  223. </if>
  224. <if test="query.isMain == 1">
  225. and (
  226. <if test="query.orderType == 1">
  227. <if test="query.entId != null">
  228. d.top_ent_id = #{query.entId}
  229. </if>
  230. </if>
  231. <if test="query.orderType == 2">
  232. <if test="query.entId != null">
  233. e.top_ent_id = #{query.entId}
  234. </if>
  235. </if>
  236. )
  237. </if>
  238. -- 状态匹配
  239. <if test="query.status != null">
  240. and a.status = #{query.status}
  241. <if test="query.status == 0">
  242. -- 草稿状态只能创建订单的人能看
  243. and a.create_by = #{query.userId}
  244. </if>
  245. </if>
  246. <if test="query.status == null">
  247. -- 非草稿状态or草稿状态且是当前人
  248. and (
  249. a.status != 0
  250. or (a.status = 0 and a.create_by = #{query.userId})
  251. )
  252. </if>
  253. -- 关键词匹配
  254. <if test="query.keywords != null and query.keywords != ''">
  255. and (
  256. a.t_order_no like concat('%', #{query.keywords}, '%')
  257. or d.firm_name like concat('%', #{query.keywords}, '%')
  258. or e.firm_name like concat('%', #{query.keywords}, '%')
  259. <if test="goodIds != null and goodIds.size() > 0">
  260. or g.goods_id in
  261. <foreach collection="goodIds" item="goodId" open="(" close=")" separator=",">
  262. #{goodId}
  263. </foreach>
  264. </if>
  265. )
  266. </if>
  267. <if test="query.startCreateTime != null">
  268. and a.create_time &gt;= #{query.startCreateTime}
  269. </if>
  270. <if test="query.endCreateTime != null">
  271. and a.create_time &lt;= #{query.endCreateTime}
  272. </if>
  273. <if test="(query.loadAddressCode != null and query.loadAddressCode != '') or (query.unloadAddressCode != null and query.unloadAddressCode != '')">
  274. and a.id in (
  275. SELECT t_order_id
  276. from kwo_trade_order_address where del_flag = 0
  277. <if test="query.loadAddressCode != null and query.loadAddressCode != ''">
  278. and address_type = 1
  279. and left(city_code, #{query.loadAddressLevel, jdbcType=INTEGER}) =
  280. left(#{query.loadAddressCode, jdbcType=INTEGER}, #{query.loadAddressLevel, jdbcType=INTEGER})
  281. </if>
  282. <if test="query.unloadAddressCode != null and query.unloadAddressCode != ''">
  283. and address_type = 2
  284. and left(city_code, #{query.unloadAddressLevel, jdbcType=INTEGER}) =
  285. left(#{query.unloadAddressCode, jdbcType=INTEGER},
  286. #{query.unloadAddressLevel, jdbcType=INTEGER})
  287. </if>
  288. )
  289. </if>
  290. <if test="query.trading != null and query.trading != ''">
  291. and a.trading = #{query.trading}
  292. </if>
  293. <if test="query.source != null and query.source != ''">
  294. and a.source = #{query.source}
  295. </if>
  296. <if test="query.deliveryType != null and query.deliveryType != ''">
  297. and a.delivery_type = #{query.deliveryType}
  298. </if>
  299. <if test="query.deliveryType != null and query.deliveryType != ''">
  300. and a.delivery_type = #{query.deliveryType}
  301. </if>
  302. -- 指定贸易订单id导出
  303. <if test="ids != null and ids.size() > 0">
  304. and a.id in
  305. <foreach collection="ids" item="item" open="(" close=")" separator=",">
  306. #{item}
  307. </foreach>
  308. <if test="query.orderType == 1">
  309. <if test="query.entId != null">
  310. and d.top_ent_id = #{query.entId}
  311. </if>
  312. </if>
  313. <if test="query.orderType == 2">
  314. <if test="query.entId != null">
  315. and e.top_ent_id = #{query.entId}
  316. </if>
  317. </if>
  318. </if>
  319. </where>
  320. ORDER BY a.create_time DESC
  321. </select>
  322. <select id="tradeOrderStatementList" resultMap="mainEntityMap">
  323. SELECT
  324. <include refid="Query_Column_List_Accept_Carriage">
  325. </include>
  326. FROM kwo_trade_order a
  327. LEFT JOIN kwo_trade_order_address b ON a.id = b.t_order_id
  328. AND b.address_type = "1" AND b.del_flag = 0
  329. LEFT JOIN kwo_trade_order_address c ON a.id = c.t_order_id
  330. AND c.address_type = "2" AND c.del_flag = 0
  331. LEFT JOIN kwo_trade_order_unit d ON a.id = d.t_order_id
  332. AND d.unit_type = "1" AND d.del_flag = 0
  333. LEFT JOIN kwo_trade_order_unit e ON a.id = e.t_order_id
  334. AND e.unit_type = "2" AND e.del_flag = 0
  335. LEFT JOIN kwo_trade_order_goods g ON a.id = g.t_order_id AND g.del_flag = 0
  336. LEFT JOIN kwo_trade_order_contract f ON a.id = f.t_order_id AND f.del_flag = 0
  337. <where>
  338. a.status = 5
  339. and a.associate_statement <![CDATA[ <> ]]> 1
  340. and a.del_flag = 0
  341. <if test="query.orderType == 1">
  342. <if test="query.entId != null">
  343. and d.top_ent_id = #{query.entId}
  344. </if>
  345. </if>
  346. <if test="query.orderType == 2">
  347. <if test="query.entId != null">
  348. and e.top_ent_id = #{query.entId}
  349. </if>
  350. </if>
  351. <if test="excludeIds != null and excludeIds.size() > 0">
  352. and a.id not in
  353. <foreach collection="excludeIds" item="item" open="(" close=")" separator=",">
  354. #{item}
  355. </foreach>
  356. </if>
  357. <if test="goodIds != null and goodIds.size() > 0">
  358. and g.goods_id in
  359. <foreach collection="goodIds" item="goodId" open="(" close=")" separator=",">
  360. #{goodId}
  361. </foreach>
  362. </if>
  363. <if test="query.procureEntId != null">
  364. and d.ent_id = #{query.procureEntId}
  365. </if>
  366. <if test="query.trading != null and query.trading != ''">
  367. and a.trading = #{query.trading}
  368. </if>
  369. <if test="query.startTime != null">
  370. and a.start_time &gt;= #{query.startTime}
  371. </if>
  372. <if test="query.endTime != null">
  373. and a.end_time &lt;= #{query.endTime}
  374. </if>
  375. </where>
  376. ORDER BY a.create_time DESC
  377. </select>
  378. <select id="tradeOrderContractList" resultMap="mainEntityMap">
  379. SELECT
  380. <include refid="Query_Column_List_Accept_Carriage">
  381. </include>
  382. FROM kwo_trade_order a
  383. LEFT JOIN kwo_trade_order_address b ON a.id = b.t_order_id
  384. AND b.address_type = "1" AND b.del_flag = 0
  385. LEFT JOIN kwo_trade_order_address c ON a.id = c.t_order_id
  386. AND c.address_type = "2" AND c.del_flag = 0
  387. LEFT JOIN kwo_trade_order_unit d ON a.id = d.t_order_id
  388. AND d.unit_type = "1" AND d.del_flag = 0
  389. LEFT JOIN kwo_trade_order_unit e ON a.id = e.t_order_id
  390. AND e.unit_type = "2" AND e.del_flag = 0
  391. LEFT JOIN kwo_trade_order_goods g ON a.id = g.t_order_id AND g.del_flag = 0
  392. LEFT JOIN kwo_trade_order_contract f ON a.id = f.t_order_id AND f.del_flag = 0
  393. <where>
  394. a.del_flag = 0
  395. <if test="query.orderType == 1">
  396. <if test="query.entId != null">
  397. and d.top_ent_id = #{query.entId}
  398. </if>
  399. </if>
  400. <if test="query.orderType == 2">
  401. <if test="query.entId != null">
  402. and e.top_ent_id = #{query.entId}
  403. </if>
  404. </if>
  405. <if test="contractIds != null and contractIds.size() > 0">
  406. and f.contract_id in
  407. <foreach collection="contractIds" item="item" open="(" close=")" separator=",">
  408. #{item}
  409. </foreach>
  410. </if>
  411. </where>
  412. ORDER BY f.contract_id, a.create_time DESC
  413. </select>
  414. <select id="workbenchPurchaseList" resultType="com.sckw.order.model.dto.WorkbenchPurchaseDTO">
  415. SELECT a.id as tOrderId,
  416. a.amount as amount,
  417. a.unit as unit,
  418. a.create_time as createTime,
  419. g.goods_id as goodsId,
  420. d.firm_name as procureFirmName
  421. FROM kwo_trade_order a
  422. LEFT JOIN kwo_trade_order_unit d ON a.id = d.t_order_id
  423. AND d.unit_type = "1" AND d.del_flag = 0
  424. LEFT JOIN kwo_trade_order_goods g ON a.id = g.t_order_id AND g.del_flag = 0
  425. <where>
  426. a.del_flag = 0
  427. <if test="procureTopEntId != null">
  428. and d.top_ent_id = #{procureTopEntId}
  429. </if>
  430. <if test="excludeStatuses != null and excludeStatuses.size() > 0">
  431. and a.status not in
  432. <foreach collection="excludeStatuses" item="item" open="(" close=")" separator=",">
  433. #{item}
  434. </foreach>
  435. </if>
  436. </where>
  437. ORDER BY a.create_time DESC
  438. LIMIT 10;
  439. </select>
  440. <select id="tradeOrderStatistic" resultType="com.sckw.core.model.vo.TableTop">
  441. SELECT a.status AS `value`, COUNT(a.status) AS total
  442. FROM kwo_trade_order a
  443. LEFT JOIN kwo_trade_order_unit d ON a.id = d.t_order_id AND d.unit_type = "1" AND d.del_flag = 0
  444. LEFT JOIN kwo_trade_order_unit e ON a.id = e.t_order_id AND e.unit_type = "2" AND e.del_flag = 0
  445. LEFT JOIN kwo_trade_order_goods g ON a.id = g.t_order_id AND g.del_flag = 0
  446. <where>
  447. a.del_flag = 0
  448. -- 数据权限匹配
  449. <if test="query.isMain == 0">
  450. and (
  451. <if test="query.orderType == 1">
  452. <if test="query.entId != null">
  453. d.top_ent_id = #{query.entId}
  454. </if>
  455. <if test="authUserIds != null and authUserIds.size() > 0">
  456. and d.contacts_id in
  457. <foreach collection="authUserIds" item="authUserId" open="(" close=")" separator=",">
  458. #{authUserId}
  459. </foreach>
  460. or d.create_by in
  461. <foreach collection="authUserIds" item="authUserId" open="(" close=")" separator=",">
  462. #{authUserId}
  463. </foreach>
  464. </if>
  465. </if>
  466. <if test="query.orderType == 2">
  467. <if test="query.entId != null">
  468. e.top_ent_id = #{query.entId}
  469. </if>
  470. <if test="authUserIds != null and authUserIds.size() > 0">
  471. and e.contacts_id in
  472. <foreach collection="authUserIds" item="authUserId" open="(" close=")" separator=",">
  473. #{authUserId}
  474. </foreach>
  475. or e.create_by in
  476. <foreach collection="authUserIds" item="authUserId" open="(" close=")" separator=",">
  477. #{authUserId}
  478. </foreach>
  479. </if>
  480. </if>
  481. )
  482. </if>
  483. <if test="query.isMain == 1">
  484. and (
  485. <if test="query.orderType == 1">
  486. <if test="query.entId != null">
  487. d.top_ent_id = #{query.entId}
  488. </if>
  489. </if>
  490. <if test="query.orderType == 2">
  491. <if test="query.entId != null">
  492. e.top_ent_id = #{query.entId}
  493. </if>
  494. </if>
  495. )
  496. </if>
  497. -- 状态匹配
  498. <if test="query.status != null">
  499. and a.status = #{query.status}
  500. <if test="query.status == 0">
  501. -- 草稿状态只能创建订单的人能看
  502. and a.create_by = #{query.userId}
  503. </if>
  504. </if>
  505. <if test="query.status == null">
  506. -- 非草稿状态or草稿状态且是当前人
  507. and (
  508. a.status != 0
  509. or (a.status = 0 and a.create_by = #{query.userId})
  510. )
  511. </if>
  512. -- 关键词匹配
  513. <if test="query.keywords != null and query.keywords != ''">
  514. and (
  515. a.t_order_no like concat('%', #{query.keywords}, '%')
  516. or d.firm_name like concat('%', #{query.keywords}, '%')
  517. or e.firm_name like concat('%', #{query.keywords}, '%')
  518. <if test="goodIds != null and goodIds.size() > 0">
  519. or g.goods_id in
  520. <foreach collection="goodIds" item="goodId" open="(" close=")" separator=",">
  521. #{goodId}
  522. </foreach>
  523. </if>
  524. )
  525. </if>
  526. <if test="query.startCreateTime != null">
  527. and a.create_time &gt;= #{query.startCreateTime}
  528. </if>
  529. <if test="query.endCreateTime != null">
  530. and a.create_time &lt;= #{query.endCreateTime}
  531. </if>
  532. <if test="(query.loadAddressCode != null and query.loadAddressCode != '') or (query.unloadAddressCode != null and query.unloadAddressCode != '')">
  533. and a.id in (
  534. SELECT t_order_id
  535. from kwo_trade_order_address where del_flag = 0
  536. <if test="query.loadAddressCode != null and query.loadAddressCode != ''">
  537. and address_type = 1
  538. and left(city_code, #{query.loadAddressLevel, jdbcType=INTEGER}) =
  539. left(#{query.loadAddressCode, jdbcType=INTEGER}, #{query.loadAddressLevel, jdbcType=INTEGER})
  540. </if>
  541. <if test="query.unloadAddressCode != null and query.unloadAddressCode != ''">
  542. and address_type = 2
  543. and left(city_code, #{query.unloadAddressLevel, jdbcType=INTEGER}) =
  544. left(#{query.unloadAddressCode, jdbcType=INTEGER},
  545. #{query.unloadAddressLevel, jdbcType=INTEGER})
  546. </if>
  547. )
  548. </if>
  549. <if test="query.trading != null and query.trading != ''">
  550. and a.trading = #{query.trading}
  551. </if>
  552. <if test="query.source != null and query.source != ''">
  553. and a.source = #{query.source}
  554. </if>
  555. <if test="query.deliveryType != null and query.deliveryType != ''">
  556. and a.delivery_type = #{query.deliveryType}
  557. </if>
  558. <if test="query.deliveryType != null and query.deliveryType != ''">
  559. and a.delivery_type = #{query.deliveryType}
  560. </if>
  561. </where>
  562. GROUP BY a.status
  563. </select>
  564. <select id="appStatistic" resultType="com.sckw.order.model.vo.res.TradeOrderAppStatisticVO">
  565. SELECT a.status AS `value`, COUNT(a.status) AS total
  566. FROM kwo_trade_order a
  567. LEFT JOIN kwo_trade_order_unit d ON a.id = d.t_order_id AND d.unit_type = "1" AND d.del_flag = 0
  568. LEFT JOIN kwo_trade_order_unit e ON a.id = e.t_order_id AND e.unit_type = "2" AND e.del_flag = 0
  569. <where>
  570. a.del_flag = 0
  571. -- 数据权限匹配
  572. <if test="query.isMain == 0">
  573. and (
  574. <if test="query.orderType == 1">
  575. <if test="query.entId != null">
  576. d.top_ent_id = #{query.entId}
  577. </if>
  578. <if test="authUserIds != null and authUserIds.size() > 0">
  579. and d.contacts_id in
  580. <foreach collection="authUserIds" item="authUserId" open="(" close=")" separator=",">
  581. #{authUserId}
  582. </foreach>
  583. </if>
  584. </if>
  585. <if test="query.orderType == 2">
  586. <if test="query.entId != null">
  587. e.top_ent_id = #{query.entId}
  588. </if>
  589. <if test="authUserIds != null and authUserIds.size() > 0">
  590. and e.contacts_id in
  591. <foreach collection="authUserIds" item="authUserId" open="(" close=")" separator=",">
  592. #{authUserId}
  593. </foreach>
  594. </if>
  595. </if>
  596. )
  597. </if>
  598. <if test="query.isMain == 1">
  599. and (
  600. <if test="query.orderType == 1">
  601. <if test="query.entId != null">
  602. d.top_ent_id = #{query.entId}
  603. </if>
  604. </if>
  605. <if test="query.orderType == 2">
  606. <if test="query.entId != null">
  607. e.top_ent_id = #{query.entId}
  608. </if>
  609. </if>
  610. )
  611. </if>
  612. <if test="query.orderType == 1">
  613. <if test="query.entId != null">
  614. and d.top_ent_id = #{query.entId}
  615. </if>
  616. </if>
  617. <if test="query.orderType == 2">
  618. <if test="query.entId != null">
  619. and e.top_ent_id = #{query.entId}
  620. </if>
  621. </if>
  622. -- 状态匹配
  623. <if test="statuses != null and statuses.size() > 0">
  624. and a.status in
  625. <foreach collection="statuses" item="item" open="(" close=")" separator=",">
  626. #{item}
  627. </foreach>
  628. </if>
  629. </where>
  630. GROUP BY a.status
  631. </select>
  632. <select id="getOrderStsInfo" resultType="com.sckw.order.model.dto.WorkbenchOrderStsDTO">
  633. SELECT SUM(a.amount) AS orderAmount,
  634. SUM(a.price) AS orderPrice,
  635. SUM(a.actual_amount) AS orderActualAmount
  636. FROM kwo_trade_order a
  637. LEFT JOIN kwo_trade_order_unit d ON a.id = d.t_order_id
  638. AND d.unit_type = "1" AND d.del_flag = 0
  639. LEFT JOIN kwo_trade_order_unit e ON a.id = e.t_order_id
  640. AND e.unit_type = "2" AND e.del_flag = 0
  641. <where>
  642. a.del_flag = 0
  643. <if test="query.unit != null and query.unit != ''">
  644. and a.unit = #{query.unit}
  645. </if>
  646. <if test="query.startCreateTime != null">
  647. and a.create_time &gt;= #{query.startCreateTime}
  648. </if>
  649. <if test="query.endCreateTime != null">
  650. and a.create_time &lt;= #{query.endCreateTime}
  651. </if>
  652. <if test="excludeStatuses != null and excludeStatuses.size() > 0">
  653. and a.status not in
  654. <foreach collection="excludeStatuses" item="item" open="(" close=")" separator=",">
  655. #{item}
  656. </foreach>
  657. </if>
  658. <if test="query.orderType == 1">
  659. <if test="query.entId != null">
  660. and d.top_ent_id = #{query.entId}
  661. </if>
  662. </if>
  663. <if test="query.orderType == 2">
  664. <if test="query.entId != null">
  665. and e.top_ent_id = #{query.entId}
  666. </if>
  667. </if>
  668. </where>
  669. </select>
  670. <select id="getMaxOrderNoByDate" resultType="java.lang.String">
  671. SELECT MAX(t_order_no)
  672. FROM kwo_trade_order
  673. WHERE create_time &gt;= #{date};
  674. </select>
  675. <select id="getOrderNumByTopEntId" resultType="com.sckw.order.api.model.TradeOrderCountStatisticsDTO">
  676. SELECT u.unit_type AS orderType,
  677. COUNT(*) AS num
  678. FROM kwo_trade_order o
  679. LEFT JOIN kwo_trade_order_unit u
  680. ON o.id = u.t_order_id
  681. <where>
  682. o.del_flag = 0
  683. AND o.status NOT IN (0, 2)
  684. AND u.del_flag = 0
  685. <if test="topEntId != null">
  686. and u.top_ent_id = #{topEntId}
  687. </if>
  688. <if test="enterpriseIds != null and enterpriseIds.size() > 0">
  689. and o.ent_id in
  690. <foreach collection="enterpriseIds" item="item" open="(" close=")" separator=",">
  691. #{item}
  692. </foreach>
  693. </if>
  694. </where>
  695. GROUP BY u.unit_type
  696. </select>
  697. <select id="workbenchExcel" resultType="com.sckw.order.model.dto.WbTOrderExcelStsResDTO">
  698. SELECT DATE_FORMAT(create_time, #{item.dateFormat}) AS formatDate,
  699. SUM(CASE
  700. WHEN #{item.stsFactorsOne} = 1 THEN price
  701. WHEN #{item.stsFactorsOne} = 2 THEN 1
  702. ELSE 0
  703. END) AS stsFactorsOneValue,
  704. SUM(CASE
  705. WHEN #{item.stsFactorsTwo} = 1 THEN price
  706. WHEN #{item.stsFactorsTwo} = 2 THEN 1
  707. ELSE 0
  708. END) AS stsFactorsTwoValue
  709. FROM kwo_trade_order
  710. WHERE id IN (SELECT t_order_id
  711. FROM kwo_trade_order_unit
  712. WHERE del_flag = 0
  713. AND unit_type = #{item.unitType}
  714. AND top_ent_id = #{item.topEntId})
  715. AND create_time >= #{item.startTime}
  716. AND status NOT IN (0, 2)
  717. AND del_flag = 0
  718. GROUP BY DATE_FORMAT(create_time, #{item.dateFormat});
  719. </select>
  720. <select id="selectGoodsId" resultType="java.lang.Long">
  721. select distinct ktog.goods_id
  722. from kwo_trade_order kto
  723. left join kwo_trade_order_goods ktog on kto.id = ktog.t_order_id and ktog.del_flag = 0
  724. where kto.del_flag = 0
  725. and kto.ent_id = #{entId}
  726. </select>
  727. <select id="querySaleOrder" resultType="com.sckw.order.api.model.OrderSaleVo">
  728. select ktog.goods_id,
  729. sum(ifnull(kto.amount, 0)) as amount
  730. from kwo_trade_order kto
  731. left join kwo_trade_order_goods ktog on kto.id = ktog.t_order_id and ktog.del_flag = 0
  732. <where>
  733. kto.del_flag = 0
  734. <if test="start != null and end != null">
  735. and kto.create_time between #{start} and #{end}
  736. </if>
  737. group by ktog.goods_id
  738. order by amount desc
  739. </where>
  740. </select>
  741. <select id="selectData" resultType="com.sckw.order.api.model.TradeOrderVo">
  742. select a.status,
  743. a.t_order_no tOrderNo,
  744. d.firm_name buyEntName,
  745. e.firm_name sellEntName,
  746. ktog.goods_name,
  747. ktog.unit_price,
  748. ktog.unit,
  749. ktog.goods_type,
  750. a.amount,
  751. a.price,
  752. a.load_amount,
  753. a.unload_amount,
  754. a.charge_type,
  755. a.create_time
  756. FROM kwo_trade_order a
  757. LEFT JOIN kwo_trade_order_unit d ON a.id = d.t_order_id AND d.unit_type = '1' AND d.del_flag = 0
  758. LEFT JOIN kwo_trade_order_unit e ON a.id = e.t_order_id AND e.unit_type = '2' AND e.del_flag = 0
  759. left join kwo_trade_order_goods ktog on a.id = ktog.t_order_id and ktog.del_flag = 0
  760. <where>
  761. a.del_flag = 0
  762. <if test="para.startTime != null and para.endTime != null">
  763. and a.create_time between #{para.startTime,jdbcType=TIMESTAMP} and #{para.endTime,jdbcType=TIMESTAMP}
  764. </if>
  765. <if test="para.entId != null and para.entId.size() > 0">
  766. and (
  767. d.ent_id in
  768. <foreach collection="para.entId" item="item" open="(" close=")" separator=",">
  769. #{item}
  770. </foreach>
  771. or e.ent_id in
  772. <foreach collection="para.entId" item="item" open="(" close=")" separator=",">
  773. #{item}
  774. </foreach>
  775. )
  776. </if>
  777. </where>
  778. </select>
  779. </mapper>