StockMapper.xml 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945
  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.zfire.mall.manager.commonmapper.stock.StockCommonMapper">
  4. <select id="list" resultType="com.zfire.mall.manager.bean.stock.StockBean">
  5. SELECT
  6. kdm.id as materialId,
  7. kdm.number AS materialNumber,
  8. kdm.`name` AS materialName,
  9. kdm.old_number AS materialOldNumber,
  10. kdm.specification,
  11. kdm.base_unit_id,
  12. kdm.category_name,
  13. kdm.material_group_name
  14. FROM
  15. stock s
  16. JOIN stock_correspond_position scp on scp.stock_id = s.stock_id
  17. JOIN king_dee_material kdm ON s.material_id = kdm.id
  18. JOIN stock_correspond sc on scp.correspond_id = sc.id
  19. where 1=1
  20. and scp.stock_id = s.stock_id
  21. <if test="correspondId != null and correspondId.size > 0">
  22. AND scp.correspond_id in
  23. <foreach item="item" index="index" collection="correspondId" open="(" separator=","
  24. close=")">
  25. #{item}
  26. </foreach>
  27. </if>
  28. <if test="stockId !=null and stockId != ''">
  29. and scp.stock_id = #{stockId}
  30. </if>
  31. <!-- <if test="categoryId !=null and categoryId != ''">
  32. and kdm.category_id = #{categoryId}
  33. </if>-->
  34. <if test="categoryId != null and categoryId.size > 0">
  35. AND kdm.category_id in
  36. <foreach item="item" index="index" collection="categoryId" open="(" separator=","
  37. close=")">
  38. #{item}
  39. </foreach>
  40. </if>
  41. <if test="materialOldNumber !=null and materialOldNumber != ''">
  42. and kdm.old_number like concat('%',#{materialOldNumber},'%')
  43. </if>
  44. <if test="materialName !=null and materialName != ''">
  45. and kdm.name like concat('%',#{materialName},'%')
  46. </if>
  47. <if test="materialNumber !=null and materialNumber != ''">
  48. and kdm.number like concat('%',#{materialNumber},'%')
  49. </if>
  50. <if test="specification !=null and specification != ''">
  51. and kdm.specification like concat('%',#{specification},'%')
  52. </if>
  53. group by kdm.id
  54. order by kdm.create_time desc
  55. </select>
  56. <select id="selectInvoiceCount" resultType="Integer">
  57. SELECT
  58. ifnull(SUM(iao.refundable_qty),0)
  59. FROM
  60. invoice_application_order iao
  61. LEFT JOIN invoice_application ia ON iao.invoice_id = ia.id
  62. where ia.examine_status in ('SAVE','WAIT')
  63. and iao.material_id=#{materialId}
  64. and type != 2
  65. <if test="correspondId != null and correspondId != ''">
  66. and ia.correspond_id =#{correspondId}
  67. </if>
  68. </select>
  69. <select id="countAll" resultType="Integer">
  70. SELECT
  71. ifnull(SUM(iao.refundable_qty),0)
  72. FROM
  73. sales_order ia
  74. LEFT JOIN sales_order_item iao ON ia.id = iao.sales_order_no
  75. where ia.examine_status != 'OK'
  76. and iao.material_id =#{materialId}
  77. and ia.type != 2
  78. <if test="correspondId != null and correspondId != ''">
  79. and ia.correspond_id =#{correspondId}
  80. </if>
  81. </select>
  82. <select id="countReserved" resultType="Integer">
  83. SELECT
  84. ifnull(sum( roi.reserved_num ),0)
  85. FROM
  86. reserved_order_item roi
  87. WHERE
  88. roi.STATUS = 1
  89. and roi.material_id = #{materialId}
  90. <if test="correspondId != null and correspondId != ''">
  91. and roi.correspond_id =#{correspondId}
  92. </if>
  93. </select>
  94. <resultMap id="sockPosition" type="com.zfire.mall.manager.bean.k3.StockPositionStock">
  95. <id column="id" jdbcType="VARCHAR" property="id"/>
  96. <result column="name" jdbcType="VARCHAR" property="name"/>
  97. <result column="stock_cordon" jdbcType="DECIMAL" property="stockCordon"/>
  98. <result column="remark" jdbcType="VARCHAR" property="remark"/>
  99. <result column="create_by" jdbcType="VARCHAR" property="createBy"/>
  100. <result column="create_time" jdbcType="TIMESTAMP" property="createTime"/>
  101. <result column="update_time" jdbcType="TIMESTAMP" property="updateTime"/>
  102. <result column="update_by" jdbcType="VARCHAR" property="updateBy"/>
  103. <collection property="kingDeeStocks" ofType="com.zfire.mall.manager.plus.entity.KingDeeStock" select="stocks" column="id">
  104. <id column="id" jdbcType="VARCHAR" property="id"/>
  105. <result column="number" jdbcType="VARCHAR" property="number"/>
  106. <result column="name" jdbcType="VARCHAR" property="name"/>
  107. <result column="useOrgNumber" jdbcType="VARCHAR" property="useOrgName"/>
  108. <result column="useOrgName" jdbcType="VARCHAR" property="useOrgName"/>
  109. <result column="syncTime" jdbcType="TIMESTAMP" property="syncTime"/>
  110. <result column="create_by" jdbcType="VARCHAR" property="createBy"/>
  111. <result column="create_time" jdbcType="TIMESTAMP" property="createTime"/>
  112. <result column="update_by" jdbcType="VARCHAR" property="updateBy"/>
  113. <result column="update_time" jdbcType="TIMESTAMP" property="updateTime"/>
  114. <result column="forbid_status" jdbcType="VARCHAR" property="forbidStatus"/>
  115. <result column="principal_name" jdbcType="VARCHAR" property="principalName"/>
  116. <result column="stock_property" jdbcType="VARCHAR" property="stockProperty"/>
  117. <result column="third_stock_type" jdbcType="VARCHAR" property="thirdStockType"/>
  118. <result column="document_status" jdbcType="VARCHAR" property="documentStatus"/>
  119. <result column="allow_minus_qty" jdbcType="VARCHAR" property="allowMinusQty"/>
  120. <result column="open_location" jdbcType="VARCHAR" property="openLocation"/>
  121. <result column="not_exp_qty" jdbcType="VARCHAR" property="notExpQty"/>
  122. <result column="available_alert" jdbcType="VARCHAR" property="availableAlert"/>
  123. <result column="create_org_name" jdbcType="VARCHAR" property="createOrgName"/>
  124. <result column="supplier_name" jdbcType="VARCHAR" property="supplierName"/>
  125. <result column="customer_name" jdbcType="VARCHAR" property="customerName"/>
  126. <result column="address" jdbcType="VARCHAR" property="address"/>
  127. <result column="tel" jdbcType="VARCHAR" property="tel"/>
  128. <result column="description" jdbcType="VARCHAR" property="description"/>
  129. <result column="group_name" jdbcType="VARCHAR" property="groupName"/>
  130. <result column="gys_stock" jdbcType="VARCHAR" property="gysStock"/>
  131. <result column="gys_stock_number" jdbcType="VARCHAR" property="gysStockNumber"/>
  132. <result column="third_stock_no" jdbcType="VARCHAR" property="thirdStockNo"/>
  133. <result column="stock_status_type" jdbcType="VARCHAR" property="stockStatusType"/>
  134. <result column="def_stock_status_name" jdbcType="VARCHAR" property="defStockStatusName"/>
  135. <result column="def_receive_status_name" jdbcType="VARCHAR" property="defReceiveStatusName"/>
  136. <result column="allow_mrp_plan" jdbcType="VARCHAR" property="allowMrpPlan"/>
  137. <result column="allow_lock" jdbcType="VARCHAR" property="allowLock"/>
  138. <result column="available_picking" jdbcType="VARCHAR" property="availablePicking"/>
  139. <result column="sorting_priority" jdbcType="VARCHAR" property="sortingPriority"/>
  140. <result column="locList_formatter" jdbcType="VARCHAR" property="loclistFormatter"/>
  141. <result column="Inquire" jdbcType="TINYINT" property="inquire"/>
  142. </collection>
  143. </resultMap>
  144. <select id="listStock" resultMap="sockPosition">
  145. SELECT
  146. sc.*
  147. FROM
  148. stock_correspond sc
  149. LEFT JOIN stock_correspond_position scp ON sc.id = scp.correspond_id
  150. LEFT JOIN king_dee_stock kds ON scp.stock_id = kds.id
  151. left join admin_user_stock aus on sc.id = aus.correspond_id
  152. where 1=1
  153. <if test="name != null and name != ''">
  154. and sc.name like CONCAT('%', #{name},'%')
  155. </if>
  156. <if test="stockName != null and stockName != ''">
  157. and kds.name like CONCAT('%', #{stockName},'%')
  158. </if>
  159. <if test="adminUserId != null and adminUserId != ''">
  160. and aus.admin_user_id = #{adminUserId}
  161. </if>
  162. <if test="type != null and type != ''">
  163. and sc.type = #{type}
  164. </if>
  165. group by sc.id
  166. order by sc.create_time desc
  167. </select>
  168. <select id="stocks" resultType="com.zfire.mall.manager.plus.entity.KingDeeStock">
  169. SELECT
  170. kds.*
  171. FROM
  172. stock_correspond sc
  173. LEFT JOIN stock_correspond_position scp ON sc.id = scp.correspond_id
  174. LEFT JOIN king_dee_stock kds ON scp.stock_id = kds.id
  175. where sc.id=#{id}
  176. </select>
  177. <select id="resverdNumber" resultType="Integer">
  178. SELECT
  179. IFNULL(SUM(roi.reserved_num),0)
  180. FROM
  181. reserved_order_item roi
  182. where roi.material_id = #{materialId}
  183. and roi.`status` = 1
  184. <if test="orderId != null and orderId != ''">
  185. and (roi.order_id != #{orderId} or roi.order_id is null)
  186. </if>
  187. and (roi.customer_id != #{customerId})
  188. <if test="correspondId == null">
  189. and roi.correspond_id = null
  190. </if>
  191. <if test="correspondId != null and correspondId != ''">
  192. and roi.correspond_id =#{correspondId}
  193. </if>
  194. </select>
  195. <select id="resverdCustomerNumber" resultType="Integer">
  196. SELECT
  197. IFNULL(SUM(roi.reserved_num),0)
  198. FROM
  199. reserved_order_item roi
  200. where roi.material_id = #{materialId}
  201. and roi.`status` = 1
  202. <if test="orderId != null and orderId != ''">
  203. and (roi.order_id != #{orderId} and roi.order_id is not null)
  204. </if>
  205. and (roi.customer_id = #{customerId})
  206. <if test="correspondId == null">
  207. and roi.correspond_id = null
  208. </if>
  209. <if test="correspondId != null and correspondId != ''">
  210. and roi.correspond_id =#{correspondId}
  211. </if>
  212. </select>
  213. <select id="resverdCustomerNumberRe" resultType="Integer">
  214. SELECT
  215. IFNULL(SUM(roi.reserved_num),0)
  216. FROM
  217. reserved_order_item roi
  218. where roi.material_id = #{materialId}
  219. and roi.`status` = 1
  220. <if test="orderId != null and orderId != ''">
  221. and (roi.order_id = #{orderId})
  222. </if>
  223. and (roi.customer_id = #{customerId})
  224. <if test="correspondId == null">
  225. and roi.correspond_id = null
  226. </if>
  227. <if test="correspondId != null and correspondId != ''">
  228. and roi.correspond_id =#{correspondId}
  229. </if>
  230. </select>
  231. <select id="resverdAllStockNumber" resultType="Integer">
  232. SELECT
  233. IFNULL(SUM(roi.reserved_num),0)
  234. FROM
  235. reserved_order_item roi
  236. where roi.material_id = #{materialId}
  237. and roi.`status` = 1
  238. <if test="correspondId == null || correspondId == ''">
  239. and roi.correspond_id is null
  240. </if>
  241. <if test="correspondId != null and correspondId != ''">
  242. and roi.correspond_id =#{correspondId}
  243. </if>
  244. </select>
  245. <select id="resverdAllStockNumberRE" resultType="Integer">
  246. SELECT
  247. IFNULL(SUM(roi.reserved_num),0)
  248. FROM
  249. reserved_order_item roi
  250. where roi.material_id = #{materialId}
  251. and roi.`status` = 1
  252. <if test="correspondId != null and correspondId != ''">
  253. and roi.correspond_id =#{correspondId}
  254. </if>
  255. </select>
  256. <select id="sumKingDeeNumber" resultType="Integer">
  257. SELECT
  258. IFNULL(SUM(s.stock_qty),0)
  259. FROM
  260. stock s
  261. join stock_correspond_position scp on s.stock_id = scp.stock_id
  262. join king_dee_stock kds on scp.stock_id = kds.id
  263. where 1=1
  264. <if test="correspondId != null and correspondId != ''">
  265. and scp.correspond_id = #{correspondId}
  266. </if>
  267. <if test="correspondId == null or correspondId == ''">
  268. and kds.not_exp_qty = 0
  269. </if>
  270. and s.material_id = #{materialId}
  271. </select>
  272. <select id="stockHintUnit" resultType="Integer">
  273. SELECT
  274. ifnull(count(pms.id ), 0)
  275. FROM
  276. pick_manager_ship pms
  277. LEFT JOIN pick_manager pm ON pm.id = pms.pick_id
  278. LEFT JOIN invoice_application_order iao ON pms.invoice_order_id = iao.id
  279. where pm.correspond_id = #{correspondId}
  280. and iao.material_id = #{materialId}
  281. and pm.pick_time BETWEEN #{startOfDay} and #{endOfDay}
  282. </select>
  283. <select id="stockHintTower" resultType="Integer">
  284. SELECT
  285. ifnull(SUM(iao.refundable_qty), 0)
  286. FROM
  287. pick_manager_ship pms
  288. LEFT JOIN pick_manager pm ON pm.id = pms.pick_id
  289. LEFT JOIN invoice_application_order iao ON pms.invoice_order_id = iao.id
  290. where pm.correspond_id = #{correspondId}
  291. and iao.material_id = #{materialId}
  292. and pm.pick_time BETWEEN #{startTime} and #{endTime}
  293. </select>
  294. <select id="listStockToDay" resultType="com.zfire.mall.manager.bean.stock.StockBeanToDay">
  295. SELECT
  296. kdm.`name` as materialName,
  297. kdm.old_number as materialOldNumber,
  298. kdm.number as materialNumber,
  299. kdm.id as materialId,
  300. kdm.specification,
  301. s.stock_qty as balanceNumber,
  302. s.stock_id,
  303. sc.`name` as correspond_name,
  304. scp.correspond_id,
  305. kdm.category_name
  306. FROM
  307. stock s
  308. JOIN stock_correspond_position scp on scp.stock_id = s.stock_id
  309. JOIN king_dee_material kdm ON s.material_id = kdm.id
  310. JOIN stock_correspond sc on scp.correspond_id = sc.id
  311. left join admin_user_stock aus on scp.correspond_id = aus.correspond_id
  312. where 1=1
  313. and scp.stock_id = s.stock_id
  314. <!-- <if test="correspondId != null and correspondId!=''">
  315. and scp.correspond_id =#{correspondId}
  316. </if>-->
  317. <if test="correspondId != null and correspondId.size > 0">
  318. AND scp.correspond_id in
  319. <foreach item="item" index="index" collection="correspondId" open="(" separator=","
  320. close=")">
  321. #{item}
  322. </foreach>
  323. </if>
  324. <if test="categoryList != null and categoryList.size > 0">
  325. AND kdm.category_id in
  326. <foreach item="item" index="index" collection="categoryList" open="(" separator=","
  327. close=")">
  328. #{item}
  329. </foreach>
  330. </if>
  331. <if test="categoryId != null and categoryId.size > 0">
  332. AND kdm.category_id in
  333. <foreach item="item" index="index" collection="categoryId" open="(" separator=","
  334. close=")">
  335. #{item}
  336. </foreach>
  337. </if>
  338. <if test="materialNumber != null and materialNumber!=''">
  339. and kdm.number like concat('%',#{materialNumber},'%')
  340. </if>
  341. <if test="materialOldNumber != null and materialOldNumber!=''">
  342. and kdm.old_number like concat('%',#{materialOldNumber},'%')
  343. </if>
  344. <if test="materialName != null and materialName!=''">
  345. and kdm.name like concat('%',#{materialName},'%')
  346. </if>
  347. <!-- <if test="categoryId != null and categoryId!=''">
  348. and kdm.category_id =#{categoryId}
  349. </if>-->
  350. <if test="specification != null and specification!=''">
  351. and kdm.specification like concat('%',#{specification},'%')
  352. </if>
  353. <if test="adminUserId != null and adminUserId!=''">
  354. and aus.admin_user_id = #{adminUserId}
  355. </if>
  356. group by s.id
  357. </select>
  358. <select id="sumKingDeeNumberList" resultType="com.zfire.mall.manager.bean.stock.StockBean">
  359. SELECT
  360. s.stock_qty,
  361. s.material_id,
  362. scp.correspond_id
  363. FROM
  364. stock s
  365. join stock_correspond_position scp on s.stock_id = scp.stock_id
  366. join king_dee_stock kds on scp.stock_id = kds.id
  367. where 1=1
  368. <if test="correspondId != null and correspondId.size > 0">
  369. AND scp.correspond_id in
  370. <foreach item="item" index="index" collection="correspondId" open="(" separator=","
  371. close=")">
  372. #{item}
  373. </foreach>
  374. </if>
  375. </select>
  376. <select id="sumKingDeeNumberAdequateList" resultType="com.zfire.mall.manager.bean.stock.StockBean">
  377. SELECT
  378. s.stock_qty as stockAdequate,
  379. s.material_id,
  380. scp.correspond_id
  381. FROM
  382. stock s
  383. join stock_correspond_position scp on s.stock_id = scp.stock_id
  384. join king_dee_stock kds on scp.stock_id = kds.id
  385. where 1=1
  386. <if test="correspondId != null and correspondId.size > 0">
  387. AND scp.correspond_id in
  388. <foreach item="item" index="index" collection="correspondId" open="(" separator=","
  389. close=")">
  390. #{item}
  391. </foreach>
  392. </if>
  393. <if test="correspondId == null ">
  394. and kds.not_exp_qty = 0
  395. </if>
  396. </select>
  397. <select id="selectInvoiceCountList" resultType="com.zfire.mall.manager.bean.stock.StockBean">
  398. SELECT
  399. iao.refundable_qty as temporaryNum,
  400. iao.material_id,
  401. ia.correspond_id
  402. FROM
  403. invoice_application_order iao
  404. LEFT JOIN invoice_application ia ON iao.invoice_id = ia.id
  405. where ia.examine_status in ('SAVE','WAIT')
  406. and type != 2
  407. <if test="correspondId != null and correspondId.size > 0">
  408. AND ia.correspond_id in
  409. <foreach item="item" index="index" collection="correspondId" open="(" separator=","
  410. close=")">
  411. #{item}
  412. </foreach>
  413. </if>
  414. </select>
  415. <select id="countAllList" resultType="com.zfire.mall.manager.bean.stock.StockBean">
  416. SELECT
  417. iao.refundable_qty as num,
  418. iao.material_id,
  419. ia.correspond_id
  420. FROM
  421. sales_order ia
  422. LEFT JOIN sales_order_item iao ON ia.id = iao.sales_order_no
  423. where ia.examine_status != 'OK'
  424. and ia.type != 2
  425. <if test="correspondId != null and correspondId.size > 0">
  426. AND ia.correspond_id in
  427. <foreach item="item" index="index" collection="correspondId" open="(" separator=","
  428. close=")">
  429. #{item}
  430. </foreach>
  431. </if>
  432. </select>
  433. <select id="countReservedList" resultType="com.zfire.mall.manager.bean.stock.StockBean">
  434. SELECT
  435. roi.reserved_num as reservedNum,
  436. roi.material_id,
  437. roi.correspond_id
  438. FROM
  439. reserved_order_item roi
  440. WHERE
  441. roi.STATUS = 1
  442. <if test="correspondId != null and correspondId.size > 0">
  443. AND roi.correspond_id in
  444. <foreach item="item" index="index" collection="correspondId" open="(" separator=","
  445. close=")">
  446. #{item}
  447. </foreach>
  448. </if>
  449. </select>
  450. <select id="listCustomer" resultType="com.zfire.mall.manager.bean.stock.StockCustomerReserved">
  451. SELECT
  452. roi.customer_id,
  453. roi.customer_name,
  454. roi.customer_number,
  455. kdm.category_name,
  456. roi.material_code as materialNumber,
  457. roi.material_old_number,
  458. roi.material_id,
  459. roi.specification,
  460. roi.material_name,
  461. roi.unit,
  462. sum(roi.reserved_num) as reservedNum
  463. FROM
  464. reserved_order ro
  465. JOIN reserved_order_item roi on roi.reserved_id = ro.id
  466. join king_dee_material kdm on kdm.id = roi.material_id
  467. where roi.status = 1
  468. <if test="materialName != null and materialName!=''">
  469. and roi.material_name like concat('%',#{materialName},'%')
  470. </if>
  471. <if test="materialNumber != null and materialNumber!=''">
  472. and kdm.number like concat('%',#{materialNumber},'%')
  473. </if>
  474. <if test="customerName != null and customerName!=''">
  475. and ro.customer_name like concat('%',#{customerName},'%')
  476. </if>
  477. <if test="customerNumber != null and customerNumber!=''">
  478. and ro.customer_number like concat('%',#{customerNumber},'%')
  479. </if>
  480. <if test="categoryId != null and categoryId!=''">
  481. and kdm.category_id =#{categoryId}
  482. </if>
  483. <if test="specification != null and specification!=''">
  484. and kdm.specification like concat('%',#{specification},'%')
  485. </if>
  486. GROUP BY roi.customer_id,roi.material_id
  487. order by roi.create_time
  488. </select>
  489. <select id="listPurchaseOrderOut" resultType="com.zfire.mall.manager.bean.stock.KingDeePurchaseStockOutBean">
  490. SELECT
  491. kdpso.id,
  492. kdpso.bill_no,
  493. kdpso.f_date,
  494. kds.`name` as supplierName,
  495. kdpso.fd_document_status,
  496. kdpsoi.material_name,
  497. kdpsoi.material_number,
  498. kdm.old_number as materialOldNumber,
  499. kdm.specification,
  500. kdm.base_unit_id as unit,
  501. kdpsoi.rm_real_qty as qty,
  502. kdsc.`name` as stockName
  503. FROM
  504. king_dee_purchase_stock_out kdpso
  505. JOIN king_dee_purchase_stock_out_item kdpsoi on kdpso.id = kdpsoi.f_id
  506. join king_dee_supplier kds on kdpso.supplier_id = kds.id
  507. JOIN king_dee_material kdm on kdpsoi.material_id = kdm.id
  508. join king_dee_stock kdsc on kdsc.id = kdpsoi.stock_id
  509. join stock_correspond_position scp on kdsc.id = scp.stock_id
  510. where 1=1
  511. <if test="specification != null and specification!=''">
  512. and kdm.specification like concat('%',#{specification},'%')
  513. </if>
  514. <if test="supplierName != null and supplierName!=''">
  515. and kds.name like concat('%',#{supplierName},'%')
  516. </if>
  517. <if test="materialOldNumber != null and materialOldNumber!=''">
  518. and kdm.old_number like concat('%',#{materialOldNumber},'%')
  519. </if>
  520. <if test="materialName != null and materialName!=''">
  521. and kdpsoi.material_name like concat('%',#{materialName},'%')
  522. </if>
  523. <if test="materialNumber != null and materialNumber!=''">
  524. and kdm.number like concat('%',#{materialNumber},'%')
  525. </if>
  526. <if test="billNo != null and billNo!=''">
  527. and kdpso.bill_no like concat('%',#{billNo},'%')
  528. </if>
  529. <if test="startTime !=null and startTime !='' and endTime !=null and endTime !=''">
  530. and kdpso.f_date between #{startTime} and #{endTime}
  531. </if>
  532. <if test="correspondId != null and correspondId.size > 0">
  533. AND scp.correspond_id in
  534. <foreach item="item" index="index" collection="correspondId" open="(" separator=","
  535. close=")">
  536. #{item}
  537. </foreach>
  538. </if>
  539. order by kdpso.f_date desc
  540. </select>
  541. <select id="listOtherStockOut" resultType="com.zfire.mall.manager.bean.stock.KingDeeOtherStockOutBean">
  542. SELECT
  543. kdpso.id,
  544. kdpso.bill_no,
  545. kdpso.f_date,
  546. kdpso.fd_document_status,
  547. kdpsoi.material_name,
  548. kdpsoi.material_number,
  549. kdm.old_number as materialOldNumber,
  550. kdm.specification,
  551. kdm.base_unit_id as unit,
  552. kdpsoi.qty,
  553. kdsc.`name` as stockName
  554. FROM
  555. king_dee_other_stock_out kdpso
  556. JOIN king_dee_other_stock_out_item kdpsoi on kdpso.id = kdpsoi.f_id
  557. JOIN king_dee_material kdm on kdpsoi.material_id = kdm.id
  558. join king_dee_stock kdsc on kdsc.id = kdpsoi.stock_id
  559. join stock_correspond_position scp on kdsc.id = scp.stock_id
  560. where 1=1
  561. <if test="specification != null and specification!=''">
  562. and kdm.specification like concat('%',#{specification},'%')
  563. </if>
  564. <if test="materialOldNumber != null and materialOldNumber!=''">
  565. and kdm.old_number like concat('%',#{materialOldNumber},'%')
  566. </if>
  567. <if test="materialName != null and materialName!=''">
  568. and kdpsoi.material_name like concat('%',#{materialName},'%')
  569. </if>
  570. <if test="billNo != null and billNo!=''">
  571. and kdpso.bill_no like concat('%',#{billNo},'%')
  572. </if>
  573. <if test="materialNumber != null and materialNumber!=''">
  574. and kdm.number like concat('%',#{materialNumber},'%')
  575. </if>
  576. <if test="startTime !=null and startTime !='' and endTime !=null and endTime !=''">
  577. and kdpso.f_date between #{startTime} and #{endTime}
  578. </if>
  579. <if test="correspondId != null and correspondId.size > 0">
  580. AND scp.correspond_id in
  581. <foreach item="item" index="index" collection="correspondId" open="(" separator=","
  582. close=")">
  583. #{item}
  584. </foreach>
  585. </if>
  586. order by kdpso.f_date desc
  587. </select>
  588. <select id="listOtherStockIn" resultType="com.zfire.mall.manager.bean.stock.KingDeeOtherStockInBean">
  589. SELECT
  590. kdpso.id,
  591. kdpso.bill_no,
  592. kdpso.f_date,
  593. kdpso.fd_document_status,
  594. kdpsoi.material_name,
  595. kdpsoi.material_number,
  596. kdm.old_number as materialOldNumber,
  597. kdm.specification,
  598. kdm.base_unit_id as unit,
  599. kdpsoi.qty,
  600. kdsc.`name` as stockName
  601. FROM
  602. king_dee_other_stock_in kdpso
  603. JOIN king_dee_other_stock_in_item kdpsoi on kdpso.id = kdpsoi.f_id
  604. JOIN king_dee_material kdm on kdpsoi.material_id = kdm.id
  605. join king_dee_stock kdsc on kdsc.id = kdpsoi.stock_id
  606. join stock_correspond_position scp on kdsc.id = scp.stock_id
  607. where 1=1
  608. <if test="specification != null and specification!=''">
  609. and kdm.specification like concat('%',#{specification},'%')
  610. </if>
  611. <if test="materialOldNumber != null and materialOldNumber!=''">
  612. and kdm.old_number like concat('%',#{materialOldNumber},'%')
  613. </if>
  614. <if test="materialName != null and materialName!=''">
  615. and kdpsoi.material_name like concat('%',#{materialName},'%')
  616. </if>
  617. <if test="materialNumber != null and materialNumber!=''">
  618. and kdm.number like concat('%',#{materialNumber},'%')
  619. </if>
  620. <if test="billNo != null and billNo!=''">
  621. and kdpso.bill_no like concat('%',#{billNo},'%')
  622. </if>
  623. <if test="startTime !=null and startTime !='' and endTime !=null and endTime !=''">
  624. and kdpso.f_date between #{startTime} and #{endTime}
  625. </if>
  626. <if test="correspondId != null and correspondId.size > 0">
  627. AND scp.correspond_id in
  628. <foreach item="item" index="index" collection="correspondId" open="(" separator=","
  629. close=")">
  630. #{item}
  631. </foreach>
  632. </if>
  633. order by kdpso.f_date desc
  634. </select>
  635. <select id="listStockToDayV2" resultType="com.zfire.mall.manager.bean.stock.StockBeanToDay">
  636. SELECT
  637. kdm.`name` as materialName,
  638. kdm.old_number as materialOldNumber,
  639. kdm.number as materialNumber,
  640. kdm.id as materialId,
  641. kdm.specification,
  642. kdm.cost_price,
  643. s.stock_qty as balanceNumber,
  644. s.stock_id,
  645. scp.correspond_id,
  646. sc.name as correspondName,
  647. kdm.category_name
  648. FROM
  649. stock s
  650. JOIN stock_correspond_position scp on scp.stock_id = s.stock_id
  651. JOIN king_dee_material kdm ON s.material_id = kdm.id
  652. JOIN stock_correspond sc on scp.correspond_id = sc.id
  653. left join admin_user_stock aus on scp.correspond_id = aus.correspond_id
  654. ${ex.query}
  655. and scp.stock_id = s.stock_id
  656. <if test="adminUserId != null and adminUserId!=''">
  657. and aus.admin_user_id = #{adminUserId}
  658. </if>
  659. group by s.id
  660. <if test="ex.orderBy == null or ex.orderBy ==''">
  661. order by s.sync_time DESC
  662. </if>
  663. ${ex.orderBy}
  664. </select>
  665. <select id="listStockToDayCustomerV2"
  666. resultType="com.zfire.mall.manager.bean.stock.StockBeanCustomerToDay">
  667. SELECT
  668. kdm.`name` as materialName,
  669. kdm.old_number as materialOldNumber,
  670. kdm.number as materialNumber,
  671. kdm.id as materialId,
  672. kdm.specification,
  673. s.stock_qty as balanceNumber,
  674. s.stock_id,
  675. scp.correspond_id,
  676. sc.name as correspondName,
  677. kdm.category_name
  678. FROM
  679. stock s
  680. JOIN stock_correspond_position scp on scp.stock_id = s.stock_id
  681. JOIN king_dee_material kdm ON s.material_id = kdm.id
  682. JOIN stock_correspond sc on scp.correspond_id = sc.id
  683. left join admin_user_stock aus on scp.correspond_id = aus.correspond_id
  684. ${ex.query}
  685. and scp.stock_id = s.stock_id
  686. <if test="adminUserId != null and adminUserId!=''">
  687. and aus.admin_user_id = #{adminUserId}
  688. </if>
  689. <if test="categoryList != null and categoryList.size > 0">
  690. AND kdm.category_id in
  691. <foreach item="item" index="index" collection="categoryList" open="(" separator=","
  692. close=")">
  693. #{item}
  694. </foreach>
  695. </if>
  696. group by s.id
  697. <if test="ex.orderBy == null or ex.orderBy ==''">
  698. order by s.sync_time DESC
  699. </if>
  700. ${ex.orderBy}
  701. </select>
  702. <select id="listPurchaseOrderOutV2"
  703. resultType="com.zfire.mall.manager.bean.stock.KingDeePurchaseStockOutVO">
  704. SELECT
  705. kdpso.id,
  706. kdpso.bill_no,
  707. kdpso.f_date as fDate,
  708. kds.`name` as supplierName,
  709. kdpso.fd_document_status,
  710. kdpsoi.material_name,
  711. kdpsoi.material_number,
  712. kdm.old_number as materialOldNumber,
  713. kdm.specification,
  714. kdm.base_unit_id as unit,
  715. kdpsoi.rm_real_qty as qty,
  716. kdsc.`name` as stockName
  717. FROM
  718. king_dee_purchase_stock_out kdpso
  719. JOIN king_dee_purchase_stock_out_item kdpsoi on kdpso.id = kdpsoi.bill_no
  720. join king_dee_supplier kds on kdpso.supplier_id = kds.id
  721. JOIN king_dee_material kdm on kdpsoi.material_id = kdm.id
  722. join king_dee_stock kdsc on kdsc.id = kdpsoi.stock_id
  723. join stock_correspond_position scp on kdsc.id = scp.stock_id
  724. ${ex.query}
  725. <if test="ex.orderBy == null or ex.orderBy ==''">
  726. order by kdpso.sync_time DESC
  727. </if>
  728. ${ex.orderBy}
  729. </select>
  730. <select id="listOtherStockOutV2" resultType="com.zfire.mall.manager.bean.stock.KingDeeOtherStockOutVO">
  731. SELECT
  732. kdpso.id,
  733. kdpso.bill_no,
  734. kdpso.f_date,
  735. kdpso.stock_direct,
  736. kdpso.cancel_status,
  737. kdpsoi.material_name,
  738. kdpsoi.material_number,
  739. kdm.old_number as materialOldNumber,
  740. kdm.specification,
  741. kdm.base_unit_id as unit,
  742. kdpsoi.qty,
  743. kdsc.`name` as stockName
  744. FROM
  745. king_dee_other_stock_out kdpso
  746. JOIN king_dee_other_stock_out_item kdpsoi on kdpso.id = kdpsoi.bill_no
  747. JOIN king_dee_material kdm on kdpsoi.material_id = kdm.id
  748. join king_dee_stock kdsc on kdsc.id = kdpsoi.stock_id
  749. join stock_correspond_position scp on kdsc.id = scp.stock_id
  750. ${ex.query}
  751. <if test="ex.orderBy == null or ex.orderBy ==''">
  752. order by kdpso.sync_time DESC
  753. </if>
  754. ${ex.orderBy}
  755. </select>
  756. <select id="listOtherStockInV2" resultType="com.zfire.mall.manager.bean.stock.KingDeeOtherStockInVO">
  757. SELECT
  758. kdpso.id,
  759. kdpso.bill_no,
  760. kdpso.f_date,
  761. kdpso.stock_direct,
  762. kdpso.cancel_status,
  763. kdpso.fd_document_status,
  764. kdpsoi.material_name,
  765. kdpsoi.material_number,
  766. kdm.old_number as materialOldNumber,
  767. kdm.specification,
  768. kdm.base_unit_id as unit,
  769. kdpsoi.qty,
  770. kdsc.`name` as stockName
  771. FROM
  772. king_dee_other_stock_in kdpso
  773. JOIN king_dee_other_stock_in_item kdpsoi on kdpso.id = kdpsoi.bill_no
  774. JOIN king_dee_material kdm on kdpsoi.material_id = kdm.id
  775. join king_dee_stock kdsc on kdsc.id = kdpsoi.stock_id
  776. join stock_correspond_position scp on kdsc.id = scp.stock_id
  777. ${ex.query}
  778. <if test="ex.orderBy == null or ex.orderBy ==''">
  779. order by kdpso.sync_time DESC
  780. </if>
  781. ${ex.orderBy}
  782. </select>
  783. <select id="listV2" resultType="com.zfire.mall.manager.bean.stock.StockVO">
  784. SELECT
  785. kdm.id as materialId,
  786. kdm.number AS materialNumber,
  787. kdm.`name` AS materialName,
  788. kdm.old_number AS materialOldNumber,
  789. kdm.specification,
  790. kdm.base_unit_id,
  791. kdm.category_name,
  792. kdm.material_group_name
  793. FROM
  794. stock s
  795. JOIN stock_correspond_position scp on scp.stock_id = s.stock_id
  796. JOIN king_dee_material kdm ON s.material_id = kdm.id
  797. JOIN stock_correspond sc on scp.correspond_id = sc.id
  798. ${ex.query}
  799. and scp.stock_id = s.stock_id
  800. group by kdm.id
  801. <if test="ex.orderBy == null or ex.orderBy ==''">
  802. order by kdm.create_time desc
  803. </if>
  804. ${ex.orderBy}
  805. </select>
  806. <select id="listCustomerV2" resultType="com.zfire.mall.manager.bean.stock.StockCustomerReserved">
  807. SELECT
  808. roi.customer_id,
  809. roi.customer_name,
  810. roi.customer_number,
  811. kdm.category_name,
  812. roi.material_code as materialNumber,
  813. roi.material_old_number,
  814. roi.material_id,
  815. roi.specification,
  816. roi.material_name,
  817. roi.unit,
  818. sum(roi.reserved_num) as reservedNum
  819. FROM
  820. reserved_order ro
  821. JOIN reserved_order_item roi on roi.reserved_id = ro.id
  822. join king_dee_material kdm on kdm.id = roi.material_id
  823. ${ex.query}
  824. and roi.status = 1
  825. GROUP BY roi.customer_id,roi.material_id
  826. <if test="ex.orderBy == null or ex.orderBy ==''">
  827. order by roi.create_time desc
  828. </if>
  829. ${ex.orderBy}
  830. </select>
  831. <select id="listOne" resultType="com.zfire.mall.manager.bean.stock.StockBean">
  832. SELECT
  833. kdm.id as materialId,
  834. kdm.number AS materialNumber,
  835. kdm.`name` AS materialName,
  836. kdm.old_number AS materialOldNumber,
  837. kdm.specification,
  838. kdm.base_unit_id,
  839. kdm.category_name,
  840. kdm.material_group_name
  841. FROM
  842. stock s
  843. JOIN stock_correspond_position scp on scp.stock_id = s.stock_id
  844. JOIN king_dee_material kdm ON s.material_id = kdm.id
  845. JOIN stock_correspond sc on scp.correspond_id = sc.id
  846. and scp.stock_id = s.stock_id
  847. <if test="correspondId != null and correspondId.size > 0">
  848. AND scp.correspond_id in
  849. <foreach item="item" index="index" collection="correspondId" open="(" separator=","
  850. close=")">
  851. #{item}
  852. </foreach>
  853. </if>
  854. and kdm.id = #{materialId}
  855. group by kdm.id
  856. </select>
  857. <select id="listStockToCostPriceV2" resultType="com.zfire.mall.manager.bean.stock.StockBeanToCostPrice">
  858. SELECT
  859. kdm.`name` as materialName,
  860. kdm.old_number as materialOldNumber,
  861. kdm.number as materialNumber,
  862. kdm.id as materialId,
  863. kdm.specification,
  864. kdm.cost_price,
  865. s.stock_qty as balanceNumber,
  866. s.stock_id,
  867. scp.correspond_id,
  868. sc.name as correspondName,
  869. kdm.category_name
  870. FROM
  871. stock s
  872. JOIN stock_correspond_position scp on scp.stock_id = s.stock_id
  873. JOIN king_dee_material kdm ON s.material_id = kdm.id
  874. JOIN stock_correspond sc on scp.correspond_id = sc.id
  875. left join admin_user_stock aus on scp.correspond_id = aus.correspond_id
  876. ${ex.query}
  877. and scp.stock_id = s.stock_id
  878. <if test="adminUserId != null and adminUserId!=''">
  879. and aus.admin_user_id = #{adminUserId}
  880. </if>
  881. group by s.id
  882. <if test="ex.orderBy == null or ex.orderBy ==''">
  883. order by s.sync_time DESC
  884. </if>
  885. ${ex.orderBy}
  886. </select>
  887. </mapper>