宿舍专业设置为null,学生、外校的导出数据优化
This commit is contained in:
parent
0b27a5cb42
commit
e0d11a649d
|
@ -189,7 +189,40 @@ public class JeecgController<T, S extends IService<T>> {
|
||||||
String groupName = nameResolverService.getGroupName(groupId);
|
String groupName = nameResolverService.getGroupName(groupId);
|
||||||
groupNameField.set(item, groupName);
|
groupNameField.set(item, groupName);
|
||||||
}
|
}
|
||||||
|
// --- 学科描述映射 --- (新增部分)
|
||||||
|
Field majorIdField = null;
|
||||||
|
Field majorIdDescriptionField = null;
|
||||||
|
try {
|
||||||
|
majorIdField = item.getClass().getDeclaredField("majorId");
|
||||||
|
majorIdDescriptionField = item.getClass().getDeclaredField("majorIdDescription");
|
||||||
|
} catch (NoSuchFieldException e) {
|
||||||
|
// 字段不存在
|
||||||
|
}
|
||||||
|
if (majorIdField != null && majorIdDescriptionField != null) {
|
||||||
|
majorIdField.setAccessible(true);
|
||||||
|
majorIdDescriptionField.setAccessible(true);
|
||||||
|
Integer majorId = (Integer) majorIdField.get(item);
|
||||||
|
// 调用映射方法
|
||||||
|
String majorDescription = mapMajorIdToDescription(majorId);
|
||||||
|
majorIdDescriptionField.set(item, majorDescription);
|
||||||
|
}
|
||||||
|
// --- 是否第一次阅卷 --- (新增部分)
|
||||||
|
Field checkedField = null;
|
||||||
|
Field checkedDescriptionField = null;
|
||||||
|
try {
|
||||||
|
checkedField = item.getClass().getDeclaredField("checked");
|
||||||
|
checkedDescriptionField = item.getClass().getDeclaredField("checkedDescription");
|
||||||
|
} catch (NoSuchFieldException e) {
|
||||||
|
// 字段不存在
|
||||||
|
}
|
||||||
|
if (checkedField != null && checkedDescriptionField != null) {
|
||||||
|
checkedField.setAccessible(true);
|
||||||
|
checkedDescriptionField.setAccessible(true);
|
||||||
|
Integer checked = (Integer) checkedField.get(item);
|
||||||
|
// 调用映射方法
|
||||||
|
String checkedDescription = StatusMappingUtil.mapChecked(checked);
|
||||||
|
checkedDescriptionField.set(item, checkedDescription);
|
||||||
|
}
|
||||||
} catch (IllegalAccessException e) {
|
} catch (IllegalAccessException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
|
@ -380,18 +413,24 @@ public class JeecgController<T, S extends IService<T>> {
|
||||||
|
|
||||||
// ===== 状态描述反向映射 =====
|
// ===== 状态描述反向映射 =====
|
||||||
|
|
||||||
// 性别反向映射
|
// // 性别反向映射
|
||||||
applyReverseMapping(item, "sexDescription", "sex", StatusMappingUtil::reverseMapSex);
|
// applyReverseMapping(item, "sexDescription", "sex", StatusMappingUtil::reverseMapSex);
|
||||||
|
//
|
||||||
|
// // 车辆状态反向映射
|
||||||
|
// applyReverseMapping(item, "carStatusDescription", "carStatus", StatusMappingUtil::reverseMapCarStatus);
|
||||||
|
//
|
||||||
|
// // 住宿状态反向映射
|
||||||
|
// applyReverseMapping(item, "dormitoryStatusDescription", "dormitoryStatus", StatusMappingUtil::reverseMapDormitoryStatus);
|
||||||
|
//
|
||||||
|
// // 一般状态反向映射
|
||||||
|
// applyReverseMapping(item, "statusDescription", "status", StatusMappingUtil::reverseMapStatus);
|
||||||
|
|
||||||
// 车辆状态反向映射
|
|
||||||
applyReverseMapping(item, "carStatusDescription", "carStatus", StatusMappingUtil::reverseMapCarStatus);
|
|
||||||
|
|
||||||
// 住宿状态反向映射
|
|
||||||
applyReverseMapping(item, "dormitoryStatusDescription", "dormitoryStatus", StatusMappingUtil::reverseMapDormitoryStatus);
|
|
||||||
|
|
||||||
// 一般状态反向映射
|
|
||||||
applyReverseMapping(item, "statusDescription", "status", StatusMappingUtil::reverseMapStatus);
|
|
||||||
|
|
||||||
|
// ===== 状态描述反向映射(带存在性判断) =====
|
||||||
|
applyReverseMappingIfExists(item, "sexDescription", "sex", s -> String.valueOf(StatusMappingUtil.reverseMapSex(s)));
|
||||||
|
applyReverseMappingIfExists(item, "carStatusDescription", "carStatus", s -> String.valueOf(StatusMappingUtil.reverseMapCarStatus(s)));
|
||||||
|
applyReverseMappingIfExists(item, "dormitoryStatusDescription", "dormitoryStatus", s -> String.valueOf(StatusMappingUtil.reverseMapDormitoryStatus(s)));
|
||||||
|
applyReverseMappingIfExists(item, "statusDescription", "status", s -> String.valueOf(StatusMappingUtil.reverseMapStatus(s)));
|
||||||
// 宿舍名称反查 ID
|
// 宿舍名称反查 ID
|
||||||
// Field dormNameField = getField(item, "dormitoryName");
|
// Field dormNameField = getField(item, "dormitoryName");
|
||||||
// Field dormIdField = getField(item, "dormitoryId");
|
// Field dormIdField = getField(item, "dormitoryId");
|
||||||
|
@ -450,17 +489,46 @@ public class JeecgController<T, S extends IService<T>> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void applyReverseMapping(Object item, String descFieldName, String codeFieldName, Function<String, Integer> mapper) throws IllegalAccessException {
|
// private void applyReverseMapping(Object item, String descFieldName, String codeFieldName, Function<String, Integer> mapper) throws IllegalAccessException {
|
||||||
Field descField = getField(item, descFieldName);
|
// Field descField = getField(item, descFieldName);
|
||||||
Field codeField = getField(item, codeFieldName);
|
// Field codeField = getField(item, codeFieldName);
|
||||||
if (descField != null && codeField != null) {
|
// if (descField != null && codeField != null) {
|
||||||
String desc = (String) descField.get(item);
|
// String desc = (String) descField.get(item);
|
||||||
if (desc != null && !desc.isEmpty()) {
|
// if (desc != null && !desc.isEmpty()) {
|
||||||
Integer code = mapper.apply(desc);
|
// Integer code = mapper.apply(desc);
|
||||||
codeField.set(item, code);
|
// codeField.set(item, code);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
private void applyReverseMappingIfExists(T item, String fromField, String toField, Function<String, String> mappingFunc) {
|
||||||
|
try {
|
||||||
|
Field descField = getField(item, fromField);
|
||||||
|
Field targetField = getField(item, toField);
|
||||||
|
if (descField != null && targetField != null) {
|
||||||
|
descField.setAccessible(true);
|
||||||
|
targetField.setAccessible(true);
|
||||||
|
Object rawValue = descField.get(item);
|
||||||
|
if (rawValue instanceof String && rawValue != null) {
|
||||||
|
String mapped = mappingFunc.apply((String) rawValue);
|
||||||
|
targetField.set(item, mapped);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.warn("映射字段失败: " + fromField + " → " + toField, e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 新增的映射方法(可放在工具类中)
|
||||||
|
private static String mapMajorIdToDescription(Integer majorId) {
|
||||||
|
if (majorId == null) return "";
|
||||||
|
|
||||||
|
switch (majorId) {
|
||||||
|
case 1: return "语文";
|
||||||
|
case 4: return "地理";
|
||||||
|
case 7: return "历史";
|
||||||
|
case 8: return "政治";
|
||||||
|
// 添加其他学科的映射关系
|
||||||
|
default: return "";
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,6 +20,11 @@ public class StatusMappingUtil {
|
||||||
return dormitoryStatus == 1 ? "是" : "否";
|
return dormitoryStatus == 1 ? "是" : "否";
|
||||||
}
|
}
|
||||||
// 住宿状态映射
|
// 住宿状态映射
|
||||||
|
public static String mapChecked(Integer checked) {
|
||||||
|
if (checked == null) return "未知";
|
||||||
|
return checked == 1 ? "是" : "否";
|
||||||
|
}
|
||||||
|
// 住宿状态映射
|
||||||
public static String mapStatus(Integer status) {
|
public static String mapStatus(Integer status) {
|
||||||
if (status == null) return "";
|
if (status == null) return "";
|
||||||
return status == 0 ? "已报到" : "未报到";
|
return status == 0 ? "已报到" : "未报到";
|
||||||
|
|
|
@ -78,6 +78,18 @@ public class CeesDormitoryInfoController extends JeecgController<CeesDormitoryIn
|
||||||
@ApiOperation(value="宿舍信息表-添加", notes="宿舍信息表-添加")
|
@ApiOperation(value="宿舍信息表-添加", notes="宿舍信息表-添加")
|
||||||
@PostMapping(value = "/add")
|
@PostMapping(value = "/add")
|
||||||
public Result<String> add(@RequestBody CeesDormitoryInfo ceesDormitoryInfo) {
|
public Result<String> add(@RequestBody CeesDormitoryInfo ceesDormitoryInfo) {
|
||||||
|
String dormitory = ceesDormitoryInfo.getDormitory();
|
||||||
|
|
||||||
|
if (dormitory != null && dormitory.contains("公寓")) {
|
||||||
|
int index = dormitory.indexOf("公寓");
|
||||||
|
// 截取“公寓”前面的楼名 + “公寓”
|
||||||
|
String apartment = dormitory.substring(0, index + 2);
|
||||||
|
// 截取“公寓”后面的房间号
|
||||||
|
String dormitoryRoom = dormitory.substring(index + 2);
|
||||||
|
|
||||||
|
ceesDormitoryInfo.setApartment(apartment);
|
||||||
|
ceesDormitoryInfo.setDormitoryRoom(dormitoryRoom);
|
||||||
|
}
|
||||||
ceesDormitoryInfoService.save(ceesDormitoryInfo);
|
ceesDormitoryInfoService.save(ceesDormitoryInfo);
|
||||||
return Result.OK("添加成功!");
|
return Result.OK("添加成功!");
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,6 @@
|
||||||
package org.jeecg.modules.entity;
|
package org.jeecg.modules.entity;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.annotation.IdType;
|
import com.baomidou.mybatisplus.annotation.*;
|
||||||
import com.baomidou.mybatisplus.annotation.TableField;
|
|
||||||
import com.baomidou.mybatisplus.annotation.TableId;
|
|
||||||
import com.baomidou.mybatisplus.annotation.TableName;
|
|
||||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||||
import io.swagger.annotations.ApiModel;
|
import io.swagger.annotations.ApiModel;
|
||||||
import io.swagger.annotations.ApiModelProperty;
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
|
@ -57,6 +54,12 @@ public class CeesDormitoryInfo implements Serializable {
|
||||||
@Excel(name = "宿舍信息", width = 15)
|
@Excel(name = "宿舍信息", width = 15)
|
||||||
@ApiModelProperty(value = "宿舍信息")
|
@ApiModelProperty(value = "宿舍信息")
|
||||||
private String dormitory;
|
private String dormitory;
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "公寓信息")
|
||||||
|
private String apartment;
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "宿舍信息")
|
||||||
|
private String dormitoryRoom;
|
||||||
/**男/女*/
|
/**男/女*/
|
||||||
@Excel(name = "男/女", width = 15)
|
@Excel(name = "男/女", width = 15)
|
||||||
@ApiModelProperty(value = "男/女")
|
@ApiModelProperty(value = "男/女")
|
||||||
|
@ -72,6 +75,7 @@ public class CeesDormitoryInfo implements Serializable {
|
||||||
/**
|
/**
|
||||||
*该宿舍所属学科
|
*该宿舍所属学科
|
||||||
*/
|
*/
|
||||||
|
@TableField(updateStrategy = FieldStrategy.IGNORED)
|
||||||
@ApiModelProperty(value = "学科id")
|
@ApiModelProperty(value = "学科id")
|
||||||
private Integer majorId;
|
private Integer majorId;
|
||||||
/**专业id*/
|
/**专业id*/
|
||||||
|
|
|
@ -107,8 +107,12 @@ public class CeesLocalTeacher implements Serializable {
|
||||||
@ApiModelProperty(value = "状态:0正常 1禁用")
|
@ApiModelProperty(value = "状态:0正常 1禁用")
|
||||||
private Integer status;
|
private Integer status;
|
||||||
/**是否第一次阅卷*/
|
/**是否第一次阅卷*/
|
||||||
@Excel(name = "是否第一次阅卷", width = 15)
|
// @Excel(name = "是否第一次阅卷", width = 15)
|
||||||
@ApiModelProperty(value = "是否第一次阅卷")
|
@ApiModelProperty(value = "是否第一次阅卷")
|
||||||
private Integer checked;
|
private Integer checked;
|
||||||
|
@Excel(name = "是否第一次阅卷", width = 15)
|
||||||
|
@ApiModelProperty(value = "是否第一次阅卷")
|
||||||
|
@TableField(exist = false)
|
||||||
|
private String checkedDescription;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -91,9 +91,13 @@ public class Student implements Serializable {
|
||||||
@ApiModelProperty(value = "手机号")
|
@ApiModelProperty(value = "手机号")
|
||||||
private String phone;
|
private String phone;
|
||||||
/**是否第一次阅卷*/
|
/**是否第一次阅卷*/
|
||||||
@Excel(name = "是否第一次阅卷", width = 15)
|
// @Excel(name = "是否第一次阅卷", width = 15)
|
||||||
@ApiModelProperty(value = "是否第一次阅卷")
|
@ApiModelProperty(value = "是否第一次阅卷")
|
||||||
private Integer checked;
|
private Integer checked;
|
||||||
|
@Excel(name = "是否第一次阅卷", width = 15)
|
||||||
|
@ApiModelProperty(value = "是否第一次阅卷")
|
||||||
|
@TableField(exist = false)
|
||||||
|
private String checkedDescription;
|
||||||
/**组id*/
|
/**组id*/
|
||||||
// @Excel(name = "组id", width = 15)
|
// @Excel(name = "组id", width = 15)
|
||||||
@ApiModelProperty(value = "组id")
|
@ApiModelProperty(value = "组id")
|
||||||
|
|
|
@ -109,15 +109,14 @@ public class CeesDormitoryInfoServiceImpl extends ServiceImpl<CeesDormitoryInfoM
|
||||||
}
|
}
|
||||||
// 2. 解析学科ID
|
// 2. 解析学科ID
|
||||||
Object majorIdObj = webData.get("majorId");
|
Object majorIdObj = webData.get("majorId");
|
||||||
if (majorIdObj == null) {
|
Integer majorId = null;
|
||||||
return Result.error("缺少学科ID");
|
if (majorIdObj != null && !"".equals(majorIdObj.toString())) {
|
||||||
}
|
|
||||||
Integer majorId;
|
|
||||||
try {
|
try {
|
||||||
majorId = Integer.valueOf(majorIdObj.toString());
|
majorId = Integer.valueOf(majorIdObj.toString());
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
return Result.error("学科ID格式错误");
|
return Result.error("学科ID格式错误");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
// 3. 批量更新
|
// 3. 批量更新
|
||||||
UpdateWrapper<CeesDormitoryInfo> updateWrapper = new UpdateWrapper<>();
|
UpdateWrapper<CeesDormitoryInfo> updateWrapper = new UpdateWrapper<>();
|
||||||
updateWrapper.in("id", userIds);
|
updateWrapper.in("id", userIds);
|
||||||
|
@ -150,4 +149,44 @@ public class CeesDormitoryInfoServiceImpl extends ServiceImpl<CeesDormitoryInfoM
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 提取公寓信息的方法
|
||||||
|
private String extractApartmentInfo(String fullDormitory) {
|
||||||
|
if (fullDormitory == null || fullDormitory.isEmpty()) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
// 使用正则表达式匹配"数字+公寓"的模式
|
||||||
|
java.util.regex.Matcher matcher = java.util.regex.Pattern.compile("\\d+公寓")
|
||||||
|
.matcher(fullDormitory);
|
||||||
|
|
||||||
|
if (matcher.find()) {
|
||||||
|
return matcher.group();
|
||||||
|
}
|
||||||
|
|
||||||
|
// 如果匹配失败,尝试匹配不带数字的公寓
|
||||||
|
if (fullDormitory.contains("公寓")) {
|
||||||
|
return fullDormitory.substring(0, fullDormitory.indexOf("公寓") + 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
return fullDormitory;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 提取宿舍房间信息的方法
|
||||||
|
private String extractDormitoryRoom(String fullDormitory, String apartment) {
|
||||||
|
if (fullDormitory == null || fullDormitory.isEmpty()) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
// 如果有公寓信息,则去掉公寓部分
|
||||||
|
if (apartment != null && !apartment.isEmpty()) {
|
||||||
|
// 确保公寓信息是以中文"公寓"结尾
|
||||||
|
if (apartment.endsWith("公寓")) {
|
||||||
|
return fullDormitory.replaceFirst(apartment, "").trim();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 如果没有公寓信息或公寓信息格式不正确,返回原字符串
|
||||||
|
return fullDormitory;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -125,6 +125,7 @@ public class CeesWaiTeacherServiceImpl extends ServiceImpl<CeesWaiTeacherMapper,
|
||||||
String dormitoryName = req.getParameter("dormitoryName");
|
String dormitoryName = req.getParameter("dormitoryName");
|
||||||
String groupName = req.getParameter("groupName");
|
String groupName = req.getParameter("groupName");
|
||||||
QueryWrapper<CeesWaiTeacher> queryWrapper = QueryGenerator.initQueryWrapper(ceesWaiTeacher, req.getParameterMap());
|
QueryWrapper<CeesWaiTeacher> queryWrapper = QueryGenerator.initQueryWrapper(ceesWaiTeacher, req.getParameterMap());
|
||||||
|
|
||||||
// 3. 处理 dormitoryName 模糊查询逻辑
|
// 3. 处理 dormitoryName 模糊查询逻辑
|
||||||
if (StringUtils.isNotBlank(dormitoryName)) {
|
if (StringUtils.isNotBlank(dormitoryName)) {
|
||||||
// 3.1 先查询匹配的宿舍ID列表
|
// 3.1 先查询匹配的宿舍ID列表
|
||||||
|
@ -140,7 +141,8 @@ public class CeesWaiTeacherServiceImpl extends ServiceImpl<CeesWaiTeacherMapper,
|
||||||
queryWrapper.in("dormitory_id", dormitoryIds);
|
queryWrapper.in("dormitory_id", dormitoryIds);
|
||||||
} else {
|
} else {
|
||||||
// 无匹配宿舍时返回空结果
|
// 无匹配宿舍时返回空结果
|
||||||
queryWrapper.isNull("dormitory_id"); // 或 .eq("1", "0")
|
// 使用一个不可能满足的条件来返回空结果
|
||||||
|
queryWrapper.in("dormitory_id", "impossible_id_" + UUID.randomUUID());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// 3. 处理 groupName 模糊查询
|
// 3. 处理 groupName 模糊查询
|
||||||
|
@ -155,7 +157,9 @@ public class CeesWaiTeacherServiceImpl extends ServiceImpl<CeesWaiTeacherMapper,
|
||||||
if (!groupIds.isEmpty()) {
|
if (!groupIds.isEmpty()) {
|
||||||
queryWrapper.in("group_id", groupIds);
|
queryWrapper.in("group_id", groupIds);
|
||||||
} else {
|
} else {
|
||||||
queryWrapper.isNull("group_id");
|
// 没有匹配的宿舍,设置永假条件返回空结果
|
||||||
|
// 使用一个不可能满足的条件来返回空结果
|
||||||
|
queryWrapper.in("group_id", "impossible_id_" + UUID.randomUUID());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue