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.

721 lines
33 KiB

5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 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. <!-- 获取可用的AGV站点列表(按状态和类型过滤) - AI制作 -->
  245. <select id="getAvailableAgvStations" resultType="AgvStation">
  246. SELECT id, station_code as stationCode, station_name as stationName,
  247. area_type as areaType, station_area as stationArea,
  248. warehouse_code as warehouseCode, location_code as locationCode,
  249. status_db as statusDb, status, station_id as stationId,
  250. station_type as stationType, active, remark,
  251. location_x as locationX, location_y as locationY, location_z as locationZ
  252. FROM agv_station
  253. WHERE active = 'Y'
  254. AND station_type = '正式站点'
  255. <if test="statusDb != null">
  256. AND status_db = #{statusDb}
  257. </if>
  258. ORDER BY station_code
  259. </select>
  260. <!-- 根据目标区域查找第一个空闲站点 - AI制作 -->
  261. <select id="findFirstFreeStationByArea" resultType="java.lang.String">
  262. SELECT TOP 1 station_code
  263. FROM agv_station
  264. WHERE station_area = #{stationArea}
  265. AND status_db = 0
  266. AND active = 'Y'
  267. AND station_type = '正式站点'
  268. ORDER BY station_code
  269. </select>
  270. <!-- 根据起点站点获取可达目标站点 - AI制作 -->
  271. <!-- 注:agv_route_config表已废弃,改为返回所有激活的站点(排除起始站点) -->
  272. <select id="getTargetStationsByStart" resultType="java.util.Map">
  273. SELECT station_code as stationCode, station_name as stationName,
  274. status_db as statusDb, status
  275. FROM agv_station
  276. WHERE active = 'Y'
  277. AND station_code != #{startStation}
  278. ORDER BY station_code
  279. </select>
  280. <!-- 插入单个运输任务 - AI制作 -->
  281. <insert id="insertTransportTask" useGeneratedKeys="true" keyProperty="id">
  282. INSERT INTO wms_transport_task (
  283. site, task_no, item_no, source_type, source_bill_no, source_line_id,
  284. part_no, qty, batch_no, serial_no, from_location, to_location,
  285. pallet_id, agv_code, priority, status, wms_send_time,
  286. created_by, created_time, updated_time,wms_status
  287. ) VALUES (
  288. #{site}, #{taskNo}, #{itemNo}, #{sourceType}, #{sourceBillNo}, #{sourceLineId},
  289. #{partNo}, #{qty}, #{batchNo}, #{serialNo}, #{fromLocation}, #{toLocation},
  290. #{palletId}, #{agvCode}, #{priority}, #{status}, #{wmsSendTime},
  291. #{createdBy}, #{createdTime}, #{updatedTime},N'未执行'
  292. )
  293. </insert>
  294. <insert id="insertOrderTask" useGeneratedKeys="true" keyProperty="id">
  295. INSERT INTO wms_order_task (
  296. site, task_no, item_no, source_type, source_bill_no, source_line_id,
  297. part_no, qty, batch_no, serial_no, from_location, to_location,
  298. pallet_id, agv_code, priority, status, wms_send_time,
  299. created_by, created_time, updated_time
  300. ) VALUES (
  301. #{site}, #{taskNo}, #{itemNo}, #{sourceType}, #{sourceBillNo}, #{sourceLineId},
  302. #{partNo}, #{qty}, #{batchNo}, #{serialNo}, #{fromLocation}, #{toLocation},
  303. #{palletId}, #{agvCode}, #{priority}, #{status}, #{wmsSendTime},
  304. #{createdBy}, #{createdTime}, #{updatedTime}
  305. )
  306. </insert>
  307. <!-- 检查站点是否有栈板 - AI制作 -->
  308. <select id="checkStationHasPallet" resultType="java.lang.Integer">
  309. SELECT COUNT(1)
  310. FROM pallet
  311. WHERE site = #{site}
  312. AND location_code = #{stationCode}
  313. AND is_deleted = '0'
  314. </select>
  315. <!-- 获取站点的栈板ID - AI制作 -->
  316. <select id="getPalletIdByStation" resultType="java.lang.String">
  317. SELECT TOP 1 pallet_id
  318. FROM pallet
  319. WHERE site = #{site}
  320. AND location_code = #{stationCode}
  321. AND is_deleted = '0'
  322. ORDER BY pallet_id
  323. </select>
  324. <!-- 根据ID查询运输任务 - AI制作 -->
  325. <select id="getTransportTaskById" 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 id = #{id}
  339. </select>
  340. <!-- 根据taskNo查询运输任务 - AI制作 -->
  341. <select id="getTransportTaskByTaskNo" resultType="WmsTransportTask">
  342. SELECT id, site, task_no as taskNo, item_no as itemNo, source_type as sourceType,
  343. source_bill_no as sourceBillNo, source_line_id as sourceLineId,
  344. part_no as partNo, qty, batch_no as batchNo, serial_no as serialNo,
  345. from_location as fromLocation, to_location as toLocation,
  346. pallet_id as palletId, agv_code as agvCode, priority, status,
  347. wms_send_time as wmsSendTime, wcs_receive_time as wcsReceiveTime,
  348. start_time as startTime, complete_time as completeTime,
  349. error_code as errorCode, error_msg as errorMsg,
  350. created_by as createdBy, created_time as createdTime,
  351. updated_time as updatedTime, wcs_task_id as wcsTaskId,
  352. finish_qty as finishQty, wms_status as wmsStatus
  353. FROM wms_transport_task
  354. WHERE task_no = #{taskNo}
  355. </select>
  356. <!-- 更新运输任务状态 - AI制作 -->
  357. <update id="updateTransportTaskStatus">
  358. UPDATE wms_transport_task
  359. SET status = #{status}, updated_time = GETDATE()
  360. WHERE id = #{id}
  361. </update>
  362. <!-- 根据taskNo更新运输任务状态 - AI制作 -->
  363. <update id="updateTransportTaskStatusByTaskNo">
  364. UPDATE wms_transport_task
  365. SET status = #{status}, updated_time = GETDATE()
  366. WHERE task_no = #{taskNo}
  367. </update>
  368. <!-- 根据站点代码获取站点信息 - AI制作 -->
  369. <select id="getStationInfoByCode" resultType="java.util.Map">
  370. SELECT station_code as stationCode, station_name as stationName,
  371. warehouse_code as warehouseCode, location_code as locationCode,
  372. area_type as areaType, active, status_db as statusDb, status,
  373. station_id as stationId, station_type as stationType
  374. FROM agv_station
  375. WHERE station_code = #{stationCode}
  376. </select>
  377. <select id="getStationDataByCode" resultType="AgvStation">
  378. SELECT station_code as stationCode, station_name as stationName,
  379. warehouse_code as warehouseCode, location_code as locationCode,
  380. area_type as areaType, active, status_db as statusDb, status,
  381. station_id as stationId, station_type as stationType
  382. FROM agv_station
  383. WHERE station_code = #{stationCode}
  384. </select>
  385. <!-- 更新栈板明细的wcs_flag为0(已传输给WCS) - AI制作 -->
  386. <update id="updatePalletDetailWcsFlag">
  387. UPDATE pallet_detail
  388. SET wcs_flag = 0
  389. WHERE site = #{site}
  390. AND pallet_id = #{palletId}
  391. AND wcs_flag = 1
  392. </update>
  393. <select id="getPalletDetailsNewDetail" resultType="PalletDetailData">
  394. 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,
  395. b.part_desc,b.qty,b.batch_no,b.wdr,c.weight,b.length,b.width,c.height,c.is_robot_pick,um_id
  396. ,c.is_commonly_used, CONVERT(varchar(10),isnull( isnull(b.manufacture_date,b.receive_date),getdate()), 23) manufactureDateStr
  397. from pallet_detail a
  398. left join handling_unit b on a.site=b.site and a.serial_no=b.unit_id
  399. left join part_attribute c on a.site=c.site and a.part_no=c.part_no
  400. where site=#{site} and a.pallet_id=#{palletId}
  401. and a.wcs_flag = 1
  402. </select>
  403. <insert id="insertWmsTransportTaskDetail" >
  404. insert into wms_transport_task_detail(
  405. site,task_no,item_no,seq_no,action_type,[comment],from_location,to_location,agv_code,[status],start_time,
  406. error_code,error_msg
  407. ) values (
  408. #{site}, #{taskNo}, #{itemNo}, #{seqNo}, #{actionType}, #{comment}, #{fromLocation}, #{toLocation}, #{agvCode}, #{status}, #{startTime},
  409. #{errorCode}, #{errorMsg}
  410. )
  411. </insert>
  412. <insert id="insertWmsOrderTaskDetail" >
  413. insert into wms_order_task_detail(
  414. site,task_no,item_no,seq_no,action_type,[comment],from_location,to_location,agv_code,[status],start_time,
  415. error_code,error_msg
  416. ) values (
  417. #{site}, #{taskNo}, #{itemNo}, #{seqNo}, #{actionType}, #{comment}, #{fromLocation}, #{toLocation}, #{agvCode}, #{status}, #{startTime},
  418. #{errorCode}, #{errorMsg}
  419. )
  420. </insert>
  421. <select id="getMaxSeqNoForTaskDetail" resultType="Integer">
  422. select isnull(max(seq_no),0)+1 from wms_transport_task_detail
  423. where task_no=#{taskNo} and site=#{site} and item_no= 1
  424. </select>
  425. <update id="updateTransportTaskStatusForSiteAndNo">
  426. update wms_transport_task set [status]=#{status} where site=#{site} and task_no=#{taskNo}
  427. </update>
  428. <update id="updateTransportTaskDetailStatusForId">
  429. update wms_transport_task_detail set [status]=#{status} where id=#{id}
  430. </update>
  431. <select id="getTransportTaskDetailListWithStatus" resultType="WmsTransportTaskDetail">
  432. select id,site,task_no as taskNo,item_no as itemNo,seq_no as seqNo,action_type as actionType,[comment],from_location as fromLocation,
  433. to_location as toLocation,agv_code as agvCode,[status],start_time as startTime,
  434. error_code as errorCode,error_msg as errorMsg
  435. from wms_transport_task_detail
  436. where site = #{site} and status in ('回调处理失败','已录入')
  437. </select>
  438. <!-- 查询指定状态的订单任务明细列表 - AI制作 -->
  439. <select id="getOrderTaskDetailListWithStatus" resultType="WmsOrderTaskDetail">
  440. select id,site,task_no as taskNo,item_no as itemNo,seq_no as seqNo,action_type as actionType,[comment],from_location as fromLocation,
  441. to_location as toLocation,agv_code as agvCode,[status],start_time as startTime,
  442. error_code as errorCode,error_msg as errorMsg
  443. from wms_order_task_detail
  444. where site = #{site} and status in ('处理失败','已录入')
  445. </select>
  446. <!-- 根据ID更新订单任务明细状态 - AI制作 -->
  447. <update id="updateOrderTaskDetailStatusForId">
  448. update wms_order_task_detail set [status]=#{status} where id=#{id}
  449. </update>
  450. <!-- 根据任务号获取栈板ID - AI制作 -->
  451. <select id="getPalletIdByOrderTaskNo" resultType="String">
  452. select pallet_id from wms_order_task where task_no = #{taskNo}
  453. </select>
  454. <!-- 根据栈板号和任务类型查找订单任务 - AI制作 -->
  455. <select id="findOrderTaskByPalletAndType" resultType="WmsOrderTask">
  456. select top 1 id, site, task_no as taskNo, item_no as itemNo, source_type as sourceType,
  457. source_bill_no as sourceBillNo, source_line_id as sourceLineId, part_no as partNo,
  458. qty, batch_no as batchNo, serial_no as serialNo, from_location as fromLocation,
  459. to_location as toLocation, pallet_id as palletId, agv_code as agvCode,
  460. priority, status, wms_send_time as wmsSendTime, wcs_receive_time as wcsReceiveTime,
  461. start_time as startTime, complete_time as completeTime, error_code as errorCode,
  462. error_msg as errorMsg, created_by as createdBy, created_time as createdTime,
  463. updated_time as updatedTime, wcs_task_id as wcsTaskId, finish_qty as finishQty,
  464. wms_status as wmsStatus
  465. from wms_order_task
  466. where site = #{site}
  467. and pallet_id = #{palletId}
  468. and source_type = #{sourceType}
  469. and status in ('已创建', '执行中', '已下发')
  470. order by created_time desc
  471. </select>
  472. <!-- 获取订单任务明细的最大序号 - AI制作 -->
  473. <select id="getMaxSeqNoForOrderTaskDetail" resultType="Integer">
  474. select isnull(max(seq_no),0)+1 from wms_order_task_detail
  475. where task_no=#{taskNo} and site=#{site}
  476. </select>
  477. <!-- 插入WCS回调任务 - AI制作 -->
  478. <insert id="insertWcsCallbackTask" useGeneratedKeys="true" keyProperty="id">
  479. INSERT INTO wcs_callback_task (
  480. site, pallet_id, trans_type_desc, to_warehouse_id, to_location_id,
  481. status, created_time, retry_count, remark, task_no, item_no, to_station
  482. ) VALUES (
  483. #{site}, #{palletId}, #{transTypeDesc}, #{toWarehouseId}, #{toLocationId},
  484. #{status}, #{createdTime}, #{retryCount}, #{remark}, #{taskNo}, #{itemNo}, #{toStation}
  485. )
  486. </insert>
  487. <!-- 查询指定状态的WCS回调任务列表(含超时恢复机制) - AI制作 -->
  488. <select id="getWcsCallbackTaskListWithStatus" resultType="WcsCallbackTask">
  489. select id, site, pallet_id as palletId, trans_type_desc as transTypeDesc,
  490. to_warehouse_id as toWarehouseId, to_location_id as toLocationId,
  491. status, created_time as createdTime, process_start_time as processStartTime,
  492. process_end_time as processEndTime, error_msg as errorMsg,
  493. retry_count as retryCount, remark,task_no,item_no,to_station
  494. from wcs_callback_task
  495. where site = #{site}
  496. and (
  497. status in ('已录入', '处理失败')
  498. or (status = '处理中' and process_start_time &lt; DATEADD(MINUTE, -10, GETDATE()))
  499. )
  500. and (retry_count is null or retry_count &lt; 3)
  501. order by created_time
  502. </select>
  503. <!-- 更新WCS回调任务状态 - AI制作 -->
  504. <update id="updateWcsCallbackTaskStatus">
  505. update wcs_callback_task
  506. set status = #{status}
  507. <if test="processStartTime != null">
  508. , process_start_time = #{processStartTime}
  509. </if>
  510. <if test="processEndTime != null">
  511. , process_end_time = #{processEndTime}
  512. </if>
  513. <if test="errorMsg != null">
  514. , error_msg = #{errorMsg}
  515. </if>
  516. where id = #{id}
  517. </update>
  518. <!-- 原子性更新WCS回调任务状态(乐观锁版本,防止重复处理) - AI制作 -->
  519. <update id="updateWcsCallbackTaskStatusWithLock">
  520. UPDATE wcs_callback_task
  521. SET status = #{newStatus},
  522. process_start_time = #{processStartTime}
  523. WHERE id = #{id}
  524. AND status = #{oldStatus}
  525. </update>
  526. <update id="updatePalletWcsLocation" >
  527. update pallet set location_code = #{location},updated_by='wms_sys',updated_time=getdate()
  528. where site = #{site} and pallet_id = #{palletId}
  529. </update>
  530. <!-- 更新WCS回调任务重试次数 - AI制作 -->
  531. <update id="updateWcsCallbackTaskRetryCount">
  532. update wcs_callback_task set retry_count = #{retryCount} where id = #{id}
  533. </update>
  534. <!-- 根据栈板ID和动作类型查找订单任务 - AI制作 -->
  535. <select id="findOrderTasksByPalletAndActionType" 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 pallet_id = #{palletId}
  548. and source_type = #{sourceType}
  549. and status = #{status}
  550. order by created_time desc
  551. </select>
  552. <select id="findOrderTasksByTaskNo" resultType="WmsOrderTask">
  553. select id, site, task_no as taskNo, item_no as itemNo, source_type as sourceType,
  554. source_bill_no as sourceBillNo, source_line_id as sourceLineId, part_no as partNo,
  555. qty, batch_no as batchNo, serial_no as serialNo, from_location as fromLocation,
  556. to_location as toLocation, pallet_id as palletId, agv_code as agvCode,
  557. priority, status, wms_send_time as wmsSendTime, wcs_receive_time as wcsReceiveTime,
  558. start_time as startTime, complete_time as completeTime, error_code as errorCode,
  559. error_msg as errorMsg, created_by as createdBy, created_time as createdTime,
  560. updated_time as updatedTime, wcs_task_id as wcsTaskId, finish_qty as finishQty,
  561. wms_status as wmsStatus
  562. from wms_order_task
  563. where site = #{site}
  564. and task_no=#{taskNo}
  565. order by created_time desc
  566. </select>
  567. <!-- 更新订单任务状态和WMS状态 - AI制作 -->
  568. <update id="updateOrderTaskStatusAndWmsStatus">
  569. update wms_order_task
  570. set status = #{status}, wms_status = #{wmsStatus}
  571. where id = #{id}
  572. </update>
  573. <!-- 根据任务号更新订单任务明细状态 - AI制作 -->
  574. <update id="updateOrderTaskDetailStatusByTaskNo">
  575. update wms_order_task_detail
  576. set status = #{status} ,wms_status = #{wmsStatus}
  577. where task_no = #{taskNo}
  578. </update>
  579. <!-- 查询立库调栈板出库的订单任务列表 - AI制作 -->
  580. <select id="getWcsOrderTaskListForPalletOut" resultType="WmsOrderTask">
  581. select id, site, task_no as taskNo, item_no as itemNo, source_type as sourceType,
  582. source_bill_no as sourceBillNo, source_line_id as sourceLineId, part_no as partNo,
  583. qty, batch_no as batchNo, serial_no as serialNo, from_location as fromLocation,
  584. to_location as toLocation, pallet_id as palletId, agv_code as agvCode,
  585. priority, status, wms_send_time as wmsSendTime, wcs_receive_time as wcsReceiveTime,
  586. start_time as startTime, complete_time as completeTime, error_code as errorCode,
  587. error_msg as errorMsg, created_by as createdBy, created_time as createdTime,
  588. updated_time as updatedTime, wcs_task_id as wcsTaskId, finish_qty as finishQty,
  589. wms_status as wmsStatus
  590. from wms_order_task
  591. where site = #{site}
  592. and status = '已创建'
  593. and source_type like '%出%'
  594. and (wms_status is null or wms_status in ('未执行', '等待重试'))
  595. order by priority desc, created_time asc
  596. </select>
  597. <!-- 更新订单任务错误信息 - AI制作 -->
  598. <update id="updateOrderTaskErrorInfo">
  599. update wms_order_task
  600. set error_code = #{errorCode},
  601. error_msg = #{errorMsg}
  602. where id = #{id}
  603. </update>
  604. <!-- 更新AGV站点状态 - AI制作 -->
  605. <update id="updateAgvStationStatus">
  606. UPDATE agv_station
  607. SET status_db = #{statusDb},
  608. status = #{status}
  609. WHERE station_code = #{stationCode}
  610. </update>
  611. <!-- 获取AGV站点状态 - AI制作 -->
  612. <select id="getAgvStationStatus" resultType="Integer">
  613. SELECT status_db
  614. FROM agv_station
  615. WHERE station_code = #{stationCode}
  616. </select>
  617. <!-- 获取栈板详细信息(包含palletType和autoSort以及托盘类型详情) - AI制作 -->
  618. <select id="getPalletInfoWithTypeDetails" resultType="PalletData">
  619. SELECT
  620. p.site,
  621. p.pallet_id AS palletId,
  622. p.pallet_type AS palletType,
  623. p.pallet_family AS palletFamily,
  624. p.auto_sort AS autoSort,
  625. p.sore_type AS soreType,
  626. p.location_code AS locationCode,
  627. p.wcs_location AS wcsLocation,
  628. pt.type_desc AS typeDesc,
  629. pt.wcs_auto_sort AS wcsAutoSort,
  630. pt.wcs_pallet_type AS wcsPalletType,
  631. pt.wcs_base_pallet_type AS wcsBasePalletType,
  632. pt.wcs_sore_type AS wcsSoreType,
  633. pt.max_layer AS maxLayer,
  634. pf.pallet_family_desc AS palletFamilyDesc
  635. FROM pallet p
  636. LEFT JOIN pallet_type pt ON p.site = pt.site AND p.pallet_type = pt.pallet_type
  637. LEFT JOIN pallet_family pf ON p.site = pf.site AND p.pallet_family = pf.pallet_family
  638. WHERE p.site = #{site}
  639. AND p.pallet_id = #{palletId}
  640. AND p.is_deleted = '0'
  641. </select>
  642. <!-- 更新栈板类型和自动分拣标志 - AI制作 -->
  643. <update id="updatePalletTypeAndAutoSort">
  644. UPDATE pallet
  645. SET pallet_type = #{palletType},
  646. auto_sort = #{autoSort},
  647. updated_time = GETDATE()
  648. WHERE site = #{site}
  649. AND pallet_id = #{palletId}
  650. AND is_deleted = '0'
  651. </update>
  652. </mapper>