package com.zhongzheng.controller.exam;

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

import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
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.modules.exam.vo.ExamSiteVo;
import com.zhongzheng.modules.exam.bo.ExamSiteQueryBo;
import com.zhongzheng.modules.exam.bo.ExamSiteAddBo;
import com.zhongzheng.modules.exam.bo.ExamSiteEditBo;
import com.zhongzheng.modules.exam.service.IExamSiteService;
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 ruoyi
 * @date 2021-12-06
 */
@Api(value = "考试地点控制器", tags = {"考试地点管理"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/system/site")
public class ExamSiteController extends BaseController {

    private final IExamSiteService iExamSiteService;

    /**
     * 查询考试地点列表
     */
    @ApiOperation("查询考试地点列表")
    @PreAuthorize("@ss.hasPermi('system:site:list')")
    @GetMapping("/list")
    public TableDataInfo<ExamSiteVo> list(ExamSiteQueryBo bo) {
        startPage();
        List<ExamSiteVo> list = iExamSiteService.queryList(bo);
        return getDataTable(list);
    }


    /**
     * 获取考试地点详细信息
     */
    @ApiOperation("获取考试地点详细信息")
    @PreAuthorize("@ss.hasPermi('system:site:query')")
    @GetMapping("/{siteId}")
    public AjaxResult<ExamSiteVo> getInfo(@PathVariable("siteId" ) Long siteId) {
        return AjaxResult.success(iExamSiteService.queryById(siteId));
    }

    /**
     * 新增考试地点
     */
    @ApiOperation("新增考试地点")
    @PreAuthorize("@ss.hasPermi('system:site:add')")
    @Log(title = "考试地点", businessType = BusinessType.INSERT)
    @PostMapping()
    public AjaxResult<Void> add(@RequestBody ExamSiteAddBo bo) {
        return toAjax(iExamSiteService.insertByAddBo(bo) ? 1 : 0);
    }

    /**
     * 修改考试地点
     */
    @ApiOperation("修改考试地点")
    @PreAuthorize("@ss.hasPermi('system:site:edit')")
    @Log(title = "考试地点", businessType = BusinessType.UPDATE)
    @PostMapping("edit")
    public AjaxResult<Void> edit(@RequestBody ExamSiteEditBo bo) {
        return toAjax(iExamSiteService.updateByEditBo(bo) ? 1 : 0);
    }

}
