Explorar o código

student 添加 根据userId获取详细信息。

tom hai 5 meses
pai
achega
5eccebbc8c

+ 20 - 6
ruoyi-sim/src/main/java/com/ruoyi/sim/controller/StudentController.java

@@ -1,11 +1,10 @@
 package com.ruoyi.sim.controller;
 
-import com.ruoyi.common.annotation.Log;
 import com.ruoyi.common.core.controller.BaseController;
 import com.ruoyi.common.core.domain.AjaxResult;
+import com.ruoyi.common.core.domain.entity.SysRole;
 import com.ruoyi.common.core.domain.entity.SysUser;
 import com.ruoyi.common.core.page.TableDataInfo;
-import com.ruoyi.common.enums.BusinessType;
 import com.ruoyi.common.utils.SecurityUtils;
 import com.ruoyi.common.utils.StringUtils;
 import com.ruoyi.sim.domain.Student;
@@ -18,12 +17,14 @@ import com.ruoyi.system.service.ISysUserService;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import org.apache.commons.lang3.ArrayUtils;
+import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.validation.annotation.Validated;
 import org.springframework.web.bind.annotation.*;
 
 import java.util.List;
+import java.util.Objects;
+import java.util.stream.Collectors;
 
 @Api("学生Controller")
 @RestController
@@ -43,8 +44,7 @@ public class StudentController extends BaseController {
     private ISysPostService postService;
 
     @Autowired
-    private StudentService extSysUserService;
-
+    private StudentService studentService;
 
     /**
      * copy
@@ -57,10 +57,24 @@ public class StudentController extends BaseController {
     @ApiOperation("查询学生列表")
     public TableDataInfo list() {
         // startPage();  todo:分页
-        List<Student> list = extSysUserService.selectStudentList();
+        List<Student> list = studentService.selectStudentList();
         return getDataTable(list);
     }
 
+    /**
+     * copy
+     * 根据用户编号获取详细信息
+     */
+    // @PreAuthorize("@ss.hasPermi('system:user:query')")
+    @GetMapping(value = "/{userId}")
+    @ApiOperation("根据userId获取详细信息")
+    public AjaxResult getInfo(@PathVariable(value = "userId") Long userId) {
+        // -------------------------------- tom add  --------------------------------
+        // 覆盖data
+        // ajax.put(AjaxResult.DATA_TAG, student);
+        // -------------------------------- tom add  --------------------------------
+        return success(studentService.selectStudentByUserId(userId));
+    }
 
     // @PreAuthorize("@ss.hasPermi('sim:student:query')")
 

+ 21 - 4
ruoyi-sim/src/main/java/com/ruoyi/sim/service/impl/StudentService.java

@@ -66,19 +66,36 @@ public class StudentService {
             List<SysRole> listR = roleMapper.selectRolesByUserName(sysUser.getUserName());
             for (SysRole sysRole : listR) {
                 if (Objects.equals(sysRole.getRoleId(), Consts.ROLE_ID_STUDENT)) {
-                    long deptId = sysUser.getDeptId();
                     Student target = new Student();
                     BeanUtils.copyProperties(sysUser, target);
-                    list2.add(target);
-                    AddOnDept a = addOnDeptService.selectAddOnDeptByDeptId(deptId);
-                    Major m = majorService.selectMajorByMajorId(a.getMajorId());
+                    Major m = getMajorByDeptId(sysUser.getDeptId());
                     if (Objects.nonNull(m)) {
                         target.setMajor(m);
                     }
+                    // final add.
+                    list2.add(target);
                     break;
                 }
             }
         }
         return list2;
     }
+
+
+    public Student selectStudentByUserId(Long userId) {
+        SysUser sysUser = userMapper.selectUserById(userId);
+        // 屏蔽密码
+        sysUser.setPassword("");
+        Student student = new Student();
+        BeanUtils.copyProperties(sysUser, student);
+        student.setMajor(getMajorByDeptId(sysUser.getDeptId()));
+        // logger.info(Objects.requireNonNull(student.toString()));
+        return student;
+    }
+
+    public Major getMajorByDeptId(long deptId) {
+        AddOnDept a = addOnDeptService.selectAddOnDeptByDeptId(deptId);
+        Major m = majorService.selectMajorByMajorId(a.getMajorId());
+        return m;
+    }
 }