| | |
| | | |
| | | import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; |
| | | import com.baomidou.mybatisplus.core.toolkit.ObjectUtils; |
| | | import com.baomidou.mybatisplus.core.toolkit.StringUtils; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.ruoyi.common.core.domain.Result; |
| | | import com.ruoyi.common.numgen.NumberGenerator; |
| | | import com.ruoyi.common.utils.FileSaveUtil; |
| | | import com.ruoyi.device.dto.DeviceMetricRecordDto; |
| | | import com.ruoyi.device.mapper.DeviceMapper; |
| | | import com.ruoyi.device.pojo.Device; |
| | | import com.ruoyi.device.pojo.DeviceMetricRecord; |
| | | import com.ruoyi.device.pojo.DeviceMetricsCopy; |
| | | import com.ruoyi.device.service.DeviceMetricRecordService; |
| | |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import java.text.SimpleDateFormat; |
| | | import java.time.LocalDateTime; |
| | | import java.time.ZoneId; |
| | | import java.util.Date; |
| | | import java.util.Locale; |
| | | |
| | |
| | | @Autowired |
| | | private NumberGenerator<DeviceMetricRecord> numberGenerator; |
| | | |
| | | @Autowired |
| | | private DeviceMapper deviceMapper; |
| | | |
| | | @Operation(summary = "设备校准分页查询") |
| | | @GetMapping("/deviceMetricRecordPage") |
| | | public Result deviceMetricRecordPage(@RequestParam("deviceId") Integer deviceId, Page page, @RequestParam("type") String type) { |
| | |
| | | } |
| | | deviceMetricRecordService.saveOrUpdate(deviceMetricRecordDto); |
| | | if (CollectionUtils.isNotEmpty(deviceMetricRecordDto.getDeviceMetricsCopyList())) { |
| | | deviceMetricRecordDto.getDeviceMetricsCopyList().forEach(i -> i.setDeviceMetricsId(deviceMetricRecordDto.getId())); |
| | | // 校准条目来自校准项目维护表,主键不能带进记录明细表,否则会覆盖历史记录的条目 |
| | | deviceMetricRecordDto.getDeviceMetricsCopyList().forEach(i -> { |
| | | i.setId(null); |
| | | i.setDeviceMetricsId(deviceMetricRecordDto.getId()); |
| | | }); |
| | | deviceMetricsCopyService.saveOrUpdateBatch(deviceMetricRecordDto.getDeviceMetricsCopyList()); |
| | | } |
| | | // 校准完成后,把设备档案的最近/下次校准日期滚动到新周期 |
| | | if ("calibrate".equals(deviceMetricRecordDto.getType()) && deviceMetricRecordDto.getDeviceId() != null |
| | | && deviceMetricRecordDto.getCalibrationDate() != null) { |
| | | updateDeviceCalibrationDate(deviceMetricRecordDto); |
| | | } |
| | | return Result.success(); |
| | | } |
| | | |
| | | /** |
| | | * 滚动设备档案的最近/下次校准日期:仅当本次校准日期比档案中的最近校准日期更新时生效 |
| | | */ |
| | | private void updateDeviceCalibrationDate(DeviceMetricRecordDto dto) { |
| | | Device device = deviceMapper.selectById(dto.getDeviceId()); |
| | | if (device == null) { |
| | | return; |
| | | } |
| | | LocalDateTime calibrationDate = LocalDateTime.ofInstant(dto.getCalibrationDate().toInstant(), ZoneId.systemDefault()); |
| | | if (device.getLastCalibrationDate() != null && !calibrationDate.isAfter(device.getLastCalibrationDate())) { |
| | | return; |
| | | } |
| | | device.setLastCalibrationDate(calibrationDate); |
| | | LocalDateTime next = null; |
| | | if (StringUtils.isNotBlank(device.getCalibrationDate())) { |
| | | try { |
| | | next = calibrationDate.plusMonths(Long.parseLong(device.getCalibrationDate().trim())); |
| | | } catch (NumberFormatException ignored) { |
| | | } |
| | | } |
| | | if (next == null && dto.getNextCalibrationDate() != null) { |
| | | next = LocalDateTime.ofInstant(dto.getNextCalibrationDate().toInstant(), ZoneId.systemDefault()); |
| | | } |
| | | if (next != null) { |
| | | device.setNextCalibrationDate(next); |
| | | device.setActivationDate(next); |
| | | } |
| | | deviceMapper.updateById(device); |
| | | } |
| | | |
| | | @Operation(summary = "设备校准 删除") |
| | | @DeleteMapping("/deleteDeviceMetricRecord") |
| | | public Result deleteDeviceMetricRecord(@RequestParam("id") Integer id) { |