mirror of
				https://github.com/suyiiyii/SIMS.git
				synced 2025-11-04 15:54:52 +08:00 
			
		
		
		
	调整个人查询无法出现类别类型
This commit is contained in:
		
							parent
							
								
									8767c5c554
								
							
						
					
					
						commit
						471079f68c
					
				@ -29,9 +29,7 @@ public class RbacInterceptor implements HandlerInterceptor {
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
        // 获取用户角色
 | 
					        // 获取用户角色
 | 
				
			||||||
        List<String> roles = getUserRole(request).stream().map(Role::getRoleName).toList();
 | 
					        List<String> roles = getUserRole(request).stream().map(Role::getRoleName).toList();
 | 
				
			||||||
 | 
					 | 
				
			||||||
        List<String> allowRoles = null;
 | 
					        List<String> allowRoles = null;
 | 
				
			||||||
 | 
					 | 
				
			||||||
        // 获取当前请求的方法上的 AuthAccess 注解,从而获取允许访问的角色
 | 
					        // 获取当前请求的方法上的 AuthAccess 注解,从而获取允许访问的角色
 | 
				
			||||||
        if (handler instanceof HandlerMethod) {
 | 
					        if (handler instanceof HandlerMethod) {
 | 
				
			||||||
            AuthAccess annotation = ((HandlerMethod) handler).getMethodAnnotation(AuthAccess.class);
 | 
					            AuthAccess annotation = ((HandlerMethod) handler).getMethodAnnotation(AuthAccess.class);
 | 
				
			||||||
 | 
				
			|||||||
@ -2,6 +2,7 @@ package top.suyiiyii.sims.controller;
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
import io.swagger.v3.oas.annotations.Operation;
 | 
					import io.swagger.v3.oas.annotations.Operation;
 | 
				
			||||||
import jakarta.servlet.http.HttpServletRequest;
 | 
					import jakarta.servlet.http.HttpServletRequest;
 | 
				
			||||||
 | 
					import jakarta.servlet.http.HttpSession;
 | 
				
			||||||
import org.modelmapper.ModelMapper;
 | 
					import org.modelmapper.ModelMapper;
 | 
				
			||||||
import org.springframework.beans.factory.annotation.Autowired;
 | 
					import org.springframework.beans.factory.annotation.Autowired;
 | 
				
			||||||
import org.springframework.web.bind.annotation.*;
 | 
					import org.springframework.web.bind.annotation.*;
 | 
				
			||||||
@ -51,13 +52,14 @@ RecordController {
 | 
				
			|||||||
        return Result.success(recordDtos);
 | 
					        return Result.success(recordDtos);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @AuthAccess(allowRoles = {"user"})
 | 
					    @AuthAccess(allowRoles = {"user","admin"})
 | 
				
			||||||
    @Operation(summary = "获取自己的奖惩记录")
 | 
					    @Operation(summary = "获取自己的奖惩记录")
 | 
				
			||||||
    @GetMapping("/record")
 | 
					    @GetMapping("/record")
 | 
				
			||||||
    public Result<List<RecordDto>> record(@RequestParam(defaultValue = "0") int page,
 | 
					    public Result<List<RecordDto>> record(@RequestParam(defaultValue = "0") int page,
 | 
				
			||||||
                                          @RequestParam(defaultValue = "10") int size,
 | 
					                                          @RequestParam(defaultValue = "10") int size,
 | 
				
			||||||
                                          HttpServletRequest request) {
 | 
					                                          HttpServletRequest request) {
 | 
				
			||||||
        String token = (String) request.getAttribute("token");
 | 
					        HttpSession session = request.getSession();
 | 
				
			||||||
 | 
					        String token = (String) session.getAttribute("token");
 | 
				
			||||||
        String userId = JwtUtils.extractUserId(token);
 | 
					        String userId = JwtUtils.extractUserId(token);
 | 
				
			||||||
        List<RecordDto> recordDtos = new ArrayList<>();
 | 
					        List<RecordDto> recordDtos = new ArrayList<>();
 | 
				
			||||||
        List<Record> records = recordService.getMyAllRecords(page, size, userId);
 | 
					        List<Record> records = recordService.getMyAllRecords(page, size, userId);
 | 
				
			||||||
@ -68,9 +70,7 @@ RecordController {
 | 
				
			|||||||
            recordDtos.add(recordDto);
 | 
					            recordDtos.add(recordDto);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        return Result.success(recordDtos);
 | 
					        return Result.success(recordDtos);
 | 
				
			||||||
 | 
					 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					 | 
				
			||||||
    @AuthAccess(allowRoles = {"admin"})
 | 
					    @AuthAccess(allowRoles = {"admin"})
 | 
				
			||||||
    @Operation(summary = "更新单个奖惩记录")
 | 
					    @Operation(summary = "更新单个奖惩记录")
 | 
				
			||||||
    @PutMapping("/admin/record/{id}")
 | 
					    @PutMapping("/admin/record/{id}")
 | 
				
			||||||
@ -93,14 +93,16 @@ RecordController {
 | 
				
			|||||||
    @Operation(summary = "添加奖惩记录")
 | 
					    @Operation(summary = "添加奖惩记录")
 | 
				
			||||||
    @PostMapping("/admin/record")
 | 
					    @PostMapping("/admin/record")
 | 
				
			||||||
    public Result<CommonResponse> adminAddRecord(@RequestBody RecordDto recordDto) {
 | 
					    public Result<CommonResponse> adminAddRecord(@RequestBody RecordDto recordDto) {
 | 
				
			||||||
        Integer categoryId = categoryService.getIdBySubCategoryName(recordDto.getSubCategoryName());
 | 
					//CategoryName不是奖励或者惩罚
 | 
				
			||||||
 | 
					        if (!recordDto.getCategoryName().equals("奖励")
 | 
				
			||||||
        Record record = modelMapper.map(recordDto, Record.class);
 | 
					                && !recordDto.getCategoryName().equals("惩罚")) {
 | 
				
			||||||
        if (categoryId == null) {
 | 
					            return Result.error("请选择正确奖惩类别");
 | 
				
			||||||
            Result.error("请选择奖惩类别,以及类型");
 | 
					 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        record.setCategoryId(categoryId);
 | 
					        if (recordDto.getSubCategoryName().isEmpty()) {
 | 
				
			||||||
        recordService.addRecord(record);
 | 
					            return Result.error("请输入奖惩类型");
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        recordService.addRecord(recordDto);
 | 
				
			||||||
        return Result.msg("添加成功");
 | 
					        return Result.msg("添加成功");
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
   @AuthAccess(allowRoles = {"admin"})
 | 
					   @AuthAccess(allowRoles = {"admin"})
 | 
				
			||||||
 | 
				
			|||||||
@ -3,6 +3,7 @@ package top.suyiiyii.sims.controller;
 | 
				
			|||||||
import cn.hutool.core.util.StrUtil;
 | 
					import cn.hutool.core.util.StrUtil;
 | 
				
			||||||
import io.swagger.v3.oas.annotations.Operation;
 | 
					import io.swagger.v3.oas.annotations.Operation;
 | 
				
			||||||
import jakarta.servlet.http.HttpServletRequest;
 | 
					import jakarta.servlet.http.HttpServletRequest;
 | 
				
			||||||
 | 
					import jakarta.servlet.http.HttpSession;
 | 
				
			||||||
import jakarta.validation.constraints.Max;
 | 
					import jakarta.validation.constraints.Max;
 | 
				
			||||||
import lombok.Data;
 | 
					import lombok.Data;
 | 
				
			||||||
import lombok.extern.slf4j.Slf4j;
 | 
					import lombok.extern.slf4j.Slf4j;
 | 
				
			||||||
@ -40,7 +41,7 @@ public class UserController {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    @AuthAccess(allowRoles = {"guest"})
 | 
					    @AuthAccess(allowRoles = {"guest"})
 | 
				
			||||||
    @PostMapping("/user/login")
 | 
					    @PostMapping("/user/login")
 | 
				
			||||||
    public Result<LoginResponse> login(@RequestBody LoginRequest request, HttpServletRequest httpServletRequest) {
 | 
					    public Result<LoginResponse> login(@RequestBody LoginRequest request,HttpServletRequest httpServletRequest) {
 | 
				
			||||||
        log.info("login request:{}", request);
 | 
					        log.info("login request:{}", request);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (StrUtil.isBlank(request.getUsername()) || StrUtil.isBlank(request.getPassword())) {
 | 
					        if (StrUtil.isBlank(request.getUsername()) || StrUtil.isBlank(request.getPassword())) {
 | 
				
			||||||
@ -53,6 +54,8 @@ public class UserController {
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
        LoginResponse response = new LoginResponse();
 | 
					        LoginResponse response = new LoginResponse();
 | 
				
			||||||
        response.setToken(token);
 | 
					        response.setToken(token);
 | 
				
			||||||
 | 
					        HttpSession session = httpServletRequest.getSession();
 | 
				
			||||||
 | 
					        session.setAttribute("token",token);
 | 
				
			||||||
        return Result.success(response);
 | 
					        return Result.success(response);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    @AuthAccess(allowRoles = {"guest"})
 | 
					    @AuthAccess(allowRoles = {"guest"})
 | 
				
			||||||
 | 
				
			|||||||
@ -12,7 +12,6 @@ public class RecordDto {
 | 
				
			|||||||
    // 用户ID
 | 
					    // 用户ID
 | 
				
			||||||
    private Integer studentId;
 | 
					    private Integer studentId;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 | 
				
			||||||
    private String categoryName;
 | 
					    private String categoryName;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    private String subCategoryName;
 | 
					    private String subCategoryName;
 | 
				
			||||||
 | 
				
			|||||||
@ -2,6 +2,7 @@ package top.suyiiyii.sims.entity;
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
import com.baomidou.mybatisplus.annotation.IdType;
 | 
					import com.baomidou.mybatisplus.annotation.IdType;
 | 
				
			||||||
import com.baomidou.mybatisplus.annotation.TableId;
 | 
					import com.baomidou.mybatisplus.annotation.TableId;
 | 
				
			||||||
 | 
					import com.tangzc.mpe.autotable.annotation.Column;
 | 
				
			||||||
import com.tangzc.mpe.autotable.annotation.Table;
 | 
					import com.tangzc.mpe.autotable.annotation.Table;
 | 
				
			||||||
import lombok.AllArgsConstructor;
 | 
					import lombok.AllArgsConstructor;
 | 
				
			||||||
import lombok.Data;
 | 
					import lombok.Data;
 | 
				
			||||||
 | 
				
			|||||||
@ -1,7 +1,9 @@
 | 
				
			|||||||
package top.suyiiyii.sims.mapper;
 | 
					package top.suyiiyii.sims.mapper;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import org.apache.ibatis.annotations.Insert;
 | 
				
			||||||
import org.apache.ibatis.annotations.Mapper;
 | 
					import org.apache.ibatis.annotations.Mapper;
 | 
				
			||||||
import org.apache.ibatis.annotations.Select;
 | 
					import org.apache.ibatis.annotations.Select;
 | 
				
			||||||
 | 
					import org.apache.ibatis.annotations.Update;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * @Author tortoise
 | 
					 * @Author tortoise
 | 
				
			||||||
@ -19,6 +21,15 @@ public interface CategoryMapper {
 | 
				
			|||||||
    @Select("SELECT category_name FROM reward_punishment_category WHERE category_id=#{categoryId}")
 | 
					    @Select("SELECT category_name FROM reward_punishment_category WHERE category_id=#{categoryId}")
 | 
				
			||||||
    String getSubCategoryName(Integer categoryId);
 | 
					    String getSubCategoryName(Integer categoryId);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @Select("SELECT category_id FROM reward_punishment_category WHERE sub_category_name=#{subCategoryName}")
 | 
					    @Select("SELECT id FROM reward_punishment_category WHERE sub_category_name=#{subCategoryName}")
 | 
				
			||||||
    Integer getIdBySubCategoryName(String subCategoryName);
 | 
					    Integer getIdBySubCategoryName(String subCategoryName);
 | 
				
			||||||
 | 
					    @Select("SELECT category_id FROM reward_punishment_category WHERE category_name=#{categoryName}")
 | 
				
			||||||
 | 
					    Integer getIdByCategoryName(String categoryName);
 | 
				
			||||||
 | 
					    @Select("SELECT sub_category_name FROM reward_punishment_category WHERE sub_category_name=#{subCategoryName}")
 | 
				
			||||||
 | 
					    String IsSubCategoryName(String subCategoryName);
 | 
				
			||||||
 | 
					@Insert("INSERT INTO reward_punishment_category (category_name, sub_category_name) VALUES (#{categoryName}, #{subCategoryName})")
 | 
				
			||||||
 | 
					    void addsubcategory(String categoryName, String subCategoryName);
 | 
				
			||||||
 | 
					//把categoryId放入对应id下
 | 
				
			||||||
 | 
					@Update("update reward_punishment_category set category_id=#{categoryId} where id=#{categoryId}")
 | 
				
			||||||
 | 
					    void addCategoryId(Integer categoryId);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -27,8 +27,12 @@ public class CategoryService {
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public Integer getIdBySubCategoryName(String subCategoryName) {
 | 
					 | 
				
			||||||
        return categoryMapper.getIdBySubCategoryName(subCategoryName);
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public Integer getIdByCategoryName(String categoryName) {
 | 
				
			||||||
 | 
					        return categoryMapper.getIdByCategoryName(categoryName);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public String IsSubCategoryName(String subCategoryName) {
 | 
				
			||||||
 | 
					        return categoryMapper.IsSubCategoryName(subCategoryName);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -1,10 +1,13 @@
 | 
				
			|||||||
package top.suyiiyii.sims.service;
 | 
					package top.suyiiyii.sims.service;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import org.modelmapper.ModelMapper;
 | 
				
			||||||
import org.springframework.beans.factory.annotation.Autowired;
 | 
					import org.springframework.beans.factory.annotation.Autowired;
 | 
				
			||||||
import org.springframework.stereotype.Service;
 | 
					import org.springframework.stereotype.Service;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import top.suyiiyii.sims.dto.RecordDto;
 | 
				
			||||||
import top.suyiiyii.sims.entity.Record;
 | 
					import top.suyiiyii.sims.entity.Record;
 | 
				
			||||||
 | 
					import top.suyiiyii.sims.mapper.CategoryMapper;
 | 
				
			||||||
import top.suyiiyii.sims.mapper.RecordMapper;
 | 
					import top.suyiiyii.sims.mapper.RecordMapper;
 | 
				
			||||||
import top.suyiiyii.sims.mapper.UserMapper;
 | 
					import top.suyiiyii.sims.mapper.UserMapper;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -24,7 +27,10 @@ public class RecordService {
 | 
				
			|||||||
    RecordMapper recordMapper;
 | 
					    RecordMapper recordMapper;
 | 
				
			||||||
    @Autowired
 | 
					    @Autowired
 | 
				
			||||||
    UserMapper userMapper;
 | 
					    UserMapper userMapper;
 | 
				
			||||||
 | 
					    @Autowired
 | 
				
			||||||
 | 
					    ModelMapper modelMapper;
 | 
				
			||||||
 | 
					    @Autowired
 | 
				
			||||||
 | 
					    CategoryMapper categoryMapper;
 | 
				
			||||||
    public List<Record> getAllRecords(Integer page, Integer size) {
 | 
					    public List<Record> getAllRecords(Integer page, Integer size) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        return recordMapper.getAllRecords(page, size);
 | 
					        return recordMapper.getAllRecords(page, size);
 | 
				
			||||||
@ -44,8 +50,21 @@ public class RecordService {
 | 
				
			|||||||
        recordMapper.deleteRecord(id);
 | 
					        recordMapper.deleteRecord(id);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public void addRecord(Record record) {
 | 
					    public void addRecord(RecordDto recordDto) {
 | 
				
			||||||
 | 
					        //把recordDto转化成Record
 | 
				
			||||||
 | 
					        Record record = modelMapper.map(recordDto, Record.class);
 | 
				
			||||||
 | 
					        //查看数据库里面是否有这个类别
 | 
				
			||||||
 | 
					        String subCategoryName = categoryMapper.IsSubCategoryName(recordDto.getCategoryName());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if(subCategoryName == null) {
 | 
				
			||||||
 | 
					            //没有这个类别就加上
 | 
				
			||||||
 | 
					            categoryMapper.addsubcategory(recordDto.getCategoryName(), recordDto.getSubCategoryName());
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        Integer categoryId = categoryMapper.getIdBySubCategoryName(recordDto.getSubCategoryName());
 | 
				
			||||||
 | 
					        categoryMapper.addCategoryId(categoryId);
 | 
				
			||||||
 | 
					        record.setCategoryId(categoryId);
 | 
				
			||||||
        recordMapper.addRecord(record);
 | 
					        recordMapper.addRecord(record);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public List<Record> getRecordsLike(int page, int size, Integer studentId, String userGroup, String grade) {
 | 
					    public List<Record> getRecordsLike(int page, int size, Integer studentId, String userGroup, String grade) {
 | 
				
			||||||
 | 
				
			|||||||
@ -92,7 +92,6 @@ public class UserService {
 | 
				
			|||||||
            throw new ServiceException("组别不能为空");
 | 
					            throw new ServiceException("组别不能为空");
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        User user = modelMapper.map(req, User.class);
 | 
					        User user = modelMapper.map(req, User.class);
 | 
				
			||||||
 | 
					 | 
				
			||||||
        mpUserMapper.insert(user);
 | 
					        mpUserMapper.insert(user);
 | 
				
			||||||
        user = mpUserMapper.selectOne(new LambdaQueryWrapper<User>().eq(User::getUsername, req.getUsername()));
 | 
					        user = mpUserMapper.selectOne(new LambdaQueryWrapper<User>().eq(User::getUsername, req.getUsername()));
 | 
				
			||||||
        rbacService.addRoleWithUserId(user.getId(), "user");
 | 
					        rbacService.addRoleWithUserId(user.getId(), "user");
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user