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.

1392 lines
59 KiB

4 months ago
4 months ago
3 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
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
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
3 months ago
3 months ago
4 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 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
3 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
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
3 months ago
3 months ago
4 months ago
4 months ago
4 months ago
3 months ago
4 months ago
4 months ago
3 months ago
3 months ago
4 months ago
3 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
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
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
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
3 months ago
4 months ago
4 months ago
4 months ago
3 months ago
4 months ago
3 months ago
3 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
4 months ago
3 months ago
4 months ago
3 months ago
4 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 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. <!-- rqrq - 增强查询逻辑:支持栈板码查询,有物料则返回明细,无物料则只返回栈板 -->
  5. <select id="palletListForPartNo" resultType="WmsLabelAndPalletData">
  6. <choose>
  7. <!-- 如果只有栈板码查询(无物料编码),只返回栈板信息,不显示物料明细 - rqrq -->
  8. <when test="palletId != null and palletId != '' and (partNo == null or partNo == '')">
  9. SELECT DISTINCT
  10. c.site,
  11. c.pallet_id AS palletId,
  12. NULL AS partNo,
  13. NULL AS qty,
  14. NULL AS batchNo,
  15. NULL AS wdr,
  16. NULL AS expiredDate
  17. FROM pallet c
  18. WHERE c.site = #{site}
  19. AND c.pallet_id = #{palletId}
  20. AND c.is_deleted = '0'
  21. AND (c.calling_flag IS NULL OR c.calling_flag != 'Y')
  22. AND c.wcs_location IS NOT NULL
  23. </when>
  24. <!-- 如果有物料编码,返回明细数据(关联handling_unit查出qty、wdr、batch_no、expired_date)- rqrq -->
  25. <otherwise>
  26. SELECT
  27. b.site,
  28. a.pallet_id AS palletId,
  29. a.part_no AS partNo,
  30. b.qty,
  31. b.batch_no AS batchNo,
  32. b.wdr,
  33. CONVERT(VARCHAR(10), b.expired_date, 120) AS expiredDate
  34. FROM pallet_detail a
  35. INNER JOIN handling_unit b ON a.site = b.site AND a.serial_no = b.unit_id
  36. INNER JOIN pallet c ON a.site = c.site AND a.pallet_id = c.pallet_id
  37. <where>
  38. AND c.is_deleted = '0'
  39. AND (c.calling_flag IS NULL OR c.calling_flag != 'Y')
  40. AND a.site = #{site}
  41. AND (b.reserve_flag IS NULL OR b.reserve_flag != 'Y')
  42. AND b.in_stock_flag = 'Y'
  43. AND c.wcs_location IS NOT NULL
  44. <if test="warehouseId != null and warehouseId != ''">
  45. AND b.warehouse_id = #{warehouseId}
  46. </if>
  47. <if test="partNo != null and partNo != ''">
  48. AND a.part_no = #{partNo}
  49. </if>
  50. <if test="palletId != null and palletId != ''">
  51. AND a.pallet_id = #{palletId}
  52. </if>
  53. <if test="serialNo != null and serialNo != ''">
  54. AND a.serial_no = #{serialNo}
  55. </if>
  56. <if test="batchNo != null and batchNo != ''">
  57. AND b.batch_no = #{batchNo}
  58. </if>
  59. </where>
  60. ORDER BY a.pallet_id, a.part_no
  61. </otherwise>
  62. </choose>
  63. </select>
  64. <select id="checkPalletTask" resultType="WmsTransportTask">
  65. select id,site,task_no,source_type,source_bill_no,source_line_id,part_no,qty,batch_no,serial_no,from_location,to_location,
  66. pallet_id,agv_code,priority,[status],wms_send_time,wcs_receive_time,start_time,complete_time,error_code,error_msg,
  67. created_by,created_time,updated_time,wcs_task_id,finish_qty,wms_status
  68. from wms_transport_task
  69. where site = #{site}
  70. and pallet_id = #{palletId}
  71. and status not in ('结束','取消','失败')
  72. </select>
  73. <insert id="batchSaveTransportTask">
  74. INSERT INTO wms_transport_task (
  75. site, task_no, source_type, source_bill_no, source_line_id, part_no, qty,
  76. batch_no, serial_no, from_location, to_location, pallet_id, agv_code,
  77. priority, status, wms_send_time,
  78. error_code, error_msg, created_by, created_time, wcs_task_id,
  79. finish_qty, wms_status,item_no
  80. ) VALUES
  81. <foreach collection="list" item="item" separator=",">
  82. (
  83. #{item.site}, #{item.taskNo}, #{item.sourceType}, #{item.sourceBillNo}, #{item.sourceLineId},
  84. #{item.partNo}, #{item.qty}, #{item.batchNo}, #{item.serialNo}, #{item.fromLocation},
  85. #{item.toLocation}, #{item.palletId}, #{item.agvCode}, #{item.priority}, #{item.status},
  86. #{item.wmsSendTime},
  87. #{item.errorCode}, #{item.errorMsg}, #{item.createdBy}, #{item.createdTime},
  88. #{item.wcsTaskId}, #{item.finishQty}, '未执行', #{item.itemNo}
  89. )
  90. </foreach>
  91. </insert>
  92. <insert id="batchSaveOrderTask">
  93. INSERT INTO wms_order_task (
  94. site, task_no, source_type, source_bill_no, source_line_id, part_no, qty,
  95. batch_no, serial_no, from_location, to_location, pallet_id, agv_code,
  96. priority, status, wms_send_time,
  97. error_code, error_msg, created_by, created_time, wcs_task_id,
  98. finish_qty, wms_status,item_no
  99. ) VALUES
  100. <foreach collection="list" item="item" separator=",">
  101. (
  102. #{item.site}, #{item.taskNo}, #{item.sourceType}, #{item.sourceBillNo}, #{item.sourceLineId},
  103. #{item.partNo}, #{item.qty}, #{item.batchNo}, #{item.serialNo}, #{item.fromLocation},
  104. #{item.toLocation}, #{item.palletId}, #{item.agvCode}, #{item.priority}, #{item.status},
  105. #{item.wmsSendTime},
  106. #{item.errorCode}, #{item.errorMsg}, #{item.createdBy}, #{item.createdTime},
  107. #{item.wcsTaskId}, #{item.finishQty}, #{item.wmsStatus}, #{item.itemNo}
  108. )
  109. </foreach>
  110. </insert>
  111. <insert id="batchSaveOrderTaskDetail">
  112. INSERT INTO wms_order_task_detail (
  113. site,task_no,item_no,seq_no,action_type,[comment],from_location,to_location,agv_code,[status],start_time,
  114. error_code,error_msg,pallet_id,wms_status
  115. ) VALUES
  116. <foreach collection="list" item="item" separator=",">
  117. (
  118. #{item.site}, #{item.taskNo}, #{item.itemNo}, #{item.seqNo}, #{item.actionType}, #{item.comment},
  119. #{item.fromLocation}, #{item.toLocation}, #{item.agvCode}, #{item.status}, getdate(),
  120. #{item.errorCode}, #{item.errorMsg}, #{item.palletId}, #{item.wmsStatus}
  121. )
  122. </foreach>
  123. </insert>
  124. <!-- ==================== 打托相关SQL - AI制作 ==================== -->
  125. <!-- 检查栈板是否存在并获取栈板信息 - AI制作 -->
  126. <select id="getPalletInfo" resultType="java.util.Map">
  127. SELECT pallet_id, pallet_type, status, location_code, site, calling_flag
  128. FROM pallet
  129. WHERE site = #{site} AND pallet_id = #{palletId} AND is_deleted = '0'
  130. </select>
  131. <!-- 获取栈板类型的位置信息 - AI制作 -->
  132. <select id="getPalletTypePositions" resultType="java.lang.String">
  133. SELECT position
  134. FROM pallet_type_area
  135. WHERE site = #{site} AND pallet_type = #{palletType}
  136. ORDER BY position
  137. </select>
  138. <!-- 获取栈板明细 - AI制作 -->
  139. <select id="getPalletDetails" resultType="java.util.Map">
  140. SELECT a.site, a.pallet_id as palletId, a.position, a.layer, a.serial_no as serialNo, a.part_no as partNo,
  141. a.create_date as createDate, a.create_by as createBy
  142. FROM pallet_detail a
  143. WHERE a.site = #{site} AND a.pallet_id = #{palletId}
  144. <if test="position != null and position != ''">
  145. AND a.position = #{position}
  146. </if>
  147. <if test="layer != null">
  148. AND a.layer = #{layer}
  149. </if>
  150. ORDER BY a.position, a.layer, a.serial_no
  151. </select>
  152. <select id="getPalletDetailsData" resultType="PalletDetailData">
  153. SELECT a.site, a.pallet_id as palletId, a.position, a.layer, a.serial_no as serialNo, a.part_no as partNo,
  154. a.create_date as createDate, a.create_by as createBy,b.warehouse_id,b.location_id
  155. FROM pallet_detail a left join handling_unit b on a.site = b.site and a.serial_no = b.unit_id
  156. WHERE a.site = #{site} AND a.pallet_id = #{palletId}
  157. </select>
  158. <select id="getPalletTypeInfoByPallet" resultType="PalletType">
  159. select b.site,b.pallet_type,b.type_desc,b.active,b.remark,b.pallet_family,b.wcs_pallet_type,b.wcs_base_pallet_type,b.wcs_auto_sort,
  160. b.wcs_sore_type,b.max_layer
  161. from pallet a left join pallet_type b on a.pallet_type=b.pallet_type and a.site=b.site
  162. where a.pallet_id=#{palletId} and a.site=#{site}
  163. </select>
  164. <!-- 根据位置获取层数 - AI制作 -->
  165. <select id="getLayersByPosition" resultType="java.lang.Integer">
  166. SELECT DISTINCT layer
  167. FROM pallet_detail
  168. WHERE site = #{site} AND pallet_id = #{palletId} AND position = #{position}
  169. ORDER BY layer
  170. </select>
  171. <!-- 验证标签 - AI制作 -->
  172. <select id="validateLabel" resultType="java.util.Map">
  173. SELECT site, unit_id as serialNo, part_no as partNo, qty, in_stock_flag as inStockFlag,
  174. unit_type as labelType, batch_no as batchNo, warehouse_id as warehouseId,
  175. location_id as locationId, remark, tid, epc
  176. FROM handling_unit
  177. WHERE site = #{site} AND unit_id = #{serialNo}
  178. </select>
  179. <!-- 获取栈板类型区域信息(用于校验层级规则) - AI制作 -->
  180. <select id="getPalletTypeAreaInfo" resultType="java.util.Map">
  181. SELECT site, pallet_type as palletType, position, position_desc as positionDesc
  182. FROM pallet_type_area
  183. WHERE site = #{site} AND pallet_type = #{palletType}
  184. ORDER BY position
  185. </select>
  186. <!-- 获取栈板指定层的明细统计 - AI制作 -->
  187. <select id="getPalletLayerStatistics" resultType="java.util.Map">
  188. SELECT position, COUNT(*) as count
  189. FROM pallet_detail
  190. WHERE site = #{site} AND pallet_id = #{palletId} AND layer = #{layer}
  191. GROUP BY position
  192. </select>
  193. <!-- 根据标签查找栈板信息 - AI制作 -->
  194. <select id="findPalletByLabel" resultType="java.util.Map">
  195. SELECT pallet_id as palletId, position, layer, wcs_flag as wcsFlag, part_no as partNo,
  196. create_date as createDate, create_by as createBy
  197. FROM pallet_detail
  198. WHERE site = #{site} AND serial_no = #{serialNo}
  199. </select>
  200. <select id="getNowStation" resultType="AgvStation">
  201. SELECT TOP 1 b.station_code, b.location_code, b.warehouse_code
  202. FROM pallet a
  203. LEFT JOIN agv_station b ON a.location_code = b.station_code
  204. WHERE a.site = #{site} AND a.pallet_id = #{palletId} AND a.is_deleted = '0'
  205. </select>
  206. <!-- 保存栈板明细 - AI制作 -->
  207. <insert id="savePalletDetail">
  208. INSERT INTO pallet_detail (site, pallet_id, position, layer, serial_no, part_no, create_date, create_by, wcs_flag)
  209. VALUES (#{site}, #{palletId}, #{position}, #{layer}, #{serialNo}, #{partNo}, GETDATE(), #{createBy}, 1)
  210. </insert>
  211. <!-- rqrq - 保存栈板明细(无校验,用于自动拣选,wcs_flag可自定义) -->
  212. <insert id="savePalletDetailNoValidation">
  213. INSERT INTO pallet_detail (site, pallet_id, position, layer, serial_no, part_no, create_date, create_by, wcs_flag)
  214. VALUES (#{site}, #{palletId}, #{position}, #{layer}, #{serialNo}, #{partNo}, GETDATE(), #{createBy}, #{wcsFlag})
  215. </insert>
  216. <!-- 删除栈板明细 - AI制作 -->
  217. <delete id="deletePalletDetail">
  218. DELETE FROM pallet_detail
  219. WHERE site = #{site} AND pallet_id = #{palletId} AND serial_no = #{serialNo}
  220. </delete>
  221. <!-- 根据条码删除栈板明细(不指定栈板ID) - AI制作 -->
  222. <delete id="deletePalletDetailBySerialNo">
  223. DELETE FROM pallet_detail
  224. WHERE site = #{site} AND serial_no = #{serialNo}
  225. </delete>
  226. <!-- 恢复标签到原栈板(分拣撤回) - rqrq -->
  227. <insert id="restorePalletDetail">
  228. -- 恢复到原栈板,保留所有原始字段 - rqrq
  229. INSERT INTO pallet_detail (site, pallet_id, position, layer, serial_no, part_no, create_date, create_by, wcs_flag)
  230. VALUES (#{site}, #{originalPalletId}, #{originalPosition}, #{originalLayer}, #{serialNo},
  231. #{partNo}, #{createDate}, #{createBy}, #{wcsFlag})
  232. </insert>
  233. <!-- 获取指定位置已占用的层数(排除指定标签) - AI制作 -->
  234. <select id="getOccupiedLayersExcludeSerial" resultType="java.lang.Integer">
  235. SELECT DISTINCT layer
  236. FROM pallet_detail
  237. WHERE site = #{site}
  238. AND pallet_id = #{palletId}
  239. AND position = #{position}
  240. AND serial_no != #{excludeSerialNo}
  241. ORDER BY layer
  242. </select>
  243. <update id="updatePalletLocationCode" >
  244. update pallet
  245. set location_code = #{newLocationCode}
  246. where site = #{site}
  247. and pallet_id = #{palletId}
  248. </update>
  249. <!-- 更新栈板明细位置 - AI制作 -->
  250. <update id="updatePalletDetailPosition">
  251. UPDATE pallet_detail
  252. SET position = #{newPosition},
  253. layer = #{newLayer},
  254. wcs_flag = 1
  255. WHERE site = #{site}
  256. AND pallet_id = #{palletId}
  257. AND serial_no = #{serialNo}
  258. </update>
  259. <!-- 更新栈板调用状态 - AI制作 -->
  260. <update id="updatePalletCallingFlag">
  261. UPDATE pallet
  262. SET calling_flag = #{callingFlag},
  263. updated_by = #{updatedBy},
  264. updated_time = GETDATE()
  265. WHERE site = #{site}
  266. AND pallet_id = #{palletId}
  267. </update>
  268. <!-- 检查栈板是否正在被调用 - AI制作 -->
  269. <select id="checkPalletCallingFlag" resultType="java.lang.String">
  270. SELECT calling_flag
  271. FROM pallet
  272. WHERE site = #{site} AND pallet_id = #{palletId} AND is_deleted = '0'
  273. </select>
  274. <!-- 统计栈板明细数量 - AI制作 -->
  275. <select id="countPalletDetails" resultType="java.lang.Integer">
  276. SELECT COUNT(1)
  277. FROM pallet_detail
  278. WHERE site = #{site} AND pallet_id = #{palletId}
  279. </select>
  280. <!-- 更新栈板空栈板标记 - AI制作 -->
  281. <update id="updatePalletEmptyFlag">
  282. UPDATE pallet
  283. SET empty_flag = #{emptyFlag},
  284. updated_by = #{updatedBy},
  285. updated_time = GETDATE()
  286. WHERE site = #{site} AND pallet_id = #{palletId}
  287. </update>
  288. <!-- ==================== 运输任务相关SQL - AI制作 ==================== -->
  289. <!-- 获取AGV站点列表 - AI制作 -->
  290. <select id="getAgvStations" resultType="java.util.Map">
  291. SELECT station_code as stationCode, station_name as stationName,
  292. area_type as areaType, station_area as stationArea,
  293. warehouse_code as warehouseCode, location_code as locationCode,
  294. status_db as statusDb, status, station_id as stationId,
  295. station_type as stationType
  296. FROM agv_station
  297. WHERE active = 'Y'
  298. ORDER BY station_code
  299. </select>
  300. <!-- 获取可用的AGV站点列表(按状态和类型过滤) - AI制作 -->
  301. <select id="getAvailableAgvStations" resultType="AgvStation">
  302. SELECT id, station_code as stationCode, station_name as stationName,
  303. area_type as areaType, station_area as stationArea,
  304. warehouse_code as warehouseCode, location_code as locationCode,
  305. status_db as statusDb, status, station_id as stationId,
  306. station_type as stationType, active, remark,
  307. location_x as locationX, location_y as locationY, location_z as locationZ
  308. FROM agv_station
  309. WHERE active = 'Y'
  310. AND station_type = '正式站点'
  311. <if test="statusDb != null">
  312. AND status_db = #{statusDb}
  313. </if>
  314. ORDER BY station_code
  315. </select>
  316. <!-- 根据目标区域查找第一个空闲站点 - AI制作 -->
  317. <select id="findFirstFreeStationByArea" resultType="java.lang.String">
  318. SELECT TOP 1 station_code
  319. FROM agv_station
  320. WHERE station_area = #{stationArea}
  321. AND status_db = 0
  322. AND active = 'Y'
  323. AND station_type = '正式站点'
  324. ORDER BY station_code
  325. </select>
  326. <!-- 根据起点站点获取可达目标站点 - AI制作 -->
  327. <!-- 注:agv_route_config表已废弃,改为返回所有激活的站点(排除起始站点) -->
  328. <select id="getTargetStationsByStart" resultType="java.util.Map">
  329. SELECT station_code as stationCode, station_name as stationName,
  330. status_db as statusDb, status
  331. FROM agv_station
  332. WHERE active = 'Y'
  333. AND station_code != #{startStation}
  334. ORDER BY station_code
  335. </select>
  336. <!-- 插入单个运输任务 - AI制作 -->
  337. <insert id="insertTransportTask" useGeneratedKeys="true" keyProperty="id">
  338. INSERT INTO wms_transport_task (
  339. site, task_no, item_no, source_type, source_bill_no, source_line_id,
  340. part_no, qty, batch_no, serial_no, from_location, to_location, to_area,
  341. pallet_id, agv_code, priority, status, wms_send_time,
  342. created_by, created_time, updated_time, wms_status, pallet_type,wcs_task_id
  343. ) VALUES (
  344. #{site}, #{taskNo}, #{itemNo}, #{sourceType}, #{sourceBillNo}, #{sourceLineId},
  345. #{partNo}, #{qty}, #{batchNo}, #{serialNo}, #{fromLocation}, #{toLocation}, #{toArea},
  346. #{palletId}, #{agvCode}, #{priority}, #{status}, #{wmsSendTime},
  347. #{createdBy}, #{createdTime}, #{updatedTime}, N'未执行', #{palletType},#{wcsTaskId}
  348. )
  349. </insert>
  350. <insert id="insertOrderTask" useGeneratedKeys="true" keyProperty="id">
  351. INSERT INTO wms_order_task (
  352. site, task_no, item_no, source_type, source_bill_no, source_line_id,
  353. part_no, qty, batch_no, serial_no, from_location, to_location,
  354. pallet_id, agv_code, priority, status, wms_send_time,
  355. created_by, created_time, updated_time,wcs_task_id
  356. ) VALUES (
  357. #{site}, #{taskNo}, #{itemNo}, #{sourceType}, #{sourceBillNo}, #{sourceLineId},
  358. #{partNo}, #{qty}, #{batchNo}, #{serialNo}, #{fromLocation}, #{toLocation},
  359. #{palletId}, #{agvCode}, #{priority}, #{status}, #{wmsSendTime},
  360. #{createdBy}, #{createdTime}, #{updatedTime},#{wcsTaskId}
  361. )
  362. </insert>
  363. <!-- 检查站点是否有栈板 - AI制作 -->
  364. <select id="checkStationHasPallet" resultType="java.lang.Integer">
  365. SELECT COUNT(1)
  366. FROM pallet
  367. WHERE site = #{site}
  368. AND location_code = #{stationCode}
  369. AND is_deleted = '0'
  370. </select>
  371. <select id="getPalletDataByStation" resultType="PalletData">
  372. SELECT TOP 1 pallet_id, location_code, status,pallet_family, pallet_type
  373. FROM pallet
  374. WHERE site = #{site}
  375. AND location_code = #{stationCode}
  376. </select>
  377. <!-- 获取站点的栈板ID - AI制作 -->
  378. <select id="getPalletIdByStation" resultType="java.lang.String">
  379. SELECT TOP 1 pallet_id
  380. FROM pallet
  381. WHERE site = #{site}
  382. AND location_code = #{stationCode}
  383. AND is_deleted = '0'
  384. </select>
  385. <!-- 根据ID查询运输任务 - AI制作 -->
  386. <select id="getTransportTaskById" resultType="WmsTransportTask">
  387. SELECT id, site, task_no as taskNo, item_no as itemNo, source_type as sourceType,
  388. source_bill_no as sourceBillNo, source_line_id as sourceLineId,
  389. part_no as partNo, qty, batch_no as batchNo, serial_no as serialNo,
  390. from_location as fromLocation, to_location as toLocation,
  391. pallet_id as palletId, agv_code as agvCode, priority, status,
  392. wms_send_time as wmsSendTime, wcs_receive_time as wcsReceiveTime,
  393. start_time as startTime, complete_time as completeTime,
  394. error_code as errorCode, error_msg as errorMsg,
  395. created_by as createdBy, created_time as createdTime,
  396. updated_time as updatedTime, wcs_task_id as wcsTaskId,
  397. finish_qty as finishQty, wms_status as wmsStatus
  398. FROM wms_transport_task
  399. WHERE id = #{id}
  400. </select>
  401. <!-- 根据taskNo查询运输任务 - AI制作 -->
  402. <select id="getTransportTaskByTaskNo" resultType="WmsTransportTask">
  403. SELECT id, site, task_no as taskNo, item_no as itemNo, source_type as sourceType,
  404. source_bill_no as sourceBillNo, source_line_id as sourceLineId,
  405. part_no as partNo, qty, batch_no as batchNo, serial_no as serialNo,
  406. from_location as fromLocation, to_location as toLocation,
  407. pallet_id as palletId, agv_code as agvCode, priority, status,
  408. wms_send_time as wmsSendTime, wcs_receive_time as wcsReceiveTime,
  409. start_time as startTime, complete_time as completeTime,
  410. error_code as errorCode, error_msg as errorMsg,
  411. created_by as createdBy, created_time as createdTime,
  412. updated_time as updatedTime, wcs_task_id as wcsTaskId,
  413. finish_qty as finishQty, wms_status as wmsStatus
  414. FROM wms_transport_task
  415. WHERE task_no = #{taskNo}
  416. </select>
  417. <!-- 更新运输任务状态 - AI制作 -->
  418. <update id="updateTransportTaskStatus">
  419. UPDATE wms_transport_task
  420. SET status = #{status}, updated_time = GETDATE()
  421. WHERE id = #{id}
  422. </update>
  423. <!-- 根据taskNo更新运输任务状态 - AI制作 -->
  424. <update id="updateTransportTaskStatusByTaskNo">
  425. UPDATE wms_transport_task
  426. SET status = #{status}, updated_time = GETDATE()
  427. WHERE task_no = #{taskNo}
  428. </update>
  429. <!-- 根据站点代码获取站点信息 - AI制作 -->
  430. <select id="getStationInfoByCode" resultType="java.util.Map">
  431. SELECT station_code as stationCode, station_name as stationName,
  432. warehouse_code as warehouseCode, location_code as locationCode,
  433. area_type as areaType, active, status_db as statusDb, status,
  434. station_id as stationId, station_type as stationType
  435. FROM agv_station
  436. WHERE station_code = #{stationCode}
  437. </select>
  438. <select id="getStationDataByCode" resultType="AgvStation">
  439. SELECT station_code as stationCode, station_name as stationName,
  440. warehouse_code as warehouseCode, location_code as locationCode,
  441. area_type as areaType, active, status_db as statusDb, status,
  442. station_id as stationId, station_type as stationType
  443. FROM agv_station
  444. WHERE station_code = #{stationCode}
  445. </select>
  446. <!-- 更新栈板明细的wcs_flag为0(已传输给WCS) - AI制作 -->
  447. <update id="updatePalletDetailWcsFlag">
  448. UPDATE pallet_detail
  449. SET wcs_flag = 0
  450. WHERE site = #{site}
  451. AND pallet_id = #{palletId}
  452. AND wcs_flag = 1
  453. </update>
  454. <update id="reUpdatePalletDetailWcsFlag">
  455. UPDATE pallet_detail
  456. SET wcs_flag = 1
  457. WHERE site = #{site}
  458. AND pallet_id = #{palletId}
  459. AND wcs_flag = 0
  460. </update>
  461. <select id="getPalletDetailsNewDetail" resultType="PalletDetailData">
  462. 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,
  463. b.part_desc,b.qty,b.batch_no,b.wdr,c.weight,b.length,b.width,c.height,c.is_robot_pick,um_id,b.height as realHeight
  464. ,c.is_commonly_used, CONVERT(varchar(10),isnull( isnull(b.manufacture_date,b.receive_date),getdate()), 23) manufactureDateStr
  465. from pallet_detail a
  466. left join handling_unit b on a.site=b.site and a.serial_no=b.unit_id
  467. left join part_attribute c on a.site=c.site and a.part_no=c.part_no
  468. where a.site=#{site} and a.pallet_id=#{palletId}
  469. and a.wcs_flag = 1
  470. </select>
  471. <update id="updateSOIssueNotifyOrderMaterialListDetailOutWcsFlag">
  472. WITH RankedRecords AS (
  473. SELECT
  474. out_wcs_flag,
  475. ROW_NUMBER() OVER (ORDER BY notify_no DESC) AS rn
  476. FROM SOIssueNotifyOrderMaterialList_detail
  477. WHERE site = #{site}
  478. AND serialNo = #{serialNo}
  479. )
  480. UPDATE RankedRecords
  481. SET out_wcs_flag = 'Y'
  482. WHERE rn = 1;
  483. </update>
  484. <!-- rqrq - 根据task_ref+task_item+serialNo更新SOIssueNotifyOrderMaterialList_detail的out_wcs_flag为Y -->
  485. <update id="updateSOIssueNotifyDetailOutWcsFlagByTask">
  486. UPDATE SOIssueNotifyOrderMaterialList_detail
  487. SET out_wcs_flag = 'Y'
  488. WHERE site = #{site}
  489. AND task_ref = #{taskRef}
  490. AND task_item = #{taskItem}
  491. AND serialNo = #{serialNo}
  492. </update>
  493. <insert id="insertWmsTransportTaskDetail" >
  494. insert into wms_transport_task_detail(
  495. site,task_no,item_no,seq_no,action_type,[comment],from_location,to_location,agv_code,[status],start_time,
  496. error_code,error_msg
  497. ) values (
  498. #{site}, #{taskNo}, #{itemNo}, #{seqNo}, #{actionType}, #{comment}, #{fromLocation}, #{toLocation}, #{agvCode}, #{status}, #{startTime},
  499. #{errorCode}, #{errorMsg}
  500. )
  501. </insert>
  502. <insert id="insertWmsOrderTaskDetail" >
  503. insert into wms_order_task_detail(
  504. site,task_no,item_no,seq_no,action_type,[comment],from_location,to_location,agv_code,[status],start_time,
  505. error_code,error_msg,pallet_id,wms_status
  506. ) values (
  507. #{site}, #{taskNo}, #{itemNo}, #{seqNo}, #{actionType}, #{comment}, #{fromLocation}, #{toLocation}, #{agvCode}, #{status}, #{startTime},
  508. #{errorCode}, #{errorMsg},#{palletId},#{wmsStatus}
  509. )
  510. </insert>
  511. <select id="getMaxSeqNoForTaskDetail" resultType="Integer">
  512. select isnull(max(seq_no),0)+1 from wms_transport_task_detail
  513. where task_no=#{taskNo} and site=#{site} and item_no= 1
  514. </select>
  515. <update id="updateTransportTaskStatusForSiteAndNo">
  516. update wms_transport_task set [status]=#{status} where site=#{site} and task_no=#{taskNo}
  517. </update>
  518. <!-- rqrq - 使用status状态控制并发:先将状态改为'处理中'锁定记录 -->
  519. <update id="lockTaskDetailForProcessing">
  520. update wms_transport_task_detail
  521. set [status]='处理中', start_time=GETDATE()
  522. where id=#{id} and status in ('已录入','处理失败','回调处理失败')
  523. </update>
  524. <!-- rqrq - 更新任务明细状态为最终状态 -->
  525. <update id="updateTransportTaskDetailStatusForId">
  526. update wms_transport_task_detail
  527. set [status]=#{status}
  528. where id=#{id}
  529. </update>
  530. <!-- rqrq - 查询待处理的AGV回调任务明细(状态控制并发) -->
  531. <select id="getTransportTaskDetailListWithStatus" resultType="WmsTransportTaskDetail">
  532. select id,site,task_no as taskNo,item_no as itemNo,seq_no as seqNo,action_type as actionType,[comment],from_location as fromLocation,
  533. to_location as toLocation,agv_code as agvCode,[status],start_time as startTime,
  534. error_code as errorCode,error_msg as errorMsg
  535. from wms_transport_task_detail
  536. where site = #{site} and status in ('处理失败','回调处理失败','已录入')
  537. </select>
  538. <!-- 查询指定状态的订单任务明细列表 - AI制作 -->
  539. <select id="getOrderTaskDetailListWithStatus" resultType="WmsOrderTaskDetail">
  540. select id,site,task_no as taskNo,item_no as itemNo,seq_no as seqNo,action_type as actionType,[comment],from_location as fromLocation,
  541. to_location as toLocation,agv_code as agvCode,[status],start_time as startTime,
  542. error_code as errorCode,error_msg as errorMsg
  543. from wms_order_task_detail
  544. where site = #{site} and status in ('处理失败','回调处理失败','已录入')
  545. </select>
  546. <!-- 根据ID更新订单任务明细状态 - AI制作 -->
  547. <update id="updateOrderTaskDetailStatusForId">
  548. update wms_order_task_detail set [status]=#{status} where id=#{id}
  549. </update>
  550. <!-- 根据任务号获取栈板ID - AI制作 -->
  551. <select id="getPalletIdByOrderTaskNo" resultType="String">
  552. select pallet_id from wms_order_task where task_no = #{taskNo}
  553. </select>
  554. <!-- 根据栈板号和任务类型查找订单任务 - AI制作 -->
  555. <select id="findOrderTaskByPalletAndType" resultType="WmsOrderTask">
  556. select top 1 id, site, task_no as taskNo, item_no as itemNo, source_type as sourceType,
  557. source_bill_no as sourceBillNo, source_line_id as sourceLineId, part_no as partNo,
  558. qty, batch_no as batchNo, serial_no as serialNo, from_location as fromLocation,
  559. to_location as toLocation, pallet_id as palletId, agv_code as agvCode,
  560. priority, status, wms_send_time as wmsSendTime, wcs_receive_time as wcsReceiveTime,
  561. start_time as startTime, complete_time as completeTime, error_code as errorCode,
  562. error_msg as errorMsg, created_by as createdBy, created_time as createdTime,
  563. updated_time as updatedTime, wcs_task_id as wcsTaskId, finish_qty as finishQty,
  564. wms_status as wmsStatus
  565. from wms_order_task
  566. where site = #{site}
  567. and pallet_id = #{palletId}
  568. and source_type = #{sourceType}
  569. and status in ('已创建', '执行中', '已下发')
  570. order by created_time desc
  571. </select>
  572. <!-- 获取订单任务明细的最大序号 - AI制作 -->
  573. <select id="getMaxSeqNoForOrderTaskDetail" resultType="Integer">
  574. select isnull(max(seq_no),0)+1 from wms_order_task_detail
  575. where task_no=#{taskNo} and site=#{site}
  576. </select>
  577. <!-- 插入WCS回调任务 - AI制作 -->
  578. <insert id="insertWcsCallbackTask" useGeneratedKeys="true" keyProperty="id">
  579. INSERT INTO wcs_callback_task (
  580. site, pallet_id, trans_type_desc, to_warehouse_id, to_location_id,
  581. status, created_time, retry_count, remark, task_no, item_no, to_station
  582. ) VALUES (
  583. #{site}, #{palletId}, #{transTypeDesc}, #{toWarehouseId}, #{toLocationId},
  584. #{status}, #{createdTime}, #{retryCount}, #{remark}, #{taskNo}, #{itemNo}, #{toStation}
  585. )
  586. </insert>
  587. <!-- 查询指定状态的WCS回调任务列表(含超时恢复机制) - AI制作 -->
  588. <select id="getWcsCallbackTaskListWithStatus" resultType="WcsCallbackTask">
  589. select id, site, pallet_id as palletId, trans_type_desc as transTypeDesc,
  590. to_warehouse_id as toWarehouseId, to_location_id as toLocationId,
  591. status, created_time as createdTime, process_start_time as processStartTime,
  592. process_end_time as processEndTime, error_msg as errorMsg,
  593. retry_count as retryCount, remark,task_no,item_no,to_station
  594. from wcs_callback_task
  595. where site = #{site}
  596. and (
  597. status in ('已录入', '处理失败')
  598. or (status = '处理中' and process_start_time &lt; DATEADD(MINUTE, -10, GETDATE()))
  599. )
  600. and (retry_count is null or retry_count &lt; 3)
  601. order by created_time
  602. </select>
  603. <!-- 更新WCS回调任务状态 - AI制作 -->
  604. <update id="updateWcsCallbackTaskStatus">
  605. update wcs_callback_task
  606. set status = #{status}
  607. <if test="processStartTime != null">
  608. , process_start_time = #{processStartTime}
  609. </if>
  610. <if test="processEndTime != null">
  611. , process_end_time = #{processEndTime}
  612. </if>
  613. <if test="errorMsg != null">
  614. , error_msg = #{errorMsg}
  615. </if>
  616. where id = #{id}
  617. </update>
  618. <!-- 原子性更新WCS回调任务状态(乐观锁版本,防止重复处理) - AI制作 -->
  619. <update id="updateWcsCallbackTaskStatusWithLock">
  620. UPDATE wcs_callback_task
  621. SET status = #{newStatus},
  622. process_start_time = #{processStartTime}
  623. WHERE id = #{id}
  624. AND status = #{oldStatus}
  625. </update>
  626. <update id="updatePalletWcsLocation" >
  627. update pallet set wcs_location = #{location},updated_by='wms_sys',updated_time=getdate()
  628. where site = #{site} and pallet_id = #{palletId}
  629. </update>
  630. <!-- 更新WCS回调任务重试次数 - AI制作 -->
  631. <update id="updateWcsCallbackTaskRetryCount">
  632. update wcs_callback_task set retry_count = #{retryCount} where id = #{id}
  633. </update>
  634. <!-- 根据栈板ID和动作类型查找订单任务 - AI制作 -->
  635. <select id="findOrderTasksByPalletAndActionType" resultType="WmsOrderTask">
  636. select id, site, task_no as taskNo, item_no as itemNo, source_type as sourceType,
  637. source_bill_no as sourceBillNo, source_line_id as sourceLineId, part_no as partNo,
  638. qty, batch_no as batchNo, serial_no as serialNo, from_location as fromLocation,
  639. to_location as toLocation, pallet_id as palletId, agv_code as agvCode,
  640. priority, status, wms_send_time as wmsSendTime, wcs_receive_time as wcsReceiveTime,
  641. start_time as startTime, complete_time as completeTime, error_code as errorCode,
  642. error_msg as errorMsg, created_by as createdBy, created_time as createdTime,
  643. updated_time as updatedTime, wcs_task_id as wcsTaskId, finish_qty as finishQty,
  644. wms_status as wmsStatus
  645. from wms_order_task
  646. <where>
  647. and site = #{site}
  648. and pallet_id = #{palletId}
  649. <if test="sourceType != null and sourceType != ''">
  650. and source_type = #{sourceType}
  651. </if>
  652. and status = #{status}
  653. </where>
  654. order by created_time desc
  655. </select>
  656. <select id="findOrderTasksByTaskNo" resultType="WmsOrderTask">
  657. select id, site, task_no as taskNo, item_no as itemNo, source_type as sourceType,
  658. source_bill_no as sourceBillNo, source_line_id as sourceLineId, part_no as partNo,
  659. qty, batch_no as batchNo, serial_no as serialNo, from_location as fromLocation,
  660. to_location as toLocation, pallet_id as palletId, agv_code as agvCode,
  661. priority, status, wms_send_time as wmsSendTime, wcs_receive_time as wcsReceiveTime,
  662. start_time as startTime, complete_time as completeTime, error_code as errorCode,
  663. error_msg as errorMsg, created_by as createdBy, created_time as createdTime,
  664. updated_time as updatedTime, wcs_task_id as wcsTaskId, finish_qty as finishQty,
  665. wms_status as wmsStatus
  666. from wms_order_task
  667. where site = #{site}
  668. and task_no=#{taskNo}
  669. order by created_time desc
  670. </select>
  671. <select id="findOrderTasksByTaskNoItem" resultType="WmsOrderTask">
  672. select id, site, task_no as taskNo, item_no as itemNo, source_type as sourceType,
  673. source_bill_no as sourceBillNo, source_line_id as sourceLineId, part_no as partNo,
  674. qty, batch_no as batchNo, serial_no as serialNo, from_location as fromLocation,
  675. to_location as toLocation, pallet_id as palletId, agv_code as agvCode,
  676. priority, status, wms_send_time as wmsSendTime, wcs_receive_time as wcsReceiveTime,
  677. start_time as startTime, complete_time as completeTime, error_code as errorCode,
  678. error_msg as errorMsg, created_by as createdBy, created_time as createdTime,
  679. updated_time as updatedTime, wcs_task_id as wcsTaskId, finish_qty as finishQty,
  680. wms_status as wmsStatus
  681. from wms_order_task
  682. where site = #{site}
  683. and task_no=#{taskNo}
  684. and item_no=#{itemNo}
  685. order by created_time desc
  686. </select>
  687. <!-- 更新订单任务状态和WMS状态 - AI制作 -->
  688. <update id="updateOrderTaskStatusAndWmsStatus">
  689. update wms_order_task
  690. set status = #{status}, wms_status = #{wmsStatus}
  691. where id = #{id}
  692. </update>
  693. <!-- 根据任务号更新订单任务明细状态 - AI制作 -->
  694. <update id="updateOrderTaskDetailStatusByTaskNo">
  695. update wms_order_task_detail
  696. set status = #{status} ,wms_status = #{wmsStatus}
  697. where task_no = #{taskNo}
  698. </update>
  699. <update id="updateOrderTaskDetailStatusByTaskNoPalletId">
  700. update wms_order_task_detail
  701. set status = #{status} ,wms_status = #{wmsStatus}
  702. where task_no = #{taskNo} and site=#{site} and pallet_id=#{palletId}
  703. </update>
  704. <!-- 查询立库调栈板出库的订单任务列表 - AI制作 -->
  705. <select id="getWcsOrderTaskListForPalletOut" resultType="WmsOrderTask">
  706. select id, site, task_no as taskNo, item_no as itemNo, source_type as sourceType,
  707. source_bill_no as sourceBillNo, source_line_id as sourceLineId, part_no as partNo,
  708. qty, batch_no as batchNo, serial_no as serialNo, from_location as fromLocation,
  709. to_location as toLocation, pallet_id as palletId, agv_code as agvCode,
  710. priority, status, wms_send_time as wmsSendTime, wcs_receive_time as wcsReceiveTime,
  711. start_time as startTime, complete_time as completeTime, error_code as errorCode,
  712. error_msg as errorMsg, created_by as createdBy, created_time as createdTime,
  713. updated_time as updatedTime, wcs_task_id as wcsTaskId, finish_qty as finishQty,
  714. wms_status as wmsStatus
  715. from wms_order_task
  716. where site = #{site}
  717. and status = '已创建'
  718. and source_type like '%栈板出库%'
  719. and (wms_status is null or wms_status in ('未执行', '等待重试'))
  720. order by priority desc, created_time asc
  721. </select>
  722. <!-- 更新订单任务错误信息 - AI制作 -->
  723. <update id="updateOrderTaskErrorInfo">
  724. update wms_order_task
  725. set error_code = #{errorCode},
  726. error_msg = #{errorMsg}
  727. where id = #{id}
  728. </update>
  729. <!-- 更新AGV站点状态 - AI制作 -->
  730. <update id="updateAgvStationStatus">
  731. UPDATE agv_station
  732. SET status_db = #{statusDb},
  733. status = #{status}
  734. WHERE station_code = #{stationCode}
  735. </update>
  736. <update id="updateWTTToLocationForId">
  737. update wms_order_task set to_location=#{toLocation} where site=#{site} and task_no=#{taskNo}
  738. </update>
  739. <!-- 获取AGV站点状态 - AI制作 -->
  740. <select id="getAgvStationStatus" resultType="Integer">
  741. SELECT status_db
  742. FROM agv_station
  743. WHERE station_code = #{stationCode}
  744. </select>
  745. <select id="getAgvStationType" resultType="String">
  746. SELECT station_type
  747. FROM agv_station
  748. WHERE station_code = #{stationCode}
  749. </select>
  750. <!-- 获取栈板详细信息(包含palletType和autoSort以及托盘类型详情) - AI制作 -->
  751. <select id="getPalletInfoWithTypeDetails" resultType="PalletData">
  752. SELECT
  753. p.site,
  754. p.pallet_id AS palletId,
  755. p.pallet_type AS palletType,
  756. p.pallet_family AS palletFamily,
  757. p.auto_sort AS autoSort,
  758. p.sore_type AS soreType,
  759. p.location_code AS locationCode,
  760. p.wcs_location AS wcsLocation,
  761. pt.type_desc AS typeDesc,
  762. pt.wcs_auto_sort AS wcsAutoSort,
  763. pt.wcs_pallet_type AS wcsPalletType,
  764. pt.wcs_base_pallet_type AS wcsBasePalletType,
  765. pt.wcs_sore_type AS wcsSoreType,
  766. pt.max_layer AS maxLayer,
  767. pf.pallet_family_desc AS palletFamilyDesc
  768. FROM pallet p
  769. LEFT JOIN pallet_type pt ON p.site = pt.site AND p.pallet_type = pt.pallet_type
  770. LEFT JOIN pallet_family pf ON p.site = pf.site AND p.pallet_family = pf.pallet_family
  771. WHERE p.site = #{site}
  772. AND p.pallet_id = #{palletId}
  773. AND p.is_deleted = '0'
  774. </select>
  775. <!-- 更新栈板类型、自动分拣标志和存储类型 - AI制作/rqrq -->
  776. <update id="updatePalletTypeAndAutoSort">
  777. UPDATE pallet
  778. SET pallet_type = #{palletType},
  779. auto_sort = #{autoSort},
  780. sore_type = #{soreType},
  781. updated_time = GETDATE()
  782. WHERE site = #{site}
  783. AND pallet_id = #{palletId}
  784. AND is_deleted = '0'
  785. </update>
  786. <!-- 获取指定层已占用的位置列表 - rqrq -->
  787. <select id="getOccupiedPositionsByLayer" resultType="java.lang.String">
  788. SELECT DISTINCT position
  789. FROM pallet_detail
  790. WHERE site = #{site}
  791. AND pallet_id = #{palletId}
  792. AND layer = #{layer}
  793. ORDER BY position
  794. </select>
  795. <!-- rqrq - 插入WCS回调栈板扫描记录 -->
  796. <insert id="insertCallbackPalletScan" parameterType="com.gaotao.modules.automatedWarehouse.entity.WcsCallbackPalletScan" useGeneratedKeys="true" keyProperty="callback.id">
  797. INSERT INTO wcs_callback_pallet_scan (
  798. site, pallet_id, task_no, item_no,
  799. wcs_scan_time, wcs_barcode_list, wcs_total_quantity, sore_type,
  800. process_status, retry_count,
  801. created_at, updated_at, json_str,action_type
  802. ) VALUES (
  803. #{callback.site}, #{callback.palletId}, #{callback.taskNo}, #{callback.itemNo},
  804. #{callback.wcsScanTime}, #{callback.wcsBarcodeList}, #{callback.wcsTotalQuantity}, #{callback.soreType},
  805. #{callback.processStatus}, #{callback.retryCount},
  806. GETDATE(), GETDATE(), #{callback.jsonStr}, #{callback.actionType}
  807. )
  808. </insert>
  809. <select id="getPalletType" resultType="PalletType">
  810. 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
  811. FROM pallet_type WHERE site = #{site} AND pallet_type = #{palletType}
  812. </select>
  813. <select id="getAgvStation" resultType="AgvStation">
  814. SELECT id,station_code,station_name,area_type,warehouse_code,location_x,location_y,location_z,active,location_code,remark,
  815. station_area,status_db,[status],station_id,station_type,auto_call_blank_pallet,wait_station_code
  816. FROM agv_station
  817. where station_code=#{stationCode}
  818. </select>
  819. <!-- ==================== 栈板换站相关SQL - rqrq ==================== -->
  820. <!-- rqrq - 检查栈板calling_flag并获取当前站点信息 -->
  821. <select id="checkPalletForChangeStation" resultType="CheckPalletResult">
  822. SELECT
  823. p.calling_flag AS callingFlag,
  824. s.station_id AS currentStationId,
  825. s.station_code AS currentStationCode
  826. FROM pallet p
  827. LEFT JOIN agv_station s ON p.location_code = s.station_code
  828. WHERE p.site = #{site}
  829. AND p.pallet_id = #{palletId}
  830. AND p.is_deleted = '0'
  831. </select>
  832. <!-- rqrq - 获取可选择的区域列表(choose_able为Y) -->
  833. <select id="getAreaOptionsForChange" resultType="Area">
  834. SELECT
  835. area_id AS areaId,
  836. area_desc AS areaDesc,
  837. choose_able AS chooseAble
  838. FROM area
  839. WHERE choose_able = 'Y'
  840. ORDER BY area_id
  841. </select>
  842. <!-- rqrq - 根据区域获取可用站点列表 -->
  843. <select id="getStationsByArea" resultType="AgvStation">
  844. SELECT
  845. station_id AS stationId,
  846. station_code AS stationCode,
  847. station_name AS stationName,
  848. area_type AS areaType,
  849. status_db AS statusDb,
  850. status,
  851. active
  852. FROM agv_station
  853. WHERE area_type = #{areaId}
  854. AND active = 'Y'
  855. AND station_type = '正式站点'
  856. AND status_db = 0
  857. ORDER BY station_id
  858. </select>
  859. <!-- rqrq - 根据区域查找第一个空闲站点(用于自动分配)-->
  860. <select id="findFirstFreeStationByAreaId" resultType="java.lang.String">
  861. SELECT TOP 1 station_code
  862. FROM agv_station
  863. WHERE area_type = #{areaId}
  864. AND active = 'Y'
  865. AND station_type = '正式站点'
  866. AND status_db = 0
  867. ORDER BY station_id
  868. </select>
  869. <!-- ==================== 手工移动托盘相关SQL - rqrq ==================== -->
  870. <!-- rqrq - 检查托盘是否可以手工移动 -->
  871. <select id="checkPalletForManualMove" resultType="CheckPalletResult">
  872. SELECT
  873. p.calling_flag AS callingFlag,
  874. p.location_code AS currentStationCode,
  875. s.station_type AS stationType,
  876. s.station_id as currentStationId,
  877. CASE
  878. WHEN p.location_code IS NULL THEN 'Y'
  879. WHEN s.station_type = '正式站点' THEN 'Y'
  880. ELSE 'N'
  881. END AS canOperate
  882. FROM pallet p
  883. LEFT JOIN agv_station s ON p.location_code = s.station_code
  884. WHERE p.site = #{site}
  885. AND p.pallet_id = #{palletId}
  886. AND p.is_deleted = '0'
  887. </select>
  888. <!-- rqrq - 更新托盘location_code为null(移出站点)-->
  889. <update id="updatePalletRemoveStation">
  890. UPDATE pallet
  891. SET location_code = NULL,
  892. updated_time = GETDATE()
  893. WHERE site = #{site}
  894. AND pallet_id = #{palletId}
  895. AND is_deleted = '0'
  896. </update>
  897. <!-- rqrq - 更新站点状态为空闲 -->
  898. <update id="updateStationToFree">
  899. UPDATE agv_station
  900. SET status_db = 0,
  901. status = '空闲'
  902. WHERE station_code = #{stationCode}
  903. </update>
  904. <!-- rqrq - 更新托盘location_code(绑定站点)-->
  905. <update id="updatePalletBindStation">
  906. UPDATE pallet
  907. SET location_code = #{stationCode},
  908. updated_time = GETDATE()
  909. WHERE site = #{site}
  910. AND pallet_id = #{palletId}
  911. AND is_deleted = '0'
  912. </update>
  913. <!-- rqrq - 更新站点状态为有货 -->
  914. <update id="updateStationToOccupied">
  915. UPDATE agv_station
  916. SET status_db = 1,
  917. status = '有货'
  918. WHERE station_code = #{stationCode}
  919. </update>
  920. <!-- ==================== 空托盘组盘相关SQL - rqrq ==================== -->
  921. <!-- rqrq - 检查托盘是否为空托盘 -->
  922. <select id="checkEmptyPallet" resultType="CheckPalletResult">
  923. SELECT
  924. p.pallet_id AS palletId,
  925. p.pallet_type AS palletType,
  926. p.pallet_family AS palletFamily,
  927. p.location_code AS currentStationCode,
  928. s.station_id AS currentStationId,
  929. CASE
  930. WHEN EXISTS (
  931. SELECT 1 FROM pallet_detail pd
  932. WHERE pd.site = p.site
  933. AND pd.pallet_id = p.pallet_id
  934. )
  935. THEN 'N'
  936. ELSE 'Y'
  937. END AS isEmpty
  938. FROM pallet p
  939. LEFT JOIN agv_station s ON p.location_code = s.station_code
  940. WHERE p.site = #{site}
  941. AND p.pallet_id = #{palletId}
  942. AND p.is_deleted = '0'
  943. </select>
  944. <!-- rqrq - 获取托盘类型列表(根据pallet_family过滤)-->
  945. <select id="getPalletTypes" resultType="PalletType">
  946. SELECT
  947. site,
  948. pallet_type AS palletType,
  949. type_desc AS typeDesc,
  950. pallet_family AS palletFamily,
  951. max_layer AS maxLayer,
  952. wcs_auto_sort AS wcsAutoSort,
  953. wcs_pallet_type AS wcsPalletType,
  954. wcs_base_pallet_type AS wcsBasePalletType,
  955. wcs_sore_type AS wcsSoreType
  956. FROM pallet_type
  957. WHERE site = #{site}
  958. <if test="palletFamily != null and palletFamily != ''">
  959. AND pallet_family = #{palletFamily}
  960. </if>
  961. ORDER BY pallet_type
  962. </select>
  963. <!-- rqrq - 获取需要自动续盘的站点列表 -->
  964. <select id="getAutoCallBlankPalletStations" resultType="AgvStation">
  965. SELECT
  966. id,
  967. station_code AS stationCode,
  968. station_name AS stationName,
  969. station_type AS stationType,
  970. status_db AS statusDb,
  971. status,
  972. auto_call_blank_pallet AS autoCallBlankPallet,
  973. auto_call_blank_pallet_type AS autoCallBlankPalletType,
  974. wait_station_code AS waitStationCode
  975. FROM agv_station
  976. WHERE auto_call_blank_pallet = 'Y'
  977. AND auto_call_blank_pallet_type IS NOT NULL
  978. AND auto_call_blank_pallet_type != ''
  979. AND station_type = '正式站点'
  980. AND status_db = 0
  981. ORDER BY station_code
  982. </select>
  983. <!-- ==================== 取消WCS组盘相关SQL - rqrq ==================== -->
  984. <!-- rqrq - 检查栈板WCS组盘状态 -->
  985. <select id="checkPalletWcsStatus" resultType="CheckPalletResult">
  986. SELECT
  987. p.pallet_id AS palletId,
  988. p.calling_flag AS callingFlag,
  989. CASE
  990. WHEN EXISTS (
  991. SELECT 1 FROM pallet_detail pd
  992. WHERE pd.site = #{site} AND pd.pallet_id = #{palletId} AND pd.wcs_flag = 0
  993. ) THEN 'Y'
  994. ELSE 'N'
  995. END AS canOperate, -- 借用canOperate字段存储hasSentWcsTask
  996. CASE
  997. WHEN EXISTS (
  998. SELECT 1 FROM pallet_detail pd
  999. WHERE pd.site = #{site} AND pd.pallet_id = #{palletId}
  1000. ) THEN 'Y'
  1001. ELSE 'N'
  1002. END AS isEmpty -- 借用isEmpty字段存储hasDetail
  1003. FROM pallet p
  1004. WHERE p.site = #{site} AND p.pallet_id = #{palletId} AND p.is_deleted = '0'
  1005. </select>
  1006. <!-- rqrq - 检查栈板是否有wcs_flag=0的明细 -->
  1007. <select id="countPalletDetailWithWcsFlagZero" resultType="int">
  1008. SELECT COUNT(*)
  1009. FROM pallet_detail
  1010. WHERE site = #{site} AND pallet_id = #{palletId} AND wcs_flag = 0
  1011. </select>
  1012. <!-- rqrq - 更新栈板所有明细的wcs_flag为1 -->
  1013. <update id="updateAllPalletDetailWcsFlagToOne">
  1014. UPDATE pallet_detail
  1015. SET wcs_flag = 1
  1016. WHERE site = #{site} AND pallet_id = #{palletId}
  1017. </update>
  1018. <!-- rqrq - 删除栈板所有明细 -->
  1019. <delete id="deleteAllPalletDetail">
  1020. DELETE FROM pallet_detail
  1021. WHERE site = #{site} AND pallet_id = #{palletId}
  1022. </delete>
  1023. <select id="getStationByCode" resultType="AgvStation">
  1024. SELECT
  1025. id,
  1026. station_code AS stationCode,
  1027. station_name AS stationName,
  1028. station_type AS stationType,
  1029. status_db AS statusDb,
  1030. status,
  1031. auto_call_blank_pallet AS autoCallBlankPallet,
  1032. auto_call_blank_pallet_type AS autoCallBlankPalletType,
  1033. wait_station_code AS waitStationCode
  1034. FROM agv_station
  1035. WHERE station_code = #{stationCode}
  1036. </select>
  1037. <!-- ==================== 预约取托盘相关SQL - rqrq ==================== -->
  1038. <!-- rqrq - 查询空托盘区可用的空托盘 -->
  1039. <select id="findAvailableEmptyPallet" resultType="Pallet">
  1040. SELECT TOP 1
  1041. p.id,
  1042. p.site,
  1043. p.pallet_id AS palletId,
  1044. p.pallet_type AS palletType,
  1045. p.pallet_size AS palletSize,
  1046. p.max_load AS maxLoad,
  1047. p.status,
  1048. p.location_code AS locationCode,
  1049. p.remark,
  1050. p.is_deleted AS isDeleted,
  1051. p.created_by AS createdBy,
  1052. p.created_time AS createdTime,
  1053. p.updated_by AS updatedBy,
  1054. p.updated_time AS updatedTime,
  1055. p.calling_flag AS callingFlag,
  1056. p.wcs_location AS wcsLocation,
  1057. p.pallet_family AS palletFamily,
  1058. p.sore_type AS soreType,
  1059. p.auto_sort AS autoSort,
  1060. p.empty_flag AS emptyFlag
  1061. FROM pallet p
  1062. INNER JOIN agv_station s ON p.location_code = s.station_code
  1063. WHERE p.site = #{site}
  1064. AND p.pallet_type = #{palletType}
  1065. AND p.calling_flag = 'N'
  1066. AND p.is_deleted = '0'
  1067. AND s.area_type = 'Z101'
  1068. AND s.status_db = 1
  1069. AND s.active = 'Y'
  1070. ORDER BY p.created_time ASC
  1071. </select>
  1072. <!-- rqrq - 检查指定托盘是否就绪 -->
  1073. <select id="checkPalletReady" resultType="Pallet">
  1074. SELECT
  1075. p.id,
  1076. p.site,
  1077. p.pallet_id AS palletId,
  1078. p.pallet_type AS palletType,
  1079. p.pallet_size AS palletSize,
  1080. p.max_load AS maxLoad,
  1081. p.status,
  1082. p.location_code AS locationCode,
  1083. p.remark,
  1084. p.is_deleted AS isDeleted,
  1085. p.created_by AS createdBy,
  1086. p.created_time AS createdTime,
  1087. p.updated_by AS updatedBy,
  1088. p.updated_time AS updatedTime,
  1089. p.calling_flag AS callingFlag,
  1090. p.wcs_location AS wcsLocation,
  1091. p.pallet_family AS palletFamily,
  1092. p.sore_type AS soreType,
  1093. p.auto_sort AS autoSort,
  1094. p.empty_flag AS emptyFlag
  1095. FROM pallet p
  1096. INNER JOIN agv_station s ON p.location_code = s.station_code
  1097. WHERE p.site = #{site}
  1098. AND p.pallet_id = #{palletId}
  1099. AND p.calling_flag = 'N'
  1100. AND p.is_deleted = '0'
  1101. AND s.area_type IN ('Z101', 'Z103', 'Z104')
  1102. AND s.status_db = 1
  1103. AND s.active = 'Y'
  1104. </select>
  1105. <!-- rqrq - 使用乐观锁更新运输任务状态 -->
  1106. <update id="updateTransportTaskWithLock">
  1107. UPDATE wms_transport_task
  1108. SET status = #{newStatus},
  1109. <if test="palletId != null and palletId != ''">
  1110. pallet_id = #{palletId},
  1111. </if>
  1112. <if test="fromLocation != null and fromLocation != ''">
  1113. from_location = #{fromLocation},
  1114. </if>
  1115. <if test="toLocation != null and toLocation != ''">
  1116. to_location = #{toLocation},
  1117. </if>
  1118. wms_status = #{newWmsStatus},
  1119. updated_time = GETDATE()
  1120. WHERE task_no = #{taskNo}
  1121. AND (wms_status = #{oldWmsStatus} OR wms_status IS NULL)
  1122. </update>
  1123. <!-- rqrq - 根据栈板ID和sourceType查询最新的OrderTask -->
  1124. <select id="findLatestOrderTaskByPallet" resultType="WmsOrderTask">
  1125. SELECT TOP 1
  1126. id,
  1127. site,
  1128. task_no AS taskNo,
  1129. item_no AS itemNo,
  1130. pallet_id AS palletId,
  1131. source_type AS sourceType,
  1132. source_bill_no AS sourceBillNo,
  1133. source_line_id AS sourceLineId,
  1134. part_no AS partNo,
  1135. qty,
  1136. batch_no AS batchNo,
  1137. serial_no AS serialNo,
  1138. from_location AS fromLocation,
  1139. to_location AS toLocation,
  1140. agv_code AS agvCode,
  1141. priority,
  1142. status,
  1143. wms_send_time AS wmsSendTime,
  1144. wcs_receive_time AS wcsReceiveTime,
  1145. start_time AS startTime,
  1146. complete_time AS completeTime,
  1147. error_code AS errorCode,
  1148. error_msg AS errorMsg,
  1149. created_by AS createdBy,
  1150. created_time AS createdTime,
  1151. updated_time AS updatedTime,
  1152. wcs_task_id AS wcsTaskId,
  1153. finish_qty AS finishQty,
  1154. wms_status AS wmsStatus
  1155. FROM wms_order_task
  1156. WHERE site = #{site}
  1157. AND pallet_id = #{palletId}
  1158. AND source_type = #{sourceType}
  1159. ORDER BY created_time DESC
  1160. </select>
  1161. <!-- rqrq - 根据栈板ID更新最新的TransportTask的source_bill_no和source_line_id -->
  1162. <update id="updateTransportTaskSourceInfo">
  1163. UPDATE wms_transport_task
  1164. SET source_bill_no = #{sourceBillNo},
  1165. source_line_id = #{sourceLineId},
  1166. updated_time = GETDATE()
  1167. WHERE id = (
  1168. SELECT TOP 1 id
  1169. FROM wms_transport_task
  1170. WHERE site = #{site}
  1171. AND pallet_id = #{palletId}
  1172. AND source_type = '预约取托盘'
  1173. ORDER BY created_time DESC
  1174. )
  1175. </update>
  1176. <!-- ==================== 调度发货任务相关SQL - rqrq ==================== -->
  1177. <!-- rqrq - 根据栈板编码获取栈板信息 -->
  1178. <select id="getPalletByCode" resultType="Pallet">
  1179. SELECT
  1180. id,
  1181. site,
  1182. pallet_id AS palletId,
  1183. pallet_type AS palletType,
  1184. pallet_size AS palletSize,
  1185. max_load AS maxLoad,
  1186. status,
  1187. location_code AS locationCode,
  1188. remark,
  1189. is_deleted AS isDeleted,
  1190. created_by AS createdBy,
  1191. created_time AS createdTime,
  1192. updated_by AS updatedBy,
  1193. updated_time AS updatedTime,
  1194. calling_flag AS callingFlag,
  1195. wcs_location AS wcsLocation,
  1196. pallet_family AS palletFamily,
  1197. sore_type AS soreType,
  1198. auto_sort AS autoSort,
  1199. empty_flag AS emptyFlag
  1200. FROM pallet
  1201. WHERE site = #{site}
  1202. AND pallet_id = #{palletId}
  1203. AND is_deleted = '0'
  1204. </select>
  1205. <!-- rqrq - 根据任务号和行号成对匹配查询发料明细的序列号列表 -->
  1206. <select id="getSerialNosByTaskRefAndItem" resultType="String">
  1207. SELECT DISTINCT serialNo
  1208. FROM SOIssueNotifyOrderMaterialList_detail
  1209. WHERE site = #{site}
  1210. <if test="taskNotes != null and taskNotes.size() > 0">
  1211. AND (
  1212. <foreach collection="taskNotes" item="note" separator=" OR ">
  1213. (task_ref = #{note.taskNo} AND task_item = #{note.itemNo})
  1214. </foreach>
  1215. )
  1216. </if>
  1217. </select>
  1218. <!-- rqrq - 根据序列号列表查询栈板ID列表(去重) -->
  1219. <select id="getPalletIdsBySerialNos" resultType="String">
  1220. SELECT DISTINCT pallet_id
  1221. FROM pallet_detail
  1222. WHERE site = #{site}
  1223. <if test="serialNoList != null and serialNoList.size() > 0">
  1224. AND serial_no IN
  1225. <foreach collection="serialNoList" item="serialNo" open="(" close=")" separator=",">
  1226. #{serialNo}
  1227. </foreach>
  1228. </if>
  1229. </select>
  1230. <!-- rqrq - 检查栈板是否在指定wcsTaskID和站点生成过运输任务 -->
  1231. <select id="checkPalletTaskExists" resultType="int">
  1232. SELECT COUNT(1)
  1233. FROM wms_transport_task
  1234. WHERE site = #{site}
  1235. AND pallet_id = #{palletId}
  1236. AND source_bill_no = #{sourceBillNo}
  1237. AND to_location = #{stationCode}
  1238. </select>
  1239. <!-- rqrq - 检查栈板是否放满(根据pallet_type_area的点位数和max_layer判断) -->
  1240. <select id="checkPalletIsFull" resultType="int">
  1241. WITH PalletInfo AS (
  1242. -- 获取栈板类型和最大层数 - rqrq
  1243. SELECT p.pallet_type, pt.max_layer
  1244. FROM pallet p
  1245. INNER JOIN pallet_type pt ON p.site = pt.site AND p.pallet_type = pt.pallet_type
  1246. WHERE p.site = #{site} AND p.pallet_id = #{palletId}
  1247. ),
  1248. PositionCount AS (
  1249. -- 获取该类型栈板的点位数 - rqrq
  1250. SELECT COUNT(1) AS position_count
  1251. FROM pallet_type_area pta
  1252. INNER JOIN PalletInfo pi ON pta.site = #{site} AND pta.pallet_type = pi.pallet_type
  1253. ),
  1254. DetailCount AS (
  1255. -- 获取栈板已使用的明细数量 - rqrq
  1256. SELECT COUNT(1) AS detail_count
  1257. FROM pallet_detail
  1258. WHERE site = #{site} AND pallet_id = #{palletId}
  1259. ),
  1260. MaxCapacity AS (
  1261. -- 计算栈板最大容量 - rqrq
  1262. SELECT
  1263. CASE
  1264. WHEN pi.max_layer IS NULL OR pi.max_layer = 0 THEN 999999 -- 混装托盘,容量无限 - rqrq
  1265. ELSE pc.position_count * pi.max_layer -- 有层数托盘 = 点位数 * 最大层数 - rqrq
  1266. END AS max_capacity
  1267. FROM PalletInfo pi, PositionCount pc
  1268. )
  1269. -- 判断是否已满(detail_count >= max_capacity 则为满)- rqrq
  1270. SELECT
  1271. CASE
  1272. WHEN dc.detail_count >= mc.max_capacity THEN 1
  1273. ELSE 0
  1274. END AS is_full
  1275. FROM DetailCount dc, MaxCapacity mc
  1276. </select>
  1277. </mapper>