|
|
|
@ -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<SpecialDevic
|
|
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
|
@Override |
|
|
|
|
public boolean saveInspection(SpecialDeviceInspectionEntity specialDeviceInspectionEntity) { |
|
|
|
|
Long deviceId = specialDeviceInspectionEntity.getDeviceId(); |
|
|
|
|
// 获取对应特种设备
|
|
|
|
|
SpecialDeviceEntity specialDeviceEntity = deviceService.getById(deviceId); |
|
|
|
|
// 计算下一次检验时间
|
|
|
|
|
Integer period = specialDeviceEntity.getInspectionPeriod(); |
|
|
|
|
Date nextInspectDate = DateUtil.addDays(specialDeviceInspectionEntity.getInspectionTime(), period); |
|
|
|
|
specialDeviceInspectionEntity.setNextInspectionTime(nextInspectDate); |
|
|
|
|
specialDeviceEntity.setInspectionNextTime(nextInspectDate); |
|
|
|
|
// 获取上一次检验时间
|
|
|
|
|
QueryWrapper<SpecialDeviceInspectionEntity> queryWrapper = new QueryWrapper<>(); |
|
|
|
|
queryWrapper.lambda().eq(SpecialDeviceInspectionEntity::getDeviceId, deviceId) |
|
|
|
|
.orderByDesc(SpecialDeviceInspectionEntity::getInspectionTime); |
|
|
|
|
List<SpecialDeviceInspectionEntity> 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<SpecialDevic
|
|
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
|
@Override |
|
|
|
|
public boolean updateInspection(SpecialDeviceInspectionEntity specialDeviceInspectionEntity) { |
|
|
|
|
Long deviceId = specialDeviceInspectionEntity.getDeviceId(); |
|
|
|
|
// 获取对应特种设备
|
|
|
|
|
SpecialDeviceEntity specialDeviceEntity = deviceService.getById(deviceId); |
|
|
|
|
// 计算下一次检验时间
|
|
|
|
|
Integer period = specialDeviceEntity.getInspectionPeriod(); |
|
|
|
|
Date nextInspectDate = DateUtil.addDays(specialDeviceInspectionEntity.getInspectionTime(), period); |
|
|
|
|
specialDeviceInspectionEntity.setNextInspectionTime(nextInspectDate); |
|
|
|
|
// 更新设备检验记录
|
|
|
|
|
boolean update = this.updateById(specialDeviceInspectionEntity); |
|
|
|
|
if (update) { |
|
|
|
|
SpecialDeviceEntity specialDeviceEntity = deviceService.getById(specialDeviceInspectionEntity.getDeviceId()); |
|
|
|
|
if (specialDeviceEntity != null) { |
|
|
|
|
// 获取按检验时间倒序排列的检验记录数据
|
|
|
|
|
QueryWrapper<SpecialDeviceInspectionEntity> queryWrapper = new QueryWrapper<>(); |
|
|
|
|
queryWrapper.lambda().eq(SpecialDeviceInspectionEntity::getDeviceId, deviceId) |
|
|
|
|
.orderByDesc(SpecialDeviceInspectionEntity::getInspectionTime); |
|
|
|
|
List<SpecialDeviceInspectionEntity> 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()); |
|
|
|
|