mirror of
				https://github.com/suyiiyii/SIMS.git
				synced 2025-11-04 15:54:52 +08:00 
			
		
		
		
	完成查询自己的记录的接口
This commit is contained in:
		
							parent
							
								
									7528d960f1
								
							
						
					
					
						commit
						aa08b363e1
					
				@ -22,7 +22,6 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupp
 | 
				
			|||||||
//                    .excludePathPatterns("/user/login") // 排除不需要验证的路径
 | 
					//                    .excludePathPatterns("/user/login") // 排除不需要验证的路径
 | 
				
			||||||
//                    .excludePathPatterns("/user/register")
 | 
					//                    .excludePathPatterns("/user/register")
 | 
				
			||||||
//                    .excludePathPatterns("/v3/api-docs/**");
 | 
					//                    .excludePathPatterns("/v3/api-docs/**");
 | 
				
			||||||
 | 
					 | 
				
			||||||
            super.addInterceptors(registry);
 | 
					            super.addInterceptors(registry);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -42,10 +42,6 @@ public class JwtInterceptor implements HandlerInterceptor {
 | 
				
			|||||||
                return true;
 | 
					                return true;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					 | 
				
			||||||
   //     request.setAttribute();
 | 
					 | 
				
			||||||
   //     request.getAttribute()
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        // 执行认证
 | 
					        // 执行认证
 | 
				
			||||||
        if (StrUtil.isBlank(token)) {
 | 
					        if (StrUtil.isBlank(token)) {
 | 
				
			||||||
            //权限错误
 | 
					            //权限错误
 | 
				
			||||||
@ -65,6 +61,8 @@ public class JwtInterceptor implements HandlerInterceptor {
 | 
				
			|||||||
        if (!JwtUtils.verifyToken(token, user.getPassword())) {
 | 
					        if (!JwtUtils.verifyToken(token, user.getPassword())) {
 | 
				
			||||||
            throw new ServiceException("401", "请登录");
 | 
					            throw new ServiceException("401", "请登录");
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					        // 验证token后,如果一切正常,将token存储到request的属性中
 | 
				
			||||||
 | 
					        request.setAttribute("token", token);
 | 
				
			||||||
        return true;
 | 
					        return true;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -1,7 +1,11 @@
 | 
				
			|||||||
package top.suyiiyii.sims.controller;
 | 
					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 io.swagger.v3.oas.annotations.Operation;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import jakarta.servlet.http.HttpServletRequest;
 | 
				
			||||||
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.*;
 | 
				
			||||||
@ -18,6 +22,7 @@ import top.suyiiyii.sims.service.CategoryService;
 | 
				
			|||||||
import top.suyiiyii.sims.service.RecordService;
 | 
					import top.suyiiyii.sims.service.RecordService;
 | 
				
			||||||
import top.suyiiyii.sims.service.RoleService;
 | 
					import top.suyiiyii.sims.service.RoleService;
 | 
				
			||||||
import top.suyiiyii.sims.service.UserService;
 | 
					import top.suyiiyii.sims.service.UserService;
 | 
				
			||||||
 | 
					import top.suyiiyii.sims.utils.JwtUtils;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import java.time.LocalDateTime;
 | 
					import java.time.LocalDateTime;
 | 
				
			||||||
import java.util.ArrayList;
 | 
					import java.util.ArrayList;
 | 
				
			||||||
@ -81,8 +86,47 @@ RecordController {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    @Operation(summary = "获取自己的奖惩记录")
 | 
					    @Operation(summary = "获取自己的奖惩记录")
 | 
				
			||||||
    @GetMapping("/record")
 | 
					    @GetMapping("/record")
 | 
				
			||||||
    public Result<List<RecordDto>> record(Integer page, Integer size) {
 | 
					    public Result<List<RecordDto>> record(@RequestParam(defaultValue = "0") int page,
 | 
				
			||||||
        return Result.success(new ArrayList<>());
 | 
					                                          @RequestParam(defaultValue = "10") int size,
 | 
				
			||||||
 | 
					                                          HttpServletRequest request) {
 | 
				
			||||||
 | 
					        String token = request.getHeader("Authorization").replace("Bearer ", "");
 | 
				
			||||||
 | 
					        String userId= JwtUtils.extractUserId(token);
 | 
				
			||||||
 | 
					        List<RecordDto> recordDtos=new ArrayList<>();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        List<Record> records = recordService.getMyAllRecords(page, size,userId);
 | 
				
			||||||
 | 
					        for (Record record : records) {
 | 
				
			||||||
 | 
					            RecordDto recordDto = new RecordDto();
 | 
				
			||||||
 | 
					            Integer studentId=record.getStudentId();
 | 
				
			||||||
 | 
					            recordDto.setStudentId(studentId);
 | 
				
			||||||
 | 
					            User user = UserService.selectByUserId(studentId);
 | 
				
			||||||
 | 
					            recordDto.setName(user.getUsername());
 | 
				
			||||||
 | 
					            recordDto.setGrade(user.getGrade());
 | 
				
			||||||
 | 
					            recordDto.setGroup(user.getUserGroup());
 | 
				
			||||||
 | 
					            List<Role> roles = UserService.selectRolesById(user.getId());
 | 
				
			||||||
 | 
					            ArrayList<String> roleName = new ArrayList<>();
 | 
				
			||||||
 | 
					            for (Role role : roles) {
 | 
				
			||||||
 | 
					                roleName.add(role.getRoleName());
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            recordDto.setRoles(roleName);
 | 
				
			||||||
 | 
					            recordDto.setCategoryName(categoryService.getCategoryName(record.getCategoryId()));
 | 
				
			||||||
 | 
					            recordDto.setSubCategoryName(categoryService.getsubCategoryName(record.getCategoryId()));
 | 
				
			||||||
 | 
					            recordDto.setDate(record.getDate());
 | 
				
			||||||
 | 
					            recordDto.setContent(record.getContent());
 | 
				
			||||||
 | 
					            recordDto.setReason(record.getReason());
 | 
				
			||||||
 | 
					            recordDto.setAmount(record.getAmount());
 | 
				
			||||||
 | 
					            recordDto.setRemark(record.getRemark());
 | 
				
			||||||
 | 
					            recordDto.setIsRevoked(record.getIsRevoked());
 | 
				
			||||||
 | 
					            // 撤销日期
 | 
				
			||||||
 | 
					            recordDto.setRevokeDate(record.getRevokeDate());
 | 
				
			||||||
 | 
					            recordDto.setRevokeReason(record.getRevokeReason());
 | 
				
			||||||
 | 
					            recordDto.setRevokeRemark(record.getRevokeRemark());
 | 
				
			||||||
 | 
					            recordDto.setOperatorUserId(record.getOperatorUserId());
 | 
				
			||||||
 | 
					            recordDto.setLastUpdateTime(record.getLastUpdateTime());
 | 
				
			||||||
 | 
					            recordDtos.add(recordDto);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        return Result.success(recordDtos);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @Operation(summary = "更新单个奖惩记录")
 | 
					    @Operation(summary = "更新单个奖惩记录")
 | 
				
			||||||
 | 
				
			|||||||
@ -21,4 +21,7 @@ public interface RecordMapper {
 | 
				
			|||||||
    //分页查询
 | 
					    //分页查询
 | 
				
			||||||
@Select("select * from record limit #{page},#{size}")
 | 
					@Select("select * from record limit #{page},#{size}")
 | 
				
			||||||
    List<Record> getAllRecords(Integer page, Integer 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);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -43,6 +43,7 @@ public interface UserMapper extends BaseMapper<User> {
 | 
				
			|||||||
            "username = #{username}, " +
 | 
					            "username = #{username}, " +
 | 
				
			||||||
            "name = #{name}, " +
 | 
					            "name = #{name}, " +
 | 
				
			||||||
            "email = #{email}, " +
 | 
					            "email = #{email}, " +
 | 
				
			||||||
 | 
					            "grade = #{grade}, " +
 | 
				
			||||||
            "userGroup = #{group} " +
 | 
					            "userGroup = #{group} " +
 | 
				
			||||||
            "WHERE id = #{id}")
 | 
					            "WHERE id = #{id}")
 | 
				
			||||||
    int updateUser(User user);
 | 
					    int updateUser(User user);
 | 
				
			||||||
@ -52,7 +53,7 @@ public interface UserMapper extends BaseMapper<User> {
 | 
				
			|||||||
     * @param
 | 
					     * @param
 | 
				
			||||||
     * @return 用户对象
 | 
					     * @return 用户对象
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    @Select("SELECT id, student_id, username, password, name, email,user_group from user WHERE id = #{id}")
 | 
					    @Select("SELECT id, student_id, username, password, name, email,grade,user_group from user WHERE student_id = #{id}")
 | 
				
			||||||
    User selectByUserId(Integer id);
 | 
					    User selectByUserId(Integer id);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
@ -73,5 +74,6 @@ public interface UserMapper extends BaseMapper<User> {
 | 
				
			|||||||
   User selectByUserName(@Param("username") String 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);
 | 
					    void updatePassword(User user);
 | 
				
			||||||
 | 
					@Select("select student_id from user where id = #{userId}")
 | 
				
			||||||
 | 
					    String getStudentIdById(String userId);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -1,11 +1,13 @@
 | 
				
			|||||||
package top.suyiiyii.sims.service;
 | 
					package top.suyiiyii.sims.service;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import org.checkerframework.checker.units.qual.A;
 | 
				
			||||||
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.dto.RecordDto;
 | 
				
			||||||
import top.suyiiyii.sims.entity.Record;
 | 
					import top.suyiiyii.sims.entity.Record;
 | 
				
			||||||
import top.suyiiyii.sims.mapper.RecordMapper;
 | 
					import top.suyiiyii.sims.mapper.RecordMapper;
 | 
				
			||||||
 | 
					import top.suyiiyii.sims.mapper.UserMapper;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import java.util.List;
 | 
					import java.util.List;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -21,10 +23,17 @@ import java.util.List;
 | 
				
			|||||||
public class RecordService {
 | 
					public class RecordService {
 | 
				
			||||||
    @Autowired
 | 
					    @Autowired
 | 
				
			||||||
    RecordMapper recordMapper;
 | 
					    RecordMapper recordMapper;
 | 
				
			||||||
 | 
					    @Autowired
 | 
				
			||||||
 | 
					    UserMapper userMapper;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    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);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public List<Record> getMyAllRecords(Integer page, Integer size, String userId) {
 | 
				
			||||||
 | 
					        String studentId = userMapper.getStudentIdById(userId);
 | 
				
			||||||
 | 
					        return recordMapper.getMyAllRecords(page, size, studentId);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user