package com.xunmei.core.edu.controller;

import com.xunmei.common.core.domain.edu.domain.CoreEduTrainingPlan;
import com.xunmei.common.core.domain.edu.dto.CoreEduTrainingPlanEditDto;
import com.xunmei.common.core.domain.edu.dto.CoreEduTrainingPlanInsertDto;
import com.xunmei.common.core.domain.edu.dto.CoreEduTrainingPlanPageDto;
import com.xunmei.core.edu.service.ICoreEduTrainingPlanService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.xunmei.common.log.annotation.Log;
import com.xunmei.common.log.enums.BusinessType;
import com.xunmei.common.security.annotation.RequiresPermissions;
import com.xunmei.common.core.web.controller.BaseController;
import com.xunmei.common.core.web.domain.AjaxResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import com.xunmei.common.core.web.page.TableDataInfo;

/**
 * 教育培训计划Controller
 *
 * @author xunmei
 * @date 2023-08-24
 */
@Api(tags = {"CoreEduTrainingPlan"})
@RestController
@RequestMapping("/plan")
public class CoreEduTrainingPlanController extends BaseController {
    @Autowired
    private ICoreEduTrainingPlanService coreEduTrainingPlanService;

    /**
     * 查询教育培训计划列表
     */
    @ApiOperation(value = "查询CoreEduTrainingPlan列表")
    @RequiresPermissions("core:plan:list")
    @GetMapping("/list")
    public TableDataInfo list(CoreEduTrainingPlanPageDto coreEduTrainingPlan) {
        return coreEduTrainingPlanService.selectPage(coreEduTrainingPlan);
    }


    /**
     * 获取教育培训计划详细信息
     */
    @ApiOperation(value = "获取CoreEduTrainingPlan详细信息")
    @RequiresPermissions("core:plan:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(coreEduTrainingPlanService.selectCoreEduTrainingPlanById(id));
    }

    /**
     * 新增教育培训计划
     */
    @ApiOperation(value = "新增CoreEduTrainingPlan")
    @RequiresPermissions("core:plan:add")
    @Log(title = "教育培训计划", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody @Validated CoreEduTrainingPlanInsertDto coreEduTrainingPlan) {
        return toAjax(coreEduTrainingPlanService.insertCoreEduTrainingPlan(coreEduTrainingPlan));
    }

    /**
     * 修改教育培训计划
     */
    @ApiOperation(value = "修改CoreEduTrainingPlan")
    @RequiresPermissions("core:plan:edit")
    @Log(title = "教育培训计划", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody @Validated CoreEduTrainingPlanEditDto coreEduTrainingPlan) {
        return toAjax(coreEduTrainingPlanService.updateCoreEduTrainingPlan(coreEduTrainingPlan));
    }

    /**
     * 删除教育培训计划
     */
    @ApiOperation(value = "删除CoreEduTrainingPlan")
    @RequiresPermissions("core:plan:remove")
    @Log(title = "教育培训计划", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(coreEduTrainingPlanService.deleteCoreEduTrainingPlanByIds(ids));
    }

    /**
     * 获取机构下的教育培训计划关联的角色信息
     */
    @ApiOperation(value = "获取机构下的教育培训计划关联的角色信息")
    @RequiresPermissions("core:plan:query")
    @GetMapping("/role/list")
    public AjaxResult listPlanRole(Long orgId) {
        return success(coreEduTrainingPlanService.listPlanRole(orgId));
    }

    /**
     * 计划下发
     */
    @ApiOperation(value = "计划下发")
    @RequiresPermissions("core:plan:publish")
    @GetMapping("/publish/{planId}")
    public AjaxResult publishPlan(@PathVariable("planId") Long planId) {
        coreEduTrainingPlanService.publishPlan(planId);
        return AjaxResult.success();
    }
}
