| | |
| | | |
| | | private static final int DETECTION_REPORT = 0; |
| | | private static final int INSPECTION_REPORT = 1; |
| | | private static final String DIRECT_TEMPLATE_LABORATORY = "新聚"; |
| | | |
| | | @Resource |
| | | private InsSampleMapper insSampleMapper; |
| | |
| | | |
| | | @Override |
| | | public Map<String, Object> doInsOrder(Integer id, String laboratory) { |
| | | ensureDirectTemplateOrderState(id); |
| | | InsOrder order = insOrderMapper.selectById(id); |
| | | Map<String, Object> map = insOrderService.getInsOrderAndSample(id, laboratory); |
| | | List<SampleProductDto> list = JSON.parseArray(JSON.toJSONString(map.get("sampleProduct")), SampleProductDto.class); |
| | |
| | | Map<String, Object> map = new HashMap<>(); |
| | | List<String> collect = new ArrayList<>(); |
| | | if (isDirectTemplateOrder(orderId)) { |
| | | map.put("errorMsg", Collections.emptyList()); |
| | | List<InsOrderStandardTemplate> snapshots = insOrderStandardTemplateService.list( |
| | | Wrappers.<InsOrderStandardTemplate>lambdaQuery() |
| | | .eq(InsOrderStandardTemplate::getInsOrderId, orderId) |
| | | .orderByAsc(InsOrderStandardTemplate::getSort, |
| | | InsOrderStandardTemplate::getId)); |
| | | for (InsOrderStandardTemplate snapshot : snapshots) { |
| | | String templateName = StringUtils.defaultIfBlank(snapshot.getName(), |
| | | "模板ID " + snapshot.getTemplateId()); |
| | | if (snapshot.getDetectionTime() == null) { |
| | | collect.add("请选择“" + templateName + "”的检测时间"); |
| | | } |
| | | if (StringUtils.isBlank(snapshot.getDetectionPlace())) { |
| | | collect.add("请填写“" + templateName + "”的检测地点"); |
| | | } |
| | | } |
| | | map.put("errorMsg", collect); |
| | | map.put("missingExportItems", getMissingTemplateExportValues(orderId)); |
| | | map.put("unInsOrderCount", 0L); |
| | | return map; |
| | |
| | | if (snapshot == null) { |
| | | throw new ErrorException("未找到当前订单的原始记录模板快照"); |
| | | } |
| | | ensureDirectTemplateOrderState(dto.getOrderId()); |
| | | List<InsProduct> products = insProductMapper.selectList(Wrappers.<InsProduct>lambdaQuery() |
| | | .eq(InsProduct::getInsSampleId, dto.getSampleId()) |
| | | .eq(InsProduct::getTemplateId, dto.getTemplateId()) |
| | |
| | | |
| | | JSONObject values = JSON.parseObject(JSON.toJSONString(dto.getValues() == null |
| | | ? Collections.emptyMap() : dto.getValues())); |
| | | List<String> exportValueCoordinates = getExportValueCoordinates(snapshot.getThing()).values().stream() |
| | | // 检验期间页面展示的是标准维护中的最新模板,保存校验必须使用同一份模板, |
| | | // 避免模板新增“导出值”批注后仍按下单时的旧快照误报未配置。 |
| | | String currentTemplateThing = getCurrentTemplateThing(snapshot); |
| | | List<String> exportValueCoordinates = getExportValueCoordinates(currentTemplateThing).values().stream() |
| | | .flatMap(Collection::stream) |
| | | .distinct() |
| | | .collect(Collectors.toList()); |
| | |
| | | .map(InsProduct::getSonLaboratory) |
| | | .filter(StringUtils::isNotBlank) |
| | | .collect(Collectors.toSet()); |
| | | if (laboratories.isEmpty() && isDirectTemplateOrder(orderId)) { |
| | | laboratories.add(DIRECT_TEMPLATE_LABORATORY); |
| | | } |
| | | if (!laboratories.isEmpty()) { |
| | | insOrderStateMapper.update(null, Wrappers.<InsOrderState>lambdaUpdate() |
| | | .eq(InsOrderState::getInsOrderId, orderId) |
| | |
| | | } |
| | | |
| | | /** |
| | | * 检验保存、提交校验读取标准维护中的实时模板;模板已被删除或内容为空时才回退订单快照。 |
| | | * 检验完成后的展示和报告仍由订单快照负责,不会随标准模板后续修改而变化。 |
| | | */ |
| | | private String getCurrentTemplateThing(InsOrderStandardTemplate snapshot) { |
| | | if (snapshot != null && snapshot.getTemplateId() != null) { |
| | | StandardTemplate currentTemplate = standardTemplateService.getById(snapshot.getTemplateId()); |
| | | if (currentTemplate != null && StrUtil.isNotBlank(currentTemplate.getThing())) { |
| | | return currentTemplate.getThing(); |
| | | } |
| | | } |
| | | return snapshot == null ? null : snapshot.getThing(); |
| | | } |
| | | |
| | | /** |
| | | * 直绑模板订单只校验模板中标记为“导出值”的单元格,不使用检验项状态或 last_value 判定。 |
| | | */ |
| | | private List<String> getMissingTemplateExportValues(Integer orderId) { |
| | |
| | | } |
| | | for (InsOrderStandardTemplate snapshot : snapshots) { |
| | | Integer templateId = snapshot.getTemplateId(); |
| | | List<String> coordinates = getExportValueCoordinates(snapshot.getThing()).values().stream() |
| | | List<String> coordinates = getExportValueCoordinates(getCurrentTemplateThing(snapshot)).values().stream() |
| | | .flatMap(Collection::stream) |
| | | .distinct() |
| | | .collect(Collectors.toList()); |
| | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public int submitPlan(Integer orderId, String laboratory, Integer verifyUser, String entrustCode, Boolean registerInsResults) { |
| | | ensureDirectTemplateOrderState(orderId); |
| | | int reportType = DETECTION_REPORT; |
| | | InsOrder order = insOrderMapper.selectOne(Wrappers.<InsOrder>lambdaQuery() |
| | | .eq(InsOrder::getId, orderId) |
| | |
| | | if (orderId == null || laboratory == null || type == null) { |
| | | throw new ErrorException("复核参数不完整"); |
| | | } |
| | | ensureDirectTemplateOrderState(orderId); |
| | | InsOrderState currentState = insOrderStateMapper.selectOne(Wrappers.<InsOrderState>lambdaQuery() |
| | | .eq(InsOrderState::getInsOrderId, orderId) |
| | | .eq(InsOrderState::getLaboratory, laboratory) |
| | |
| | | return insProductMapper.selectCount(Wrappers.<InsProduct>lambdaQuery() |
| | | .in(InsProduct::getInsSampleId, samples.stream().map(InsSample::getId).collect(Collectors.toList())) |
| | | .isNotNull(InsProduct::getTemplateRowIndex)) > 0; |
| | | } |
| | | |
| | | /** |
| | | * 兼容修复上线前已经下发、但因没有 ins_product 而缺少任务状态的直绑模板订单。 |
| | | */ |
| | | private void ensureDirectTemplateOrderState(Integer orderId) { |
| | | if (!isDirectTemplateOrder(orderId)) { |
| | | return; |
| | | } |
| | | Long stateCount = insOrderStateMapper.selectCount(Wrappers.<InsOrderState>lambdaQuery() |
| | | .eq(InsOrderState::getInsOrderId, orderId) |
| | | .eq(InsOrderState::getLaboratory, DIRECT_TEMPLATE_LABORATORY)); |
| | | if (stateCount > 0) { |
| | | return; |
| | | } |
| | | InsOrderState state = new InsOrderState(); |
| | | state.setInsOrderId(orderId); |
| | | state.setLaboratory(DIRECT_TEMPLATE_LABORATORY); |
| | | state.setInsState(0); |
| | | insOrderStateMapper.insert(state); |
| | | } |
| | | |
| | | private Integer resolveInspectionUserId(Integer orderId, String laboratory) { |
| | |
| | | // 来样方式 |
| | | String formType = iSysDictTypeService.selectLabelByDict(DictDataConstants.FORM_TYPE, insOrder.getFormType()); |
| | | |
| | | // 样品状态 |
| | | String sampleStatus = iSysDictTypeService.selectLabelByDict(DictDataConstants.SAMPLE_STATUS_LIST, insOrder.getSampleStatus()); |
| | | ; |
| | | // 样品外观优先展示字典名称;历史数据或直接保存文本时,回退展示订单原值。 |
| | | String sampleStatus = defaultReportText( |
| | | iSysDictTypeService.selectLabelByDict( |
| | | DictDataConstants.SAMPLE_STATUS_LIST, insOrder.getSampleStatus()), |
| | | insOrder.getSampleStatus()); |
| | | |
| | | // 公司信息 |
| | | Custom custom = customMapper.selectById(insOrder.getCompanyId()); |
| | |
| | | |
| | | Map<String, String> row = new LinkedHashMap<>(); |
| | | row.put("seq", String.valueOf(sequence++)); |
| | | row.put("itemName", defaultReportText(itemName, |
| | | defaultReportText(snapshot.getName(), "模板ID " + snapshot.getTemplateId()))); |
| | | String reportItemName = defaultReportText(itemName, |
| | | defaultReportText(snapshot.getName(), "模板ID " + snapshot.getTemplateId())); |
| | | row.put("itemName", formatExportItemName(reportItemName)); |
| | | row.put("unit", defaultReportText(unit, "/")); |
| | | row.put("result", result); |
| | | rows.add(row); |
| | |
| | | } |
| | | } |
| | | if (numbers.isEmpty()) { |
| | | return StringUtils.isBlank(fallback) ? "" : fallback + unit; |
| | | // “/”表示模板明确填写了不适用,不能再按空值处理或追加单位。 |
| | | return candidates.stream() |
| | | .filter(StringUtils::isNotBlank) |
| | | .map(String::trim) |
| | | .distinct() |
| | | .collect(Collectors.joining("~")); |
| | | } |
| | | BigDecimal minimum = Collections.min(numbers); |
| | | BigDecimal maximum = Collections.max(numbers); |
| | |
| | | return minimumText + "~" + maximum.stripTrailingZeros().toPlainString() + unit; |
| | | } |
| | | |
| | | /** 报告项目名称不展示模板计算过程中的“平均值”字样及其后的分隔逗号。 */ |
| | | private static String formatExportItemName(String itemName) { |
| | | if (StringUtils.isBlank(itemName)) { |
| | | return itemName; |
| | | } |
| | | return itemName.replaceAll("平均值\\s*[,,]?\\s*", ""); |
| | | } |
| | | |
| | | private static String getMapText(Map<String, String> map, String... keys) { |
| | | if (map == null) { |
| | | return null; |