| | |
| | | import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.ruoyi.basic.dto.StorageBlobDTO; |
| | | import com.ruoyi.basic.pojo.StorageAttachment; |
| | | import com.ruoyi.basic.service.StorageAttachmentService; |
| | | import com.ruoyi.common.enums.FileNameType; |
| | | import com.ruoyi.common.enums.StorageAttachmentRecordType; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import com.ruoyi.common.utils.poi.ExcelUtil; |
| | | import com.ruoyi.framework.web.domain.AjaxResult; |
| | | import com.ruoyi.measuringinstrumentledger.dto.MeasuringInstrumentLedgerDto; |
| | | import com.ruoyi.measuringinstrumentledger.dto.MeasuringInstrumentLedgerRecordDTO; |
| | | import com.ruoyi.measuringinstrumentledger.mapper.MeasuringInstrumentLedgerMapper; |
| | | import com.ruoyi.measuringinstrumentledger.mapper.MeasuringInstrumentLedgerRecordMapper; |
| | | import com.ruoyi.measuringinstrumentledger.pojo.MeasuringInstrumentLedger; |
| | |
| | | import java.time.LocalDateTime; |
| | | import java.time.format.DateTimeFormatter; |
| | | import java.util.ArrayList; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.UUID; |
| | | import java.util.stream.Collectors; |
| | | |
| | | import static com.ruoyi.common.constant.StorageAttachmentConstants.StorageAttachmentFile; |
| | | |
| | | /** |
| | | * @author :yys |
| | |
| | | @Autowired |
| | | private SysUserMapper sysUserMapper; |
| | | |
| | | @Autowired |
| | | private StorageAttachmentService attachmentService; |
| | | |
| | | @Value("${file.upload-dir}") |
| | | private String uploadDir; |
| | | |
| | | @Override |
| | | public IPage<MeasuringInstrumentLedger> listPage(Page page, MeasuringInstrumentLedger measuringInstrumentLedger) { |
| | | IPage<MeasuringInstrumentLedger> measuringInstrumentLedgerIPage = measuringInstrumentLedgerMapper.listPage(page, measuringInstrumentLedger); |
| | | List<Integer> types = new ArrayList<>(); |
| | | types.add(FileNameType.MEASURING.getValue()); |
| | | types.add(FileNameType.MEASURINGRecord.getValue()); |
| | | measuringInstrumentLedgerIPage.getRecords().forEach(item -> { |
| | | LambdaQueryWrapper<MeasuringInstrumentLedgerRecord> measuringInstrumentLedgerRecordLambdaQueryWrapper = new LambdaQueryWrapper<>(); |
| | | measuringInstrumentLedgerRecordLambdaQueryWrapper.eq(MeasuringInstrumentLedgerRecord::getMeasuringInstrumentLedgerId, item.getId()); |
| | | List<MeasuringInstrumentLedgerRecord> measuringInstrumentLedgerRecords = measuringInstrumentLedgerRecordMapper.selectList(measuringInstrumentLedgerRecordLambdaQueryWrapper); |
| | | List<Long> collect = new ArrayList<>(); |
| | | if(!CollectionUtils.isEmpty(measuringInstrumentLedgerRecords)){ |
| | | collect = measuringInstrumentLedgerRecords.stream().map(MeasuringInstrumentLedgerRecord::getId).collect(Collectors.toList()); |
| | | } |
| | | collect.add(item.getId()); |
| | | LambdaQueryWrapper<CommonFile> salesLedgerFileWrapper = new LambdaQueryWrapper<>(); |
| | | salesLedgerFileWrapper.in(CommonFile::getCommonId, collect) |
| | | .in(CommonFile::getType,types); |
| | | List<CommonFile> commonFiles = commonFileMapper.selectList(salesLedgerFileWrapper); |
| | | item.setCommonFiles(commonFiles); |
| | | IPage<MeasuringInstrumentLedger> iPage = measuringInstrumentLedgerMapper.listPage(page, measuringInstrumentLedger); |
| | | List<MeasuringInstrumentLedger> records = iPage.getRecords(); |
| | | List<Long> ids = records.stream().map(MeasuringInstrumentLedger::getId).collect(Collectors.toList()); |
| | | |
| | | }); |
| | | return measuringInstrumentLedgerIPage; |
| | | List<MeasuringInstrumentLedgerRecord> measuringInstrumentLedgerRecords = measuringInstrumentLedgerRecordMapper.selectList(new LambdaQueryWrapper<MeasuringInstrumentLedgerRecord>() |
| | | .in(MeasuringInstrumentLedgerRecord::getMeasuringInstrumentLedgerId, ids) |
| | | .orderByDesc(MeasuringInstrumentLedgerRecord::getCreateTime)); |
| | | if (!CollectionUtils.isEmpty(measuringInstrumentLedgerRecords)) { |
| | | Map<Long, List<MeasuringInstrumentLedgerRecord>> collect = measuringInstrumentLedgerRecords.stream().collect(Collectors.groupingBy(MeasuringInstrumentLedgerRecord::getMeasuringInstrumentLedgerId)); |
| | | for (MeasuringInstrumentLedger ledger : records) { |
| | | if (collect.containsKey(ledger.getId())) { |
| | | ledger.setMostDate(collect.get(ledger.getId()).get(0).getRecordDate()); |
| | | } |
| | | } |
| | | } |
| | | return iPage; |
| | | } |
| | | |
| | | @Override |
| | | public boolean verifying(MeasuringInstrumentLedgerDto req) throws IOException { |
| | | MeasuringInstrumentLedger measuringInstrumentLedger = measuringInstrumentLedgerMapper.selectById(req.getId()); |
| | | if(measuringInstrumentLedger == null) { |
| | | return false; |
| | | public boolean verifying(MeasuringInstrumentLedgerRecordDTO req) throws IOException { |
| | | MeasuringInstrumentLedger measuringInstrumentLedger = measuringInstrumentLedgerMapper.selectById(req.getMeasuringInstrumentLedgerId()); |
| | | if (measuringInstrumentLedger == null) { |
| | | throw new RuntimeException("计量器具台账不存在"); |
| | | } |
| | | SysUser sysUser = sysUserMapper.selectUserById(measuringInstrumentLedger.getUserId()); |
| | | measuringInstrumentLedger.setValid(req.getValid()); |
| | | measuringInstrumentLedger.setMostDate(req.getRecordDate()); |
| | | measuringInstrumentLedger.setNextDate(new Date(req.getRecordDate().getTime() + 1000L * 60 * 60 * 24 * req.getValid())); |
| | | MeasuringInstrumentLedgerRecord measuringInstrumentLedgerRecord = new MeasuringInstrumentLedgerRecord(); |
| | | if(measuringInstrumentLedgerMapper.updateById(measuringInstrumentLedger) > 0) { |
| | | measuringInstrumentLedgerRecord.setMeasuringInstrumentLedgerId(req.getId()); |
| | | measuringInstrumentLedgerRecord.setRecordDate(req.getRecordDate()); |
| | | measuringInstrumentLedgerRecord.setEntryDate(req.getEntryDate()); |
| | | measuringInstrumentLedgerRecord.setValid(req.getValid()); |
| | | measuringInstrumentLedgerRecord.setUserId(req.getUserId()); |
| | | measuringInstrumentLedgerRecord.setUserName(sysUser.getUserName()); |
| | | measuringInstrumentLedgerRecordMapper.insert(measuringInstrumentLedgerRecord); |
| | | // 台账绑定一次 |
| | | // if(!CollectionUtils.isEmpty(req.getTempFileIds())){ |
| | | // migrateTempFilesToFormal(measuringInstrumentLedger.getId(), req.getTempFileIds(), FileNameType.MEASURING.getValue()); |
| | | // } |
| | | // 台账记录绑定一次 |
| | | if(!CollectionUtils.isEmpty(req.getTempFileIds())){ |
| | | migrateTempFilesToFormal(measuringInstrumentLedgerRecord.getId(), req.getTempFileIds(), FileNameType.MEASURINGRecord.getValue()); |
| | | measuringInstrumentLedgerRecordMapper.insert(req); |
| | | if (req.getBlobs() != null && !req.getBlobs().isEmpty()) { |
| | | List<StorageAttachment> attachments = new ArrayList<>(); |
| | | |
| | | for (StorageBlobDTO storageBlobDTO : req.getBlobs()) { |
| | | StorageAttachment storageAttachment = new StorageAttachment( |
| | | StorageAttachmentFile, |
| | | (long) StorageAttachmentRecordType.MeasuringInstrumentLedgerRecord.ordinal(), |
| | | req.getId() |
| | | ); |
| | | storageAttachment.setStorageBlobDTO(storageBlobDTO); |
| | | attachments.add(storageAttachment); |
| | | } |
| | | return true; |
| | | attachmentService.saveStorageAttachment(attachments, req.getId(), StorageAttachmentRecordType.MeasuringInstrumentLedgerRecord, StorageAttachmentFile); |
| | | } |
| | | return false; |
| | | return true; |
| | | } |
| | | |
| | | @Override |
| | |
| | | |
| | | try { |
| | | // 执行文件迁移(使用原子操作确保安全性) |
| | | Files.move( |
| | | Paths.get(tempFile.getTempPath()), |
| | | formalFilePath, |
| | | StandardCopyOption.REPLACE_EXISTING, |
| | | StandardCopyOption.ATOMIC_MOVE |
| | | ); |
| | | // Files.move( |
| | | // Paths.get(tempFile.getTempPath()), |
| | | // formalFilePath, |
| | | // StandardCopyOption.REPLACE_EXISTING, |
| | | // StandardCopyOption.ATOMIC_MOVE |
| | | // ); |
| | | // 原子移动失败,使用复制+删除 |
| | | Files.copy(Paths.get(tempFile.getTempPath()), formalFilePath, StandardCopyOption.REPLACE_EXISTING); |
| | | Files.deleteIfExists(Paths.get(tempFile.getTempPath())); |
| | | log.info("文件迁移成功: {} -> {}", tempFile.getTempPath(), formalFilePath); |
| | | |
| | | // 更新文件记录(关联到业务ID) |