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

import java.util.List;

import com.ztmap.project.zhny.strategycondition.domain.TStrategyCondition;
import com.ztmap.project.zhny.strategycondition.service.ITStrategyConditionService;
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.strategytarget.domain.TStrategyTarget;
import com.ztmap.project.zhny.strategytarget.service.ITStrategyTargetService;
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/strategytarget")
public class TStrategyTargetController extends BaseController
{
    private String prefix = "zhny/strategytarget";

    @Autowired
    private ITStrategyConditionService tStrategyConditionService;

    @Autowired
    private ITStrategyTargetService tStrategyTargetService;

    @RequiresPermissions("zhny:strategytarget:view")
    @GetMapping("/strategytarget/{condId}")
    public String strategytarget(@PathVariable("condId")Long condId,ModelMap mmap)
    {
        mmap.put("condId",condId);
        mmap.put("condList",tStrategyConditionService.selectTStrategyConditionList(new TStrategyCondition()));
        return prefix + "/strategytarget";
    }

    /**
     * 查询目标列表
     */
    @RequiresPermissions("zhny:strategytarget:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TStrategyTarget tStrategyTarget)
    {
        startPage();
        List<TStrategyTarget> list = tStrategyTargetService.selectTStrategyTargetList(tStrategyTarget);
        return getDataTable(list);
    }

    /**
     * 导出目标列表
     */
    @RequiresPermissions("zhny:strategytarget:export")
    @Log(title = "目标", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TStrategyTarget tStrategyTarget)
    {
        List<TStrategyTarget> list = tStrategyTargetService.selectTStrategyTargetList(tStrategyTarget);
        ExcelUtil<TStrategyTarget> util = new ExcelUtil<TStrategyTarget>(TStrategyTarget.class);
        return util.exportExcel(list, "目标数据");
    }

    /**
     * 新增目标
     */
    @GetMapping("/add/{condId}")
    public String add(@PathVariable("condId")Long condId,ModelMap mmap)
    {
        mmap.put("condId",condId);
        mmap.put("condList",tStrategyConditionService.selectTStrategyConditionList(new TStrategyCondition()));
        return prefix + "/add";
    }

    /**
     * 新增保存目标
     */
    @RequiresPermissions("zhny:strategytarget:add")
    @Log(title = "目标", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TStrategyTarget tStrategyTarget)
    {
        return toAjax(tStrategyTargetService.insertTStrategyTarget(tStrategyTarget));
    }

    /**
     * 修改目标
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        TStrategyTarget tStrategyTarget = tStrategyTargetService.selectTStrategyTargetById(id);
        mmap.put("tStrategyTarget", tStrategyTarget);
        return prefix + "/edit";
    }

    /**
     * 修改保存目标
     */
    @RequiresPermissions("zhny:strategytarget:edit")
    @Log(title = "目标", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TStrategyTarget tStrategyTarget)
    {
        return toAjax(tStrategyTargetService.updateTStrategyTarget(tStrategyTarget));
    }

    /**
     * 删除目标
     */
    @RequiresPermissions("zhny:strategytarget:remove")
    @Log(title = "目标", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(tStrategyTargetService.deleteTStrategyTargetByIds(ids));
    }
}
