package com.cn.fdapfe.biz.controller;

import java.util.List;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
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.cn.fdapfe.common.annotation.Log;
import com.cn.fdapfe.common.core.controller.BaseController;
import com.cn.fdapfe.common.core.domain.AjaxResult;
import com.cn.fdapfe.common.enums.BusinessType;
import com.cn.fdapfe.biz.domain.Data;
import com.cn.fdapfe.biz.service.IDataService;
import com.cn.fdapfe.common.utils.poi.ExcelUtil;
import com.cn.fdapfe.common.core.page.TableDataInfo;

/**
 * 数据管理Controller
 * 
 * @author Allem
 * @date 2025-03-07
 */
@RestController
@RequestMapping("/data/data")
public class DataController extends BaseController
{
    @Resource
    private IDataService dataService;

    /**
     * 查询数据管理列表
     */
    @PreAuthorize("@ss.hasPermi('data:data:list')")
    @GetMapping("/list")
    public TableDataInfo list(Data data)
    {
        startPage();
        List<Data> list = dataService.selectDataList(data);
        return getDataTable(list);
    }

    /**
     * 导出数据管理列表
     */
    @PreAuthorize("@ss.hasPermi('data:data:export')")
    @Log(title = "数据管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Data data)
    {
        List<Data> list = dataService.selectDataList(data);
        ExcelUtil<Data> util = new ExcelUtil<Data>(Data.class);
        util.exportExcel(response, list, "数据管理数据");
    }

    /**
     * 获取数据管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('data:data:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(dataService.selectDataById(id));
    }

    /**
     * 新增数据管理
     */
    @PreAuthorize("@ss.hasPermi('data:data:add')")
    @Log(title = "数据管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Data data)
    {
        return toAjax(dataService.insertData(data));
    }

    /**
     * 修改数据管理
     */
    @PreAuthorize("@ss.hasPermi('data:data:edit')")
    @Log(title = "数据管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Data data)
    {
        return toAjax(dataService.updateData(data));
    }

    /**
     * 删除数据管理
     */
    @PreAuthorize("@ss.hasPermi('data:data:remove')")
    @Log(title = "数据管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(dataService.deleteDataByIds(ids));
    }


    /**
     * 查询数据管理Options
     */
    @PreAuthorize("@ss.hasPermi('data:data:list')")
    @GetMapping("/getOptions")
    public AjaxResult getOptions()
    {
        return success(dataService.getOptions());
    }
}
