package com.zhongzheng.controller.user;

import java.util.List;
import java.util.Arrays;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.zhongzheng.modules.user.bo.SchoolTypeAddBo;
import com.zhongzheng.modules.user.bo.SchoolTypeEditBo;
import com.zhongzheng.modules.user.bo.SchoolTypeQueryBo;
import com.zhongzheng.modules.user.service.ISchoolTypeService;
import com.zhongzheng.modules.user.vo.SchoolTypeVo;
import lombok.RequiredArgsConstructor;
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-18
 */
@Api(value = "高校类型控制器", tags = {"高校类型管理"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/system/type")
public class SchoolTypeController extends BaseController {

    private final ISchoolTypeService iSchoolTypeService;

    /**
     * 查询高校类型列表
     */
    @ApiOperation("查询高校类型列表")
    @PreAuthorize("@ss.hasPermi('system:type:list')")
    @GetMapping("/list")
    public TableDataInfo<SchoolTypeVo> list(SchoolTypeQueryBo bo) {
        startPage();
        List<SchoolTypeVo> list = iSchoolTypeService.queryList(bo);
        return getDataTable(list);
    }

    /**
     * 导出高校类型列表
     */
  /*  @ApiOperation("导出高校类型列表")
    @PreAuthorize("@ss.hasPermi('system:type:export')")
    @Log(title = "高校类型", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult<SchoolTypeVo> export(SchoolTypeQueryBo bo) {
        List<SchoolTypeVo> list = iSchoolTypeService.queryList(bo);
        ExcelUtil<SchoolTypeVo> util = new ExcelUtil<SchoolTypeVo>(SchoolTypeVo.class);
        return util.exportExcel(list, "高校类型");
    }*/

    /**
     * 获取高校类型详细信息
     */
    @ApiOperation("获取高校类型详细信息")
    @PreAuthorize("@ss.hasPermi('system:type:query')")
    @GetMapping("/{id}")
    public AjaxResult<SchoolTypeVo> getInfo(@PathVariable("id" ) Long id) {
        return AjaxResult.success(iSchoolTypeService.queryById(id));
    }

    /**
     * 新增高校类型
     */
    @ApiOperation("新增高校类型")
    @ApiOperationSupport(ignoreParameters = {"updateTime","createTime"})
    @PreAuthorize("@ss.hasPermi('system:type:add')")
    @Log(title = "高校类型", businessType = BusinessType.INSERT)
    @PostMapping()
    public AjaxResult<Void> add(@Validated  @RequestBody SchoolTypeAddBo bo) {
        return toAjax(iSchoolTypeService.insertByAddBo(bo) ? 1 : 0);
    }

    /**
     * 修改高校类型
     */
    @ApiOperation("修改高校类型")
    @ApiOperationSupport(ignoreParameters = {"updateTime","createTime"})
    @PreAuthorize("@ss.hasPermi('system:type:edit')")
    @Log(title = "高校类型", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    public AjaxResult<Void> edit(@Validated @RequestBody SchoolTypeEditBo bo) {
        return toAjax(iSchoolTypeService.updateByEditBo(bo) ? 1 : 0);
    }

    /**
     * 删除高校类型
     */
    @ApiOperation("删除高校类型")
    @PreAuthorize("@ss.hasPermi('system:type:remove')")
    @Log(title = "高校类型" , businessType = BusinessType.DELETE)
    @PostMapping("/delete")
    public AjaxResult<Void> remove(@PathVariable Long[] ids) {
        return toAjax(iSchoolTypeService.deleteWithValidByIds(Arrays.asList(ids), true) ? 1 : 0);
    }
}
