| | |
| | | import com.ruoyi.device.mapper.CollectBridgeMapper; |
| | | import com.ruoyi.device.mapper.DeviceCalibrationPlanDetailMapper; |
| | | import com.ruoyi.device.mapper.DeviceCalibrationPlanMapper; |
| | | import com.ruoyi.device.mapper.DeviceExaminePlanDetailsMapper; |
| | | import com.ruoyi.device.mapper.DeviceExaminePlanMapper; |
| | | import com.ruoyi.device.mapper.DeviceMaintenanceMapper; |
| | | import com.ruoyi.device.mapper.DeviceMaintenancePlanDetailsMapper; |
| | | import com.ruoyi.device.mapper.DeviceMaintenancePlanMapper; |
| | | import com.ruoyi.device.mapper.DeviceMapper; |
| | | import com.ruoyi.device.mapper.DeviceMetricRecordMapper; |
| | | import com.ruoyi.device.pojo.*; |
| | | import com.ruoyi.device.service.DataConfigService; |
| | | import com.ruoyi.device.service.DeviceCalibrationPlanService; |
| | | import com.ruoyi.device.service.DeviceExaminePlanService; |
| | | import com.ruoyi.device.service.DeviceMaintenancePlanService; |
| | | import com.ruoyi.device.service.DeviceService; |
| | | import com.ruoyi.device.service.DeviceDocumentsService; |
| | | import com.ruoyi.device.utils.DataAcquisition; |
| | |
| | | |
| | | private CollectBridgeMapper collectBridgeMapper; |
| | | |
| | | private DeviceCalibrationPlanMapper deviceCalibrationPlanMapper; |
| | | private DeviceCalibrationPlanService deviceCalibrationPlanService; |
| | | |
| | | private DeviceCalibrationPlanDetailMapper deviceCalibrationPlanDetailMapper; |
| | | private DeviceExaminePlanService deviceExaminePlanService; |
| | | |
| | | private DeviceExaminePlanMapper deviceExaminePlanMapper; |
| | | |
| | | private DeviceExaminePlanDetailsMapper deviceExaminePlanDetailsMapper; |
| | | |
| | | private DeviceMaintenancePlanMapper deviceMaintenancePlanMapper; |
| | | |
| | | private DeviceMaintenancePlanDetailsMapper deviceMaintenancePlanDetailsMapper; |
| | | private DeviceMaintenancePlanService deviceMaintenancePlanService; |
| | | |
| | | @Override |
| | | public IPage<DeviceDto> selectDeviceParameter(Page page, DeviceDto itemParameter, Boolean laboratoryNameIsNull) { |
| | |
| | | @Override |
| | | public int upDeviceParameter(Device itemParameter) { |
| | | int rows = deviceMapper.updateById(itemParameter); |
| | | // 档案修订填写了校准有效期和校准周期后,自动同步到设备校准计划 |
| | | // 档案修订填写了校准信息后,到点的自动同步到设备校准计划 |
| | | Device device = deviceMapper.selectById(itemParameter.getId()); |
| | | if (device != null && device.getActivationDate() != null && StringUtils.isNotBlank(device.getCalibrationDate())) { |
| | | syncCalibrationPlanDetail(device); |
| | | if (device != null && (device.getNextCalibrationDate() != null || device.getActivationDate() != null)) { |
| | | deviceCalibrationPlanService.syncDeviceCalibrationDetail(device); |
| | | } |
| | | // 档案修订填写了核查信息后,自动同步到设备核查计划 |
| | | if (device != null && device.getNextExamineDate() != null && StringUtils.isNotBlank(device.getExamineCycle())) { |
| | | syncExaminePlanDetail(device); |
| | | // 档案修订填写了核查信息后,到点的自动同步到设备核查计划 |
| | | if (device != null && (device.getNextExamineDate() != null |
| | | || (device.getLastExamineDate() != null && StringUtils.isNotBlank(device.getExamineCycle())))) { |
| | | deviceExaminePlanService.syncDeviceExamineDetail(device); |
| | | } |
| | | // 档案修订填写了保养信息后,自动同步到设备保养计划 |
| | | if (device != null && device.getNextMaintenanceDate() != null && StringUtils.isNotBlank(device.getMaintenanceCycle())) { |
| | | syncMaintenancePlanDetail(device); |
| | | // 档案修订填写了保养信息后,到点的自动同步到设备保养计划 |
| | | if (device != null && (device.getNextMaintenanceDate() != null |
| | | || (device.getLastMaintenanceDate() != null && StringUtils.isNotBlank(device.getMaintenanceCycle())))) { |
| | | deviceMaintenancePlanService.syncDeviceMaintenanceDetail(device); |
| | | } |
| | | return rows; |
| | | } |
| | | |
| | | /** |
| | | * 把设备同步到今年的设备校准计划明细:本年计划校准时间 = 校准有效期前一个月 |
| | | */ |
| | | private void syncCalibrationPlanDetail(Device device) { |
| | | String planYear = String.valueOf(LocalDate.now().getYear()); |
| | | DeviceCalibrationPlan plan = deviceCalibrationPlanMapper.selectOne(Wrappers.<DeviceCalibrationPlan>lambdaQuery() |
| | | .eq(DeviceCalibrationPlan::getPlanYear, planYear) |
| | | .and(w -> w.isNull(DeviceCalibrationPlan::getRatifyStatus).or().ne(DeviceCalibrationPlan::getRatifyStatus, 1)) |
| | | .orderByDesc(DeviceCalibrationPlan::getPlanId) |
| | | .last("limit 1")); |
| | | if (plan == null) { |
| | | plan = new DeviceCalibrationPlan(); |
| | | plan.setPlanName(planYear + "年度设备校准计划"); |
| | | plan.setPlanYear(planYear); |
| | | plan.setWriteUserId(SecurityUtils.getUserId().intValue()); |
| | | plan.setWriteTime(LocalDateTime.now()); |
| | | deviceCalibrationPlanMapper.insert(plan); |
| | | } |
| | | |
| | | DeviceCalibrationPlanDetail detail = deviceCalibrationPlanDetailMapper.selectOne(Wrappers.<DeviceCalibrationPlanDetail>lambdaQuery() |
| | | .eq(DeviceCalibrationPlanDetail::getPlanId, plan.getPlanId()) |
| | | .eq(DeviceCalibrationPlanDetail::getDeviceId, device.getId()) |
| | | .last("limit 1")); |
| | | boolean isInsert = detail == null; |
| | | if (isInsert) { |
| | | detail = new DeviceCalibrationPlanDetail(); |
| | | detail.setPlanId(plan.getPlanId()); |
| | | detail.setDeviceId(device.getId()); |
| | | } |
| | | String deviceName = device.getDeviceName() == null ? "" : device.getDeviceName(); |
| | | if (StringUtils.isNotBlank(device.getSpecificationModel())) { |
| | | deviceName = deviceName + " " + device.getSpecificationModel(); |
| | | } |
| | | detail.setDeviceName(deviceName); |
| | | detail.setDeviceAmount("1"); |
| | | detail.setDeviceNumber(device.getManagementNumber()); |
| | | detail.setVerificationUnit(device.getCalibrationServices()); |
| | | detail.setVerificationCycles(device.getCalibrationDate()); |
| | | detail.setLastDate(device.getLastCalibrationDate() == null ? null : device.getLastCalibrationDate().toLocalDate()); |
| | | detail.setPlanDate(device.getActivationDate().toLocalDate().minusMonths(1)); |
| | | if (isInsert) { |
| | | deviceCalibrationPlanDetailMapper.insert(detail); |
| | | } else { |
| | | deviceCalibrationPlanDetailMapper.updateById(detail); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 把设备同步到今年的设备核查计划明细:核查时间 = 下次核查日期前一个月 |
| | | */ |
| | | private void syncExaminePlanDetail(Device device) { |
| | | String planYear = String.valueOf(LocalDate.now().getYear()); |
| | | DeviceExaminePlan plan = deviceExaminePlanMapper.selectOne(Wrappers.<DeviceExaminePlan>lambdaQuery() |
| | | .eq(DeviceExaminePlan::getPlanYear, planYear) |
| | | .and(w -> w.isNull(DeviceExaminePlan::getRatifyStatus).or().ne(DeviceExaminePlan::getRatifyStatus, 1)) |
| | | .orderByDesc(DeviceExaminePlan::getPlanId) |
| | | .last("limit 1")); |
| | | if (plan == null) { |
| | | plan = new DeviceExaminePlan(); |
| | | plan.setPlanName(planYear + "年度设备核查计划"); |
| | | plan.setPlanYear(planYear); |
| | | plan.setWriteUserId(SecurityUtils.getUserId().intValue()); |
| | | plan.setWriteTime(LocalDateTime.now()); |
| | | deviceExaminePlanMapper.insert(plan); |
| | | } |
| | | |
| | | DeviceExaminePlanDetails detail = deviceExaminePlanDetailsMapper.selectOne(Wrappers.<DeviceExaminePlanDetails>lambdaQuery() |
| | | .eq(DeviceExaminePlanDetails::getPlanId, plan.getPlanId()) |
| | | .eq(DeviceExaminePlanDetails::getDeviceId, device.getId()) |
| | | .last("limit 1")); |
| | | boolean isInsert = detail == null; |
| | | if (isInsert) { |
| | | detail = new DeviceExaminePlanDetails(); |
| | | detail.setPlanId(plan.getPlanId()); |
| | | detail.setDeviceId(device.getId()); |
| | | } |
| | | String deviceName = device.getDeviceName() == null ? "" : device.getDeviceName(); |
| | | if (StringUtils.isNotBlank(device.getSpecificationModel())) { |
| | | deviceName = deviceName + " " + device.getSpecificationModel(); |
| | | } |
| | | detail.setDeviceName(deviceName); |
| | | detail.setDeviceNumber(device.getManagementNumber()); |
| | | detail.setCheckTime(device.getNextExamineDate().toLocalDate().minusMonths(1).toString()); |
| | | if (isInsert) { |
| | | deviceExaminePlanDetailsMapper.insert(detail); |
| | | } else { |
| | | deviceExaminePlanDetailsMapper.updateById(detail); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 把设备同步到今年的设备保养计划明细:计划保养时间 = 下次保养日期前一个月 |
| | | */ |
| | | private void syncMaintenancePlanDetail(Device device) { |
| | | String planYear = String.valueOf(LocalDate.now().getYear()); |
| | | DeviceMaintenancePlan plan = deviceMaintenancePlanMapper.selectOne(Wrappers.<DeviceMaintenancePlan>lambdaQuery() |
| | | .eq(DeviceMaintenancePlan::getPlanYear, planYear) |
| | | .and(w -> w.isNull(DeviceMaintenancePlan::getStatus).or().ne(DeviceMaintenancePlan::getStatus, 1)) |
| | | .orderByDesc(DeviceMaintenancePlan::getMaintenancePlanId) |
| | | .last("limit 1")); |
| | | if (plan == null) { |
| | | plan = new DeviceMaintenancePlan(); |
| | | plan.setPlanName(planYear + "年度设备保养计划"); |
| | | plan.setPlanYear(planYear); |
| | | Integer userId = SecurityUtils.getUserId().intValue(); |
| | | User user = userMapper.selectById(userId); |
| | | plan.setCompilerId(userId); |
| | | if (user != null) { |
| | | plan.setCompiler(user.getName()); |
| | | } |
| | | plan.setDatePreparation(LocalDateTime.now()); |
| | | deviceMaintenancePlanMapper.insert(plan); |
| | | } |
| | | |
| | | DeviceMaintenancePlanDetails detail = deviceMaintenancePlanDetailsMapper.selectOne(Wrappers.<DeviceMaintenancePlanDetails>lambdaQuery() |
| | | .eq(DeviceMaintenancePlanDetails::getMaintenancePlanId, plan.getMaintenancePlanId()) |
| | | .eq(DeviceMaintenancePlanDetails::getDeviceId, device.getId()) |
| | | .last("limit 1")); |
| | | boolean isInsert = detail == null; |
| | | if (isInsert) { |
| | | detail = new DeviceMaintenancePlanDetails(); |
| | | detail.setMaintenancePlanId(plan.getMaintenancePlanId()); |
| | | detail.setDeviceId(device.getId()); |
| | | } |
| | | detail.setMaintenanceIntervals(device.getMaintenanceCycle()); |
| | | detail.setMaintenanceDate(device.getNextMaintenanceDate().toLocalDate().minusMonths(1)); |
| | | if (isInsert) { |
| | | deviceMaintenancePlanDetailsMapper.insert(detail); |
| | | } else { |
| | | deviceMaintenancePlanDetailsMapper.updateById(detail); |
| | | } |
| | | } |
| | | |
| | | @Override |