xuhy
8 天以前 6ab07ab8a747e9ea1c1c3b3d1d5953ddc7bb3dbe
分公司业绩报表,业务员业绩报表
6个文件已修改
3个文件已添加
735 ■■■■■ 已修改文件
ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/FinancialStatementsController.java 83 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-system/src/main/java/com/ruoyi/system/mapper/TErpProcurementMapper.java 29 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-system/src/main/java/com/ruoyi/system/query/PerformanceReportQuery.java 35 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-system/src/main/java/com/ruoyi/system/service/TErpProcurementService.java 29 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TCrmBranchServiceImpl.java 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TErpProcurementServiceImpl.java 266 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-system/src/main/java/com/ruoyi/system/vo/BranchPerformanceReportVO.java 56 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-system/src/main/java/com/ruoyi/system/vo/SalespersonPerformanceReportVO.java 60 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-system/src/main/resources/mapper/system/TErpProcurementMapper.xml 175 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/FinancialStatementsController.java
@@ -17,9 +17,12 @@
import com.ruoyi.system.model.TCrmSupplier;
import com.ruoyi.system.query.ClinicProcurementReportQuery;
import com.ruoyi.system.query.DetectionPaymentReportQuery;
import com.ruoyi.system.query.PerformanceReportQuery;
import com.ruoyi.system.service.*;
import com.ruoyi.system.vo.BranchPerformanceReportVO;
import com.ruoyi.system.vo.ClinicProcurementReportVO;
import com.ruoyi.system.vo.DetectionPaymentReportVO;
import com.ruoyi.system.vo.SalespersonPerformanceReportVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.poi.ss.usermodel.Workbook;
@@ -305,4 +308,84 @@
        }
    }
    /**
     * 分公司业绩报表
     */
    @ApiOperation(value = "分公司业绩报表")
    @PostMapping(value = "/branchPerformanceReport")
    public R<PageInfo<BranchPerformanceReportVO>> branchPerformanceReport(@RequestBody PerformanceReportQuery query) {
        PageInfo<BranchPerformanceReportVO> pageInfo = erpProcurementService.branchPerformanceReport(query);
        return R.ok(pageInfo);
    }
    @Log(title = "财务报表-分公司业绩报表导出", businessType = BusinessType.EXPORT)
    @ApiOperation(value = "分公司业绩报表导出")
    @PostMapping("/exportBranchPerformanceReport")
    public void exportBranchPerformanceReport(@RequestBody PerformanceReportQuery query){
        List<BranchPerformanceReportVO> list = erpProcurementService.exportBranchPerformanceReport(query);
        Workbook workbook = ExcelExportUtil.exportExcel(new ExportParams(), BranchPerformanceReportVO.class, list);
        HttpServletResponse response = WebUtils.response();
        assert response != null;
        response.setContentType("application/vnd.ms-excel");
        response.setCharacterEncoding("utf-8");
        ServletOutputStream outputStream = null;
        try {
            String fileName = URLEncoder.encode("分公司业绩报表.xls", "utf-8");
            response.setHeader("Content-Disposition", "attachment;filename=" + fileName);
            response.setContentType("application/vnd.ms-excel;charset=UTF-8");
            response.setHeader("Pragma", "no-cache");
            response.setHeader("Cache-Control", "no-cache");
            outputStream = response.getOutputStream();
            workbook.write(outputStream);
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                outputStream.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
    /**
     * 业务员业绩报表
     */
    @ApiOperation(value = "业务员业绩报表")
    @PostMapping(value = "/salespersonPerformanceReport")
    public R<PageInfo<SalespersonPerformanceReportVO>> salespersonPerformanceReport(@RequestBody PerformanceReportQuery query) {
        PageInfo<SalespersonPerformanceReportVO> pageInfo = erpProcurementService.salespersonPerformanceReport(query);
        return R.ok(pageInfo);
    }
    @Log(title = "财务报表-业务员业绩报表导出", businessType = BusinessType.EXPORT)
    @ApiOperation(value = "业务员业绩报表导出")
    @PostMapping("/exportSalespersonPerformanceReport")
    public void exportSalespersonPerformanceReport(@RequestBody PerformanceReportQuery query){
        List<SalespersonPerformanceReportVO> list = erpProcurementService.exportSalespersonPerformanceReport(query);
        Workbook workbook = ExcelExportUtil.exportExcel(new ExportParams(), SalespersonPerformanceReportVO.class, list);
        HttpServletResponse response = WebUtils.response();
        assert response != null;
        response.setContentType("application/vnd.ms-excel");
        response.setCharacterEncoding("utf-8");
        ServletOutputStream outputStream = null;
        try {
            String fileName = URLEncoder.encode("业务员业绩报表.xls", "utf-8");
            response.setHeader("Content-Disposition", "attachment;filename=" + fileName);
            response.setContentType("application/vnd.ms-excel;charset=UTF-8");
            response.setHeader("Pragma", "no-cache");
            response.setHeader("Cache-Control", "no-cache");
            outputStream = response.getOutputStream();
            workbook.write(outputStream);
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                outputStream.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
ruoyi-system/src/main/java/com/ruoyi/system/mapper/TErpProcurementMapper.java
@@ -10,6 +10,7 @@
import com.ruoyi.system.model.TErpProcurement;
import com.ruoyi.system.model.TErpProcurementGoods;
import com.ruoyi.system.query.ClinicProcurementReportQuery;
import com.ruoyi.system.query.PerformanceReportQuery;
import com.ruoyi.system.query.TErpGoodsQuery;
import com.ruoyi.system.query.TErpProcurementQuery;
import com.ruoyi.system.vo.*;
@@ -135,4 +136,32 @@
     * @return
     */
    List<PlatformLedgerReportExport> exportPlatformLedgerReport(@Param("query")ClinicProcurementReportQuery query);
    /**
     * 分公司业绩报表
     * @param query
     * @return
     */
    List<BranchPerformanceReportVO> branchPerformanceReport(@Param("query")PerformanceReportQuery query, @Param("pageInfo")PageInfo<BranchPerformanceReportVO> pageInfo);
    /**
     * 业务员业绩报表
     * @param query
     * @return
     */
    List<SalespersonPerformanceReportVO> salespersonPerformanceReport(@Param("query")PerformanceReportQuery query, @Param("pageInfo")PageInfo<SalespersonPerformanceReportVO> pageInfo);
    /**
     * 分公司业绩报表导出
     * @param query
     * @return
     */
    List<BranchPerformanceReportVO> exportBranchPerformanceReport(@Param("query")PerformanceReportQuery query);
    /**
     * 业务员业绩报表导出
     * @param query
     * @return
     */
    List<SalespersonPerformanceReportVO> exportSalespersonPerformanceReport(@Param("query")PerformanceReportQuery query);
}
ruoyi-system/src/main/java/com/ruoyi/system/query/PerformanceReportQuery.java
New file
@@ -0,0 +1,35 @@
package com.ruoyi.system.query;
import com.ruoyi.common.core.domain.model.TimeRangeQueryBody;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.List;
@Data
@ApiModel(value = "分公司业务员业绩报表查询PerformanceReportQuery")
public class PerformanceReportQuery extends TimeRangeQueryBody {
    @ApiModelProperty(value = "采购单号")
    private String procurementCode;
    @ApiModelProperty(value = "供应商名称")
    private String supplierName;
    @ApiModelProperty(value = "诊所名称")
    private String clinicName;
    @ApiModelProperty(value = "状态 1=草稿 2=待支付 3=待发货 4=已发货 5=已入库 6=已取消")
    private Integer status;
    @ApiModelProperty(value = "分公司名称")
    private String branchName;
    @ApiModelProperty(value = "业务员名称")
    private String salespersonName;
    @ApiModelProperty(value = "诊所id 前端忽略")
    private List<String> clinicIds;
}
ruoyi-system/src/main/java/com/ruoyi/system/service/TErpProcurementService.java
@@ -12,6 +12,7 @@
import com.ruoyi.system.model.TErpProcurement;
import com.ruoyi.system.model.TErpProcurementGoods;
import com.ruoyi.system.query.ClinicProcurementReportQuery;
import com.ruoyi.system.query.PerformanceReportQuery;
import com.ruoyi.system.query.TErpGoodsQuery;
import com.ruoyi.system.query.TErpProcurementQuery;
import com.ruoyi.system.vo.*;
@@ -168,4 +169,32 @@
     * @return
     */
    List<PlatformLedgerReportExport> exportPlatformLedgerReport(ClinicProcurementReportQuery query);
    /**
     * 分公司业绩报表
     * @param query
     * @return
     */
    PageInfo<BranchPerformanceReportVO> branchPerformanceReport(PerformanceReportQuery query);
    /**
     * 业务员业绩报表
     * @param query
     * @return
     */
    PageInfo<SalespersonPerformanceReportVO> salespersonPerformanceReport(PerformanceReportQuery query);
    /**
     * 分公司业绩报表导出
     * @param query
     * @return
     */
    List<BranchPerformanceReportVO> exportBranchPerformanceReport(PerformanceReportQuery query);
    /**
     * 业务员业绩报表导出
     * @param query
     * @return
     */
    List<SalespersonPerformanceReportVO> exportSalespersonPerformanceReport(PerformanceReportQuery query);
}
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TCrmBranchServiceImpl.java
@@ -64,8 +64,6 @@
        if(!CollectionUtils.isEmpty(crmBranchAreas)){
            List<String> branchIds = crmBranchAreas.stream().map(TCrmBranchArea::getBranchId).collect(Collectors.toList());
            query.setBranchIds(branchIds);
        }else {
            return pageInfo;
        }
        List<TCrmBranchVO> list = this.baseMapper.pageList(query,pageInfo);
        if(CollectionUtils.isEmpty(list)){
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TErpProcurementServiceImpl.java
@@ -7,6 +7,7 @@
import com.ruoyi.common.core.domain.BaseModel;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.system.dto.AddProcurementDto;
import com.ruoyi.system.export.PlatformLedgerReportExport;
import com.ruoyi.system.export.ProcurementReportClinicExport;
@@ -15,6 +16,7 @@
import com.ruoyi.system.mapper.*;
import com.ruoyi.system.model.*;
import com.ruoyi.system.query.ClinicProcurementReportQuery;
import com.ruoyi.system.query.PerformanceReportQuery;
import com.ruoyi.system.query.TErpGoodsQuery;
import com.ruoyi.system.query.TErpProcurementQuery;
import com.ruoyi.system.service.TErpGoodsService;
@@ -111,6 +113,14 @@
    @Resource
    private TCrmWarehouseMapper crmWarehouseMapper;
    @Resource
    private TCrmBranchMapper crmBranchMapper;
    @Resource
    private TCrmSalespersonMapper crmSalespersonMapper;
    @Resource
    private TCrmChangePointsMapper crmChangePointsMapper;
    @Resource
    private TErpProcurementCommissionMapper erpProcurementCommissionMapper;
    @Override
@@ -759,4 +769,260 @@
        return list;
    }
    @Override
    public PageInfo<BranchPerformanceReportVO> branchPerformanceReport(PerformanceReportQuery query) {
        List<String> clinicIds = new ArrayList<>();
        if(StringUtils.isNotBlank(query.getBranchName())){
            // 查询分公司名称
            List<TCrmBranch> crmBranches = crmBranchMapper.selectList(Wrappers.lambdaQuery(TCrmBranch.class)
                    .like(TCrmBranch::getBranchName, query.getBranchName()));
            if(CollectionUtils.isEmpty(crmBranches)){
                return new PageInfo<>();
            }
            List<String> branchIds = crmBranches.stream().map(TCrmBranch::getId).collect(Collectors.toList());
            List<TCrmClinic> crmClinics = crmClinicMapper.selectList(Wrappers.lambdaQuery(TCrmClinic.class)
                    .in(TCrmClinic::getBranchId, branchIds));
            if(CollectionUtils.isEmpty(crmClinics)){
                return new PageInfo<>();
            }
            List<String> ids = crmClinics.stream().map(TCrmClinic::getId).collect(Collectors.toList());
            clinicIds.addAll(ids);
        }
        query.setClinicIds(clinicIds);
        PageInfo<BranchPerformanceReportVO> pageInfo = new PageInfo<>(query.getPageNum(), query.getPageSize());
        List<BranchPerformanceReportVO> list = this.baseMapper.branchPerformanceReport(query, pageInfo);
        if(CollectionUtils.isEmpty(list)){
            return pageInfo;
        }
        List<String> procurementIds = list.stream().map(BranchPerformanceReportVO::getId).collect(Collectors.toList());
        // 查询可获得积分
        List<TCrmChangePoints> crmChangePoints = crmChangePointsMapper.selectList(Wrappers.lambdaQuery(TCrmChangePoints.class)
                .in(TCrmChangePoints::getProcurementId, procurementIds)
                .eq(TCrmChangePoints::getUserType, 1)
                .eq(TCrmChangePoints::getChangeType, 1)
                .eq(TCrmChangePoints::getChangeReason, 1));
        // 查询业绩
        List<TErpProcurementCommission> erpProcurementCommissions = erpProcurementCommissionMapper.selectList(Wrappers.lambdaQuery(TErpProcurementCommission.class)
                .in(TErpProcurementCommission::getProcurementId, procurementIds)
                .eq(TErpProcurementCommission::getCommissionType, 1));
        for (BranchPerformanceReportVO branchPerformanceReportVO : list) {
            // 查询可获得积分
            List<TCrmChangePoints> changePoints = crmChangePoints.stream().filter(tCrmChangePoints -> branchPerformanceReportVO.getId().equals(tCrmChangePoints.getProcurementId())).collect(Collectors.toList());
            if(!CollectionUtils.isEmpty(changePoints)){
                branchPerformanceReportVO.setAvailablePoints(changePoints.stream().mapToInt(TCrmChangePoints::getChangeValue).sum());
            }
            // 查询业绩
            List<TErpProcurementCommission> commissions = erpProcurementCommissions.stream().filter(tErpProcurementCommission -> branchPerformanceReportVO.getId().equals(tErpProcurementCommission.getProcurementId())).collect(Collectors.toList());
            if(!CollectionUtils.isEmpty(commissions)){
                branchPerformanceReportVO.setPerformance(commissions.stream().map(TErpProcurementCommission::getMoney).reduce(BigDecimal.ZERO, BigDecimal::add));
            }
        }
        pageInfo.setRecords(list);
        return pageInfo;
    }
    @Override
    public PageInfo<SalespersonPerformanceReportVO> salespersonPerformanceReport(PerformanceReportQuery query) {
        List<String> clinicIds = new ArrayList<>();
        if(StringUtils.isNotBlank(query.getBranchName())){
            // 查询分公司名称
            List<TCrmBranch> crmBranches = crmBranchMapper.selectList(Wrappers.lambdaQuery(TCrmBranch.class)
                    .like(TCrmBranch::getBranchName, query.getBranchName()));
            if(CollectionUtils.isEmpty(crmBranches)){
                return new PageInfo<>();
            }
            List<String> branchIds = crmBranches.stream().map(TCrmBranch::getId).collect(Collectors.toList());
            List<TCrmClinic> crmClinics = crmClinicMapper.selectList(Wrappers.lambdaQuery(TCrmClinic.class)
                    .in(TCrmClinic::getBranchId, branchIds));
            if(CollectionUtils.isEmpty(crmClinics)){
                return new PageInfo<>();
            }
            List<String> ids = crmClinics.stream().map(TCrmClinic::getId).collect(Collectors.toList());
            clinicIds.addAll(ids);
        }
        if(StringUtils.isNotBlank(query.getSalespersonName())){
            // 查询业务员名称
            List<TCrmSalesperson> crmSalespeopleList = crmSalespersonMapper.selectList(Wrappers.lambdaQuery(TCrmSalesperson.class)
                    .like(TCrmSalesperson::getSalespersonName, query.getSalespersonName()));
            if(CollectionUtils.isEmpty(crmSalespeopleList)){
                return new PageInfo<>();
            }
            List<String> salespersonIds = crmSalespeopleList.stream().map(TCrmSalesperson::getId).collect(Collectors.toList());
            List<TCrmClinic> crmClinics = crmClinicMapper.selectList(Wrappers.lambdaQuery(TCrmClinic.class)
                    .in(TCrmClinic::getSalespersonId, salespersonIds));
            if(CollectionUtils.isEmpty(crmClinics)){
                return new PageInfo<>();
            }
            List<String> ids = crmClinics.stream().map(TCrmClinic::getId).collect(Collectors.toList());
            clinicIds.addAll(ids);
        }
        clinicIds = clinicIds.stream().distinct().collect(Collectors.toList());
        query.setClinicIds(clinicIds);
        PageInfo<SalespersonPerformanceReportVO> pageInfo = new PageInfo<>(query.getPageNum(), query.getPageSize());
        List<SalespersonPerformanceReportVO> list = this.baseMapper.salespersonPerformanceReport(query, pageInfo);
        if(CollectionUtils.isEmpty(list)){
            return pageInfo;
        }
        List<String> procurementIds = list.stream().map(SalespersonPerformanceReportVO::getId).collect(Collectors.toList());
        // 查询可获得积分
        List<TCrmChangePoints> crmChangePoints = crmChangePointsMapper.selectList(Wrappers.lambdaQuery(TCrmChangePoints.class)
                .in(TCrmChangePoints::getProcurementId, procurementIds)
                .eq(TCrmChangePoints::getUserType, 2)
                .eq(TCrmChangePoints::getChangeType, 1)
                .eq(TCrmChangePoints::getChangeReason, 1));
        // 查询业绩
        List<TErpProcurementCommission> erpProcurementCommissions = erpProcurementCommissionMapper.selectList(Wrappers.lambdaQuery(TErpProcurementCommission.class)
                .in(TErpProcurementCommission::getProcurementId, procurementIds)
                .eq(TErpProcurementCommission::getCommissionType, 2));
        for (SalespersonPerformanceReportVO salespersonPerformanceReportVO : list) {
            // 查询可获得积分
            List<TCrmChangePoints> changePoints = crmChangePoints.stream().filter(tCrmChangePoints -> salespersonPerformanceReportVO.getId().equals(tCrmChangePoints.getProcurementId())).collect(Collectors.toList());
            if(!CollectionUtils.isEmpty(changePoints)){
                salespersonPerformanceReportVO.setAvailablePoints(changePoints.stream().mapToInt(TCrmChangePoints::getChangeValue).sum());
            }
            // 查询业绩
            List<TErpProcurementCommission> commissions = erpProcurementCommissions.stream().filter(tErpProcurementCommission -> salespersonPerformanceReportVO.getId().equals(tErpProcurementCommission.getProcurementId())).collect(Collectors.toList());
            if(!CollectionUtils.isEmpty(commissions)){
                salespersonPerformanceReportVO.setPerformance(commissions.stream().map(TErpProcurementCommission::getMoney).reduce(BigDecimal.ZERO, BigDecimal::add));
            }
        }
        pageInfo.setRecords(list);
        return pageInfo;
    }
    @Override
    public List<BranchPerformanceReportVO> exportBranchPerformanceReport(PerformanceReportQuery query) {
        List<String> clinicIds = new ArrayList<>();
        if(StringUtils.isNotBlank(query.getBranchName())){
            // 查询分公司名称
            List<TCrmBranch> crmBranches = crmBranchMapper.selectList(Wrappers.lambdaQuery(TCrmBranch.class)
                    .like(TCrmBranch::getBranchName, query.getBranchName()));
            if(CollectionUtils.isEmpty(crmBranches)){
                return new ArrayList<>();
            }
            List<String> branchIds = crmBranches.stream().map(TCrmBranch::getId).collect(Collectors.toList());
            List<TCrmClinic> crmClinics = crmClinicMapper.selectList(Wrappers.lambdaQuery(TCrmClinic.class)
                    .in(TCrmClinic::getBranchId, branchIds));
            if(CollectionUtils.isEmpty(crmClinics)){
                return new ArrayList<>();
            }
            List<String> ids = crmClinics.stream().map(TCrmClinic::getId).collect(Collectors.toList());
            clinicIds.addAll(ids);
        }
        query.setClinicIds(clinicIds);
        List<BranchPerformanceReportVO> list = this.baseMapper.exportBranchPerformanceReport(query);
        if(CollectionUtils.isEmpty(list)){
            return new ArrayList<>();
        }
        List<String> procurementIds = list.stream().map(BranchPerformanceReportVO::getId).collect(Collectors.toList());
        // 查询可获得积分
        List<TCrmChangePoints> crmChangePoints = crmChangePointsMapper.selectList(Wrappers.lambdaQuery(TCrmChangePoints.class)
                .in(TCrmChangePoints::getProcurementId, procurementIds)
                .eq(TCrmChangePoints::getUserType, 1)
                .eq(TCrmChangePoints::getChangeType, 1)
                .eq(TCrmChangePoints::getChangeReason, 1));
        // 查询业绩
        List<TErpProcurementCommission> erpProcurementCommissions = erpProcurementCommissionMapper.selectList(Wrappers.lambdaQuery(TErpProcurementCommission.class)
                .in(TErpProcurementCommission::getProcurementId, procurementIds)
                .eq(TErpProcurementCommission::getCommissionType, 1));
        for (BranchPerformanceReportVO branchPerformanceReportVO : list) {
            // 查询可获得积分
            List<TCrmChangePoints> changePoints = crmChangePoints.stream().filter(tCrmChangePoints -> branchPerformanceReportVO.getId().equals(tCrmChangePoints.getProcurementId())).collect(Collectors.toList());
            if(!CollectionUtils.isEmpty(changePoints)){
                branchPerformanceReportVO.setAvailablePoints(changePoints.stream().mapToInt(TCrmChangePoints::getChangeValue).sum());
            }
            // 查询业绩
            List<TErpProcurementCommission> commissions = erpProcurementCommissions.stream().filter(tErpProcurementCommission -> branchPerformanceReportVO.getId().equals(tErpProcurementCommission.getProcurementId())).collect(Collectors.toList());
            if(!CollectionUtils.isEmpty(commissions)){
                branchPerformanceReportVO.setPerformance(commissions.stream().map(TErpProcurementCommission::getMoney).reduce(BigDecimal.ZERO, BigDecimal::add));
            }
            if(Objects.nonNull(branchPerformanceReportVO.getPayTime())){
                String payTimeStr = new SimpleDateFormat("yyyy-MM-dd").format(branchPerformanceReportVO.getPayTime());
                branchPerformanceReportVO.setPayTimeStr(payTimeStr);
            }
        }
        return list;
    }
    @Override
    public List<SalespersonPerformanceReportVO> exportSalespersonPerformanceReport(PerformanceReportQuery query) {
        List<String> clinicIds = new ArrayList<>();
        if(StringUtils.isNotBlank(query.getBranchName())){
            // 查询分公司名称
            List<TCrmBranch> crmBranches = crmBranchMapper.selectList(Wrappers.lambdaQuery(TCrmBranch.class)
                    .like(TCrmBranch::getBranchName, query.getBranchName()));
            if(CollectionUtils.isEmpty(crmBranches)){
                return new ArrayList<>();
            }
            List<String> branchIds = crmBranches.stream().map(TCrmBranch::getId).collect(Collectors.toList());
            List<TCrmClinic> crmClinics = crmClinicMapper.selectList(Wrappers.lambdaQuery(TCrmClinic.class)
                    .in(TCrmClinic::getBranchId, branchIds));
            if(CollectionUtils.isEmpty(crmClinics)){
                return new ArrayList<>();
            }
            List<String> ids = crmClinics.stream().map(TCrmClinic::getId).collect(Collectors.toList());
            clinicIds.addAll(ids);
        }
        if(StringUtils.isNotBlank(query.getSalespersonName())){
            // 查询业务员名称
            List<TCrmSalesperson> crmSalespeopleList = crmSalespersonMapper.selectList(Wrappers.lambdaQuery(TCrmSalesperson.class)
                    .like(TCrmSalesperson::getSalespersonName, query.getSalespersonName()));
            if(CollectionUtils.isEmpty(crmSalespeopleList)){
                return new ArrayList<>();
            }
            List<String> salespersonIds = crmSalespeopleList.stream().map(TCrmSalesperson::getId).collect(Collectors.toList());
            List<TCrmClinic> crmClinics = crmClinicMapper.selectList(Wrappers.lambdaQuery(TCrmClinic.class)
                    .in(TCrmClinic::getSalespersonId, salespersonIds));
            if(CollectionUtils.isEmpty(crmClinics)){
                return new ArrayList<>();
            }
            List<String> ids = crmClinics.stream().map(TCrmClinic::getId).collect(Collectors.toList());
            clinicIds.addAll(ids);
        }
        clinicIds = clinicIds.stream().distinct().collect(Collectors.toList());
        query.setClinicIds(clinicIds);
        List<SalespersonPerformanceReportVO> list = this.baseMapper.exportSalespersonPerformanceReport(query);
        if(CollectionUtils.isEmpty(list)){
            return new ArrayList<>();
        }
        List<String> procurementIds = list.stream().map(SalespersonPerformanceReportVO::getId).collect(Collectors.toList());
        // 查询可获得积分
        List<TCrmChangePoints> crmChangePoints = crmChangePointsMapper.selectList(Wrappers.lambdaQuery(TCrmChangePoints.class)
                .in(TCrmChangePoints::getProcurementId, procurementIds)
                .eq(TCrmChangePoints::getUserType, 2)
                .eq(TCrmChangePoints::getChangeType, 1)
                .eq(TCrmChangePoints::getChangeReason, 1));
        // 查询业绩
        List<TErpProcurementCommission> erpProcurementCommissions = erpProcurementCommissionMapper.selectList(Wrappers.lambdaQuery(TErpProcurementCommission.class)
                .in(TErpProcurementCommission::getProcurementId, procurementIds)
                .eq(TErpProcurementCommission::getCommissionType, 2));
        for (SalespersonPerformanceReportVO salespersonPerformanceReportVO : list) {
            // 查询可获得积分
            List<TCrmChangePoints> changePoints = crmChangePoints.stream().filter(tCrmChangePoints -> salespersonPerformanceReportVO.getId().equals(tCrmChangePoints.getProcurementId())).collect(Collectors.toList());
            if(!CollectionUtils.isEmpty(changePoints)){
                salespersonPerformanceReportVO.setAvailablePoints(changePoints.stream().mapToInt(TCrmChangePoints::getChangeValue).sum());
            }
            // 查询业绩
            List<TErpProcurementCommission> commissions = erpProcurementCommissions.stream().filter(tErpProcurementCommission -> salespersonPerformanceReportVO.getId().equals(tErpProcurementCommission.getProcurementId())).collect(Collectors.toList());
            if(!CollectionUtils.isEmpty(commissions)){
                salespersonPerformanceReportVO.setPerformance(commissions.stream().map(TErpProcurementCommission::getMoney).reduce(BigDecimal.ZERO, BigDecimal::add));
            }
            if(Objects.nonNull(salespersonPerformanceReportVO.getPayTime())){
                String payTimeStr = new SimpleDateFormat("yyyy-MM-dd").format(salespersonPerformanceReportVO.getPayTime());
                salespersonPerformanceReportVO.setPayTimeStr(payTimeStr);
            }
        }
        return list;
    }
}
ruoyi-system/src/main/java/com/ruoyi/system/vo/BranchPerformanceReportVO.java
New file
@@ -0,0 +1,56 @@
package com.ruoyi.system.vo;
import cn.afterturn.easypoi.excel.annotation.Excel;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
import java.math.BigDecimal;
import java.time.LocalDateTime;
@Data
@ApiModel(value = "分公司业绩报表BranchPerformanceReportVO")
public class BranchPerformanceReportVO implements Serializable {
    private String id;
    @ApiModelProperty(value = "诊所名称")
    @Excel(name = "诊所名称", width = 20)
    private String clinicName;
    @ApiModelProperty(value = "采购供应商")
    @Excel(name = "采购供应商", width = 20)
    private String supplierName;
    @ApiModelProperty(value = "采购单号")
    @Excel(name = "采购单号", width = 20)
    private String procurementCode;
    @ApiModelProperty(value = "支付时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private LocalDateTime payTime;
    @Excel(name = "采购时间", width = 20)
    private String payTimeStr;
    @ApiModelProperty(value = "采购金额")
    @Excel(name = "采购金额", width = 20)
    private BigDecimal payMoney;
    @ApiModelProperty(value = "所属分公司")
    @Excel(name = "所属分公司", width = 20)
    private String branchName;
    @ApiModelProperty(value = "分公司业绩")
    @Excel(name = "分公司业绩", width = 20)
    private BigDecimal performance;
    @ApiModelProperty(value = "分公司可获积分")
    @Excel(name = "分公司可获积分", width = 20)
    private Integer availablePoints;
    @ApiModelProperty(value = "状态 1=草稿 2=待支付 3=待发货 4=已发货 5=已入库 6=已取消")
    @Excel(name = "状态", width = 20, replace = {"草稿_1", "待支付_2", "待发货_3", "已发货_4", "已入库_5", "已取消_6"})
    private Integer status;
}
ruoyi-system/src/main/java/com/ruoyi/system/vo/SalespersonPerformanceReportVO.java
New file
@@ -0,0 +1,60 @@
package com.ruoyi.system.vo;
import cn.afterturn.easypoi.excel.annotation.Excel;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
import java.math.BigDecimal;
import java.time.LocalDateTime;
@Data
@ApiModel(value = "业务员业绩报表SalespersonPerformanceReportVO")
public class SalespersonPerformanceReportVO implements Serializable {
    private String id;
    @ApiModelProperty(value = "诊所名称")
    @Excel(name = "诊所名称", width = 20)
    private String clinicName;
    @ApiModelProperty(value = "采购供应商")
    @Excel(name = "采购供应商", width = 20)
    private String supplierName;
    @ApiModelProperty(value = "采购单号")
    @Excel(name = "采购单号", width = 20)
    private String procurementCode;
    @ApiModelProperty(value = "支付时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private LocalDateTime payTime;
    @Excel(name = "采购时间", width = 20)
    private String payTimeStr;
    @ApiModelProperty(value = "采购金额")
    @Excel(name = "采购金额", width = 20)
    private BigDecimal payMoney;
    @ApiModelProperty(value = "所属分公司")
    @Excel(name = "所属分公司", width = 20)
    private String branchName;
    @ApiModelProperty(value = "所属业务员")
    @Excel(name = "所属业务员", width = 20)
    private String salespersonName;
    @ApiModelProperty(value = "业务员业绩")
    @Excel(name = "业务员业绩", width = 20)
    private BigDecimal performance;
    @ApiModelProperty(value = "业务员可获积分")
    @Excel(name = "业务员可获积分", width = 20)
    private Integer availablePoints;
    @ApiModelProperty(value = "状态 1=草稿 2=待支付 3=待发货 4=已发货 5=已入库 6=已取消")
    @Excel(name = "状态", width = 20, replace = {"草稿_1", "待支付_2", "待发货_3", "已发货_4", "已入库_5", "已取消_6"})
    private Integer status;
}
ruoyi-system/src/main/resources/mapper/system/TErpProcurementMapper.xml
@@ -487,5 +487,180 @@
        </where>
        order by tep.pay_time desc
    </select>
    <select id="branchPerformanceReport" resultType="com.ruoyi.system.vo.BranchPerformanceReportVO">
        select tep.id, tep.procurement_code, tep.pay_money, tep.status,tep.pay_time,tep.clinic_id, tep.supplier_id,
        tep.money,tep.supplier_money,
        tcs.supplier_name as supplierName, tcc.clinic_name as clinicName,tcc.person_charge_name,tcc.phone,
        tcb.branch_name as branchName
        from t_erp_procurement tep
        left join t_crm_supplier tcs on tep.supplier_id = tcs.id
        left join t_crm_clinic tcc on tep.clinic_id = tcc.id
        left join t_crm_branch tcb on tcc.branch_id = tcb.id
        <where>
            <if test="query.procurementCode != null and query.procurementCode != ''">
                and tep.procurement_code like concat('%',#{query.procurementCode},'%')
            </if>
            <if test="query.supplierName != null and query.supplierName != ''">
                and tcs.supplier_name like concat('%',#{query.supplierName},'%')
            </if>
            <if test="query.clinicName != null and query.clinicName != ''">
                and tcc.clinic_name like concat('%',#{query.clinicName},'%')
            </if>
            <if test="query.status != null and query.status != ''">
                and tep.status = #{query.status}
            </if>
            <if test="query.startTime != null and query.startTime != '' and query.endTime != null and query.endTime != ''">
                AND tep.pay_time &gt;= #{query.startTime}
                AND tep.pay_time &lt;= #{query.endTime}
            </if>
            <if test="query.clinicIds != null and query.clinicIds.size()>0">
                and tep.clinic_id in
                <foreach item="item" collection="query.clinicIds" separator="," open="(" close=")" index="">
                    #{item}
                </foreach>
            </if>
            <if test="query.personChargeName != null and query.personChargeName != ''">
                and tep.person_charge_name like concat('%',#{query.personChargeName},'%')
            </if>
            <if test="query.phone != null and query.phone != ''">
                and tep.phone like concat('%',#{query.phone},'%')
            </if>
            AND tep.status in (3,4,5)
            AND tep.disabled = ${@com.ruoyi.common.enums.DisabledEnum@NO.getCode()}
        </where>
        order by tep.pay_time desc
    </select>
    <select id="salespersonPerformanceReport" resultType="com.ruoyi.system.vo.SalespersonPerformanceReportVO">
        select tep.id, tep.procurement_code, tep.pay_money, tep.status,tep.pay_time,tep.clinic_id, tep.supplier_id,
        tep.money,tep.supplier_money,
        tcs.supplier_name as supplierName, tcc.clinic_name as clinicName,tcc.person_charge_name,tcc.phone,
        tcb.branch_name as branchName,tcsa.salesperson_name as salespersonName
        from t_erp_procurement tep
        left join t_crm_supplier tcs on tep.supplier_id = tcs.id
        left join t_crm_clinic tcc on tep.clinic_id = tcc.id
        left join t_crm_branch tcb on tcc.branch_id = tcb.id
        left join t_crm_salesperson tcsa on tcc.salesperson_id = tcsa.id
        <where>
            <if test="query.procurementCode != null and query.procurementCode != ''">
                and tep.procurement_code like concat('%',#{query.procurementCode},'%')
            </if>
            <if test="query.supplierName != null and query.supplierName != ''">
                and tcs.supplier_name like concat('%',#{query.supplierName},'%')
            </if>
            <if test="query.clinicName != null and query.clinicName != ''">
                and tcc.clinic_name like concat('%',#{query.clinicName},'%')
            </if>
            <if test="query.status != null and query.status != ''">
                and tep.status = #{query.status}
            </if>
            <if test="query.startTime != null and query.startTime != '' and query.endTime != null and query.endTime != ''">
                AND tep.pay_time &gt;= #{query.startTime}
                AND tep.pay_time &lt;= #{query.endTime}
            </if>
            <if test="query.clinicIds != null and query.clinicIds.size()>0">
                and tep.clinic_id in
                <foreach item="item" collection="query.clinicIds" separator="," open="(" close=")" index="">
                    #{item}
                </foreach>
            </if>
            <if test="query.personChargeName != null and query.personChargeName != ''">
                and tep.person_charge_name like concat('%',#{query.personChargeName},'%')
            </if>
            <if test="query.phone != null and query.phone != ''">
                and tep.phone like concat('%',#{query.phone},'%')
            </if>
            AND tep.status in (3,4,5)
            AND tep.disabled = ${@com.ruoyi.common.enums.DisabledEnum@NO.getCode()}
        </where>
        order by tep.pay_time desc
    </select>
    <select id="exportBranchPerformanceReport" resultType="com.ruoyi.system.vo.BranchPerformanceReportVO">
        select tep.id, tep.procurement_code, tep.pay_money, tep.status,tep.pay_time,tep.clinic_id, tep.supplier_id,
        tep.money,tep.supplier_money,
        tcs.supplier_name as supplierName, tcc.clinic_name as clinicName,tcc.person_charge_name,tcc.phone,
        tcb.branch_name as branchName
        from t_erp_procurement tep
        left join t_crm_supplier tcs on tep.supplier_id = tcs.id
        left join t_crm_clinic tcc on tep.clinic_id = tcc.id
        left join t_crm_branch tcb on tcc.branch_id = tcb.id
        <where>
            <if test="query.procurementCode != null and query.procurementCode != ''">
                and tep.procurement_code like concat('%',#{query.procurementCode},'%')
            </if>
            <if test="query.supplierName != null and query.supplierName != ''">
                and tcs.supplier_name like concat('%',#{query.supplierName},'%')
            </if>
            <if test="query.clinicName != null and query.clinicName != ''">
                and tcc.clinic_name like concat('%',#{query.clinicName},'%')
            </if>
            <if test="query.status != null and query.status != ''">
                and tep.status = #{query.status}
            </if>
            <if test="query.startTime != null and query.startTime != '' and query.endTime != null and query.endTime != ''">
                AND tep.pay_time &gt;= #{query.startTime}
                AND tep.pay_time &lt;= #{query.endTime}
            </if>
            <if test="query.clinicIds != null and query.clinicIds.size()>0">
                and tep.clinic_id in
                <foreach item="item" collection="query.clinicIds" separator="," open="(" close=")" index="">
                    #{item}
                </foreach>
            </if>
            <if test="query.personChargeName != null and query.personChargeName != ''">
                and tep.person_charge_name like concat('%',#{query.personChargeName},'%')
            </if>
            <if test="query.phone != null and query.phone != ''">
                and tep.phone like concat('%',#{query.phone},'%')
            </if>
            AND tep.status in (3,4,5)
            AND tep.disabled = ${@com.ruoyi.common.enums.DisabledEnum@NO.getCode()}
        </where>
        order by tep.pay_time desc
    </select>
    <select id="exportSalespersonPerformanceReport"
            resultType="com.ruoyi.system.vo.SalespersonPerformanceReportVO">
        select tep.id, tep.procurement_code, tep.pay_money, tep.status,tep.pay_time,tep.clinic_id, tep.supplier_id,
        tep.money,tep.supplier_money,
        tcs.supplier_name as supplierName, tcc.clinic_name as clinicName,tcc.person_charge_name,tcc.phone,
        tcb.branch_name as branchName,tcsa.salesperson_name as salespersonName
        from t_erp_procurement tep
        left join t_crm_supplier tcs on tep.supplier_id = tcs.id
        left join t_crm_clinic tcc on tep.clinic_id = tcc.id
        left join t_crm_branch tcb on tcc.branch_id = tcb.id
        left join t_crm_salesperson tcsa on tcc.salesperson_id = tcsa.id
        <where>
            <if test="query.procurementCode != null and query.procurementCode != ''">
                and tep.procurement_code like concat('%',#{query.procurementCode},'%')
            </if>
            <if test="query.supplierName != null and query.supplierName != ''">
                and tcs.supplier_name like concat('%',#{query.supplierName},'%')
            </if>
            <if test="query.clinicName != null and query.clinicName != ''">
                and tcc.clinic_name like concat('%',#{query.clinicName},'%')
            </if>
            <if test="query.status != null and query.status != ''">
                and tep.status = #{query.status}
            </if>
            <if test="query.startTime != null and query.startTime != '' and query.endTime != null and query.endTime != ''">
                AND tep.pay_time &gt;= #{query.startTime}
                AND tep.pay_time &lt;= #{query.endTime}
            </if>
            <if test="query.clinicIds != null and query.clinicIds.size()>0">
                and tep.clinic_id in
                <foreach item="item" collection="query.clinicIds" separator="," open="(" close=")" index="">
                    #{item}
                </foreach>
            </if>
            <if test="query.personChargeName != null and query.personChargeName != ''">
                and tep.person_charge_name like concat('%',#{query.personChargeName},'%')
            </if>
            <if test="query.phone != null and query.phone != ''">
                and tep.phone like concat('%',#{query.phone},'%')
            </if>
            AND tep.status in (3,4,5)
            AND tep.disabled = ${@com.ruoyi.common.enums.DisabledEnum@NO.getCode()}
        </where>
        order by tep.pay_time desc
    </select>
</mapper>