package com.zksy.web.controller.basicData.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 annotation.com.zksy.common.Log;
import controller.core.com.zksy.common.BaseController;
import domain.core.com.zksy.common.AjaxResult;
import enums.com.zksy.common.BusinessType;
import com.zksy.web.controller.basicData.domain.CrmFile;
import com.zksy.web.controller.basicData.service.ICrmFileService;
import poi.utils.com.zksy.common.ExcelUtil;
import page.core.com.zksy.common.TableDataInfo;

/**
 * 文件管理Controller
 * 
 * @author sy
 * @date 2024-05-10
 */
@RestController
@RequestMapping("/basicData/file")
public class CrmFileController extends BaseController
{
    @Autowired
    private ICrmFileService crmFileService;

    /**
     * 查询文件管理列表
     */
    @PreAuthorize("@ss.hasPermi('basicData:file:list')")
    @GetMapping("/list")
    public TableDataInfo list(CrmFile crmFile)
    {
        startPage();
        List<CrmFile> list = crmFileService.selectCrmFileList(crmFile);
        return getDataTable(list);
    }

    /**
     * 导出文件管理列表
     */
    @PreAuthorize("@ss.hasPermi('basicData:file:export')")
    @Log(title = "文件管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CrmFile crmFile)
    {
        List<CrmFile> list = crmFileService.selectCrmFileList(crmFile);
        ExcelUtil<CrmFile> util = new ExcelUtil<CrmFile>(CrmFile.class);
        util.exportExcel(response, list, "文件管理数据");
    }

    /**
     * 获取文件管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('basicData:file:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(crmFileService.selectCrmFileById(id));
    }

    /**
     * 新增文件管理
     */
    @PreAuthorize("@ss.hasPermi('basicData:file:add')")
    @Log(title = "文件管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CrmFile crmFile)
    {
        return toAjax(crmFileService.insertCrmFile(crmFile));
    }

    /**
     * 修改文件管理
     */
    @PreAuthorize("@ss.hasPermi('basicData:file:edit')")
    @Log(title = "文件管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CrmFile crmFile)
    {
        return toAjax(crmFileService.updateCrmFile(crmFile));
    }

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