lige
2024-01-24 d8b9f897e40a9640780a64cf7569e306d65b156b
ltkj-admin/src/main/java/com/ltkj/web/controller/system/TjFlowingWaterController.java
@@ -7,6 +7,7 @@
import javax.servlet.http.HttpServletResponse;
import cn.hutool.core.date.DateUtil;
import cn.hutool.extra.pinyin.PinyinUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.ltkj.common.core.domain.entity.SysUser;
import com.ltkj.common.utils.SecurityUtils;
@@ -68,7 +69,8 @@
    private TjAsyncService asyncService;
    @Resource
    private IJimuOnlineReportService reportService;
    @Resource
    private ITjPackageProjectService tjPackageProjectService;
    /**
     * 查询该体检号对应的订单流水列表
@@ -104,7 +106,7 @@
    /**
     * 查询体检流水列表
     */
    @PreAuthorize("@ss.hasPermi('hosp:water:list')")
//    @PreAuthorize("@ss.hasPermi('hosp:water:list')")
    @GetMapping("/list")
    @ApiOperation(value = "查询体检流水列表")
    public TableDataInfo list(TjFlowingWater tjFlowingWater) {
@@ -205,7 +207,7 @@
        TjOrder order = orderService.getById(tjFlowingWater.getOrderId());
        TjCustomer customer = customerService.getById(order.getUserId());
        if (null != tjFlowingWater.getTjProIds() && tjFlowingWater.getTjProIds().length > 0) {
            tjFlowingWater.setWaterId(SecurityUtils.getUsername() + DateUtil.format(new Date(), "yyMMddHHmmssSSS"));
            tjFlowingWater.setWaterId(PinyinUtil.getFirstLetter(customer.getCusName(), "").toUpperCase() + DateUtil.format(new Date(), "yyMMddHHmmssSSS"));
            tjFlowingWater.setIsAddition("Y");
            if (tjFlowingWaterService.save(tjFlowingWater)) {
                //异步单项收费明细
@@ -254,127 +256,11 @@
        return AjaxResult.error();
    }
   /* private void extracted(TjFlowingWater tjFlowingWater, TjOrder order, TjCustomer customer) {
        List<TjConsumables> list2 = new ArrayList<>();
        String[] tjProIds = tjFlowingWater.getTjProIds();
        for (String tjProId : tjProIds) {
            LambdaQueryWrapper<TjProject> wq0 = new LambdaQueryWrapper<>();
            wq0.eq(TjProject::getProParentId, tjProId);
            List<Long> proIds = projectService.list(wq0).stream().map(TjProject::getProId).collect(Collectors.toList());
            TjOrderDetail detail = new TjOrderDetail();
            detail.setTjStatus(0L);
            detail.setOrderId(tjFlowingWater.getOrderId());
            detail.setFlowingWaterId(String.valueOf(tjFlowingWater.getTjSerialNumber()));
            detail.setProId(Long.valueOf(tjProId));
            detail.setIsAddition("Y");
            detailService.save(detail);
            for (Long proId : proIds) {
                TjOrderDetail detail1 = new TjOrderDetail();
                detail1.setTjStatus(0L);
                detail1.setOrderId(tjFlowingWater.getOrderId());
                detail1.setFlowingWaterId(String.valueOf(tjFlowingWater.getTjSerialNumber()));
                detail1.setProId(proId);
                detail1.setIsAddition("Y");
                detailService.save(detail1);
            }
            LambdaQueryWrapper<TbTransition> wqq = new LambdaQueryWrapper<>();
            wqq.eq(TbTransition::getCusId, customer.getCusIdcard());
            wqq.in(TbTransition::getProId, proIds);
            List<TbTransition> tbTransitionList = transitionService.list(wqq);
            if (null != tbTransitionList && tbTransitionList.size() > 0) {
                for (TbTransition transition : tbTransitionList) {
                    TjProject tjProject = projectService.selectTjProjectByProId(transition.getProId());
                    //子项
                    if (null != tjProject) {
                        TjChargingStandard tjChargingStandard = new TjChargingStandard();
                        tjChargingStandard.setTjNum(order.getTjNumber());
                        tjChargingStandard.setProId(transition.getProId());
                        tjChargingStandard.setPrice(transition.getNowPrice());
                        tjChargingStandard.setProName(tjProject.getProName());
                        chargingStandardService.save(tjChargingStandard);
                    }
                }
                //父项
                TjProject parentProject = projectService.getById(tjProId);
                if (null != parentProject) {
                    LambdaQueryWrapper<TjProConsumables> wqqq = new LambdaQueryWrapper<>();
                    wqqq.eq(TjProConsumables::getProId, parentProject.getProId());
                    List<TjProConsumables> proConsumables = proConsumablesService.list(wqqq);
                    if (null != proConsumables && proConsumables.size() > 0) {
                        for (TjProConsumables tjProConsumables : proConsumables) {
                            TjConsumables tjConsumables = consumablesService.selectTjConsumablesById(tjProConsumables.getConsumablesId());
                            list2.add(tjConsumables);
                        }
                    }
                }
            }
        }
        //父项耗材
        ArrayList<TjConsumables> collect = list2.stream().collect(Collectors.collectingAndThen(Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(TjConsumables::getId))), ArrayList::new));
        for (TjConsumables tjConsumables : collect) {
            TjChargingStandard tjChargingStandard = new TjChargingStandard();
            tjChargingStandard.setTjNum(order.getTjNumber());
            tjChargingStandard.setConsumablesId(tjConsumables.getId());
            tjChargingStandard.setPrice(tjConsumables.getPrice());
            tjChargingStandard.setProName(tjConsumables.getMakings());
            tjChargingStandard.setConsumablesName(tjConsumables.getMakings());
            tjChargingStandard.setCompany(tjConsumables.getSpecifications());
            chargingStandardService.save(tjChargingStandard);
        }
    }*/
    //备用添加收费明细
    /*private void extracted(TjOrder order, List<TjConsumables> list2, List<TbTransition> tbTransitionList) {
        for (TbTransition transition : tbTransitionList) {
            TjProject tjProject = projectService.selectTjProjectByProId(transition.getProId());
            //子项
            if (null != tjProject) {
                TjChargingStandard tjChargingStandard = new TjChargingStandard();
                tjChargingStandard.setTjNum(order.getTjNumber());
                tjChargingStandard.setProId(transition.getProId());
                tjChargingStandard.setPrice(transition.getNowPrice());
                tjChargingStandard.setProName(tjProject.getProName());
                chargingStandardService.save(tjChargingStandard);
            }
        }
        //父项
        ArrayList<TbTransition> collect1 = tbTransitionList.stream().collect(Collectors.collectingAndThen(Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(TbTransition::getParentProId))), ArrayList::new));
        List<Long> parentProIds = collect1.stream().map(TbTransition::getParentProId).collect(Collectors.toList());
        if (parentProIds.size() > 0) {
            for (Long parentProId : parentProIds) {
                TjProject parentProject = projectService.selectTjProjectByProId(parentProId);
                if (null != parentProject) {
                    LambdaQueryWrapper<TjProConsumables> wqqq = new LambdaQueryWrapper<>();
                    wqqq.eq(TjProConsumables::getProId, parentProject.getProId());
                    List<TjProConsumables> proConsumables = proConsumablesService.list(wqqq);
                    if (null != proConsumables && proConsumables.size() > 0) {
                        for (TjProConsumables tjProConsumables : proConsumables) {
                            TjConsumables tjConsumables = consumablesService.selectTjConsumablesById(tjProConsumables.getConsumablesId());
                            list2.add(tjConsumables);
                        }
                    }
                }
            }
        }
        ArrayList<TjConsumables> collect = list2.stream().collect(Collectors.collectingAndThen(Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(TjConsumables::getId))), ArrayList::new));
        for (TjConsumables tjConsumables : collect) {
            TjChargingStandard tjChargingStandard = new TjChargingStandard();
            tjChargingStandard.setTjNum(order.getTjNumber());
            tjChargingStandard.setConsumablesId(tjConsumables.getId());
            tjChargingStandard.setPrice(tjConsumables.getPrice());
            tjChargingStandard.setProName(tjConsumables.getMakings());
            tjChargingStandard.setConsumablesName(tjConsumables.getMakings());
            tjChargingStandard.setCompany(tjConsumables.getSpecifications());
            chargingStandardService.save(tjChargingStandard);
        }
    }*/
    /**
     * 删除体检流水
     */
    @PreAuthorize("@ss.hasPermi('hosp:water:remove')")
//    @PreAuthorize("@ss.hasPermi('hosp:water:remove')")
    @Log(title = "体检流水", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids) {
@@ -419,8 +305,8 @@
                    List<TjOrderDetail> detailList = detailService.list(wq2);
                    if (null != detailList && detailList.size() > 0) {
                        TjRefundVo tjRefundVo = new TjRefundVo();
                        tjRefundVo.setTjName(MatchUtils.hideCusName(customer.getCusName()));
                        tjRefundVo.setTjPhone(MatchUtils.hidePhoneNum(customer.getCusPhone()));
                        tjRefundVo.setTjName(customer.getCusName());
                        tjRefundVo.setTjPhone(customer.getCusPhone());
                        tjRefundVo.setTjNumber(order.getTjNumber());
                        tjRefundVo.setTjOrderId(String.valueOf(order.getOrderId()));
                        if (null != order.getDictCompName()) tjRefundVo.setTjComp(order.getDictCompName());
@@ -466,8 +352,8 @@
                        TjCustomer customer = customerService.getById(order.getUserId());
                        if (null != customer) {
                            TjRefundVo tjRefundVo = new TjRefundVo();
                            tjRefundVo.setTjName(MatchUtils.hideCusName(customer.getCusName()));
                            tjRefundVo.setTjPhone(MatchUtils.hidePhoneNum(customer.getCusPhone()));
                            tjRefundVo.setTjName(customer.getCusName());
                            tjRefundVo.setTjPhone(customer.getCusPhone());
                            tjRefundVo.setTjNumber(order.getTjNumber());
                            tjRefundVo.setTjOrderId(String.valueOf(order.getOrderId()));
                            if (null != order.getDictCompName()) tjRefundVo.setTjComp(order.getDictCompName());
@@ -531,10 +417,10 @@
                            if (null != detailList && detailList.size() > 0) {
                                TjCollectFeesVo tjRefundVo = new TjCollectFeesVo();
                                tjRefundVo.setTjCusId(String.valueOf(customer.getCusId()));
                                tjRefundVo.setTjName(MatchUtils.hideCusName(customer.getCusName()));
                                tjRefundVo.setTjPhone(MatchUtils.hidePhoneNum(customer.getCusPhone()));
                                tjRefundVo.setTjName(customer.getCusName());
                                tjRefundVo.setTjPhone(customer.getCusPhone());
                                tjRefundVo.setSex(String.valueOf(customer.getCusSex()));
                                tjRefundVo.setIdCard(MatchUtils.hideIdCardNum(customer.getCusIdcard()));
                               if(null !=customer.getCusIdcard()) tjRefundVo.setIdCard(customer.getCusIdcard());
                                DictComp dictComp = compService.getById(order.getFirmId());
                                if(null !=dictComp){
                                    tjRefundVo.setTjComp(dictComp.getCnName());
@@ -597,7 +483,7 @@
        if (null != tjNum) {
            LambdaQueryWrapper<TjOrder> wq1 = new LambdaQueryWrapper<>();
            wq1.likeLeft(TjOrder::getTjNumber, tjNum);
            wq1.eq(TjOrder::getCheckStatus, 0);
//            wq1.eq(TjOrder::getCheckStatus, 0);
            List<TjOrder> orderList = orderService.list(wq1);
            if (null != orderList && orderList.size() > 0) {
                for (TjOrder order : orderList) {
@@ -610,12 +496,16 @@
                        if (null != customer) {
                            TjCollectFeesVo tjRefundVo = new TjCollectFeesVo();
                            tjRefundVo.setTjCusId(String.valueOf(customer.getCusId()));
                            tjRefundVo.setTjName(MatchUtils.hideCusName(customer.getCusName()));
                            tjRefundVo.setTjPhone(MatchUtils.hidePhoneNum(customer.getCusPhone()));
                            tjRefundVo.setTjName(customer.getCusName());
                            tjRefundVo.setTjPhone(customer.getCusPhone());
                            tjRefundVo.setSex(String.valueOf(customer.getCusSex()));
                            tjRefundVo.setIdCard(MatchUtils.hideIdCardNum(customer.getCusIdcard()));
                            if (null != order.getDictCompName())
                                tjRefundVo.setTjComp(compService.getById(order.getFirmId()) != null ? compService.getById(order.getFirmId()).getCnName() : null);
                            tjRefundVo.setIdCard(customer.getCusIdcard());
                            if (null != order.getFirmId()){
                                DictComp byId = compService.getById(order.getFirmId());
                                if(null != byId){
                                    tjRefundVo.setTjComp(byId.getCnName());
                                }
                            }
                            if (null != order.getTjType()) tjRefundVo.setTjType(order.getTjType());
                            TjFlowingWater one = tjFlowingWaterService.getOne(new LambdaQueryWrapper<TjFlowingWater>()
                                    .eq(TjFlowingWater::getOrderId, order.getOrderId())
@@ -652,22 +542,66 @@
                } else {
                    tjProjectList = detailService.selectTjOrderDetailListByFlowingWaterIdIsNotNull(OrderId);
                }
                String pacId = transitionService.selectPacIdByTbTransitionTjNumAndProId(order.getTjNumber());
                if (null != tjProjectList && tjProjectList.size() > 0) {
                    for (TjProject project : tjProjectList) {
                        if (project.getProParentId() == 0) {
                            LambdaQueryWrapper<TbTransition> wqq1 = new LambdaQueryWrapper<>();
                            wqq1.eq(TbTransition::getCusId, customerService.getById(order.getUserId()).getCusIdcard());
                            wqq1.eq(TbTransition::getParentProId, project.getProId());
                            List<TbTransition> tbTransitionList = transitionService.list(wqq1);
                            BigDecimal bigDecimal = new BigDecimal("0.00");
                            BigDecimal bigDecimal1 = new BigDecimal("0.00");
                            for (TbTransition transition : tbTransitionList) {
                                 bigDecimal = bigDecimal.add(transition.getNowPrice());
                                 bigDecimal1=bigDecimal1.add(transition.getOrdPrice());
/*                            //LambdaQueryWrapper<TbTransition> wqq1 = new LambdaQueryWrapper<>();
//                            wqq1.eq(TbTransition::getCusId, customerService.getById(order.getUserId()).getCusIdcard());
//                            wqq1.eq(TbTransition::getParentProId, project.getProId());
//                            List<TbTransition> tbTransitionList = transitionService.list(wqq1);
//                            BigDecimal bigDecimal = new BigDecimal("0.00");
//                            BigDecimal bigDecimal1 = new BigDecimal("0.00");
//                            for (TbTransition transition : tbTransitionList) {
//                                 bigDecimal = bigDecimal.add(transition.getNowPrice());
//                                 bigDecimal1=bigDecimal1.add(transition.getOrdPrice());
//                            }
//                            project.setProPrice(bigDecimal.setScale(0,BigDecimal.ROUND_UP));
//                            project.setProOrdPrice(bigDecimal1);
                            BigDecimal decimal = transitionService.getTbTransitionPriceAndOrdPrice(customerService.getById(order.getUserId()).getCusIdcard(),
                                    project.getProId());
                            String s = tjFlowingWaterService.getDiscount(OrderId);
                            if(null !=decimal){
//                                project.setProPrice(decimal.setScale(2));
                                project.setProPrice(decimal);
//                                project.setProOrdPrice(decimal.multiply(new BigDecimal(s)).setScale(2));
                                project.setProOrdPrice(decimal);
                            }else {
                                BigDecimal decimal1 = transitionService.getTbTransitionDxPriceAndOrdPrice(String.valueOf(order.getUserId()),project.getProId());
                                if(null !=decimal1){
                                    project.setProPrice(decimal1.setScale(2));
                                    project.setProOrdPrice(decimal1.multiply(new BigDecimal(s)).setScale(2));
                                }else {
                                    project.setProPrice(new BigDecimal("0.00").setScale(2));
                                    project.setProOrdPrice(new BigDecimal("0.00").setScale(2));
                                }
                            }*/
                            String s = tjFlowingWaterService.getDiscount(OrderId);
                            if(null !=pacId){
                                TjPackageProject pp = tjPackageProjectService.getOne(new LambdaQueryWrapper<TjPackageProject>().eq(TjPackageProject::getPacId, pacId)
                                        .eq(TjPackageProject::getProId,String.valueOf(project.getProId())));
                                if(null !=pp){
                                    project.setProPrice(pp.getPriceNow());
                                    project.setProOrdPrice(pp.getPriceNow().multiply(new BigDecimal(s)));
                                }else {
                                    project.setProPrice(project.getProPrice().setScale(2));
                                    project.setProOrdPrice(project.getProPrice().multiply(new BigDecimal(s)).setScale(2));
                                }
                            }else {
                                project.setProPrice(project.getProPrice().setScale(2));
                                project.setProOrdPrice(project.getProPrice().multiply(new BigDecimal(s)).setScale(2));
                            }
                            project.setProPrice(bigDecimal.setScale(0,BigDecimal.ROUND_UP));
                            project.setProOrdPrice(bigDecimal1);
                        }
                    }
                    TjPackageProject ppp = tjPackageProjectService.getOne(new LambdaQueryWrapper<TjPackageProject>().eq(TjPackageProject::getPacId, pacId)
                            .eq(TjPackageProject::getProId,"1735504273274236929"));
                    List<TjFlowingWater> list = tjFlowingWaterService.list(new LambdaQueryWrapper<TjFlowingWater>()
                            .eq(TjFlowingWater::getOrderId, order)
                            .eq(TjFlowingWater::getPayStasus, 2));
                    if(null != ppp && tjProjectList.size() > 0 &&null !=list&& list.size()>0){
                        TjProject project = projectService.selectTjProjectByProId(1735504273274236929L);
                        project.setProOrdPrice(project.getProPrice());
                        tjProjectList.add(project);
                    }
                }
                return AjaxResult.success(tjProjectList);
@@ -686,7 +620,7 @@
    public AjaxResult getTjRefundProInfoVoList(@RequestParam @ApiParam(value = "体检订单id") String orderId) {
        TjOrder tjOrder = orderService.getById(orderId);
        if (null == tjOrder) return AjaxResult.error("该体检记录不存在");
        TjCustomer customer = customerService.getById(tjOrder.getUserId());
//        TjCustomer customer = customerService.getById(tjOrder.getUserId());
        if (tjOrder.getCheckStatus() == 0 && tjOrder.getReportTime() == null) {
            LambdaQueryWrapper<TjOrderDetail> wq = new LambdaQueryWrapper<>();
            wq.eq(TjOrderDetail::getOrderId, orderId);
@@ -695,32 +629,43 @@
            wq.ne(TjOrderDetail::getTjStatus,3);
            wq.isNotNull(TjOrderDetail::getFlowingWaterId);
            List<TjOrderDetail> detailList = detailService.list(wq);
            String pacId = transitionService.selectPacIdByTbTransitionTjNumAndProId(tjOrder.getTjNumber());
            if (null != detailList && detailList.size() > 0) {
                List<TjRefundProInfoVo> tjRefundProInfoVoList = new ArrayList<>();
                for (TjOrderDetail detail : detailList) {
                    TjProject project = projectService.getById(detail.getProId());
                    if (project.getProParentId() == 0) {
                        LambdaQueryWrapper<TbTransition> wqq1 = new LambdaQueryWrapper<>();
                        wqq1.eq(TbTransition::getCusId, customer.getCusIdcard());
                        wqq1.eq(TbTransition::getParentProId, project.getProId());
                        List<TbTransition> tbTransitionList = transitionService.list(wqq1);
                        BigDecimal bigDecimal = new BigDecimal("0.00");
                        BigDecimal bigDecimal1 = new BigDecimal("0.00");
                        for (TbTransition transition : tbTransitionList) {
                            bigDecimal = bigDecimal.add(transition.getNowPrice());
                            bigDecimal1 = bigDecimal1.add(transition.getOrdPrice());
                        }
//                        LambdaQueryWrapper<TbTransition> wqq1 = new LambdaQueryWrapper<>();
//                        wqq1.eq(TbTransition::getCusId, customer.getCusIdcard());
//                        wqq1.eq(TbTransition::getParentProId, project.getProId());
//                        List<TbTransition> tbTransitionList = transitionService.list(wqq1);
//                        BigDecimal bigDecimal = new BigDecimal("0.00");
//                        BigDecimal bigDecimal1 = new BigDecimal("0.00");
//                        for (TbTransition transition : tbTransitionList) {
//                            bigDecimal = bigDecimal.add(transition.getNowPrice());
//                            bigDecimal1 = bigDecimal1.add(transition.getOrdPrice());
//                        }
                        String s = tjFlowingWaterService.getDiscount(orderId);
                        TjRefundProInfoVo proInfoVo = new TjRefundProInfoVo();
                       // double discount = Double.parseDouble(tjFlowingWaterService.getById(detail.getFlowingWaterId()).getDiscount());
                        //BigDecimal decimal = BigDecimal.valueOf(discount).divide(BigDecimal.valueOf(100));
                        //proInfoVo.setNetReceipts(bigDecimal.multiply(decimal).setScale(2, BigDecimal.ROUND_DOWN));
                        proInfoVo.setNetReceipts(bigDecimal);
                        if(null !=pacId){
                            TjPackageProject pp = tjPackageProjectService.getOne(new LambdaQueryWrapper<TjPackageProject>().eq(TjPackageProject::getPacId, pacId)
                                    .eq(TjPackageProject::getProId,String.valueOf(project.getProId())));
                            if(null !=pp){
                                proInfoVo.setNetReceipts(pp.getPriceNow().multiply(new BigDecimal(s)));
                                proInfoVo.setPrice(pp.getPriceNow());
                            }else {
                                proInfoVo.setNetReceipts(project.getProPrice().multiply(new BigDecimal(s)));
                                proInfoVo.setPrice(project.getProPrice());
                            }
                        }else {
                            proInfoVo.setNetReceipts(project.getProPrice().multiply(new BigDecimal(s)));
                            proInfoVo.setPrice(project.getProPrice());
                        }
                        proInfoVo.setCollectFeesTime(tjFlowingWaterService.getById(detail.getFlowingWaterId()).getUpdateTime());
                        proInfoVo.setTollCollector(userService.getById(tjFlowingWaterService.getById(detail.getFlowingWaterId()).getTollCollectorId()).getNickName());
                        proInfoVo.setProName(project.getProName());
                        proInfoVo.setProId(String.valueOf(project.getProId()));
                        //proInfoVo.setPrice(project.getProPrice().setScale(2, BigDecimal.ROUND_DOWN));
                        proInfoVo.setPrice(bigDecimal1);
                        tjRefundProInfoVoList.add(proInfoVo);
                    }
                }
@@ -743,7 +688,7 @@
        tjFlowingWater.setRefundTime(new Date());
        tjFlowingWater.setIsAddition("N");
        tjFlowingWater.setPayStasus(2L);
        tjFlowingWater.setWaterId(SecurityUtils.getUsername() + DateUtil.format(new Date(), "yyMMddHHmmssSSS"));
        tjFlowingWater.setWaterId("TF"+SecurityUtils.getUsername() + DateUtil.format(new Date(), "yyMMddHHmmssSSS"));
        tjFlowingWater.setPaidIn(BigDecimal.valueOf(0.00).subtract(tjFlowingWater.getRefundPrice()));
        tjFlowingWater.setCopeWith(tjFlowingWater.getRefundPrice());
        if (tjFlowingWaterService.save(tjFlowingWater)){