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.bean.params.obe.cultureProgram.ObeCultureProgramCourseParam;
import com.qmth.distributed.print.business.bean.params.obe.cultureProgram.ObeCultureProgramDescriptionParam;
import com.qmth.distributed.print.business.entity.*;
import com.qmth.distributed.print.business.service.*;
import com.qmth.teachcloud.common.annotation.OperationLogDetail;
import com.qmth.teachcloud.common.contant.SystemConstant;
import com.qmth.teachcloud.common.enums.log.OperationTypeEnum;
import com.qmth.teachcloud.common.util.Result;
import com.qmth.teachcloud.common.util.ResultUtil;
import io.swagger.annotations.*;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import java.util.List;

/**
 * <p>
 * 培养方案 前端控制器
 * </p>
 */
@Api(tags = "培养方案Controller")
@RestController
@RequestMapping(ApiConstant.DEFAULT_URI_PREFIX + SystemConstant.PREFIX_URL_CULTURE_PROGRAM)
public class ObeCultureProgramController {

    @Resource
    private ObeCultureProgramService obeCultureProgramService;
    @Resource
    private ObeCultureProgramTargetService obeCultureProgramTargetService;
    @Resource
    private ObeCultureProgramRequirementService obeCultureProgramRequirementService;
    @Resource
    private ObeRequirementTargetMatrixService obeRequirementTargetMatrixService;
    @Resource
    private ObeCultureProgramCourseService obeCultureProgramCourseService;
    @Resource
    private ObeCourseRequirementMatrixService obeCourseRequirementMatrixService;

    @ApiOperation(value = "查询")
    @RequestMapping(value = "/page", method = RequestMethod.POST)
    @ApiResponses({@ApiResponse(code = 200, message = "分页查询", response = ProfessionalDto.class)})
    public Result page(@ApiParam(value = "专业ID") @RequestParam(required = false) Long professionalId,
                       @ApiParam(value = "培养方案名称") @RequestParam(required = false) String name,
                       @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(obeCultureProgramService.pageData(new Page<>(pageNumber, pageSize), professionalId, name));
    }

    @ApiOperation(value = "新增/编辑")
    @RequestMapping(value = "/save", method = RequestMethod.POST)
    @ApiResponses({@ApiResponse(code = 200, message = "新增/编辑", response = Boolean.class)})
    @OperationLogDetail(operationType = OperationTypeEnum.SAVE, detail = "新增/编辑操作，ID：{{obeCultureProgram.id}}、专业ID：{{obeCultureProgram.professionalId}}、名称：{{obeCultureProgram.name}}")
    public Result save(@Validated @RequestBody ObeCultureProgram obeCultureProgram) {
        return ResultUtil.ok(obeCultureProgramService.saveData(obeCultureProgram));
    }

    @ApiOperation(value = "删除")
    @RequestMapping(value = "/remove", method = RequestMethod.POST)
    @ApiResponses({@ApiResponse(code = 200, message = "删除", response = Boolean.class)})
    @OperationLogDetail(operationType = OperationTypeEnum.DELETE, detail = "删除操作，ID：{{id}}")
    public Result removeCultureProgram(@ApiParam(value = "培养方案ID", required = true) @RequestParam(value = "id") Long id) {
        return ResultUtil.ok(obeCultureProgramService.delete(id));
    }

    @ApiOperation(value = "复制")
    @RequestMapping(value = "/copy", method = RequestMethod.POST)
    @ApiResponses({@ApiResponse(code = 200, message = "删除", response = Boolean.class)})
    @OperationLogDetail(operationType = OperationTypeEnum.UPDATE, detail = "复制操作，ID：{{id}}")
    public Result copyCultureProgram(@ApiParam(value = "培养方案ID", required = true) @RequestParam(value = "id") Long id) {
        return ResultUtil.ok(obeCultureProgramService.copy(id));
    }

    @ApiOperation(value = "保存总体描述")
    @RequestMapping(value = "/description/save", method = RequestMethod.POST)
    @ApiResponses({@ApiResponse(code = 200, message = "保存总体描述", response = Boolean.class)})
    public Result saveDescription(@Validated @RequestBody ObeCultureProgramDescriptionParam obeCultureProgramDescriptionParam) {
        return ResultUtil.ok(obeCultureProgramService.saveDescription(obeCultureProgramDescriptionParam));
    }

    @ApiOperation(value = "基本信息查询")
    @RequestMapping(value = "/get", method = RequestMethod.POST)
    @ApiResponses({@ApiResponse(code = 200, message = "保存总体描述", response = Boolean.class)})
    public Result get(@ApiParam(value = "培养方案ID", required = true) @RequestParam(value = "id") Long id) {
        return ResultUtil.ok(obeCultureProgramService.getByCultureProgramId(id));
    }

    @ApiOperation(value = "培养目标-列表")
    @RequestMapping(value = "/target/list", method = RequestMethod.POST)
    @ApiResponses({@ApiResponse(code = 200, message = "培养目标-列表", response = Boolean.class)})
    public Result listCultureProgramTarget(@ApiParam(value = "培养方案ID", required = true) @RequestParam(value = "cultureProgramId") Long cultureProgramId) {
        return ResultUtil.ok(obeCultureProgramTargetService.list(cultureProgramId));
    }

    @ApiOperation(value = "培养目标-新增/编辑")
    @RequestMapping(value = "/target/save", method = RequestMethod.POST)
    @ApiResponses({@ApiResponse(code = 200, message = "培养目标-新增/编辑", response = Boolean.class)})
    @OperationLogDetail(operationType = OperationTypeEnum.SAVE, detail = "培养目标-新增/编辑操作，ID：{{obeCultureProgram.id}}、专业ID：{{obeCultureProgram.professionalId}}、名称：{{obeCultureProgram.name}}")
    public Result saveCultureProgramTarget(@Validated @RequestBody ObeCultureProgramTarget obeCultureProgramTarget) {
        return ResultUtil.ok(obeCultureProgramTargetService.saveData(obeCultureProgramTarget));
    }

    @ApiOperation(value = "培养目标-删除")
    @RequestMapping(value = "/target/remove", method = RequestMethod.POST)
    @ApiResponses({@ApiResponse(code = 200, message = "培养目标-删除", response = Boolean.class)})
    @OperationLogDetail(operationType = OperationTypeEnum.DELETE, detail = "培养目标-删除操作，ID：{{id}}")
    public Result deleteCultureProgramTarget(@ApiParam(value = "培养目标ID", required = true) @RequestParam(value = "id") Long id) {
        return ResultUtil.ok(obeCultureProgramTargetService.delete(id));
    }

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

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

    @ApiOperation(value = "毕业要求-新增指标点")
    @RequestMapping(value = "/requirement/node/add", method = RequestMethod.POST)
    @ApiResponses({@ApiResponse(code = 200, message = "分页查询", response = Boolean.class)})
    public Result addRequirementNode(ObeCultureProgramRequirement obeCultureProgramRequirement) {
        return ResultUtil.ok(obeCultureProgramRequirementService.addRequirementNode(obeCultureProgramRequirement));
    }

    @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(obeCultureProgramRequirementService.removeRequirement(id));
    }

    @ApiOperation(value = "毕业要求-设置期望值")
    @RequestMapping(value = "/requirement/expect/save", method = RequestMethod.POST)
    @ApiResponses({@ApiResponse(code = 200, message = "分页查询", response = Boolean.class)})
    public Result saveRequirementExpect(@RequestBody ObeCultureProgramRequirement obeCultureProgramRequirement) {
        return ResultUtil.ok(obeCultureProgramRequirementService.saveRequirementExpect(obeCultureProgramRequirement));
    }

    @ApiOperation(value = "培养目标与毕业要求关系矩阵-查询")
    @RequestMapping(value = "/target/matrix/get", method = RequestMethod.POST)
    @ApiResponses({@ApiResponse(code = 200, message = "分页查询", response = Result.class)})
    public Result listTargetMatrix(@ApiParam(value = "培养方案ID", required = true) @RequestParam Long cultureProgramId) {
        return ResultUtil.ok(obeRequirementTargetMatrixService.getMatrix(cultureProgramId));
    }

    @ApiOperation(value = "培养目标与毕业要求关系矩阵-提交")
    @RequestMapping(value = "/target/matrix/save", method = RequestMethod.POST)
    @ApiResponses({@ApiResponse(code = 200, message = "分页查询", response = Boolean.class)})
    public Result saveTargetMatrix(@RequestBody List<ObeRequirementTargetMatrix> obeRequirementTargetMatrixList) {
        return ResultUtil.ok(obeRequirementTargetMatrixService.saveMatrix(obeRequirementTargetMatrixList));
    }

    @ApiOperation(value = "课程体系-选择课程")
    @RequestMapping(value = "/course/query_list", method = RequestMethod.POST)
    @ApiResponses({@ApiResponse(code = 200, message = "分页查询", response = Result.class)})
    public Result queryList(@ApiParam(value = "培养方案ID", required = true) @RequestParam Long cultureProgramId,
                            @ApiParam(value = "机构ID") @RequestParam(required = false) Long orgId) {
        return ResultUtil.ok(obeCultureProgramCourseService.queryList(cultureProgramId, orgId));
    }

    @ApiOperation(value = "课程体系-列表")
    @RequestMapping(value = "/course/list", method = RequestMethod.POST)
    @ApiResponses({@ApiResponse(code = 200, message = "分页查询", response = Result.class)})
    public Result listCourse(@ApiParam(value = "培养方案ID", required = true) @RequestParam Long cultureProgramId) {
        return ResultUtil.ok(obeCultureProgramCourseService.listCourse(cultureProgramId));
    }

    @ApiOperation(value = "课程体系-新增")
    @RequestMapping(value = "/course/save", method = RequestMethod.POST)
    @ApiResponses({@ApiResponse(code = 200, message = "新增", response = Boolean.class)})
    public Result saveCourse(@RequestBody ObeCultureProgramCourseParam obeCultureProgramCourseParam) {
        return ResultUtil.ok(obeCultureProgramCourseService.saveCourse(obeCultureProgramCourseParam));
    }

    @ApiOperation(value = "课程体系-排序")
    @RequestMapping(value = "/course/sort", method = RequestMethod.POST)
    @ApiResponses({@ApiResponse(code = 200, message = "排序", response = Boolean.class)})
    public Result saveSort(@RequestBody List<ObeCultureProgramCourse> courseList) {
        return ResultUtil.ok(obeCultureProgramCourseService.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(obeCultureProgramCourseService.removeCourse(id));
    }

    @ApiOperation(value = "课程支撑毕业要求达成矩阵-查询")
    @RequestMapping(value = "/course/matrix/get", method = RequestMethod.POST)
    @ApiResponses({@ApiResponse(code = 200, message = "分页查询", response = Result.class)})
    public Result listCourseMatrix(@ApiParam(value = "培养方案ID", required = true) @RequestParam Long cultureProgramId) {
        return ResultUtil.ok(obeCourseRequirementMatrixService.getMatrix(cultureProgramId));
    }

    @ApiOperation(value = "课程支撑毕业要求达成矩阵-提交")
    @RequestMapping(value = "/course/matrix/save", method = RequestMethod.POST)
    @ApiResponses({@ApiResponse(code = 200, message = "分页查询", response = Boolean.class)})
    public Result saveCourseMatrix(@RequestBody List<ObeCourseRequirementMatrix> obeCourseRequirementMatrices) {
        return ResultUtil.ok(obeCourseRequirementMatrixService.saveMatrix(obeCourseRequirementMatrices));
    }
}
