package com.sooka.system.controller;

import java.util.List;

import com.sooka.common.core.controller.BaseController;
import com.sooka.common.core.domain.AjaxResult;
import com.sooka.common.core.page.TableDataInfo;
import com.sooka.common.enums.BusinessType;
import com.sooka.common.utils.poi.ExcelUtil;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
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.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.sooka.common.annotation.Log;
import com.sooka.system.domain.TgjjZcxx;
import com.sooka.system.service.ITgjjZcxxService;

/**
 * 政策信息Controller
 * 
 * @author lei
 * @date 2021-11-16
 */
@Controller
@RequestMapping("/system/zcxx")
public class TgjjZcxxController extends BaseController
{
    private String prefix = "system/zcxx";

    @Autowired
    private ITgjjZcxxService tgjjZcxxService;

    @RequiresPermissions("system:zcxx:view")
    @GetMapping()
    public String zcxx()
    {
        return prefix + "/zcxx";
    }

    /**
     * 查询政策信息列表
     */
    @RequiresPermissions("system:zcxx:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TgjjZcxx tgjjZcxx)
    {
        startPage();
        List<TgjjZcxx> list = tgjjZcxxService.selectTgjjZcxxList(tgjjZcxx);
        return getDataTable(list);
    }

    /**
     * 导出政策信息列表
     */
    @RequiresPermissions("system:zcxx:export")
    @Log(title = "政策信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TgjjZcxx tgjjZcxx)
    {
        List<TgjjZcxx> list = tgjjZcxxService.selectTgjjZcxxList(tgjjZcxx);
        ExcelUtil<TgjjZcxx> util = new ExcelUtil<TgjjZcxx>(TgjjZcxx.class);
        return util.exportExcel(list, "zcxx");
    }

    /**
     * 新增政策信息
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存政策信息
     */
    @RequiresPermissions("system:zcxx:add")
    @Log(title = "政策信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TgjjZcxx tgjjZcxx)
    {
        return toAjax(tgjjZcxxService.insertTgjjZcxx(tgjjZcxx));
    }

    /**
     * 修改政策信息
     */
    @GetMapping("/edit/{ID}")
    public String edit(@PathVariable("ID") Long ID, ModelMap mmap)
    {
        TgjjZcxx tgjjZcxx = tgjjZcxxService.selectTgjjZcxxById(ID);
        mmap.put("tgjjZcxx", tgjjZcxx);
        return prefix + "/edit";
    }

    /**
     * 修改保存政策信息
     */
    @RequiresPermissions("system:zcxx:edit")
    @Log(title = "政策信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TgjjZcxx tgjjZcxx)
    {
        return toAjax(tgjjZcxxService.updateTgjjZcxx(tgjjZcxx));
    }

    /**
     * 删除政策信息
     */
    @RequiresPermissions("system:zcxx:remove")
    @Log(title = "政策信息", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(tgjjZcxxService.deleteTgjjZcxxByIds(ids));
    }
}
