| | |
| | | package com.ltkj.web.controller.lis; |
| | | |
| | | |
| | | import cn.hutool.core.date.DateUtil; |
| | | import cn.hutool.core.util.RandomUtil; |
| | | import cn.hutool.core.util.StrUtil; |
| | | import cn.hutool.extra.pinyin.PinyinUtil; |
| | | import cn.hutool.json.JSONObject; |
| | | import cn.hutool.json.JSONUtil; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.ltkj.common.core.domain.AjaxResult; |
| | | import com.ltkj.common.utils.AgeResult; |
| | | import com.ltkj.common.utils.DateUtils; |
| | | import com.ltkj.common.utils.IdUtils; |
| | | import com.ltkj.hosp.domain.*; |
| | | import com.ltkj.hosp.hisDto.OutpintestapplyDetailsDto; |
| | | import com.ltkj.hosp.lisDto.LisSaveSqdxxDto; |
| | | import com.ltkj.hosp.lisDto.LisSaveSqdxxJyxmlistDto; |
| | | import com.ltkj.hosp.service.*; |
| | | import com.ltkj.system.service.ISysDeptService; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.commons.lang3.time.DateFormatUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.util.ArrayList; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.Objects; |
| | | import java.util.concurrent.atomic.AtomicInteger; |
| | | import java.util.stream.Collectors; |
| | | |
| | | @Component |
| | | @Slf4j |
| | | public class LisApiMethod { |
| | | @Autowired |
| | | private LisApiMethodService lisApiMethodService; |
| | | @Autowired |
| | | private ISysDeptService deptService; |
| | | @Autowired |
| | | private ITjProjectService projectService; |
| | | @Autowired |
| | | private LtkjJfzhglmxjfxmzdService ltkjJfzhglmxjfxmzdService; |
| | | @Autowired |
| | | private LtkjMxjfxmzdService ltkjMxjfxmzdService; |
| | | @Autowired |
| | | private LtkjEjjfxmzdService ltkjEjjfxmzdService; |
| | | @Autowired |
| | | private LtkjJianchajianyanTreeService ltkjJianchajianyanTreeService; |
| | | @Autowired |
| | | private LtkjJfzhgljyxmzdService ltkjJfzhgljyxmzdService; |
| | | @Autowired |
| | | private LtkjJyxmzdService ltkjJyxmzdService; |
| | | @Autowired |
| | | private LtkjJfxmgljyxmzdService ltkjJfxmgljyxmzdService; |
| | | @Autowired |
| | | private LtkjJyxmzdService jyxmzdService; |
| | | @Autowired |
| | | private IdUtils idUtils; |
| | | |
| | | /** |
| | | * 保存检验单申请信息 |
| | | * @param tjOrder |
| | | * @param tjCustomer |
| | | * @param detailList |
| | | * @return |
| | | */ |
| | | public Boolean save(TjOrder tjOrder, TjCustomer tjCustomer, List<TbTransition> detailList){ |
| | | if (detailList != null && !detailList.isEmpty()) { |
| | | LambdaQueryWrapper<TjProject> wq = new LambdaQueryWrapper<>(); |
| | | wq.in(TjProject::getProId, detailList.stream().map(TbTransition::getParentProId).collect(Collectors.toList())); |
| | | wq.in(TjProject::getDeptId,deptService.getJyDeptIds()); |
| | | List<TjProject> projects = projectService.list(wq); |
| | | if (projects != null && !projects.isEmpty()){ |
| | | // 根据project表的his_xmbm查组合关联表 ltkj_jfzhgljyxmzd 根据字段`zhxmdm` |
| | | // - 查到 使用字段`jyxmdm`查检验项目字典表 ltkj_jyxmzd 根据字段`jyxmdm` |
| | | // - 未查到 查项目关联表ltkj_jfxmgljyxmzd 根据字段`xmdm` |
| | | for (TjProject project : projects) { |
| | | List<OutpintestapplyDetailsDto> detailsDtos = new ArrayList<>(); |
| | | if (0 == project.getProParentId() && project.getProPrice().compareTo(BigDecimal.ZERO) != 0) { |
| | | if (null != project.getHisXmbm()) { |
| | | LisSaveSqdxxDto lisSaveSqdxxDto = new LisSaveSqdxxDto(); |
| | | LtkjJyxmzd jyxmzd = getGetYbDm(project); |
| | | BigDecimal allPrice = new BigDecimal("0"); |
| | | for (TbTransition transition : detailList.stream().filter(item -> Objects.equals(item.getParentProId(), project.getProId())) |
| | | .collect(Collectors.toList())) { |
| | | allPrice = allPrice.add(transition.getNowPrice()); |
| | | } |
| | | if (jyxmzd != null) { |
| | | ArrayList<LisSaveSqdxxJyxmlistDto> dtos = new ArrayList<>(); |
| | | AtomicInteger xh = new AtomicInteger(); |
| | | detailList.stream().filter(detail -> detail.getParentProId().equals(project.getProId())) |
| | | .forEach(item -> { |
| | | LisSaveSqdxxJyxmlistDto dto = new LisSaveSqdxxJyxmlistDto(); |
| | | dto.setXh(String.valueOf(xh.getAndIncrement())); |
| | | TjProject project1 = projectService.getById(item.getProId()); |
| | | LtkjJyxmzd jyxmzd1 = getGetYbDm(project1); |
| | | if (jyxmzd1 == null) dto.setJyxm(project1.getHisXmbm()); |
| | | else dto.setJyxm(jyxmzd1.getJyxmdm()); |
| | | dto.setXmmc(project1.getProName()); |
| | | dtos.add(dto); |
| | | |
| | | OutpintestapplyDetailsDto detailsDto = new OutpintestapplyDetailsDto(); |
| | | detailsDto.setMxfyxmbm(project.getHisXmbm()); |
| | | if (project.getSfzhfy().equals("Y")) { |
| | | detailsDto.setSfzhfy("1"); |
| | | } else { |
| | | detailsDto.setSfzhfy("0"); |
| | | } |
| | | detailsDto.setSl(project.getSl()); |
| | | detailsDto.setProjg(project.getProPrice()); |
| | | detailsDtos.add(detailsDto); |
| | | }); |
| | | |
| | | String yyyyMMdd = DateFormatUtils.format(tjCustomer.getCusBrithday(), "yyyyMMdd"); |
| | | // String sqdh = "3"+yyyyMMdd.substring(2)+ RandomUtil.randomString(String.valueOf(System.currentTimeMillis()), 3); |
| | | String jyxh = idUtils.generateID(); |
| | | lisSaveSqdxxDto.setJyxh(jyxh); |
| | | lisSaveSqdxxDto.setBah(tjOrder.getCardId()); |
| | | lisSaveSqdxxDto.setBrxm(tjCustomer.getCusName()); |
| | | lisSaveSqdxxDto.setBrdm(PinyinUtil.getPinyin(tjCustomer.getCusName())); |
| | | lisSaveSqdxxDto.setXb(tjCustomer.getCusSex()==1?"2":"1"); |
| | | lisSaveSqdxxDto.setCsrq(DateFormatUtils.format(tjCustomer.getCusBrithday(), "yyyy-MM-dd")); |
| | | AgeResult ageResult = DateUtils.calculateAge(tjCustomer.getCusBrithday()); |
| | | lisSaveSqdxxDto.setNl(String.valueOf(ageResult.getAge())); |
| | | lisSaveSqdxxDto.setNldw(String.valueOf(ageResult.getUnit())); |
| | | lisSaveSqdxxDto.setSfzh(tjCustomer.getCusIdcard()); |
| | | lisSaveSqdxxDto.setLxdh(tjCustomer.getCusPhone()); |
| | | lisSaveSqdxxDto.setJtzz(""); |
| | | Date date = new Date(); |
| | | lisSaveSqdxxDto.setSqrq(DateFormatUtils.format(date, "yyyy-MM-dd HH:mm:ss")); |
| | | lisSaveSqdxxDto.setYbbm(jyxmzd.getJybbdm()); |
| | | lisSaveSqdxxDto.setCyrq(""); |
| | | lisSaveSqdxxDto.setLczd(""); |
| | | lisSaveSqdxxDto.setFyje(allPrice.toString()); |
| | | lisSaveSqdxxDto.setBz(""); |
| | | lisSaveSqdxxDto.setKsbm("0101"); |
| | | lisSaveSqdxxDto.setSqys("00029"); |
| | | lisSaveSqdxxDto.setJyxmlistDtoList(dtos); |
| | | log.info("检验申请 ->{}",JSONUtil.toJsonStr(lisSaveSqdxxDto)); |
| | | // TODO 暂不发出请求 |
| | | if (!detailsDtos.isEmpty() && false) { |
| | | AjaxResult ajaxResult = lisApiMethodService.saveSqdxx(lisSaveSqdxxDto); |
| | | String result = ajaxResult.get("data").toString(); |
| | | JSONObject object = JSONUtil.parseObj(JSONUtil.parseObj(result).getStr("Response")); |
| | | log.info("请求返回 ->{}",object); |
| | | String code = object.getStr("ResultCode"); |
| | | if(code.equals("0")){ |
| | | for (OutpintestapplyDetailsDto detail : detailsDtos) { |
| | | LtkjJianchajianyanTree tree = new LtkjJianchajianyanTree(); |
| | | tree.setCardId(tjOrder.getCardId()); |
| | | tree.setPationid(tjCustomer.getPationId()); |
| | | tree.setSqdh(jyxh); |
| | | tree.setFyhj(allPrice.toString()); |
| | | String mxfyxmbm = detail.getMxfyxmbm(); |
| | | tree.setHisXmdm(mxfyxmbm); |
| | | tree.setType("检验"); |
| | | tree.setTjPrice(String.valueOf(detail.getProjg())); |
| | | LambdaQueryWrapper<LtkjJfzhglmxjfxmzd> wrapper1 = new LambdaQueryWrapper<>(); |
| | | if (detail.getSfzhfy().equals("1")) |
| | | wrapper1.eq(LtkjJfzhglmxjfxmzd::getZhxmdm, mxfyxmbm); |
| | | else wrapper1.eq(LtkjJfzhglmxjfxmzd::getXmdm, mxfyxmbm); |
| | | List<LtkjJfzhglmxjfxmzd> ltkjJfzhglmxjfxmzds = ltkjJfzhglmxjfxmzdService.list(wrapper1); |
| | | if (ltkjJfzhglmxjfxmzds != null && !ltkjJfzhglmxjfxmzds.isEmpty()) { |
| | | String xmdm = ltkjJfzhglmxjfxmzds.get(0).getXmdm(); |
| | | LambdaQueryWrapper<LtkjMxjfxmzd> wrapper3 = new LambdaQueryWrapper<>(); |
| | | wrapper3.eq(LtkjMxjfxmzd::getXmdm, xmdm); |
| | | LtkjMxjfxmzd mxjfxmzd = ltkjMxjfxmzdService.getOne(wrapper3); |
| | | LambdaQueryWrapper<LtkjEjjfxmzd> wrapper4 = new LambdaQueryWrapper<>(); |
| | | wrapper4.eq(LtkjEjjfxmzd::getEjkmdm, mxjfxmzd.getEjkmdm()); |
| | | LtkjEjjfxmzd ejjfxmzd = ltkjEjjfxmzdService.getOne(wrapper4); |
| | | tree.setXmfl(ejjfxmzd.getYjkmdm()); |
| | | } |
| | | tree.setCreateTime(DateUtil.date()); |
| | | ltkjJianchajianyanTreeService.save(tree); |
| | | } |
| | | }else { |
| | | log.error("请求失败 ->{}",lisSaveSqdxxDto); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | return true; |
| | | } |
| | | |
| | | /** |
| | | * 获取检验结果 |
| | | * @param cardId |
| | | * @return |
| | | */ |
| | | public AjaxResult getJyJg(String cardId){ |
| | | return lisApiMethodService.getJyjg(cardId); |
| | | } |
| | | |
| | | /** |
| | | * 作废申请单 |
| | | * @param jyxh |
| | | * @param cardId |
| | | * @param cusName |
| | | * @return |
| | | */ |
| | | public AjaxResult cancel(String jyxh,String cardId,String cusName){ |
| | | return lisApiMethodService.updateSqdxx(cardId,jyxh,cusName); |
| | | } |
| | | |
| | | |
| | | |
| | | private LtkjJyxmzd getGetYbDm(TjProject project) { |
| | | String jyxmdm = ""; |
| | | LambdaQueryWrapper<LtkjJfzhgljyxmzd> wrapper = new LambdaQueryWrapper<>(); |
| | | wrapper.eq(LtkjJfzhgljyxmzd::getZhxmdm, project.getHisXmbm()); |
| | | LtkjJfzhgljyxmzd jfzhgljyxmzd = ltkjJfzhgljyxmzdService.getOne(wrapper); |
| | | if (jfzhgljyxmzd != null) jyxmdm = jfzhgljyxmzd.getJyxmdm(); |
| | | else { |
| | | LambdaQueryWrapper<LtkjJfxmgljyxmzd> wrapper1 = new LambdaQueryWrapper<>(); |
| | | wrapper1.eq(LtkjJfxmgljyxmzd::getXmdm, project.getHisXmbm()); |
| | | LtkjJfxmgljyxmzd jfxmgljyxmzd = ltkjJfxmgljyxmzdService.getOne(wrapper1); |
| | | if (jfxmgljyxmzd != null) jyxmdm = jfxmgljyxmzd.getJyxmdm(); |
| | | } |
| | | // if (StrUtil.isBlank(jyxmdm)) log.error("获取检验项目代码为空 ->{}", project); |
| | | LambdaQueryWrapper<LtkjJyxmzd> wrapper2 = new LambdaQueryWrapper<>(); |
| | | wrapper2.eq(LtkjJyxmzd::getJyxmdm,jyxmdm); |
| | | LtkjJyxmzd jyxmzd = jyxmzdService.getOne(wrapper2); |
| | | if (jyxmzd != null) return jyxmzd; |
| | | return null; |
| | | } |
| | | } |