Browse Source

新生导入

dzx 8 months ago
parent
commit
4c967232cd

+ 40 - 4
src/main/java/com/xjrsoft/module/student/controller/BaseNewStudentController.java

@@ -3,6 +3,7 @@ package com.xjrsoft.module.student.controller;
 import cn.dev33.satoken.annotation.SaCheckPermission;
 import cn.hutool.core.bean.BeanUtil;
 import com.alibaba.excel.EasyExcel;
+import com.alibaba.excel.support.ExcelTypeEnum;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.xjrsoft.common.model.result.RT;
 import com.xjrsoft.common.page.ConventPage;
@@ -12,6 +13,7 @@ import com.xjrsoft.module.student.dto.BaseNewStudentPageDto;
 import com.xjrsoft.module.student.dto.UpdateBaseNewStudentDto;
 import com.xjrsoft.module.student.entity.BaseNewStudent;
 import com.xjrsoft.module.student.service.IBaseNewStudentService;
+import com.xjrsoft.module.student.vo.BaseNewStudentExcelVo;
 import com.xjrsoft.module.student.vo.BaseNewStudentPageVo;
 import com.xjrsoft.module.student.vo.BaseNewStudentTreeVo;
 import com.xjrsoft.module.student.vo.BaseNewStudentVo;
@@ -20,6 +22,7 @@ import com.xjrsoft.module.student.vo.EnrollmentPlanTreeVo;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import lombok.AllArgsConstructor;
+import org.springframework.http.ResponseEntity;
 import org.springframework.web.bind.annotation.DeleteMapping;
 import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.PostMapping;
@@ -31,9 +34,12 @@ import org.springframework.web.bind.annotation.RestController;
 import org.springframework.web.multipart.MultipartFile;
 
 import javax.validation.Valid;
+import java.io.ByteArrayOutputStream;
 import java.io.IOException;
+import java.math.BigDecimal;
 import java.util.ArrayList;
 import java.util.List;
+import java.util.Map;
 
 /**
 * @title: 新生维护信息
@@ -133,10 +139,40 @@ public class BaseNewStudentController {
     }
     @PostMapping("/import")
     @ApiOperation(value = "导入")
-    public RT<Boolean> importData(@RequestParam MultipartFile file) throws IOException {
-        List<BaseNewStudentPageVo> savedDataList = EasyExcel.read(file.getInputStream()).head(BaseNewStudentPageVo.class).sheet().doReadSync();
-        Boolean result = baseNewStudentService.saveBatch(BeanUtil.copyToList(savedDataList, BaseNewStudent.class));
-        return RT.ok(result);
+    public ResponseEntity<byte[]> importData(@RequestParam Long treeId, @RequestParam MultipartFile file) throws IOException {
+        List<Map<Integer, Object>> errorList = baseNewStudentService.importData(treeId, file);
+        List<BaseNewStudentExcelVo> result = new ArrayList<>();
+        for (Map<Integer, Object> objectMap : errorList) {
+            result.add(
+                    new BaseNewStudentExcelVo(){{
+                        setGraduateSchool(objectMap.get(0).toString());
+                        setName(objectMap.get(1).toString());
+                        setGender(objectMap.get(2).toString());
+                        setCredentialNumber(objectMap.get(3).toString());
+                        setHeight(BigDecimal.valueOf(Double.parseDouble(objectMap.get(4).toString())));
+                        setWeight(BigDecimal.valueOf(Double.parseDouble(objectMap.get(5).toString())));
+                        if(objectMap.get(6) != null){
+                            setGraduateClass(objectMap.get(6).toString());
+                        }
+                        setSource(objectMap.get(7).toString());
+                        setStduyStatus(objectMap.get(8).toString());
+                        setMobile(objectMap.get(9).toString());
+                        setFirstAmbition(objectMap.get(10).toString());
+                        setSecondAmbition(objectMap.get(11).toString());
+                        setIsAdjust(objectMap.get(12).toString());
+                        if(objectMap.get(13) != null){
+                            setFamilyMobile(objectMap.get(13).toString());
+                        }
+                        if(objectMap.get(14) != null){
+                            setFamilyAddress(objectMap.get(14).toString());
+                        }
+                        setErrorMsg(objectMap.get(15).toString());
+                    }}
+            );
+        }
+        ByteArrayOutputStream bot = new ByteArrayOutputStream();
+        EasyExcel.write(bot, BaseNewStudentExcelVo.class).automaticMergeHead(false).excelType(ExcelTypeEnum.XLSX).sheet().doWrite(result);
+        return RT.fileStream(bot.toByteArray(), "未导入数据" + ExcelTypeEnum.XLSX.getValue());
     }
 
 }

+ 6 - 0
src/main/java/com/xjrsoft/module/student/dto/AddBaseNewStudentDto.java

@@ -100,4 +100,10 @@ public class AddBaseNewStudentDto implements Serializable {
 
     @ApiModelProperty("招生计划id(enrollment_plan)")
     private Long enrollmentPlanId;
+
+    @ApiModelProperty("家庭电话")
+    private String familyMobile;
+
+    @ApiModelProperty("家庭地址")
+    private String familyAddress;
 }

+ 8 - 0
src/main/java/com/xjrsoft/module/student/entity/BaseNewStudent.java

@@ -158,4 +158,12 @@ public class BaseNewStudent implements Serializable {
 
     @ApiModelProperty("家庭地址")
     private String familyAddress;
+
+    @ApiModelProperty("第一志愿id")
+    private Long firstAmbitionId;
+    /**
+     * 第二志愿
+     */
+    @ApiModelProperty("第二志愿")
+    private Long secondAmbitionId;
 }

+ 5 - 0
src/main/java/com/xjrsoft/module/student/service/IBaseNewStudentService.java

@@ -7,8 +7,11 @@ import com.xjrsoft.module.student.entity.BaseNewStudent;
 import com.xjrsoft.module.student.vo.BaseNewStudentPageVo;
 import com.xjrsoft.module.student.vo.EnrollmentPlanGradeVo;
 import com.xjrsoft.module.student.vo.EnrollmentPlanTreeVo;
+import org.springframework.web.multipart.MultipartFile;
 
+import java.io.IOException;
 import java.util.List;
+import java.util.Map;
 
 /**
 * @title: 新生维护信息
@@ -25,4 +28,6 @@ public interface IBaseNewStudentService extends MPJBaseService<BaseNewStudent> {
     List<EnrollmentPlanTreeVo> getEnrollmentPlanList();
 
     List<EnrollmentPlanGradeVo> getGradeList();
+
+    List<Map<Integer, Object>> importData(Long treeId, MultipartFile file) throws IOException;
 }

+ 191 - 0
src/main/java/com/xjrsoft/module/student/service/impl/BaseNewStudentServiceImpl.java

@@ -1,7 +1,15 @@
 package com.xjrsoft.module.student.service.impl;
 
+import cn.dev33.satoken.stp.StpUtil;
+import cn.hutool.core.util.StrUtil;
+import com.alibaba.excel.EasyExcel;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.github.yulichang.base.MPJBaseServiceImpl;
+import com.github.yulichang.wrapper.MPJLambdaWrapper;
+import com.xjrsoft.common.enums.YesOrNoEnum;
+import com.xjrsoft.common.utils.VoToColumnUtil;
+import com.xjrsoft.module.base.entity.BaseMajorSet;
+import com.xjrsoft.module.base.service.IBaseMajorSetService;
 import com.xjrsoft.module.student.dto.BaseNewStudentPageDto;
 import com.xjrsoft.module.student.entity.BaseNewStudent;
 import com.xjrsoft.module.student.mapper.BaseNewStudentMapper;
@@ -9,10 +17,21 @@ import com.xjrsoft.module.student.service.IBaseNewStudentService;
 import com.xjrsoft.module.student.vo.BaseNewStudentPageVo;
 import com.xjrsoft.module.student.vo.EnrollmentPlanGradeVo;
 import com.xjrsoft.module.student.vo.EnrollmentPlanTreeVo;
+import com.xjrsoft.module.system.entity.DictionaryDetail;
+import com.xjrsoft.module.system.entity.DictionaryItem;
+import com.xjrsoft.module.system.mapper.DictionarydetailMapper;
 import lombok.AllArgsConstructor;
 import org.springframework.stereotype.Service;
+import org.springframework.web.multipart.MultipartFile;
 
+import java.io.IOException;
+import java.math.BigDecimal;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
 
 /**
 * @title: 新生维护信息
@@ -23,6 +42,9 @@ import java.util.List;
 @Service
 @AllArgsConstructor
 public class BaseNewStudentServiceImpl extends MPJBaseServiceImpl<BaseNewStudentMapper, BaseNewStudent> implements IBaseNewStudentService {
+
+    private final DictionarydetailMapper dictionarydetailMapper;
+    private final IBaseMajorSetService majorSetService;
     @Override
     public Page<BaseNewStudentPageVo> getPage(Page<BaseNewStudentPageVo> page, BaseNewStudentPageDto dto) {
         return this.baseMapper.getPage(page, dto);
@@ -37,4 +59,173 @@ public class BaseNewStudentServiceImpl extends MPJBaseServiceImpl<BaseNewStudent
     public List<EnrollmentPlanGradeVo> getGradeList() {
         return this.baseMapper.getGradeList();
     }
+
+    /**
+     * 导入数据
+     * @param file 上传的文件
+     * @return 未成功导入的数据
+     */
+    @Override
+    public List<Map<Integer, Object>> importData(Long treeId, MultipartFile file) throws IOException {
+        List<Map<Integer, Object>> excelDataList = EasyExcel.read(file.getInputStream()).sheet().headRowNumber(3).doReadSync();
+
+        //查询字典数据
+        List<String> codeList = new ArrayList<>();
+        codeList.add("gender");
+        codeList.add("student_type");
+        codeList.add("stduy_status");
+
+        List<DictionaryDetail> detailList = dictionarydetailMapper.selectJoinList(DictionaryDetail.class,
+                new MPJLambdaWrapper<DictionaryDetail>()
+                        .select(DictionaryDetail.class, x -> VoToColumnUtil.fieldsToColumns(DictionaryDetail.class).contains(x.getProperty()))
+                        .leftJoin(DictionaryItem.class, DictionaryItem::getId, DictionaryDetail::getItemId)
+                        .in(DictionaryItem::getCode, codeList)
+        );
+        Map<String, String> dictMap = new HashMap<>();
+        for (DictionaryDetail detail : detailList) {
+            dictMap.put(detail.getName(), detail.getCode());
+        }
+
+        //查询专业数据
+        Map<String, Long> majorSetMap = majorSetService.list().stream().collect(Collectors.toMap(BaseMajorSet::getName, BaseMajorSet::getId));
+
+        List<BaseNewStudent> dataList = new ArrayList<>();
+
+        List<Map<Integer, Object>> errorList = new ArrayList<>();
+        Date createDate = new Date();
+        for (Map<Integer, Object> objectMap : excelDataList) {
+
+            //1、验证数据
+            if(checkData(objectMap, dictMap, majorSetMap) != null){
+                errorList.add(objectMap);
+                continue;
+            }
+            dataList.add(
+                new BaseNewStudent(){{
+                    setCreateDate(createDate);
+                    setCreateUserId(StpUtil.getLoginIdAsLong());
+                    setGraduateSchool(objectMap.get(0).toString());
+                    setName(objectMap.get(1).toString());
+                    setGender(dictMap.get(objectMap.get(2).toString()));
+                    setCredentialNumber(objectMap.get(3).toString());
+                    setHeight(BigDecimal.valueOf(Double.parseDouble(objectMap.get(4).toString())));
+                    setWeight(BigDecimal.valueOf(Double.parseDouble(objectMap.get(5).toString())));
+                    if(objectMap.get(6) != null){
+                        setGraduateClass(objectMap.get(6).toString());
+                    }
+
+                    setSource(dictMap.get(objectMap.get(7).toString()));
+                    setStduyStatus(dictMap.get(objectMap.get(8).toString()));
+                    setMobile(objectMap.get(9).toString());
+                    setFirstAmbition(objectMap.get(10).toString());
+                    setFirstAmbitionId(majorSetMap.get(objectMap.get(10).toString()));
+                    setSecondAmbition(objectMap.get(11).toString());
+                    setSecondAmbitionId(majorSetMap.get(objectMap.get(11).toString()));
+                    setIsAdjust(YesOrNoEnum.getCode(objectMap.get(12).toString()));
+                    if(objectMap.get(13) != null){
+                        setFamilyMobile(objectMap.get(13).toString());
+                    }
+                    if(objectMap.get(14) != null){
+                        setFamilyAddress(objectMap.get(14).toString());
+                    }
+                    setEnrollmentPlanId(treeId);
+                    setStatus(0);
+                }}
+            );
+        }
+        this.saveBatch(dataList);
+        return errorList;
+    }
+
+    /**
+     * 检查必填字段是否为空
+     */
+    Map<Integer, Object> checkData(Map<Integer, Object> objectMap, Map<String, String> dictMap, Map<String, Long> majorSetMap){
+        //验证哪些列是空
+        List<Integer> emptyColumn = new ArrayList<>();
+        List<String> errorMsg = new ArrayList<>();
+        if(objectMap.get(0) == null || "".equals(objectMap.get(0).toString())){
+            emptyColumn.add(0);
+        }
+        if(objectMap.get(1) == null || "".equals(objectMap.get(1).toString())){
+            emptyColumn.add(1);
+        }
+        if(objectMap.get(2) == null || "".equals(objectMap.get(2).toString())){
+            emptyColumn.add(2);
+        }else{
+            if(dictMap.get(objectMap.get(2).toString()) == null){
+                errorMsg.add("性别不正确");
+            }
+        }
+        if(objectMap.get(3) == null || "".equals(objectMap.get(3).toString())){
+            emptyColumn.add(3);
+        }
+        if(objectMap.get(4) == null || "".equals(objectMap.get(4).toString())){
+            emptyColumn.add(4);
+        }else{
+            if(objectMap.get(4) instanceof Integer){
+                errorMsg.add("身高请只填写数字");
+            }
+        }
+        if(objectMap.get(5) == null || "".equals(objectMap.get(5).toString())){
+            emptyColumn.add(5);
+        }else{
+            if(objectMap.get(5) instanceof Integer){
+                errorMsg.add("体重请只填写数字");
+            }
+        }
+
+        if(objectMap.get(7) == null || "".equals(objectMap.get(7).toString())){
+            emptyColumn.add(7);
+        }else{
+            if(dictMap.get(objectMap.get(8).toString()) == null){
+                errorMsg.add("学生来源填写不正确");
+            }
+        }
+        if(objectMap.get(8) == null || "".equals(objectMap.get(8).toString())){
+            emptyColumn.add(8);
+        }else{
+            if(dictMap.get(objectMap.get(8).toString()) == null){
+                errorMsg.add("住宿类型填写不正确");
+            }
+        }
+        if(objectMap.get(9) == null || "".equals(objectMap.get(9).toString())){
+            emptyColumn.add(9);
+        }
+        if(objectMap.get(10) == null || "".equals(objectMap.get(10).toString())){
+            emptyColumn.add(10);
+        }else{
+            if(majorSetMap.get(objectMap.get(10).toString()) == null){
+                errorMsg.add("第一志愿填写不正确");
+            }
+        }
+        if(objectMap.get(11) == null || "".equals(objectMap.get(11).toString())){
+            emptyColumn.add(11);
+        }else{
+            if(majorSetMap.get(objectMap.get(11).toString()) == null){
+                errorMsg.add("第二志愿填写不正确");
+            }
+        }
+        if(objectMap.get(12) == null || "".equals(objectMap.get(12).toString())){
+            emptyColumn.add(12);
+        }else{
+            if(!"是".equals(objectMap.get(12).toString()) && !"否".equals(objectMap.get(12).toString()) ){
+                errorMsg.add("是否可调配请只填写“是”或“否”");
+            }
+        }
+        String msg = "";
+        if(!errorMsg.isEmpty()){
+            msg += errorMsg.toString().replace("]", "").replace("[", "");
+        }
+        if(!emptyColumn.isEmpty()){
+            msg += "以下列不能为空:" + emptyColumn.toString().replace("]", "").replace("[", "") + ";";
+        }
+
+        if(StrUtil.isNotEmpty(msg)){
+            objectMap.put(15, msg);
+            return objectMap;
+        }
+
+        return null;
+    }
 }

+ 131 - 0
src/main/java/com/xjrsoft/module/student/vo/BaseNewStudentExcelVo.java

@@ -0,0 +1,131 @@
+package com.xjrsoft.module.student.vo;
+
+import com.alibaba.excel.annotation.ExcelProperty;
+import com.alibaba.excel.annotation.write.style.ContentStyle;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import java.math.BigDecimal;
+
+/**
+* @title: 新生维护信息分页列表出参
+* @Author dzx
+* @Date: 2024-06-27
+* @Version 1.0
+*/
+@Data
+public class BaseNewStudentExcelVo {
+
+    /**
+    * 毕业学校
+    */
+    @ContentStyle(dataFormat = 49)
+    @ExcelProperty("毕业学校")
+    @ApiModelProperty("毕业学校")
+    private String graduateSchool;
+    /**
+    * 学生姓名
+    */
+    @ContentStyle(dataFormat = 49)
+    @ExcelProperty("学生姓名")
+    @ApiModelProperty("学生姓名")
+    private String name;
+    /**
+    * 性别
+    */
+    @ContentStyle(dataFormat = 49)
+    @ExcelProperty("性别")
+    @ApiModelProperty("性别")
+    private String gender;
+
+    /**
+    * 身份证号
+    */
+    @ContentStyle(dataFormat = 49)
+    @ExcelProperty("身份证号")
+    @ApiModelProperty("身份证号")
+    private String credentialNumber;
+    /**
+    * 身高
+    */
+    @ContentStyle(dataFormat = 49)
+    @ExcelProperty("身高")
+    @ApiModelProperty("身高")
+    private BigDecimal height;
+    /**
+    * 体重
+    */
+    @ContentStyle(dataFormat = 49)
+    @ExcelProperty("体重")
+    @ApiModelProperty("体重")
+    private BigDecimal weight;
+    /**
+    * 成绩
+    */
+    @ContentStyle(dataFormat = 49)
+    @ExcelProperty("成绩")
+    @ApiModelProperty("成绩")
+    private BigDecimal score;
+    /**
+    * 毕业班级
+    */
+    @ContentStyle(dataFormat = 49)
+    @ExcelProperty("毕业班级")
+    @ApiModelProperty("毕业班级")
+    private String graduateClass;
+    /**
+    * 学生来源
+    */
+    @ContentStyle(dataFormat = 49)
+    @ExcelProperty("学生来源")
+    @ApiModelProperty("学生来源")
+    private String source;
+    /**
+    * 住宿类型
+    */
+    @ContentStyle(dataFormat = 49)
+    @ExcelProperty("住宿类型")
+    @ApiModelProperty("住宿类型")
+    private String stduyStatus;
+
+    /**
+    * 手机号
+    */
+    @ContentStyle(dataFormat = 49)
+    @ExcelProperty("手机号")
+    @ApiModelProperty("手机号")
+    private String mobile;
+
+
+    @ContentStyle(dataFormat = 49)
+    @ExcelProperty("第一志愿")
+    @ApiModelProperty("第一志愿")
+    private String firstAmbition;
+
+
+    @ContentStyle(dataFormat = 49)
+    @ExcelProperty("第二志愿")
+    @ApiModelProperty("第二志愿")
+    private String secondAmbition;
+
+    @ContentStyle(dataFormat = 49)
+    @ExcelProperty("家庭电话")
+    @ApiModelProperty("是否可调配")
+    private String isAdjust;
+
+    @ContentStyle(dataFormat = 49)
+    @ExcelProperty("家庭电话")
+    @ApiModelProperty("家庭电话")
+    private String familyMobile;
+
+    @ContentStyle(dataFormat = 49)
+    @ExcelProperty("家庭地址")
+    @ApiModelProperty("家庭地址")
+    private String familyAddress;
+
+    @ContentStyle(dataFormat = 49)
+    @ExcelProperty("错误信息")
+    @ApiModelProperty("错误信息")
+    private String errorMsg;
+
+}

+ 8 - 0
src/main/java/com/xjrsoft/module/student/vo/BaseNewStudentPageVo.java

@@ -141,4 +141,12 @@ public class BaseNewStudentPageVo {
     @ApiModelProperty("是否可调配(0:否,1:是)")
     private Integer isAdjust;
 
+    @ExcelProperty("家庭电话")
+    @ApiModelProperty("家庭电话")
+    private String familyMobile;
+
+    @ExcelProperty("家庭地址")
+    @ApiModelProperty("家庭地址")
+    private String familyAddress;
+
 }