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.
 
 
 
 
 
 

403 lines
20 KiB

<?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.gaotao.modules.notify.mapper.NewIssureMapper">
<insert id="saveSOIssueNotifyOrderListForExcel">
insert into SOIssueNotifyOrderList(notify_no,site,item_no,fgpart_no,soorder_no,issure_qty,out_work_order_flag,need_date,release_no,sequence_no,order_type)
values(#{notifyNo},#{site},#{itemNo},#{fgPartNo},#{soorderNo},#{issureQty,jdbcType=DECIMAL},#{outWorkOrderFlag}
,#{needDate},#{releaseNo},#{sequenceNo},#{orderType})
</insert>
<delete id="deleteSOIssueNotifyOrderMaterialListDataForExcel">
delete from SOIssueNotifyOrderMaterialList where site=#{site} and notify_no=#{notifyNo} and item_no=#{itemNo}
</delete>
<insert id="batchSaveSOIssueNotifyOrderMaterialListDataForExcel">
insert into SOIssueNotifyOrderMaterialList (notify_no,site,item_no,BOM_item_no,component_part_no,qty_to_issue,qty_to_issue_original,issue_type,remark,order_type)
values
<foreach collection="data" separator="," item="item">
(#{item.notifyNo},#{item.site},#{item.itemNo},#{item.bOMItemNo},#{item.componentPartNo},#{item.qtyToIssue,jdbcType=DECIMAL},#{item.qtyToIssueOriginal,jdbcType=DECIMAL},#{item.issueType},rtrim(#{item.remark}),#{item.orderType})
</foreach>
</insert>
<select id="getSOSBOMForIssureNew" resultType="SOIssueNotifyOrderMaterialListData">
SELECT a.notify_no, a.site, a.item_no, a.BOM_item_no AS BOMItemNo, a.component_part_no AS ComponentPartNo,
a.qty_to_issue AS QtyToIssue, a.qty_to_issue_original AS QtyToIssueOriginal, a.remark
FROM SOIssueNotifyOrderMaterialList a WITH (NOLOCK)
INNER JOIN SOIssueNotifyOrderList b WITH (NOLOCK) ON a.site=b.site AND a.notify_no=b.notify_no AND a.item_no=b.item_no
WHERE a.notify_no=#{notifyNo} AND a.site=#{site} AND b.soorder_no=#{orderNo}
AND b.release_no=#{releaseNo} AND b.sequence_no=#{sequenceNo}
</select>
<!-- AI制作 - 查询申请单主表 -->
<select id="searchNotifyHeaderNew" parameterType="SOIssueNotifyHeaderData" resultType="SOIssueNotifyHeaderData">
select a.notify_no as notifyNo,a.site,a.notify_date as notifyDate,a.username,a.entered_date as enteredDate,a.receiver,a.department_id as departmentId,a.remark,a.credit_flag as creditFlag,a.issue_flag as issueFlag,
a.issue_result as issueResult,a.plan_issue_date as planIssueDate,a.real_issue_date as realIssueDate,a.status,a.have_issue_record_flag as haveIssueRecordFlag,a.calc_flag as calcFlag,a.need_approve_flag as needApproveFlag,a.approved_flag as approvedFlag,
a.approver,a.approve_date as approveDate,a.warehouse_id as warehouseId,a.record_version as recordVersion,a.out_work_order_flag as outWorkOrderFlag,a.project_id as projectId,a.order_type as orderType,a.auth_rule_id as authRuleId,
a.confirm_status,
a.confirm_user_id AS confirmUserId, a.confirm_username AS confirmUsername, a.confirm_user_display AS confirmUserDisplay, a.confirm_date AS confirmDate, a.handler_username AS handlerUsername, a.handler_display AS handlerDisplay, a.push_wcs_flag AS pushWcsFlag
FROM SOIssueNotifyHeader a WITH (NOLOCK)
<where>
<if test="query.notifyNo != null and query.notifyNo != ''">
AND a.notify_no = #{query.notifyNo}
</if>
<if test="query.username != null and query.username != ''">
AND a.username LIKE '%' + #{query.username} + '%'
</if>
<if test="query.orderType != null and query.orderType != ''">
AND a.order_type = #{query.orderType}
</if>
<if test="query.status != null and query.status != ''">
AND a.status = #{query.status}
</if>
<if test="query.orderNo != null and query.orderNo != ''">
AND EXISTS (
SELECT 1
FROM SOIssueNotifyOrderList b WITH (NOLOCK)
WHERE b.site = a.site
AND b.notify_no = a.notify_no
AND b.soorder_no = #{query.orderNo}
)
</if>
<if test="query.startDate != null">
AND CONVERT(date, a.notify_date) >= CONVERT(date, #{query.startDate})
</if>
<if test="query.endDate != null">
AND CONVERT(date, a.notify_date) &lt; DATEADD(day, 1, CONVERT(date, #{query.endDate}))
</if>
<if test="query.site != null and query.site != ''">
AND a.site = #{query.site}
</if>
<if test="query.pushWcsFlag != null and query.pushWcsFlag != ''">
AND a.push_wcs_flag = #{query.pushWcsFlag}
</if>
and a.status!='UNISSUE'
</where>
order by a.notify_no desc
</select>
<!-- rqrq - 查询申请单明细,关联area表获取配送区域描述 -->
<select id="searchNotifyOrderListNew" resultType="SOIssueNotifyOrderListData">
select a.notify_no as notifyNo,a.site,a.item_no as itemNo,a.fgpart_no as fgPartNo,a.soorder_no as soorderNo,a.ops_item_no as opsItemNo,a.seq_no as seqNo,
a.issure_qty as issureQty,a.location_no as locationNo,a.need_date as needDate,a.out_work_order_flag as outWorkOrderFlag,a.release_no as releaseNo,a.sequence_no as sequenceNo,
a.push_wms_flag as pushWmsFlag, a.transport_flag as transportFlag, a.production_area as productionArea,
b.area_desc as areaDesc
FROM SOIssueNotifyOrderList a WITH (NOLOCK)
LEFT JOIN area b WITH (NOLOCK) ON a.production_area = b.area_id
WHERE a.notify_no=#{notifyNo} AND a.site=#{site}
ORDER BY a.item_no
</select>
<!-- AI制作 - 查询材料明细 -->
<!-- rqrq - 关联part_attribute表查询is_in_wh字段 -->
<select id="searchNotifyMaterialListNew" resultType="SOIssueNotifyOrderMaterialListData">
select a.notify_no as notifyNo,a.site,a.item_no as itemNo,a.BOM_item_no as bOMItemNo,a.component_part_no as componentPartNo,a.qty_to_issue as qtyToIssue,a.qty_to_issue_original as qtyToIssueOriginal,
b.fgpart_no as fgpartNo,b.ops_item_no as opsItemNo,b.soorder_no as soorderNo,b.seq_no as seqNo,
b.location_no AS locationNo, a.issue_type AS issueType, b.need_date AS needDate, a.remark,
ISNULL(pa.is_in_wh, '未维护') AS isInWh
FROM SOIssueNotifyOrderMaterialList a WITH (NOLOCK)
LEFT JOIN SOIssueNotifyOrderList b WITH (NOLOCK) ON a.site=b.site AND a.notify_no=b.notify_no AND a.item_no=b.item_no
LEFT JOIN part_attribute pa WITH (NOLOCK) ON a.site=pa.site AND a.component_part_no=pa.part_no
WHERE a.notify_no=#{notifyNo} AND a.site=#{site}
order by b.need_date,a.item_no
</select>
<!-- AI制作 - 查询材料汇总 -->
<!-- rqrq - 关联part_attribute表查询is_in_wh字段 -->
<select id="searchSumNotifyMaterialListNew" resultType="SOIssueNotifyOrderMaterialListData">
select a.component_part_no as componentPartNo,sum(a.qty_to_issue) as qtyToIssue,sum(isnull(a.qty_to_issue_original,0)) as qtyToIssueOriginal,
a.issue_type AS issueType,
ISNULL(MAX(pa.is_in_wh), '未维护') AS isInWh
FROM SOIssueNotifyOrderMaterialList a WITH (NOLOCK)
LEFT JOIN part_attribute pa WITH (NOLOCK) ON a.site=pa.site AND a.component_part_no=pa.part_no
WHERE a.notify_no=#{notifyNo} AND a.site=#{site}
GROUP BY a.site, a.component_part_no, a.issue_type
order by a.issue_type
</select>
<!-- AI制作 - 更新申请单状态为关闭 -->
<!-- 优化:添加 WITH (ROWLOCK) 避免锁升级导致死锁 - rqrq -->
<update id="updateNotifyStatusNew">
UPDATE SOIssueNotifyHeader WITH (ROWLOCK)
SET status = #{status}, remark = #{closeRemark}
WHERE site = #{site} AND notify_no = #{notifyNo}
</update>
<!-- AI制作 - 查询申请单日志 -->
<select id="searchNotifyLogNew" resultType="java.lang.Object">
select '暂无日志数据' as message
where 1=2
</select>
<!-- AI制作 - 查询申请单关闭日志 -->
<select id="searchNotifyLogCloseNew" resultType="java.lang.Object">
select '暂无关闭日志数据' as message
where 1=2
</select>
<!-- AI制作 - 根据site和notify_no查询申请单明细 -->
<!-- 注意:不能用NOLOCK,结果用于batchSaveOrderTask插入,脏读可能导致数据不一致 - rqrq -->
<select id="getOrderListForWcs" resultType="SOIssueNotifyOrderListData">
SELECT a.notify_no AS notifyNo, a.site, a.item_no AS itemNo, a.fgpart_no AS fgPartNo, a.soorder_no AS soorderNo, a.ops_item_no AS opsItemNo, a.seq_no AS seqNo,
a.issure_qty AS issureQty, a.location_no AS locationNo, a.need_date AS needDate, a.out_work_order_flag AS outWorkOrderFlag, a.release_no AS releaseNo, a.sequence_no AS sequenceNo
FROM SOIssueNotifyOrderList a
WHERE a.notify_no=#{notifyNo} AND a.site=#{site}
ORDER BY a.item_no
</select>
<!-- AI制作 - 根据site、notify_no和item_no查询材料明细 -->
<!-- 注意:不能用NOLOCK,结果用于构建运输任务后插入,脏读可能导致数据不一致 - rqrq -->
<select id="getMaterialListForWcs" resultType="SOIssueNotifyOrderMaterialListData">
SELECT a.notify_no AS notifyNo, a.site, a.item_no AS itemNo, a.BOM_item_no AS bomItemNo, a.component_part_no AS componentPartNo, a.qty_to_issue AS qtyToIssue, a.qty_to_issue_original AS qtyToIssueOriginal,
a.issue_type AS issueType, a.remark
FROM SOIssueNotifyOrderMaterialList a
WHERE a.notify_no=#{notifyNo} AND a.site=#{site} AND a.item_no=#{itemNo}
ORDER BY a.BOM_item_no
</select>
<!-- AI制作 - 根据site和part_no列表查询物料属性 -->
<select id="getPartAttributeListForWcs" resultType="com.gaotao.modules.factory.entity.PartAttribute">
select site, part_no as partNo, is_in_wh as isInWh, is_robot_pick as isRobotPick, weight, length, width, height, diameter
from part_attribute
where site = #{site}
<if test="partNos != null and partNos.size() > 0">
and part_no in
<foreach collection="partNos" item="partNo" open="(" separator="," close=")">
#{partNo}
</foreach>
</if>
</select>
<!-- AI制作 - 更新申请单推送WCS状态 -->
<!-- 优化:添加 WITH (ROWLOCK) 避免锁升级导致死锁 - rqrq -->
<update id="updatePushWcsFlag">
UPDATE SOIssueNotifyHeader WITH (ROWLOCK)
SET push_wcs_flag = '已完成'
WHERE site = #{site} AND notify_no = #{notifyNo}
</update>
<!-- ==================== 新增推送WCS相关SQL - rqrq ==================== -->
<!-- rqrq - 根据条码列表查询handling_unit的reserve_flag -->
<!-- 注意:不能用NOLOCK,结果用于判断是否可以预留,脏读可能导致重复预留 - rqrq -->
<select id="checkReserveFlagBySerialNos" resultType="java.lang.String">
SELECT reserve_flag
FROM handling_unit
WHERE site = #{site}
AND unit_id IN
<foreach collection="serialNos" item="serialNo" open="(" separator="," close=")">
#{serialNo}
</foreach>
AND (reserve_flag ='Y')
</select>
<!-- rqrq - 根据条码列表查询所有栈板ID -->
<!-- 注意:不能用NOLOCK,结果用于后续更新栈板calling_flag,脏读可能导致数据不一致,去重在Java层处理 - rqrq -->
<select id="getPalletIdsBySerialNos" resultType="java.lang.String">
SELECT pd.pallet_id
FROM pallet_detail pd
WHERE pd.site = #{site}
AND pd.serial_no IN
<foreach collection="serialNos" item="serialNo" open="(" separator="," close=")">
#{serialNo}
</foreach>
</select>
<!-- rqrq - 检查栈板的calling_flag(注意:不能用NOLOCK,结果用于判断后推送WCS,脏读可能导致推送已被调用的栈板)-->
<select id="checkCallingFlagByPalletIds" resultType="java.lang.String">
SELECT pallet_id
FROM pallet
WHERE site = #{site}
AND pallet_id IN
<foreach collection="palletIds" item="palletId" open="(" separator="," close=")">
#{palletId}
</foreach>
AND calling_flag = 'Y'
</select>
<!-- rqrq - 根据notifyNo和productionOrderNo查询itemNo -->
<!-- 注意:不能用NOLOCK,结果用于后续INSERT和UPDATE操作,脏读可能导致数据不一致 - rqrq -->
<select id="getItemNoByNotifyNoAndOrderNo" resultType="java.math.BigDecimal">
SELECT TOP 1 item_no
FROM SOIssueNotifyOrderList
<where>
AND site = #{site}
AND notify_no = #{notifyNo}
<if test="productionOrderNo != null and productionOrderNo != ''">
AND soorder_no = #{productionOrderNo}
</if>
</where>
</select>
<!-- 注意:不能用NOLOCK,结果可能用于构建WCS数据后操作 - rqrq -->
<select id="getFgPartNoWithNotifyNo" resultType="String">
SELECT TOP 1 fgpart_no
FROM SOIssueNotifyOrderList
<where>
AND site = #{site}
AND notify_no = #{notifyNo}
<if test="productionOrderNo != null and productionOrderNo != ''">
AND soorder_no = #{productionOrderNo}
</if>
</where>
</select>
<!-- 注意:不能用NOLOCK,结果可能用于构建WCS数据后操作 - rqrq -->
<select id="getFgPartNoWithNotifyNoItemNo" resultType="String">
SELECT TOP 1 fgpart_no
FROM SOIssueNotifyOrderList
WHERE site = #{site}
AND notify_no = #{notifyNo}
AND item_no = #{itemNo,jdbcType=DECIMAL}
</select>
<!-- rqrq - 根据site+notifyNo+itemNo查询生产区域 -->
<!-- 注意:不能用NOLOCK,结果可能用于构建WCS数据后操作 - rqrq -->
<select id="getProductionAreaByNotifyNoAndItemNo" resultType="String">
SELECT production_area
FROM SOIssueNotifyOrderList
WHERE site = #{site}
AND notify_no = #{notifyNo}
AND item_no = #{itemNo,jdbcType=DECIMAL}
</select>
<!-- rqrq - 根据site+notifyNo+itemNo查询订单类型 -->
<!-- 注意:不能用NOLOCK,结果可能用于构建WCS数据后操作 - rqrq -->
<select id="getOrderTypeByNotifyNoAndItemNo" resultType="String">
SELECT order_type
FROM SOIssueNotifyOrderList
WHERE site = #{site}
AND notify_no = #{notifyNo}
AND item_no = #{itemNo,jdbcType=DECIMAL}
</select>
<!-- rqrq - 根据site+notifyNo+itemNo查询订单行完整信息(一次性获取所有需要的字段)-->
<select id="getOrderListByNotifyNoAndItemNo" resultType="SOIssueNotifyOrderList">
SELECT notify_no AS notifyNo,
site,
item_no AS itemNo,
fgpart_no AS fgPartNo,
soorder_no AS soorderNo,
ops_item_no AS opsItemNo,
seq_no AS seqNo,
issure_qty AS issureQty,
out_work_order_flag AS outWorkOrderFlag,
need_date AS needDate,
location_no AS locationNo,
release_no AS releaseNo,
sequence_no AS sequenceNo,
push_wms_flag AS pushWmsFlag,
production_area AS productionArea,
transport_flag AS transportFlag,
order_type AS orderType
FROM SOIssueNotifyOrderList
WHERE site = #{site}
AND notify_no = #{notifyNo}
AND item_no = #{itemNo,jdbcType=DECIMAL}
</select>
<!-- rqrq - 更新handling_unit的reserve标志 -->
<!-- 优化:添加 WITH (ROWLOCK) 避免锁升级导致死锁 - rqrq -->
<update id="updateHandlingUnitReserveFlag">
UPDATE handling_unit WITH (ROWLOCK)
SET reserve_flag = 'Y',
reserve_order_ref1 = #{notifyNo},
reserve_order_ref2 = CAST(#{itemNo} AS VARCHAR(50)),
reserve_order_ref3 = #{productionOrderNo}
WHERE site = #{site}
AND unit_id IN
<foreach collection="serialNos" item="serialNo" open="(" separator="," close=")">
#{serialNo}
</foreach>
</update>
<!-- rqrq - 更新栈板的calling_flag和remark -->
<!-- 优化:添加 WITH (ROWLOCK) 避免锁升级导致死锁 - rqrq -->
<update id="updatePalletCallingFlag">
UPDATE pallet WITH (ROWLOCK)
SET calling_flag = 'Y',
remark = #{remark},
updated_by = 'WMS_SYSTEM',
updated_time = GETDATE()
WHERE site = #{site}
AND pallet_id IN
<foreach collection="palletIds" item="palletId" open="(" separator="," close=")">
#{palletId}
</foreach>
</update>
<!-- rqrq - 批量插入SOIssueNotifyOrderMaterialList_detail记录 -->
<!-- rqrq - 批量插入SOIssueNotifyOrderMaterialList_detail,固定order_type为shoporder -->
<insert id="batchInsertMaterialListDetail">
INSERT INTO SOIssueNotifyOrderMaterialList_detail
(site, notify_no, item_no, BOM_item_no, serialNo, task_ref, task_item, task_seq, out_wcs_flag, issure_flag, order_type)
VALUES
<foreach collection="list" item="item" separator=",">
(#{item.site}, #{item.notifyNo}, #{item.itemNo}, #{item.bomItemNo}, #{item.serialNo},
#{item.taskRef}, #{item.taskItem}, #{item.taskSeq}, #{item.outWcsFlag}, #{item.issureFlag}, #{item.orderType})
</foreach>
</insert>
<!-- rqrq - 更新SOIssueNotifyOrderList的push_wms_flag -->
<!-- 优化:添加 WITH (ROWLOCK) 避免锁升级导致死锁 - rqrq -->
<update id="updateOrderListPushWmsFlag">
UPDATE SOIssueNotifyOrderList WITH (ROWLOCK)
SET push_wms_flag = 'Y'
WHERE site = #{site}
AND notify_no = #{notifyNo}
AND item_no = #{itemNo}
</update>
<!-- rqrq - 更新SOIssueNotifyHeader的push_wcs_flag -->
<!-- 优化:添加 WITH (ROWLOCK) 避免锁升级导致死锁 - rqrq -->
<update id="updateNotifyHeaderPushWcsFlag">
UPDATE SOIssueNotifyHeader WITH (ROWLOCK)
SET push_wcs_flag = #{pushWcsFlag}
WHERE site = #{site}
AND notify_no = #{notifyNo}
</update>
<!-- rqrq - 根据栈板ID和序列号列表查询栈板明细信息 -->
<!-- 优化:添加 WITH (NOLOCK) 避免死锁 - rqrq -->
<select id="getPalletDetailsByPalletAndSerials" resultType="com.gaotao.modules.automatedWarehouse.entity.PalletDetail">
SELECT position, layer, serial_no as serialNo
FROM pallet_detail
WHERE site = #{site}
AND pallet_id = #{palletId}
AND serial_no IN
<foreach collection="serialNos" item="serialNo" open="(" separator="," close=")">
#{serialNo}
</foreach>
ORDER BY position, layer
</select>
<!-- rqrq - 查询序列号在handling_unit中的location_id -->
<!-- 注意:不能用NOLOCK,结果用于设置outWcsFlag后INSERT到detail表,脏读可能导致标记错误 - rqrq -->
<select id="getSerialNoLocationId" resultType="java.lang.String">
SELECT location_id
FROM handling_unit
WHERE site = #{site}
AND unit_id = #{serialNo}
</select>
<!-- rqrq - 查询预留标签清单(适用于所有订单类型:shoporder/shipment/noorder) -->
<select id="searchMaterialListDetail" resultType="com.gaotao.modules.notify.entity.SOIssueNotifyOrderMaterialListDetail">
SELECT
site,
notify_no AS notifyNo,
item_no AS itemNo,
BOM_item_no AS bomItemNo,
serialNo,
task_ref AS taskRef,
task_item AS taskItem,
task_seq AS taskSeq,
out_wcs_flag AS outWcsFlag,
issure_flag AS issureFlag,
order_type AS orderType
FROM SOIssueNotifyOrderMaterialList_detail
WHERE site = #{site}
AND notify_no = #{notifyNo}
ORDER BY item_no, BOM_item_no, task_seq
</select>
</mapper>