|
|
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.xujie.sys.modules.pms.mapper.InventoryStockMapper">
<!-- 可根据自己的需求,是否要使用 --> <resultMap type="com.xujie.sys.modules.pms.entity.InventoryStockEntity" id="inventoryStockMap"> <result property="site" column="site"/> <result property="warehouseId" column="warehouse_id"/> <result property="partNo" column="part_no"/> <result property="batchNo" column="batch_no"/> <result property="locationId" column="location_id"/> <result property="firstInDate" column="first_in_date"/> <result property="latestOutDate" column="latest_out_date"/> <result property="latestInDate" column="latest_in_date"/> <result property="activeDate" column="active_date"/> <result property="inQty" column="in_qty"/> <result property="outQty" column="out_qty"/> <result property="qtyOnHand" column="qty_on_hand"/> <result property="qtyReserved" column="qty_reserved"/> <result property="inStandardValue" column="in_standard_value"/> <result property="inActualValue" column="in_actual_value"/> <result property="outStandardValue" column="out_standard_value"/> <result property="outActualValue" column="out_actual_value"/> <result property="partnerId" column="partner_id"/> <result property="partnerType" column="partner_type"/> <result property="latestCountDate" column="latest_count_date"/> <result property="freezeFlag" column="freeze_flag"/> <result property="qtyTmp" column="qty_tmp"/> <result property="manuFactureDate" column="manu_facture_date"/> <result property="expiredDate" column="expired_date"/> <result property="qtyToIssue" column="qty_to_issue"/> <result property="id" column="id"/> <result property="citemCode" column="citem_code"/> <result property="qtyOfPo" column="qty_of_po"/> </resultMap> <insert id="saveCoreSparePart"> insert into core_spare_part(site,bu_no,part_no,part_desc,serial_number,status,arrival_time,remark,create_time,create_by) values(#{site},#{buNo},#{partNo},#{partDesc},#{serialNumber},#{status},#{arrivalTime},#{remark},GETDATE(),#{createBy}) </insert> <select id="countCoreSparePartBySerial" resultType="java.lang.Integer"> select count(1) from core_spare_part where site = #{site} and bu_no = #{buNo} and serial_number = #{serialNumber} </select> <delete id="deleteCoreSparePart"> delete from core_spare_part where site = #{site} and bu_no = #{buNo} and part_no = #{partNo} and serial_number = #{serialNumber} </delete>
<select id="queryPage" resultType="com.xujie.sys.modules.pms.entity.InventoryStockVoData"> SELECT a.citem_code, min(A.id) id, A.site, min(A.warehouse_id) AS warehouse_id, A.part_no,min(A.batch_no) as batch_no, min(A.location_id) AS location_id, sum(isnull(A.in_qty, 0)) AS inQty, sum(isnull(A.out_qty, 0)) AS outQty, sum(isnull(A.qty_on_hand, 0)) AS qtyOnHand, B.part_description, min(B.spec) AS spec, B.min_stock, B.max_stock, min(A.partner_id) AS partner_id, min(A.first_in_date) AS first_in_date, B.average_price, B.umid, (sum(isnull(A.qty_on_hand, 0)) * B.average_price) as totalCost, dbo.get_bu_desc(A.site, A.citem_code) buDesc, B.est_use_qty from inventory_stock A left join part_spare B on A.site = B.site and A.part_no = B.part_no and a.citem_code = b.bu_no <where> A.site in (select site from eam_access_site where username = #{query.username}) and (A.site + '-' + A.citem_code) in (select * from dbo.query_bu(#{query.username})) and A.batch_no is not null and b.part_no is not null <if test="query.buDesc != null and query.buDesc != ''"> AND dbo.get_bu_desc (a.site, a.citem_code) = #{query.buDesc} </if> <if test="query.active != null and query.active != ''"> and B.active = #{query.active} </if> <if test="query.batchNo != null and query.batchNo != ''"> and A.batch_no like '%'+#{query.batchNo}+'%' </if> <if test="query.warehouseId != null and query.warehouseId != ''"> and A.warehouse_id like '%'+#{query.warehouseId}+'%' </if> <if test="query.locationId != null and query.locationId != ''"> and A.location_id like '%'+#{query.locationId}+'%' </if> <if test="query.partNo != null and query.partNo != ''"> and A.part_no like '%'+#{query.partNo}+'%' </if> <if test="query.partDescription != null and query.partDescription != ''"> and B.part_description like '%'+#{query.partDescription}+'%' </if> <if test="query.spec != null and query.spec != '' "> and B.spec like '%'+#{query.spec}+'%' </if> <if test="query.startFirstInDate != null and query.startFirstInDate != ''"> and A.first_in_date >= #{query.startFirstInDate} </if> <if test="query.endFirstInDate != null and query.endFirstInDate != ''"> and A.first_in_date <![CDATA[<=]]> #{query.endFirstInDate} </if> <if test="query.startQtyOnHand != null "> and A.qty_on_hand >= #{query.startQtyOnHand} </if> <if test="query.endQtyOnHand !=null "> and A.qty_on_hand <![CDATA[<=]]> #{query.endQtyOnHand} </if> <if test="query.safetyStock == '安全'"> and A.qty_on_hand <![CDATA[>]]> B.min_stock </if> <if test="query.safetyStock == '不安全'"> and A.qty_on_hand <![CDATA[<=]]> B.min_stock </if> <if test="query.isZeroFlag == 1"> and A.qty_on_hand = 0 </if> <if test="query.isZeroFlag == 2"> and A.qty_on_hand != 0 </if> </where> GROUP BY <if test="query.groupType == 0"> 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 </if> <if test="query.groupType == 1"> 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 </if> </select>
<update id="updateQtyOfPoByIdOfAdd"> update inventory_stock set qty_of_po = isnull(qty_of_po,0) + #{qtyOfPo} where id = #{id} </update>
<update id="updateQtyOnHandByIdOfAdd"> 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} </update>
<update id="updateQtyOfPoByIdOfSub"> update inventory_stock set qty_of_po = isnull(qty_of_po,0) - #{qtyOfPo} where id = #{id} </update> <update id="updateCoreSparePart"> update core_spare_part set status = #{status}, arrival_time = #{arrivalTime}, remark = #{remark}, update_time = getdate(), update_by = #{updateBy} where site = #{site} and bu_no = #{buNo} and part_no = #{partNo} and serial_number = #{serialNumber}
</update>
<select id="queryPageByPo" resultType="com.xujie.sys.modules.pms.entity.InventoryStockVoData"> SELECT A.citem_code, min(A.id) as id, A.site, min(A.warehouse_id) AS warehouse_id, A.part_no,min(A.batch_no) as batch_no, min(A.location_id) AS location_id, sum(isnull( A.in_qty , 0 )) AS inQty, sum(isnull( A.out_qty , 0 )) AS outQty, sum(isnull( A.qty_on_hand , 0 )) AS qtyOnHand, B.part_description, min(B.spec) AS spec, B.min_stock, B.max_stock, min(A.partner_id) AS partner_id, min(A.first_in_date) AS first_in_date, B.average_price, B.umid, sum(isnull(A.qty_of_po,0)) as qty_of_po, (sum(isnull( A.qty_on_hand , 0 )) * B.average_price) as totalCost, dbo.get_bu_desc( A.site,A.citem_code) buDesc from inventory_stock A left join part_spare B on A.site = B.site and A.part_no = B.part_no and a.citem_code = b.bu_no <where> A.site in (select site from eam_access_site where username = #{query.username}) and (A.site + '-' + A.citem_code) in (select * from dbo.query_bu(#{query.username})) and A.batch_no is not null and b.part_no is not null <if test="query.buDesc != null and query.buDesc != ''"> AND dbo.get_bu_desc (a.site, a.citem_code) = #{query.buDesc} </if> <if test="query.active != null and query.active != ''"> and B.active = #{query.active} </if> <if test="query.buNo != null and query.buNo != ''"> and a.citem_code = #{query.buNo} </if> <if test="query.batchNo != null and query.batchNo != ''"> and A.batch_no like '%'+#{query.batchNo}+'%' </if> <if test="query.warehouseId != null and query.warehouseId != ''"> and A.warehouse_id like '%'+#{query.warehouseId}+'%' </if> <if test="query.locationId != null and query.locationId != ''"> and A.location_id like '%'+#{query.locationId}+'%' </if> <if test="query.partNo != null and query.partNo != ''"> and A.part_no like '%'+#{query.partNo}+'%' </if> <if test="query.partDescription != null and query.partDescription != ''"> and B.part_description like '%'+#{query.partDescription}+'%' </if> <if test="query.spec != null and query.spec != '' "> and B.spec like '%'+#{query.spec}+'%' </if> <if test="query.startFirstInDate != null and query.startFirstInDate != ''"> and A.first_in_date >= #{query.startFirstInDate} </if> <if test="query.endFirstInDate != null and query.endFirstInDate != ''"> and A.first_in_date <![CDATA[<=]]> #{query.endFirstInDate} </if> <if test="query.startQtyOnHand != null "> and A.qty_on_hand >= #{query.startQtyOnHand} </if> <if test="query.endQtyOnHand !=null "> and A.qty_on_hand <![CDATA[<=]]> #{query.endQtyOnHand} </if> <if test="query.safetyStock == '安全'"> and A.qty_on_hand <![CDATA[>]]> B.min_stock </if> <if test="query.isZeroFlag == 1"> and A.qty_on_hand = 0 </if> <if test="query.isZeroFlag == 2"> and A.qty_on_hand != 0 </if> </where> GROUP BY <if test="query.groupType == 0"> 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 </if> <if test="query.groupType == 1"> A.site, A.part_no, B.part_description, b.min_stock, b.max_stock, B.average_price, B.umid,a.citem_code </if> <if test="query.safetyStock == '不安全' and (query.securityMethod == '库存' or query.securityMethod == '' or query.securityMethod == null )"> having sum(A.qty_on_hand) <![CDATA[<]]> B.min_stock </if> <if test="query.safetyStock == '不安全' and query.securityMethod == '库存和在途'"> having sum(A.qty_on_hand) + sum(isnull(A.qty_of_po,0.0)) <![CDATA[<]]> B.min_stock </if> </select> <select id="getEamWorkOrderCoreComponentsList" resultType="com.xujie.sys.modules.pms.entity.EamWorkOrderCoreComponentsData"> WITH ranked_records AS ( SELECT D.OrderNo, ewc.site, ewc.bu_no, ewc.partno, ps.part_description, ewc.oldSerialNo, ewc.newSerialNo, ewc.created_date, ps.spec, ps.umid, 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, dbo.eam_Get_eamResourceDesc(d.Site, d.ObjectID) AS resourceDesc,ps.location_id,ps.est_use_qty,v.SupplierName, CASE WHEN DATEADD(year, ps.est_use_qty, ewc.created_date)> GETDATE() THEN '否' ELSE '是' END AS lifespan, ROW_NUMBER() OVER (PARTITION BY ewc.partNo ORDER BY ewc.created_date DESC) AS rn FROM eam_workOrder_coreComponents ewc LEFT JOIN part_spare ps ON ewc.site = ps.site AND ewc.bu_no = ps.bu_no AND ewc.partNo = ps.part_no LEFT JOIN eam_workOrder d ON ewc.site = d.Site AND ewc.bu_no = d.bu_no AND ewc.OrderNo = d.OrderNo LEFT JOIN resource B ON ewc.site = b.site AND d.objectid = b.resource_id LEFT JOIN view_Supplier v ON ps.site = V.Site AND ps.supplier_id = V.SupplierID WHERE ps.coreFlag = 'Y' <if test="query.site != null and query.site != ''"> and ewc.site = #{query.site} </if> <if test="query.buNo != null and query.buNo != ''"> and ewc.bu_no = #{query.buNo} </if> <if test="query.partNo != null and query.partNo != ''"> and ewc.partNo = #{query.partNo} </if> <if test="query.partDescription != null and query.partDescription != ''"> and ps.part_description like '%'+ #{query.partDescription} +'%' </if> ) SELECT OrderNo, site, bu_no, partno, part_description, oldSerialNo, newSerialNo,workTime, created_date, spec, umid, remark, created_by, fault_reason, resource_id, resourceDesc,location_id,est_use_qty,lifespan,SupplierName FROM ranked_records WHERE rn = 1; </select> <select id="getEamWorkOrderCoreComponentsList2" resultType="com.xujie.sys.modules.pms.entity.EamWorkOrderCoreComponentsData"> WITH ranked_records AS ( SELECT D.OrderNo, ewc.site, ewc.bu_no, ewc.partno, ps.part_description, ewc.oldSerialNo, ewc.newSerialNo, ewc.created_date, ps.spec, ps.umid, ps.remark, ewc.created_by, d.fault_reason, b.resource_id, dbo.eam_Get_eamResourceDesc(d.Site, d.ObjectID) AS resourceDesc,ps.location_id,ps.est_use_qty,v.SupplierName, CASE WHEN DATEADD(year, ps.est_use_qty, ewc.created_date)> GETDATE() THEN '否' ELSE '是' END AS lifespan, ROW_NUMBER() OVER (PARTITION BY ewc.partNo ORDER BY ewc.created_date DESC) AS rn FROM eam_workOrder_coreComponents ewc LEFT JOIN part_spare ps ON ewc.site = ps.site AND ewc.bu_no = ps.bu_no AND ewc.partNo = ps.part_no LEFT JOIN eam_workOrder d ON ewc.site = d.Site AND ewc.bu_no = d.bu_no AND ewc.OrderNo = d.OrderNo LEFT JOIN resource B ON ewc.site = b.site AND d.objectid = b.resource_id LEFT JOIN view_Supplier v ON ps.site = V.Site AND ps.supplier_id = V.SupplierID WHERE ps.coreFlag = 'Y' <if test="query.site != null and query.site != ''"> and ewc.site = #{query.site} </if> <if test="query.buNo != null and query.buNo != ''"> and ewc.bu_no = #{query.buNo} </if> <if test="query.partNo != null and query.partNo != ''"> and ewc.partNo = #{query.partNo} </if> <if test="query.partDescription != null and query.partDescription != ''"> and ps.part_description like '%'+ #{query.partDescription} +'%' </if> ) SELECT OrderNo, site, bu_no, partno, part_description, oldSerialNo, newSerialNo, created_date, spec, umid, remark, created_by, fault_reason, resource_id, resourceDesc, location_id, est_use_qty, lifespan, SupplierName FROM ( SELECT *, ROW_NUMBER() OVER (PARTITION BY site,bu_no,partno,oldSerialNo ORDER BY created_date ASC) AS rn2 FROM ranked_records ) AS subquery WHERE rn > 1 and rn2 = 1; </select> <select id="getEamWorkOrderCoreComponentsList3" resultType="com.xujie.sys.modules.pms.entity.EamWorkOrderCoreComponentsData"> WITH SerialStatus AS ( SELECT site, bu_no, OrderNo, partno, oldSerialNo AS serialNo, '下机' AS action, created_by, created_date FROM eam_workOrder_coreComponents WHERE oldSerialNo IS NOT NULL and site = #{query.site} AND bu_no = #{query.buNo} AND partNo = #{query.partNo} UNION ALL SELECT site, bu_no, OrderNo, partno, newSerialNo AS serialNo, '上机' AS action, created_by, created_date FROM eam_workOrder_coreComponents WHERE newSerialNo IS NOT NULL and site = #{query.site} AND bu_no = #{query.buNo} AND partNo = #{query.partNo} ), RankedSerials AS ( SELECT site, bu_no, OrderNo, partno, serialNo, action, created_by, created_date, ROW_NUMBER() OVER (PARTITION BY partno, serialNo,SerialStatus.action ORDER BY created_date) AS rn FROM SerialStatus ), TimeDifferences AS ( SELECT site, bu_no, OrderNo, partno, serialNo, action, created_by, created_date, CASE WHEN action = '上机' THEN '第' + CAST(rn AS VARCHAR) + '次上机' WHEN action = '下机' THEN '第' + CAST(rn AS VARCHAR) + '次下机' END AS status, DATEDIFF(DAY, LAG(created_date) OVER (PARTITION BY partno, serialNo ORDER BY created_date), created_date ) AS time_diff_months FROM RankedSerials ) SELECT ewc.site, ewc.bu_no, ewc.OrderNo, ewc.partno, ps.part_description, ps.est_use_qty, ewc.serialNo, ewc.action, ewc.created_by, ewc.created_date, ewc.status as onOffStatus, edf.FeedBackDesc, ewc.time_diff_months FROM TimeDifferences ewc LEFT JOIN part_spare ps ON ewc.site = ps.site AND ewc.bu_no = ps.bu_no AND ewc.partNo = ps.part_no LEFT JOIN eam_workOrder ew ON ewc.site = ew.site AND ewc.bu_no = ew.bu_no AND ewc.OrderNo = ew.OrderNo LEFT JOIN eam_defect_feedBack edf on ew.site = edf.site and ew.PlanID = edf.feedBackID and ew.bu_no = edf.bu_no WHERE ps.coreFlag = 'Y' <if test="query.serialNo != null and query.serialNo != ''"> and ewc.serialNo = #{query.serialNo} </if> ORDER BY partno, serialNo, created_date </select> <select id="getCoreSparePartList" resultType="com.xujie.sys.modules.pms.data.CoreSparePart"> select dbo.get_bu_desc(csp.site,csp.bu_no) as bu, csp.*, ps.location_id from core_spare_part csp left join part_spare ps on csp.site = ps.site and csp.bu_no = ps.bu_no and csp.part_no = ps.part_no <where> <if test="site != null and site != ''"> and csp.site = #{site} </if> <if test="buNo != null and buNo != ''"> and csp.bu_no = #{buNo} </if> <if test="partNo != null and partNo != ''"> and csp.part_no like '%' + #{partNo} + '%' </if> <if test="partDesc != null and partDesc != ''"> and csp.part_desc like '%' + #{partDesc} + '%' </if> <if test="serialNumber != null and serialNumber != ''"> and csp.serial_number like '%' + #{serialNumber} + '%' </if> <if test="status != null and status != ''"> and csp.status = #{status} </if> </where> </select></mapper>
|