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.FileExchangeResolveLog;
import com.ruoyi.business.service.IFileExchangeResolveLogService;
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 ruoyi
 * @date 2024-01-31
 */
@Slf4j
@Validated
@RestController
@RequestMapping("/filePackageResolveLog")
@RequiredArgsConstructor
public class FileExchangeResolveLogController extends BaseController {

    private final IFileExchangeResolveLogService fileExchangeResolveLogService;

    /**
     * 查询文件打包解析日志列表
     */
    @RequiresPermissions("business_log_list")
    @GetMapping
    public AjaxResult list(FileExchangeResolveLog fileExchangeResolveLog) {
        List<FileExchangeResolveLog> list = fileExchangeResolveLogService.selectFileExchangeResolveLogList(fileExchangeResolveLog);
        return success(list);
    }

    /**
     * 查询文件打包解析日志列表(分页)
     */
    @RequiresPermissions("business_log_list")
    @GetMapping("/list")
    public TableDataInfo pageList(FileExchangeResolveLog fileExchangeResolveLog) {
        startPage();
        List<FileExchangeResolveLog> list = fileExchangeResolveLogService.selectFileExchangeResolveLogList(fileExchangeResolveLog);
        return getDataTable(list);
    }

    /**
     * 获取文件打包解析日志详细信息
     */
    @RequiresPermissions("business_log_query")
    @GetMapping(value = "/{id}")
    public AjaxResult getFileExchangeResolveLogById(@PathVariable("id") Long id) {
        return success(fileExchangeResolveLogService.selectFileExchangeResolveLogById(id));
    }

    /**
     * 新增文件打包解析日志
     */
    @RequiresPermissions("business_log_add")
    @Log(title = "文件打包解析日志", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult addFileExchangeResolveLog(@RequestBody FileExchangeResolveLog fileExchangeResolveLog) {
        fileExchangeResolveLog.setDeptIdPath(SecurityUtils.getDeptIdPath());
        fileExchangeResolveLog.setDeptName(SecurityUtils.getDeptName());
        fileExchangeResolveLog.setCreateUserId(SecurityUtils.getUserId());
        fileExchangeResolveLog.setCreateBy(SecurityUtils.getUsername());
        return toAjax(fileExchangeResolveLogService.insertFileExchangeResolveLog(fileExchangeResolveLog));
    }

    /**
     * 修改文件打包解析日志
     */
    @RequiresPermissions("business_log_edit")
    @Log(title = "文件打包解析日志", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult updateFileExchangeResolveLog(@RequestBody FileExchangeResolveLog fileExchangeResolveLog) {
        fileExchangeResolveLog.setUpdateBy(SecurityUtils.getUsername());
        return toAjax(fileExchangeResolveLogService.updateFileExchangeResolveLog(fileExchangeResolveLog));
    }

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

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

    /**
     * 导出文件打包解析日志列表
     */
    @RequiresPermissions("business_log_export")
    @Log(title = "文件打包解析日志", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, FileExchangeResolveLog fileExchangeResolveLog) {
        List<FileExchangeResolveLog> list = fileExchangeResolveLogService.selectFileExchangeResolveLogList(fileExchangeResolveLog);
        ExcelUtil<FileExchangeResolveLog> util = new ExcelUtil<FileExchangeResolveLog>(FileExchangeResolveLog.class);
        util.exportExcel(response, list, "文件打包解析日志数据");
    }
}
