package com.ruoyi.web.controller.dz;

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

import com.alibaba.fastjson2.JSONObject;
import com.ruoyi.common.annotation.Anonymous;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
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.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.dz.domain.DzControl;
import com.ruoyi.dz.service.IDzControlService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 单招省份状态Controller
 * 
 * @author ruoyi
 * @date 2025-09-12
 */
@RestController
@RequestMapping("/dz/control")
@Api(tags = "后台-基础-控制")
public class DzControlController extends BaseController
{
    @Autowired
    private IDzControlService dzControlService;

    /**
     * 查询单招省份状态列表
     */
    @PreAuthorize("@ss.hasPermi('dz:control:list')")
    @GetMapping("/list")
    public TableDataInfo list(DzControl dzControl)
    {
        startPage();
        List<DzControl> list = dzControlService.selectDzControlList(dzControl);
        return getDataTable(list);
    }

    /**
     * 导出单招省份状态列表
     */
    @PreAuthorize("@ss.hasPermi('dz:control:export')")
    @Log(title = "单招省份状态", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DzControl dzControl)
    {
        List<DzControl> list = dzControlService.selectDzControlList(dzControl);
        ExcelUtil<DzControl> util = new ExcelUtil<DzControl>(DzControl.class);
        util.exportExcel(response, list, "单招省份状态数据");
    }

    /**
     * 获取单招省份状态详细信息
     */
    @PreAuthorize("@ss.hasPermi('dz:control:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(dzControlService.selectDzControlById(id));
    }

    /**
     * 新增单招省份状态
     */
    @PreAuthorize("@ss.hasPermi('dz:control:add')")
    @Log(title = "单招省份状态", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DzControl dzControl)
    {
        return toAjax(dzControlService.insertDzControl(dzControl));
    }

    /**
     * 修改单招省份状态
     */
    @PreAuthorize("@ss.hasPermi('dz:control:edit')")
    @Log(title = "单招省份状态", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DzControl dzControl)
    {
        return toAjax(dzControlService.updateDzControl(dzControl));
    }

    /**
     * 删除单招省份状态
     */
    @PreAuthorize("@ss.hasPermi('dz:control:remove')")
    @Log(title = "单招省份状态", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(dzControlService.deleteDzControlByIds(ids));
    }

    @GetMapping(value = "provinces")
    @Anonymous
    @ApiOperation("1. 省份列表")
    public AjaxResult provinces()
    {
        DzControl cond = new DzControl();
        cond.setIsValid(1);
        return AjaxResult.success(dzControlService.selectDzControlList(cond).stream().map(t -> {
            JSONObject o = new JSONObject();
            o.put("dictValue", t.getLocation());
            o.put("dictLabel", t.getLocation());
            return o;
        }).collect(Collectors.toList()));
    }
}
