package com.zhongzheng.controller.base;

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

import com.zhongzheng.modules.base.bo.ApplyAreasAddBo;
import com.zhongzheng.modules.base.bo.ApplyAreasEditBo;
import com.zhongzheng.modules.base.bo.ApplyAreasQueryBo;
import com.zhongzheng.modules.base.domain.ApplyAreas;
import com.zhongzheng.modules.base.service.IApplyAreasService;
import com.zhongzheng.modules.base.vo.ApplyAreasVo;
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.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-10-08
 */
@Api(value = "报考省市控制器", tags = {"报考省市管理"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/apply/areas")
public class ApplyAreasController extends BaseController {

    private final IApplyAreasService iApplyAreasService;

    /**
     * 查询报考省地区列表
     */
    @ApiOperation("查询报考省地区列表")
    @PreAuthorize("@ss.hasPermi('system:areas:list')")
    @GetMapping("/list")
    public TableDataInfo<ApplyAreasVo> list(ApplyAreasQueryBo bo) {
        startPage();
        List<ApplyAreasVo> list = iApplyAreasService.queryList(bo);
        return getDataTable(list);
    }

    /**
     * 查询报考市地区列表
     */
    @ApiOperation("查询报考市地区列表")
    @PreAuthorize("@ss.hasPermi('system:areas:city_list')")
    @GetMapping("/cityList")
    public TableDataInfo<ApplyAreas> cityList(ApplyAreasQueryBo bo) {
        startPage();
        List<ApplyAreas> list = iApplyAreasService.selectCityList(bo);
        return getDataTable(list);
    }

    /**
     * 导出报考地区列表
     */
   /* @ApiOperation("导出报考地区列表")
    @PreAuthorize("@ss.hasPermi('system:areas:export')")
    @Log(title = "报考地区", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult<ApplyAreasVo> export(ApplyAreasQueryBo bo) {
        List<ApplyAreasVo> list = iApplyAreasService.queryList(bo);
        ExcelUtil<ApplyAreasVo> util = new ExcelUtil<ApplyAreasVo>(ApplyAreasVo.class);
        return util.exportExcel(list, "报考地区");
    }*/

    /**
     * 获取报考地区详细信息
     */
    @ApiOperation("获取报考地区详细信息")
    @PreAuthorize("@ss.hasPermi('system:areas:query')")
    @GetMapping("/{areaId}")
    public AjaxResult<ApplyAreasVo> getInfo(@PathVariable("areaId" ) Long areaId) {
        return AjaxResult.success(iApplyAreasService.queryById(areaId));
    }

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

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

    /**
     * 删除报考地区
     */
   /* @ApiOperation("删除报考地区")
    @PreAuthorize("@ss.hasPermi('system:areas:remove')")
    @Log(title = "报考地区" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{areaIds}")
    public AjaxResult<Void> remove(@PathVariable Long[] areaIds) {
        return toAjax(iApplyAreasService.deleteWithValidByIds(Arrays.asList(areaIds), true) ? 1 : 0);
    }*/
}
