Przeglądaj źródła

添加家长绑定学生

DESKTOP-USV654P\pc 1 rok temu
rodzic
commit
c4adb9b6a3

+ 24 - 0
src/main/java/com/xjrsoft/module/organization/controller/UserController.java

@@ -1,5 +1,6 @@
 package com.xjrsoft.module.organization.controller;
 
+import cn.dev33.satoken.annotation.SaCheckPermission;
 import cn.dev33.satoken.secure.BCrypt;
 import cn.dev33.satoken.secure.SaSecureUtil;
 import cn.dev33.satoken.session.SaSession;
@@ -76,6 +77,8 @@ public class UserController {
 
     private final SmsCtcc smsCtcc;
 
+    private final IUserStudentService userStudentService;
+
 
     @GetMapping(value = "/list")
     @ApiOperation(value = "用户列表(不分页)")
@@ -372,4 +375,25 @@ public class UserController {
         dto.setPostId(RoleEnum.PARENT.getCode());
         return R.ok(userService.add(dto));
     }
+
+    @PostMapping("/bind-student")
+    @ApiOperation(value = "绑定学生")
+    public R bindStudent(@Valid @RequestBody UserStudentBindDto dto) {
+        User user = userService.getOne(Wrappers.<User>query().lambda()
+                .eq(User::getName, dto.getName())
+                .eq(User::getCredentialNumber, dto.getIdCard()));
+        UserStudentAddDto userStudentAddDto = new UserStudentAddDto();
+        if (user == null) {
+            return R.error("学生不存在!");
+        }
+        userStudentAddDto.setUserId(dto.getUserId());
+        userStudentAddDto.setStudentId(user.getId());
+        return R.ok(userStudentService.add(userStudentAddDto));
+    }
+
+    @DeleteMapping("/unbind-student")
+    @ApiOperation(value = "解绑学生")
+    public R unBindStudent(@Valid @RequestBody List<Long> ids) {
+        return R.ok(userStudentService.delete(ids));
+    }
 }

+ 9 - 0
src/main/java/com/xjrsoft/module/organization/dto/UserStudentAddDto.java

@@ -0,0 +1,9 @@
+package com.xjrsoft.module.organization.dto;
+
+import lombok.Data;
+
+@Data
+public class UserStudentAddDto {
+    private Long userId;
+    private Long studentId;
+}

+ 10 - 0
src/main/java/com/xjrsoft/module/organization/dto/UserStudentBindDto.java

@@ -0,0 +1,10 @@
+package com.xjrsoft.module.organization.dto;
+
+import lombok.Data;
+
+@Data
+public class UserStudentBindDto {
+    private Long userId;
+    private String name;
+    private String idCard;
+}

+ 8 - 0
src/main/java/com/xjrsoft/module/organization/dto/UserStudentUpdateDto.java

@@ -0,0 +1,8 @@
+package com.xjrsoft.module.organization.dto;
+
+import lombok.Data;
+
+@Data
+public class UserStudentUpdateDto extends UserStudentAddDto {
+    private Long id;
+}

+ 32 - 0
src/main/java/com/xjrsoft/module/organization/entity/UserStudent.java

@@ -0,0 +1,32 @@
+package com.xjrsoft.module.organization.entity;
+
+import com.baomidou.mybatisplus.annotation.FieldFill;
+import com.baomidou.mybatisplus.annotation.TableField;
+import com.baomidou.mybatisplus.annotation.TableName;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import java.io.Serializable;
+import java.time.LocalDateTime;
+
+@Data
+@TableName("base_user_student")
+@ApiModel(value = "家长学生关联表", description = "家长学生关联表")
+public class UserStudent implements Serializable {
+
+    private static final long serialVersionUID = 1L;
+    private Long id;
+
+    @ApiModelProperty("家长ID(xjr_user)")
+    private Long userId;
+
+    @ApiModelProperty("学生ID(xjr_user)")
+    private Long studentId;
+
+    @TableField(fill = FieldFill.INSERT)
+    private LocalDateTime createDate;
+
+    @TableField(fill = FieldFill.UPDATE)
+    private LocalDateTime modifyDate;
+}

+ 10 - 0
src/main/java/com/xjrsoft/module/organization/mapper/UserStudentMapper.java

@@ -0,0 +1,10 @@
+package com.xjrsoft.module.organization.mapper;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.github.yulichang.base.MPJBaseMapper;
+import com.xjrsoft.module.organization.entity.UserStudent;
+import org.apache.ibatis.annotations.Mapper;
+
+@Mapper
+public interface UserStudentMapper extends BaseMapper<UserStudent>, MPJBaseMapper<UserStudent> {
+}

+ 12 - 0
src/main/java/com/xjrsoft/module/organization/service/IUserStudentService.java

@@ -0,0 +1,12 @@
+package com.xjrsoft.module.organization.service;
+
+import com.github.yulichang.base.MPJBaseService;
+import com.xjrsoft.module.organization.dto.UserStudentAddDto;
+import com.xjrsoft.module.organization.entity.UserStudent;
+
+import java.util.List;
+
+public interface IUserStudentService  extends MPJBaseService<UserStudent> {
+    boolean add(UserStudentAddDto dto);
+    boolean delete(List<Long> ids);
+}

+ 38 - 0
src/main/java/com/xjrsoft/module/organization/service/impl/UserStudentServiceImpl.java

@@ -0,0 +1,38 @@
+package com.xjrsoft.module.organization.service.impl;
+
+import cn.hutool.core.bean.BeanUtil;
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
+import com.github.yulichang.base.MPJBaseServiceImpl;
+import com.xjrsoft.common.exception.MyException;
+import com.xjrsoft.module.organization.dto.UserStudentAddDto;
+import com.xjrsoft.module.organization.entity.UserStudent;
+import com.xjrsoft.module.organization.mapper.UserStudentMapper;
+import com.xjrsoft.module.organization.service.IUserStudentService;
+import lombok.AllArgsConstructor;
+import org.springframework.stereotype.Service;
+
+import java.util.List;
+
+@Service
+@AllArgsConstructor
+public class UserStudentServiceImpl extends MPJBaseServiceImpl<UserStudentMapper, UserStudent> implements IUserStudentService {
+    private final UserStudentMapper userStudentMapper;
+
+    @Override
+    public boolean add(UserStudentAddDto dto) {
+        long count = count(Wrappers.<UserStudent>query().lambda()
+                .eq(UserStudent::getUserId, dto.getUserId())
+                .eq(UserStudent::getStudentId, dto.getStudentId()));
+        if (count > 0) {
+            throw new MyException("已经绑定了学生,不能出重复绑定");
+        }
+        UserStudent userStudent = BeanUtil.toBean(dto, UserStudent.class);
+        userStudentMapper.insert(userStudent);
+        return Boolean.TRUE;
+    }
+    @Override
+    public  boolean delete(List<Long> ids){
+        userStudentMapper.deleteBatchIds(ids);
+        return Boolean.TRUE;
+    }
+}

+ 10 - 0
src/main/java/com/xjrsoft/module/organization/vo/UserStudentVo.java

@@ -0,0 +1,10 @@
+package com.xjrsoft.module.organization.vo;
+
+import com.xjrsoft.module.organization.dto.UserStudentUpdateDto;
+import lombok.Data;
+
+@Data
+public class UserStudentVo extends UserStudentUpdateDto {
+    private String studentName;
+    private String className;
+}

+ 13 - 0
src/main/resources/sqlScript/init_sql.sql

@@ -810,5 +810,18 @@ create table sms_send_record
     primary key (`id`)
 ) engine=innodb default charset=utf8mb4 COLLATE = utf8mb4_0900_ai_ci comment '短信发送记录';
 
+-- ----------------------------
+-- 家长学生关联表
+-- ----------------------------
+DROP TABLE IF EXISTS base_user_student;
+create table base_user_student
+(
+    `id` bigint NOT NULL COMMENT '主键',
+    user_id bigint not null comment '家长ID(xjr_user)',
+    student_id bigint not null comment '学生ID(xjr_user)',
+    `create_date` date null default null COMMENT '创建时间',
+    `modify_date` date null default null COMMENT '修改时间',
+    primary key (`id`)
+) engine=innodb default charset=utf8mb4 COLLATE = utf8mb4_0900_ai_ci comment '家长学生关联表';
 
 SET FOREIGN_KEY_CHECKS = 1;