入伍保留学籍-批量插入(辅导员批量申请)

This commit is contained in:
2026-03-20 15:20:24 +08:00
parent 2c591aa557
commit 1b9ffef757
5 changed files with 220 additions and 5 deletions

View File

@@ -156,6 +156,34 @@ public class RtEnlistmentReserveController extends BaseController {
return success(rtEnlistmentReserveService.insertRtEnlistmentReserve(rtEnlistmentReserve)); return success(rtEnlistmentReserveService.insertRtEnlistmentReserve(rtEnlistmentReserve));
} }
/**
* 批量插入应征入伍预约信息
* @param list 预约信息列表
* @return 插入结果
*/
@PreAuthorize("@ss.hasPermi('routine:enlistmentReserve:add')")
@Log(title = "应征入伍保留学籍申请", businessType = BusinessType.INSERT)
@PostMapping("/batchInsert")
@ApiOperation("新增应征入伍保留学籍申请")
public AjaxResult batchInsert(@RequestBody List<RtEnlistmentReserve> list) {
try {
// 调用批量插入方法
int insertCount = rtEnlistmentReserveService.batchInsertRtEnlistmentReserve(list);
// 若依框架成功返回(带数据)
return AjaxResult.success("批量插入成功,共插入" + insertCount + "条数据", insertCount);
} catch (IllegalArgumentException e) {
// 入参无效异常(如姓名/学号为空)
return AjaxResult.error(e.getMessage());
} catch (RuntimeException e) {
// 重复数据异常
return AjaxResult.error(e.getMessage());
} catch (Exception e) {
// 其他未知异常(若依框架建议记录日志)
logger.error("批量插入应征入伍预约信息失败", e); // 继承BaseController自带logger
return AjaxResult.error("批量插入失败:" + e.getMessage());
}
}
/** /**
* 修改应征入伍保留学籍申请 * 修改应征入伍保留学籍申请
*/ */

View File

@@ -63,6 +63,20 @@ public interface RtEnlistmentReserveMapper extends BaseMapper<RtEnlistmentReserv
@Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id") @Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id")
int insertRtEnlistmentReserve(RtEnlistmentReserve rtEnlistmentReserve); int insertRtEnlistmentReserve(RtEnlistmentReserve rtEnlistmentReserve);
/**
* 批量插入应征入伍预约信息
* @param list 应征入伍预约信息列表
* @return 插入成功的记录数
*/
int batchInsertRtEnlistmentReserve(List<RtEnlistmentReserve> list);
/**
* 查询数据库中已存在的学生(姓名+学号拼接)
* @param list 待插入的学生列表
* @return 已存在的学生标识格式姓名_学号
*/
List<String> selectExistStudents(List<RtEnlistmentReserve> list);
/** /**
* Mapper接口方法统计指定年份的保留学籍记录数 * Mapper接口方法统计指定年份的保留学籍记录数
* @param year 年份如2026 * @param year 年份如2026

View File

@@ -45,6 +45,13 @@ public interface IRtEnlistmentReserveService extends IService<RtEnlistmentReserv
*/ */
RtEnlistmentReserve insertRtEnlistmentReserve(RtEnlistmentReserve rtEnlistmentReserve); RtEnlistmentReserve insertRtEnlistmentReserve(RtEnlistmentReserve rtEnlistmentReserve);
/**
* 批量插入应征入伍预约信息
* @param list 应征入伍预约信息列表
* @return 插入成功的记录数
*/
int batchInsertRtEnlistmentReserve(List<RtEnlistmentReserve> list);
/** /**
* 修改应征入伍保留学籍申请 * 修改应征入伍保留学籍申请
* *

View File

@@ -1,11 +1,10 @@
package com.srs.routine.service.impl; package com.srs.routine.service.impl;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.Date; import java.util.*;
import java.util.HashMap; import java.util.stream.Collectors;
import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.srs.common.core.domain.AjaxResult; import com.srs.common.core.domain.AjaxResult;
import com.srs.common.core.domain.entity.SysUser; import com.srs.common.core.domain.entity.SysUser;
import com.srs.common.doman.dto.ProcessResultDto; import com.srs.common.doman.dto.ProcessResultDto;
@@ -177,6 +176,101 @@ public class RtEnlistmentReserveServiceImpl extends ServiceImpl<RtEnlistmentRese
return rtEnlistmentReserve; return rtEnlistmentReserve;
} }
@Override
public int batchInsertRtEnlistmentReserve(List<RtEnlistmentReserve> list) {
// 1. 校验入参是否为空
if (CollectionUtils.isEmpty(list)) {
return 0;
}
// 2. 过滤掉姓名或学号为空的数据(避免拼接异常)
List<RtEnlistmentReserve> validList = list.stream()
.filter(item -> item.getStudentName() != null && !item.getStudentName().isEmpty()
&& item.getStudentNo() != null && !item.getStudentNo().isEmpty())
.collect(Collectors.toList());
if (CollectionUtils.isEmpty(validList)) {
throw new IllegalArgumentException("待插入数据中无有效学生信息(姓名/学号为空)");
}
// 3. 查询数据库中已存在的学生姓名_学号
List<String> existStudentKeys = rtEnlistmentReserveMapper.selectExistStudents(validList);
Set<String> existStudentKeySet = new HashSet<>(existStudentKeys);
// 4. 拆分重复数据和待插入数据
List<RtEnlistmentReserve> duplicateList = validList.stream()
.filter(item -> existStudentKeySet.contains(item.getStudentName() + "_" + item.getStudentNo()))
.collect(Collectors.toList());
List<RtEnlistmentReserve> insertList = validList.stream()
.filter(item -> !existStudentKeySet.contains(item.getStudentName() + "_" + item.getStudentNo()))
.collect(Collectors.toList());
// 5. 存在重复数据则抛出异常提示
if (!CollectionUtils.isEmpty(duplicateList)) {
String duplicateMsg = duplicateList.stream()
.map(item -> "学生姓名:" + item.getStudentName() + ",学号:" + item.getStudentNo())
.collect(Collectors.joining(""));
throw new RuntimeException("存在重复数据,不执行申请:" + duplicateMsg);
}
// 6. 无重复数据时为每条待插入数据生成唯一的reserveNo核心新增逻辑
if (!CollectionUtils.isEmpty(insertList)) {
// ========== 生成保留学籍编号(适配批量场景) ==========
// 6.1 获取当前系统年份(用于编号和序号重置判断)
SimpleDateFormat yearSdf = new SimpleDateFormat("yyyy");
String currentYear = yearSdf.format(new Date()); // 如2026
// 6.2 查询「当前年份」的记录总数(按年份分组统计,实现每年序号重置)
// 统计rt_enlistment_reserve表中reserve_no以"BLXJ("+currentYear+")"开头的记录数
int yearTotal = rtEnlistmentReserveMapper.countByYear(currentYear);
// ========== 保留学籍开始和结束日期生成核心逻辑 ==========
Calendar calendar = Calendar.getInstance();
int currentMonth = calendar.get(Calendar.MONTH) + 1; // 月份从0开始+1转为实际月份1-12
// 6.3 为批量数据逐个生成递增的reserveNo
for (int i = 0; i < insertList.size(); i++) {
RtEnlistmentReserve item = insertList.get(i);
// 计算当前条目的序号(年份总数 + 1 + 循环索引,保证批量递增)
int seq = yearTotal + 1 + i;
// 补零为4位0001、0002...9999
String seqStr = String.format("%04d", seq);
// 拼接最终编号BLXJ(年份)序号
String reserveNo = "BLXJ(" + currentYear + ")" + seqStr;
// 设置到当前实体对象中
item.setReserveNo(reserveNo);
// ========== 保留学籍开始和结束日期生成核心逻辑 ==========
// --- 生成reserveStartDate按学期判断 ---
// 重置Calendar为当前年份的起始
calendar.clear();
calendar.set(Calendar.YEAR, Integer.parseInt(currentYear));
// 判断学期春季1-6月→3月1日秋季7-12月→9月1日
if (currentMonth >= 1 && currentMonth <= 6) {
calendar.set(Calendar.MONTH, Calendar.MARCH); // 3月Calendar中3月是2这里直接用常量更清晰
} else {
calendar.set(Calendar.MONTH, Calendar.SEPTEMBER); // 9月
}
calendar.set(Calendar.DAY_OF_MONTH, 1); // 1日
Date reserveStartDate = calendar.getTime();
item.setReserveStartDate(reserveStartDate);
// --- 生成reserveEndDatestartDate加2年 ---
Calendar endCalendar = (Calendar) calendar.clone(); // 克隆避免影响原日期
endCalendar.add(Calendar.YEAR, 2); // 加2年
Date reserveEndDate = endCalendar.getTime();
item.setReserveEndDate(reserveEndDate);
}
}
// 7. 执行批量插入
if (CollectionUtils.isEmpty(insertList)) {
return 0;
}
return rtEnlistmentReserveMapper.batchInsertRtEnlistmentReserve(insertList);
}
/** /**
* 修改应征入伍保留学籍申请 * 修改应征入伍保留学籍申请
* *
@@ -250,7 +344,7 @@ public class RtEnlistmentReserveServiceImpl extends ServiceImpl<RtEnlistmentRese
Long applyStatus = rtEnlistmentReserve.getApplyStatus(); Long applyStatus = rtEnlistmentReserve.getApplyStatus();
if (1L == applyStatus) { if (1L == applyStatus) {
// 绑定当前学生ID启动流程 // 绑定当前学生ID启动流程
rtEnlistmentReserve.setStudentId(SecurityUtils.getUserId()); // rtEnlistmentReserve.setStudentId(SecurityUtils.getUserId());
ProcessResultDto processResultDto = startEnlistmentReserveProcess(rtEnlistmentReserve); ProcessResultDto processResultDto = startEnlistmentReserveProcess(rtEnlistmentReserve);
if (processResultDto == null || StringUtils.isBlank(processResultDto.getProcessInstanceId())) { if (processResultDto == null || StringUtils.isBlank(processResultDto.getProcessInstanceId())) {
throw new ServiceException("流程启动失败,请重试", 500); throw new ServiceException("流程启动失败,请重试", 500);

View File

@@ -216,6 +216,16 @@
WHERE a.stu_no = #{stuNo} WHERE a.stu_no = #{stuNo}
</select> </select>
<!-- 查询数据库中已存在的学生(按姓名+学号) -->
<select id="selectExistStudents" parameterType="java.util.List" resultType="java.lang.String">
SELECT CONCAT(student_name, '_', student_no)
FROM rt_enlistment_reserve
WHERE CONCAT(student_name, '_', student_no) IN
<foreach collection="list" item="item" open="(" separator="," close=")">
CONCAT(#{item.studentName}, '_', #{item.studentNo})
</foreach>
</select>
<insert id="insertRtEnlistmentReserve" parameterType="RtEnlistmentReserve" useGeneratedKeys="true" keyProperty="id"> <insert id="insertRtEnlistmentReserve" parameterType="RtEnlistmentReserve" useGeneratedKeys="true" keyProperty="id">
insert into rt_enlistment_reserve insert into rt_enlistment_reserve
<trim prefix="(" suffix=")" suffixOverrides=","> <trim prefix="(" suffix=")" suffixOverrides=",">
@@ -272,6 +282,68 @@
</trim> </trim>
</insert> </insert>
<!-- 批量插入 -->
<insert id="batchInsertRtEnlistmentReserve" parameterType="java.util.List" useGeneratedKeys="true" keyProperty="id">
insert into rt_enlistment_reserve
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="list != null and list.size() > 0">
<if test="list[0].applyNo != null and list[0].applyNo != ''">apply_no,</if>
<if test="list[0].studentId != null">student_id,</if>
<if test="list[0].teacherName != null and list[0].teacherName != ''">teacher_name,</if>
<if test="list[0].studentName != null and list[0].studentName != ''">student_name,</if>
<if test="list[0].gender != null and list[0].gender != ''">gender,</if>
<if test="list[0].nation != null and list[0].nation != ''">nation,</if>
<if test="list[0].grade != null and list[0].grade != ''">grade,</if>
<if test="list[0].studentNo != null and list[0].studentNo != ''">student_no,</if>
<if test="list[0].className != null and list[0].className != ''">class_name,</if>
<if test="list[0].major != null and list[0].major != ''">major,</if>
<if test="list[0].familyAddress != null and list[0].familyAddress != ''">family_address,</if>
<if test="list[0].parentPhone != null and list[0].parentPhone != ''">parent_phone,</if>
<if test="list[0].applyReason != null and list[0].applyReason != ''">apply_reason,</if>
<if test="list[0].applyStatus != null">apply_status,</if>
<if test="list[0].processInstanceId != null">process_instance_id,</if>
<if test="list[0].reserveNo != null">reserve_no,</if>
<if test="list[0].reserveStartDate != null">reserve_start_date,</if>
<if test="list[0].reserveEndDate != null">reserve_end_date,</if>
<if test="list[0].approvalNo != null">approval_no,</if>
<if test="list[0].createTime != null">create_time,</if>
<if test="list[0].updateTime != null">update_time,</if>
<if test="list[0].affixId != null">affix_id,</if>
<if test="list[0].deployId != null">deploy_id,</if>
<if test="list[0].deptName != null">dept_name,</if>
</if>
</trim>
values
<foreach collection="list" item="item" separator=",">
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="item.applyNo != null and item.applyNo != ''">#{item.applyNo},</if>
<if test="item.studentId != null">#{item.studentId},</if>
<if test="item.teacherName != null and item.teacherName != ''">#{item.teacherName},</if>
<if test="item.studentName != null and item.studentName != ''">#{item.studentName},</if>
<if test="item.gender != null and item.gender != ''">#{item.gender},</if>
<if test="item.nation != null and item.nation != ''">#{item.nation},</if>
<if test="item.grade != null and item.grade != ''">#{item.grade},</if>
<if test="item.studentNo != null and item.studentNo != ''">#{item.studentNo},</if>
<if test="item.className != null and item.className != ''">#{item.className},</if>
<if test="item.major != null and item.major != ''">#{item.major},</if>
<if test="item.familyAddress != null and item.familyAddress != ''">#{item.familyAddress},</if>
<if test="item.parentPhone != null and item.parentPhone != ''">#{item.parentPhone},</if>
<if test="item.applyReason != null and item.applyReason != ''">#{item.applyReason},</if>
<if test="item.applyStatus != null">#{item.applyStatus},</if>
<if test="item.processInstanceId != null">#{item.processInstanceId},</if>
<if test="item.reserveNo != null">#{item.reserveNo},</if>
<if test="item.reserveStartDate != null">#{item.reserveStartDate},</if>
<if test="item.reserveEndDate != null">#{item.reserveEndDate},</if>
<if test="item.approvalNo != null">#{item.approvalNo},</if>
<if test="item.createTime != null">#{item.createTime},</if>
<if test="item.updateTime != null">#{item.updateTime},</if>
<if test="item.affixId != null">#{item.affixId},</if>
<if test="item.deployId != null">#{item.deployId},</if>
<if test="item.deptName != null">#{item.deptName},</if>
</trim>
</foreach>
</insert>
<update id="updateRtEnlistmentReserve" parameterType="RtEnlistmentReserve"> <update id="updateRtEnlistmentReserve" parameterType="RtEnlistmentReserve">
update rt_enlistment_reserve update rt_enlistment_reserve
<trim prefix="SET" suffixOverrides=","> <trim prefix="SET" suffixOverrides=",">