Parcourir la source

pc端学生基本信息增加学习形式和学籍照片

dzx il y a 1 an
Parent
commit
ea1de88dd8

+ 67 - 18
src/main/java/com/xjrsoft/module/student/controller/StudentManagerController.java

@@ -10,13 +10,16 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.core.toolkit.StringPool;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.github.yulichang.wrapper.MPJLambdaWrapper;
 import com.xjrsoft.common.enums.DeleteMark;
 import com.xjrsoft.common.enums.GenderDictionaryEnum;
 import com.xjrsoft.common.model.result.R;
 import com.xjrsoft.common.model.result.RT;
 import com.xjrsoft.common.page.ConventPage;
 import com.xjrsoft.common.page.PageOutput;
+import com.xjrsoft.common.utils.FileZipUtil;
 import com.xjrsoft.common.utils.TreeUtil;
+import com.xjrsoft.common.utils.VoToColumnUtil;
 import com.xjrsoft.module.base.entity.BaseClass;
 import com.xjrsoft.module.base.entity.BaseGrade;
 import com.xjrsoft.module.base.service.IBaseClassService;
@@ -24,12 +27,11 @@ import com.xjrsoft.module.base.service.IBaseGradeService;
 import com.xjrsoft.module.concat.service.IXjrUserService;
 import com.xjrsoft.module.organization.entity.UserDeptRelation;
 import com.xjrsoft.module.organization.service.IUserDeptRelationService;
-import com.xjrsoft.module.personnel.entity.FaceManagement;
-import com.xjrsoft.module.personnel.service.IFaceManagementService;
 import com.xjrsoft.module.room.service.IRoomBedService;
 import com.xjrsoft.module.student.dto.AddBaseStudentUserDto;
 import com.xjrsoft.module.student.dto.BaseStudentUserPageDto;
 import com.xjrsoft.module.student.dto.UpdateBaseStudentUserDto;
+import com.xjrsoft.module.student.entity.BaseStudent;
 import com.xjrsoft.module.student.entity.BaseStudentUser;
 import com.xjrsoft.module.student.service.IStudentManagerService;
 import com.xjrsoft.module.student.vo.BaseStudentSchoolRollVo;
@@ -43,7 +45,6 @@ import lombok.AllArgsConstructor;
 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;
@@ -51,14 +52,21 @@ 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.io.InputStream;
 import java.text.ParseException;
 import java.util.ArrayList;
+import java.util.Base64;
+import java.util.Enumeration;
+import java.util.HashMap;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
 import java.util.stream.Collectors;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipFile;
 
 @RestController
 @RequestMapping("/student" + "/studentmanager")
@@ -72,7 +80,6 @@ public class StudentManagerController {
     private final IXjrUserService xjrUserService;
     private final IRoomBedService roomBedService;
     private final IUserDeptRelationService userDeptRelationService;
-    private final IFaceManagementService faceManagementService;
     @GetMapping(value = "/page")
     @ApiOperation(value = "学生列表(分页)")
     @SaCheckPermission("studentmanager:detail")
@@ -173,30 +180,22 @@ public class StudentManagerController {
 
         userVo.setGenderCn(GenderDictionaryEnum.getValue(userVo.getGender()));
 
-        //查询头像照片
-        FaceManagement faceManagement = faceManagementService.getOne(
-            new QueryWrapper<FaceManagement>().lambda()
-            .eq(FaceManagement::getUserId, userVo.getId())
-        );
         return R.ok(userVo);
     }
 
 
-    @PostMapping
+    @PostMapping("/add")
     @ApiOperation(value = "新增学生")
     @SaCheckPermission("studentmanager:add")
-    public R add(@Valid @RequestBody AddBaseStudentUserDto dto) {
-        return R.ok(studentManagerService.add(dto));
+    public R add(@Valid AddBaseStudentUserDto dto, @RequestParam("file") MultipartFile file) throws IOException {
+        return R.ok(studentManagerService.add(dto, file));
     }
 
-    @PutMapping
+    @PostMapping
     @ApiOperation(value = "修改学生")
     @SaCheckPermission("studentmanager:edit")
-    public R update(@Valid @RequestBody UpdateBaseStudentUserDto dto) {
-
-
-        return R.ok(studentManagerService.update(dto));
-
+    public R update(@Valid UpdateBaseStudentUserDto dto, @RequestParam("file") MultipartFile file) throws IOException {
+        return R.ok(studentManagerService.update(dto, file));
     }
 
     @DeleteMapping
@@ -221,4 +220,54 @@ public class StudentManagerController {
 
         return RT.ok(studentManagerService.importStudentData(excelDataList));
     }
+
+
+    @PostMapping(value = "/avatar-import")
+    @ApiOperation(value = "批量导入学生学学籍照")
+    @SaCheckPermission("stundentfaceprocess:batch-upload")
+    public RT<Boolean> batchUpload(@RequestParam("file") MultipartFile file) throws Exception {
+        List<BaseStudentUser> list = studentManagerService.list(
+                new MPJLambdaWrapper<BaseStudentUser>().distinct()
+                        .select(BaseStudentUser::getId)
+                        .select(BaseStudentUser.class, x -> VoToColumnUtil.fieldsToColumns(BaseStudentUser.class).contains(x.getProperty()))
+                        .leftJoin(BaseStudent.class, BaseStudent::getUserId, BaseStudentUser::getId)
+                        .eq(BaseStudent::getDeleteMark, DeleteMark.NODELETE.getCode())
+                        .eq(BaseStudentUser::getDeleteMark, DeleteMark.NODELETE.getCode())
+        );
+        Map<String, BaseStudentUser> studentMap = new HashMap<>();
+        for (BaseStudentUser baseStudentUser : list) {
+            studentMap.put(baseStudentUser.getCredentialNumber(), baseStudentUser);
+        }
+
+        ZipFile zipFile = FileZipUtil.convertToZipFile(file);
+        Enumeration<? extends ZipEntry> entries = zipFile.entries();
+        while (entries.hasMoreElements()){
+            ZipEntry entry = entries.nextElement();
+            String filename = entry.getName();
+            InputStream inputStream = zipFile.getInputStream(entry); //读取文件内容
+
+            String idNumber = filename.substring(0, 18);
+            BaseStudentUser studentUser = studentMap.get(idNumber);
+            if(studentUser == null){
+                continue;
+            }
+            //将照片转换成base64
+            ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
+            byte[] buffer = new byte[4096];
+            int bytesRead;
+            while ((bytesRead = inputStream.read(buffer)) != -1) {
+                outputStream.write(buffer, 0, bytesRead);
+            }
+            byte[] imageBytes = outputStream.toByteArray();
+            String base64String = Base64.getEncoder().encodeToString(imageBytes);
+            inputStream.close();
+            outputStream.close();
+
+            studentUser.setAvatar(base64String);
+
+            studentManagerService.updateById(studentUser);
+
+        }
+        return RT.ok(true);
+    }
 }

+ 4 - 2
src/main/java/com/xjrsoft/module/student/service/IStudentManagerService.java

@@ -9,7 +9,9 @@ import com.xjrsoft.module.student.entity.BaseStudentUser;
 import com.xjrsoft.module.student.vo.BaseStudentClassVo;
 import com.xjrsoft.module.student.vo.BaseStudentUserPageVo;
 import com.xjrsoft.module.student.vo.PersonalPortraitPersonalInfoVo;
+import org.springframework.web.multipart.MultipartFile;
 
+import java.io.IOException;
 import java.text.ParseException;
 import java.util.List;
 import java.util.Map;
@@ -22,7 +24,7 @@ public interface IStudentManagerService extends MPJBaseService<BaseStudentUser>
      * @param baseStudentUser
      * @return
      */
-    Boolean add(AddBaseStudentUserDto baseStudentUser);
+    Boolean add(AddBaseStudentUserDto baseStudentUser, MultipartFile file) throws IOException;
 
     /**
      * 更新
@@ -30,7 +32,7 @@ public interface IStudentManagerService extends MPJBaseService<BaseStudentUser>
      * @param baseStudentUser
      * @return
      */
-    Boolean update(UpdateBaseStudentUserDto baseStudentUser);
+    Boolean update(UpdateBaseStudentUserDto baseStudentUser, MultipartFile file) throws IOException;
 
     /**
      * 删除

+ 14 - 2
src/main/java/com/xjrsoft/module/student/service/impl/StudentManagerServiceImpl.java

@@ -68,7 +68,9 @@ import lombok.AllArgsConstructor;
 import org.springframework.beans.BeanUtils;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
+import org.springframework.web.multipart.MultipartFile;
 
+import java.io.IOException;
 import java.text.ParseException;
 import java.text.SimpleDateFormat;
 import java.time.LocalDate;
@@ -109,10 +111,15 @@ public class StudentManagerServiceImpl extends MPJBaseServiceImpl<BaseStudentUse
 
     @Override
     @Transactional(rollbackFor = Exception.class)
-    public Boolean add(AddBaseStudentUserDto dto) {
+    public Boolean add(AddBaseStudentUserDto dto, MultipartFile file) throws IOException {
 
         BaseStudentUser baseStudentUser = BeanUtil.toBean(dto, BaseStudentUser.class);
         baseStudentUser.setCode(dto.getUserName());
+
+        //存学籍照片
+        String base64String = Base64.getEncoder().encodeToString(file.getBytes());
+        baseStudentUser.setAvatar(base64String);
+
         // 用户身份证后6位作为默认密码
         baseStudentUser.setPassword(BCrypt.hashpw(propertiesConfig.getDefaultPassword(), BCrypt.gensalt()));
         studentbaseManagerBaseStudentUserMapper.insert(baseStudentUser);
@@ -177,10 +184,15 @@ public class StudentManagerServiceImpl extends MPJBaseServiceImpl<BaseStudentUse
 
     @Override
     @Transactional(rollbackFor = Exception.class)
-    public Boolean update(UpdateBaseStudentUserDto dto) {
+    public Boolean update(UpdateBaseStudentUserDto dto, MultipartFile file) throws IOException {
 
         BaseStudentUser baseStudentUser = BeanUtil.toBean(dto, BaseStudentUser.class);
         baseStudentUser.setCode(dto.getUserName());
+
+        //存学籍照片
+        String base64String = Base64.getEncoder().encodeToString(file.getBytes());
+        baseStudentUser.setAvatar(base64String);
+
         studentbaseManagerBaseStudentUserMapper.updateById(baseStudentUser);
 
         //先删除再新增