package com.ruoyi.business.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import lombok.extern.slf4j.Slf4j;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
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.ruoyi.common.security.utils.SecurityUtils;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.business.domain.FileExchangeResolve;
import com.ruoyi.business.service.IFileExchangeResolveService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 文件打包解析Controller
 * 
 * @author gx
 * @date 2024-01-31
 */
@Slf4j
@Validated
@RestController
@RequestMapping("/filePackageResolve")
@RequiredArgsConstructor
public class FileExchangeResolveController extends BaseController {

    private final IFileExchangeResolveService fileExchangeResolveService;

    /**
     * 查询文件打包解析列表
     */
    @RequiresPermissions("business_packageResolve_list")
    @GetMapping
    public AjaxResult list(FileExchangeResolve fileExchangeResolve) {
        List<FileExchangeResolve> list = fileExchangeResolveService.selectFileExchangeResolveList(fileExchangeResolve);
        return success(list);
    }

    /**
     * 查询文件打包解析列表(分页)
     */
    @RequiresPermissions("business_packageResolve_list")
    @GetMapping("/list")
    public TableDataInfo pageList(FileExchangeResolve fileExchangeResolve) {
        startPage();
        List<FileExchangeResolve> list = fileExchangeResolveService.selectFileExchangeResolveList(fileExchangeResolve);
        return getDataTable(list);
    }

    /**
     * 获取文件打包解析详细信息
     */
    @RequiresPermissions("business_packageResolve_query")
    @GetMapping(value = "/{id}")
    public AjaxResult getFileExchangeResolveById(@PathVariable("id") Long id) {
        return success(fileExchangeResolveService.selectFileExchangeResolveById(id));
    }

    /**
     * 新增文件打包解析
     */
    @RequiresPermissions("business_packageResolve_add")
    @Log(title = "文件打包解析", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult addFileExchangeResolve(@RequestBody FileExchangeResolve fileExchangeResolve) {
        fileExchangeResolve.setDeptIdPath(SecurityUtils.getDeptIdPath());
        fileExchangeResolve.setDeptName(SecurityUtils.getDeptName());
        fileExchangeResolve.setCreateUserId(SecurityUtils.getUserId());
        fileExchangeResolve.setCreateBy(SecurityUtils.getUsername());
        return toAjax(fileExchangeResolveService.insertFileExchangeResolve(fileExchangeResolve));
    }

    /**
     * 修改文件打包解析
     */
    @RequiresPermissions("business_packageResolve_edit")
    @Log(title = "文件打包解析", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult updateFileExchangeResolve(@RequestBody FileExchangeResolve fileExchangeResolve) {
        fileExchangeResolve.setUpdateBy(SecurityUtils.getUsername());
        return toAjax(fileExchangeResolveService.updateFileExchangeResolve(fileExchangeResolve));
    }

    /**
     * 批量删除文件打包解析
     */
    @RequiresPermissions("business_packageResolve_delete")
    @Log(title = "文件打包解析", businessType = BusinessType.DELETE)
    @DeleteMapping("deleteByIds/{ids}")
    public AjaxResult delete(@PathVariable Long[] ids) {
        return toAjax(fileExchangeResolveService.deleteFileExchangeResolveByIds(ids));
    }

    /**
     * 删除文件打包解析
     */
    @RequiresPermissions("business_packageResolve_delete")
    @Log(title = "文件打包解析", businessType = BusinessType.DELETE)
    @DeleteMapping("deleteById/{id}")
    public AjaxResult delete(@PathVariable Long id) {
        return toAjax(fileExchangeResolveService.deleteFileExchangeResolveById(id));
    }

    /**
     * 导出文件打包解析列表
     */
    @RequiresPermissions("business_packageResolve_export")
    @Log(title = "文件打包解析", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, FileExchangeResolve fileExchangeResolve) {
        List<FileExchangeResolve> list = fileExchangeResolveService.selectFileExchangeResolveList(fileExchangeResolve);
        ExcelUtil<FileExchangeResolve> util = new ExcelUtil<FileExchangeResolve>(FileExchangeResolve.class);
        util.exportExcel(response, list, "文件打包解析数据");
    }
}
