From 9571229a2013472dc701ecf5767f2873b36d8f90 Mon Sep 17 00:00:00 2001
From: huang <1532065656@qq.com>
Date: 星期四, 11 十二月 2025 17:07:19 +0800
Subject: [PATCH] 修复导入Excel功能工程号自增; 添加选择工程号自动填写玻璃id列表
---
mes-processes/mes-plcSend/src/main/java/com/mes/device/controller/GlassInfoImportController.java | 157 ++++++++++++++++++++++++++++++++++++++++++++++++++-
1 files changed, 152 insertions(+), 5 deletions(-)
diff --git a/mes-processes/mes-plcSend/src/main/java/com/mes/device/controller/GlassInfoImportController.java b/mes-processes/mes-plcSend/src/main/java/com/mes/device/controller/GlassInfoImportController.java
index f310f10..59670ef 100644
--- a/mes-processes/mes-plcSend/src/main/java/com/mes/device/controller/GlassInfoImportController.java
+++ b/mes-processes/mes-plcSend/src/main/java/com/mes/device/controller/GlassInfoImportController.java
@@ -1,19 +1,21 @@
package com.mes.device.controller;
+import com.mes.device.entity.EngineeringSequence;
+import com.mes.device.entity.GlassInfo;
+import com.mes.device.service.EngineeringSequenceService;
import com.mes.device.service.GlassInfoService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.util.CollectionUtils;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.RequestBody;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;
+import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.stream.Collectors;
/**
* @author :huang
@@ -27,6 +29,7 @@
public class GlassInfoImportController {
private final GlassInfoService glassInfoService;
+ private final EngineeringSequenceService engineeringSequenceService;
private final RestTemplate restTemplate = new RestTemplate();
@@ -54,12 +57,56 @@
Map<String, Object> payload = glassInfoService.buildEngineerImportPayload(excelRows);
log.info("鏋勫缓鐨� MES 瀵煎叆鏁版嵁: {}", payload);
+ // 浠巔ayload涓彁鍙栧伐绋嬪彿锛坧ayload涓娇鐢ㄧ殑鏄痚ngineerId锛�
+ String engineeringId = (String) payload.get("engineerId");
+ if (engineeringId == null || engineeringId.isEmpty()) {
+ // 濡傛灉payload涓病鏈塭ngineerId锛屽皾璇曚粠glassInfolList涓幏鍙�
+ @SuppressWarnings("unchecked")
+ List<Map<String, Object>> glassInfoList = (List<Map<String, Object>>) payload.get("glassInfolList");
+ if (glassInfoList != null && !glassInfoList.isEmpty()) {
+ Object firstEngineerId = glassInfoList.get(0).get("engineerId");
+ if (firstEngineerId != null) {
+ engineeringId = firstEngineerId.toString();
+ }
+ }
+ }
+
String mesEngineeringImportUrl = glassInfoService.getMesEngineeringImportUrl();
try {
ResponseEntity<Map> mesResp = restTemplate.postForEntity(mesEngineeringImportUrl, payload, Map.class);
+ Map<String, Object> mesBody = mesResp.getBody();
+
+ // 妫�鏌ES鍝嶅簲鏄惁鐪熸鎴愬姛锛堜笉浠呮鏌TTP鐘舵�佺爜锛岃繕瑕佹鏌ュ搷搴斾綋涓殑code瀛楁锛�
+ boolean mesSuccess = false;
+ if (mesResp.getStatusCode().is2xxSuccessful() && mesBody != null) {
+ Object codeObj = mesBody.get("code");
+ if (codeObj != null) {
+ int code = codeObj instanceof Number ? ((Number) codeObj).intValue() :
+ Integer.parseInt(String.valueOf(codeObj));
+ // MES鎴愬姛閫氬父杩斿洖code=200鎴�0
+ mesSuccess = (code == 200 || code == 0);
+ } else {
+ // 濡傛灉娌℃湁code瀛楁锛岃涓篐TTP 2xx灏辨槸鎴愬姛
+ mesSuccess = true;
+ }
+ }
+
+ // 鍙湁MES瀵煎叆鐪熸鎴愬姛鏃讹紝鎵嶄繚瀛樼幓鐠冧俊鎭埌鏈湴鏁版嵁搴擄紝骞跺叧鑱攅ngineering_id
+ if (mesSuccess && engineeringId != null) {
+ try {
+ glassInfoService.saveGlassInfosFromExcel(excelRows, engineeringId);
+ log.info("MES瀵煎叆鎴愬姛锛屽凡淇濆瓨鐜荤拑淇℃伅鍒版湰鍦版暟鎹簱锛屽伐绋嬪彿: {}", engineeringId);
+ } catch (Exception e) {
+ log.error("MES瀵煎叆鎴愬姛锛屼絾淇濆瓨鐜荤拑淇℃伅鍒版湰鍦版暟鎹簱澶辫触: engineeringId={}", engineeringId, e);
+ // 鍗充娇淇濆瓨澶辫触锛屼篃杩斿洖MES鐨勬垚鍔熷搷搴旓紝浣嗚褰曢敊璇棩蹇�
+ }
+ } else {
+ log.warn("MES瀵煎叆鏈垚鍔燂紝涓嶄繚瀛樼幓鐠冧俊鎭埌鏈湴鏁版嵁搴�: engineeringId={}, mesSuccess={}", engineeringId, mesSuccess);
+ }
+
// 鐩存帴杩斿洖 MES 鐨勫搷搴旓紝璁╁墠绔牴鎹搷搴斾綋涓殑 code 瀛楁鍒ゆ柇鏄惁鎴愬姛
- return ResponseEntity.status(mesResp.getStatusCode()).body(mesResp.getBody());
+ return ResponseEntity.status(mesResp.getStatusCode()).body(mesBody);
} catch (org.springframework.web.client.ResourceAccessException e) {
// 杩炴帴瓒呮椂鎴栨棤娉曡繛鎺�
log.error("杞彂 MES 瀵煎叆鎺ュ彛澶辫触锛堣繛鎺ラ棶棰橈級 url={}, error={}", mesEngineeringImportUrl, e.getMessage(), e);
@@ -78,6 +125,106 @@
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(errorResponse);
}
}
+
+ /**
+ * 鏌ヨ鎵�鏈夊伐绋嬪彿鍒楄〃
+ */
+ @GetMapping("/engineering/list")
+ public ResponseEntity<?> getEngineeringList() {
+ try {
+ List<EngineeringSequence> list = engineeringSequenceService.list();
+ List<Map<String, Object>> result = list.stream()
+ .map(seq -> {
+ Map<String, Object> map = new HashMap<>();
+ map.put("engineeringId", seq.getEngineeringId());
+ map.put("date", seq.getDate());
+ map.put("sequence", seq.getSequence());
+ return map;
+ })
+ .collect(Collectors.toList());
+ return ResponseEntity.ok(result);
+ } catch (Exception e) {
+ log.error("鏌ヨ宸ョ▼鍙峰垪琛ㄥけ璐�", e);
+ Map<String, Object> errorResponse = new HashMap<>();
+ errorResponse.put("code", 500);
+ errorResponse.put("message", "鏌ヨ宸ョ▼鍙峰垪琛ㄥけ璐�: " + e.getMessage());
+ return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(errorResponse);
+ }
+ }
+
+ /**
+ * 鏍规嵁宸ョ▼鍙锋煡璇㈠搴旂殑鐜荤拑ID鍒楄〃
+ */
+ @GetMapping("/engineering/{engineeringId}/glassIds")
+ public ResponseEntity<?> getGlassIdsByEngineeringId(@PathVariable String engineeringId) {
+ try {
+ List<GlassInfo> glassInfos = glassInfoService.getGlassInfosByEngineeringId(engineeringId);
+ List<String> glassIds = glassInfos.stream()
+ .map(GlassInfo::getGlassId)
+ .filter(id -> id != null && !id.trim().isEmpty())
+ .collect(Collectors.toList());
+
+ Map<String, Object> result = new HashMap<>();
+ result.put("engineeringId", engineeringId);
+ result.put("glassIds", glassIds);
+ result.put("count", glassIds.size());
+
+ return ResponseEntity.ok(result);
+ } catch (Exception e) {
+ log.error("鏍规嵁宸ョ▼鍙锋煡璇㈢幓鐠僆D鍒楄〃澶辫触: engineeringId={}", engineeringId, e);
+ Map<String, Object> errorResponse = new HashMap<>();
+ errorResponse.put("code", 500);
+ errorResponse.put("message", "鏌ヨ鐜荤拑ID鍒楄〃澶辫触: " + e.getMessage());
+ return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(errorResponse);
+ }
+ }
+
+ /**
+ * 鍒犻櫎宸ョ▼鍙峰強鍏跺叧鑱旂殑鐜荤拑淇℃伅
+ */
+ @DeleteMapping("/engineering/{engineeringId}")
+ public ResponseEntity<?> deleteEngineering(@PathVariable String engineeringId) {
+ try {
+ // 1. 鍒犻櫎glass_info琛ㄤ腑瀵瑰簲宸ョ▼鍙风殑鐜荤拑淇℃伅
+ int deletedGlassCount = glassInfoService.deleteGlassInfosByEngineeringId(engineeringId);
+
+ // 2. 鍒犻櫎engineering_sequence琛ㄤ腑鐨勫伐绋嬪彿璁板綍锛堥�昏緫鍒犻櫎锛�
+ EngineeringSequence sequence = engineeringSequenceService.getOne(
+ new com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper<EngineeringSequence>()
+ .eq(EngineeringSequence::getEngineeringId, engineeringId)
+ .eq(EngineeringSequence::getIsDeleted, 0) // 鍙煡璇㈡湭鍒犻櫎鐨勮褰�
+ .last("LIMIT 1")
+ );
+
+ boolean deletedSequence = false;
+ if (sequence != null) {
+ // removeById 浼氳嚜鍔ㄤ娇鐢ㄩ�昏緫鍒犻櫎锛堝洜涓哄疄浣撶被鏈� @TableLogic 娉ㄨВ锛�
+ deletedSequence = engineeringSequenceService.removeById(sequence.getId());
+ log.info("宸插垹闄ゅ伐绋嬪彿璁板綍: engineeringId={}, sequenceId={}", engineeringId, sequence.getId());
+ } else {
+ log.warn("鏈壘鍒板伐绋嬪彿璁板綍: engineeringId={}", engineeringId);
+ }
+
+ Map<String, Object> result = new HashMap<>();
+ result.put("engineeringId", engineeringId);
+ result.put("deletedGlassCount", deletedGlassCount);
+ result.put("deletedSequence", deletedSequence);
+ result.put("success", true);
+ result.put("message", String.format("宸插垹闄ゅ伐绋嬪彿 %s锛屽叡鍒犻櫎 %d 鏉$幓鐠冧俊鎭�", engineeringId, deletedGlassCount));
+
+ log.info("鍒犻櫎宸ョ▼鍙锋垚鍔�: engineeringId={}, deletedGlassCount={}, deletedSequence={}",
+ engineeringId, deletedGlassCount, deletedSequence);
+
+ return ResponseEntity.ok(result);
+ } catch (Exception e) {
+ log.error("鍒犻櫎宸ョ▼鍙峰け璐�: engineeringId={}", engineeringId, e);
+ Map<String, Object> errorResponse = new HashMap<>();
+ errorResponse.put("code", 500);
+ errorResponse.put("message", "鍒犻櫎宸ョ▼鍙峰け璐�: " + e.getMessage());
+ errorResponse.put("success", false);
+ return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(errorResponse);
+ }
+ }
}
--
Gitblit v1.8.0