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.

284 lines
11 KiB

1 year ago
​
11 months ago
1 year ago
​
​
11 months ago
​
1 year ago
​
11 months ago
1 year ago
11 months ago
1 year ago
​
11 months ago
​
​
1 year ago
​
​
​
11 months ago
1 year ago
​
​
​
​
11 months ago
1 year ago
​
​
​
​
​
​
11 months ago
1 year ago
​
11 months ago
​
11 months ago
​
​
​
​
​
​
11 months ago
1 year ago
​
​
​
​
​
​
​
​
​
1 year ago
11 months ago
1 year ago
11 months ago
1 year ago
1 year ago
11 months ago
1 year ago
​
​
11 months ago
1 year ago
​
​
​
11 months ago
1 year ago
1 year ago
​
11 months ago
12 months ago
​
11 months ago
​
1 year ago
​
​
​
​
​
11 months ago
1 year ago
11 months ago
1 year ago
11 months ago
1 year ago
​
​
​
​
11 months ago
​
​
​
​
​
​
​
​
​
​
11 months ago
​
11 months ago
​
​
​
11 months ago
​
​
11 months ago
​
​
​
​
11 months ago
​
​
​
11 months ago
​
​
​
​
11 months ago
​
11 months ago
​
​
​
11 months ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
11 months ago
11 months ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
11 months ago
11 months ago
​
11 months ago
11 months ago
11 months ago
11 months ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
1 year ago
​
  1. package com.gaotao.modules.handlingunit.controller;
  2. import com.gaotao.common.exception.XJException;
  3. import com.gaotao.common.utils.R;
  4. import com.gaotao.modules.handlingunit.entity.HandlingUnit;
  5. import com.gaotao.modules.handlingunit.service.HandlingUnitService;
  6. import com.gaotao.modules.handlingunit.service.HandlingUnitIdGeneratorService;
  7. import com.gaotao.modules.handlingunit.service.HandlingUnitIdLogService;
  8. import com.gaotao.modules.handlingunit.dao.HandlingUnitMapper;
  9. import com.gaotao.modules.sys.controller.AbstractController;
  10. import lombok.extern.slf4j.Slf4j;
  11. import org.springframework.beans.BeanUtils;
  12. import org.springframework.beans.factory.annotation.Autowired;
  13. import org.springframework.transaction.annotation.Transactional;
  14. import org.springframework.web.bind.annotation.*;
  15. import java.math.BigDecimal;
  16. import java.util.Date;
  17. import java.util.HashMap;
  18. import java.util.Map;
  19. /**
  20. * PDA标签查询控制器
  21. *
  22. * <p><b>主要功能:</b></p>
  23. * <ul>
  24. * <li>扫描标签查询HandlingUnit信息</li>
  25. * <li>显示物料编码、库位、仓库、批次号、wdr等信息</li>
  26. * </ul>
  27. *
  28. * @author System
  29. * @since 2025-01-23
  30. */
  31. @Slf4j
  32. @RestController
  33. @RequestMapping("/pda/label")
  34. public class PdaLabelController extends AbstractController {
  35. @Autowired
  36. private HandlingUnitService handlingUnitService;
  37. @Autowired
  38. private HandlingUnitMapper handlingUnitMapper;
  39. @Autowired
  40. private HandlingUnitIdGeneratorService handlingUnitIdGeneratorService;
  41. @Autowired
  42. private HandlingUnitIdLogService handlingUnitIdLogService;
  43. /**
  44. * @Author System
  45. * @Description 查询标签信息
  46. * @Date 2025/01/23
  47. * @Param [Map<String, Object>]
  48. * @return com.gaotao.common.utils.R
  49. **/
  50. @PostMapping("query")
  51. public R queryLabelInfo(@RequestBody Map<String, Object> params) {
  52. try {
  53. //String site = (String) params.get("site");
  54. String labelCode = (String) params.get("labelCode");
  55. log.info("=== 开始查询标签信息 ===");
  56. //log.info("工厂: {}, 标签编码: {}", site, labelCode);
  57. // 参数验证
  58. /*if (site == null || site.trim().isEmpty()) {
  59. return R.error("工厂编码不能为空");
  60. }*/
  61. if (labelCode == null || labelCode.trim().isEmpty()) {
  62. return R.error("标签编码不能为空");
  63. }
  64. // 查询HandlingUnit信息
  65. HandlingUnit handlingUnit = handlingUnitService.lambdaQuery()
  66. .eq(HandlingUnit::getUnitId, labelCode.trim())
  67. .one();
  68. if (handlingUnit == null) {
  69. log.warn("标签不存在: labelCode={}", labelCode);
  70. return R.error("标签不存在");
  71. }
  72. if(!"Y".equals(handlingUnit.getInStockFlag()) && !"X".equals(handlingUnit.getInStockFlag())){
  73. return R.error("标签库存已经被消耗!");
  74. }
  75. log.info("查询到标签信息: unitId={}, partNo={}, locationId={}, warehouseId={}, batchNo={}, wdr={}",
  76. handlingUnit.getUnitId(),
  77. handlingUnit.getPartNo(),
  78. handlingUnit.getLocationId(),
  79. handlingUnit.getWarehouseId(),
  80. handlingUnit.getBatchNo(),
  81. handlingUnit.getWdr());
  82. log.info("=== 标签信息查询完成 ===");
  83. return R.ok().put("data", handlingUnit);
  84. } catch (Exception e) {
  85. log.error("=== 查询标签信息失败 === 错误信息: {}", e.getMessage(), e);
  86. return R.error("查询失败: " + e.getMessage());
  87. }
  88. }
  89. /**
  90. * @Author rqrq
  91. * @Description 取消WMS预留 - rqrq
  92. * @Date 2025/11/01
  93. * @Param [Map<String, Object>]
  94. * @return com.gaotao.common.utils.R
  95. **/
  96. @PostMapping("cancelReserve")
  97. public R cancelReserve(@RequestBody Map<String, Object> params) throws Exception {
  98. String site = (String) params.get("site");
  99. String unitId = (String) params.get("unitId");
  100. log.info("=== 开始取消WMS预留 - rqrq ===");
  101. log.info("工厂: {}, 标签编码: {}", site, unitId);
  102. // 参数验证 - rqrq
  103. if (site == null || site.trim().isEmpty()) {
  104. throw new RuntimeException("工厂编码不能为空");
  105. }
  106. if (unitId == null || unitId.trim().isEmpty()) {
  107. throw new RuntimeException("标签编码不能为空");
  108. }
  109. // 查询HandlingUnit是否存在 - rqrq
  110. HandlingUnit handlingUnit = handlingUnitService.lambdaQuery()
  111. .eq(HandlingUnit::getSite, site)
  112. .eq(HandlingUnit::getUnitId, unitId.trim())
  113. .one();
  114. if (handlingUnit == null) {
  115. log.warn("标签不存在 - rqrq: site={}, unitId={}", site, unitId);
  116. throw new RuntimeException("标签不存在");
  117. }
  118. // 检查是否被预留 - rqrq
  119. if (!"Y".equals(handlingUnit.getReserveFlag())) {
  120. log.warn("标签未被预留 - rqrq: site={}, unitId={}", site, unitId);
  121. throw new RuntimeException("该标签未被WMS预留");
  122. }
  123. // 调用Mapper方法取消预留 - rqrq
  124. handlingUnitMapper.cancelReserve(site, unitId);
  125. log.info("取消WMS预留成功 - rqrq: unitId={}", unitId);
  126. log.info("=== 取消WMS预留完成 - rqrq ===");
  127. return R.ok();
  128. }
  129. /**
  130. * @Author System
  131. * @Description 标签拆分 - 将原标签拆分出指定数量到新标签
  132. * @Date 2025/01/18
  133. * @Param [Map<String, Object>]
  134. * @return com.gaotao.common.utils.R
  135. **/
  136. @PostMapping("split")
  137. @Transactional
  138. public R splitLabel(@RequestBody Map<String, Object> params) {
  139. try {
  140. String site = (String) params.get("site");
  141. String unitId = (String) params.get("unitId");
  142. String operatorName = (String) params.get("operatorName");
  143. BigDecimal splitQty = new BigDecimal(params.get("splitQty").toString());
  144. log.info("=== 开始标签拆分 ===");
  145. log.info("工厂: {}, 原标签: {}, 拆分数量: {}, 操作人: {}", site, unitId, splitQty, operatorName);
  146. // 1. 参数验证
  147. if (site == null || site.trim().isEmpty()) {
  148. throw new XJException("工厂编码不能为空");
  149. }
  150. if (unitId == null || unitId.trim().isEmpty()) {
  151. throw new XJException("标签编码不能为空");
  152. }
  153. if (splitQty.compareTo(BigDecimal.ZERO) <= 0) {
  154. throw new XJException("拆分数量必须大于0");
  155. }
  156. // 2. 查询原标签
  157. HandlingUnit originalUnit = handlingUnitService.lambdaQuery()
  158. .eq(HandlingUnit::getSite, site)
  159. .eq(HandlingUnit::getUnitId, unitId)
  160. .one();
  161. if (originalUnit == null) {
  162. throw new XJException("原标签不存在");
  163. }
  164. // 3. 验证库存状态
  165. if (!"Y".equals(originalUnit.getInStockFlag()) && !"X".equals(originalUnit.getInStockFlag())) {
  166. throw new XJException("该标签库存已被消耗,不能拆分");
  167. }
  168. // 4. 验证拆分数量
  169. BigDecimal originalQty = originalUnit.getQty();
  170. if (splitQty.compareTo(originalQty) >= 0) {
  171. throw new XJException("拆分数量必须小于原标签数量(" + originalQty + ")");
  172. }
  173. // 5. 生成新标签编码
  174. String newUnitId = handlingUnitIdGeneratorService.generateUnitId(site);
  175. log.info("生成新标签编码: {}", newUnitId);
  176. // 6. 创建新标签(复制原标签所有信息,只修改数量)
  177. HandlingUnit newUnit = new HandlingUnit();
  178. BeanUtils.copyProperties(originalUnit, newUnit);
  179. newUnit.setUnitId(newUnitId);
  180. newUnit.setQty(splitQty); // 新标签数量
  181. newUnit.setOriginalQty(splitQty); // 新标签原始数量
  182. newUnit.setSourceType("SPLIT"); // 来源类型:拆分
  183. newUnit.setParentUnitId(unitId); // 原标签编码
  184. newUnit.setCreatedDate(new Date());
  185. newUnit.setCreatedBy(operatorName);
  186. newUnit.setModifiedDate(new Date());
  187. newUnit.setModifiedBy(operatorName);
  188. newUnit.setRemark("从标签 " + unitId + " 拆分");
  189. // 7. 保存新标签
  190. boolean saveResult = handlingUnitService.save(newUnit);
  191. if (!saveResult) {
  192. log.error("严重错误:新标签保存返回失败!unitId={}", newUnitId);
  193. handlingUnitIdLogService.logUnitIdGeneration(
  194. newUnitId, site, "LABEL_SPLIT", unitId,
  195. "", originalUnit.getPartNo(), originalUnit.getBatchNo(),
  196. splitQty.doubleValue(), operatorName,
  197. "N", "保存失败-save返回false"
  198. );
  199. throw new XJException("新标签保存失败(save返回false): " + newUnitId);
  200. }
  201. // 8. 记录新标签生成日志
  202. handlingUnitIdLogService.logUnitIdGeneration(
  203. newUnitId, site, "LABEL_SPLIT", unitId,
  204. "", originalUnit.getPartNo(), originalUnit.getBatchNo(),
  205. splitQty.doubleValue(), operatorName,
  206. "Y", "标签拆分成功"
  207. );
  208. // 9. 更新原标签数量
  209. BigDecimal remainQty = originalQty.subtract(splitQty);
  210. originalUnit.setQty(remainQty);
  211. originalUnit.setModifiedDate(new Date());
  212. originalUnit.setModifiedBy(operatorName);
  213. boolean updateResult = handlingUnitService.updateById(originalUnit);
  214. if (!updateResult) {
  215. log.error("严重错误:原标签更新失败!unitId={}", unitId);
  216. throw new XJException("原标签更新失败");
  217. }
  218. log.info("=== 标签拆分成功 ===");
  219. log.info("原标签: {} 剩余数量: {}", unitId, remainQty);
  220. log.info("新标签: {} 数量: {}", newUnitId, splitQty);
  221. // 10. 返回结果(包含原标签和新标签ID,用于打印)
  222. Map<String, Object> result = new HashMap<>();
  223. result.put("originalUnitId", unitId);
  224. result.put("newUnitId", newUnitId);
  225. result.put("originalQty", originalQty);
  226. result.put("remainQty", remainQty);
  227. result.put("splitQty", splitQty);
  228. return R.ok().put("data", result);
  229. } catch (XJException e) {
  230. log.error("=== 标签拆分失败 === 错误信息: {}", e.getMessage());
  231. return R.error(e.getMessage());
  232. } catch (Exception e) {
  233. log.error("=== 标签拆分失败 === 错误信息: {}", e.getMessage(), e);
  234. return R.error("拆分失败: " + e.getMessage());
  235. }
  236. }
  237. }