|
@@ -7,13 +7,19 @@ import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
|
|
import cn.iocoder.yudao.framework.common.pojo.PageParam;
|
|
|
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
|
|
import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
|
|
|
+import cn.iocoder.yudao.module.infra.api.file.FileApi;
|
|
|
+import cn.iocoder.yudao.module.infra.service.file.FileService;
|
|
|
import cn.iocoder.yudao.module.system.controller.admin.user.vo.user.*;
|
|
|
+import cn.iocoder.yudao.module.system.controller.admin.userPhotoGroup.vo.UserPhotoGroupSaveReqVO;
|
|
|
+import cn.iocoder.yudao.module.system.controller.admin.userPhotos.vo.UserPhotosSaveReqVO;
|
|
|
import cn.iocoder.yudao.module.system.convert.user.UserConvert;
|
|
|
import cn.iocoder.yudao.module.system.dal.dataobject.dept.DeptDO;
|
|
|
import cn.iocoder.yudao.module.system.dal.dataobject.user.AdminUserDO;
|
|
|
import cn.iocoder.yudao.module.system.enums.common.SexEnum;
|
|
|
import cn.iocoder.yudao.module.system.service.dept.DeptService;
|
|
|
import cn.iocoder.yudao.module.system.service.user.AdminUserService;
|
|
|
+import cn.iocoder.yudao.module.system.service.userPhotoGroup.UserPhotoGroupService;
|
|
|
+import cn.iocoder.yudao.module.system.service.userPhotos.UserPhotosService;
|
|
|
import io.swagger.v3.oas.annotations.Operation;
|
|
|
import io.swagger.v3.oas.annotations.Parameter;
|
|
|
import io.swagger.v3.oas.annotations.Parameters;
|
|
@@ -26,13 +32,15 @@ import org.springframework.web.multipart.MultipartFile;
|
|
|
import javax.annotation.Resource;
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
import javax.validation.Valid;
|
|
|
-import java.io.IOException;
|
|
|
-import java.util.Arrays;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
-import java.util.Objects;
|
|
|
+import java.io.*;
|
|
|
+import java.nio.file.Files;
|
|
|
+import java.nio.file.Path;
|
|
|
+import java.util.*;
|
|
|
+import java.util.zip.ZipEntry;
|
|
|
+import java.util.zip.ZipInputStream;
|
|
|
|
|
|
import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.EXPORT;
|
|
|
+import static cn.iocoder.yudao.framework.common.pojo.CommonResult.error;
|
|
|
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
|
|
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList;
|
|
|
|
|
@@ -47,6 +55,18 @@ public class UserController {
|
|
|
@Resource
|
|
|
private DeptService deptService;
|
|
|
|
|
|
+ //新加的
|
|
|
+ @Resource
|
|
|
+ private UserPhotosService userPhotosService;
|
|
|
+ @Resource
|
|
|
+ private UserPhotoGroupService userPhotoGroupService;
|
|
|
+ @Resource
|
|
|
+ private FileService fileService;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private FileApi fileApi;
|
|
|
+
|
|
|
+
|
|
|
@PostMapping("/create")
|
|
|
@Operation(summary = "新增用户")
|
|
|
@PreAuthorize("@ss.hasPermission('system:user:create')")
|
|
@@ -54,6 +74,7 @@ public class UserController {
|
|
|
Long id = userService.createUser(reqVO);
|
|
|
return success(id);
|
|
|
}
|
|
|
+
|
|
|
@PostMapping("/create_teacher")
|
|
|
@Operation(summary = "新增教师")
|
|
|
@PreAuthorize("@ss.hasPermission('system:teacher:create')")
|
|
@@ -110,6 +131,7 @@ public class UserController {
|
|
|
return success(new PageResult<>(UserConvert.INSTANCE.convertList(pageResult.getList(), deptMap),
|
|
|
pageResult.getTotal()));
|
|
|
}
|
|
|
+
|
|
|
//lsq
|
|
|
@GetMapping("/page0")
|
|
|
@Operation(summary = "获得老师分页列表")
|
|
@@ -143,6 +165,7 @@ public class UserController {
|
|
|
return success(new PageResult<>(UserConvert.INSTANCE.convertList(pageResult.getList(), deptMap),
|
|
|
pageResult.getTotal()));
|
|
|
}
|
|
|
+
|
|
|
//lsq
|
|
|
@GetMapping("/DeptTeacherPage")
|
|
|
@Operation(summary = "获得工作间教师分页列表")
|
|
@@ -185,6 +208,7 @@ public class UserController {
|
|
|
List<AdminUserDO> deptUser = userService.getDeptUser();
|
|
|
return success(deptUser);
|
|
|
}
|
|
|
+
|
|
|
@GetMapping("/supervisor")
|
|
|
@Operation(summary = "获得所有导师")
|
|
|
public CommonResult<List<AdminUserDO>> getSupervisor() {
|
|
@@ -203,10 +227,10 @@ public class UserController {
|
|
|
// 循环处理每个毕业生
|
|
|
for (AdminUserDO student : pageResult.getList()) {
|
|
|
// 根据 supervisorId 查询导师信息
|
|
|
- if (student.getSupervisorId()!=null) {
|
|
|
+ if (student.getSupervisorId() != null) {
|
|
|
AdminUserDO supervisorUser = userService.getUser(student.getSupervisorId());
|
|
|
String supervisor = supervisorUser.getNickname();
|
|
|
- String mobile =supervisorUser.getMobile();
|
|
|
+ String mobile = supervisorUser.getMobile();
|
|
|
// 赋值给 对应 字段
|
|
|
student.setSupervisor(supervisor);
|
|
|
student.setSupervisorMobile(mobile);
|
|
@@ -229,10 +253,10 @@ public class UserController {
|
|
|
public CommonResult<PageResult<UserRespVO>> getGraduateStudentTPage(@Valid UserPageReqVO pageReqVO) {
|
|
|
PageResult<AdminUserDO> pageResult = userService.getGraduateStudentTPage(pageReqVO);
|
|
|
for (AdminUserDO student : pageResult.getList()) {
|
|
|
- if (student.getSupervisorId()!=null) {
|
|
|
+ if (student.getSupervisorId() != null) {
|
|
|
AdminUserDO supervisorUser = userService.getUser(student.getSupervisorId());
|
|
|
String supervisor = supervisorUser.getNickname();
|
|
|
- String mobile =supervisorUser.getMobile();
|
|
|
+ String mobile = supervisorUser.getMobile();
|
|
|
|
|
|
student.setSupervisor(supervisor);
|
|
|
student.setSupervisorMobile(mobile);
|
|
@@ -265,7 +289,7 @@ public class UserController {
|
|
|
public CommonResult<UserRespVO> getUser(@RequestParam("id") Long id) {
|
|
|
AdminUserDO user = userService.getUser(id);
|
|
|
//毕业生专属
|
|
|
- if (user.getSupervisorId()!=null && Objects.equals(user.getUserType(), "2")) {
|
|
|
+ if (user.getSupervisorId() != null && Objects.equals(user.getUserType(), "2")) {
|
|
|
AdminUserDO supervisorUser = userService.getUser(user.getSupervisorId());
|
|
|
String supervisor = supervisorUser.getNickname();
|
|
|
user.setSupervisor(supervisor);
|
|
@@ -321,7 +345,6 @@ public class UserController {
|
|
|
}
|
|
|
|
|
|
|
|
|
-
|
|
|
//毕业生
|
|
|
@GetMapping("/get-import-GraduateStudentTemplate")
|
|
|
@Operation(summary = "获得导入用户模板")
|
|
@@ -343,5 +366,67 @@ public class UserController {
|
|
|
ExcelUtils.write(response, "用户导入模板.xls", "用户列表", graduateStudentImportExcelVO.class, list);
|
|
|
}
|
|
|
|
|
|
+ @PostMapping("/addPhotos")
|
|
|
+ @Operation(summary = "增加照片组")
|
|
|
+ public CommonResult<Long> addPhotos(@RequestParam("groupName") String groupName,
|
|
|
+ @RequestParam("groupDescription") String groupDescription,
|
|
|
+ @RequestParam("file") MultipartFile file) throws Exception {
|
|
|
+ if (!file.getOriginalFilename().endsWith(".zip")) {
|
|
|
+ throw new IllegalArgumentException("上传文件必须是压缩包");
|
|
|
+ }
|
|
|
+ // 创建照片组
|
|
|
+ UserPhotoGroupSaveReqVO createVO = new UserPhotoGroupSaveReqVO();
|
|
|
+ createVO.setGroupName(groupName);
|
|
|
+ createVO.setGroupDescription(groupDescription);
|
|
|
+ Long groupId = userPhotoGroupService.createUserPhotoGroup(createVO);
|
|
|
|
|
|
-}
|
|
|
+ // 文件格式检查
|
|
|
+ try (InputStream inputStream = file.getInputStream()) {
|
|
|
+ java.util.zip.ZipInputStream zipStream = new ZipInputStream(inputStream);
|
|
|
+ ZipEntry entry;
|
|
|
+ while ((entry = zipStream.getNextEntry())!= null) {
|
|
|
+ System.out.println("文件格式错误");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 创建临时目录存放解压后的文件
|
|
|
+ File tempDir = Files.createTempDirectory("photo_group_images").toFile();
|
|
|
+ try (ZipInputStream zipInputStream = new ZipInputStream(file.getInputStream())) {
|
|
|
+ ZipEntry entry;
|
|
|
+ while ((entry = zipInputStream.getNextEntry())!= null) {
|
|
|
+ if (!entry.isDirectory()) {
|
|
|
+ File newFile = new File(tempDir, entry.getName());
|
|
|
+ try (BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(newFile))) {
|
|
|
+ byte[] buffer = new byte[1024];
|
|
|
+ int len;
|
|
|
+ while ((len = zipInputStream.read(buffer)) > 0) {
|
|
|
+ bos.write(buffer, 0, len);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ System.out.println("到这里");
|
|
|
+ try {
|
|
|
+ // 上传文件并获取 URL
|
|
|
+ String photoUrl = fileApi.createFile(Files.readAllBytes(newFile.toPath()));
|
|
|
+ System.out.println("照片路径: " + photoUrl);
|
|
|
+ // 获取新创建的照片组 ID
|
|
|
+ // 保存照片信息到数据库
|
|
|
+ UserPhotosSaveReqVO photo = new UserPhotosSaveReqVO();
|
|
|
+ photo.setPhotoGroupId(groupId);
|
|
|
+ photo.setPhotoUrl(photoUrl);
|
|
|
+ userPhotosService.createUserPhotos(photo);
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new RuntimeException("上传照片失败:" + e.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ zipInputStream.closeEntry();
|
|
|
+ }
|
|
|
+ } finally {
|
|
|
+ // 删除临时目录
|
|
|
+ Files.walk(tempDir.toPath())
|
|
|
+ .sorted(Comparator.reverseOrder())
|
|
|
+ .map(Path::toFile)
|
|
|
+ .forEach(File::delete);
|
|
|
+ }
|
|
|
+ return success(groupId);
|
|
|
+ }
|
|
|
+}
|