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

import java.util.List;
import javax.servlet.http.HttpServletResponse;
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.common.utils.poi.ExcelUtil;
import com.ruoyi.web.modules.prosperity.domain.BizCommonProsperityAchievement;
import com.ruoyi.web.modules.prosperity.service.IBizCommonProsperityAchievementService;

/**
 * 共同富裕成果管理
 */
@RestController
@RequestMapping("/commonProsperity/achievement")
public class BizCommonProsperityAchievementController extends BaseController
{
    @Autowired
    private IBizCommonProsperityAchievementService bizCommonProsperityAchievementService;

    @PreAuthorize("@ss.hasPermi('commonProsperity:achievement:list')")
    @GetMapping("/list")
    public TableDataInfo list(BizCommonProsperityAchievement query)
    {
        startPage();
        List<BizCommonProsperityAchievement> list =
                bizCommonProsperityAchievementService.selectBizCommonProsperityAchievementList(query);
        return getDataTable(list);
    }

    @PreAuthorize("@ss.hasPermi('commonProsperity:achievement:export')")
    @Log(title = "共同富裕成果", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BizCommonProsperityAchievement query)
    {
        List<BizCommonProsperityAchievement> list =
                bizCommonProsperityAchievementService.selectBizCommonProsperityAchievementList(query);
        ExcelUtil<BizCommonProsperityAchievement> util =
                new ExcelUtil<BizCommonProsperityAchievement>(BizCommonProsperityAchievement.class);
        util.exportExcel(response, list, "共同富裕成果");
    }

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

    @PreAuthorize("@ss.hasPermi('commonProsperity:achievement:add')")
    @Log(title = "共同富裕成果", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Validated @RequestBody BizCommonProsperityAchievement row)
    {
        row.setCreateBy(getUsername());
        return toAjax(bizCommonProsperityAchievementService.insertBizCommonProsperityAchievement(row));
    }

    @PreAuthorize("@ss.hasPermi('commonProsperity:achievement:edit')")
    @Log(title = "共同富裕成果", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@Validated @RequestBody BizCommonProsperityAchievement row)
    {
        row.setUpdateBy(getUsername());
        return toAjax(bizCommonProsperityAchievementService.updateBizCommonProsperityAchievement(row));
    }

    @PreAuthorize("@ss.hasPermi('commonProsperity:achievement:remove')")
    @Log(title = "共同富裕成果", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(bizCommonProsperityAchievementService.deleteBizCommonProsperityAchievementByIds(ids));
    }
}
