| | |
| | | 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; |
| | | |
| | | /** |
| | | * 查询体检采样管理列表 |
| | |
| | | LambdaQueryWrapper<TjSampling> wrapper = new LambdaQueryWrapper<>(); |
| | | wrapper.eq(TjSampling::getIsSignFor, isSignFor); |
| | | if (null != tjNum && StrUtil.isNotBlank(tjNum)) |
| | | wrapper.eq(TjSampling::getTjNum, tjNum); |
| | | wrapper.like(TjSampling::getTjNum, tjNum); |
| | | if (null != name && StrUtil.isNotBlank(name)) |
| | | wrapper.eq(TjSampling::getCusName, name); |
| | | wrapper.like(TjSampling::getCusName, name); |
| | | if (null != beginTime && null != endTime && StrUtil.isNotBlank(beginTime) && StrUtil.isNotBlank(endTime)) |
| | | wrapper.between(TjSampling::getApplicationTime, beginTime, endTime); |
| | | wrapper.groupBy(TjSampling::getCusId); |
| | | wrapper.orderByDesc(TjSampling::getCreateTime); |
| | | // wrapper.last("LIMIT " + (pageNum - 1) * pageSize + "," + pageSize); |
| | | Page<TjSampling> page = tjSamplingService.page(samplingPage, wrapper); |
| | | List<TjSampling> list = page.getRecords(); |
| | | ArrayList<TjCustomer> tjCustomers = new ArrayList<>(); |
| | | for (TjSampling tjSampling : list) { |
| | | TjCustomer customer = customerService.getById(tjSampling.getCusId()); |
| | | customer.setCusName(customer.getCusName()); |
| | | customer.setCusPhone(MatchUtils.hidePhoneNum(customer.getCusPhone())); |
| | | customer.setCusIdcard(MatchUtils.hideIdCardNum(customer.getCusIdcard())); |
| | | customer.setTjNumber(tjSampling.getTjNum()); |
| | | customer.setApplicationTime(tjSampling.getApplicationTime()); |
| | | tjCustomers.add(customer); |
| | | if(null !=customer){ |
| | | customer.setCusName(customer.getCusName()); |
| | | customer.setCusPhone(MatchUtils.hidePhoneNum(customer.getCusPhone())); |
| | | customer.setCusIdcard(MatchUtils.hideIdCardNum(customer.getCusIdcard())); |
| | | customer.setTjNumber(tjSampling.getTjNum()); |
| | | customer.setApplicationTime(tjSampling.getApplicationTime()); |
| | | tjCustomers.add(customer); |
| | | } |
| | | } |
| | | HashMap<String, Object> hashMap = new HashMap<>(); |
| | | hashMap.put("list", tjCustomers); |
| | |
| | | /** |
| | | * 根据客户获取采样列表 |
| | | * |
| | | * @param cusId |
| | | * @param tjNumber |
| | | * @return |
| | | */ |
| | | @GetMapping("/getCusCyList") |
| | | @ApiOperation(value = "根据客户获取采样列表") |
| | | public AjaxResult getCusCyList(@RequestParam @ApiParam(value = "客户id") String cusId, |
| | | public AjaxResult getCusCyList(@RequestParam @ApiParam(value = "客户id") String tjNumber, |
| | | @RequestParam(defaultValue = "1") @ApiParam(value = "0是1否") Integer isSignFor) { |
| | | if (cusId == null || StrUtil.isBlank(cusId)) |
| | | if (tjNumber == null || StrUtil.isBlank(tjNumber)) |
| | | return AjaxResult.error("参数错误,未传参数"); |
| | | LambdaQueryWrapper<TjSampling> wrapper = new LambdaQueryWrapper<>(); |
| | | wrapper.eq(TjSampling::getCusId, cusId); |
| | | wrapper.eq(TjSampling::getTjNum, tjNumber); |
| | | wrapper.eq(TjSampling::getIsSignFor,isSignFor); |
| | | wrapper.and(i -> i.isNull(TjSampling::getParentId).or().eq(TjSampling::getIsMerge,1)); |
| | | // wrapper.eq(TjSampling::getIsPay,1); |
| | | // if (isSignFor == 1) |
| | | // wrapper.eq(TjSampling::getIsApply,0); |
| | | wrapper.orderByDesc(TjSampling::getIsMerge); |
| | | List<TjSampling> list = tjSamplingService.list(wrapper); |
| | | if (list.isEmpty()){ |
| | | logger.info("cusId参数传的是:"+cusId); |
| | | logger.info("jtNum ->{}",tjNumber); |
| | | // return AjaxResult.error("未查询到数据,人员未缴费或没有未采样项目"); |
| | | return AjaxResult.error("参数错误,未查询到数据"); |
| | | } |
| | | // for (TjSampling sampling : list) { |
| | | // TjCustomer customer = customerService.getById(sampling.getCusId()); |
| | | // TjOrder order = orderService.getOrderByTjNum(sampling.getTjNum()); |
| | | // 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)); |
| | | } |
| | | } |
| | | String lis_tmh_prefix = configService.selectConfigByKey("make_lis_tmh_prefix"); |
| | | Map<String, List<TjSampling>> map = list.stream().filter(i->StrUtil.isNotBlank(i.getSpecimenTypeCode())).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()),lis_tmh_prefix); |
| | | } |
| | | } |
| | | wrapper = new LambdaQueryWrapper<>(); |
| | | wrapper.eq(TjSampling::getTjNum, tjNumber); |
| | | wrapper.eq(TjSampling::getIsSignFor,isSignFor); |
| | | wrapper.and(i -> i.isNull(TjSampling::getParentId).or().eq(TjSampling::getIsMerge,1)); |
| | | // wrapper.orderByDesc(TjSampling::getIsMerge); |
| | | wrapper.orderByAsc(TjSampling::getSpecimenTypeCode,TjSampling::getIsMerge); |
| | | list = tjSamplingService.list(wrapper); |
| | | for (TjSampling sampling : list) { |
| | | TjCustomer customer = customerService.getById(sampling.getCusId()); |
| | | TjOrder order = orderService.getOrderByTjNum(sampling.getTjNum()); |
| | |
| | | |
| | | @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("请选择你要合并的项目!!!"); |
| | | String lis_tmh_prefix = configService.selectConfigByKey("make_lis_tmh_prefix"); |
| | | return tjSamplingService.mergeCaiYangTran(ids,lis_tmh_prefix); |
| | | } |
| | | |
| | | |
| | |
| | | @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); |
| | | } |
| | | } |