package com.vctgo.system.controller;

import com.vctgo.common.core.utils.poi.ExcelUtil;
import com.vctgo.common.core.web.controller.BaseController;
import com.vctgo.common.core.web.domain.AjaxResult;
import com.vctgo.common.log.annotation.Log;
import com.vctgo.common.log.enums.BusinessType;
import com.vctgo.common.security.annotation.RequiresPermissions;
import com.vctgo.system.domain.SysProvince;
import com.vctgo.system.service.ISysProvinceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 省份信息Controller
 *
 * @author wanglonghua
 * @date 2023-06-08
 */
@RestController
@RequestMapping("/province")
public class SysProvinceController extends BaseController
{
    @Autowired
    private ISysProvinceService sysProvinceService;

    /**
     * 查询省份信息列表
     */
    @RequiresPermissions("system:province:list")
    @GetMapping("/list")
    public AjaxResult list(SysProvince sysProvince)
    {
        List<SysProvince> list = sysProvinceService.selectSysProvinceList(sysProvince);
        return AjaxResult.success(list);
    }

    /**
     * 查询省份信息列表
     */
    @GetMapping("/tree/list")
    public AjaxResult getProvinceTreeList(@RequestParam(value = "provinceId", required = false) String provinceId,
                                @RequestParam(value = "cityId", required = false) String cityId)
    {
        List<SysProvince> list = sysProvinceService.selectProvinceListRelationChild(provinceId, cityId);
        return AjaxResult.success(list);
    }

    /**
     * 导出省份信息列表
     */
    @RequiresPermissions("system:province:export")
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysProvince sysProvince)
    {
        List<SysProvince> list = sysProvinceService.selectSysProvinceList(sysProvince);
        ExcelUtil<SysProvince> util = new ExcelUtil<SysProvince>(SysProvince.class);
        util.exportExcel(response, list, "省份信息数据");
    }

    /**
     * 获取省份信息详细信息
     */
    @RequiresPermissions("system:province:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success((sysProvinceService.selectSysProvinceById(id)));
    }


    @GetMapping("/getProvince")
    public AjaxResult getProvince(){
        return success(sysProvinceService.getProvince());
    }

}
