添加功能

This commit is contained in:
马宝龙
2026-06-30 18:57:01 +08:00
parent 28b295f4ab
commit 4baeb8262f
6 changed files with 810 additions and 123 deletions

View File

@@ -302,4 +302,45 @@ public class CommonConstant {
Tuple2::getT1,
Tuple2::getT2
)));
/**
* 企业类型列表
*/
public static final List<Tuple2<String, String>> COMPANY_TYPE_LIST =
Collections.unmodifiableList(new ArrayList<>(Arrays.asList(
Tuples.of("1", "国有企业"),
Tuples.of("2", "民营企业"),
Tuples.of("3", "外资企业"),
Tuples.of("4", "合资企业"),
Tuples.of("5", "事业单位")
)));
/**
* 企业类型Map
*/
public static final Map<String, String> COMPANY_TYPE_MAP =
Collections.unmodifiableMap(COMPANY_TYPE_LIST.stream()
.collect(Collectors.toMap(
Tuple2::getT1,
Tuple2::getT2
)));
/**
* 招聘方式列表
*/
public static final List<Tuple2<String, String>> RECRUITMENT_WAY_LIST =
Collections.unmodifiableList(new ArrayList<>(Arrays.asList(
Tuples.of("1", "线上招聘"),
Tuples.of("2", "线下招聘"),
Tuples.of("3", "校园招聘"),
Tuples.of("4", "内部推荐")
)));
/**
* 企业类型Map
*/
public static final Map<String, String> RECRUITMENT_WAY_MAP =
Collections.unmodifiableMap(RECRUITMENT_WAY_LIST.stream()
.collect(Collectors.toMap(
Tuple2::getT1,
Tuple2::getT2
)));
}

View File

@@ -24,10 +24,18 @@ public class TreadVo implements Serializable {
* 编码
*/
private String code;
/**
* 另一个编码
*/
private String anotherCode;
/**
* 描述
*/
private String desc;
/**
* 另一个描述
*/
private String anotherDesc;
/**
* 排序
*/

View File

@@ -4,6 +4,7 @@ import com.ruoyi.cms.domain.dto.QueryParamDto;
import com.ruoyi.cms.domain.vo.HeatmapVo;
import com.ruoyi.cms.domain.vo.MajorIndustryEmploymentMonitorTreadVo;
import com.ruoyi.cms.domain.vo.QueryResultVo;
import com.ruoyi.cms.domain.vo.TreadVo;
import java.math.BigDecimal;
import java.util.List;
@@ -123,4 +124,101 @@ public interface ThemeRecruitmentJobMapper {
* @return 热力图列表
*/
List<HeatmapVo> heatmap(QueryParamDto dto);
/**
* 招聘需求规模趋势 - 年度
*
* @param dto 查询参数
* @return 趋势列表
*/
List<TreadVo> recruitmentTrendYear(QueryParamDto dto);
/**
* 招聘需求规模趋势 - 季度
*
* @param dto 查询参数
* @return 趋势列表
*/
List<TreadVo> recruitmentTrendQuarter(QueryParamDto dto);
/**
* 招聘需求规模趋势 - 月度
*
* @param dto 查询参数
* @return 趋势列表
*/
List<TreadVo> recruitmentTrendMonth(QueryParamDto dto);
/**
* 重点产业招聘需求对比
*
* @param dto 查询参数
* @return 结果列表
*/
List<QueryResultVo> majorIndustryRecruitment(QueryParamDto dto);
/**
* 重点监测行业劳动力动态走势 - 年度
*
* @param dto 查询参数
* @return 趋势列表
*/
List<TreadVo> majorIndustryLaborForceTreadYear(QueryParamDto dto);
/**
* 重点监测行业劳动力动态走势 - 季度
*
* @param dto 查询参数
* @return 趋势列表
*/
List<TreadVo> majorIndustryLaborForceTreadQuarter(QueryParamDto dto);
/**
* 重点监测行业劳动力动态走势 - 月度
*
* @param dto 查询参数
* @return 趋势列表
*/
List<TreadVo> majorIndustryLaborForceTreadMonth(QueryParamDto dto);
/**
* 不同类型企业用工规模
*
* @param dto 查询参数
* @return 结果列表
*/
List<QueryResultVo> companyRecruitmentCount(QueryParamDto dto);
/**
* 不同企业类型招聘活跃度
*
* @param dto 查询参数
* @return 结果列表
*/
List<TreadVo> companyRecruitmentWay(QueryParamDto dto);
/**
* 不同类型企业的人才结构需求
*
* @param dto 查询参数
* @return 结果列表
*/
List<TreadVo> companyRecruitmentEducationLevel(QueryParamDto dto);
/**
* 招聘需求区域分布
*
* @param dto 查询参数
* @return 结果列表
*/
List<QueryResultVo> recruitmentArea(QueryParamDto dto);
/**
* 承诺薪酬分布分布
*
* @param dto 查询参数
* @return 结果列表
*/
List<QueryResultVo> commitmentSalary(QueryParamDto dto);
}

View File

@@ -12,21 +12,24 @@ import com.ruoyi.cms.mapper.ThemeRecruitmentJobMapper;
import com.ruoyi.cms.service.AnalysisLaborForceRecruitmentDemandService;
import com.ruoyi.cms.util.MathUtil;
import com.ruoyi.cms.util.ParamUtil;
import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.bean.BeanUtils;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;
import reactor.util.function.Tuple2;
import reactor.util.function.Tuples;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
/**
* 劳动力招聘需求分析
@@ -140,178 +143,207 @@ public class AnalysisLaborForceRecruitmentDemandServiceImpl implements AnalysisL
@Override
public List<TreadVo> recruitmentTrend(QueryParamDto dto) {
List<TreadVo> list = new ArrayList<>();
for (int i = 1; i <= 12; i++) {
long currentCount = (long) Math.floor(Math.random() * 15000) + 5000;
long lastYearCount = (long) Math.floor(Math.random() * 14000) + 4000;
list.add(TreadVo.builder()
.code(String.valueOf(i))
.desc(i + "")
.sort(i)
.currentCount(currentCount)
.lastYearCount(lastYearCount)
.build());
ParamUtil.dealParam(dto);
List<TreadVo> list;
switch (dto.getQueryTimeType()) {
case YEAR: {
dto.setStartTime(LocalDateTime.of(dto.getYear(), 1, 1, 0, 0, 0)
.minusYears(5L));
dto.setEndTime(LocalDateTime.of(dto.getYear(), 12, 31, 23, 59, 59));
list = themeRecruitmentJobMapper.recruitmentTrendYear(dto);
break;
}
case QUARTER: {
dto.setStartTime(LocalDateTime.of(dto.getYear(), 1, 1, 0, 0, 0));
dto.setEndTime(LocalDateTime.of(dto.getYear(), 12, 31, 23, 59, 59));
list = themeRecruitmentJobMapper.recruitmentTrendQuarter(dto);
break;
}
case MONTH: {
dto.setStartTime(LocalDateTime.of(dto.getYear(), 1, 1, 0, 0, 0));
dto.setEndTime(LocalDateTime.of(dto.getYear(), 12, 31, 23, 59, 59));
list = themeRecruitmentJobMapper.recruitmentTrendMonth(dto);
break;
}
default:
throw new ServiceException("时间类型错误");
}
// 计算同环比
MathUtil.calculatePercentageGrowthRate(dto.getQueryTimeType(), list);
return list;
}
@Override
public List<QueryResultVo> majorIndustryRecruitment(QueryParamDto dto) {
List<QueryResultVo> list = new ArrayList<>();
List<Tuple2<String, String>> industryList =
Collections.unmodifiableList(new ArrayList<>(Arrays.asList(
Tuples.of("1", "制造业"),
Tuples.of("2", "信息技术"),
Tuples.of("3", "建筑业"),
Tuples.of("4", "批发零售业"),
Tuples.of("5", "住宿餐饮业"),
Tuples.of("6", "交通运输业")
)));
for (Tuple2<String, String> industry : industryList) {
list.add(QueryResultVo.builder()
.code(industry.getT1())
.desc(industry.getT2())
.count((long) Math.floor(Math.random() * 5000) + 500)
.build());
}
dealParam(dto);
List<QueryResultVo> list = themeRecruitmentJobMapper.majorIndustryRecruitment(dto);
MathUtil.calculatePercentage(list);
ParamUtil.fillDictName(list, "majorIndustry");
return list;
}
@Override
public EchartsVo majorIndustryLaborForceTread(QueryParamDto dto) {
List<String> xAxis = IntStream.rangeClosed(1, 12)
.mapToObj(i -> i + "")
.collect(Collectors.toList());
List<Tuple2<String, String>> industryList =
Collections.unmodifiableList(new ArrayList<>(Arrays.asList(
Tuples.of("1", "制造业"),
Tuples.of("2", "信息技术"),
Tuples.of("3", "建筑业")
)));
List<EchartsSeriesVo> series = new ArrayList<>();
for (Tuple2<String, String> industry : industryList) {
List<Long> dataList = new ArrayList<>();
for (int i = 0; i < 12; i++) {
dataList.add((long) Math.floor(Math.random() * 4000) + 1000);
ParamUtil.dealParam(dto);
EchartsVo vo;
List<TreadVo> list;
switch (dto.getQueryTimeType()) {
case YEAR: {
dto.setStartTime(LocalDateTime.of(dto.getYear(), 1, 1, 0, 0, 0)
.minusYears(5L));
dto.setEndTime(LocalDateTime.of(dto.getYear(), 12, 31, 23, 59, 59));
list = themeRecruitmentJobMapper.majorIndustryLaborForceTreadYear(dto);
vo = transform(list);
ParamUtil.fillDictName(vo, "majorIndustry");
break;
}
series.add(EchartsSeriesVo.builder().name(industry.getT2()).data(dataList).build());
case QUARTER: {
dto.setStartTime(LocalDateTime.of(dto.getYear(), 1, 1, 0, 0, 0));
dto.setEndTime(LocalDateTime.of(dto.getYear(), 12, 31, 23, 59, 59));
list = themeRecruitmentJobMapper.majorIndustryLaborForceTreadQuarter(dto);
vo = transform(list);
ParamUtil.fillDictName(vo, "majorIndustry");
break;
}
case MONTH: {
dto.setStartTime(LocalDateTime.of(dto.getYear(), 1, 1, 0, 0, 0));
dto.setEndTime(LocalDateTime.of(dto.getYear(), 12, 31, 23, 59, 59));
list = themeRecruitmentJobMapper.majorIndustryLaborForceTreadMonth(dto);
vo = transform(list);
ParamUtil.fillDictName(vo, "majorIndustry");
break;
}
default:
throw new ServiceException("时间类型错误");
}
return vo;
}
private EchartsVo transform(List<TreadVo> list) {
EchartsVo vo = EchartsVo.builder()
.xAxis(new ArrayList<>())
.series(new ArrayList<>())
.build();
if (CollectionUtils.isEmpty(list)) {
return vo;
}
return EchartsVo.builder().xAxis(xAxis).series(series).build();
Map<String, List<TreadVo>> anotherCodeMap = new HashMap<>();
for (TreadVo tread : list) {
if (StringUtils.isBlank(tread.getAnotherCode())) {
continue;
}
if (!anotherCodeMap.containsKey(tread.getAnotherCode())) {
anotherCodeMap.put(tread.getAnotherCode(), new ArrayList<>());
}
anotherCodeMap.get(tread.getAnotherCode()).add(tread);
}
List<String> xAxis = anotherCodeMap.values().stream()
.findFirst()
.map(firstGroup -> firstGroup.stream()
.map(TreadVo::getDesc)
.collect(Collectors.toList()))
.orElse(new ArrayList<>());
List<EchartsSeriesVo> series = new ArrayList<>();
for (Map.Entry<String, List<TreadVo>> entry : anotherCodeMap.entrySet()) {
List<Long> dataList = new ArrayList<>();
for (TreadVo tread : entry.getValue()) {
dataList.add(tread.getCurrentCount());
}
series.add(EchartsSeriesVo.builder()
.name(entry.getKey())
.data(dataList)
.build());
}
vo.setXAxis(xAxis);
vo.setSeries(series);
return vo;
}
@Override
public List<QueryResultVo> companyRecruitmentCount(QueryParamDto dto) {
List<QueryResultVo> list = new ArrayList<>();
List<Tuple2<String, String>> companyTypeList =
Collections.unmodifiableList(new ArrayList<>(Arrays.asList(
Tuples.of("1", "国有企业"),
Tuples.of("2", "民营企业"),
Tuples.of("3", "外资企业"),
Tuples.of("4", "合资企业"),
Tuples.of("5", "事业单位")
)));
for (Tuple2<String, String> type : companyTypeList) {
list.add(QueryResultVo.builder()
.code(type.getT1())
.desc(type.getT2())
.count((long) Math.floor(Math.random() * 3000) + 200)
.build());
}
ParamUtil.dealParam(dto);
List<QueryResultVo> list = themeRecruitmentJobMapper.companyRecruitmentCount(dto);
MathUtil.calculatePercentage(list);
ParamUtil.fillDictName(list, "companyType");
return list;
}
@Override
public EchartsVo companyRecruitmentWay(QueryParamDto dto) {
List<String> xAxis = IntStream.rangeClosed(1, 12)
.mapToObj(i -> i + "")
.collect(Collectors.toList());
List<Tuple2<String, String>> wayList =
Collections.unmodifiableList(new ArrayList<>(Arrays.asList(
Tuples.of("1", "线上招聘"),
Tuples.of("2", "线下招聘"),
Tuples.of("3", "校园招聘"),
Tuples.of("4", "内部推荐")
)));
ParamUtil.dealParam(dto);
List<TreadVo> list = themeRecruitmentJobMapper.companyRecruitmentWay(dto);
EchartsVo vo = transform(list);
ParamUtil.fillDictName(vo, "recruitmentWay");
List<EchartsSeriesVo> series = new ArrayList<>();
for (Tuple2<String, String> way : wayList) {
List<Long> dataList = new ArrayList<>();
for (int i = 0; i < 12; i++) {
dataList.add((long) Math.floor(Math.random() * 300) + 50);
// 填充重点行业
List<String> xAxis = vo.getXAxis();
if (CollectionUtils.isNotEmpty(xAxis)) {
List<String> xAxisDesc = new ArrayList<>();
for (String x : xAxis) {
xAxisDesc.add(ParamUtil.fillDictName(x, "majorIndustry"));
}
series.add(EchartsSeriesVo.builder().name(way.getT2()).data(dataList).build());
vo.setXAxis(xAxisDesc);
}
return EchartsVo.builder().xAxis(xAxis).series(series).build();
return vo;
}
@Override
public EchartsVo companyRecruitmentEducationLevel(QueryParamDto dto) {
List<String> xAxis = IntStream.rangeClosed(1, 12)
.mapToObj(i -> i + "")
.collect(Collectors.toList());
List<Tuple2<String, String>> levelList =
Collections.unmodifiableList(new ArrayList<>(Arrays.asList(
Tuples.of("1", "高中及以下"),
Tuples.of("2", "大专"),
Tuples.of("3", "本科"),
Tuples.of("4", "硕士及以上")
)));
ParamUtil.dealParam(dto);
List<TreadVo> list = themeRecruitmentJobMapper.companyRecruitmentEducationLevel(dto);
EchartsVo vo = transform(list);
ParamUtil.fillDictName(vo, "educationLevel");
List<EchartsSeriesVo> series = new ArrayList<>();
for (Tuple2<String, String> level : levelList) {
List<Long> dataList = new ArrayList<>();
for (int i = 0; i < 12; i++) {
dataList.add((long) Math.floor(Math.random() * 500) + 100);
// 填充重点行业
List<String> xAxis = vo.getXAxis();
if (CollectionUtils.isNotEmpty(xAxis)) {
List<String> xAxisDesc = new ArrayList<>();
for (String x : xAxis) {
xAxisDesc.add(ParamUtil.fillDictName(x, "majorIndustry"));
}
series.add(EchartsSeriesVo.builder().name(level.getT2()).data(dataList).build());
vo.setXAxis(xAxisDesc);
}
return EchartsVo.builder().xAxis(xAxis).series(series).build();
return vo;
}
@Override
public List<QueryResultVo> recruitmentArea(QueryParamDto dto) {
List<QueryResultVo> list = new ArrayList<>();
for (Tuple2<String, String> area : CommonConstant.AREA_LIST) {
list.add(QueryResultVo.builder()
.code(area.getT1())
.desc(area.getT2())
.count((long) Math.floor(Math.random() * 2000) + 100)
.build());
}
ParamUtil.dealParam(dto);
List<QueryResultVo> list = themeRecruitmentJobMapper.recruitmentArea(dto);
MathUtil.calculatePercentage(list);
ParamUtil.fillDictName(list, "area");
return list;
}
@Override
public List<QueryResultVo> commitmentSalary(QueryParamDto dto) {
List<QueryResultVo> list = new ArrayList<>();
List<Tuple2<String, String>> salaryList =
Collections.unmodifiableList(new ArrayList<>(Arrays.asList(
Tuples.of("1", "2000元以下"),
Tuples.of("2", "2000-4000元"),
Tuples.of("3", "4000-6000元"),
Tuples.of("4", "6000-8000元"),
Tuples.of("5", "8000-10000元"),
Tuples.of("6", "10000元以上")
)));
for (Tuple2<String, String> salary : salaryList) {
list.add(QueryResultVo.builder()
.code(salary.getT1())
.desc(salary.getT2())
.count((long) Math.floor(Math.random() * 3000) + 200)
.build());
}
ParamUtil.dealParam(dto);
List<QueryResultVo> list = themeRecruitmentJobMapper.commitmentSalary(dto);
MathUtil.calculatePercentage(list);
return list;
}
}

View File

@@ -2,8 +2,11 @@ package com.ruoyi.cms.util;
import com.ruoyi.cms.constant.CommonConstant;
import com.ruoyi.cms.domain.dto.QueryParamDto;
import com.ruoyi.cms.domain.vo.EchartsSeriesVo;
import com.ruoyi.cms.domain.vo.EchartsVo;
import com.ruoyi.cms.domain.vo.GraduateEmploymentInfoTreadVo;
import com.ruoyi.cms.domain.vo.QueryResultVo;
import com.ruoyi.cms.domain.vo.TreadVo;
import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.common.utils.StringUtils;
import org.apache.commons.collections4.CollectionUtils;
@@ -146,6 +149,21 @@ public class ParamUtil {
}
}
/**
* 填充字典名称
*
* @param echarts 数据
* @param dictName 字典名称
*/
public static void fillDictName(EchartsVo echarts, String dictName) {
if (Objects.isNull(echarts) || CollectionUtils.isEmpty(echarts.getSeries()) || StringUtils.isBlank(dictName)) {
return;
}
for (EchartsSeriesVo vo : echarts.getSeries()) {
vo.setName(fillDictName(vo.getName(), dictName));
}
}
/**
* 填充字典名称
@@ -164,7 +182,13 @@ public class ParamUtil {
}
}
private static String fillDictName(String code, String dictName){
/**
* 填充字典名称
* @param code 码值
* @param dictName 字典名称
* @return 字典值
*/
public static String fillDictName(String code, String dictName) {
switch (dictName) {
case "industry": {
return Optional.ofNullable(CommonConstant.INDUSTRY_MAP.get(code)).orElse("未知");
@@ -190,6 +214,15 @@ public class ParamUtil {
case "jobType": {
return Optional.ofNullable(CommonConstant.JOB_TYPE_MAP.get(code)).orElse("未知");
}
case "companyType": {
return Optional.ofNullable(CommonConstant.COMPANY_TYPE_MAP.get(code)).orElse("未知");
}
case "recruitmentWay": {
return Optional.ofNullable(CommonConstant.RECRUITMENT_WAY_MAP.get(code)).orElse("未知");
}
case "area": {
return Optional.ofNullable(CommonConstant.AREA_MAP.get(code)).orElse("未知");
}
default:
throw new ServiceException("字典名称错误");
}

View File

@@ -332,4 +332,479 @@
GROUP BY areaCode
ORDER BY areaCode
</select>
<select id="recruitmentTrendYear"
parameterType="com.ruoyi.cms.domain.dto.QueryParamDto"
resultType="com.ruoyi.cms.domain.vo.TreadVo">
WITH params AS (
SELECT CAST(EXTRACT(YEAR FROM #{endTime}) AS INT) AS current_year
),
-- 一次性生成两年(当前年、去年)的所有月度时间范围
month_ranges AS (
SELECT
m.month_num,
y.year_offset,
(make_timestamp(p.current_year - y.year_offset - month_num + 1, 1, 1, 0, 0, 0) ) AS start_time,
(make_timestamp(p.current_year - month_num + 1 , 12, 31, 23, 59, 59) ) AS end_time
FROM params p
CROSS JOIN (SELECT 0 AS year_offset UNION ALL SELECT 1) y
CROSS JOIN (SELECT generate_series(1, 5) AS month_num) m
),
-- 一次扫描表,按条件区分当前年和去年数据
aggregated_data AS (
SELECT
r.month_num,
COALESCE(SUM(CASE WHEN r.year_offset = 0 THEN vacancies END), 0) AS current_count,
COALESCE(SUM(CASE WHEN r.year_offset = 1 THEN vacancies END), 0) AS last_count
FROM month_ranges r
LEFT JOIN theme_recruitment_job
ON
posting_date BETWEEN r.start_time AND r.end_time
<if test="area != null and area != ''">
AND job_location_area_code = #{area}
</if>
<if test="industry != null and industry != ''">
AND industry LIKE #{industry} || '%'
</if>
<if test="industryList != null and industryList.size() > 0">
AND (
<foreach collection="industryList" item="industry" open="" separator=" OR " close="">
industry LIKE #{industry} || '%'
</foreach>
)
</if>
GROUP BY r.month_num
)
SELECT
(CAST(EXTRACT(YEAR FROM #{endTime}) AS INT) +1 - month_num) AS code,
(CAST(EXTRACT(YEAR FROM #{endTime}) AS INT) +1 - month_num) AS sort,
(CAST(EXTRACT(YEAR FROM #{endTime}) AS INT) +1 - month_num) || '年' AS "desc",
COALESCE(current_count, 0) AS currentCount,
COALESCE(last_count, 0) AS lastYearCount
FROM aggregated_data
ORDER BY sort ;
</select>
<select id="recruitmentTrendQuarter"
parameterType="com.ruoyi.cms.domain.dto.QueryParamDto"
resultType="com.ruoyi.cms.domain.vo.TreadVo">
WITH params AS (
SELECT CAST(EXTRACT(YEAR FROM #{endTime}) AS INT) AS current_year
),
-- 一次性生成两年(当前年、去年)的所有月度时间范围
month_ranges AS (
SELECT
m.month_num,
y.year_offset,
(make_timestamp(p.current_year - y.year_offset, 1, 1, 0, 0, 0)
+ (m.month_num - 1) * 3 * INTERVAL '1 month') AS start_time,
(make_timestamp(p.current_year - y.year_offset, 1, 1, 0, 0, 0)
+ m.month_num * 3 * INTERVAL '1 month' - INTERVAL '1 second') AS end_time
FROM params p
CROSS JOIN (SELECT 0 AS year_offset UNION ALL SELECT 1) y
CROSS JOIN (SELECT generate_series(1, 4) AS month_num) m
),
-- 一次扫描表,按条件区分当前年和去年数据
aggregated_data AS (
SELECT
r.month_num,
COALESCE(SUM(CASE WHEN r.year_offset = 0 THEN vacancies END), 0) AS current_count,
COALESCE(SUM(CASE WHEN r.year_offset = 1 THEN vacancies END), 0) AS last_count
FROM month_ranges r
LEFT JOIN theme_recruitment_job
ON
posting_date BETWEEN r.start_time AND r.end_time
<if test="area != null and area != ''">
AND job_location_area_code = #{area}
</if>
<if test="industry != null and industry != ''">
AND industry LIKE #{industry} || '%'
</if>
<if test="industryList != null and industryList.size() > 0">
AND (
<foreach collection="industryList" item="industry" open="" separator=" OR " close="">
industry LIKE #{industry} || '%'
</foreach>
)
</if>
GROUP BY r.month_num
)
SELECT
month_num AS code,
month_num AS sort,
'第' || month_num || '季度' AS "desc",
COALESCE(current_count, 0) AS currentCount,
COALESCE(last_count, 0) AS lastYearCount
FROM aggregated_data
ORDER BY month_num;
</select>
<select id="recruitmentTrendMonth"
parameterType="com.ruoyi.cms.domain.dto.QueryParamDto"
resultType="com.ruoyi.cms.domain.vo.TreadVo">
WITH params AS (
SELECT CAST(EXTRACT(YEAR FROM #{endTime}) AS INT) AS current_year
),
-- 一次性生成两年(当前年、去年)的所有月度时间范围
month_ranges AS (
SELECT
m.month_num,
y.year_offset,
(make_timestamp(p.current_year - y.year_offset, 1, 1, 0, 0, 0)
+ (m.month_num - 1) * INTERVAL '1 month') AS start_time,
(make_timestamp(p.current_year - y.year_offset, 1, 1, 0, 0, 0)
+ m.month_num * INTERVAL '1 month' - INTERVAL '1 second') AS end_time
FROM params p
CROSS JOIN (SELECT 0 AS year_offset UNION ALL SELECT 1) y
CROSS JOIN (SELECT generate_series(1, 12) AS month_num) m
),
-- 一次扫描表,按条件区分当前年和去年数据
aggregated_data AS (
SELECT
r.month_num,
COALESCE(SUM(CASE WHEN r.year_offset = 0 THEN vacancies END), 0) AS current_count,
COALESCE(SUM(CASE WHEN r.year_offset = 1 THEN vacancies END), 0) AS last_count
FROM month_ranges r
LEFT JOIN theme_recruitment_job
ON
posting_date BETWEEN r.start_time AND r.end_time
<if test="area != null and area != ''">
AND job_location_area_code = #{area}
</if>
<if test="industry != null and industry != ''">
AND industry LIKE #{industry} || '%'
</if>
<if test="industryList != null and industryList.size() > 0">
AND (
<foreach collection="industryList" item="industry" open="" separator=" OR " close="">
industry LIKE #{industry} || '%'
</foreach>
)
</if>
GROUP BY r.month_num
)
SELECT
month_num AS code,
month_num AS sort,
month_num || '月' AS "desc",
COALESCE(current_count, 0) AS currentCount,
COALESCE(last_count, 0) AS lastYearCount
FROM aggregated_data
ORDER BY month_num;
</select>
<select id="majorIndustryRecruitment"
parameterType="com.ruoyi.cms.domain.dto.QueryParamDto"
resultType="com.ruoyi.cms.domain.vo.QueryResultVo">
SELECT
code,
COALESCE(SUM(vacancies), 0) AS count
FROM (
SELECT
vacancies,
SUBSTRING(industry FROM 1 FOR 3) AS code
FROM theme_recruitment_job
WHERE
<!-- 引入公共条件 -->
<include refid="commonConditions"/>
) subquery
GROUP BY code
ORDER BY code
</select>
<select id="majorIndustryLaborForceTreadYear"
parameterType="com.ruoyi.cms.domain.dto.QueryParamDto"
resultType="com.ruoyi.cms.domain.vo.TreadVo">
WITH params AS (
SELECT CAST(EXTRACT(YEAR FROM #{endTime}) AS INT) AS current_year
),
-- 一次性生成两年(当前年、去年)的所有月度时间范围
month_ranges AS (
SELECT
m.month_num,
y.year_offset,
(make_timestamp(p.current_year - y.year_offset - month_num + 1, 1, 1, 0, 0, 0) ) AS start_time,
(make_timestamp(p.current_year - month_num + 1 , 12, 31, 23, 59, 59) ) AS end_time
FROM params p
CROSS JOIN (SELECT 0 AS year_offset UNION ALL SELECT 1) y
CROSS JOIN (SELECT generate_series(1, 5) AS month_num) m
),
-- 一次扫描表,按条件区分当前年和去年数据
aggregated_data AS (
SELECT
r.month_num,
SUBSTRING(industry FROM 1 FOR 3) AS another_code,
COALESCE(SUM(CASE WHEN r.year_offset = 0 THEN vacancies END), 0) AS current_count,
COALESCE(SUM(CASE WHEN r.year_offset = 1 THEN vacancies END), 0) AS last_count
FROM month_ranges r
LEFT JOIN theme_recruitment_job
ON
posting_date BETWEEN r.start_time AND r.end_time
<if test="area != null and area != ''">
AND job_location_area_code = #{area}
</if>
<if test="industry != null and industry != ''">
AND industry LIKE #{industry} || '%'
</if>
<if test="industryList != null and industryList.size() > 0">
AND (
<foreach collection="industryList" item="industry" open="" separator=" OR " close="">
industry LIKE #{industry} || '%'
</foreach>
)
</if>
GROUP BY r.month_num,SUBSTRING(industry FROM 1 FOR 3)
)
SELECT
(CAST(EXTRACT(YEAR FROM #{endTime}) AS INT) +1 - month_num) AS code,
(CAST(EXTRACT(YEAR FROM #{endTime}) AS INT) +1 - month_num) AS sort,
(CAST(EXTRACT(YEAR FROM #{endTime}) AS INT) +1 - month_num) || '年' AS "desc",
another_code AS anotherCode,
COALESCE(current_count, 0) AS currentCount,
COALESCE(last_count, 0) AS lastYearCount
FROM aggregated_data
ORDER BY sort ;
</select>
<select id="majorIndustryLaborForceTreadQuarter"
parameterType="com.ruoyi.cms.domain.dto.QueryParamDto"
resultType="com.ruoyi.cms.domain.vo.TreadVo">
WITH params AS (
SELECT CAST(EXTRACT(YEAR FROM #{endTime}) AS INT) AS current_year
),
-- 一次性生成两年(当前年、去年)的所有月度时间范围
month_ranges AS (
SELECT
m.month_num,
y.year_offset,
(make_timestamp(p.current_year - y.year_offset, 1, 1, 0, 0, 0)
+ (m.month_num - 1) * 3 * INTERVAL '1 month') AS start_time,
(make_timestamp(p.current_year - y.year_offset, 1, 1, 0, 0, 0)
+ m.month_num * 3 * INTERVAL '1 month' - INTERVAL '1 second') AS end_time
FROM params p
CROSS JOIN (SELECT 0 AS year_offset UNION ALL SELECT 1) y
CROSS JOIN (SELECT generate_series(1, 4) AS month_num) m
),
-- 一次扫描表,按条件区分当前年和去年数据
aggregated_data AS (
SELECT
r.month_num,
SUBSTRING(industry FROM 1 FOR 3) AS another_code,
COALESCE(SUM(CASE WHEN r.year_offset = 0 THEN vacancies END), 0) AS current_count,
COALESCE(SUM(CASE WHEN r.year_offset = 1 THEN vacancies END), 0) AS last_count
FROM month_ranges r
LEFT JOIN theme_recruitment_job
ON
posting_date BETWEEN r.start_time AND r.end_time
<if test="area != null and area != ''">
AND job_location_area_code = #{area}
</if>
<if test="industry != null and industry != ''">
AND industry LIKE #{industry} || '%'
</if>
<if test="industryList != null and industryList.size() > 0">
AND (
<foreach collection="industryList" item="industry" open="" separator=" OR " close="">
industry LIKE #{industry} || '%'
</foreach>
)
</if>
GROUP BY r.month_num,SUBSTRING(industry FROM 1 FOR 3)
)
SELECT
month_num AS code,
month_num AS sort,
'第' || month_num || '季度' AS "desc",
another_code AS anotherCode,
COALESCE(current_count, 0) AS currentCount,
COALESCE(last_count, 0) AS lastYearCount
FROM aggregated_data
ORDER BY month_num;
</select>
<select id="majorIndustryLaborForceTreadMonth"
parameterType="com.ruoyi.cms.domain.dto.QueryParamDto"
resultType="com.ruoyi.cms.domain.vo.TreadVo">
WITH params AS (
SELECT CAST(EXTRACT(YEAR FROM #{endTime}) AS INT) AS current_year
),
-- 一次性生成两年(当前年、去年)的所有月度时间范围
month_ranges AS (
SELECT
m.month_num,
y.year_offset,
(make_timestamp(p.current_year - y.year_offset, 1, 1, 0, 0, 0)
+ (m.month_num - 1) * INTERVAL '1 month') AS start_time,
(make_timestamp(p.current_year - y.year_offset, 1, 1, 0, 0, 0)
+ m.month_num * INTERVAL '1 month' - INTERVAL '1 second') AS end_time
FROM params p
CROSS JOIN (SELECT 0 AS year_offset UNION ALL SELECT 1) y
CROSS JOIN (SELECT generate_series(1, 12) AS month_num) m
),
-- 一次扫描表,按条件区分当前年和去年数据
aggregated_data AS (
SELECT
r.month_num,
SUBSTRING(industry FROM 1 FOR 3) AS another_code,
COALESCE(SUM(CASE WHEN r.year_offset = 0 THEN vacancies END), 0) AS current_count,
COALESCE(SUM(CASE WHEN r.year_offset = 1 THEN vacancies END), 0) AS last_count
FROM month_ranges r
LEFT JOIN theme_recruitment_job
ON
posting_date BETWEEN r.start_time AND r.end_time
<if test="area != null and area != ''">
AND job_location_area_code = #{area}
</if>
<if test="industry != null and industry != ''">
AND industry LIKE #{industry} || '%'
</if>
<if test="industryList != null and industryList.size() > 0">
AND (
<foreach collection="industryList" item="industry" open="" separator=" OR " close="">
industry LIKE #{industry} || '%'
</foreach>
)
</if>
GROUP BY r.month_num,SUBSTRING(industry FROM 1 FOR 3)
)
SELECT
month_num AS code,
month_num AS sort,
month_num || '月' AS "desc",
another_code AS anotherCode,
COALESCE(current_count, 0) AS currentCount,
COALESCE(last_count, 0) AS lastYearCount
FROM aggregated_data
ORDER BY month_num;
</select>
<select id="companyRecruitmentCount"
parameterType="com.ruoyi.cms.domain.dto.QueryParamDto"
resultType="com.ruoyi.cms.domain.vo.QueryResultVo">
SELECT
code,
COALESCE(SUM(vacancies), 0) AS count
FROM (
SELECT
vacancies,
nature AS code
FROM theme_recruitment_job
WHERE
<!-- 引入公共条件 -->
<include refid="commonConditions"/>
) subquery
GROUP BY code
ORDER BY code
</select>
<select id="companyRecruitmentWay"
parameterType="com.ruoyi.cms.domain.dto.QueryParamDto"
resultType="com.ruoyi.cms.domain.vo.TreadVo">
SELECT
code,
anotherCode,
COALESCE(SUM(vacancies), 0) AS currentCount
FROM (
SELECT
vacancies,
nature AS code,
recruitment_way AS anotherCode
FROM theme_recruitment_job
WHERE
<!-- 引入公共条件 -->
<include refid="commonConditions"/>
) subquery
GROUP BY code,anotherCode
ORDER BY code,anotherCode
</select>
<select id="companyRecruitmentEducationLevel"
parameterType="com.ruoyi.cms.domain.dto.QueryParamDto"
resultType="com.ruoyi.cms.domain.vo.TreadVo">
SELECT
code,
anotherCode,
COALESCE(SUM(vacancies), 0) AS currentCount
FROM (
SELECT
vacancies,
nature AS code,
education AS anotherCode
FROM theme_recruitment_job
WHERE
<!-- 引入公共条件 -->
<include refid="commonConditions"/>
) subquery
GROUP BY code,anotherCode
ORDER BY code,anotherCode
</select>
<select id="recruitmentArea"
parameterType="com.ruoyi.cms.domain.dto.QueryParamDto"
resultType="com.ruoyi.cms.domain.vo.QueryResultVo">
SELECT
code,
COALESCE(SUM(vacancies), 0) AS count
FROM (
SELECT
vacancies,
job_location_area_code AS code
FROM theme_recruitment_job
WHERE
<!-- 引入公共条件 -->
<include refid="commonConditions"/>
) subquery
GROUP BY code
ORDER BY code
</select>
<select id="commitmentSalary"
parameterType="com.ruoyi.cms.domain.dto.QueryParamDto"
resultType="com.ruoyi.cms.domain.vo.QueryResultVo">
SELECT
code,
"desc",
count
FROM(
SELECT
"desc" AS code,
"desc",
COALESCE(SUM(vacancies), 0) AS count
FROM (
SELECT
vacancies,
CASE
WHEN COALESCE(ROUND(AVG(((min_salary + max_salary)/2)), 2), 0) &lt; 5000 THEN '5K以下'
WHEN COALESCE(ROUND(AVG(((min_salary + max_salary)/2)), 2), 0) BETWEEN 5000 AND 8000 THEN '5-8K'
WHEN COALESCE(ROUND(AVG(((min_salary + max_salary)/2)), 2), 0) BETWEEN 8001 AND 12000 THEN '8-12K'
WHEN COALESCE(ROUND(AVG(((min_salary + max_salary)/2)), 2), 0) BETWEEN 12001 AND 15000 THEN '12-15K'
WHEN COALESCE(ROUND(AVG(((min_salary + max_salary)/2)), 2), 0) &gt; 15000 THEN '15K以上'
ELSE '未知'
END AS "desc"
FROM theme_recruitment_job
WHERE
<!-- 引入公共条件 -->
<include refid="commonConditions"/>
) subquery
GROUP BY "desc"
)
WHERE
COALESCE(SUM(vacancies), 0) > 0;
ORDER BY
CASE "desc"
WHEN '5K以下' THEN 1
WHEN '5-8K' THEN 2
WHEN '8-12K' THEN 3
WHEN '12-15K' THEN 4
WHEN '15K以上' THEN 5
ELSE 6
END
</select>
</mapper>