| | |
| | | |
| | | |
| | | import com.mindskip.xzs.context.WebContext; |
| | | import com.mindskip.xzs.domain.enums.DeptAdminEnum; |
| | | import com.mindskip.xzs.domain.enums.RoleEnum; |
| | | import com.mindskip.xzs.domain.enums.UserStatusEnum; |
| | | import com.mindskip.xzs.repository.DepartmentMapper; |
| | | import com.mindskip.xzs.service.AuthenticationService; |
| | | import com.mindskip.xzs.service.UserService; |
| | | import lombok.RequiredArgsConstructor; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.security.authentication.AuthenticationProvider; |
| | | import org.springframework.security.authentication.BadCredentialsException; |
| | |
| | | * @date 2021/12/25 9:45 |
| | | */ |
| | | @Component |
| | | @RequiredArgsConstructor |
| | | public class RestAuthenticationProvider implements AuthenticationProvider { |
| | | |
| | | private final AuthenticationService authenticationService; |
| | | private final UserService userService; |
| | | private final WebContext webContext; |
| | | |
| | | /** |
| | | * Instantiates a new Rest authentication provider. |
| | | * |
| | | * @param authenticationService the authentication service |
| | | * @param userService the user service |
| | | * @param webContext the web context |
| | | */ |
| | | @Autowired |
| | | public RestAuthenticationProvider(AuthenticationService authenticationService, UserService userService, WebContext webContext) { |
| | | this.authenticationService = authenticationService; |
| | | this.userService = userService; |
| | | this.webContext = webContext; |
| | | } |
| | | private final DepartmentMapper departmentMapper; |
| | | |
| | | @Override |
| | | public Authentication authenticate(Authentication authentication) throws AuthenticationException { |
| | |
| | | throw new LockedException("用户被禁用"); |
| | | } |
| | | |
| | | // // 查询该用户是不是部门管理员 |
| | | // Integer num = departmentMapper.countByAdminId(user.getId()); |
| | | |
| | | ArrayList<GrantedAuthority> grantedAuthorities = new ArrayList<>(); |
| | | // 赋予部门管理员角色 |
| | | if (DeptAdminEnum.YES.getValue().equals(user.getDeptAdmin())) { |
| | | grantedAuthorities.add(new SimpleGrantedAuthority(RoleEnum.DEPT_ADMIN.getRoleName())); |
| | | } |
| | | grantedAuthorities.add(new SimpleGrantedAuthority(RoleEnum.fromCode(user.getRole()).getRoleName())); |
| | | |
| | | User authUser = new User(user.getUserName(), user.getPassword(), grantedAuthorities); |
| | |
| | | com.mindskip.xzs.domain.User newUser = new com.mindskip.xzs.domain.User(); |
| | | newUser.setUserName(user.getUserName()); |
| | | newUser.setImagePath(user.getImagePath()); |
| | | // 返回是否部门管理员的标识 |
| | | newUser.setDeptAdmin(user.getDeptAdmin()); |
| | | RestUtil.response(response, SystemCode.OK.getCode(), SystemCode.OK.getMessage(), newUser); |
| | | } |
| | | } else { |
| | |
| | | .authorizeRequests() |
| | | .antMatchers(securityIgnoreUrls.toArray(ignores)).permitAll() |
| | | .antMatchers("/api/admin/department/list", "/api/admin/video/getList","/api/admin/user/conversion","/api/admin/examPaperGrade/updates").permitAll() |
| | | .antMatchers("/api/admin/**").hasRole(RoleEnum.ADMIN.getName()) |
| | | // todo 设置部门管理员可以看的请求 |
| | | .antMatchers("/api/admin/**").hasAnyRole(RoleEnum.ADMIN.getName(), RoleEnum.DEPT_ADMIN.getName()) |
| | | .antMatchers("/api/student/**").hasRole(RoleEnum.STUDENT.getName()) |
| | | .anyRequest().permitAll() |
| | | .and().exceptionHandling().accessDeniedHandler(restAccessDeniedHandler) |
| | |
| | | package com.mindskip.xzs.domain; |
| | | |
| | | import lombok.Data; |
| | | |
| | | import java.io.Serializable; |
| | | import java.util.Date; |
| | | |
| | | @Data |
| | | public class User implements Serializable { |
| | | |
| | | private static final long serialVersionUID = -7797183521247423117L; |
| | |
| | | private String wxOpenId; |
| | | private String deptIds; |
| | | |
| | | public Integer getId() { |
| | | return id; |
| | | } |
| | | |
| | | public void setId(Integer id) { |
| | | this.id = id; |
| | | } |
| | | |
| | | public String getUserUuid() { |
| | | return userUuid; |
| | | } |
| | | |
| | | public void setUserUuid(String userUuid) { |
| | | this.userUuid = userUuid == null ? null : userUuid.trim(); |
| | | } |
| | | |
| | | public String getUserName() { |
| | | return userName; |
| | | } |
| | | |
| | | public void setUserName(String userName) { |
| | | this.userName = userName == null ? null : userName.trim(); |
| | | } |
| | | |
| | | public String getPassword() { |
| | | return password; |
| | | } |
| | | |
| | | public void setPassword(String password) { |
| | | this.password = password == null ? null : password.trim(); |
| | | } |
| | | |
| | | public String getRealName() { |
| | | return realName; |
| | | } |
| | | |
| | | public void setRealName(String realName) { |
| | | this.realName = realName == null ? null : realName.trim(); |
| | | } |
| | | |
| | | public Integer getAge() { |
| | | return age; |
| | | } |
| | | |
| | | public void setAge(Integer age) { |
| | | this.age = age; |
| | | } |
| | | |
| | | public Integer getSex() { |
| | | return sex; |
| | | } |
| | | |
| | | public void setSex(Integer sex) { |
| | | this.sex = sex; |
| | | } |
| | | |
| | | public Date getBirthDay() { |
| | | return birthDay; |
| | | } |
| | | |
| | | public void setBirthDay(Date birthDay) { |
| | | this.birthDay = birthDay; |
| | | } |
| | | |
| | | public Integer getUserLevel() { |
| | | return userLevel; |
| | | } |
| | | |
| | | public void setUserLevel(Integer userLevel) { |
| | | this.userLevel = userLevel; |
| | | } |
| | | |
| | | public String getPhone() { |
| | | return phone; |
| | | } |
| | | |
| | | public void setPhone(String phone) { |
| | | this.phone = phone == null ? null : phone.trim(); |
| | | } |
| | | |
| | | public Integer getRole() { |
| | | return role; |
| | | } |
| | | |
| | | public void setRole(Integer role) { |
| | | this.role = role; |
| | | } |
| | | |
| | | public Integer getStatus() { |
| | | return status; |
| | | } |
| | | |
| | | public void setStatus(Integer status) { |
| | | this.status = status; |
| | | } |
| | | |
| | | public String getImagePath() { |
| | | return imagePath; |
| | | } |
| | | |
| | | public void setImagePath(String imagePath) { |
| | | this.imagePath = imagePath == null ? null : imagePath.trim(); |
| | | } |
| | | |
| | | public Date getCreateTime() { |
| | | return createTime; |
| | | } |
| | | |
| | | public void setCreateTime(Date createTime) { |
| | | this.createTime = createTime; |
| | | } |
| | | |
| | | public Date getModifyTime() { |
| | | return modifyTime; |
| | | } |
| | | |
| | | public void setModifyTime(Date modifyTime) { |
| | | this.modifyTime = modifyTime; |
| | | } |
| | | |
| | | public Date getLastActiveTime() { |
| | | return lastActiveTime; |
| | | } |
| | | |
| | | public void setLastActiveTime(Date lastActiveTime) { |
| | | this.lastActiveTime = lastActiveTime; |
| | | } |
| | | |
| | | public Boolean getDeleted() { |
| | | return deleted; |
| | | } |
| | | |
| | | public void setDeleted(Boolean deleted) { |
| | | this.deleted = deleted; |
| | | } |
| | | |
| | | public String getWxOpenId() { |
| | | return wxOpenId; |
| | | } |
| | | |
| | | public void setWxOpenId(String wxOpenId) { |
| | | this.wxOpenId = wxOpenId == null ? null : wxOpenId.trim(); |
| | | } |
| | | |
| | | public String getDeptIds() { |
| | | return deptIds; |
| | | } |
| | | |
| | | public void setDeptIds(String deptIds) { |
| | | this.deptIds = deptIds; |
| | | } |
| | | /** |
| | | * 是否部门管理员 |
| | | */ |
| | | private String deptAdmin; |
| | | } |
New file |
| | |
| | | package com.mindskip.xzs.domain.enums; |
| | | |
| | | import lombok.Getter; |
| | | |
| | | /** |
| | | * @author:xp |
| | | * @date:2024/3/8 15:37 |
| | | */ |
| | | @Getter |
| | | public enum DeptAdminEnum { |
| | | NO("0", "不是"), |
| | | YES("1", "是"), |
| | | ; |
| | | |
| | | private final String value; |
| | | |
| | | private final String desc; |
| | | |
| | | DeptAdminEnum(String value, String desc) { |
| | | this.value = value; |
| | | this.desc = desc; |
| | | } |
| | | } |
| | |
| | | public enum RoleEnum { |
| | | |
| | | STUDENT(1, "STUDENT"), |
| | | ADMIN(3, "ADMIN"); |
| | | ADMIN(3, "ADMIN"), |
| | | DEPT_ADMIN(-1, "DEPT_ADMIN"); |
| | | |
| | | int code; |
| | | String name; |
| | |
| | | * 管理员,userId |
| | | */ |
| | | @NotNull(message = "部门管理员不能为空") |
| | | private Integer deptAdmin; |
| | | private Integer adminId; |
| | | |
| | | } |
| | |
| | | Department getName(String name); |
| | | |
| | | Department getById(Integer id); |
| | | |
| | | List<Integer> selectByAdminId(Integer id); |
| | | } |
| | |
| | | List<User> getUserByLevel(@Param("userLevel") Integer userLevel); |
| | | |
| | | User getUserByRealName(@Param("realName") String realName); |
| | | |
| | | /** |
| | | * 修改部门管理员标识 |
| | | * @param id |
| | | * @param deptAdmin |
| | | */ |
| | | void updateDeptAdmin(Integer id, String deptAdmin); |
| | | } |
| | |
| | | import com.github.pagehelper.PageInfo; |
| | | import com.mindskip.xzs.domain.Department; |
| | | import com.mindskip.xzs.domain.UserDepartment; |
| | | import com.mindskip.xzs.domain.enums.DeptAdminEnum; |
| | | import com.mindskip.xzs.domain.vo.BaseSelect; |
| | | import com.mindskip.xzs.domain.vo.UpdateDeptAdminVO; |
| | | import com.mindskip.xzs.repository.BaseMapper; |
| | | import com.mindskip.xzs.repository.DepartmentMapper; |
| | | import com.mindskip.xzs.repository.UserDepartmentMapper; |
| | | import com.mindskip.xzs.repository.UserMapper; |
| | | import com.mindskip.xzs.service.DepartmentService; |
| | | import com.mindskip.xzs.utility.ModelMapperSingle; |
| | | import com.mindskip.xzs.viewmodel.admin.department.DepartmentResponseVM; |
| | |
| | | |
| | | private final DepartmentMapper departmentMapper; |
| | | private final UserDepartmentMapper userDepartmentMapper; |
| | | private final UserMapper userMapper; |
| | | |
| | | public DepartmentServiceImpl(BaseMapper<Department> baseMapper, DepartmentMapper departmentMapper, UserDepartmentMapper userDepartmentMapper) { |
| | | public DepartmentServiceImpl(BaseMapper<Department> baseMapper, DepartmentMapper departmentMapper, UserDepartmentMapper userDepartmentMapper, UserMapper userMapper) { |
| | | super(baseMapper); |
| | | this.departmentMapper = departmentMapper; |
| | | this.userDepartmentMapper = userDepartmentMapper; |
| | | this.userMapper = userMapper; |
| | | } |
| | | |
| | | @Override |
| | |
| | | @Override |
| | | public Integer update(Department department) { |
| | | // userDepartmentMapper.removeByDepartmentId(department.getId()); |
| | | return departmentMapper.update(department); |
| | | Department entity = departmentMapper.getById(department.getId()); |
| | | if (Objects.isNull(entity)) { |
| | | throw new RuntimeException("该部门不存在"); |
| | | } |
| | | if (Objects.nonNull(department.getAdminId())) { |
| | | if (! Objects.equals(entity.getAdminId(), department.getAdminId())) { |
| | | // 取消原先的管理员标识 |
| | | List<Integer> depIds = departmentMapper.selectByAdminId(entity.getAdminId()); |
| | | depIds.remove(department.getId()); |
| | | if (depIds.size() < 1) { |
| | | userMapper.updateDeptAdmin(entity.getAdminId(), DeptAdminEnum.NO.getValue()); |
| | | } |
| | | } |
| | | // 标识部门管理员 |
| | | userMapper.updateDeptAdmin(department.getAdminId(), DeptAdminEnum.YES.getValue()); |
| | | } |
| | | Integer update = departmentMapper.update(department); |
| | | return update; |
| | | } |
| | | |
| | | @Override |
| | |
| | | |
| | | @Override |
| | | public void updateAdmin(UpdateDeptAdminVO form) { |
| | | Department department = departmentMapper.getById(form.getId()); |
| | | if (Objects.isNull(department)) { |
| | | Department entity = departmentMapper.getById(form.getId()); |
| | | if (Objects.isNull(form)) { |
| | | throw new RuntimeException("该部门不存在"); |
| | | } |
| | | department.setAdminId(form.getDeptAdmin()); |
| | | departmentMapper.update(department); |
| | | if (Objects.nonNull(form.getAdminId())) { |
| | | if (! Objects.equals(entity.getAdminId(), form.getAdminId())) { |
| | | // 取消原先的管理员标识 |
| | | List<Integer> depIds = departmentMapper.selectByAdminId(entity.getAdminId()); |
| | | depIds.remove(form.getId()); |
| | | if (depIds.size() < 1) { |
| | | userMapper.updateDeptAdmin(entity.getAdminId(), DeptAdminEnum.NO.getValue()); |
| | | } |
| | | } |
| | | // 标识部门管理员 |
| | | userMapper.updateDeptAdmin(form.getAdminId(), DeptAdminEnum.YES.getValue()); |
| | | } |
| | | entity.setAdminId(form.getAdminId()); |
| | | departmentMapper.update(entity); |
| | | } |
| | | } |
| | |
| | | </sql> |
| | | |
| | | <insert id="add" parameterType="com.mindskip.xzs.domain.Department" useGeneratedKeys="true" keyProperty="id"> |
| | | insert into t_department (name, admin_id, deleted) |
| | | values (#{name,jdbcType=VARCHAR}, {#{adminId}, #{deleted,jdbcType=VARCHAR}) |
| | | insert into t_department (name, deleted) |
| | | values (#{name,jdbcType=VARCHAR}, #{deleted,jdbcType=VARCHAR}) |
| | | </insert> |
| | | |
| | | <update id="update" parameterType="com.mindskip.xzs.domain.Department"> |
| | |
| | | WHERE |
| | | td.name = #{name} AND td.deleted = 0 |
| | | </select> |
| | | |
| | | <select id="selectByAdminId" resultType="integer"> |
| | | SELECT id FROM t_department WHERE admin_id = #{id} AND deleted = 0 |
| | | </select> |
| | | |
| | | </mapper> |
| | |
| | | </resultMap> |
| | | <sql id="Base_Column_List"> |
| | | id, user_uuid, user_name, password, real_name, age, sex, birth_day, user_level, phone, |
| | | role, status, image_path, create_time, modify_time, last_active_time, deleted, wx_open_id |
| | | role, status, image_path, create_time, modify_time, last_active_time, deleted, wx_open_id, dept_admin |
| | | </sql> |
| | | <select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap"> |
| | | select |
| | |
| | | <if test="wxOpenId != null"> |
| | | wx_open_id = #{wxOpenId,jdbcType=VARCHAR}, |
| | | </if> |
| | | <if test="deptAdmin != null"> |
| | | dept_admin = #{deptAdmin}, |
| | | </if> |
| | | </set> |
| | | where id = #{id,jdbcType=INTEGER} |
| | | </update> |
| | |
| | | modify_time = #{modifyTime,jdbcType=TIMESTAMP}, |
| | | last_active_time = #{lastActiveTime,jdbcType=TIMESTAMP}, |
| | | deleted = #{deleted,jdbcType=BIT}, |
| | | wx_open_id = #{wxOpenId,jdbcType=VARCHAR} |
| | | wx_open_id = #{wxOpenId,jdbcType=VARCHAR}, |
| | | dept_admin = #{deptAdmin} |
| | | where id = #{id,jdbcType=INTEGER} |
| | | </update> |
| | | |
| | |
| | | </if> |
| | | </where> |
| | | </select> |
| | | |
| | | |
| | | <update id="updateDeptAdmin"> |
| | | UPDATE t_user SET dept_admin = #{deptAdmin} WHERE id = #{id} AND deleted = 0 |
| | | </update> |
| | | |
| | | </mapper> |