| | |
| | | package com.ltkj.web.controller.system; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | import javax.annotation.Resource; |
| | | import javax.servlet.ServletSecurityElement; |
| | |
| | | @Autowired |
| | | private LisApiMethod lisApiMethod; |
| | | @Autowired |
| | | private IdUtils idUtils; |
| | | @Autowired |
| | | private ISysConfigService configService; |
| | | @Autowired |
| | | private SamplingServiceApi samplingService; |
| | | |
| | | /** |
| | | * 查询体检采样管理列表 |
| | |
| | | if(null !=order)sampling.setCardId(order.getCardId()); |
| | | sampling.setCustomer(customer); |
| | | } |
| | | |
| | | if (list.size() >= 2) { |
| | | // 进行合并 |
| | | List<String> stringList = list.stream().map(TjSampling::getId).collect(Collectors.toList()); |
| | | log.info("提取id ->{}",stringList); |
| | | for (String s : stringList) { |
| | | if (tjSamplingService.isMergeItem(s) != 0) { |
| | | list.removeIf(item -> Objects.equals(item.getId(), s)); |
| | | } |
| | | } |
| | | Map<String, List<TjSampling>> map = list.stream().collect(Collectors.groupingBy(item -> item.getSpecimenTypeCode())); |
| | | for (Map.Entry<String, List<TjSampling>> entry : map.entrySet()) { |
| | | List<TjSampling> entryValue = entry.getValue(); |
| | | tjSamplingService.mergeCaiYangTran(entryValue.stream().map(TjSampling::getId).collect(Collectors.toList())); |
| | | } |
| | | } |
| | | wrapper = new LambdaQueryWrapper<>(); |
| | | wrapper.eq(TjSampling::getCusId, cusId); |
| | | wrapper.eq(TjSampling::getIsSignFor,isSignFor); |
| | | wrapper.and(i -> i.isNull(TjSampling::getParentId).or().eq(TjSampling::getIsMerge,1)); |
| | | wrapper.orderByDesc(TjSampling::getIsMerge); |
| | | list = tjSamplingService.list(wrapper); |
| | | return AjaxResult.success(list); |
| | | } |
| | | |
| | | @PostMapping("/mergeCaiYang") |
| | | @ApiOperation(value = "采样登记合并项目接口") |
| | | @Transactional |
| | | public AjaxResult mergeCaiYang(@RequestBody List<String> ids) { |
| | | if (null != ids && !ids.isEmpty()) { |
| | | if(ids.size()==1)return AjaxResult.error("请选择至少两条项目进行合并!"); |
| | | int i = tjSamplingService.panduanshifoukeyihebing(ids); |
| | | if (i > 1) { |
| | | return AjaxResult.error("标本类型不一致,不可合并"); |
| | | } |
| | | int pdsfczhbxm = tjSamplingService.pdsfczhbxm(ids); |
| | | if (pdsfczhbxm == ids.size()) return AjaxResult.error("多个合并项目不可再继续合并!"); |
| | | if (pdsfczhbxm > 1) return AjaxResult.error("最多允许选择一个合并过的项目!"); |
| | | // 查询出里面不可合并的化验项目 |
| | | String string = tjSamplingService.getBuKeHebingProName(ids); |
| | | if(null !=string){ |
| | | return AjaxResult.error(string+"这几个项目不可合并!"); |
| | | } |
| | | if (pdsfczhbxm == 0) { |
| | | TjSampling tjSampling = tjSamplingService.getById(ids.get(0)); |
| | | Map<String, Object> map = tjSamplingService.hebingCaiYangInFo(ids); |
| | | TjSampling sampling = new TjSampling(); |
| | | String proId = map.get("proId").toString(); |
| | | String proName = map.get("proName").toString(); |
| | | BeanUtil.copyProperties(tjSampling, sampling, new String[]{"id"}); |
| | | sampling.setProId(proId); |
| | | sampling.setProName(proName); |
| | | sampling.setIsMerge(1); |
| | | sampling.setJyxh(idUtils.generateLisID()); |
| | | if (tjSamplingService.save(sampling)) { |
| | | if (tjSamplingService.updateHeBingXm(ids, sampling.getId())) { |
| | | return AjaxResult.success("合并项目成功!"); |
| | | } |
| | | } |
| | | return AjaxResult.error("操作失败!"); |
| | | } else { |
| | | TjSampling tjSampling = tjSamplingService.getTjSamplingByHb(ids); |
| | | List<TjSampling> samplingList = tjSamplingService.getTjSamplingListByHb(ids); |
| | | if (null != tjSampling && null != samplingList && !samplingList.isEmpty()) { |
| | | List<String> stringList = samplingList.stream().map(TjSampling::getId).collect(Collectors.toList()); |
| | | Map<String, Object> map = tjSamplingService.hebingCaiYangInFo(stringList); |
| | | String proId = map.get("proId").toString(); |
| | | String proName = map.get("proName").toString(); |
| | | tjSampling.setProId(proId); |
| | | tjSampling.setProName(proName); |
| | | if (tjSamplingService.updateById(tjSampling)) { |
| | | if (tjSamplingService.updateHeBingXm(stringList, tjSampling.getParentId())) { |
| | | return AjaxResult.success("合并项目成功!"); |
| | | } |
| | | } |
| | | } |
| | | return AjaxResult.error("操作失败!"); |
| | | } |
| | | } |
| | | return AjaxResult.error("请选择你要合并的项目!!!"); |
| | | return tjSamplingService.mergeCaiYangTran(ids); |
| | | } |
| | | |
| | | |
| | |
| | | @ApiOperation(value = "确认采样接口") |
| | | @Transactional |
| | | public AjaxResult confirmSampling(@RequestBody List<String> ids) { |
| | | if (null == ids || ids.isEmpty()) { |
| | | return AjaxResult.error("请选择要确认项"); |
| | | } |
| | | List<TjSampling> tjSamplings = tjSamplingService.listByIds(ids); |
| | | if (tjSamplings.isEmpty()) |
| | | return AjaxResult.error("请选择要确认项"); |
| | | String errorMsg = ""; |
| | | for (TjSampling sampling : tjSamplings) { |
| | | if (sampling.getJyxmdm() == null) |
| | | errorMsg+=sampling.getProName()+"在lis系统未找到对应编码无法发出申请"; |
| | | sampling.setIsSignFor("0"); |
| | | // LambdaQueryWrapper<TjProject> wq = new LambdaQueryWrapper<>(); |
| | | // wq.eq(TjProject::getProParentId, sampling.getProId()); |
| | | // List<TjProject> projectList = projectService.list(wq); |
| | | // List<String> collect = new ArrayList<>(); |
| | | // for (TjProject project : projectList) { |
| | | // Long proId = project.getProId(); |
| | | // collect.add(String.valueOf(proId)); |
| | | // } |
| | | // LambdaQueryWrapper<TjSampling> wq1 = new LambdaQueryWrapper<>(); |
| | | // wq1.eq(TjSampling::getTjNum, sampling.getTjNum()); |
| | | // wq1.in(TjSampling::getProId, collect); |
| | | // List<TjSampling> samplingList = tjSamplingService.list(wq1); |
| | | // if (null != samplingList && samplingList.size() > 0) { |
| | | // for (TjSampling tjSampling : samplingList) { |
| | | // tjSampling.setIsSignFor("0"); |
| | | // tjSamplingService.updateById(tjSampling); |
| | | // } |
| | | // } |
| | | TjOrder tjOrder = orderService.getOrderByTjNum(sampling.getTjNum()); |
| | | if(null==tjOrder)return AjaxResult.error("体检记录不存在"); |
| | | TjCustomer tjCustomer = customerService.getById(tjOrder.getUserId()); |
| | | boolean updChild; |
| | | String config = configService.selectConfigByKey("sfkqdyhis"); |
| | | Boolean save; |
| | | if (null != config && config.equals("Y")) { |
| | | save = lisApiMethod.save(sampling, tjOrder, tjCustomer); |
| | | }else { |
| | | save = true; |
| | | } |
| | | if (save) { |
| | | if (sampling.getIsMerge() == 1) { |
| | | LambdaQueryWrapper<TjSampling> wrapper = new LambdaQueryWrapper<>(); |
| | | wrapper.eq(TjSampling::getParentId, sampling.getId()); |
| | | List<TjSampling> list = tjSamplingService.list(wrapper); |
| | | for (TjSampling tjSampling : list) { |
| | | tjSampling.setIsSignFor("0"); |
| | | } |
| | | updChild = tjSamplingService.updateBatchById(list); |
| | | } else { |
| | | updChild = true; |
| | | } |
| | | if (!tjSamplingService.updateById(sampling) && !updChild) { |
| | | // lisApiMethod.cancel(sampling.getJyxh(), tjOrder.getCardId(), PinyinUtil.getFirstLetter(tjCustomer.getCusName(), "")); |
| | | // TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); |
| | | return AjaxResult.error("操作失败请重试"); |
| | | } |
| | | } else { |
| | | return AjaxResult.error("操作失败请重试"); |
| | | } |
| | | } |
| | | if (StrUtil.isNotBlank(errorMsg)) return AjaxResult.error(errorMsg); |
| | | return AjaxResult.success("操作成功"); |
| | | String config = configService.selectConfigByKey("sfkqdyhis"); |
| | | String mergeRequest = configService.selectConfigByKey("use_lis_pacs_is_auto_merge_request"); |
| | | return samplingService.confirm(ids,config,mergeRequest); |
| | | } |
| | | } |