zjh
2025-03-31 92fec7876dbbc43f1780e66901ef8bfd0fad445b
ltkj-admin/src/main/java/com/ltkj/web/controller/system/TjOrderController.java
@@ -2,31 +2,24 @@
import java.io.*;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.OffsetTime;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.List;
import java.util.concurrent.*;
import java.util.concurrent.locks.ReentrantLock;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import cn.hutool.core.codec.Base64;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUnit;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.RandomUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.crypto.symmetric.DES;
import cn.hutool.extra.pinyin.PinyinUtil;
import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONObject;
@@ -34,10 +27,7 @@
import com.alibaba.fastjson2.JSON;
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.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fasterxml.jackson.databind.BeanProperty;
import com.itextpdf.text.Document;
import com.itextpdf.text.DocumentException;
import com.ltkj.common.annotation.RepeatSubmit;
@@ -54,12 +44,10 @@
import com.ltkj.hosp.dto.QianDaoDto;
import com.ltkj.hosp.dto.TjProBlDto;
import com.ltkj.hosp.dto.UpdateTransitionnewPriceDto;
import com.ltkj.hosp.hisDto.OutpinimpapplyDto;
import com.ltkj.hosp.hisDto.OutpinmedicapplyDto;
import com.ltkj.hosp.mapper.TbTransitionMapper;
import com.ltkj.hosp.mapper.TestMapper;
import com.ltkj.hosp.mapper.TjSamplingMapper;
import com.ltkj.hosp.pacsDto.SavePacsApply;
import com.ltkj.hosp.service.*;
import com.ltkj.hosp.sqlDomain.LtkjMiddleDetail;
import com.ltkj.hosp.sqlDomain.LtkjMiddleHead;
@@ -76,24 +64,19 @@
import com.ltkj.mall.service.IMallOrderService;
import com.ltkj.system.domain.TjDjdDyjl;
import com.ltkj.system.service.*;
import com.ltkj.hosp.idutil.IdUtils;
import com.ltkj.web.controller.his.*;
import com.ltkj.web.controller.lis.LisApiMethod;
import com.ltkj.web.controller.pacs.PacsApiMethodService;
import com.ltkj.web.controller.service.TjSysAsyncServiceImpl;
import com.ltkj.web.wxUtils.HttpClientUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import jodd.util.StringUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.time.DateFormatUtils;
import org.aspectj.weaver.ast.Var;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.http.HttpRequest;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
@@ -1107,11 +1090,38 @@
        //生成体检号
//        String tjNumber = (SecurityUtils.getUsername() + new SimpleDateFormat("yyMMddHHmmss").format(new Date()));
//        if(StringUtil.isNotBlank(makeLisTmhPrefix)) tjNumber=makeLisTmhPrefix+tjNumber;
//        String tjNumber = (SecurityUtils.getUsername() + idUtils.getTjNumber());
        String tjNumber = idUtils.getTjNumber();
        if (StringUtil.isNotBlank(makeLisTmhPrefix)) tjNumber = makeLisTmhPrefix + tjNumber;
//        String tjNumber = idUtils.getTjNumber();
        String tjNumber = null;
        int a =0;
        while (tjNumber ==null){
            if(a>3){
                throw new RuntimeException("前方拥挤,请稍等!!!");
            }
            try {
                String newTjNumberRedisLockAndMysql = idUtils.getNewTjNumberRedisLockAndMysql();
                if (StringUtil.isNotBlank(makeLisTmhPrefix)){
                 String tjh=  makeLisTmhPrefix + newTjNumberRedisLockAndMysql;
                 int countByTjNum = tjOrderService.getOrderCountByTjNum(tjh);
                 if(countByTjNum==0){
                     tjNumber=tjh;
                 }
                }else {
                    int countByTjNum = tjOrderService.getOrderCountByTjNum(newTjNumberRedisLockAndMysql);
                    if(countByTjNum==0){
                        tjNumber=newTjNumberRedisLockAndMysql;
                    }
                }
            } catch (Exception e) {
                log.error(e.getMessage());
            }finally {
                a++;
            }
        }
        if(StringUtil.isBlank(tjNumber)) return AjaxResult.error("登记失败 重新操作");
        tjOrder.setTjNumber(tjNumber);
@@ -1461,89 +1471,93 @@
    }
    public void addCaiYangDengJi(List<TjOrderDetail> detailList, boolean detailList1, TjOrder order, SysUser sysUser, String jxbz) {
        String lis_tmh_prefix = configService.selectConfigByKey("make_lis_tmh_prefix");
        String config = configService.selectConfigByKey("sfkqdyhis");
        Boolean lisAndPacsRegister = lisApiMethod.isUseLisAndPacsRegister(order);
        if (null != detailList && detailList1) {
            Date date = new Date();
            String format = DateUtil.format(date, "yyMMddHHmmssSSS");
            for (TjOrderDetail detail : detailList) {
                int i = samplingService.isExistProId(order.getTjNumber(), String.valueOf(detail.getProId()));
                if(i>0) continue;
                TjSampling sampling = new TjSampling();
                if (null == projectService.getById(detail.getProId())) continue;
                TjProject project = projectService.getById(detail.getProId());
                Long proParentId = project.getProParentId();
                String dictLabel = sysDictDataService.selectDictLabel("sys_dict_specimen", project.getSpecimenType());
                if (null != proParentId && proParentId == 0) {
                    sampling.setJyxh(idUtils.generateLisID(lis_tmh_prefix));
                    sampling.setSpecimenTypeCode(project.getSpecimenType());
                    sampling.setSpecimenType(dictLabel);
                    if (config.equals("Y") && lisAndPacsRegister)
                        sampling.setJyxmdm(project.getLisXmbm());
                    else sampling.setJyxmdm(project.getProId().toString());
                } else {
                    TjProject project1 = projectService.getById(proParentId);
                    sampling.setJyxh(idUtils.generateLisID(lis_tmh_prefix));
                    sampling.setSpecimenTypeCode(project1.getSpecimenType());
                    sampling.setSpecimenType(dictLabel);
                    if (config.equals("Y") && lisAndPacsRegister)
                        sampling.setJyxmdm(project1.getLisXmbm());
                    else sampling.setJyxmdm(project1.getProId().toString());
                }
                sampling.setSamplingNumber(format);
                sampling.setTjNum(order.getTjNumber());
                sampling.setCusId(String.valueOf(order.getUserId()));
                if (tjCustomerService.getById(String.valueOf(order.getUserId())) != null) {
                    sampling.setCusName(tjCustomerService.getById(String.valueOf(order.getUserId())).getCusName());
                }
                sampling.setApplicationTime(date);
                sampling.setTjTime(order.getCreateTime());
                sampling.setProId(String.valueOf(detail.getProId()));
                sampling.setProName(projectService.getById(detail.getProId()).getProName());
                sampling.setCreateBy(sysUser.getNickName());
                sampling.setCreateTime(date);
                sampling.setUpdateBy(sysUser.getNickName());
                sampling.setUpdateTime(date);
                sampling.setCreateId(String.valueOf(sysUser.getUserId()));
                sampling.setUpdateId(String.valueOf(sysUser.getUserId()));
                sampling.setJxbz(jxbz);
                samplingService.save(sampling);
            }
        }
        if (lisApiMethod.isUseLisAndPacsRegister(order) && (null != config && config.equals("Y"))) {
            AjaxResult ajaxResult = lisApiMethod.getJyFlHb();
            if (ajaxResult.get("code").toString().equals("200")) {
                String str = ajaxResult.get("data").toString();
                str = str.replace("=", ":");
                JSONArray array = JSONUtil.parseArray(str);
                for (Object o : array) {
                    JSONObject object = (JSONObject) o;
                    LisJyflhb lisJyflhb = new LisJyflhb();
                    lisJyflhb.setHbhxm(object.getStr("hbhxm"));
                    lisJyflhb.setFlmc(object.getStr("flmc"));
                    lisJyflhb.setMc(object.getStr("mc"));
                    lisJyflhb.setFlbm(object.getStr("flbm"));
                    LambdaQueryWrapper<LisJyflhb> wrapper = new LambdaQueryWrapper<>();
                    wrapper.eq(LisJyflhb::getFlbm, lisJyflhb.getFlbm());
                    LisJyflhb jyflhb = lisJyflhbService.getOne(wrapper);
                    if (jyflhb == null) {
                        lisJyflhb.setId(IdUtil.getSnowflake().nextId());
                        lisJyflhbService.save(lisJyflhb);
        try {
            String lis_tmh_prefix = configService.selectConfigByKey("make_lis_tmh_prefix");
            String config = configService.selectConfigByKey("sfkqdyhis");
            Boolean lisAndPacsRegister = lisApiMethod.isUseLisAndPacsRegister(order);
            if (null != detailList && detailList1) {
                Date date = new Date();
                String format = DateUtil.format(date, "yyMMddHHmmssSSS");
                for (TjOrderDetail detail : detailList) {
                    int i = samplingService.isExistProId(order.getTjNumber(), String.valueOf(detail.getProId()));
                    if(i>0) continue;
                    TjSampling sampling = new TjSampling();
                    if (null == projectService.getById(detail.getProId())) continue;
                    TjProject project = projectService.getById(detail.getProId());
                    Long proParentId = project.getProParentId();
                    String dictLabel = sysDictDataService.selectDictLabel("sys_dict_specimen", project.getSpecimenType());
                    if (null != proParentId && proParentId == 0) {
                        sampling.setJyxh(idUtils.generateLisID(lis_tmh_prefix));
                        sampling.setSpecimenTypeCode(project.getSpecimenType());
                        sampling.setSpecimenType(dictLabel);
                        if (config.equals("Y") && lisAndPacsRegister)
                            sampling.setJyxmdm(project.getLisXmbm());
                        else sampling.setJyxmdm(project.getProId().toString());
                    } else {
                        lisJyflhb.setId(jyflhb.getId());
                        lisJyflhbService.updateById(lisJyflhb);
                        TjProject project1 = projectService.getById(proParentId);
                        sampling.setJyxh(idUtils.generateLisID(lis_tmh_prefix));
                        sampling.setSpecimenTypeCode(project1.getSpecimenType());
                        sampling.setSpecimenType(dictLabel);
                        if (config.equals("Y") && lisAndPacsRegister)
                            sampling.setJyxmdm(project1.getLisXmbm());
                        else sampling.setJyxmdm(project1.getProId().toString());
                    }
                    sampling.setSamplingNumber(format);
                    sampling.setTjNum(order.getTjNumber());
                    sampling.setCusId(String.valueOf(order.getUserId()));
                    if (tjCustomerService.getById(String.valueOf(order.getUserId())) != null) {
                        sampling.setCusName(tjCustomerService.getById(String.valueOf(order.getUserId())).getCusName());
                    }
                    sampling.setApplicationTime(date);
                    sampling.setTjTime(order.getCreateTime());
                    sampling.setProId(String.valueOf(detail.getProId()));
                    sampling.setProName(projectService.getById(detail.getProId()).getProName());
                    sampling.setCreateBy(sysUser.getNickName());
                    sampling.setCreateTime(date);
                    sampling.setUpdateBy(sysUser.getNickName());
                    sampling.setUpdateTime(date);
                    sampling.setCreateId(String.valueOf(sysUser.getUserId()));
                    sampling.setUpdateId(String.valueOf(sysUser.getUserId()));
                    sampling.setJxbz(jxbz);
                    samplingService.save(sampling);
                }
            }
            if (lisApiMethod.isUseLisAndPacsRegister(order) && (null != config && config.equals("Y"))) {
                AjaxResult ajaxResult = lisApiMethod.getJyFlHb();
                if (ajaxResult.get("code").toString().equals("200")) {
                    String str = ajaxResult.get("data").toString();
                    str = str.replace("=", ":");
                    JSONArray array = JSONUtil.parseArray(str);
                    for (Object o : array) {
                        JSONObject object = (JSONObject) o;
                        LisJyflhb lisJyflhb = new LisJyflhb();
                        lisJyflhb.setHbhxm(object.getStr("hbhxm"));
                        lisJyflhb.setFlmc(object.getStr("flmc"));
                        lisJyflhb.setMc(object.getStr("mc"));
                        lisJyflhb.setFlbm(object.getStr("flbm"));
                        LambdaQueryWrapper<LisJyflhb> wrapper = new LambdaQueryWrapper<>();
                        wrapper.eq(LisJyflhb::getFlbm, lisJyflhb.getFlbm());
                        LisJyflhb jyflhb = lisJyflhbService.getOne(wrapper);
                        if (jyflhb == null) {
                            lisJyflhb.setId(IdUtil.getSnowflake().nextId());
                            lisJyflhbService.save(lisJyflhb);
                        } else {
                            lisJyflhb.setId(jyflhb.getId());
                            lisJyflhbService.updateById(lisJyflhb);
                        }
                    }
                }
            }
        }
        if (StrUtil.isNotBlank(jxbz)) {
            tjSamplingMapper.updateUserIdByTjNumAndJxbz(order.getTjNumber(), sysUser.getNickName(), String.valueOf(sysUser.getUserId()), jxbz);
        } else {
            tjSamplingMapper.updateUserIdByTjNum(order.getTjNumber(), sysUser.getNickName(), String.valueOf(sysUser.getUserId()));
            }
            if (StrUtil.isNotBlank(jxbz)) {
                tjSamplingMapper.updateUserIdByTjNumAndJxbz(order.getTjNumber(), sysUser.getNickName(), String.valueOf(sysUser.getUserId()), jxbz);
            } else {
                tjSamplingMapper.updateUserIdByTjNum(order.getTjNumber(), sysUser.getNickName(), String.valueOf(sysUser.getUserId()));
            }
        } catch (Exception e) {
            log.error(e.getMessage());
        }
    }
@@ -1913,7 +1927,8 @@
            //获取拼接前缀
            String makeLisTmhPrefix = configService.selectConfigByKey("make_lis_tmh_prefix");
//            String tjNumber = (sysUser.getUserName() + idUtils.getTjNumber());
            String tjNumber = idUtils.getTjNumber();
//            String tjNumber = idUtils.getTjNumber();
            String tjNumber = idUtils.getNewTjNumberRedisLockAndMysql();
            if (StringUtil.isNotBlank(makeLisTmhPrefix)) tjNumber = makeLisTmhPrefix + tjNumber;