CGradeController.java 7.4 KB
package cn.bronet.admin.demo.controller;

import java.util.List;
import java.util.Arrays;

import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiModelProperty;
import lombok.RequiredArgsConstructor;
import javax.validation.constraints.*;

import lombok.extern.slf4j.Slf4j;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import cn.bronet.admin.common.annotation.RepeatSubmit;
import cn.bronet.admin.common.annotation.Log;
import cn.bronet.admin.common.core.controller.BaseController;
import cn.bronet.admin.common.core.domain.AjaxResult;
import cn.bronet.admin.common.core.validate.AddGroup;
import cn.bronet.admin.common.core.validate.EditGroup;
import cn.bronet.admin.common.enums.BusinessType;
import cn.bronet.admin.demo.domain.vo.CGradeVo;
import cn.bronet.admin.demo.domain.bo.CGradeBo;
import cn.bronet.admin.demo.service.ICGradeService;
import cn.bronet.admin.common.utils.poi.ExcelUtil;
import cn.bronet.admin.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 学校年级Controller
 *
 * @author ruoyi
 * @date 2021-09-09
 */
@Slf4j
@Validated
@Api(value = "学校年级控制器", tags = {"学校年级管理"})
@RequiredArgsConstructor()
@RestController
@RequestMapping("/demo/grade")
public class CGradeController extends BaseController {

    private final ICGradeService iCGradeService;

    /**
     * 查询学校年级列表
     */
    @ApiOperation("查询学校年级列表")
    @PreAuthorize("@ss.hasPermi('demo:grade:list')")
    @GetMapping("/list")
    public TableDataInfo<CGradeVo> list(@Validated CGradeBo bo) {

    	log.info("<<<接收的参数<<<::"+bo);
        return iCGradeService.queryPageList(bo);
    }

    /**
     * 导出学校年级列表
     */
    @ApiOperation("导出学校年级列表")
    @PreAuthorize("@ss.hasPermi('demo:grade:export')")
    @Log(title = "学校年级", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult<CGradeVo> export(@Validated CGradeBo bo) {
        List<CGradeVo> list = iCGradeService.queryList(bo);
        ExcelUtil<CGradeVo> util = new ExcelUtil<CGradeVo>(CGradeVo.class);
        return util.exportExcel(list, "学校年级");
    }

    /**
     * 获取需要修改的年级信息
     */
    @ApiOperation("获取需要修改的年级信息")
    @PreAuthorize("@ss.hasPermi('demo:grade:query')")
    @GetMapping("/{id}")
    public AjaxResult<CGradeVo> getInfo(@NotNull(message = "主键不能为空")
                                                  @PathVariable("id") Long id) {
        return AjaxResult.success(iCGradeService.queryById(id));
    }

    /**
     * 新增学校年级
     */
    @ApiOperation("新增学校年级")
    @PreAuthorize("@ss.hasPermi('demo:grade:add')")
    @Log(title = "学校年级", businessType = BusinessType.INSERT)
    @RepeatSubmit
    @PostMapping()
    public AjaxResult<Void> add(@Validated(AddGroup.class) @RequestBody CGradeBo bo) {
        return toAjax(iCGradeService.insertByBo(bo) ? 1 : 0);
    }

    /**
     * 修改学校年级和班级
     */
    @ApiOperation("修改学校年级和班级")
    @PreAuthorize("@ss.hasPermi('demo:grade:edit')")
    @Log(title = "学校年级", businessType = BusinessType.UPDATE)
    @RepeatSubmit
    @PutMapping()
    public AjaxResult<Void> edit(@Validated(EditGroup.class) @RequestBody CGradeBo bo) {
        return toAjax(iCGradeService.updateByBo(bo) ? 1 : 0);
    }

    /**
     * 删除学校班级
     */
    @ApiOperation("删除学校班级")
    @PreAuthorize("@ss.hasPermi('demo:grade:remove')")
    @Log(title = "学校班级" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult<Void> remove(@NotEmpty(message = "主键不能为空")
                                       @PathVariable Long[] ids) {
        return toAjax(iCGradeService.deleteWithValidByIds(Arrays.asList(ids), true) ? 1 : 0);
    }


	/**
	 * 查询此学校下所有的年级
	 *//*
	@ApiOperation("查询此年级下的所有年级")
	@GetMapping("/getAllGrades")
	public AjaxResult myAllGrades(@RequestBody CGradeBo bo){

		return iCGradeService.getAllGrades(bo);
	}*/

	/**
	 * 添加年级
	 */
	@ApiOperation("添加年级")
	@PostMapping("/saveGrade")
	public AjaxResult mySaveGrade(@RequestBody CGradeBo bo){

		log.info("<<<接收的参数<<<::"+bo);

		return iCGradeService.saveGrade(bo);
	}

	/**
	 * 查询此学校下正常状态的年级
	 */
	@ApiOperation("查询此学校下正常状态的年级")
	@GetMapping("/getGrades")
	public AjaxResult myGrades(){

		return iCGradeService.getGrades();
	}

	/**
	 * 添加班级
	 */
	@ApiOperation("添加班级")
	@PostMapping("/saveClasses")
	public AjaxResult myClasses(@RequestBody CGradeBo bo){

		log.info("<<<接收的参数<<<::"+bo);

		return iCGradeService.saveClasses(bo);
	}

	/**
	 * 查询此学校下所有班级
	 *//*
	@ApiOperation("查询此学校下所有班级")
	@PostMapping("/getAllClasses")
	public AjaxResult myAllClasses(@RequestBody CGradeBo bo){

		log.info("<<<接收的参数<<<::"+bo);

		return iCGradeService.getAllClasses(bo);
	}*/

	/**
	 * 查询此学校下正常状态的班级
	 */
	@ApiImplicitParam(name = "gradeParentId",value = "年级ID",dataType = "Long",required = true,paramType = "query")
	@ApiOperation("查询此学校下正常状态的班级")
	@GetMapping("/getClasses")
	public AjaxResult myClasses( Long gradeParentId){

		return iCGradeService.getClasses(gradeParentId);
	}

	/**
	 * 查看年级的详细信息
	 */
	@ApiImplicitParam(name = "gradeId",value ="年级ID",dataType = "Long",required = true,paramType = "query")
	@ApiOperation("查看年级的详细信息")
	@PostMapping("/getGradeInfo")
	public AjaxResult myGradeInfo(Long gradeId){

		log.info("<<<接收的参数<<<::"+gradeId);

		return iCGradeService.getGradeInfo(gradeId);
	}

	/**
	 * 查看班级的详细信息
	 */
	@ApiImplicitParam(name = "gradeId",value = "班级ID",dataType = "Long",required = true,paramType = "query")
	@ApiOperation("查看班级的详细信息")
	@PostMapping("/getClassInfo")
	public AjaxResult myClassInfo(Long gradeId){

		log.info("<<<接收的参数<<<::"+gradeId);

		return iCGradeService.getClassInfo(gradeId);
	}

	/**
	 * 获取需要修改的班级信息
	 */
	@ApiImplicitParam(name = "gradeId",value = "班级ID",dataType = "Long",required = true,paramType = "query")
	@ApiOperation("获取需要修改的班级信息")
	@GetMapping("/getClassInfo")
	public AjaxResult myClassEdit(Long gradeId){

		log.info("<<<接收的参数<<<::"+gradeId);

		return iCGradeService.getUpdateClassInfo(gradeId);
	}

	/**
	 * 删除学校年级
	 */
	@ApiOperation("删除学校年级")
	@DeleteMapping("/deleteGrade/{ids}")
	public AjaxResult myDeleteGrade(@NotEmpty(message = "主键不能为空")
								   @PathVariable Long[] ids) {

		List<@NotEmpty(message = "主键不能为空") Long> gradeIds = Arrays.asList(ids);

		return iCGradeService.deleteGrade(gradeIds);
	}

	/**
	 * 删除学校班级(备选)
	 */
	@ApiOperation("删除学校班级(备选)")
	@DeleteMapping("/deleteClasses/{ids}")
	public AjaxResult myDeleteClasses(@NotEmpty(message = "主键不能为空")
									@PathVariable Long[] ids) {

		List<@NotEmpty(message = "主键不能为空") Long> gradeIds = Arrays.asList(ids);

		return iCGradeService.deleteClasses(gradeIds);
	}

}