diff --git a/yun-admin/src/main/java/net/lab1024/sa/admin/module/service/dao/ServiceApplicationsDao.java b/yun-admin/src/main/java/net/lab1024/sa/admin/module/service/dao/ServiceApplicationsDao.java index d41c7ff..e83fa00 100644 --- a/yun-admin/src/main/java/net/lab1024/sa/admin/module/service/dao/ServiceApplicationsDao.java +++ b/yun-admin/src/main/java/net/lab1024/sa/admin/module/service/dao/ServiceApplicationsDao.java @@ -73,6 +73,11 @@ public interface ServiceApplicationsDao extends BaseMapper getLawyerStatisticsWithParamYear(Page page, @Param("queryForm") LawyerStatisticsQueryForm queryForm); + /** + * 年度律师统计查询(带参数)无分页 + */ + List getLawyerStatisticsWithParamYearNoPage(@Param("queryForm") LawyerStatisticsQueryForm queryForm); + /** * 月度统计 * @param queryForm diff --git a/yun-admin/src/main/java/net/lab1024/sa/admin/module/service/service/ServiceApplicationsService.java b/yun-admin/src/main/java/net/lab1024/sa/admin/module/service/service/ServiceApplicationsService.java index 82555f6..ffbbb6a 100644 --- a/yun-admin/src/main/java/net/lab1024/sa/admin/module/service/service/ServiceApplicationsService.java +++ b/yun-admin/src/main/java/net/lab1024/sa/admin/module/service/service/ServiceApplicationsService.java @@ -61,11 +61,9 @@ import java.io.FileOutputStream; import java.io.IOException; import java.math.BigDecimal; import java.math.RoundingMode; -import java.util.ArrayList; +import java.util.*; import java.time.LocalDateTime; -import java.util.Arrays; -import java.util.List; -import java.util.Objects; +import java.util.function.Function; import java.util.stream.Collectors; @@ -784,71 +782,148 @@ public class ServiceApplicationsService { public List getLawyerStatisticsByDepartment(@Valid LawyerStatisticsQueryFormList queryForms) { LawyerStatisticsQueryForm queryForm = getQueryForm(queryForms); DictEntity dictItem = dictService.getOne("FILECOST"); - //根据统计出律所的年度服务时长 - List lawyerStatisticsWithParamYear = serviceApplicationsDao.getdepartmentStatistics(queryForm); - if (!lawyerStatisticsWithParamYear.isEmpty() && lawyerStatisticsWithParamYear.get(0).getFirmId() != null) { - //律所季度服务时长和服务成本 - monthStatisticsDepartment(queryForm, lawyerStatisticsWithParamYear,null); - //查询这个部门下面律师的统计信息 - lawyerStatisticsWithParamYear.forEach(lawyerStatisticsVO -> { + + // 第一步:先查询年度统计数据(有条件) + LawyerStatisticsQueryForm annualQueryForm = new LawyerStatisticsQueryForm(); + annualQueryForm.setYear(queryForm.getYear()); + // 如果指定了机构ID,则应用过滤条件 + if (queryForm.getFirmId() != null) { + annualQueryForm.setFirmId(queryForm.getFirmId()); + } + // 设置年度时间范围 + String yearStart = queryForm.getYear() + "-01-01"; + String yearEnd = queryForm.getYear() + "-12-31"; + annualQueryForm.setStartTime(yearStart); + annualQueryForm.setEndTime(yearEnd); + + // 初始化季度时间变量 + LocalDateTime quarterStart = null; + LocalDateTime quarterEnd = null; + + List annualStatistics = serviceApplicationsDao.getdepartmentStatistics(annualQueryForm); + + if (!annualStatistics.isEmpty()) { + // 第二步:如果有季度条件,查询季度统计数据 + List quarterlyStatistics = new ArrayList<>(); + if (queryForm.getQuarter() != null) { + // 设置季度时间范围 + quarterStart = DateTimeEnum.getQuarterStart(queryForm.getYear(), queryForm.getQuarter()); + quarterEnd = DateTimeEnum.getQuarterEnd(queryForm.getYear(), queryForm.getQuarter()); + annualQueryForm.setStartTime(quarterStart.toString()); + annualQueryForm.setEndTime(quarterEnd.toString()); + quarterlyStatistics = serviceApplicationsDao.getdepartmentStatistics(annualQueryForm); + } + + // 第三步:合并年度和季度数据 + Map quarterlyMap = quarterlyStatistics.stream() + .collect(Collectors.toMap(LawyerStatisticsVO::getFirmId, Function.identity())); + + for (LawyerStatisticsVO annualStat : annualStatistics) { + // 计算年度成本 + BigDecimal annualCost = BigDecimal.valueOf(annualStat.getAnnualServiceDuration() * Long.valueOf(dictItem.getRemark())); + annualStat.setAnnualServiceCost(annualCost); + + // 查询amount类型的金额并添加到年度成本 + LawyerStatisticsQueryForm amountQueryForm = new LawyerStatisticsQueryForm(); + amountQueryForm.setFirmId(annualStat.getFirmId()); + amountQueryForm.setStartTime(yearStart); + amountQueryForm.setEndTime(yearEnd); + BigDecimal annualAmount = serviceApplicationsDao.getServiceAmount(amountQueryForm); + + // 安全地添加年度特殊金额 + BigDecimal currentAnnualCost = annualStat.getAnnualServiceCost(); + if (currentAnnualCost != null) { + annualStat.setAnnualServiceCost(currentAnnualCost.add(annualAmount != null ? annualAmount : BigDecimal.ZERO)); + } else { + annualStat.setAnnualServiceCost(annualAmount != null ? annualAmount : BigDecimal.ZERO); + } + + // 设置季度数据 + LawyerStatisticsVO quarterlyStat = quarterlyMap.get(annualStat.getFirmId()); + if (quarterlyStat != null && queryForm.getQuarter() != null) { + annualStat.setQuarterlyServiceDuration(quarterlyStat.getAnnualServiceDuration()); + BigDecimal quarterlyCost = BigDecimal.valueOf(quarterlyStat.getAnnualServiceDuration() * Long.valueOf(dictItem.getRemark())); + annualStat.setQuarterlyServiceCost(quarterlyCost); + // 修复:创建独立的季度金额查询表单,避免时间范围污染 + LawyerStatisticsQueryForm quarterlyAmountQueryForm = new LawyerStatisticsQueryForm(); + quarterlyAmountQueryForm.setFirmId(annualStat.getFirmId()); + quarterlyAmountQueryForm.setStartTime(quarterStart.toString()); + quarterlyAmountQueryForm.setEndTime(quarterEnd.toString()); + BigDecimal quarterlyAmount = serviceApplicationsDao.getServiceAmount(quarterlyAmountQueryForm); + annualStat.setQuarterlyServiceCost(annualStat.getQuarterlyServiceCost().add(quarterlyAmount != null ? quarterlyAmount : BigDecimal.ZERO)); + } else { + // 没有季度数据时设置默认值 + annualStat.setQuarterlyServiceDuration(0.00); + annualStat.setQuarterlyServiceCost(BigDecimal.ZERO); + } + + // 查询律所下律师的详细统计信息 ServiceLawyerQueryForm serviceLawyerQueryForm = new ServiceLawyerQueryForm(); - serviceLawyerQueryForm.setFirmId(lawyerStatisticsVO.getFirmId()); - //每个人的年度 - List lawyerServiceVOList = serviceApplicationsDao.getLawyerStatisticsWithParam(serviceLawyerQueryForm); - //每个人的季度 - if (!lawyerServiceVOList.isEmpty() && queryForm.getQuarter() != null) { - lawyerServiceVOList.forEach(lawyerServiceVO -> { - BigDecimal annualDuration = BigDecimal.valueOf(lawyerServiceVO.getAnnualServiceDuration()); - BigDecimal costRate = BigDecimal.valueOf(Long.valueOf(dictItem.getRemark())); - lawyerServiceVO.setAnnualServiceCost(annualDuration.multiply(costRate)); - - //查詢每個律師季度服務信息 - serviceLawyerQueryForm.setUserId(lawyerServiceVO.getUserId()); - List lawyerImportForms = serviceApplicationsDao.getLawyerStatisticsByMonth(serviceLawyerQueryForm); - - if (lawyerImportForms != null && !lawyerImportForms.isEmpty() && lawyerImportForms.get(0) != null) { - BigDecimal quarterlyDuration = BigDecimal.valueOf(lawyerImportForms.get(0).getQuarterlyServiceDuration()); - lawyerServiceVO.setQuarterlyServiceCost(quarterlyDuration.multiply(costRate)); - lawyerServiceVO.setQuarterlyServiceDuration(lawyerImportForms.get(0).getQuarterlyServiceDuration()); - } - - //查询amount类型的金额,然后添加到服务成本中 - queryForm.setUserId(lawyerServiceVO.getUserId()); - BigDecimal amount = serviceApplicationsDao.getServiceAmount(queryForm); - - // 安全地添加季度服务成本 - BigDecimal currentQuarterlyCost = lawyerServiceVO.getQuarterlyServiceCost(); - if (currentQuarterlyCost != null) { - lawyerServiceVO.setQuarterlyServiceCost(currentQuarterlyCost.add(amount)); - } else { - lawyerServiceVO.setQuarterlyServiceCost(amount); - } - }); - }else { - lawyerServiceVOList.forEach(lawyerServiceVO -> { - BigDecimal annualDuration = BigDecimal.valueOf(lawyerServiceVO.getAnnualServiceDuration()); - BigDecimal costRate = BigDecimal.valueOf(Long.valueOf(dictItem.getRemark())); - lawyerServiceVO.setAnnualServiceCost(annualDuration.multiply(costRate)); - - //查询amount类型的金额,然后添加到服务成本中 - queryForm.setUserId(lawyerServiceVO.getUserId()); - BigDecimal amount = serviceApplicationsDao.getServiceAmount(queryForm); - - // 安全地添加年度服务成本 - BigDecimal currentAnnualCost = lawyerServiceVO.getAnnualServiceCost(); - if (currentAnnualCost != null) { - lawyerServiceVO.setAnnualServiceCost(currentAnnualCost.add(amount)); - } else { - lawyerServiceVO.setAnnualServiceCost(amount); - } - }); + serviceLawyerQueryForm.setFirmId(annualStat.getFirmId()); + serviceLawyerQueryForm.setYear(queryForm.getYear()); + + // 设置律师年度统计时间范围 + serviceLawyerQueryForm.setStartTime(yearStart); + serviceLawyerQueryForm.setEndTime(yearEnd); + List lawyerAnnualStats = serviceApplicationsDao.getLawyerStatisticsWithParam(serviceLawyerQueryForm); + + // 处理律师季度统计 + List lawyerQuarterlyStats = new ArrayList<>(); + if (queryForm.getQuarter() != null) { + // 为律师季度统计创建独立的查询表单,使用季度时间范围 + ServiceLawyerQueryForm lawyerQuarterlyQueryForm = new ServiceLawyerQueryForm(); + lawyerQuarterlyQueryForm.setFirmId(annualStat.getFirmId()); + lawyerQuarterlyQueryForm.setYear(queryForm.getYear()); + lawyerQuarterlyQueryForm.setStartTime(quarterStart.toString()); + lawyerQuarterlyQueryForm.setEndTime(quarterEnd.toString()); + lawyerQuarterlyStats = serviceApplicationsDao.getLawyerStatisticsWithParam(lawyerQuarterlyQueryForm); } - lawyerStatisticsVO.setLawyerServiceVOList(lawyerServiceVOList); - }); + + // 合并律师年度和季度数据 + Map lawyerQuarterlyMap = lawyerQuarterlyStats.stream() + .collect(Collectors.toMap(ServiceLawyerImportForm::getUserId, Function.identity())); + + for (ServiceLawyerImportForm lawyerAnnual : lawyerAnnualStats) { + // 计算律师年度成本 + BigDecimal lawyerAnnualCost = BigDecimal.valueOf(lawyerAnnual.getAnnualServiceDuration() * Long.valueOf(dictItem.getRemark())); + lawyerAnnual.setAnnualServiceCost(lawyerAnnualCost); + + // 查询律师年度amount类型金额 + LawyerStatisticsQueryForm lawyerAmountQueryForm = new LawyerStatisticsQueryForm(); + lawyerAmountQueryForm.setUserId(lawyerAnnual.getUserId()); + lawyerAmountQueryForm.setStartTime(yearStart); + lawyerAmountQueryForm.setEndTime(yearEnd); + BigDecimal lawyerAnnualAmount = serviceApplicationsDao.getServiceAmount(lawyerAmountQueryForm); + + // 安全地添加律师年度特殊金额 + BigDecimal currentLawyerAnnualCost = lawyerAnnual.getAnnualServiceCost(); + if (currentLawyerAnnualCost != null) { + lawyerAnnual.setAnnualServiceCost(currentLawyerAnnualCost.add(lawyerAnnualAmount != null ? lawyerAnnualAmount : BigDecimal.ZERO)); + } else { + lawyerAnnual.setAnnualServiceCost(lawyerAnnualAmount != null ? lawyerAnnualAmount : BigDecimal.ZERO); + } + + // 设置律师季度数据 + ServiceLawyerImportForm lawyerQuarterly = lawyerQuarterlyMap.get(lawyerAnnual.getUserId()); + if (lawyerQuarterly != null && queryForm.getQuarter() != null) { + lawyerAnnual.setQuarterlyServiceDuration(lawyerQuarterly.getAnnualServiceDuration()); + BigDecimal lawyerQuarterlyCost = BigDecimal.valueOf(lawyerQuarterly.getAnnualServiceDuration() * Long.valueOf(dictItem.getRemark())); + lawyerAnnual.setQuarterlyServiceCost(lawyerQuarterlyCost); + BigDecimal lawyerQuarterlyAmount = serviceApplicationsDao.getServiceAmount(annualQueryForm); + lawyerAnnual.setQuarterlyServiceCost(lawyerAnnual.getQuarterlyServiceCost().add(lawyerQuarterlyAmount != null ? lawyerQuarterlyAmount : BigDecimal.ZERO)); + } else { + lawyerAnnual.setQuarterlyServiceDuration(0.0); + lawyerAnnual.setQuarterlyServiceCost(BigDecimal.ZERO); + } + } + + annualStat.setLawyerServiceVOList(lawyerAnnualStats); + } } + //屏蔽成本数据 - maskCostDataForUser(lawyerStatisticsWithParamYear); - return lawyerStatisticsWithParamYear; + maskCostDataForUser(annualStatistics); + return annualStatistics; } /** @@ -1297,11 +1372,9 @@ public class ServiceApplicationsService { String yearEnd = yearStartAndEnd.getEndTime(); queryForm.setStartTime(yearStart); queryForm.setEndTime(yearEnd); - if (UserTypeEnum.USER.getDesc().equals(roleList.getRoleCode())){ - queryForm.setUserId(requestUser.getEmployeeId()); - }else if (UserTypeEnum.CTO.getDesc().equals(roleList.getRoleCode())){ - queryForm.setUserId(null); + if (UserTypeEnum.CTO.getDesc().equals(roleList.getRoleCode())){ queryForm.setFirmId(requestUser.getDepartmentId()); + } //统计当前年度的 List lawyerStatisticsWithParamYear = serviceApplicationsDao.getLawyerStatisticsWithParamYear(page, queryForm); @@ -1313,8 +1386,39 @@ public class ServiceApplicationsService { queryForm.setUserId(statisticsVO.getUserId()); BigDecimal amount = serviceApplicationsDao.getServiceAmount(queryForm); statisticsVO.setAnnualServiceCost(statisticsVO.getAnnualServiceCost().add(amount)); + + // 直接为每个律师查询季度数据 + LawyerStatisticsQueryForm quarterQueryForm = new LawyerStatisticsQueryForm(); + quarterQueryForm.setYear(queryForm.getYear()); + quarterQueryForm.setQuarter(queryForm.getQuarter()); + quarterQueryForm.setUserId(statisticsVO.getUserId()); + + // 设置季度时间范围 + if (quarterQueryForm.getQuarter() == null) { + TimeVo startQuarter = DateTimeUtil.getStartQuarter(); + quarterQueryForm.setStartTime(startQuarter.getStartTime()); + quarterQueryForm.setEndTime(startQuarter.getEndTime()); + } else { + LocalDateTime quarterStart = DateTimeEnum.getQuarterStart(quarterQueryForm.getYear(), quarterQueryForm.getQuarter()); + LocalDateTime quarterEnd = DateTimeEnum.getQuarterEnd(quarterQueryForm.getYear(), quarterQueryForm.getQuarter()); + quarterQueryForm.setStartTime(quarterStart.toString()); + quarterQueryForm.setEndTime(quarterEnd.toString()); + } + + // 查询该律师的季度数据 + LawyerStatisticsVO quarterData = serviceApplicationsDao.getLawyerStatistic(quarterQueryForm); + if (quarterData != null && quarterData.getQuarterlyServiceDuration() != null) { + statisticsVO.setQuarterlyServiceDuration(quarterData.getQuarterlyServiceDuration()); + statisticsVO.setQuarterlyServiceCost(BigDecimal.valueOf(quarterData.getQuarterlyServiceDuration() * Long.valueOf(one.getRemark()))); + // 统计金额 + BigDecimal quarterAmount = serviceApplicationsDao.getServiceAmount(quarterQueryForm); + statisticsVO.setQuarterlyServiceCost(statisticsVO.getQuarterlyServiceCost().add(quarterAmount)); + } else { + // 如果没有季度数据,设置季度成本为0 + statisticsVO.setQuarterlyServiceDuration(0.0); + statisticsVO.setQuarterlyServiceCost(BigDecimal.ZERO); + } } - monthStatistics(queryForm, lawyerStatisticsVOPageResult.getList(),null); } // 根据用户权限控制成本数据显示 maskCostDataForUser(lawyerStatisticsVOPageResult.getList()); @@ -1328,34 +1432,95 @@ public class ServiceApplicationsService { public void exportLawyer(ServiceLawyerQueryForm queryForm, HttpServletResponse response) { RequestEmployee requestUser = AdminRequestUtil.getRequestUser(); RoleVO roleList = roleEmployeeService.getRoleIdList(requestUser.getEmployeeId()).get(0); - if (UserTypeEnum.USER.getDesc().equals(roleList.getRoleCode())){ - queryForm.setUserId(requestUser.getEmployeeId()); - }else if (UserTypeEnum.CTO.getDesc().equals(roleList.getRoleCode())){ + + // 应用权限控制和查询条件 + if (UserTypeEnum.CTO.getDesc().equals(roleList.getRoleCode())){ + // 律所只能查看自己的部门的数据 queryForm.setFirmId(requestUser.getDepartmentId()); } + // 管理员可以看到所有数据,但仍应尊重用户指定的查询条件 DictEntity one = dictService.getOne("FILECOST"); - // 如果没有指定季度,则使用年度范围,否则使用季度范围 + + // 保存原始的查询条件,用于年度数据查询 + ServiceLawyerQueryForm annualQueryForm = SmartBeanUtil.copy(queryForm, ServiceLawyerQueryForm.class); + + // 如果没有指定季度,则使用年度范围,否则使用季度范围(仅用于季度数据查询) if (queryForm.getQuarter() == null) { TimeVo yearStartAndEnd = DateTimeUtil.getYearStartAndEnd(queryForm.getYear()); String yearStart = yearStartAndEnd.getStartTime(); String yearEnd = yearStartAndEnd.getEndTime(); queryForm.setStartTime(yearStart); queryForm.setEndTime(yearEnd); + + annualQueryForm.setStartTime(yearStart); + annualQueryForm.setEndTime(yearEnd); } else { - // 根据指定的季度设置时间范围 + // 根据指定的季度设置时间范围(仅用于季度数据查询) LocalDateTime quarterStart = DateTimeEnum.getQuarterStart(queryForm.getYear(), queryForm.getQuarter()); LocalDateTime quarterEnd = DateTimeEnum.getQuarterEnd(queryForm.getYear(), queryForm.getQuarter()); queryForm.setStartTime(quarterStart.toString()); queryForm.setEndTime(quarterEnd.toString()); + // 年度数据查询仍使用完整年度范围 + TimeVo yearStartAndEnd = DateTimeUtil.getYearStartAndEnd(queryForm.getYear()); + annualQueryForm.setStartTime(yearStartAndEnd.getStartTime()); + annualQueryForm.setEndTime(yearStartAndEnd.getEndTime()); + annualQueryForm.setQuarter(null); } - //律师年度 - List lawyerStatisticsWithParamYear = serviceApplicationsDao.getLawyerStatisticsWithParam(queryForm); + //律师年度数据查询使用完整的年度范围 + List lawyerStatisticsWithParamYear = serviceApplicationsDao.getLawyerStatisticsWithParam(annualQueryForm); if (!lawyerStatisticsWithParamYear.isEmpty()) { for (ServiceLawyerImportForm serviceLawyerImportForm : lawyerStatisticsWithParamYear) { serviceLawyerImportForm.setAnnualServiceCost(BigDecimal.valueOf(serviceLawyerImportForm.getAnnualServiceDuration() * Long.valueOf(one.getRemark()))); + + // 查询该律师的年度特殊金额 + LawyerStatisticsQueryForm annualAmountQueryForm = new LawyerStatisticsQueryForm(); + annualAmountQueryForm.setYear(queryForm.getYear()); + annualAmountQueryForm.setUserId(serviceLawyerImportForm.getUserId()); + // 年度金额使用完整年度范围 + TimeVo yearStartAndEnd = DateTimeUtil.getYearStartAndEnd(queryForm.getYear()); + annualAmountQueryForm.setStartTime(yearStartAndEnd.getStartTime()); + annualAmountQueryForm.setEndTime(yearStartAndEnd.getEndTime()); + + // 添加年度特殊金额 + BigDecimal annualAmount = serviceApplicationsDao.getServiceAmount(annualAmountQueryForm); + if (annualAmount != null) { + serviceLawyerImportForm.setAnnualServiceCost(serviceLawyerImportForm.getAnnualServiceCost().add(annualAmount)); + } + + // 直接为每个律师查询季度数据 + LawyerStatisticsQueryForm quarterQueryForm = new LawyerStatisticsQueryForm(); + quarterQueryForm.setYear(queryForm.getYear()); + quarterQueryForm.setQuarter(queryForm.getQuarter()); + quarterQueryForm.setUserId(serviceLawyerImportForm.getUserId()); + + // 设置季度时间范围 + if (quarterQueryForm.getQuarter() == null) { + TimeVo startQuarter = DateTimeUtil.getStartQuarter(); + quarterQueryForm.setStartTime(startQuarter.getStartTime()); + quarterQueryForm.setEndTime(startQuarter.getEndTime()); + } else { + LocalDateTime quarterStart = DateTimeEnum.getQuarterStart(quarterQueryForm.getYear(), quarterQueryForm.getQuarter()); + LocalDateTime quarterEnd = DateTimeEnum.getQuarterEnd(quarterQueryForm.getYear(), quarterQueryForm.getQuarter()); + quarterQueryForm.setStartTime(quarterStart.toString()); + quarterQueryForm.setEndTime(quarterEnd.toString()); + } + + // 查询该律师的季度数据 + LawyerStatisticsVO quarterData = serviceApplicationsDao.getLawyerStatistic(quarterQueryForm); + if (quarterData != null && quarterData.getQuarterlyServiceDuration() != null) { + serviceLawyerImportForm.setQuarterlyServiceDuration(quarterData.getQuarterlyServiceDuration()); + serviceLawyerImportForm.setQuarterlyServiceCost(BigDecimal.valueOf(quarterData.getQuarterlyServiceDuration() * Long.valueOf(one.getRemark()))); + // 统计季度特殊金额 + BigDecimal quarterAmount = serviceApplicationsDao.getServiceAmount(quarterQueryForm); + if (quarterAmount != null) { + serviceLawyerImportForm.setQuarterlyServiceCost(serviceLawyerImportForm.getQuarterlyServiceCost().add(quarterAmount)); + } + } else { + // 如果没有季度数据,设置季度成本为0 + serviceLawyerImportForm.setQuarterlyServiceDuration(0.0); + serviceLawyerImportForm.setQuarterlyServiceCost(BigDecimal.ZERO); + } } - LawyerStatisticsQueryForm queryForm1 = SmartBeanUtil.copy(queryForm, LawyerStatisticsQueryForm.class); - monthStatistics(queryForm1, null, lawyerStatisticsWithParamYear); } maskCostDataForExport(lawyerStatisticsWithParamYear); @@ -1364,76 +1529,6 @@ public class ServiceApplicationsService { } - /** - * 统计月度的工作时长 - * @param originalQueryForm - * @param lawyerStatisticsVOPageResult - */ - public void monthStatistics(LawyerStatisticsQueryForm originalQueryForm, List lawyerStatisticsVOPageResult,List lawyerStatisticsWithParamYear) { - DictEntity one = dictService.getOne("FILECOST"); - if (lawyerStatisticsVOPageResult != null) { - for (LawyerStatisticsVO statisticsVO : lawyerStatisticsVOPageResult) { - // 创建新的查询表单对象以避免修改原始对象 - LawyerStatisticsQueryForm queryForm = SmartBeanUtil.copy(originalQueryForm, LawyerStatisticsQueryForm.class); - if (queryForm.getQuarter() == null) { - //获取当前月份上一季度的开始时间和结束时间 - TimeVo startQuarter = DateTimeUtil.getStartQuarter(); - String quarterStart = startQuarter.getStartTime(); - String quarterEnd = startQuarter.getEndTime(); - queryForm.setStartTime(quarterStart.toString()); - queryForm.setEndTime(quarterEnd.toString()); - } else{ - //根据季度获取季度的开发时间和 - LocalDateTime quarterStart = DateTimeEnum.getQuarterStart(queryForm.getYear(), queryForm.getQuarter()); - //结束时间 - LocalDateTime quarterEnd = DateTimeEnum.getQuarterEnd(queryForm.getYear(), queryForm.getQuarter()); - queryForm.setStartTime(quarterStart.toString()); - queryForm.setEndTime(quarterEnd.toString()); - } - queryForm.setUserId(statisticsVO.getUserId()); - //季度服务时间范围 - LawyerStatisticsVO quarterStatisticsVO = serviceApplicationsDao.getLawyerStatistic(queryForm); - if (quarterStatisticsVO != null && quarterStatisticsVO.getQuarterlyServiceDuration() != null) { - statisticsVO.setQuarterlyServiceDuration(quarterStatisticsVO.getQuarterlyServiceDuration()); - statisticsVO.setQuarterlyServiceCost(BigDecimal.valueOf(quarterStatisticsVO.getQuarterlyServiceDuration() * Long.valueOf(one.getRemark()))); - //统计金额 - BigDecimal amount = serviceApplicationsDao.getServiceAmount(queryForm); - statisticsVO.setQuarterlyServiceCost(statisticsVO.getQuarterlyServiceCost().add(amount)); - } - } - }else if (lawyerStatisticsWithParamYear != null) { - for (ServiceLawyerImportForm statisticsVO : lawyerStatisticsWithParamYear) { - // 创建新的查询表单对象以避免修改原始对象 - LawyerStatisticsQueryForm queryForm = SmartBeanUtil.copy(originalQueryForm, LawyerStatisticsQueryForm.class); - if (queryForm.getQuarter() == null) { - //获取当前月份上一季度的开始时间和结束时间 - TimeVo startQuarter = DateTimeUtil.getStartQuarter(); - String quarterStart = startQuarter.getStartTime(); - String quarterEnd = startQuarter.getEndTime(); - queryForm.setStartTime(quarterStart.toString()); - queryForm.setEndTime(quarterEnd.toString()); - } else{ - //根据季度获取季度的开发时间和 - LocalDateTime quarterStart = DateTimeEnum.getQuarterStart(queryForm.getYear(), queryForm.getQuarter()); - //结束时间 - LocalDateTime quarterEnd = DateTimeEnum.getQuarterEnd(queryForm.getYear(), queryForm.getQuarter()); - queryForm.setStartTime(quarterStart.toString()); - queryForm.setEndTime(quarterEnd.toString()); - } - queryForm.setUserId(statisticsVO.getUserId()); - //季度服务时间范围 - LawyerStatisticsVO quarterStatisticsVO = serviceApplicationsDao.getLawyerStatistic(queryForm); - if (quarterStatisticsVO != null && quarterStatisticsVO.getQuarterlyServiceDuration() != null) { - statisticsVO.setQuarterlyServiceDuration(quarterStatisticsVO.getQuarterlyServiceDuration()); - statisticsVO.setQuarterlyServiceCost(BigDecimal.valueOf(quarterStatisticsVO.getQuarterlyServiceDuration() * Long.valueOf(one.getRemark()))); - //统计金额 - BigDecimal amount = serviceApplicationsDao.getServiceAmount(queryForm); - statisticsVO.setQuarterlyServiceCost(statisticsVO.getQuarterlyServiceCost().add(amount)); - } - } - } - } - public void monthStatisticsDepartment(LawyerStatisticsQueryForm originalQueryForm, List lawyerStatisticsVOPageResult,List lawyerStatisticsWithParamYear) { DictEntity dictItem = dictService.getOne("FILECOST"); if (lawyerStatisticsVOPageResult != null) { @@ -1467,6 +1562,10 @@ public class ServiceApplicationsService { statisticsVO.setQuarterlyServiceDuration(quarterStatisticsVO.getQuarterlyServiceDuration()); //计算季度累计服务成本 statisticsVO.setQuarterlyServiceCost(BigDecimal.valueOf(quarterStatisticsVO.getQuarterlyServiceDuration() * Long.valueOf(dictItem.getRemark()))); + } else { + // 如果没有季度数据,设置季度成本为0而不是null + statisticsVO.setQuarterlyServiceDuration(0.0); + statisticsVO.setQuarterlyServiceCost(BigDecimal.ZERO); } if (queryForm.getQuarter() == null) { BigDecimal currentAnnualCost = statisticsVO.getAnnualServiceCost(); @@ -1486,8 +1585,11 @@ public class ServiceApplicationsService { } }else if (lawyerStatisticsWithParamYear != null) { for (ServiceDepartmentImportForm statisticsVO : lawyerStatisticsWithParamYear) { - // 创建新的查询表单对象以避免修改原始对象 - LawyerStatisticsQueryForm queryForm = SmartBeanUtil.copy(originalQueryForm, LawyerStatisticsQueryForm.class); + // 为每个律所单独构建季度查询条件 + LawyerStatisticsQueryForm queryForm = new LawyerStatisticsQueryForm(); + queryForm.setYear(originalQueryForm.getYear()); + queryForm.setQuarter(originalQueryForm.getQuarter()); + if (queryForm.getQuarter() == null) { // 如果没有指定季度,使用上一季度的时间范围 TimeVo startQuarter = DateTimeUtil.getStartQuarter(); @@ -1504,6 +1606,7 @@ public class ServiceApplicationsService { queryForm.setEndTime(quarterEnd.toString()); } queryForm.setFirmId(statisticsVO.getFirmId()); + //计算年度累计服务成本 statisticsVO.setAnnualServiceCost(BigDecimal.valueOf(statisticsVO.getAnnualServiceDuration() * Long.valueOf(dictItem.getRemark()))); BigDecimal amount = serviceApplicationsDao.getServiceAmount(queryForm); @@ -1513,6 +1616,10 @@ public class ServiceApplicationsService { statisticsVO.setQuarterlyServiceDuration(quarterStatisticsVO.getQuarterlyServiceDuration()); //计算季度累计服务成本 statisticsVO.setQuarterlyServiceCost(BigDecimal.valueOf(quarterStatisticsVO.getQuarterlyServiceDuration() * Long.valueOf(dictItem.getRemark()))); + } else { + // 如果没有季度数据,设置季度成本为0而不是null + statisticsVO.setQuarterlyServiceDuration(0.0); + statisticsVO.setQuarterlyServiceCost(BigDecimal.ZERO); } if (queryForm.getQuarter() == null) { BigDecimal currentAnnualCost = statisticsVO.getAnnualServiceCost(); diff --git a/yun-admin/src/main/resources/mapper/service/ServiceApplicationsMapper.xml b/yun-admin/src/main/resources/mapper/service/ServiceApplicationsMapper.xml index 71766a5..934ffe2 100644 --- a/yun-admin/src/main/resources/mapper/service/ServiceApplicationsMapper.xml +++ b/yun-admin/src/main/resources/mapper/service/ServiceApplicationsMapper.xml @@ -313,6 +313,41 @@ GROUP BY tsa.user_id, tsa.certificate_number + +