liujie
2025-08-11 7c9f5fc33099083e0e1f5afcaad86546293bd08d
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TbCompanyServiceImpl.java
@@ -25,6 +25,7 @@
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.function.Consumer;
import java.util.stream.Collectors;
/**
@@ -83,17 +84,15 @@
            queryWrapper.in(TbCompany::getId, tbPermits.stream().map(TbPermit::getCompanyId).collect(Collectors.toList()));
        }
        queryWrapper.eq(TbCompany::getCityCode, query.getCityCode());
        queryWrapper.eq(TbCompany::getAreaCode, query.getAreaCode());
        queryWrapper.like(StringUtils.isNotEmpty(query.getCompanyName()),TbCompany::getCompanyName, query.getCompanyName());
        if (query.getAreaCode() != null && !"".equals(query.getAreaCode())) {
            queryWrapper.eq(TbCompany::getAreaCode, query.getAreaCode());
        }
        queryWrapper.like(StringUtils.isNotEmpty(query.getCompanyName()), TbCompany::getCompanyName, query.getCompanyName());
        if (query.getCompanyCategorys() != null && query.getCompanyCategorys().size() > 0) {
            queryWrapper.in(TbCompany::getCompanyCategory, query.getCompanyCategorys());
        }
        if (query.getRegisteredCapitals() != null && query.getRegisteredCapitals().size() > 0) {
            queryWrapper.in(TbCompany::getRegisteredCapital, query.getRegisteredCapitals());
        }
        if (query.getCompanyIndustryIds() != null && query.getCompanyIndustryIds().size() > 0) {
            queryWrapper.in(TbCompany::getCompanyIndustryId, query.getCompanyIndustryIds());
@@ -124,13 +123,48 @@
        if (query.getHaveSoftWorks() != null) {
            queryWrapper.eq(TbCompany::getHaveSoftWorks, query.getHaveSoftWorks());
        }
        if (query.getMoneySort() != null && query.getMoneySort() == 1) {
            queryWrapper.orderByDesc(TbCompany::getSaleMoney);
        } else if (query.getMoneySort() != null && query.getMoneySort() == 2) {
            queryWrapper.orderByAsc(TbCompany::getSaleMoney);
        } else {
            queryWrapper.orderByDesc(TbCompany::getCreateTime);
        String sql="";
        if (query.getRegisteredCapitals() != null && query.getRegisteredCapitals().size() > 0) {
            List<String> registeredCapitals = query.getRegisteredCapitals();
            sql += " and (";
            boolean first = true;
            for (String registeredCapital : registeredCapitals) {
                if (!first) {
                    sql += " OR ";
                }
                switch (registeredCapital) {
                    case "10W以下":
                        sql += " (registered_capital between 0 and 10)";
                        break;
                    case "10-50W以下":
                        sql += " (registered_capital between 10 and 50)";
                        break;
                    case "50-100W以下":
                        sql += " (registered_capital between 50 and 100)";
                        break;
                    case "100-500W以下":
                        sql += " (registered_capital between 100 and 501)";
                        break;
                    case "500-1000W以下":
                        sql += " (registered_capital between 500 and 1000)";
                        break;
                    case "1000W以上":
                        sql += " (registered_capital >= 1000)";
                        break;
                }
                first = false;
            }
            sql += ")";
        }
        if (query.getMoneySort() != null && query.getMoneySort() == 1) {
            sql += " ORDER BY sale_money DESC";
        } else if (query.getMoneySort() != null && query.getMoneySort() == 2) {
            sql += " ORDER BY sale_money ASC";
        } else {
            sql += " ORDER BY create_time DESC";
        }
        queryWrapper.last(sql);
        Page<TbCompany> companyPage = this.baseMapper.selectPage(page, queryWrapper);
        if (companyPage.getRecords().isEmpty()) {
            return page1;
@@ -151,6 +185,7 @@
            indexCompanyListVo.setHighTechEnterpriseTechnology(record.getHighTechEnterpriseTechnology());
            indexCompanyListVo.setPaidInFunds(record.getPaidInFunds());
            indexCompanyListVo.setRegisteredCapital(record.getRegisteredCapital());
            indexCompanyListVo.setRealRegisteredCapital(record.getRealRegisteredCapital());
            indexCompanyListVo.setSaleMoney(record.getSaleMoney());
            if (record.getUserId().equals(userId.toString())) {
                indexCompanyListVo.setIsMyself(1);
@@ -209,7 +244,16 @@
    @Override
    public Page<MyPushCompanyListVo> getMyPushCompanyList(MyPushCompanyListQuery query, Long userId) {
        Page<MyPushCompanyListVo> page = new Page<>(query.getPageNum(), query.getPageSize());
        return this.baseMapper.getMyPushCompanyList(page, query, userId);
        Page<MyPushCompanyListVo> myPushCompanyList = this.baseMapper.getMyPushCompanyList(page, query, userId);
        for (MyPushCompanyListVo record : myPushCompanyList.getRecords()) {
            if (record.getStatus() != 1) {
                TbOrder order = orderService.getOne(new LambdaQueryWrapper<TbOrder>().eq(TbOrder::getCompanyId, record.getId()).ne(TbOrder::getStatus, -1).last("limit 1"));
                if (order != null) {
                    record.setOrderId(order.getId());
                }
            }
        }
        return myPushCompanyList;
    }
    @Override
@@ -219,15 +263,17 @@
        map.put("toBeConfirmed", list.stream().filter(e -> e.getStatus() == 2).count());
        map.put("confirmed", list.stream().filter(e -> e.getStatus() == 3).count());
        map.put("processing", list.stream().filter(e -> e.getStatus() == 4).count());
        map.put("completed", list.stream().filter(e -> e.getStatus() == 5).count());
        map.put("completed", list.stream().filter(e -> e.getStatus() == 5).count() + list.stream().filter(e -> e.getStatus() == 6).count());
        return map;
    }
    @Override
    public CompanyDetailVo companyDetail(String companyId, Long userId) {
        CompanyDetailVo companyDetailVo = new CompanyDetailVo();
        TbCompany tbCompany = this.baseMapper.selectById(companyId);
        BeanUtils.copyProperties(tbCompany, companyDetailVo);
        companyDetailVo.setState(tbCompany.getStatus());
        TbIndustry industry = industryService.getById(tbCompany.getCompanyIndustryId());
        companyDetailVo.setCompanyIndustryName(industry.getName());
@@ -249,47 +295,53 @@
        }
        TbOrder order = orderService.getOne(new LambdaQueryWrapper<TbOrder>().eq(TbOrder::getCompanyId, companyId).gt(TbOrder::getStatus, 0).orderByDesc(TbOrder::getCreateTime).last("limit 1"));
        if(order!=null){
        if (order != null) {
            companyDetailVo.setStatus(order.getStatus());
            companyDetailVo.setSellerFinishTime(order.getSellerFinishTime());
            companyDetailVo.setOrderId(order.getId());
        }
            companyDetailVo.setOrderMoney(order.getPrice());
        List<TbSchedule> list2 = scheduleService.list(new LambdaQueryWrapper<TbSchedule>().eq(TbSchedule::getOrderId, order.getId()).orderByDesc(TbSchedule::getCreateTime));
        List<TbSchedule> collect = list2.stream().filter(e -> StringUtils.isEmpty(e.getParentId())).collect(Collectors.toList());
        for (TbSchedule tbSchedule : collect) {
            List<TbSchedule> collect1 = list2.stream().filter(e -> StringUtils.isNotEmpty(e.getParentId()) && e.getParentId().equals(tbSchedule.getId())).collect(Collectors.toList());
            tbSchedule.setSchedules(collect1);
        }
        companyDetailVo.setSchedules(collect);
        companyDetailVo.setPayTime(order.getPayTime());
        companyDetailVo.setConfirmTime(order.getConfirmTime());
        TbBuyerCompanyInfo one = buyerCompanyInfoService.getOne(new LambdaQueryWrapper<TbBuyerCompanyInfo>().eq(TbBuyerCompanyInfo::getOrderId, order.getId()));
        CustomerInfoVo customerInfoVo = new CustomerInfoVo();
        if(one!=null){
            BeanUtils.copyProperties(one, customerInfoVo);
            String orderId = one.getOrderId();
            List<TbShareholder> list3 = shareholderService.list(new LambdaQueryWrapper<TbShareholder>().eq(TbShareholder::getOrderId, orderId));
            customerInfoVo.setShareHolders(list3);
        }
        companyDetailVo.setCustomerInfoVo(customerInfoVo);
        companyDetailVo.setEstimatedRevenue(order.getPrice().subtract(order.getCommissionPrice()).subtract(order.getCommissionPlatform()));
        TbUser user = userService.getById(order.getUserId());
        companyDetailVo.setCustomerName(user.getUserName());
        // 判断是否要迁区 是否要改名 新增天数
        if(one!=null){
            companyDetailVo.setEstimatedDays(one.getAddDay()+companyDetailVo.getEstimatedDays());
            if(one.getNeedRename()==1){
                companyDetailVo.setSaleMoney( companyDetailVo.getSaleMoney().add(companyDetailVo.getRenameMoney()));
            List<TbSchedule> list2 = scheduleService.list(new LambdaQueryWrapper<TbSchedule>().eq(TbSchedule::getOrderId, order.getId()).orderByDesc(TbSchedule::getCreateTime));
            List<TbSchedule> collect = list2.stream().filter(e -> StringUtils.isEmpty(e.getParentId())).collect(Collectors.toList());
            for (TbSchedule tbSchedule : collect) {
                List<TbSchedule> collect1 = list2.stream().filter(e -> StringUtils.isNotEmpty(e.getParentId()) && e.getParentId().equals(tbSchedule.getId())).collect(Collectors.toList());
                tbSchedule.setSchedules(collect1);
            }
            if(one.getNewDistrict()==1){
                companyDetailVo.setSaleMoney( companyDetailVo.getSaleMoney().add(companyDetailVo.getRelocationAreaMoney()));
            companyDetailVo.setSchedules(collect);
            companyDetailVo.setPayTime(order.getPayTime());
            companyDetailVo.setConfirmTime(order.getConfirmTime());
            TbBuyerCompanyInfo one = buyerCompanyInfoService.getOne(new LambdaQueryWrapper<TbBuyerCompanyInfo>().eq(TbBuyerCompanyInfo::getOrderId, order.getId()));
            CustomerInfoVo customerInfoVo = new CustomerInfoVo();
            if (one != null) {
                BeanUtils.copyProperties(one, customerInfoVo);
                String orderId = one.getOrderId();
                List<TbShareholder> list3 = shareholderService.list(new LambdaQueryWrapper<TbShareholder>().eq(TbShareholder::getOrderId, orderId));
                customerInfoVo.setShareHolders(list3);
            }
            companyDetailVo.setCustomerInfoVo(customerInfoVo);
            companyDetailVo.setEstimatedRevenue(order.getPrice().subtract(order.getCommissionPrice()).subtract(order.getCommissionPlatform()));
            TbUser user = userService.getById(order.getUserId());
            companyDetailVo.setCustomerName(user.getUserName());
            companyDetailVo.setCustomerPhone(user.getPhone());
            companyDetailVo.setSellerName(userService.getById(tbCompany.getUserId()).getUserName());
            // 判断是否要迁区 是否要改名 新增天数
            if (one != null) {
                companyDetailVo.setEstimatedDays(one.getAddDay() + companyDetailVo.getEstimatedDays());
                if (one.getNeedRename() == 1 && companyDetailVo.getRenameMoney() != null) {
                    companyDetailVo.setSaleMoney(companyDetailVo.getSaleMoney().add(companyDetailVo.getRenameMoney()));
                }
                if (one.getNewDistrict() == 1 && companyDetailVo.getRelocationAreaMoney() != null) {
                    companyDetailVo.setSaleMoney(companyDetailVo.getSaleMoney().add(companyDetailVo.getRelocationAreaMoney()));
                }
            }
        }
        return companyDetailVo;
    }