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.

704 lines
32 KiB

4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
3 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
3 months ago
4 months ago
4 months ago
3 months ago
4 months ago
3 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
3 months ago
4 months ago
3 months ago
3 months ago
3 months ago
4 months ago
4 months ago
4 months ago
4 months ago
3 months ago
3 months ago
4 months ago
4 months ago
3 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
3 months ago
4 months ago
3 months ago
4 months ago
3 months ago
4 months ago
3 months ago
4 months ago
3 months ago
4 months ago
3 months ago
4 months ago
4 months ago
3 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
3 months ago
4 months ago
4 months ago
3 months ago
4 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.gaotao.modules.automatedWarehouse.mapper.WcsIntegrationMapper">
  4. <select id="palletListForPartNo" resultType="WmsLabelAndPalletData">
  5. select b.site,a.pallet_id,b.part_no,sum(b.qty) as qty
  6. from pallet_detail a ,handling_unit b, pallet c
  7. <where>
  8. and a.site = b.site
  9. and a.serial_no = b.unit_id
  10. and a.site = c.site
  11. and a.pallet_id = c.pallet_id
  12. and c.is_deleted = '0'
  13. and (c.calling_flag IS NULL OR c.calling_flag != 'Y')
  14. and a.site = #{site}
  15. and b.reserve_flag != 'Y'
  16. and b.in_stock_flag='Y'
  17. and c.wcs_location is not null
  18. <if test="warehouseId != null and warehouseId != ''">
  19. and b.warehouse_id=#{warehouseId}
  20. </if>
  21. <if test="partNo != null and partNo != ''">
  22. and a.part_no = #{partNo}
  23. </if>
  24. <if test="serialNo != null and serialNo != ''">
  25. and a.serial_no = #{serialNo}
  26. </if>
  27. <if test="batchNo != null and batchNo != ''">
  28. and b.batch_no = #{batchNo}
  29. </if>
  30. </where>
  31. group by b.site, a.pallet_id, b.part_no
  32. </select>
  33. <select id="checkPalletTask" resultType="WmsTransportTask">
  34. select id,site,task_no,source_type,source_bill_no,source_line_id,part_no,qty,batch_no,serial_no,from_location,to_location,
  35. pallet_id,agv_code,priority,[status],wms_send_time,wcs_receive_time,start_time,complete_time,error_code,error_msg,
  36. created_by,created_time,updated_time,wcs_task_id,finish_qty,wms_status
  37. from wms_transport_task
  38. where site = #{site}
  39. and pallet_id = #{palletId}
  40. and status not in ('结束','取消','失败')
  41. </select>
  42. <insert id="batchSaveTransportTask">
  43. INSERT INTO wms_transport_task (
  44. site, task_no, source_type, source_bill_no, source_line_id, part_no, qty,
  45. batch_no, serial_no, from_location, to_location, pallet_id, agv_code,
  46. priority, status, wms_send_time,
  47. error_code, error_msg, created_by, created_time, wcs_task_id,
  48. finish_qty, wms_status,item_no
  49. ) VALUES
  50. <foreach collection="list" item="item" separator=",">
  51. (
  52. #{item.site}, #{item.taskNo}, #{item.sourceType}, #{item.sourceBillNo}, #{item.sourceLineId},
  53. #{item.partNo}, #{item.qty}, #{item.batchNo}, #{item.serialNo}, #{item.fromLocation},
  54. #{item.toLocation}, #{item.palletId}, #{item.agvCode}, #{item.priority}, #{item.status},
  55. #{item.wmsSendTime},
  56. #{item.errorCode}, #{item.errorMsg}, #{item.createdBy}, #{item.createdTime},
  57. #{item.wcsTaskId}, #{item.finishQty}, '未执行', #{item.itemNo}
  58. )
  59. </foreach>
  60. </insert>
  61. <insert id="batchSaveOrderTask">
  62. INSERT INTO wms_order_task (
  63. site, task_no, source_type, source_bill_no, source_line_id, part_no, qty,
  64. batch_no, serial_no, from_location, to_location, pallet_id, agv_code,
  65. priority, status, wms_send_time,
  66. error_code, error_msg, created_by, created_time, wcs_task_id,
  67. finish_qty, wms_status,item_no
  68. ) VALUES
  69. <foreach collection="list" item="item" separator=",">
  70. (
  71. #{item.site}, #{item.taskNo}, #{item.sourceType}, #{item.sourceBillNo}, #{item.sourceLineId},
  72. #{item.partNo}, #{item.qty}, #{item.batchNo}, #{item.serialNo}, #{item.fromLocation},
  73. #{item.toLocation}, #{item.palletId}, #{item.agvCode}, #{item.priority}, #{item.status},
  74. #{item.wmsSendTime},
  75. #{item.errorCode}, #{item.errorMsg}, #{item.createdBy}, #{item.createdTime},
  76. #{item.wcsTaskId}, #{item.finishQty}, #{item.wmsStatus}, #{item.itemNo}
  77. )
  78. </foreach>
  79. </insert>
  80. <insert id="batchSaveOrderTaskDetail">
  81. INSERT INTO wms_order_task_detail (
  82. site,task_no,item_no,seq_no,action_type,[comment],from_location,to_location,agv_code,[status],start_time,
  83. error_code,error_msg,pallet_id,wms_status
  84. ) VALUES
  85. <foreach collection="list" item="item" separator=",">
  86. (
  87. #{item.site}, #{item.taskNo}, #{item.itemNo}, #{item.seqNo}, #{item.actionType}, #{item.comment},
  88. #{item.fromLocation}, #{item.toLocation}, #{item.agvCode}, #{item.status}, getdate(),
  89. #{item.errorCode}, #{item.errorMsg}, #{item.palletId}, #{item.wmsStatus}
  90. )
  91. </foreach>
  92. </insert>
  93. <!-- ==================== 打托相关SQL - AI制作 ==================== -->
  94. <!-- 检查栈板是否存在并获取栈板信息 - AI制作 -->
  95. <select id="getPalletInfo" resultType="java.util.Map">
  96. SELECT pallet_id, pallet_type, status, location_code, site, calling_flag
  97. FROM pallet
  98. WHERE site = #{site} AND pallet_id = #{palletId} AND is_deleted = '0'
  99. </select>
  100. <!-- 获取栈板类型的位置信息 - AI制作 -->
  101. <select id="getPalletTypePositions" resultType="java.lang.String">
  102. SELECT position
  103. FROM pallet_type_area
  104. WHERE site = #{site} AND pallet_type = #{palletType}
  105. ORDER BY position
  106. </select>
  107. <!-- 获取栈板明细 - AI制作 -->
  108. <select id="getPalletDetails" resultType="java.util.Map">
  109. SELECT a.site, a.pallet_id as palletId, a.position, a.layer, a.serial_no as serialNo, a.part_no as partNo,
  110. a.create_date as createDate, a.create_by as createBy
  111. FROM pallet_detail a
  112. WHERE a.site = #{site} AND a.pallet_id = #{palletId}
  113. <if test="position != null and position != ''">
  114. AND a.position = #{position}
  115. </if>
  116. <if test="layer != null">
  117. AND a.layer = #{layer}
  118. </if>
  119. ORDER BY a.position, a.layer, a.serial_no
  120. </select>
  121. <select id="getPalletDetailsData" resultType="PalletDetailData">
  122. SELECT a.site, a.pallet_id as palletId, a.position, a.layer, a.serial_no as serialNo, a.part_no as partNo,
  123. a.create_date as createDate, a.create_by as createBy,b.warehouse_id,b.location_id
  124. FROM pallet_detail a left join handling_unit b on a.site = b.site and a.serial_no = b.unit_id
  125. WHERE a.site = #{site} AND a.pallet_id = #{palletId}
  126. </select>
  127. <!-- 根据位置获取层数 - AI制作 -->
  128. <select id="getLayersByPosition" resultType="java.lang.Integer">
  129. SELECT DISTINCT layer
  130. FROM pallet_detail
  131. WHERE site = #{site} AND pallet_id = #{palletId} AND position = #{position}
  132. ORDER BY layer
  133. </select>
  134. <!-- 验证标签 - AI制作 -->
  135. <select id="validateLabel" resultType="java.util.Map">
  136. SELECT site, unit_id as serialNo, part_no as partNo, qty, in_stock_flag as inStockFlag,
  137. unit_type as labelType, batch_no as batchNo, warehouse_id as warehouseId,
  138. location_id as locationId, remark, tid, epc
  139. FROM handling_unit
  140. WHERE site = #{site} AND unit_id = #{serialNo}
  141. </select>
  142. <!-- 获取栈板类型区域信息(用于校验层级规则) - AI制作 -->
  143. <select id="getPalletTypeAreaInfo" resultType="java.util.Map">
  144. SELECT site, pallet_type as palletType, position, position_desc as positionDesc
  145. FROM pallet_type_area
  146. WHERE site = #{site} AND pallet_type = #{palletType}
  147. ORDER BY position
  148. </select>
  149. <!-- 获取栈板指定层的明细统计 - AI制作 -->
  150. <select id="getPalletLayerStatistics" resultType="java.util.Map">
  151. SELECT position, COUNT(*) as count
  152. FROM pallet_detail
  153. WHERE site = #{site} AND pallet_id = #{palletId} AND layer = #{layer}
  154. GROUP BY position
  155. </select>
  156. <!-- 根据标签查找栈板信息 - AI制作 -->
  157. <select id="findPalletByLabel" resultType="java.util.Map">
  158. SELECT pallet_id as palletId, position, layer
  159. FROM pallet_detail
  160. WHERE site = #{site} AND serial_no = #{serialNo}
  161. </select>
  162. <select id="getNowStation" resultType="AgvStation">
  163. SELECT TOP 1 b.station_code, b.location_code, b.warehouse_code
  164. FROM pallet a
  165. LEFT JOIN agv_station b ON a.location_code = b.station_code
  166. WHERE a.site = #{site} AND a.pallet_id = #{palletId} AND a.is_deleted = '0'
  167. </select>
  168. <!-- 保存栈板明细 - AI制作 -->
  169. <insert id="savePalletDetail">
  170. INSERT INTO pallet_detail (site, pallet_id, position, layer, serial_no, part_no, create_date, create_by, wcs_flag)
  171. VALUES (#{site}, #{palletId}, #{position}, #{layer}, #{serialNo}, #{partNo}, GETDATE(), #{createBy}, 1)
  172. </insert>
  173. <!-- 删除栈板明细 - AI制作 -->
  174. <delete id="deletePalletDetail">
  175. DELETE FROM pallet_detail
  176. WHERE site = #{site} AND pallet_id = #{palletId} AND serial_no = #{serialNo}
  177. </delete>
  178. <!-- 根据条码删除栈板明细(不指定栈板ID) - AI制作 -->
  179. <delete id="deletePalletDetailBySerialNo">
  180. DELETE FROM pallet_detail
  181. WHERE site = #{site} AND serial_no = #{serialNo}
  182. </delete>
  183. <!-- 获取指定位置已占用的层数(排除指定标签) - AI制作 -->
  184. <select id="getOccupiedLayersExcludeSerial" resultType="java.lang.Integer">
  185. SELECT DISTINCT layer
  186. FROM pallet_detail
  187. WHERE site = #{site}
  188. AND pallet_id = #{palletId}
  189. AND position = #{position}
  190. AND serial_no != #{excludeSerialNo}
  191. ORDER BY layer
  192. </select>
  193. <!-- 更新栈板明细位置 - AI制作 -->
  194. <update id="updatePalletDetailPosition">
  195. UPDATE pallet_detail
  196. SET position = #{newPosition},
  197. layer = #{newLayer},
  198. wcs_flag = 1
  199. WHERE site = #{site}
  200. AND pallet_id = #{palletId}
  201. AND serial_no = #{serialNo}
  202. </update>
  203. <!-- 更新栈板调用状态 - AI制作 -->
  204. <update id="updatePalletCallingFlag">
  205. UPDATE pallet
  206. SET calling_flag = #{callingFlag},
  207. updated_by = #{updatedBy},
  208. updated_time = GETDATE()
  209. WHERE site = #{site}
  210. AND pallet_id = #{palletId}
  211. </update>
  212. <!-- 检查栈板是否正在被调用 - AI制作 -->
  213. <select id="checkPalletCallingFlag" resultType="java.lang.String">
  214. SELECT calling_flag
  215. FROM pallet
  216. WHERE site = #{site} AND pallet_id = #{palletId} AND is_deleted = '0'
  217. </select>
  218. <!-- 统计栈板明细数量 - AI制作 -->
  219. <select id="countPalletDetails" resultType="java.lang.Integer">
  220. SELECT COUNT(1)
  221. FROM pallet_detail
  222. WHERE site = #{site} AND pallet_id = #{palletId}
  223. </select>
  224. <!-- 更新栈板空栈板标记 - AI制作 -->
  225. <update id="updatePalletEmptyFlag">
  226. UPDATE pallet
  227. SET empty_flag = #{emptyFlag},
  228. updated_by = #{updatedBy},
  229. updated_time = GETDATE()
  230. WHERE site = #{site} AND pallet_id = #{palletId}
  231. </update>
  232. <!-- ==================== 运输任务相关SQL - AI制作 ==================== -->
  233. <!-- 获取AGV站点列表 - AI制作 -->
  234. <select id="getAgvStations" resultType="java.util.Map">
  235. SELECT station_code as stationCode, station_name as stationName,
  236. area_type as areaType, station_area as stationArea,
  237. warehouse_code as warehouseCode, location_code as locationCode,
  238. status_db as statusDb, status, station_id as stationId,
  239. station_type as stationType
  240. FROM agv_station
  241. WHERE active = 'Y'
  242. ORDER BY station_code
  243. </select>
  244. <!-- 根据目标区域查找第一个空闲站点 - AI制作 -->
  245. <select id="findFirstFreeStationByArea" resultType="java.lang.String">
  246. SELECT TOP 1 station_code
  247. FROM agv_station
  248. WHERE station_area = #{stationArea}
  249. AND status_db = 0
  250. AND active = 'Y'
  251. AND station_type = '正式站点'
  252. ORDER BY station_code
  253. </select>
  254. <!-- 根据起点站点获取可达目标站点 - AI制作 -->
  255. <!-- 注:agv_route_config表已废弃,改为返回所有激活的站点(排除起始站点) -->
  256. <select id="getTargetStationsByStart" resultType="java.util.Map">
  257. SELECT station_code as stationCode, station_name as stationName,
  258. status_db as statusDb, status
  259. FROM agv_station
  260. WHERE active = 'Y'
  261. AND station_code != #{startStation}
  262. ORDER BY station_code
  263. </select>
  264. <!-- 插入单个运输任务 - AI制作 -->
  265. <insert id="insertTransportTask" useGeneratedKeys="true" keyProperty="id">
  266. INSERT INTO wms_transport_task (
  267. site, task_no, item_no, source_type, source_bill_no, source_line_id,
  268. part_no, qty, batch_no, serial_no, from_location, to_location,
  269. pallet_id, agv_code, priority, status, wms_send_time,
  270. created_by, created_time, updated_time,wms_status
  271. ) VALUES (
  272. #{site}, #{taskNo}, #{itemNo}, #{sourceType}, #{sourceBillNo}, #{sourceLineId},
  273. #{partNo}, #{qty}, #{batchNo}, #{serialNo}, #{fromLocation}, #{toLocation},
  274. #{palletId}, #{agvCode}, #{priority}, #{status}, #{wmsSendTime},
  275. #{createdBy}, #{createdTime}, #{updatedTime},N'未执行'
  276. )
  277. </insert>
  278. <insert id="insertOrderTask" useGeneratedKeys="true" keyProperty="id">
  279. INSERT INTO wms_order_task (
  280. site, task_no, item_no, source_type, source_bill_no, source_line_id,
  281. part_no, qty, batch_no, serial_no, from_location, to_location,
  282. pallet_id, agv_code, priority, status, wms_send_time,
  283. created_by, created_time, updated_time
  284. ) VALUES (
  285. #{site}, #{taskNo}, #{itemNo}, #{sourceType}, #{sourceBillNo}, #{sourceLineId},
  286. #{partNo}, #{qty}, #{batchNo}, #{serialNo}, #{fromLocation}, #{toLocation},
  287. #{palletId}, #{agvCode}, #{priority}, #{status}, #{wmsSendTime},
  288. #{createdBy}, #{createdTime}, #{updatedTime}
  289. )
  290. </insert>
  291. <!-- 检查站点是否有栈板 - AI制作 -->
  292. <select id="checkStationHasPallet" resultType="java.lang.Integer">
  293. SELECT COUNT(1)
  294. FROM pallet
  295. WHERE site = #{site}
  296. AND location_code = #{stationCode}
  297. AND is_deleted = '0'
  298. </select>
  299. <!-- 获取站点的栈板ID - AI制作 -->
  300. <select id="getPalletIdByStation" resultType="java.lang.String">
  301. SELECT TOP 1 pallet_id
  302. FROM pallet
  303. WHERE site = #{site}
  304. AND location_code = #{stationCode}
  305. AND is_deleted = '0'
  306. ORDER BY pallet_id
  307. </select>
  308. <!-- 根据ID查询运输任务 - AI制作 -->
  309. <select id="getTransportTaskById" resultType="WmsTransportTask">
  310. SELECT id, site, task_no as taskNo, item_no as itemNo, source_type as sourceType,
  311. source_bill_no as sourceBillNo, source_line_id as sourceLineId,
  312. part_no as partNo, qty, batch_no as batchNo, serial_no as serialNo,
  313. from_location as fromLocation, to_location as toLocation,
  314. pallet_id as palletId, agv_code as agvCode, priority, status,
  315. wms_send_time as wmsSendTime, wcs_receive_time as wcsReceiveTime,
  316. start_time as startTime, complete_time as completeTime,
  317. error_code as errorCode, error_msg as errorMsg,
  318. created_by as createdBy, created_time as createdTime,
  319. updated_time as updatedTime, wcs_task_id as wcsTaskId,
  320. finish_qty as finishQty, wms_status as wmsStatus
  321. FROM wms_transport_task
  322. WHERE id = #{id}
  323. </select>
  324. <!-- 根据taskNo查询运输任务 - AI制作 -->
  325. <select id="getTransportTaskByTaskNo" resultType="WmsTransportTask">
  326. SELECT id, site, task_no as taskNo, item_no as itemNo, source_type as sourceType,
  327. source_bill_no as sourceBillNo, source_line_id as sourceLineId,
  328. part_no as partNo, qty, batch_no as batchNo, serial_no as serialNo,
  329. from_location as fromLocation, to_location as toLocation,
  330. pallet_id as palletId, agv_code as agvCode, priority, status,
  331. wms_send_time as wmsSendTime, wcs_receive_time as wcsReceiveTime,
  332. start_time as startTime, complete_time as completeTime,
  333. error_code as errorCode, error_msg as errorMsg,
  334. created_by as createdBy, created_time as createdTime,
  335. updated_time as updatedTime, wcs_task_id as wcsTaskId,
  336. finish_qty as finishQty, wms_status as wmsStatus
  337. FROM wms_transport_task
  338. WHERE task_no = #{taskNo}
  339. </select>
  340. <!-- 更新运输任务状态 - AI制作 -->
  341. <update id="updateTransportTaskStatus">
  342. UPDATE wms_transport_task
  343. SET status = #{status}, updated_time = GETDATE()
  344. WHERE id = #{id}
  345. </update>
  346. <!-- 根据taskNo更新运输任务状态 - AI制作 -->
  347. <update id="updateTransportTaskStatusByTaskNo">
  348. UPDATE wms_transport_task
  349. SET status = #{status}, updated_time = GETDATE()
  350. WHERE task_no = #{taskNo}
  351. </update>
  352. <!-- 根据站点代码获取站点信息 - AI制作 -->
  353. <select id="getStationInfoByCode" resultType="java.util.Map">
  354. SELECT station_code as stationCode, station_name as stationName,
  355. warehouse_code as warehouseCode, location_code as locationCode,
  356. area_type as areaType, active, status_db as statusDb, status,
  357. station_id as stationId, station_type as stationType
  358. FROM agv_station
  359. WHERE station_code = #{stationCode}
  360. </select>
  361. <select id="getStationDataByCode" resultType="AgvStation">
  362. SELECT station_code as stationCode, station_name as stationName,
  363. warehouse_code as warehouseCode, location_code as locationCode,
  364. area_type as areaType, active, status_db as statusDb, status,
  365. station_id as stationId, station_type as stationType
  366. FROM agv_station
  367. WHERE station_code = #{stationCode}
  368. </select>
  369. <!-- 更新栈板明细的wcs_flag为0(已传输给WCS) - AI制作 -->
  370. <update id="updatePalletDetailWcsFlag">
  371. UPDATE pallet_detail
  372. SET wcs_flag = 0
  373. WHERE site = #{site}
  374. AND pallet_id = #{palletId}
  375. AND wcs_flag = 1
  376. </update>
  377. <select id="getPalletDetailsNewDetail" resultType="PalletDetailData">
  378. 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,
  379. b.part_desc,b.qty,b.batch_no,b.wdr,c.weight,b.length,b.width,c.height,c.is_robot_pick,um_id
  380. ,c.is_commonly_used, CONVERT(varchar(10),isnull( isnull(b.manufacture_date,b.receive_date),getdate()), 23) manufactureDateStr
  381. from pallet_detail a
  382. left join handling_unit b on a.site=b.site and a.serial_no=b.unit_id
  383. left join part_attribute c on a.site=c.site and a.part_no=c.part_no
  384. where a.wcs_flag = 1
  385. </select>
  386. <insert id="insertWmsTransportTaskDetail" >
  387. insert into wms_transport_task_detail(
  388. site,task_no,item_no,seq_no,action_type,[comment],from_location,to_location,agv_code,[status],start_time,
  389. error_code,error_msg
  390. ) values (
  391. #{site}, #{taskNo}, #{itemNo}, #{seqNo}, #{actionType}, #{comment}, #{fromLocation}, #{toLocation}, #{agvCode}, #{status}, #{startTime},
  392. #{errorCode}, #{errorMsg}
  393. )
  394. </insert>
  395. <insert id="insertWmsOrderTaskDetail" >
  396. insert into wms_order_task_detail(
  397. site,task_no,item_no,seq_no,action_type,[comment],from_location,to_location,agv_code,[status],start_time,
  398. error_code,error_msg
  399. ) values (
  400. #{site}, #{taskNo}, #{itemNo}, #{seqNo}, #{actionType}, #{comment}, #{fromLocation}, #{toLocation}, #{agvCode}, #{status}, #{startTime},
  401. #{errorCode}, #{errorMsg}
  402. )
  403. </insert>
  404. <select id="getMaxSeqNoForTaskDetail" resultType="Integer">
  405. select isnull(max(seq_no),0)+1 from wms_transport_task_detail
  406. where task_no=#{taskNo} and site=#{site} and item_no= 1
  407. </select>
  408. <update id="updateTransportTaskStatusForSiteAndNo">
  409. update wms_transport_task set [status]=#{status} where site=#{site} and task_no=#{taskNo}
  410. </update>
  411. <update id="updateTransportTaskDetailStatusForId">
  412. update wms_transport_task_detail set [status]=#{status} where id=#{id}
  413. </update>
  414. <select id="getTransportTaskDetailListWithStatus" resultType="WmsTransportTaskDetail">
  415. select id,site,task_no as taskNo,item_no as itemNo,seq_no as seqNo,action_type as actionType,[comment],from_location as fromLocation,
  416. to_location as toLocation,agv_code as agvCode,[status],start_time as startTime,
  417. error_code as errorCode,error_msg as errorMsg
  418. from wms_transport_task_detail
  419. where site = #{site} and status in ('回调处理失败','已录入')
  420. </select>
  421. <!-- 查询指定状态的订单任务明细列表 - AI制作 -->
  422. <select id="getOrderTaskDetailListWithStatus" resultType="WmsOrderTaskDetail">
  423. select id,site,task_no as taskNo,item_no as itemNo,seq_no as seqNo,action_type as actionType,[comment],from_location as fromLocation,
  424. to_location as toLocation,agv_code as agvCode,[status],start_time as startTime,
  425. error_code as errorCode,error_msg as errorMsg
  426. from wms_order_task_detail
  427. where site = #{site} and status in ('处理失败','已录入')
  428. </select>
  429. <!-- 根据ID更新订单任务明细状态 - AI制作 -->
  430. <update id="updateOrderTaskDetailStatusForId">
  431. update wms_order_task_detail set [status]=#{status} where id=#{id}
  432. </update>
  433. <!-- 根据任务号获取栈板ID - AI制作 -->
  434. <select id="getPalletIdByOrderTaskNo" resultType="String">
  435. select pallet_id from wms_order_task where task_no = #{taskNo}
  436. </select>
  437. <!-- 根据栈板号和任务类型查找订单任务 - AI制作 -->
  438. <select id="findOrderTaskByPalletAndType" resultType="WmsOrderTask">
  439. select top 1 id, site, task_no as taskNo, item_no as itemNo, source_type as sourceType,
  440. source_bill_no as sourceBillNo, source_line_id as sourceLineId, part_no as partNo,
  441. qty, batch_no as batchNo, serial_no as serialNo, from_location as fromLocation,
  442. to_location as toLocation, pallet_id as palletId, agv_code as agvCode,
  443. priority, status, wms_send_time as wmsSendTime, wcs_receive_time as wcsReceiveTime,
  444. start_time as startTime, complete_time as completeTime, error_code as errorCode,
  445. error_msg as errorMsg, created_by as createdBy, created_time as createdTime,
  446. updated_time as updatedTime, wcs_task_id as wcsTaskId, finish_qty as finishQty,
  447. wms_status as wmsStatus
  448. from wms_order_task
  449. where site = #{site}
  450. and pallet_id = #{palletId}
  451. and source_type = #{sourceType}
  452. and status in ('已创建', '执行中', '已下发')
  453. order by created_time desc
  454. </select>
  455. <!-- 获取订单任务明细的最大序号 - AI制作 -->
  456. <select id="getMaxSeqNoForOrderTaskDetail" resultType="Integer">
  457. select isnull(max(seq_no),0)+1 from wms_order_task_detail
  458. where task_no=#{taskNo} and site=#{site}
  459. </select>
  460. <!-- 插入WCS回调任务 - AI制作 -->
  461. <insert id="insertWcsCallbackTask" useGeneratedKeys="true" keyProperty="id">
  462. INSERT INTO wcs_callback_task (
  463. site, pallet_id, trans_type_desc, to_warehouse_id, to_location_id,
  464. status, created_time, retry_count, remark, task_no, item_no, to_station
  465. ) VALUES (
  466. #{site}, #{palletId}, #{transTypeDesc}, #{toWarehouseId}, #{toLocationId},
  467. #{status}, #{createdTime}, #{retryCount}, #{remark}, #{taskNo}, #{itemNo}, #{toStation}
  468. )
  469. </insert>
  470. <!-- 查询指定状态的WCS回调任务列表(含超时恢复机制) - AI制作 -->
  471. <select id="getWcsCallbackTaskListWithStatus" resultType="WcsCallbackTask">
  472. select id, site, pallet_id as palletId, trans_type_desc as transTypeDesc,
  473. to_warehouse_id as toWarehouseId, to_location_id as toLocationId,
  474. status, created_time as createdTime, process_start_time as processStartTime,
  475. process_end_time as processEndTime, error_msg as errorMsg,
  476. retry_count as retryCount, remark,task_no,item_no,to_station
  477. from wcs_callback_task
  478. where site = #{site}
  479. and (
  480. status in ('已录入', '处理失败')
  481. or (status = '处理中' and process_start_time &lt; DATEADD(MINUTE, -10, GETDATE()))
  482. )
  483. and (retry_count is null or retry_count &lt; 3)
  484. order by created_time
  485. </select>
  486. <!-- 更新WCS回调任务状态 - AI制作 -->
  487. <update id="updateWcsCallbackTaskStatus">
  488. update wcs_callback_task
  489. set status = #{status}
  490. <if test="processStartTime != null">
  491. , process_start_time = #{processStartTime}
  492. </if>
  493. <if test="processEndTime != null">
  494. , process_end_time = #{processEndTime}
  495. </if>
  496. <if test="errorMsg != null">
  497. , error_msg = #{errorMsg}
  498. </if>
  499. where id = #{id}
  500. </update>
  501. <!-- 原子性更新WCS回调任务状态(乐观锁版本,防止重复处理) - AI制作 -->
  502. <update id="updateWcsCallbackTaskStatusWithLock">
  503. UPDATE wcs_callback_task
  504. SET status = #{newStatus},
  505. process_start_time = #{processStartTime}
  506. WHERE id = #{id}
  507. AND status = #{oldStatus}
  508. </update>
  509. <update id="updatePalletWcsLocation" >
  510. update pallet set location_code = #{location},updated_by='wms_sys',updated_time=getdate()
  511. where site = #{site} and pallet_id = #{palletId}
  512. </update>
  513. <!-- 更新WCS回调任务重试次数 - AI制作 -->
  514. <update id="updateWcsCallbackTaskRetryCount">
  515. update wcs_callback_task set retry_count = #{retryCount} where id = #{id}
  516. </update>
  517. <!-- 根据栈板ID和动作类型查找订单任务 - AI制作 -->
  518. <select id="findOrderTasksByPalletAndActionType" resultType="WmsOrderTask">
  519. select id, site, task_no as taskNo, item_no as itemNo, source_type as sourceType,
  520. source_bill_no as sourceBillNo, source_line_id as sourceLineId, part_no as partNo,
  521. qty, batch_no as batchNo, serial_no as serialNo, from_location as fromLocation,
  522. to_location as toLocation, pallet_id as palletId, agv_code as agvCode,
  523. priority, status, wms_send_time as wmsSendTime, wcs_receive_time as wcsReceiveTime,
  524. start_time as startTime, complete_time as completeTime, error_code as errorCode,
  525. error_msg as errorMsg, created_by as createdBy, created_time as createdTime,
  526. updated_time as updatedTime, wcs_task_id as wcsTaskId, finish_qty as finishQty,
  527. wms_status as wmsStatus
  528. from wms_order_task
  529. where site = #{site}
  530. and pallet_id = #{palletId}
  531. and source_type = #{sourceType}
  532. and status = #{status}
  533. order by created_time desc
  534. </select>
  535. <select id="findOrderTasksByTaskNo" resultType="WmsOrderTask">
  536. select id, site, task_no as taskNo, item_no as itemNo, source_type as sourceType,
  537. source_bill_no as sourceBillNo, source_line_id as sourceLineId, part_no as partNo,
  538. qty, batch_no as batchNo, serial_no as serialNo, from_location as fromLocation,
  539. to_location as toLocation, pallet_id as palletId, agv_code as agvCode,
  540. priority, status, wms_send_time as wmsSendTime, wcs_receive_time as wcsReceiveTime,
  541. start_time as startTime, complete_time as completeTime, error_code as errorCode,
  542. error_msg as errorMsg, created_by as createdBy, created_time as createdTime,
  543. updated_time as updatedTime, wcs_task_id as wcsTaskId, finish_qty as finishQty,
  544. wms_status as wmsStatus
  545. from wms_order_task
  546. where site = #{site}
  547. and task_no=#{taskNo}
  548. order by created_time desc
  549. </select>
  550. <!-- 更新订单任务状态和WMS状态 - AI制作 -->
  551. <update id="updateOrderTaskStatusAndWmsStatus">
  552. update wms_order_task
  553. set status = #{status}, wms_status = #{wmsStatus}
  554. where id = #{id}
  555. </update>
  556. <!-- 根据任务号更新订单任务明细状态 - AI制作 -->
  557. <update id="updateOrderTaskDetailStatusByTaskNo">
  558. update wms_order_task_detail
  559. set status = #{status} ,wms_status = #{wmsStatus}
  560. where task_no = #{taskNo}
  561. </update>
  562. <!-- 查询立库调栈板出库的订单任务列表 - AI制作 -->
  563. <select id="getWcsOrderTaskListForPalletOut" resultType="WmsOrderTask">
  564. select id, site, task_no as taskNo, item_no as itemNo, source_type as sourceType,
  565. source_bill_no as sourceBillNo, source_line_id as sourceLineId, part_no as partNo,
  566. qty, batch_no as batchNo, serial_no as serialNo, from_location as fromLocation,
  567. to_location as toLocation, pallet_id as palletId, agv_code as agvCode,
  568. priority, status, wms_send_time as wmsSendTime, wcs_receive_time as wcsReceiveTime,
  569. start_time as startTime, complete_time as completeTime, error_code as errorCode,
  570. error_msg as errorMsg, created_by as createdBy, created_time as createdTime,
  571. updated_time as updatedTime, wcs_task_id as wcsTaskId, finish_qty as finishQty,
  572. wms_status as wmsStatus
  573. from wms_order_task
  574. where site = #{site}
  575. and status = '已创建'
  576. and source_type like '%出%'
  577. and (wms_status is null or wms_status in ('未执行', '等待重试'))
  578. order by priority desc, created_time asc
  579. </select>
  580. <!-- 更新订单任务错误信息 - AI制作 -->
  581. <update id="updateOrderTaskErrorInfo">
  582. update wms_order_task
  583. set error_code = #{errorCode},
  584. error_msg = #{errorMsg}
  585. where id = #{id}
  586. </update>
  587. <!-- 更新AGV站点状态 - AI制作 -->
  588. <update id="updateAgvStationStatus">
  589. UPDATE agv_station
  590. SET status_db = #{statusDb},
  591. status = #{status}
  592. WHERE station_code = #{stationCode}
  593. </update>
  594. <!-- 获取AGV站点状态 - AI制作 -->
  595. <select id="getAgvStationStatus" resultType="Integer">
  596. SELECT status_db
  597. FROM agv_station
  598. WHERE station_code = #{stationCode}
  599. </select>
  600. <!-- 获取栈板详细信息(包含palletType和autoSort以及托盘类型详情) - AI制作 -->
  601. <select id="getPalletInfoWithTypeDetails" resultType="PalletData">
  602. SELECT
  603. p.site,
  604. p.pallet_id AS palletId,
  605. p.pallet_type AS palletType,
  606. p.pallet_family AS palletFamily,
  607. p.auto_sort AS autoSort,
  608. p.sore_type AS soreType,
  609. p.location_code AS locationCode,
  610. p.wcs_location AS wcsLocation,
  611. pt.type_desc AS typeDesc,
  612. pt.wcs_auto_sort AS wcsAutoSort,
  613. pt.wcs_pallet_type AS wcsPalletType,
  614. pt.wcs_base_pallet_type AS wcsBasePalletType,
  615. pt.wcs_sore_type AS wcsSoreType,
  616. pt.max_layer AS maxLayer,
  617. pf.pallet_family_desc AS palletFamilyDesc
  618. FROM pallet p
  619. LEFT JOIN pallet_type pt ON p.site = pt.site AND p.pallet_type = pt.pallet_type
  620. LEFT JOIN pallet_family pf ON p.site = pf.site AND p.pallet_family = pf.pallet_family
  621. WHERE p.site = #{site}
  622. AND p.pallet_id = #{palletId}
  623. AND p.is_deleted = '0'
  624. </select>
  625. <!-- 更新栈板类型和自动分拣标志 - AI制作 -->
  626. <update id="updatePalletTypeAndAutoSort">
  627. UPDATE pallet
  628. SET pallet_type = #{palletType},
  629. auto_sort = #{autoSort},
  630. updated_time = GETDATE()
  631. WHERE site = #{site}
  632. AND pallet_id = #{palletId}
  633. AND is_deleted = '0'
  634. </update>
  635. </mapper>