package com.yanzhen.controller; import com.github.pagehelper.PageInfo; import com.yanzhen.entity.Org; import com.yanzhen.entity.Selection; import com.yanzhen.service.OrgService机构管理; import com.yanzhen.service.SelectionJoinerService用户id筛选增删查改数据库; import com.yanzhen.service.SelectionService学生查询管理; import com.yanzhen.utils.Result; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; import java.util.List; import java.util.Map; @RestController // 声明这是一个RESTful控制器,返回的数据直接写入HTTP响应体中 @RequestMapping("/selection") // 设置请求路径的映射前缀为/selection public class SelectionController { // 定义一个名为SelectionController的类 @Autowired // 自动注入SelectionService实例 private SelectionService学生查询管理 selectionService; @Autowired // 自动注入SelectionJoinerService实例 private SelectionJoinerService用户id筛选增删查改数据库 selectionJoinerService; @Autowired // 自动注入OrgService实例 private OrgService机构管理 orgService; @PostMapping("create") // 映射HTTP POST请求到create方法 public Result create(@RequestBody Selection selection){ // 接收JSON格式的Selection对象作为请求体 int flag = selectionService.create(selection); // 调用selectionService的create方法创建记录 if(flag>0){ // 如果创建成功 return Result.ok(); // 返回操作成功的Result对象 }else{ // 如果创建失败 return Result.fail(); // 返回操作失败的Result对象 } } @GetMapping("delete") // 映射HTTP GET请求到delete方法 public Result delete(String ids){ // 接收要删除的记录ID字符串 int flag = selectionService.delete(ids); // 调用selectionService的delete方法删除记录 if(flag>0){ // 如果删除成功 return Result.ok(); // 返回操作成功的Result对象 }else{ // 如果删除失败 return Result.fail(); // 返回操作失败的Result对象 } } @PostMapping("update") // 映射HTTP POST请求到update方法 public Result update(@RequestBody Selection selection){ // 接收JSON格式的Selection对象作为请求体 int flag = selectionService.update(selection); // 调用selectionService的update方法更新记录 if(flag>0){ // 如果更新成功 return Result.ok(); // 返回操作成功的Result对象 }else{ // 如果更新失败 return Result.fail(); // 返回操作失败的Result对象 } } @GetMapping("detail") // 映射HTTP GET请求到detail方法 public Selection detail(Integer id){ // 接收记录的ID作为参数 return selectionService.detail(id); // 调用selectionService的detail方法获取详细信息并返回 } @PostMapping("query") // 映射HTTP POST请求到query方法 public Map query(@RequestBody Selection selection){ // 接收JSON格式的Selection对象作为请求体 PageInfo pageInfo = selectionService.query(selection); // 调用selectionService的query方法查询记录 pageInfo.getList().forEach(item->{ // 遍历查询结果列表 List clazzes = orgService.queryOrgBySelectionId(item.getId()); // 根据选择ID查询关联的组织信息 item.setClazzes(clazzes); // 将组织信息设置到选择项中 }); return Result.ok(pageInfo); // 返回包含分页信息的Result对象 } }