You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
94 lines
2.8 KiB
94 lines
2.8 KiB
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;
|
|
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
|
|
@RequestMapping("/selection")
|
|
public class SelectionController {
|
|
|
|
//注入实例
|
|
//注入选择管理的服务类
|
|
@Autowired
|
|
private SelectionService selectionService;
|
|
//注入SelectionJoiner的服务类
|
|
@Autowired
|
|
private SelectionJoinerService selectionJoinerService;
|
|
//注入宿舍服务类
|
|
@Autowired
|
|
private OrgService orgService;
|
|
|
|
//创建新的实例
|
|
@PostMapping("create")
|
|
public Result create(@RequestBody Selection selection){
|
|
//在选择管理服务类中引用create方法
|
|
int flag = selectionService.create(selection);
|
|
//判断是否创建成功
|
|
if(flag>0){
|
|
//成功
|
|
return Result.ok();
|
|
}else{
|
|
//失败
|
|
return Result.fail();
|
|
}
|
|
}
|
|
//删除选择记录
|
|
@GetMapping("delete")
|
|
public Result delete(String ids){
|
|
//在选择管理服务类中引用delete方法
|
|
int flag = selectionService.delete(ids);
|
|
//判断是否删除成功
|
|
if(flag>0){
|
|
//成功
|
|
return Result.ok();
|
|
}else{
|
|
//失败
|
|
return Result.fail();
|
|
}
|
|
}
|
|
//更新选择信息
|
|
@PostMapping("update")
|
|
public Result update(@RequestBody Selection selection){
|
|
//在选择管理服务类中引用update方法
|
|
int flag = selectionService.update(selection);
|
|
//判断是否创建成功
|
|
if(flag>0){
|
|
//成功
|
|
return Result.ok();
|
|
}else{
|
|
//失败
|
|
return Result.fail();
|
|
}
|
|
}
|
|
//获取选择的详细信息
|
|
@GetMapping("detail")
|
|
public Selection detail(Integer id){
|
|
//返回结果
|
|
return selectionService.detail(id);
|
|
}
|
|
//查询选择信息
|
|
@PostMapping("query")
|
|
public Map<String,Object> query(@RequestBody Selection selection){
|
|
//创建分页对象
|
|
PageInfo<Selection> pageInfo = selectionService.query(selection);
|
|
//遍历查询
|
|
pageInfo.getList().forEach(item->{
|
|
//根据选择ID查询组织信息
|
|
List<Org> clazzes = orgService.queryOrgBySelectionId(item.getId());
|
|
//组织信息设置到选择项中
|
|
item.setClazzes(clazzes);
|
|
});
|
|
//返回结果
|
|
return Result.ok(pageInfo);
|
|
}
|
|
} |