|
@@ -8,6 +8,7 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.qmth.boot.core.collection.PageResult;
|
|
|
import com.qmth.boot.core.exception.StatusException;
|
|
|
import com.qmth.boot.core.fss.store.FileStore;
|
|
|
+import com.qmth.exam.reserve.bean.Constants;
|
|
|
import com.qmth.exam.reserve.bean.applytask.CurrentApplyTaskVO;
|
|
|
import com.qmth.exam.reserve.bean.login.LoginUser;
|
|
|
import com.qmth.exam.reserve.bean.stdapply.CategoryVO;
|
|
@@ -43,11 +44,11 @@ import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
import java.io.File;
|
|
|
import java.io.IOException;
|
|
|
-import java.nio.file.Files;
|
|
|
import java.util.Arrays;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
import java.util.StringJoiner;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
@Service
|
|
|
public class StudentServiceImpl extends ServiceImpl<StudentDao, StudentEntity> implements StudentService {
|
|
@@ -314,19 +315,24 @@ public class StudentServiceImpl extends ServiceImpl<StudentDao, StudentEntity> i
|
|
|
|
|
|
@Override
|
|
|
public void uploadStudentPhoto(Long operateId, MultipartFile file) {
|
|
|
+ //文件大小限制
|
|
|
+ if (file.getSize() > Constants.FILE_SIZE_LIMIT) {
|
|
|
+ throw new StatusException("上传的考生照片大小不能超过5M");
|
|
|
+ }
|
|
|
+
|
|
|
CurrentApplyTaskVO curApplyTask = applyTaskCacheService.currentApplyTask(null);
|
|
|
if (curApplyTask == null) {
|
|
|
throw new StatusException("未开启预约任务,无法导入");
|
|
|
}
|
|
|
|
|
|
//照片必须以考生的身份证命名
|
|
|
- String identityNumber = FileNameUtils.getBaseName(file.getName());
|
|
|
+ String identityNumber = FileNameUtils.getBaseName(file.getOriginalFilename());
|
|
|
LambdaQueryWrapper<StudentEntity> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
queryWrapper.eq(StudentEntity::getIdentityNumber, identityNumber);
|
|
|
queryWrapper.eq(StudentEntity::getApplyTaskId, curApplyTask.getTaskId());
|
|
|
- StudentEntity student = this.getOne(queryWrapper);
|
|
|
- if (student == null) {
|
|
|
- throw new StatusException("上次照片必须以考生的身份证命名");
|
|
|
+ List<StudentEntity> studentList = this.list(queryWrapper);
|
|
|
+ if (CollectionUtils.isEmpty(studentList)) {
|
|
|
+ throw new StatusException("考生照片必须以考生的身份证命名");
|
|
|
}
|
|
|
|
|
|
StringJoiner stringJoiner = FileUtil.getDirName(FileUploadType.UPLOAD, true);
|
|
@@ -335,12 +341,16 @@ public class StudentServiceImpl extends ServiceImpl<StudentDao, StudentEntity> i
|
|
|
try {
|
|
|
fileStore.write(path + file.getOriginalFilename(), file.getInputStream(), DigestUtils.md5Hex(file.getInputStream()));
|
|
|
} catch (Exception e) {
|
|
|
- throw new RuntimeException(e);
|
|
|
+ log.error("[上传考生头像],上传失败:{}", e.getMessage());
|
|
|
+ throw new StatusException("考生头像上传失败,请稍后重试");
|
|
|
}
|
|
|
|
|
|
- //更新考生照片
|
|
|
-
|
|
|
-
|
|
|
+ //更新考生照片路径
|
|
|
+ List<Long> studentIds = studentList.stream().map(StudentEntity::getId).collect(Collectors.toList());
|
|
|
+ LambdaUpdateWrapper<StudentEntity> updateWrapper = new LambdaUpdateWrapper<>();
|
|
|
+ updateWrapper.set(StudentEntity::getPhotoPath, path + file.getOriginalFilename());
|
|
|
+ updateWrapper.in(StudentEntity::getId, studentIds);
|
|
|
+ this.update(null, updateWrapper);
|
|
|
}
|
|
|
|
|
|
}
|