package com.zhongzheng.controller.course;

import java.lang.reflect.Field;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import java.util.HashMap;
import java.util.List;
import java.util.Arrays;
import java.util.Map;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.zhongzheng.modules.course.bo.MajorCategoryAddBo;
import com.zhongzheng.modules.course.bo.MajorCategoryEditBo;
import com.zhongzheng.modules.course.bo.MajorCategoryQueryBo;
import com.zhongzheng.modules.course.service.IMajorCategoryService;
import com.zhongzheng.modules.course.vo.MajorCategoryVo;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.expression.EvaluationContext;
import org.springframework.expression.spel.support.StandardEvaluationContext;
import org.springframework.security.access.prepost.PreAuthorize;
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.zhongzheng.common.annotation.Log;
import com.zhongzheng.common.core.controller.BaseController;
import com.zhongzheng.common.core.domain.AjaxResult;
import com.zhongzheng.common.enums.BusinessType;
import com.zhongzheng.common.utils.poi.ExcelUtil;
import com.zhongzheng.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 【专业分类】Controller
 *
 * @author hjl
 * @date 2021-05-13
 */
@Api(value = "【专业分类】控制器", tags = {"专业分类"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/course/category")
public class MajorCategoryController extends BaseController {

    private final IMajorCategoryService iMajorCategoryService;

    /**
     * 查询【专业分类】列表
     */
    @ApiOperation("查询【专业分类】列表")
    @PreAuthorize("@ss.hasPermi('course:category:list')")
    @GetMapping("/list")
    public TableDataInfo<MajorCategoryVo> list(MajorCategoryQueryBo bo) {
        startPage();
        List<MajorCategoryVo> list = iMajorCategoryService.queryList(bo);
        return getDataTable(list);
    }

    /**
     * 导出【专业分类】列表
     */
  /*  @ApiOperation("导出【专业分类】列表")
    @PreAuthorize("@ss.hasPermi('course:category:export')")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult<MajorCategoryVo> export(MajorCategoryQueryBo bo) {
        List<MajorCategoryVo> list = iMajorCategoryService.queryList(bo);
        ExcelUtil<MajorCategoryVo> util = new ExcelUtil<MajorCategoryVo>(MajorCategoryVo.class);
        return util.exportExcel(list, "【专业分类】");
    }*/

    /**
     * 获取【专业分类】详细信息
     */
    @ApiOperation("获取【专业分类】详细信息")
    @PreAuthorize("@ss.hasPermi('course:category:query')")
    @GetMapping("/{categoryId}")
    public AjaxResult<MajorCategoryVo> getInfo(@PathVariable("categoryId" ) Long categoryId) {
        return AjaxResult.success(iMajorCategoryService.queryById(categoryId));
    }

    /**
     * 新增【专业分类】
     */
    @ApiOperation("新增【专业分类】")
    @ApiOperationSupport(ignoreParameters = {"updateTime","createTime"})
    @PreAuthorize("@ss.hasPermi('course:category:add')")
    @Log(title = "【专业分类】", businessType = BusinessType.INSERT)
    @PostMapping()
    public AjaxResult add(@Validated  @RequestBody MajorCategoryAddBo bo) throws NoSuchMethodException, NoSuchFieldException, IllegalAccessException {
        Long id = iMajorCategoryService.insertByAddBo(bo);
        String content = "新增分类:"+bo.getCategoryName();
        return AjaxResult.success_log(id,content);
    }

    /**
     * 修改【专业分类】
     */
    @ApiOperation("修改【专业分类】")
    @ApiOperationSupport(ignoreParameters = {"updateTime","createTime"})
    @PreAuthorize("@ss.hasPermi('course:category:edit')")
    @Log(title = "【专业分类】", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    public AjaxResult<Void> edit(@Validated @RequestBody MajorCategoryEditBo bo) {
        if(iMajorCategoryService.updateByEditBo(bo)){
            Long id = bo.getCategoryId();
            String content = "修改分类:"+bo.getCategoryName();
            return AjaxResult.success_log(id,content);
        }
        return AjaxResult.error();
    }

    /**
     * 删除【专业分类】
     */
    /*@ApiOperation("删除【专业分类】")
    @PreAuthorize("@ss.hasPermi('course:category:remove')")
    @Log(title = "【专业分类】" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{categoryIds}")
    public AjaxResult<Void> remove(@PathVariable Long[] categoryIds) {
        return toAjax(iMajorCategoryService.deleteWithValidByIds(Arrays.asList(categoryIds), true) ? 1 : 0);
    }*/
}
