| | |
| | | import com.mes.device.service.GlassInfoService; |
| | | import lombok.RequiredArgsConstructor; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.http.HttpStatus; |
| | | import org.springframework.http.ResponseEntity; |
| | | import org.springframework.util.CollectionUtils; |
| | | import org.springframework.web.bind.annotation.*; |
| | | 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.client.RestTemplate; |
| | | |
| | | import java.util.List; |
| | |
| | | private final GlassInfoService glassInfoService; |
| | | private final RestTemplate restTemplate = new RestTemplate(); |
| | | |
| | | @Value("${mes.engineering.import-url}") |
| | | private String mesEngineeringImportUrl; |
| | | |
| | | /** |
| | | * 导入工程 |
| | | * 前端入参示例: |
| | | * { |
| | | * "excelRows": [ |
| | | * {"glassId":"GL001","width":"1000","height":"2000","thickness":"5","quantity":"2","orderNumber":"NG25082101","filmsId":"白玻"} |
| | | * {"glassId":"GL001","width":"1000","height":"2000","thickness":"5","quantity":"2","flowCardId":"NG25082101","filmsId":"白玻"} |
| | | * ] |
| | | * } |
| | | */ |
| | |
| | | Map<String, Object> payload = glassInfoService.buildEngineerImportPayload(excelRows); |
| | | log.info("构建的 MES 导入数据: {}", payload); |
| | | |
| | | String mesEngineeringImportUrl = glassInfoService.getMesEngineeringImportUrl(); |
| | | |
| | | try { |
| | | ResponseEntity<Map> mesResp = restTemplate.postForEntity(mesEngineeringImportUrl, payload, Map.class); |
| | | // 直接返回 MES 的响应,让前端根据响应体中的 code 字段判断是否成功 |
| | | return ResponseEntity.status(mesResp.getStatusCode()).body(mesResp.getBody()); |
| | | } catch (org.springframework.web.client.ResourceAccessException e) { |
| | | // 连接超时或无法连接 |
| | | log.error("转发 MES 导入接口失败(连接问题) url={}, error={}", mesEngineeringImportUrl, e.getMessage(), e); |
| | | Map<String, Object> errorResponse = new java.util.HashMap<>(); |
| | | errorResponse.put("code", 500); |
| | | errorResponse.put("message", "无法连接到 MES 接口,请检查网络连接或联系管理员"); |
| | | errorResponse.put("data", false); |
| | | return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(errorResponse); |
| | | } catch (Exception e) { |
| | | // 其他异常 |
| | | log.error("转发 MES 导入接口失败 url={}, error={}", mesEngineeringImportUrl, e.getMessage(), e); |
| | | return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("转发 MES 失败: " + e.getMessage()); |
| | | Map<String, Object> errorResponse = new java.util.HashMap<>(); |
| | | errorResponse.put("code", 500); |
| | | errorResponse.put("message", "转发 MES 失败: " + e.getMessage()); |
| | | errorResponse.put("data", false); |
| | | return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(errorResponse); |
| | | } |
| | | } |
| | | } |