mirror of
				https://github.com/suyiiyii/SIMS.git
				synced 2025-11-05 00:04:54 +08:00 
			
		
		
		
	调整个人查询无法出现类别类型
This commit is contained in:
		
							parent
							
								
									471079f68c
								
							
						
					
					
						commit
						e48adf67c3
					
				@ -19,6 +19,7 @@ import top.suyiiyii.sims.service.UserService;
 | 
				
			|||||||
import top.suyiiyii.sims.utils.JwtUtils;
 | 
					import top.suyiiyii.sims.utils.JwtUtils;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import java.util.ArrayList;
 | 
					import java.util.ArrayList;
 | 
				
			||||||
 | 
					import java.util.HashSet;
 | 
				
			||||||
import java.util.List;
 | 
					import java.util.List;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@RestController
 | 
					@RestController
 | 
				
			||||||
@ -52,7 +53,7 @@ RecordController {
 | 
				
			|||||||
        return Result.success(recordDtos);
 | 
					        return Result.success(recordDtos);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @AuthAccess(allowRoles = {"user","admin"})
 | 
					    @AuthAccess(allowRoles = {"user"})
 | 
				
			||||||
    @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,
 | 
				
			||||||
@ -112,10 +113,12 @@ RecordController {
 | 
				
			|||||||
            @RequestParam(defaultValue = "0") int page,
 | 
					            @RequestParam(defaultValue = "0") int page,
 | 
				
			||||||
            @RequestParam(defaultValue = "10") int size,
 | 
					            @RequestParam(defaultValue = "10") int size,
 | 
				
			||||||
            String username,Integer studentId, String userGroup, String grade,String roleName) {
 | 
					            String username,Integer studentId, String userGroup, String grade,String roleName) {
 | 
				
			||||||
        Integer s1=studentId;
 | 
					        Integer s1;
 | 
				
			||||||
        List<Integer> studentIds = new ArrayList<>();
 | 
					        List<Integer> studentIds = new ArrayList<>();
 | 
				
			||||||
        List<Record> records=new ArrayList<>();
 | 
					        List<Record> records=new ArrayList<>();
 | 
				
			||||||
        studentIds.add(studentId);
 | 
					        if(studentId!=null) {
 | 
				
			||||||
 | 
					            studentIds.add(studentId);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
        if(roleName!="") {
 | 
					        if(roleName!="") {
 | 
				
			||||||
            //rolename查用户id
 | 
					            //rolename查用户id
 | 
				
			||||||
            Integer userId = roleService.getIdByrolename(roleName);
 | 
					            Integer userId = roleService.getIdByrolename(roleName);
 | 
				
			||||||
@ -134,10 +137,88 @@ RecordController {
 | 
				
			|||||||
        List<RecordDto> RecordDtos = new ArrayList<>();
 | 
					        List<RecordDto> RecordDtos = new ArrayList<>();
 | 
				
			||||||
        for (Record record : records) {
 | 
					        for (Record record : records) {
 | 
				
			||||||
            RecordDto RecordDto = modelMapper.map(record, RecordDto.class);
 | 
					            RecordDto RecordDto = modelMapper.map(record, RecordDto.class);
 | 
				
			||||||
 | 
					            RecordDto.setCategoryName(categoryService.getCategoryName(record.getCategoryId()));
 | 
				
			||||||
 | 
					            RecordDto.setSubCategoryName(categoryService.getsubCategoryName(record.getCategoryId()));
 | 
				
			||||||
 | 
					            RecordDtos.add(RecordDto);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        return Result.success(RecordDtos);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    @AuthAccess(allowRoles = {"admin"})
 | 
				
			||||||
 | 
					    @Operation(summary = "筛选查询奖惩记录")
 | 
				
			||||||
 | 
					    @GetMapping("/admin/screenRecords")
 | 
				
			||||||
 | 
					    public Result<List<RecordDto>> screenRecords(
 | 
				
			||||||
 | 
					            @RequestParam(defaultValue = "0") int page,
 | 
				
			||||||
 | 
					            @RequestParam(defaultValue = "10") int size,
 | 
				
			||||||
 | 
					            String categoryName) {
 | 
				
			||||||
 | 
					        List<Integer> studentIds = new ArrayList<>();
 | 
				
			||||||
 | 
					        //CategoryName不是奖励或者惩罚
 | 
				
			||||||
 | 
					        if (!categoryName.equals("奖励")
 | 
				
			||||||
 | 
					                && !categoryName.equals("惩罚")) {
 | 
				
			||||||
 | 
					            return Result.error("请选择正确奖惩类别");
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        List<Integer> idByCategoryName = categoryService.getIdByCategoryName(categoryName);
 | 
				
			||||||
 | 
					        for (Integer i : idByCategoryName) {
 | 
				
			||||||
 | 
					            Integer sid = recordService.getSidByCategoryId(i);
 | 
				
			||||||
 | 
					            studentIds.add(sid);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        List<Record> records=new ArrayList<>();
 | 
				
			||||||
 | 
					        HashSet<Integer> studentIds1= new HashSet<>(studentIds);
 | 
				
			||||||
 | 
					        for (Integer Sid : studentIds1) {
 | 
				
			||||||
 | 
					            if(Sid!=null){
 | 
				
			||||||
 | 
					                records.addAll(recordService.getRecordsById(page,size,Sid));
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        List<RecordDto> RecordDtos = new ArrayList<>();
 | 
				
			||||||
 | 
					        for (Record record : records) {
 | 
				
			||||||
 | 
					            RecordDto RecordDto = modelMapper.map(record, RecordDto.class);
 | 
				
			||||||
 | 
					            RecordDto.setCategoryName(categoryService.getCategoryName(record.getCategoryId()));
 | 
				
			||||||
 | 
					            RecordDto.setSubCategoryName(categoryService.getsubCategoryName(record.getCategoryId()));
 | 
				
			||||||
            RecordDtos.add(RecordDto);
 | 
					            RecordDtos.add(RecordDto);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        return Result.success(RecordDtos);
 | 
					        return Result.success(RecordDtos);
 | 
				
			||||||
 | 
					 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @AuthAccess(allowRoles = {"user","admin"})
 | 
				
			||||||
 | 
					    @Operation(summary = "用户筛选查询奖惩记录")
 | 
				
			||||||
 | 
					    @GetMapping("/screenRecords")
 | 
				
			||||||
 | 
					    public Result<List<RecordDto>> screenRecords1(
 | 
				
			||||||
 | 
					            @RequestParam(defaultValue = "0") int page,
 | 
				
			||||||
 | 
					            @RequestParam(defaultValue = "10") int size,
 | 
				
			||||||
 | 
					            String categoryName,HttpServletRequest request) {
 | 
				
			||||||
 | 
					        HttpSession session = request.getSession();
 | 
				
			||||||
 | 
					        String token = (String) session.getAttribute("token");
 | 
				
			||||||
 | 
					        String userId = JwtUtils.extractUserId(token);
 | 
				
			||||||
 | 
					        if (userId==null){
 | 
				
			||||||
 | 
					            throw new RuntimeException("请先登录");
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        List<Integer> studentIds = new ArrayList<>();
 | 
				
			||||||
 | 
					        //CategoryName不是奖励或者惩罚
 | 
				
			||||||
 | 
					        if (!categoryName.equals("奖励")
 | 
				
			||||||
 | 
					                && !categoryName.equals("惩罚")) {
 | 
				
			||||||
 | 
					            return Result.error("请选择正确奖惩类别");
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        List<Integer> idByCategoryName = categoryService.getIdByCategoryName(categoryName);
 | 
				
			||||||
 | 
					        for (Integer i : idByCategoryName) {
 | 
				
			||||||
 | 
					            Integer sid = recordService.getSidByCategoryId(i);
 | 
				
			||||||
 | 
					            if(sid!=null) {
 | 
				
			||||||
 | 
					                studentIds.add(sid);
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        List<Record> records=new ArrayList<>();
 | 
				
			||||||
 | 
					        HashSet<Integer> studentIds1= new HashSet<>(studentIds);
 | 
				
			||||||
 | 
					        for (Integer Sid : studentIds1) {
 | 
				
			||||||
 | 
					            Integer studentId1 =userService.getStudentIdByUserId(Integer.valueOf(userId));
 | 
				
			||||||
 | 
					            if (studentId1!= null && studentId1.equals(Sid)) {
 | 
				
			||||||
 | 
					                records.addAll(recordService.getRecordsById(page, size, Sid));
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        List<RecordDto> RecordDtos = new ArrayList<>();
 | 
				
			||||||
 | 
					        for (Record record : records) {
 | 
				
			||||||
 | 
					            RecordDto RecordDto = modelMapper.map(record, RecordDto.class);
 | 
				
			||||||
 | 
					            RecordDto.setCategoryName(categoryService.getCategoryName(record.getCategoryId()));
 | 
				
			||||||
 | 
					            RecordDto.setSubCategoryName(categoryService.getsubCategoryName(record.getCategoryId()));
 | 
				
			||||||
 | 
					            RecordDtos.add(RecordDto);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        return Result.success(RecordDtos);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -9,6 +9,8 @@ import lombok.NoArgsConstructor;
 | 
				
			|||||||
@NoArgsConstructor
 | 
					@NoArgsConstructor
 | 
				
			||||||
public class RecordDto {
 | 
					public class RecordDto {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    //
 | 
				
			||||||
 | 
					    private Integer id;
 | 
				
			||||||
    // 用户ID
 | 
					    // 用户ID
 | 
				
			||||||
    private Integer studentId;
 | 
					    private Integer studentId;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -8,6 +8,8 @@ import lombok.AllArgsConstructor;
 | 
				
			|||||||
import lombok.Data;
 | 
					import lombok.Data;
 | 
				
			||||||
import lombok.NoArgsConstructor;
 | 
					import lombok.NoArgsConstructor;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import java.util.Objects;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * @Author tortoise
 | 
					 * @Author tortoise
 | 
				
			||||||
 * @Date 2024/8/9 15:43
 | 
					 * @Date 2024/8/9 15:43
 | 
				
			||||||
@ -27,9 +29,19 @@ public class RewardPunishmentCategory {
 | 
				
			|||||||
    private Integer categoryId;
 | 
					    private Integer categoryId;
 | 
				
			||||||
    // 类别名称
 | 
					    // 类别名称
 | 
				
			||||||
    private String categoryName;
 | 
					    private String categoryName;
 | 
				
			||||||
 | 
					 | 
				
			||||||
    private String subCategoryName;
 | 
					    private String subCategoryName;
 | 
				
			||||||
    // 类别说明
 | 
					    // 类别说明
 | 
				
			||||||
    private String description;
 | 
					    private String description;
 | 
				
			||||||
 | 
					    @Override
 | 
				
			||||||
 | 
					    public boolean equals(Object o) {
 | 
				
			||||||
 | 
					        if (this == o) return true;
 | 
				
			||||||
 | 
					        if (o == null || getClass() != o.getClass()) return false;
 | 
				
			||||||
 | 
					        RewardPunishmentCategory that = (RewardPunishmentCategory) o;
 | 
				
			||||||
 | 
					        return Objects.equals(categoryId, that.categoryId);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Override
 | 
				
			||||||
 | 
					    public int hashCode() {
 | 
				
			||||||
 | 
					        return Objects.hash(categoryId);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -5,6 +5,8 @@ import org.apache.ibatis.annotations.Mapper;
 | 
				
			|||||||
import org.apache.ibatis.annotations.Select;
 | 
					import org.apache.ibatis.annotations.Select;
 | 
				
			||||||
import org.apache.ibatis.annotations.Update;
 | 
					import org.apache.ibatis.annotations.Update;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import java.util.List;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * @Author tortoise
 | 
					 * @Author tortoise
 | 
				
			||||||
 * @Date 2024/8/16 23:31
 | 
					 * @Date 2024/8/16 23:31
 | 
				
			||||||
@ -15,16 +17,16 @@ import org.apache.ibatis.annotations.Update;
 | 
				
			|||||||
 */
 | 
					 */
 | 
				
			||||||
@Mapper
 | 
					@Mapper
 | 
				
			||||||
public interface CategoryMapper {
 | 
					public interface CategoryMapper {
 | 
				
			||||||
    @Select("SELECT * FROM reward_punishment_category WHERE category_id=#{id}")
 | 
					    @Select("SELECT category_name FROM reward_punishment_category WHERE category_id=#{id}")
 | 
				
			||||||
    String getCategoryName(Integer categoryId);
 | 
					    String getCategoryName(Integer categoryId);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @Select("SELECT category_name FROM reward_punishment_category WHERE category_id=#{categoryId}")
 | 
					    @Select("SELECT sub_category_name FROM reward_punishment_category WHERE category_id=#{categoryId}")
 | 
				
			||||||
    String getSubCategoryName(Integer categoryId);
 | 
					    String getSubCategoryName(Integer categoryId);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @Select("SELECT 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}")
 | 
					    @Select("SELECT category_id FROM reward_punishment_category WHERE category_name=#{categoryName}")
 | 
				
			||||||
    Integer getIdByCategoryName(String categoryName);
 | 
					    List<Integer> getIdByCategoryName(String categoryName);
 | 
				
			||||||
    @Select("SELECT sub_category_name FROM reward_punishment_category WHERE sub_category_name=#{subCategoryName}")
 | 
					    @Select("SELECT sub_category_name FROM reward_punishment_category WHERE sub_category_name=#{subCategoryName}")
 | 
				
			||||||
    String IsSubCategoryName(String subCategoryName);
 | 
					    String IsSubCategoryName(String subCategoryName);
 | 
				
			||||||
@Insert("INSERT INTO reward_punishment_category (category_name, sub_category_name) VALUES (#{categoryName}, #{subCategoryName})")
 | 
					@Insert("INSERT INTO reward_punishment_category (category_name, sub_category_name) VALUES (#{categoryName}, #{subCategoryName})")
 | 
				
			||||||
 | 
				
			|||||||
@ -72,4 +72,11 @@ public interface RecordMapper {
 | 
				
			|||||||
            @Param("userGroup") String userGroup,
 | 
					            @Param("userGroup") String userGroup,
 | 
				
			||||||
            @Param("grade") String grade
 | 
					            @Param("grade") String grade
 | 
				
			||||||
    );
 | 
					    );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					@Select("select student_id from record where category_id = #{i}")
 | 
				
			||||||
 | 
					    Integer getSidByCategoryId(Integer i);
 | 
				
			||||||
 | 
					@Select("SELECT * FROM record WHERE student_id = #{sid} LIMIT #{page},#{size}")
 | 
				
			||||||
 | 
					    List<Record> getRecordsById(int page, int size, Integer sid);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -4,6 +4,8 @@ import org.springframework.beans.factory.annotation.Autowired;
 | 
				
			|||||||
import org.springframework.stereotype.Service;
 | 
					import org.springframework.stereotype.Service;
 | 
				
			||||||
import top.suyiiyii.sims.mapper.CategoryMapper;
 | 
					import top.suyiiyii.sims.mapper.CategoryMapper;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import java.util.List;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * @Author tortoise
 | 
					 * @Author tortoise
 | 
				
			||||||
 * @Date 2024/8/16 23:32
 | 
					 * @Date 2024/8/16 23:32
 | 
				
			||||||
@ -28,11 +30,11 @@ public class CategoryService {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public Integer getIdByCategoryName(String categoryName) {
 | 
					    public List<Integer> getIdByCategoryName(String categoryName) {
 | 
				
			||||||
        return categoryMapper.getIdByCategoryName(categoryName);
 | 
					        return categoryMapper.getIdByCategoryName(categoryName);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public String IsSubCategoryName(String subCategoryName) {
 | 
					
 | 
				
			||||||
        return categoryMapper.IsSubCategoryName(subCategoryName);
 | 
					
 | 
				
			||||||
    }
 | 
					
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -70,4 +70,14 @@ public class RecordService {
 | 
				
			|||||||
    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) {
 | 
				
			||||||
        return recordMapper.getRecordsLike(page, size, studentId, userGroup,grade);
 | 
					        return recordMapper.getRecordsLike(page, size, studentId, userGroup,grade);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public  Integer getSidByCategoryId(Integer i) {
 | 
				
			||||||
 | 
					        return recordMapper.getSidByCategoryId(i);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public List<Record> getRecordsById(int page, int size, Integer sid) {
 | 
				
			||||||
 | 
					        return recordMapper.getRecordsById(page, size, sid);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user