diff --git a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/SpecialDeviceInspectionServiceImpl.java b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/SpecialDeviceInspectionServiceImpl.java index 7bfd8c2..88509db 100644 --- a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/SpecialDeviceInspectionServiceImpl.java +++ b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/SpecialDeviceInspectionServiceImpl.java @@ -10,11 +10,15 @@ import com.hnac.hzims.safeproduct.enums.DeviceStatusEnum; import com.hnac.hzims.safeproduct.mapper.SpecialDeviceInspectionMapper; import com.hnac.hzims.safeproduct.service.ISpecialDeviceInspectionService; import com.hnac.hzims.safeproduct.service.ISpecialDeviceService; +import com.xxl.job.core.util.DateUtil; import org.springblade.core.mp.support.Query; +import org.springblade.core.tool.utils.CollectionUtil; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import java.util.Date; +import java.util.List; import java.util.Map; /** @@ -35,16 +39,31 @@ public class SpecialDeviceInspectionServiceImpl extends ServiceImpl queryWrapper = new QueryWrapper<>(); + queryWrapper.lambda().eq(SpecialDeviceInspectionEntity::getDeviceId, deviceId) + .orderByDesc(SpecialDeviceInspectionEntity::getInspectionTime); + List list = this.list(queryWrapper); + if (CollectionUtil.isNotEmpty(list)) { + SpecialDeviceInspectionEntity lastDeviceInspection = list.get(0); + Date lastInspectionTime = lastDeviceInspection.getInspectionTime(); + specialDeviceInspectionEntity.setLastInspectionTime(lastInspectionTime); + specialDeviceEntity.setInspectionLastTime(lastInspectionTime); + } + // 本次检验时间 + specialDeviceEntity.setInspectionCurrentTime(specialDeviceInspectionEntity.getInspectionTime()); boolean save = this.save(specialDeviceInspectionEntity); if (save) { - SpecialDeviceEntity specialDeviceEntity = deviceService.getById(specialDeviceInspectionEntity.getDeviceId()); - if (specialDeviceEntity != null) { - specialDeviceEntity.setInspectionLastTime(specialDeviceInspectionEntity.getLastInspectionTime()); - specialDeviceEntity.setInspectionCurrentTime(specialDeviceInspectionEntity.getInspectionTime()); - specialDeviceEntity.setInspectionNextTime(specialDeviceInspectionEntity.getNextInspectionTime()); - specialDeviceEntity.setDeviceStatus(DeviceStatusEnum.NORMAL.getValue()); - return deviceService.updateById(specialDeviceEntity); - } + specialDeviceEntity.setDeviceStatus(DeviceStatusEnum.NORMAL.getValue()); + return deviceService.updateById(specialDeviceEntity); } return false; } @@ -55,10 +74,23 @@ public class SpecialDeviceInspectionServiceImpl extends ServiceImpl queryWrapper = new QueryWrapper<>(); + queryWrapper.lambda().eq(SpecialDeviceInspectionEntity::getDeviceId, deviceId) + .orderByDesc(SpecialDeviceInspectionEntity::getInspectionTime); + List list = this.list(queryWrapper); + if (CollectionUtil.isNotEmpty(list)) { + // 仅最新的检验记录对特种设备的检验时间造成影响 + if (specialDeviceInspectionEntity.getId().equals(list.get(0).getId()) && update) { specialDeviceEntity.setInspectionLastTime(specialDeviceInspectionEntity.getLastInspectionTime()); specialDeviceEntity.setInspectionCurrentTime(specialDeviceInspectionEntity.getInspectionTime()); specialDeviceEntity.setInspectionNextTime(specialDeviceInspectionEntity.getNextInspectionTime());