liujie
2 天以前 14c10d5021513463109aa800aeb3e8dbf479b05c
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TbCompanyServiceImpl.java
@@ -1,9 +1,11 @@
package com.ruoyi.system.service.impl;
import com.alibaba.fastjson2.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.core.redis.RedisCache;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.system.dto.EditCompanyDto;
import com.ruoyi.system.dto.PushCompanyDto;
@@ -12,10 +14,8 @@
import com.ruoyi.system.query.CompanyListQuery;
import com.ruoyi.system.query.MyPushCompanyListQuery;
import com.ruoyi.system.service.*;
import com.ruoyi.system.vo.CompanyDetailVo;
import com.ruoyi.system.vo.CustomerInfoVo;
import com.ruoyi.system.vo.IndexCompanyListVo;
import com.ruoyi.system.vo.MyPushCompanyListVo;
import com.ruoyi.system.vo.*;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@@ -23,7 +23,9 @@
import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.function.Consumer;
import java.util.stream.Collectors;
/**
@@ -53,6 +55,9 @@
    private TbScheduleService scheduleService;
    @Autowired
    private TbShareholderService shareholderService;
    @Autowired
    private TbBuyerCompanyInfoService buyerCompanyInfoService;
    @Autowired
@@ -60,6 +65,9 @@
    @Autowired
    private TbCompanyTypeService companyTypeService;
    @Autowired
    private RedisCache redisCache;
    @Override
    public Page<IndexCompanyListVo> getCompanyList(CompanyListQuery query, Long userId) {
@@ -76,15 +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());
        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());
@@ -115,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 += " (real_registered_capital between 0 and 9.99)";
                        break;
                    case "10-50W以下":
                        sql += " (real_registered_capital between 10 and 49.99)";
                        break;
                    case "50-100W以下":
                        sql += " (real_registered_capital between 50 and 99.99)";
                        break;
                    case "100-500W以下":
                        sql += " (real_registered_capital between 100 and 499.99)";
                        break;
                    case "500-1000W以下":
                        sql += " (real_registered_capital between 500 and 999.99)";
                        break;
                    case "1000W以上":
                        sql += " (real_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;
@@ -142,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);
@@ -156,7 +200,7 @@
    @Override
    @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
    public void pushCompany(PushCompanyDto dto, Long userId) {
    public String pushCompany(PushCompanyDto dto, Long userId) {
        TbCompany tbCompany = new TbCompany();
        BeanUtils.copyProperties(dto, tbCompany);
        tbCompany.setUserId(userId.toString());
@@ -172,6 +216,7 @@
            openingBank.setCompanyId(tbCompany.getId());
            openingBankService.save(openingBank);
        }
        return tbCompany.getId();
    }
@@ -199,7 +244,27 @@
    @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
    public HashMap<String, Object> getMyPushCompanyListNum(Long userId, HashMap<String, Object> map) {
        List<MyPushCompanyListVo> list = this.baseMapper.getMyPushCompanyListNum(userId);
        map.put("pendingTransaction", list.stream().filter(e -> e.getStatus() == 1).count());
        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() + list.stream().filter(e -> e.getStatus() == 6).count());
        return map;
    }
    @Override
@@ -207,6 +272,8 @@
        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());
@@ -228,27 +295,55 @@
        }
        TbOrder order = orderService.getOne(new LambdaQueryWrapper<TbOrder>().eq(TbOrder::getCompanyId, companyId).gt(TbOrder::getStatus, 0).orderByDesc(TbOrder::getCreateTime).last("limit 1"));
        companyDetailVo.setStatus(order.getStatus());
        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);
            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());
            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()));
                }
            }
        }
        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();
        BeanUtils.copyProperties(one, customerInfoVo);
        companyDetailVo.setCustomerInfoVo(customerInfoVo);
        companyDetailVo.setEstimatedRevenue(order.getPrice().subtract(order.getCommissionPrice()).subtract(order.getCommissionPlatform()));
        TbUser user = userService.getById(order.getUserId());
        companyDetailVo.setCustomerName(user.getUserName());
        return companyDetailVo;
    }
}