package com.zd.system.controller;

import com.zd.common.core.domain.per.PerFun;
import com.zd.common.core.domain.per.PerPrefix;
import com.zd.common.core.utils.poi.ExcelUtil;
import com.zd.common.core.web.controller.BaseController;
import com.zd.common.core.web.domain.ResultData;
import com.zd.common.core.web.page.TableDataInfo;
import com.zd.common.log.annotation.Log;
import com.zd.common.log.enums.BusinessType;
import com.zd.common.security.annotation.PreAuthorize;
import com.zd.system.domain.SysMajor;
import com.zd.system.service.ISysMajorService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * majorController
 *
 * @author zd
 * @date 2021-12-10
 */
@RestController
@Api(tags = "【major】")
//作者手动加入 ，在接口上加作者@ApiOperationSupport(author = "XXX")
@RequestMapping("/major")
public class SysMajorController extends BaseController {
    @Autowired
    private ISysMajorService sysMajorService;

    /**
     * 查询major列表 "system:major:list"
     */
    @PreAuthorize(hasPermi = PerPrefix.SYSTEM_MAJOR+ PerFun.LIST)
    @GetMapping("/list")
    @ApiOperation(value = "查询major列表")
    public TableDataInfo<SysMajor> list(SysMajor sysMajor) {
        startPage();
        List<SysMajor> list = sysMajorService.selectSysMajorList(sysMajor);
        return getDataTable(list);
    }

    // "system:major:list"
//    @PreAuthorize(hasPermi = PerPrefix.SYSTEM_MAJOR+ PerFun.LIST)
    @GetMapping("/listAll")
    @ApiOperation(value = "查询major列表")
    public ResultData<List<SysMajor>> listAll(SysMajor sysMajor) {
        List<SysMajor> list = sysMajorService.selectSysMajorList(sysMajor);
        return ResultData.success(list);
    }


    /**
     * 导出major列表 "system:major:export"
     */
    @ApiOperation(value = "导出major列表")
    @PreAuthorize(hasPermi = PerPrefix.SYSTEM_MAJOR+ PerFun.EXPORT)
    @Log(title = "major", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysMajor sysMajor) throws IOException {
        List<SysMajor> list = sysMajorService.selectSysMajorList(sysMajor);
        ExcelUtil<SysMajor> util = new ExcelUtil<SysMajor>(SysMajor.class);
        util.exportExcel(response, list, "major数据");
    }

    /**
     * 获取major详细信息 "system:major:query"
     */
    @ApiOperation(value = "获取major详细信息")
    @PreAuthorize(hasPermi = PerPrefix.SYSTEM_MAJOR+ PerFun.QUERY)
    @GetMapping(value = "/{id}")
    public ResultData<SysMajor> getInfo(@PathVariable("id") Long id) {
        return ResultData.success(sysMajorService.selectSysMajorById(id));
    }

    /**
     * 新增major "system:major:add"
     */
    @ApiOperation(value = "新增major")
    @PreAuthorize(hasPermi = PerPrefix.SYSTEM_MAJOR+ PerFun.ADD)
    @Log(title = "major", businessType = BusinessType.INSERT)
    @PostMapping
    public ResultData add(@RequestBody SysMajor sysMajor) {
        return ResultData.result(sysMajorService.insertSysMajor(sysMajor));
    }

    /**
     * 修改major "system:major:edit"
     */
    @ApiOperation(value = "修改major")
    @PreAuthorize(hasPermi = PerPrefix.SYSTEM_MAJOR+ PerFun.EDIT)
    @Log(title = "major", businessType = BusinessType.UPDATE)
    @PutMapping
    public ResultData edit(@RequestBody SysMajor sysMajor) {
        return ResultData.result(sysMajorService.updateSysMajor(sysMajor));
    }

    /**
     * 删除major "system:major:remove"
     */
    @ApiOperation(value = "删除major")
    @PreAuthorize(hasPermi = PerPrefix.SYSTEM_MAJOR+ PerFun.REMOVE)
    @Log(title = "major", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public ResultData remove(@PathVariable Long[] ids) {
        return ResultData.result(sysMajorService.deleteSysMajorByIds(ids));
    }

    @GetMapping("/listPower")
    @ApiOperation(value = "查询major列表")
    public TableDataInfo<SysMajor> listPower(SysMajor sysMajor) {
        //startPage();
        List<SysMajor> list = sysMajorService.selectSysMajorListPower(sysMajor);
        return getDataTable(list);
    }
}
