From e240a43a925f6d0d826d09e61f454fdfcc64e3c5 Mon Sep 17 00:00:00 2001 From: "zangch@mesnac.com" Date: Fri, 6 Feb 2026 15:10:05 +0800 Subject: [PATCH] =?UTF-8?q?feat(dms):=20=E6=B7=BB=E5=8A=A0PDA=E7=AB=AF?= =?UTF-8?q?=E8=AE=BE=E5=A4=87=E7=AE=A1=E7=90=86=E5=8A=9F=E8=83=BD=E6=94=AF?= =?UTF-8?q?=E6=8C=81=E5=81=9C=E6=9C=BA=E8=AE=B0=E5=BD=95=E5=AE=8C=E6=95=B4?= =?UTF-8?q?=E6=B5=81=E7=A8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 新增获取OLD开头设备列表接口用于PDA端显示 - 实现停机记录开始功能支持自动设置开始时间和三色灯状态 - 添加停机记录完成接口用于设置结束时间和计算停机时长 - 更新三色灯状态参数写入逻辑支持运行/暂停状态切换 - 修改停机时间字段格式为精确到秒的时间戳格式 - 集成事务管理确保停机记录数据一致性 --- .../dms/controller/DmsMobileController.java | 74 +++++++++++++++++-- .../aucma/dms/domain/DmsRecordShutDown.java | 8 +- 2 files changed, 73 insertions(+), 9 deletions(-) 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; /** 停机时长 */