| | |
| | | package com.ltkj.web.controller.system; |
| | | |
| | | import cn.hutool.core.util.StrUtil; |
| | | import cn.hutool.json.JSONArray; |
| | | import cn.hutool.json.JSONObject; |
| | | import cn.hutool.json.JSONUtil; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; |
| | | import com.ltkj.common.core.domain.AjaxResult; |
| | | import com.ltkj.hosp.domain.TjCustomer; |
| | | import com.ltkj.hosp.domain.TjOrder; |
| | | import com.ltkj.hosp.domain.TjSampling; |
| | | import com.ltkj.hosp.domain.*; |
| | | import com.ltkj.hosp.mapper.TjProjectMapper; |
| | | import com.ltkj.hosp.service.ITbTransitionService; |
| | | import com.ltkj.hosp.service.ITjCustomerService; |
| | | import com.ltkj.hosp.service.ITjOrderService; |
| | | import com.ltkj.hosp.service.ITjSamplingService; |
| | | import com.ltkj.system.mapper.SysConfigMapper; |
| | | import com.ltkj.system.service.ISysConfigService; |
| | | import com.ltkj.web.controller.lis.LisApiMethod; |
| | | import com.ltkj.web.wxUtils.HttpClientUtils; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.util.Arrays; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.stream.Collectors; |
| | | |
| | | @Slf4j |
| | | @Service |
| | |
| | | private SysConfigMapper sysConfigMapper; |
| | | @Autowired |
| | | private ISysConfigService sysConfigService; |
| | | @Autowired |
| | | private TjProjectMapper tjProjectMapper; |
| | | @Autowired |
| | | private ITjCustomerService tjCustomerService; |
| | | @Autowired |
| | | private ITbTransitionService tbTransitionService; |
| | | |
| | | /** |
| | | * 确认采样接口 |
| | |
| | | } |
| | | |
| | | public AjaxResult confirm(List<String> ids,String config,String mergeRequest) { |
| | | |
| | | |
| | | |
| | | // sfkqdshitulianjie |
| | |
| | | TjCustomer tjCustomer = customerService.getById(tjOrder.getUserId()); |
| | | boolean updChild; |
| | | Boolean save; |
| | | String is_request_common_his_api = sysConfigService.selectConfigByKey("is_request_common_his_api"); |
| | | if (null != config && config.equals("Y") && !mergeRequest.equals("Y")) { |
| | | save = lisApiMethod.save(sampling, tjOrder, tjCustomer); |
| | | } else if (is_request_common_his_api.equals("Y")){ |
| | | // String apiUrl = sysConfigService.selectConfigByKey("common_api_url"); |
| | | // String hospbm = sysConfigService.selectConfigByKey("common_api_service_hospbm"); |
| | | // save = sendLis(sampling,tjOrder,apiUrl,hospbm); |
| | | save = true; |
| | | }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("1"); |
| | | } |
| | | 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("操作成功"); |
| | | } |
| | | |
| | | /** |
| | | * 采样管理 确认采码按钮调用 |
| | | * @param ids |
| | | * @param config |
| | | * @param mergeRequest |
| | | * @return |
| | | */ |
| | | public AjaxResult confirmApi(List<String> ids,String config,String mergeRequest) { |
| | | |
| | | |
| | | |
| | | // sfkqdshitulianjie |
| | | 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 (!sysConfigService.selectConfigByKey("sfkqdshitulianjie").toLowerCase().equals("y")) { |
| | | 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; |
| | | Boolean save; |
| | | // String is_request_common_his_api = sysConfigService.selectConfigByKey("is_request_common_his_api"); |
| | | // if (null != config && config.equals("Y") && !mergeRequest.equals("Y")) { |
| | | // save = lisApiMethod.save(sampling, tjOrder, tjCustomer); |
| | | // } else if (is_request_common_his_api.equals("Y")){ |
| | | //// String apiUrl = sysConfigService.selectConfigByKey("common_api_url"); |
| | | //// String hospbm = sysConfigService.selectConfigByKey("common_api_service_hospbm"); |
| | | //// save = sendLis(sampling,tjOrder,apiUrl,hospbm); |
| | | // save = true; |
| | | // }else { |
| | | // save = true; |
| | | // } |
| | | save = true; |
| | | if (save) { |
| | | if (sampling.getIsMerge() == 1) { |
| | | LambdaQueryWrapper<TjSampling> wrapper = new LambdaQueryWrapper<>(); |
| | |
| | | if (StrUtil.isNotBlank(errorMsg)) return AjaxResult.error(errorMsg); |
| | | return AjaxResult.success("操作成功"); |
| | | } |
| | | |
| | | |
| | | private void sendLisSqd(Long orderId, String jxbz) { |
| | | String apiUrl = sysConfigService.selectConfigByKey("common_api_url"); |
| | | String hospbm = sysConfigService.selectConfigByKey("common_api_service_hospbm"); |
| | | TjOrder order = orderService.getById(orderId); |
| | | if (StrUtil.isNotBlank(jxbz)){ |
| | | LambdaQueryWrapper<TjSampling> wrapper1 = new LambdaQueryWrapper<>(); |
| | | wrapper1.eq(TjSampling::getTjNum,order.getTjNumber()); |
| | | wrapper1.eq(TjSampling::getJxbz,jxbz); |
| | | getLisMxList(wrapper1, order,apiUrl,hospbm); |
| | | }else { |
| | | LambdaQueryWrapper<TjSampling> wrapper1 = new LambdaQueryWrapper<>(); |
| | | wrapper1.eq(TjSampling::getTjNum,order.getTjNumber()); |
| | | wrapper1.isNull(TjSampling::getJxbz); |
| | | getLisMxList(wrapper1, order,apiUrl,hospbm); |
| | | } |
| | | } |
| | | |
| | | private void getLisMxList(LambdaQueryWrapper<TjSampling> wrapper1, TjOrder order,String apiUrl,String hospbm) { |
| | | List<TjSampling> samplings = tjSamplingService.list(wrapper1); |
| | | if (!samplings.isEmpty()){ |
| | | List<TjSampling> mergeList = samplings.stream().filter(i -> i.getIsMerge() == 1).collect(Collectors.toList()); |
| | | List<TjSampling> notMergeList = samplings.stream().filter(i -> i.getIsMerge() == 0).collect(Collectors.toList()); |
| | | if (!mergeList.isEmpty()){ |
| | | notMergeList = sendLis(order, apiUrl, hospbm, mergeList, notMergeList); |
| | | } |
| | | if (!notMergeList.isEmpty()){ |
| | | sendLis(order,apiUrl,hospbm,notMergeList,notMergeList); |
| | | } |
| | | } |
| | | } |
| | | |
| | | private List<TjSampling> sendLis(TjOrder order, String apiUrl, String hospbm, List<TjSampling> mergeList, List<TjSampling> notMergeList) { |
| | | for (TjSampling sampling : mergeList) { |
| | | JSONArray xmList = JSONUtil.createArray(); |
| | | String code = sampling.getSpecimenTypeCode(); |
| | | String type = sampling.getSpecimenType(); |
| | | String[] prodIds = sampling.getProId().split(","); |
| | | for (String prodId : prodIds) { |
| | | JSONObject entries = JSONUtil.createObj(); |
| | | String id = notMergeList.stream().filter(i -> i.getProId().equals(prodId)).collect(Collectors.toList()).get(0).getId(); |
| | | TjProject project = tjProjectMapper.selectById(prodId); |
| | | entries.putOpt("sfxmid",project.getProId()); |
| | | entries.putOpt("sfxmname",project.getProName()); |
| | | // 取tb表 |
| | | entries.putOpt("sfxmprice",project.getProPrice()); |
| | | entries.putOpt("quality",project.getSl()); |
| | | |
| | | entries.putOpt("specimencode",code); |
| | | entries.putOpt("specimendesc",type); |
| | | entries.putOpt("primaryKey",id); |
| | | xmList.add(entries); |
| | | notMergeList = notMergeList.stream().filter(i -> !i.getProId().equals(prodId)).collect(Collectors.toList()); |
| | | } |
| | | |
| | | JSONObject entries = JSONUtil.createObj(); |
| | | TjCustomer customer = tjCustomerService.getById(order.getUserId()); |
| | | entries.putOpt("patientno",customer.getHisJzkh()); |
| | | entries.putOpt("gh_patientno", order.getTjNumber()); |
| | | entries.putOpt("txm",sampling.getJyxh()); |
| | | entries.putOpt("printno",customer.getHisJzkh()); |
| | | entries.putOpt("cusName",customer.getCusName()); |
| | | entries.putOpt("cusBrithday",customer.getCusBrithday()); |
| | | entries.putOpt("cusIdCard",customer.getCusIdcard()); |
| | | entries.putOpt("cusSex",customer.getCusSex()); |
| | | entries.putOpt("cusAddr",customer.getCusAddr()); |
| | | entries.putOpt("cusPhone",customer.getCusPhone()); |
| | | entries.putOpt("compName",""); |
| | | |
| | | entries.putOpt("mxList",xmList); |
| | | String post = HttpClientUtils.sendPost(apiUrl + "/api/lis/"+ hospbm +"/create", JSONUtil.toBean(entries, Map.class)); |
| | | JSONObject result = JSONUtil.parseObj(post); |
| | | if (result.getStr("code").equals("200")){ |
| | | List<String> list = Arrays.asList(prodIds); |
| | | list.add(sampling.getId()); |
| | | LambdaUpdateWrapper<TjSampling> wrapper = new LambdaUpdateWrapper<>(); |
| | | wrapper.in(TjSampling::getId,list); |
| | | wrapper.set(TjSampling::getIsApply,1); |
| | | tjSamplingService.update(wrapper); |
| | | } |
| | | } |
| | | return notMergeList; |
| | | } |
| | | |
| | | private Boolean sendLis(TjSampling sampling,TjOrder order,String apiUrl,String hospbm){ |
| | | JSONArray xmList = JSONUtil.createArray(); |
| | | String code = sampling.getSpecimenTypeCode(); |
| | | String type = sampling.getSpecimenType(); |
| | | String[] prodIds = sampling.getProId().split(","); |
| | | for (String prodId : prodIds) { |
| | | JSONObject entries = JSONUtil.createObj(); |
| | | TjProject project = tjProjectMapper.selectById(prodId); |
| | | entries.putOpt("sfxmid",project.getProId()); |
| | | entries.putOpt("sfxmname",project.getProName()); |
| | | |
| | | QueryWrapper<TbTransition> wrapper = new QueryWrapper<>(); |
| | | wrapper |
| | | .select("sum(now_price) as now_price") |
| | | .eq("tj_num",order.getTjNumber()) |
| | | .eq("parent_pro_id",prodId); |
| | | TbTransition transition = tbTransitionService.getOne(wrapper); |
| | | |
| | | entries.putOpt("sfxmprice",transition.getNowPrice()); |
| | | entries.putOpt("quality",project.getSl()); |
| | | |
| | | entries.putOpt("specimencode",code); |
| | | entries.putOpt("specimendesc",type); |
| | | entries.putOpt("primaryKey",prodId); |
| | | xmList.add(entries); |
| | | } |
| | | JSONObject entries = JSONUtil.createObj(); |
| | | TjCustomer customer = tjCustomerService.getById(order.getUserId()); |
| | | entries.putOpt("patientno",customer.getHisJzkh()); |
| | | entries.putOpt("gh_patientno", order.getTjNumber()); |
| | | entries.putOpt("txm",sampling.getJyxh()); |
| | | entries.putOpt("printno",customer.getHisJzkh()); |
| | | entries.putOpt("cusName",customer.getCusName()); |
| | | entries.putOpt("cusBrithday",customer.getCusBrithday()); |
| | | entries.putOpt("cusIdCard",customer.getCusIdcard()); |
| | | entries.putOpt("cusSex",customer.getCusSex()); |
| | | entries.putOpt("cusAddr",customer.getCusAddr()); |
| | | entries.putOpt("cusPhone",customer.getCusPhone()); |
| | | entries.putOpt("compName",""); |
| | | |
| | | entries.putOpt("mxList",xmList); |
| | | String post = HttpClientUtils.sendPost(apiUrl + "/api/lis/"+ hospbm +"/create", JSONUtil.toBean(entries, Map.class)); |
| | | // JSONObject result = JSONUtil.parseObj(post); |
| | | // if (result.getStr("code").equals("200")){ |
| | | // List<String> list = Arrays.asList(prodIds); |
| | | // list.add(sampling.getId()); |
| | | // LambdaUpdateWrapper<TjSampling> wrapper = new LambdaUpdateWrapper<>(); |
| | | // wrapper.in(TjSampling::getId,list); |
| | | // wrapper.set(TjSampling::getIsApply,1); |
| | | // tjSamplingService.update(wrapper); |
| | | // return true; |
| | | // } |
| | | // return false; |
| | | return true; |
| | | } |
| | | } |