添加功能

This commit is contained in:
马宝龙
2026-07-03 13:15:14 +08:00
parent fbf2b2da0e
commit 631c4fdc21
10 changed files with 629 additions and 1 deletions

View File

@@ -20,6 +20,8 @@ public enum ModelTemplateTypeEnum {
MODEL_SUPPLY_MONITOR_TOTAL_FERTILITY_RATE("劳动力动态监测系统-劳动力供给预测总和生育率"),
MODEL_SUPPLY_MONITOR_LABOR_JOIN_RATE("劳动力动态监测系统-劳动力供给劳动参与率"),
MODEL_SUPPLY_MONITOR_INDUSTRY_POPULATION("劳动力动态监测系统-劳动力供给分行业劳动力人口"),
;
private final String desc;
}

View File

@@ -0,0 +1,104 @@
package com.ruoyi.cms.controller;
import com.ruoyi.cms.domain.ModelSupplyMonitorIndustryPopulation;
import com.ruoyi.cms.service.ModelSupplyMonitorIndustryPopulationService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import javax.validation.Valid;
import java.util.List;
/**
* 劳动力供给分行业劳动力人口
*
* @author 马宝龙
* @date 2026/7/3
*/
@RestController
@RequestMapping("/model/supplyMonitorIndustryPopulation")
@RequiredArgsConstructor
public class ModelSupplyMonitorIndustryPopulationController extends BaseController {
private final ModelSupplyMonitorIndustryPopulationService modelSupplyMonitorIndustryPopulationService;
/**
* 创建
*
* @param modelSupplyMonitorIndustryPopulation 劳动力供给分行业劳动力人口
* @return 创建结果
*/
@PostMapping("/create")
public AjaxResult create(@Valid @RequestBody ModelSupplyMonitorIndustryPopulation modelSupplyMonitorIndustryPopulation) {
modelSupplyMonitorIndustryPopulationService.create(modelSupplyMonitorIndustryPopulation);
return AjaxResult.success();
}
/**
* 更新
*
* @param modelSupplyMonitorIndustryPopulation 劳动力供给分行业劳动力人口
* @return 更新结果
*/
@PutMapping("/update")
public AjaxResult update(@Valid @RequestBody ModelSupplyMonitorIndustryPopulation modelSupplyMonitorIndustryPopulation) {
modelSupplyMonitorIndustryPopulationService.update(modelSupplyMonitorIndustryPopulation);
return AjaxResult.success();
}
/**
* 删除
*
* @param id ID
* @return 删除结果
*/
@DeleteMapping("/delete")
public AjaxResult delete(@RequestParam Long id) {
modelSupplyMonitorIndustryPopulationService.delete(id);
return AjaxResult.success();
}
/**
* 清空
*
* @return 清空结果
*/
@DeleteMapping("/clear")
public AjaxResult clear() {
modelSupplyMonitorIndustryPopulationService.clear();
return AjaxResult.success();
}
/**
* 查询详情
*
* @param id ID
* @return 劳动力供给分行业劳动力人口
*/
@GetMapping("/detail")
public AjaxResult detail(@RequestParam Long id) {
ModelSupplyMonitorIndustryPopulation data = modelSupplyMonitorIndustryPopulationService.detail(id);
return AjaxResult.success(data);
}
/**
* 查询列表
*
* @param modelSupplyMonitorIndustryPopulation 劳动力供给分行业劳动力人口
* @return 列表
*/
@PostMapping("/list")
public AjaxResult list(@RequestBody ModelSupplyMonitorIndustryPopulation modelSupplyMonitorIndustryPopulation) {
List<ModelSupplyMonitorIndustryPopulation> list =
modelSupplyMonitorIndustryPopulationService.list(modelSupplyMonitorIndustryPopulation);
return AjaxResult.success(list);
}
}

View File

@@ -0,0 +1,53 @@
package com.ruoyi.cms.domain;
import com.ruoyi.common.annotation.Excel;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.io.Serializable;
/**
* 劳动力供给分行业劳动力人口
*
* @author 马宝龙
* @date 2026/7/3
*/
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class ModelSupplyMonitorIndustryPopulation implements Serializable {
private static final long serialVersionUID = 1L;
/**
* 主键
*/
private Long id;
/**
* 年份
*/
@Excel(name = "年份")
private Integer year;
/**
* 行业编号
*/
@Excel(name = "行业编号")
private String industryCode;
/**
* 行业名称
*/
@Excel(name = "行业名称")
private String industryName;
/**
* 男性人数
*/
@Excel(name = "男性人数")
private Integer maleCount;
/**
* 女性人数
*/
@Excel(name = "女性人数")
private Integer femaleCount;
}

View File

@@ -0,0 +1,64 @@
package com.ruoyi.cms.mapper;
import com.ruoyi.cms.domain.ModelSupplyMonitorIndustryPopulation;
import java.util.List;
/**
* 劳动力供给分行业劳动力人口
*
* @author 马宝龙
* @date 2026/7/3
*/
public interface ModelSupplyMonitorIndustryPopulationMapper {
/**
* 新增
*
* @param modelSupplyMonitorIndustryPopulation 劳动力供给分行业劳动力人口
*/
void insert(ModelSupplyMonitorIndustryPopulation modelSupplyMonitorIndustryPopulation);
/**
* 修改
*
* @param modelSupplyMonitorIndustryPopulation 劳动力供给分行业劳动力人口
*/
void update(ModelSupplyMonitorIndustryPopulation modelSupplyMonitorIndustryPopulation);
/**
* 通过ID删除
*
* @param id ID
*/
void deleteById(Long id);
/**
* 清空
*/
void clear();
/**
* 通过ID查询
*
* @param id ID
* @return 劳动力供给分行业劳动力人口
*/
ModelSupplyMonitorIndustryPopulation selectById(Long id);
/**
* 查询唯一(按年份+行业编号)
*
* @param modelSupplyMonitorIndustryPopulation 劳动力供给分行业劳动力人口
* @return 劳动力供给分行业劳动力人口
*/
ModelSupplyMonitorIndustryPopulation findUnique(ModelSupplyMonitorIndustryPopulation modelSupplyMonitorIndustryPopulation);
/**
* 查询列表
*
* @param modelSupplyMonitorIndustryPopulation 劳动力供给分行业劳动力人口
* @return 列表
*/
List<ModelSupplyMonitorIndustryPopulation> list(ModelSupplyMonitorIndustryPopulation modelSupplyMonitorIndustryPopulation);
}

View File

@@ -0,0 +1,75 @@
package com.ruoyi.cms.service;
import com.ruoyi.cms.domain.ModelSupplyMonitorIndustryPopulation;
import com.ruoyi.cms.domain.dto.ModelExportParamDto;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
/**
* 劳动力供给分行业劳动力人口
*
* @author 马宝龙
* @date 2026/7/3
*/
public interface ModelSupplyMonitorIndustryPopulationService {
/**
* 创建
*
* @param modelSupplyMonitorIndustryPopulation 劳动力供给分行业劳动力人口
*/
void create(ModelSupplyMonitorIndustryPopulation modelSupplyMonitorIndustryPopulation);
/**
* 更新
*
* @param modelSupplyMonitorIndustryPopulation 劳动力供给分行业劳动力人口
*/
void update(ModelSupplyMonitorIndustryPopulation modelSupplyMonitorIndustryPopulation);
/**
* 删除
*
* @param id ID
*/
void delete(Long id);
/**
* 清空
*/
void clear();
/**
* 查询详情
*
* @param id ID
* @return 劳动力供给分行业劳动力人口
*/
ModelSupplyMonitorIndustryPopulation detail(Long id);
/**
* 查询列表
*
* @param modelSupplyMonitorIndustryPopulation 劳动力供给分行业劳动力人口
* @return 列表
*/
List<ModelSupplyMonitorIndustryPopulation> list(ModelSupplyMonitorIndustryPopulation modelSupplyMonitorIndustryPopulation);
/**
* 导入数据
*
* @param file 文件
* @return 导入结果
*/
String importExcel(MultipartFile file);
/**
* 导出数据
*
* @param response 响应体
* @param dto 导出参数
*/
void exportExcel(HttpServletResponse response, ModelExportParamDto dto);
}

View File

@@ -3,6 +3,7 @@ package com.ruoyi.cms.service.impl;
import com.ruoyi.cms.constant.enums.ModelTemplateTypeEnum;
import com.ruoyi.cms.domain.dto.ModelExportParamDto;
import com.ruoyi.cms.service.ModelCommonService;
import com.ruoyi.cms.service.ModelSupplyMonitorIndustryPopulationService;
import com.ruoyi.cms.service.ModelSupplyMonitorLaborJoinRateService;
import com.ruoyi.cms.service.ModelSupplyMonitorPopulationService;
import com.ruoyi.cms.service.ModelSupplyMonitorTotalFertilityRateService;
@@ -40,6 +41,7 @@ public class ModelCommonServiceImpl implements ModelCommonService {
private final ModelSupplyMonitorPopulationService modelSupplyMonitorPopulationService;
private final ModelSupplyMonitorTotalFertilityRateService modelSupplyMonitorTotalFertilityRateService;
private final ModelSupplyMonitorLaborJoinRateService modelSupplyMonitorLaborJoinRateService;
private final ModelSupplyMonitorIndustryPopulationService modelSupplyMonitorIndustryPopulationService;
@Override
public void template(HttpServletResponse response,
@@ -91,6 +93,8 @@ public class ModelCommonServiceImpl implements ModelCommonService {
return modelSupplyMonitorTotalFertilityRateService.importExcel(file);
case MODEL_SUPPLY_MONITOR_LABOR_JOIN_RATE:
return modelSupplyMonitorLaborJoinRateService.importExcel(file);
case MODEL_SUPPLY_MONITOR_INDUSTRY_POPULATION:
return modelSupplyMonitorIndustryPopulationService.importExcel(file);
default:
throw new ServiceException("模板类型错误");
}
@@ -115,6 +119,9 @@ public class ModelCommonServiceImpl implements ModelCommonService {
case MODEL_SUPPLY_MONITOR_LABOR_JOIN_RATE:
modelSupplyMonitorLaborJoinRateService.exportExcel(response, dto);
break;
case MODEL_SUPPLY_MONITOR_INDUSTRY_POPULATION:
modelSupplyMonitorIndustryPopulationService.exportExcel(response, dto);
break;
default:
throw new ServiceException("模板类型错误");
}

View File

@@ -0,0 +1,204 @@
package com.ruoyi.cms.service.impl;
import com.ruoyi.cms.constant.enums.ModelTemplateTypeEnum;
import com.ruoyi.cms.domain.ModelSupplyMonitorIndustryPopulation;
import com.ruoyi.cms.domain.dto.ModelExportParamDto;
import com.ruoyi.cms.mapper.ModelSupplyMonitorIndustryPopulationMapper;
import com.ruoyi.cms.service.ModelSupplyMonitorIndustryPopulationService;
import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.bean.BeanValidators;
import com.ruoyi.common.utils.poi.ExcelUtil;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Validator;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
/**
* 劳动力供给分行业劳动力人口
*
* @author 马宝龙
* @date 2026/7/3
*/
@Slf4j
@Service
@Validated
@RequiredArgsConstructor
public class ModelSupplyMonitorIndustryPopulationServiceImpl implements ModelSupplyMonitorIndustryPopulationService {
private final ModelSupplyMonitorIndustryPopulationMapper modelSupplyMonitorIndustryPopulationMapper;
private final Validator validator;
@Override
public void create(ModelSupplyMonitorIndustryPopulation modelSupplyMonitorIndustryPopulation) {
check(modelSupplyMonitorIndustryPopulation);
// 查询唯一(按年份+行业编号)
Optional<ModelSupplyMonitorIndustryPopulation> optional = findUnique(modelSupplyMonitorIndustryPopulation);
if (optional.isPresent()) {
// 更新
ModelSupplyMonitorIndustryPopulation exists = optional.get();
modelSupplyMonitorIndustryPopulation.setId(exists.getId());
modelSupplyMonitorIndustryPopulationMapper.update(modelSupplyMonitorIndustryPopulation);
} else {
// 新增
modelSupplyMonitorIndustryPopulationMapper.insert(modelSupplyMonitorIndustryPopulation);
}
}
/**
* 检查
*
* @param modelSupplyMonitorIndustryPopulation 劳动力供给分行业劳动力人口
*/
void check(ModelSupplyMonitorIndustryPopulation modelSupplyMonitorIndustryPopulation) {
if (Objects.isNull(modelSupplyMonitorIndustryPopulation.getYear())) {
throw new ServiceException("年份不能为空");
}
if (StringUtils.isBlank(modelSupplyMonitorIndustryPopulation.getIndustryCode())) {
throw new ServiceException("行业编号不能为空");
}
if (StringUtils.isBlank(modelSupplyMonitorIndustryPopulation.getIndustryName())) {
throw new ServiceException("行业名称不能为空");
}
if (Objects.isNull(modelSupplyMonitorIndustryPopulation.getMaleCount())) {
throw new ServiceException("男性人数不能为空");
}
if (Objects.isNull(modelSupplyMonitorIndustryPopulation.getFemaleCount())) {
throw new ServiceException("女性人数不能为空");
}
}
@Override
public void update(ModelSupplyMonitorIndustryPopulation modelSupplyMonitorIndustryPopulation) {
check(modelSupplyMonitorIndustryPopulation);
if (Objects.isNull(modelSupplyMonitorIndustryPopulation.getId())) {
throw new ServiceException("id不能为空");
}
Optional<ModelSupplyMonitorIndustryPopulation> unique = findUnique(modelSupplyMonitorIndustryPopulation);
if (!unique.isPresent()) {
modelSupplyMonitorIndustryPopulationMapper.update(modelSupplyMonitorIndustryPopulation);
return;
}
ModelSupplyMonitorIndustryPopulation exists = unique.get();
if (!exists.getId().equals(modelSupplyMonitorIndustryPopulation.getId())) {
throw new ServiceException("数据已存在");
}
modelSupplyMonitorIndustryPopulationMapper.update(modelSupplyMonitorIndustryPopulation);
}
@Override
public void delete(Long id) {
if (Objects.isNull(id)) {
throw new ServiceException("id不能为空");
}
modelSupplyMonitorIndustryPopulationMapper.deleteById(id);
}
@Override
public void clear() {
modelSupplyMonitorIndustryPopulationMapper.clear();
}
@Override
public ModelSupplyMonitorIndustryPopulation detail(Long id) {
if (Objects.isNull(id)) {
throw new ServiceException("id不能为空");
}
return modelSupplyMonitorIndustryPopulationMapper.selectById(id);
}
/**
* 查询唯一
*
* @param modelSupplyMonitorIndustryPopulation 劳动力供给分行业劳动力人口
* @return 劳动力供给分行业劳动力人口
*/
private Optional<ModelSupplyMonitorIndustryPopulation> findUnique(ModelSupplyMonitorIndustryPopulation modelSupplyMonitorIndustryPopulation) {
ModelSupplyMonitorIndustryPopulation unique =
modelSupplyMonitorIndustryPopulationMapper.findUnique(modelSupplyMonitorIndustryPopulation);
return Optional.ofNullable(unique);
}
@Override
public List<ModelSupplyMonitorIndustryPopulation> list(ModelSupplyMonitorIndustryPopulation modelSupplyMonitorIndustryPopulation) {
return modelSupplyMonitorIndustryPopulationMapper.list(modelSupplyMonitorIndustryPopulation);
}
@Override
public String importExcel(MultipartFile file) {
try {
ExcelUtil<ModelSupplyMonitorIndustryPopulation> util = new ExcelUtil<>(ModelSupplyMonitorIndustryPopulation.class);
List<ModelSupplyMonitorIndustryPopulation> list = util.importExcel(file.getInputStream());
ModelSupplyMonitorIndustryPopulation exists;
int successNum = 0;
int failureNum = 0;
StringBuilder successMsg = new StringBuilder();
StringBuilder failureMsg = new StringBuilder();
for (ModelSupplyMonitorIndustryPopulation item : list) {
try {
check(item);
exists = modelSupplyMonitorIndustryPopulationMapper.findUnique(item);
if (exists == null) {
BeanValidators.validateWithException(validator, item);
modelSupplyMonitorIndustryPopulationMapper.insert(item);
successNum++;
String msg =
"<br/>" + successNum + "" + "年份:" + item.getYear() + "行业:" + item.getIndustryName() + "数据导入成功。";
successMsg.append(msg);
} else {
item.setId(exists.getId());
BeanValidators.validateWithException(validator, item);
modelSupplyMonitorIndustryPopulationMapper.update(item);
successNum++;
String msg =
"<br/>" + successNum + "" + "年份:" + item.getYear() + "行业:" + item.getIndustryName() + "数据更新成功。";
successMsg.append(msg);
}
} catch (Exception e) {
failureNum++;
String msg = "<br/>" + failureNum + "" + "年份:" + item.getYear() + "行业:" + item.getIndustryName() + "数据导入失败:";
failureMsg.append(msg).append(e.getMessage());
log.error(msg, e);
}
}
if (failureNum > 0) {
failureMsg.insert(0, "导入失败!共 " + failureNum + " 条数据出现问题,错误如下:");
throw new ServiceException(failureMsg.toString());
} else {
successMsg.insert(0, "数据已全部导入成功!共 " + successNum + " 条:");
}
return successMsg.toString();
} catch (Exception e) {
log.error("数据导入失败", e);
throw new ServiceException("数据导入失败");
}
}
@Override
public void exportExcel(HttpServletResponse response, ModelExportParamDto dto) {
try {
List<ModelSupplyMonitorIndustryPopulation> list = list(ModelSupplyMonitorIndustryPopulation.builder()
.year(dto.getYear())
.build());
ExcelUtil<ModelSupplyMonitorIndustryPopulation> util = new ExcelUtil<>(ModelSupplyMonitorIndustryPopulation.class);
util.exportExcel(response, list, ModelTemplateTypeEnum.MODEL_SUPPLY_MONITOR_INDUSTRY_POPULATION.getDesc());
} catch (Exception e) {
log.error("数据导出失败", e);
throw new ServiceException("数据导出失败");
}
}
}

View File

@@ -0,0 +1,82 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.ruoyi.cms.mapper.ModelSupplyMonitorIndustryPopulationMapper">
<insert id="insert" parameterType="com.ruoyi.cms.domain.ModelSupplyMonitorIndustryPopulation">
INSERT INTO model_supply_monitor_industry_population (year, industry_code, industry_name, male_count, female_count)
VALUES (#{year}, #{industryCode}, #{industryName}, #{maleCount}, #{femaleCount})
</insert>
<insert id="update" parameterType="com.ruoyi.cms.domain.ModelSupplyMonitorIndustryPopulation">
UPDATE model_supply_monitor_industry_population
SET year = #{year},
industry_code = #{industryCode},
industry_name = #{industryName},
male_count = #{maleCount},
female_count = #{femaleCount}
WHERE id = #{id}
</insert>
<delete id="deleteById" parameterType="java.lang.Long">
DELETE
FROM model_supply_monitor_industry_population
WHERE id = #{id}
</delete>
<delete id="clear">
DELETE FROM model_supply_monitor_industry_population
WHERE id IS NOT NULL;
</delete>
<select id="selectById" parameterType="java.lang.Long"
resultType="com.ruoyi.cms.domain.ModelSupplyMonitorIndustryPopulation">
SELECT id,
year,
industry_code AS industryCode,
industry_name AS industryName,
male_count AS maleCount,
female_count AS femaleCount
FROM model_supply_monitor_industry_population
WHERE id = #{id}
</select>
<select id="findUnique" parameterType="com.ruoyi.cms.domain.ModelSupplyMonitorIndustryPopulation"
resultType="com.ruoyi.cms.domain.ModelSupplyMonitorIndustryPopulation">
SELECT id,
year,
industry_code AS industryCode,
industry_name AS industryName,
male_count AS maleCount,
female_count AS femaleCount
FROM model_supply_monitor_industry_population
WHERE year = #{year}
AND industry_code = #{industryCode}
</select>
<select id="list" parameterType="com.ruoyi.cms.domain.ModelSupplyMonitorIndustryPopulation"
resultType="com.ruoyi.cms.domain.ModelSupplyMonitorIndustryPopulation">
SELECT id,
year,
industry_code AS industryCode,
industry_name AS industryName,
male_count AS maleCount,
female_count AS femaleCount
FROM model_supply_monitor_industry_population
<where>
<if test="id != null">
AND id = #{id}
</if>
<if test="year != null">
AND year = #{year}
</if>
<if test="industryCode != null and industryCode != ''">
AND industry_code = #{industryCode}
</if>
<if test="industryName != null and industryName != ''">
AND industry_name LIKE '%'||#{industryName}||'%'
</if>
</where>
ORDER BY year DESC
</select>
</mapper>