| | |
| | | package com.ruoyi.process.service.impl; |
| | | |
| | | import cn.hutool.core.util.StrUtil; |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.deepoove.poi.XWPFTemplate; |
| | | import com.deepoove.poi.config.Configure; |
| | | import com.ruoyi.common.core.domain.entity.User; |
| | | import com.ruoyi.common.utils.QueryWrappers; |
| | | import com.ruoyi.framework.exception.ErrorException; |
| | | import com.ruoyi.inspect.pojo.InsOrder; |
| | | import com.ruoyi.inspect.pojo.InsReport; |
| | | import com.ruoyi.inspect.dto.InsOrderDeviceRecordDto; |
| | | import com.ruoyi.inspect.mapper.InsProductResultMapper; |
| | | import com.ruoyi.inspect.mapper.InsSampleMapper; |
| | | import com.ruoyi.inspect.pojo.*; |
| | | import com.ruoyi.inspect.service.InsOrderService; |
| | | import com.ruoyi.inspect.service.InsReportService; |
| | | import com.ruoyi.inspect.util.HackLoopTableRenderPolicy; |
| | | import com.ruoyi.process.dto.InspectionOrderDto; |
| | | import com.ruoyi.process.dto.InspectionOrderExportDto; |
| | | import com.ruoyi.process.mapper.InspectionOrderMapper; |
| | | import com.ruoyi.process.pojo.InspectionOrder; |
| | | import com.ruoyi.process.pojo.InspectionOrderDetail; |
| | | import com.ruoyi.process.service.InspectionOrderDetailService; |
| | | import com.ruoyi.process.service.InspectionOrderService; |
| | | import com.ruoyi.process.mapper.ProcessOrderDeviceMapper; |
| | | import com.ruoyi.process.mapper.ProcessSampleMapper; |
| | | import com.ruoyi.process.pojo.*; |
| | | import com.ruoyi.process.service.*; |
| | | import com.ruoyi.system.mapper.UserMapper; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.stereotype.Service; |
| | |
| | | import java.nio.file.Path; |
| | | import java.nio.file.Paths; |
| | | import java.nio.file.StandardCopyOption; |
| | | import java.time.LocalDate; |
| | | import java.time.LocalDateTime; |
| | | import java.time.format.DateTimeFormatter; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * <p> |
| | |
| | | @Resource |
| | | private InsOrderService insOrderService; |
| | | @Resource |
| | | private InsSampleMapper insSampleMapper; |
| | | @Resource |
| | | private InsReportService insReportService; |
| | | @Value("${wordUrl}") |
| | | private String wordUrl; |
| | | @Resource |
| | | private ProcessReportService processReportService; |
| | | @Resource |
| | | private ProcessOrderDeviceMapper processOrderDeviceMapper; |
| | | @Resource |
| | | private InsProductResultMapper insProductResultMapper; |
| | | @Resource |
| | | private ProcessOrderDeviceService processOrderDeviceService; |
| | | @Resource |
| | | private UserMapper userMapper; |
| | | @Resource |
| | | private ProcessSampleService processSampleService; |
| | | @Resource |
| | | private ProcessSampleMapper processSampleMapper; |
| | | @Resource |
| | | private ProcessDealService processDealService; |
| | | |
| | | |
| | | /** |
| | |
| | | } |
| | | inspectionOrderDetailService.saveBatch(inspectionOrder.getOrderDetailList()); |
| | | } |
| | | |
| | | /*新增7.8报告结果*/ |
| | | ProcessReport processReport = new ProcessReport(); |
| | | processReport.setInspectionOrderId(inspectionOrder.getInsOrderId()); |
| | | processReport.setInsReportCode(inspectionOrder.getEntrustCode());//报告编号=委托编号 |
| | | //页数 |
| | | try { |
| | | com.aspose.words.Document doc = new com.aspose.words.Document(path); |
| | | processReport.setPages(doc.getPageCount()+""); |
| | | } catch (Exception e) { |
| | | } |
| | | processReport.setNumber("1");//发送份数默认1 |
| | | processReport.setSend(inspectionOrder.getCommissionUnit());//发往何处=委托单位 |
| | | processReport.setMethod(inspectionOrder.getSend()==1?"自取":"其他");//发送方式 |
| | | processReport.setSendTime(insReport.getRatifyTime().toLocalDate());//发送日期 |
| | | processReport.setSendUser(64);//发送人固定 |
| | | processReport.setSignatory(inspectionOrder.getCommissionUser());//签收人=委托人 |
| | | processReportService.save(processReport); |
| | | /*新增7.1委托单对应的设备使用记录*/ |
| | | addDeviceRecord(inspectionOrder,insReport.getWriteUserId()); |
| | | /*新增7.4样品接收*/ |
| | | List<InsSample> insSamples = insSampleMapper.selectList(Wrappers.<InsSample>lambdaQuery() |
| | | .eq(InsSample::getInsOrderId, inspectionOrder.getInsOrderId())); |
| | | if (insSamples.size()>0){ |
| | | List<ProcessSample> processSamples = new ArrayList<>(); |
| | | for (InsSample insSample : insSamples) { |
| | | ProcessSample processSample = new ProcessSample(); |
| | | processSample.setReceiveDate(inspectionOrder.getSampleData());//收样日期=领样日期 |
| | | processSample.setSampleCode(insSample.getSampleCode());//样品编号 |
| | | processSample.setSampleName(insSample.getSample());//样品名称 |
| | | processSample.setNum(1);//样品数量=1 |
| | | processSample.setSampleSupplier(inspectionOrder.getCommissionUnit());//来样单位 |
| | | LocalDate plusMonths = inspectionOrder.getSampleData() == null ? null : inspectionOrder.getSampleData().plusMonths(1); |
| | | processSample.setLeaveDate(plusMonths);//留样日期=收样日期往后延一个月 |
| | | processSample.setSampleState(inspectionOrder.getSampleStatus());//样品状态 |
| | | processSample.setDealTime(plusMonths);//退样日期=留样日期 |
| | | processSample.setInspectionOrderId(inspectionOrder.getInspectionOrderId());//委托单id |
| | | processSamples.add(processSample); |
| | | } |
| | | processSampleService.saveBatch(processSamples); |
| | | } |
| | | return true; |
| | | } |
| | | |
| | | private synchronized void addDeviceRecord(InspectionOrder inspectionOrder,Integer userId) { |
| | | // 查询设备使用记录查询该订单的使用记录 |
| | | Set<String> recordCodeset = processOrderDeviceMapper.selectDeviceNumber(inspectionOrder.getInspectionOrderId()); |
| | | // 获取订单设备编号 |
| | | List<InsProductResult> resultList = insProductResultMapper.selectResultByOrderId(inspectionOrder.getInsOrderId()); |
| | | Set<String> deviceCodeSet = new HashSet<>(); |
| | | for (InsProductResult result : resultList) { |
| | | // 添加设备编号 |
| | | List<JSONObject> jsonObjects = JSON.parseArray(result.getEquipValue(), JSONObject.class); |
| | | for (JSONObject jsonObject : jsonObjects) { |
| | | if (!"".equals(jsonObject.get("v") + "")) { |
| | | List<String> v = StrUtil.split(jsonObject.get("v") + "", ","); |
| | | deviceCodeSet.addAll(v); |
| | | } |
| | | } |
| | | } |
| | | // 1.判断是否有没有添加的使用记录 |
| | | Set<String> orderDeviceNumbers = getDeviceDifference(deviceCodeSet, recordCodeset); |
| | | // 添加使用记录, 根据编号查询设备id |
| | | if (CollectionUtils.isNotEmpty(orderDeviceNumbers)) { |
| | | List<Integer> orderDeviceIds = processOrderDeviceMapper.selectDeviceIdsByNumbers(orderDeviceNumbers); |
| | | List<ProcessOrderDevice> collect = orderDeviceIds.stream().map(deviceId -> { |
| | | ProcessOrderDevice processOrderDevice = new ProcessOrderDevice(); |
| | | processOrderDevice.setInspectionOrderId(inspectionOrder.getInspectionOrderId()); |
| | | processOrderDevice.setDeviceId(deviceId); |
| | | processOrderDevice.setSampleCode(inspectionOrder.getEntrustCode()); |
| | | processOrderDevice.setUseBefore(1); |
| | | processOrderDevice.setUseAfter(1); |
| | | processOrderDevice.setUsePerson(userMapper.selectById(userId).getName());//使用人 |
| | | processOrderDevice.setUsePersonId(userId);//使用人id |
| | | return processOrderDevice; |
| | | }).collect(Collectors.toList()); |
| | | processOrderDeviceService.saveBatch(collect); |
| | | } |
| | | } |
| | | |
| | | private static Set<String> getDeviceDifference(Set<String> number1, Set<String> number2) { |
| | | return number1.stream().filter(s1 -> number2.stream().noneMatch(s2 -> s1.equals(s2))) |
| | | .collect(Collectors.toSet()); |
| | | } |
| | | |
| | | /** |
| | |
| | | } |
| | | inspectionOrderDetailService.saveBatch(InspectionOrder.getOrderDetailList()); |
| | | |
| | | //修改7.9报告结果 |
| | | ProcessReport processReport = processReportService.getOne(Wrappers.<ProcessReport>lambdaQuery().eq(ProcessReport::getInspectionOrderId, InspectionOrder.getInspectionOrderId())); |
| | | processReport.setInsReportCode(InspectionOrder.getEntrustCode());//报告编号=委托编号 |
| | | processReportService.updateById(processReport); |
| | | |
| | | return true; |
| | | } |
| | | |
| | |
| | | inspectionOrderDetailService.remove(Wrappers.<InspectionOrderDetail>lambdaQuery() |
| | | .eq(InspectionOrderDetail::getInspectionOrderId, inspectionOrderId)); |
| | | baseMapper.deleteById(inspectionOrderId); |
| | | //删除7.8报告 |
| | | processReportService.remove(Wrappers.<ProcessReport>lambdaQuery() |
| | | .eq(ProcessReport::getInspectionOrderId, inspectionOrderId)); |
| | | //删除对应的设备使用记录 |
| | | processOrderDeviceService.remove(Wrappers.<ProcessOrderDevice>lambdaQuery() |
| | | .eq(ProcessOrderDevice::getInspectionOrderId, inspectionOrderId)); |
| | | //删除对应的7.4的样品申请 |
| | | List<ProcessSample> processSamples = processSampleMapper.selectList(Wrappers.<ProcessSample>lambdaQuery() |
| | | .eq(ProcessSample::getInspectionOrderId, inspectionOrderId)); |
| | | if (processSamples.size()>0){ |
| | | List<Integer> list = processSamples.stream().map(ProcessSample::getId).collect(Collectors.toList()); |
| | | processDealService.remove(Wrappers.<ProcessDeal>lambdaQuery() |
| | | .in(ProcessDeal::getProcessSampleId,list)); |
| | | } |
| | | //删除对应7.4的样品接收 |
| | | processSampleService.remove(Wrappers.<ProcessSample>lambdaQuery() |
| | | .eq(ProcessSample::getInspectionOrderId,inspectionOrderId)); |
| | | return true; |
| | | } |
| | | |
| | |
| | | template.write(os); |
| | | os.flush(); |
| | | os.close(); |
| | | inputStream.close(); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | throw new RuntimeException("导出失败"); |