mirror of
				https://github.com/suyiiyii/SIMS.git
				synced 2025-11-04 15:54:52 +08:00 
			
		
		
		
	
							parent
							
								
									8d10add577
								
							
						
					
					
						commit
						6e3ffa092b
					
				
							
								
								
									
										2
									
								
								.github/workflows/maven.yml
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										2
									
								
								.github/workflows/maven.yml
									
									
									
									
										vendored
									
									
								
							@ -24,6 +24,8 @@ jobs:
 | 
			
		||||
  build:
 | 
			
		||||
 | 
			
		||||
    runs-on: ubuntu-latest
 | 
			
		||||
    permissions:
 | 
			
		||||
      contents: write
 | 
			
		||||
 | 
			
		||||
    steps:
 | 
			
		||||
    - uses: actions/checkout@v4
 | 
			
		||||
 | 
			
		||||
@ -31,7 +31,7 @@ public class InterceptorConfig extends WebMvcConfigurationSupport {
 | 
			
		||||
                .addPathPatterns("/**")
 | 
			
		||||
                .excludePathPatterns("/v3/api-docs/**");
 | 
			
		||||
        registry.addInterceptor(rbacInterceptor)
 | 
			
		||||
                .excludePathPatterns("/v3/api-docs/**");;
 | 
			
		||||
                .excludePathPatterns("/v3/api-docs/**");
 | 
			
		||||
 | 
			
		||||
        super.addInterceptors(registry);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@ -4,8 +4,6 @@ import org.modelmapper.ModelMapper;
 | 
			
		||||
import org.modelmapper.convention.MatchingStrategies;
 | 
			
		||||
import org.springframework.context.annotation.Bean;
 | 
			
		||||
import org.springframework.context.annotation.Configuration;
 | 
			
		||||
import top.suyiiyii.sims.dto.RecordDto;
 | 
			
		||||
import top.suyiiyii.sims.entity.User;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @Author tortoise
 | 
			
		||||
@ -28,6 +26,7 @@ public class ModelMapperConfig {
 | 
			
		||||
        //  configureUser(modelMapper);
 | 
			
		||||
        return modelMapper;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // 配置 User 类的映射规则
 | 
			
		||||
    private void configureUser(ModelMapper modelMapper) {
 | 
			
		||||
        // 定义 UserModel -> User 的映射规则
 | 
			
		||||
 | 
			
		||||
@ -43,8 +43,8 @@ public class AdminController {
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
/**
 | 
			
		||||
 request.setAttribute();lUsers();
 | 
			
		||||
        return Result.success(userList);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
**/
 | 
			
		||||
 * request.setAttribute();lUsers();
 | 
			
		||||
 * return Result.success(userList);
 | 
			
		||||
 * }
 | 
			
		||||
 * }
 | 
			
		||||
 **/
 | 
			
		||||
@ -1,35 +1,23 @@
 | 
			
		||||
package top.suyiiyii.sims.controller;
 | 
			
		||||
 | 
			
		||||
import com.auth0.jwt.JWT;
 | 
			
		||||
import com.auth0.jwt.exceptions.JWTDecodeException;
 | 
			
		||||
import com.auth0.jwt.interfaces.DecodedJWT;
 | 
			
		||||
import io.swagger.v3.oas.annotations.Operation;
 | 
			
		||||
 | 
			
		||||
import jakarta.servlet.http.HttpServletRequest;
 | 
			
		||||
import org.modelmapper.ModelMapper;
 | 
			
		||||
import org.springframework.beans.factory.annotation.Autowired;
 | 
			
		||||
 | 
			
		||||
import org.springframework.web.bind.annotation.*;
 | 
			
		||||
import top.suyiiyii.sims.common.AuthAccess;
 | 
			
		||||
import top.suyiiyii.sims.common.Result;
 | 
			
		||||
import top.suyiiyii.sims.dto.CommonResponse;
 | 
			
		||||
import top.suyiiyii.sims.dto.RecordDto;
 | 
			
		||||
import top.suyiiyii.sims.entity.Record;
 | 
			
		||||
import top.suyiiyii.sims.entity.Role;
 | 
			
		||||
import top.suyiiyii.sims.entity.User;
 | 
			
		||||
import top.suyiiyii.sims.entity.UserRole;
 | 
			
		||||
import top.suyiiyii.sims.mapper.CategoryMapper;
 | 
			
		||||
import top.suyiiyii.sims.mapper.UserMapper;
 | 
			
		||||
import top.suyiiyii.sims.service.CategoryService;
 | 
			
		||||
import top.suyiiyii.sims.service.RecordService;
 | 
			
		||||
import top.suyiiyii.sims.service.RoleService;
 | 
			
		||||
import top.suyiiyii.sims.service.UserService;
 | 
			
		||||
import top.suyiiyii.sims.utils.JwtUtils;
 | 
			
		||||
 | 
			
		||||
import java.time.LocalDateTime;
 | 
			
		||||
import java.util.ArrayList;
 | 
			
		||||
import java.util.List;
 | 
			
		||||
import java.util.stream.Collectors;
 | 
			
		||||
 | 
			
		||||
@RestController
 | 
			
		||||
public class
 | 
			
		||||
@ -57,7 +45,7 @@ RecordController {
 | 
			
		||||
 | 
			
		||||
            RecordDto recordDto = modelMapper.map(record, RecordDto.class);
 | 
			
		||||
            recordDto.setCategoryName(categoryService.getCategoryName(record.getCategoryId()));
 | 
			
		||||
            recordDto.setSubCategoryName(categoryService.getsubCategoryName( record.getCategoryId()));
 | 
			
		||||
            recordDto.setSubCategoryName(categoryService.getsubCategoryName(record.getCategoryId()));
 | 
			
		||||
            recordDtos.add(recordDto);
 | 
			
		||||
        }
 | 
			
		||||
        return Result.success(recordDtos);
 | 
			
		||||
@ -70,16 +58,16 @@ RecordController {
 | 
			
		||||
                                          @RequestParam(defaultValue = "10") int size,
 | 
			
		||||
                                          HttpServletRequest request) {
 | 
			
		||||
        String token = (String) request.getAttribute("token");
 | 
			
		||||
        String userId= JwtUtils.extractUserId(token);
 | 
			
		||||
        List<RecordDto> recordDtos=new ArrayList<>();
 | 
			
		||||
        String userId = JwtUtils.extractUserId(token);
 | 
			
		||||
        List<RecordDto> recordDtos = new ArrayList<>();
 | 
			
		||||
 | 
			
		||||
        List<Record> records = recordService.getMyAllRecords(page, size,userId);
 | 
			
		||||
        List<Record> records = recordService.getMyAllRecords(page, size, userId);
 | 
			
		||||
        for (Record record : records) {
 | 
			
		||||
 | 
			
		||||
            RecordDto recordDto = modelMapper.map(record, RecordDto.class);
 | 
			
		||||
 | 
			
		||||
            recordDto.setCategoryName(categoryService.getCategoryName(record.getCategoryId()));
 | 
			
		||||
            recordDto.setSubCategoryName(categoryService.getsubCategoryName( record.getCategoryId()));
 | 
			
		||||
            recordDto.setSubCategoryName(categoryService.getsubCategoryName(record.getCategoryId()));
 | 
			
		||||
 | 
			
		||||
            recordDtos.add(recordDto);
 | 
			
		||||
        }
 | 
			
		||||
@ -92,7 +80,7 @@ RecordController {
 | 
			
		||||
    @PutMapping("/admin/record/{id}")
 | 
			
		||||
    public Result<CommonResponse> adminUpdateRecord(@PathVariable Integer id, @RequestBody RecordDto recordDto) {
 | 
			
		||||
        Record record = modelMapper.map(recordDto, Record.class);
 | 
			
		||||
        recordService.updateRecord(record,id);
 | 
			
		||||
        recordService.updateRecord(record, id);
 | 
			
		||||
        return Result.msg("修改成功");
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -11,7 +11,6 @@ import top.suyiiyii.sims.common.AuthAccess;
 | 
			
		||||
import top.suyiiyii.sims.common.Result;
 | 
			
		||||
import top.suyiiyii.sims.dto.CommonResponse;
 | 
			
		||||
import top.suyiiyii.sims.dto.UserDto;
 | 
			
		||||
import top.suyiiyii.sims.entity.User;
 | 
			
		||||
import top.suyiiyii.sims.exception.ServiceException;
 | 
			
		||||
import top.suyiiyii.sims.service.RoleService;
 | 
			
		||||
import top.suyiiyii.sims.service.UserService;
 | 
			
		||||
 | 
			
		||||
@ -4,9 +4,6 @@ import lombok.AllArgsConstructor;
 | 
			
		||||
import lombok.Data;
 | 
			
		||||
import lombok.NoArgsConstructor;
 | 
			
		||||
 | 
			
		||||
import java.time.LocalDateTime;
 | 
			
		||||
import java.util.List;
 | 
			
		||||
 | 
			
		||||
@Data
 | 
			
		||||
@AllArgsConstructor
 | 
			
		||||
@NoArgsConstructor
 | 
			
		||||
 | 
			
		||||
@ -1,7 +1,5 @@
 | 
			
		||||
package top.suyiiyii.sims.entity;
 | 
			
		||||
 | 
			
		||||
import com.baomidou.mybatisplus.annotation.IdType;
 | 
			
		||||
import com.baomidou.mybatisplus.annotation.TableField;
 | 
			
		||||
import com.baomidou.mybatisplus.annotation.TableId;
 | 
			
		||||
import com.tangzc.mpe.autotable.annotation.Table;
 | 
			
		||||
import lombok.AllArgsConstructor;
 | 
			
		||||
 | 
			
		||||
@ -1,7 +1,5 @@
 | 
			
		||||
package top.suyiiyii.sims.entity;
 | 
			
		||||
 | 
			
		||||
import com.baomidou.mybatisplus.annotation.IdType;
 | 
			
		||||
import com.baomidou.mybatisplus.annotation.TableField;
 | 
			
		||||
import com.baomidou.mybatisplus.annotation.TableId;
 | 
			
		||||
import com.tangzc.mpe.autotable.annotation.Table;
 | 
			
		||||
import lombok.AllArgsConstructor;
 | 
			
		||||
 | 
			
		||||
@ -1,6 +1,5 @@
 | 
			
		||||
package top.suyiiyii.sims.entity;
 | 
			
		||||
 | 
			
		||||
import com.baomidou.mybatisplus.annotation.IdType;
 | 
			
		||||
import com.baomidou.mybatisplus.annotation.TableId;
 | 
			
		||||
import com.tangzc.mpe.autotable.annotation.Table;
 | 
			
		||||
import lombok.AllArgsConstructor;
 | 
			
		||||
 | 
			
		||||
@ -7,8 +7,6 @@ import lombok.AllArgsConstructor;
 | 
			
		||||
import lombok.Data;
 | 
			
		||||
import lombok.NoArgsConstructor;
 | 
			
		||||
 | 
			
		||||
import java.time.LocalDateTime;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @Author tortoise
 | 
			
		||||
 * @Date 2024/8/9 14:04
 | 
			
		||||
 | 
			
		||||
@ -1,6 +1,5 @@
 | 
			
		||||
package top.suyiiyii.sims.entity;
 | 
			
		||||
 | 
			
		||||
import com.baomidou.mybatisplus.annotation.IdType;
 | 
			
		||||
import com.baomidou.mybatisplus.annotation.TableId;
 | 
			
		||||
import com.tangzc.mpe.autotable.annotation.Table;
 | 
			
		||||
import lombok.AllArgsConstructor;
 | 
			
		||||
 | 
			
		||||
@ -21,7 +21,7 @@ import lombok.NoArgsConstructor;
 | 
			
		||||
@AllArgsConstructor
 | 
			
		||||
@NoArgsConstructor
 | 
			
		||||
public class Role {
 | 
			
		||||
    @ColumnId(mode = IdType.AUTO,comment = "id主键")
 | 
			
		||||
    @ColumnId(mode = IdType.AUTO, comment = "id主键")
 | 
			
		||||
    private Integer id;
 | 
			
		||||
    //管理员,普通用户,组员,组长,队长
 | 
			
		||||
    @ColumnNotNull
 | 
			
		||||
@ -29,6 +29,6 @@ public class Role {
 | 
			
		||||
    private String tag;
 | 
			
		||||
 | 
			
		||||
    public static Role guest() {
 | 
			
		||||
        return new Role(-1, "guest","");
 | 
			
		||||
        return new Role(-1, "guest", "");
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -1,8 +1,6 @@
 | 
			
		||||
package top.suyiiyii.sims.entity;
 | 
			
		||||
 | 
			
		||||
import com.baomidou.mybatisplus.annotation.IdType;
 | 
			
		||||
import com.baomidou.mybatisplus.annotation.TableField;
 | 
			
		||||
import com.baomidou.mybatisplus.annotation.TableId;
 | 
			
		||||
import com.tangzc.autotable.annotation.ColumnNotNull;
 | 
			
		||||
import com.tangzc.mpe.autotable.annotation.ColumnId;
 | 
			
		||||
import com.tangzc.mpe.autotable.annotation.Table;
 | 
			
		||||
@ -10,8 +8,6 @@ import lombok.AllArgsConstructor;
 | 
			
		||||
import lombok.Data;
 | 
			
		||||
import lombok.NoArgsConstructor;
 | 
			
		||||
 | 
			
		||||
import java.security.Permission;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @Author tortoise
 | 
			
		||||
 * @Date 2024/8/9 14:03
 | 
			
		||||
@ -25,7 +21,7 @@ import java.security.Permission;
 | 
			
		||||
@AllArgsConstructor
 | 
			
		||||
@NoArgsConstructor
 | 
			
		||||
public class RolePermission {
 | 
			
		||||
    @ColumnId(mode = IdType.AUTO,comment = "id主键")
 | 
			
		||||
    @ColumnId(mode = IdType.AUTO, comment = "id主键")
 | 
			
		||||
    private Integer id;
 | 
			
		||||
    @ColumnNotNull
 | 
			
		||||
    private Integer roleId;
 | 
			
		||||
 | 
			
		||||
@ -21,18 +21,18 @@ import lombok.NoArgsConstructor;
 | 
			
		||||
@AllArgsConstructor
 | 
			
		||||
@NoArgsConstructor
 | 
			
		||||
public class User {
 | 
			
		||||
    @ColumnId(mode = IdType.AUTO,comment = "id主键")
 | 
			
		||||
    @ColumnId(mode = IdType.AUTO, comment = "id主键")
 | 
			
		||||
    private Integer id;
 | 
			
		||||
    @Column(comment = "学生id",notNull = true)
 | 
			
		||||
    @Column(comment = "学生id", notNull = true)
 | 
			
		||||
    private Integer studentId;
 | 
			
		||||
    @Column(comment = "用户名",notNull = true)
 | 
			
		||||
    @Column(comment = "用户名", notNull = true)
 | 
			
		||||
    private String username;
 | 
			
		||||
    @Column(comment = "密码",notNull = true)
 | 
			
		||||
    @Column(comment = "密码", notNull = true)
 | 
			
		||||
    private String password;
 | 
			
		||||
    @Column(comment = "邮箱",notNull = true)
 | 
			
		||||
    @Column(comment = "邮箱", notNull = true)
 | 
			
		||||
    private String email;
 | 
			
		||||
    @Column(comment = "年级",notNull = true)
 | 
			
		||||
    @Column(comment = "年级", notNull = true)
 | 
			
		||||
    private String grade;
 | 
			
		||||
    @Column(comment = "用户所属团队",notNull = true)
 | 
			
		||||
    @Column(comment = "用户所属团队", notNull = true)
 | 
			
		||||
    private String userGroup;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -1,7 +1,6 @@
 | 
			
		||||
package top.suyiiyii.sims.entity;
 | 
			
		||||
 | 
			
		||||
import com.baomidou.mybatisplus.annotation.IdType;
 | 
			
		||||
import com.baomidou.mybatisplus.annotation.TableId;
 | 
			
		||||
import com.tangzc.autotable.annotation.ColumnNotNull;
 | 
			
		||||
import com.tangzc.mpe.autotable.annotation.ColumnId;
 | 
			
		||||
import com.tangzc.mpe.autotable.annotation.Table;
 | 
			
		||||
@ -22,7 +21,7 @@ import lombok.NoArgsConstructor;
 | 
			
		||||
@AllArgsConstructor
 | 
			
		||||
@NoArgsConstructor
 | 
			
		||||
public class UserRole {
 | 
			
		||||
    @ColumnId(mode = IdType.AUTO,comment = "id主键")
 | 
			
		||||
    @ColumnId(mode = IdType.AUTO, comment = "id主键")
 | 
			
		||||
    private Integer id;
 | 
			
		||||
    @ColumnNotNull
 | 
			
		||||
    private Integer userId;
 | 
			
		||||
 | 
			
		||||
@ -11,14 +11,15 @@ import lombok.Getter;
 | 
			
		||||
 * @Version 1.0
 | 
			
		||||
 */
 | 
			
		||||
@Getter
 | 
			
		||||
public class ServiceException extends RuntimeException{
 | 
			
		||||
public class ServiceException extends RuntimeException {
 | 
			
		||||
    public final String code;
 | 
			
		||||
 | 
			
		||||
    public ServiceException(String msg){
 | 
			
		||||
    public ServiceException(String msg) {
 | 
			
		||||
        super(msg);
 | 
			
		||||
        this.code = "500";
 | 
			
		||||
    }
 | 
			
		||||
    public ServiceException(String code ,String msg){
 | 
			
		||||
 | 
			
		||||
    public ServiceException(String code, String msg) {
 | 
			
		||||
        super(msg);
 | 
			
		||||
        this.code = code;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@ -18,6 +18,7 @@ public interface CategoryMapper {
 | 
			
		||||
 | 
			
		||||
    @Select("SELECT category_name FROM reward_punishment_category WHERE category_id=#{categoryId}")
 | 
			
		||||
    String getSubCategoryName(Integer categoryId);
 | 
			
		||||
@Select("SELECT category_id FROM reward_punishment_category WHERE sub_category_name=#{subCategoryName}")
 | 
			
		||||
 | 
			
		||||
    @Select("SELECT category_id FROM reward_punishment_category WHERE sub_category_name=#{subCategoryName}")
 | 
			
		||||
    Integer getIdBySubCategoryName(String subCategoryName);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -1,6 +1,5 @@
 | 
			
		||||
package top.suyiiyii.sims.mapper;
 | 
			
		||||
 | 
			
		||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 | 
			
		||||
import org.apache.ibatis.annotations.Mapper;
 | 
			
		||||
import org.apache.ibatis.annotations.Select;
 | 
			
		||||
import top.suyiiyii.sims.entity.Permissions;
 | 
			
		||||
@ -18,8 +17,9 @@ import java.util.List;
 | 
			
		||||
 */
 | 
			
		||||
@Mapper
 | 
			
		||||
public interface PermissionsMapper {
 | 
			
		||||
@Select("SELECT * FROM role_permission WHERE role_id = #{id}")
 | 
			
		||||
    @Select("SELECT * FROM role_permission WHERE role_id = #{id}")
 | 
			
		||||
    List<RolePermission> getRolePerminsionByRoleId(Integer id);
 | 
			
		||||
@Select("SELECT * FROM permissions WHERE permission_id = #{permissionId}")
 | 
			
		||||
 | 
			
		||||
    @Select("SELECT * FROM permissions WHERE permission_id = #{permissionId}")
 | 
			
		||||
    Permissions selectById(Integer permissionId);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -1,7 +1,6 @@
 | 
			
		||||
package top.suyiiyii.sims.mapper;
 | 
			
		||||
 | 
			
		||||
import org.apache.ibatis.annotations.*;
 | 
			
		||||
import top.suyiiyii.sims.dto.RecordDto;
 | 
			
		||||
import top.suyiiyii.sims.entity.Record;
 | 
			
		||||
 | 
			
		||||
import java.util.List;
 | 
			
		||||
@ -17,9 +16,10 @@ import java.util.List;
 | 
			
		||||
@Mapper
 | 
			
		||||
public interface RecordMapper {
 | 
			
		||||
    //分页查询
 | 
			
		||||
@Select("select * from record limit #{page},#{size}")
 | 
			
		||||
    @Select("select * from record limit #{page},#{size}")
 | 
			
		||||
    List<Record> getAllRecords(Integer page, Integer size);
 | 
			
		||||
//根据学号分页查询所以信息
 | 
			
		||||
 | 
			
		||||
    //根据学号分页查询所以信息
 | 
			
		||||
    @Select("select * from record where student_id = #{id} limit #{page},#{size}")
 | 
			
		||||
    List<Record> getMyAllRecords(Integer page, Integer size, String id);
 | 
			
		||||
 | 
			
		||||
@ -42,6 +42,7 @@ public interface RecordMapper {
 | 
			
		||||
 | 
			
		||||
    @Delete("delete from record where id = #{id}")
 | 
			
		||||
    void deleteRecord(Integer id);
 | 
			
		||||
 | 
			
		||||
    @Insert({
 | 
			
		||||
            "insert into record (student_id, category_id, `date`, content, reason, amount, remark, is_revoked,",
 | 
			
		||||
            "revoke_date, revoke_reason, revoke_remark, operator_user_id, last_update_time)",
 | 
			
		||||
 | 
			
		||||
@ -1,12 +1,8 @@
 | 
			
		||||
package top.suyiiyii.sims.mapper;
 | 
			
		||||
 | 
			
		||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 | 
			
		||||
import lombok.Data;
 | 
			
		||||
import org.apache.ibatis.annotations.*;
 | 
			
		||||
import top.suyiiyii.sims.entity.Permissions;
 | 
			
		||||
import top.suyiiyii.sims.entity.Role;
 | 
			
		||||
import top.suyiiyii.sims.entity.User;
 | 
			
		||||
import top.suyiiyii.sims.entity.UserRole;
 | 
			
		||||
 | 
			
		||||
import java.util.List;
 | 
			
		||||
 | 
			
		||||
@ -22,15 +18,18 @@ import java.util.List;
 | 
			
		||||
public interface RoleMapper {
 | 
			
		||||
    @Insert("INSERT INTO role(name) VALUES(#{name}")
 | 
			
		||||
    void addRole(String name);
 | 
			
		||||
@Delete("DELETE FROM role WHERE name=#{name}")
 | 
			
		||||
 | 
			
		||||
    @Delete("DELETE FROM role WHERE name=#{name}")
 | 
			
		||||
    void deleteRole(String name);
 | 
			
		||||
@Update("UPDATE role SET name=#{newName} WHERE name=#{name}")
 | 
			
		||||
 | 
			
		||||
    @Update("UPDATE role SET name=#{newName} WHERE name=#{name}")
 | 
			
		||||
    void updateRole(String name, String newName);
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @param
 | 
			
		||||
     * @author: tortoise
 | 
			
		||||
     * @date: 2024/8/14 14:23
 | 
			
		||||
     * @Description: TODO 查询用户信息
 | 
			
		||||
     * @param
 | 
			
		||||
     * @return: java.util.List<top.suyiiyii.sims.entity.User>
 | 
			
		||||
     */
 | 
			
		||||
    @Select("SELECT u.username, u.name, u.userId, r.role_name " +
 | 
			
		||||
@ -53,7 +52,7 @@ public interface RoleMapper {
 | 
			
		||||
            "(SELECT role_id FROM user_role WHERE user_id = #{user_id})")
 | 
			
		||||
    List<Role> selectRolesById(@Param("user_id") int id);
 | 
			
		||||
 | 
			
		||||
@Select("SELECT role_name FROM role WHERE role_id=#{roleId}")
 | 
			
		||||
    @Select("SELECT role_name FROM role WHERE role_id=#{roleId}")
 | 
			
		||||
    List<String> selectRoleNamesByRoleId(Integer roleId);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -2,7 +2,6 @@ package top.suyiiyii.sims.mapper;
 | 
			
		||||
 | 
			
		||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 | 
			
		||||
import org.apache.ibatis.annotations.*;
 | 
			
		||||
import top.suyiiyii.sims.entity.Role;
 | 
			
		||||
import top.suyiiyii.sims.entity.User;
 | 
			
		||||
 | 
			
		||||
import java.util.List;
 | 
			
		||||
@ -19,6 +18,7 @@ import java.util.List;
 | 
			
		||||
public interface UserMapper extends BaseMapper<User> {
 | 
			
		||||
    /**
 | 
			
		||||
     * 添加新用户
 | 
			
		||||
     *
 | 
			
		||||
     * @param user 新用户对象
 | 
			
		||||
     * @return 影响的行数
 | 
			
		||||
     */
 | 
			
		||||
@ -27,6 +27,7 @@ public interface UserMapper extends BaseMapper<User> {
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 根据ID删除用户
 | 
			
		||||
     *
 | 
			
		||||
     * @param id 用户ID
 | 
			
		||||
     * @return 影响的行数
 | 
			
		||||
     */
 | 
			
		||||
@ -35,6 +36,7 @@ public interface UserMapper extends BaseMapper<User> {
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 更新用户信息
 | 
			
		||||
     *
 | 
			
		||||
     * @param user 更新后的用户对象
 | 
			
		||||
     * @return 影响的行数
 | 
			
		||||
     */
 | 
			
		||||
@ -50,6 +52,7 @@ public interface UserMapper extends BaseMapper<User> {
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 根据ID查询用户信息
 | 
			
		||||
     *
 | 
			
		||||
     * @param
 | 
			
		||||
     * @return 用户对象
 | 
			
		||||
     */
 | 
			
		||||
@ -58,13 +61,16 @@ public interface UserMapper extends BaseMapper<User> {
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 根据iD查询用户信息
 | 
			
		||||
     *
 | 
			
		||||
     * @param
 | 
			
		||||
     * @return 用户对象
 | 
			
		||||
     */
 | 
			
		||||
    @Select("SELECT id, student_id, username, password, username, email,grade, user_group from user WHERE id = #{id}")
 | 
			
		||||
    User selectById(Integer id);
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 查询所有用户信息
 | 
			
		||||
     *
 | 
			
		||||
     * @return 用户列表
 | 
			
		||||
     */
 | 
			
		||||
    @Select("SELECT id, student_id, username, password, username, email, grade, user_group FROM user")
 | 
			
		||||
@ -72,8 +78,10 @@ public interface UserMapper extends BaseMapper<User> {
 | 
			
		||||
 | 
			
		||||
    @Select("select * from user where username = #{username}")
 | 
			
		||||
    User selectByUserName(@Param("username") String username);
 | 
			
		||||
@Update("update user set password = #{password} where username = #{username}")
 | 
			
		||||
 | 
			
		||||
    @Update("update user set password = #{password} where username = #{username}")
 | 
			
		||||
    void updatePassword(User user);
 | 
			
		||||
@Select("select student_id from user where id = #{userId}")
 | 
			
		||||
 | 
			
		||||
    @Select("select student_id from user where id = #{userId}")
 | 
			
		||||
    String getStudentIdById(String userId);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -1,10 +1,8 @@
 | 
			
		||||
package top.suyiiyii.sims.service;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
import org.checkerframework.checker.units.qual.A;
 | 
			
		||||
import org.springframework.beans.factory.annotation.Autowired;
 | 
			
		||||
import org.springframework.stereotype.Service;
 | 
			
		||||
import top.suyiiyii.sims.dto.RecordDto;
 | 
			
		||||
import top.suyiiyii.sims.entity.Record;
 | 
			
		||||
import top.suyiiyii.sims.mapper.RecordMapper;
 | 
			
		||||
import top.suyiiyii.sims.mapper.UserMapper;
 | 
			
		||||
 | 
			
		||||
@ -1,11 +1,9 @@
 | 
			
		||||
package top.suyiiyii.sims.service;
 | 
			
		||||
 | 
			
		||||
import org.checkerframework.checker.units.qual.A;
 | 
			
		||||
import org.springframework.beans.factory.annotation.Autowired;
 | 
			
		||||
import org.springframework.stereotype.Service;
 | 
			
		||||
import top.suyiiyii.sims.entity.Role;
 | 
			
		||||
import top.suyiiyii.sims.entity.User;
 | 
			
		||||
import top.suyiiyii.sims.entity.UserRole;
 | 
			
		||||
import top.suyiiyii.sims.mapper.RoleMapper;
 | 
			
		||||
 | 
			
		||||
import java.util.List;
 | 
			
		||||
@ -23,23 +21,22 @@ public class RoleService {
 | 
			
		||||
    @Autowired
 | 
			
		||||
    RoleMapper roleMapper;
 | 
			
		||||
 | 
			
		||||
    public List<User> findAllUsersWithRoles(){
 | 
			
		||||
    public List<User> findAllUsersWithRoles() {
 | 
			
		||||
        return roleMapper.selectAllUsersWithRoles();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @param Id
 | 
			
		||||
     * @author: tortoise
 | 
			
		||||
     * @date: 2024/8/14 14:39
 | 
			
		||||
     * @Description: TODO 查看自己身份
 | 
			
		||||
     * @param Id
 | 
			
		||||
     * @return: java.util.List<top.suyiiyii.sims.entity.Role>
 | 
			
		||||
     */
 | 
			
		||||
    public List<Role> selectRolesById(int id){
 | 
			
		||||
    public List<Role> selectRolesById(int id) {
 | 
			
		||||
        return roleMapper.selectRolesById(id);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    public boolean isRoleNameAdmin(Integer id) {
 | 
			
		||||
        List<Role> roles = roleMapper.selectRolesById(id);
 | 
			
		||||
        for (Role role : roles) {
 | 
			
		||||
 | 
			
		||||
@ -1,23 +1,24 @@
 | 
			
		||||
package top.suyiiyii.sims.service;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 | 
			
		||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 | 
			
		||||
import org.modelmapper.ModelMapper;
 | 
			
		||||
import org.springframework.beans.factory.annotation.Autowired;
 | 
			
		||||
import org.springframework.beans.factory.annotation.Value;
 | 
			
		||||
import org.springframework.stereotype.Service;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
import top.suyiiyii.sims.controller.UserController;
 | 
			
		||||
import top.suyiiyii.sims.dto.UserDto;
 | 
			
		||||
import top.suyiiyii.sims.entity.*;
 | 
			
		||||
import top.suyiiyii.sims.entity.Role;
 | 
			
		||||
import top.suyiiyii.sims.entity.User;
 | 
			
		||||
import top.suyiiyii.sims.exception.ServiceException;
 | 
			
		||||
import top.suyiiyii.sims.mapper.*;
 | 
			
		||||
import top.suyiiyii.sims.mapper.MpUserMapper;
 | 
			
		||||
import top.suyiiyii.sims.mapper.PermissionsMapper;
 | 
			
		||||
import top.suyiiyii.sims.mapper.RoleMapper;
 | 
			
		||||
import top.suyiiyii.sims.mapper.UserMapper;
 | 
			
		||||
import top.suyiiyii.sims.utils.JwtUtils;
 | 
			
		||||
 | 
			
		||||
import java.util.*;
 | 
			
		||||
import java.util.ArrayList;
 | 
			
		||||
import java.util.List;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @Author tortoise
 | 
			
		||||
@ -59,7 +60,8 @@ public class UserService {
 | 
			
		||||
    public List<User> selectAll() {
 | 
			
		||||
        return userMapper.selectAll();
 | 
			
		||||
    }
 | 
			
		||||
//TODO:返回一个DTO,用户基本信息
 | 
			
		||||
 | 
			
		||||
    //TODO:返回一个DTO,用户基本信息
 | 
			
		||||
    public String login(String username, String password) {
 | 
			
		||||
 | 
			
		||||
        User dbUser = userMapper.selectByUserName(username);
 | 
			
		||||
@ -95,19 +97,22 @@ public class UserService {
 | 
			
		||||
        if (req.getUserGroup() == null || req.getUserGroup().equals("")) {
 | 
			
		||||
            throw new ServiceException("组别不能为空");
 | 
			
		||||
        }
 | 
			
		||||
        User user =modelMapper.map(req, User.class);
 | 
			
		||||
        User user = modelMapper.map(req, User.class);
 | 
			
		||||
 | 
			
		||||
        mpUserMapper.insert(user);
 | 
			
		||||
        user = mpUserMapper.selectOne(new LambdaQueryWrapper<User>().eq(User::getUsername, req.getUsername()));
 | 
			
		||||
        rbacService.addRoleWithUserId(user.getId(), "user");
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public User selectByUsername(String username) {
 | 
			
		||||
        return userMapper.selectByUserName(username);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void updatePassword(User user) {
 | 
			
		||||
        userMapper.updatePassword(user);
 | 
			
		||||
    }
 | 
			
		||||
    public List<UserDto> findAllUsers(){
 | 
			
		||||
 | 
			
		||||
    public List<UserDto> findAllUsers() {
 | 
			
		||||
        List<User> users = userMapper.selectAll();
 | 
			
		||||
        List<UserDto> UserDtos = new ArrayList<>();
 | 
			
		||||
 | 
			
		||||
@ -131,6 +136,7 @@ public class UserService {
 | 
			
		||||
        }
 | 
			
		||||
        return UserDtos;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public UserDto findUser(Integer id) {
 | 
			
		||||
 | 
			
		||||
        UserDto UserDto = new UserDto();
 | 
			
		||||
 | 
			
		||||
@ -30,17 +30,13 @@ public class JwtUtils {
 | 
			
		||||
    private static UserMapper staticUserMapper;
 | 
			
		||||
    @Resource
 | 
			
		||||
    UserMapper userMapper;
 | 
			
		||||
    @PostConstruct
 | 
			
		||||
    public void setUserService() {
 | 
			
		||||
        staticUserMapper=userMapper;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @param userId
 | 
			
		||||
     * @param sign
 | 
			
		||||
     * @author: tortoise
 | 
			
		||||
     * @date: 2024/8/1 15:12
 | 
			
		||||
     * @Description: 生成token
 | 
			
		||||
     * @param userId
 | 
			
		||||
     * @param sign
 | 
			
		||||
     * @return: java.lang.String
 | 
			
		||||
     */
 | 
			
		||||
    public static String createToken(String userId, String sign) {
 | 
			
		||||
@ -50,6 +46,7 @@ public class JwtUtils {
 | 
			
		||||
                .sign(Algorithm.HMAC256(sign));
 | 
			
		||||
        // 设置令牌过期时间为2小时
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static User getCurrentUser() {
 | 
			
		||||
        try {
 | 
			
		||||
            HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
 | 
			
		||||
@ -63,6 +60,7 @@ public class JwtUtils {
 | 
			
		||||
        }
 | 
			
		||||
        return null;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // 验证 JWT 令牌
 | 
			
		||||
    public static boolean verifyToken(String token, String secret) {
 | 
			
		||||
        try {
 | 
			
		||||
@ -74,6 +72,7 @@ public class JwtUtils {
 | 
			
		||||
            return false;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static String extractUserId(String token) {
 | 
			
		||||
        try {
 | 
			
		||||
            return JWT.decode(token).getAudience().get(0); // 从 token 中提取用户ID
 | 
			
		||||
@ -82,4 +81,9 @@ public class JwtUtils {
 | 
			
		||||
            return null;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @PostConstruct
 | 
			
		||||
    public void setUserService() {
 | 
			
		||||
        staticUserMapper = userMapper;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user