KwoTradeOrderMapper.xml 35 KB

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