KwoTradeOrderMapper.xml 51 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117
  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. <result column="addVehicles" property="addVehicles"/>
  34. <collection property="loadAddresses" ofType="com.sckw.order.model.dto.LoadAddressDTO">
  35. <id column="loadAddressId" property="loadAddressId"/>
  36. <result column="loadName" property="loadName"/>
  37. <result column="loadCityName" property="loadCityName"/>
  38. <result column="loadDetailAddress" property="loadDetailAddress"/>
  39. </collection>
  40. <collection property="unloadAddresses" ofType="com.sckw.order.model.dto.UnloadAddressDTO">
  41. <id column="unloadAddressId" property="unloadAddressId"/>
  42. <result column="unloadName" property="unloadName"/>
  43. <result column="unloadCityName" property="unloadCityName"/>
  44. <result column="unloadDetailAddress" property="unloadDetailAddress"/>
  45. </collection>
  46. </resultMap>
  47. <sql id="Query_Column_List_Accept_Carriage">
  48. a.id AS tOrderId,
  49. a.status AS status,
  50. a.t_order_no AS tOrderNo,
  51. d.ent_id AS procureEntId,
  52. d.firm_name AS procureFirmName,
  53. e.ent_id AS supplyEntId,
  54. e.firm_name AS supplyFirmName,
  55. a.trading AS trading,
  56. a.delivery_type AS deliveryType,
  57. a.pickup_type AS pickupType,
  58. a.source AS source,
  59. f.contract_id AS contractId,
  60. f.contract_no AS contractNo,
  61. g.goods_id AS goodsId,
  62. g.unit_price AS unitPrice,
  63. a.price AS price,
  64. a.amount AS amount,
  65. a.entrust_amount AS entrustAmount,
  66. a.charge_type AS chargeType,
  67. a.load_amount AS loadAmount,
  68. a.unload_amount AS unloadAmount,
  69. a.actual_amount AS actualAmount,
  70. a.start_time AS startTime,
  71. a.end_time AS endTime,
  72. a.remark AS remark,
  73. a.unit AS unit,
  74. a.create_by AS createBy,
  75. a.create_time AS createTime,
  76. a.add_vehicles AS addVehicles
  77. </sql>
  78. <select id="tradeOrderSelect" resultMap="mainEntityMap">
  79. SELECT
  80. <include refid="Query_Column_List_Accept_Carriage">
  81. </include>
  82. FROM kwo_trade_order a
  83. LEFT JOIN kwo_trade_order_unit d ON a.id = d.t_order_id AND d.unit_type = "1" AND d.del_flag = 0
  84. LEFT JOIN kwo_trade_order_unit e ON a.id = e.t_order_id AND e.unit_type = "2" AND e.del_flag = 0
  85. LEFT JOIN kwo_trade_order_goods g ON a.id = g.t_order_id AND g.del_flag = 0
  86. LEFT JOIN kwo_trade_order_contract f ON a.id = f.t_order_id AND f.del_flag = 0
  87. <where>
  88. a.del_flag = 0
  89. -- 数据权限匹配
  90. <choose>
  91. <when test="query.manager != null and !query.manager">
  92. <if test="query.isMain == 1">
  93. <if test="query.entList != null and query.entList.size() > 0 and query.entType != null">
  94. <if test="query.entType == 1">
  95. and
  96. e.top_ent_id in
  97. <foreach collection="query.entList" item="authUserId" open="(" close=")" separator=",">
  98. #{authUserId}
  99. </foreach>
  100. </if>
  101. <if test="query.entType == 2">
  102. and
  103. d.top_ent_id in
  104. <foreach collection="query.entList" item="authUserId" open="(" close=")" separator=",">
  105. #{authUserId}
  106. </foreach>
  107. </if>
  108. </if>
  109. </if>
  110. <if test="query.isMain == 0">
  111. <if test="query.entId != null and query.entType != null">
  112. <if test="query.entType == 1">
  113. and e.top_ent_id = #{query.entId}
  114. </if>
  115. <if test="query.entType == 2">
  116. and d.top_ent_id = #{query.entId}
  117. </if>
  118. </if>
  119. </if>
  120. </when>
  121. </choose>
  122. <if test="query.buyEntId != null">
  123. and d.ent_id = #{query.buyEntId}
  124. </if>
  125. <if test="query.contractId != null">
  126. and f.contract_id = #{query.contractId}
  127. </if>
  128. <!-- <if test="query.dataPermissionForceEmpty != null and query.dataPermissionForceEmpty">-->
  129. <!-- and 1 = 0-->
  130. <!-- </if>-->
  131. <!-- <if test="query.dataPermissionFilter != null and query.dataPermissionFilter">-->
  132. <!-- and exists (-->
  133. <!-- select 1-->
  134. <!-- from kwc_contract_trade ct-->
  135. <!-- where ct.id = f.contract_id-->
  136. <!-- and ct.del_flag = 0-->
  137. <!-- <if test="query.dataPermissionAllVisible != null and !query.dataPermissionAllVisible">-->
  138. <!-- and ct.ent_id in-->
  139. <!-- <foreach collection="query.dataPermissionEntIds" item="entId" open="(" close=")" separator=",">-->
  140. <!-- #{entId}-->
  141. <!-- </foreach>-->
  142. <!-- </if>-->
  143. <!-- <if test="query.dataPermissionPersonal != null and query.dataPermissionPersonal">-->
  144. <!-- and ct.salesman_id = #{query.dataPermissionUserId}-->
  145. <!-- </if>-->
  146. <!-- )-->
  147. <!-- </if>-->
  148. <if test="query.saleEntId != null">
  149. and e.ent_id = #{query.saleEntId}
  150. </if>
  151. <if test="query.status != null">
  152. and a.status = #{query.status}
  153. </if>
  154. <if test="query.keywords != null and query.keywords != ''">
  155. and (
  156. a.t_order_no like concat('%', #{query.keywords}, '%')
  157. or d.firm_name like concat('%', #{query.keywords}, '%')
  158. or e.firm_name like concat('%', #{query.keywords}, '%')
  159. <if test="goodIds != null and goodIds.size() > 0">
  160. or g.goods_id in
  161. <foreach collection="goodIds" item="goodId" open="(" close=")" separator=",">
  162. #{goodId}
  163. </foreach>
  164. </if>
  165. )
  166. </if>
  167. <if test="query.startCreateTime != null">
  168. and a.create_time &gt;= #{query.startCreateTime}
  169. </if>
  170. <if test="query.endCreateTime != null">
  171. and a.create_time &lt;= #{query.endCreateTime}
  172. </if>
  173. <if test="(query.loadAddressCode != null and query.loadAddressCode != '') or (query.unloadAddressCode != null and query.unloadAddressCode != '')">
  174. and a.id in (
  175. SELECT t_order_id
  176. from kwo_trade_order_address where del_flag = 0
  177. <if test="query.loadAddressCode != null and query.loadAddressCode != ''">
  178. and address_type = 1
  179. and left(city_code, #{query.loadAddressLevel, jdbcType=INTEGER}) =
  180. left(#{query.loadAddressCode, jdbcType=INTEGER}, #{query.loadAddressLevel, jdbcType=INTEGER})
  181. </if>
  182. <if test="query.unloadAddressCode != null and query.unloadAddressCode != ''">
  183. and address_type = 2
  184. and left(city_code, #{query.unloadAddressLevel, jdbcType=INTEGER}) =
  185. left(#{query.unloadAddressCode, jdbcType=INTEGER},
  186. #{query.unloadAddressLevel, jdbcType=INTEGER})
  187. </if>
  188. )
  189. </if>
  190. <if test="query.trading != null and query.trading != ''">
  191. and a.trading = #{query.trading}
  192. </if>
  193. <if test="query.source != null and query.source != ''">
  194. and a.source = #{query.source}
  195. </if>
  196. <if test="query.deliveryType != null and query.deliveryType != ''">
  197. and a.delivery_type = #{query.deliveryType}
  198. </if>
  199. <if test="query.deliveryType != null and query.deliveryType != ''">
  200. and a.delivery_type = #{query.deliveryType}
  201. </if>
  202. <if test="query.pickupType != null and query.pickupType != ''">
  203. and a.pickup_type = #{query.pickupType}
  204. </if>
  205. </where>
  206. ORDER BY a.create_time DESC
  207. </select>
  208. <select id="tradeOrderExport" resultMap="mainEntityMap">
  209. SELECT
  210. <include refid="Query_Column_List_Accept_Carriage">
  211. </include>
  212. FROM kwo_trade_order a
  213. LEFT JOIN kwo_trade_order_unit d ON a.id = d.t_order_id AND d.unit_type = "1" AND d.del_flag = 0
  214. LEFT JOIN kwo_trade_order_unit e ON a.id = e.t_order_id AND e.unit_type = "2" AND e.del_flag = 0
  215. LEFT JOIN kwo_trade_order_goods g ON a.id = g.t_order_id AND g.del_flag = 0
  216. LEFT JOIN kwo_trade_order_contract f ON a.id = f.t_order_id AND f.del_flag = 0
  217. <where>
  218. a.del_flag = 0
  219. -- 数据权限匹配
  220. <if test="query.isMain == 0">
  221. and (
  222. <if test="query.orderType == 1">
  223. <if test="query.entId != null">
  224. d.top_ent_id = #{query.entId}
  225. </if>
  226. <if test="authUserIds != null and authUserIds.size() > 0">
  227. and d.contacts_id in
  228. <foreach collection="authUserIds" item="authUserId" open="(" close=")" separator=",">
  229. #{authUserId}
  230. </foreach>
  231. or d.create_by in
  232. <foreach collection="authUserIds" item="authUserId" open="(" close=")" separator=",">
  233. #{authUserId}
  234. </foreach>
  235. </if>
  236. </if>
  237. <if test="query.orderType == 2">
  238. <if test="query.entId != null">
  239. e.top_ent_id = #{query.entId}
  240. </if>
  241. <if test="authUserIds != null and authUserIds.size() > 0">
  242. and e.contacts_id in
  243. <foreach collection="authUserIds" item="authUserId" open="(" close=")" separator=",">
  244. #{authUserId}
  245. </foreach>
  246. or e.create_by in
  247. <foreach collection="authUserIds" item="authUserId" open="(" close=")" separator=",">
  248. #{authUserId}
  249. </foreach>
  250. </if>
  251. </if>
  252. )
  253. </if>
  254. <if test="query.isMain == 1">
  255. and (
  256. <if test="query.orderType == 1">
  257. <if test="query.entId != null">
  258. d.top_ent_id = #{query.entId}
  259. </if>
  260. </if>
  261. <if test="query.orderType == 2">
  262. <if test="query.entId != null">
  263. e.top_ent_id = #{query.entId}
  264. </if>
  265. </if>
  266. )
  267. </if>
  268. -- 状态匹配
  269. <if test="query.status != null">
  270. and a.status = #{query.status}
  271. <if test="query.status == 0">
  272. -- 草稿状态只能创建订单的人能看
  273. and a.create_by = #{query.userId}
  274. </if>
  275. </if>
  276. <if test="query.status == null">
  277. -- 非草稿状态or草稿状态且是当前人
  278. and (
  279. a.status != 0
  280. or (a.status = 0 and a.create_by = #{query.userId})
  281. )
  282. </if>
  283. -- 关键词匹配
  284. <if test="query.keywords != null and query.keywords != ''">
  285. and (
  286. a.t_order_no like concat('%', #{query.keywords}, '%')
  287. or d.firm_name like concat('%', #{query.keywords}, '%')
  288. or e.firm_name like concat('%', #{query.keywords}, '%')
  289. <if test="goodIds != null and goodIds.size() > 0">
  290. or g.goods_id in
  291. <foreach collection="goodIds" item="goodId" open="(" close=")" separator=",">
  292. #{goodId}
  293. </foreach>
  294. </if>
  295. )
  296. </if>
  297. <if test="query.startCreateTime != null">
  298. and a.create_time &gt;= #{query.startCreateTime}
  299. </if>
  300. <if test="query.endCreateTime != null">
  301. and a.create_time &lt;= #{query.endCreateTime}
  302. </if>
  303. <if test="(query.loadAddressCode != null and query.loadAddressCode != '') or (query.unloadAddressCode != null and query.unloadAddressCode != '')">
  304. and a.id in (
  305. SELECT t_order_id
  306. from kwo_trade_order_address where del_flag = 0
  307. <if test="query.loadAddressCode != null and query.loadAddressCode != ''">
  308. and address_type = 1
  309. and left(city_code, #{query.loadAddressLevel, jdbcType=INTEGER}) =
  310. left(#{query.loadAddressCode, jdbcType=INTEGER}, #{query.loadAddressLevel, jdbcType=INTEGER})
  311. </if>
  312. <if test="query.unloadAddressCode != null and query.unloadAddressCode != ''">
  313. and address_type = 2
  314. and left(city_code, #{query.unloadAddressLevel, jdbcType=INTEGER}) =
  315. left(#{query.unloadAddressCode, jdbcType=INTEGER},
  316. #{query.unloadAddressLevel, jdbcType=INTEGER})
  317. </if>
  318. )
  319. </if>
  320. <if test="query.trading != null and query.trading != ''">
  321. and a.trading = #{query.trading}
  322. </if>
  323. <if test="query.source != null and query.source != ''">
  324. and a.source = #{query.source}
  325. </if>
  326. <if test="query.deliveryType != null and query.deliveryType != ''">
  327. and a.delivery_type = #{query.deliveryType}
  328. </if>
  329. <if test="query.deliveryType != null and query.deliveryType != ''">
  330. and a.delivery_type = #{query.deliveryType}
  331. </if>
  332. -- 指定贸易订单id导出
  333. <if test="ids != null and ids.size() > 0">
  334. and a.id in
  335. <foreach collection="ids" item="item" open="(" close=")" separator=",">
  336. #{item}
  337. </foreach>
  338. <if test="query.orderType == 1">
  339. <if test="query.entId != null">
  340. and d.top_ent_id = #{query.entId}
  341. </if>
  342. </if>
  343. <if test="query.orderType == 2">
  344. <if test="query.entId != null">
  345. and e.top_ent_id = #{query.entId}
  346. </if>
  347. </if>
  348. </if>
  349. </where>
  350. ORDER BY a.create_time DESC
  351. </select>
  352. <select id="tradeOrderStatementList" resultMap="mainEntityMap">
  353. SELECT
  354. <include refid="Query_Column_List_Accept_Carriage">
  355. </include>
  356. FROM kwo_trade_order a
  357. LEFT JOIN kwo_trade_order_address b ON a.id = b.t_order_id
  358. AND b.address_type = "1" AND b.del_flag = 0
  359. LEFT JOIN kwo_trade_order_address c ON a.id = c.t_order_id
  360. AND c.address_type = "2" AND c.del_flag = 0
  361. LEFT JOIN kwo_trade_order_unit d ON a.id = d.t_order_id
  362. AND d.unit_type = "1" AND d.del_flag = 0
  363. LEFT JOIN kwo_trade_order_unit e ON a.id = e.t_order_id
  364. AND e.unit_type = "2" AND e.del_flag = 0
  365. LEFT JOIN kwo_trade_order_goods g ON a.id = g.t_order_id AND g.del_flag = 0
  366. LEFT JOIN kwo_trade_order_contract f ON a.id = f.t_order_id AND f.del_flag = 0
  367. <where>
  368. a.status = 5
  369. and a.associate_statement <![CDATA[ <> ]]> 1
  370. and a.del_flag = 0
  371. <if test="query.orderType == 1">
  372. <if test="query.entId != null">
  373. and d.top_ent_id = #{query.entId}
  374. </if>
  375. </if>
  376. <if test="query.orderType == 2">
  377. <if test="query.entId != null">
  378. and e.top_ent_id = #{query.entId}
  379. </if>
  380. </if>
  381. <if test="excludeIds != null and excludeIds.size() > 0">
  382. and a.id not in
  383. <foreach collection="excludeIds" item="item" open="(" close=")" separator=",">
  384. #{item}
  385. </foreach>
  386. </if>
  387. <if test="goodIds != null and goodIds.size() > 0">
  388. and g.goods_id in
  389. <foreach collection="goodIds" item="goodId" open="(" close=")" separator=",">
  390. #{goodId}
  391. </foreach>
  392. </if>
  393. <if test="query.procureEntId != null">
  394. and d.ent_id = #{query.procureEntId}
  395. </if>
  396. <if test="query.trading != null and query.trading != ''">
  397. and a.trading = #{query.trading}
  398. </if>
  399. <if test="query.startTime != null">
  400. and a.start_time &gt;= #{query.startTime}
  401. </if>
  402. <if test="query.endTime != null">
  403. and a.end_time &lt;= #{query.endTime}
  404. </if>
  405. </where>
  406. ORDER BY a.create_time DESC
  407. </select>
  408. <select id="tradeOrderContractList" resultMap="mainEntityMap">
  409. SELECT
  410. <include refid="Query_Column_List_Accept_Carriage">
  411. </include>
  412. FROM kwo_trade_order a
  413. LEFT JOIN kwo_trade_order_address b ON a.id = b.t_order_id
  414. AND b.address_type = "1" AND b.del_flag = 0
  415. LEFT JOIN kwo_trade_order_address c ON a.id = c.t_order_id
  416. AND c.address_type = "2" AND c.del_flag = 0
  417. LEFT JOIN kwo_trade_order_unit d ON a.id = d.t_order_id
  418. AND d.unit_type = "1" AND d.del_flag = 0
  419. LEFT JOIN kwo_trade_order_unit e ON a.id = e.t_order_id
  420. AND e.unit_type = "2" AND e.del_flag = 0
  421. LEFT JOIN kwo_trade_order_goods g ON a.id = g.t_order_id AND g.del_flag = 0
  422. LEFT JOIN kwo_trade_order_contract f ON a.id = f.t_order_id AND f.del_flag = 0
  423. <where>
  424. a.del_flag = 0
  425. <if test="query.orderType == 1">
  426. <if test="query.entId != null">
  427. and d.top_ent_id = #{query.entId}
  428. </if>
  429. </if>
  430. <if test="query.orderType == 2">
  431. <if test="query.entId != null">
  432. and e.top_ent_id = #{query.entId}
  433. </if>
  434. </if>
  435. <if test="contractIds != null and contractIds.size() > 0">
  436. and f.contract_id in
  437. <foreach collection="contractIds" item="item" open="(" close=")" separator=",">
  438. #{item}
  439. </foreach>
  440. </if>
  441. </where>
  442. ORDER BY f.contract_id, a.create_time DESC
  443. </select>
  444. <select id="workbenchPurchaseList" resultType="com.sckw.order.model.dto.WorkbenchPurchaseDTO">
  445. SELECT a.id as tOrderId,
  446. a.amount as amount,
  447. a.unit as unit,
  448. a.create_time as createTime,
  449. g.goods_id as goodsId,
  450. d.firm_name as procureFirmName
  451. FROM kwo_trade_order a
  452. LEFT JOIN kwo_trade_order_unit d ON a.id = d.t_order_id
  453. AND d.unit_type = "1" AND d.del_flag = 0
  454. LEFT JOIN kwo_trade_order_goods g ON a.id = g.t_order_id AND g.del_flag = 0
  455. <where>
  456. a.del_flag = 0
  457. <if test="procureTopEntId != null">
  458. and d.top_ent_id = #{procureTopEntId}
  459. </if>
  460. <if test="excludeStatuses != null and excludeStatuses.size() > 0">
  461. and a.status not in
  462. <foreach collection="excludeStatuses" item="item" open="(" close=")" separator=",">
  463. #{item}
  464. </foreach>
  465. </if>
  466. </where>
  467. ORDER BY a.create_time DESC
  468. LIMIT 10;
  469. </select>
  470. <select id="tradeOrderStatistic" resultType="com.sckw.core.model.vo.TableTop">
  471. SELECT a.status AS `value`, COUNT(a.status) AS total
  472. FROM kwo_trade_order a
  473. LEFT JOIN kwo_trade_order_unit d ON a.id = d.t_order_id AND d.unit_type = "1" AND d.del_flag = 0
  474. LEFT JOIN kwo_trade_order_unit e ON a.id = e.t_order_id AND e.unit_type = "2" AND e.del_flag = 0
  475. LEFT JOIN kwo_trade_order_goods g ON a.id = g.t_order_id AND g.del_flag = 0
  476. LEFT JOIN kwo_trade_order_contract f ON a.id = f.t_order_id AND f.del_flag = 0
  477. <where>
  478. a.del_flag = 0
  479. <choose>
  480. <when test="query.manager != null and !query.manager">
  481. <if test="query.isMain == 1">
  482. <if test="query.entList != null and query.entList.size() > 0 and query.entType != null">
  483. <if test="query.entType == 1">
  484. and
  485. e.top_ent_id in
  486. <foreach collection="query.entList" item="authUserId" open="(" close=")" separator=",">
  487. #{authUserId}
  488. </foreach>
  489. </if>
  490. <if test="query.entType == 2">
  491. and
  492. d.top_ent_id in
  493. <foreach collection="query.entList" item="authUserId" open="(" close=")" separator=",">
  494. #{authUserId}
  495. </foreach>
  496. </if>
  497. </if>
  498. </if>
  499. <if test="query.isMain == 0">
  500. <if test="query.entId != null and query.entType != null">
  501. <if test="query.entType == 1">
  502. and e.top_ent_id = #{query.entId}
  503. </if>
  504. <if test="query.entType == 2">
  505. and d.top_ent_id = #{query.entId}
  506. </if>
  507. </if>
  508. </if>
  509. </when>
  510. </choose>
  511. <if test="query.buyEntId != null">
  512. and d.ent_id = #{query.buyEntId}
  513. </if>
  514. <if test="query.saleEntId != null">
  515. and e.ent_id = #{query.saleEntId}
  516. </if>
  517. <!-- <if test="query.dataPermissionForceEmpty != null and query.dataPermissionForceEmpty">-->
  518. <!-- and 1 = 0-->
  519. <!-- </if>-->
  520. <!-- <if test="query.dataPermissionFilter != null and query.dataPermissionFilter">-->
  521. <!-- and exists (-->
  522. <!-- select 1-->
  523. <!-- from kwc_contract_trade ct-->
  524. <!-- where ct.id = f.contract_id-->
  525. <!-- and ct.del_flag = 0-->
  526. <!-- <if test="query.dataPermissionAllVisible != null and !query.dataPermissionAllVisible">-->
  527. <!-- and ct.ent_id in-->
  528. <!-- <foreach collection="query.dataPermissionEntIds" item="entId" open="(" close=")" separator=",">-->
  529. <!-- #{entId}-->
  530. <!-- </foreach>-->
  531. <!-- </if>-->
  532. <!-- <if test="query.dataPermissionPersonal != null and query.dataPermissionPersonal">-->
  533. <!-- and ct.salesman_id = #{query.dataPermissionUserId}-->
  534. <!-- </if>-->
  535. <!-- )-->
  536. <!-- </if>-->
  537. <if test="query.status != null">
  538. and a.status = #{query.status}
  539. </if>
  540. <if test="query.keywords != null and query.keywords != ''">
  541. and (
  542. a.t_order_no like concat('%', #{query.keywords}, '%')
  543. or d.firm_name like concat('%', #{query.keywords}, '%')
  544. or e.firm_name like concat('%', #{query.keywords}, '%')
  545. <if test="goodIds != null and goodIds.size() > 0">
  546. or g.goods_id in
  547. <foreach collection="goodIds" item="goodId" open="(" close=")" separator=",">
  548. #{goodId}
  549. </foreach>
  550. </if>
  551. )
  552. </if>
  553. <if test="query.startCreateTime != null">
  554. and a.create_time &gt;= #{query.startCreateTime}
  555. </if>
  556. <if test="query.endCreateTime != null">
  557. and a.create_time &lt;= #{query.endCreateTime}
  558. </if>
  559. <if test="(query.loadAddressCode != null and query.loadAddressCode != '') or (query.unloadAddressCode != null and query.unloadAddressCode != '')">
  560. and a.id in (
  561. SELECT t_order_id
  562. from kwo_trade_order_address where del_flag = 0
  563. <if test="query.loadAddressCode != null and query.loadAddressCode != ''">
  564. and address_type = 1
  565. and left(city_code, #{query.loadAddressLevel, jdbcType=INTEGER}) =
  566. left(#{query.loadAddressCode, jdbcType=INTEGER}, #{query.loadAddressLevel, jdbcType=INTEGER})
  567. </if>
  568. <if test="query.unloadAddressCode != null and query.unloadAddressCode != ''">
  569. and address_type = 2
  570. and left(city_code, #{query.unloadAddressLevel, jdbcType=INTEGER}) =
  571. left(#{query.unloadAddressCode, jdbcType=INTEGER},
  572. #{query.unloadAddressLevel, jdbcType=INTEGER})
  573. </if>
  574. )
  575. </if>
  576. <if test="query.trading != null and query.trading != ''">
  577. and a.trading = #{query.trading}
  578. </if>
  579. <if test="query.source != null and query.source != ''">
  580. and a.source = #{query.source}
  581. </if>
  582. <if test="query.deliveryType != null and query.deliveryType != ''">
  583. and a.delivery_type = #{query.deliveryType}
  584. </if>
  585. <if test="query.deliveryType != null and query.deliveryType != ''">
  586. and a.delivery_type = #{query.deliveryType}
  587. </if>
  588. </where>
  589. GROUP BY a.status
  590. </select>
  591. <select id="appStatistic" resultType="com.sckw.order.model.vo.res.TradeOrderAppStatisticVO">
  592. SELECT a.status AS `value`, COUNT(a.status) AS total
  593. FROM kwo_trade_order a
  594. LEFT JOIN kwo_trade_order_unit d ON a.id = d.t_order_id AND d.unit_type = "1" AND d.del_flag = 0
  595. LEFT JOIN kwo_trade_order_unit e ON a.id = e.t_order_id AND e.unit_type = "2" AND e.del_flag = 0
  596. <where>
  597. a.del_flag = 0
  598. -- 数据权限匹配
  599. <if test="query.isMain == 0">
  600. and (
  601. <if test="query.orderType == 1">
  602. <if test="query.entId != null">
  603. d.top_ent_id = #{query.entId}
  604. </if>
  605. <if test="authUserIds != null and authUserIds.size() > 0">
  606. and d.contacts_id in
  607. <foreach collection="authUserIds" item="authUserId" open="(" close=")" separator=",">
  608. #{authUserId}
  609. </foreach>
  610. </if>
  611. </if>
  612. <if test="query.orderType == 2">
  613. <if test="query.entId != null">
  614. e.top_ent_id = #{query.entId}
  615. </if>
  616. <if test="authUserIds != null and authUserIds.size() > 0">
  617. and e.contacts_id in
  618. <foreach collection="authUserIds" item="authUserId" open="(" close=")" separator=",">
  619. #{authUserId}
  620. </foreach>
  621. </if>
  622. </if>
  623. )
  624. </if>
  625. <if test="query.isMain == 1">
  626. and (
  627. <if test="query.orderType == 1">
  628. <if test="query.entId != null">
  629. d.top_ent_id = #{query.entId}
  630. </if>
  631. </if>
  632. <if test="query.orderType == 2">
  633. <if test="query.entId != null">
  634. e.top_ent_id = #{query.entId}
  635. </if>
  636. </if>
  637. )
  638. </if>
  639. <if test="query.orderType == 1">
  640. <if test="query.entId != null">
  641. and d.top_ent_id = #{query.entId}
  642. </if>
  643. </if>
  644. <if test="query.orderType == 2">
  645. <if test="query.entId != null">
  646. and e.top_ent_id = #{query.entId}
  647. </if>
  648. </if>
  649. <if test="statuses != null and statuses.size() > 0">
  650. and a.status in
  651. <foreach collection="statuses" item="item" open="(" close=")" separator=",">
  652. #{item}
  653. </foreach>
  654. </if>
  655. </where>
  656. GROUP BY a.status
  657. </select>
  658. <select id="getOrderStsInfo" resultType="com.sckw.order.model.dto.WorkbenchOrderStsDTO">
  659. SELECT SUM(a.amount) AS orderAmount,
  660. SUM(a.price) AS orderPrice,
  661. SUM(a.actual_amount) AS orderActualAmount
  662. FROM kwo_trade_order a
  663. LEFT JOIN kwo_trade_order_unit d ON a.id = d.t_order_id
  664. AND d.unit_type = "1" AND d.del_flag = 0
  665. LEFT JOIN kwo_trade_order_unit e ON a.id = e.t_order_id
  666. AND e.unit_type = "2" AND e.del_flag = 0
  667. <where>
  668. a.del_flag = 0
  669. <if test="query.unit != null and query.unit != ''">
  670. and a.unit = #{query.unit}
  671. </if>
  672. <if test="query.startCreateTime != null">
  673. and a.create_time &gt;= #{query.startCreateTime}
  674. </if>
  675. <if test="query.endCreateTime != null">
  676. and a.create_time &lt;= #{query.endCreateTime}
  677. </if>
  678. <if test="excludeStatuses != null and excludeStatuses.size() > 0">
  679. and a.status not in
  680. <foreach collection="excludeStatuses" item="item" open="(" close=")" separator=",">
  681. #{item}
  682. </foreach>
  683. </if>
  684. <if test="query.orderType == 1">
  685. <if test="query.entId != null">
  686. and d.top_ent_id = #{query.entId}
  687. </if>
  688. </if>
  689. <if test="query.orderType == 2">
  690. <if test="query.entId != null">
  691. and e.top_ent_id = #{query.entId}
  692. </if>
  693. </if>
  694. </where>
  695. </select>
  696. <select id="getMaxOrderNoByDate" resultType="java.lang.String">
  697. SELECT MAX(t_order_no)
  698. FROM kwo_trade_order
  699. WHERE create_time &gt;= #{date};
  700. </select>
  701. <select id="getOrderNumByTopEntId" resultType="com.sckw.order.api.model.TradeOrderCountStatisticsDTO">
  702. SELECT u.unit_type AS orderType,
  703. COUNT(0) AS num
  704. FROM kwo_trade_order o
  705. LEFT JOIN kwo_trade_order_unit u
  706. ON o.id = u.t_order_id
  707. <where>
  708. o.del_flag = 0
  709. AND o.status NOT IN (0, 2)
  710. AND u.del_flag = 0
  711. <if test="topEntId != null">
  712. and u.top_ent_id = #{topEntId}
  713. </if>
  714. <if test="enterpriseIds != null and enterpriseIds.size() > 0">
  715. and o.ent_id in
  716. <foreach collection="enterpriseIds" item="item" open="(" close=")" separator=",">
  717. #{item}
  718. </foreach>
  719. </if>
  720. </where>
  721. GROUP BY u.unit_type
  722. </select>
  723. <select id="workbenchExcel" resultType="com.sckw.order.model.dto.WbTOrderExcelStsResDTO">
  724. SELECT DATE_FORMAT(create_time, #{item.dateFormat}) AS formatDate,
  725. SUM(CASE
  726. WHEN #{item.stsFactorsOne} = 1 THEN price
  727. WHEN #{item.stsFactorsOne} = 2 THEN 1
  728. ELSE 0
  729. END) AS stsFactorsOneValue,
  730. SUM(CASE
  731. WHEN #{item.stsFactorsTwo} = 1 THEN price
  732. WHEN #{item.stsFactorsTwo} = 2 THEN 1
  733. ELSE 0
  734. END) AS stsFactorsTwoValue
  735. FROM kwo_trade_order
  736. WHERE id IN (SELECT t_order_id
  737. FROM kwo_trade_order_unit
  738. WHERE del_flag = 0
  739. AND unit_type = #{item.unitType}
  740. AND top_ent_id = #{item.topEntId})
  741. AND create_time >= #{item.startTime}
  742. AND status NOT IN (0, 2)
  743. AND del_flag = 0
  744. GROUP BY DATE_FORMAT(create_time, #{item.dateFormat});
  745. </select>
  746. <select id="querySaleOrder" resultType="com.sckw.order.api.model.OrderSaleVo">
  747. select ktog.goods_id,
  748. sum(ifnull(kto.amount, 0)) as amount
  749. from kwo_trade_order kto
  750. left join kwo_trade_order_goods ktog on kto.id = ktog.t_order_id and ktog.del_flag = 0
  751. <where>
  752. kto.del_flag = 0
  753. <if test="start != null and end != null">
  754. and kto.create_time between #{start} and #{end}
  755. </if>
  756. group by ktog.goods_id
  757. order by amount desc
  758. </where>
  759. </select>
  760. <select id="selectData" resultType="com.sckw.order.api.model.TradeOrderVo">
  761. select a.status,
  762. a.id tOrderId,
  763. a.t_order_no tOrderNo,
  764. d.firm_name buyEntName,
  765. e.firm_name sellEntName,
  766. ktog.goods_name,
  767. ktog.unit_price,
  768. ktog.unit,
  769. ktog.goods_type,
  770. a.amount,
  771. a.price,
  772. a.load_amount,
  773. a.unload_amount,
  774. a.charge_type,
  775. a.create_time,
  776. a.add_vehicles
  777. FROM kwo_trade_order a
  778. LEFT JOIN kwo_trade_order_unit d ON a.id = d.t_order_id AND d.unit_type = '1' AND d.del_flag = 0
  779. LEFT JOIN kwo_trade_order_unit e ON a.id = e.t_order_id AND e.unit_type = '2' AND e.del_flag = 0
  780. left join kwo_trade_order_goods ktog on a.id = ktog.t_order_id and ktog.del_flag = 0
  781. <where>
  782. a.del_flag = 0
  783. <if test="para.startTime != null and para.endTime != null">
  784. and a.create_time between #{para.startTime,jdbcType=TIMESTAMP} and #{para.endTime,jdbcType=TIMESTAMP}
  785. </if>
  786. <if test="para.orderNo != null and para.orderNo != ''">
  787. and a.t_order_no = #{para.orderNo}
  788. </if>
  789. <if test="para.entId != null and para.entId.size() > 0">
  790. <if test="para.type != null and para.type == 1">
  791. and
  792. e.ent_id in
  793. <foreach collection="para.entId" item="item" open="(" close=")" separator=",">
  794. #{item}
  795. </foreach>
  796. </if>
  797. <if test="para.type != null and para.type == 2">
  798. and d.ent_id in
  799. <foreach collection="para.entId" item="item" open="(" close=")" separator=",">
  800. #{item}
  801. </foreach>
  802. </if>
  803. </if>
  804. limit 10
  805. </where>
  806. </select>
  807. <select id="queryCount" resultType="java.lang.Long">
  808. select count(1)
  809. from kwo_trade_order kto
  810. inner JOIN kwo_trade_order_unit d ON kto.id = d.t_order_id AND d.unit_type = '2' AND d.del_flag = 0
  811. <where>
  812. kto.del_flag = 0
  813. and kto.status = 1
  814. <if test="ids != null and ids.size() != 0">
  815. and d.ent_id in
  816. <foreach collection="ids" item="item" separator="," open="(" close=")">
  817. #{item}
  818. </foreach>
  819. </if>
  820. </where>
  821. </select>
  822. <select id="queryList" resultType="com.sckw.order.api.model.TradeVo">
  823. select kto.id,
  824. kto.create_time,
  825. kto.status,
  826. kto.amount,
  827. ktog.unit_price,
  828. ktog.goods_name,
  829. kto.t_order_no,
  830. c.firm_name
  831. from kwo_trade_order kto
  832. inner JOIN kwo_trade_order_unit d ON kto.id = d.t_order_id AND d.unit_type = '2' AND d.del_flag = 0
  833. inner JOIN kwo_trade_order_unit c ON kto.id = c.t_order_id AND c.unit_type = '1' AND c.del_flag = 0
  834. inner join kwo_trade_order_goods ktog on kto.id = ktog.t_order_id and ktog.del_flag = 0
  835. <where>
  836. kto.del_flag = 0
  837. and kto.status = 1
  838. <if test="ids != null and ids.size() != 0">
  839. and d.ent_id in
  840. <foreach collection="ids" item="item" separator="," open="(" close=")">
  841. #{item}
  842. </foreach>
  843. </if>
  844. order by kto.create_time desc
  845. <if test="all != null and all">
  846. limit 10
  847. </if>
  848. </where>
  849. </select>
  850. <select id="querySalesReportRawData" resultType="com.sckw.order.model.SalesReportRawData">
  851. select
  852. kto.charge_type as chargeType,
  853. kto.load_amount as loadAmount,
  854. kto.unload_amount as unloadAmount,
  855. d.ent_id as customerId,
  856. d.firm_name as customerName,
  857. ktog.goods_id as goodsId,
  858. ktog.unit_price as unitPrice,
  859. kto.amount as amount,
  860. kto.price as price,
  861. DATE_FORMAT(kto.create_time, '%Y-%m-%d %H:%i:%S') as createTime
  862. from kwo_trade_order kto
  863. inner join kwo_trade_order_unit d on kto.id = d.t_order_id and d.unit_type = '1' and d.del_flag = 0
  864. inner join kwo_trade_order_unit e on kto.id = e.t_order_id and e.unit_type = '2' and e.del_flag = 0
  865. inner join kwo_trade_order_goods ktog on kto.id = ktog.t_order_id and ktog.del_flag = 0
  866. where kto.del_flag = 0
  867. and e.ent_id = #{curEntId}
  868. <if test="customerId != null">
  869. and d.ent_id = #{customerId}
  870. </if>
  871. <if test="goodsId != null">
  872. and ktog.goods_id = #{goodsId}
  873. </if>
  874. </select>
  875. <select id="countList" resultType="com.sckw.order.api.model.TradeSaleVo">
  876. select ktog.goods_id,
  877. CONCAT(
  878. LPAD(HOUR(kto.create_time), 2, '0'),
  879. ':00-',
  880. LPAD(MOD(HOUR(kto.create_time) + 1, 24), 2, '0'),
  881. ':00'
  882. ) AS time_period,
  883. sum(kto.amount) as amount
  884. from kwo_trade_order kto
  885. inner JOIN kwo_trade_order_unit d ON kto.id = d.t_order_id AND d.unit_type = '2' AND d.del_flag = 0
  886. inner JOIN kwo_trade_order_unit c ON kto.id = c.t_order_id AND c.unit_type = '1' AND c.del_flag = 0
  887. inner join kwo_trade_order_goods ktog on kto.id = ktog.t_order_id and ktog.del_flag = 0
  888. <where>
  889. kto.del_flag = 0
  890. and kto.status in (1, 2, 3, 4)
  891. <if test="ids != null and ids.size() != 0">
  892. and d.ent_id in
  893. <foreach collection="ids" item="item" separator="," open="(" close=")">
  894. #{item}
  895. </foreach>
  896. </if>
  897. and kto.create_time between #{para.startTime} and #{para.endTime}
  898. group by time_period, ktog.goods_id
  899. order by time_period
  900. </where>
  901. </select>
  902. <select id="countSale" resultType="com.sckw.order.api.model.SaleVo">
  903. select DATE_FORMAT(kto.create_time, '%Y-%m-%d') as order_day,
  904. count(kto.id) count,
  905. sum(kto.price) as price
  906. from kwo_trade_order kto
  907. inner JOIN kwo_trade_order_unit d
  908. ON kto.id = d.t_order_id AND d.unit_type = '2' AND d.del_flag = 0
  909. inner JOIN kwo_trade_order_unit c ON kto.id = c.t_order_id AND c.unit_type = '1' AND c.del_flag = 0
  910. <where>
  911. kto.del_flag = 0
  912. and kto.status in (1, 2, 3, 4)
  913. <if test="ids != null and ids.size() != 0">
  914. and d.ent_id in
  915. <foreach collection="ids" item="item" separator="," open="(" close=")">
  916. #{item}
  917. </foreach>
  918. </if>
  919. and kto.create_time between #{para.startTime}
  920. and #{para.endTime}
  921. group by order_day
  922. </where>
  923. </select>
  924. <select id="countBuy" resultType="com.sckw.order.api.model.BuyVo">
  925. select sum(kto.price) as price,
  926. c.firm_name,
  927. c.ent_id
  928. from kwo_trade_order kto
  929. inner JOIN kwo_trade_order_unit d
  930. ON kto.id = d.t_order_id AND d.unit_type = '2' AND d.del_flag = 0
  931. inner JOIN kwo_trade_order_unit c ON kto.id = c.t_order_id AND c.unit_type = '1' AND c.del_flag = 0
  932. <where>
  933. kto.del_flag = 0
  934. and kto.status in (1, 2, 3, 4)
  935. <if test="ids != null and ids.size() != 0">
  936. and d.ent_id in
  937. <foreach collection="ids" item="item" separator="," open="(" close=")">
  938. #{item}
  939. </foreach>
  940. </if>
  941. and kto.create_time between #{para.startTime}
  942. and #{para.endTime}
  943. group by c.ent_id, c.firm_name
  944. order by price desc
  945. limit 5
  946. </where>
  947. </select>
  948. <select id="countGoods" resultType="com.sckw.order.api.model.GoodsVo">
  949. select sum(kto.amount), ktog.goods_name, ktog.goods_id
  950. from kwo_trade_order kto
  951. inner JOIN kwo_trade_order_unit d ON kto.id = d.t_order_id AND d.unit_type = '2' AND d.del_flag = 0
  952. inner join kwo_trade_order_goods ktog on kto.id = ktog.t_order_id and ktog.del_flag = 0
  953. <where>
  954. kto.del_flag = 0
  955. and kto.status in (1, 2, 3, 4)
  956. <if test="ids != null and ids.size() != 0">
  957. and d.ent_id in
  958. <foreach collection="ids" item="item" separator="," open="(" close=")">
  959. #{item}
  960. </foreach>
  961. </if>
  962. and kto.create_time between #{para.startTime} and #{para.endTime}
  963. group by ktog.goods_name, ktog.goods_id
  964. </where>
  965. </select>
  966. <select id="buyRank" resultType="com.sckw.order.api.model.TradeBuyVo">
  967. select sum(kto.amount) as amount,
  968. c.firm_name as firmName
  969. from kwo_trade_order kto
  970. inner JOIN kwo_trade_order_unit d ON kto.id = d.t_order_id AND d.unit_type = '2' AND d.del_flag = 0
  971. inner JOIN kwo_trade_order_unit c ON kto.id = c.t_order_id AND c.unit_type = '1' AND c.del_flag = 0
  972. inner join kwo_trade_order_goods ktog on kto.id = ktog.t_order_id and ktog.del_flag = 0
  973. <where>
  974. kto.del_flag = 0
  975. and kto.status in (1, 2, 3, 4)
  976. <if test="ids != null and ids.size() != 0">
  977. and d.ent_id in
  978. <foreach collection="ids" item="item" separator="," open="(" close=")">
  979. #{item}
  980. </foreach>
  981. </if>
  982. and kto.create_time between #{para.startTime} and #{para.endTime}
  983. group by c.ent_id, c.firm_name
  984. order by amount desc
  985. limit 5
  986. </where>
  987. </select>
  988. <select id="saleTop" resultType="com.sckw.order.model.vo.SaleTopVo">
  989. select ROW_NUMBER() OVER (ORDER BY amount DESC) AS sort,
  990. sum(kto.price) as amount,
  991. d.firm_name entName
  992. from kwo_trade_order kto
  993. inner JOIN kwo_trade_order_unit d ON kto.id = d.t_order_id AND d.unit_type = '1' AND d.del_flag = 0
  994. inner join kwo_trade_order_unit ku on kto.id = ku.t_order_id and ku.unit_type = '2' and ku.del_flag = 0
  995. <where>
  996. kto.del_flag = 0
  997. and kto.status = 4
  998. and ku.ent_id in (538038314096136193,538039617157337089,538040297439891457)
  999. group by kto.id,
  1000. d.firm_name
  1001. </where>
  1002. </select>
  1003. <select id="saleSum" resultType="java.math.BigDecimal">
  1004. select
  1005. sum(kto.price) as amount
  1006. from kwo_trade_order kto
  1007. inner join kwo_trade_order_unit ku on kto.id = ku.t_order_id and ku.unit_type = '2' and ku.del_flag = 0
  1008. <where>
  1009. kto.del_flag = 0
  1010. and kto.status = 4
  1011. and ku.ent_id in (538038314096136193,538039617157337089,538040297439891457)
  1012. </where>
  1013. </select>
  1014. <select id="joinSelect" resultType="com.sckw.order.api.model.TradeOrderDto">
  1015. select kto.id,
  1016. ktog.goods_id,
  1017. kto.amount,
  1018. ktog.unit_price
  1019. from kwo_trade_order kto
  1020. inner join kwo_trade_order_goods ktog on kto.id = ktog.t_order_id and ktog.del_flag = 0
  1021. inner join kwo_trade_order_unit ku on kto.id = ku.t_order_id and ku.unit_type = '2' and ku.del_flag = 0
  1022. <where>
  1023. kto.del_flag = 0
  1024. and kto.archive_flag != 1
  1025. and kto.status = 4
  1026. and ku.ent_id in (538038314096136193,538039617157337089,538040297439891457)
  1027. limit 20
  1028. </where>
  1029. </select>
  1030. <select id="selectDailyShipmentByCategory" resultType="com.sckw.order.model.dto.DailyShipmentStatisticsDTO">
  1031. select DATE_FORMAT(kto.create_time, '%Y-%m-%d') as orderDate,
  1032. ktog.goods_type as goodsType,
  1033. SUM(kto.actual_amount) as actualAmount
  1034. from kwo_trade_order kto
  1035. inner join kwo_trade_order_goods ktog on kto.id = ktog.t_order_id and ktog.del_flag = 0
  1036. inner join kwo_trade_order_unit ku on kto.id = ku.t_order_id and ku.unit_type = '2' and ku.del_flag = 0
  1037. where kto.del_flag = 0
  1038. and kto.status = 5
  1039. and ku.top_ent_id = #{entId}
  1040. and kto.create_time >= #{startTime}
  1041. and kto.create_time &lt;= #{endTime}
  1042. group by DATE_FORMAT(kto.create_time, '%Y-%m-%d'), ktog.goods_type
  1043. order by orderDate, goodsType;
  1044. </select>
  1045. <select id="selectDailySalesByCategory" resultType="com.sckw.order.model.dto.DailySalesStatisticsDTO">
  1046. select DATE_FORMAT(kto.create_time, '%Y-%m-%d') as orderDate,
  1047. ktog.goods_type as goodsType,
  1048. SUM(kto.price) as salesAmount
  1049. from kwo_trade_order kto
  1050. inner join kwo_trade_order_goods ktog on kto.id = ktog.t_order_id and ktog.del_flag = 0
  1051. inner join kwo_trade_order_unit ku on kto.id = ku.t_order_id and ku.unit_type = '2' and ku.del_flag = 0
  1052. where kto.del_flag = 0
  1053. and kto.status = 5
  1054. and ku.top_ent_id = #{entId}
  1055. and kto.create_time >= #{startTime}
  1056. and kto.create_time &lt;= #{endTime}
  1057. group by DATE_FORMAT(kto.create_time, '%Y-%m-%d'), ktog.goods_type
  1058. order by orderDate, goodsType;
  1059. </select>
  1060. <select id="selectGoodsVolumeTop5" resultType="com.sckw.order.model.dto.GoodsVolumeStatisticsDTO">
  1061. select ktog.goods_name as goodsName,
  1062. SUM(kto.actual_amount) as totalVolume
  1063. from kwo_trade_order kto
  1064. inner join kwo_trade_order_goods ktog on kto.id = ktog.t_order_id and ktog.del_flag = 0
  1065. inner join kwo_trade_order_unit ku on kto.id = ku.t_order_id and ku.unit_type = '2' and ku.del_flag = 0
  1066. where kto.del_flag = 0
  1067. and kto.status = 5
  1068. and ku.top_ent_id = #{entId}
  1069. group by ktog.goods_name
  1070. order by totalVolume desc
  1071. limit 5;
  1072. </select>
  1073. <select id="selectGoodsAmountTop5" resultType="com.sckw.order.model.dto.GoodsAmountStatisticsDTO">
  1074. select ktog.goods_name as goodsName,
  1075. SUM(kto.price) as totalAmount
  1076. from kwo_trade_order kto
  1077. inner join kwo_trade_order_goods ktog on kto.id = ktog.t_order_id and ktog.del_flag = 0
  1078. inner join kwo_trade_order_unit ku on kto.id = ku.t_order_id and ku.unit_type = '2' and ku.del_flag = 0
  1079. where kto.del_flag = 0
  1080. and kto.status = 5
  1081. and ku.top_ent_id = #{entId}
  1082. group by ktog.goods_name
  1083. order by totalAmount desc
  1084. limit 5;
  1085. </select>
  1086. </mapper>