| | |
| | | package com.ruoyi.process.service.impl; |
| | | |
| | | import cn.hutool.core.util.NumberUtil; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.core.toolkit.ObjectUtils; |
| | | import com.baomidou.mybatisplus.core.toolkit.StringUtils; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.deepoove.poi.XWPFTemplate; |
| | |
| | | import com.ruoyi.common.core.domain.entity.User; |
| | | import com.ruoyi.common.utils.QueryWrappers; |
| | | import com.ruoyi.framework.exception.ErrorException; |
| | | import com.ruoyi.basic.util.HackLoopTableRenderPolicy; |
| | | import com.ruoyi.basic.util.XWPFDocumentUtils; |
| | | import com.ruoyi.inspect.util.HackLoopTableRenderPolicy; |
| | | import com.ruoyi.inspect.util.XWPFDocumentUtils; |
| | | import com.ruoyi.process.dto.InspectionOrderDetail; |
| | | import com.ruoyi.process.dto.InspectionOrderExportDto; |
| | | import com.ruoyi.process.dto.ProcessOrderDto; |
| | | import com.ruoyi.process.dto.SampleItemDto; |
| | | import com.ruoyi.process.mapper.ProcessOrderMapper; |
| | | import com.ruoyi.process.mapper.ProcessSampleNewMapper; |
| | | import com.ruoyi.process.pojo.ProcessOrder; |
| | | import com.ruoyi.process.pojo.ProcessSampleNew; |
| | | import com.ruoyi.process.service.ProcessOrderService; |
| | | import com.ruoyi.system.mapper.UserMapper; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.poi.xwpf.usermodel.XWPFDocument; |
| | | import org.apache.poi.xwpf.usermodel.XWPFTable; |
| | | import org.apache.poi.xwpf.usermodel.XWPFTableCell; |
| | | import org.apache.poi.xwpf.usermodel.XWPFTableRow; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import javax.annotation.Resource; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.io.InputStream; |
| | | import java.io.OutputStream; |
| | | import java.net.URLEncoder; |
| | | import java.time.LocalDate; |
| | | import java.time.LocalDateTime; |
| | | import java.time.LocalTime; |
| | | import java.time.format.DateTimeFormatter; |
| | | import java.util.ArrayList; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Objects; |
| | | |
| | | /** |
| | | * <p> |
| | |
| | | * @since 2024-11-05 03:06:20 |
| | | */ |
| | | @Service |
| | | @Slf4j |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public class ProcessOrderServiceImpl extends ServiceImpl<ProcessOrderMapper, ProcessOrder> implements ProcessOrderService { |
| | | |
| | | @Resource |
| | | private ProcessSampleNewMapper processSampleNewMapper; |
| | | |
| | | @Resource |
| | | private ProcessOrderMapper processOrderMapper; |
| | |
| | | } |
| | | |
| | | @Override |
| | | public void uploadFile(MultipartFile file, Integer id) { |
| | | ProcessOrder processOrder = processOrderMapper.selectById(id); |
| | | ArrayList<String> list = new ArrayList<>(); |
| | | try (InputStream inputStream = file.getInputStream()) { |
| | | XWPFDocument xwpfDocument = new XWPFDocument(inputStream); |
| | | // 获取所有表格 |
| | | List<XWPFTable> tables = xwpfDocument.getTables(); |
| | | for (XWPFTable table : tables) { |
| | | // 获取表格的行 |
| | | List<XWPFTableRow> rows = table.getRows(); |
| | | for (int i = 0; i < rows.size(); i++) { |
| | | // 获取每一行 |
| | | List<XWPFTableCell> tableCells = rows.get(i).getTableCells(); |
| | | for (int j = 0; j < tableCells.size(); j++) { |
| | | // 获取每一单元格 |
| | | String text = rows.get(i).getCell(j).getText(); |
| | | log.info("读取的内容:{}", text); |
| | | list.add(text); |
| | | } |
| | | } |
| | | } |
| | | // 根据获取到的内容进行赋值 |
| | | DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy年MM月dd日"); |
| | | processOrder.setIsUpload(1); // 是否上传 |
| | | processOrder.setSampleS(list.get(1)); // 试样名称 |
| | | processOrder.setEntrustmentTimeS(list.get(3)); // 委托时间 |
| | | processOrder.setSampleTypeS(list.get(5)); // 型号 |
| | | processOrder.setCompanyS(list.get(7)); // 委托单位 |
| | | processOrder.setProductionS(list.get(9)); // 生产单位 |
| | | processOrder.setPrepareUserS(list.get(11)); // 委托人 |
| | | if (NumberUtil.isNumber(list.get(13))) { |
| | | processOrder.setSampleNumS(Integer.parseInt(list.get(13))); // 样品数量 |
| | | } |
| | | // 样品状态 |
| | | switch (list.get(15)) { |
| | | case "待审核": |
| | | processOrder.setInsStateS(0); |
| | | break; |
| | | case "待检验": |
| | | processOrder.setInsStateS(1); |
| | | break; |
| | | case "已检验": |
| | | processOrder.setInsStateS(4); |
| | | break; |
| | | case "退回": |
| | | processOrder.setInsStateS(2); |
| | | break; |
| | | case "撤销": |
| | | processOrder.setInsStateS(3); |
| | | break; |
| | | } |
| | | if (list.get(17).contains("☑是Yes")) { |
| | | processOrder.setIsLeaveS(1); // 是否留样 |
| | | } else { |
| | | processOrder.setIsLeaveS(0); // 是否留样 |
| | | } |
| | | |
| | | if (list.get(19).contains("☑委托单位取回")) { |
| | | processOrder.setProcessingS(0); // 样品处理方式 |
| | | } |
| | | if(list.get(19).contains("☑实验室处理")){ |
| | | processOrder.setProcessingS(1); // 样品处理方式 |
| | | } |
| | | processOrder.setAppointedS(list.get(21)); // 约定时间 |
| | | if (list.get(23).contains("☑自取")) { |
| | | processOrder.setSendS(1); // 是否自取 |
| | | } |
| | | if(list.get(23).contains("☑其它")) { |
| | | processOrder.setSendS(0); // 是否自取 |
| | | } |
| | | // 从30开始是样品表格数据 到 值为判定规则结束 |
| | | ArrayList<String> sampleList = new ArrayList<>(); |
| | | for (int i = 29; i < list.size(); i++) { |
| | | if (list.get(i).contains("判定规则")) { |
| | | break; |
| | | } |
| | | sampleList.add(list.get(i)); |
| | | } |
| | | // 样品表格数据 |
| | | // 根据orderId 将原本的删除 |
| | | processSampleNewMapper.delete(new LambdaQueryWrapper<ProcessSampleNew>().eq(ProcessSampleNew::getCnasOrderId, id)); |
| | | for (int i = 0; i < sampleList.size(); i += 5) { |
| | | ProcessSampleNew processSampleNew = new ProcessSampleNew(); |
| | | processSampleNew.setCnasOrderId(id); |
| | | processSampleNew.setSampleCode(sampleList.get(i + 1)); |
| | | processSampleNew.setInspectionItem(sampleList.get(i + 2)); |
| | | processSampleNew.setMethod(sampleList.get(i + 3)); |
| | | processSampleNew.setRemark(sampleList.get(i + 4)); |
| | | processSampleNewMapper.insert(processSampleNew); |
| | | } |
| | | int len = sampleList.size() + 28; |
| | | // 判定规则 |
| | | processOrder.setPrepareUserUrlS(list.get(len + 4)); // 委托人签名 |
| | | if (StringUtils.isNotEmpty(list.get(len + 6))) { |
| | | String date = list.get(len + 6).substring(0, list.get(len + 6).indexOf("日") + 1); |
| | | processOrder.setCreateTimeTwoS(date); // 委托日期 |
| | | } |
| | | |
| | | processOrder.setPhoneS(list.get(len + 8)); // 联系方式 |
| | | Integer comprehensiveUser = null; |
| | | if (StringUtils.isNotEmpty(list.get(len + 10))) { |
| | | List<User> users = userMapper.selectList(new LambdaQueryWrapper<User>().like(User::getName, list.get(len + 10))); |
| | | comprehensiveUser = users.get(0).getId(); |
| | | } |
| | | processOrder.setComprehensiveUser(comprehensiveUser); // 综合室签名 |
| | | |
| | | if (StringUtils.isNotEmpty(list.get(len + 12))) { |
| | | String date = list.get(len + 12).substring(0, list.get(len + 12).indexOf("日") + 1); |
| | | if (StringUtils.isNotEmpty(date)) { |
| | | LocalDate parse = LocalDate.parse(date, formatter); |
| | | processOrder.setComprehensiveTime(parse); // 接收日期 |
| | | } |
| | | } |
| | | if (StringUtils.isNotEmpty(list.get(len + 14))) { |
| | | List<User> users = userMapper.selectList(new LambdaQueryWrapper<User>().like(User::getName, list.get(len + 14))); |
| | | processOrder.setIssueUser(users.get(0).getId()); // 领样员 |
| | | } |
| | | if (StringUtils.isNotEmpty(list.get(len + 16))) { |
| | | String date = list.get(len + 16).substring(0, list.get(len + 16).indexOf("日") + 1); |
| | | if (StringUtils.isNotEmpty(date)) { |
| | | LocalDate parse = LocalDate.parse(date, formatter); |
| | | processOrder.setIssueTime(parse); // 领样日期 |
| | | } |
| | | } |
| | | processOrderMapper.updateById(processOrder); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | throw new ErrorException("上传失败"); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public ProcessOrderDto getProcessOrder(Integer id) { |
| | | return processOrderMapper.getProcessOrder(id); |
| | | ProcessOrderDto a = processOrderMapper.getProcessOrder(id); |
| | | // 如果上传了则采用上传了的字段 |
| | | if (Objects.nonNull(a.getIsUpload()) && a.getIsUpload().equals(1)) { |
| | | a = getNewValue(a); |
| | | } |
| | | return a; |
| | | } |
| | | public ProcessOrderDto getNewValue(ProcessOrderDto a) { |
| | | List<ProcessSampleNew> processSampleNews = processSampleNewMapper.selectList(new LambdaQueryWrapper<ProcessSampleNew>() |
| | | .eq(ProcessSampleNew::getCnasOrderId, a.getId())); |
| | | a.setSample(a.getSampleS()); // 试样名称 |
| | | DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy年MM月dd日"); |
| | | if (StringUtils.isNotEmpty(a.getEntrustmentTimeS())) { |
| | | LocalDate parse = LocalDate.parse(a.getEntrustmentTimeS(), dateTimeFormatter); |
| | | LocalDateTime localDateTime = LocalDateTime.of(parse, LocalTime.MIDNIGHT); |
| | | a.setCreateTime(localDateTime); // 委托时间 |
| | | } |
| | | a.setSampleType(a.getSampleTypeS()); // 型号 |
| | | a.setCompany(a.getCompanyS()); // 委托单位 |
| | | a.setProduction(a.getProductionS()); // 生产单位 |
| | | a.setPrepareUser(a.getPrepareUserS()); // 委托人 |
| | | a.setSampleNum(a.getSampleNumS() + ""); // 样品数量 |
| | | a.setInsState(a.getInsStateS()); // 样品状态 |
| | | a.setIsLeave(a.getIsLeaveS()); // 是否留样 |
| | | a.setProcessing(a.getProcessingS()); // 样品处理方式 |
| | | a.setPhone(a.getPhoneS()); // 联系方式 |
| | | |
| | | if (StringUtils.isNotEmpty(a.getAppointedS())) { |
| | | LocalDate parse = LocalDate.parse(a.getAppointedS(), dateTimeFormatter); |
| | | a.setAppointed(parse); // 约定时间 |
| | | } |
| | | a.setSend(a.getSendS()); // 报告发送方式 |
| | | ArrayList<SampleItemDto> sampleItemDtos = new ArrayList<>(); |
| | | for (ProcessSampleNew b : processSampleNews) { |
| | | SampleItemDto sampleItemDto = new SampleItemDto(); |
| | | sampleItemDto.setCode(b.getSampleCode()); |
| | | sampleItemDto.setProduct(b.getInspectionItem()); |
| | | sampleItemDto.setStandardMethodList(b.getMethod()); |
| | | sampleItemDto.setRemark(b.getRemark()); |
| | | sampleItemDtos.add(sampleItemDto); |
| | | } |
| | | a.setSampleItems(sampleItemDtos); |
| | | return a; |
| | | } |
| | | |
| | | @Override |
| | |
| | | public void exportInspectionOrder(Integer id, HttpServletResponse response) { |
| | | ProcessOrder processOrder = baseMapper.selectById(id); |
| | | InspectionOrderExportDto inspectionOrderExportDto = extracted(processOrder); |
| | | List<InspectionOrderDetail> list = baseMapper.selectInsOrder(processOrder.getInsOrderId()); |
| | | int index = 1; |
| | | for (InspectionOrderDetail inspectionOrderDetail : list) { |
| | | inspectionOrderDetail.setIndex(index); |
| | | index++; |
| | | final List<InspectionOrderDetail> list; |
| | | // 如果该数据上传了文件 就使用上传的数据 |
| | | if(Objects.nonNull(processOrder.getIsUpload()) && processOrder.getIsUpload().equals(1)) { |
| | | list = new ArrayList<>(); |
| | | List<ProcessSampleNew> processSampleNews = processSampleNewMapper.selectList(new LambdaQueryWrapper<ProcessSampleNew>() |
| | | .eq(ProcessSampleNew::getCnasOrderId, id)); |
| | | inspectionOrderExportDto.setSample(processOrder.getSampleS()); // 试样名称 |
| | | inspectionOrderExportDto.setCommissionDateString(processOrder.getEntrustmentTimeS()); // 委托时间 |
| | | inspectionOrderExportDto.setSampleType(processOrder.getSampleTypeS()); // 型号 |
| | | inspectionOrderExportDto.setCompany(processOrder.getCompanyS()); // 委托单位 |
| | | inspectionOrderExportDto.setProduction(processOrder.getProductionS()); // 生产单位 |
| | | inspectionOrderExportDto.setPrepareUser(processOrder.getPrepareUserS()); // 委托人 |
| | | inspectionOrderExportDto.setSampleNum(processOrder.getSampleNumS() + ""); // 样品数量 |
| | | inspectionOrderExportDto.setInsState(processOrder.getInsStateS()); // 样品状态 |
| | | // 是否留样 |
| | | inspectionOrderExportDto.setIsLeave1(processOrder.getIsLeaveS() == 1 ? "☑" : "□"); |
| | | inspectionOrderExportDto.setIsLeave2(processOrder.getIsLeaveS() == 0 ? "☑" : "□"); |
| | | // 样品处理方式 |
| | | inspectionOrderExportDto.setProcessing0(processOrder.getProcessingS() == 0 ? "☑" : "□"); |
| | | inspectionOrderExportDto.setProcessing1(processOrder.getProcessingS() == 1 ? "☑" : "□"); |
| | | // 约定时间 |
| | | inspectionOrderExportDto.setAppointedString(processOrder.getAppointedS()); |
| | | // 是否自取 |
| | | inspectionOrderExportDto.setSend0(processOrder.getSendS() == 0 ? "☑" : "□"); |
| | | inspectionOrderExportDto.setSend1(processOrder.getSendS() == 1 ? "☑" : "□"); |
| | | int i = 1; |
| | | for(ProcessSampleNew a : processSampleNews) { |
| | | InspectionOrderDetail inspectionOrderDetail = new InspectionOrderDetail(); |
| | | inspectionOrderDetail.setSampleNumber(a.getSampleCode()); |
| | | inspectionOrderDetail.setTestItem(a.getInspectionItem()); |
| | | inspectionOrderDetail.setTestStandard(a.getMethod()); |
| | | inspectionOrderDetail.setRemark(a.getRemark()); |
| | | inspectionOrderDetail.setIndex(i); |
| | | list.add(inspectionOrderDetail); |
| | | i++; |
| | | } |
| | | // 委托人签名 |
| | | inspectionOrderExportDto.setPrepareUser(processOrder.getPrepareUserS()); |
| | | // 委托日期 |
| | | inspectionOrderExportDto.setCommissionDateString(processOrder.getEntrustmentTimeS()); |
| | | // 联系方式 |
| | | inspectionOrderExportDto.setPhone(processOrder.getPhoneS()); |
| | | }else { |
| | | list = baseMapper.selectInsOrder(processOrder.getInsOrderId()); |
| | | int index = 1; |
| | | for (InspectionOrderDetail inspectionOrderDetail : list) { |
| | | inspectionOrderDetail.setIndex(index); |
| | | index++; |
| | | } |
| | | } |
| | | |
| | | // 获取路径 |
| | | InputStream inputStream = this.getClass().getResourceAsStream("/static/inspection-order.docx"); |
| | | Configure configure = Configure.builder() |
| | |
| | | |
| | | inspectionOrderExportDto.setIsLeave1(processOrderDto.getIsLeave() != null && processOrderDto.getIsLeave() == 1 ? "☑" : "□"); |
| | | inspectionOrderExportDto.setIsLeave2(processOrderDto.getIsLeave() != null && processOrderDto.getIsLeave() == 0 ? "☑" : "□"); |
| | | inspectionOrderExportDto.setSend0(processOrderDto.getSend() != null && processOrderDto.getSend() == 1 ? "☑" : "□"); |
| | | inspectionOrderExportDto.setSend1(processOrderDto.getSend() != null && processOrderDto.getSend() == 0 ? "☑" : "□"); |
| | | inspectionOrderExportDto.setSend0(processOrderDto.getSend() != null && processOrderDto.getSend() == 0 ? "☑" : "□"); |
| | | inspectionOrderExportDto.setSend1(processOrderDto.getSend() != null && processOrderDto.getSend() == 1 ? "☑" : "□"); |
| | | inspectionOrderExportDto.setProcessing0(processOrderDto.getProcessing() != null && processOrderDto.getProcessing() == 0 ? "☑" : "□"); |
| | | inspectionOrderExportDto.setProcessing1(processOrderDto.getProcessing() != null && processOrderDto.getProcessing() == 1 ? "☑" : "□"); |
| | | if (ObjectUtils.isNotEmpty(processOrder.getRule())) { |