zjh
2024-06-26 ec2bb08f0aad10bbf1f133046d8e9943be3a6d72
ltkj-admin/src/main/java/com/ltkj/web/controller/system/TjOrderController.java
@@ -23,6 +23,9 @@
import cn.hutool.core.date.DateUtil;
import cn.hutool.crypto.symmetric.DES;
import cn.hutool.extra.pinyin.PinyinUtil;
import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.alibaba.fastjson2.JSON;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
@@ -183,6 +186,8 @@
    private HisMzJysqController hisMzJysqController;
    @Autowired
    private HisApiGetMethodService hisApiGetMethodService;
    @Autowired
    private ISysDeptService sysDeptService;
    /**
@@ -440,9 +445,8 @@
                if (null != tjCustomer) {
                    order.setTjCustomerSex(tjCustomer.getCusSex());
                    order.setTjCustomerAge(DateUtil.ageOfNow(tjCustomer.getCusBrithday()));
                    order.setTjCustomerName(MatchUtils.hideCusName(tjCustomer.getCusName()));
                    order.setTjCustomerName(tjCustomer.getCusName());
                    order.setTjCustomerPhone(MatchUtils.hidePhoneNum(tjCustomer.getCusPhone()));
                    order.setTjCustomerPhone(tjCustomer.getCusPhone());
//                    order.setTjCusIdCard(MatchUtils.hideIdCardNum(tjCustomer.getCusIdcard()));
                    order.setTjCusIdCard(tjCustomer.getCusIdcard());
                    order.setCareer(tjCustomer.getCareer());
@@ -856,7 +860,7 @@
//        }
        TjOrder order = tjOrderService.getOne(wqq);
        if (null != order) {
            transitionService.deletedTbTransitionListByCusIdAndTjNum(tjCustomer.getCusIdcard(),tjCustomer.getCardId());
            transitionService.deletedTbTransitionListByCusIdAndTjNum(tjCustomer.getCusIdcard(), tjCustomer.getCardId());
            return AjaxResult.error("不可重复登记");
        }
@@ -1034,18 +1038,18 @@
            /*调用his接口*/
            String config = configService.selectConfigByKey("sfkqdyhis");
            if(null !=config && config.equals("Y")){
            if (null != config && config.equals("Y")) {
                AjaxResult result = hisApiMethod.HisApiMethods(tjCustomer, tjOrder.getOrderId());
                if(!result.get("code").toString().equals("200")){
                if (!result.get("code").toString().equals("200")) {
                    TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                    return AjaxResult.error("挂号失败!"+result.get("msg").toString());
                    return AjaxResult.error("挂号失败!" + result.get("msg").toString());
                }
            }else {
            tjCustomer.setCardId(tjOrder.getTjNumber());
            tjCustomerService.updateById(tjCustomer);
            transitionService.updateCardIdByTjNumAndIdCard(tjCustomer.getCusIdcard(),tjOrder.getTjNumber(),tjOrder.getTjNumber());
            tjOrder.setCardId(tjOrder.getTjNumber());
             tjOrderService.updateById(tjOrder);
            } 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.success(tjNumber);
        }
@@ -1056,7 +1060,7 @@
    @PostMapping("/addPlOrderAndDetail")
    @ApiOperation(value = "体检批量签到登记接口")
    @Transactional  //(切换数据库出错,所以注释)
    public AjaxResult addPlOrderAndDetail(@RequestBody QianDaoDto daoDto,HttpServletResponse response) {
    public AjaxResult addPlOrderAndDetail(@RequestBody QianDaoDto daoDto, HttpServletResponse response) {
        SysUser sysUser = UserHoder.getLoginUser().getUser();
        List<String> cusIds = daoDto.getCusIds();
        ArrayList<String> tjNumbers = new ArrayList<>();
@@ -1441,7 +1445,7 @@
                tjCustomer.setCardId("0");
                tjCustomerService.updateById(tjCustomer);
                return AjaxResult.success().put("tjNumber",tjNumber);
                return AjaxResult.success().put("tjNumber", tjNumber);
            }
        }
        return AjaxResult.error();
@@ -1540,7 +1544,7 @@
                if (null != ppList && ppList.size() > 0) {
                    //异步保存数据库
//                    asyncService.addRedisTransitionPac(cusId, pacId, ppList);
                    asyncService.saveRedisTransitionByPacId(cusId,cardId, pacId, null);
                    asyncService.saveRedisTransitionByPacId(cusId, cardId, pacId, null);
                    for (TjPackageProject tjPackageProject : ppList) {
                        TjProject project = projectService.getTjProjectById(String.valueOf(tjPackageProject.getProId()));
                        if (null != project) {
@@ -1585,7 +1589,7 @@
        //单项
        if (null != proIds && proIds.size() > 0) {
            //异步保存数据库表
            asyncService.saveRedisTransitionByPacId(cusId,cardId,null, proIds);
            asyncService.saveRedisTransitionByPacId(cusId, cardId, null, proIds);
            for (Long proId : proIds) {
                List<TbTransition> transitions = transitionService.getTbTransitionListByCusIdAndPacIdAndProId(cusId, String.valueOf(proId));
                if (null != transitions && transitions.size() > 0) {
@@ -1918,8 +1922,10 @@
        for (Map.Entry<Long, List<TbTransition>> entry : collect.entrySet()) {
            Map<String, Object> map = new HashMap<>();
            Long pacId = entry.getValue().get(0).getPacId();
            map.put("proPrantId", entry.getKey().toString());
            if (null != pacId) {
                TjPackage aPackage = tjPackageService.getById(entry.getValue().get(0).getPacId());
                map.put("tjCategory",aPackage.getTjCategory());
                map.put("pacName", aPackage.getPacName());
                TjProject tjProject = projectService.getById(entry.getKey());
//                TjPackageProject project = tjPackageProjectService.getOne(new LambdaQueryWrapper<TjPackageProject>().eq(TjPackageProject::getPacId, pacId)
@@ -1932,6 +1938,7 @@
//                }
                map.put("nowPrice", transitionService.getTbTransitionDxPriceByPac(cusId, entry.getKey(), cardId, pacId));
            } else {
                map.put("tjCategory",null);
                map.put("pacName", "单项");
                List<TbTransition> tbTransitionList = entry.getValue();
                if (null != tbTransitionList && tbTransitionList.size() > 0) {
@@ -1953,7 +1960,7 @@
    }
    private List<Map<String, Object>> getMap(String cusId, String cardId,List<TbTransition> transitionList) {
    private List<Map<String, Object>> getMap(String cusId, String cardId, List<TbTransition> transitionList) {
//        List<TbTransition> transitionList = null;
//        if (redisCache.hasKey(cardId + cusId)) {
@@ -1967,8 +1974,10 @@
        for (Map.Entry<Long, List<TbTransition>> entry : collect.entrySet()) {
            Map<String, Object> map = new HashMap<>();
            Long pacId = entry.getValue().get(0).getPacId();
            map.put("proPrantId", entry.getKey().toString());
            if (null != pacId) {
                TjPackage aPackage = tjPackageService.getById(entry.getValue().get(0).getPacId());
                map.put("tjCategory",aPackage.getTjCategory());
                map.put("pacName", aPackage.getPacName());
                TjProject tjProject = projectService.getById(entry.getKey());
//                TjPackageProject project = tjPackageProjectService.getOne(new LambdaQueryWrapper<TjPackageProject>().eq(TjPackageProject::getPacId, pacId)
@@ -1979,8 +1988,9 @@
//                } else {
//                    map.put("nowPrice", tjProject.getProPrice());
//                }
                map.put("nowPrice", transitionService.getTbTransitionDxPriceByPac(cusId, entry.getKey(), cardId, pacId));
                map.put("nowPrice",tjProject.getProPrice());
            } else {
                map.put("tjCategory",null);
                map.put("pacName", "单项");
                List<TbTransition> tbTransitionList = entry.getValue();
                if (null != tbTransitionList && tbTransitionList.size() > 0) {
@@ -2216,6 +2226,65 @@
        return AjaxResult.success(transitionService.remove(wq));
    }
    @GetMapping("/getTransitionInfo")
    @ApiOperation(value = "根据体检号获取汇总和明细的数据")
    public AjaxResult getTransitionInfo(@RequestParam("tjNumber")String tjNumber){
        QueryWrapper<TbTransition> wrapper = new QueryWrapper<>();
        wrapper.select("parent_pro_id","parent_pro_name","sum(ord_price) as ord_price")
                .eq("tj_num",tjNumber)
                .groupBy("parent_pro_name");
        List<TbTransition> list = transitionService.list(wrapper);
        List<Long> parentProIds = list.stream().map(item -> item.getParentProId()).collect(Collectors.toList());
        LambdaQueryWrapper<TjProject> projectQueryWrapper = new LambdaQueryWrapper<>();
        projectQueryWrapper.in(TjProject::getProId,parentProIds);
        List<TjProject> projects = projectService.list(projectQueryWrapper);
        JSONArray huiZong = JSONUtil.createArray();
        int index = 1;
        for (TjProject project : projects) {
            LambdaQueryWrapper<SysDept> queryWrapper = new LambdaQueryWrapper<>();
            queryWrapper.eq(SysDept::getDeptId,project.getDeptId());
            SysDept dept = sysDeptService.getOne(queryWrapper);
            for (TbTransition tbTransition : list) {
                if (tbTransition.getParentProId().toString().equals(project.getProId().toString())){
                    JSONObject obj = JSONUtil.createObj();
                    obj.putOpt("index",index++);
                    obj.putOpt("parent_pro_name",tbTransition.getParentProName());
                    obj.putOpt("price",tbTransition.getOrdPrice());
                    obj.putOpt("ks",dept.getDeptName());
                    huiZong.add(obj);
                }
            }
        }
        wrapper = new QueryWrapper<>();
        wrapper.eq("tj_num",tjNumber);
        list = transitionService.list(wrapper);
        JSONArray info = JSONUtil.createArray();
        index = 1;
        for (TbTransition tbTransition : list) {
            JSONObject obj = JSONUtil.createObj();
            obj.putOpt("index",index++);
            obj.putOpt("parent_pro_name",tbTransition.getParentProName());
            obj.putOpt("pro_name",tbTransition.getProName());
            BigDecimal ordPrice = tbTransition.getOrdPrice();
            obj.putOpt("zongjia",ordPrice);
            QueryWrapper<TjProject> queryWrapper = new QueryWrapper<>();
            queryWrapper.eq("pro_id",tbTransition.getProId());
            TjProject tjProject = projectService.getOne(queryWrapper);
            Integer num = tjProject.getSl();
            obj.putOpt("num",num);
            BigDecimal price = ordPrice.divide(new BigDecimal(num));
            obj.putOpt("danjia",price);
            Date createTime = tbTransition.getCreateTime();
            SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            obj.putOpt("time",dateFormat.format(createTime));
            info.put(obj);
        }
        HashMap<String, Object> map = new HashMap<>();
        map.put("huizong",huiZong);
        map.put("info",info);
        return AjaxResult.success().put("data",map);
    }
    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()));
        tjOrderDetailService.saveTjOrderDetailsByCusId(tjCustomer.getCusIdcard(), String.valueOf(tjOrder.getOrderId()), sysUser.getNickName(), String.valueOf(sysUser.getUserId()));
@@ -2393,39 +2462,41 @@
            remarkService.deletedOrderRemarkByTjNum(tjNum);
            tjFlowingWaterService.deleteTjFlowingWaterByOrderId(String.valueOf(order.getOrderId()));
            transitionService.deletedTbTransitionByTjNum(tjNum);
            transitionService.updateTbTransitionByTjNum(tjNum);
            TjCustomer customer = tjCustomerService.getById(order.getUserId());
            if(null !=customer){
            if (null != customer) {
                customer.setCardId("0");
                tjCustomerService.updateById(customer);
            }
            String configByKey = configService.selectConfigByKey("sfkqdyhis");
            if (configByKey.equals("Y")){
            if (configByKey.equals("Y")) {
                HashMap<String, Object> map = new HashMap<>();
                map.put("cardtype","4");
                map.put("input",order.getCardId());
                map.put("cardtype", "4");
                map.put("input", order.getCardId());
                LocalDate currentDate = LocalDate.now();
                LocalDateTime startOfDay = currentDate.atStartOfDay();
                LocalDateTime nineteenOClock = currentDate.atTime(LocalTime.of(19, 0));
                DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
                String ksrq = startOfDay.format(formatter);
                String jsrq = nineteenOClock.format(formatter);
                map.put("ksrq",ksrq);
                map.put("jsrq",jsrq);
                map.put("ksrq", ksrq);
                map.put("jsrq", jsrq);
                AjaxResult result = hisApiGetMethodService.getHISDataNew("Getoutpatientcostinfo", map);
                if (Integer.parseInt(String.valueOf(result.get("code"))) == 200){
                if (Integer.parseInt(String.valueOf(result.get("code"))) == 200) {
                    TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                    return AjaxResult.error("撤销失败,门诊患者费用清单信息不为空");
                }else {
                } else {
                    boolean zfHisApiMethods = hisApiMethod.ZfHisApiMethods(null, order);
                    if (zfHisApiMethods) {
                        return AjaxResult.success("撤销成功", map);
                    }else {
                    } else {
                        TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                        return AjaxResult.error("撤销失败,调用作废出现失败");
                    }
                }
            }
//            transitionService.updateTbTransitionByTjNum(tjNum);
            return AjaxResult.success("撤销成功!!!");
        }
        return AjaxResult.success("签到记录不存在!");
@@ -2506,7 +2577,7 @@
    @ApiOperation(value = "批量生成PDF")
    public AjaxResult makeTjPDF(@RequestBody List<String> reservations) {
        QueryWrapper<TjOrder> queryWrapper = new QueryWrapper<>();
        queryWrapper.in("reservation_id",reservations);
        queryWrapper.in("reservation_id", reservations);
        List<TjOrder> tjNumbers = tjOrderService.list(queryWrapper);
        Map<String, Object> map = null;
        try {
@@ -2543,5 +2614,77 @@
            return AjaxResult.error(e.getMessage());
        }
    }
    @GetMapping("/delTbBycusCardIdAndProId")
    @ApiOperation(value = "根据客户身份证号和项目父项id删除临时表数据")
    @Transactional
    public AjaxResult delTbBycusCardIdAndProId(@RequestParam @ApiParam(value = "身份证号") String cusCardId,
                                               @RequestParam @ApiParam(value = "父项id") String proId) {
        if (transitionService.delTbBycusCardIdAndProId(cusCardId, proId)) {
            return AjaxResult.success();
        }
        return AjaxResult.error("记录不存在!");
    }
    @GetMapping("/revokeTjOrderByTjCardId")
    @ApiOperation(value = "根据就诊号撤销申请记录")
    @Transactional
    public AjaxResult revokeTjOrderByTjCardId(@RequestParam @ApiParam(value = "就诊号") String cardId) {
        TjOrder order = new TjOrder();
        order.setCardId(cardId);
        String configByKey = configService.selectConfigByKey("sfkqdyhis");
        if (configByKey.equals("Y")) {
            HashMap<String, Object> map = new HashMap<>();
            map.put("cardtype", "4");
            map.put("input", order.getCardId());
            LocalDate currentDate = LocalDate.now();
            LocalDateTime startOfDay = currentDate.atStartOfDay();
            LocalDateTime nineteenOClock = currentDate.atTime(LocalTime.of(19, 0));
            DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
            String ksrq = startOfDay.format(formatter);
            String jsrq = nineteenOClock.format(formatter);
            map.put("ksrq", ksrq);
            map.put("jsrq", jsrq);
            AjaxResult result = hisApiGetMethodService.getHISDataNew("Getoutpatientcostinfo", map);
            if (Integer.parseInt(String.valueOf(result.get("code"))) == 200) {
                TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                return AjaxResult.error("撤销失败,门诊患者费用清单信息不为空");
            } else {
                boolean zfHisApiMethods = hisApiMethod.ZfHisApiMethods(null, order);
                if (zfHisApiMethods) {
                    return AjaxResult.success("撤销成功", map);
                } else {
                    TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                    return AjaxResult.error("撤销失败,调用作废出现失败");
                }
            }
        }
        return AjaxResult.success();
    }
    @GetMapping("/revokeTjOrderByTjh")
    @ApiOperation(value = "根据就体检号删除记录")
    @Transactional
    public AjaxResult revokeTjOrderByTjh(@RequestParam @ApiParam(value = "体检号") String tjNum) {
        TjOrder order = tjOrderService.getOrderByTjNum(tjNum);
        if (null != order) {
//            String payByTjNum = tjOrderService.isPayByTjNum(String.valueOf(order.getOrderId()));
//            if (null != payByTjNum) {
//                return AjaxResult.error("该用户已收费不可撤销签到!");
//            }
            tjOrderService.deleteTjOrderByOrderId(order.getOrderId());
            tjOrderDetailService.deleteTjOrderDetailByOrderDetailId(String.valueOf(order.getOrderId()));
            remarkService.deletedOrderRemarkByTjNum(tjNum);
            tjFlowingWaterService.deleteTjFlowingWaterByOrderId(String.valueOf(order.getOrderId()));
            transitionService.deletedTbTransitionByTjNum(tjNum);
        }
        return AjaxResult.success();
    }
}