zjh
2025-06-03 37e2d3c73caac445d1d8e229747b439e3719c13b
ltkj-admin/src/main/java/com/ltkj/web/controller/system/TjOrderController.java
@@ -2,31 +2,25 @@
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.bean.BeanUtil;
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 +28,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,11 +45,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;
@@ -75,23 +65,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.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;
@@ -140,8 +126,8 @@
    private ITbTransitionService transitionService;
    @Resource
    private ISysConfigService configService;
    @Value("${path.filePath}")
    private String value;
//    @Value("${path.filePath}")
//    private String value;
    @Resource
    private ITjOrderRemarkService remarkService;
    @Resource
@@ -234,6 +220,12 @@
    private TjFlowingWaterHisService tjFlowingWaterHisService;
    @Resource
    private ITjXdPictureService xdPictureService;
    @Autowired
    private TjOrderYcxmService ycxmService;
    @Autowired
    private TbTransitionMapper tbTransitionMapper;
    private static final String TJH = "tjhs:tjh";
    //将方法返回值解析成json格式
    public JSONObject getJSONObject(String builder) {
@@ -300,7 +292,7 @@
            wqq.like(TjCustomer::getCusName, name);
            List<TjCustomer> customerList = tjCustomerService.list(wqq);
            List<TjOrder> list2 = new ArrayList<>();
            if (null != customerList && customerList.size() > 0) {
            if (null != customerList && !customerList.isEmpty()) {
                List<TjOrder> list = new ArrayList<>();
                for (TjCustomer customer : customerList) {
                    LambdaQueryWrapper<TjOrder> wq = new LambdaQueryWrapper<>();
@@ -311,13 +303,13 @@
                    list.addAll(tjOrderService.list(wq));
                }
                List<TjOrder> collect = null;
                if (list.size() > 0) {
                if (!list.isEmpty()) {
                    for (TjOrder order : list) {
                        //筛选有调查问卷的
                        LambdaQueryWrapper<TjSurveyRecord> wqq1 = new LambdaQueryWrapper<>();
                        wqq1.eq(TjSurveyRecord::getTjnumber, order.getTjNumber());
                        List<TjSurveyRecord> one = surveyRecordService.list(wqq1);
                        if (one.size() == 0) {
                        if (one.isEmpty()) {
                            TjCustomer tjCustomer = tjCustomerService.getById(order.getUserId());
                            if (null != tjCustomer) {
                                order.setTjCustomerName(MatchUtils.hideCusName(tjCustomer.getCusName()));
@@ -378,7 +370,7 @@
                LambdaQueryWrapper<TjSurveyRecord> wqq = new LambdaQueryWrapper<>();
                wqq.eq(TjSurveyRecord::getTjnumber, order.getTjNumber());
                List<TjSurveyRecord> one = surveyRecordService.list(wqq);
                if (one.size() == 0) {
                if (one.isEmpty()) {
                    TjCustomer tjCustomer = tjCustomerService.getById(order.getUserId());
                    if (null != tjCustomer) {
                        order.setTjCustomerName(MatchUtils.hideCusName(tjCustomer.getCusName()));
@@ -498,13 +490,9 @@
                            order.setIdType(tjCustomer.getIdType());
                            order.setAgeUnit(tjCustomer.getAgeUnit());
                            order.setTjCount(String.valueOf(tjCustomer.getCusNumber()));
                            if (null != tjCustomer.getCompName()) {
                                order.setDictCompName(tjCustomer.getCompName());
                            } else {
                                String firmId = order.getFirmId();
                                if (firmId != null && null != iDictCompService.getById(String.valueOf(order.getFirmId()))) {
                                    order.setDictCompName(iDictCompService.getById(String.valueOf(order.getFirmId())).getCnName());
                                }
                            String firmName = order.getFirmName();
                            if (StringUtil.isNotBlank(firmName)) {
                                order.setDictCompName(firmName);
                            }
                            if (null != order.getPacId()) {
                                if (null != tjPackageService.getById(order.getPacId())) {
@@ -546,7 +534,7 @@
                wq.isNull(TjOrder::getPrintLastTime);
            }
            if (zt == 6) {
                //已出报告
                //已打印
                wq.isNotNull(TjOrder::getPrintLastTime);
                wq.eq(TjOrder::getHeshouStatus, 1);
                wq.isNotNull(TjOrder::getPrintLastTime);
@@ -605,7 +593,7 @@
                        order.setZt("报告核收");
                    }
                    if (zt == 6) {
                        order.setZt("已出报告");
                        order.setZt("已打印");
                    }
                } else {
                    if (czwj == 0) {
@@ -633,8 +621,8 @@
                        order.setZt("报告核收");
                    }
                    if (null != lastTime) {
                        //已出报告6
                        order.setZt("已出报告");
                        //已打印6
                        order.setZt("已打印");
                    }
                }
            }
@@ -655,82 +643,6 @@
                                     @ApiParam(value = "单位") @RequestParam(required = false) String dw,
                                     @ApiParam(value = "报告开始时间") @RequestParam(required = false) String djbeginTime,
                                     @ApiParam(value = "报告结束时间") @RequestParam(required = false) String djendTime) {
                                    /*        Map<String, Object> map = new HashMap<>();
        List<Long> cusIds = null;
        if (StringUtil.isNotBlank(name)) {
            LambdaQueryWrapper<TjCustomer> wqq = new LambdaQueryWrapper<>();
            wqq.like(TjCustomer::getCusName, name);
            cusIds = tjCustomerService.list(wqq).stream().map(TjCustomer::getCusId).collect(Collectors.toList());
        }
        Page<TjOrder> page1 = new Page<>(pageNum, pageSize);
        LambdaQueryWrapper<TjOrder> wq = new LambdaQueryWrapper<>();
        if (dyzt == 0) {
            wq.isNull(TjOrder::getPrintLastTime);
            wq.eq(TjOrder::getHeshouStatus, 1);  //核收状态为1才能打印
        } else {
            wq.isNotNull(TjOrder::getPrintLastTime);
        }
        if (null != djbeginTime && null != djendTime) {
            wq.between(TjOrder::getCreateTime, DateUtil.beginOfDay(DateUtil.parseDate(djbeginTime)), DateUtil.endOfDay(DateUtil.parseDate(djendTime)));
        }
        if (null != tjNum) {
            wq.like(TjOrder::getTjNumber, tjNum);
        }
        if (StringUtil.isNotBlank(dw)) {
            wq.like(TjOrder::getFirmName, dw);
        }
        if (null != cusIds && !cusIds.isEmpty()) {
            wq.in(TjOrder::getUserId, cusIds);
        }
        wq.orderByDesc(TjOrder::getCreateTime);
        Page<TjOrder> page2 = tjOrderService.page(page1, wq);
        List<TjOrder> list = page2.getRecords();
        if (list != null) {
            for (int i = 0; i < list.size(); i++) {
                TjCustomer tjCustomer = tjCustomerService.getById(list.get(i).getUserId());
                if (null == tjCustomer) {
                    list.remove(list.get(i));
                    continue;
                }
                list.get(i).setTjCustomerSex(tjCustomer.getCusSex());
                list.get(i).setTjCustomerAge(DateUtil.ageOfNow(tjCustomer.getCusBrithday()));
                list.get(i).setTjCustomerName(tjCustomer.getCusName());
                list.get(i).setTjCustomerPhone(tjCustomer.getCusPhone());
                if (tjCustomer.getCusIdcard() != null) {
                    list.get(i).setTjCusIdCard(tjCustomer.getCusIdcard());
                }
                if (null != tjCustomer.getCompName()) {
                    list.get(i).setDictCompName(tjCustomer.getCompName());
                } else {
                    String firmId = list.get(i).getFirmId();
                    if (firmId != null && null != iDictCompService.getById(String.valueOf(list.get(i).getFirmId()))) {
                        list.get(i).setDictCompName(iDictCompService.getById(String.valueOf(list.get(i).getFirmId())).getCnName());
                    }
                }
                if (null != list.get(i).getPacId()) {
                    if (null != tjPackageService.getById(list.get(i).getPacId())) {
                        list.get(i).setPacName(tjPackageService.getById(list.get(i).getPacId()).getPacName());
                    }
                    if (null != dwDeptService.getById(list.get(i).getPacId())) {
                        list.get(i).setPacName(dwDeptService.getById(list.get(i).getPacId()).getDwDeptName());
                    }
                }
                //从打印记录查出最新打印时间
//                LambdaQueryWrapper<TjReportPrint> wqqq = new LambdaQueryWrapper<>();
//                wqqq.eq(TjReportPrint::getTjNumber, list.get(i).getTjNumber());
//                wqqq.orderByDesc(TjReportPrint::getPrintTime);
//                wqqq.last("limit 1");
//                TjReportPrint one = tjReportPrintService.getOne(wqqq);
//                if (one != null) {
//                    list.get(i).setPrintLastTime(one.getPrintTime());
//                }
            }
        }
        map.put("list", list);
        map.put("total", page2.getTotal());*/
        if (djbeginTime == null) djbeginTime = "";
        if (djendTime == null) djendTime = "";
        Map<String, Object> map = tjOrderService.getTjBgdyList(pageNum, pageSize, dyzt, tjNum, name, dw, djbeginTime, djendTime);
@@ -933,16 +845,236 @@
    }
    /**
     * 导出体检记录列表
     */
//    @PreAuthorize("@ss.hasPermi('hosp:order:export')")
    @Log(title = "体检记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @PostMapping("/exportOrderList")
    @ApiOperation(value = "导出体检记录列表")
    public void export(HttpServletResponse response, TjOrder tjOrder) {
        //List<TjOrder> list = tjOrderService.selectTjOrderList(tjOrder);
        List<TjOrder> list = tjOrderService.selectExportOrderList(tjOrder);
    public void exportOrderList(@ApiParam(value = "页码数(默认1)") @RequestParam(defaultValue = "1") Integer pageNum,
                                   @ApiParam(value = "显示条数(默认10)") @RequestParam(defaultValue = "10") Integer pageSize,
                                   @ApiParam(value = "状态") @RequestParam(required = false) Integer zt,
                                   @ApiParam(value = "体检号)") @RequestParam(required = false) String tjNum,
                                   @ApiParam(value = "姓名)") @RequestParam(required = false) String name,
                                   @ApiParam(value = "项目名)") @RequestParam(required = false) String xmmc,
                                   @ApiParam(value = "登记开始时间") @RequestParam(required = false) Date djbeginTime,
                                   @ApiParam(value = "登记结束时间") @RequestParam(required = false) Date djendTime,
                                   @ApiParam(value = "报告开始时间") @RequestParam(required = false) Date bgbeginTime,
                                   @ApiParam(value = "报告结束时间") @RequestParam(required = false) Date bgendTime,
                                   @ApiParam(value = "单位") @RequestParam(required = false) String dw,
                                   @ApiParam(value = "当前页或全部数据") @RequestParam(required = false) String dqyorqbsj,
                                   HttpServletResponse response) {
        List<Long> cusIds = null;
        if (null != name) {
            LambdaQueryWrapper<TjCustomer> wqq = new LambdaQueryWrapper<>();
            wqq.like(TjCustomer::getCusName, name);
            cusIds = tjCustomerService.list(wqq).stream().map(TjCustomer::getCusId).collect(Collectors.toList());
        }
        Page<TjOrder> page1 = new Page<>(pageNum, pageSize);
        LambdaQueryWrapper<TjOrder> wq = new LambdaQueryWrapper<>();
        if (null != djbeginTime && null != djendTime) {
            wq.between(TjOrder::getCreateTime, DateUtil.beginOfDay(djbeginTime), DateUtil.endOfDay(djendTime));
        }
        if (null != bgbeginTime && null != bgendTime) {
            wq.between(TjOrder::getCreateTime, DateUtil.beginOfDay(bgbeginTime), DateUtil.endOfDay(bgendTime));
        }
        if (null != tjNum) {
            wq.eq(TjOrder::getTjNumber, tjNum);
        }
        if (null != xmmc) {
            wq.in(TjOrder::getTjNumber, projectService.getTjNumLIstByXmmx(xmmc));
        }
        if (StrUtil.isNotBlank(dw)) {
            wq.like(TjOrder::getFirmName, dw);
        }
        if (null != cusIds && !cusIds.isEmpty()) {
            wq.in(TjOrder::getUserId, cusIds);
        }
        if (null != zt && (zt == 0 || zt == 1 || zt == 2)) {
            List<TjOrder> orders = new ArrayList<>();
            List<TjOrder> tjOrders = null;
            List<TjOrder> orderList = tjOrderService.list(wq);
            if (null != orderList && !orderList.isEmpty()) {
                for (TjOrder order : orderList) {
                    int czwj = remarkService.panduaniscunzaiweijian(order.getTjNumber());
                    int sfwc = remarkService.panduaniswancheng(order.getTjNumber());
                    if (zt == 0 && czwj == 0) {
                        //未检0
                        order.setZt("未检");
                        orders.add(order);
                    }
                    if (zt == 1 && czwj > 0) {
                        //在检1
                        order.setZt("在检");
                        orders.add(order);
                    }
                    if (zt == 2 && sfwc == 0 && order.getCheckStatus() == 0 && order.getCheckTime() == null && order.getHeshouStatus() == 0 && order.getPrintLastTime() == null) {
                        //已完成2
                        order.setZt("已完成");
                        orders.add(order);
                    }
                }
                if (!orders.isEmpty()) {
                    tjOrders = orders.stream().sorted(Comparator.comparing(TjOrder::getCreateTime).reversed())
                            .skip((long) (pageNum - 1) * pageSize).limit(pageSize).collect(Collectors.toList());
                    for (TjOrder order : tjOrders) {
                        TjCustomer tjCustomer = tjCustomerService.getById(order.getUserId());
                        if (null != tjCustomer) {
                            order.setTjCustomerSex(tjCustomer.getCusSex());
                            order.setTjCustomerAge(DateUtil.ageOfNow(tjCustomer.getCusBrithday()));
                            order.setTjCustomerName(tjCustomer.getCusName());
                            order.setTjCustomerPhone(tjCustomer.getCusPhone());
                            order.setTjCusIdCard(tjCustomer.getCusIdcard());
                            order.setCareer(tjCustomer.getCareer());
                            order.setIdType(tjCustomer.getIdType());
                            order.setAgeUnit(tjCustomer.getAgeUnit());
                            order.setTjCount(String.valueOf(tjCustomer.getCusNumber()));
                            String firmName = order.getFirmName();
                            if (StringUtil.isNotBlank(firmName)) {
                                order.setDictCompName(firmName);
                            }
                            if (null != order.getPacId()) {
                                if (null != tjPackageService.getById(order.getPacId())) {
                                    order.setPacName(tjPackageService.getById(order.getPacId()).getPacName());
                                } else if (null != dwDeptService.getById(order.getPacId())) {
                                    order.setPacName(dwDeptService.getById(order.getPacId()).getDwDeptName());
                                }
                            }
                            TjDjdDyjl dycs = djdDyjlService.getDjdDyCsByTjNum(order.getTjNumber());
                            if (null != dycs) order.setDycs(Math.toIntExact(dycs.getDycs()));
                        }
                    }
                }
            }
            ExcelUtil<TjOrder> util = new ExcelUtil<TjOrder>(TjOrder.class);
            util.exportExcel(response, tjOrders, "体检记录数据");
        }
        if (null != zt) {
            if (zt == 3) {
                //已审核
                wq.isNotNull(TjOrder::getCheckTime);
                wq.eq(TjOrder::getCheckStatus, 1);
                wq.isNull(TjOrder::getHeshouTime);
                wq.isNull(TjOrder::getPrintLastTime);
                wq.eq(TjOrder::getHeshouStatus, 0);
            }
            if (zt == 4) {
                //生成报告
                wq.isNotNull(TjOrder::getReportTime);
                wq.isNull(TjOrder::getHeshouTime);
                wq.isNull(TjOrder::getPrintLastTime);
                wq.eq(TjOrder::getHeshouStatus, 0);
            }
            if (zt == 5) {
                //报告核收
                wq.eq(TjOrder::getHeshouStatus, 1);
                wq.isNull(TjOrder::getPrintLastTime);
            }
            if (zt == 6) {
                //已打印
                wq.isNotNull(TjOrder::getPrintLastTime);
                wq.eq(TjOrder::getHeshouStatus, 1);
                wq.isNotNull(TjOrder::getPrintLastTime);
            }
        }
        wq.orderByDesc(TjOrder::getCreateTime);
        List<TjOrder> list =null;
        if(StringUtil.isNotBlank(dqyorqbsj) && dqyorqbsj.equals("1")){
            list = tjOrderService.list(wq);
        }else {
            Page<TjOrder> page2 = tjOrderService.page(page1, wq);
            list = page2.getRecords();
        }
        if (!list.isEmpty()) {
            for (TjOrder order : list) {
                TjCustomer tjCustomer = tjCustomerService.getById(order.getUserId());
                if (null != tjCustomer) {
                    order.setTjCustomerSex(tjCustomer.getCusSex());
                    order.setTjCustomerAge(DateUtil.ageOfNow(tjCustomer.getCusBrithday()));
                    order.setTjCustomerName(tjCustomer.getCusName());
                    order.setTjCustomerPhone(tjCustomer.getCusPhone());
                    order.setTjCusIdCard(tjCustomer.getCusIdcard());
                    order.setCareer(tjCustomer.getCareer());
                    order.setIdType(tjCustomer.getIdType());
                    order.setAgeUnit(tjCustomer.getAgeUnit());
                    order.setTjCount(String.valueOf(tjCustomer.getCusNumber()));
                    if (null != tjCustomer.getCompName()) {
                        order.setDictCompName(tjCustomer.getCompName());
                    } else {
                        String firmId = order.getFirmId();
                        if (firmId != null && null != iDictCompService.getById(String.valueOf(order.getFirmId()))) {
                            order.setDictCompName(iDictCompService.getById(String.valueOf(order.getFirmId())).getCnName());
                        }
                    }
                    if (null != order.getPacId()) {
                        if (null != tjPackageService.getById(order.getPacId())) {
                            order.setPacName(tjPackageService.getById(order.getPacId()).getPacName());
                        } else if (null != dwDeptService.getById(order.getPacId())) {
                            order.setPacName(dwDeptService.getById(order.getPacId()).getDwDeptName());
                        }
                    }
                    TjDjdDyjl dycs = djdDyjlService.getDjdDyCsByTjNum(order.getTjNumber());
                    if (null != dycs) order.setDycs(Math.toIntExact(dycs.getDycs()));
                }
                int czwj = remarkService.panduaniscunzaiweijian(order.getTjNumber());
                int sfwc = remarkService.panduaniswancheng(order.getTjNumber());
                Date checkTime = order.getCheckTime();
                Date reportTime = order.getReportTime();
                Integer heshouStatus = order.getHeshouStatus();
                Date lastTime = order.getPrintLastTime();
                if (null != zt) {
                    if (zt == 3) {
                        order.setZt("已审核");
                    }
                    if (zt == 4) {
                        order.setZt("生成报告");
                    }
                    if (zt == 5) {
                        order.setZt("报告核收");
                    }
                    if (zt == 6) {
                        order.setZt("已打印");
                    }
                } else {
                    if (czwj == 0) {
                        //未检0
                        order.setZt("未检");
                    }
                    if (czwj > 0) {
                        //在检1
                        order.setZt("在检");
                    }
                    if (sfwc == 0) {
                        //已完成2
                        order.setZt("已完成");
                    }
                    if (null != checkTime) {
                        //已审核3
                        order.setZt("已审核");
                    }
                    if (null != reportTime) {
                        //生成报告4
                        order.setZt("生成报告");
                    }
                    if (1 == heshouStatus) {
                        //报告核收5
                        order.setZt("报告核收");
                    }
                    if (null != lastTime) {
                        //已打印6
                        order.setZt("已打印");
                    }
                }
            }
        }
        ExcelUtil<TjOrder> util = new ExcelUtil<TjOrder>(TjOrder.class);
        util.exportExcel(response, list, "体检记录数据");
    }
@@ -991,18 +1123,18 @@
        TjCustomer tjCustomer = tjCustomerService.getOne(wq);
        if (tjCustomer == null) return AjaxResult.error("该客户未登记");
        LambdaQueryWrapper<TjOrder> wqq = new LambdaQueryWrapper<>();
        wqq.eq(TjOrder::getUserId, tjOrder.getUserId());
        wqq.eq(TjOrder::getCheckStatus, 0);
        wqq.isNull(TjOrder::getFinishTime);
//        if (!tjCustomer.getCardId().equals("0")) {
        wqq.eq(TjOrder::getCardId, tjCustomer.getCardId());
//        LambdaQueryWrapper<TjOrder> wqq = new LambdaQueryWrapper<>();
//        wqq.eq(TjOrder::getUserId, tjOrder.getUserId());
//        wqq.eq(TjOrder::getCheckStatus, 0);
//        wqq.isNull(TjOrder::getFinishTime);
////        if (!tjCustomer.getCardId().equals("0")) {
//        wqq.eq(TjOrder::getCardId, tjCustomer.getCardId());
////        }
//        TjOrder order = tjOrderService.getOne(wqq);
//        if (null != order) {
//            transitionService.deletedTbTransitionListByCusIdAndTjNum(tjCustomer.getCusIdcard(), tjCustomer.getCardId());
//            return AjaxResult.error("不可重复登记");
//        }
        TjOrder order = tjOrderService.getOne(wqq);
        if (null != order) {
            transitionService.deletedTbTransitionListByCusIdAndTjNum(tjCustomer.getCusIdcard(), tjCustomer.getCardId());
            return AjaxResult.error("不可重复登记");
        }
        TjFlowingWater tjFlowingWater = new TjFlowingWater();
        LambdaQueryWrapper<TjReservation> wq1 = new LambdaQueryWrapper<>();
        wq1.eq(TjReservation::getIdCard, tjCustomer.getCusIdcard());
@@ -1021,34 +1153,28 @@
                return AjaxResult.error("对不起您的预约已超时请重新预约");
            }
            if (null != tjReservation.getTeamNo()) tjOrder.setTeamNo(tjReservation.getTeamNo());
//            if (null != tjReservation.getCompanyId()) tjOrder.setFirmId(tjReservation.getCompanyId());
//            if (null != tjReservation.getCompany()) tjOrder.setFirmName(tjReservation.getCompany());
            if (null != tjReservation.getCompanyId()) tjOrder.setFirmId(tjReservation.getCompanyId());
            if (null != tjReservation.getCompany()) tjOrder.setFirmName(tjReservation.getCompany());
            if (null != tjReservation.getDepartment()) tjOrder.setFirmDeptName(tjReservation.getDepartment());
            if (null != tjReservation.getJobNo()) tjOrder.setFirmWorkId(tjReservation.getJobNo());
            if (null != tjReservation.getPacId()) tjOrder.setPacId(tjReservation.getPacId());
            if (null != tjReservation.getTjCategory()) tjOrder.setTjCategory(tjReservation.getTjCategory());
            if (null != tjReservation.getGroupingId()) {
                TjDwGrouping dwGrouping = dwGroupingService.getById(tjReservation.getGroupingId());
                tjOrder.setGroupId(tjReservation.getGroupingId());
                tjOrder.setFirmDeptId(tjReservation.getPacId());
                tjOrder.setFirmDeptId(dwGrouping.getDwDeptId());
            }
            tjReservation.setIsExpire(1);
            tjReservationService.updateById(tjReservation);
            if (null != tjReservation.getTeamNo() && tjOrder.getTjType().equals("1")) {
            if (null != tjReservation.getTeamNo()) {
                tjOrder.setTjType("1");
            } else if (tjOrder.getTjType().equals("2")) {
                tjOrder.setTjType("2");
            }
        }
        if (null != tjCustomer.getCompName()) {
            tjOrder.setFirmName(tjCustomer.getCompName());
        }
        if (null != tjCustomer.getDictCompId()) {
            tjOrder.setFirmId(String.valueOf(tjCustomer.getDictCompId()));
        } else {
        if (StringUtil.isBlank(tjOrder.getFirmId())) {
            tjOrder.setFirmId("0");
        }
        if (null != tjOrder.getPhoto()) {
            File file = new File(tjOrder.getPhoto());
@@ -1088,19 +1214,66 @@
                tjOrderService.tjQiandaodengji(tjOrder.getTjNumber());
                return result;
            }
        } finally {
        }catch (Exception e){
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            log.error(String.valueOf(e));
        }
        finally {
            lock.unlock();
        }
        return AjaxResult.error();
    }
    @Transactional(propagation = Propagation.REQUIRES_NEW, isolation = Isolation.READ_COMMITTED)
//    @Transactional(propagation = Propagation.REQUIRES_NEW, isolation = Isolation.READ_COMMITTED)
    @Transactional(propagation = Propagation.REQUIRED) // 共享事务
    public AjaxResult processOrderWithTransaction(TjOrder tjOrder, TjCustomer tjCustomer, TjReservation tjReservation, TjFlowingWater tjFlowingWater, MallOrder mallOrder, SysUser sysUser) {
        //生成体检号
        String tjNumber = (SecurityUtils.getUsername() + new SimpleDateFormat("yyMMddHHmmss").format(new Date()));
        tjOrder.setTjNumber(tjNumber);
        BigDecimal discount = BigDecimal.valueOf(Double.parseDouble(tjOrder.getTjFlowingWater().getDiscount()));
        //获取拼接前缀
        String sfkqtjhqz = configService.selectConfigByKey("sfkqtjhqz");
        String makeLisTmhPrefix = "";
        if(sfkqtjhqz.equalsIgnoreCase("Y")){
             makeLisTmhPrefix = configService.selectConfigByKey("make_lis_tmh_prefix");
        }
        //生成体检号
//        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();
        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);
        BigDecimal discount = BigDecimal.valueOf(Double.parseDouble(tjOrder.getTjFlowingWater().getDiscount()));
        tjOrder.setDiscount(discount.toString());
        if (tjOrderService.save(tjOrder)) {
            //保存收货地址
@@ -1143,10 +1316,10 @@
            tjFlowingWater.setDiscount(discount.toString());
            BigDecimal subtract = paidIn.subtract(copeWith.multiply(discount.divide(BigDecimal.valueOf(10))));
            log.info("签到登记体检人: "+tjOrder.getTjNumber()+" 应付: "+copeWith);
            log.info("签到登记体检人: "+tjOrder.getTjNumber()+" 折扣: "+discount);
            log.info("签到登记体检人: "+tjOrder.getTjNumber()+" 实付: "+paidIn);
            log.info("签到登记体检人: "+tjOrder.getTjNumber()+" 相差: "+subtract);
            log.info("签到登记体检人: " + tjOrder.getTjNumber() + " 应付: " + copeWith);
            log.info("签到登记体检人: " + tjOrder.getTjNumber() + " 折扣: " + discount);
            log.info("签到登记体检人: " + tjOrder.getTjNumber() + " 实付: " + paidIn);
            log.info("签到登记体检人: " + tjOrder.getTjNumber() + " 相差: " + subtract);
            if (isPay.equals("true")) {
                if (null != mallOrder) {
@@ -1180,7 +1353,7 @@
            //修改每项的原价现价
//            transitionService.updateTbTransitionPriceByCusId(tjCustomer.getCusIdcard(), discount, tjOrder.getTjNumber());
            //修改临时表体检号
            transitionService.updateTbTransitionTjNumByCusId(tjCustomer.getCusIdcard(),tjOrder.getTjNumber());
            transitionService.updateTbTransitionTjNumByCusId(tjCustomer.getCusIdcard(), tjOrder.getTjNumber());
            //补差价
    /*        if(subtract.compareTo(BigDecimal.ZERO)>0){
                tjFlowingWater.setPaidIn(paidIn.add(subtract));
@@ -1201,6 +1374,23 @@
            /*调用his接口*/
            String config = configService.selectConfigByKey("sfkqdyhis");
            if (null != config && config.equals("Y")) {
                if(tjCustomer.getPationId().equals("0")){
                    AjaxResult result = controller.Outpincreateapply(tjCustomer);
                    String result1 = getAjaxResult(result);
                    JSONObject object = getJSONObject(result1);
                    String code = object.getStr("ResultCode");
                    if (code.equals("0")) {
                        JSONArray resultDatass = object.getJSONArray("ResultData");
                        Map<String, Object> resultData = (Map<String, Object>) resultDatass.get(0);
                        if (null != resultData && !resultData.isEmpty()) {
                            String pationid = resultData.get("PationId").toString();
                            if (null != pationid) {
                                tjCustomer.setPationId(pationid);
                                tjCustomerService.updateById(tjCustomer);
                            }
                        }
                    }
                }
                AjaxResult result = hisApiMethod.HisApiMethods(tjCustomer, tjOrder);
                if (!result.get("code").toString().equals("200")) {
                    TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
@@ -1209,40 +1399,39 @@
                        hisApiMethod.ZfHisApiMethod(jzh.toString());
                    }
                    log.info("该登记人挂号失败, 就诊号为: " + tjOrder.getCardId());
                    return AjaxResult.error("挂号失败!" + result.get("msg").toString());
                    throw new IllegalStateException("挂号失败!" + result.get("msg").toString());
                }
                log.info("该登记人的his就诊号是: " + tjOrder.getCardId());
                //团体
/*                if ("1".equals(tjOrder.getTjType())) {
//                            asyncService.ttextracted(tjOrder, tjCustomer, sysUser, tjReservation, tjFlowingWater);
                    ttextracted(tjOrder, tjCustomer, sysUser, tjReservation, tjFlowingWater);
                }*/
                //个人
         /*       if ("2".equals(tjOrder.getTjType())) {
                    //asyncService.newSaveextracted(tjOrder, tjCustomer, discount, sysUser, tjReservation, tjFlowingWater);
                    newSaveextracted(tjOrder, tjCustomer, discount, sysUser, tjReservation, tjFlowingWater);
                }*/
                // 查询 对接Lis、Pacs申请如果类型包含在配置内则使用对接lis、pacs
                if (lisApiMethod.isUseLisAndPacsRegister(tjOrder)) {
                    // 这是上面个人方法引入数据
                    tjFlowingWater.setPayStasus(1L);
                    newSaveextracted(tjOrder, tjCustomer, discount, sysUser, tjReservation, tjFlowingWater);
                    AjaxResult ajaxResult = hisApiMethod.tijianshenqing(tjCustomer, DateUtil.format(date1, "yyyy-MM-dd HH:mm:ss"), tjOrder, sysUser, result);
                    if (!ajaxResult.get("code").toString().equals("200")) return ajaxResult;
                    tjOrderDetailService.updateTjOrderDetailsByOrderId(String.valueOf(tjOrder.getOrderId()),
                            sysUser.getNickName(), String.valueOf(sysUser.getUserId()), String.valueOf(tjFlowingWater.getTjSerialNumber()));
                    remarkService.updateTjOrderRemarkSfbzByJxbzisnull(tjOrder.getOrderId().toString(), tjFlowingWater.getTjSerialNumber().toString());
                    List<TjXdPicture> xdPictureList = xdPictureService.saveTjXdPicture(tjOrder.getTjNumber());
                    xdPictureService.saveBatch(xdPictureList);
                    List<TjOrderDetail> detailList = tjOrderDetailService.getCaiYangDengJi(tjOrder.getOrderId());
                    addCaiYangDengJi(detailList, !detailList.isEmpty(), tjOrder, sysUser, null);
                } else {
                    newSaveextracted(tjOrder, tjCustomer, discount, sysUser, tjReservation, tjFlowingWater);
                    List<TjOrderDetail> detailList = tjOrderDetailService.getCaiYangDengJi(tjOrder.getOrderId());
                    addCaiYangDengJi(detailList, !detailList.isEmpty(), tjOrder, sysUser, null);
                    hisApiMethod.tijianshenqing(tjCustomer, DateUtil.format(date1, "yyyy-MM-dd HH:mm:ss"), tjOrder.getCardId());
                try {
                    if (lisApiMethod.isUseLisAndPacsRegister(tjOrder)) {
                        log.info("调用his开启 进入不收费方法 该体检人员不收费:"+tjOrder.getTjNumber());
                        // 这是上面个人方法引入数据
                        tjFlowingWater.setPayStasus(1L);
                        newSaveextracted(tjOrder, tjCustomer, discount, sysUser, tjReservation, tjFlowingWater);
                        AjaxResult ajaxResult = hisApiMethod.tijianshenqing(tjCustomer, DateUtil.format(date1, "yyyy-MM-dd HH:mm:ss"), tjOrder, sysUser, result);
                        if (!ajaxResult.get("code").toString().equals("200")) return ajaxResult;
                        tjOrderDetailService.updateTjOrderDetailsByOrderId(String.valueOf(tjOrder.getOrderId()),
                                sysUser.getNickName(), String.valueOf(sysUser.getUserId()), String.valueOf(tjFlowingWater.getTjSerialNumber()));
                        remarkService.updateTjOrderRemarkSfbzByJxbzisnull(tjOrder.getOrderId().toString(), tjFlowingWater.getTjSerialNumber().toString());
                        List<TjXdPicture> xdPictureList = xdPictureService.saveTjXdPicture(tjOrder.getTjNumber());
                        xdPictureService.saveBatch(xdPictureList);
                        List<TjOrderDetail> detailList = tjOrderDetailService.getCaiYangDengJi(tjOrder.getOrderId());
                        addCaiYangDengJi(detailList, !detailList.isEmpty(), tjOrder, sysUser, null);
                        log.info("调用his开启 进入不收费方法 该方法执行完毕");
                    } else {
                        log.info("调用his开启 进入收费方法 该体检人员收费:"+tjOrder.getTjNumber());
                        newSaveextracted(tjOrder, tjCustomer, discount, sysUser, tjReservation, tjFlowingWater);
                        List<TjOrderDetail> detailList = tjOrderDetailService.getCaiYangDengJi(tjOrder.getOrderId());
                        addCaiYangDengJi(detailList, !detailList.isEmpty(), tjOrder, sysUser, null);
                        String isUseMx = configService.selectConfigByKey("jcxhis_is_use_mx");
                        if (isUseMx.equalsIgnoreCase("Y"))
                            hisApiMethod.tijianshenqing(tjCustomer, DateUtil.format(date1, "yyyy-MM-dd HH:mm:ss"), tjOrder.getCardId());
                        else hisApiMethod.tijianshenqingJinchuanNew(tjCustomer, DateUtil.format(date1, "yyyy-MM-dd HH:mm:ss"), tjOrder.getCardId());
                    }
                } catch (Exception e) {
                    log.error(String.valueOf(e),e.getMessage());
                    throw new IllegalStateException();
                }
                return AjaxResult.success(tjNumber);
            } else {
@@ -1339,196 +1528,258 @@
            // 查询 对接Lis、Pacs申请如果类型包含在配置内则使用对接lis、pacs
            log.info("签到登记接口该人员: "+tjOrder.getTjNumber()+" 的体检类型是:"+tjOrder.getTjType());
            if (lisApiMethod.isUseLisAndPacsRegister(tjOrder)) {
                // 这是上面个人方法引入数据
                tjFlowingWater.setPayStasus(1L);
                newSaveextracted(tjOrder, tjCustomer, discount, sysUser, tjReservation, tjFlowingWater);
                tjOrderDetailService.updateTjOrderDetailsByOrderId(String.valueOf(tjOrder.getOrderId()),
                        sysUser.getNickName(), String.valueOf(sysUser.getUserId()), String.valueOf(tjFlowingWater.getTjSerialNumber()));
                remarkService.updateTjOrderRemarkSfbzByJxbzisnull(tjOrder.getOrderId().toString(), tjFlowingWater.getTjSerialNumber().toString());
                List<TjXdPicture> xdPictureList = xdPictureService.saveTjXdPicture(tjOrder.getTjNumber());
                xdPictureService.saveBatch(xdPictureList);
                List<TjOrderDetail> detailList = tjOrderDetailService.getCaiYangDengJi(tjOrder.getOrderId());
                addCaiYangDengJi(detailList, !detailList.isEmpty(), tjOrder, sysUser, null);
                return AjaxResult.success(tjNumber);
            }else {
                newSaveextracted(tjOrder, tjCustomer, discount, sysUser, tjReservation, tjFlowingWater);
                try {
                    log.info(tjOrder.getTjNumber()+"签到登记进入未收费方法");
                    // 这是上面个人方法引入数据
                    tjFlowingWater.setPayStasus(1L);
                    newSaveextracted(tjOrder, tjCustomer, discount, sysUser, tjReservation, tjFlowingWater);
                    tjOrderDetailService.updateTjOrderDetailsByOrderId(String.valueOf(tjOrder.getOrderId()),
                            sysUser.getNickName(), String.valueOf(sysUser.getUserId()), String.valueOf(tjFlowingWater.getTjSerialNumber()));
                    remarkService.updateTjOrderRemarkSfbzByJxbzisnull(tjOrder.getOrderId().toString(), tjFlowingWater.getTjSerialNumber().toString());
                    List<TjXdPicture> xdPictureList = xdPictureService.saveTjXdPicture(tjOrder.getTjNumber());
                    xdPictureService.saveBatch(xdPictureList);
                    List<TjOrderDetail> detailList = tjOrderDetailService.getCaiYangDengJi(tjOrder.getOrderId());
                    log.info(tjOrder.getTjNumber()+"签到登记:采样数据查询个数"+detailList.size());
                    addCaiYangDengJi(detailList, !detailList.isEmpty(), tjOrder, sysUser, null);
                    return AjaxResult.success(tjNumber);
                } catch (Exception e) {
                    log.error(e.getMessage());
                    throw new IllegalStateException(e);
                }
            } else {
                try {
                    log.info(tjOrder.getTjNumber()+"else签到登记进入收费方法");
                    newSaveextracted(tjOrder, tjCustomer, discount, sysUser, tjReservation, tjFlowingWater);
                    isRequestCommonHisApi(tjOrder, tjCustomer, tjFlowingWater);
                } catch (Exception e) {
                    log.error("processOrderWithTransaction 方法异常"+e.getMessage());
                    throw new RuntimeException("调用公共方法失败 强制触发回滚");
//                    return AjaxResult.error();
                }
//                if (error != null) return error;
//                List<TjOrderDetail> detailList = tjOrderDetailService.getCaiYangDengJi(tjOrder.getOrderId());
//                addCaiYangDengJi(detailList, !detailList.isEmpty(), tjOrder, sysUser, null);
            }
            String s = configService.selectConfigByKey("is_request_common_his_api");
            if (null != s && s.equals("Y")) {
                String apiUrl = configService.selectConfigByKey("common_api_url");
                String hospbm = configService.selectConfigByKey("common_api_service_hospbm");
                HashMap<String, Object> map = new HashMap<>();
                map.put("pationId", tjCustomer.getPationId());
                map.put("cardId", tjCustomer.getHisJzkh());
                map.put("tjNum", tjFlowingWater.getTjSerialNumber());
                map.put("kaiDanKs", "7805");
                // 收费标志 1待售费 2待退费
                map.put("shouTuiStatus", "1");
                JSONArray array = JSONUtil.createArray();
                LambdaQueryWrapper<TbTransition> wrapper = new LambdaQueryWrapper<>();
                wrapper.eq(TbTransition::getTjNum, tjOrder.getTjNumber());
                wrapper.eq(TbTransition::getCusId, tjCustomer.getCusIdcard());
                wrapper.eq(TbTransition::getCardId, tjCustomer.getCardId());
                wrapper.isNotNull(TbTransition::getOrdPrice);
                wrapper.gt(TbTransition::getOrdPrice, 0);
                List<TbTransition> list = tbTransitionService.list(wrapper);
                for (TbTransition transition : list) {
                    LambdaQueryWrapper<TjProject> wrapper1 = new LambdaQueryWrapper<>();
                    wrapper1.eq(TjProject::getProId, transition.getProId());
                    TjProject project = projectService.getOne(wrapper1);
                    LambdaQueryWrapper<SysDept> wrapper2 = new LambdaQueryWrapper<>();
                    wrapper2.eq(SysDept::getDeptId, project.getDeptId());
                    SysDept dept = sysDeptService.getOne(wrapper2);
                    JSONObject obj = JSONUtil.createObj();
                    Integer sl = project.getSl();
                    BigDecimal danjia = transition.getOrdPrice();
                    BigDecimal allPrice = danjia.multiply(new BigDecimal(sl));
                    obj.putOpt("danJia", danjia);
                    obj.putOpt("jieSuanJe", allPrice);
                    obj.putOpt("shuliang", sl);
                    obj.putOpt("zhiXingKs", dept.getDeptId());
                    obj.putOpt("zhiXingKsMc", dept.getDeptName());
                    obj.putOpt("shouFeiXmId", project.getHisXmbm());
                    obj.putOpt("shouFeiXmMc", project.getHisXmmc());
//                        obj.putOpt("zhiXingKs","7805");
//                        obj.putOpt("zhiXingKsMc","体检科");
//                        obj.putOpt("shouFeiXmId","4735346");
//                        obj.putOpt("shouFeiXmMc","体检费");
                    array.add(obj);
                }
                map.put("feiYongInfoList", array);
                String post = HttpClientUtils.sendPost(apiUrl + "/api/his/" + hospbm + "/creatCostInfo", map);
                JSONObject object = JSONUtil.parseObj(post);
                if (object.getInt("code") == 200) {
                    JSONObject data = object.getJSONObject("data");
                    tjFlowingWater.setHisWaterId(data.getStr("feiYongId"));
                    JSONArray mxList = data.getJSONArray("mxList");
                    if (mxList != null && !mxList.isEmpty()) {
                        List<TjFlowingWaterHis> his = mxList.toList(TjFlowingWaterHis.class);
                        tjFlowingWaterHisService.saveBatch(his);
                    }
                    tjFlowingWaterService.updateById(tjFlowingWater);
                } else {
                    TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                    return AjaxResult.error();
                }
            }
            return AjaxResult.success(tjNumber);
//            pacsApiMethodService.OrderAdd(tjCustomer,tjOrder);
//            return AjaxResult.success(tjNumber);
        }
        TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
        return AjaxResult.error();
//        TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
        throw new RuntimeException("体检记录保存失败 强制触发回滚");
    }
    public void addCaiYangDengJi(List<TjOrderDetail> detailList, boolean detailList1, TjOrder order, SysUser sysUser, String jxbz) {
        String lis_tmh_prefix = configService.selectConfigByKey("make_lis_tmh_prefix");
        if (null != detailList && detailList1) {
            Date date = new Date();
            String format = DateUtil.format(date, "yyMMddHHmmssSSS");
            for (TjOrderDetail detail : detailList) {
                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);
                    sampling.setJyxmdm(project.getProId().toString());
                } else {
                    TjProject project1 = projectService.getById(proParentId);
                    sampling.setJyxh(idUtils.generateLisID(lis_tmh_prefix));
    @Transactional(propagation = Propagation.REQUIRED) // 共享事务
    public void isRequestCommonHisApi(TjOrder tjOrder, TjCustomer tjCustomer, TjFlowingWater tjFlowingWater) {
        String s = configService.selectConfigByKey("is_request_common_his_api");
        if (null != s && s.equals("Y")) {
            String apiUrl = configService.selectConfigByKey("common_api_url");
            String hospbm = configService.selectConfigByKey("common_api_service_hospbm");
            HashMap<String, Object> map = new HashMap<>();
            map.put("pationId", tjCustomer.getPationId());
            map.put("cardId", tjCustomer.getHisJzkh());
            map.put("tjNum", tjFlowingWater.getTjSerialNumber());
            map.put("kaiDanKs", "7805");
            // 收费标志 1待售费 2待退费
            map.put("shouTuiStatus", "1");
                    sampling.setSpecimenTypeCode(project1.getSpecimenType());
                    sampling.setSpecimenType(dictLabel);
                    sampling.setJyxmdm(project.getProId().toString());
            JSONArray array = JSONUtil.createArray();
            LambdaQueryWrapper<TbTransition> wrapper = new LambdaQueryWrapper<>();
            wrapper.eq(TbTransition::getTjNum, tjOrder.getTjNumber());
            wrapper.eq(TbTransition::getCusId, tjCustomer.getCusIdcard());
            wrapper.eq(TbTransition::getCardId, tjCustomer.getCardId());
            wrapper.isNotNull(TbTransition::getNowPrice);
            wrapper.gt(TbTransition::getNowPrice, 0);
            List<TbTransition> list = tbTransitionService.list(wrapper);
            BigDecimal zongjia = new BigDecimal("0.0");
            for (TbTransition transition : list) {
                LambdaQueryWrapper<TjProject> wrapper1 = new LambdaQueryWrapper<>();
                wrapper1.eq(TjProject::getProId, transition.getProId());
                TjProject project = projectService.getOne(wrapper1);
                LambdaQueryWrapper<SysDept> wrapper2 = new LambdaQueryWrapper<>();
                wrapper2.eq(SysDept::getDeptId, project.getDeptId());
                SysDept dept = sysDeptService.getOne(wrapper2);
                JSONObject obj = JSONUtil.createObj();
//                Integer sl = project.getSl();
                int sl = 1;
                BigDecimal danjia = transition.getNowPrice();
                BigDecimal allPrice = danjia.multiply(new BigDecimal(sl));
                obj.putOpt("danJia", danjia);
                obj.putOpt("jieSuanJe", allPrice);
                obj.putOpt("shuliang", sl);
                obj.putOpt("zhiXingKs", dept.getDeptId());
                obj.putOpt("zhiXingKsMc", dept.getDeptName());
                obj.putOpt("shouFeiXmId", project.getHisXmbm());
                obj.putOpt("shouFeiXmMc", project.getHisXmmc());
                array.add(obj);
                zongjia = zongjia.add(allPrice);
            }
            map.put("feiYongInfoList", array);
            log.info("调用His接口前 收费总价:{}", zongjia.toString());
            String post = HttpClientUtils.sendPost(apiUrl + "/api/his/" + hospbm + "/creatCostInfo", map);
            JSONObject object = JSONUtil.parseObj(post);
            if (object.getInt("code") == 200) {
                JSONObject data = object.getJSONObject("data");
                tjFlowingWater.setHisWaterId(data.getStr("feiYongId"));
                JSONArray mxList = data.getJSONArray("mxList");
                if (mxList != null && !mxList.isEmpty()) {
                    List<TjFlowingWaterHis> his = mxList.toList(TjFlowingWaterHis.class);
                    tjFlowingWaterHisService.saveBatch(his);
                }
                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);
                tjFlowingWaterService.updateById(tjFlowingWater);
            } else {
//                TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                log.error("isRequestCommonHisApi 方法异常");
                throw new RuntimeException("is_request_common_his_api 强制触发回滚");
//                return AjaxResult.error();
            }
        }
        String config = configService.selectConfigByKey("sfkqdyhis");
        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);
//        return null;
    }
    @Transactional(propagation = Propagation.REQUIRED) // 共享事务
    public void addCaiYangDengJi(List<TjOrderDetail> detailList, boolean detailList1, TjOrder order, SysUser sysUser, String jxbz) {
        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()));
            }
        } catch (Exception e) {
            log.error(e.getMessage());
        }
        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()));
    }
    @GetMapping("/addCaiYangDengJi")
    @ApiOperation(value = "手动添加采样记录接口")
    public AjaxResult addCaiYangDengJi(@RequestParam("tjNum") String tjNum){
        try {
            TjOrder order = tjOrderService.getOrderByTjNum(tjNum);
            if(null !=order){
                Long userId = Long.valueOf(SecurityUtils.getLoginUser().getUserId());
                SysUser sysUser = userService.getById(userId);
                List<TjOrderDetail> detailList = tjOrderDetailService.getCaiYangDengJi(order.getOrderId());
                log.info("签到登记:采样数据查询个数"+detailList.size());
                addCaiYangDengJi(detailList, !detailList.isEmpty(), order, sysUser, null);
            }
        } catch (NumberFormatException e) {
            log.error(String.valueOf(e));
        }
        return AjaxResult.success();
    }
    @PostMapping("/addPlOrderAndDetail")
    @ApiOperation(value = "体检批量签到登记接口")
    @Transactional  //(切换数据库出错,所以注释)
//    @Transactional  //(切换数据库出错,所以注释)
    public AjaxResult addPlOrderAndDetail(@RequestBody QianDaoDto daoDto, HttpServletResponse response) {
        SysUser sysUser = UserHoder.getLoginUser().getUser();
        List<String> cusIds = daoDto.getCusIds();
        ArrayList<String> tjNumbers = new ArrayList<>();
        ArrayList<String> errTjh = new ArrayList<>();
        if (null != cusIds && !cusIds.isEmpty()) {
            ExecutorService threadPools = Executors.newFixedThreadPool(cusIds.size());
            for (String cusId : cusIds) {
                threadPools.execute(new Runnable() {
                    @Override
                    public void run() {
                        getAjaxResults(cusId);
                    }
                });
//                threadPools.execute(new Runnable() {
//                    @Override
//                    public void run() {
                        try {
                            getAjaxResults(cusId);
                        } catch (Exception e) {
                        }
//                    }
//                });
            }
            LambdaQueryWrapper<TjCustomer> wq = new LambdaQueryWrapper<>();
            wq.in(TjCustomer::getCusIdcard, cusIds);
@@ -1548,6 +1799,7 @@
//                            }
//                        }
//                    });
                    Future<AjaxResult> future = executor.submit(new Callable<AjaxResult>() {
                        @Override
                        public AjaxResult call() throws Exception {
@@ -1556,61 +1808,45 @@
                    });
                    try {
                        AjaxResult result = future.get();
                        String tjNumber = result.get("tjNumber").toString();
                        tjNumbers.add(tjNumber);
                        String code = result.get("code").toString();
                        if (code.equals("200")) {
                            String tjNumber = result.get("tjNumber").toString();
                            tjNumbers.add(tjNumber);
                        }else {
                            String userId = result.get("userId").toString();
                            errTjh.add(userId);
                        }
                    } catch (InterruptedException | ExecutionException e) {
//                        TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                        e.printStackTrace();
                    }
                }
                threadPools.shutdown();
            }
        }
        // TODO 因为有体检号会查出空数据 先使用死数据
        tjNumbers = new ArrayList<>();
        tjNumbers.add("02095240229171627");
        tjNumbers.add("02095240229173104");
        tjNumbers.add("10001240524172002");
        tjNumbers.add("10001240304124410");
        tjNumbers.add("00325240304160123");
        tjNumbers.add("02095240304162044");
        tjNumbers.add("02095240304162152");
        tjNumbers.add("10001240304163505");
        Map<String, Object> map = null;
        try {
            map = PDFDocumentUtil.getDocument();
            Document document = (Document) map.get("document");
            for (int i = 0; i < tjNumbers.size(); i++) {
                try {
                    List<Map<String, String>> djdInfos = tjOrderService.selectDjdInfo(tjNumbers.get(i));
                    Map<String, Object> userInfo = tjOrderService.selectDjdUserInfo(tjNumbers.get(i));
                    LocalDateTime tjsj = (LocalDateTime) userInfo.get("tjsj");
                    DateTimeFormatter dateFormat = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm");
                    String time = null;
                    if (tjsj != null) {
                        time = dateFormat.format(tjsj);
                    }
                    PDFDocumentUtil.makeUserInfoTable(document, (String) userInfo.get("tjname"), (String) userInfo.get("sex")
                            , (String) userInfo.get("tjh"), (String) userInfo.get("lxdh"), (String) userInfo.get("tjname"), time);
                    PDFDocumentUtil.makeTjInfo(document, djdInfos);
                    // 多条则换页
                    if (i + 1 < tjNumbers.size()) {
                        document.newPage();
                    }
                } catch (DocumentException | IOException e) {
                    e.printStackTrace();
                }
            // TODO 因为有体检号会查出空数据 先使用死数据  打印导诊单
            Map<String,Object> map=new HashMap<>();
            if (!tjNumbers.isEmpty()) {
                map.put("tjh",tjNumbers);
            }
            document.close();
            ByteArrayOutputStream outputStream = (ByteArrayOutputStream) map.get("stream");
            String encodeToString = java.util.Base64.getEncoder().encodeToString(outputStream.toByteArray());
            return AjaxResult.success().put("file", encodeToString);
        } catch (IOException | DocumentException e) {
            e.printStackTrace();
            map.put("errtjh",errTjh);
            return AjaxResult.success("操作成功",map);
        }
        return AjaxResult.success("操作成功");
//        TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
        return AjaxResult.error();
    }
    private void getAjaxResults(String cusIdcard) {
    @GetMapping("/signOrderInfo")
    public AjaxResult signOrderInfo(@RequestParam("tjNum") String tjNum){
        List<Map<String, Object>> djdInfos = tjOrderService.selectDjdInfo(tjNum);
        Map<String, Object> userInfo = tjOrderService.selectDjdUserInfo(tjNum);
        HashMap<String, Object> hashMap = new HashMap<>();
        hashMap.put("djd",djdInfos);
        hashMap.put("user",userInfo);
        return AjaxResult.success(hashMap);
    }
    @Transactional
    public void getAjaxResults(String cusIdcard) {
        if (!"".equals(cusIdcard) && cusIdcard != null) {
            //根据配置调取存储过程 将临时表数据存入预约表2023.12.12
            final String getInfoFromSqlData = configService.selectConfigByKey("getInfoFromSqlData");
@@ -1672,51 +1908,59 @@
                    tjReservationService.updateById(tjReservation);
//                    return AjaxResult.error("对不起您的预约已超时请重新预约");
                }*/
                LambdaQueryWrapper<TjCustomer> qw = new LambdaQueryWrapper<>();
                qw.eq(TjCustomer::getCusIdcard, cusIdcard);
                TjCustomer tjCustomer1 = tjCustomerService.getOne(qw);
                if (tjCustomer1 != null) {
                    tjCustomer1.setTjType(tjReservation.getTjType());
                    tjCustomer1.setCusName(tjReservation.getName());
                    tjCustomer1.setCusSex(Long.valueOf(tjReservation.getSex()));
                    tjCustomer1.setCusBrithday(tjReservation.getBirthday());
                    tjCustomer1.setCusPhone(tjReservation.getPhoe());
                    tjCustomer1.setCusEmail(tjReservation.getEmail());
                    tjCustomer1.setCusAddr(tjReservation.getAddress());
                    tjCustomer1.setCusMarryStatus(String.valueOf(tjReservation.getMarriage()));
                    tjCustomer1.setCusNational(String.valueOf(tjReservation.getNation()));
                    tjCustomer1.setIdType(tjReservation.getIdType());
                    tjCustomer1.setAge(tjReservation.getAge());
                    tjCustomer1.setAgeUnit(tjReservation.getAgeUnit());
                    tjCustomer1.setCareer(tjReservation.getCareer());
                    tjCustomerService.updateById(tjCustomer1);
                } else {
                    TjCustomer tjCustomer = new TjCustomer();
                    tjCustomer.setCusIdcard(tjReservation.getIdCard());
                    tjCustomer.setCusName(tjReservation.getName());
                    tjCustomer.setCusSex(Long.valueOf(tjReservation.getSex()));
                    tjCustomer.setCusBrithday(tjReservation.getBirthday());
                    tjCustomer.setCusPhone(tjReservation.getPhoe());
                    tjCustomer.setCusEmail(tjReservation.getEmail());
                    tjCustomer.setCusAddr(tjReservation.getAddress());
                    tjCustomer.setCusMarryStatus(String.valueOf(tjReservation.getMarriage()));
                    tjCustomer.setCusNational(String.valueOf(tjReservation.getNation()));
                    tjCustomer.setIdType(tjReservation.getIdType());
                    tjCustomer.setAge(tjReservation.getAge());
                    tjCustomer.setAgeUnit(tjReservation.getAgeUnit());
                    tjCustomer.setCareer(tjReservation.getCareer());
                    tjCustomer.setDwPhone(tjReservation.getDwPhone());
                    tjCustomer.setCardId(tjReservation.getCardId());
                    tjCustomer.setIndexCard(tjReservation.getIndexCard());
                    //截取密码自动生成set进去
                    String substring = cusIdcard.substring(cusIdcard.length() - 6);
                    substring = DigestUtils.md5DigestAsHex(substring.getBytes());
                    tjCustomer.setCusPassword(substring);
                    tjCustomer.setTjType(tjReservation.getTjType());
                    tjCustomerService.save(tjCustomer);
                try {
                    LambdaQueryWrapper<TjCustomer> qw = new LambdaQueryWrapper<>();
                    qw.eq(TjCustomer::getCusIdcard, cusIdcard);
                    TjCustomer tjCustomer1 = tjCustomerService.getOne(qw);
                    if (tjCustomer1 != null) {
                        tjCustomer1.setTjType(tjReservation.getTjType());
                        tjCustomer1.setCusName(tjReservation.getName());
                        tjCustomer1.setCusSex(Long.valueOf(tjReservation.getSex()));
                        tjCustomer1.setCusBrithday(tjReservation.getBirthday());
                        tjCustomer1.setCusPhone(tjReservation.getPhoe());
                        tjCustomer1.setCusEmail(tjReservation.getEmail());
                        tjCustomer1.setCusAddr(tjReservation.getAddress());
                        tjCustomer1.setCusMarryStatus(String.valueOf(tjReservation.getMarriage()));
                        tjCustomer1.setCusNational(String.valueOf(tjReservation.getNation()));
                        tjCustomer1.setIdType(tjReservation.getIdType());
                        tjCustomer1.setAge(tjReservation.getAge());
                        tjCustomer1.setAgeUnit(tjReservation.getAgeUnit());
                        tjCustomer1.setCareer(tjReservation.getCareer());
                        tjCustomerService.updateById(tjCustomer1);
                    } else {
                        TjCustomer tjCustomer = new TjCustomer();
                        tjCustomer.setCusIdcard(tjReservation.getIdCard());
                        tjCustomer.setCusName(tjReservation.getName());
                        tjCustomer.setCusSex(Long.valueOf(tjReservation.getSex()));
                        tjCustomer.setCusBrithday(tjReservation.getBirthday());
                        tjCustomer.setCusPhone(tjReservation.getPhoe());
                        tjCustomer.setCusEmail(tjReservation.getEmail());
                        tjCustomer.setCusAddr(tjReservation.getAddress());
                        tjCustomer.setCusMarryStatus(String.valueOf(tjReservation.getMarriage()));
                        tjCustomer.setCusNational(String.valueOf(tjReservation.getNation()));
                        tjCustomer.setIdType(tjReservation.getIdType());
                        tjCustomer.setAge(tjReservation.getAge());
                        tjCustomer.setAgeUnit(tjReservation.getAgeUnit());
                        tjCustomer.setCareer(tjReservation.getCareer());
                        tjCustomer.setDwPhone(tjReservation.getDwPhone());
                        tjCustomer.setCardId(tjReservation.getCardId());
                        tjCustomer.setIndexCard(tjReservation.getIndexCard());
                        //截取密码自动生成set进去
                        String substring = cusIdcard.substring(cusIdcard.length() - 6);
                        substring = DigestUtils.md5DigestAsHex(substring.getBytes());
                        tjCustomer.setCusPassword(substring);
                        tjCustomer.setTjType(tjReservation.getTjType());
                        tjCustomerService.save(tjCustomer);
                    }
                } catch (Exception e) {
                    throw new RuntimeException(e);
                }
            }else {
                throw new RuntimeException();
            }
        }else {
            throw new RuntimeException();
        }
    }
@@ -1744,25 +1988,13 @@
        DynamicDataSourceContextHolder.clearDataSourceType();
    }
    private AjaxResult getAjaxResult(Long userId, SysUser sysUser, String tjCategory) throws IOException {
    @Transactional
    public AjaxResult getAjaxResult(Long userId, SysUser sysUser, String tjCategory) throws IOException {
        LambdaQueryWrapper<TjCustomer> wq = new LambdaQueryWrapper<>();
        wq.eq(TjCustomer::getCusId, userId);
        TjCustomer tjCustomer = tjCustomerService.getOne(wq);
        if (tjCustomer == null) return AjaxResult.error("该客户未登记或不存在");
        LambdaQueryWrapper<TjOrder> wqq = new LambdaQueryWrapper<>();
        wqq.eq(TjOrder::getUserId, userId);
        wqq.eq(TjOrder::getCheckStatus, 0);
        wqq.isNull(TjOrder::getFinishTime);
        if (!tjCustomer.getCardId().equals("0")) {
            wqq.eq(TjOrder::getCardId, tjCustomer.getCardId());
        }
        TjOrder order = tjOrderService.getOne(wqq);
        if (null != order) {
            transitionService.deletedTbTransitionListByCusIdAndTjNum(tjCustomer.getCusIdcard(), tjCustomer.getCardId());
            return AjaxResult.error("不可重复登记");
        }
        TjOrder tjOrder = new TjOrder();
        Date date = new Date();
        tjOrder.setCreateTime(date);
@@ -1779,16 +2011,17 @@
        if (tjReservation != null) {
            tjOrder.setReservationId(tjReservation.getId());
            mallOrder = mallOrderService.getOne(new LambdaQueryWrapper<MallOrder>().eq(MallOrder::getReservationId, tjReservation.getId()));
            if (DateUtil.endOfDay(new Date()).before(tjReservation.getReservationTime())) {
                return AjaxResult.error("未到预约时间");
            }
            if (DateUtil.endOfDay(tjReservation.getReservationTime()).before(new Date())) {
                tjReservation.setIsExpire(1);
                tjReservationService.updateById(tjReservation);
                return AjaxResult.error("对不起您的预约已超时请重新预约");
            }
//            if (DateUtil.endOfDay(new Date()).before(tjReservation.getReservationTime())) {
//                return AjaxResult.error("未到预约时间");
//            }
//            if (DateUtil.endOfDay(tjReservation.getReservationTime()).before(new Date())) {
//                tjReservation.setIsExpire(1);
//                tjReservationService.updateById(tjReservation);
//                return AjaxResult.error("对不起您的预约已超时请重新预约");
//            }
            if (null != tjReservation.getTeamNo()) tjOrder.setTeamNo(tjReservation.getTeamNo());
            if (null != tjReservation.getCompanyId()) tjOrder.setFirmId(tjReservation.getCompanyId());
            if (null != tjReservation.getCompany()) tjOrder.setFirmName(tjReservation.getCompany());
            if (null != tjReservation.getDepartment()) tjOrder.setFirmDeptName(tjReservation.getDepartment());
            if (null != tjReservation.getJobNo()) tjOrder.setFirmWorkId(tjReservation.getJobNo());
            if (null != tjReservation.getPacId()) tjOrder.setPacId(tjReservation.getPacId());
@@ -1799,12 +2032,48 @@
            }
            tjReservation.setIsExpire(1);
            tjReservationService.updateById(tjReservation);
            if (null != tjReservation.getTeamNo()) {
                tjOrder.setTjType("1");
            } else{
                tjOrder.setTjType("2");
            }
        if (StringUtil.isBlank(tjOrder.getFirmId())) {
            tjOrder.setFirmId("0");
        }
//
//            tjReservation.setIsExpire(1);
//            tjReservationService.updateById(tjReservation);
            //生成体检号
            String tjNumber = (sysUser.getUserName() + new SimpleDateFormat("yyMMddHHmmss").format(new Date()));
//            String tjNumber = (sysUser.getUserName() + new SimpleDateFormat("yyMMddHHmmss").format(new Date()));
//            tjNumber = tjNumber.replaceAll(".{6}$", userId.toString().substring(userId.toString().length() - 6));
            tjNumber = tjNumber.replaceAll(".{4}$", userId.toString().substring(userId.toString().length() - 4));
            //获取拼接前缀
            String makeLisTmhPrefix = configService.selectConfigByKey("make_lis_tmh_prefix");
//            String tjNumber = (sysUser.getUserName() + idUtils.getTjNumber());
//            String tjNumber = idUtils.getTjNumber();
            String tjNumber = idUtils.getNewTjNumberRedisLockAndMysql();
            if (StringUtil.isNotBlank(makeLisTmhPrefix)) tjNumber = makeLisTmhPrefix + tjNumber;
//            if (redisCache.hasKey(TJH)) {
//                while (true){
//                    List<String> tjh = redisCache.getCacheList(TJH);
//                    if(tjh.contains(tjNumber)){
//                        tjNumber =(sysUser.getUserName() + IdUtils.getTjNumber());
//                        if (StringUtil.isNotBlank(makeLisTmhPrefix)) tjNumber = makeLisTmhPrefix + tjNumber;
//                    }else {
//                        tjh.add(tjNumber);
//                    }
//                }
//            }else {
//                List<String> stringList = tjOrderService.
//                        list(new LambdaQueryWrapper<TjOrder>().select(TjOrder::getTjNumber)).stream().map(TjOrder::getTjNumber).collect(Collectors.toList());
//                stringList.add(tjNumber);
//                redisCache.setCacheList(TJH,stringList);
//            }
            tjOrder.setTjNumber(tjNumber);
            if (null != tjOrder.getPhoto()) {
                File file = new File(tjOrder.getPhoto());
@@ -1845,6 +2114,21 @@
                tjCustomer.setCusNumber(cusNumber);
//            BigDecimal discount = BigDecimal.valueOf(Double.parseDouble(tjOrder.getTjFlowingWater().getDiscount())).divide(BigDecimal.valueOf(10));
                TjFlowingWater tjFlowingWater = new TjFlowingWater();
                tjFlowingWater.setCreateTime(date);
                tjFlowingWater.setCreateTime(date);
                tjFlowingWater.setUpdateTime(date);
                tjFlowingWater.setCreateBy(sysUser.getNickName());
                tjFlowingWater.setUpdateBy(sysUser.getNickName());
//                BigDecimal bigDecimal = tbTransitionMapper.sumTbTransitionOrdPriceByTjNum(tjOrder.getTjNumber());
                BigDecimal bigDecimal = tbTransitionMapper.sumTbTransitionOrdPriceByTjNumIsNull(tjCustomer.getCusIdcard());
                tjFlowingWater.setCopeWith(bigDecimal);
//                BigDecimal bigDecimal1 = tbTransitionMapper.sumTbTransitionNowPriceByTjNum(tjOrder.getTjNumber());
                BigDecimal bigDecimal1 = tbTransitionMapper.sumTbTransitionNowPriceByTjNumIsNull(tjCustomer.getCusIdcard());
                tjFlowingWater.setPaidIn(bigDecimal1);
                tjFlowingWater.setDiscount(String.valueOf(10));
                tjFlowingWater.setPayStasus(1L);
                tjFlowingWater.setPayType(3L);
                tjFlowingWater.setPayStasus(0L);
                if ("1".equals(tjOrder.getTjType())) {
                    if (tjReservation.getPayType() == 1) {
@@ -1893,18 +2177,37 @@
                if (tjFlowingWaterService.save(tjFlowingWater)) {
                    tjOrder.setTjSerialNumber(String.valueOf(tjFlowingWater.getTjSerialNumber()));
                    tjOrderService.updateById(tjOrder);
                }
                asyncService.ttextracted(tjOrder, tjCustomer, sysUser, tjReservation, tjFlowingWater);
                transitionService.updateTbTransitionTjNumByCusId(tjCustomer.getCusIdcard(), tjOrder.getTjNumber());
                tjCustomer.setCardId(tjOrder.getTjNumber());
                tjCustomerService.updateById(tjCustomer);
                transitionService.updateCardIdByTjNumAndIdCard(tjCustomer.getCusIdcard(), tjOrder.getTjNumber(), tjOrder.getTjNumber());
                tjOrder.setCardId(tjOrder.getTjNumber());
                tjOrderService.updateById(tjOrder);
//                asyncService.ttextracted(tjOrder, tjCustomer, sysUser, tjReservation, tjFlowingWater);
                if (lisApiMethod.isUseLisAndPacsRegister(tjOrder)) {
                    // 这是上面个人方法引入数据
                    tjFlowingWater.setPayStasus(1L);
                    tjOrder.setTjFlowingWater(tjFlowingWater);
                    newSaveextracted(tjOrder, tjCustomer, BigDecimal.valueOf(10), sysUser, tjReservation, tjFlowingWater);
                    tjOrderDetailService.updateTjOrderDetailsByOrderId(String.valueOf(tjOrder.getOrderId()),
                            sysUser.getNickName(), String.valueOf(sysUser.getUserId()), String.valueOf(tjFlowingWater.getTjSerialNumber()));
                    remarkService.updateTjOrderRemarkSfbzByJxbzisnull(tjOrder.getOrderId().toString(), tjFlowingWater.getTjSerialNumber().toString());
                    List<TjXdPicture> xdPictureList = xdPictureService.saveTjXdPicture(tjOrder.getTjNumber());
                    xdPictureService.saveBatch(xdPictureList);
                    List<TjOrderDetail> detailList = tjOrderDetailService.getCaiYangDengJi(tjOrder.getOrderId());
                    addCaiYangDengJi(detailList, !detailList.isEmpty(), tjOrder, sysUser, null);
                }
                tjCustomer.setCardId("0");
                tjCustomerService.updateById(tjCustomer);
                return AjaxResult.success().put("tjNumber", tjNumber);
            }
        }
        return AjaxResult.error();
        TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
        return AjaxResult.error().put("userId",userId);
    }
@@ -1992,6 +2295,17 @@
                        return AjaxResult.error("操作失败! 以下项目已存在: " + string);
                    }
                    transitionService.saveRedisTransitionByPacId(cusId, cardId, pacId);
                    //补差价
                    List<Map<String, Object>> cjMaps = transitionService.addTbhuoquxiangmuchajia(pacId.toString(), cusId);
                    if (null != cjMaps && !cjMaps.isEmpty()) {
                        log.info("该套餐"+pacId+"中有差价:"+cjMaps.size()+"个");
                        for (Map<String, Object> cjMap : cjMaps) {
                            log.info("添加临时表套餐数据时所选的差价为:"+ cjMap.get("cj").toString());
                            transitionService.buxiangmuchajia(cusId, pacId.toString(), cjMap.get("xmid").toString(), new BigDecimal(cjMap.get("cj").toString()));
                        }
                    }
                }
            }
        }
@@ -2677,46 +2991,51 @@
    }
    @Transactional(propagation = Propagation.REQUIRED) // 共享事务
    public void newSaveextracted(TjOrder tjOrder, TjCustomer tjCustomer, BigDecimal discount, SysUser sysUser, TjReservation tjReservation, TjFlowingWater tjFlowingWater) {
        tjAskMedicalHistoryService.updateTjAskMedicalHistoryByCusId(tjOrder.getTjNumber(), sysUser.getNickName(), String.valueOf(sysUser.getUserId()), String.valueOf(tjCustomer.getCusId()));
        if (null != tjOrder.getTjCategory() && tjOrder.getTjCategory().equals("13")) {
            tjOrderDetailService.saveJSYTjOrderDetailsByCusId(tjCustomer.getCusIdcard(),
                    String.valueOf(tjOrder.getOrderId()), sysUser.getNickName(), String.valueOf(sysUser.getUserId()), tjOrder.getCardId(), String.valueOf(tjFlowingWater.getTjSerialNumber()));
        } else {
            tjOrderDetailService.saveTjOrderDetailsByCusId(tjCustomer.getCusIdcard(), String.valueOf(tjOrder.getOrderId()), sysUser.getNickName(), String.valueOf(sysUser.getUserId()), tjOrder.getCardId());
        }
        try {
            tjAskMedicalHistoryService.updateTjAskMedicalHistoryByCusId(tjOrder.getTjNumber(), sysUser.getNickName(), String.valueOf(sysUser.getUserId()), String.valueOf(tjCustomer.getCusId()));
            if (null != tjOrder.getTjCategory() && tjOrder.getTjCategory().equals("13")) {
                tjOrderDetailService.saveJSYTjOrderDetailsByCusId(tjCustomer.getCusIdcard(),
                        String.valueOf(tjOrder.getOrderId()), sysUser.getNickName(), String.valueOf(sysUser.getUserId()), tjOrder.getCardId(), String.valueOf(tjFlowingWater.getTjSerialNumber()));
            } else {
                tjOrderDetailService.saveTjOrderDetailsByCusId(tjCustomer.getCusIdcard(), String.valueOf(tjOrder.getOrderId()), sysUser.getNickName(), String.valueOf(sysUser.getUserId()), tjOrder.getCardId());
            }
        tjOrderDetailService.saveTjPureToneTesByCusId(tjCustomer.getCusIdcard(), tjOrder.getTjNumber(), sysUser.getNickName(), String.valueOf(sysUser.getUserId()), tjOrder.getCardId());
            tjOrderDetailService.saveTjPureToneTesByCusId(tjCustomer.getCusIdcard(), tjOrder.getTjNumber(), sysUser.getNickName(), String.valueOf(sysUser.getUserId()), tjOrder.getCardId());
        //添加remark表数据
        if (null != tjOrder.getTjCategory() && tjOrder.getTjCategory().equals("13")) {
            remarkService.saveJSYTjOrderRemarkByOrderId(tjOrder.getTjNumber(), sysUser.getNickName(), String.valueOf(sysUser.getUserId()), String.valueOf(tjOrder.getOrderId()));
            //添加remark表数据
            if (null != tjOrder.getTjCategory() && tjOrder.getTjCategory().equals("13")) {
                remarkService.saveJSYTjOrderRemarkByOrderId(tjOrder.getTjNumber(), sysUser.getNickName(), String.valueOf(sysUser.getUserId()), String.valueOf(tjOrder.getOrderId()));
        } else {
            remarkService.saveTjOrderRemarkByOrderId(tjOrder.getTjNumber(), sysUser.getNickName(), String.valueOf(sysUser.getUserId()), String.valueOf(tjOrder.getOrderId()));
            } else {
                remarkService.saveTjOrderRemarkByOrderId(tjOrder.getTjNumber(), sysUser.getNickName(), String.valueOf(sysUser.getUserId()), String.valueOf(tjOrder.getOrderId()));
        }
        //判断是否交钱
        if ("1".equals(tjOrder.getTjType())) {
            if (null != tjReservation && tjReservation.getPayType() == 1) {
            }
            //判断是否交钱
            if ("1".equals(tjOrder.getTjType())) {
                if (null != tjReservation && tjReservation.getPayType() == 1) {
                    tjOrderDetailService.updateTjOrderDetailsByOrderId(String.valueOf(tjOrder.getOrderId()),
                            sysUser.getNickName(), String.valueOf(sysUser.getUserId()), String.valueOf(tjFlowingWater.getTjSerialNumber()));
                    remarkService.updateTjOrderRemarkSfbzByJxbzisnull(tjOrder.getOrderId().toString(), tjFlowingWater.getTjSerialNumber().toString());
                    List<TjXdPicture> xdPictureList = xdPictureService.saveTjXdPicture(tjOrder.getTjNumber());
                    xdPictureService.saveBatch(xdPictureList);
                }
            }
            if (tjFlowingWater.getPayStasus() == 1L) {
                tjOrderDetailService.updateTjOrderDetailsByOrderId(String.valueOf(tjOrder.getOrderId()),
                        sysUser.getNickName(), String.valueOf(sysUser.getUserId()), String.valueOf(tjFlowingWater.getTjSerialNumber()));
                tjFlowingWater.setPaidIn(tjOrder.getTjFlowingWater().getPaidIn());
                tjFlowingWater.setCopeWith(tjOrder.getTjFlowingWater().getCopeWith());
                tjFlowingWater.setPayType(4L);
                tjFlowingWaterService.updateById(tjFlowingWater);
                remarkService.updateTjOrderRemarkSfbzByJxbzisnull(tjOrder.getOrderId().toString(), tjFlowingWater.getTjSerialNumber().toString());
    //            asyncService.addTjChargingStandard(tjOrder, transitionService.getTbTransitionListByCusId(tjCustomer.getCusIdcard(), tjOrder.getCardId()), sysUser);
                List<TjXdPicture> xdPictureList = xdPictureService.saveTjXdPicture(tjOrder.getTjNumber());
                xdPictureService.saveBatch(xdPictureList);
            }
        }
        if (tjFlowingWater.getPayStasus() == 1L) {
            tjOrderDetailService.updateTjOrderDetailsByOrderId(String.valueOf(tjOrder.getOrderId()),
                    sysUser.getNickName(), String.valueOf(sysUser.getUserId()), String.valueOf(tjFlowingWater.getTjSerialNumber()));
            tjFlowingWater.setPaidIn(tjOrder.getTjFlowingWater().getPaidIn());
            tjFlowingWater.setCopeWith(tjOrder.getTjFlowingWater().getCopeWith());
            tjFlowingWater.setPayType(4L);
            tjFlowingWaterService.updateById(tjFlowingWater);
            remarkService.updateTjOrderRemarkSfbzByJxbzisnull(tjOrder.getOrderId().toString(), tjFlowingWater.getTjSerialNumber().toString());
//            asyncService.addTjChargingStandard(tjOrder, transitionService.getTbTransitionListByCusId(tjCustomer.getCusIdcard(), tjOrder.getCardId()), sysUser);
            List<TjXdPicture> xdPictureList = xdPictureService.saveTjXdPicture(tjOrder.getTjNumber());
            xdPictureService.saveBatch(xdPictureList);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
@@ -2901,9 +3220,9 @@
            TjReport tjReport = new TjReport();
            tjReport.setTjNumber(String.valueOf(tjNumber));
            tjReport.setPath(urlValue + outputFileName1);
            String outputPath1 = value + File.separator;
            String pdfBinary = getPDFBinary(outputPath1 + outputFileName1);
            tjReport.setReport(pdfBinary);
//            String outputPath1 = value + File.separator;
//            String pdfBinary = getPDFBinary(outputPath1 + outputFileName1);
//            tjReport.setReport(pdfBinary);
            tjReport.setType("体检报告");
            tjReport.setPrint("pdf");
            tjReportService.save(tjReport);
@@ -3040,9 +3359,11 @@
//            }
            if (null != order.getFinishTime()) return AjaxResult.error("该人员已签离,不可撤销!!!");
            Boolean useLisAndPacsRegister = lisApiMethod.isUseLisAndPacsRegister(order);
            String s = configService.selectConfigByKey("is_request_common_his_api");
//            if (null != s && s.equals("Y") && "2".equals(order.getTjType())) {
            if (null != s && s.equals("Y")) {
            if (null != s && s.equals("Y") && !useLisAndPacsRegister) {
                String apiUrl = configService.selectConfigByKey("common_api_url");
                String hospbm = configService.selectConfigByKey("common_api_service_hospbm");
@@ -3075,6 +3396,7 @@
                remarkService.deletedOrderRemarkByTjNum(tjNum);
                tjFlowingWaterService.deleteTjFlowingWaterByOrderId(String.valueOf(order.getOrderId()));
                transitionService.deletedTbTransitionByTjNum(tjNum);
                ycxmService.delOrderYcXmJyByTjh(tjNum);
                TjCustomer customer = tjCustomerService.getById(order.getUserId());
                customer.setCardId("0");
@@ -3199,7 +3521,7 @@
            for (int i = 0; i < tjNumbers.size(); i++) {
                String tjNumber = tjNumbers.get(i).getTjNumber();
                try {
                    List<Map<String, String>> djdInfos = tjOrderService.selectDjdInfo(tjNumber);
                    List<Map<String, Object>> djdInfos = tjOrderService.selectDjdInfo(tjNumber);
                    Map<String, Object> userInfo = tjOrderService.selectDjdUserInfo(tjNumber);
                    LocalDateTime tjsj = (LocalDateTime) userInfo.get("tjsj");
                    DateTimeFormatter dateFormat = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm");
@@ -3391,8 +3713,9 @@
                }
            }
            String s = configService.selectConfigByKey("is_request_common_his_api");
            Boolean useLisAndPacsRegister = lisApiMethod.isUseLisAndPacsRegister(order);
//            if (null != s && s.equals("Y") && "2".equals(order.getTjType())) {
            if (null != s && s.equals("Y")) {
            if (null != s && s.equals("Y") && !useLisAndPacsRegister) {
                ArrayList<TjFlowingWater> weizhifu = new ArrayList<>();
                ArrayList<TjFlowingWater> yizhifu = new ArrayList<>();
                for (String bldh : dto.getBldhs()) {
@@ -3492,24 +3815,26 @@
                log.info("退费申请 入参 -> {}", JSONUtil.toJsonStr(map));
                String post = HttpClientUtils.sendPost(apiUrl + "/api/his/" + hospbm + "/creatCostInfo", map);
                log.info("退费申请 返回 -> {}", JSONUtil.toJsonStr(post));
                JSONObject jsonObject = JSONUtil.parseObj(post);
                if (jsonObject.getStr("code").equals("200")) {
                    // hisTfWaterId
                    String tfid = jsonObject.getJSONObject("data").getStr("feiYongId");
                    water.setHisTfWaterId(tfid);
                    tjFlowingWaterService.updateById(water);
                    if (isDelete) {
                        for (TjFlowingWater water1 : yizhifu) {
                            String bldh1 = water1.getJxbz();
                            remarkService.deleteTjOrderDetailByjxbz(bldh1);
                            tjOrderDetailService.deleteTjOrderDetailByjxbz(bldh1);
                            tjFlowingWaterService.deleteTjOrderDetailByjxbz(bldh1);
                            transitionService.deleteTjOrderDetailByjxbz(bldh1);
                            blService.remove(new LambdaQueryWrapper<TjProBl>().eq(TjProBl::getTjh, tjNum).eq(TjProBl::getBldh, bldh1));
                            tjSamplingMapper.deleteByTjNumAndCusIdAndJxbzo(tjNum, order.getUserId(), bldh1);
                if (null != post) {
                    JSONObject jsonObject = JSONUtil.parseObj(post);
                    if (jsonObject.getStr("code").equals("200")) {
                        // hisTfWaterId
                        String tfid = jsonObject.getJSONObject("data").getStr("feiYongId");
                        water.setHisTfWaterId(tfid);
                        tjFlowingWaterService.updateById(water);
                        if (isDelete) {
                            for (TjFlowingWater water1 : yizhifu) {
                                String bldh1 = water1.getJxbz();
                                remarkService.deleteTjOrderDetailByjxbz(bldh1);
                                tjOrderDetailService.deleteTjOrderDetailByjxbz(bldh1);
                                tjFlowingWaterService.deleteTjOrderDetailByjxbz(bldh1);
                                transitionService.deleteTjOrderDetailByjxbz(bldh1);
                                blService.remove(new LambdaQueryWrapper<TjProBl>().eq(TjProBl::getTjh, tjNum).eq(TjProBl::getBldh, bldh1));
                                tjSamplingMapper.deleteByTjNumAndCusIdAndJxbzo(tjNum, order.getUserId(), bldh1);
                            }
                        }
                    }
                } else return AjaxResult.error();
                    } else return AjaxResult.error();
                }
            }
        }
        return null;
@@ -3594,6 +3919,20 @@
    }
    @GetMapping("/chushenyemianyijianjiekou")
    @ApiOperation(value = "初审页面弃检接口")
    @Transactional
    public AjaxResult chushenyemianyijianjiekou(@RequestParam String tjNUm, @RequestParam String proId) {
        LambdaQueryWrapper<TjOrderRemark> wq = new LambdaQueryWrapper<>();
        wq.eq(TjOrderRemark::getTjNumber, tjNUm);
        wq.eq(TjOrderRemark::getProId, proId);
        TjOrderRemark remark = remarkService.getOne(wq);
        remark.setType(1);
        remarkService.updateById(remark);
        return AjaxResult.success("操作成功!");
    }
    @PostMapping("/zongjanyemianshjianzhou")
    @ApiOperation(value = "总检获取时间轴接口")
    @Transactional
@@ -3637,7 +3976,7 @@
                        a = 5;
                    }
                    if (null != lastTime) {
                        //已出报告
                        //已打印
                        a = 6;
                    }
                    map.put("tjNUm", tjNUm);
@@ -3680,9 +4019,11 @@
                    }
                }
            }
            int i = tjReportService.deleteTjReportByReIds(list.toArray(new Long[]{}));
            if (i == 0) {
                return AjaxResult.error("撤回失败!");
            if (!list.isEmpty()) {
                int i = tjReportService.deleteTjReportByReIds(list.toArray(new Long[]{}));
                if (i == 0) {
                    return AjaxResult.error("撤回失败!");
                }
            }
            return AjaxResult.success("操作成功");
        }
@@ -3735,6 +4076,13 @@
                    return AjaxResult.error("操作失败! 以下项目已存在: " + string);
                }
                transitionService.ttsaveTemoTransitionByGroupingId(cusId, cardId, pacId.toString());
                //补差价
                List<Map<String, Object>> cjMaps = groupingProService.huoquxiangmuchajia(pacId.toString(), cusId);
                if (null != cjMaps && !cjMaps.isEmpty()) {
                    for (Map<String, Object> cjMap : cjMaps) {
                        transitionService.buxiangmuchajia(cusId, pacId.toString(), cjMap.get("xmid").toString(), new BigDecimal(cjMap.get("cj").toString()));
                    }
                }
            }
        }
@@ -3759,7 +4107,7 @@
    @GetMapping(value = "newgetTransitionList")
    @ApiOperation(value = "最新查询过渡表数据")
    public AjaxResult newgetTransitionList(@RequestParam @ApiParam(value = "客户id") String cusId) {
        List<TbTransition> list= transitionService.newgetTransitionList(cusId);
        List<TbTransition> list = transitionService.newgetTransitionList(cusId);
        return AjaxResult.success(list);
    }
@@ -3768,24 +4116,46 @@
    @Transactional
    public AjaxResult updateTransitionnewPrice(@RequestBody List<UpdateTransitionnewPriceDto> dtos) {
        if(null !=dtos && !dtos.isEmpty()){
        if (null != dtos && !dtos.isEmpty()) {
            int index = 0;
            boolean flag = false;
            for (UpdateTransitionnewPriceDto dto : dtos) {
                LambdaQueryWrapper<TbTransition> wq=new LambdaQueryWrapper<>();
                wq.eq(TbTransition::getCusId,dto.getCusIdCard());
                wq.eq(TbTransition::getParentProId,dto.getParentProId());
                index++;
                LambdaQueryWrapper<TbTransition> wq = new LambdaQueryWrapper<>();
                wq.eq(TbTransition::getCusId, dto.getCusIdCard());
                wq.eq(TbTransition::getParentProId, dto.getParentProId());
                wq.isNull(TbTransition::getTjNum);
                List<TbTransition> list = transitionService.list(wq);
                log.info("修改的客户身份证号为: "+dto.getCusIdCard());
                log.info("父项目id为: "+dto.getParentProId());
                log.info("折扣为: "+new BigDecimal(dto.getDiscount()));
                if(null !=list && !list.isEmpty()){
                log.info("修改的客户身份证号为: " + dto.getCusIdCard());
                log.info("父项目id为: " + dto.getParentProId());
                log.info("折扣为: " + new BigDecimal(dto.getDiscount()));
                if (null != list && !list.isEmpty()) {
                    for (TbTransition transition : list) {
                        BigDecimal ordPrice = transition.getOrdPrice();
                        BigDecimal multiply = ordPrice.multiply((new BigDecimal(dto.getDiscount()).divide(BigDecimal.valueOf(10))));
                        log.info("后端计算的金额: "+multiply);
                        log.info("后端计算的金额: " + multiply.toString());
                        transition.setNowPrice(multiply);
                        transition.setDiscount(new BigDecimal(dto.getDiscount()));
                        transitionService.updateById(transition);
                    }
                    BigDecimal dxzj = transitionService.getTbTransitionPriceAndOrdPrice(dto.getCusIdCard(), dto.getParentProId());
                    BigDecimal yhj = dto.getYhj();
                    log.info("前端传递的价格:{}",yhj.toString());
                    BigDecimal cj = yhj.subtract(dxzj);
                    log.info("计算的差价:{}",cj.toString());
                    for (TbTransition transition : list) {
                        BigDecimal result = transition.getNowPrice().add(cj);
                        log.info("补上差价前的价格为:{}",transition.getNowPrice().toString());
                        if (result.compareTo(BigDecimal.ZERO)>0 && !flag && cj.compareTo(BigDecimal.ZERO) != 0){
                            transition.setNowPrice(result);
                            transitionService.updateById(transition);
                            log.info("修改 补上差价后的价格为:{}",result.toString());
                            flag = true;
                            break;
                        }
                    }
                }
            }
@@ -3794,5 +4164,76 @@
    }
    @PostMapping("/huifuyuyuejilu")
    @ApiOperation(value = "体检记录页面恢复预约记录接口")
    @Transactional
    public AjaxResult huifuyuyuejilu(@RequestBody List<String> tjNUms) {
        if (null != tjNUms && !tjNUms.isEmpty()) {
            for (String tjNUm : tjNUms) {
                TjOrder order = tjOrderService.getOrderByTjNum(tjNUm);
                if(null !=order && StringUtil.isNotBlank(order.getReservationId())){
                    //这里删除的是这个人所有项目包括补录项目
                    tjOrderService.deleteTjOrderByOrderId(order.getOrderId());
                    tjOrderDetailService.deleteTjOrderDetailByOrderDetailId(String.valueOf(order.getOrderId()));
                    remarkService.deletedOrderRemarkByTjNum(tjNUm);
                    tjFlowingWaterService.deleteTjFlowingWaterByOrderId(String.valueOf(order.getOrderId()));
//                transitionService.deletedTbTransitionByTjNum(tjNum);
                    tjSamplingMapper.deleteByTjNumAndCusId(order.getTjNumber(), order.getUserId());
                    TjReservation reservation = tjReservationService.getById(order.getReservationId());
                    if(null !=reservation){
                        reservation.setIsExpire(2);
                        tjReservationService.updateById(reservation);
                        transitionService.updateTbTransitionByTjNum(tjNUm);
                    }
                }
            }
            return AjaxResult.success();
        }
        return AjaxResult.error();
    }
    @PostMapping("/addBlTransition")
    @ApiOperation(value = "补录添加过渡表数据")
    @Transactional
    public AjaxResult addBlTransition(@RequestBody Map<String, Object> map) {
        Object packId = map.get("pacId");
        if (null == map.get("cusId")) return AjaxResult.error("请选择体检人");
        String cusId = map.get("cusId").toString();
        Object proIds1 = map.get("proIds");
        List<Long> proIds = null;
        if (null != proIds1 && !proIds1.equals("")) {
            proIds = JSON.parseArray(proIds1.toString(), Long.class);
        }
        TjCustomer tjCustomer = tjCustomerService.getTjCustomerByCusIdCard(cusId);
        String cardId = "0";
        if (null != tjCustomer) {
            cardId = tjCustomer.getCardId();
        }
        if ((null == proIds || proIds.isEmpty()) && (null == packId || packId.equals(""))) {
            transitionService.deletedTbTransitionByCusId(cusId);
        }
        //单项
        if (null != proIds && !proIds.isEmpty()) {
            //异步保存数据库表
            for (Long proId : proIds) {
                TjProject project = projectService.selectTjProjectByProId(proId);
                if (null != project) {
                    List<TbTransition> transitionList = transitionService.getTbTransitionListByCusIdAndPacIdAndProId(cusId, String.valueOf(proId));
                    if (null == transitionList || transitionList.isEmpty()) {
                        transitionService.saveRedisTransitionByProId(cusId, cardId, proId);
                    }
                }
            }
        }
        return AjaxResult.success();
    }
}