Просмотр исходного кода

获取当前学生的班主任

fanxp 2 лет назад
Родитель
Сommit
71e0548820

+ 22 - 27
src/main/java/com/xjrsoft/module/student/controller/StudentManagerController.java

@@ -33,34 +33,34 @@ import java.util.List;
 
 @RestController
 @RequestMapping("/student" + "/studentmanager")
-@Api(value = "/student"  + "/studentmanager",tags = "学生基本信息管理代码")
+@Api(value = "/student" + "/studentmanager", tags = "学生基本信息管理代码")
 @AllArgsConstructor
 public class StudentManagerController {
 
     private final IStudentManagerService studentManagerService;
 
     @GetMapping(value = "/page")
-    @ApiOperation(value="学生列表(分页)")
+    @ApiOperation(value = "学生列表(分页)")
     @SaCheckPermission("studentmanager:detail")
-    public R page(@Valid BaseStudentUserPageDto dto){
+    public R page(@Valid BaseStudentUserPageDto dto) {
 
         MPJLambdaWrapper<BaseStudentUser> queryWrapper = new MPJLambdaWrapper<>();
         queryWrapper
                 .disableSubLogicDel()
-                .like(StrUtil.isNotBlank(dto.getUserName()),BaseStudentUser::getUserName,dto.getUserName())
-                .like(StrUtil.isNotBlank(dto.getMobile()),BaseStudentUser::getMobile,dto.getMobile())
-                .like(StrUtil.isNotBlank(dto.getName()),BaseStudentUser::getName,dto.getName())
-                .like(StrUtil.isNotBlank(dto.getEmail()),BaseStudentUser::getEmail,dto.getEmail())
+                .like(StrUtil.isNotBlank(dto.getUserName()), BaseStudentUser::getUserName, dto.getUserName())
+                .like(StrUtil.isNotBlank(dto.getMobile()), BaseStudentUser::getMobile, dto.getMobile())
+                .like(StrUtil.isNotBlank(dto.getName()), BaseStudentUser::getName, dto.getName())
+                .like(StrUtil.isNotBlank(dto.getEmail()), BaseStudentUser::getEmail, dto.getEmail())
                 .orderByDesc(BaseStudentUser::getId)
                 .select(BaseStudentUser::getId)
-                .select(BaseStudentUser.class,x -> VoToColumnUtil.fieldsToColumns(BaseStudentUserPageVo.class).contains(x.getProperty()))
+                .select(BaseStudentUser.class, x -> VoToColumnUtil.fieldsToColumns(BaseStudentUserPageVo.class).contains(x.getProperty()))
                 .select(BaseStudentSchoolRoll::getStudyYear)
                 .select("a.`name` as grade_id")
                 .select("b.`name` as major_set_id")
                 .select("c.`name` as class_id")
-                .innerJoin(BaseStudent.class,BaseStudent::getUserId,BaseStudentUser::getId)
-                .leftJoin(BaseStudentSchoolRoll.class,BaseStudentSchoolRoll::getUserId,BaseStudentUser::getId)
-                .leftJoin(DictionaryDetail.class,DictionaryDetail::getCode,BaseStudentSchoolRoll::getArchivesStatus, ext->ext.selectAs(DictionaryDetail::getName, BaseStudentUserPageVo::getArchivesStatus))
+                .innerJoin(BaseStudent.class, BaseStudent::getUserId, BaseStudentUser::getId)
+                .leftJoin(BaseStudentSchoolRoll.class, BaseStudentSchoolRoll::getUserId, BaseStudentUser::getId)
+                .leftJoin(DictionaryDetail.class, DictionaryDetail::getCode, BaseStudentSchoolRoll::getArchivesStatus, ext -> ext.selectAs(DictionaryDetail::getName, BaseStudentUserPageVo::getArchivesStatus))
                 .leftJoin("base_grade a on a.id = t2.grade_id")
                 .leftJoin("base_major_set b on b.id = t2.major_set_id")
                 .leftJoin("base_class c on c.id = t2.class_id")
@@ -73,9 +73,9 @@ public class StudentManagerController {
     }
 
     @GetMapping(value = "/info")
-    @ApiOperation(value="根据id查询学生信息")
+    @ApiOperation(value = "根据id查询学生信息")
     @SaCheckPermission("studentmanager:detail")
-    public R info(@RequestParam Long id){
+    public R info(@RequestParam Long id) {
         BaseStudentUser baseStudentUser = studentManagerService.getByIdDeep(id);
         if (baseStudentUser == null) {
             return R.error("找不到此数据!");
@@ -87,7 +87,7 @@ public class StudentManagerController {
     @PostMapping
     @ApiOperation(value = "新增学生")
     @SaCheckPermission("studentmanager:add")
-    public R add(@Valid @RequestBody AddBaseStudentUserDto dto){
+    public R add(@Valid @RequestBody AddBaseStudentUserDto dto) {
         BaseStudentUser baseStudentUser = BeanUtil.toBean(dto, BaseStudentUser.class);
         return R.ok(studentManagerService.add(baseStudentUser));
 
@@ -96,7 +96,7 @@ public class StudentManagerController {
     @PutMapping
     @ApiOperation(value = "修改学生")
     @SaCheckPermission("studentmanager:edit")
-    public R update(@Valid @RequestBody UpdateBaseStudentUserDto dto){
+    public R update(@Valid @RequestBody UpdateBaseStudentUserDto dto) {
 
         BaseStudentUser baseStudentUser = BeanUtil.toBean(dto, BaseStudentUser.class);
         return R.ok(studentManagerService.update(baseStudentUser));
@@ -106,19 +106,14 @@ public class StudentManagerController {
     @DeleteMapping
     @ApiOperation(value = "删除")
     @SaCheckPermission("studentmanager:delete")
-    public R delete(@Valid @RequestBody List<Long> ids){
+    public R delete(@Valid @RequestBody List<Long> ids) {
         return R.ok(studentManagerService.delete(ids));
     }
 
-//    @GetMapping(value = "/class-teacher")
-//    @ApiOperation(value="获取当前学生的班主任")
-//    public R classTeacher(){
-//        Long userId = StpUtil.getLoginIdAsLong();
-//        MPJLambdaWrapper<BaseClass> queryWrapper = new MPJLambdaWrapper<>();
-//        queryWrapper
-//                .select(BaseClass::getTeacherId)
-//                .innerJoin(BaseStudentSchoolRoll.class,BaseStudentSchoolRoll::getClassId,BaseStudent::getId)
-//                .eq(BaseStudentSchoolRoll::getUserId,userId);
-//        BaseClass user = studentManagerService.getOne(queryWrapper, false);
-//    }
+    @GetMapping(value = "/class")
+    @ApiOperation(value = "获取当前学生的班主任")
+    public R studentClass() {
+        Long userId = StpUtil.getLoginIdAsLong();
+        return R.ok(studentManagerService.getStudentClass(userId));
+    }
 }

+ 2 - 38
src/main/java/com/xjrsoft/module/student/entity/BaseClass.java

@@ -1,6 +1,7 @@
 package com.xjrsoft.module.student.entity;
 
 import com.baomidou.mybatisplus.annotation.*;
+import com.xjrsoft.common.model.base.AuditEntity;
 import io.swagger.annotations.ApiModel;
 import io.swagger.annotations.ApiModelProperty;
 import lombok.Data;
@@ -11,7 +12,7 @@ import java.time.LocalDateTime;
 @Data
 @TableName("base_class")
 @ApiModel(value = "学生班级", description = "学生班级管理")
-public class BaseClass  implements Serializable {
+public class BaseClass extends AuditEntity implements Serializable {
     private static final long serialVersionUID = 1L;
     /**
      * 主键
@@ -19,43 +20,6 @@ public class BaseClass  implements Serializable {
     @ApiModelProperty("主键")
     @TableId
     private Long id;
-    /**
-     * 创建人
-     */
-    @ApiModelProperty("创建人")
-    @TableField(fill = FieldFill.INSERT)
-    private Long createUserId;
-    /**
-     * 创建时间
-     */
-    @ApiModelProperty("创建时间")
-    @TableField(fill = FieldFill.INSERT)
-    private LocalDateTime createDate;
-    /**
-     * 修改人
-     */
-    @ApiModelProperty("修改人")
-    @TableField(fill = FieldFill.UPDATE)
-    private Long modifyUserId;
-    /**
-     * 修改时间
-     */
-    @ApiModelProperty("修改时间")
-    @TableField(fill = FieldFill.UPDATE)
-    private LocalDateTime modifyDate;
-    /**
-     * 删除标记
-     */
-    @ApiModelProperty("删除标记")
-    @TableField(fill = FieldFill.INSERT)
-    @TableLogic
-    private Integer deleteMark;
-    /**
-     * 有效标志
-     */
-    @ApiModelProperty("有效标志")
-    @TableField(fill = FieldFill.INSERT)
-    private Integer enabledMark;
 
     /**
      * 用户ID(xjr_user)

+ 10 - 0
src/main/java/com/xjrsoft/module/student/mapper/BaseClassMapper.java

@@ -0,0 +1,10 @@
+package com.xjrsoft.module.student.mapper;
+
+import com.github.yulichang.base.MPJBaseMapper;
+import com.xjrsoft.module.student.entity.BaseClass;
+import com.xjrsoft.module.student.entity.BaseStudentContact;
+import org.apache.ibatis.annotations.Mapper;
+
+@Mapper
+public interface BaseClassMapper extends MPJBaseMapper<BaseClass> {
+}

+ 10 - 0
src/main/java/com/xjrsoft/module/student/service/IStudentManagerService.java

@@ -1,7 +1,9 @@
 package com.xjrsoft.module.student.service;
 
 import com.github.yulichang.base.MPJBaseService;
+import com.xjrsoft.module.student.entity.BaseClass;
 import com.xjrsoft.module.student.entity.BaseStudentUser;
+import com.xjrsoft.module.student.vo.BaseStudentClassVo;
 
 import java.util.List;
 
@@ -29,4 +31,12 @@ public interface IStudentManagerService extends MPJBaseService<BaseStudentUser>
      * @return
      */
     Boolean delete(List<Long> ids);
+
+    /**
+     * 获取学生班级信息
+     *
+     * @param userId
+     * @return
+     */
+    BaseStudentClassVo getStudentClass(Long userId);
 }

+ 20 - 0
src/main/java/com/xjrsoft/module/student/service/impl/StudentManagerServiceImpl.java

@@ -1,10 +1,13 @@
 package com.xjrsoft.module.student.service.impl;
 
+import cn.hutool.core.bean.BeanUtil;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.github.yulichang.base.MPJBaseServiceImpl;
+import com.github.yulichang.wrapper.MPJLambdaWrapper;
 import com.xjrsoft.module.student.entity.*;
 import com.xjrsoft.module.student.mapper.*;
 import com.xjrsoft.module.student.service.IStudentManagerService;
+import com.xjrsoft.module.student.vo.BaseStudentClassVo;
 import lombok.AllArgsConstructor;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
@@ -19,6 +22,7 @@ public class StudentManagerServiceImpl  extends MPJBaseServiceImpl<BaseStudentUs
     private final com.xjrsoft.module.student.mapper.BaseStudentUserMapper studentbaseManagerBaseStudentUserMapper;
 
     private final BaseStudentMapper studentbaseManagerBaseStudentMapper;
+    private final BaseClassMapper baseClassMapper;
     private final BaseStudentContactMapper studentbaseManagerBaseStudentContactMapper;
     private final BaseStudentFamilyMapper studentbaseManagerBaseStudentFamilyMapper;
     private final BaseStudentFamilyMemberMapper studentbaseManagerBaseStudentFamilyMemberMapper;
@@ -250,4 +254,20 @@ public class StudentManagerServiceImpl  extends MPJBaseServiceImpl<BaseStudentUs
         studentbaseManagerBaseStudentSubsidizeMapper.delete(Wrappers.lambdaQuery(BaseStudentSubsidize.class).in(BaseStudentSubsidize::getUserId, ids));
         return true;
     }
+
+
+    @Override
+    public BaseStudentClassVo getStudentClass(Long userId) {
+
+        MPJLambdaWrapper<BaseClass> queryWrapper = new MPJLambdaWrapper<>();
+        queryWrapper
+                .disableSubLogicDel()
+                .innerJoin(BaseStudentSchoolRoll.class,BaseStudentSchoolRoll::getClassId,BaseStudent::getId)
+                .eq(BaseStudentSchoolRoll::getUserId,userId)
+                .selectAsClass(BaseClass.class,BaseStudentClassVo.class);
+
+        BaseClass baseClass = baseClassMapper.selectOne(queryWrapper);
+
+        return  BeanUtil.toBean(baseClass,BaseStudentClassVo.class);
+    }
 }

+ 19 - 0
src/main/java/com/xjrsoft/module/student/vo/BaseStudentClassVo.java

@@ -0,0 +1,19 @@
+package com.xjrsoft.module.student.vo;
+
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+@Data
+public class BaseStudentClassVo {
+    /**
+     * 用户ID(xjr_user)
+     */
+    @ApiModelProperty("用户ID(xjr_user)")
+    private Long teacherId;
+
+    /**
+     * 名称
+     */
+    @ApiModelProperty("名称")
+    private String name;
+}