package com.ruoyi.web.controller.system.property;

import java.util.List;

import com.ruoyi.common.utils.uuid.Seq;
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.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.TdPropertyNet;
import com.ruoyi.system.service.ITdPropertyNetService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 涉密网络设备Controller
 * 
 * @author ruoyi
 * @date 2024-05-09
 */
@Controller
@RequestMapping("/system/network")
public class TdPropertyNetController extends BaseController
{
    private String prefix = "system/network/network";

    @Autowired
    private ITdPropertyNetService tdPropertyNetService;

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

    /**
     * 查询涉密网络设备列表
     */
    @RequiresPermissions("system:network:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TdPropertyNet tdPropertyNet)
    {
        startPage();
        List<TdPropertyNet> list = tdPropertyNetService.selectTdPropertyNetList(tdPropertyNet);
        return getDataTable(list);
    }

    /**
     * 导出涉密网络设备列表
     */
    @RequiresPermissions("system:network:export")
    @Log(title = "涉密网络设备", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TdPropertyNet tdPropertyNet)
    {
        List<TdPropertyNet> list = tdPropertyNetService.selectTdPropertyNetList(tdPropertyNet);
        ExcelUtil<TdPropertyNet> util = new ExcelUtil<TdPropertyNet>(TdPropertyNet.class);
        return util.exportExcel(list, "涉密网络设备数据");
    }

    /**
     * 新增涉密网络设备
     */
    @GetMapping("/add")
    public String add(ModelMap mmap)
    {
        mmap.put("sysuser",getSysUser());
        return prefix + "/add";
    }

    /**
     * 新增保存涉密网络设备
     */
    @RequiresPermissions("system:network:add")
    @Log(title = "涉密网络设备", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TdPropertyNet tdPropertyNet)
    {
        tdPropertyNet.setNetId("Net_"+ Seq.getId(Seq.commSeqType));
        return toAjax(tdPropertyNetService.insertTdPropertyNet(tdPropertyNet));
    }

    /**
     * 修改涉密网络设备
     */
    @RequiresPermissions("system:network:edit")
    @GetMapping("/edit/{netId}")
    public String edit(@PathVariable("netId") String netId, ModelMap mmap)
    {
        TdPropertyNet tdPropertyNet = tdPropertyNetService.selectTdPropertyNetByNetId(netId);
        mmap.put("tdPropertyNet", tdPropertyNet);
        return prefix + "/edit";
    }

    /**
     * 修改保存涉密网络设备
     */
    @RequiresPermissions("system:network:edit")
    @Log(title = "涉密网络设备", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TdPropertyNet tdPropertyNet)
    {
        return toAjax(tdPropertyNetService.updateTdPropertyNet(tdPropertyNet));
    }

    /**
     * 删除涉密网络设备
     */
    @RequiresPermissions("system:network:remove")
    @Log(title = "涉密网络设备", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(tdPropertyNetService.deleteTdPropertyNetByNetIds(ids));
    }

    /**
     * 添加网络设备条目
     */
    @RequiresPermissions("system:network:list")
    @GetMapping("/detail/{netId}")
    public String detail(@PathVariable("netId") String netId, ModelMap mmap)
    {
        mmap.put("netId",netId);
        return "system/network/netinfo/netinfo";
    }


}
