| | |
| | | import java.math.RoundingMode; |
| | | import java.nio.file.Files; |
| | | import java.nio.file.Paths; |
| | | import java.text.DecimalFormat; |
| | | import java.text.SimpleDateFormat; |
| | | import java.time.LocalDate; |
| | | import java.time.LocalDateTime; |
| | |
| | | private ISysDictTypeService iSysDictTypeService; |
| | | @Resource |
| | | private InsOrderRatesService insOrderRatesService; |
| | | @Resource |
| | | private InsProductDeviationWarningService insProductDeviationWarningService; |
| | | @Resource |
| | | private InsProductDeviationWarningDetailService insProductDeviationWarningDetailService; |
| | | |
| | | |
| | | @Override |
| | | public IPage<InsOrderPlanVO> selectInsOrderPlanList(Page page, InsOrderPlanDTO insOrderPlanDTO) { |
| | |
| | | |
| | | // 添加设备记录 |
| | | threadPoolTaskExecutor.execute(() -> { |
| | | InsOrder order = insOrderMapper.selectById(insSample.getInsOrderId()); |
| | | User user = userMapper.selectById(userId); |
| | | // 查询设备使用记录查询该订单的使用记录 |
| | | List<InsOrderDeviceRecordDto> deviceRecordDtoList = insOrderDeviceRecordMapper.selectDeviceNumber(insSample.getInsOrderId()); |
| | | Set<String> recordCodeset = deviceRecordDtoList.stream().map(InsOrderDeviceRecordDto::getManagementNumber).collect(Collectors.toSet()); |
| | | // 添加设备使用记录 |
| | | addDeviceRecord(insSample, userId); |
| | | }); |
| | | } |
| | | |
| | | // 获取订单设备编号 |
| | | List<InsProductResult> resultList = insProductResultMapper.selectResultByOrderId(insSample.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); |
| | | } |
| | | private synchronized void addDeviceRecord(InsSample insSample, Integer userId) { |
| | | InsOrder order = insOrderMapper.selectById(insSample.getInsOrderId()); |
| | | User user = userMapper.selectById(userId); |
| | | // 查询设备使用记录查询该订单的使用记录 |
| | | List<InsOrderDeviceRecordDto> deviceRecordDtoList = insOrderDeviceRecordMapper.selectDeviceNumber(insSample.getInsOrderId()); |
| | | Set<String> recordCodeset = deviceRecordDtoList.stream().map(InsOrderDeviceRecordDto::getManagementNumber).collect(Collectors.toSet()); |
| | | |
| | | // 获取订单设备编号 |
| | | List<InsProductResult> resultList = insProductResultMapper.selectResultByOrderId(insSample.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 = insOrderDeviceRecordMapper.selectDeviceIdsByNumbers(orderDeviceNumbers); |
| | | List<InsOrderDeviceRecord> collect = orderDeviceIds.stream().map(deviceId -> { |
| | | InsOrderDeviceRecord insOrderDeviceRecord = new InsOrderDeviceRecord(); |
| | | insOrderDeviceRecord.setInsOrderId(insSample.getInsOrderId()); |
| | | insOrderDeviceRecord.setDeviceId(deviceId); |
| | | insOrderDeviceRecord.setSampleCode(order.getEntrustCode()); |
| | | insOrderDeviceRecord.setUseBefore(1); |
| | | insOrderDeviceRecord.setUseAfter(1); |
| | | insOrderDeviceRecord.setUsePerson(user.getName()); |
| | | insOrderDeviceRecord.setUsePersonId(user.getId()); |
| | | return insOrderDeviceRecord; |
| | | }).collect(Collectors.toList()); |
| | | } |
| | | // 1.判断是否有没有添加的使用记录 |
| | | Set<String> orderDeviceNumbers = getDeviceDifference(deviceCodeSet, recordCodeset); |
| | | // 添加使用记录, 根据编号查询设备id |
| | | if (CollectionUtils.isNotEmpty(orderDeviceNumbers)) { |
| | | List<Integer> orderDeviceIds = insOrderDeviceRecordMapper.selectDeviceIdsByNumbers(orderDeviceNumbers); |
| | | List<InsOrderDeviceRecord> collect = orderDeviceIds.stream().map(deviceId -> { |
| | | InsOrderDeviceRecord insOrderDeviceRecord = new InsOrderDeviceRecord(); |
| | | insOrderDeviceRecord.setInsOrderId(insSample.getInsOrderId()); |
| | | insOrderDeviceRecord.setDeviceId(deviceId); |
| | | insOrderDeviceRecord.setSampleCode(order.getEntrustCode()); |
| | | insOrderDeviceRecord.setUseBefore(1); |
| | | insOrderDeviceRecord.setUseAfter(1); |
| | | insOrderDeviceRecord.setUsePerson(user.getName()); |
| | | insOrderDeviceRecord.setUsePersonId(user.getId()); |
| | | return insOrderDeviceRecord; |
| | | }).collect(Collectors.toList()); |
| | | |
| | | insOrderDeviceRecordService.saveBatch(collect); |
| | | insOrderDeviceRecordService.saveBatch(collect); |
| | | |
| | | } |
| | | } |
| | | |
| | | // 2.判断是否取消了设备使用 |
| | | Set<String> repoprNumbers = getDeviceDifference(recordCodeset, deviceCodeSet); |
| | | if (CollectionUtils.isNotEmpty(repoprNumbers)) { |
| | | List<Integer> reportDeviceIds = insOrderDeviceRecordMapper.selectDeviceIdsByNumbers(repoprNumbers); |
| | | insOrderDeviceRecordMapper.delete(Wrappers.<InsOrderDeviceRecord>lambdaQuery() |
| | | .in(InsOrderDeviceRecord::getDeviceId, reportDeviceIds) |
| | | .eq(InsOrderDeviceRecord::getInsOrderId, insSample.getInsOrderId())); |
| | | } |
| | | }); |
| | | // 2.判断是否取消了设备使用 |
| | | Set<String> repoprNumbers = getDeviceDifference(recordCodeset, deviceCodeSet); |
| | | if (CollectionUtils.isNotEmpty(repoprNumbers)) { |
| | | List<Integer> reportDeviceIds = insOrderDeviceRecordMapper.selectDeviceIdsByNumbers(repoprNumbers); |
| | | insOrderDeviceRecordMapper.delete(Wrappers.<InsOrderDeviceRecord>lambdaQuery() |
| | | .in(InsOrderDeviceRecord::getDeviceId, reportDeviceIds) |
| | | .eq(InsOrderDeviceRecord::getInsOrderId, insSample.getInsOrderId())); |
| | | } |
| | | } |
| | | |
| | | private static Set<String> getDeviceDifference(Set<String> number1, Set<String> number2) { |
| | |
| | | } |
| | | |
| | | /** |
| | | * todo: 清除没有使用的检验项 |
| | | * todo: 原始记录模板清除没有使用的检验项(暂时有bug无法使用) |
| | | * @param sheet |
| | | * @param itemNameList |
| | | */ |
| | |
| | | |
| | | // 16 判断当前样品是否为原材料, 原材料需要进行数据分析, 判断之前10条数据同一个供应商, 同一个检验项的偏差是否超过10% |
| | | // 查询ifs信息获取获取前10个供应商一样的, 检验项一样信息 |
| | | // threadPoolTaskExecutor.execute(() -> { |
| | | // |
| | | // for (InsProduct insProduct : productList) { |
| | | // // todo: 暂时判断是否是老化 |
| | | // if (insProduct.getInspectionItem().contains("老化")) { |
| | | // List<InsProductAnalysisDto> insProductAnalysisDtoList = insProductMapper.selectAnalysis(insProduct, ifsInventoryQuantity.getSupplierName()); |
| | | // |
| | | // // 判断当前检测项是否偏差超过10% |
| | | // List<String> laseValueList = insProductAnalysisDtoList.stream().map(InsProductAnalysisDto::getLastValue) |
| | | // .collect(Collectors.toList()); |
| | | // |
| | | // |
| | | // |
| | | // |
| | | // } |
| | | // } |
| | | // }); |
| | | threadPoolTaskExecutor.execute(() -> { |
| | | // 添加分析数据 |
| | | addAnalysis(productList, ifsInventoryQuantity, order); |
| | | }); |
| | | |
| | | |
| | | } else { |
| | |
| | | } |
| | | |
| | | /** |
| | | * *****添加分析数据****** |
| | | * @param productList |
| | | * @param ifsInventoryQuantity |
| | | * @param order |
| | | */ |
| | | private void addAnalysis(List<InsProduct> productList, IfsInventoryQuantity ifsInventoryQuantity, InsOrder order) { |
| | | for (InsProduct insProduct : productList) { |
| | | // todo: 暂时判断是否是老化 |
| | | if (insProduct.getInspectionItem().contains("老化") && insProduct.getInsResult().equals(1)) { |
| | | List<InsProductDeviationWarningDetail> insProductAnalysisDtoList = insProductMapper.selectAnalysis(insProduct, ifsInventoryQuantity.getSupplierName()); |
| | | |
| | | if (insProductAnalysisDtoList.size() < 10) { |
| | | continue; |
| | | } |
| | | |
| | | // 判断当前检测项是否偏差超过10% |
| | | List<String> laseValueList = insProductAnalysisDtoList.stream().map(InsProductDeviationWarningDetail::getTestValue) |
| | | .collect(Collectors.toList()); |
| | | |
| | | double deviation = isDeviationOverTenPercent(laseValueList, insProduct.getLastValue()); |
| | | // 判断偏差是否大于10 |
| | | if (deviation > 10) { |
| | | // 判断之前是否添加过, 添加过不需要添加 |
| | | long count = insProductDeviationWarningService.count(Wrappers.<InsProductDeviationWarning>lambdaQuery() |
| | | .eq(InsProductDeviationWarning::getInsProductId, insProduct.getId())); |
| | | if (count == 0L) { |
| | | // 发送通知, 并且添加数据 |
| | | // 添加主表信息 |
| | | InsProductDeviationWarning deviationWarning = new InsProductDeviationWarning(); |
| | | deviationWarning.setInsOrderId(order.getId()); |
| | | deviationWarning.setInsSampleId(insProduct.getInsSampleId()); |
| | | deviationWarning.setInsProductId(insProduct.getId()); |
| | | deviationWarning.setEntrustCode(order.getEntrustCode()); |
| | | deviationWarning.setSampleCode(insProduct.getSampleCode()); |
| | | deviationWarning.setSupplierName(ifsInventoryQuantity.getSupplierName()); |
| | | deviationWarning.setDeviationValue(Double.toString(deviation)); |
| | | deviationWarning.setDetectionTime(insProduct.getUpdateTime()); |
| | | insProductDeviationWarningService.save(deviationWarning); |
| | | |
| | | // 添加详情数据 |
| | | InsProductDeviationWarningDetail deviationWarningDetail = new InsProductDeviationWarningDetail(); |
| | | deviationWarningDetail.setInsOrderId(order.getId()); |
| | | deviationWarningDetail.setInsSampleId(insProduct.getInsSampleId()); |
| | | deviationWarningDetail.setInsProductId(insProduct.getId()); |
| | | deviationWarningDetail.setEntrustCode(order.getEntrustCode()); |
| | | deviationWarningDetail.setSampleCode(insProduct.getSampleCode()); |
| | | deviationWarningDetail.setSupplierName(ifsInventoryQuantity.getSupplierName()); |
| | | deviationWarningDetail.setTestValue(insProduct.getLastValue()); |
| | | deviationWarningDetail.setIsIssue(1); |
| | | |
| | | insProductAnalysisDtoList.add(deviationWarningDetail); |
| | | |
| | | // 添加id |
| | | for (InsProductDeviationWarningDetail warningDetail : insProductAnalysisDtoList) { |
| | | warningDetail.setDeviationWarningId(deviationWarning.getDeviationWarningId()); |
| | | } |
| | | |
| | | insProductDeviationWarningDetailService.saveBatch(insProductAnalysisDtoList); |
| | | |
| | | |
| | | // String message = ""; |
| | | // message += "检验任务复核通知"; |
| | | // message += "\n提交人: " + userName; |
| | | // message += "\n委托编号: " + order.getEntrustCode(); |
| | | // message += "\n样品名称: " + insSample.getModel(); |
| | | // message += "\n规格型号: " + order.getPartDetail(); |
| | | // if (ifsInventoryQuantity != null) { |
| | | // message += "\n批次号: " + ifsInventoryQuantity.getUpdateBatchNo(); |
| | | // } |
| | | // //发送企业微信消息通知 提交复核 |
| | | // try { |
| | | // WxCpUtils.inform(sendUserAccount, message, null); |
| | | // } catch (Exception e) { |
| | | // throw new RuntimeException(e); |
| | | // } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * *****计算偏差**** |
| | | * @param data |
| | | * @param targetStr |
| | |
| | | double target = Double.parseDouble(targetStr); |
| | | double deviationPercent = Math.abs(target - average) / average * 100; |
| | | |
| | | return deviationPercent; |
| | | // 保留两位小数 |
| | | DecimalFormat df = new DecimalFormat("#.00"); |
| | | String formatted = df.format(deviationPercent); |
| | | return Double.parseDouble(formatted); |
| | | } |
| | | |
| | | /** |
| | |
| | | |
| | | ConfigureBuilder builder = Configure.builder(); |
| | | builder.useSpringEL(true); |
| | | // 获取当前时间 |
| | | LocalDate currentDate = LocalDate.now(); |
| | | DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); |
| | | String formattedDate = currentDate.format(formatter); |
| | | |
| | | InputStream inputStream = this.getClass().getResourceAsStream("/static/small-report-template.docx"); |
| | | XWPFTemplate template = XWPFTemplate.compile(inputStream, builder.build()).render( |