企业信息统计 查询企业年度、月度、季度注册数

This commit is contained in:
lc 2024-06-19 14:08:35 +08:00
parent ce40a055d3
commit 7b662fad1a
3 changed files with 105 additions and 0 deletions

View File

@ -106,4 +106,24 @@ public class EnterpriseInformationController {
Map<Integer, Long> integerLongMap = enterpriseInformationService.statisticByEnterpriseType();
return success(integerLongMap);
}
@GetMapping("/selectEnterpriseByYear")
@Operation(summary = "查询平台企业年度注册数")
public CommonResult<Map<Integer,Long>> selectEnterpriseByYear(){
Map<Integer, Long> integerLongMap = enterpriseInformationService.selectEnterpriseByYear();
return success(integerLongMap);
}
@GetMapping("/selectEnterpriseByQuarter")
@Operation(summary = "查询平台企业季度注册数")
public CommonResult<Map<String,Long>> selectEnterpriseByQuarter(){
Map<String, Long> stringLongMap = enterpriseInformationService.selectEnterpriseByQuarter();
return success(stringLongMap);
}
@GetMapping("/selectEnterpriseByMonth")
@Operation(summary = "查询平台企业月度注册数")
public CommonResult<Map<String,Long>> selectEnterpriseByMonth(){
Map<String, Long> stringLongMap = enterpriseInformationService.selectEnterpriseByMonth();
return success(stringLongMap);
}
}

View File

@ -82,4 +82,22 @@ public interface EnterpriseInformationService {
* @return
*/
Map<Integer,Long> statisticByEnterpriseType();
/**
* 查询平台企业年度注册数
* @return
*/
Map<Integer, Long> selectEnterpriseByYear();
/**
* 查询平台企业季度注册数
* @return
*/
Map<String, Long> selectEnterpriseByQuarter();
/**
* 查询平台企业月度注册数
* @return
*/
Map<String, Long> selectEnterpriseByMonth();
}

View File

@ -241,6 +241,73 @@ public class EnterpriseInformationServiceImpl implements EnterpriseInformationSe
return enterpriseTypeCounts;
}
/**
* 查询平台企业年度注册数
* @return
*/
@Override
public Map<Integer, Long> selectEnterpriseByYear() {
List<EnterpriseInformationDO> enterpriseInformationDOS = enterpriseInformationMapper.selectList();
// 按年分组并计算企业数量
Map<Integer, Long> collect = enterpriseInformationDOS.stream()
.collect(Collectors.groupingBy(enterprise -> enterprise.getCreateTime().getYear(), Collectors.counting()));
//// 按月分组并计算企业数量
// Map<YearMonth, Long> monthlyCounts = enterpriseInformationDOS.stream()
// .collect(Collectors.groupingBy(
// EnterpriseInformationDO::getCreateTime::toYearMonth, // 注意这里需要修改以适配Java的语法
// Collectors.counting()
// ));
//
//// 注意上面的toYearMonth是一个假设的方法Java中并没有这样的方法直接在Lambda表达式中使用
//// 你需要创建一个Function来实现这个转换
// Function<LocalDate, YearMonth> toYearMonth = LocalDate::toYearMonth;
// Map<YearMonth, Long> monthlyCountsCorrect = enterpriseInformationDOS.stream()
// .collect(Collectors.groupingBy(
// toYearMonth, // 使用上面定义的Function
// Collectors.counting()
// ));
return collect;
}
/**
* 查询平台企业季度注册数
* @return
*/
@Override
public Map<String, Long> selectEnterpriseByQuarter() {
List<EnterpriseInformationDO> enterpriseInformationDOS = enterpriseInformationMapper.selectList();
// 按季度分组并计算企业数量
Map<String, Long> quarterlyCounts = enterpriseInformationDOS.stream()
.collect(Collectors.groupingBy(
enterprise -> enterprise.getCreateTime().getYear() + "-" +
((enterprise.getCreateTime().getMonthValue() - 1) / 3 + 1), // 季度计算
Collectors.counting()
));
return quarterlyCounts;
}
/**
* 查询平台企业月度注册数
* @return
*/
@Override
public Map<String, Long> selectEnterpriseByMonth() {
List<EnterpriseInformationDO> enterpriseInformationDOS = enterpriseInformationMapper.selectList();
// 按月度分组并计算企业数量
Map<String, Long> monthlyCounts = enterpriseInformationDOS.stream()
.collect(Collectors.groupingBy(
enterprise -> enterprise.getCreateTime().getYear() + "-" +
((enterprise.getCreateTime().getMonthValue())),
Collectors.counting()
));
return monthlyCounts;
}
private void validateLeaveExists(Long id) {
if (enterpriseInformationMapper.selectById(id) == null) {
throw exception(ENTERPRISE_INFORMATION_NOT_EXISTS);