zhaowenxuan
2024-10-11 cebb4511b4f7102570b0151d48779670b32cad62
ltkj-admin/src/main/java/com/ltkj/web/controller/system/TjOrderController.java
@@ -12,6 +12,7 @@
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;
@@ -88,6 +89,8 @@
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;
import org.springframework.transaction.interceptor.TransactionAspectSupport;
import org.springframework.util.DigestUtils;
@@ -871,12 +874,18 @@
    }
    /**
     * 体检签到登记接口
     */
    ReentrantLock lock=new ReentrantLock();
    @PostMapping
    @ApiOperation(value = "体检签到登记接口")
    @Transactional  //(切换数据库出错,所以注释)
//    @Transactional  //(切换数据库出错,所以注释)
    @Transactional(propagation = Propagation.REQUIRED, isolation = Isolation.READ_COMMITTED)
    public AjaxResult addOrderAndDetail(@RequestBody TjOrder tjOrder) throws Exception {
        Long userId = Long.valueOf(SecurityUtils.getLoginUser().getUserId());
        SysUser sysUser = userService.getById(userId);
@@ -898,7 +907,6 @@
            transitionService.deletedTbTransitionListByCusIdAndTjNum(tjCustomer.getCusIdcard(), tjCustomer.getCardId());
            return AjaxResult.error("不可重复登记");
        }
        TjFlowingWater tjFlowingWater = new TjFlowingWater();
        LambdaQueryWrapper<TjReservation> wq1 = new LambdaQueryWrapper<>();
        wq1.eq(TjReservation::getIdCard, tjCustomer.getCusIdcard());
@@ -908,9 +916,9 @@
        if (null != tjReservation) {
            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(new Date()).before(tjReservation.getReservationTime())) {
            //                return AjaxResult.error("未到预约时间");
            //            }
            if (DateUtil.endOfDay(DateUtil.offsetDay(tjReservation.getReservationTime(), tjReservation.getYxts())).before(new Date())) {
                tjReservation.setIsExpire(1);
                tjReservationService.updateById(tjReservation);
@@ -926,7 +934,7 @@
                tjOrder.setGroupId(tjReservation.getGroupingId());
                tjOrder.setFirmDeptId(tjReservation.getPacId());
            }
//            if (null != tjReservation.getDepartmentId()) tjOrder.setFirmDeptId(tjReservation.getDepartmentId());
            //            if (null != tjReservation.getDepartmentId()) tjOrder.setFirmDeptId(tjReservation.getDepartmentId());
            tjReservation.setIsExpire(1);
            tjReservationService.updateById(tjReservation);
            if (null != tjReservation.getTeamNo()) {
@@ -935,9 +943,7 @@
                tjOrder.setTjType("2");
            }
        }
        //生成体检号
        String tjNumber = (SecurityUtils.getUsername() + new SimpleDateFormat("yyMMddHHmmss").format(new Date()));
        tjOrder.setTjNumber(tjNumber);
        if (null != tjOrder.getPhoto()) {
            File file = new File(tjOrder.getPhoto());
            if (file.isFile()) {
@@ -964,146 +970,156 @@
            tjOrder.setFinishTime(new Date());
            tjOrder.setCheckStatus(1);
            tjOrder.setStatus(TjConstants.TJ_WAIT);
//            tjFlowingWater.setPayStasus(1L);
            //            tjFlowingWater.setPayStasus(1L);
        }
//        else {
        tjFlowingWater.setPayStasus(0L);
//        }
        if (tjOrderService.save(tjOrder)) {
            //保存收货地址
            if ("2".equals(tjOrder.getGetType())) {
                final TjReportGetAddress address = tjOrder.getAddAddress();
                if (address != null) {
                    address.setTjNumber(tjNumber);
                    tjReportGetAddressService.save(address);
                }
            }
            Long cusNumber = tjCustomer.getCusNumber();
            cusNumber += 1;
            tjCustomer.setCusNumber(cusNumber);
            BigDecimal discount = BigDecimal.valueOf(Double.parseDouble(tjOrder.getTjFlowingWater().getDiscount()));
        try {
            boolean b = lock.tryLock(3, TimeUnit.MINUTES);
            if(b){
                //生成体检号
                String tjNumber = (SecurityUtils.getUsername() + new SimpleDateFormat("yyMMddHHmmss").format(new Date()));
                tjOrder.setTjNumber(tjNumber);
            if ("1".equals(tjOrder.getTjType())) {
                if (null != tjReservation && tjReservation.getPayType() == 1) {
                    tjFlowingWater.setPayStasus(3L);
                }
            }
            //调用SQL server拿取收费情况
            //根据配置调取存储过程 将临时表数据存入预约表2023.12.12
            final String getInfoFromSqlData = configService.selectConfigByKey("getInfoFromSqlData");
            final String isPay = configService.selectConfigByKey("isPay");
            if ("Y".equals(getInfoFromSqlData)) {
                LtkjMiddleHead middleHead = headService.getMiddleHeadByPartId(tjCustomer.getCardId());
                if (null != middleHead) {
                    tjFlowingWater.setPayStasus(1L);
                }
            }
            tjFlowingWater.setOrderId(tjOrder.getOrderId());
            Date date1 = new Date(System.currentTimeMillis());
            String s1 = SecurityUtils.getUsername() + new SimpleDateFormat("yyMMddHHmmssSSS").format(date1);
            tjFlowingWater.setWaterId(PinyinUtil.getFirstLetter(tjCustomer.getCusName(), "").toUpperCase() + s1);
            tjFlowingWater.setCopeWith(tjOrder.getTjFlowingWater().getCopeWith());
            tjFlowingWater.setPaidIn(tjOrder.getTjFlowingWater().getPaidIn());
            tjFlowingWater.setDiscount(tjOrder.getTjFlowingWater().getDiscount());
            if (isPay.equals("true")) {
                if (null != mallOrder) {
                    if (mallOrder.getOrderStatus().equals(201L)) {
                        tjFlowingWater.setCopeWith(mallOrder.getActualPrice());
                        tjFlowingWater.setPaidIn(mallOrder.getActualPrice());
                        tjFlowingWater.setDiscount(String.valueOf(1));
                        tjFlowingWater.setPayStasus(1L);
                        tjFlowingWater.setPayType(3L);
                        MallCheckLog checkLog = new MallCheckLog();
                        checkLog.setCheckBy(sysUser.getNickName());
                        checkLog.setUserId(mallOrder.getUserId());
                        checkLog.setConsignee(mallOrder.getConsignee());
                        checkLog.setIdCard(mallOrder.getIdCard());
                        checkLog.setOrderId(String.valueOf(mallOrder.getId()));
                        checkLog.setOrderSn(mallOrder.getOrderSn());
                        checkLog.setCheckTime(new Date());
                        checkLog.setShipSn("HX" + s1);
                        mallCheckLogService.save(checkLog);
                        mallOrder.setOrderStatus(301L);
                        mallOrderService.updateById(mallOrder);
                if (tjOrderService.save(tjOrder)) {
                    //保存收货地址
                    if ("2".equals(tjOrder.getGetType())) {
                        final TjReportGetAddress address = tjOrder.getAddAddress();
                        if (address != null) {
                            address.setTjNumber(tjNumber);
                            tjReportGetAddressService.save(address);
                        }
                    }
                } else {
                    Long cusNumber = tjCustomer.getCusNumber();
                    cusNumber += 1;
                    tjCustomer.setCusNumber(cusNumber);
                    BigDecimal discount = BigDecimal.valueOf(Double.parseDouble(tjOrder.getTjFlowingWater().getDiscount()));
                    if ("1".equals(tjOrder.getTjType())) {
                        if (null != tjReservation && tjReservation.getPayType() == 1) {
                            tjFlowingWater.setPayStasus(3L);
                        }
                    }
                    //调用SQL server拿取收费情况
                    //根据配置调取存储过程 将临时表数据存入预约表2023.12.12
                    final String getInfoFromSqlData = configService.selectConfigByKey("getInfoFromSqlData");
                    final String isPay = configService.selectConfigByKey("isPay");
                    if ("Y".equals(getInfoFromSqlData)) {
                        LtkjMiddleHead middleHead = headService.getMiddleHeadByPartId(tjCustomer.getCardId());
                        if (null != middleHead) {
                            tjFlowingWater.setPayStasus(1L);
                        }
                    }
                    tjFlowingWater.setOrderId(tjOrder.getOrderId());
                    Date date1 = new Date(System.currentTimeMillis());
                    String s1 = SecurityUtils.getUsername() + new SimpleDateFormat("yyMMddHHmmssSSS").format(date1);
                    tjFlowingWater.setWaterId(PinyinUtil.getFirstLetter(tjCustomer.getCusName(), "").toUpperCase() + s1);
                    tjFlowingWater.setCopeWith(tjOrder.getTjFlowingWater().getCopeWith());
                    tjFlowingWater.setPaidIn(tjOrder.getTjFlowingWater().getPaidIn());
                    tjFlowingWater.setDiscount(tjOrder.getTjFlowingWater().getDiscount());
//                    tjFlowingWater.setPayStasus(0L);
                }
            }
            if (tjFlowingWaterService.save(tjFlowingWater)) {
                tjOrder.setTjSerialNumber(String.valueOf(tjFlowingWater.getTjSerialNumber()));
                tjOrderService.updateById(tjOrder);
            }
            //修改每项的原价现价 //修改临时表体检号
            transitionService.updateTbTransitionPriceByCusId(tjCustomer.getCusIdcard(), discount, tjOrder.getTjNumber());
            /*调用his接口*/
            String config = configService.selectConfigByKey("sfkqdyhis");
            if (null != config && config.equals("Y")) {
                AjaxResult result = hisApiMethod.HisApiMethods(tjCustomer, tjOrder);
                if (!result.get("code").toString().equals("200")) {
                    TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                    Object jzh = result.get("jzh");
                    if (null != jzh && null != jzh.toString()) {
                        hisApiMethod.ZfHisApiMethod(jzh.toString());
                    if (isPay.equals("true")) {
                        if (null != mallOrder) {
                            if (mallOrder.getOrderStatus().equals(201L)) {
                                tjFlowingWater.setCopeWith(mallOrder.getActualPrice());
                                tjFlowingWater.setPaidIn(mallOrder.getActualPrice());
                                tjFlowingWater.setDiscount(String.valueOf(1));
                                tjFlowingWater.setPayStasus(1L);
                                tjFlowingWater.setPayType(3L);
                                MallCheckLog checkLog = new MallCheckLog();
                                checkLog.setCheckBy(sysUser.getNickName());
                                checkLog.setUserId(mallOrder.getUserId());
                                checkLog.setConsignee(mallOrder.getConsignee());
                                checkLog.setIdCard(mallOrder.getIdCard());
                                checkLog.setOrderId(String.valueOf(mallOrder.getId()));
                                checkLog.setOrderSn(mallOrder.getOrderSn());
                                checkLog.setCheckTime(new Date());
                                checkLog.setShipSn("HX" + s1);
                                mallCheckLogService.save(checkLog);
                                mallOrder.setOrderStatus(301L);
                                mallOrderService.updateById(mallOrder);
                            }
                        } else {
                            tjFlowingWater.setCopeWith(tjOrder.getTjFlowingWater().getCopeWith());
                            tjFlowingWater.setPaidIn(tjOrder.getTjFlowingWater().getPaidIn());
                            tjFlowingWater.setDiscount(tjOrder.getTjFlowingWater().getDiscount());
    //                    tjFlowingWater.setPayStasus(0L);
                        }
                    }
                    log.info("该登记人挂号失败, 就诊号为: " + tjOrder.getCardId());
                    return AjaxResult.error("挂号失败!" + result.get("msg").toString());
                    if (tjFlowingWaterService.save(tjFlowingWater)) {
                        tjOrder.setTjSerialNumber(String.valueOf(tjFlowingWater.getTjSerialNumber()));
                        tjOrderService.updateById(tjOrder);
                    }
                    //修改每项的原价现价 //修改临时表体检号
                    transitionService.updateTbTransitionPriceByCusId(tjCustomer.getCusIdcard(), discount, tjOrder.getTjNumber());
                    /*调用his接口*/
                    String config = configService.selectConfigByKey("sfkqdyhis");
                    if (null != config && config.equals("Y")) {
                        AjaxResult result = hisApiMethod.HisApiMethods(tjCustomer, tjOrder);
                        if (!result.get("code").toString().equals("200")) {
                            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                            Object jzh = result.get("jzh");
                            if (null != jzh && null != jzh.toString()) {
                                hisApiMethod.ZfHisApiMethod(jzh.toString());
                            }
                            log.info("该登记人挂号失败, 就诊号为: " + tjOrder.getCardId());
                            return AjaxResult.error("挂号失败!" + result.get("msg").toString());
                        }
                        log.info("该登记人的his就诊号是: " + tjOrder.getCardId());
                        //团体
                        if ("1".equals(tjOrder.getTjType())) {
                            asyncService.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
    //                String useLisAndPacsRegisterDictTeam = configService.selectConfigByKey("use_lis_and_pacs_register_dict_team");
    //                String[] split = useLisAndPacsRegisterDictTeam.split(",");
    //                List<String> list = Arrays.asList(split);
    //                if (list.contains(tjOrder.getTjType())) {
    //                    List<TbTransition> detailList = tbTransitionService.getTbTransitionListByCusId(tjCustomer.getCusIdcard(),tjOrder.getCardId());
    //                    pacsApiMethodService.save(tjOrder,tjCustomer,detailList);
    //                    lisApiMethod.save(tjOrder,tjCustomer,detailList);
    //                }else {
    //                    hisApiMethod.tijianshenqing(tjCustomer, DateUtil.format(date1, "yyyy-MM-dd HH:mm:ss"), tjOrder.getCardId());
    //                }
                        hisApiMethod.tijianshenqing(tjCustomer, DateUtil.format(date1, "yyyy-MM-dd HH:mm:ss"), tjOrder.getCardId());
                        return AjaxResult.success(tjNumber);
                    } else {
                        tjCustomer.setCardId(tjOrder.getTjNumber());
                        tjCustomerService.updateById(tjCustomer);
                        transitionService.updateCardIdByTjNumAndIdCard(tjCustomer.getCusIdcard(), tjOrder.getTjNumber(), tjOrder.getTjNumber());
                        tjOrder.setCardId(tjOrder.getTjNumber());
                        tjOrderService.updateById(tjOrder);
                    }
                    //团体
                    if ("1".equals(tjOrder.getTjType())) {
                        asyncService.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);
                    }
                    return AjaxResult.success(tjNumber);
                }
                log.info("该登记人的his就诊号是: " + tjOrder.getCardId());
                //团体
                if ("1".equals(tjOrder.getTjType())) {
                    asyncService.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
//                String useLisAndPacsRegisterDictTeam = configService.selectConfigByKey("use_lis_and_pacs_register_dict_team");
//                String[] split = useLisAndPacsRegisterDictTeam.split(",");
//                List<String> list = Arrays.asList(split);
//                if (list.contains(tjOrder.getTjType())) {
//                    List<TbTransition> detailList = tbTransitionService.getTbTransitionListByCusId(tjCustomer.getCusIdcard(),tjOrder.getCardId());
//                    pacsApiMethodService.save(tjOrder,tjCustomer,detailList);
//                    lisApiMethod.save(tjOrder,tjCustomer,detailList);
//                }else {
//                    hisApiMethod.tijianshenqing(tjCustomer, DateUtil.format(date1, "yyyy-MM-dd HH:mm:ss"), tjOrder.getCardId());
//                }
                hisApiMethod.tijianshenqing(tjCustomer, DateUtil.format(date1, "yyyy-MM-dd HH:mm:ss"), tjOrder.getCardId());
                return AjaxResult.success(tjNumber);
            } else {
                tjCustomer.setCardId(tjOrder.getTjNumber());
                tjCustomerService.updateById(tjCustomer);
                transitionService.updateCardIdByTjNumAndIdCard(tjCustomer.getCusIdcard(), tjOrder.getTjNumber(), tjOrder.getTjNumber());
                tjOrder.setCardId(tjOrder.getTjNumber());
                tjOrderService.updateById(tjOrder);
                return AjaxResult.error();
            }
            //团体
            if ("1".equals(tjOrder.getTjType())) {
                asyncService.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);
            }
            return AjaxResult.success(tjNumber);
        } finally {
            lock.unlock();
        }
        return AjaxResult.error();
    }
@@ -1116,7 +1132,7 @@
        SysUser sysUser = UserHoder.getLoginUser().getUser();
        List<String> cusIds = daoDto.getCusIds();
        ArrayList<String> tjNumbers = new ArrayList<>();
        if (null != cusIds && cusIds.size() > 0) {
        if (null != cusIds && !cusIds.isEmpty()) {
            ExecutorService threadPools = Executors.newFixedThreadPool(cusIds.size());
            for (String cusId : cusIds) {
                threadPools.execute(new Runnable() {
@@ -1129,7 +1145,7 @@
            LambdaQueryWrapper<TjCustomer> wq = new LambdaQueryWrapper<>();
            wq.in(TjCustomer::getCusIdcard, cusIds);
            List<Long> list = tjCustomerService.list(wq).stream().map(TjCustomer::getCusId).collect(Collectors.toList());
            if (list.size() > 0) {
            if (!list.isEmpty()) {
//                ExecutorService threadPool = Executors.newFixedThreadPool(list.size());
                ThreadPoolTaskExecutor executor = threadPoolConfig.threadPoolTaskExecutor();
                for (Long aLong : list) {