zlwu 1 سال پیش
والد
کامیت
714f0f97e8

+ 10 - 1
backend/ruoyi-modules/ruoyi-xg/src/main/java/org/dromara/xg/controller/XgDormViolationController.java

@@ -1,5 +1,6 @@
 package org.dromara.xg.controller;
 
+import java.util.ArrayList;
 import java.util.List;
 
 import lombok.RequiredArgsConstructor;
@@ -7,6 +8,7 @@ import jakarta.servlet.http.HttpServletResponse;
 import jakarta.validation.constraints.*;
 import cn.dev33.satoken.annotation.SaCheckPermission;
 import org.springframework.web.bind.annotation.*;
+import org.springframework.beans.BeanUtils;
 import org.springframework.validation.annotation.Validated;
 import org.dromara.common.idempotent.annotation.RepeatSubmit;
 import org.dromara.common.log.annotation.Log;
@@ -20,6 +22,7 @@ import org.dromara.common.excel.utils.ExcelUtil;
 import org.dromara.xg.domain.vo.XgDormViolationVo;
 import org.dromara.xg.domain.bo.XgDormViolationBo;
 import org.dromara.xg.domain.vo.StudentOptionVo;
+import org.dromara.xg.domain.vo.XgDormViolationExportVo;
 import org.dromara.xg.domain.bo.StudentOptionBo;
 import org.dromara.xg.service.IXgDormViolationService;
 import org.dromara.common.mybatis.core.page.TableDataInfo;
@@ -55,7 +58,13 @@ public class XgDormViolationController extends BaseController {
     @PostMapping("/export")
     public void export(XgDormViolationBo bo, HttpServletResponse response) {
         List<XgDormViolationVo> list = xgDormViolationService.queryList(bo);
-        ExcelUtil.exportExcel(list, "宿舍违纪记录", XgDormViolationVo.class, response);
+        List<XgDormViolationExportVo> exportList = new ArrayList<XgDormViolationExportVo>();
+        for (XgDormViolationVo vo : list) {
+            XgDormViolationExportVo exportVo = new XgDormViolationExportVo();
+            BeanUtils.copyProperties(vo, exportVo);
+            exportList.add(exportVo);
+        }
+        ExcelUtil.exportExcel(exportList, "宿舍违纪记录", XgDormViolationExportVo.class, response);
     }
 
     /**

+ 138 - 0
backend/ruoyi-modules/ruoyi-xg/src/main/java/org/dromara/xg/convert/StudentInfoExcelConvert.java

@@ -0,0 +1,138 @@
+package org.dromara.xg.convert;
+
+import cn.hutool.core.util.StrUtil;
+import cn.idev.excel.converters.Converter;
+import cn.idev.excel.enums.CellDataTypeEnum;
+import cn.idev.excel.metadata.GlobalConfiguration;
+import cn.idev.excel.metadata.data.ReadCellData;
+import cn.idev.excel.metadata.data.WriteCellData;
+import cn.idev.excel.metadata.property.ExcelContentProperty;
+import org.dromara.common.core.utils.SpringUtils;
+import org.dromara.xg.domain.vo.StudentOptionVo;
+import org.dromara.xg.service.IXgDormViolationService;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.Arrays;
+import java.util.List;
+import java.util.stream.Collectors;
+
+/**
+ * 学生信息Excel转换器
+ * 将学生ID转换为学生详细信息(学号、姓名、学院名称、专业名称、班级名称)
+ *
+ * @author zlwu
+ * @date 2025-01-03
+ */
+public class StudentInfoExcelConvert implements Converter<String> {
+
+    private static final Logger log = LoggerFactory.getLogger(StudentInfoExcelConvert.class);
+
+    @Override
+    public Class<String> supportJavaTypeKey() {
+        return String.class;
+    }
+
+    @Override
+    public CellDataTypeEnum supportExcelTypeKey() {
+        return CellDataTypeEnum.STRING;
+    }
+
+    @Override
+    public String convertToJavaData(ReadCellData<?> cellData, ExcelContentProperty contentProperty,
+            GlobalConfiguration globalConfiguration) {
+        String value = cellData.getStringValue();
+        if (StrUtil.isBlank(value)) {
+            return "";
+        }
+
+        try {
+            // 获取服务实例
+            IXgDormViolationService dormViolationService = SpringUtils.getBean(IXgDormViolationService.class);
+            if (dormViolationService == null) {
+                log.warn("无法获取宿舍违纪服务实例,返回原始值");
+                return value;
+            }
+
+            // 分割学号(逗号分隔)
+            String[] studentNoArray = value.split(",");
+            List<String> studentIdList = Arrays.stream(studentNoArray)
+                    .map(String::trim)
+                    .filter(StrUtil::isNotBlank)
+                    .map(studentNo -> {
+                        try {
+                            StudentOptionVo student = dormViolationService.getStudentByStudentNo(studentNo);
+                            if (student != null) {
+                                return student.getId().toString();
+                            } else {
+                                log.warn("未找到学号为 {} 的学生", studentNo);
+                                return null;
+                            }
+                        } catch (Exception e) {
+                            log.error("根据学号查询学生信息失败,学号: {}", studentNo, e);
+                            return null;
+                        }
+                    })
+                    .filter(id -> id != null)
+                    .collect(Collectors.toList());
+
+            return String.join(",", studentIdList);
+        } catch (Exception e) {
+            log.error("学号转学生ID失败,原始值: {}", value, e);
+            return "";
+        }
+    }
+
+    @Override
+    public WriteCellData<String> convertToExcelData(String value, ExcelContentProperty contentProperty,
+            GlobalConfiguration globalConfiguration) {
+        if (StrUtil.isBlank(value)) {
+            return new WriteCellData<>("");
+        }
+
+        try {
+            // 获取服务实例
+            IXgDormViolationService dormViolationService = SpringUtils.getBean(IXgDormViolationService.class);
+            if (dormViolationService == null) {
+                log.warn("无法获取宿舍违纪服务实例,返回原始值");
+                return new WriteCellData<>(value);
+            }
+
+            // 分割学生ID(逗号分隔)
+            String[] idArray = value.split(",");
+            List<String> studentInfoList = Arrays.stream(idArray)
+                    .map(String::trim)
+                    .filter(StrUtil::isNotBlank)
+                    .map(idStr -> {
+                        try {
+                            Long studentId = Long.parseLong(idStr);
+                            StudentOptionVo student = dormViolationService.getStudentById(studentId);
+                            if (student != null) {
+                                // 格式:学号-姓名(学院-专业-班级)
+                                return String.format("%s-%s(%s-%s-%s)",
+                                        student.getStudentNo(),
+                                        student.getName(),
+                                        student.getCollegeName(),
+                                        student.getMajorName(),
+                                        student.getClassName());
+                            } else {
+                                return idStr + "-未知学生";
+                            }
+                        } catch (NumberFormatException e) {
+                            log.warn("无效的学生ID格式: {}", idStr);
+                            return idStr + "-格式错误";
+                        } catch (Exception e) {
+                            log.error("查询学生信息失败,学生ID: {}", idStr, e);
+                            return idStr + "-查询失败";
+                        }
+                    })
+                    .collect(Collectors.toList());
+
+            String convertedValue = String.join("; ", studentInfoList);
+            return new WriteCellData<>(convertedValue);
+        } catch (Exception e) {
+            log.error("学生信息转换失败,原始值: {}", value, e);
+            return new WriteCellData<>(value + "-转换失败");
+        }
+    }
+}

+ 206 - 0
backend/ruoyi-modules/ruoyi-xg/src/main/java/org/dromara/xg/domain/vo/XgDormViolationExportVo.java

@@ -0,0 +1,206 @@
+package org.dromara.xg.domain.vo;
+
+import java.util.Date;
+import com.fasterxml.jackson.annotation.JsonFormat;
+
+import org.dromara.xg.convert.StudentInfoExcelConvert;
+import org.dromara.xg.domain.XgDormViolation;
+import cn.idev.excel.annotation.ExcelIgnoreUnannotated;
+import cn.idev.excel.annotation.ExcelProperty;
+import org.dromara.common.excel.annotation.ExcelDictFormat;
+import org.dromara.common.excel.convert.ExcelDictConvert;
+import io.github.linpeilie.annotations.AutoMapper;
+import lombok.Data;
+
+import java.io.Serial;
+import java.io.Serializable;
+import java.util.Date;
+
+/**
+ * 宿舍违纪记录视图对象 xg_dorm_violation
+ *
+ * @author zlwu
+ * @date 2025-08-16
+ */
+@Data
+@ExcelIgnoreUnannotated
+@AutoMapper(target = XgDormViolation.class)
+public class XgDormViolationExportVo implements Serializable {
+
+    @Serial
+    private static final long serialVersionUID = 1L;
+
+    /**
+     * 违纪记录ID(主键)
+     */
+    @ExcelProperty(value = "违纪记录ID")
+    private Long id;
+
+    /**
+     * 学生ID
+     */
+    // @ExcelProperty(value = "学生ID")
+    // private Long studentId;
+
+    /**
+     * 学生姓名
+     */
+    @ExcelProperty(value = "学生姓名")
+    private String studentName;
+
+    /**
+     * 学号
+     */
+    @ExcelProperty(value = "学号")
+    private String studentNo;
+
+    /**
+     * 学院ID
+     */
+    // @ExcelProperty(value = "学院ID")
+    // private Long collegeId;
+
+    /**
+     * 学院名称
+     */
+    @ExcelProperty(value = "学院名称")
+    private String collegeName;
+
+    /**
+     * 专业ID
+     */
+    // @ExcelProperty(value = "专业ID")
+    // private Long majorId;
+
+    /**
+     * 专业名称
+     */
+    @ExcelProperty(value = "专业名称")
+    private String majorName;
+
+    /**
+     * 班级ID
+     */
+    // @ExcelProperty(value = "班级ID")
+    // private Long classId;
+
+    /**
+     * 班级名称
+     */
+    @ExcelProperty(value = "班级名称")
+    private String className;
+
+    /**
+     * 校区ID
+     */
+    // @ExcelProperty(value = "校区ID")
+    // private Long campusId;
+
+    /**
+     * 校区名称
+     */
+    @ExcelProperty(value = "校区名称")
+    private String campusName;
+
+    /**
+     * 宿舍区域ID
+     */
+    // @ExcelProperty(value = "宿舍区域ID")
+    // private Long areaId;
+
+    /**
+     * 宿舍区域名称
+     */
+    @ExcelProperty(value = "宿舍区域名称")
+    private String areaName;
+
+    /**
+     * 宿舍楼ID
+     */
+    // @ExcelProperty(value = "宿舍楼ID")
+    // private Long buildingId;
+
+    /**
+     * 宿舍楼名称
+     */
+    @ExcelProperty(value = "宿舍楼名称")
+    private String buildingName;
+
+    /**
+     * 宿舍房间ID
+     */
+    // @ExcelProperty(value = "宿舍房间ID")
+    // private Long roomId;
+
+    /**
+     * 房间名称
+     */
+    @ExcelProperty(value = "房间名称")
+    private String roomName;
+
+    /**
+     * 床位ID
+     */
+    // @ExcelProperty(value = "床位ID")
+    // private Long bedId;
+
+    /**
+     * 床位名称
+     */
+    @ExcelProperty(value = "床位名称")
+    private String bedName;
+
+    /**
+     * 违纪类型
+     */
+    @ExcelProperty(value = "违纪类型", converter = ExcelDictConvert.class)
+    @ExcelDictFormat(dictType = "dorm_violation_type")
+    private String violationType;
+
+    /**
+     * 违纪等级:1轻微 2一般 3严重 4特别严重
+     */
+    @ExcelProperty(value = "违纪等级", converter = ExcelDictConvert.class)
+    @ExcelDictFormat(dictType = "dorm_violation_level")
+    private String violationLevel;
+
+    /**
+     * 违纪发生时间
+     */
+    @ExcelProperty(value = "违纪发生时间")
+    private Date violationTime;
+
+    /**
+     * 违纪行为描述
+     */
+    @ExcelProperty(value = "违纪行为描述")
+    private String violationDescription;
+
+    /**
+     * 涉及其他学生id(逗号分隔)
+     */
+    @ExcelProperty(value = "涉及其他学生id", converter = StudentInfoExcelConvert.class)
+    // @ExcelDictFormat(readConverterExp = "逗=号分隔")
+    private String involvedStudents;
+
+    /**
+     * 附件OSS ID列表(逗号分隔)
+     */
+    // @ExcelProperty(value = "附件OSS ID列表", converter = ExcelDictConvert.class)
+    // @ExcelDictFormat(readConverterExp = "逗=号分隔")
+    // private String attachmentOssIds;
+
+    /**
+     * 删除标志(0代表存在 1代表删除)
+     */
+    // @ExcelProperty(value = "删除标志", converter = ExcelDictConvert.class)
+    // @ExcelDictFormat(readConverterExp = "0=代表存在,1=代表删除")
+    // private String deleted;
+
+    /**
+     * 备注
+     */
+    @ExcelProperty(value = "备注")
+    private String remark;
+
+}

+ 16 - 12
backend/ruoyi-modules/ruoyi-xg/src/main/java/org/dromara/xg/domain/vo/XgDormViolationVo.java

@@ -32,12 +32,13 @@ public class XgDormViolationVo implements Serializable {
      * 违纪记录ID(主键)
      */
     @ExcelProperty(value = "违纪记录ID", converter = ExcelDictConvert.class)
+    @ExcelDictFormat(readConverterExp = "主=键")
     private Long id;
 
     /**
      * 学生ID
      */
-    // @ExcelProperty(value = "学生ID")
+    @ExcelProperty(value = "学生ID")
     private Long studentId;
 
     /**
@@ -55,7 +56,7 @@ public class XgDormViolationVo implements Serializable {
     /**
      * 学院ID
      */
-    // @ExcelProperty(value = "学院ID")
+    @ExcelProperty(value = "学院ID")
     private Long collegeId;
 
     /**
@@ -67,7 +68,7 @@ public class XgDormViolationVo implements Serializable {
     /**
      * 专业ID
      */
-    // @ExcelProperty(value = "专业ID")
+    @ExcelProperty(value = "专业ID")
     private Long majorId;
 
     /**
@@ -79,7 +80,7 @@ public class XgDormViolationVo implements Serializable {
     /**
      * 班级ID
      */
-    // @ExcelProperty(value = "班级ID")
+    @ExcelProperty(value = "班级ID")
     private Long classId;
 
     /**
@@ -91,7 +92,7 @@ public class XgDormViolationVo implements Serializable {
     /**
      * 校区ID
      */
-    // @ExcelProperty(value = "校区ID")
+    @ExcelProperty(value = "校区ID")
     private Long campusId;
 
     /**
@@ -103,7 +104,7 @@ public class XgDormViolationVo implements Serializable {
     /**
      * 宿舍区域ID
      */
-    // @ExcelProperty(value = "宿舍区域ID")
+    @ExcelProperty(value = "宿舍区域ID")
     private Long areaId;
 
     /**
@@ -115,7 +116,7 @@ public class XgDormViolationVo implements Serializable {
     /**
      * 宿舍楼ID
      */
-    // @ExcelProperty(value = "宿舍楼ID")
+    @ExcelProperty(value = "宿舍楼ID")
     private Long buildingId;
 
     /**
@@ -127,7 +128,7 @@ public class XgDormViolationVo implements Serializable {
     /**
      * 宿舍房间ID
      */
-    // @ExcelProperty(value = "宿舍房间ID")
+    @ExcelProperty(value = "宿舍房间ID")
     private Long roomId;
 
     /**
@@ -139,7 +140,7 @@ public class XgDormViolationVo implements Serializable {
     /**
      * 床位ID
      */
-    // @ExcelProperty(value = "床位ID")
+    @ExcelProperty(value = "床位ID")
     private Long bedId;
 
     /**
@@ -158,7 +159,7 @@ public class XgDormViolationVo implements Serializable {
     /**
      * 违纪等级:1轻微 2一般 3严重 4特别严重
      */
-    @ExcelProperty(value = "违纪等级", converter = ExcelDictConvert.class)
+    @ExcelProperty(value = "违纪等级:1轻微 2一般 3严重 4特别严重", converter = ExcelDictConvert.class)
     @ExcelDictFormat(dictType = "dorm_violation_level")
     private String violationLevel;
 
@@ -178,18 +179,21 @@ public class XgDormViolationVo implements Serializable {
      * 涉及其他学生id(逗号分隔)
      */
     @ExcelProperty(value = "涉及其他学生id", converter = ExcelDictConvert.class)
+    @ExcelDictFormat(readConverterExp = "逗=号分隔")
     private String involvedStudents;
 
     /**
      * 附件OSS ID列表(逗号分隔)
      */
-    // @ExcelProperty(value = "附件OSS ID列表", converter = ExcelDictConvert.class)
+    @ExcelProperty(value = "附件OSS ID列表", converter = ExcelDictConvert.class)
+    @ExcelDictFormat(readConverterExp = "逗=号分隔")
     private String attachmentOssIds;
 
     /**
      * 删除标志(0代表存在 1代表删除)
      */
-    // @ExcelProperty(value = "删除标志", converter = ExcelDictConvert.class)
+    @ExcelProperty(value = "删除标志", converter = ExcelDictConvert.class)
+    @ExcelDictFormat(readConverterExp = "0=代表存在,1=代表删除")
     private String deleted;
 
     /**

+ 8 - 0
backend/ruoyi-modules/ruoyi-xg/src/main/java/org/dromara/xg/mapper/XgDormViolationMapper.java

@@ -33,4 +33,12 @@ public interface XgDormViolationMapper extends BaseMapperPlus<XgDormViolation, X
      * @return 学生详细信息
      */
     StudentOptionVo selectStudentById(@Param("studentId") Long studentId);
+
+    /**
+     * 根据学号获取学生详细信息
+     *
+     * @param studentNo 学号
+     * @return 学生详细信息
+     */
+    StudentOptionVo selectStudentByStudentNo(@Param("studentNo") String studentNo);
 }

+ 8 - 0
backend/ruoyi-modules/ruoyi-xg/src/main/java/org/dromara/xg/service/IXgDormViolationService.java

@@ -84,4 +84,12 @@ public interface IXgDormViolationService {
      * @return 学生详细信息
      */
     StudentOptionVo getStudentById(Long studentId);
+
+    /**
+     * 根据学号获取学生详细信息
+     *
+     * @param studentNo 学号
+     * @return 学生详细信息
+     */
+    StudentOptionVo getStudentByStudentNo(String studentNo);
 }

+ 11 - 0
backend/ruoyi-modules/ruoyi-xg/src/main/java/org/dromara/xg/service/impl/XgDormViolationServiceImpl.java

@@ -184,4 +184,15 @@ public class XgDormViolationServiceImpl implements IXgDormViolationService {
     public StudentOptionVo getStudentById(Long studentId) {
         return baseMapper.selectStudentById(studentId);
     }
+
+    /**
+     * 根据学号获取学生详细信息
+     *
+     * @param studentNo 学号
+     * @return 学生详细信息
+     */
+    @Override
+    public StudentOptionVo getStudentByStudentNo(String studentNo) {
+        return baseMapper.selectStudentByStudentNo(studentNo);
+    }
 }

BIN
backend/ruoyi-modules/ruoyi-xg/src/main/resources/dormViolation_template.xlsx


+ 39 - 0
backend/ruoyi-modules/ruoyi-xg/src/main/resources/mapper/dormViolation/XgDormViolationMapper.xml

@@ -118,4 +118,43 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         AND s.id = #{studentId}
     </select>
 
+    <!-- 根据学号获取学生详细信息 -->
+    <select id="selectStudentByStudentNo" resultMap="StudentOptionResult">
+        SELECT
+            s.id,
+            s.student_no,
+            s.name,
+            s.gender,
+            s.college_id,
+            s.college_name,
+            s.major_id,
+            s.major_name,
+            s.class_id,
+            s.class_name,
+            s.phone,
+            s.create_by,
+            s.create_time,
+            s.update_by,
+            s.update_time,
+            COALESCE(dc.id, NULL) as campus_id,
+            COALESCE(dc.campus_name, NULL) as campus_name,
+            COALESCE(da.id, NULL) as area_id,
+            COALESCE(da.area_name, NULL) as area_name,
+            COALESCE(db.id, NULL) as building_id,
+            COALESCE(db.building_name, NULL) as building_name,
+            COALESCE(dr.id, NULL) as room_id,
+            COALESCE(dr.room_name, NULL) as room_name,
+            COALESCE(bed.id, NULL) as bed_id,
+            COALESCE(bed.bed_name, NULL) as bed_name
+        FROM xg_student_msg s
+        LEFT JOIN xg_dorm_bed_student dbs ON s.id = dbs.student_id AND dbs.deleted = 0
+        LEFT JOIN xg_dorm_bed bed ON dbs.bed_id = bed.id AND bed.deleted = 0
+        LEFT JOIN xg_dorm_room dr ON bed.room_id = dr.id AND dr.deleted = 0
+        LEFT JOIN xg_dorm_building db ON dr.building_id = db.id AND db.deleted = 0
+        LEFT JOIN xg_dorm_area da ON db.area_id = da.id AND da.deleted = 0
+        LEFT JOIN xg_dorm_campus dc ON da.campus_id = dc.id AND dc.deleted = 0
+        WHERE s.deleted = 0
+        AND s.student_no = #{studentNo}
+    </select>
+
 </mapper>