package com.ruoyi.web.controller.buyerapi;

import java.util.List;

import cn.hutool.core.util.IdUtil;

import javax.servlet.http.HttpServletResponse;

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.BuyerDeptFinancialData;
import com.ruoyi.buyerapi.service.IBuyerDeptFinancialDataService;
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/companydata")
public class BuyerDeptFinancialDataController extends BaseController {
    @Autowired
    private IBuyerDeptFinancialDataService buyerDeptFinancialDataService;

    /**
     * 查询该年度是否已有数据
     */
    @ApiOperation(value = "查询该年度是否已有数据")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "year", value = "年份", required = true, paramType = "query"),
    })
    @GetMapping("/check")
    public AjaxResult check(BuyerDeptFinancialData buyerDeptFinancialData) {
        AjaxResult ajaxResult = new AjaxResult();
        List<BuyerDeptFinancialData> list = buyerDeptFinancialDataService.selectBuyerDeptFinancialDataList(buyerDeptFinancialData);
        if (list.size() > 0) {
            ajaxResult.put("code", 200);
            ajaxResult.put("repeat", true);
            ajaxResult.put("msg", "该年度已有数据，是否覆盖");
            return ajaxResult;
        } else {
            ajaxResult.put("code", 200);
            ajaxResult.put("repeat", false);
            return ajaxResult;
        }
    }

    /**
     * 查询企业信息管理财务数据列表
     */
    @ApiOperation(value = "查询企业信息管理财务数据列表")
    @PreAuthorize("@ss.hasPermi('buyer:companydata:list')")
    @GetMapping("/list")
    public TableDataInfo list(BuyerDeptFinancialData buyerDeptFinancialData) {
        startPage();
        List<BuyerDeptFinancialData> list = buyerDeptFinancialDataService.selectBuyerDeptFinancialDataList(buyerDeptFinancialData);
        return getDataTable(list);
    }

    /**
     * 导出企业信息管理财务数据列表
     */
    @ApiOperation(value = "导出企业信息管理财务数据列表")
    @PreAuthorize("@ss.hasPermi('buyer:companydata:export')")
    @Log(title = "企业信息管理财务数据", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BuyerDeptFinancialData buyerDeptFinancialData) {
        List<BuyerDeptFinancialData> list = buyerDeptFinancialDataService.selectBuyerDeptFinancialDataList(buyerDeptFinancialData);
        ExcelUtil<BuyerDeptFinancialData> util = new ExcelUtil<BuyerDeptFinancialData>(BuyerDeptFinancialData.class);
        util.exportExcel(response, list, "企业信息管理财务数据数据");
    }

    /**
     * 获取企业信息管理财务数据详细信息
     */
    @ApiOperation(value = "获取企业信息管理财务数据详细信息")
    @PreAuthorize("@ss.hasPermi('buyer:companydata:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return AjaxResult.success(buyerDeptFinancialDataService.selectBuyerDeptFinancialDataById(id));
    }

    /**
     * 新增企业信息管理财务数据
     */
    @ApiOperation(value = "新增企业信息管理财务数据")
    @PreAuthorize("@ss.hasPermi('buyer:companydata:add')")
    @Log(title = "企业信息管理财务数据", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BuyerDeptFinancialData buyerDeptFinancialData) {
        buyerDeptFinancialData.setId(IdUtil.simpleUUID());
        buyerDeptFinancialData.setCreateBy(getUsername());
        return toAjax(buyerDeptFinancialDataService.insertBuyerDeptFinancialData(buyerDeptFinancialData));
    }

    /**
     * 修改企业信息管理财务数据
     */
    @ApiOperation(value = "修改企业信息管理财务数据")
    @PreAuthorize("@ss.hasPermi('buyer:companydata:edit')")
    @Log(title = "企业信息管理财务数据", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BuyerDeptFinancialData buyerDeptFinancialData) {
        buyerDeptFinancialData.setUpdateBy(getUsername());
        return toAjax(buyerDeptFinancialDataService.updateBuyerDeptFinancialData(buyerDeptFinancialData));
    }

    /**
     * 删除企业信息管理财务数据
     */
    @ApiOperation(value = "删除企业信息管理财务数据")
    @PreAuthorize("@ss.hasPermi('buyer:companydata:remove')")
    @Log(title = "企业信息管理财务数据", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(buyerDeptFinancialDataService.deleteBuyerDeptFinancialDataByIds(ids));
    }
}
