package com.ruoyi.web.modules.industrypolicy.controller;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
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.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.web.modules.industrypolicy.domain.BizSubsidyMatter;
import com.ruoyi.web.modules.industrypolicy.service.IBizSubsidyMatterService;

/**
 * 项目与补贴-补贴管理
 */
@RestController
@RequestMapping("/industryPolicy/subsidyMatter")
public class BizSubsidyMatterController extends BaseController
{
    @Autowired
    private IBizSubsidyMatterService bizSubsidyMatterService;

    @PreAuthorize("@ss.hasPermi('industryPolicy:subsidyMatter:list')")
    @GetMapping("/list")
    public TableDataInfo list(BizSubsidyMatter query)
    {
        startPage();
        List<BizSubsidyMatter> list = bizSubsidyMatterService.selectBizSubsidyMatterList(query);
        return getDataTable(list);
    }

    @PreAuthorize("@ss.hasPermi('industryPolicy:subsidyMatter:query')")
    @GetMapping("/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(bizSubsidyMatterService.selectBizSubsidyMatterById(id));
    }

    @PreAuthorize("@ss.hasPermi('industryPolicy:subsidyMatter:add')")
    @Log(title = "项目与补贴-补贴", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Validated @RequestBody BizSubsidyMatter row)
    {
        row.setCreateBy(getUsername());
        return toAjax(bizSubsidyMatterService.insertBizSubsidyMatter(row));
    }

    @PreAuthorize("@ss.hasPermi('industryPolicy:subsidyMatter:edit')")
    @Log(title = "项目与补贴-补贴", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@Validated @RequestBody BizSubsidyMatter row)
    {
        row.setUpdateBy(getUsername());
        return toAjax(bizSubsidyMatterService.updateBizSubsidyMatter(row));
    }

    @PreAuthorize("@ss.hasPermi('industryPolicy:subsidyMatter:remove')")
    @Log(title = "项目与补贴-补贴", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(bizSubsidyMatterService.deleteBizSubsidyMatterByIds(ids));
    }

    @PreAuthorize("@ss.hasPermi('industryPolicy:subsidyMatter:publish')")
    @Log(title = "项目与补贴-补贴发布", businessType = BusinessType.UPDATE)
    @PostMapping("/publish/{id}")
    public AjaxResult publish(@PathVariable Long id)
    {
        return toAjax(bizSubsidyMatterService.publish(id));
    }

    @PreAuthorize("@ss.hasPermi('industryPolicy:subsidyMatter:offline')")
    @Log(title = "项目与补贴-补贴下架", businessType = BusinessType.UPDATE)
    @PostMapping("/offline/{id}")
    public AjaxResult offline(@PathVariable Long id)
    {
        return toAjax(bizSubsidyMatterService.offline(id));
    }
}
