package com.phm.manage.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
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.phm.common.annotation.Log;
import com.phm.common.core.controller.BaseController;
import com.phm.common.core.domain.AjaxResult;
import com.phm.common.enums.BusinessType;
import com.phm.manage.domain.DataDownResult;
import com.phm.manage.service.IDataDownResultService;
import com.phm.common.utils.poi.ExcelUtil;
import com.phm.common.core.page.TableDataInfo;

/**
 * 数据下载Controller
 * 
 * @author phm
 * @date 2023-08-24
 */
@RestController
@RequestMapping("/manage/dataDown")
public class DataDownResultController extends BaseController
{
    @Autowired
    private IDataDownResultService dataDownResultService;

    /**
     * 查询数据下载列表
     */
    @PreAuthorize("@ss.hasPermi('manage:dataDown:list')")
    @GetMapping("/list")
    public TableDataInfo list(DataDownResult dataDownResult)
    {
        startPage();
        List<DataDownResult> list = dataDownResultService.selectDataDownResultList(dataDownResult);
        return getDataTable(list);
    }

    /**
     * 导出数据下载列表
     */
    @PreAuthorize("@ss.hasPermi('manage:dataDown:export')")
    @Log(title = "数据下载", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DataDownResult dataDownResult)
    {
        List<DataDownResult> list = dataDownResultService.selectDataDownResultList(dataDownResult);
        ExcelUtil<DataDownResult> util = new ExcelUtil<DataDownResult>(DataDownResult.class);
        util.exportExcel(response, list, "数据下载数据");
    }

    /**
     * 获取数据下载详细信息
     */
    @PreAuthorize("@ss.hasPermi('manage:dataDown:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(dataDownResultService.selectDataDownResultById(id));
    }

    /**
     * 新增数据下载
     */
    @PreAuthorize("@ss.hasPermi('manage:dataDown:add')")
    @Log(title = "数据下载", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DataDownResult dataDownResult)
    {
        return toAjax(dataDownResultService.insertDataDownResult(dataDownResult));
    }

    /**
     * 修改数据下载
     */
    @PreAuthorize("@ss.hasPermi('manage:dataDown:edit')")
    @Log(title = "数据下载", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DataDownResult dataDownResult)
    {
        return toAjax(dataDownResultService.updateDataDownResult(dataDownResult));
    }

    /**
     * 删除数据下载
     */
    @PreAuthorize("@ss.hasPermi('manage:dataDown:remove')")
    @Log(title = "数据下载", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(dataDownResultService.deleteDataDownResultByIds(ids));
    }
}
