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.

1465 lines
62 KiB

4 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
3 months ago
4 months ago
4 months ago
3 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
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
3 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
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 WITH (NOLOCK)
  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 WITH (NOLOCK)
  35. INNER JOIN handling_unit b WITH (NOLOCK) ON a.site = b.site AND a.serial_no = b.unit_id
  36. INNER JOIN pallet c WITH (NOLOCK) 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制作/rqrq -->
  126. <select id="getPalletInfo" resultType="java.util.Map">
  127. SELECT pallet_id, pallet_type, status, location_code, site, calling_flag
  128. FROM pallet WITH (NOLOCK)
  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. <!-- rqrq - 根据序列号列表查询SOIssueNotifyOrderMaterialList_detail明细 -->
  494. <select id="getSOIssueNotifyDetailsBySerialNos" resultType="com.gaotao.modules.notify.entity.SOIssueNotifyOrderMaterialListDetail">
  495. SELECT
  496. site,
  497. notify_no AS notifyNo,
  498. item_no AS itemNo,
  499. bom_item_no AS bomItemNo,
  500. serialNo,
  501. task_ref AS taskRef,
  502. task_item AS taskItem,
  503. task_seq AS taskSeq,
  504. out_wcs_flag AS outWcsFlag,
  505. issure_flag AS issureFlag
  506. FROM SOIssueNotifyOrderMaterialList_detail
  507. WHERE site = #{site} and out_wcs_flag='N'
  508. <if test="serialNos != null and serialNos.size() > 0">
  509. AND serialNo IN
  510. <foreach collection="serialNos" item="serialNo" open="(" separator="," close=")">
  511. #{serialNo}
  512. </foreach>
  513. </if>
  514. </select>
  515. <!-- rqrq - 根据task_no+item_no+seq_no更新wms_order_task_detail状态为已完成已分拣 -->
  516. <update id="updateWmsOrderTaskDetailStatusForSorting">
  517. UPDATE wms_order_task_detail
  518. SET status = '已完成',
  519. wms_status = '已分拣'
  520. WHERE site = #{site}
  521. AND task_no = #{taskNo}
  522. AND item_no = #{itemNo}
  523. AND seq_no = #{seqNo}
  524. </update>
  525. <update id="updateWmsOrderTaskDetailStatusForAllOuting">
  526. UPDATE wms_order_task_detail
  527. SET status = '已完成',
  528. wms_status = '直接出库'
  529. WHERE site = #{site}
  530. AND task_no = #{taskNo}
  531. AND item_no = #{itemNo}
  532. AND seq_no = #{seqNo}
  533. </update>
  534. <!-- rqrq - 检查某个任务的所有明细是否都已完成 -->
  535. <select id="checkAllTaskDetailCompleted" resultType="int">
  536. SELECT COUNT(*)
  537. FROM wms_order_task_detail
  538. WHERE site = #{site}
  539. AND task_no = #{taskNo}
  540. AND item_no = #{itemNo}
  541. AND status != '已完成'
  542. </select>
  543. <!-- rqrq - 更新wms_order_task主表状态为已完成 -->
  544. <update id="updateWmsOrderTaskStatusCompleted">
  545. UPDATE wms_order_task
  546. SET status = '已完成'
  547. WHERE site = #{site}
  548. AND task_no = #{taskNo}
  549. AND item_no = #{itemNo}
  550. </update>
  551. <insert id="insertWmsTransportTaskDetail" >
  552. insert into wms_transport_task_detail(
  553. site,task_no,item_no,seq_no,action_type,[comment],from_location,to_location,agv_code,[status],start_time,
  554. error_code,error_msg
  555. ) values (
  556. #{site}, #{taskNo}, #{itemNo}, #{seqNo}, #{actionType}, #{comment}, #{fromLocation}, #{toLocation}, #{agvCode}, #{status}, #{startTime},
  557. #{errorCode}, #{errorMsg}
  558. )
  559. </insert>
  560. <insert id="insertWmsOrderTaskDetail" >
  561. insert into wms_order_task_detail(
  562. site,task_no,item_no,seq_no,action_type,[comment],from_location,to_location,agv_code,[status],start_time,
  563. error_code,error_msg,pallet_id,wms_status
  564. ) values (
  565. #{site}, #{taskNo}, #{itemNo}, #{seqNo}, #{actionType}, #{comment}, #{fromLocation}, #{toLocation}, #{agvCode}, #{status}, #{startTime},
  566. #{errorCode}, #{errorMsg},#{palletId},#{wmsStatus}
  567. )
  568. </insert>
  569. <select id="getMaxSeqNoForTaskDetail" resultType="Integer">
  570. select isnull(max(seq_no),0)+1 from wms_transport_task_detail
  571. where task_no=#{taskNo} and site=#{site} and item_no= 1
  572. </select>
  573. <update id="updateTransportTaskStatusForSiteAndNo">
  574. update wms_transport_task set [status]=#{status} where site=#{site} and task_no=#{taskNo}
  575. </update>
  576. <!-- rqrq - 使用status状态控制并发:先将状态改为'处理中'锁定记录 -->
  577. <update id="lockTaskDetailForProcessing">
  578. update wms_transport_task_detail
  579. set [status]='处理中', start_time=GETDATE()
  580. where id=#{id} and status in ('已录入','处理失败','回调处理失败')
  581. </update>
  582. <!-- rqrq - 更新任务明细状态为最终状态 -->
  583. <update id="updateTransportTaskDetailStatusForId">
  584. update wms_transport_task_detail
  585. set [status]=#{status}
  586. where id=#{id}
  587. </update>
  588. <!-- rqrq - 查询待处理的AGV回调任务明细(状态控制并发) -->
  589. <select id="getTransportTaskDetailListWithStatus" resultType="WmsTransportTaskDetail">
  590. select id,site,task_no as taskNo,item_no as itemNo,seq_no as seqNo,action_type as actionType,[comment],from_location as fromLocation,
  591. to_location as toLocation,agv_code as agvCode,[status],start_time as startTime,
  592. error_code as errorCode,error_msg as errorMsg
  593. from wms_transport_task_detail
  594. where site = #{site} and status in ('处理失败','回调处理失败','已录入')
  595. </select>
  596. <!-- 查询指定状态的订单任务明细列表 - AI制作 -->
  597. <select id="getOrderTaskDetailListWithStatus" resultType="WmsOrderTaskDetail">
  598. select id,site,task_no as taskNo,item_no as itemNo,seq_no as seqNo,action_type as actionType,[comment],from_location as fromLocation,
  599. to_location as toLocation,agv_code as agvCode,[status],start_time as startTime,
  600. error_code as errorCode,error_msg as errorMsg
  601. from wms_order_task_detail
  602. where site = #{site} and status in ('处理失败','回调处理失败','已录入')
  603. </select>
  604. <!-- 根据ID更新订单任务明细状态 - AI制作 -->
  605. <update id="updateOrderTaskDetailStatusForId">
  606. update wms_order_task_detail set [status]=#{status} where id=#{id}
  607. </update>
  608. <!-- 根据任务号获取栈板ID - AI制作 -->
  609. <select id="getPalletIdByOrderTaskNo" resultType="String">
  610. select pallet_id from wms_order_task where task_no = #{taskNo}
  611. </select>
  612. <!-- 根据栈板号和任务类型查找订单任务 - AI制作 -->
  613. <select id="findOrderTaskByPalletAndType" resultType="WmsOrderTask">
  614. select top 1 id, site, task_no as taskNo, item_no as itemNo, source_type as sourceType,
  615. source_bill_no as sourceBillNo, source_line_id as sourceLineId, part_no as partNo,
  616. qty, batch_no as batchNo, serial_no as serialNo, from_location as fromLocation,
  617. to_location as toLocation, pallet_id as palletId, agv_code as agvCode,
  618. priority, status, wms_send_time as wmsSendTime, wcs_receive_time as wcsReceiveTime,
  619. start_time as startTime, complete_time as completeTime, error_code as errorCode,
  620. error_msg as errorMsg, created_by as createdBy, created_time as createdTime,
  621. updated_time as updatedTime, wcs_task_id as wcsTaskId, finish_qty as finishQty,
  622. wms_status as wmsStatus
  623. from wms_order_task
  624. where site = #{site}
  625. and pallet_id = #{palletId}
  626. and source_type = #{sourceType}
  627. and status in ('已创建', '执行中', '已下发')
  628. order by created_time desc
  629. </select>
  630. <!-- 获取订单任务明细的最大序号 - AI制作 -->
  631. <select id="getMaxSeqNoForOrderTaskDetail" resultType="Integer">
  632. select isnull(max(seq_no),0)+1 from wms_order_task_detail
  633. where task_no=#{taskNo} and site=#{site}
  634. </select>
  635. <!-- 插入WCS回调任务 - AI制作 -->
  636. <insert id="insertWcsCallbackTask" useGeneratedKeys="true" keyProperty="id">
  637. INSERT INTO wcs_callback_task (
  638. site, pallet_id, trans_type_desc, to_warehouse_id, to_location_id,
  639. status, created_time, retry_count, remark, task_no, item_no, to_station
  640. ) VALUES (
  641. #{site}, #{palletId}, #{transTypeDesc}, #{toWarehouseId}, #{toLocationId},
  642. #{status}, #{createdTime}, #{retryCount}, #{remark}, #{taskNo}, #{itemNo}, #{toStation}
  643. )
  644. </insert>
  645. <!-- 查询指定状态的WCS回调任务列表(含超时恢复机制) - AI制作 -->
  646. <select id="getWcsCallbackTaskListWithStatus" resultType="WcsCallbackTask">
  647. select id, site, pallet_id as palletId, trans_type_desc as transTypeDesc,
  648. to_warehouse_id as toWarehouseId, to_location_id as toLocationId,
  649. status, created_time as createdTime, process_start_time as processStartTime,
  650. process_end_time as processEndTime, error_msg as errorMsg,
  651. retry_count as retryCount, remark,task_no,item_no,to_station
  652. from wcs_callback_task
  653. where site = #{site}
  654. and (
  655. status in ('已录入', '处理失败')
  656. or (status = '处理中' and process_start_time &lt; DATEADD(MINUTE, -10, GETDATE()))
  657. )
  658. and (retry_count is null or retry_count &lt; 3)
  659. order by created_time
  660. </select>
  661. <!-- 更新WCS回调任务状态 - AI制作 -->
  662. <update id="updateWcsCallbackTaskStatus">
  663. update wcs_callback_task
  664. set status = #{status}
  665. <if test="processStartTime != null">
  666. , process_start_time = #{processStartTime}
  667. </if>
  668. <if test="processEndTime != null">
  669. , process_end_time = #{processEndTime}
  670. </if>
  671. <if test="errorMsg != null">
  672. , error_msg = #{errorMsg}
  673. </if>
  674. where id = #{id}
  675. </update>
  676. <!-- 原子性更新WCS回调任务状态(乐观锁版本,防止重复处理) - AI制作 -->
  677. <update id="updateWcsCallbackTaskStatusWithLock">
  678. UPDATE wcs_callback_task
  679. SET status = #{newStatus},
  680. process_start_time = #{processStartTime}
  681. WHERE id = #{id}
  682. AND status = #{oldStatus}
  683. </update>
  684. <update id="updatePalletWcsLocation" >
  685. update pallet set wcs_location = #{location},updated_by='wms_sys',updated_time=getdate()
  686. where site = #{site} and pallet_id = #{palletId}
  687. </update>
  688. <!-- 更新WCS回调任务重试次数 - AI制作 -->
  689. <update id="updateWcsCallbackTaskRetryCount">
  690. update wcs_callback_task set retry_count = #{retryCount} where id = #{id}
  691. </update>
  692. <!-- 根据栈板ID和动作类型查找订单任务 - AI制作 -->
  693. <select id="findOrderTasksByPalletAndActionType" resultType="WmsOrderTask">
  694. select id, site, task_no as taskNo, item_no as itemNo, source_type as sourceType,
  695. source_bill_no as sourceBillNo, source_line_id as sourceLineId, part_no as partNo,
  696. qty, batch_no as batchNo, serial_no as serialNo, from_location as fromLocation,
  697. to_location as toLocation, pallet_id as palletId, agv_code as agvCode,
  698. priority, status, wms_send_time as wmsSendTime, wcs_receive_time as wcsReceiveTime,
  699. start_time as startTime, complete_time as completeTime, error_code as errorCode,
  700. error_msg as errorMsg, created_by as createdBy, created_time as createdTime,
  701. updated_time as updatedTime, wcs_task_id as wcsTaskId, finish_qty as finishQty,
  702. wms_status as wmsStatus
  703. from wms_order_task
  704. <where>
  705. and site = #{site}
  706. and pallet_id = #{palletId}
  707. <if test="sourceType != null and sourceType != ''">
  708. and source_type = #{sourceType}
  709. </if>
  710. and status = #{status}
  711. </where>
  712. order by created_time desc
  713. </select>
  714. <select id="findOrderTasksByTaskNo" resultType="WmsOrderTask">
  715. select id, site, task_no as taskNo, item_no as itemNo, source_type as sourceType,
  716. source_bill_no as sourceBillNo, source_line_id as sourceLineId, part_no as partNo,
  717. qty, batch_no as batchNo, serial_no as serialNo, from_location as fromLocation,
  718. to_location as toLocation, pallet_id as palletId, agv_code as agvCode,
  719. priority, status, wms_send_time as wmsSendTime, wcs_receive_time as wcsReceiveTime,
  720. start_time as startTime, complete_time as completeTime, error_code as errorCode,
  721. error_msg as errorMsg, created_by as createdBy, created_time as createdTime,
  722. updated_time as updatedTime, wcs_task_id as wcsTaskId, finish_qty as finishQty,
  723. wms_status as wmsStatus
  724. from wms_order_task
  725. where site = #{site}
  726. and task_no=#{taskNo}
  727. order by created_time desc
  728. </select>
  729. <select id="findOrderTasksByTaskNoItem" resultType="WmsOrderTask">
  730. select id, site, task_no as taskNo, item_no as itemNo, source_type as sourceType,
  731. source_bill_no as sourceBillNo, source_line_id as sourceLineId, part_no as partNo,
  732. qty, batch_no as batchNo, serial_no as serialNo, from_location as fromLocation,
  733. to_location as toLocation, pallet_id as palletId, agv_code as agvCode,
  734. priority, status, wms_send_time as wmsSendTime, wcs_receive_time as wcsReceiveTime,
  735. start_time as startTime, complete_time as completeTime, error_code as errorCode,
  736. error_msg as errorMsg, created_by as createdBy, created_time as createdTime,
  737. updated_time as updatedTime, wcs_task_id as wcsTaskId, finish_qty as finishQty,
  738. wms_status as wmsStatus
  739. from wms_order_task
  740. where site = #{site}
  741. and task_no=#{taskNo}
  742. and item_no=#{itemNo}
  743. order by created_time desc
  744. </select>
  745. <!-- 更新订单任务状态和WMS状态 - AI制作 -->
  746. <update id="updateOrderTaskStatusAndWmsStatus">
  747. update wms_order_task
  748. set status = #{status}, wms_status = #{wmsStatus}
  749. where id = #{id}
  750. </update>
  751. <!-- 根据任务号更新订单任务明细状态 - AI制作 -->
  752. <update id="updateOrderTaskDetailStatusByTaskNo">
  753. update wms_order_task_detail
  754. set status = #{status} ,wms_status = #{wmsStatus}
  755. where task_no = #{taskNo}
  756. </update>
  757. <update id="updateOrderTaskDetailStatusByTaskNoPalletId">
  758. update wms_order_task_detail
  759. set status = #{status} ,wms_status = #{wmsStatus}
  760. where task_no = #{taskNo} and site=#{site} and pallet_id=#{palletId}
  761. </update>
  762. <!-- 查询立库调栈板出库的订单任务列表 - AI制作 -->
  763. <select id="getWcsOrderTaskListForPalletOut" resultType="WmsOrderTask">
  764. select id, site, task_no as taskNo, item_no as itemNo, source_type as sourceType,
  765. source_bill_no as sourceBillNo, source_line_id as sourceLineId, part_no as partNo,
  766. qty, batch_no as batchNo, serial_no as serialNo, from_location as fromLocation,
  767. to_location as toLocation, pallet_id as palletId, agv_code as agvCode,
  768. priority, status, wms_send_time as wmsSendTime, wcs_receive_time as wcsReceiveTime,
  769. start_time as startTime, complete_time as completeTime, error_code as errorCode,
  770. error_msg as errorMsg, created_by as createdBy, created_time as createdTime,
  771. updated_time as updatedTime, wcs_task_id as wcsTaskId, finish_qty as finishQty,
  772. wms_status as wmsStatus
  773. from wms_order_task
  774. where site = #{site}
  775. and status = '已创建'
  776. and source_type like '%栈板出库%'
  777. and (wms_status is null or wms_status in ('未执行', '等待重试'))
  778. order by priority desc, created_time asc
  779. </select>
  780. <!-- 更新订单任务错误信息 - AI制作 -->
  781. <update id="updateOrderTaskErrorInfo">
  782. update wms_order_task
  783. set error_code = #{errorCode},
  784. error_msg = #{errorMsg}
  785. where id = #{id}
  786. </update>
  787. <!-- 更新AGV站点状态 - AI制作 -->
  788. <update id="updateAgvStationStatus">
  789. UPDATE agv_station
  790. SET status_db = #{statusDb},
  791. status = #{status}
  792. WHERE station_code = #{stationCode}
  793. </update>
  794. <update id="updateWTTToLocationForId">
  795. update wms_transport_task set to_location=#{toLocation} where site=#{site} and task_no=#{taskNo}
  796. </update>
  797. <!-- 获取AGV站点状态 - AI制作 -->
  798. <select id="getAgvStationStatus" resultType="Integer">
  799. SELECT status_db
  800. FROM agv_station
  801. WHERE station_code = #{stationCode}
  802. </select>
  803. <select id="getAgvStationType" resultType="String">
  804. SELECT station_type
  805. FROM agv_station
  806. WHERE station_code = #{stationCode}
  807. </select>
  808. <!-- 获取栈板详细信息(包含palletType和autoSort以及托盘类型详情) - AI制作/rqrq -->
  809. <select id="getPalletInfoWithTypeDetails" resultType="PalletData">
  810. SELECT
  811. p.site,
  812. p.pallet_id AS palletId,
  813. p.pallet_type AS palletType,
  814. p.pallet_family AS palletFamily,
  815. p.auto_sort AS autoSort,
  816. p.sore_type AS soreType,
  817. p.location_code AS locationCode,
  818. p.wcs_location AS wcsLocation,
  819. pt.type_desc AS typeDesc,
  820. pt.wcs_auto_sort AS wcsAutoSort,
  821. pt.wcs_pallet_type AS wcsPalletType,
  822. pt.wcs_base_pallet_type AS wcsBasePalletType,
  823. pt.wcs_sore_type AS wcsSoreType,
  824. pt.max_layer AS maxLayer,
  825. pf.pallet_family_desc AS palletFamilyDesc
  826. FROM pallet p WITH (NOLOCK)
  827. LEFT JOIN pallet_type pt WITH (NOLOCK) ON p.site = pt.site AND p.pallet_type = pt.pallet_type
  828. LEFT JOIN pallet_family pf WITH (NOLOCK) ON p.site = pf.site AND p.pallet_family = pf.pallet_family
  829. WHERE p.site = #{site}
  830. AND p.pallet_id = #{palletId}
  831. AND p.is_deleted = '0'
  832. </select>
  833. <!-- 更新栈板类型、自动分拣标志和存储类型 - AI制作/rqrq -->
  834. <update id="updatePalletTypeAndAutoSort">
  835. UPDATE pallet
  836. SET pallet_type = #{palletType},
  837. auto_sort = #{autoSort},
  838. sore_type = #{soreType},
  839. updated_time = GETDATE()
  840. WHERE site = #{site}
  841. AND pallet_id = #{palletId}
  842. AND is_deleted = '0'
  843. </update>
  844. <!-- 获取指定层已占用的位置列表 - rqrq -->
  845. <select id="getOccupiedPositionsByLayer" resultType="java.lang.String">
  846. SELECT DISTINCT position
  847. FROM pallet_detail
  848. WHERE site = #{site}
  849. AND pallet_id = #{palletId}
  850. AND layer = #{layer}
  851. ORDER BY position
  852. </select>
  853. <!-- rqrq - 插入WCS回调栈板扫描记录 -->
  854. <insert id="insertCallbackPalletScan" parameterType="com.gaotao.modules.automatedWarehouse.entity.WcsCallbackPalletScan" useGeneratedKeys="true" keyProperty="callback.id">
  855. INSERT INTO wcs_callback_pallet_scan (
  856. site, pallet_id, task_no, item_no,
  857. wcs_scan_time, wcs_barcode_list, wcs_total_quantity, sore_type,
  858. process_status, retry_count,
  859. created_at, updated_at, json_str,action_type
  860. ) VALUES (
  861. #{callback.site}, #{callback.palletId}, #{callback.taskNo}, #{callback.itemNo},
  862. #{callback.wcsScanTime}, #{callback.wcsBarcodeList}, #{callback.wcsTotalQuantity}, #{callback.soreType},
  863. #{callback.processStatus}, #{callback.retryCount},
  864. GETDATE(), GETDATE(), #{callback.jsonStr}, #{callback.actionType}
  865. )
  866. </insert>
  867. <select id="getPalletType" resultType="PalletType">
  868. 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
  869. FROM pallet_type WHERE site = #{site} AND pallet_type = #{palletType}
  870. </select>
  871. <select id="getAgvStation" resultType="AgvStation">
  872. SELECT id,station_code,station_name,area_type,warehouse_code,location_x,location_y,location_z,active,location_code,remark,
  873. station_area,status_db,[status],station_id,station_type,auto_call_blank_pallet,wait_station_code
  874. FROM agv_station
  875. where station_code=#{stationCode}
  876. </select>
  877. <!-- ==================== 栈板换站相关SQL - rqrq ==================== -->
  878. <!-- rqrq - 检查栈板calling_flag并获取当前站点信息 -->
  879. <select id="checkPalletForChangeStation" resultType="CheckPalletResult">
  880. SELECT
  881. p.calling_flag AS callingFlag,
  882. s.station_id AS currentStationId,
  883. s.station_code AS currentStationCode
  884. FROM pallet p
  885. LEFT JOIN agv_station s ON p.location_code = s.station_code
  886. WHERE p.site = #{site}
  887. AND p.pallet_id = #{palletId}
  888. AND p.is_deleted = '0'
  889. </select>
  890. <!-- rqrq - 获取可选择的区域列表(choose_able为Y) -->
  891. <select id="getAreaOptionsForChange" resultType="Area">
  892. SELECT
  893. area_id AS areaId,
  894. area_desc AS areaDesc,
  895. choose_able AS chooseAble
  896. FROM area
  897. WHERE choose_able = 'Y'
  898. ORDER BY area_id
  899. </select>
  900. <!-- rqrq - 根据区域获取可用站点列表 -->
  901. <select id="getStationsByArea" resultType="AgvStation">
  902. SELECT
  903. station_id AS stationId,
  904. station_code AS stationCode,
  905. station_name AS stationName,
  906. area_type AS areaType,
  907. status_db AS statusDb,
  908. status,
  909. active
  910. FROM agv_station
  911. WHERE area_type = #{areaId}
  912. AND active = 'Y'
  913. AND station_type = '正式站点'
  914. AND status_db = 0
  915. ORDER BY station_id
  916. </select>
  917. <!-- rqrq - 根据区域查找第一个空闲站点(用于自动分配)-->
  918. <select id="findFirstFreeStationByAreaId" resultType="java.lang.String">
  919. SELECT TOP 1 station_code
  920. FROM agv_station
  921. WHERE area_type = #{areaId}
  922. AND active = 'Y'
  923. AND station_type = '正式站点'
  924. AND status_db = 0
  925. ORDER BY station_id
  926. </select>
  927. <!-- ==================== 手工移动托盘相关SQL - rqrq ==================== -->
  928. <!-- rqrq - 检查托盘是否可以手工移动 -->
  929. <select id="checkPalletForManualMove" resultType="CheckPalletResult">
  930. SELECT
  931. p.calling_flag AS callingFlag,
  932. p.location_code AS currentStationCode,
  933. s.station_type AS stationType,
  934. s.station_id as currentStationId,
  935. CASE
  936. WHEN p.location_code IS NULL THEN 'Y'
  937. WHEN s.station_type = '正式站点' THEN 'Y'
  938. ELSE 'N'
  939. END AS canOperate
  940. FROM pallet p
  941. LEFT JOIN agv_station s ON p.location_code = s.station_code
  942. WHERE p.site = #{site}
  943. AND p.pallet_id = #{palletId}
  944. AND p.is_deleted = '0'
  945. </select>
  946. <!-- rqrq - 更新托盘location_code为null(移出站点)-->
  947. <update id="updatePalletRemoveStation">
  948. UPDATE pallet
  949. SET location_code = NULL,
  950. updated_time = GETDATE()
  951. WHERE site = #{site}
  952. AND pallet_id = #{palletId}
  953. AND is_deleted = '0'
  954. </update>
  955. <!-- rqrq - 更新站点状态为空闲 -->
  956. <update id="updateStationToFree">
  957. UPDATE agv_station
  958. SET status_db = 0,
  959. status = '空闲'
  960. WHERE station_code = #{stationCode}
  961. </update>
  962. <!-- rqrq - 更新托盘location_code(绑定站点)-->
  963. <update id="updatePalletBindStation">
  964. UPDATE pallet
  965. SET location_code = #{stationCode},
  966. updated_time = GETDATE()
  967. WHERE site = #{site}
  968. AND pallet_id = #{palletId}
  969. AND is_deleted = '0'
  970. </update>
  971. <!-- rqrq - 更新站点状态为有货 -->
  972. <update id="updateStationToOccupied">
  973. UPDATE agv_station
  974. SET status_db = 1,
  975. status = '有货'
  976. WHERE station_code = #{stationCode}
  977. </update>
  978. <!-- ==================== 空托盘组盘相关SQL - rqrq ==================== -->
  979. <!-- rqrq - 检查托盘是否为空托盘 -->
  980. <select id="checkEmptyPallet" resultType="CheckPalletResult">
  981. SELECT
  982. p.pallet_id AS palletId,
  983. p.pallet_type AS palletType,
  984. p.pallet_family AS palletFamily,
  985. p.location_code AS currentStationCode,
  986. s.station_id AS currentStationId,
  987. CASE
  988. WHEN EXISTS (
  989. SELECT 1 FROM pallet_detail pd
  990. WHERE pd.site = p.site
  991. AND pd.pallet_id = p.pallet_id
  992. )
  993. THEN 'N'
  994. ELSE 'Y'
  995. END AS isEmpty
  996. FROM pallet p
  997. LEFT JOIN agv_station s ON p.location_code = s.station_code
  998. WHERE p.site = #{site}
  999. AND p.pallet_id = #{palletId}
  1000. AND p.is_deleted = '0'
  1001. </select>
  1002. <!-- rqrq - 获取托盘类型列表(根据pallet_family过滤)-->
  1003. <select id="getPalletTypes" resultType="PalletType">
  1004. SELECT
  1005. site,
  1006. pallet_type AS palletType,
  1007. type_desc AS typeDesc,
  1008. pallet_family AS palletFamily,
  1009. max_layer AS maxLayer,
  1010. wcs_auto_sort AS wcsAutoSort,
  1011. wcs_pallet_type AS wcsPalletType,
  1012. wcs_base_pallet_type AS wcsBasePalletType,
  1013. wcs_sore_type AS wcsSoreType
  1014. FROM pallet_type
  1015. WHERE site = #{site}
  1016. <if test="palletFamily != null and palletFamily != ''">
  1017. AND pallet_family = #{palletFamily}
  1018. </if>
  1019. ORDER BY pallet_type
  1020. </select>
  1021. <!-- rqrq - 获取需要自动续盘的站点列表 -->
  1022. <select id="getAutoCallBlankPalletStations" resultType="AgvStation">
  1023. SELECT
  1024. id,
  1025. station_code AS stationCode,
  1026. station_name AS stationName,
  1027. station_type AS stationType,
  1028. status_db AS statusDb,
  1029. status,
  1030. auto_call_blank_pallet AS autoCallBlankPallet,
  1031. auto_call_blank_pallet_type AS autoCallBlankPalletType,
  1032. wait_station_code AS waitStationCode
  1033. FROM agv_station
  1034. WHERE auto_call_blank_pallet = 'Y'
  1035. AND auto_call_blank_pallet_type IS NOT NULL
  1036. AND auto_call_blank_pallet_type != ''
  1037. AND station_type = '正式站点'
  1038. AND status_db = 0
  1039. ORDER BY station_code
  1040. </select>
  1041. <!-- ==================== 取消WCS组盘相关SQL - rqrq ==================== -->
  1042. <!-- rqrq - 检查栈板WCS组盘状态 -->
  1043. <select id="checkPalletWcsStatus" resultType="CheckPalletResult">
  1044. SELECT
  1045. p.pallet_id AS palletId,
  1046. p.calling_flag AS callingFlag,
  1047. CASE
  1048. WHEN EXISTS (
  1049. SELECT 1 FROM pallet_detail pd
  1050. WHERE pd.site = #{site} AND pd.pallet_id = #{palletId} AND pd.wcs_flag = 0
  1051. ) THEN 'Y'
  1052. ELSE 'N'
  1053. END AS canOperate, -- 借用canOperate字段存储hasSentWcsTask
  1054. CASE
  1055. WHEN EXISTS (
  1056. SELECT 1 FROM pallet_detail pd
  1057. WHERE pd.site = #{site} AND pd.pallet_id = #{palletId}
  1058. ) THEN 'Y'
  1059. ELSE 'N'
  1060. END AS isEmpty -- 借用isEmpty字段存储hasDetail
  1061. FROM pallet p
  1062. WHERE p.site = #{site} AND p.pallet_id = #{palletId} AND p.is_deleted = '0'
  1063. </select>
  1064. <!-- rqrq - 检查栈板是否有wcs_flag=0的明细 -->
  1065. <select id="countPalletDetailWithWcsFlagZero" resultType="int">
  1066. SELECT COUNT(*)
  1067. FROM pallet_detail
  1068. WHERE site = #{site} AND pallet_id = #{palletId} AND wcs_flag = 0
  1069. </select>
  1070. <!-- rqrq - 更新栈板所有明细的wcs_flag为1 -->
  1071. <update id="updateAllPalletDetailWcsFlagToOne">
  1072. UPDATE pallet_detail
  1073. SET wcs_flag = 1
  1074. WHERE site = #{site} AND pallet_id = #{palletId}
  1075. </update>
  1076. <!-- rqrq - 删除栈板所有明细 -->
  1077. <delete id="deleteAllPalletDetail">
  1078. DELETE FROM pallet_detail
  1079. WHERE site = #{site} AND pallet_id = #{palletId}
  1080. </delete>
  1081. <select id="getStationByCode" resultType="AgvStation">
  1082. SELECT
  1083. id,
  1084. station_code AS stationCode,
  1085. station_name AS stationName,
  1086. station_type AS stationType,
  1087. status_db AS statusDb,
  1088. status,
  1089. auto_call_blank_pallet AS autoCallBlankPallet,
  1090. auto_call_blank_pallet_type AS autoCallBlankPalletType,
  1091. wait_station_code AS waitStationCode
  1092. FROM agv_station
  1093. WHERE station_code = #{stationCode}
  1094. </select>
  1095. <!-- ==================== 预约取托盘相关SQL - rqrq ==================== -->
  1096. <!-- rqrq - 查询空托盘区可用的空托盘 -->
  1097. <select id="findAvailableEmptyPallet" resultType="Pallet">
  1098. SELECT TOP 1
  1099. p.id,
  1100. p.site,
  1101. p.pallet_id AS palletId,
  1102. p.pallet_type AS palletType,
  1103. p.pallet_size AS palletSize,
  1104. p.max_load AS maxLoad,
  1105. p.status,
  1106. p.location_code AS locationCode,
  1107. p.remark,
  1108. p.is_deleted AS isDeleted,
  1109. p.created_by AS createdBy,
  1110. p.created_time AS createdTime,
  1111. p.updated_by AS updatedBy,
  1112. p.updated_time AS updatedTime,
  1113. p.calling_flag AS callingFlag,
  1114. p.wcs_location AS wcsLocation,
  1115. p.pallet_family AS palletFamily,
  1116. p.sore_type AS soreType,
  1117. p.auto_sort AS autoSort,
  1118. p.empty_flag AS emptyFlag
  1119. FROM pallet p
  1120. INNER JOIN agv_station s ON p.location_code = s.station_code
  1121. left join pallet_detail c on p.pallet_id=c.pallet_id and p.site=c.site
  1122. WHERE p.site = #{site}
  1123. AND p.pallet_type = #{palletType}
  1124. AND p.calling_flag = 'N'
  1125. AND p.is_deleted = '0'
  1126. AND s.area_type = 'Z101'
  1127. AND s.status_db = 1
  1128. AND s.active = 'Y'
  1129. and c.id IS NULL
  1130. ORDER BY p.created_time ASC
  1131. </select>
  1132. <!-- rqrq - 检查指定托盘是否就绪 -->
  1133. <select id="checkPalletReady" resultType="Pallet">
  1134. SELECT
  1135. p.id,
  1136. p.site,
  1137. p.pallet_id AS palletId,
  1138. p.pallet_type AS palletType,
  1139. p.pallet_size AS palletSize,
  1140. p.max_load AS maxLoad,
  1141. p.status,
  1142. p.location_code AS locationCode,
  1143. p.remark,
  1144. p.is_deleted AS isDeleted,
  1145. p.created_by AS createdBy,
  1146. p.created_time AS createdTime,
  1147. p.updated_by AS updatedBy,
  1148. p.updated_time AS updatedTime,
  1149. p.calling_flag AS callingFlag,
  1150. p.wcs_location AS wcsLocation,
  1151. p.pallet_family AS palletFamily,
  1152. p.sore_type AS soreType,
  1153. p.auto_sort AS autoSort,
  1154. p.empty_flag AS emptyFlag
  1155. FROM pallet p
  1156. INNER JOIN agv_station s ON p.location_code = s.station_code
  1157. WHERE p.site = #{site}
  1158. AND p.pallet_id = #{palletId}
  1159. AND p.calling_flag = 'N'
  1160. AND p.is_deleted = '0'
  1161. AND s.area_type IN ('Z101', 'Z103', 'Z104')
  1162. AND s.status_db = 1
  1163. AND s.active = 'Y'
  1164. </select>
  1165. <!-- rqrq - 使用乐观锁更新运输任务状态 -->
  1166. <update id="updateTransportTaskWithLock">
  1167. UPDATE wms_transport_task
  1168. SET status = #{newStatus},
  1169. <if test="palletId != null and palletId != ''">
  1170. pallet_id = #{palletId},
  1171. </if>
  1172. <if test="fromLocation != null and fromLocation != ''">
  1173. from_location = #{fromLocation},
  1174. </if>
  1175. <if test="toLocation != null and toLocation != ''">
  1176. to_location = #{toLocation},
  1177. </if>
  1178. wms_status = #{newWmsStatus},
  1179. updated_time = GETDATE()
  1180. WHERE task_no = #{taskNo}
  1181. AND (wms_status = #{oldWmsStatus} OR wms_status IS NULL)
  1182. </update>
  1183. <!-- rqrq - 根据栈板ID和sourceType查询最新的OrderTask -->
  1184. <select id="findLatestOrderTaskByPallet" resultType="WmsOrderTask">
  1185. SELECT TOP 1
  1186. id,
  1187. site,
  1188. task_no AS taskNo,
  1189. item_no AS itemNo,
  1190. pallet_id AS palletId,
  1191. source_type AS sourceType,
  1192. source_bill_no AS sourceBillNo,
  1193. source_line_id AS sourceLineId,
  1194. part_no AS partNo,
  1195. qty,
  1196. batch_no AS batchNo,
  1197. serial_no AS serialNo,
  1198. from_location AS fromLocation,
  1199. to_location AS toLocation,
  1200. agv_code AS agvCode,
  1201. priority,
  1202. status,
  1203. wms_send_time AS wmsSendTime,
  1204. wcs_receive_time AS wcsReceiveTime,
  1205. start_time AS startTime,
  1206. complete_time AS completeTime,
  1207. error_code AS errorCode,
  1208. error_msg AS errorMsg,
  1209. created_by AS createdBy,
  1210. created_time AS createdTime,
  1211. updated_time AS updatedTime,
  1212. wcs_task_id AS wcsTaskId,
  1213. finish_qty AS finishQty,
  1214. wms_status AS wmsStatus
  1215. FROM wms_order_task
  1216. WHERE site = #{site}
  1217. AND pallet_id = #{palletId}
  1218. AND source_type = #{sourceType}
  1219. ORDER BY created_time DESC
  1220. </select>
  1221. <!-- rqrq - 根据栈板ID更新最新的TransportTask的source_bill_no和source_line_id -->
  1222. <update id="updateTransportTaskSourceInfo">
  1223. UPDATE wms_transport_task
  1224. SET source_bill_no = #{sourceBillNo},
  1225. source_line_id = #{sourceLineId},
  1226. updated_time = GETDATE()
  1227. WHERE id = (
  1228. SELECT TOP 1 id
  1229. FROM wms_transport_task
  1230. WHERE site = #{site}
  1231. AND pallet_id = #{palletId}
  1232. AND source_type = '预约取托盘'
  1233. ORDER BY created_time DESC
  1234. )
  1235. </update>
  1236. <!-- ==================== 调度发货任务相关SQL - rqrq ==================== -->
  1237. <!-- rqrq - 根据栈板编码获取栈板信息 -->
  1238. <select id="getPalletByCode" resultType="Pallet">
  1239. SELECT
  1240. id,
  1241. site,
  1242. pallet_id AS palletId,
  1243. pallet_type AS palletType,
  1244. pallet_size AS palletSize,
  1245. max_load AS maxLoad,
  1246. status,
  1247. location_code AS locationCode,
  1248. remark,
  1249. is_deleted AS isDeleted,
  1250. created_by AS createdBy,
  1251. created_time AS createdTime,
  1252. updated_by AS updatedBy,
  1253. updated_time AS updatedTime,
  1254. calling_flag AS callingFlag,
  1255. wcs_location AS wcsLocation,
  1256. pallet_family AS palletFamily,
  1257. sore_type AS soreType,
  1258. auto_sort AS autoSort,
  1259. empty_flag AS emptyFlag
  1260. FROM pallet WITH (NOLOCK)
  1261. WHERE site = #{site}
  1262. AND pallet_id = #{palletId}
  1263. AND is_deleted = '0'
  1264. </select>
  1265. <!-- rqrq - 根据任务号和行号成对匹配查询发料明细的序列号列表 -->
  1266. <select id="getSerialNosByTaskRefAndItem" resultType="String">
  1267. SELECT DISTINCT serialNo
  1268. FROM SOIssueNotifyOrderMaterialList_detail
  1269. WHERE site = #{site}
  1270. <if test="taskNotes != null and taskNotes.size() > 0">
  1271. AND (
  1272. <foreach collection="taskNotes" item="note" separator=" OR ">
  1273. (task_ref = #{note.taskNo} AND task_item = #{note.itemNo})
  1274. </foreach>
  1275. )
  1276. </if>
  1277. </select>
  1278. <!-- rqrq - 根据序列号列表查询栈板ID列表(去重) -->
  1279. <select id="getPalletIdsBySerialNos" resultType="String">
  1280. SELECT DISTINCT pallet_id
  1281. FROM pallet_detail
  1282. WHERE site = #{site}
  1283. <if test="serialNoList != null and serialNoList.size() > 0">
  1284. AND serial_no IN
  1285. <foreach collection="serialNoList" item="serialNo" open="(" close=")" separator=",">
  1286. #{serialNo}
  1287. </foreach>
  1288. </if>
  1289. </select>
  1290. <!-- rqrq - 检查栈板是否在指定wcsTaskID和站点生成过运输任务 -->
  1291. <select id="checkPalletTaskExists" resultType="int">
  1292. SELECT COUNT(1)
  1293. FROM wms_transport_task
  1294. WHERE site = #{site}
  1295. AND pallet_id = #{palletId}
  1296. AND source_bill_no = #{sourceBillNo}
  1297. AND to_location = #{stationCode}
  1298. </select>
  1299. <!-- rqrq - 检查栈板是否放满(根据pallet_type_area的点位数和max_layer判断) -->
  1300. <select id="checkPalletIsFull" resultType="int">
  1301. WITH PalletInfo AS (
  1302. -- 获取栈板类型和最大层数 - rqrq
  1303. SELECT p.pallet_type, pt.max_layer
  1304. FROM pallet p
  1305. INNER JOIN pallet_type pt ON p.site = pt.site AND p.pallet_type = pt.pallet_type
  1306. WHERE p.site = #{site} AND p.pallet_id = #{palletId}
  1307. ),
  1308. PositionCount AS (
  1309. -- 获取该类型栈板的点位数 - rqrq
  1310. SELECT COUNT(1) AS position_count
  1311. FROM pallet_type_area pta
  1312. INNER JOIN PalletInfo pi ON pta.site = #{site} AND pta.pallet_type = pi.pallet_type
  1313. ),
  1314. DetailCount AS (
  1315. -- 获取栈板已使用的明细数量 - rqrq
  1316. SELECT COUNT(1) AS detail_count
  1317. FROM pallet_detail
  1318. WHERE site = #{site} AND pallet_id = #{palletId}
  1319. ),
  1320. MaxCapacity AS (
  1321. -- 计算栈板最大容量 - rqrq
  1322. SELECT
  1323. CASE
  1324. WHEN pi.max_layer IS NULL OR pi.max_layer = 0 THEN 999999 -- 混装托盘,容量无限 - rqrq
  1325. ELSE pc.position_count * pi.max_layer -- 有层数托盘 = 点位数 * 最大层数 - rqrq
  1326. END AS max_capacity
  1327. FROM PalletInfo pi, PositionCount pc
  1328. )
  1329. -- 判断是否已满(detail_count >= max_capacity 则为满)- rqrq
  1330. SELECT
  1331. CASE
  1332. WHEN dc.detail_count >= mc.max_capacity THEN 1
  1333. ELSE 0
  1334. END AS is_full
  1335. FROM DetailCount dc, MaxCapacity mc
  1336. </select>
  1337. <select id="checkIfHasNeedTask" resultType="WmsTransportTask">
  1338. SELECT top 1
  1339. id,site,task_no,item_no,source_type,source_bill_no,source_line_id,part_no,qty,batch_no,serial_no,from_location,to_location,
  1340. pallet_id,agv_code,priority,[status],wms_send_time,wcs_receive_time,start_time,complete_time,error_code,error_msg,
  1341. created_by,created_time,updated_time,wcs_task_id,finish_qty,wms_status,pallet_type,to_area
  1342. from wms_transport_task
  1343. where site=#{site} and pallet_id=#{palletId} and source_type like '%取托盘%' and [status] in ('已预约','已创建','已下达')
  1344. </select>
  1345. </mapper>