package com.qmth.distributed.print.api;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qmth.boot.api.constant.ApiConstant;
import com.qmth.distributed.print.business.bean.dto.professional.ProfessionalDto;
import com.qmth.distributed.print.business.entity.BasicProfessional;
import com.qmth.distributed.print.business.service.BasicProfessionalService;
import com.qmth.teachcloud.common.contant.SystemConstant;
import com.qmth.teachcloud.common.util.Result;
import com.qmth.teachcloud.common.util.ResultUtil;
import io.swagger.annotations.*;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.constraints.Max;
import javax.validation.constraints.Min;

/**
 * <p>
 * 专业认证专业表 前端控制器
 * </p>
 *
 * @author xf
 * @since 2024-04-22
 */
@Api(tags = "专业Controller")
@RestController
@RequestMapping(ApiConstant.DEFAULT_URI_PREFIX + SystemConstant.PREFIX_URL_PROFESSIONAL)
public class BasicProfessionalController {

    @Resource
    private BasicProfessionalService basicProfessionalService;

    @ApiOperation(value = "查询（不分页）")
    @RequestMapping(value = "/list", method = RequestMethod.POST)
    @ApiResponses({@ApiResponse(code = 200, message = "分页查询", response = ProfessionalDto.class)})
    public Result list(@ApiParam(value = "专业名称") @RequestParam(required = false) String name,
                       @ApiParam(value = "所属学院") @RequestParam(required = false) Long orgId) {
        return ResultUtil.ok(basicProfessionalService.listData(name, orgId));
    }

    @ApiOperation(value = "查询")
    @RequestMapping(value = "/page", method = RequestMethod.POST)
    @ApiResponses({@ApiResponse(code = 200, message = "分页查询", response = ProfessionalDto.class)})
    public Result page(@ApiParam(value = "专业名称") @RequestParam(required = false) String name,
                       @ApiParam(value = "所属学院") @RequestParam(required = false) Long orgId,
                       @ApiParam(value = "分页页码", required = true) @RequestParam @Min(SystemConstant.PAGE_NUMBER_MIN) Integer pageNumber,
                       @ApiParam(value = "分页数", required = true) @RequestParam @Min(SystemConstant.PAGE_SIZE_MIN) @Max(SystemConstant.PAGE_SIZE_MAX) Integer pageSize) {
        return ResultUtil.ok(basicProfessionalService.pageData(new Page<>(pageNumber, pageSize), name, orgId));
    }

    @ApiOperation(value = "新增")
    @RequestMapping(value = "/save", method = RequestMethod.POST)
    @ApiResponses({@ApiResponse(code = 200, message = "新增", response = Boolean.class)})
    public Result save(@RequestBody BasicProfessional tpProfessional) {
        return ResultUtil.ok(basicProfessionalService.saveData(tpProfessional));
    }

    @ApiOperation(value = "删除")
    @RequestMapping(value = "/remove", method = RequestMethod.POST)
    @ApiResponses({@ApiResponse(code = 200, message = "新增", response = Boolean.class)})
    public Result remove(Long id) {
        return ResultUtil.ok(basicProfessionalService.remove(id));
    }

}
