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

import java.util.List;

import com.ztmap.project.zhny.strategy.domain.TStrategy;
import com.ztmap.project.zhny.strategy.service.ITStrategyService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
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.strategycondition.domain.TStrategyCondition;
import com.ztmap.project.zhny.strategycondition.service.ITStrategyConditionService;
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/strategycondition")
public class TStrategyConditionController extends BaseController
{
    private String prefix = "zhny/strategycondition";

    @Autowired
    private ITStrategyConditionService tStrategyConditionService;
    @Autowired
    private ITStrategyService tStrategyService;

    @RequiresPermissions("zhny:strategycondition:view")
    @GetMapping("/strategycondition/{strategyId}")
    public String strategycondition(@PathVariable("strategyId")Long strategyId,ModelMap mmap)
    {
        mmap.put("strategyList",tStrategyService.selectTStrategyList(new TStrategy()));
        mmap.put("strategyId",strategyId);
        return prefix + "/strategycondition";
    }

    /**
     * 查询策略条件列表
     */
    @RequiresPermissions("zhny:strategycondition:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TStrategyCondition tStrategyCondition)
    {
        startPage();
        List<TStrategyCondition> list = tStrategyConditionService.selectTStrategyConditionList(tStrategyCondition);
        return getDataTable(list);
    }

    /**
     * 导出策略条件列表
     */
    @RequiresPermissions("zhny:strategycondition:export")
    @Log(title = "策略条件", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TStrategyCondition tStrategyCondition)
    {
        List<TStrategyCondition> list = tStrategyConditionService.selectTStrategyConditionList(tStrategyCondition);
        ExcelUtil<TStrategyCondition> util = new ExcelUtil<TStrategyCondition>(TStrategyCondition.class);
        return util.exportExcel(list, "策略条件数据");
    }

    /**
     * 新增策略条件
     */
    @GetMapping("/add/{strategyId}")
    public String add(@PathVariable("strategyId")Long strategyId, ModelMap mmap)
    {
        mmap.put("strategyId",strategyId);
        mmap.put("strategyList",tStrategyService.selectTStrategyList(new TStrategy()));
        return prefix + "/add";
    }

    /**
     * 新增保存策略条件
     */
    @RequiresPermissions("zhny:strategycondition:add")
    @Log(title = "策略条件", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TStrategyCondition tStrategyCondition)
    {
        return toAjax(tStrategyConditionService.insertTStrategyCondition(tStrategyCondition));
    }

    /**
     * 修改策略条件
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        TStrategyCondition tStrategyCondition = tStrategyConditionService.selectTStrategyConditionById(id);
        mmap.put("tStrategyCondition", tStrategyCondition);
        return prefix + "/edit";
    }

    /**
     * 修改保存策略条件
     */
    @RequiresPermissions("zhny:strategycondition:edit")
    @Log(title = "策略条件", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TStrategyCondition tStrategyCondition)
    {
        return toAjax(tStrategyConditionService.updateTStrategyCondition(tStrategyCondition));
    }

    /**
     * 删除策略条件
     */
    @RequiresPermissions("zhny:strategycondition:remove")
    @Log(title = "策略条件", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(tStrategyConditionService.deleteTStrategyConditionByIds(ids));
    }
}
