| | |
| | | import com.ruoyi.basic.pojo.StructureItemParameter; |
| | | import com.ruoyi.common.core.domain.Result; |
| | | import com.ruoyi.common.core.domain.entity.SysDictData; |
| | | import com.ruoyi.common.core.domain.entity.SysDept; |
| | | import com.ruoyi.common.core.domain.entity.User; |
| | | import com.ruoyi.common.utils.QueryWrappers; |
| | | import com.ruoyi.common.utils.SecurityUtils; |
| | | import com.ruoyi.device.dto.*; |
| | | import com.ruoyi.device.excel.upload.DeviceImport; |
| | | 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.inspect.pojo.InsProduct; |
| | | import com.ruoyi.inspect.util.HackLoopTableRenderPolicy; |
| | | import com.ruoyi.system.mapper.SysDictDataMapper; |
| | | import com.ruoyi.system.mapper.SysDeptMapper; |
| | | import com.ruoyi.system.mapper.UserMapper; |
| | | import lombok.AllArgsConstructor; |
| | | import org.apache.logging.log4j.util.Strings; |
| | |
| | | |
| | | private UserMapper userMapper; |
| | | |
| | | private SysDeptMapper sysDeptMapper; |
| | | |
| | | private SysDictDataMapper sysDictDataMapper; |
| | | |
| | | private StructureItemParameterMapper structureItemParameterMapper; |
| | |
| | | private DeviceMaintenanceMapper deviceMaintenanceMapper; |
| | | |
| | | private CollectBridgeMapper collectBridgeMapper; |
| | | |
| | | private DeviceCalibrationPlanMapper deviceCalibrationPlanMapper; |
| | | |
| | | private DeviceCalibrationPlanDetailMapper deviceCalibrationPlanDetailMapper; |
| | | |
| | | private DeviceExaminePlanMapper deviceExaminePlanMapper; |
| | | |
| | | private DeviceExaminePlanDetailsMapper deviceExaminePlanDetailsMapper; |
| | | |
| | | private DeviceMaintenancePlanMapper deviceMaintenancePlanMapper; |
| | | |
| | | private DeviceMaintenancePlanDetailsMapper deviceMaintenancePlanDetailsMapper; |
| | | |
| | | @Override |
| | | public IPage<DeviceDto> selectDeviceParameter(Page page, DeviceDto itemParameter, Boolean laboratoryNameIsNull) { |
| | |
| | | @Transactional(rollbackFor = Exception.class) |
| | | @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.getNextExamineDate() != null && StringUtils.isNotBlank(device.getExamineCycle())) { |
| | | syncExaminePlanDetail(device); |
| | | } |
| | | // 档案修订填写了保养信息后,自动同步到设备保养计划 |
| | | if (device != null && device.getNextMaintenanceDate() != null && StringUtils.isNotBlank(device.getMaintenanceCycle())) { |
| | | syncMaintenancePlanDetail(device); |
| | | } |
| | | return rows; |
| | | } |
| | | |
| | | return deviceMapper.updateById(itemParameter); |
| | | /** |
| | | * 把设备同步到今年的设备校准计划明细:本年计划校准时间 = 校准有效期前一个月 |
| | | */ |
| | | 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 |
| | |
| | | .select(Device::getDeviceName, Device::getSpecificationModel, Device::getManagementNumber)) |
| | | .stream().map(d -> deviceKey(d.getDeviceName(), d.getSpecificationModel(), d.getManagementNumber())).collect(Collectors.toSet()); |
| | | |
| | | Map<String, List<SysDept>> departmentMap = sysDeptMapper.selectDeptList(new SysDept()).stream() |
| | | .filter(item -> StringUtils.isNotBlank(item.getDeptName())) |
| | | .collect(Collectors.groupingBy(item -> item.getDeptName().trim())); |
| | | Map<String, List<User>> userMap = userMapper.selectList(Wrappers.<User>lambdaQuery() |
| | | .isNotNull(User::getName).select(User::getId, User::getName)) |
| | | .stream().collect(Collectors.groupingBy(item -> item.getName().trim())); |
| | |
| | | throw new RuntimeException("第" + rowNumber + "行:仪器名称“" + deviceName + "”+规格型号“" + specificationModel + "”+管理编号“" + managementNumber + "”已存在"); |
| | | } |
| | | |
| | | String laboratoryName = required(row.getLaboratoryName(), rowNumber, "所属部门"); |
| | | List<SysDept> departments = departmentMap.get(laboratoryName); |
| | | if (CollectionUtils.isEmpty(departments) || departments.size() > 1) { |
| | | throw new RuntimeException("第" + rowNumber + "行:所属部门“" + laboratoryName + "”不存在或不唯一"); |
| | | } |
| | | |
| | | Device device = new Device(); |
| | | device.setDeviceName(deviceName); |
| | | device.setSpecificationModel(specificationModel); |
| | | device.setManagementNumber(managementNumber); |
| | | device.setActivationDate(parseDate(row.getActivationDate())); |
| | | device.setSubordinateDepartmentsId(departments.get(0).getDeptId().intValue()); |
| | | device.setDeviceStatus(Integer.valueOf(dictValue(statusMap, row.getDeviceStatus(), rowNumber, "当前状态", true))); |
| | | device.setCalibrationDate(required(row.getCalibrationDate(), rowNumber, "校准周期(月)")); |
| | | device.setEnDeviceName(trim(row.getEnDeviceName())); |