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.

838 lines
38 KiB

9 months ago
9 months ago
9 months ago
9 months ago
8 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
8 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
8 months ago
9 months ago
8 months ago
9 months ago
8 months ago
9 months ago
8 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
8 months ago
9 months ago
8 months ago
9 months ago
8 months ago
9 months ago
8 months ago
9 months ago
9 months ago
8 months ago
9 months ago
9 months ago
9 months ago
9 months ago
8 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
8 months ago
8 months ago
9 months ago
8 months ago
8 months ago
8 months ago
9 months ago
9 months ago
9 months ago
8 months ago
9 months ago
8 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
8 months ago
9 months ago
9 months ago
9 months ago
8 months ago
9 months ago
8 months ago
9 months ago
9 months ago
9 months ago
8 months ago
9 months ago
9 months ago
8 months ago
9 months ago
9 months ago
9 months ago
8 months ago
9 months ago
9 months ago
8 months ago
9 months ago
9 months ago
8 months ago
9 months ago
9 months ago
9 months ago
9 months ago
8 months ago
9 months ago
8 months ago
9 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 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 IS NULL OR 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, wcs_flag as wcsFlag, part_no as partNo,
  159. create_date as createDate, create_by as createBy
  160. FROM pallet_detail
  161. WHERE site = #{site} AND serial_no = #{serialNo}
  162. </select>
  163. <select id="getNowStation" resultType="AgvStation">
  164. SELECT TOP 1 b.station_code, b.location_code, b.warehouse_code
  165. FROM pallet a
  166. LEFT JOIN agv_station b ON a.location_code = b.station_code
  167. WHERE a.site = #{site} AND a.pallet_id = #{palletId} AND a.is_deleted = '0'
  168. </select>
  169. <!-- 保存栈板明细 - AI制作 -->
  170. <insert id="savePalletDetail">
  171. INSERT INTO pallet_detail (site, pallet_id, position, layer, serial_no, part_no, create_date, create_by, wcs_flag)
  172. VALUES (#{site}, #{palletId}, #{position}, #{layer}, #{serialNo}, #{partNo}, GETDATE(), #{createBy}, 1)
  173. </insert>
  174. <!-- rqrq - 保存栈板明细(无校验,用于自动拣选,wcs_flag可自定义) -->
  175. <insert id="savePalletDetailNoValidation">
  176. INSERT INTO pallet_detail (site, pallet_id, position, layer, serial_no, part_no, create_date, create_by, wcs_flag)
  177. VALUES (#{site}, #{palletId}, #{position}, #{layer}, #{serialNo}, #{partNo}, GETDATE(), #{createBy}, #{wcsFlag})
  178. </insert>
  179. <!-- 删除栈板明细 - AI制作 -->
  180. <delete id="deletePalletDetail">
  181. DELETE FROM pallet_detail
  182. WHERE site = #{site} AND pallet_id = #{palletId} AND serial_no = #{serialNo}
  183. </delete>
  184. <!-- 根据条码删除栈板明细(不指定栈板ID) - AI制作 -->
  185. <delete id="deletePalletDetailBySerialNo">
  186. DELETE FROM pallet_detail
  187. WHERE site = #{site} AND serial_no = #{serialNo}
  188. </delete>
  189. <!-- 恢复标签到原栈板(分拣撤回) - rqrq -->
  190. <insert id="restorePalletDetail">
  191. -- 恢复到原栈板,保留所有原始字段 - rqrq
  192. INSERT INTO pallet_detail (site, pallet_id, position, layer, serial_no, part_no, create_date, create_by, wcs_flag)
  193. VALUES (#{site}, #{originalPalletId}, #{originalPosition}, #{originalLayer}, #{serialNo},
  194. #{partNo}, #{createDate}, #{createBy}, #{wcsFlag})
  195. </insert>
  196. <!-- 获取指定位置已占用的层数(排除指定标签) - AI制作 -->
  197. <select id="getOccupiedLayersExcludeSerial" resultType="java.lang.Integer">
  198. SELECT DISTINCT layer
  199. FROM pallet_detail
  200. WHERE site = #{site}
  201. AND pallet_id = #{palletId}
  202. AND position = #{position}
  203. AND serial_no != #{excludeSerialNo}
  204. ORDER BY layer
  205. </select>
  206. <update id="updatePalletLocationCode" >
  207. update pallet
  208. set location_code = #{newLocationCode}
  209. where site = #{site}
  210. and pallet_id = #{palletId}
  211. </update>
  212. <!-- 更新栈板明细位置 - AI制作 -->
  213. <update id="updatePalletDetailPosition">
  214. UPDATE pallet_detail
  215. SET position = #{newPosition},
  216. layer = #{newLayer},
  217. wcs_flag = 1
  218. WHERE site = #{site}
  219. AND pallet_id = #{palletId}
  220. AND serial_no = #{serialNo}
  221. </update>
  222. <!-- 更新栈板调用状态 - AI制作 -->
  223. <update id="updatePalletCallingFlag">
  224. UPDATE pallet
  225. SET calling_flag = #{callingFlag},
  226. updated_by = #{updatedBy},
  227. updated_time = GETDATE()
  228. WHERE site = #{site}
  229. AND pallet_id = #{palletId}
  230. </update>
  231. <!-- 检查栈板是否正在被调用 - AI制作 -->
  232. <select id="checkPalletCallingFlag" resultType="java.lang.String">
  233. SELECT calling_flag
  234. FROM pallet
  235. WHERE site = #{site} AND pallet_id = #{palletId} AND is_deleted = '0'
  236. </select>
  237. <!-- 统计栈板明细数量 - AI制作 -->
  238. <select id="countPalletDetails" resultType="java.lang.Integer">
  239. SELECT COUNT(1)
  240. FROM pallet_detail
  241. WHERE site = #{site} AND pallet_id = #{palletId}
  242. </select>
  243. <!-- 更新栈板空栈板标记 - AI制作 -->
  244. <update id="updatePalletEmptyFlag">
  245. UPDATE pallet
  246. SET empty_flag = #{emptyFlag},
  247. updated_by = #{updatedBy},
  248. updated_time = GETDATE()
  249. WHERE site = #{site} AND pallet_id = #{palletId}
  250. </update>
  251. <!-- ==================== 运输任务相关SQL - AI制作 ==================== -->
  252. <!-- 获取AGV站点列表 - AI制作 -->
  253. <select id="getAgvStations" resultType="java.util.Map">
  254. SELECT station_code as stationCode, station_name as stationName,
  255. area_type as areaType, station_area as stationArea,
  256. warehouse_code as warehouseCode, location_code as locationCode,
  257. status_db as statusDb, status, station_id as stationId,
  258. station_type as stationType
  259. FROM agv_station
  260. WHERE active = 'Y'
  261. ORDER BY station_code
  262. </select>
  263. <!-- 获取可用的AGV站点列表(按状态和类型过滤) - AI制作 -->
  264. <select id="getAvailableAgvStations" resultType="AgvStation">
  265. SELECT id, station_code as stationCode, station_name as stationName,
  266. area_type as areaType, station_area as stationArea,
  267. warehouse_code as warehouseCode, location_code as locationCode,
  268. status_db as statusDb, status, station_id as stationId,
  269. station_type as stationType, active, remark,
  270. location_x as locationX, location_y as locationY, location_z as locationZ
  271. FROM agv_station
  272. WHERE active = 'Y'
  273. AND station_type = '正式站点'
  274. <if test="statusDb != null">
  275. AND status_db = #{statusDb}
  276. </if>
  277. ORDER BY station_code
  278. </select>
  279. <!-- 根据目标区域查找第一个空闲站点 - AI制作 -->
  280. <select id="findFirstFreeStationByArea" resultType="java.lang.String">
  281. SELECT TOP 1 station_code
  282. FROM agv_station
  283. WHERE station_area = #{stationArea}
  284. AND status_db = 0
  285. AND active = 'Y'
  286. AND station_type = '正式站点'
  287. ORDER BY station_code
  288. </select>
  289. <!-- 根据起点站点获取可达目标站点 - AI制作 -->
  290. <!-- 注:agv_route_config表已废弃,改为返回所有激活的站点(排除起始站点) -->
  291. <select id="getTargetStationsByStart" resultType="java.util.Map">
  292. SELECT station_code as stationCode, station_name as stationName,
  293. status_db as statusDb, status
  294. FROM agv_station
  295. WHERE active = 'Y'
  296. AND station_code != #{startStation}
  297. ORDER BY station_code
  298. </select>
  299. <!-- 插入单个运输任务 - AI制作 -->
  300. <insert id="insertTransportTask" useGeneratedKeys="true" keyProperty="id">
  301. INSERT INTO wms_transport_task (
  302. site, task_no, item_no, source_type, source_bill_no, source_line_id,
  303. part_no, qty, batch_no, serial_no, from_location, to_location,
  304. pallet_id, agv_code, priority, status, wms_send_time,
  305. created_by, created_time, updated_time,wms_status
  306. ) VALUES (
  307. #{site}, #{taskNo}, #{itemNo}, #{sourceType}, #{sourceBillNo}, #{sourceLineId},
  308. #{partNo}, #{qty}, #{batchNo}, #{serialNo}, #{fromLocation}, #{toLocation},
  309. #{palletId}, #{agvCode}, #{priority}, #{status}, #{wmsSendTime},
  310. #{createdBy}, #{createdTime}, #{updatedTime},N'未执行'
  311. )
  312. </insert>
  313. <insert id="insertOrderTask" useGeneratedKeys="true" keyProperty="id">
  314. INSERT INTO wms_order_task (
  315. site, task_no, item_no, source_type, source_bill_no, source_line_id,
  316. part_no, qty, batch_no, serial_no, from_location, to_location,
  317. pallet_id, agv_code, priority, status, wms_send_time,
  318. created_by, created_time, updated_time
  319. ) VALUES (
  320. #{site}, #{taskNo}, #{itemNo}, #{sourceType}, #{sourceBillNo}, #{sourceLineId},
  321. #{partNo}, #{qty}, #{batchNo}, #{serialNo}, #{fromLocation}, #{toLocation},
  322. #{palletId}, #{agvCode}, #{priority}, #{status}, #{wmsSendTime},
  323. #{createdBy}, #{createdTime}, #{updatedTime}
  324. )
  325. </insert>
  326. <!-- 检查站点是否有栈板 - AI制作 -->
  327. <select id="checkStationHasPallet" resultType="java.lang.Integer">
  328. SELECT COUNT(1)
  329. FROM pallet
  330. WHERE site = #{site}
  331. AND location_code = #{stationCode}
  332. AND is_deleted = '0'
  333. </select>
  334. <select id="getPalletDataByStation" resultType="PalletData">
  335. SELECT TOP 1 pallet_id, location_code, status,pallet_family, pallet_type
  336. FROM pallet
  337. WHERE site = #{site}
  338. AND location_code = #{stationCode}
  339. </select>
  340. <!-- 获取站点的栈板ID - AI制作 -->
  341. <select id="getPalletIdByStation" resultType="java.lang.String">
  342. SELECT TOP 1 pallet_id
  343. FROM pallet
  344. WHERE site = #{site}
  345. AND location_code = #{stationCode}
  346. AND is_deleted = '0'
  347. </select>
  348. <!-- 根据ID查询运输任务 - AI制作 -->
  349. <select id="getTransportTaskById" resultType="WmsTransportTask">
  350. SELECT id, site, task_no as taskNo, item_no as itemNo, source_type as sourceType,
  351. source_bill_no as sourceBillNo, source_line_id as sourceLineId,
  352. part_no as partNo, qty, batch_no as batchNo, serial_no as serialNo,
  353. from_location as fromLocation, to_location as toLocation,
  354. pallet_id as palletId, agv_code as agvCode, priority, status,
  355. wms_send_time as wmsSendTime, wcs_receive_time as wcsReceiveTime,
  356. start_time as startTime, complete_time as completeTime,
  357. error_code as errorCode, error_msg as errorMsg,
  358. created_by as createdBy, created_time as createdTime,
  359. updated_time as updatedTime, wcs_task_id as wcsTaskId,
  360. finish_qty as finishQty, wms_status as wmsStatus
  361. FROM wms_transport_task
  362. WHERE id = #{id}
  363. </select>
  364. <!-- 根据taskNo查询运输任务 - AI制作 -->
  365. <select id="getTransportTaskByTaskNo" resultType="WmsTransportTask">
  366. SELECT id, site, task_no as taskNo, item_no as itemNo, source_type as sourceType,
  367. source_bill_no as sourceBillNo, source_line_id as sourceLineId,
  368. part_no as partNo, qty, batch_no as batchNo, serial_no as serialNo,
  369. from_location as fromLocation, to_location as toLocation,
  370. pallet_id as palletId, agv_code as agvCode, priority, status,
  371. wms_send_time as wmsSendTime, wcs_receive_time as wcsReceiveTime,
  372. start_time as startTime, complete_time as completeTime,
  373. error_code as errorCode, error_msg as errorMsg,
  374. created_by as createdBy, created_time as createdTime,
  375. updated_time as updatedTime, wcs_task_id as wcsTaskId,
  376. finish_qty as finishQty, wms_status as wmsStatus
  377. FROM wms_transport_task
  378. WHERE task_no = #{taskNo}
  379. </select>
  380. <!-- 更新运输任务状态 - AI制作 -->
  381. <update id="updateTransportTaskStatus">
  382. UPDATE wms_transport_task
  383. SET status = #{status}, updated_time = GETDATE()
  384. WHERE id = #{id}
  385. </update>
  386. <!-- 根据taskNo更新运输任务状态 - AI制作 -->
  387. <update id="updateTransportTaskStatusByTaskNo">
  388. UPDATE wms_transport_task
  389. SET status = #{status}, updated_time = GETDATE()
  390. WHERE task_no = #{taskNo}
  391. </update>
  392. <!-- 根据站点代码获取站点信息 - AI制作 -->
  393. <select id="getStationInfoByCode" resultType="java.util.Map">
  394. SELECT station_code as stationCode, station_name as stationName,
  395. warehouse_code as warehouseCode, location_code as locationCode,
  396. area_type as areaType, active, status_db as statusDb, status,
  397. station_id as stationId, station_type as stationType
  398. FROM agv_station
  399. WHERE station_code = #{stationCode}
  400. </select>
  401. <select id="getStationDataByCode" resultType="AgvStation">
  402. SELECT station_code as stationCode, station_name as stationName,
  403. warehouse_code as warehouseCode, location_code as locationCode,
  404. area_type as areaType, active, status_db as statusDb, status,
  405. station_id as stationId, station_type as stationType
  406. FROM agv_station
  407. WHERE station_code = #{stationCode}
  408. </select>
  409. <!-- 更新栈板明细的wcs_flag为0(已传输给WCS) - AI制作 -->
  410. <update id="updatePalletDetailWcsFlag">
  411. UPDATE pallet_detail
  412. SET wcs_flag = 0
  413. WHERE site = #{site}
  414. AND pallet_id = #{palletId}
  415. AND wcs_flag = 1
  416. </update>
  417. <update id="reUpdatePalletDetailWcsFlag">
  418. UPDATE pallet_detail
  419. SET wcs_flag = 1
  420. WHERE site = #{site}
  421. AND pallet_id = #{palletId}
  422. AND wcs_flag = 0
  423. </update>
  424. <select id="getPalletDetailsNewDetail" resultType="PalletDetailData">
  425. 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,
  426. b.part_desc,b.qty,b.batch_no,b.wdr,c.weight,b.length,b.width,c.height,c.is_robot_pick,um_id
  427. ,c.is_commonly_used, CONVERT(varchar(10),isnull( isnull(b.manufacture_date,b.receive_date),getdate()), 23) manufactureDateStr
  428. from pallet_detail a
  429. left join handling_unit b on a.site=b.site and a.serial_no=b.unit_id
  430. left join part_attribute c on a.site=c.site and a.part_no=c.part_no
  431. where a.site=#{site} and a.pallet_id=#{palletId}
  432. and a.wcs_flag = 1
  433. </select>
  434. <update id="updateSOIssueNotifyOrderMaterialListDetailOutWcsFlag">
  435. WITH RankedRecords AS (
  436. SELECT
  437. out_wcs_flag,
  438. ROW_NUMBER() OVER (ORDER BY notify_no DESC) AS rn
  439. FROM SOIssueNotifyOrderMaterialList_detail
  440. WHERE site = #{site}
  441. AND serialNo = #{serialNo}
  442. )
  443. UPDATE RankedRecords
  444. SET out_wcs_flag = 'Y'
  445. WHERE rn = 1;
  446. </update>
  447. <!-- rqrq - 根据task_ref+task_item+serialNo更新SOIssueNotifyOrderMaterialList_detail的out_wcs_flag为Y -->
  448. <update id="updateSOIssueNotifyDetailOutWcsFlagByTask">
  449. UPDATE SOIssueNotifyOrderMaterialList_detail
  450. SET out_wcs_flag = 'Y'
  451. WHERE site = #{site}
  452. AND task_ref = #{taskRef}
  453. AND task_item = #{taskItem}
  454. AND serialNo = #{serialNo}
  455. </update>
  456. <insert id="insertWmsTransportTaskDetail" >
  457. insert into wms_transport_task_detail(
  458. site,task_no,item_no,seq_no,action_type,[comment],from_location,to_location,agv_code,[status],start_time,
  459. error_code,error_msg
  460. ) values (
  461. #{site}, #{taskNo}, #{itemNo}, #{seqNo}, #{actionType}, #{comment}, #{fromLocation}, #{toLocation}, #{agvCode}, #{status}, #{startTime},
  462. #{errorCode}, #{errorMsg}
  463. )
  464. </insert>
  465. <insert id="insertWmsOrderTaskDetail" >
  466. insert into wms_order_task_detail(
  467. site,task_no,item_no,seq_no,action_type,[comment],from_location,to_location,agv_code,[status],start_time,
  468. error_code,error_msg,pallet_id,wms_status
  469. ) values (
  470. #{site}, #{taskNo}, #{itemNo}, #{seqNo}, #{actionType}, #{comment}, #{fromLocation}, #{toLocation}, #{agvCode}, #{status}, #{startTime},
  471. #{errorCode}, #{errorMsg},#{palletId},#{wmsStatus}
  472. )
  473. </insert>
  474. <select id="getMaxSeqNoForTaskDetail" resultType="Integer">
  475. select isnull(max(seq_no),0)+1 from wms_transport_task_detail
  476. where task_no=#{taskNo} and site=#{site} and item_no= 1
  477. </select>
  478. <update id="updateTransportTaskStatusForSiteAndNo">
  479. update wms_transport_task set [status]=#{status} where site=#{site} and task_no=#{taskNo}
  480. </update>
  481. <update id="updateTransportTaskDetailStatusForId">
  482. update wms_transport_task_detail set [status]=#{status} where id=#{id}
  483. </update>
  484. <select id="getTransportTaskDetailListWithStatus" resultType="WmsTransportTaskDetail">
  485. select id,site,task_no as taskNo,item_no as itemNo,seq_no as seqNo,action_type as actionType,[comment],from_location as fromLocation,
  486. to_location as toLocation,agv_code as agvCode,[status],start_time as startTime,
  487. error_code as errorCode,error_msg as errorMsg
  488. from wms_transport_task_detail
  489. where site = #{site} and status in ('回调处理失败','已录入')
  490. </select>
  491. <!-- 查询指定状态的订单任务明细列表 - AI制作 -->
  492. <select id="getOrderTaskDetailListWithStatus" resultType="WmsOrderTaskDetail">
  493. select id,site,task_no as taskNo,item_no as itemNo,seq_no as seqNo,action_type as actionType,[comment],from_location as fromLocation,
  494. to_location as toLocation,agv_code as agvCode,[status],start_time as startTime,
  495. error_code as errorCode,error_msg as errorMsg
  496. from wms_order_task_detail
  497. where site = #{site} and status in ('处理失败','已录入')
  498. </select>
  499. <!-- 根据ID更新订单任务明细状态 - AI制作 -->
  500. <update id="updateOrderTaskDetailStatusForId">
  501. update wms_order_task_detail set [status]=#{status} where id=#{id}
  502. </update>
  503. <!-- 根据任务号获取栈板ID - AI制作 -->
  504. <select id="getPalletIdByOrderTaskNo" resultType="String">
  505. select pallet_id from wms_order_task where task_no = #{taskNo}
  506. </select>
  507. <!-- 根据栈板号和任务类型查找订单任务 - AI制作 -->
  508. <select id="findOrderTaskByPalletAndType" resultType="WmsOrderTask">
  509. select top 1 id, site, task_no as taskNo, item_no as itemNo, source_type as sourceType,
  510. source_bill_no as sourceBillNo, source_line_id as sourceLineId, part_no as partNo,
  511. qty, batch_no as batchNo, serial_no as serialNo, from_location as fromLocation,
  512. to_location as toLocation, pallet_id as palletId, agv_code as agvCode,
  513. priority, status, wms_send_time as wmsSendTime, wcs_receive_time as wcsReceiveTime,
  514. start_time as startTime, complete_time as completeTime, error_code as errorCode,
  515. error_msg as errorMsg, created_by as createdBy, created_time as createdTime,
  516. updated_time as updatedTime, wcs_task_id as wcsTaskId, finish_qty as finishQty,
  517. wms_status as wmsStatus
  518. from wms_order_task
  519. where site = #{site}
  520. and pallet_id = #{palletId}
  521. and source_type = #{sourceType}
  522. and status in ('已创建', '执行中', '已下发')
  523. order by created_time desc
  524. </select>
  525. <!-- 获取订单任务明细的最大序号 - AI制作 -->
  526. <select id="getMaxSeqNoForOrderTaskDetail" resultType="Integer">
  527. select isnull(max(seq_no),0)+1 from wms_order_task_detail
  528. where task_no=#{taskNo} and site=#{site}
  529. </select>
  530. <!-- 插入WCS回调任务 - AI制作 -->
  531. <insert id="insertWcsCallbackTask" useGeneratedKeys="true" keyProperty="id">
  532. INSERT INTO wcs_callback_task (
  533. site, pallet_id, trans_type_desc, to_warehouse_id, to_location_id,
  534. status, created_time, retry_count, remark, task_no, item_no, to_station
  535. ) VALUES (
  536. #{site}, #{palletId}, #{transTypeDesc}, #{toWarehouseId}, #{toLocationId},
  537. #{status}, #{createdTime}, #{retryCount}, #{remark}, #{taskNo}, #{itemNo}, #{toStation}
  538. )
  539. </insert>
  540. <!-- 查询指定状态的WCS回调任务列表(含超时恢复机制) - AI制作 -->
  541. <select id="getWcsCallbackTaskListWithStatus" resultType="WcsCallbackTask">
  542. select id, site, pallet_id as palletId, trans_type_desc as transTypeDesc,
  543. to_warehouse_id as toWarehouseId, to_location_id as toLocationId,
  544. status, created_time as createdTime, process_start_time as processStartTime,
  545. process_end_time as processEndTime, error_msg as errorMsg,
  546. retry_count as retryCount, remark,task_no,item_no,to_station
  547. from wcs_callback_task
  548. where site = #{site}
  549. and (
  550. status in ('已录入', '处理失败')
  551. or (status = '处理中' and process_start_time &lt; DATEADD(MINUTE, -10, GETDATE()))
  552. )
  553. and (retry_count is null or retry_count &lt; 3)
  554. order by created_time
  555. </select>
  556. <!-- 更新WCS回调任务状态 - AI制作 -->
  557. <update id="updateWcsCallbackTaskStatus">
  558. update wcs_callback_task
  559. set status = #{status}
  560. <if test="processStartTime != null">
  561. , process_start_time = #{processStartTime}
  562. </if>
  563. <if test="processEndTime != null">
  564. , process_end_time = #{processEndTime}
  565. </if>
  566. <if test="errorMsg != null">
  567. , error_msg = #{errorMsg}
  568. </if>
  569. where id = #{id}
  570. </update>
  571. <!-- 原子性更新WCS回调任务状态(乐观锁版本,防止重复处理) - AI制作 -->
  572. <update id="updateWcsCallbackTaskStatusWithLock">
  573. UPDATE wcs_callback_task
  574. SET status = #{newStatus},
  575. process_start_time = #{processStartTime}
  576. WHERE id = #{id}
  577. AND status = #{oldStatus}
  578. </update>
  579. <update id="updatePalletWcsLocation" >
  580. update pallet set wcs_location = #{location},updated_by='wms_sys',updated_time=getdate()
  581. where site = #{site} and pallet_id = #{palletId}
  582. </update>
  583. <!-- 更新WCS回调任务重试次数 - AI制作 -->
  584. <update id="updateWcsCallbackTaskRetryCount">
  585. update wcs_callback_task set retry_count = #{retryCount} where id = #{id}
  586. </update>
  587. <!-- 根据栈板ID和动作类型查找订单任务 - AI制作 -->
  588. <select id="findOrderTasksByPalletAndActionType" resultType="WmsOrderTask">
  589. select id, site, task_no as taskNo, item_no as itemNo, source_type as sourceType,
  590. source_bill_no as sourceBillNo, source_line_id as sourceLineId, part_no as partNo,
  591. qty, batch_no as batchNo, serial_no as serialNo, from_location as fromLocation,
  592. to_location as toLocation, pallet_id as palletId, agv_code as agvCode,
  593. priority, status, wms_send_time as wmsSendTime, wcs_receive_time as wcsReceiveTime,
  594. start_time as startTime, complete_time as completeTime, error_code as errorCode,
  595. error_msg as errorMsg, created_by as createdBy, created_time as createdTime,
  596. updated_time as updatedTime, wcs_task_id as wcsTaskId, finish_qty as finishQty,
  597. wms_status as wmsStatus
  598. from wms_order_task
  599. <where>
  600. and site = #{site}
  601. and pallet_id = #{palletId}
  602. <if test="sourceType != null and sourceType != ''">
  603. and source_type = #{sourceType}
  604. </if>
  605. and status = #{status}
  606. </where>
  607. order by created_time desc
  608. </select>
  609. <select id="findOrderTasksByTaskNo" resultType="WmsOrderTask">
  610. select id, site, task_no as taskNo, item_no as itemNo, source_type as sourceType,
  611. source_bill_no as sourceBillNo, source_line_id as sourceLineId, part_no as partNo,
  612. qty, batch_no as batchNo, serial_no as serialNo, from_location as fromLocation,
  613. to_location as toLocation, pallet_id as palletId, agv_code as agvCode,
  614. priority, status, wms_send_time as wmsSendTime, wcs_receive_time as wcsReceiveTime,
  615. start_time as startTime, complete_time as completeTime, error_code as errorCode,
  616. error_msg as errorMsg, created_by as createdBy, created_time as createdTime,
  617. updated_time as updatedTime, wcs_task_id as wcsTaskId, finish_qty as finishQty,
  618. wms_status as wmsStatus
  619. from wms_order_task
  620. where site = #{site}
  621. and task_no=#{taskNo}
  622. order by created_time desc
  623. </select>
  624. <select id="findOrderTasksByTaskNoItem" resultType="WmsOrderTask">
  625. select id, site, task_no as taskNo, item_no as itemNo, source_type as sourceType,
  626. source_bill_no as sourceBillNo, source_line_id as sourceLineId, part_no as partNo,
  627. qty, batch_no as batchNo, serial_no as serialNo, from_location as fromLocation,
  628. to_location as toLocation, pallet_id as palletId, agv_code as agvCode,
  629. priority, status, wms_send_time as wmsSendTime, wcs_receive_time as wcsReceiveTime,
  630. start_time as startTime, complete_time as completeTime, error_code as errorCode,
  631. error_msg as errorMsg, created_by as createdBy, created_time as createdTime,
  632. updated_time as updatedTime, wcs_task_id as wcsTaskId, finish_qty as finishQty,
  633. wms_status as wmsStatus
  634. from wms_order_task
  635. where site = #{site}
  636. and task_no=#{taskNo}
  637. and item_no=#{itemNo}
  638. order by created_time desc
  639. </select>
  640. <!-- 更新订单任务状态和WMS状态 - AI制作 -->
  641. <update id="updateOrderTaskStatusAndWmsStatus">
  642. update wms_order_task
  643. set status = #{status}, wms_status = #{wmsStatus}
  644. where id = #{id}
  645. </update>
  646. <!-- 根据任务号更新订单任务明细状态 - AI制作 -->
  647. <update id="updateOrderTaskDetailStatusByTaskNo">
  648. update wms_order_task_detail
  649. set status = #{status} ,wms_status = #{wmsStatus}
  650. where task_no = #{taskNo}
  651. </update>
  652. <update id="updateOrderTaskDetailStatusByTaskNoPalletId">
  653. update wms_order_task_detail
  654. set status = #{status} ,wms_status = #{wmsStatus}
  655. where task_no = #{taskNo} and site=#{site} and pallet_id=#{palletId}
  656. </update>
  657. <!-- 查询立库调栈板出库的订单任务列表 - AI制作 -->
  658. <select id="getWcsOrderTaskListForPalletOut" resultType="WmsOrderTask">
  659. select id, site, task_no as taskNo, item_no as itemNo, source_type as sourceType,
  660. source_bill_no as sourceBillNo, source_line_id as sourceLineId, part_no as partNo,
  661. qty, batch_no as batchNo, serial_no as serialNo, from_location as fromLocation,
  662. to_location as toLocation, pallet_id as palletId, agv_code as agvCode,
  663. priority, status, wms_send_time as wmsSendTime, wcs_receive_time as wcsReceiveTime,
  664. start_time as startTime, complete_time as completeTime, error_code as errorCode,
  665. error_msg as errorMsg, created_by as createdBy, created_time as createdTime,
  666. updated_time as updatedTime, wcs_task_id as wcsTaskId, finish_qty as finishQty,
  667. wms_status as wmsStatus
  668. from wms_order_task
  669. where site = #{site}
  670. and status = '已创建'
  671. and source_type like '%栈板出库%'
  672. and (wms_status is null or wms_status in ('未执行', '等待重试'))
  673. order by priority desc, created_time asc
  674. </select>
  675. <!-- 更新订单任务错误信息 - AI制作 -->
  676. <update id="updateOrderTaskErrorInfo">
  677. update wms_order_task
  678. set error_code = #{errorCode},
  679. error_msg = #{errorMsg}
  680. where id = #{id}
  681. </update>
  682. <!-- 更新AGV站点状态 - AI制作 -->
  683. <update id="updateAgvStationStatus">
  684. UPDATE agv_station
  685. SET status_db = #{statusDb},
  686. status = #{status}
  687. WHERE station_code = #{stationCode}
  688. </update>
  689. <!-- 获取AGV站点状态 - AI制作 -->
  690. <select id="getAgvStationStatus" resultType="Integer">
  691. SELECT status_db
  692. FROM agv_station
  693. WHERE station_code = #{stationCode}
  694. </select>
  695. <!-- 获取栈板详细信息(包含palletType和autoSort以及托盘类型详情) - AI制作 -->
  696. <select id="getPalletInfoWithTypeDetails" resultType="PalletData">
  697. SELECT
  698. p.site,
  699. p.pallet_id AS palletId,
  700. p.pallet_type AS palletType,
  701. p.pallet_family AS palletFamily,
  702. p.auto_sort AS autoSort,
  703. p.sore_type AS soreType,
  704. p.location_code AS locationCode,
  705. p.wcs_location AS wcsLocation,
  706. pt.type_desc AS typeDesc,
  707. pt.wcs_auto_sort AS wcsAutoSort,
  708. pt.wcs_pallet_type AS wcsPalletType,
  709. pt.wcs_base_pallet_type AS wcsBasePalletType,
  710. pt.wcs_sore_type AS wcsSoreType,
  711. pt.max_layer AS maxLayer,
  712. pf.pallet_family_desc AS palletFamilyDesc
  713. FROM pallet p
  714. LEFT JOIN pallet_type pt ON p.site = pt.site AND p.pallet_type = pt.pallet_type
  715. LEFT JOIN pallet_family pf ON p.site = pf.site AND p.pallet_family = pf.pallet_family
  716. WHERE p.site = #{site}
  717. AND p.pallet_id = #{palletId}
  718. AND p.is_deleted = '0'
  719. </select>
  720. <!-- 更新栈板类型、自动分拣标志和存储类型 - AI制作/rqrq -->
  721. <update id="updatePalletTypeAndAutoSort">
  722. UPDATE pallet
  723. SET pallet_type = #{palletType},
  724. auto_sort = #{autoSort},
  725. sore_type = #{soreType},
  726. updated_time = GETDATE()
  727. WHERE site = #{site}
  728. AND pallet_id = #{palletId}
  729. AND is_deleted = '0'
  730. </update>
  731. <!-- 获取指定层已占用的位置列表 - rqrq -->
  732. <select id="getOccupiedPositionsByLayer" resultType="java.lang.String">
  733. SELECT DISTINCT position
  734. FROM pallet_detail
  735. WHERE site = #{site}
  736. AND pallet_id = #{palletId}
  737. AND layer = #{layer}
  738. ORDER BY position
  739. </select>
  740. <!-- rqrq - 插入WCS回调栈板扫描记录 -->
  741. <insert id="insertCallbackPalletScan" parameterType="com.gaotao.modules.automatedWarehouse.entity.WcsCallbackPalletScan" useGeneratedKeys="true" keyProperty="callback.id">
  742. INSERT INTO wcs_callback_pallet_scan (
  743. site, pallet_id, task_no, item_no,
  744. wcs_scan_time, wcs_barcode_list, wcs_total_quantity, sore_type,
  745. process_status, retry_count,
  746. created_at, updated_at, json_str,action_type
  747. ) VALUES (
  748. #{callback.site}, #{callback.palletId}, #{callback.taskNo}, #{callback.itemNo},
  749. #{callback.wcsScanTime}, #{callback.wcsBarcodeList}, #{callback.wcsTotalQuantity}, #{callback.soreType},
  750. #{callback.processStatus}, #{callback.retryCount},
  751. GETDATE(), GETDATE(), #{callback.jsonStr}, #{callback.actionType}
  752. )
  753. </insert>
  754. <select id="getPalletType" resultType="PalletType">
  755. 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
  756. FROM pallet_type WHERE site = #{site} AND pallet_type = #{palletType}
  757. </select>
  758. </mapper>