package com.ruoyi.web.modules.prosperity.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.prosperity.domain.BizCommonProsperityProject;
import com.ruoyi.web.modules.prosperity.service.IBizCommonProsperityProjectService;

/**
 * 共同富裕项目管理
 */
@RestController
@RequestMapping("/commonProsperity/project")
public class BizCommonProsperityProjectController extends BaseController
{
    @Autowired
    private IBizCommonProsperityProjectService bizCommonProsperityProjectService;

    @PreAuthorize("@ss.hasPermi('commonProsperity:project:list')")
    @GetMapping("/list")
    public TableDataInfo list(BizCommonProsperityProject query)
    {
        startPage();
        List<BizCommonProsperityProject> list = bizCommonProsperityProjectService.selectBizCommonProsperityProjectList(query);
        return getDataTable(list);
    }

    @PreAuthorize("@ss.hasPermi('commonProsperity:project:query')")
    @GetMapping("/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(bizCommonProsperityProjectService.selectBizCommonProsperityProjectById(id));
    }

    @PreAuthorize("@ss.hasPermi('commonProsperity:project:add')")
    @Log(title = "共同富裕项目", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Validated @RequestBody BizCommonProsperityProject row)
    {
        row.setCreateBy(getUsername());
        return toAjax(bizCommonProsperityProjectService.insertBizCommonProsperityProject(row));
    }

    @PreAuthorize("@ss.hasPermi('commonProsperity:project:edit')")
    @Log(title = "共同富裕项目", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@Validated @RequestBody BizCommonProsperityProject row)
    {
        row.setUpdateBy(getUsername());
        return toAjax(bizCommonProsperityProjectService.updateBizCommonProsperityProject(row));
    }

    @PreAuthorize("@ss.hasPermi('commonProsperity:project:remove')")
    @Log(title = "共同富裕项目", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(bizCommonProsperityProjectService.deleteBizCommonProsperityProjectByIds(ids));
    }

    @PreAuthorize("@ss.hasPermi('commonProsperity:project:publish')")
    @Log(title = "共同富裕项目发布", businessType = BusinessType.UPDATE)
    @PostMapping("/publish/{id}")
    public AjaxResult publish(@PathVariable Long id)
    {
        return toAjax(bizCommonProsperityProjectService.publish(id));
    }

    @PreAuthorize("@ss.hasPermi('commonProsperity:project:offline')")
    @Log(title = "共同富裕项目下架", businessType = BusinessType.UPDATE)
    @PostMapping("/offline/{id}")
    public AjaxResult offline(@PathVariable Long id)
    {
        return toAjax(bizCommonProsperityProjectService.offline(id));
    }
}
