KwpLedgerTradeMapper.xml 43 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929
  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.payment.dao.KwpLedgerTradeMapper">
  4. <resultMap id="BaseResultMap" type="com.sckw.payment.model.KwpLedgerTrade">
  5. <!--@mbg.generated-->
  6. <!--@Table kwp_ledger_trade-->
  7. <id column="id" jdbcType="BIGINT" property="id"/>
  8. <result column="ent_id" jdbcType="BIGINT" property="entId"/>
  9. <result column="t_ledger_no" jdbcType="VARCHAR" property="tLedgerNo"/>
  10. <result column="name" jdbcType="VARCHAR" property="name"/>
  11. <result column="start_time" jdbcType="TIMESTAMP" property="startTime"/>
  12. <result column="end_time" jdbcType="TIMESTAMP" property="endTime"/>
  13. <result column="tax_rate" jdbcType="INTEGER" property="taxRate"/>
  14. <result column="trading" jdbcType="VARCHAR" property="trading"/>
  15. <result column="total_price" jdbcType="DECIMAL" property="totalPrice"/>
  16. <result column="ex_tax_price" jdbcType="DECIMAL" property="exTaxPrice"/>
  17. <result column="settle_price" jdbcType="DECIMAL" property="settlePrice"/>
  18. <result column="actual_price" jdbcType="DECIMAL" property="actualPrice"/>
  19. <result column="deduct_price" jdbcType="DECIMAL" property="deductPrice"/>
  20. <result column="audit_user" jdbcType="VARCHAR" property="auditUser"/>
  21. <result column="audit_phone" jdbcType="VARCHAR" property="auditPhone"/>
  22. <result column="success_user" jdbcType="VARCHAR" property="successUser"/>
  23. <result column="success_phone" jdbcType="VARCHAR" property="successPhone"/>
  24. <result column="generate_time" jdbcType="TIMESTAMP" property="generateTime"/>
  25. <result column="receipt_time" jdbcType="TIMESTAMP" property="receiptTime"/>
  26. <result column="url" jdbcType="VARCHAR" property="url"/>
  27. <result column="order_count" jdbcType="INTEGER" property="orderCount"/>
  28. <result column="remark" jdbcType="VARCHAR" property="remark"/>
  29. <result column="status" jdbcType="INTEGER" property="status"/>
  30. <result column="create_by" jdbcType="BIGINT" property="createBy"/>
  31. <result column="create_time" jdbcType="TIMESTAMP" property="createTime"/>
  32. <result column="update_by" jdbcType="BIGINT" property="updateBy"/>
  33. <result column="update_time" jdbcType="TIMESTAMP" property="updateTime"/>
  34. <result column="del_flag" jdbcType="INTEGER" property="delFlag"/>
  35. </resultMap>
  36. <sql id="Base_Column_List">
  37. <!--@mbg.generated-->
  38. id,
  39. ent_id,
  40. t_ledger_no,
  41. `name`,
  42. start_time,
  43. end_time,
  44. tax_rate,
  45. trading,
  46. total_price,
  47. ex_tax_price,
  48. settle_price,
  49. actual_price,
  50. deduct_price,
  51. audit_user,
  52. audit_phone,
  53. success_user,
  54. success_phone,
  55. generate_time,
  56. receipt_time,
  57. url,
  58. order_count,
  59. remark,
  60. `status`,
  61. create_by,
  62. create_time,
  63. update_by,
  64. update_time,
  65. del_flag
  66. </sql>
  67. <sql id="sell_col">
  68. klt.id,
  69. klt.t_ledger_no tLedgerNo,
  70. klt.name,
  71. klt.start_time startTime,
  72. klt.end_time endTime,
  73. klt.tax_rate taxRate,
  74. klt.trading,
  75. klt.total_price totalPrice,
  76. klt.ex_tax_price exTaxPrice,
  77. klt.settle_price settlePrice,
  78. klt.actual_price actualPrice,
  79. klt.deduct_price deductPrice,
  80. klt.audit_phone auditPhone,
  81. klt.audit_user auditUser,
  82. klt.url,
  83. klt.generate_time generateTime,
  84. klt.receipt_time receiptTime,
  85. klt.remark,
  86. klt.status,
  87. klt.create_by createBy,
  88. kltu.contacts,
  89. kltu.phone,
  90. kltu.firm_name firmName,
  91. klt.order_count orderCount
  92. </sql>
  93. <sql id="purchase_col">
  94. klt.id,
  95. klt.t_ledger_no tLedgerNo,
  96. klt.name,
  97. klt.start_time startTime,
  98. klt.end_time endTime,
  99. klt.tax_rate taxRate,
  100. klt.trading,
  101. klt.total_price totalPrice,
  102. klt.ex_tax_price exTaxPrice,
  103. klt.settle_price settlePrice,
  104. klt.actual_price actualPrice,
  105. klt.deduct_price deductPrice,
  106. klt.success_phone successPhone,
  107. klt.success_user successUser,
  108. klt.url,
  109. klt.generate_time generateTime,
  110. klt.receipt_time receiptTime,
  111. klt.remark,
  112. klt.create_by createBy,
  113. klt.status,
  114. kltu.contacts,
  115. kltu.phone,
  116. kltu.firm_name firmName,
  117. klt.order_count orderCount
  118. </sql>
  119. <!--销售2 采购1-->
  120. <select id="sellList" resultType="com.sckw.payment.model.dto.LedgerSellDto">
  121. select
  122. <include refid="sell_col"/>
  123. from kwp_ledger_trade klt
  124. inner join kwp_ledger_trade_unit kltu
  125. on klt.id = kltu.t_ledger_id and kltu.del_flag = 0 and
  126. kltu.unit_type = #{tradeReq.unitType,jdbcType=INTEGER}
  127. inner join kwp_ledger_trade_unit kltu2
  128. on klt.id = kltu2.t_ledger_id and kltu2.del_flag = 0 and kltu2.unit_type =
  129. #{tradeReq.unitTypeTwo,jdbcType=INTEGER}
  130. <where>
  131. klt.del_flag = 0
  132. and kltu2.top_ent_id = #{tradeReq.entId,jdbcType=BIGINT}
  133. <if test="tradeReq.status != null">
  134. and klt.status = #{tradeReq.status}
  135. </if>
  136. <if test="tradeReq.trading != null">
  137. and klt.trading = #{tradeReq.trading,jdbcType=INTEGER}
  138. </if>
  139. <if test="tradeReq.endCreateTime != null and tradeReq.endCreateTime != '' and tradeReq.startCreateTime != null and tradeReq.startCreateTime != ''">
  140. and klt.generate_time between #{tradeReq.startCreateTime,jdbcType=TIMESTAMP}
  141. and #{tradeReq.endCreateTime,jdbcType=TIMESTAMP}
  142. </if>
  143. <if test="tradeReq.keywords != null and tradeReq.keywords != ''">
  144. and (
  145. klt.t_ledger_no like concat('%'
  146. , #{tradeReq.keywords,jdbcType=VARCHAR}
  147. , '%')
  148. or kltu.firm_name like concat('%'
  149. , #{tradeReq.keywords,jdbcType=VARCHAR}
  150. , '%')
  151. or kltu.contacts like concat('%'
  152. , #{tradeReq.keywords,jdbcType=VARCHAR}
  153. , '%')
  154. )
  155. </if>
  156. <if test="authList != null and authList.size() != 0">
  157. and (
  158. case when klt.status in (1, 6)
  159. then
  160. klt.create_by in
  161. <foreach collection="authList" item="item" open="(" close=")" separator=",">
  162. #{item,jdbcType=BIGINT}
  163. </foreach>
  164. when klt.status in (2, 3, 4, 5) then
  165. (
  166. klt.create_by in
  167. <foreach collection="authList" item="item" open="(" close=")" separator=",">
  168. #{item,jdbcType=BIGINT}
  169. </foreach>
  170. or kltu2.contacts_id in
  171. <foreach collection="authList" item="item" open="(" close=")" separator=",">
  172. #{item,jdbcType=BIGINT}
  173. </foreach>
  174. )
  175. end
  176. )
  177. </if>
  178. </where>
  179. order by klt.generate_time desc
  180. </select>
  181. <select id="list" resultType="com.sckw.payment.model.vo.LedgerSell">
  182. select klt.id,
  183. klt.t_ledger_no tLedgerNo,
  184. klt.name,
  185. klt.start_time startTime,
  186. klt.end_time endTime,
  187. klt.tax_rate taxRate,
  188. klt.trading,
  189. klt.total_price totalPrice,
  190. klt.ex_tax_price exTaxPrice,
  191. klt.settle_price settlePrice,
  192. klt.actual_price actualPrice,
  193. klt.deduct_price deductPrice,
  194. klt.audit_phone auditPhone,
  195. klt.audit_user auditUser,
  196. klt.success_user successUser,
  197. klt.success_phone successPhone,
  198. klt.url,
  199. klt.generate_time generateTime,
  200. klt.receipt_time receiptTime,
  201. klt.remark,
  202. klt.status,
  203. klt.create_by createBy,
  204. kltu.contacts,
  205. kltu.phone,
  206. kltu.firm_name purchaseFirmName,
  207. kltu2.firm_name sellFirmName,
  208. klt.order_count orderCount
  209. from kwp_ledger_trade klt
  210. inner join kwp_ledger_trade_unit kltu
  211. on klt.id = kltu.t_ledger_id and kltu.del_flag = 0 and
  212. kltu.unit_type = #{tradeReq.unitType,jdbcType=INTEGER}
  213. inner join kwp_ledger_trade_unit kltu2
  214. on klt.id = kltu2.t_ledger_id and kltu2.del_flag = 0 and kltu2.unit_type =
  215. #{tradeReq.unitTypeTwo,jdbcType=INTEGER}
  216. <where>
  217. klt.del_flag = 0
  218. <if test="tradeReq.status != null">
  219. and klt.status = #{tradeReq.status}
  220. </if>
  221. <if test="tradeReq.trading != null">
  222. and klt.trading = #{tradeReq.trading,jdbcType=INTEGER}
  223. </if>
  224. <if test="tradeReq.endCreateTime != null and tradeReq.endCreateTime != '' and tradeReq.startCreateTime != null and tradeReq.startCreateTime != ''">
  225. and klt.generate_time between #{tradeReq.startCreateTime,jdbcType=TIMESTAMP}
  226. and #{tradeReq.endCreateTime,jdbcType=TIMESTAMP}
  227. </if>
  228. <if test="tradeReq.keywords != null and tradeReq.keywords != ''">
  229. and (
  230. klt.t_ledger_no like concat('%'
  231. , #{tradeReq.keywords,jdbcType=VARCHAR}
  232. , '%')
  233. or kltu.firm_name like concat('%'
  234. , #{tradeReq.keywords,jdbcType=VARCHAR}
  235. , '%')
  236. or kltu2.firm_name like concat('%'
  237. , #{tradeReq.keywords,jdbcType=VARCHAR}
  238. , '%')
  239. or kltu.contacts like concat('%'
  240. , #{tradeReq.keywords,jdbcType=VARCHAR}
  241. , '%')
  242. )
  243. </if>
  244. </where>
  245. order by klt.generate_time desc
  246. </select>
  247. <select id="selectIds" resultType="com.sckw.payment.model.vo.LedgerSell">
  248. select klt.id,
  249. klt.t_ledger_no tLedgerNo,
  250. klt.name,
  251. klt.start_time startTime,
  252. klt.end_time endTime,
  253. klt.tax_rate taxRate,
  254. klt.trading,
  255. klt.total_price totalPrice,
  256. klt.ex_tax_price exTaxPrice,
  257. klt.settle_price settlePrice,
  258. klt.actual_price actualPrice,
  259. klt.deduct_price deductPrice,
  260. klt.audit_phone auditPhone,
  261. klt.audit_user auditUser,
  262. klt.success_user successUser,
  263. klt.success_phone successPhone,
  264. klt.url,
  265. klt.generate_time generateTime,
  266. klt.receipt_time receiptTime,
  267. klt.remark,
  268. klt.status,
  269. klt.create_by createBy,
  270. kltu.contacts,
  271. kltu.phone,
  272. kltu.firm_name purchaseFirmName,
  273. kltu2.firm_name sellFirmName,
  274. klt.order_count orderCount
  275. from kwp_ledger_trade klt
  276. inner join kwp_ledger_trade_unit kltu
  277. on klt.id = kltu.t_ledger_id and kltu.del_flag = 0 and
  278. kltu.unit_type = 1
  279. inner join kwp_ledger_trade_unit kltu2
  280. on klt.id = kltu2.t_ledger_id and kltu2.del_flag = 0 and kltu2.unit_type = 2
  281. <where>
  282. klt.del_flag = 0
  283. and klt.id in
  284. <foreach collection="ids" item="id" close=")" open="(" separator=",">
  285. #{id,jdbcType=BIGINT}
  286. </foreach>
  287. </where>
  288. </select>
  289. <select id="purchaseList" resultType="com.sckw.payment.model.dto.LedgerPurchaseDto">
  290. select
  291. <include refid="purchase_col"/>
  292. from kwp_ledger_trade klt
  293. inner join kwp_ledger_trade_unit kltu
  294. on klt.id = kltu.t_ledger_id and kltu.del_flag = 0 and
  295. kltu.unit_type = #{tradeReq.unitType,jdbcType=INTEGER}
  296. inner join kwp_ledger_trade_unit kltu2
  297. on klt.id = kltu2.t_ledger_id and kltu2.del_flag = 0 and kltu2.unit_type =
  298. #{tradeReq.unitTypeTwo,jdbcType=INTEGER}
  299. <where>
  300. klt.del_flag = 0
  301. and kltu2.top_ent_id = #{tradeReq.entId,jdbcType=BIGINT}
  302. <choose>
  303. <when test="tradeReq.status != null">
  304. and klt.status = #{tradeReq.status}
  305. </when>
  306. <otherwise>
  307. and klt.status not in (1, 6)
  308. </otherwise>
  309. </choose>
  310. <if test="tradeReq.trading != null">
  311. and klt.trading = #{tradeReq.trading,jdbcType=INTEGER}
  312. </if>
  313. <if test="tradeReq.endCreateTime != null and tradeReq.endCreateTime != '' and tradeReq.startCreateTime != null and tradeReq.startCreateTime != ''">
  314. and klt.generate_time between #{tradeReq.startCreateTime,jdbcType=TIMESTAMP}
  315. and #{tradeReq.endCreateTime,jdbcType=TIMESTAMP}
  316. </if>
  317. <if test="tradeReq.keywords != null and tradeReq.keywords != ''">
  318. and (
  319. klt.t_ledger_no like concat('%'
  320. , #{tradeReq.keywords,jdbcType=VARCHAR}
  321. , '%')
  322. or kltu.firm_name like concat('%'
  323. , #{tradeReq.keywords,jdbcType=VARCHAR}
  324. , '%')
  325. or kltu.contacts like concat('%'
  326. , #{tradeReq.keywords,jdbcType=VARCHAR}
  327. , '%')
  328. )
  329. </if>
  330. <if test="authList != null and authList.size() != 0">
  331. and (
  332. case
  333. when klt.status = 2 then
  334. true
  335. when klt.status in (3, 4, 5) then
  336. (
  337. (
  338. kltu2.contacts_id in
  339. <foreach collection="authList" item="item" open="(" close=")" separator=",">
  340. #{item,jdbcType=BIGINT}
  341. </foreach>)
  342. or
  343. (
  344. select kllt.id
  345. from kwp_ledger_logistics_track kllt where kllt.del_flag = 0
  346. and kllt.l_ledger_id = klt.id
  347. and kllt.status in (3, 5)
  348. and kllt.create_by in
  349. <foreach collection="authList" item="item" open="(" close=")" separator=",">
  350. #{item,jdbcType=BIGINT}
  351. </foreach>
  352. )
  353. )
  354. end
  355. )
  356. </if>
  357. </where>
  358. order by klt.generate_time desc
  359. </select>
  360. <!--数量统计规则:未筛选,统计所有。需要根据企业方,排除已保存,已撤回两个状态-->
  361. <select id="countSum" resultType="java.lang.Long">
  362. select IFNULL(count(1), 0)
  363. from kwp_ledger_trade klt
  364. inner join kwp_ledger_trade_unit kltu
  365. on klt.id = kltu.t_ledger_id and kltu.del_flag = 0 and
  366. kltu.unit_type = #{tradeReq.unitType,jdbcType=INTEGER}
  367. inner join kwp_ledger_trade_unit kltu2
  368. on klt.id = kltu2.t_ledger_id and kltu2.del_flag = 0 and
  369. kltu2.unit_type = #{tradeReq.unitTypeTwo,jdbcType=INTEGER}
  370. <where>
  371. klt.del_flag = 0
  372. and kltu2.top_ent_id = #{tradeReq.entId,jdbcType=BIGINT}
  373. <if test="tradeReq.status != null">
  374. and klt.status = #{tradeReq.status}
  375. </if>
  376. <if test="status != null and status.size() > 0">
  377. and klt.status not in
  378. <foreach collection="status" item="id" close=")" open="(" separator=",">
  379. #{id,jdbcType=BIGINT}
  380. </foreach>
  381. </if>
  382. <if test="tradeReq.trading != null">
  383. and klt.trading = #{tradeReq.trading,jdbcType=INTEGER}
  384. </if>
  385. <if test="tradeReq.endCreateTime != null and tradeReq.endCreateTime != '' and tradeReq.startCreateTime != null and tradeReq.startCreateTime != ''">
  386. and klt.generate_time between #{tradeReq.startCreateTime,jdbcType=TIMESTAMP}
  387. and #{tradeReq.endCreateTime,jdbcType=TIMESTAMP}
  388. </if>
  389. <if test="tradeReq.keywords != null and tradeReq.keywords != ''">
  390. and (
  391. klt.t_ledger_no like concat('%'
  392. , #{tradeReq.keywords,jdbcType=VARCHAR}
  393. , '%')
  394. or kltu.firm_name like concat('%'
  395. , #{tradeReq.keywords,jdbcType=VARCHAR}
  396. , '%')
  397. or kltu.contacts like concat('%'
  398. , #{tradeReq.keywords,jdbcType=VARCHAR}
  399. , '%')
  400. )
  401. </if>
  402. </where>
  403. </select>
  404. <!--金额统计规则:未筛选状态,统计已完成的对账单,结算金额。筛选状态统计具体的状态-->
  405. <select id="countSumMoney" resultType="java.math.BigDecimal">
  406. select sum(klt.settle_price)
  407. from kwp_ledger_trade klt
  408. inner join kwp_ledger_trade_unit kltu
  409. on klt.id = kltu.t_ledger_id and kltu.del_flag = 0 and
  410. kltu.unit_type = #{tradeReq.unitType,jdbcType=INTEGER}
  411. inner join kwp_ledger_trade_unit kltu2
  412. on klt.id = kltu2.t_ledger_id and kltu2.del_flag = 0 and
  413. kltu2.unit_type = #{tradeReq.unitTypeTwo,jdbcType=INTEGER}
  414. <where>
  415. klt.del_flag = 0
  416. and kltu2.top_ent_id = #{tradeReq.entId,jdbcType=BIGINT}
  417. <if test="tradeReq.status != null">
  418. and klt.status = #{tradeReq.status}
  419. </if>
  420. <if test="tradeReq.status == null">
  421. and klt.status = 4
  422. </if>
  423. <if test="status != null and status.size() > 0">
  424. and klt.status not in
  425. <foreach collection="status" item="id" close=")" open="(" separator=",">
  426. #{id,jdbcType=BIGINT}
  427. </foreach>
  428. </if>
  429. <if test="tradeReq.trading != null">
  430. and klt.trading = #{tradeReq.trading,jdbcType=INTEGER}
  431. </if>
  432. <if test="tradeReq.endCreateTime != null and tradeReq.endCreateTime != '' and tradeReq.startCreateTime != null and tradeReq.startCreateTime != ''">
  433. and klt.generate_time between #{tradeReq.startCreateTime,jdbcType=TIMESTAMP}
  434. and #{tradeReq.endCreateTime,jdbcType=TIMESTAMP}
  435. </if>
  436. <if test="tradeReq.keywords != null and tradeReq.keywords != ''">
  437. and (
  438. klt.t_ledger_no like concat('%'
  439. , #{tradeReq.keywords,jdbcType=VARCHAR}
  440. , '%')
  441. or kltu.firm_name like concat('%'
  442. , #{tradeReq.keywords,jdbcType=VARCHAR}
  443. , '%')
  444. or kltu.contacts like concat('%'
  445. , #{tradeReq.keywords,jdbcType=VARCHAR}
  446. , '%')
  447. )
  448. </if>
  449. </where>
  450. </select>
  451. <select id="countOrder" resultType="java.util.Map">
  452. SELECT count(1) "0",
  453. count(IF(klt.status = 1, 1, NULL)) "1",
  454. count(IF(klt.status = 2, 1, NULL)) "2",
  455. count(IF(klt.status = 3, 1, NULL)) "3",
  456. count(IF(klt.status = 4, 1, NULL)) "4",
  457. count(IF(klt.status = 5, 1, NULL)) "5",
  458. count(IF(klt.status = 6, 1, NULL)) "6"
  459. from kwp_ledger_trade klt
  460. inner join kwp_ledger_trade_unit kltu
  461. on klt.id = kltu.t_ledger_id and kltu.del_flag = 0 and
  462. kltu.unit_type = #{tradeReq.unitType,jdbcType=INTEGER}
  463. inner join kwp_ledger_trade_unit kltu2
  464. on klt.id = kltu2.t_ledger_id and kltu2.del_flag = 0 and kltu2.unit_type =
  465. #{tradeReq.unitTypeTwo,jdbcType=INTEGER}
  466. <where>
  467. klt.del_flag = 0
  468. and kltu2.top_ent_id = #{tradeReq.entId,jdbcType=BIGINT}
  469. <if test="tradeReq.unitType != null and tradeReq.unitType == 2">
  470. and klt.status not in (1, 6)
  471. </if>
  472. <if test="tradeReq.trading != null">
  473. and klt.trading = #{tradeReq.trading,jdbcType=INTEGER}
  474. </if>
  475. <if test="tradeReq.endCreateTime != null and tradeReq.endCreateTime != '' and tradeReq.startCreateTime != null and tradeReq.startCreateTime != ''">
  476. and klt.generate_time between #{tradeReq.startCreateTime,jdbcType=TIMESTAMP}
  477. and #{tradeReq.endCreateTime,jdbcType=TIMESTAMP}
  478. </if>
  479. <if test="tradeReq.keywords != null and tradeReq.keywords != ''">
  480. and (
  481. klt.t_ledger_no like concat('%'
  482. , #{tradeReq.keywords,jdbcType=VARCHAR}
  483. , '%')
  484. or kltu.firm_name like concat('%'
  485. , #{tradeReq.keywords,jdbcType=VARCHAR}
  486. , '%')
  487. or kltu.contacts like concat('%'
  488. , #{tradeReq.keywords,jdbcType=VARCHAR}
  489. , '%')
  490. )
  491. </if>
  492. </where>
  493. </select>
  494. <select id="countSellOrder" resultType="java.util.Map">
  495. SELECT count(1) "0",
  496. count(IF(klt.status = 1, 1, NULL)) "1",
  497. count(IF(klt.status = 2, 1, NULL)) "2",
  498. count(IF(klt.status = 3, 1, NULL)) "3",
  499. count(IF(klt.status = 4, 1, NULL)) "4",
  500. count(IF(klt.status = 5, 1, NULL)) "5",
  501. count(IF(klt.status = 6, 1, NULL)) "6"
  502. from kwp_ledger_trade klt
  503. inner join kwp_ledger_trade_unit kltu
  504. on klt.id = kltu.t_ledger_id and kltu.del_flag = 0 and
  505. kltu.unit_type = #{tradeReq.unitType,jdbcType=INTEGER}
  506. inner join kwp_ledger_trade_unit kltu2
  507. on klt.id = kltu2.t_ledger_id and kltu2.del_flag = 0 and kltu2.unit_type =
  508. #{tradeReq.unitTypeTwo,jdbcType=INTEGER}
  509. <where>
  510. klt.del_flag = 0
  511. and kltu2.top_ent_id = #{tradeReq.entId,jdbcType=BIGINT}
  512. <if test="tradeReq.unitType != null and tradeReq.unitType == 2">
  513. and klt.status not in (1, 6)
  514. </if>
  515. <if test="tradeReq.trading != null">
  516. and klt.trading = #{tradeReq.trading,jdbcType=INTEGER}
  517. </if>
  518. <if test="tradeReq.endCreateTime != null and tradeReq.endCreateTime != '' and tradeReq.startCreateTime != null and tradeReq.startCreateTime != ''">
  519. and klt.generate_time between #{tradeReq.startCreateTime,jdbcType=TIMESTAMP}
  520. and #{tradeReq.endCreateTime,jdbcType=TIMESTAMP}
  521. </if>
  522. <if test="tradeReq.keywords != null and tradeReq.keywords != ''">
  523. and (
  524. klt.t_ledger_no like concat('%'
  525. , #{tradeReq.keywords,jdbcType=VARCHAR}
  526. , '%')
  527. or kltu.firm_name like concat('%'
  528. , #{tradeReq.keywords,jdbcType=VARCHAR}
  529. , '%')
  530. or kltu.contacts like concat('%'
  531. , #{tradeReq.keywords,jdbcType=VARCHAR}
  532. , '%')
  533. )
  534. </if>
  535. <if test="authList != null and authList.size() != 0">
  536. and (
  537. case when klt.status in (1, 6)
  538. then
  539. klt.create_by in
  540. <foreach collection="authList" item="item" open="(" close=")" separator=",">
  541. #{item,jdbcType=BIGINT}
  542. </foreach>
  543. when klt.status in (2, 3, 4, 5) then
  544. (
  545. klt.create_by in
  546. <foreach collection="authList" item="item" open="(" close=")" separator=",">
  547. #{item,jdbcType=BIGINT}
  548. </foreach>
  549. or kltu2.contacts_id in
  550. <foreach collection="authList" item="item" open="(" close=")" separator=",">
  551. #{item,jdbcType=BIGINT}
  552. </foreach>
  553. )
  554. end
  555. )
  556. </if>
  557. </where>
  558. </select>
  559. <select id="countPurchaseOrder" resultType="java.util.Map">
  560. SELECT count(1) "0",
  561. count(IF(klt.status = 1, 1, NULL)) "1",
  562. count(IF(klt.status = 2, 1, NULL)) "2",
  563. count(IF(klt.status = 3, 1, NULL)) "3",
  564. count(IF(klt.status = 4, 1, NULL)) "4",
  565. count(IF(klt.status = 5, 1, NULL)) "5",
  566. count(IF(klt.status = 6, 1, NULL)) "6"
  567. from kwp_ledger_trade klt
  568. inner join kwp_ledger_trade_unit kltu
  569. on klt.id = kltu.t_ledger_id and kltu.del_flag = 0 and
  570. kltu.unit_type = #{tradeReq.unitType,jdbcType=INTEGER}
  571. inner join kwp_ledger_trade_unit kltu2
  572. on klt.id = kltu2.t_ledger_id and kltu2.del_flag = 0 and kltu2.unit_type =
  573. #{tradeReq.unitTypeTwo,jdbcType=INTEGER}
  574. <where>
  575. klt.del_flag = 0
  576. and kltu2.top_ent_id = #{tradeReq.entId,jdbcType=BIGINT}
  577. <if test="tradeReq.unitType != null and tradeReq.unitType == 2">
  578. and klt.status not in (1, 6)
  579. </if>
  580. <if test="tradeReq.trading != null">
  581. and klt.trading = #{tradeReq.trading,jdbcType=INTEGER}
  582. </if>
  583. <if test="tradeReq.endCreateTime != null and tradeReq.endCreateTime != '' and tradeReq.startCreateTime != null and tradeReq.startCreateTime != ''">
  584. and klt.generate_time between #{tradeReq.startCreateTime,jdbcType=TIMESTAMP}
  585. and #{tradeReq.endCreateTime,jdbcType=TIMESTAMP}
  586. </if>
  587. <if test="tradeReq.keywords != null and tradeReq.keywords != ''">
  588. and (
  589. klt.t_ledger_no like concat('%'
  590. , #{tradeReq.keywords,jdbcType=VARCHAR}
  591. , '%')
  592. or kltu.firm_name like concat('%'
  593. , #{tradeReq.keywords,jdbcType=VARCHAR}
  594. , '%')
  595. or kltu.contacts like concat('%'
  596. , #{tradeReq.keywords,jdbcType=VARCHAR}
  597. , '%')
  598. )
  599. </if>
  600. <if test="authList != null and authList.size() != 0">
  601. and (
  602. case
  603. when klt.status = 2 then
  604. true
  605. when klt.status in (3, 4, 5) then
  606. (
  607. (
  608. kltu2.contacts_id in
  609. <foreach collection="authList" item="item" open="(" close=")" separator=",">
  610. #{item,jdbcType=BIGINT}
  611. </foreach>)
  612. or
  613. (
  614. select kllt.id
  615. from kwp_ledger_logistics_track kllt where kllt.del_flag = 0
  616. and kllt.l_ledger_id = klt.id
  617. and kllt.status in (3, 5)
  618. and kllt.create_by in
  619. <foreach collection="authList" item="item" open="(" close=")" separator=",">
  620. #{item,jdbcType=BIGINT}
  621. </foreach>
  622. )
  623. )
  624. end
  625. )
  626. </if>
  627. </where>
  628. </select>
  629. <select id="countOrder2" resultType="java.util.Map">
  630. SELECT count(1) "0",
  631. count(IF(kll_distinct.status = 1, 1, NULL)) "1",
  632. count(IF(kll_distinct.status = 2, 1, NULL)) "2",
  633. count(IF(kll_distinct.status = 3, 1, NULL)) "3",
  634. count(IF(kll_distinct.status = 4, 1, NULL)) "4",
  635. count(IF(kll_distinct.status = 5, 1, NULL)) "5",
  636. count(IF(kll_distinct.status = 6, 1, NULL)) "6"
  637. FROM (
  638. SELECT distinct klt.id, klt.status
  639. from kwp_ledger_trade klt
  640. inner join kwp_ledger_trade_unit kltu
  641. on klt.id = kltu.t_ledger_id and kltu.del_flag = 0
  642. <where>
  643. klt.del_flag = 0
  644. <if test="tradeReq.trading != null">
  645. and klt.trading = #{tradeReq.trading,jdbcType=INTEGER}
  646. </if>
  647. <if test="tradeReq.endCreateTime != null and tradeReq.endCreateTime != '' and tradeReq.startCreateTime != null and tradeReq.startCreateTime != ''">
  648. and klt.generate_time between #{tradeReq.startCreateTime,jdbcType=TIMESTAMP}
  649. and #{tradeReq.endCreateTime,jdbcType=TIMESTAMP}
  650. </if>
  651. <if test="tradeReq.keywords != null and tradeReq.keywords != ''">
  652. and (
  653. klt.t_ledger_no like concat('%', #{tradeReq.keywords,jdbcType=VARCHAR}, '%')
  654. or kltu.firm_name like concat('%', #{tradeReq.keywords,jdbcType=VARCHAR}, '%')
  655. or kltu.contacts like concat('%', #{tradeReq.keywords,jdbcType=VARCHAR}, '%')
  656. )
  657. </if>
  658. </where>
  659. ) kll_distinct
  660. </select>
  661. <select id="selectSellIds" resultType="com.sckw.payment.model.dto.LedgerSellDto">
  662. select klt.id,
  663. klt.t_ledger_no tLedgerNo,
  664. klt.name,
  665. klt.start_time startTime,
  666. klt.end_time endTime,
  667. klt.tax_rate taxRate,
  668. klt.trading,
  669. klt.total_price totalPrice,
  670. klt.ex_tax_price exTaxPrice,
  671. klt.settle_price settlePrice,
  672. klt.actual_price actualPrice,
  673. klt.deduct_price deductPrice,
  674. klt.audit_phone auditPhone,
  675. klt.audit_user auditUser,
  676. klt.url,
  677. klt.generate_time generateTime,
  678. klt.receipt_time receiptTime,
  679. klt.remark,
  680. klt.status,
  681. kltu.contacts,
  682. kltu.phone,
  683. kltu.firm_name firmName,
  684. klt.order_count orderCount
  685. from kwp_ledger_trade klt
  686. inner join kwp_ledger_trade_unit kltu on klt.id = kltu.t_ledger_id and kltu.del_flag = 0
  687. <where>
  688. klt.del_flag = 0
  689. and kltu.unit_type = 1
  690. and klt.id in
  691. <foreach collection="ids" item="id" close=")" open="(" separator=",">
  692. #{id,jdbcType=BIGINT}
  693. </foreach>
  694. </where>
  695. order by klt.generate_time desc
  696. </select>
  697. <select id="selectPurchaseIds" resultType="com.sckw.payment.model.dto.LedgerPurchaseDto">
  698. select klt.id,
  699. klt.t_ledger_no tLedgerNo,
  700. klt.name,
  701. klt.start_time startTime,
  702. klt.end_time endTime,
  703. klt.tax_rate taxRate,
  704. klt.trading,
  705. klt.total_price totalPrice,
  706. klt.ex_tax_price exTaxPrice,
  707. klt.settle_price settlePrice,
  708. klt.actual_price actualPrice,
  709. klt.deduct_price deductPrice,
  710. klt.audit_phone auditPhone,
  711. klt.audit_user auditUser,
  712. klt.url,
  713. klt.generate_time generateTime,
  714. klt.receipt_time receiptTime,
  715. klt.remark,
  716. klt.status,
  717. kltu.contacts,
  718. kltu.phone,
  719. kltu.firm_name firmName,
  720. klt.order_count orderCount
  721. from kwp_ledger_trade klt
  722. inner join kwp_ledger_trade_unit kltu on klt.id = kltu.t_ledger_id and kltu.del_flag = 0
  723. <where>
  724. klt.del_flag = 0
  725. and kltu.unit_type = 2
  726. and klt.id in
  727. <foreach collection="ids" item="id" close=")" open="(" separator=",">
  728. #{id,jdbcType=BIGINT}
  729. </foreach>
  730. </where>
  731. order by klt.generate_time desc
  732. </select>
  733. <select id="selectId" resultType="com.sckw.payment.model.dto.LedgerTradeDto">
  734. select klt.id,
  735. klt.t_ledger_no tLedgerNo,
  736. klt.name,
  737. klt.start_time startTime,
  738. klt.end_time endTime,
  739. klt.tax_rate taxRate,
  740. klt.trading,
  741. klt.total_price totalPrice,
  742. klt.ex_tax_price exTaxPrice,
  743. klt.settle_price settlePrice,
  744. klt.actual_price actualPrice,
  745. klt.deduct_price deductPrice,
  746. klt.audit_phone auditPhone,
  747. klt.audit_user auditUser,
  748. klt.success_user successUser,
  749. klt.success_phone successPhone,
  750. klt.url,
  751. klt.generate_time generateTime,
  752. klt.receipt_time receiptTime,
  753. klt.remark,
  754. klt.status,
  755. kltu.contacts,
  756. kltu.top_ent_id purchaseEntId,
  757. kltu.phone,
  758. kltu.firm_name firmName,
  759. klt.order_count orderCount
  760. from kwp_ledger_trade klt
  761. inner join kwp_ledger_trade_unit kltu on klt.id = kltu.t_ledger_id and kltu.del_flag = 0
  762. <where>
  763. klt.del_flag = 0
  764. and kltu.unit_type = #{unitType,jdbcType=INTEGER}
  765. and klt.id = #{id,jdbcType=BIGINT}
  766. </where>
  767. </select>
  768. <update id="updatePrice">
  769. update kwp_ledger_trade
  770. set actual_price = IFNULL(actual_price, 0) + #{totalPrice,jdbcType=DECIMAL}
  771. where id = #{id,jdbcType=BIGINT}
  772. </update>
  773. <select id="selectJoin" resultType="java.lang.String">
  774. SELECT klt.t_ledger_no
  775. from kwp_ledger_trade klt
  776. inner join kwp_ledger_trade_unit kltu
  777. on klt.id = kltu.t_ledger_id and kltu.del_flag = 0 and
  778. kltu.unit_type = 1
  779. inner join kwp_ledger_trade_unit kltu2
  780. on klt.id = kltu2.t_ledger_id and kltu2.del_flag = 0 and kltu2.unit_type = 2
  781. <where>
  782. klt.del_flag = 0
  783. and klt.status != 4
  784. and kltu.top_ent_id = #{entId,jdbcType=BIGINT}
  785. and kltu2.top_ent_id = #{entTarget,jdbcType=BIGINT}
  786. </where>
  787. </select>
  788. <select id="countSize" resultType="com.sckw.payment.model.dto.LedgerSize">
  789. select count(distinct if(kltu.unit_type = 2, klt.id, null)) send,
  790. count(distinct if(kltu.unit_type = 1, klt.id, null)) receive
  791. from kwp_ledger_trade klt
  792. inner join kwp_ledger_trade_unit kltu on klt.id = kltu.t_ledger_id and kltu.del_flag = 0
  793. <where>
  794. klt.del_flag = 0
  795. and klt.status != 1
  796. and kltu.top_ent_id = #{entId,jdbcType=BIGINT}
  797. </where>
  798. </select>
  799. <select id="exportList" resultType="com.sckw.payment.model.dto.LedgerTradeDto">
  800. select klt.id,
  801. klt.t_ledger_no tLedgerNo,
  802. klt.name,
  803. klt.start_time startTime,
  804. klt.end_time endTime,
  805. klt.tax_rate taxRate,
  806. klt.trading,
  807. klt.total_price totalPrice,
  808. klt.ex_tax_price exTaxPrice,
  809. klt.settle_price settlePrice,
  810. klt.actual_price actualPrice,
  811. klt.deduct_price deductPrice,
  812. klt.url,
  813. klt.generate_time generateTime,
  814. klt.receipt_time receiptTime,
  815. klt.remark,
  816. klt.status,
  817. klt.create_by createBy,
  818. (case
  819. when #{tradeReq.unitType,jdbcType=INTEGER} = 1 then klt.audit_user
  820. else klt.success_user end) as contacts,
  821. (case
  822. when #{tradeReq.unitType,jdbcType=INTEGER} = 1 then klt.audit_phone
  823. else klt.success_phone end) as phone,
  824. kltu.firm_name firmName,
  825. klt.order_count orderCount
  826. from kwp_ledger_trade klt
  827. inner join kwp_ledger_trade_unit kltu
  828. on klt.id = kltu.t_ledger_id and kltu.del_flag = 0 and
  829. kltu.unit_type = #{tradeReq.unitType,jdbcType=INTEGER}
  830. inner join kwp_ledger_trade_unit kltu2
  831. on klt.id = kltu2.t_ledger_id and kltu2.del_flag = 0 and kltu2.unit_type =
  832. #{tradeReq.unitTypeTwo,jdbcType=INTEGER}
  833. <where>
  834. klt.del_flag = 0
  835. <choose>
  836. <when test="idList != null and idList.size() != 0">
  837. and klt.id in
  838. <foreach collection="idList" open="(" separator="," close=")" item="item">
  839. #{item,jdbcType=BIGINT}
  840. </foreach>
  841. </when>
  842. <otherwise>
  843. and kltu2.top_ent_id = #{tradeReq.entId,jdbcType=BIGINT}
  844. <if test="tradeReq.status != null and tradeReq.status != 0">
  845. and klt.status = #{tradeReq.status}
  846. </if>
  847. <if test="tradeReq.trading != null">
  848. and klt.trading = #{tradeReq.trading,jdbcType=INTEGER}
  849. </if>
  850. <if test="tradeReq.endCreateTime != null and tradeReq.endCreateTime != '' and tradeReq.startCreateTime != null and tradeReq.startCreateTime != ''">
  851. and klt.generate_time between #{tradeReq.startCreateTime,jdbcType=TIMESTAMP}
  852. and #{tradeReq.endCreateTime,jdbcType=TIMESTAMP}
  853. </if>
  854. <if test="tradeReq.keywords != null and tradeReq.keywords != ''">
  855. and (
  856. klt.t_ledger_no like concat('%'
  857. , #{tradeReq.keywords,jdbcType=VARCHAR}
  858. , '%')
  859. or kltu.firm_name like concat('%'
  860. , #{tradeReq.keywords,jdbcType=VARCHAR}
  861. , '%')
  862. or kltu.contacts like concat('%'
  863. , #{tradeReq.keywords,jdbcType=VARCHAR}
  864. , '%')
  865. )
  866. </if>
  867. <if test="authList != null and authList.size() != 0">
  868. <if test="tradeReq.unitType == 1">
  869. and (
  870. case when klt.status in (1, 6)
  871. then
  872. klt.create_by in
  873. <foreach collection="authList" item="item" open="(" close=")" separator=",">
  874. #{item,jdbcType=BIGINT}
  875. </foreach>
  876. when klt.status in (2, 3, 4, 5) then
  877. (
  878. klt.create_by in
  879. <foreach collection="authList" item="item" open="(" close=")" separator=",">
  880. #{item,jdbcType=BIGINT}
  881. </foreach>
  882. or kltu2.contacts_id in
  883. <foreach collection="authList" item="item" open="(" close=")" separator=",">
  884. #{item,jdbcType=BIGINT}
  885. </foreach>
  886. )
  887. end
  888. )
  889. </if>
  890. <if test="tradeReq.unitType == 2">
  891. and (
  892. case
  893. when klt.status = 2 then
  894. true
  895. when klt.status in (3, 4, 5) then
  896. (
  897. (
  898. kltu2.contacts_id in
  899. <foreach collection="authList" item="item" open="(" close=")" separator=",">
  900. #{item,jdbcType=BIGINT}
  901. </foreach>)
  902. or
  903. (
  904. select kllt.id
  905. from kwp_ledger_logistics_track kllt where kllt.del_flag = 0
  906. and kllt.l_ledger_id = klt.id
  907. and kllt.status in (3, 5)
  908. and kllt.create_by in
  909. <foreach collection="authList" item="item" open="(" close=")" separator=",">
  910. #{item,jdbcType=BIGINT}
  911. </foreach>
  912. )
  913. )
  914. end
  915. )
  916. </if>
  917. </if>
  918. </otherwise>
  919. </choose>
  920. </where>
  921. </select>
  922. </mapper>