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.MatrixDto;
import com.qmth.distributed.print.business.bean.dto.professional.ProfessionalDto;
import com.qmth.distributed.print.business.bean.params.professional.TPCourseParam;
import com.qmth.distributed.print.business.bean.result.ScoreResult;
import com.qmth.distributed.print.business.entity.TPCourse;
import com.qmth.distributed.print.business.entity.TPMatrix;
import com.qmth.distributed.print.business.entity.TPProfessional;
import com.qmth.distributed.print.business.entity.TPRequirement;
import com.qmth.distributed.print.business.service.TPCourseService;
import com.qmth.distributed.print.business.service.TPMatrixService;
import com.qmth.distributed.print.business.service.TPProfessionalService;
import com.qmth.distributed.print.business.service.TPRequirementService;
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.servlet.http.HttpServletResponse;
import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import java.util.List;

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

    @Resource
    private TPProfessionalService tpProfessionalService;
    @Resource
    private TPCourseService tpCourseService;
    @Resource
    private TPRequirementService tpRequirementService;
    @Resource
    private TPMatrixService tpMatrixService;

    @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(tpProfessionalService.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 TPProfessional tpProfessional) {
        return ResultUtil.ok(tpProfessionalService.saveData(tpProfessional));
    }

    @ApiOperation(value = "课程管理-选择课程")
    @RequestMapping(value = "/course/query_list", method = RequestMethod.POST)
    @ApiResponses({@ApiResponse(code = 200, message = "分页查询", response = TPCourse.class)})
    public Result queryList(@ApiParam(value = "机构ID", required = true) @RequestParam Long orgId,
                            @ApiParam(value = "机构ID", required = true) @RequestParam Long professionalId) {
        return ResultUtil.ok(tpCourseService.queryList(orgId, professionalId));
    }

    @ApiOperation(value = "课程管理-查询")
    @RequestMapping(value = "/course/list", method = RequestMethod.POST)
    @ApiResponses({@ApiResponse(code = 200, message = "分页查询", response = TPCourse.class)})
    public Result listCourse(@ApiParam(value = "专业ID", required = true) @RequestParam Long professionalId) {
        return ResultUtil.ok(tpCourseService.listCourse(professionalId));
    }

    @ApiOperation(value = "课程管理-新增")
    @RequestMapping(value = "/course/save", method = RequestMethod.POST)
    @ApiResponses({@ApiResponse(code = 200, message = "新增", response = Boolean.class)})
    public Result saveCourse(@RequestBody TPCourseParam tpCourseParam) {
        return ResultUtil.ok(tpCourseService.saveCourse(tpCourseParam));
    }

    @ApiOperation(value = "课程管理-排序")
    @RequestMapping(value = "/course/sort", method = RequestMethod.POST)
    @ApiResponses({@ApiResponse(code = 200, message = "排序", response = Boolean.class)})
    public Result saveSort(@RequestBody List<TPCourse> courseList) {
        return ResultUtil.ok(tpCourseService.saveSort(courseList));
    }

    @ApiOperation(value = "课程管理-删除")
    @RequestMapping(value = "/course/remove", method = RequestMethod.POST)
    @ApiResponses({@ApiResponse(code = 200, message = "删除", response = Boolean.class)})
    public Result removeCourse(@ApiParam(value = "专业课程ID", required = true) @RequestParam Long id) {
        return ResultUtil.ok(tpCourseService.removeCourse(id));
    }

    @ApiOperation(value = "毕业要求-查询")
    @RequestMapping(value = "/requirement/list", method = RequestMethod.POST)
    @ApiResponses({@ApiResponse(code = 200, message = "分页查询", response = TPRequirement.class)})
    public Result listRequirement(@ApiParam(value = "专业ID", required = true) @RequestParam Long professionalId) {
        return ResultUtil.ok(tpRequirementService.listRequirement(professionalId));
    }

    @ApiOperation(value = "毕业要求-新增/编辑")
    @RequestMapping(value = "/requirement/save", method = RequestMethod.POST)
    @ApiResponses({@ApiResponse(code = 200, message = "分页查询", response = Boolean.class)})
    public Result saveRequirement(@RequestBody TPRequirement tpRequirement) {
        return ResultUtil.ok(tpRequirementService.saveRequirement(tpRequirement));
    }

    @ApiOperation(value = "毕业要求-排序")
    @RequestMapping(value = "/requirement/sort", method = RequestMethod.POST)
    @ApiResponses({@ApiResponse(code = 200, message = "排序", response = Boolean.class)})
    public Result sortRequirement(@RequestBody List<TPRequirement> requirementList) {
        return ResultUtil.ok(tpRequirementService.saveSort(requirementList));
    }

    @ApiOperation(value = "毕业要求-删除")
    @RequestMapping(value = "/requirement/remove", method = RequestMethod.POST)
    @ApiResponses({@ApiResponse(code = 200, message = "删除", response = Boolean.class)})
    public Result removeRequirement(@ApiParam(value = "毕业要求ID", required = true) @RequestParam Long id) {
        return ResultUtil.ok(tpRequirementService.removeRequirement(id));
    }

    @ApiOperation(value = "毕业矩阵支撑-查询")
    @RequestMapping(value = "/matrix/get", method = RequestMethod.POST)
    @ApiResponses({@ApiResponse(code = 200, message = "分页查询", response = MatrixDto.class)})
    public Result listMatrix(@ApiParam(value = "专业ID", required = true) @RequestParam Long professionalId) {
        return ResultUtil.ok(tpMatrixService.getMatrix(professionalId));
    }

    @ApiOperation(value = "毕业矩阵支撑-提交")
    @RequestMapping(value = "/matrix/save", method = RequestMethod.POST)
    @ApiResponses({@ApiResponse(code = 200, message = "分页查询", response = Boolean.class)})
    public Result saveMatrix(@RequestBody List<TPMatrix> tpMatrixList) {
        return ResultUtil.ok(tpMatrixService.saveMatrix(tpMatrixList));
    }

    @ApiOperation(value = "毕业矩阵支撑-下载")
    @RequestMapping(value = "/matrix/download", method = RequestMethod.POST)
    @ApiResponses({@ApiResponse(code = 200, message = "分页查询", response = Boolean.class)})
    public void downloadMatrix(@ApiParam(value = "专业ID", required = true) @RequestParam Long professionalId,
                               HttpServletResponse response) {
        tpMatrixService.downloadMatrix(professionalId, response);
    }

}
