feat(dms): 添加PDA端设备管理功能支持停机记录完整流程

- 新增获取OLD开头设备列表接口用于PDA端显示
- 实现停机记录开始功能支持自动设置开始时间和三色灯状态
- 添加停机记录完成接口用于设置结束时间和计算停机时长
- 更新三色灯状态参数写入逻辑支持运行/暂停状态切换
- 修改停机时间字段格式为精确到秒的时间戳格式
- 集成事务管理确保停机记录数据一致性
master
zangch@mesnac.com 1 week ago
parent 1c391a0662
commit e240a43a92

@ -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-baseBaseDeviceLedgerDmsBaseDeviceLedger
@ -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<BaseDeviceLedger> list = baseDeviceLedgerService.selectBaseDeviceLedgerList(query);
List<DmsBaseDeviceLedgerDTO> 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<BaseDeviceParamVal> 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) {

@ -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;
/** 停机时长 */

Loading…
Cancel
Save