diff --git a/aucma-dms/src/main/java/com/aucma/dms/controller/DmsMobileController.java b/aucma-dms/src/main/java/com/aucma/dms/controller/DmsMobileController.java index 994fddd..483899c 100644 --- a/aucma-dms/src/main/java/com/aucma/dms/controller/DmsMobileController.java +++ b/aucma-dms/src/main/java/com/aucma/dms/controller/DmsMobileController.java @@ -25,6 +25,7 @@ import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; +import java.math.BigDecimal; import java.util.ArrayList; import java.util.Date; import java.util.List; @@ -81,6 +82,7 @@ public class DmsMobileController extends BaseController { @Autowired private IDmsRecordShutDownService dmsRecordShutDownService; + /** * 根据设备编号获取设备信息 * 【重构】使用aucma-base模块的BaseDeviceLedger,返回类型转换为DmsBaseDeviceLedger @@ -226,6 +228,27 @@ public class DmsMobileController extends BaseController { // ========== PDA 停机相关 ========== + + /** + * 获取OLD开头的设备列表(仅启用) + */ + @GetMapping("/device/listOld") + public AjaxResult listOldDevices() { + BaseDeviceLedger query = new BaseDeviceLedger(); + query.setIsFlag(1L); + List list = baseDeviceLedgerService.selectBaseDeviceLedgerList(query); + List resultList = new ArrayList<>(); + if (!CollectionUtils.isEmpty(list)) { + for (BaseDeviceLedger base : list) { + if (base.getDeviceCode() != null && base.getDeviceCode().startsWith("OLD")) { + resultList.add(convertDeviceLedgerToDto(convertToDeviceLedger(base))); + } + } + } + return success(resultList); + } + + /** * PDA-获取停机原因列表(仅启用 isFlag=1) */ @@ -260,21 +283,60 @@ public class DmsMobileController extends BaseController { if (shutDown.getIsFlag() == null) { shutDown.setIsFlag(1L); } + // 若未传入开始时间,则使用当前时间 + if (shutDown.getShutBeginTime() == null) { + shutDown.setShutBeginTime(new Date()); + } int rows = dmsRecordShutDownService.insertDmsRecordShutDown(shutDown); // 对指定设备(OLD-01~OLD-05)同步写入三色灯状态参数,供设备状态统计使用 String deviceCode = shutDown.getDeviceCode(); if (deviceCode != null && deviceCode.startsWith("OLD-")) { - insertTriColorStatusParams(deviceCode, shutDown.getDeviceId()); + // 新增停机记录代表进入停机,三色灯置为“暂停” + insertTriColorStatusParams(deviceCode, shutDown.getDeviceId(), false); } return success(rows); } + /** + * PDA-更新停机记录:设置结束时间并计算停机时长(秒) + */ + @PostMapping("/shutDown/complete") + @Transactional(rollbackFor = Exception.class) + public AjaxResult completeShutDownForPda(@RequestBody DmsRecordShutDown shutDown) { + if (shutDown.getRecordShutDownId() == null) { + return error("recordShutDownId不能为空"); + } + // 查询原记录以获取开始时间 + DmsRecordShutDown origin = dmsRecordShutDownService.selectDmsRecordShutDownByRecordShutDownId(shutDown.getRecordShutDownId()); + if (origin == null) { + return error("停机记录不存在"); + } + + Date end = new Date(); + Date begin = origin.getShutBeginTime(); + shutDown.setShutEndTime(end); + if (begin != null) { + long minutes = Math.max(0, (end.getTime() - begin.getTime()) / 60000); + shutDown.setShutTime(BigDecimal.valueOf(minutes)); + } + + int rows = dmsRecordShutDownService.updateDmsRecordShutDown(shutDown); + // 对指定设备(OLD-01~OLD-05)同步写入三色灯状态参数,供设备状态统计使用 + String deviceCode = shutDown.getDeviceCode() != null ? shutDown.getDeviceCode() : origin.getDeviceCode(); + Long deviceId = shutDown.getDeviceId() != null ? shutDown.getDeviceId() : origin.getDeviceId(); + if (deviceCode != null && deviceCode.startsWith("OLD-")) { + // 完成停机代表重新运行,三色灯置为“运行” + insertTriColorStatusParams(deviceCode, deviceId, true); + } + return rows > 0 ? success(origin.getRecordShutDownId()) : error("更新停机记录失败"); + } + /** * 插入三色灯状态参数(运行/暂停/报警),以“暂停”为当前状态 */ - private void insertTriColorStatusParams(String deviceCode, Long deviceId) { + private void insertTriColorStatusParams(String deviceCode, Long deviceId, boolean running) { // 仅处理 OLD-01~OLD-05 if (!"OLD-01".equals(deviceCode) && !"OLD-02".equals(deviceCode) && !"OLD-03".equals(deviceCode) && !"OLD-04".equals(deviceCode) @@ -295,10 +357,12 @@ public class DmsMobileController extends BaseController { } Date now = new Date(); - // 运行、暂停、报警 三个参数,只有“暂停”置 TRUE,其余 FALSE + // 运行、暂停、报警 三个参数,运行/暂停取决于状态 List records = new ArrayList<>(); - records.add(buildParamVal("295", deviceCode, resolvedDeviceId, "机台状态-三色灯机器运行", "False", now)); - records.add(buildParamVal("296", deviceCode, resolvedDeviceId, "机台状态-三色灯机器暂停", "True", now)); + String runVal = running ? "True" : "False"; + String pauseVal = running ? "False" : "True"; + records.add(buildParamVal("295", deviceCode, resolvedDeviceId, "机台状态-三色灯机器运行", runVal, now)); + records.add(buildParamVal("296", deviceCode, resolvedDeviceId, "机台状态-三色灯机器暂停", pauseVal, now)); records.add(buildParamVal("297", deviceCode, resolvedDeviceId, "机台状态-三色灯机器报警", "False", now)); for (BaseDeviceParamVal rec : records) { diff --git a/aucma-dms/src/main/java/com/aucma/dms/domain/DmsRecordShutDown.java b/aucma-dms/src/main/java/com/aucma/dms/domain/DmsRecordShutDown.java index de30fa1..9cedb76 100644 --- a/aucma-dms/src/main/java/com/aucma/dms/domain/DmsRecordShutDown.java +++ b/aucma-dms/src/main/java/com/aucma/dms/domain/DmsRecordShutDown.java @@ -36,13 +36,13 @@ public class DmsRecordShutDown extends DmsBaseEntity private String shutReason; /** 停机开始时间 */ - @JsonFormat(pattern = "yyyy-MM-dd") - @Excel(name = "停机开始时间", width = 30, dateFormat = "yyyy-MM-dd") + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") + @Excel(name = "停机开始时间", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss") private Date shutBeginTime; /** 停机结束时间 */ - @JsonFormat(pattern = "yyyy-MM-dd") - @Excel(name = "停机结束时间", width = 30, dateFormat = "yyyy-MM-dd") + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") + @Excel(name = "停机结束时间", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss") private Date shutEndTime; /** 停机时长 */