From 247cb86585a1d1894596ed18a6c93efecb992946 Mon Sep 17 00:00:00 2001
From: luohairen <3399054449@qq.com>
Date: 星期四, 14 十一月 2024 10:34:27 +0800
Subject: [PATCH] 班级成绩图表分析

---
 src/main/java/com/ycl/jxkg/controller/admin/UserController.java |   90 ++++++++++++++++++++++++++++++++++++++------
 1 files changed, 77 insertions(+), 13 deletions(-)

diff --git a/src/main/java/com/ycl/jxkg/controller/admin/UserController.java b/src/main/java/com/ycl/jxkg/controller/admin/UserController.java
index d9aa558..5090210 100644
--- a/src/main/java/com/ycl/jxkg/controller/admin/UserController.java
+++ b/src/main/java/com/ycl/jxkg/controller/admin/UserController.java
@@ -1,27 +1,30 @@
 package com.ycl.jxkg.controller.admin;
 
 import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
+import com.github.pagehelper.PageInfo;
 import com.ycl.jxkg.base.BaseApiController;
 import com.ycl.jxkg.base.Result;
-import com.ycl.jxkg.domain.enums.RoleEnum;
-import com.ycl.jxkg.domain.other.KeyValue;
+import com.ycl.jxkg.base.SystemCode;
+import com.ycl.jxkg.context.WebContext;
+import com.ycl.jxkg.domain.entity.Classes;
+import com.ycl.jxkg.domain.entity.SysConfig;
 import com.ycl.jxkg.domain.entity.User;
 import com.ycl.jxkg.domain.entity.UserEventLog;
-import com.ycl.jxkg.domain.enums.UserStatusEnum;
+import com.ycl.jxkg.domain.other.KeyValue;
 import com.ycl.jxkg.domain.vo.StudentVO;
-import com.ycl.jxkg.service.AuthenticationService;
-import com.ycl.jxkg.service.UserEventLogService;
-import com.ycl.jxkg.service.UserService;
-import com.ycl.jxkg.utils.DateTimeUtil;
 import com.ycl.jxkg.domain.vo.admin.user.*;
+import com.ycl.jxkg.enums.RoleEnum;
+import com.ycl.jxkg.enums.UserStatusEnum;
+import com.ycl.jxkg.service.*;
+import com.ycl.jxkg.utils.DateTimeUtil;
 import com.ycl.jxkg.utils.PageInfoHelper;
-import com.github.pagehelper.PageInfo;
-
 import lombok.RequiredArgsConstructor;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.BeanUtils;
 import org.springframework.web.bind.annotation.*;
+import org.springframework.web.multipart.MultipartFile;
 
+import javax.servlet.http.HttpServletResponse;
 import javax.validation.Valid;
 import java.util.Date;
 import java.util.List;
@@ -36,11 +39,33 @@
     private final UserService userService;
     private final UserEventLogService userEventLogService;
     private final AuthenticationService authenticationService;
+    private final WebContext webContext;
+    private final ClassesUserService classesUserService;
+    private final ClassesService classesService;
+    private final Integer teacher = 2;
+    private final Integer student = 1;
 
     @RequestMapping(value = "/page/list", method = RequestMethod.POST)
     public Result<PageInfo<UserResponseVO>> pageList(@RequestBody UserPageRequestVO model) {
+        if(!student.equals(model.getRole())) {
+            User currentUser = webContext.getCurrentUser();
+            if (teacher.equals(currentUser.getRole())) {
+                return Result.fail(SystemCode.InnerError.getCode(), "鎮ㄦ病鏈夎闂潈闄�");
+            }
+        }
         PageInfo<User> pageInfo = userService.userPage(model);
         PageInfo<UserResponseVO> page = PageInfoHelper.copyMap(pageInfo, d -> UserResponseVO.from(d));
+        // 鎵惧埌姣忎釜鐢ㄦ埛瀵瑰簲鐨勭彮绾�
+        List<UserResponseVO> list = page.getList();
+        list.stream().peek(item -> {
+            List<Integer> classesIds = classesUserService.getByUserId(item.getId());
+            List<String> classNames = classesIds.stream().map(classesId -> {
+                Classes classes = classesService.getById(classesId);
+                return classes.getClassName();
+            }).collect(Collectors.toList());
+            item.setClassName(classNames);
+        }).collect(Collectors.toList());
+        page.setList(list);
         return Result.ok(page);
     }
 
@@ -56,6 +81,20 @@
             return student;
         }).collect(Collectors.toList());
         return Result.ok().data(studentVOS);
+    }
+
+    @RequestMapping(value = "/teacher/list", method = RequestMethod.GET)
+    public Result<?> teacherList() {
+        List<User> teacherList = new LambdaQueryChainWrapper<>(userService.getBaseMapper())
+                .eq(User::getRole, RoleEnum.TEACHER.getCode())
+                .orderByDesc(User::getCreateTime)
+                .list();
+        List<StudentVO> teachers = teacherList.stream().map(item -> {
+            StudentVO student = new StudentVO();
+            BeanUtils.copyProperties(item, student);
+            return student;
+        }).collect(Collectors.toList());
+        return Result.ok().data(teachers);
     }
 
     @RequestMapping(value = "/classes/students", method = RequestMethod.GET)
@@ -103,11 +142,9 @@
                 return new Result<>(3, "瀵嗙爜涓嶈兘涓虹┖");
             }
         }
-        if (StringUtils.isBlank(model.getBirthDay())) {
-            model.setBirthDay(null);
-        }
         User user = new User();
         BeanUtils.copyProperties(model, user);
+        user.setAge(model.getAge());
 
         if (model.getId() == null) {
             String encodePwd = authenticationService.pwdEncode(model.getPassword());
@@ -153,7 +190,7 @@
     @RequestMapping(value = "/delete/{id}", method = RequestMethod.POST)
     public Result delete(@PathVariable Integer id) {
         User user = userService.getUserById(id);
-        userService.updateById(user);
+        userService.removeById(user.getId());
         return Result.ok();
     }
 
@@ -164,4 +201,31 @@
         return Result.ok(keyValues);
     }
 
+    @GetMapping("importTemplate")
+    public void importTemplate(HttpServletResponse response) {
+        userService.importTemplate(response);
+    }
+
+    @PostMapping("import")
+    public Result<String> importExcel(MultipartFile file) {
+        return Result.ok(userService.importExcel(file));
+    }
+
+    @PostMapping("/reset/password/{id}")
+    public Result<String> resetPassword(@PathVariable Integer id) {
+        User user = userService.getUserById(id);
+        String encodePwd = authenticationService.pwdEncode(new SysConfig().getPasswordDefault());
+        user.setPassword(encodePwd);
+        userService.updateById(user);
+        return Result.ok();
+    }
+
+    @PostMapping("/edit/password")
+    public Result<String> editPassword(@RequestBody UserEditPasswordVO model) {
+        User user = userService.getUserById(model.getId());
+        String newPassword = authenticationService.pwdEncode(model.getNewPassword());
+        user.setPassword(newPassword);
+        userService.updateById(user);
+        return Result.ok();
+    }
 }

--
Gitblit v1.8.0