KwoTradeOrderMapper.xml 46 KB

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