package com.sooka.system.controller;

import java.util.List;

import com.sooka.common.annotation.Log;
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 com.sooka.system.domain.TUParamsbusiness;
import com.sooka.system.domain.TUParamspublic;
import com.sooka.system.service.ITUParamsbusinessService;
import com.sooka.system.service.ITUParamspublicService;
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.system.domain.TUInterfaceinfo;
import com.sooka.system.service.ITUInterfaceinfoService;

import javax.annotation.Resource;


/**
 * 【请填写功能名称】Controller
 *
 * @author lei
 * @date 2021-07-01
 */
@Controller
@RequestMapping("/system/interfaceinfo")
public class TUInterfaceinfoController extends BaseController {
    private String prefix = "system/interfaceinfo";

    @Autowired
    private ITUInterfaceinfoService tUInterfaceinfoService;
    @Resource
    private ITUParamsbusinessService ituParamsbusinessService;
    @Resource
    private ITUParamspublicService ituParamspublicService;

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

    /**
     * 查询【请填写功能名称】列表
     */
    @RequiresPermissions("system:interfaceinfo:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TUInterfaceinfo tUInterfaceinfo) {
        startPage();
        List<TUInterfaceinfo> list = tUInterfaceinfoService.selectTUInterfaceinfoList(tUInterfaceinfo);
        return getDataTable(list);
    }

    /**
     * 导出【请填写功能名称】列表
     */
    @RequiresPermissions("system:interfaceinfo:export")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TUInterfaceinfo tUInterfaceinfo) {
        List<TUInterfaceinfo> list = tUInterfaceinfoService.selectTUInterfaceinfoList(tUInterfaceinfo);
        ExcelUtil<TUInterfaceinfo> util = new ExcelUtil<TUInterfaceinfo>(TUInterfaceinfo.class);
        return util.exportExcel(list, "interfaceinfo");
    }

    /**
     * 新增【请填写功能名称】
     */
    @GetMapping("/add")
    public String add() {
        return prefix + "/add";
    }

    /**
     * 新增保存【请填写功能名称】
     */
    @RequiresPermissions("system:interfaceinfo:add")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TUInterfaceinfo tUInterfaceinfo) {
        return toAjax(tUInterfaceinfoService.insertTUInterfaceinfo(tUInterfaceinfo));
    }

    /**
     * 修改【请填写功能名称】
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap) {
        TUInterfaceinfo tUInterfaceinfo = tUInterfaceinfoService.selectTUInterfaceinfoById(id);
        mmap.put("tUInterfaceinfo", tUInterfaceinfo);
        return prefix + "/edit";
    }

    /**
     * 修改保存【请填写功能名称】
     */
    @RequiresPermissions("system:interfaceinfo:edit")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TUInterfaceinfo tUInterfaceinfo) {
        return toAjax(tUInterfaceinfoService.updateTUInterfaceinfo(tUInterfaceinfo));
    }

    /**
     * 删除【请填写功能名称】
     */
    @RequiresPermissions("system:interfaceinfo:remove")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(tUInterfaceinfoService.deleteTUInterfaceinfoByIds(ids));
    }

    @GetMapping("/settingParams/{id}")
    public String settingParams(@PathVariable("id") String id, ModelMap mmap) {
        mmap.put("interfaceinfo_id", id);
        return "system/paramsbusiness/paramsbusiness";
    }

    @GetMapping("/execInterface/{id}")
    public String execInterface(@PathVariable("id") String id, ModelMap mmap) {
        mmap.put("interfaceinfo_id", id);
        //按接口id查询接口基本信息
        TUInterfaceinfo tuInterfaceinfo = tUInterfaceinfoService.selectTUInterfaceinfoById(id);
        //按接口id查询公共参数
        List params_public = ituParamspublicService.selectTUParamspublicList(new TUParamspublic());
        //按接口id查询业务参数
        TUParamsbusiness tuParamsbusiness = new TUParamsbusiness();
        tuParamsbusiness.setInterfaceinfoId(id);
        List params_business = ituParamsbusinessService.selectTUParamsbusinessList(tuParamsbusiness);

        mmap.put("tuInterfaceinfo",tuInterfaceinfo);
        mmap.put("params_public_list",params_public);
        mmap.put("params_business_list",params_business);
        return "system/interfaceinfo/execInterface";
    }

}
