|
|
|
@ -2370,6 +2370,7 @@ public class ScheduleController extends AbstractController { |
|
|
|
String date = Objects.toString(params.get("date"), "").trim(); |
|
|
|
String shift = Objects.toString(params.get("shift"), "").trim(); |
|
|
|
String type = Objects.toString(params.get("type"), "").trim(); |
|
|
|
logger.info("MES获取班次请求开始: machineNo={}, date={}, shift={}, type={}", machineNo, date, shift, type); |
|
|
|
|
|
|
|
if (!StringUtils.hasText(machineNo)) { |
|
|
|
return R.error("机器账号不能为空").put("code", 400); |
|
|
|
@ -2381,24 +2382,26 @@ public class ScheduleController extends AbstractController { |
|
|
|
UriComponentsBuilder uriBuilder = UriComponentsBuilder |
|
|
|
.fromHttpUrl(buildMesApiUrl("/getShift")) |
|
|
|
.queryParam("machineNo", machineNo) |
|
|
|
.queryParam("date", date); |
|
|
|
if (StringUtils.hasText(shift)) { |
|
|
|
uriBuilder.queryParam("shift", shift); |
|
|
|
} |
|
|
|
.queryParam("date", date) |
|
|
|
.queryParam("shift", shift); |
|
|
|
if (StringUtils.hasText(type)) { |
|
|
|
uriBuilder.queryParam("type", type); |
|
|
|
} |
|
|
|
|
|
|
|
HttpHeaders headers = buildMesHeaders(false); |
|
|
|
String requestUrl = uriBuilder.toUriString(); |
|
|
|
logger.info("MES获取班次调用地址: {}", requestUrl); |
|
|
|
HttpEntity<Void> requestEntity = new HttpEntity<>(headers); |
|
|
|
ResponseEntity<String> response = restTemplate.exchange( |
|
|
|
uriBuilder.toUriString(), |
|
|
|
requestUrl, |
|
|
|
HttpMethod.GET, |
|
|
|
requestEntity, |
|
|
|
String.class |
|
|
|
); |
|
|
|
|
|
|
|
logger.info("MES获取班次HTTP响应: status={}, body={}", response.getStatusCodeValue(), response.getBody()); |
|
|
|
Map<String, Object> mesResult = parseMesResponse(response.getBody()); |
|
|
|
logger.info("MES获取班次业务响应: code={}, msg={}", mesResult.get("code"), mesResult.get("msg")); |
|
|
|
return buildMesResult(mesResult, "获取班次数据失败"); |
|
|
|
} catch (Exception e) { |
|
|
|
logger.error("MES获取班次数据失败", e); |
|
|
|
@ -2419,6 +2422,10 @@ public class ScheduleController extends AbstractController { |
|
|
|
@RequestParam("shift") String shift, |
|
|
|
@RequestParam("operatorNo") String operatorNo) { |
|
|
|
try { |
|
|
|
logger.info("MES上传订单日志请求开始: process={}, machineNo={}, date={}, shift={}, operatorNo={}, fileName={}, fileSize={}", |
|
|
|
process, machineNo, date, shift, operatorNo, |
|
|
|
log == null ? "" : log.getOriginalFilename(), |
|
|
|
log == null ? 0 : log.getSize()); |
|
|
|
if (log == null || log.isEmpty()) { |
|
|
|
return R.error("上传文件不能为空").put("code", 400); |
|
|
|
} |
|
|
|
@ -2463,7 +2470,9 @@ public class ScheduleController extends AbstractController { |
|
|
|
String.class |
|
|
|
); |
|
|
|
|
|
|
|
logger.info("MES上传订单日志HTTP响应: status={}, body={}", response.getStatusCodeValue(), response.getBody()); |
|
|
|
Map<String, Object> mesResult = parseMesResponse(response.getBody()); |
|
|
|
logger.info("MES上传订单日志业务响应: code={}, msg={}", mesResult.get("code"), mesResult.get("msg")); |
|
|
|
return buildMesResult(mesResult, "上传订单日志失败"); |
|
|
|
} catch (Exception e) { |
|
|
|
logger.error("MES上传订单日志失败", e); |
|
|
|
@ -2473,6 +2482,109 @@ public class ScheduleController extends AbstractController { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* MES接口:结束班次 |
|
|
|
*/ |
|
|
|
@PostMapping("finishMesShift") |
|
|
|
public R finishMesShift(@RequestBody Map<String, Object> params) { |
|
|
|
try { |
|
|
|
String machineNo = Objects.toString(params.get("machineNo"), "").trim(); |
|
|
|
String date = Objects.toString(params.get("date"), "").trim(); |
|
|
|
String shift = Objects.toString(params.get("shift"), "").trim(); |
|
|
|
logger.info("MES结束班次请求开始: machineNo={}, date={}, shift={}", machineNo, date, shift); |
|
|
|
|
|
|
|
if (!StringUtils.hasText(machineNo)) { |
|
|
|
return R.error("机器账号不能为空").put("code", 400); |
|
|
|
} |
|
|
|
if (!StringUtils.hasText(date)) { |
|
|
|
return R.error("日期不能为空").put("code", 400); |
|
|
|
} |
|
|
|
if (!StringUtils.hasText(shift)) { |
|
|
|
return R.error("班次不能为空").put("code", 400); |
|
|
|
} |
|
|
|
|
|
|
|
HttpHeaders headers = buildMesHeaders(true); |
|
|
|
MultiValueMap<String, Object> body = new LinkedMultiValueMap<>(); |
|
|
|
body.add("machineNo", machineNo); |
|
|
|
body.add("date", date); |
|
|
|
body.add("shift", shift); |
|
|
|
|
|
|
|
HttpEntity<MultiValueMap<String, Object>> requestEntity = new HttpEntity<>(body, headers); |
|
|
|
ResponseEntity<String> response = restTemplate.exchange( |
|
|
|
buildMesApiUrl("/finishShift"), |
|
|
|
HttpMethod.POST, |
|
|
|
requestEntity, |
|
|
|
String.class |
|
|
|
); |
|
|
|
|
|
|
|
logger.info("MES结束班次HTTP响应: status={}, body={}", response.getStatusCodeValue(), response.getBody()); |
|
|
|
Map<String, Object> mesResult = parseMesResponse(response.getBody()); |
|
|
|
logger.info("MES结束班次业务响应: code={}, msg={}", mesResult.get("code"), mesResult.get("msg")); |
|
|
|
return buildMesResult(mesResult, "结束班次失败"); |
|
|
|
} catch (Exception e) { |
|
|
|
logger.error("MES结束班次失败", e); |
|
|
|
return R.error("结束班次失败: " + e.getMessage()) |
|
|
|
.put("code", 400) |
|
|
|
.put("msg", "结束班次失败: " + e.getMessage()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* MES接口:上传MT日志 |
|
|
|
*/ |
|
|
|
@PostMapping("uploadMesMtLog") |
|
|
|
public R uploadMesMtLog(@RequestParam("log") MultipartFile log, |
|
|
|
@RequestParam("machineNo") String machineNo, |
|
|
|
@RequestParam("date") String date) { |
|
|
|
try { |
|
|
|
logger.info("MES上传MT日志请求开始: machineNo={}, date={}, fileName={}, fileSize={}", |
|
|
|
machineNo, date, |
|
|
|
log == null ? "" : log.getOriginalFilename(), |
|
|
|
log == null ? 0 : log.getSize()); |
|
|
|
if (log == null || log.isEmpty()) { |
|
|
|
return R.error("上传文件不能为空").put("code", 400); |
|
|
|
} |
|
|
|
if (!StringUtils.hasText(machineNo)) { |
|
|
|
return R.error("机器账号不能为空").put("code", 400); |
|
|
|
} |
|
|
|
if (!StringUtils.hasText(date)) { |
|
|
|
return R.error("日期不能为空").put("code", 400); |
|
|
|
} |
|
|
|
|
|
|
|
HttpHeaders headers = buildMesHeaders(true); |
|
|
|
MultiValueMap<String, Object> body = new LinkedMultiValueMap<>(); |
|
|
|
body.add("machineNo", machineNo); |
|
|
|
body.add("date", date); |
|
|
|
|
|
|
|
final byte[] fileBytes = log.getBytes(); |
|
|
|
final String fileName = StringUtils.hasText(log.getOriginalFilename()) ? log.getOriginalFilename() : "upload_mt.log"; |
|
|
|
body.add("log", new ByteArrayResource(fileBytes) { |
|
|
|
@Override |
|
|
|
public String getFilename() { |
|
|
|
return fileName; |
|
|
|
} |
|
|
|
}); |
|
|
|
|
|
|
|
HttpEntity<MultiValueMap<String, Object>> requestEntity = new HttpEntity<>(body, headers); |
|
|
|
ResponseEntity<String> response = restTemplate.exchange( |
|
|
|
buildMesApiUrl("/uploadMt"), |
|
|
|
HttpMethod.POST, |
|
|
|
requestEntity, |
|
|
|
String.class |
|
|
|
); |
|
|
|
|
|
|
|
logger.info("MES上传MT日志HTTP响应: status={}, body={}", response.getStatusCodeValue(), response.getBody()); |
|
|
|
Map<String, Object> mesResult = parseMesResponse(response.getBody()); |
|
|
|
logger.info("MES上传MT日志业务响应: code={}, msg={}", mesResult.get("code"), mesResult.get("msg")); |
|
|
|
return buildMesResult(mesResult, "上传MT日志失败"); |
|
|
|
} catch (Exception e) { |
|
|
|
logger.error("MES上传MT日志失败", e); |
|
|
|
return R.error("上传MT日志失败: " + e.getMessage()) |
|
|
|
.put("code", 400) |
|
|
|
.put("msg", "上传MT日志失败: " + e.getMessage()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private String buildMesApiUrl(String path) { |
|
|
|
String baseUrl = StringUtils.hasText(mesLogsBaseUrl) ? mesLogsBaseUrl.trim() : "http://logs.bt.in/api/logs"; |
|
|
|
if (baseUrl.endsWith("/")) { |
|
|
|
|