package com.ruoyi.web.controller.buyerapi;

import java.util.List;

import cn.hutool.core.util.IdUtil;

import javax.servlet.http.HttpServletResponse;

import com.ruoyi.buyerapi.domain.BuyerFileInfo;
import com.ruoyi.buyerapi.mapper.BuyerFileInfoMapper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
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.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.buyerapi.domain.BuyerProcessFile;
import com.ruoyi.buyerapi.service.IBuyerProcessFileService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 项目管理过程文件Controller
 *
 * @author ruoyi
 * @date 2022-09-22
 */
@Api(tags = "项目管理过程文件")
@RestController
@RequestMapping("/buyer/processfile")
public class BuyerProcessFileController extends BaseController {
    @Autowired
    private IBuyerProcessFileService buyerProcessFileService;

    @Autowired
    private BuyerFileInfoMapper buyerFileInfoMapper;

    /**
     * 查询项目管理过程文件列表
     */
    @ApiOperation(value = "查询项目管理过程文件列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "projectName", value = "项目名称", required = true, paramType = "query"),
            @ApiImplicitParam(name = "fileName", value = "文件名称", required = true, paramType = "query"),
            @ApiImplicitParam(name = "fileType", value = "文件类型", required = true, paramType = "query"),
            @ApiImplicitParam(name = "remarks", value = "备注", required = true, paramType = "query")
    })
    @PreAuthorize("@ss.hasPermi('buyer:processfile:list')")
    @GetMapping("/list")
    public TableDataInfo list(BuyerProcessFile buyerProcessFile) {
        startPage();
        List<BuyerProcessFile> list = buyerProcessFileService.selectBuyerProcessFileList(buyerProcessFile);
        return getDataTable(list);
    }

    /**
     * 查询过程文件列表
     */
    @ApiOperation(value = "查询过程文件列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "linkId", value = "关联Id", required = true, paramType = "query"),
    })
    @PreAuthorize("@ss.hasPermi('buyer:processfile:list')")
    @GetMapping("/lists")
    public AjaxResult lists(String linkId) {
        List<BuyerFileInfo> buyerFileInfos = buyerFileInfoMapper.selectBuyerFileInfoByLinkId(linkId);
        return AjaxResult.success(buyerFileInfos);
    }

    /**
     * 导出项目管理过程文件列表
     */
    @ApiOperation(value = "导出项目管理过程文件列表")
    @PreAuthorize("@ss.hasPermi('buyer:processfile:export')")
    @Log(title = "项目管理过程文件", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BuyerProcessFile buyerProcessFile) {
        List<BuyerProcessFile> list = buyerProcessFileService.selectBuyerProcessFileList(buyerProcessFile);
        ExcelUtil<BuyerProcessFile> util = new ExcelUtil<BuyerProcessFile>(BuyerProcessFile.class);
        util.exportExcel(response, list, "项目管理过程文件数据");
    }

    /**
     * 获取项目管理过程文件详细信息
     */
    @ApiOperation(value = "获取项目管理过程文件详细信息")
    @PreAuthorize("@ss.hasPermi('buyer:processfile:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return AjaxResult.success(buyerProcessFileService.selectBuyerProcessFileById(id));
    }

    /**
     * 新增项目管理过程文件
     */
    @ApiOperation(value = "新增项目管理过程文件")
    @PreAuthorize("@ss.hasPermi('buyer:processfile:add')")
    @Log(title = "项目管理过程文件", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BuyerProcessFile buyerProcessFile) {
        buyerProcessFile.setId(IdUtil.simpleUUID());
        buyerProcessFile.setCreateBy(getUsername());
        return toAjax(buyerProcessFileService.insertBuyerProcessFile(buyerProcessFile));
    }

    /**
     * 修改项目管理过程文件
     */
    @ApiOperation(value = "修改项目管理过程文件")
    @PreAuthorize("@ss.hasPermi('buyer:processfile:edit')")
    @Log(title = "项目管理过程文件", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BuyerProcessFile buyerProcessFile) {
        buyerProcessFile.setUpdateBy(getUsername());
        return toAjax(buyerProcessFileService.updateBuyerProcessFile(buyerProcessFile));
    }

    /**
     * 删除项目管理过程文件
     */
    @ApiOperation(value = "删除项目管理过程文件")
    @PreAuthorize("@ss.hasPermi('buyer:processfile:remove')")
    @Log(title = "项目管理过程文件", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(buyerProcessFileService.deleteBuyerProcessFileByIds(ids));
    }
}
