|
|
<?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.automatedWarehouse.mapper.WcsIntegrationMapper">
<!-- rqrq - 增强查询逻辑:支持栈板码查询,有物料则返回明细,无物料则只返回栈板 --> <select id="palletListForPartNo" resultType="WmsLabelAndPalletData"> <choose> <!-- 如果只有栈板码查询(无物料编码),只返回栈板信息,不显示物料明细 - rqrq --> <when test="palletId != null and palletId != '' and (partNo == null or partNo == '')"> SELECT DISTINCT c.site, c.pallet_id AS palletId, NULL AS partNo, NULL AS qty, NULL AS batchNo, NULL AS wdr, NULL AS expiredDate FROM pallet c WHERE c.site = #{site} AND c.pallet_id = #{palletId} AND c.is_deleted = '0' AND (c.calling_flag IS NULL OR c.calling_flag != 'Y') AND c.wcs_location IS NOT NULL </when> <!-- 如果有物料编码,返回明细数据(关联handling_unit查出qty、wdr、batch_no、expired_date)- rqrq --> <otherwise> SELECT b.site, a.pallet_id AS palletId, a.part_no AS partNo, b.qty, b.batch_no AS batchNo, b.wdr, CONVERT(VARCHAR(10), b.expired_date, 120) AS expiredDate FROM pallet_detail a INNER JOIN handling_unit b ON a.site = b.site AND a.serial_no = b.unit_id INNER JOIN pallet c ON a.site = c.site AND a.pallet_id = c.pallet_id <where> AND c.is_deleted = '0' AND (c.calling_flag IS NULL OR c.calling_flag != 'Y') AND a.site = #{site} AND (b.reserve_flag IS NULL OR b.reserve_flag != 'Y') AND b.in_stock_flag = 'Y' AND c.wcs_location IS NOT NULL <if test="warehouseId != null and warehouseId != ''"> AND b.warehouse_id = #{warehouseId} </if> <if test="partNo != null and partNo != ''"> AND a.part_no = #{partNo} </if> <if test="palletId != null and palletId != ''"> AND a.pallet_id = #{palletId} </if> <if test="serialNo != null and serialNo != ''"> AND a.serial_no = #{serialNo} </if> <if test="batchNo != null and batchNo != ''"> AND b.batch_no = #{batchNo} </if> </where> ORDER BY a.pallet_id, a.part_no </otherwise> </choose> </select>
<select id="checkPalletTask" resultType="WmsTransportTask"> select id,site,task_no,source_type,source_bill_no,source_line_id,part_no,qty,batch_no,serial_no,from_location,to_location, pallet_id,agv_code,priority,[status],wms_send_time,wcs_receive_time,start_time,complete_time,error_code,error_msg, created_by,created_time,updated_time,wcs_task_id,finish_qty,wms_status from wms_transport_task where site = #{site} and pallet_id = #{palletId} and status not in ('结束','取消','失败') </select>
<insert id="batchSaveTransportTask"> INSERT INTO wms_transport_task ( site, task_no, source_type, source_bill_no, source_line_id, part_no, qty, batch_no, serial_no, from_location, to_location, pallet_id, agv_code, priority, status, wms_send_time, error_code, error_msg, created_by, created_time, wcs_task_id, finish_qty, wms_status,item_no ) VALUES <foreach collection="list" item="item" separator=","> ( #{item.site}, #{item.taskNo}, #{item.sourceType}, #{item.sourceBillNo}, #{item.sourceLineId}, #{item.partNo}, #{item.qty}, #{item.batchNo}, #{item.serialNo}, #{item.fromLocation}, #{item.toLocation}, #{item.palletId}, #{item.agvCode}, #{item.priority}, #{item.status}, #{item.wmsSendTime}, #{item.errorCode}, #{item.errorMsg}, #{item.createdBy}, #{item.createdTime}, #{item.wcsTaskId}, #{item.finishQty}, '未执行', #{item.itemNo} ) </foreach> </insert> <insert id="batchSaveOrderTask"> INSERT INTO wms_order_task ( site, task_no, source_type, source_bill_no, source_line_id, part_no, qty, batch_no, serial_no, from_location, to_location, pallet_id, agv_code, priority, status, wms_send_time, error_code, error_msg, created_by, created_time, wcs_task_id, finish_qty, wms_status,item_no ) VALUES <foreach collection="list" item="item" separator=","> ( #{item.site}, #{item.taskNo}, #{item.sourceType}, #{item.sourceBillNo}, #{item.sourceLineId}, #{item.partNo}, #{item.qty}, #{item.batchNo}, #{item.serialNo}, #{item.fromLocation}, #{item.toLocation}, #{item.palletId}, #{item.agvCode}, #{item.priority}, #{item.status}, #{item.wmsSendTime}, #{item.errorCode}, #{item.errorMsg}, #{item.createdBy}, #{item.createdTime}, #{item.wcsTaskId}, #{item.finishQty}, #{item.wmsStatus}, #{item.itemNo} ) </foreach> </insert> <insert id="batchSaveOrderTaskDetail"> INSERT INTO wms_order_task_detail ( site,task_no,item_no,seq_no,action_type,[comment],from_location,to_location,agv_code,[status],start_time, error_code,error_msg,pallet_id,wms_status ) VALUES <foreach collection="list" item="item" separator=","> ( #{item.site}, #{item.taskNo}, #{item.itemNo}, #{item.seqNo}, #{item.actionType}, #{item.comment}, #{item.fromLocation}, #{item.toLocation}, #{item.agvCode}, #{item.status}, getdate(), #{item.errorCode}, #{item.errorMsg}, #{item.palletId}, #{item.wmsStatus} ) </foreach> </insert>
<!-- ==================== 打托相关SQL - AI制作 ==================== --> <!-- 检查栈板是否存在并获取栈板信息 - AI制作 --> <select id="getPalletInfo" resultType="java.util.Map"> SELECT pallet_id, pallet_type, status, location_code, site, calling_flag FROM pallet WHERE site = #{site} AND pallet_id = #{palletId} AND is_deleted = '0' </select> <!-- 获取栈板类型的位置信息 - AI制作 --> <select id="getPalletTypePositions" resultType="java.lang.String"> SELECT position FROM pallet_type_area WHERE site = #{site} AND pallet_type = #{palletType} ORDER BY position </select> <!-- 获取栈板明细 - AI制作 --> <select id="getPalletDetails" resultType="java.util.Map"> SELECT a.site, a.pallet_id as palletId, a.position, a.layer, a.serial_no as serialNo, a.part_no as partNo, a.create_date as createDate, a.create_by as createBy FROM pallet_detail a WHERE a.site = #{site} AND a.pallet_id = #{palletId} <if test="position != null and position != ''"> AND a.position = #{position} </if> <if test="layer != null"> AND a.layer = #{layer} </if> ORDER BY a.position, a.layer, a.serial_no </select> <select id="getPalletDetailsData" resultType="PalletDetailData"> SELECT a.site, a.pallet_id as palletId, a.position, a.layer, a.serial_no as serialNo, a.part_no as partNo, a.create_date as createDate, a.create_by as createBy,b.warehouse_id,b.location_id
FROM pallet_detail a left join handling_unit b on a.site = b.site and a.serial_no = b.unit_id WHERE a.site = #{site} AND a.pallet_id = #{palletId}
</select> <select id="getPalletTypeInfoByPallet" resultType="PalletType"> select b.site,b.pallet_type,b.type_desc,b.active,b.remark,b.pallet_family,b.wcs_pallet_type,b.wcs_base_pallet_type,b.wcs_auto_sort, b.wcs_sore_type,b.max_layer from pallet a left join pallet_type b on a.pallet_type=b.pallet_type and a.site=b.site where a.pallet_id=#{palletId} and a.site=#{site} </select> <!-- 根据位置获取层数 - AI制作 --> <select id="getLayersByPosition" resultType="java.lang.Integer"> SELECT DISTINCT layer FROM pallet_detail WHERE site = #{site} AND pallet_id = #{palletId} AND position = #{position} ORDER BY layer </select> <!-- 验证标签 - AI制作 --> <select id="validateLabel" resultType="java.util.Map"> SELECT site, unit_id as serialNo, part_no as partNo, qty, in_stock_flag as inStockFlag, unit_type as labelType, batch_no as batchNo, warehouse_id as warehouseId, location_id as locationId, remark, tid, epc FROM handling_unit WHERE site = #{site} AND unit_id = #{serialNo} </select> <!-- 获取栈板类型区域信息(用于校验层级规则) - AI制作 --> <select id="getPalletTypeAreaInfo" resultType="java.util.Map"> SELECT site, pallet_type as palletType, position, position_desc as positionDesc FROM pallet_type_area WHERE site = #{site} AND pallet_type = #{palletType} ORDER BY position </select> <!-- 获取栈板指定层的明细统计 - AI制作 --> <select id="getPalletLayerStatistics" resultType="java.util.Map"> SELECT position, COUNT(*) as count FROM pallet_detail WHERE site = #{site} AND pallet_id = #{palletId} AND layer = #{layer} GROUP BY position </select> <!-- 根据标签查找栈板信息 - AI制作 --> <select id="findPalletByLabel" resultType="java.util.Map"> SELECT pallet_id as palletId, position, layer, wcs_flag as wcsFlag, part_no as partNo, create_date as createDate, create_by as createBy FROM pallet_detail WHERE site = #{site} AND serial_no = #{serialNo} </select>
<select id="getNowStation" resultType="AgvStation"> SELECT TOP 1 b.station_code, b.location_code, b.warehouse_code FROM pallet a LEFT JOIN agv_station b ON a.location_code = b.station_code WHERE a.site = #{site} AND a.pallet_id = #{palletId} AND a.is_deleted = '0' </select> <!-- 保存栈板明细 - AI制作 --> <insert id="savePalletDetail"> INSERT INTO pallet_detail (site, pallet_id, position, layer, serial_no, part_no, create_date, create_by, wcs_flag) VALUES (#{site}, #{palletId}, #{position}, #{layer}, #{serialNo}, #{partNo}, GETDATE(), #{createBy}, 1) </insert>
<!-- rqrq - 保存栈板明细(无校验,用于自动拣选,wcs_flag可自定义) --> <insert id="savePalletDetailNoValidation"> INSERT INTO pallet_detail (site, pallet_id, position, layer, serial_no, part_no, create_date, create_by, wcs_flag) VALUES (#{site}, #{palletId}, #{position}, #{layer}, #{serialNo}, #{partNo}, GETDATE(), #{createBy}, #{wcsFlag}) </insert> <!-- 删除栈板明细 - AI制作 --> <delete id="deletePalletDetail"> DELETE FROM pallet_detail WHERE site = #{site} AND pallet_id = #{palletId} AND serial_no = #{serialNo} </delete> <!-- 根据条码删除栈板明细(不指定栈板ID) - AI制作 --> <delete id="deletePalletDetailBySerialNo"> DELETE FROM pallet_detail WHERE site = #{site} AND serial_no = #{serialNo} </delete>
<!-- 恢复标签到原栈板(分拣撤回) - rqrq --> <insert id="restorePalletDetail">
-- 恢复到原栈板,保留所有原始字段 - rqrq INSERT INTO pallet_detail (site, pallet_id, position, layer, serial_no, part_no, create_date, create_by, wcs_flag) VALUES (#{site}, #{originalPalletId}, #{originalPosition}, #{originalLayer}, #{serialNo}, #{partNo}, #{createDate}, #{createBy}, #{wcsFlag}) </insert>
<!-- 获取指定位置已占用的层数(排除指定标签) - AI制作 --> <select id="getOccupiedLayersExcludeSerial" resultType="java.lang.Integer"> SELECT DISTINCT layer FROM pallet_detail WHERE site = #{site} AND pallet_id = #{palletId} AND position = #{position} AND serial_no != #{excludeSerialNo} ORDER BY layer </select> <update id="updatePalletLocationCode" > update pallet set location_code = #{newLocationCode} where site = #{site} and pallet_id = #{palletId} </update>
<!-- 更新栈板明细位置 - AI制作 --> <update id="updatePalletDetailPosition"> UPDATE pallet_detail SET position = #{newPosition}, layer = #{newLayer}, wcs_flag = 1 WHERE site = #{site} AND pallet_id = #{palletId} AND serial_no = #{serialNo} </update>
<!-- 更新栈板调用状态 - AI制作 --> <update id="updatePalletCallingFlag"> UPDATE pallet SET calling_flag = #{callingFlag}, updated_by = #{updatedBy}, updated_time = GETDATE() WHERE site = #{site} AND pallet_id = #{palletId} </update>
<!-- 检查栈板是否正在被调用 - AI制作 --> <select id="checkPalletCallingFlag" resultType="java.lang.String"> SELECT calling_flag FROM pallet WHERE site = #{site} AND pallet_id = #{palletId} AND is_deleted = '0' </select>
<!-- 统计栈板明细数量 - AI制作 --> <select id="countPalletDetails" resultType="java.lang.Integer"> SELECT COUNT(1) FROM pallet_detail WHERE site = #{site} AND pallet_id = #{palletId} </select>
<!-- 更新栈板空栈板标记 - AI制作 --> <update id="updatePalletEmptyFlag"> UPDATE pallet SET empty_flag = #{emptyFlag}, updated_by = #{updatedBy}, updated_time = GETDATE() WHERE site = #{site} AND pallet_id = #{palletId} </update>
<!-- ==================== 运输任务相关SQL - AI制作 ==================== -->
<!-- 获取AGV站点列表 - AI制作 --> <select id="getAgvStations" resultType="java.util.Map"> SELECT station_code as stationCode, station_name as stationName, area_type as areaType, station_area as stationArea, warehouse_code as warehouseCode, location_code as locationCode, status_db as statusDb, status, station_id as stationId, station_type as stationType FROM agv_station WHERE active = 'Y' ORDER BY station_code </select>
<!-- 获取可用的AGV站点列表(按状态和类型过滤) - AI制作 --> <select id="getAvailableAgvStations" resultType="AgvStation"> SELECT id, station_code as stationCode, station_name as stationName, area_type as areaType, station_area as stationArea, warehouse_code as warehouseCode, location_code as locationCode, status_db as statusDb, status, station_id as stationId, station_type as stationType, active, remark, location_x as locationX, location_y as locationY, location_z as locationZ FROM agv_station WHERE active = 'Y' AND station_type = '正式站点' <if test="statusDb != null"> AND status_db = #{statusDb} </if> ORDER BY station_code </select>
<!-- 根据目标区域查找第一个空闲站点 - AI制作 --> <select id="findFirstFreeStationByArea" resultType="java.lang.String"> SELECT TOP 1 station_code FROM agv_station WHERE station_area = #{stationArea} AND status_db = 0 AND active = 'Y' AND station_type = '正式站点' ORDER BY station_code </select>
<!-- 根据起点站点获取可达目标站点 - AI制作 --> <!-- 注:agv_route_config表已废弃,改为返回所有激活的站点(排除起始站点) --> <select id="getTargetStationsByStart" resultType="java.util.Map"> SELECT station_code as stationCode, station_name as stationName, status_db as statusDb, status FROM agv_station WHERE active = 'Y' AND station_code != #{startStation} ORDER BY station_code </select>
<!-- 插入单个运输任务 - AI制作 --> <insert id="insertTransportTask" useGeneratedKeys="true" keyProperty="id"> INSERT INTO wms_transport_task ( site, task_no, item_no, source_type, source_bill_no, source_line_id, part_no, qty, batch_no, serial_no, from_location, to_location, to_area, pallet_id, agv_code, priority, status, wms_send_time, created_by, created_time, updated_time, wms_status, pallet_type,wcs_task_id ) VALUES ( #{site}, #{taskNo}, #{itemNo}, #{sourceType}, #{sourceBillNo}, #{sourceLineId}, #{partNo}, #{qty}, #{batchNo}, #{serialNo}, #{fromLocation}, #{toLocation}, #{toArea}, #{palletId}, #{agvCode}, #{priority}, #{status}, #{wmsSendTime}, #{createdBy}, #{createdTime}, #{updatedTime}, N'未执行', #{palletType},#{wcsTaskId} ) </insert>
<insert id="insertOrderTask" useGeneratedKeys="true" keyProperty="id"> INSERT INTO wms_order_task ( site, task_no, item_no, source_type, source_bill_no, source_line_id, part_no, qty, batch_no, serial_no, from_location, to_location, pallet_id, agv_code, priority, status, wms_send_time, created_by, created_time, updated_time,wcs_task_id ) VALUES ( #{site}, #{taskNo}, #{itemNo}, #{sourceType}, #{sourceBillNo}, #{sourceLineId}, #{partNo}, #{qty}, #{batchNo}, #{serialNo}, #{fromLocation}, #{toLocation}, #{palletId}, #{agvCode}, #{priority}, #{status}, #{wmsSendTime}, #{createdBy}, #{createdTime}, #{updatedTime},#{wcsTaskId} ) </insert>
<!-- 检查站点是否有栈板 - AI制作 --> <select id="checkStationHasPallet" resultType="java.lang.Integer"> SELECT COUNT(1) FROM pallet WHERE site = #{site} AND location_code = #{stationCode} AND is_deleted = '0' </select> <select id="getPalletDataByStation" resultType="PalletData"> SELECT TOP 1 pallet_id, location_code, status,pallet_family, pallet_type FROM pallet WHERE site = #{site} AND location_code = #{stationCode}
</select> <!-- 获取站点的栈板ID - AI制作 --> <select id="getPalletIdByStation" resultType="java.lang.String"> SELECT TOP 1 pallet_id FROM pallet WHERE site = #{site} AND location_code = #{stationCode} AND is_deleted = '0'
</select>
<!-- 根据ID查询运输任务 - AI制作 --> <select id="getTransportTaskById" resultType="WmsTransportTask"> SELECT id, site, task_no as taskNo, item_no as itemNo, source_type as sourceType, source_bill_no as sourceBillNo, source_line_id as sourceLineId, part_no as partNo, qty, batch_no as batchNo, serial_no as serialNo, from_location as fromLocation, to_location as toLocation, pallet_id as palletId, agv_code as agvCode, priority, status, wms_send_time as wmsSendTime, wcs_receive_time as wcsReceiveTime, start_time as startTime, complete_time as completeTime, error_code as errorCode, error_msg as errorMsg, created_by as createdBy, created_time as createdTime, updated_time as updatedTime, wcs_task_id as wcsTaskId, finish_qty as finishQty, wms_status as wmsStatus FROM wms_transport_task WHERE id = #{id} </select>
<!-- 根据taskNo查询运输任务 - AI制作 --> <select id="getTransportTaskByTaskNo" resultType="WmsTransportTask"> SELECT id, site, task_no as taskNo, item_no as itemNo, source_type as sourceType, source_bill_no as sourceBillNo, source_line_id as sourceLineId, part_no as partNo, qty, batch_no as batchNo, serial_no as serialNo, from_location as fromLocation, to_location as toLocation, pallet_id as palletId, agv_code as agvCode, priority, status, wms_send_time as wmsSendTime, wcs_receive_time as wcsReceiveTime, start_time as startTime, complete_time as completeTime, error_code as errorCode, error_msg as errorMsg, created_by as createdBy, created_time as createdTime, updated_time as updatedTime, wcs_task_id as wcsTaskId, finish_qty as finishQty, wms_status as wmsStatus FROM wms_transport_task WHERE task_no = #{taskNo} </select>
<!-- 更新运输任务状态 - AI制作 --> <update id="updateTransportTaskStatus"> UPDATE wms_transport_task SET status = #{status}, updated_time = GETDATE() WHERE id = #{id} </update>
<!-- 根据taskNo更新运输任务状态 - AI制作 --> <update id="updateTransportTaskStatusByTaskNo"> UPDATE wms_transport_task SET status = #{status}, updated_time = GETDATE() WHERE task_no = #{taskNo} </update>
<!-- 根据站点代码获取站点信息 - AI制作 --> <select id="getStationInfoByCode" resultType="java.util.Map"> SELECT station_code as stationCode, station_name as stationName, warehouse_code as warehouseCode, location_code as locationCode, area_type as areaType, active, status_db as statusDb, status, station_id as stationId, station_type as stationType FROM agv_station WHERE station_code = #{stationCode} </select>
<select id="getStationDataByCode" resultType="AgvStation"> SELECT station_code as stationCode, station_name as stationName, warehouse_code as warehouseCode, location_code as locationCode, area_type as areaType, active, status_db as statusDb, status, station_id as stationId, station_type as stationType FROM agv_station WHERE station_code = #{stationCode} </select>
<!-- 更新栈板明细的wcs_flag为0(已传输给WCS) - AI制作 --> <update id="updatePalletDetailWcsFlag"> UPDATE pallet_detail SET wcs_flag = 0 WHERE site = #{site} AND pallet_id = #{palletId} AND wcs_flag = 1 </update> <update id="reUpdatePalletDetailWcsFlag"> UPDATE pallet_detail SET wcs_flag = 1 WHERE site = #{site} AND pallet_id = #{palletId} AND wcs_flag = 0 </update>
<select id="getPalletDetailsNewDetail" resultType="PalletDetailData"> select a.site,a.pallet_id,a.[position],a.layer,a.serial_no,a.part_no,a.create_date,a.create_by,a.wcs_flag, b.part_desc,b.qty,b.batch_no,b.wdr,c.weight,b.length,b.width,c.height,c.is_robot_pick,um_id,b.height as realHeight ,c.is_commonly_used, CONVERT(varchar(10),isnull( isnull(b.manufacture_date,b.receive_date),getdate()), 23) manufactureDateStr from pallet_detail a left join handling_unit b on a.site=b.site and a.serial_no=b.unit_id left join part_attribute c on a.site=c.site and a.part_no=c.part_no where a.site=#{site} and a.pallet_id=#{palletId} and a.wcs_flag = 1 </select> <update id="updateSOIssueNotifyOrderMaterialListDetailOutWcsFlag"> WITH RankedRecords AS ( SELECT out_wcs_flag, ROW_NUMBER() OVER (ORDER BY notify_no DESC) AS rn FROM SOIssueNotifyOrderMaterialList_detail WHERE site = #{site} AND serialNo = #{serialNo} ) UPDATE RankedRecords SET out_wcs_flag = 'Y' WHERE rn = 1; </update> <!-- rqrq - 根据task_ref+task_item+serialNo更新SOIssueNotifyOrderMaterialList_detail的out_wcs_flag为Y --> <update id="updateSOIssueNotifyDetailOutWcsFlagByTask"> UPDATE SOIssueNotifyOrderMaterialList_detail SET out_wcs_flag = 'Y' WHERE site = #{site} AND task_ref = #{taskRef} AND task_item = #{taskItem} AND serialNo = #{serialNo} </update> <insert id="insertWmsTransportTaskDetail" > insert into wms_transport_task_detail( site,task_no,item_no,seq_no,action_type,[comment],from_location,to_location,agv_code,[status],start_time, error_code,error_msg ) values ( #{site}, #{taskNo}, #{itemNo}, #{seqNo}, #{actionType}, #{comment}, #{fromLocation}, #{toLocation}, #{agvCode}, #{status}, #{startTime}, #{errorCode}, #{errorMsg} ) </insert>
<insert id="insertWmsOrderTaskDetail" > insert into wms_order_task_detail( site,task_no,item_no,seq_no,action_type,[comment],from_location,to_location,agv_code,[status],start_time, error_code,error_msg,pallet_id,wms_status ) values ( #{site}, #{taskNo}, #{itemNo}, #{seqNo}, #{actionType}, #{comment}, #{fromLocation}, #{toLocation}, #{agvCode}, #{status}, #{startTime}, #{errorCode}, #{errorMsg},#{palletId},#{wmsStatus} ) </insert>
<select id="getMaxSeqNoForTaskDetail" resultType="Integer"> select isnull(max(seq_no),0)+1 from wms_transport_task_detail where task_no=#{taskNo} and site=#{site} and item_no= 1 </select>
<update id="updateTransportTaskStatusForSiteAndNo"> update wms_transport_task set [status]=#{status} where site=#{site} and task_no=#{taskNo} </update> <!-- rqrq - 使用status状态控制并发:先将状态改为'处理中'锁定记录 --> <update id="lockTaskDetailForProcessing"> update wms_transport_task_detail set [status]='处理中', start_time=GETDATE() where id=#{id} and status in ('已录入','处理失败','回调处理失败') </update> <!-- rqrq - 更新任务明细状态为最终状态 --> <update id="updateTransportTaskDetailStatusForId"> update wms_transport_task_detail set [status]=#{status} where id=#{id} </update> <!-- rqrq - 查询待处理的AGV回调任务明细(状态控制并发) --> <select id="getTransportTaskDetailListWithStatus" resultType="WmsTransportTaskDetail"> select id,site,task_no as taskNo,item_no as itemNo,seq_no as seqNo,action_type as actionType,[comment],from_location as fromLocation, to_location as toLocation,agv_code as agvCode,[status],start_time as startTime, error_code as errorCode,error_msg as errorMsg from wms_transport_task_detail where site = #{site} and status in ('处理失败','回调处理失败','已录入')
</select>
<!-- 查询指定状态的订单任务明细列表 - AI制作 --> <select id="getOrderTaskDetailListWithStatus" resultType="WmsOrderTaskDetail"> select id,site,task_no as taskNo,item_no as itemNo,seq_no as seqNo,action_type as actionType,[comment],from_location as fromLocation, to_location as toLocation,agv_code as agvCode,[status],start_time as startTime, error_code as errorCode,error_msg as errorMsg from wms_order_task_detail where site = #{site} and status in ('处理失败','回调处理失败','已录入') </select>
<!-- 根据ID更新订单任务明细状态 - AI制作 --> <update id="updateOrderTaskDetailStatusForId"> update wms_order_task_detail set [status]=#{status} where id=#{id} </update>
<!-- 根据任务号获取栈板ID - AI制作 --> <select id="getPalletIdByOrderTaskNo" resultType="String"> select pallet_id from wms_order_task where task_no = #{taskNo} </select>
<!-- 根据栈板号和任务类型查找订单任务 - AI制作 --> <select id="findOrderTaskByPalletAndType" resultType="WmsOrderTask"> select top 1 id, site, task_no as taskNo, item_no as itemNo, source_type as sourceType, source_bill_no as sourceBillNo, source_line_id as sourceLineId, part_no as partNo, qty, batch_no as batchNo, serial_no as serialNo, from_location as fromLocation, to_location as toLocation, pallet_id as palletId, agv_code as agvCode, priority, status, wms_send_time as wmsSendTime, wcs_receive_time as wcsReceiveTime, start_time as startTime, complete_time as completeTime, error_code as errorCode, error_msg as errorMsg, created_by as createdBy, created_time as createdTime, updated_time as updatedTime, wcs_task_id as wcsTaskId, finish_qty as finishQty, wms_status as wmsStatus from wms_order_task where site = #{site} and pallet_id = #{palletId} and source_type = #{sourceType} and status in ('已创建', '执行中', '已下发') order by created_time desc
</select>
<!-- 获取订单任务明细的最大序号 - AI制作 --> <select id="getMaxSeqNoForOrderTaskDetail" resultType="Integer"> select isnull(max(seq_no),0)+1 from wms_order_task_detail where task_no=#{taskNo} and site=#{site} </select>
<!-- 插入WCS回调任务 - AI制作 --> <insert id="insertWcsCallbackTask" useGeneratedKeys="true" keyProperty="id"> INSERT INTO wcs_callback_task ( site, pallet_id, trans_type_desc, to_warehouse_id, to_location_id, status, created_time, retry_count, remark, task_no, item_no, to_station ) VALUES ( #{site}, #{palletId}, #{transTypeDesc}, #{toWarehouseId}, #{toLocationId}, #{status}, #{createdTime}, #{retryCount}, #{remark}, #{taskNo}, #{itemNo}, #{toStation} ) </insert>
<!-- 查询指定状态的WCS回调任务列表(含超时恢复机制) - AI制作 --> <select id="getWcsCallbackTaskListWithStatus" resultType="WcsCallbackTask"> select id, site, pallet_id as palletId, trans_type_desc as transTypeDesc, to_warehouse_id as toWarehouseId, to_location_id as toLocationId, status, created_time as createdTime, process_start_time as processStartTime, process_end_time as processEndTime, error_msg as errorMsg, retry_count as retryCount, remark,task_no,item_no,to_station from wcs_callback_task where site = #{site} and ( status in ('已录入', '处理失败') or (status = '处理中' and process_start_time < DATEADD(MINUTE, -10, GETDATE())) ) and (retry_count is null or retry_count < 3) order by created_time </select>
<!-- 更新WCS回调任务状态 - AI制作 --> <update id="updateWcsCallbackTaskStatus"> update wcs_callback_task set status = #{status} <if test="processStartTime != null"> , process_start_time = #{processStartTime} </if> <if test="processEndTime != null"> , process_end_time = #{processEndTime} </if> <if test="errorMsg != null"> , error_msg = #{errorMsg} </if> where id = #{id} </update> <!-- 原子性更新WCS回调任务状态(乐观锁版本,防止重复处理) - AI制作 --> <update id="updateWcsCallbackTaskStatusWithLock"> UPDATE wcs_callback_task SET status = #{newStatus}, process_start_time = #{processStartTime} WHERE id = #{id} AND status = #{oldStatus} </update> <update id="updatePalletWcsLocation" > update pallet set wcs_location = #{location},updated_by='wms_sys',updated_time=getdate() where site = #{site} and pallet_id = #{palletId} </update>
<!-- 更新WCS回调任务重试次数 - AI制作 --> <update id="updateWcsCallbackTaskRetryCount"> update wcs_callback_task set retry_count = #{retryCount} where id = #{id} </update>
<!-- 根据栈板ID和动作类型查找订单任务 - AI制作 --> <select id="findOrderTasksByPalletAndActionType" resultType="WmsOrderTask"> select id, site, task_no as taskNo, item_no as itemNo, source_type as sourceType, source_bill_no as sourceBillNo, source_line_id as sourceLineId, part_no as partNo, qty, batch_no as batchNo, serial_no as serialNo, from_location as fromLocation, to_location as toLocation, pallet_id as palletId, agv_code as agvCode, priority, status, wms_send_time as wmsSendTime, wcs_receive_time as wcsReceiveTime, start_time as startTime, complete_time as completeTime, error_code as errorCode, error_msg as errorMsg, created_by as createdBy, created_time as createdTime, updated_time as updatedTime, wcs_task_id as wcsTaskId, finish_qty as finishQty, wms_status as wmsStatus from wms_order_task <where> and site = #{site} and pallet_id = #{palletId} <if test="sourceType != null and sourceType != ''"> and source_type = #{sourceType} </if>
and status = #{status} </where>
order by created_time desc </select> <select id="findOrderTasksByTaskNo" resultType="WmsOrderTask"> select id, site, task_no as taskNo, item_no as itemNo, source_type as sourceType, source_bill_no as sourceBillNo, source_line_id as sourceLineId, part_no as partNo, qty, batch_no as batchNo, serial_no as serialNo, from_location as fromLocation, to_location as toLocation, pallet_id as palletId, agv_code as agvCode, priority, status, wms_send_time as wmsSendTime, wcs_receive_time as wcsReceiveTime, start_time as startTime, complete_time as completeTime, error_code as errorCode, error_msg as errorMsg, created_by as createdBy, created_time as createdTime, updated_time as updatedTime, wcs_task_id as wcsTaskId, finish_qty as finishQty, wms_status as wmsStatus from wms_order_task where site = #{site} and task_no=#{taskNo} order by created_time desc </select> <select id="findOrderTasksByTaskNoItem" resultType="WmsOrderTask"> select id, site, task_no as taskNo, item_no as itemNo, source_type as sourceType, source_bill_no as sourceBillNo, source_line_id as sourceLineId, part_no as partNo, qty, batch_no as batchNo, serial_no as serialNo, from_location as fromLocation, to_location as toLocation, pallet_id as palletId, agv_code as agvCode, priority, status, wms_send_time as wmsSendTime, wcs_receive_time as wcsReceiveTime, start_time as startTime, complete_time as completeTime, error_code as errorCode, error_msg as errorMsg, created_by as createdBy, created_time as createdTime, updated_time as updatedTime, wcs_task_id as wcsTaskId, finish_qty as finishQty, wms_status as wmsStatus from wms_order_task where site = #{site} and task_no=#{taskNo} and item_no=#{itemNo} order by created_time desc </select>
<!-- 更新订单任务状态和WMS状态 - AI制作 --> <update id="updateOrderTaskStatusAndWmsStatus"> update wms_order_task set status = #{status}, wms_status = #{wmsStatus} where id = #{id} </update>
<!-- 根据任务号更新订单任务明细状态 - AI制作 --> <update id="updateOrderTaskDetailStatusByTaskNo"> update wms_order_task_detail set status = #{status} ,wms_status = #{wmsStatus} where task_no = #{taskNo} </update> <update id="updateOrderTaskDetailStatusByTaskNoPalletId"> update wms_order_task_detail set status = #{status} ,wms_status = #{wmsStatus} where task_no = #{taskNo} and site=#{site} and pallet_id=#{palletId} </update>
<!-- 查询立库调栈板出库的订单任务列表 - AI制作 --> <select id="getWcsOrderTaskListForPalletOut" resultType="WmsOrderTask"> select id, site, task_no as taskNo, item_no as itemNo, source_type as sourceType, source_bill_no as sourceBillNo, source_line_id as sourceLineId, part_no as partNo, qty, batch_no as batchNo, serial_no as serialNo, from_location as fromLocation, to_location as toLocation, pallet_id as palletId, agv_code as agvCode, priority, status, wms_send_time as wmsSendTime, wcs_receive_time as wcsReceiveTime, start_time as startTime, complete_time as completeTime, error_code as errorCode, error_msg as errorMsg, created_by as createdBy, created_time as createdTime, updated_time as updatedTime, wcs_task_id as wcsTaskId, finish_qty as finishQty, wms_status as wmsStatus from wms_order_task where site = #{site} and status = '已创建' and source_type like '%栈板出库%' and (wms_status is null or wms_status in ('未执行', '等待重试')) order by priority desc, created_time asc </select>
<!-- 更新订单任务错误信息 - AI制作 --> <update id="updateOrderTaskErrorInfo"> update wms_order_task set error_code = #{errorCode}, error_msg = #{errorMsg} where id = #{id} </update>
<!-- 更新AGV站点状态 - AI制作 --> <update id="updateAgvStationStatus"> UPDATE agv_station SET status_db = #{statusDb}, status = #{status} WHERE station_code = #{stationCode} </update> <update id="updateWTTToLocationForId"> update wms_order_task set to_location=#{toLocation} where site=#{site} and task_no=#{taskNo} </update>
<!-- 获取AGV站点状态 - AI制作 --> <select id="getAgvStationStatus" resultType="Integer"> SELECT status_db FROM agv_station WHERE station_code = #{stationCode} </select>
<select id="getAgvStationType" resultType="String"> SELECT station_type FROM agv_station WHERE station_code = #{stationCode} </select>
<!-- 获取栈板详细信息(包含palletType和autoSort以及托盘类型详情) - AI制作 --> <select id="getPalletInfoWithTypeDetails" resultType="PalletData"> SELECT p.site, p.pallet_id AS palletId, p.pallet_type AS palletType, p.pallet_family AS palletFamily, p.auto_sort AS autoSort, p.sore_type AS soreType, p.location_code AS locationCode, p.wcs_location AS wcsLocation, pt.type_desc AS typeDesc, pt.wcs_auto_sort AS wcsAutoSort, pt.wcs_pallet_type AS wcsPalletType, pt.wcs_base_pallet_type AS wcsBasePalletType, pt.wcs_sore_type AS wcsSoreType, pt.max_layer AS maxLayer, pf.pallet_family_desc AS palletFamilyDesc FROM pallet p LEFT JOIN pallet_type pt ON p.site = pt.site AND p.pallet_type = pt.pallet_type LEFT JOIN pallet_family pf ON p.site = pf.site AND p.pallet_family = pf.pallet_family WHERE p.site = #{site} AND p.pallet_id = #{palletId} AND p.is_deleted = '0' </select>
<!-- 更新栈板类型、自动分拣标志和存储类型 - AI制作/rqrq --> <update id="updatePalletTypeAndAutoSort"> UPDATE pallet SET pallet_type = #{palletType}, auto_sort = #{autoSort}, sore_type = #{soreType}, updated_time = GETDATE() WHERE site = #{site} AND pallet_id = #{palletId} AND is_deleted = '0' </update>
<!-- 获取指定层已占用的位置列表 - rqrq --> <select id="getOccupiedPositionsByLayer" resultType="java.lang.String"> SELECT DISTINCT position FROM pallet_detail WHERE site = #{site} AND pallet_id = #{palletId} AND layer = #{layer} ORDER BY position </select> <!-- rqrq - 插入WCS回调栈板扫描记录 --> <insert id="insertCallbackPalletScan" parameterType="com.gaotao.modules.automatedWarehouse.entity.WcsCallbackPalletScan" useGeneratedKeys="true" keyProperty="callback.id"> INSERT INTO wcs_callback_pallet_scan ( site, pallet_id, task_no, item_no, wcs_scan_time, wcs_barcode_list, wcs_total_quantity, sore_type, process_status, retry_count, created_at, updated_at, json_str,action_type ) VALUES ( #{callback.site}, #{callback.palletId}, #{callback.taskNo}, #{callback.itemNo}, #{callback.wcsScanTime}, #{callback.wcsBarcodeList}, #{callback.wcsTotalQuantity}, #{callback.soreType}, #{callback.processStatus}, #{callback.retryCount}, GETDATE(), GETDATE(), #{callback.jsonStr}, #{callback.actionType} ) </insert>
<select id="getPalletType" resultType="PalletType"> SELECT site, pallet_type, type_desc, active, remark, pallet_family, wcs_pallet_type, wcs_base_pallet_type, wcs_auto_sort, wcs_sore_type, max_layer FROM pallet_type WHERE site = #{site} AND pallet_type = #{palletType} </select> <select id="getAgvStation" resultType="AgvStation"> SELECT id,station_code,station_name,area_type,warehouse_code,location_x,location_y,location_z,active,location_code,remark, station_area,status_db,[status],station_id,station_type,auto_call_blank_pallet,wait_station_code FROM agv_station where station_code=#{stationCode} </select>
<!-- ==================== 栈板换站相关SQL - rqrq ==================== --> <!-- rqrq - 检查栈板calling_flag并获取当前站点信息 --> <select id="checkPalletForChangeStation" resultType="CheckPalletResult"> SELECT p.calling_flag AS callingFlag, s.station_id AS currentStationId, s.station_code AS currentStationCode FROM pallet p LEFT JOIN agv_station s ON p.location_code = s.station_code WHERE p.site = #{site} AND p.pallet_id = #{palletId} AND p.is_deleted = '0' </select> <!-- rqrq - 获取可选择的区域列表(choose_able为Y) --> <select id="getAreaOptionsForChange" resultType="Area"> SELECT area_id AS areaId, area_desc AS areaDesc, choose_able AS chooseAble FROM area WHERE choose_able = 'Y' ORDER BY area_id </select> <!-- rqrq - 根据区域获取可用站点列表 --> <select id="getStationsByArea" resultType="AgvStation"> SELECT station_id AS stationId, station_code AS stationCode, station_name AS stationName, area_type AS areaType, status_db AS statusDb, status, active FROM agv_station WHERE area_type = #{areaId} AND active = 'Y' AND station_type = '正式站点' AND status_db = 0 ORDER BY station_id </select> <!-- rqrq - 根据区域查找第一个空闲站点(用于自动分配)--> <select id="findFirstFreeStationByAreaId" resultType="java.lang.String"> SELECT TOP 1 station_code FROM agv_station WHERE area_type = #{areaId} AND active = 'Y' AND station_type = '正式站点' AND status_db = 0 ORDER BY station_id </select>
<!-- ==================== 手工移动托盘相关SQL - rqrq ==================== --> <!-- rqrq - 检查托盘是否可以手工移动 --> <select id="checkPalletForManualMove" resultType="CheckPalletResult"> SELECT p.calling_flag AS callingFlag, p.location_code AS currentStationCode, s.station_type AS stationType, s.station_id as currentStationId, CASE WHEN p.location_code IS NULL THEN 'Y' WHEN s.station_type = '正式站点' THEN 'Y' ELSE 'N' END AS canOperate FROM pallet p LEFT JOIN agv_station s ON p.location_code = s.station_code WHERE p.site = #{site} AND p.pallet_id = #{palletId} AND p.is_deleted = '0' </select> <!-- rqrq - 更新托盘location_code为null(移出站点)--> <update id="updatePalletRemoveStation"> UPDATE pallet SET location_code = NULL, updated_time = GETDATE() WHERE site = #{site} AND pallet_id = #{palletId} AND is_deleted = '0' </update> <!-- rqrq - 更新站点状态为空闲 --> <update id="updateStationToFree"> UPDATE agv_station SET status_db = 0, status = '空闲' WHERE station_code = #{stationCode} </update> <!-- rqrq - 更新托盘location_code(绑定站点)--> <update id="updatePalletBindStation"> UPDATE pallet SET location_code = #{stationCode}, updated_time = GETDATE() WHERE site = #{site} AND pallet_id = #{palletId} AND is_deleted = '0' </update> <!-- rqrq - 更新站点状态为有货 --> <update id="updateStationToOccupied"> UPDATE agv_station SET status_db = 1, status = '有货' WHERE station_code = #{stationCode} </update>
<!-- ==================== 空托盘组盘相关SQL - rqrq ==================== --> <!-- rqrq - 检查托盘是否为空托盘 --> <select id="checkEmptyPallet" resultType="CheckPalletResult"> SELECT p.pallet_id AS palletId, p.pallet_type AS palletType, p.pallet_family AS palletFamily, p.location_code AS currentStationCode, s.station_id AS currentStationId, CASE WHEN EXISTS ( SELECT 1 FROM pallet_detail pd WHERE pd.site = p.site AND pd.pallet_id = p.pallet_id ) THEN 'N' ELSE 'Y' END AS isEmpty FROM pallet p LEFT JOIN agv_station s ON p.location_code = s.station_code WHERE p.site = #{site} AND p.pallet_id = #{palletId} AND p.is_deleted = '0' </select> <!-- rqrq - 获取托盘类型列表(根据pallet_family过滤)--> <select id="getPalletTypes" resultType="PalletType"> SELECT site, pallet_type AS palletType, type_desc AS typeDesc, pallet_family AS palletFamily, max_layer AS maxLayer, wcs_auto_sort AS wcsAutoSort, wcs_pallet_type AS wcsPalletType, wcs_base_pallet_type AS wcsBasePalletType, wcs_sore_type AS wcsSoreType FROM pallet_type WHERE site = #{site} <if test="palletFamily != null and palletFamily != ''"> AND pallet_family = #{palletFamily} </if> ORDER BY pallet_type </select> <!-- rqrq - 获取需要自动续盘的站点列表 --> <select id="getAutoCallBlankPalletStations" resultType="AgvStation"> SELECT id, station_code AS stationCode, station_name AS stationName, station_type AS stationType, status_db AS statusDb, status, auto_call_blank_pallet AS autoCallBlankPallet, auto_call_blank_pallet_type AS autoCallBlankPalletType, wait_station_code AS waitStationCode FROM agv_station WHERE auto_call_blank_pallet = 'Y' AND auto_call_blank_pallet_type IS NOT NULL AND auto_call_blank_pallet_type != '' AND station_type = '正式站点' AND status_db = 0 ORDER BY station_code </select>
<!-- ==================== 取消WCS组盘相关SQL - rqrq ==================== --> <!-- rqrq - 检查栈板WCS组盘状态 --> <select id="checkPalletWcsStatus" resultType="CheckPalletResult"> SELECT p.pallet_id AS palletId, p.calling_flag AS callingFlag, CASE WHEN EXISTS ( SELECT 1 FROM pallet_detail pd WHERE pd.site = #{site} AND pd.pallet_id = #{palletId} AND pd.wcs_flag = 0 ) THEN 'Y' ELSE 'N' END AS canOperate, -- 借用canOperate字段存储hasSentWcsTask CASE WHEN EXISTS ( SELECT 1 FROM pallet_detail pd WHERE pd.site = #{site} AND pd.pallet_id = #{palletId} ) THEN 'Y' ELSE 'N' END AS isEmpty -- 借用isEmpty字段存储hasDetail FROM pallet p WHERE p.site = #{site} AND p.pallet_id = #{palletId} AND p.is_deleted = '0' </select> <!-- rqrq - 检查栈板是否有wcs_flag=0的明细 --> <select id="countPalletDetailWithWcsFlagZero" resultType="int"> SELECT COUNT(*) FROM pallet_detail WHERE site = #{site} AND pallet_id = #{palletId} AND wcs_flag = 0 </select> <!-- rqrq - 更新栈板所有明细的wcs_flag为1 --> <update id="updateAllPalletDetailWcsFlagToOne"> UPDATE pallet_detail SET wcs_flag = 1 WHERE site = #{site} AND pallet_id = #{palletId} </update> <!-- rqrq - 删除栈板所有明细 --> <delete id="deleteAllPalletDetail"> DELETE FROM pallet_detail WHERE site = #{site} AND pallet_id = #{palletId} </delete>
<select id="getStationByCode" resultType="AgvStation"> SELECT id, station_code AS stationCode, station_name AS stationName, station_type AS stationType, status_db AS statusDb, status, auto_call_blank_pallet AS autoCallBlankPallet, auto_call_blank_pallet_type AS autoCallBlankPalletType, wait_station_code AS waitStationCode FROM agv_station WHERE station_code = #{stationCode} </select>
<!-- ==================== 预约取托盘相关SQL - rqrq ==================== --> <!-- rqrq - 查询空托盘区可用的空托盘 --> <select id="findAvailableEmptyPallet" resultType="Pallet"> SELECT TOP 1 p.id, p.site, p.pallet_id AS palletId, p.pallet_type AS palletType, p.pallet_size AS palletSize, p.max_load AS maxLoad, p.status, p.location_code AS locationCode, p.remark, p.is_deleted AS isDeleted, p.created_by AS createdBy, p.created_time AS createdTime, p.updated_by AS updatedBy, p.updated_time AS updatedTime, p.calling_flag AS callingFlag, p.wcs_location AS wcsLocation, p.pallet_family AS palletFamily, p.sore_type AS soreType, p.auto_sort AS autoSort, p.empty_flag AS emptyFlag FROM pallet p INNER JOIN agv_station s ON p.location_code = s.station_code WHERE p.site = #{site} AND p.pallet_type = #{palletType} AND p.calling_flag = 'N' AND p.is_deleted = '0' AND s.area_type = 'Z101' AND s.status_db = 1 AND s.active = 'Y' ORDER BY p.created_time ASC </select> <!-- rqrq - 检查指定托盘是否就绪 --> <select id="checkPalletReady" resultType="Pallet"> SELECT p.id, p.site, p.pallet_id AS palletId, p.pallet_type AS palletType, p.pallet_size AS palletSize, p.max_load AS maxLoad, p.status, p.location_code AS locationCode, p.remark, p.is_deleted AS isDeleted, p.created_by AS createdBy, p.created_time AS createdTime, p.updated_by AS updatedBy, p.updated_time AS updatedTime, p.calling_flag AS callingFlag, p.wcs_location AS wcsLocation, p.pallet_family AS palletFamily, p.sore_type AS soreType, p.auto_sort AS autoSort, p.empty_flag AS emptyFlag FROM pallet p INNER JOIN agv_station s ON p.location_code = s.station_code WHERE p.site = #{site} AND p.pallet_id = #{palletId} AND p.calling_flag = 'N' AND p.is_deleted = '0' AND s.area_type IN ('Z101', 'Z103', 'Z104') AND s.status_db = 1 AND s.active = 'Y' </select> <!-- rqrq - 使用乐观锁更新运输任务状态 --> <update id="updateTransportTaskWithLock"> UPDATE wms_transport_task SET status = #{newStatus}, <if test="palletId != null and palletId != ''"> pallet_id = #{palletId}, </if> <if test="fromLocation != null and fromLocation != ''"> from_location = #{fromLocation}, </if> <if test="toLocation != null and toLocation != ''"> to_location = #{toLocation}, </if> wms_status = #{newWmsStatus}, updated_time = GETDATE() WHERE task_no = #{taskNo} AND (wms_status = #{oldWmsStatus} OR wms_status IS NULL) </update> <!-- rqrq - 根据栈板ID和sourceType查询最新的OrderTask --> <select id="findLatestOrderTaskByPallet" resultType="WmsOrderTask"> SELECT TOP 1 id, site, task_no AS taskNo, item_no AS itemNo, pallet_id AS palletId, source_type AS sourceType, source_bill_no AS sourceBillNo, source_line_id AS sourceLineId, part_no AS partNo, qty, batch_no AS batchNo, serial_no AS serialNo, from_location AS fromLocation, to_location AS toLocation, agv_code AS agvCode, priority, status, wms_send_time AS wmsSendTime, wcs_receive_time AS wcsReceiveTime, start_time AS startTime, complete_time AS completeTime, error_code AS errorCode, error_msg AS errorMsg, created_by AS createdBy, created_time AS createdTime, updated_time AS updatedTime, wcs_task_id AS wcsTaskId, finish_qty AS finishQty, wms_status AS wmsStatus FROM wms_order_task WHERE site = #{site} AND pallet_id = #{palletId} AND source_type = #{sourceType} ORDER BY created_time DESC </select> <!-- rqrq - 根据栈板ID更新最新的TransportTask的source_bill_no和source_line_id --> <update id="updateTransportTaskSourceInfo"> UPDATE wms_transport_task SET source_bill_no = #{sourceBillNo}, source_line_id = #{sourceLineId}, updated_time = GETDATE() WHERE id = ( SELECT TOP 1 id FROM wms_transport_task WHERE site = #{site} AND pallet_id = #{palletId} AND source_type = '预约取托盘' ORDER BY created_time DESC ) </update>
<!-- ==================== 调度发货任务相关SQL - rqrq ==================== --> <!-- rqrq - 根据栈板编码获取栈板信息 --> <select id="getPalletByCode" resultType="Pallet"> SELECT id, site, pallet_id AS palletId, pallet_type AS palletType, pallet_size AS palletSize, max_load AS maxLoad, status, location_code AS locationCode, remark, is_deleted AS isDeleted, created_by AS createdBy, created_time AS createdTime, updated_by AS updatedBy, updated_time AS updatedTime, calling_flag AS callingFlag, wcs_location AS wcsLocation, pallet_family AS palletFamily, sore_type AS soreType, auto_sort AS autoSort, empty_flag AS emptyFlag FROM pallet WHERE site = #{site} AND pallet_id = #{palletId} AND is_deleted = '0' </select> <!-- rqrq - 根据任务号和行号成对匹配查询发料明细的序列号列表 --> <select id="getSerialNosByTaskRefAndItem" resultType="String"> SELECT DISTINCT serialNo FROM SOIssueNotifyOrderMaterialList_detail WHERE site = #{site} <if test="taskNotes != null and taskNotes.size() > 0"> AND ( <foreach collection="taskNotes" item="note" separator=" OR "> (task_ref = #{note.taskNo} AND task_item = #{note.itemNo}) </foreach> ) </if> </select> <!-- rqrq - 根据序列号列表查询栈板ID列表(去重) --> <select id="getPalletIdsBySerialNos" resultType="String"> SELECT DISTINCT pallet_id FROM pallet_detail WHERE site = #{site} <if test="serialNoList != null and serialNoList.size() > 0"> AND serial_no IN <foreach collection="serialNoList" item="serialNo" open="(" close=")" separator=","> #{serialNo} </foreach> </if> </select> <!-- rqrq - 检查栈板是否在指定wcsTaskID和站点生成过运输任务 --> <select id="checkPalletTaskExists" resultType="int"> SELECT COUNT(1) FROM wms_transport_task WHERE site = #{site} AND pallet_id = #{palletId} AND source_bill_no = #{sourceBillNo} AND to_location = #{stationCode} </select> <!-- rqrq - 检查栈板是否放满(根据pallet_type_area的点位数和max_layer判断) --> <select id="checkPalletIsFull" resultType="int"> WITH PalletInfo AS ( -- 获取栈板类型和最大层数 - rqrq SELECT p.pallet_type, pt.max_layer FROM pallet p INNER JOIN pallet_type pt ON p.site = pt.site AND p.pallet_type = pt.pallet_type WHERE p.site = #{site} AND p.pallet_id = #{palletId} ), PositionCount AS ( -- 获取该类型栈板的点位数 - rqrq SELECT COUNT(1) AS position_count FROM pallet_type_area pta INNER JOIN PalletInfo pi ON pta.site = #{site} AND pta.pallet_type = pi.pallet_type ), DetailCount AS ( -- 获取栈板已使用的明细数量 - rqrq SELECT COUNT(1) AS detail_count FROM pallet_detail WHERE site = #{site} AND pallet_id = #{palletId} ), MaxCapacity AS ( -- 计算栈板最大容量 - rqrq SELECT CASE WHEN pi.max_layer IS NULL OR pi.max_layer = 0 THEN 999999 -- 混装托盘,容量无限 - rqrq ELSE pc.position_count * pi.max_layer -- 有层数托盘 = 点位数 * 最大层数 - rqrq END AS max_capacity FROM PalletInfo pi, PositionCount pc ) -- 判断是否已满(detail_count >= max_capacity 则为满)- rqrq SELECT CASE WHEN dc.detail_count >= mc.max_capacity THEN 1 ELSE 0 END AS is_full FROM DetailCount dc, MaxCapacity mc </select>
</mapper>
|