From 1fb6d20b7ab964d29c8e649c097ed7e0c4e13fa6 Mon Sep 17 00:00:00 2001 From: wenyu441069198 <14186472+wenyu441069198@user.noreply.gitee.com> Date: Sat, 22 Jun 2024 12:29:56 +0800 Subject: [PATCH] =?UTF-8?q?=E8=82=96=E6=B5=B7=E5=8D=97=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E5=BA=93=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../backend/config/MallSecurityConfig.java | 9 +- ...Controller.java => UmsUserController.java} | 81 +++---- .../mapper/umsAdmin/UmsRoleMapper.java | 4 +- .../mapper/umsAdmin/UmsStudentMapper.java | 1 + .../mapper/umsAdmin/UmsTeacherMapper.java | 1 + ...UmsAdminMapper.java => UmsUserMapper.java} | 6 +- .../dto/umsAdmin/UmsStudentAndTeacherDTO.java | 7 +- .../UmsUserParam.java} | 9 +- .../UpdateUserPasswordParam.java} | 4 +- .../entity/umsAdmin/AdminUserDetails.java | 4 +- .../model/entity/umsAdmin/UmsMenu.java | 41 ---- .../model/entity/umsAdmin/UmsPermission.java | 24 ++ .../model/entity/umsAdmin/UmsRole.java | 20 +- .../model/entity/umsAdmin/UmsStudent.java | 46 +--- .../model/entity/umsAdmin/UmsTeacher.java | 48 ++-- .../umsAdmin/{UmsAdmin.java => UmsUser.java} | 7 +- .../model/vo/umsAdmin/UmsStudentVO.java | 10 +- .../model/vo/umsAdmin/UmsTeacherVO.java | 10 +- .../impl/courses/CoursesServiceImpl.java | 19 +- .../courses/StudentCoursesServiceImpl.java | 9 +- .../favour/SeResourceFavourServiceImpl.java | 9 +- .../service/umsAdmin/UmsRoleService.java | 11 +- ...sAdminService.java => UmsUserService.java} | 22 +- .../umsAdmin/impl/UmsRoleServiceImpl.java | 39 +++- ...rviceImpl.java => UmsUserServiceImpl.java} | 212 ++++++++++-------- src/main/resources/mapper/UmsRoleMapper.xml | 44 ++-- .../resources/mapper/UmsStudentMapper.xml | 8 + .../resources/mapper/UmsTeacherMapper.xml | 12 +- .../{UmsAdminMapper.xml => UmsUserMapper.xml} | 2 +- 29 files changed, 352 insertions(+), 367 deletions(-) rename src/main/java/com/teaching/backend/controller/umsAdmin/{UmsAdminController.java => UmsUserController.java} (64%) rename src/main/java/com/teaching/backend/mapper/umsAdmin/{UmsAdminMapper.java => UmsUserMapper.java} (72%) rename src/main/java/com/teaching/backend/model/dto/{UmsAdminParam.java => umsAdmin/UmsUserParam.java} (56%) rename src/main/java/com/teaching/backend/model/dto/{UpdateAdminPasswordParam.java => umsAdmin/UpdateUserPasswordParam.java} (84%) delete mode 100644 src/main/java/com/teaching/backend/model/entity/umsAdmin/UmsMenu.java create mode 100644 src/main/java/com/teaching/backend/model/entity/umsAdmin/UmsPermission.java rename src/main/java/com/teaching/backend/model/entity/umsAdmin/{UmsAdmin.java => UmsUser.java} (85%) rename src/main/java/com/teaching/backend/service/umsAdmin/{UmsAdminService.java => UmsUserService.java} (72%) rename src/main/java/com/teaching/backend/service/umsAdmin/impl/{UmsAdminServiceImpl.java => UmsUserServiceImpl.java} (65%) rename src/main/resources/mapper/{UmsAdminMapper.xml => UmsUserMapper.xml} (97%) diff --git a/src/main/java/com/teaching/backend/config/MallSecurityConfig.java b/src/main/java/com/teaching/backend/config/MallSecurityConfig.java index 93060ca..f901b4f 100644 --- a/src/main/java/com/teaching/backend/config/MallSecurityConfig.java +++ b/src/main/java/com/teaching/backend/config/MallSecurityConfig.java @@ -1,17 +1,12 @@ package com.teaching.backend.config; -import com.teaching.backend.service.umsAdmin.UmsAdminService; +import com.teaching.backend.service.umsAdmin.UmsUserService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -import org.springframework.security.access.ConfigAttribute; import org.springframework.security.core.userdetails.UserDetailsService; -import java.util.List; -import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; - /** * mall-security模块相关配置 * Created by macro on 2019/11/9. @@ -20,7 +15,7 @@ import java.util.concurrent.ConcurrentHashMap; public class MallSecurityConfig { @Autowired - private UmsAdminService umsadminService; + private UmsUserService umsadminService; // @Autowired // private UmsResourceService resourceService; diff --git a/src/main/java/com/teaching/backend/controller/umsAdmin/UmsAdminController.java b/src/main/java/com/teaching/backend/controller/umsAdmin/UmsUserController.java similarity index 64% rename from src/main/java/com/teaching/backend/controller/umsAdmin/UmsAdminController.java rename to src/main/java/com/teaching/backend/controller/umsAdmin/UmsUserController.java index 97964bd..7a46257 100644 --- a/src/main/java/com/teaching/backend/controller/umsAdmin/UmsAdminController.java +++ b/src/main/java/com/teaching/backend/controller/umsAdmin/UmsUserController.java @@ -1,16 +1,14 @@ package com.teaching.backend.controller.umsAdmin; -import cn.hutool.core.collection.CollUtil; import com.teaching.backend.common.CommonResult; import com.teaching.backend.common.BaseResponse; import com.teaching.backend.common.ResultUtils; -import com.teaching.backend.model.dto.UmsAdminParam; -import com.teaching.backend.model.dto.UpdateAdminPasswordParam; +import com.teaching.backend.model.dto.umsAdmin.UmsUserParam; +import com.teaching.backend.model.dto.umsAdmin.UpdateUserPasswordParam; import com.teaching.backend.model.dto.umsAdmin.UmsStudentAndTeacherDTO; -import com.teaching.backend.model.entity.umsAdmin.UmsAdmin; -import com.teaching.backend.model.entity.umsAdmin.UmsRole; +import com.teaching.backend.model.entity.umsAdmin.UmsUser; import com.teaching.backend.model.vo.courses.TeacherInfVO; -import com.teaching.backend.service.umsAdmin.UmsAdminService; +import com.teaching.backend.service.umsAdmin.UmsUserService; import com.teaching.backend.service.umsAdmin.UmsRoleService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; @@ -24,7 +22,6 @@ import java.security.Principal; import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.stream.Collectors; /** @@ -36,31 +33,31 @@ import java.util.stream.Collectors; @Api(tags = "UmsAdminController") @RequestMapping("/api/user") @Slf4j -public class UmsAdminController { +public class UmsUserController { @Value("${jwt.tokenHeader}") private String tokenHeader; @Value("${jwt.tokenHead}") private String tokenHead; @Autowired - private UmsAdminService umsAdminService; + private UmsUserService umsUserService; @Autowired private UmsRoleService umsRoleService; @ApiOperation(value = "用户注册") @PostMapping("/register") - public CommonResult register(@Validated @RequestBody UmsAdminParam umsAdminParam) { - if (umsAdminParam == null) { + public CommonResult register(@Validated @RequestBody UmsUserParam umsUserParam) { + if (umsUserParam == null) { return CommonResult.failed(); } - UmsAdmin umsAdmin = umsAdminService.register(umsAdminParam); - return CommonResult.success(umsAdmin); + UmsUser umsUser = umsUserService.register(umsUserParam); + return CommonResult.success(umsUser); } @ApiOperation(value = "用户名登录以后返回token") @PostMapping("/login") - public CommonResult login(@Validated @RequestBody UmsAdmin umsAdmin) { - String token = umsAdminService.login(umsAdmin.getUsername(), umsAdmin.getPassword()); + public CommonResult login(@Validated @RequestBody UmsUser umsUser) { + String token = umsUserService.login(umsUser.getUsername(), umsUser.getPassword()); if (token == null) { return CommonResult.validateFailed("用户名或密码错误"); } @@ -73,7 +70,7 @@ public class UmsAdminController { @ApiOperation(value = "手机号登录以后返回token") @PostMapping("/phone/login") public CommonResult phoneLogin(@RequestParam("phone")String phone) { - String token = umsAdminService.phoneLogin(phone); + String token = umsUserService.phoneLogin(phone); if (token == null) { return CommonResult.validateFailed("手机号不存在!"); } @@ -91,24 +88,24 @@ public class UmsAdminController { @ApiOperation(value = "发送短信返回验证码") @PostMapping("/code") public CommonResult sendVerifyCode(@RequestParam("phone")String phone){ - return CommonResult.success(umsAdminService.sendVerifyCode(phone)); + return CommonResult.success(umsUserService.sendVerifyCode(phone)); } @ApiOperation(value = "手机号注册") @PostMapping("/phone/register") - public CommonResult phoneRegister(@Validated @RequestBody UmsAdminParam umsAdminParam) { + public CommonResult phoneRegister(@Validated @RequestBody UmsUserParam umsAdminParam) { if (umsAdminParam == null) { return CommonResult.failed(); } - UmsAdmin umsAdmin = umsAdminService.phoneRegister(umsAdminParam); - return CommonResult.success(umsAdmin); + UmsUser umsUser = umsUserService.phoneRegister(umsAdminParam); + return CommonResult.success(umsUser); } @ApiOperation(value = "刷新token") @GetMapping("/refreshToken") public CommonResult refreshToken(HttpServletRequest request) { String token = request.getHeader(tokenHeader); - String refreshToken = umsAdminService.refreshToken(token); + String refreshToken = umsUserService.refreshToken(token); if (refreshToken == null) { return CommonResult.failed("token已经过期!"); } @@ -126,26 +123,22 @@ public class UmsAdminController { return CommonResult.unauthorized("用户名为空"); } String username = principal.getName(); - UmsAdmin umsAdmin = umsAdminService.getAdminByUsername(username); + UmsUser umsUser = umsUserService.getUserByUsername(username); Map data = new HashMap<>(); - data.put("id",umsAdmin.getId()); - data.put("username", umsAdmin.getUsername()); - data.put("menus", umsRoleService.getMenuList(umsAdmin.getId())); - data.put("phone", umsAdmin.getPhone()); - data.put("nickName", umsAdmin.getNickName()); - data.put("icon", umsAdmin.getIcon()); - List roleList = umsAdminService.getRoleList(umsAdmin.getId()); - if(CollUtil.isNotEmpty(roleList)){ - List roles = roleList.stream().map(UmsRole::getName).collect(Collectors.toList()); - data.put("roles",roles); - } + data.put("id",umsUser.getId()); + data.put("username", umsUser.getUsername()); + data.put("permissions", umsRoleService.getPermissionList(umsUser.getRoleId())); + data.put("phone", umsUser.getPhone()); + data.put("nickName", umsUser.getNickName()); + data.put("icon", umsUser.getIcon()); + data.put("roles",umsRoleService.getRoleList(umsUser.getRoleId())); return CommonResult.success(data); } @ApiOperation("修改指定用户信息") @PostMapping("/update") - public CommonResult updateUms(@RequestBody UmsAdmin umsadmin) { - boolean count = umsAdminService.updateUms(umsadmin); + public CommonResult updateUms(@RequestBody UmsUser umsUser) { + boolean count = umsUserService.updateUms(umsUser); if (count == true) { return CommonResult.success(count); } @@ -154,16 +147,10 @@ public class UmsAdminController { @ApiOperation("修改指定用户密码") @PostMapping("/updatePassword") - public CommonResult updatePassword(@Validated @RequestBody UpdateAdminPasswordParam updatePasswordParam) { - int status = umsAdminService.updatePassword(updatePasswordParam); - if (status > 0) { + public CommonResult updatePassword(@Validated @RequestBody UpdateUserPasswordParam updatePasswordParam) { + int status = umsUserService.updatePassword(updatePasswordParam); + if (status == 1) { return CommonResult.success(status); - } else if (status == -1) { - return CommonResult.failed("提交参数不合法"); - } else if (status == -2) { - return CommonResult.failed("找不到该用户"); - } else if (status == -3) { - return CommonResult.failed("旧密码错误"); } else { return CommonResult.failed(); } @@ -175,7 +162,7 @@ public class UmsAdminController { if (id == null){ return CommonResult.failed("参数为空"); } - Object count = umsAdminService.getByIdPersonalInfo(id); + Object count = umsUserService.getByIdPersonalInfo(id); if (count == null) { return CommonResult.failed(); } @@ -185,7 +172,7 @@ public class UmsAdminController { @ApiOperation("修改指定个人信息") @PostMapping("/update/PersonalInfo") public CommonResult updatePersonalInfo(@RequestBody UmsStudentAndTeacherDTO umsStudentAndTeacherDTO) { - boolean count = umsAdminService.updatePersonalInfo(umsStudentAndTeacherDTO); + boolean count = umsUserService.updatePersonalInfo(umsStudentAndTeacherDTO); if (count == true) { return CommonResult.success("修改成功"); } @@ -195,7 +182,7 @@ public class UmsAdminController { @ApiOperation("获取教师信息列表,关联教师的username和name") @GetMapping("/get_teacherinf_list") public BaseResponse> getTeacherInfList(){ - List teacherInfVO = umsAdminService.getTeacherInfList(); + List teacherInfVO = umsUserService.getTeacherInfList(); return ResultUtils.success(teacherInfVO); } diff --git a/src/main/java/com/teaching/backend/mapper/umsAdmin/UmsRoleMapper.java b/src/main/java/com/teaching/backend/mapper/umsAdmin/UmsRoleMapper.java index f702a8f..d25043c 100644 --- a/src/main/java/com/teaching/backend/mapper/umsAdmin/UmsRoleMapper.java +++ b/src/main/java/com/teaching/backend/mapper/umsAdmin/UmsRoleMapper.java @@ -2,8 +2,6 @@ package com.teaching.backend.mapper.umsAdmin; import com.baomidou.mybatisplus.core.mapper.BaseMapper; -import com.teaching.backend.model.entity.umsAdmin.UmsAdminRoleRelation; -import com.teaching.backend.model.entity.umsAdmin.UmsMenu; import com.teaching.backend.model.entity.umsAdmin.UmsRole; import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Param; @@ -19,7 +17,7 @@ public interface UmsRoleMapper extends BaseMapper { /** * 根据后台用户ID获取菜单 */ - List getMenuList(@Param("adminId") Long adminId); +// List getMenuList(@Param("adminId") Long adminId); // /** // * 根据角色ID获取菜单 // */ diff --git a/src/main/java/com/teaching/backend/mapper/umsAdmin/UmsStudentMapper.java b/src/main/java/com/teaching/backend/mapper/umsAdmin/UmsStudentMapper.java index 146dfab..438b200 100644 --- a/src/main/java/com/teaching/backend/mapper/umsAdmin/UmsStudentMapper.java +++ b/src/main/java/com/teaching/backend/mapper/umsAdmin/UmsStudentMapper.java @@ -14,4 +14,5 @@ import com.teaching.backend.model.entity.umsAdmin.UmsStudent; public interface UmsStudentMapper extends BaseMapper { boolean updateStudentInfo(UmsStudent umsStudent); + UmsStudent selectByUserId(Integer userId); } diff --git a/src/main/java/com/teaching/backend/mapper/umsAdmin/UmsTeacherMapper.java b/src/main/java/com/teaching/backend/mapper/umsAdmin/UmsTeacherMapper.java index acbf47d..a5d85b8 100644 --- a/src/main/java/com/teaching/backend/mapper/umsAdmin/UmsTeacherMapper.java +++ b/src/main/java/com/teaching/backend/mapper/umsAdmin/UmsTeacherMapper.java @@ -14,4 +14,5 @@ import com.teaching.backend.model.entity.umsAdmin.UmsTeacher; public interface UmsTeacherMapper extends BaseMapper { boolean updateTeacherInfo(UmsTeacher umsTeacher); + UmsTeacher selectByUserId(Integer userId); } diff --git a/src/main/java/com/teaching/backend/mapper/umsAdmin/UmsAdminMapper.java b/src/main/java/com/teaching/backend/mapper/umsAdmin/UmsUserMapper.java similarity index 72% rename from src/main/java/com/teaching/backend/mapper/umsAdmin/UmsAdminMapper.java rename to src/main/java/com/teaching/backend/mapper/umsAdmin/UmsUserMapper.java index c2f056d..c1d1a74 100644 --- a/src/main/java/com/teaching/backend/mapper/umsAdmin/UmsAdminMapper.java +++ b/src/main/java/com/teaching/backend/mapper/umsAdmin/UmsUserMapper.java @@ -1,16 +1,16 @@ package com.teaching.backend.mapper.umsAdmin; import com.baomidou.mybatisplus.core.mapper.BaseMapper; -import com.teaching.backend.model.entity.umsAdmin.UmsAdmin; import com.teaching.backend.model.entity.umsAdmin.UmsRole; import com.teaching.backend.model.entity.umsAdmin.UmsTeacher; +import com.teaching.backend.model.entity.umsAdmin.UmsUser; import com.teaching.backend.model.vo.umsAdmin.UmsStudentVO; import org.apache.ibatis.annotations.Mapper; @Mapper -public interface UmsAdminMapper extends BaseMapper { +public interface UmsUserMapper extends BaseMapper { - boolean updateUserInformation(UmsAdmin umsadmin); + boolean updateUserInformation(UmsUser umsUser); UmsRole getByIdRoleInfo(String id); diff --git a/src/main/java/com/teaching/backend/model/dto/umsAdmin/UmsStudentAndTeacherDTO.java b/src/main/java/com/teaching/backend/model/dto/umsAdmin/UmsStudentAndTeacherDTO.java index 812fe34..4d8d3b5 100644 --- a/src/main/java/com/teaching/backend/model/dto/umsAdmin/UmsStudentAndTeacherDTO.java +++ b/src/main/java/com/teaching/backend/model/dto/umsAdmin/UmsStudentAndTeacherDTO.java @@ -92,7 +92,7 @@ public class UmsStudentAndTeacherDTO implements Serializable { /** * 学位 */ - private String degree; + private String academicDegree; /** * 职称 @@ -114,6 +114,11 @@ public class UmsStudentAndTeacherDTO implements Serializable { */ private String politicalStatus; + /** + * user_id + */ + private Integer userId; + /** * role_id */ diff --git a/src/main/java/com/teaching/backend/model/dto/UmsAdminParam.java b/src/main/java/com/teaching/backend/model/dto/umsAdmin/UmsUserParam.java similarity index 56% rename from src/main/java/com/teaching/backend/model/dto/UmsAdminParam.java rename to src/main/java/com/teaching/backend/model/dto/umsAdmin/UmsUserParam.java index 8bdac88..43f83d6 100644 --- a/src/main/java/com/teaching/backend/model/dto/UmsAdminParam.java +++ b/src/main/java/com/teaching/backend/model/dto/umsAdmin/UmsUserParam.java @@ -1,16 +1,13 @@ -package com.teaching.backend.model.dto; +package com.teaching.backend.model.dto.umsAdmin; -import com.baomidou.mybatisplus.annotation.IdType; -import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableName; import lombok.Data; import java.io.Serializable; -import java.time.LocalDateTime; @Data -@TableName("ums_admin") -public class UmsAdminParam implements Serializable { +@TableName("ums_user") +public class UmsUserParam implements Serializable { //用户名 private String username; diff --git a/src/main/java/com/teaching/backend/model/dto/UpdateAdminPasswordParam.java b/src/main/java/com/teaching/backend/model/dto/umsAdmin/UpdateUserPasswordParam.java similarity index 84% rename from src/main/java/com/teaching/backend/model/dto/UpdateAdminPasswordParam.java rename to src/main/java/com/teaching/backend/model/dto/umsAdmin/UpdateUserPasswordParam.java index b7add78..6f78b14 100644 --- a/src/main/java/com/teaching/backend/model/dto/UpdateAdminPasswordParam.java +++ b/src/main/java/com/teaching/backend/model/dto/umsAdmin/UpdateUserPasswordParam.java @@ -1,4 +1,4 @@ -package com.teaching.backend.model.dto; +package com.teaching.backend.model.dto.umsAdmin; import io.swagger.annotations.ApiModelProperty; import lombok.Data; @@ -9,7 +9,7 @@ import lombok.Data; * Created by macro on 2019/10/9. */ @Data -public class UpdateAdminPasswordParam { +public class UpdateUserPasswordParam { // @NotEmpty @ApiModelProperty(value = "用户名", required = true) private String username; diff --git a/src/main/java/com/teaching/backend/model/entity/umsAdmin/AdminUserDetails.java b/src/main/java/com/teaching/backend/model/entity/umsAdmin/AdminUserDetails.java index 757fd4b..ffb8ff4 100644 --- a/src/main/java/com/teaching/backend/model/entity/umsAdmin/AdminUserDetails.java +++ b/src/main/java/com/teaching/backend/model/entity/umsAdmin/AdminUserDetails.java @@ -15,11 +15,11 @@ import java.util.stream.Collectors; */ public class AdminUserDetails implements UserDetails { //后台用户 - private final UmsAdmin umsAdmin; + private final UmsUser umsAdmin; //拥有资源列表 private final List resourceList; - public AdminUserDetails(UmsAdmin umsAdmin, List resourceList) { + public AdminUserDetails(UmsUser umsAdmin, List resourceList) { this.umsAdmin = umsAdmin; this.resourceList = resourceList; } diff --git a/src/main/java/com/teaching/backend/model/entity/umsAdmin/UmsMenu.java b/src/main/java/com/teaching/backend/model/entity/umsAdmin/UmsMenu.java deleted file mode 100644 index 64b4d0b..0000000 --- a/src/main/java/com/teaching/backend/model/entity/umsAdmin/UmsMenu.java +++ /dev/null @@ -1,41 +0,0 @@ -package com.teaching.backend.model.entity.umsAdmin; - -import com.baomidou.mybatisplus.annotation.TableName; -import io.swagger.annotations.ApiModelProperty; -import lombok.Data; - -import java.io.Serializable; -import java.util.Date; - -@Data -@TableName("ums_menu") -public class UmsMenu implements Serializable { - private Long id; - - @ApiModelProperty(value = "父级ID") - private Long parentId; - - @ApiModelProperty(value = "创建时间") - private Date createTime; - - @ApiModelProperty(value = "菜单名称") - private String title; - - @ApiModelProperty(value = "菜单级数") - private Integer level; - - @ApiModelProperty(value = "菜单排序") - private Integer sort; - - @ApiModelProperty(value = "前端名称") - private String name; - - @ApiModelProperty(value = "前端图标") - private String icon; - - @ApiModelProperty(value = "前端隐藏") - private Integer hidden; - - private static final long serialVersionUID = 1L; - -} diff --git a/src/main/java/com/teaching/backend/model/entity/umsAdmin/UmsPermission.java b/src/main/java/com/teaching/backend/model/entity/umsAdmin/UmsPermission.java new file mode 100644 index 0000000..591c760 --- /dev/null +++ b/src/main/java/com/teaching/backend/model/entity/umsAdmin/UmsPermission.java @@ -0,0 +1,24 @@ +package com.teaching.backend.model.entity.umsAdmin; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.Data; + +import java.io.Serializable; +import java.util.Date; + +@Data +@TableName("ums_permission") +public class UmsPermission implements Serializable { + + //主键 + @TableId(type = IdType.AUTO) + private Long id; + + //菜单名称 + private String name; + + //创建时间 + private Date createTime; +} diff --git a/src/main/java/com/teaching/backend/model/entity/umsAdmin/UmsRole.java b/src/main/java/com/teaching/backend/model/entity/umsAdmin/UmsRole.java index eaeb260..b4a484e 100644 --- a/src/main/java/com/teaching/backend/model/entity/umsAdmin/UmsRole.java +++ b/src/main/java/com/teaching/backend/model/entity/umsAdmin/UmsRole.java @@ -1,5 +1,7 @@ package com.teaching.backend.model.entity.umsAdmin; +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableName; import io.swagger.annotations.ApiModelProperty; import lombok.Data; @@ -9,25 +11,23 @@ import java.util.Date; @Data @TableName("ums_role") public class UmsRole implements Serializable { + //主键 + @TableId(type = IdType.AUTO) private Long id; - @ApiModelProperty(value = "名称") + //名称 private String name; - @ApiModelProperty(value = "描述") + //描述 private String description; - @ApiModelProperty(value = "后台用户数量") - private Integer adminCount; - - @ApiModelProperty(value = "创建时间") + //创建时间 private Date createTime; - @ApiModelProperty(value = "启用状态:0->禁用;1->启用") + //启用状态:0->禁用;1->启用 private Integer status; - private Integer sort; - - private static final long serialVersionUID = 1L; + //权限id + private String permissionId; } diff --git a/src/main/java/com/teaching/backend/model/entity/umsAdmin/UmsStudent.java b/src/main/java/com/teaching/backend/model/entity/umsAdmin/UmsStudent.java index 99d0e7e..ec40634 100644 --- a/src/main/java/com/teaching/backend/model/entity/umsAdmin/UmsStudent.java +++ b/src/main/java/com/teaching/backend/model/entity/umsAdmin/UmsStudent.java @@ -26,62 +26,40 @@ public class UmsStudent implements Serializable { private static final long serialVersionUID = 1L; - @TableId(value = "id", type = IdType.ASSIGN_ID) + @TableId(value = "id", type = IdType.AUTO) private Integer id; - /** - * 姓名 - */ + //姓名 private String name; - /** - * 性别 - */ + //性别 private String sex; - /** - * 民族 - */ + //民族 private String nationality; - /** - * 学号 - */ + //学号 private String number; - /** - * 生日 - */ + //生日 private LocalDateTime birthday; - /** - * 手机号 - */ + //手机号 private String phone; - /** - * 院系 - */ + //院系 private String faculty; - /** - * 专业 - */ + //专业 private String major; - /** - * 入学年份 - */ + //入学年份 private LocalDate yearAge; - /** - * 班级 - */ + //班级 private String className; - /** - * user_id - */ + //user_id private Integer userId; diff --git a/src/main/java/com/teaching/backend/model/entity/umsAdmin/UmsTeacher.java b/src/main/java/com/teaching/backend/model/entity/umsAdmin/UmsTeacher.java index 05041b8..0a185d0 100644 --- a/src/main/java/com/teaching/backend/model/entity/umsAdmin/UmsTeacher.java +++ b/src/main/java/com/teaching/backend/model/entity/umsAdmin/UmsTeacher.java @@ -11,7 +11,7 @@ import lombok.experimental.Accessors; /** *

- * + * *

* * @author zjh @@ -28,59 +28,37 @@ public class UmsTeacher implements Serializable { @TableId(value = "id", type = IdType.AUTO) private Integer id; - /** - * 姓名 - */ + //姓名 private String name; - /** - * 性别 - */ + //性别 private String sex; - /** - * 民族 - */ + //民族 private String nationality; - /** - * 专业 - */ + //专业 private String profession; - /** - * 学历 - */ + //学历 private String education; - /** - * 学位 - */ - private String degree; + //学位 + private String academicDegree; - /** - * 职称 - */ + //职称 private String professionalTitle; - /** - * 手机号 - */ + //手机号 private String emergencyContact; - /** - * 参加工作时间 - */ + //参加工作时间 private LocalDateTime joinWorkTime; - /** - * 政治面貌 - */ + //政治面貌 private String politicalStatus; - /** - * user_id - */ + //user_id private Integer userId; diff --git a/src/main/java/com/teaching/backend/model/entity/umsAdmin/UmsAdmin.java b/src/main/java/com/teaching/backend/model/entity/umsAdmin/UmsUser.java similarity index 85% rename from src/main/java/com/teaching/backend/model/entity/umsAdmin/UmsAdmin.java rename to src/main/java/com/teaching/backend/model/entity/umsAdmin/UmsUser.java index 431ad5e..d05dad7 100644 --- a/src/main/java/com/teaching/backend/model/entity/umsAdmin/UmsAdmin.java +++ b/src/main/java/com/teaching/backend/model/entity/umsAdmin/UmsUser.java @@ -9,8 +9,8 @@ import java.io.Serializable; import java.time.LocalDateTime; @Data -@TableName("ums_admin") -public class UmsAdmin implements Serializable { +@TableName("ums_user") +public class UmsUser implements Serializable { //主键 @TableId(type = IdType.AUTO) @@ -36,4 +36,7 @@ public class UmsAdmin implements Serializable { //账号状态 private Integer status; + + //角色id + private String roleId; } diff --git a/src/main/java/com/teaching/backend/model/vo/umsAdmin/UmsStudentVO.java b/src/main/java/com/teaching/backend/model/vo/umsAdmin/UmsStudentVO.java index 0c43b64..2667380 100644 --- a/src/main/java/com/teaching/backend/model/vo/umsAdmin/UmsStudentVO.java +++ b/src/main/java/com/teaching/backend/model/vo/umsAdmin/UmsStudentVO.java @@ -10,6 +10,7 @@ import lombok.experimental.Accessors; import java.io.Serializable; import java.time.LocalDate; import java.time.LocalDateTime; +import java.util.List; /** *

@@ -27,7 +28,7 @@ public class UmsStudentVO implements Serializable { private static final long serialVersionUID = 1L; - @TableId(value = "id", type = IdType.ASSIGN_ID) + @TableId(value = "id", type = IdType.AUTO) private Integer id; /** @@ -80,9 +81,14 @@ public class UmsStudentVO implements Serializable { */ private String className; + /** + * user_id + */ + private Integer userId; + /** * role_id */ - private Integer roleId; + private List roleId; } diff --git a/src/main/java/com/teaching/backend/model/vo/umsAdmin/UmsTeacherVO.java b/src/main/java/com/teaching/backend/model/vo/umsAdmin/UmsTeacherVO.java index cba0af8..41edbd5 100644 --- a/src/main/java/com/teaching/backend/model/vo/umsAdmin/UmsTeacherVO.java +++ b/src/main/java/com/teaching/backend/model/vo/umsAdmin/UmsTeacherVO.java @@ -9,6 +9,7 @@ import lombok.experimental.Accessors; import java.io.Serializable; import java.time.LocalDateTime; +import java.util.List; /** *

@@ -57,7 +58,7 @@ public class UmsTeacherVO implements Serializable { /** * 学位 */ - private String degree; + private String academicDegree; /** * 职称 @@ -79,9 +80,14 @@ public class UmsTeacherVO implements Serializable { */ private String politicalStatus; + /** + * user_id + */ + private Integer userId; + /** * role_id */ - private Integer roleId; + private List roleId; } diff --git a/src/main/java/com/teaching/backend/service/impl/courses/CoursesServiceImpl.java b/src/main/java/com/teaching/backend/service/impl/courses/CoursesServiceImpl.java index 2c77506..94243f2 100644 --- a/src/main/java/com/teaching/backend/service/impl/courses/CoursesServiceImpl.java +++ b/src/main/java/com/teaching/backend/service/impl/courses/CoursesServiceImpl.java @@ -14,18 +14,18 @@ import com.teaching.backend.mapper.chapter.ChapterMapper; import com.teaching.backend.mapper.courses.*; import com.teaching.backend.mapper.know.KnowRelationshipMapper; import com.teaching.backend.mapper.records.LearningRecordsMapper; -import com.teaching.backend.mapper.umsAdmin.UmsAdminMapper; import com.teaching.backend.mapper.umsAdmin.UmsAdminRoleRelationMapper; import com.teaching.backend.mapper.umsAdmin.UmsTeacherMapper; +import com.teaching.backend.mapper.umsAdmin.UmsUserMapper; import com.teaching.backend.model.dto.courses.CoursesDTO; import com.teaching.backend.model.dto.courses.PageDTO; import com.teaching.backend.model.entity.chapter.Chapter; import com.teaching.backend.model.entity.courses.*; import com.teaching.backend.model.entity.know.KnowRelationship; import com.teaching.backend.model.entity.records.LearningRecords; -import com.teaching.backend.model.entity.umsAdmin.UmsAdmin; import com.teaching.backend.model.entity.umsAdmin.UmsAdminRoleRelation; import com.teaching.backend.model.entity.umsAdmin.UmsTeacher; +import com.teaching.backend.model.entity.umsAdmin.UmsUser; import com.teaching.backend.model.query.CourseQuery; import com.teaching.backend.model.vo.courses.CourseObjectivesTreeVO; import com.teaching.backend.model.vo.courses.CoursesVO; @@ -82,7 +82,7 @@ public class CoursesServiceImpl extends ServiceImpl impl @Autowired ObjectivesTypeMapper objectivesTypeMapper; @Autowired - UmsAdminMapper umsAdminMapper; + UmsUserMapper umsUserMapper; @Autowired UmsTeacherMapper umsTeacherMapper; @Autowired @@ -158,8 +158,8 @@ public class CoursesServiceImpl extends ServiceImpl impl // throw new BusinessException(ErrorCode.USERNAME_NOT_EXIT); // } - UmsAdmin umsAdmin = umsAdminMapper.selectOne(new LambdaQueryWrapper() - .eq(UmsAdmin::getUsername, username)); + UmsUser umsAdmin = umsUserMapper.selectOne(new LambdaQueryWrapper() + .eq(UmsUser::getUsername, username)); UmsAdminRoleRelation umsAdminRoleRelation = umsAdminRoleRelationMapper.selectOne(new LambdaQueryWrapper() .eq(UmsAdminRoleRelation::getAdminId, umsAdmin.getId())); @@ -225,14 +225,14 @@ public class CoursesServiceImpl extends ServiceImpl impl List teacherNameList = new ArrayList<>(); String[] teacherIds = coursesVO.getTeacher().split(","); for (String teacherId : teacherIds) { - UmsAdmin umsAdminTea = umsAdminMapper.selectOne(new LambdaQueryWrapper() - .eq(UmsAdmin::getUsername, teacherId)); - if (umsAdminTea == null) { + UmsUser umsUserTea = umsUserMapper.selectOne(new LambdaQueryWrapper() + .eq(UmsUser::getUsername, teacherId)); + if (umsUserTea == null) { throw new BusinessException(ErrorCode.OPERATION_ERROR); } // System.out.println(umsAdminTea); UmsTeacher umsTeacher = umsTeacherMapper.selectOne(new LambdaQueryWrapper() - .eq(UmsTeacher::getUserId, umsAdminTea.getId())); + .eq(UmsTeacher::getUserId, umsUserTea.getId())); System.out.println(umsTeacher); if (umsTeacher == null){ throw new BusinessException(ErrorCode.PARAMS_USER_NOTEXISTS); @@ -308,6 +308,7 @@ public class CoursesServiceImpl extends ServiceImpl impl // List list = coursesMapper.selectList(null); List coursesVo = BeanUtil.copyToList(list, CoursesVO.class); coursesVo = coursesVo.stream().map((item) -> { + item.setTotalHours(countHours(item.getId())); item.setTotalchapter(countChapters(item.getId())); item.setTotalKnow(countKnow(item.getId())); diff --git a/src/main/java/com/teaching/backend/service/impl/courses/StudentCoursesServiceImpl.java b/src/main/java/com/teaching/backend/service/impl/courses/StudentCoursesServiceImpl.java index c975735..7b83c8a 100644 --- a/src/main/java/com/teaching/backend/service/impl/courses/StudentCoursesServiceImpl.java +++ b/src/main/java/com/teaching/backend/service/impl/courses/StudentCoursesServiceImpl.java @@ -9,23 +9,18 @@ import com.teaching.backend.common.ErrorCode; import com.teaching.backend.exception.BusinessException; import com.teaching.backend.mapper.courses.CoursesMapper; import com.teaching.backend.mapper.courses.StudentCoursesMapper; -import com.teaching.backend.mapper.umsAdmin.UmsAdminMapper; +import com.teaching.backend.mapper.umsAdmin.UmsUserMapper; import com.teaching.backend.mapper.umsAdmin.UmsTeacherMapper; -import com.teaching.backend.model.dto.courses.ObjectiveContentKnowDTO; import com.teaching.backend.model.dto.courses.PageDTO; import com.teaching.backend.model.dto.courses.StudentCoursesDTO; import com.teaching.backend.model.entity.courses.Courses; -import com.teaching.backend.model.entity.courses.ObjectiveContentKnow; import com.teaching.backend.model.entity.courses.StudentCourses; -import com.teaching.backend.model.entity.umsAdmin.UmsAdmin; -import com.teaching.backend.model.entity.umsAdmin.UmsTeacher; import com.teaching.backend.model.query.CourseQuery; import com.teaching.backend.model.vo.courses.CoursesVO; import com.teaching.backend.service.courses.ICoursesService; import com.teaching.backend.service.courses.IStudentCoursesService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; import java.util.ArrayList; import java.util.Arrays; @@ -46,7 +41,7 @@ public class StudentCoursesServiceImpl extends ServiceImpl listCourseFavourByPage(String userId, Integer type, Integer page, Integer pageSize) { - UmsAdmin umsAdmin = umsAdminMapper.selectById(userId); + UmsUser umsAdmin = umsAdminMapper.selectById(userId); if(umsAdmin == null){ throw new BusinessException(ErrorCode.PARAMS_USER_NOTEXISTS); } diff --git a/src/main/java/com/teaching/backend/service/umsAdmin/UmsRoleService.java b/src/main/java/com/teaching/backend/service/umsAdmin/UmsRoleService.java index 4eb76ef..1fb0488 100644 --- a/src/main/java/com/teaching/backend/service/umsAdmin/UmsRoleService.java +++ b/src/main/java/com/teaching/backend/service/umsAdmin/UmsRoleService.java @@ -1,10 +1,5 @@ package com.teaching.backend.service.umsAdmin; -import com.teaching.backend.model.entity.umsAdmin.UmsMenu; -import com.teaching.backend.model.entity.umsAdmin.UmsResource; -import com.teaching.backend.model.entity.umsAdmin.UmsRole; -import org.springframework.transaction.annotation.Transactional; - import java.util.List; /** @@ -14,8 +9,10 @@ import java.util.List; public interface UmsRoleService { /** - * 根据管理员ID获取对应菜单 + * 根据角色id获取对应权限 */ - List getMenuList(Long adminId); + List getPermissionList(String roleId); + + List getRoleList(String roleId); } diff --git a/src/main/java/com/teaching/backend/service/umsAdmin/UmsAdminService.java b/src/main/java/com/teaching/backend/service/umsAdmin/UmsUserService.java similarity index 72% rename from src/main/java/com/teaching/backend/service/umsAdmin/UmsAdminService.java rename to src/main/java/com/teaching/backend/service/umsAdmin/UmsUserService.java index 9a9ff4a..d913cc8 100644 --- a/src/main/java/com/teaching/backend/service/umsAdmin/UmsAdminService.java +++ b/src/main/java/com/teaching/backend/service/umsAdmin/UmsUserService.java @@ -1,23 +1,23 @@ package com.teaching.backend.service.umsAdmin; import com.baomidou.mybatisplus.extension.service.IService; -import com.teaching.backend.model.dto.UmsAdminParam; -import com.teaching.backend.model.dto.UpdateAdminPasswordParam; +import com.teaching.backend.model.dto.umsAdmin.UmsUserParam; +import com.teaching.backend.model.dto.umsAdmin.UpdateUserPasswordParam; import com.teaching.backend.model.dto.umsAdmin.UmsStudentAndTeacherDTO; -import com.teaching.backend.model.entity.umsAdmin.UmsAdmin; import com.teaching.backend.model.entity.umsAdmin.UmsResource; import com.teaching.backend.model.entity.umsAdmin.UmsRole; +import com.teaching.backend.model.entity.umsAdmin.UmsUser; import com.teaching.backend.model.vo.courses.TeacherInfVO; import org.springframework.security.core.userdetails.UserDetails; import java.util.List; -public interface UmsAdminService extends IService { +public interface UmsUserService extends IService { /** * 注册功能 */ - UmsAdmin register(UmsAdminParam umsAdminParam); + UmsUser register(UmsUserParam umsUserParam); /** * 登录功能 @@ -31,12 +31,12 @@ public interface UmsAdminService extends IService { /** * 根据用户名获取后台管理员 */ - UmsAdmin getAdminByUsername(String username); + UmsUser getUserByUsername(String username); /** * 获取指定用户的可访问的资源 */ - List getResourceList(Long adminId); + List getResourceList(Long userId); /** * 获取用户信息 @@ -52,17 +52,17 @@ public interface UmsAdminService extends IService { /** * 获取用户对应角色 */ - List getRoleList(Long adminId); + List getRoleList(Long userId); /** * 修改指定用户信息 */ - boolean updateUms(UmsAdmin umsadmin); + boolean updateUms(UmsUser umsUser); /** * 修改密码 */ - int updatePassword(UpdateAdminPasswordParam updatePasswordParam); + int updatePassword(UpdateUserPasswordParam updatePasswordParam); /** * 发送短信 @@ -72,7 +72,7 @@ public interface UmsAdminService extends IService { /** * 手机号注册 */ - UmsAdmin phoneRegister(UmsAdminParam umsAdminParam); + UmsUser phoneRegister(UmsUserParam umsUserParam); /** * 手机号登录 diff --git a/src/main/java/com/teaching/backend/service/umsAdmin/impl/UmsRoleServiceImpl.java b/src/main/java/com/teaching/backend/service/umsAdmin/impl/UmsRoleServiceImpl.java index b3c8d29..63a5180 100644 --- a/src/main/java/com/teaching/backend/service/umsAdmin/impl/UmsRoleServiceImpl.java +++ b/src/main/java/com/teaching/backend/service/umsAdmin/impl/UmsRoleServiceImpl.java @@ -1,26 +1,49 @@ package com.teaching.backend.service.umsAdmin.impl; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.teaching.backend.mapper.umsAdmin.UmsRoleMapper; -import com.teaching.backend.model.entity.umsAdmin.UmsMenu; import com.teaching.backend.model.entity.umsAdmin.UmsRole; import com.teaching.backend.service.umsAdmin.UmsRoleService; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; -import java.util.List; +import java.util.*; +import java.util.stream.Collectors; + /** * 后台角色管理Service实现类 * Created by macro on 2018/9/30. */ @Service -public class UmsRoleServiceImpl implements UmsRoleService { +public class UmsRoleServiceImpl extends ServiceImpl implements UmsRoleService { + + @Override + public List getPermissionList(String roleId) { + Set set = new HashSet<>(); + String[] roleList = roleId.split(","); + for (String role : roleList) { + UmsRole umsRole = lambdaQuery().eq(UmsRole::getId, role).one(); + if(umsRole.getStatus() == 1){ + String[] permissions = umsRole.getPermissionId().split(","); + List permissionList = Arrays.stream(permissions).collect(Collectors.toList()); + set.addAll(permissionList); + } + } + List permissionList = new ArrayList<>(set); - @Autowired - private UmsRoleMapper umsRoleMapper; + return permissionList; + } @Override - public List getMenuList(Long adminId) { - return umsRoleMapper.getMenuList(adminId); + public List getRoleList(String roleId) { + List roleList = new ArrayList<>(); + String[] roles = roleId.split(","); + for (String role : roles) { + UmsRole umsRole = lambdaQuery().eq(UmsRole::getId, role).one(); + if(umsRole.getStatus() == 1){ + roleList.add(role); + } + } + return roleList; } } diff --git a/src/main/java/com/teaching/backend/service/umsAdmin/impl/UmsAdminServiceImpl.java b/src/main/java/com/teaching/backend/service/umsAdmin/impl/UmsUserServiceImpl.java similarity index 65% rename from src/main/java/com/teaching/backend/service/umsAdmin/impl/UmsAdminServiceImpl.java rename to src/main/java/com/teaching/backend/service/umsAdmin/impl/UmsUserServiceImpl.java index 93649da..b5b7ca8 100644 --- a/src/main/java/com/teaching/backend/service/umsAdmin/impl/UmsAdminServiceImpl.java +++ b/src/main/java/com/teaching/backend/service/umsAdmin/impl/UmsUserServiceImpl.java @@ -7,31 +7,24 @@ import com.aliyuncs.dysmsapi.model.v20170525.SendSmsResponse; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.google.gson.Gson; -import com.teaching.backend.exception.Asserts; import com.teaching.backend.exception.BusinessException; -import com.teaching.backend.exception.LyException; -import com.teaching.backend.mapper.umsAdmin.UmsAdminMapper; -import com.teaching.backend.mapper.umsAdmin.UmsAdminRoleRelationMapper; -import com.teaching.backend.mapper.umsAdmin.UmsStudentMapper; -import com.teaching.backend.mapper.umsAdmin.UmsTeacherMapper; -import com.teaching.backend.model.dto.UmsAdminParam; -import com.teaching.backend.model.dto.UpdateAdminPasswordParam; +import com.teaching.backend.mapper.umsAdmin.*; +import com.teaching.backend.model.dto.umsAdmin.UmsUserParam; +import com.teaching.backend.model.dto.umsAdmin.UpdateUserPasswordParam; import com.teaching.backend.model.dto.umsAdmin.UmsStudentAndTeacherDTO; import com.teaching.backend.model.entity.umsAdmin.*; import com.teaching.backend.model.vo.courses.TeacherInfVO; import com.teaching.backend.model.vo.umsAdmin.UmsStudentVO; import com.teaching.backend.model.vo.umsAdmin.UmsTeacherVO; -import com.teaching.backend.service.umsAdmin.UmsAdminService; +import com.teaching.backend.service.umsAdmin.UmsUserService; import com.teaching.backend.utils.JwtTokenUtil; import com.teaching.backend.utils.RegexUtils; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.RandomStringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.springframework.amqp.core.AmqpTemplate; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.redis.core.StringRedisTemplate; import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; import org.springframework.security.core.AuthenticationException; import org.springframework.security.core.context.SecurityContextHolder; @@ -51,9 +44,9 @@ import java.util.UUID; @Service @Slf4j -public class UmsAdminServiceImpl extends ServiceImpl implements UmsAdminService { +public class UmsUserServiceImpl extends ServiceImpl implements UmsUserService { - private static final Logger LOGGER = LoggerFactory.getLogger(UmsAdminServiceImpl.class); + private static final Logger LOGGER = LoggerFactory.getLogger(UmsUserServiceImpl.class); @Autowired private JwtTokenUtil jwtTokenUtil; @Autowired @@ -65,37 +58,40 @@ public class UmsAdminServiceImpl extends ServiceImpl i @Autowired UmsTeacherMapper umsTeacherMapper; @Autowired - UmsAdminMapper umsAdminMapper; + UmsUserMapper umsUserMapper; + @Autowired + UmsRoleMapper umsRoleMapper; @Override - public UmsAdmin register(UmsAdminParam umsAdminParam) { - UmsAdmin umsAdmin = new UmsAdmin(); - BeanUtils.copyProperties(umsAdminParam, umsAdmin); - umsAdmin.setCreateTime(LocalDateTime.now()); - umsAdmin.setStatus(1); + public UmsUser register(UmsUserParam umsAdminParam) { + UmsUser umsUser = new UmsUser(); + BeanUtils.copyProperties(umsAdminParam, umsUser); + umsUser.setCreateTime(LocalDateTime.now()); + umsUser.setStatus(1); //查询是否有相同用户名的用户 - List umsAdminList = lambdaQuery() - .eq(UmsAdmin::getUsername, umsAdmin.getUsername()) + List umsAdminList = lambdaQuery() + .eq(UmsUser::getUsername, umsUser.getUsername()) .list(); if (umsAdminList.size() > 0) { throw new BusinessException(500,"用户已存在"); } //将密码进行加密操作 - String encodePassword = passwordEncoder.encode(umsAdmin.getPassword()); - umsAdmin.setPassword(encodePassword); - save(umsAdmin); + String encodePassword = passwordEncoder.encode(umsUser.getPassword()); + umsUser.setPassword(encodePassword); + + //分配角色(学生) + umsUser.setRoleId("2"); + save(umsUser); //创建学生信息(默认是学生) - UmsAdmin byUsername = lambdaQuery().eq(UmsAdmin::getUsername, umsAdmin.getUsername()) + UmsUser byUsername = lambdaQuery().eq(UmsUser::getUsername, umsUser.getUsername()) .one(); UmsStudent umsStudent = new UmsStudent(); umsStudent.setUserId(Math.toIntExact(byUsername.getId())); umsStudentMapper.insert(umsStudent); - //分配角色(学生) - adminRoleRelation.insert(byUsername.getId(), 2L); - return umsAdmin; + return umsUser; } @Override @@ -127,7 +123,7 @@ public class UmsAdminServiceImpl extends ServiceImpl i String token = null; //密码需要客户端加密后传递 try { - UmsAdmin phoneAdmin = lambdaQuery().eq(UmsAdmin::getPhone, phone) + UmsUser phoneAdmin = lambdaQuery().eq(UmsUser::getPhone, phone) .one(); if (phoneAdmin == null){ throw new BusinessException(400,"手机号未注册"); @@ -148,24 +144,39 @@ public class UmsAdminServiceImpl extends ServiceImpl i @Override public Object getByIdPersonalInfo(String id) { - UmsRole umsRole = umsAdminMapper.getByIdRoleInfo(id); - if (umsRole == null){ + UmsUser umsUser = lambdaQuery().eq(UmsUser::getId, id).one(); + if (umsUser.getRoleId() == null){ throw new BusinessException(500,"用户未分配角色"); } - if(umsRole.getStatus()==0){ + String[] roles = umsUser.getRoleId().split(","); + List roleList = new ArrayList<>(); + for (String role : roles) { + UmsRole umsRole = umsRoleMapper.selectById(role); + if(umsRole.getStatus() == 1){ + roleList.add(role); + } + } + if (roleList == null){ throw new BusinessException(500,"角色被禁用"); } - if (umsRole.getId() == 1){ - UmsTeacher teacher = umsAdminMapper.getByIdTeacher(id); - UmsTeacherVO umsTeacherVO = new UmsTeacherVO(); + + //查询个人信息 + UmsTeacher teacher = umsUserMapper.getByIdTeacher(id); + UmsTeacherVO umsTeacherVO = new UmsTeacherVO(); + if (teacher != null){ BeanUtils.copyProperties(teacher,umsTeacherVO); - umsTeacherVO.setRoleId(Math.toIntExact(umsRole.getId())); + } + umsTeacherVO.setRoleId(roleList); + if (teacher != null){ return umsTeacherVO; - }else if (umsRole.getId() == 2){ - UmsStudentVO student = umsAdminMapper.getByIdStudent(id); - UmsStudentVO umsStudentVO = new UmsStudentVO(); + } + UmsStudentVO student = umsUserMapper.getByIdStudent(id); + UmsStudentVO umsStudentVO = new UmsStudentVO(); + if (student != null){ BeanUtils.copyProperties(student,umsStudentVO); - umsStudentVO.setRoleId(Math.toIntExact(umsRole.getId())); + } + umsStudentVO.setRoleId(roleList); + if (student != null){ return umsStudentVO; } return null; @@ -174,54 +185,59 @@ public class UmsAdminServiceImpl extends ServiceImpl i @Override public boolean updatePersonalInfo(UmsStudentAndTeacherDTO umsStudentAndTeacherDTO) { - if (umsStudentAndTeacherDTO.getRoleId() == 1){ - UmsTeacher umsTeacher = new UmsTeacher(); - BeanUtils.copyProperties(umsStudentAndTeacherDTO,umsTeacher); - System.out.println(umsTeacher); + UmsTeacher umsTeacher = new UmsTeacher(); + BeanUtils.copyProperties(umsStudentAndTeacherDTO,umsTeacher); + UmsTeacher teacher = umsTeacherMapper.selectByUserId(umsTeacher.getUserId()); + + if (teacher != null){ return umsTeacherMapper.updateTeacherInfo(umsTeacher); - } else if (umsStudentAndTeacherDTO.getRoleId() == 2) { - UmsStudent umsStudent = new UmsStudent(); - BeanUtils.copyProperties(umsStudentAndTeacherDTO,umsStudent); + } + + UmsStudent umsStudent = new UmsStudent(); + BeanUtils.copyProperties(umsStudentAndTeacherDTO,umsStudent); + UmsStudent student = umsStudentMapper.selectByUserId(umsStudent.getUserId()); + + if (student != null){ return umsStudentMapper.updateStudentInfo(umsStudent); } return false; } @Override - public boolean updateUms(UmsAdmin umsadmin) { - List adminList = lambdaQuery().eq(UmsAdmin::getUsername, umsadmin.getUsername()) + public boolean updateUms(UmsUser umsUser) { + List adminList = lambdaQuery().eq(UmsUser::getUsername, umsUser.getUsername()) .list(); if (adminList.size() > 0){ throw new BusinessException(400,"用户名已存在"); } - if (!StrUtil.isEmpty(umsadmin.getPassword())){ + if (!StrUtil.isEmpty(umsUser.getPassword())){ throw new BusinessException(400,"修改操作错误1"); } - if (umsadmin.getCreateTime() != null){ + if (umsUser.getCreateTime() != null){ throw new BusinessException(400,"修改操作错误2"); } - return umsAdminMapper.updateUserInformation(umsadmin); + return umsUserMapper.updateUserInformation(umsUser); } @Override - public int updatePassword(UpdateAdminPasswordParam param) { + public int updatePassword(UpdateUserPasswordParam param) { if(StrUtil.isEmpty(param.getUsername()) ||StrUtil.isEmpty(param.getOldPassword()) ||StrUtil.isEmpty(param.getNewPassword())){ throw new BusinessException(400,"修改密码操作错误"); } - List adminList = lambdaQuery() - .eq(UmsAdmin::getUsername, param.getUsername()) + List userList = lambdaQuery() + .eq(UmsUser::getUsername, param.getUsername()) .list(); - if(CollUtil.isEmpty(adminList)){ + if(CollUtil.isEmpty(userList)){ throw new BusinessException(400,"用户名不存在"); } - UmsAdmin umsAdmin = adminList.get(0); - if(!passwordEncoder.matches(param.getOldPassword(),umsAdmin.getPassword())){ + UmsUser umsUser = userList.get(0); + if(!passwordEncoder.matches(param.getOldPassword(),umsUser.getPassword())){ throw new BusinessException(400,"密码重复"); } - umsAdmin.setPassword(passwordEncoder.encode(param.getNewPassword())); - updateById(umsAdmin); + umsUser.setPassword(passwordEncoder.encode(param.getNewPassword())); + updateById(umsUser); return 1; } @@ -231,14 +247,6 @@ public class UmsAdminServiceImpl extends ServiceImpl i throw new BusinessException(400, "手机号格式错误"); } -// UmsAdmin admin = lambdaQuery() -// .eq(UmsAdmin::getPhone, phone) -// .one(); -// if (admin != null){ -//// throw new ; -// return null; -// } - String code = RandomStringUtils.randomNumeric(5); String ALIBABA_CLOUD_ACCESS_KEY_ID = "LTAI5tF7fcDC5VTj1cVWKDU6"; @@ -267,34 +275,34 @@ public class UmsAdminServiceImpl extends ServiceImpl i } @Override - public UmsAdmin phoneRegister(UmsAdminParam umsAdminParam) { - UmsAdmin umsAdmin = new UmsAdmin(); - BeanUtils.copyProperties(umsAdminParam, umsAdmin); - umsAdmin.setCreateTime(LocalDateTime.now()); - umsAdmin.setStatus(1); + public UmsUser phoneRegister(UmsUserParam umsUserParam) { + UmsUser umsUser = new UmsUser(); + BeanUtils.copyProperties(umsUserParam, umsUser); + umsUser.setCreateTime(LocalDateTime.now()); + umsUser.setStatus(1); //查询是否有相同手机号的用户 - List umsAdminList = lambdaQuery() - .eq(UmsAdmin::getPhone,umsAdminParam.getPhone()) + List umsUserList = lambdaQuery() + .eq(UmsUser::getPhone,umsUserParam.getPhone()) .list(); - if (umsAdminList.size() > 0 ) { + if (umsUserList.size() > 0 ) { throw new BusinessException(400,"手机号已存在"); } //将密码进行加密操作 - String encodePassword = passwordEncoder.encode(umsAdmin.getPassword()); - umsAdmin.setUsername(randomUsername()); - umsAdmin.setPassword(encodePassword); - save(umsAdmin); + String encodePassword = passwordEncoder.encode(umsUser.getPassword()); + umsUser.setUsername(randomUsername()); + umsUser.setPassword(encodePassword); + //分配角色(学生) + umsUser.setRoleId("2"); + save(umsUser); //创建学生信息(默认是学生) - UmsAdmin byUsername = lambdaQuery().eq(UmsAdmin::getPhone, umsAdmin.getPhone()) + UmsUser byUsername = lambdaQuery().eq(UmsUser::getPhone, umsUser.getPhone()) .one(); UmsStudent umsStudent = new UmsStudent(); umsStudent.setUserId(Math.toIntExact(byUsername.getId())); umsStudentMapper.insert(umsStudent); - //分配角色(学生) - adminRoleRelation.insert(byUsername.getId(), 2L); - return umsAdmin; + return umsUser; } /* @@ -302,12 +310,12 @@ public class UmsAdminServiceImpl extends ServiceImpl i */ private String randomUsername(){ String username; - UmsAdmin newUsername = new UmsAdmin(); + UmsUser newUsername = new UmsUser(); do { UUID uuid = UUID.randomUUID(); // 这里只是简单地截取UUID的一部分作为用户名,但你可以根据需要进行更复杂的处理 username = uuid.toString().substring(0, 10); // 截取前10个字符作 - newUsername = lambdaQuery().eq(UmsAdmin::getUsername, username) + newUsername = lambdaQuery().eq(UmsUser::getUsername, username) .one(); } while ( newUsername != null); // 如果用户名已存在,则重新生成 return username; @@ -324,30 +332,38 @@ public class UmsAdminServiceImpl extends ServiceImpl i } @Override - public UmsAdmin getAdminByUsername(String username) { + public UmsUser getUserByUsername(String username) { //从数据库中获取 - UmsAdmin admin = lambdaQuery().eq(UmsAdmin::getUsername, username) + UmsUser user = lambdaQuery().eq(UmsUser::getUsername, username) .one(); - if (admin != null) { - return admin; + if (user != null) { + return user; } return null; } @Override - public List getResourceList(Long adminId) { + public List getResourceList(Long userId) { //从数据库中获取 - List resourceList = adminRoleRelation.getResourceList(adminId); + List resourceList = new ArrayList<>(); + + UmsUser umsUser = lambdaQuery().eq(UmsUser::getId, userId).one(); + String[] roles = umsUser.getRoleId().split(","); + List roleList = new ArrayList<>(); + for (String role : roles) { + UmsRole umsRole = umsRoleMapper.selectById(role); + resourceList = adminRoleRelation.getResourceList(umsRole.getId()); + } return resourceList; } @Override public UserDetails loadUserByUsername(String username){ //获取用户信息 - UmsAdmin admin = getAdminByUsername(username); - if (admin != null) { - List resourceList = getResourceList(admin.getId()); - return new AdminUserDetails(admin,resourceList); + UmsUser user = getUserByUsername(username); + if (user != null) { + List resourceList = getResourceList(user.getId()); + return new AdminUserDetails(user,resourceList); } throw new UsernameNotFoundException("用户名或密码错误"); } @@ -359,8 +375,8 @@ public class UmsAdminServiceImpl extends ServiceImpl i List teacherInfList = new ArrayList<>();; for (UmsTeacher umsTeacher : umsTeachers) { teacherInfVO = new TeacherInfVO(); - UmsAdmin umsAdmin = umsAdminMapper.selectOne(new LambdaQueryWrapper() - .eq(UmsAdmin::getId, umsTeacher.getUserId())); + UmsUser umsAdmin = umsUserMapper.selectOne(new LambdaQueryWrapper() + .eq(UmsUser::getId, umsTeacher.getUserId())); teacherInfVO.setName(umsTeacher.getName()); teacherInfVO.setUsername(umsAdmin.getUsername()); teacherInfList.add(teacherInfVO); diff --git a/src/main/resources/mapper/UmsRoleMapper.xml b/src/main/resources/mapper/UmsRoleMapper.xml index daaebc5..58b9f99 100644 --- a/src/main/resources/mapper/UmsRoleMapper.xml +++ b/src/main/resources/mapper/UmsRoleMapper.xml @@ -2,28 +2,28 @@ - + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/main/resources/mapper/UmsStudentMapper.xml b/src/main/resources/mapper/UmsStudentMapper.xml index d3abacf..3a452f1 100644 --- a/src/main/resources/mapper/UmsStudentMapper.xml +++ b/src/main/resources/mapper/UmsStudentMapper.xml @@ -38,4 +38,12 @@ where id = #{id,jdbcType=BIGINT} + diff --git a/src/main/resources/mapper/UmsTeacherMapper.xml b/src/main/resources/mapper/UmsTeacherMapper.xml index 4b1d14c..97122e4 100644 --- a/src/main/resources/mapper/UmsTeacherMapper.xml +++ b/src/main/resources/mapper/UmsTeacherMapper.xml @@ -20,8 +20,8 @@ education = #{education,jdbcType=VARCHAR}, - - degree = #{degree,jdbcType=TIMESTAMP}, + + academic_degree = #{academicDegree,jdbcType=TIMESTAMP}, professional_title = #{professionalTitle,jdbcType=INTEGER}, @@ -38,4 +38,12 @@ where id = #{id,jdbcType=BIGINT} + diff --git a/src/main/resources/mapper/UmsAdminMapper.xml b/src/main/resources/mapper/UmsUserMapper.xml similarity index 97% rename from src/main/resources/mapper/UmsAdminMapper.xml rename to src/main/resources/mapper/UmsUserMapper.xml index b1f7b5c..2618444 100644 --- a/src/main/resources/mapper/UmsAdminMapper.xml +++ b/src/main/resources/mapper/UmsUserMapper.xml @@ -1,6 +1,6 @@ - + update ums_admin