You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

434 lines
21 KiB

1 year ago
1 year ago
1 year ago
1 year ago
6 months ago
1 year ago
1 year ago
1 year ago
1 year ago
6 months ago
6 months ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
6 months ago
6 months ago
  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.xujie.sys.modules.pms.mapper.InventoryStockMapper">
  4. <!-- 可根据自己的需求,是否要使用 -->
  5. <resultMap type="com.xujie.sys.modules.pms.entity.InventoryStockEntity" id="inventoryStockMap">
  6. <result property="site" column="site"/>
  7. <result property="warehouseId" column="warehouse_id"/>
  8. <result property="partNo" column="part_no"/>
  9. <result property="batchNo" column="batch_no"/>
  10. <result property="locationId" column="location_id"/>
  11. <result property="firstInDate" column="first_in_date"/>
  12. <result property="latestOutDate" column="latest_out_date"/>
  13. <result property="latestInDate" column="latest_in_date"/>
  14. <result property="activeDate" column="active_date"/>
  15. <result property="inQty" column="in_qty"/>
  16. <result property="outQty" column="out_qty"/>
  17. <result property="qtyOnHand" column="qty_on_hand"/>
  18. <result property="qtyReserved" column="qty_reserved"/>
  19. <result property="inStandardValue" column="in_standard_value"/>
  20. <result property="inActualValue" column="in_actual_value"/>
  21. <result property="outStandardValue" column="out_standard_value"/>
  22. <result property="outActualValue" column="out_actual_value"/>
  23. <result property="partnerId" column="partner_id"/>
  24. <result property="partnerType" column="partner_type"/>
  25. <result property="latestCountDate" column="latest_count_date"/>
  26. <result property="freezeFlag" column="freeze_flag"/>
  27. <result property="qtyTmp" column="qty_tmp"/>
  28. <result property="manuFactureDate" column="manu_facture_date"/>
  29. <result property="expiredDate" column="expired_date"/>
  30. <result property="qtyToIssue" column="qty_to_issue"/>
  31. <result property="id" column="id"/>
  32. <result property="citemCode" column="citem_code"/>
  33. <result property="qtyOfPo" column="qty_of_po"/>
  34. </resultMap>
  35. <insert id="saveCoreSparePart">
  36. insert into core_spare_part(site,bu_no,part_no,part_desc,serial_number,status,arrival_time,remark,create_time,create_by)
  37. values(#{site},#{buNo},#{partNo},#{partDesc},#{serialNumber},#{status},#{arrivalTime},#{remark},GETDATE(),#{createBy})
  38. </insert>
  39. <select id="countCoreSparePartBySerial" resultType="java.lang.Integer">
  40. select count(1)
  41. from core_spare_part
  42. where site = #{site}
  43. and bu_no = #{buNo}
  44. and serial_number = #{serialNumber}
  45. </select>
  46. <delete id="deleteCoreSparePart">
  47. delete from core_spare_part
  48. where site = #{site} and bu_no = #{buNo} and part_no = #{partNo} and serial_number = #{serialNumber}
  49. </delete>
  50. <select id="queryPage" resultType="com.xujie.sys.modules.pms.entity.InventoryStockVoData">
  51. SELECT
  52. a.citem_code,
  53. min(A.id) id,
  54. A.site,
  55. min(A.warehouse_id) AS warehouse_id,
  56. A.part_no,min(A.batch_no) as batch_no,
  57. min(A.location_id) AS location_id,
  58. sum(isnull(A.in_qty, 0)) AS inQty,
  59. sum(isnull(A.out_qty, 0)) AS outQty,
  60. sum(isnull(A.qty_on_hand, 0)) AS qtyOnHand,
  61. B.part_description,
  62. min(B.spec) AS spec,
  63. B.min_stock,
  64. B.max_stock,
  65. min(A.partner_id) AS partner_id,
  66. min(A.first_in_date) AS first_in_date,
  67. B.average_price,
  68. B.umid,
  69. (sum(isnull(A.qty_on_hand, 0)) * B.average_price) as totalCost,
  70. dbo.get_bu_desc(A.site, A.citem_code) buDesc,
  71. B.est_use_qty
  72. from inventory_stock A
  73. left join part_spare B on A.site = B.site and A.part_no = B.part_no and a.citem_code = b.bu_no
  74. <where>
  75. A.site in (select site from eam_access_site where username = #{query.username})
  76. and (A.site + '-' + A.citem_code) in (select * from dbo.query_bu(#{query.username}))
  77. and A.batch_no is not null and b.part_no is not null
  78. <if test="query.buDesc != null and query.buDesc != ''">
  79. AND dbo.get_bu_desc (a.site, a.citem_code) = #{query.buDesc}
  80. </if>
  81. <if test="query.active != null and query.active != ''">
  82. and B.active = #{query.active}
  83. </if>
  84. <if test="query.batchNo != null and query.batchNo != ''">
  85. and A.batch_no like '%'+#{query.batchNo}+'%'
  86. </if>
  87. <if test="query.warehouseId != null and query.warehouseId != ''">
  88. and A.warehouse_id like '%'+#{query.warehouseId}+'%'
  89. </if>
  90. <if test="query.locationId != null and query.locationId != ''">
  91. and A.location_id like '%'+#{query.locationId}+'%'
  92. </if>
  93. <if test="query.partNo != null and query.partNo != ''">
  94. and A.part_no like '%'+#{query.partNo}+'%'
  95. </if>
  96. <if test="query.partDescription != null and query.partDescription != ''">
  97. and B.part_description like '%'+#{query.partDescription}+'%'
  98. </if>
  99. <if test="query.spec != null and query.spec != '' ">
  100. and B.spec like '%'+#{query.spec}+'%'
  101. </if>
  102. <if test="query.startFirstInDate != null and query.startFirstInDate != ''">
  103. and A.first_in_date >= #{query.startFirstInDate}
  104. </if>
  105. <if test="query.endFirstInDate != null and query.endFirstInDate != ''">
  106. and A.first_in_date <![CDATA[<=]]> #{query.endFirstInDate}
  107. </if>
  108. <if test="query.startQtyOnHand != null ">
  109. and A.qty_on_hand >= #{query.startQtyOnHand}
  110. </if>
  111. <if test="query.endQtyOnHand !=null ">
  112. and A.qty_on_hand <![CDATA[<=]]> #{query.endQtyOnHand}
  113. </if>
  114. <if test="query.safetyStock == '安全'">
  115. and A.qty_on_hand <![CDATA[>]]> B.min_stock
  116. </if>
  117. <if test="query.safetyStock == '不安全'">
  118. and A.qty_on_hand <![CDATA[<=]]> B.min_stock
  119. </if>
  120. <if test="query.isZeroFlag == 1">
  121. and A.qty_on_hand = 0
  122. </if>
  123. <if test="query.isZeroFlag == 2">
  124. and A.qty_on_hand != 0
  125. </if>
  126. </where>
  127. GROUP BY
  128. <if test="query.groupType == 0">
  129. A.site, A.part_no, B.part_description, A.batch_no, b.min_stock, b.max_stock, B.average_price, B.umid, a.citem_code,B.est_use_qty
  130. </if>
  131. <if test="query.groupType == 1">
  132. A.site, A.part_no, B.part_description, b.min_stock, b.max_stock, B.average_price, B.umid, a.citem_code,B.est_use_qty
  133. </if>
  134. </select>
  135. <update id="updateQtyOfPoByIdOfAdd">
  136. update inventory_stock set qty_of_po = isnull(qty_of_po,0) + #{qtyOfPo} where id = #{id}
  137. </update>
  138. <update id="updateQtyOnHandByIdOfAdd">
  139. update inventory_stock set qty_on_hand = isnull(qty_on_hand,0) + #{qtyOfPo}, qty_of_po = isnull(qty_of_po,0) - #{qtyOfPo} where id = #{id}
  140. </update>
  141. <update id="updateQtyOfPoByIdOfSub">
  142. update inventory_stock set qty_of_po = isnull(qty_of_po,0) - #{qtyOfPo} where id = #{id}
  143. </update>
  144. <update id="updateCoreSparePart">
  145. update core_spare_part
  146. set status = #{status},
  147. arrival_time = #{arrivalTime},
  148. remark = #{remark},
  149. update_time = getdate(),
  150. update_by = #{updateBy}
  151. where site = #{site} and bu_no = #{buNo} and part_no = #{partNo} and serial_number = #{serialNumber}
  152. </update>
  153. <select id="queryPageByPo" resultType="com.xujie.sys.modules.pms.entity.InventoryStockVoData">
  154. SELECT
  155. A.citem_code,
  156. min(A.id) as id,
  157. A.site,
  158. min(A.warehouse_id) AS warehouse_id,
  159. A.part_no,min(A.batch_no) as batch_no,
  160. min(A.location_id) AS location_id,
  161. sum(isnull( A.in_qty , 0 )) AS inQty,
  162. sum(isnull( A.out_qty , 0 )) AS outQty,
  163. sum(isnull( A.qty_on_hand , 0 )) AS qtyOnHand,
  164. B.part_description,
  165. min(B.spec) AS spec,
  166. B.min_stock,
  167. B.max_stock,
  168. min(A.partner_id) AS partner_id,
  169. min(A.first_in_date) AS first_in_date,
  170. B.average_price,
  171. B.umid,
  172. sum(isnull(A.qty_of_po,0)) as qty_of_po,
  173. (sum(isnull( A.qty_on_hand , 0 )) * B.average_price) as totalCost,
  174. dbo.get_bu_desc( A.site,A.citem_code) buDesc
  175. from inventory_stock A
  176. left join part_spare B on A.site = B.site and A.part_no = B.part_no and a.citem_code = b.bu_no
  177. <where>
  178. A.site in (select site from eam_access_site where username = #{query.username})
  179. and (A.site + '-' + A.citem_code) in (select * from dbo.query_bu(#{query.username}))
  180. and A.batch_no is not null and b.part_no is not null
  181. <if test="query.buDesc != null and query.buDesc != ''">
  182. AND dbo.get_bu_desc (a.site, a.citem_code) = #{query.buDesc}
  183. </if>
  184. <if test="query.active != null and query.active != ''">
  185. and B.active = #{query.active}
  186. </if>
  187. <if test="query.buNo != null and query.buNo != ''">
  188. and a.citem_code = #{query.buNo}
  189. </if>
  190. <if test="query.batchNo != null and query.batchNo != ''">
  191. and A.batch_no like '%'+#{query.batchNo}+'%'
  192. </if>
  193. <if test="query.warehouseId != null and query.warehouseId != ''">
  194. and A.warehouse_id like '%'+#{query.warehouseId}+'%'
  195. </if>
  196. <if test="query.locationId != null and query.locationId != ''">
  197. and A.location_id like '%'+#{query.locationId}+'%'
  198. </if>
  199. <if test="query.partNo != null and query.partNo != ''">
  200. and A.part_no like '%'+#{query.partNo}+'%'
  201. </if>
  202. <if test="query.partDescription != null and query.partDescription != ''">
  203. and B.part_description like '%'+#{query.partDescription}+'%'
  204. </if>
  205. <if test="query.spec != null and query.spec != '' ">
  206. and B.spec like '%'+#{query.spec}+'%'
  207. </if>
  208. <if test="query.startFirstInDate != null and query.startFirstInDate != ''">
  209. and A.first_in_date >= #{query.startFirstInDate}
  210. </if>
  211. <if test="query.endFirstInDate != null and query.endFirstInDate != ''">
  212. and A.first_in_date <![CDATA[<=]]> #{query.endFirstInDate}
  213. </if>
  214. <if test="query.startQtyOnHand != null ">
  215. and A.qty_on_hand >= #{query.startQtyOnHand}
  216. </if>
  217. <if test="query.endQtyOnHand !=null ">
  218. and A.qty_on_hand <![CDATA[<=]]> #{query.endQtyOnHand}
  219. </if>
  220. <if test="query.safetyStock == '安全'">
  221. and A.qty_on_hand <![CDATA[>]]> B.min_stock
  222. </if>
  223. <if test="query.isZeroFlag == 1">
  224. and A.qty_on_hand = 0
  225. </if>
  226. <if test="query.isZeroFlag == 2">
  227. and A.qty_on_hand != 0
  228. </if>
  229. </where>
  230. GROUP BY
  231. <if test="query.groupType == 0">
  232. A.site, A.part_no, B.part_description, A.batch_no, b.min_stock, b.max_stock, B.average_price, B.umid,a.citem_code
  233. </if>
  234. <if test="query.groupType == 1">
  235. A.site, A.part_no, B.part_description, b.min_stock, b.max_stock, B.average_price, B.umid,a.citem_code
  236. </if>
  237. <if test="query.safetyStock == '不安全' and (query.securityMethod == '库存' or query.securityMethod == '' or query.securityMethod == null )">
  238. having sum(A.qty_on_hand) <![CDATA[<]]> B.min_stock
  239. </if>
  240. <if test="query.safetyStock == '不安全' and query.securityMethod == '库存和在途'">
  241. having sum(A.qty_on_hand) + sum(isnull(A.qty_of_po,0.0)) <![CDATA[<]]> B.min_stock
  242. </if>
  243. </select>
  244. <select id="getEamWorkOrderCoreComponentsList" resultType="com.xujie.sys.modules.pms.entity.EamWorkOrderCoreComponentsData">
  245. WITH ranked_records AS (
  246. SELECT
  247. D.OrderNo, ewc.site, ewc.bu_no, ewc.partno, ps.part_description,
  248. ewc.oldSerialNo, ewc.newSerialNo, ewc.created_date, ps.spec, ps.umid,
  249. ps.remark, ewc.created_by, d.fault_reason, b.resource_id,DATEDIFF(HOUR, CAST(ewc.created_date AS DATETIME), CAST(GETDATE() AS DATETIME)) as workTime,
  250. dbo.eam_Get_eamResourceDesc(d.Site, d.ObjectID) AS resourceDesc,ps.location_id,ps.est_use_qty,v.SupplierName,
  251. CASE WHEN DATEADD(year, ps.est_use_qty, ewc.created_date)> GETDATE() THEN '否' ELSE '是' END AS lifespan,
  252. ROW_NUMBER() OVER (PARTITION BY ewc.partNo ORDER BY ewc.created_date DESC) AS rn
  253. FROM eam_workOrder_coreComponents ewc
  254. LEFT JOIN part_spare ps ON ewc.site = ps.site AND ewc.bu_no = ps.bu_no AND ewc.partNo = ps.part_no
  255. LEFT JOIN eam_workOrder d ON ewc.site = d.Site AND ewc.bu_no = d.bu_no AND ewc.OrderNo = d.OrderNo
  256. LEFT JOIN resource B ON ewc.site = b.site AND d.objectid = b.resource_id
  257. LEFT JOIN view_Supplier v ON ps.site = V.Site AND ps.supplier_id = V.SupplierID
  258. WHERE ps.coreFlag = 'Y'
  259. <if test="query.site != null and query.site != ''">
  260. and ewc.site = #{query.site}
  261. </if>
  262. <if test="query.buNo != null and query.buNo != ''">
  263. and ewc.bu_no = #{query.buNo}
  264. </if>
  265. <if test="query.partNo != null and query.partNo != ''">
  266. and ewc.partNo = #{query.partNo}
  267. </if>
  268. <if test="query.partDescription != null and query.partDescription != ''">
  269. and ps.part_description like '%'+ #{query.partDescription} +'%'
  270. </if>
  271. )
  272. SELECT OrderNo, site, bu_no, partno, part_description, oldSerialNo, newSerialNo,workTime,
  273. created_date, spec, umid, remark, created_by, fault_reason, resource_id, resourceDesc,location_id,est_use_qty,lifespan,SupplierName
  274. FROM ranked_records
  275. WHERE rn = 1;
  276. </select>
  277. <select id="getEamWorkOrderCoreComponentsList2" resultType="com.xujie.sys.modules.pms.entity.EamWorkOrderCoreComponentsData">
  278. WITH ranked_records AS (
  279. SELECT
  280. D.OrderNo, ewc.site, ewc.bu_no, ewc.partno, ps.part_description,
  281. ewc.oldSerialNo, ewc.newSerialNo, ewc.created_date, ps.spec, ps.umid,
  282. ps.remark, ewc.created_by, d.fault_reason, b.resource_id,
  283. dbo.eam_Get_eamResourceDesc(d.Site, d.ObjectID) AS resourceDesc,ps.location_id,ps.est_use_qty,v.SupplierName,
  284. CASE WHEN DATEADD(year, ps.est_use_qty, ewc.created_date)> GETDATE() THEN '否' ELSE '是' END AS lifespan,
  285. ROW_NUMBER() OVER (PARTITION BY ewc.partNo ORDER BY ewc.created_date DESC) AS rn
  286. FROM eam_workOrder_coreComponents ewc
  287. LEFT JOIN part_spare ps ON ewc.site = ps.site AND ewc.bu_no = ps.bu_no AND ewc.partNo = ps.part_no
  288. LEFT JOIN eam_workOrder d ON ewc.site = d.Site AND ewc.bu_no = d.bu_no AND ewc.OrderNo = d.OrderNo
  289. LEFT JOIN resource B ON ewc.site = b.site AND d.objectid = b.resource_id
  290. LEFT JOIN view_Supplier v ON ps.site = V.Site AND ps.supplier_id = V.SupplierID
  291. WHERE ps.coreFlag = 'Y'
  292. <if test="query.site != null and query.site != ''">
  293. and ewc.site = #{query.site}
  294. </if>
  295. <if test="query.buNo != null and query.buNo != ''">
  296. and ewc.bu_no = #{query.buNo}
  297. </if>
  298. <if test="query.partNo != null and query.partNo != ''">
  299. and ewc.partNo = #{query.partNo}
  300. </if>
  301. <if test="query.partDescription != null and query.partDescription != ''">
  302. and ps.part_description like '%'+ #{query.partDescription} +'%'
  303. </if>
  304. )
  305. SELECT
  306. OrderNo, site, bu_no, partno, part_description, oldSerialNo, newSerialNo,
  307. created_date, spec, umid, remark, created_by, fault_reason, resource_id, resourceDesc,
  308. location_id, est_use_qty, lifespan, SupplierName
  309. FROM (
  310. SELECT *,
  311. ROW_NUMBER() OVER (PARTITION BY site,bu_no,partno,oldSerialNo ORDER BY created_date ASC) AS rn2
  312. FROM ranked_records
  313. ) AS subquery
  314. WHERE rn > 1 and rn2 = 1;
  315. </select>
  316. <select id="getEamWorkOrderCoreComponentsList3" resultType="com.xujie.sys.modules.pms.entity.EamWorkOrderCoreComponentsData">
  317. WITH SerialStatus AS (
  318. SELECT
  319. site,
  320. bu_no,
  321. OrderNo,
  322. partno,
  323. oldSerialNo AS serialNo,
  324. '下机' AS action,
  325. created_by,
  326. created_date
  327. FROM eam_workOrder_coreComponents
  328. WHERE oldSerialNo IS NOT NULL and site = #{query.site} AND bu_no = #{query.buNo} AND partNo = #{query.partNo}
  329. UNION ALL
  330. SELECT
  331. site,
  332. bu_no,
  333. OrderNo,
  334. partno,
  335. newSerialNo AS serialNo,
  336. '上机' AS action,
  337. created_by,
  338. created_date
  339. FROM eam_workOrder_coreComponents
  340. WHERE newSerialNo IS NOT NULL and site = #{query.site} AND bu_no = #{query.buNo} AND partNo = #{query.partNo}
  341. ),
  342. RankedSerials AS (
  343. SELECT
  344. site,
  345. bu_no,
  346. OrderNo,
  347. partno,
  348. serialNo,
  349. action,
  350. created_by,
  351. created_date,
  352. ROW_NUMBER() OVER (PARTITION BY partno, serialNo,SerialStatus.action ORDER BY created_date) AS rn
  353. FROM SerialStatus
  354. ),
  355. TimeDifferences AS (
  356. SELECT
  357. site,
  358. bu_no,
  359. OrderNo,
  360. partno,
  361. serialNo,
  362. action,
  363. created_by,
  364. created_date,
  365. CASE
  366. WHEN action = '上机' THEN '第' + CAST(rn AS VARCHAR) + '次上机'
  367. WHEN action = '下机' THEN '第' + CAST(rn AS VARCHAR) + '次下机'
  368. END AS status,
  369. DATEDIFF(DAY,
  370. LAG(created_date) OVER (PARTITION BY partno, serialNo ORDER BY created_date),
  371. created_date
  372. ) AS time_diff_months
  373. FROM RankedSerials
  374. )
  375. SELECT
  376. ewc.site,
  377. ewc.bu_no,
  378. ewc.OrderNo,
  379. ewc.partno,
  380. ps.part_description,
  381. ps.est_use_qty,
  382. ewc.serialNo,
  383. ewc.action,
  384. ewc.created_by,
  385. ewc.created_date,
  386. ewc.status as onOffStatus,
  387. edf.FeedBackDesc,
  388. ewc.time_diff_months
  389. FROM TimeDifferences ewc
  390. LEFT JOIN part_spare ps ON ewc.site = ps.site AND ewc.bu_no = ps.bu_no AND ewc.partNo = ps.part_no
  391. LEFT JOIN eam_workOrder ew ON ewc.site = ew.site AND ewc.bu_no = ew.bu_no AND ewc.OrderNo = ew.OrderNo
  392. LEFT JOIN eam_defect_feedBack edf on ew.site = edf.site and ew.PlanID = edf.feedBackID and ew.bu_no = edf.bu_no
  393. WHERE ps.coreFlag = 'Y'
  394. <if test="query.serialNo != null and query.serialNo != ''">
  395. and ewc.serialNo = #{query.serialNo}
  396. </if>
  397. ORDER BY partno, serialNo, created_date
  398. </select>
  399. <select id="getCoreSparePartList" resultType="com.xujie.sys.modules.pms.data.CoreSparePart">
  400. select dbo.get_bu_desc(csp.site,csp.bu_no) as bu,
  401. csp.*,
  402. ps.location_id
  403. from core_spare_part csp
  404. left join part_spare ps on csp.site = ps.site and csp.bu_no = ps.bu_no and csp.part_no = ps.part_no
  405. <where>
  406. <if test="site != null and site != ''">
  407. and csp.site = #{site}
  408. </if>
  409. <if test="buNo != null and buNo != ''">
  410. and csp.bu_no = #{buNo}
  411. </if>
  412. <if test="partNo != null and partNo != ''">
  413. and csp.part_no like '%' + #{partNo} + '%'
  414. </if>
  415. <if test="partDesc != null and partDesc != ''">
  416. and csp.part_desc like '%' + #{partDesc} + '%'
  417. </if>
  418. <if test="serialNumber != null and serialNumber != ''">
  419. and csp.serial_number like '%' + #{serialNumber} + '%'
  420. </if>
  421. <if test="status != null and status != ''">
  422. and csp.status = #{status}
  423. </if>
  424. </where>
  425. </select>
  426. </mapper>