KwoTradeOrderMapper.xml 46 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007
  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 d.ent_id as customerId,
  852. d.firm_name as customerName,
  853. ktog.goods_id as goodsId,
  854. kto.amount as amount,
  855. kto.price as price,
  856. DATE_FORMAT(kto.create_time, '%Y-%m-%d') as createTime
  857. from kwo_trade_order kto
  858. inner join kwo_trade_order_unit d on kto.id = d.t_order_id and d.unit_type = '1' and d.del_flag = 0
  859. inner join kwo_trade_order_unit e on kto.id = e.t_order_id and e.unit_type = '2' and e.del_flag = 0
  860. inner join kwo_trade_order_goods ktog on kto.id = ktog.t_order_id and ktog.del_flag = 0
  861. where kto.del_flag = 0
  862. and e.ent_id = #{curEntId}
  863. <if test="customerId != null">
  864. and d.ent_id = #{customerId}
  865. </if>
  866. <if test="goodsId != null">
  867. and ktog.goods_id = #{goodsId}
  868. </if>
  869. </select>
  870. <select id="countList" resultType="com.sckw.order.api.model.TradeSaleVo">
  871. select ktog.goods_id,
  872. CONCAT(
  873. LPAD(HOUR(kto.create_time), 2, '0'),
  874. ':00-',
  875. LPAD(MOD(HOUR(kto.create_time) + 1, 24), 2, '0'),
  876. ':00'
  877. ) AS time_period,
  878. sum(kto.amount) as amount
  879. from kwo_trade_order kto
  880. inner JOIN kwo_trade_order_unit d ON kto.id = d.t_order_id AND d.unit_type = '2' AND d.del_flag = 0
  881. inner JOIN kwo_trade_order_unit c ON kto.id = c.t_order_id AND c.unit_type = '1' AND c.del_flag = 0
  882. inner join kwo_trade_order_goods ktog on kto.id = ktog.t_order_id and ktog.del_flag = 0
  883. <where>
  884. kto.del_flag = 0
  885. and kto.status in (1, 2, 3, 4)
  886. <if test="ids != null and ids.size() != 0">
  887. and d.ent_id in
  888. <foreach collection="ids" item="item" separator="," open="(" close=")">
  889. #{item}
  890. </foreach>
  891. </if>
  892. and kto.create_time between #{para.startTime} and #{para.endTime}
  893. group by time_period, ktog.goods_id
  894. order by time_period
  895. </where>
  896. </select>
  897. <select id="countSale" resultType="com.sckw.order.api.model.SaleVo">
  898. select DATE_FORMAT(kto.create_time, '%Y-%m-%d') as order_day,
  899. count(kto.id) count,
  900. sum(kto.price) as price
  901. from kwo_trade_order kto
  902. inner JOIN kwo_trade_order_unit d
  903. ON kto.id = d.t_order_id AND d.unit_type = '2' AND d.del_flag = 0
  904. inner JOIN kwo_trade_order_unit c ON kto.id = c.t_order_id AND c.unit_type = '1' AND c.del_flag = 0
  905. <where>
  906. kto.del_flag = 0
  907. and kto.status in (1, 2, 3, 4)
  908. <if test="ids != null and ids.size() != 0">
  909. and d.ent_id in
  910. <foreach collection="ids" item="item" separator="," open="(" close=")">
  911. #{item}
  912. </foreach>
  913. </if>
  914. and kto.create_time between #{para.startTime}
  915. and #{para.endTime}
  916. group by order_day
  917. </where>
  918. </select>
  919. <select id="countBuy" resultType="com.sckw.order.api.model.BuyVo">
  920. select sum(kto.price) as price,
  921. c.firm_name,
  922. c.ent_id
  923. from kwo_trade_order kto
  924. inner JOIN kwo_trade_order_unit d
  925. ON kto.id = d.t_order_id AND d.unit_type = '2' AND d.del_flag = 0
  926. inner JOIN kwo_trade_order_unit c ON kto.id = c.t_order_id AND c.unit_type = '1' AND c.del_flag = 0
  927. <where>
  928. kto.del_flag = 0
  929. and kto.status in (1, 2, 3, 4)
  930. <if test="ids != null and ids.size() != 0">
  931. and d.ent_id in
  932. <foreach collection="ids" item="item" separator="," open="(" close=")">
  933. #{item}
  934. </foreach>
  935. </if>
  936. and kto.create_time between #{para.startTime}
  937. and #{para.endTime}
  938. group by c.ent_id, c.firm_name
  939. order by price desc
  940. limit 5
  941. </where>
  942. </select>
  943. <select id="countGoods" resultType="com.sckw.order.api.model.GoodsVo">
  944. select sum(kto.amount), ktog.goods_name, ktog.goods_id
  945. from kwo_trade_order kto
  946. inner JOIN kwo_trade_order_unit d ON kto.id = d.t_order_id AND d.unit_type = '2' AND d.del_flag = 0
  947. inner join kwo_trade_order_goods ktog on kto.id = ktog.t_order_id and ktog.del_flag = 0
  948. <where>
  949. kto.del_flag = 0
  950. and kto.status in (1, 2, 3, 4)
  951. <if test="ids != null and ids.size() != 0">
  952. and d.ent_id in
  953. <foreach collection="ids" item="item" separator="," open="(" close=")">
  954. #{item}
  955. </foreach>
  956. </if>
  957. and kto.create_time between #{para.startTime} and #{para.endTime}
  958. group by ktog.goods_name, ktog.goods_id
  959. </where>
  960. </select>
  961. <select id="buyRank" resultType="com.sckw.order.api.model.TradeBuyVo">
  962. select sum(kto.amount) as amount,
  963. c.firm_name as firmName
  964. from kwo_trade_order kto
  965. inner JOIN kwo_trade_order_unit d ON kto.id = d.t_order_id AND d.unit_type = '2' AND d.del_flag = 0
  966. inner JOIN kwo_trade_order_unit c ON kto.id = c.t_order_id AND c.unit_type = '1' AND c.del_flag = 0
  967. inner join kwo_trade_order_goods ktog on kto.id = ktog.t_order_id and ktog.del_flag = 0
  968. <where>
  969. kto.del_flag = 0
  970. and kto.status in (1, 2, 3, 4)
  971. <if test="ids != null and ids.size() != 0">
  972. and d.ent_id in
  973. <foreach collection="ids" item="item" separator="," open="(" close=")">
  974. #{item}
  975. </foreach>
  976. </if>
  977. and kto.create_time between #{para.startTime} and #{para.endTime}
  978. group by c.ent_id, c.firm_name
  979. order by amount desc
  980. limit 5
  981. </where>
  982. </select>
  983. </mapper>