diff --git a/op-modules/op-device/src/main/java/com/op/device/mapper/EquOperationRecordMapper.java b/op-modules/op-device/src/main/java/com/op/device/mapper/EquOperationRecordMapper.java index 3a356f44..e7f2d37e 100644 --- a/op-modules/op-device/src/main/java/com/op/device/mapper/EquOperationRecordMapper.java +++ b/op-modules/op-device/src/main/java/com/op/device/mapper/EquOperationRecordMapper.java @@ -3,6 +3,7 @@ package com.op.device.mapper; import java.util.List; import com.op.device.domain.EquOperationRecord; +import org.apache.ibatis.annotations.Param; /** * 设备运行记录Mapper接口 @@ -71,4 +72,11 @@ public interface EquOperationRecordMapper { //设备完好率 EquOperationRecord getEquipmentIntactRate(EquOperationRecord equOperationRecord); + + /** + * 查询改设备最后一条运行记录 + * @param equipmentCode + * @return + */ + EquOperationRecord selectLastOperationRecordByEquipmentCode(String equipmentCode); } diff --git a/op-modules/op-device/src/main/java/com/op/device/service/impl/DevicePDAServiceImpl.java b/op-modules/op-device/src/main/java/com/op/device/service/impl/DevicePDAServiceImpl.java index 6d681c52..00b38dca 100644 --- a/op-modules/op-device/src/main/java/com/op/device/service/impl/DevicePDAServiceImpl.java +++ b/op-modules/op-device/src/main/java/com/op/device/service/impl/DevicePDAServiceImpl.java @@ -334,6 +334,8 @@ public class DevicePDAServiceImpl implements IDevicePDAService { // 更新设备状态为开机 equ.setStatus("1"); equOrderMapper.updateEquipmentStatus(equ); + // 更新设备运行记录 + updateOperationRecord(equOrder.getEquipmentCode(),"on",""); //上传附件 if (StringUtils.isNotEmpty(equOrder.getPicturePath())) { String[] ids = equOrder.getPicturePath().split(","); @@ -467,12 +469,19 @@ public class DevicePDAServiceImpl implements IDevicePDAService { // 创建设备对象用于更新设备状态 Equipment equ = new Equipment(); equ.setEquipmentCode(order.getEquipmentCode()); + // 运行记录类型 + String operationType; // 停机保养 if (pdadto.getShutDown().equals("1")){ // 更改设备状态为停机 equ.setStatus("0"); equOrderMapper.updateEquipmentStatus(equ); + operationType = "off"; + }else { + operationType = "on"; } + // 更新设备运行记录 + updateOperationRecord(order.getEquipmentCode(),operationType,"upkeep"); // 设置开始时间 order.setOrderStart(DateUtils.getNowDate()); @@ -824,4 +833,31 @@ public class DevicePDAServiceImpl implements IDevicePDAService { return equEquipmentMapper.selectEquEquipmentList(equEquipment); } + /** + * 更新设备运行记录 + * @param equipmentCode + * @param operationType 开机/停机 + * @param type 保养/维修 + */ + private void updateOperationRecord(String equipmentCode,String operationType,String type) { + // 设备最后一条运行记录 + EquOperationRecord lastRecord = equOperationRecordMapper.selectLastOperationRecordByEquipmentCode(equipmentCode); + lastRecord.setEndTime(DateUtils.getNowDate()); + lastRecord.setUpdateBy(SecurityContextHolder.getUserName()); + // 更新运行记录 + equOperationRecordMapper.updateEquOperationRecord(lastRecord); + // 创建新的运行记录 + EquOperationRecord newRecord = new EquOperationRecord(); + newRecord.setId(IdUtils.fastSimpleUUID()); + newRecord.setEquipmentCode(equipmentCode); + newRecord.setStartTime(DateUtils.getNowDate()); + newRecord.setType(operationType); + newRecord.setMaintenanceType(type);// 维护类型 + newRecord.setParentId(lastRecord.getId()); + newRecord.setFactoryCode(lastRecord.getFactoryCode()); + newRecord.setCreateBy(SecurityContextHolder.getUserName()); + newRecord.setCreateTime(DateUtils.getNowDate()); + equOperationRecordMapper.insertEquOperationRecord(newRecord); + } + } diff --git a/op-modules/op-device/src/main/resources/mapper/device/EquOperationRecordMapper.xml b/op-modules/op-device/src/main/resources/mapper/device/EquOperationRecordMapper.xml index ebd25fc1..7e34a4db 100644 --- a/op-modules/op-device/src/main/resources/mapper/device/EquOperationRecordMapper.xml +++ b/op-modules/op-device/src/main/resources/mapper/device/EquOperationRecordMapper.xml @@ -178,5 +178,28 @@ FROM base_equipment WHERE del_flag = '0' AND status = '1' + + \ No newline at end of file diff --git a/op-modules/op-device/src/main/resources/mapper/device/EquOrderMapper.xml b/op-modules/op-device/src/main/resources/mapper/device/EquOrderMapper.xml index 0d93ddf6..05011613 100644 --- a/op-modules/op-device/src/main/resources/mapper/device/EquOrderMapper.xml +++ b/op-modules/op-device/src/main/resources/mapper/device/EquOrderMapper.xml @@ -359,10 +359,10 @@ - update base_equipment be - set be.status = #{status} - where be.equipmentCode = #{equipmentCode} - and be.del_flag = '0' + update base_equipment + set status = #{status} + where equipment_code = #{equipmentCode} + and del_flag = '0'