| | |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Component; |
| | | import org.springframework.transaction.NoTransactionException; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.transaction.interceptor.TransactionAspectSupport; |
| | | |
| | |
| | | String mergeRequest = configService.selectConfigByKey("use_lis_pacs_is_auto_merge_request"); |
| | | String lis_tmh_prefix = configService.selectConfigByKey("make_lis_tmh_prefix"); |
| | | if (mergeRequest.equals("Y")){ |
| | | LambdaQueryWrapper<TjSampling> wrapper = new LambdaQueryWrapper<>(); |
| | | wrapper.eq(TjSampling::getTjNum,tjOrder.getTjNumber()); |
| | | List<TjSampling> list = tjSamplingService.list(wrapper); |
| | | log.info("采样数据 ->{}",JSONUtil.toJsonStr(list)); |
| | | if (!list.isEmpty()) { |
| | | Map<String, List<TjSampling>> listMap = list.stream().collect(Collectors.groupingBy(TjSampling::getSpecimenTypeCode)); |
| | | log.info("分组后 ->{}",JSONUtil.toJsonStr(listMap)); |
| | | ArrayList<String> ids = new ArrayList<>(); |
| | | for (Map.Entry<String, List<TjSampling>> entry : listMap.entrySet()) { |
| | | log.info("key ->{},val ->{}",entry.getKey(),entry.getValue()); |
| | | // Lis标本代码 |
| | | String specimenTypeCode = entry.getKey(); |
| | | List<TjSampling> samplings = entry.getValue(); |
| | | if (samplings.size() >= 2) { |
| | | // 进行合并 |
| | | List<String> stringList = samplings.stream().map(TjSampling::getId).collect(Collectors.toList()); |
| | | // log.info("提取id ->{}",stringList); |
| | | for (int i = 0; i < stringList.size(); i++) { |
| | | String s = stringList.get(i); |
| | | if (tjSamplingService.isMergeItem(s) != 0) { |
| | | stringList.remove(s); |
| | | ids.add(s); |
| | | try { |
| | | LambdaQueryWrapper<TjSampling> wrapper = new LambdaQueryWrapper<>(); |
| | | wrapper.eq(TjSampling::getTjNum,tjOrder.getTjNumber()); |
| | | List<TjSampling> list = tjSamplingService.list(wrapper); |
| | | log.info("采样数据 ->{}",JSONUtil.toJsonStr(list)); |
| | | if (!list.isEmpty()) { |
| | | Map<String, List<TjSampling>> listMap = list.stream().collect(Collectors.groupingBy(TjSampling::getSpecimenTypeCode)); |
| | | log.info("分组后 ->{}",JSONUtil.toJsonStr(listMap)); |
| | | ArrayList<String> ids = new ArrayList<>(); |
| | | for (Map.Entry<String, List<TjSampling>> entry : listMap.entrySet()) { |
| | | log.info("key ->{},val ->{}",entry.getKey(),entry.getValue()); |
| | | // Lis标本代码 |
| | | String specimenTypeCode = entry.getKey(); |
| | | List<TjSampling> samplings = entry.getValue(); |
| | | if (samplings.size() >= 2) { |
| | | // 进行合并 |
| | | List<String> stringList = samplings.stream().map(TjSampling::getId).collect(Collectors.toList()); |
| | | // log.info("提取id ->{}",stringList); |
| | | for (int i = 0; i < stringList.size(); i++) { |
| | | String s = stringList.get(i); |
| | | if (tjSamplingService.isMergeItem(s) != 0) { |
| | | stringList.remove(s); |
| | | ids.add(s); |
| | | } |
| | | } |
| | | if (stringList.size() > 1) { |
| | | String id = tjSamplingService.mergeCaiYangApi(stringList,lis_tmh_prefix); |
| | | ids.add(id); |
| | | }else { |
| | | ids.add(stringList.get(0)); |
| | | } |
| | | } else { |
| | | ids.add(samplings.get(0).getId()); |
| | | } |
| | | if (stringList.size() > 1) { |
| | | String id = tjSamplingService.mergeCaiYangApi(stringList,lis_tmh_prefix); |
| | | ids.add(id); |
| | | }else { |
| | | ids.add(stringList.get(0)); |
| | | } |
| | | } else { |
| | | ids.add(samplings.get(0).getId()); |
| | | } |
| | | Boolean confirmed = samplingService.confirmSamplingApi(ids, "Y", "N"); |
| | | if (!confirmed) { |
| | | TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); |
| | | return AjaxResult.error("处理失败"); |
| | | } |
| | | } |
| | | Boolean confirmed = samplingService.confirmSamplingApi(ids, "Y", "N"); |
| | | if (!confirmed) { |
| | | TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); |
| | | return AjaxResult.error("处理失败"); |
| | | } |
| | | } catch (NoTransactionException e) { |
| | | // throw new RuntimeException(e); |
| | | log.error(e.getMessage().toString()); |
| | | } |
| | | } |
| | | |