package com.goomood.phm.controller;

import com.goomood.common.annotation.Log;
import com.goomood.common.core.controller.BaseController;
import com.goomood.common.core.domain.AjaxResult;
import com.goomood.common.core.page.TableDataInfo;
import com.goomood.common.enums.BusinessType;
import com.goomood.common.utils.poi.ExcelUtil;
import com.goomood.phm.domain.AlsAtlasFileT;
import com.goomood.phm.service.IAlsAtlasFileTService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

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

/**
 * 文件管理Controller
 */
@RestController
@RequestMapping("/als/file")
public class AlsAtlasFileTController extends BaseController {
    @Resource
    private IAlsAtlasFileTService alsAtlasFileTService;

    /**
     * 查询文件管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:file:list')")
    @GetMapping("/list")
    public TableDataInfo list(AlsAtlasFileT alsAtlasFileT) {
        startPage();
        List<AlsAtlasFileT> list = alsAtlasFileTService.selectAlsAtlasFileTList(alsAtlasFileT);
        return getDataTable(list);
    }

    /**
     * 导出文件管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:file:export')")
    @Log(title = "文件管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(AlsAtlasFileT alsAtlasFileT) {
        List<AlsAtlasFileT> list = alsAtlasFileTService.selectAlsAtlasFileTList(alsAtlasFileT);
        ExcelUtil<AlsAtlasFileT> util = new ExcelUtil<>(AlsAtlasFileT.class);
        return util.exportExcel(list, "文件管理数据");
    }

    /**
     * 获取文件管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:file:query')")
    @PostMapping(value = "/selectOne")
    public AjaxResult getInfo(@RequestBody AlsAtlasFileT alsAtlasFileT) {
        return success(alsAtlasFileTService.getById(alsAtlasFileT.getId()));
    }

    /**
     * 新增文件管理
     */
    @PreAuthorize("@ss.hasPermi('system:file:add')")
    @Log(title = "文件管理", businessType = BusinessType.INSERT)
    @PostMapping("add")
    public AjaxResult add(@RequestBody AlsAtlasFileT alsAtlasFileT) {
        return toAjax(alsAtlasFileTService.insertAlsAtlasFileT(alsAtlasFileT));
    }

    /**
     * 修改文件管理
     */
    @PreAuthorize("@ss.hasPermi('system:file:edit')")
    @Log(title = "文件管理", businessType = BusinessType.UPDATE)
    @PutMapping("updata")
    public AjaxResult edit(@RequestBody AlsAtlasFileT alsAtlasFileT) {
        return toAjax(alsAtlasFileTService.updateAlsAtlasFileT(alsAtlasFileT));
    }

    /**
     * 删除文件管理
     */
    @PreAuthorize("@ss.hasPermi('system:file:remove')")
    @Log(title = "文件管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(alsAtlasFileTService.deleteAlsAtlasFileTByIds(ids));
    }

//    /**
//     * 导入文件
//     */
//    @PreAuthorize("@ss.hasPermi('system:file:import')")
//    @Log(title = "文件管理", businessType = BusinessType.IMPORT)
//    @PostMapping("/importData")
//    @ResponseBody
//    public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception {
//        ExcelUtil<AlsAtlasFileT> util = new ExcelUtil<>(AlsAtlasFileT.class);
//        List<AlsAtlasFileT> fileList = util.importExcel(file.getInputStream());
//        String operName = getUsername();
//        String message = alsAtlasFileTService.importFile(fileList, updateSupport, operName);
//        return AjaxResult.success(message);
//    }

    /**
     * 下载导入模板
     */
    @GetMapping("/importTemplate")
    public void importTemplate(HttpServletResponse response) {
        ExcelUtil<AlsAtlasFileT> util = new ExcelUtil<>(AlsAtlasFileT.class);
        util.importTemplateExcel(response, "文件管理数据");
    }
}