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.BuyerIntangibleAssets;
import com.ruoyi.buyerapi.service.IBuyerIntangibleAssetsService;
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/intangibleassets")
public class BuyerIntangibleAssetsController extends BaseController
{
    @Autowired
    private IBuyerIntangibleAssetsService buyerIntangibleAssetsService;

    /**
     * 查询无形资产摊销记录列表
     */
    @ApiOperation(value = "查询无形资产摊销记录列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "collectDate", value = "领用日期", required = true, paramType = "query"),
            @ApiImplicitParam(name = "projectName", value = "项目名称", required = true, paramType = "query"),
            @ApiImplicitParam(name = "info", value = "摘要", required = true, paramType = "query"),
            @ApiImplicitParam(name = "type", value = "种类", required = true, paramType = "query"),
            @ApiImplicitParam(name = "createBy", value = "操作人", required = true, paramType = "query")
    })
    @PreAuthorize("@ss.hasPermi('buyer:intangibleassets:list')")
    @GetMapping("/list")
    public TableDataInfo list(BuyerIntangibleAssets buyerIntangibleAssets)
    {
        startPage();
        List<BuyerIntangibleAssets> list = buyerIntangibleAssetsService.selectBuyerIntangibleAssetsList(buyerIntangibleAssets);
        return getDataTable(list);
    }

    /**
     * 统计无形资产摊销记录列表
     */
    @ApiOperation(value = "统计无形资产摊销记录列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "projectName", value = "项目名称", required = true, paramType = "query")
    })
    @GetMapping("/statist")
    public TableDataInfo statist(BuyerIntangibleAssets buyerIntangibleAssets)
    {
        startPage();
        List<BuyerIntangibleAssets> list = buyerIntangibleAssetsService.selectStatistBuyerIntangibleAssetsList(buyerIntangibleAssets);
        return getDataTable(list);
    }

    /**
     * 导出无形资产摊销记录列表
     */
    @ApiOperation(value = "导出无形资产摊销记录列表")
    @PreAuthorize("@ss.hasPermi('buyer:intangibleassets:export')")
    @Log(title = "无形资产摊销记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BuyerIntangibleAssets buyerIntangibleAssets)
    {
        List<BuyerIntangibleAssets> list = buyerIntangibleAssetsService.selectBuyerIntangibleAssetsList(buyerIntangibleAssets);
        ExcelUtil<BuyerIntangibleAssets> util = new ExcelUtil<BuyerIntangibleAssets>(BuyerIntangibleAssets.class);
        util.exportExcel(response, list, "无形资产摊销记录数据");
    }

    /**
     * 获取无形资产摊销记录详细信息
     */
    @ApiOperation(value = "获取无形资产摊销记录详细信息")
    @PreAuthorize("@ss.hasPermi('buyer:intangibleassets:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return AjaxResult.success(buyerIntangibleAssetsService.selectBuyerIntangibleAssetsById(id));
    }

    /**
     * 新增无形资产摊销记录
     */
    @ApiOperation(value = "新增无形资产摊销记录")
    @PreAuthorize("@ss.hasPermi('buyer:intangibleassets:add')")
    @Log(title = "无形资产摊销记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BuyerIntangibleAssets buyerIntangibleAssets)
    {
        buyerIntangibleAssets.setId(IdUtil.simpleUUID());
        buyerIntangibleAssets.setCreateBy(getUsername());
        return toAjax(buyerIntangibleAssetsService.insertBuyerIntangibleAssets(buyerIntangibleAssets));
    }

    /**
     * 修改无形资产摊销记录
     */
    @ApiOperation(value = "修改无形资产摊销记录")
    @PreAuthorize("@ss.hasPermi('buyer:intangibleassets:edit')")
    @Log(title = "无形资产摊销记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BuyerIntangibleAssets buyerIntangibleAssets)
    {
        buyerIntangibleAssets.setUpdateBy(getUsername());
        return toAjax(buyerIntangibleAssetsService.updateBuyerIntangibleAssets(buyerIntangibleAssets));
    }

    /**
     * 删除无形资产摊销记录
     */
    @ApiOperation(value = "删除无形资产摊销记录")
    @PreAuthorize("@ss.hasPermi('buyer:intangibleassets:remove')")
    @Log(title = "无形资产摊销记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(buyerIntangibleAssetsService.deleteBuyerIntangibleAssetsByIds(ids));
    }
}
