zjh
2023-10-17 4d1cc2fd7553f3c648da150971cd4a87c282f5ad
ltkj-admin/src/main/java/com/ltkj/web/controller/system/TjOrderController.java
@@ -15,6 +15,7 @@
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import cn.hutool.crypto.symmetric.DES;
import cn.hutool.extra.pinyin.PinyinUtil;
import com.alibaba.fastjson2.JSON;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
@@ -128,11 +129,14 @@
    @Resource
    private ITjRulesService rulesService;
    @Autowired
    private ITjAskMedicalHistoryService tjAskMedicalHistoryService;
    /**
     * 查询体检记录列表
     */
    @PreAuthorize("@ss.hasPermi('hosp:order:list')")
//    @PreAuthorize("@ss.hasPermi('hosp:order:list')")
    @GetMapping("/list")
    @ApiOperation(value = "查询体检记录列表(默认)")
    public TableDataInfo list(TjOrder tjOrder) {
@@ -558,8 +562,8 @@
                            order.setTjCustomerAge(DateUtil.ageOfNow(tjCustomer.getCusBrithday()));
                            order.setGrMoBanId(reportService.getGrMoBanIds());
                            order.setTjCustomerName(MatchUtils.hideCusName(tjCustomer.getCusName()));
                            order.setTjCustomerPhone(MatchUtils.hidePhoneNum(tjCustomer.getCusPhone()));
                            order.setTjCusIdCard(MatchUtils.hideIdCardNum(tjCustomer.getCusIdcard()));
                            if(null!=tjCustomer.getCusPhone())order.setTjCustomerPhone(MatchUtils.hidePhoneNum(tjCustomer.getCusPhone()));
                            if(null!=tjCustomer.getCusIdcard())order.setTjCusIdCard(MatchUtils.hideIdCardNum(tjCustomer.getCusIdcard()));
                        }
                        String firmId = order.getFirmId();
                        if (firmId != null && null != iDictCompService.getById(String.valueOf(order.getFirmId()))) {
@@ -609,8 +613,8 @@
                        order.setTjCustomerAge(DateUtil.ageOfNow(tjCustomer.getCusBrithday()));
                        order.setGrMoBanId(reportService.getGrMoBanIds());
                        order.setTjCustomerName(MatchUtils.hideCusName(tjCustomer.getCusName()));
                        order.setTjCustomerPhone(MatchUtils.hidePhoneNum(tjCustomer.getCusPhone()));
                        order.setTjCusIdCard(MatchUtils.hideIdCardNum(tjCustomer.getCusIdcard()));
                        if(null!=tjCustomer.getCusPhone())order.setTjCustomerPhone(MatchUtils.hidePhoneNum(tjCustomer.getCusPhone()));
                        if(null!=tjCustomer.getCusIdcard())order.setTjCusIdCard(MatchUtils.hideIdCardNum(tjCustomer.getCusIdcard()));
                    }
                    String firmId = order.getFirmId();
                    if (firmId != null && null != iDictCompService.getById(String.valueOf(order.getFirmId()))) {
@@ -652,43 +656,21 @@
        List<TjOrder> list = Optional.ofNullable(tjOrderService.list(wq)).get();
        if (list.size() > 0) {
            List<TjOrder> list1 = new ArrayList<>();
            for (TjOrder order : list) {
                TjCustomer tjCustomer = tjCustomerService.selectTjCustomerByCusId(order.getUserId());
                if (null != tjCustomer) {
                    order.setTjCustomerSex(tjCustomer.getCusSex());
                    order.setTjCustomerAge(DateUtil.ageOfNow(tjCustomer.getCusBrithday()));
                    order.setGrMoBanId(reportService.getGrMoBanIds());
                    order.setTjCustomerName(MatchUtils.hideCusName(tjCustomer.getCusName()));
                    order.setTjCustomerPhone(MatchUtils.hidePhoneNum(tjCustomer.getCusPhone()));
                    order.setTjCusIdCard(MatchUtils.hideIdCardNum(tjCustomer.getCusIdcard()));
            asyncService.getPrintOrderList(list);
            if(redisCache.hasKey("getPrintOrderList")){
                if(null !=type && type==0){
                    List<TjOrder> list1 = redisCache.getCacheMapValue("getPrintOrderList", "0");
                    collect = list1.stream().skip((long) (pageNum - 1) * pageSize).limit(pageSize).collect(Collectors.toList());
                }
                String firmId = order.getFirmId();
                if (firmId != null && null != iDictCompService.selectDictCompByDrugManufacturerId(String.valueOf(order.getFirmId()))) {
                    order.setDictCompName(iDictCompService.selectDictCompByDrugManufacturerId(String.valueOf(order.getFirmId())).getCnName());
                if(null !=type && type==1){
                    List<TjOrder> list1 = redisCache.getCacheMapValue("getPrintOrderList","1");
                    collect = list1.stream().skip((long) (pageNum - 1) * pageSize).limit(pageSize).collect(Collectors.toList());
                }
                if (null != order.getPacId()) {
                    if (null != tjPackageService.getById(order.getPacId())) {
                        order.setPacName(tjPackageService.getById(order.getPacId()).getPacName());
                    }
                    if (null != dwDeptService.getById(order.getPacId())) {
                        order.setPacName(dwDeptService.getById(order.getPacId()).getDwDeptName());
                    }
                }
                //从打印记录查出最新打印时间
                TjPrintOrder one = printOrderService.getTjPrintOrderByTjNum(order.getTjNumber());
                if (null != type && type == 1 && one != null) {
                    order.setPrintTime(one.getCreateTime());
                    order.setPrintName(one.getCreateBy());
                    order.setType(1);
                    list1.add(order);
                }
                if (null != type && type == 0 && one == null) {
                    order.setType(0);
                    list1.add(order);
                }
            }else {
                List<TjOrder> list1 = new ArrayList<>();
                extracted(type, list, list1);
                collect = list1.stream().skip((long) (pageNum - 1) * pageSize).limit(pageSize).collect(Collectors.toList());
            }
            collect = list1.stream().skip((long) (pageNum - 1) * pageSize).limit(pageSize).collect(Collectors.toList());
        }
        if (null != collect) {
            map.put("total", collect.size());
@@ -699,11 +681,49 @@
        return AjaxResult.success(map);
    }
    private void extracted(Integer type, List<TjOrder> list, List<TjOrder> list1) {
        for (TjOrder order : list) {
            TjCustomer tjCustomer = tjCustomerService.selectTjCustomerByCusId(order.getUserId());
            if (null != tjCustomer) {
                order.setTjCustomerSex(tjCustomer.getCusSex());
                order.setTjCustomerAge(DateUtil.ageOfNow(tjCustomer.getCusBrithday()));
                order.setGrMoBanId(reportService.getGrMoBanIds());
                order.setTjCustomerName(MatchUtils.hideCusName(tjCustomer.getCusName()));
                if(null!=tjCustomer.getCusPhone())order.setTjCustomerPhone(MatchUtils.hidePhoneNum(tjCustomer.getCusPhone()));
                if(null!=tjCustomer.getCusIdcard())order.setTjCusIdCard(MatchUtils.hideIdCardNum(tjCustomer.getCusIdcard()));
            }
            String firmId = order.getFirmId();
            if (firmId != null && null != iDictCompService.selectDictCompByDrugManufacturerId(String.valueOf(order.getFirmId()))) {
                order.setDictCompName(iDictCompService.selectDictCompByDrugManufacturerId(String.valueOf(order.getFirmId())).getCnName());
            }
            if (null != order.getPacId()) {
                if (null != tjPackageService.getById(order.getPacId())) {
                    order.setPacName(tjPackageService.getById(order.getPacId()).getPacName());
                }
                if (null != dwDeptService.getById(order.getPacId())) {
                    order.setPacName(dwDeptService.getById(order.getPacId()).getDwDeptName());
                }
            }
            //从打印记录查出最新打印时间
            TjPrintOrder one = printOrderService.getTjPrintOrderByTjNum(order.getTjNumber());
            if (null != type && type == 1 && one != null) {
                order.setPrintTime(one.getCreateTime());
                order.setPrintName(one.getCreateBy());
                order.setType(1);
                list1.add(order);
            }
            if (null != type && type == 0 && one == null) {
                order.setType(0);
                list1.add(order);
            }
        }
    }
    /**
     * 导出体检记录列表
     */
    @PreAuthorize("@ss.hasPermi('hosp:order:export')")
//    @PreAuthorize("@ss.hasPermi('hosp:order:export')")
    @Log(title = "体检记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ApiOperation(value = "导出体检记录列表")
@@ -717,7 +737,7 @@
    /**
     * 获取体检记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('hosp:order:query')")
//    @PreAuthorize("@ss.hasPermi('hosp:order:query')")
    @GetMapping(value = "/{orderId}")
    @ApiOperation(value = "获取体检记录详细信息")
    public AjaxResult getInfo(@PathVariable("orderId") Long orderId) {
@@ -814,10 +834,8 @@
            }
            tjFlowingWater.setOrderId(tjOrder.getOrderId());
            Date date1 = new Date(System.currentTimeMillis());
            SimpleDateFormat sdf = new SimpleDateFormat("yyMMddHHmmssSSS");
            String userId1 = SecurityUtils.getUsername();
            String s1 = userId1 + sdf.format(date1);
            tjFlowingWater.setWaterId(s1);
            String s1 = SecurityUtils.getUsername() + new SimpleDateFormat("yyMMddHHmmssSSS").format(date1);
            tjFlowingWater.setWaterId(PinyinUtil.getFirstLetter(tjCustomer.getCusName(),"")+s1);
            if (null != mallOrder) {
                if (mallOrder.getOrderStatus().equals(201L)) {
                    tjFlowingWater.setCopeWith(mallOrder.getActualPrice());
@@ -858,7 +876,9 @@
            //个人
            if ("2".equals(tjOrder.getTjType())) {
                asyncService.extracted(tjOrder, tjCustomer, discount, sysUser, tjReservation, tjFlowingWater);
//                asyncService.newSaveextracted(tjOrder, tjCustomer, discount, sysUser, tjReservation, tjFlowingWater);
                newSaveextracted(tjOrder, tjCustomer, discount, sysUser, tjReservation, tjFlowingWater);
            }
            return AjaxResult.success(tjNumber);
        }
@@ -869,7 +889,7 @@
    /**
     * 修改体检记录
     */
    @PreAuthorize("@ss.hasPermi('hosp:order:edit')")
//    @PreAuthorize("@ss.hasPermi('hosp:order:edit')")
    @Log(title = "体检记录", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation(value = "修改体检记录")
@@ -880,7 +900,7 @@
    /**
     * 删除体检记录
     */
    @PreAuthorize("@ss.hasPermi('hosp:order:remove')")
//    @PreAuthorize("@ss.hasPermi('hosp:order:remove')")
    @Log(title = "体检记录", businessType = BusinessType.DELETE)
    @DeleteMapping("/{orderIds}")
    @ApiOperation(value = "删除体检记录")
@@ -934,6 +954,7 @@
        } else {
            tbTransitionList = redisCache.getCacheList(cusId);
        }
        //套餐
        if (null != packId && !packId.equals("")) {
            Long pacId = Long.valueOf(packId.toString());
            List<TbTransition> list = transitionService.getTbTransitionListByCusIdAndPac(cusId, String.valueOf(pacId));
@@ -947,11 +968,12 @@
                List<TjPackageProject> ppList = tjPackageProjectService.getTjPackageProjectListByPacId(String.valueOf(pacId));
                if (null != ppList && ppList.size() > 0) {
                    //异步保存数据库
                    asyncService.addRedisTransitionPac(cusId, pacId, ppList);
//                    asyncService.addRedisTransitionPac(cusId, pacId, ppList);
                    asyncService.saveRedisTransitionByPacId(cusId, pacId,proIds);
                    for (TjPackageProject tjPackageProject : ppList) {
                        TjProject project = projectService.getTjProjectById(String.valueOf(tjPackageProject.getProId()));
                        if (null != project) {
                            BigDecimal divide = tjPackageProject.getPriceNow().divide(project.getProPrice(), 5, RoundingMode.DOWN);
                            BigDecimal divide = tjPackageProject.getPriceNow().divide(project.getProPrice(), 5, RoundingMode.HALF_DOWN);
                            List<TjProject> tjProSonList = projectService.getTjProjectListBySoneId(String.valueOf(project.getProId()));
                            if (null != tjProSonList && tjProSonList.size() > 0) {
                                //addRedisTransitionPac(cusId, tbTransitionList, pacId, tjPackageProject, project, divide, tjProSonList);
@@ -959,11 +981,6 @@
                                    TbTransition tbTransition = new TbTransition();
                                    tbTransition.setCusId(cusId);
                                    tbTransition.setPacId(pacId);
//                                    if (null != tjProject.getProPrice()) {
//                                        tbTransition.setOrdPrice(tjProject.getProPrice());
//                                    } else {
//                                        tbTransition.setOrdPrice(BigDecimal.valueOf(0.00));
//                                    }
                                    if (null != tjPackageProject.getPriceNow() && divide.compareTo(BigDecimal.valueOf(0)) > 0) {
                                        tbTransition.setNowPrice(tjProject.getProPrice().multiply(divide).setScale(2, RoundingMode.HALF_DOWN));
                                        tbTransition.setOrdPrice(tjProject.getProPrice().multiply(divide).setScale(2, RoundingMode.HALF_DOWN));
@@ -987,8 +1004,13 @@
                }
            }
        }
        //单项
        if (null != proIds && proIds.size() > 0) {
            asyncService.addRedisTransitionPro(cusId, proIds);
            //异步保存数据库表
//            asyncService.addRedisTransitionPro(cusId, proIds);
            asyncService.saveRedisTransitionByPacId(cusId,null,proIds);
            for (Long proId : proIds) {
                List<TbTransition> transitions = transitionService.getTbTransitionListByCusIdAndPacIdAndProId(cusId, String.valueOf(proId));
                if (null != transitions && transitions.size() > 0) {
@@ -998,7 +1020,6 @@
                if (null != project) {
                    List<TjProject> tjProSonList = projectService.getTjProjectListBySoneId(String.valueOf(project.getProId()));
                    if (null != tjProSonList && tjProSonList.size() > 0) {
                        //异步保存数据库表
                        for (TjProject tjProject : tjProSonList) {
                            List<TbTransition> transitionss = transitionService.getTbTransitionListByCusIdAndPacIdAndProId(cusId, String.valueOf(tjProject.getProId()));
                            if (null != transitionss && transitionss.size() > 0) {
@@ -1294,9 +1315,6 @@
        List<Map<String, Object>> list = new ArrayList<>();
        for (Map.Entry<Long, List<TbTransition>> entry : collect.entrySet()) {
            Map<String, Object> map = new HashMap<>();
            LambdaQueryWrapper<TbTransition> wq = new LambdaQueryWrapper<>();
            wq.eq(TbTransition::getCusId, cusId);
            wq.eq(TbTransition::getParentProId, entry.getKey());
            Long pacId = entry.getValue().get(0).getPacId();
            if (null != pacId) {
                TjPackage aPackage = tjPackageService.getById(entry.getValue().get(0).getPacId());
@@ -1313,21 +1331,20 @@
                for (TbTransition tbTransition : tbTransitionList) {
                    money1 = money1.add(tbTransition.getOrdPrice());
                    money2 = money2.add(tbTransition.getNowPrice());
                    if (tbTransition.getOrdPrice().compareTo(BigDecimal.valueOf(0)) == 0 || tbTransition.getNowPrice().compareTo(BigDecimal.valueOf(0)) == 0) {
                        tbTransition.setDiscount("0");
                    } else {
                        tbTransition.setDiscount((tbTransition.getNowPrice()).divide(tbTransition.getOrdPrice(), BigDecimal.ROUND_CEILING).toString());
                    }
                    if (null != tbTransition.getPacId()) {
                        tbTransition.setPacPrice(tjPackageService.getById(tbTransition.getPacId()).getPrice());
                    }
                    if (null != tbTransition.getParentProId()) {
                        tbTransition.setPacPrice(projectService.getTjProjectById(String.valueOf(tbTransition.getParentProId())).getProPrice());
                    }
//                    if (tbTransition.getOrdPrice().compareTo(BigDecimal.valueOf(0)) == 0 || tbTransition.getNowPrice().compareTo(BigDecimal.valueOf(0)) == 0) {
//                        tbTransition.setDiscount("0");
//                    } else {
//                        tbTransition.setDiscount((tbTransition.getNowPrice()).divide(tbTransition.getOrdPrice(), BigDecimal.ROUND_CEILING).toString());
//                    }
//                    if (null != tbTransition.getPacId()) {
//                        tbTransition.setPacPrice(tjPackageService.getById(tbTransition.getPacId()).getPrice());
//                    }
//                    if (null != tbTransition.getParentProId()) {
//                        tbTransition.setPacPrice(projectService.getTjProjectById(String.valueOf(tbTransition.getParentProId())).getProPrice());
//                    }
                }
//                map.put("ordPrice", money1.setScale(Integer.parseInt(configService.selectConfigByKey("sys.price.save")), Integer.parseInt(configService.selectConfigByKey("sys.price"))));
//                map.put("nowPrice", money2.setScale(Integer.parseInt(configService.selectConfigByKey("sys.price.save")), Integer.parseInt(configService.selectConfigByKey("sys.price"))));
                map.put("ordPrice", money1);
                map.put("nowPrice", money2);
            }
@@ -1546,4 +1563,27 @@
        wq.eq(TbTransition::getCusId,cusId);
        return AjaxResult.success(transitionService.remove(wq));
    }
    public void newSaveextracted(TjOrder tjOrder, TjCustomer tjCustomer, BigDecimal discount, SysUser sysUser, TjReservation tjReservation, TjFlowingWater tjFlowingWater) {
        long l = System.currentTimeMillis();
        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()));
        //修改每项的原价现价
        transitionService.updateTbTransitionPriceByCusId(tjCustomer.getCusIdcard(),discount);
        //添加remark表数据
        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) {
                tjOrderDetailService.updateTjOrderDetailsByOrderId(String.valueOf(tjOrder.getOrderId()),
                        sysUser.getNickName(), String.valueOf(sysUser.getUserId()),String.valueOf(tjFlowingWater.getTjSerialNumber()));
            }
        }
        if (tjFlowingWater.getPayStasus() == 1) {
            tjOrderDetailService.updateTjOrderDetailsByOrderId(String.valueOf(tjOrder.getOrderId()),
                    sysUser.getNickName(), String.valueOf(sysUser.getUserId()),String.valueOf(tjFlowingWater.getTjSerialNumber()));
        }
        System.out.println("这段代码时间"+(System.currentTimeMillis()-l));
    }
}