package com.ruoyi.web.controller.business;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
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.system.domain.PolicyGuide;
import com.ruoyi.system.service.IPolicyGuideService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 政策指南Controller
 * 
 * @author boman
 * @date 2022-06-16
 */
@RestController
@RequestMapping("/system/guide")
public class PolicyGuideController extends BaseController
{
    @Autowired
    private IPolicyGuideService policyGuideService;

    /**
     * 查询政策指南列表
     */
    @PreAuthorize("@ss.hasPermi('system:guide:list')")
    @GetMapping("/list")
    public TableDataInfo list(PolicyGuide policyGuide)
    {
        startPage();
        List<PolicyGuide> list = policyGuideService.selectPolicyGuideList(policyGuide);
        return getDataTable(list);
    }

    /**
     * 导出政策指南列表
     */
    @PreAuthorize("@ss.hasPermi('system:guide:export')")
    @Log(title = "政策指南", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PolicyGuide policyGuide)
    {
        List<PolicyGuide> list = policyGuideService.selectPolicyGuideList(policyGuide);
        ExcelUtil<PolicyGuide> util = new ExcelUtil<PolicyGuide>(PolicyGuide.class);
        util.exportExcel(response, list, "政策指南数据");
    }

    /**
     * 获取政策指南详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:guide:query')")
    @GetMapping(value = "/{policyId}")
    public AjaxResult getInfo(@PathVariable("policyId") Long policyId)
    {
        return AjaxResult.success(policyGuideService.selectPolicyGuideByPolicyId(policyId));
    }

    /**
     * 新增政策指南
     */
    @PreAuthorize("@ss.hasPermi('system:guide:add')")
    @Log(title = "政策指南", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PolicyGuide policyGuide)
    {
        return toAjax(policyGuideService.insertPolicyGuide(policyGuide));
    }

    /**
     * 修改政策指南
     */
    @PreAuthorize("@ss.hasPermi('system:guide:edit')")
    @Log(title = "政策指南", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PolicyGuide policyGuide)
    {
        return toAjax(policyGuideService.updatePolicyGuide(policyGuide));
    }

    /**
     * 删除政策指南
     */
    @PreAuthorize("@ss.hasPermi('system:guide:remove')")
    @Log(title = "政策指南", businessType = BusinessType.DELETE)
	@DeleteMapping("/{policyIds}")
    public AjaxResult remove(@PathVariable Long[] policyIds)
    {
        return toAjax(policyGuideService.deletePolicyGuideByPolicyIds(policyIds));
    }
}
