package com.admin.web.controller.major;

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.admin.common.annotation.Log;
import com.admin.common.core.controller.BaseController;
import com.admin.common.core.domain.AjaxResult;
import com.admin.common.enums.BusinessType;
import com.admin.major.domain.DataFile;
import com.admin.major.service.IDataFileService;
import com.admin.common.utils.poi.ExcelUtil;
import com.admin.common.core.page.TableDataInfo;

/**
 * 数据归档Controller
 * 
 * @author ljx
 * @date 2022-06-24
 */
@RestController
@RequestMapping("/major/dataFile")
public class DataFileController extends BaseController
{
    @Autowired
    private IDataFileService dataFileService;

    /**
     * 查询数据归档列表
     */
    @PreAuthorize("@ss.hasPermi('major:dataFile:list')")
    @GetMapping("/list")
    public TableDataInfo list(DataFile dataFile)
    {
        startPage();
        List<DataFile> list = dataFileService.selectDataFileList(dataFile);
        return getDataTable(list);
    }

    /**
     * 导出数据归档列表
     */
    @PreAuthorize("@ss.hasPermi('major:dataFile:export')")
    @Log(title = "数据归档", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DataFile dataFile)
    {
        List<DataFile> list = dataFileService.selectDataFileList(dataFile);
        ExcelUtil<DataFile> util = new ExcelUtil<DataFile>(DataFile.class);
        util.exportExcel(response, list, "数据归档数据");
    }

    /**
     * 获取数据归档详细信息
     */
    @PreAuthorize("@ss.hasPermi('major:dataFile:query')")
    @GetMapping(value = "/{dataFileId}")
    public AjaxResult getInfo(@PathVariable("dataFileId") Long dataFileId)
    {
        return AjaxResult.success(dataFileService.selectDataFileByDataFileId(dataFileId));
    }

    /**
     * 新增数据归档
     */
    @PreAuthorize("@ss.hasPermi('major:dataFile:add')")
    @Log(title = "数据归档", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DataFile dataFile)
    {
        return toAjax(dataFileService.insertDataFile(dataFile));
    }

    /**
     * 修改数据归档
     */
    @PreAuthorize("@ss.hasPermi('major:dataFile:edit')")
    @Log(title = "数据归档", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DataFile dataFile)
    {
        return toAjax(dataFileService.updateDataFile(dataFile));
    }

    /**
     * 删除数据归档
     */
    @PreAuthorize("@ss.hasPermi('major:dataFile:remove')")
    @Log(title = "数据归档", businessType = BusinessType.DELETE)
	@DeleteMapping("/{dataFileIds}")
    public AjaxResult remove(@PathVariable Long[] dataFileIds)
    {
        return toAjax(dataFileService.deleteDataFileByDataFileIds(dataFileIds));
    }
}
