| | |
| | | import com.itextpdf.text.pdf.PdfStamper; |
| | | import com.yuanchu.mom.common.GetLook; |
| | | import com.yuanchu.mom.common.PrintChina; |
| | | import com.yuanchu.mom.dto.InsReportDto; |
| | | import com.yuanchu.mom.dto.InsReportDto1; |
| | | import com.yuanchu.mom.dto.ReportPageDto; |
| | | import com.yuanchu.mom.dto.SampleProductDto; |
| | | import com.yuanchu.mom.exception.ErrorException; |
| | |
| | | private InsOrderMapper insOrderMapper; |
| | | |
| | | @Resource |
| | | private StandardMethodListMapper standardMethodListMapper; |
| | | |
| | | @Resource |
| | | private InsOrderStateMapper insOrderStateMapper; |
| | | |
| | | @Resource |
| | | private InsProductMapper insProductMapper; |
| | | |
| | | @Resource |
| | | private InsProductResultMapper insProductResultMapper; |
| | | |
| | | @Resource |
| | | private InsProductResult2Mapper insProductResult2Mapper; |
| | | |
| | | @Resource |
| | | private InsSampleMapper insSampleMapper; |
| | |
| | | //是否需要生成报告: 0不需要;1需要 |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public int isReport(Integer id, Integer state) { |
| | | public int isReport(InsReportDto insReportDto) { |
| | | //先判断该订单是否可以去生产报告 |
| | | Long count = insOrderStateMapper.selectCount(Wrappers.<InsOrderState>lambdaQuery().eq(InsOrderState::getInsOrderId, id).eq(InsOrderState::getInsState, 5)); |
| | | Long count = insOrderStateMapper.selectCount(Wrappers.<InsOrderState>lambdaQuery().eq(InsOrderState::getInsOrderId, insReportDto.getId()).eq(InsOrderState::getInsState, 5)); |
| | | if (count > 0) { |
| | | if (state == 1) { |
| | | generateReport(id); |
| | | if (insReportDto.getState() == 1) { |
| | | generateReport(insReportDto.getId(), insReportDto.getInsReportDto1s()); |
| | | } else { |
| | | //结束订单 |
| | | InsOrder insOrder = new InsOrder(); |
| | | insOrder.setId(id); |
| | | insOrder.setId(insReportDto.getId()); |
| | | insOrder.setState(4); |
| | | insOrderMapper.updateById(insOrder); |
| | | } |
| | |
| | | throw new ErrorException("该订单还未结束试验,无法生产报告!"); |
| | | } |
| | | return 0; |
| | | } |
| | | |
| | | //查出该订单下每个站点下的检验次数 |
| | | @Override |
| | | public List<InsOrderState> getInsOrderStateCount(Integer id) { |
| | | List<InsOrderState> insOrderStates = insOrderStateMapper.getInsOrderStateCount(id); |
| | | return insOrderStates; |
| | | } |
| | | |
| | | |
| | |
| | | } |
| | | |
| | | //生成报告 |
| | | private void generateReport(Integer orderId) { |
| | | private void generateReport(Integer orderId, List<InsReportDto1> insReportDto1s) { |
| | | LocalDateTime now = LocalDateTime.now(); |
| | | InsOrder insOrder = insOrderMapper.selectById(orderId); |
| | | //委托部门 departLims |
| | | String departLims = userMapper.selectDepartLims(insOrder.getPrepareUser()); |
| | | //samples是过滤掉没有检验项目的样品 |
| | | List<SampleProductDto> samples = insSampleMapper.selectSampleProductListByOrderId(orderId); |
| | | if (samples.size()==0){ |
| | | samples=insSampleMapper.selectSampleProductListByOrder2Id(orderId); |
| | | } |
| | | String sampleCode = samples.get(0).getSampleCode(); |
| | | InsReport insReport = new InsReport(); |
| | | insReport.setCode(insOrder.getEntrustCode()); |
| | |
| | | String[] monthNames = {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"}; |
| | | samples.forEach(s -> { |
| | | models.add(s.getModel()); |
| | | standardMethod.add(insOrderMapper.getStandardMethodCode(s.getStandardMethodListId())); |
| | | standardMethod.addAll(standardMethodListMapper.selectList(Wrappers.<StandardMethodList>lambdaQuery() |
| | | .in(StandardMethodList::getId,Arrays.stream(s.getStandardMethodListId().replaceAll("[\\[\\]]", "").split(",")) |
| | | .map(String::trim).map(Integer::parseInt).collect(Collectors.toList()))).stream().map(StandardMethodList::getCode).distinct().collect(Collectors.toList())); |
| | | //总数 |
| | | Long productCount = insProductMapper.selectCount(Wrappers.<InsProduct>lambdaQuery().eq(InsProduct::getInsSampleId, s.getId())); |
| | | Long productCount = insProductMapper.selectCount(Wrappers.<InsProduct>lambdaQuery() |
| | | .eq(InsProduct::getInsSampleId, s.getId())); |
| | | productSize.set(productSize.get() + Integer.parseInt(productCount + "")); |
| | | //不判定 |
| | | Long productCount1 = insProductMapper.selectCount(Wrappers.<InsProduct>lambdaQuery() |
| | | .eq(InsProduct::getInsSampleId, s.getId()) |
| | | .eq(InsProduct::getInsResult,3)); |
| | | .eq(InsProduct::getInsResult, 3)); |
| | | productSize1.set(productSize1.get() + Integer.parseInt(productCount1 + "")); |
| | | //不合格 |
| | | Long productCount2 = insProductMapper.selectCount(Wrappers.<InsProduct>lambdaQuery() |
| | | .eq(InsProduct::getInsSampleId, s.getId()) |
| | | .eq(InsProduct::getInsResult,0)); |
| | | .eq(InsProduct::getInsResult, 0)); |
| | | productSize2.set(productSize2.get() + Integer.parseInt(productCount2 + "")); |
| | | //合格 |
| | | Long productCount3 = insProductMapper.selectCount(Wrappers.<InsProduct>lambdaQuery() |
| | | .eq(InsProduct::getInsSampleId, s.getId()) |
| | | .eq(InsProduct::getInsResult,1)); |
| | | .eq(InsProduct::getInsResult, 1)); |
| | | productSize3.set(productSize3.get() + Integer.parseInt(productCount3 + "")); |
| | | for (InsProduct b : s.getInsProduct()) { |
| | | if (b.getInsProductResult() != null) { |
| | | List<JSONObject> jsonObjects = JSON.parseArray(b.getInsProductResult().getEquipValue(), JSONObject.class); |
| | | //将项目按照站点进行分类 |
| | | Map<String, List<InsProduct>> listMap = s.getInsProduct().stream().collect(Collectors.groupingBy(InsProduct::getLaboratory)); |
| | | // 创建一个 Map 将站点和项目ID的映射关系 |
| | | Map<String, Set<Integer>> labToDeviceMap = new HashMap<>(); |
| | | // 获取所有站点的项目ID 列表 |
| | | for (Map.Entry<String, List<InsProduct>> entry : listMap.entrySet()) { |
| | | Set<Integer> deviceIds = entry.getValue().stream() |
| | | .map(InsProduct::getId) |
| | | .collect(Collectors.toSet()); |
| | | labToDeviceMap.put(entry.getKey(), deviceIds); |
| | | } |
| | | for (InsReportDto1 insReportDto1 : insReportDto1s) { |
| | | String laboratory = insReportDto1.getLaboratory(); |
| | | if (!labToDeviceMap.containsKey(laboratory)) { |
| | | continue; |
| | | } |
| | | Set<Integer> deviceIds = labToDeviceMap.get(laboratory); |
| | | Integer num = insReportDto1.getNum(); |
| | | List<InsProductResult> insProductResults = insProductResultMapper.selectList( |
| | | Wrappers.<InsProductResult>lambdaQuery() |
| | | .eq(InsProductResult::getNum, num) |
| | | .in(InsProductResult::getInsProductId, deviceIds)); |
| | | for (InsProductResult insProductResult : insProductResults) { |
| | | List<JSONObject> jsonObjects = JSON.parseArray(insProductResult.getEquipValue(), JSONObject.class); |
| | | for (JSONObject jsonObject : jsonObjects) { |
| | | if (!"".equals(jsonObject.get("v") + "")) { |
| | | deviceSet.add(jsonObject.get("v") + ""); |
| | | String value = jsonObject.getString("v"); |
| | | if (value != null && !value.isEmpty()) { |
| | | deviceSet.add(value); |
| | | } |
| | | } |
| | | } |
| | | if (b.getInsProductResult2() != null) { |
| | | for (InsProductResult2 jsonObject : b.getInsProductResult2()) { |
| | | if (jsonObject.getEquipValue() != null) { |
| | | deviceSet.add(jsonObject.getEquipValue()); |
| | | } |
| | | List<InsProductResult2> insProductResult2s = insProductResult2Mapper.selectList( |
| | | Wrappers.<InsProductResult2>lambdaQuery() |
| | | .eq(InsProductResult2::getNum, num) |
| | | .in(InsProductResult2::getInsProductId, deviceIds)); |
| | | for (InsProductResult2 result2 : insProductResult2s) { |
| | | String equipValue = result2.getEquipValue(); |
| | | if (equipValue != null && !equipValue.isEmpty()) { |
| | | deviceSet.add(equipValue); |
| | | } |
| | | } |
| | | } |