package com.ztmap.project.zhny.strategy.controller;

import java.util.List;
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.ztmap.framework.aspectj.lang.annotation.Log;
import com.ztmap.framework.aspectj.lang.enums.BusinessType;
import com.ztmap.project.zhny.strategy.domain.TStrategy;
import com.ztmap.project.zhny.strategy.service.ITStrategyService;
import com.ztmap.framework.web.controller.BaseController;
import com.ztmap.framework.web.domain.AjaxResult;
import com.ztmap.common.utils.poi.ExcelUtil;
import com.ztmap.framework.web.page.TableDataInfo;

/**
 * 策略管理Controller
 * 
 * @author ztmap
 * @date 2023-10-11
 */
@Controller
@RequestMapping("/zhny/strategy")
public class TStrategyController extends BaseController
{
    private String prefix = "zhny/strategy";

    @Autowired
    private ITStrategyService tStrategyService;

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

    /**
     * 查询策略管理列表
     */
    @RequiresPermissions("zhny:strategy:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TStrategy tStrategy)
    {
        startPage();
        List<TStrategy> list = tStrategyService.selectTStrategyList(tStrategy);
        return getDataTable(list);
    }

    /**
     * 导出策略管理列表
     */
    @RequiresPermissions("zhny:strategy:export")
    @Log(title = "策略管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TStrategy tStrategy)
    {
        List<TStrategy> list = tStrategyService.selectTStrategyList(tStrategy);
        ExcelUtil<TStrategy> util = new ExcelUtil<TStrategy>(TStrategy.class);
        return util.exportExcel(list, "策略管理数据");
    }

    /**
     * 新增策略管理
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存策略管理
     */
    @RequiresPermissions("zhny:strategy:add")
    @Log(title = "策略管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TStrategy tStrategy)
    {
        return toAjax(tStrategyService.insertTStrategy(tStrategy));
    }

    /**
     * 修改策略管理
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        TStrategy tStrategy = tStrategyService.selectTStrategyById(id);
        mmap.put("tStrategy", tStrategy);
        return prefix + "/edit";
    }

    /**
     * 修改保存策略管理
     */
    @RequiresPermissions("zhny:strategy:edit")
    @Log(title = "策略管理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TStrategy tStrategy)
    {
        return toAjax(tStrategyService.updateTStrategy(tStrategy));
    }

    /**
     * 删除策略管理
     */
    @RequiresPermissions("zhny:strategy:remove")
    @Log(title = "策略管理", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(tStrategyService.deleteTStrategyByIds(ids));
    }
}
