/* * @Author: lilig * @Date: 2023-10-10 15:22:58 * @LastEditors: lilifor * @LastEditTime: 2023-10-10 15:22:58 * @FilePath: \SCD\controllers\TaskController.go * @Description: * * Copyright (c) 2023 by lilig/jujutong, All Rights Reserved. */ package controllers import ( "encoding/json" "fmt" "scd_check_tools/models/bo" "scd_check_tools/tools" "strconv" "strings" "github.com/astaxie/beego/orm" ) //业务管理服务 type BusAdminController struct { BaseController } func init() { } // @Summary 创建新的接线方式 // @Description 创建新的接线方式 // @Tags 业务管理服务 // @Accept x-www-form-urlencoded // @Produce json // @Param id formData int false "数据ID。指定id值大于0时为编辑操作;否则为新增操作" // @Param name formData string true "任务名称" // @Param vol_id formData int true "电压等级ID" // @Param pic formData string false "接线图地址" // @Success 200 {object} ResultOK 成功 // @Failure 500 {object} ResultError 失败 // @router /admin/linkstyle/save [post] func (c *BusAdminController) SaveLinkStyleInfo() { id, _ := c.GetInt("id") obj := new(bo.LinkStyleMgr) obj.SetUserInfo(c.GetCurrentUserInfo()) obj.Model = bo.T_data_link_style{Id: id} obj.Model.Name = c.GetString("name") obj.Model.VolLevelId, _ = c.GetInt("vol_id") obj.Model.Pic = c.GetString("pic") if obj.Model.Name == "" { c.Data["json"] = c.ResultError("名称不能为空") c.ServeJSON() return } if obj.Model.VolLevelId == 0 { c.Data["json"] = c.ResultError("电压等级不能为空") c.ServeJSON() return } err := obj.Save() if err != nil { c.Data["json"] = c.ResultError(err.Error()) c.ServeJSON() return } c.Data["json"] = c.ResultOK("", 0) c.ServeJSON() } // @Summary 删除指定的接线方式 // @Description 删除指定的接线方式 // @Tags 业务管理服务 // @Accept x-www-form-urlencoded // @Produce json // @Param id formData int true "接线方式ID" // @Success 200 {object} ResultOK 成功 // @Failure 500 {object} ResultError 失败 // @router /admin/linkstyle/delete [post] func (c *BusAdminController) DeleteLinkStyleByID() { id, _ := c.GetInt("id") if id == 0 { c.Data["json"] = c.ResultError("id不能为空!") c.ServeJSON() return } obj := new(bo.LinkStyleMgr) obj.SetUserInfo(c.GetCurrentUserInfo()) obj.Model = bo.T_data_link_style{} obj.Model.Id = id err := obj.Delete() if err != nil { c.Data["json"] = c.ResultError(err.Error()) c.ServeJSON() return } c.Data["json"] = c.ResultOK("", 0) c.ServeJSON() } // @Summary 查询接线方式 // @Description 查询接线方式。支持名称、电压等级等过滤条件 // @Tags 检测任务服务接口 // @Accept x-www-form-urlencoded // @Produce json // @Param pageno query int true "当前页码。默认为1" // @Param pagesize query int true "每页显示数据数。默认为20" // @Param id query int false "ID" // @Param vol_id query int false "电压ID" // @Param name query string false "名称" // @Success 200 {object} ResultOK 成功 // @Failure 500 {object} ResultError 失败 // @router /admin/linkstyle/list [get] func (c *BusAdminController) GetLinkStyleList() { obj := new(bo.LinkStyleMgr) obj.SetUserInfo(c.GetCurrentUserInfo()) obj.Model = bo.T_data_link_style{} obj.Model.Id, _ = c.GetInt("id") obj.Model.VolLevelId, _ = c.GetInt("vol_id") obj.Model.Name = c.GetString("name") pi, _ := c.GetInt("pagesize", 20) po, _ := c.GetInt("pageno", 0) if po == 0 { po, _ = c.GetInt("pageindex", 0) } if po == 0 { po = 1 } lst, cnt, err := obj.List(po, pi) if err != nil { c.Data["json"] = c.ResultError(err.Error()) c.ServeJSON() return } c.Data["json"] = c.ResultOK(lst, cnt) c.ServeJSON() } // @Summary 添加接线方式的模型 // @Description 添加接线方式的模型 // @Tags 业务管理服务 // @Accept x-www-form-urlencoded // @Produce json // @Param id formData int false "数据ID。指定id值大于0时为编辑操作;否则为新增操作" // @Param linkstyle_id formData int true "接线方式ID" // @Param model_id formData int true "内置模型id" // @Success 200 {object} ResultOK 成功 // @Failure 500 {object} ResultError 失败 // @router /admin/linkstyle-model/save [post] func (c *BusAdminController) SaveLinkStyleModelInfo() { id, _ := c.GetInt("id") obj := new(bo.LinkStyleModelMgr) obj.SetUserInfo(c.GetCurrentUserInfo()) obj.Model = bo.T_data_link_style_model{Id: id} obj.Model.LinkstyleId, _ = c.GetInt("linkstyle_id") obj.Model.ModelId, _ = c.GetInt("model_id") if obj.Model.LinkstyleId == 0 { c.Data["json"] = c.ResultError("接线方式不能为空") c.ServeJSON() return } if obj.Model.ModelId == 0 { c.Data["json"] = c.ResultError("模型ID不能为空") c.ServeJSON() return } err := obj.Save() if err != nil { c.Data["json"] = c.ResultError(err.Error()) c.ServeJSON() return } c.Data["json"] = c.ResultOK("", 0) c.ServeJSON() } // @Summary 删除指定接线方式下属的模型 // @Description 删除指定接线方式下属的模型 // @Tags 业务管理服务 // @Accept x-www-form-urlencoded // @Produce json // @Param id formData int true "接线方式ID" // @Param model_id formData int true "模型ID" // @Success 200 {object} ResultOK 成功 // @Failure 500 {object} ResultError 失败 // @router /admin/linkstyle-model/delete [post] func (c *BusAdminController) DeleteLinkStyleModelByID() { id, _ := c.GetInt("id") if id == 0 { c.Data["json"] = c.ResultError("id不能为空!") c.ServeJSON() return } model_id, _ := c.GetInt("model_id") if model_id == 0 { c.Data["json"] = c.ResultError("模型id不能为空!") c.ServeJSON() return } obj := new(bo.LinkStyleModelMgr) obj.SetUserInfo(c.GetCurrentUserInfo()) obj.Model = bo.T_data_link_style_model{} obj.Model.LinkstyleId = id obj.Model.Id = model_id err := obj.Delete() if err != nil { c.Data["json"] = c.ResultError(err.Error()) c.ServeJSON() return } c.Data["json"] = c.ResultOK("", 0) c.ServeJSON() } // @Summary 查询接线方式下模型列表 // @Description 查询接线方式下模型列表 // @Tags 检测任务服务接口 // @Accept x-www-form-urlencoded // @Produce json // @Param pageno query int true "当前页码。默认为1" // @Param pagesize query int true "每页显示数据数。默认为20" // @Param id query int false "ID" // @Param linkstyle_id query int false "接线方式ID" // @Success 200 {object} ResultOK 成功 // @Failure 500 {object} ResultError 失败 // @router /admin/linkstyle-model/list [get] func (c *BusAdminController) GetLinkStyleModelList() { obj := new(bo.LinkStyleModelMgr) obj.SetUserInfo(c.GetCurrentUserInfo()) obj.Model = bo.T_data_link_style_model{} obj.Model.Id, _ = c.GetInt("id") obj.Model.LinkstyleId, _ = c.GetInt("linkstyle_id") pi, _ := c.GetInt("pagesize", 20) po, _ := c.GetInt("pageno", 0) if po == 0 { po, _ = c.GetInt("pageindex", 0) } if po == 0 { po = 1 } lst, cnt, err := obj.List(po, pi) if err != nil { c.Data["json"] = c.ResultError(err.Error()) c.ServeJSON() return } c.Data["json"] = c.ResultOK(lst, cnt) c.ServeJSON() } // @Summary 创建或编辑新的内置模型 // @Description 创建新的内置模型 // @Tags 业务管理服务 // @Accept x-www-form-urlencoded // @Produce json // @Param id formData int false "数据ID。指定id值大于0时为编辑操作;否则为新增操作" // @Param model_name formData string true "模型名称" // @Param vol_id formData int true "电压等级ID" // @Param line_link_style formData int true "接线方式ID" // @Param ied_types formData string false "包含的装置类型,关联代码:ied_type。多个类型之间使用逗号分隔。" // @Param relation_json formData string false "模型定义内容。svg源代码(xml格式)。" // @Param area_type formData string false "间隔类型。关联代码:area_type" // @Success 200 {object} ResultOK 成功 // @Failure 500 {object} ResultError 失败 // @router /admin/sysmodel/save [post] func (c *BusAdminController) SaveSysModelInfo() { id, _ := c.GetInt("id") obj := new(bo.SysCheckModelMgr) obj.SetUserInfo(c.GetCurrentUserInfo()) obj.Model = bo.T_data_model_defualt{Id: id} obj.Model.ModelName = c.GetString("model_name") obj.Model.AreaType, _ = c.GetInt("area_type") obj.Model.IedTypes = c.GetString("ied_types") obj.Model.VolId, _ = c.GetInt("vol_id") obj.Model.LineLinkStyle, _ = c.GetInt("line_link_style") obj.Model.RelationJson = c.GetString("relation_json") if id == 0 && obj.Model.ModelName == "" { c.Data["json"] = c.ResultError("模型名称不能为空") c.ServeJSON() return } if id == 0 && obj.Model.VolId == 0 { c.Data["json"] = c.ResultError("电压等级不能为空") c.ServeJSON() return } if id == 0 && obj.Model.LineLinkStyle == 0 { c.Data["json"] = c.ResultError("接线方式不能为空") c.ServeJSON() return } if id == 0 && obj.Model.AreaType == 0 { c.Data["json"] = c.ResultError("间隔类型不能为空") c.ServeJSON() return } model, err := obj.Save() if err != nil { c.Data["json"] = c.ResultError(err.Error()) c.ServeJSON() return } c.Data["json"] = c.ResultOK(model, 0) c.ServeJSON() } // @Summary 复制并保存指定的内置检测模型为自定义模型 // @Description 复制并保存指定的内置检测模型为自定义模型 // @Tags 业务管理服务 // @Accept x-www-form-urlencoded // @Produce json // @Param id formData int true "被复制模型的ID" // @Param newname formData string true "新模型名称" // @Param vol_id formData int false "目标电压等级ID" // @Param link_style_id formData int false "目标接线方式ID" // @Success 200 {object} ResultOK 成功 // @Failure 500 {object} ResultError 失败 // @router /admin/sysmodel/saveas [post] func (c *BusAdminController) CopySysModelByID() { id, _ := c.GetInt("id") if id == 0 { c.Data["json"] = c.ResultError("id不能为空!") c.ServeJSON() return } new_name := c.GetString("newname") obj := new(bo.SysCheckModelMgr) obj.SetUserInfo(c.GetCurrentUserInfo()) obj.Model = bo.T_data_model_defualt{Id: id} obj.Model.Id = id obj.Model.ModelName = new_name //判断名称是否已存在 h, _ := obj.ExistName(new_name) if h { c.Data["json"] = c.ResultError("当前的模型名称已存在") c.ServeJSON() return } volid, _ := c.GetInt("vol_id") linkid, _ := c.GetInt("link_style_id") if volid > 0 { obj.Model.VolId = volid } if linkid > 0 { obj.Model.LineLinkStyle = linkid } obj.Model.IsSys = 1 err, newid := obj.Copy(id) if err != nil { c.Data["json"] = c.ResultError(err.Error()) c.ServeJSON() return } c.Data["json"] = c.ResultOK(newid, 0) c.ServeJSON() } // @Summary 删除指定的检测模型 // @Description 删除指定的检测模型 // @Tags 业务管理服务 // @Accept x-www-form-urlencoded // @Produce json // @Param id formData int true "模型ID" // @Success 200 {object} ResultOK 成功 // @Failure 500 {object} ResultError 失败 // @router /admin/sysmodel/delete [post] func (c *BusAdminController) DeleteSysModelByID() { id, _ := c.GetInt("id") if id == 0 { c.Data["json"] = c.ResultError("id不能为空!") c.ServeJSON() return } obj := new(bo.SysCheckModelMgr) obj.SetUserInfo(c.GetCurrentUserInfo()) obj.Model = bo.T_data_model_defualt{Id: id} obj.Model.Id = id err := obj.Delete() if err != nil { c.Data["json"] = c.ResultError(err.Error()) c.ServeJSON() return } c.Data["json"] = c.ResultOK("", 0) c.ServeJSON() } // @Summary 更新检测模型指定装置的类型编码 // @Description 更新检测模型指定装置的类型编码 // @Tags 业务管理服务 // @Accept x-www-form-urlencoded // @Produce json // @Param id formData int true "模型ID" // @Param old_iedtype formData string true "装置原编码" // @Param new_iedtype formData string true "装置新编码" // @Success 200 {object} ResultOK 成功 // @Failure 500 {object} ResultError 失败 // @router /admin/sysmodel/update/iedtype [post] func (c *BusAdminController) UPdateSysModelIedType() { id, _ := c.GetInt("id") if id == 0 { c.Data["json"] = c.ResultError("模型编号不能为空!") c.ServeJSON() return } oldtype := c.GetString("old_iedtype") newtype := c.GetString("new_iedtype") if oldtype == "" { c.Data["json"] = c.ResultError("装置类型编码不能为空!") c.ServeJSON() return } obj := new(bo.SysCheckModelMgr) obj.SetUserInfo(c.GetCurrentUserInfo()) obj.Model = bo.T_data_model_defualt{Id: id} err := obj.UpdateIedType(oldtype, newtype) if err != nil { c.Data["json"] = c.ResultError(err.Error()) c.ServeJSON() return } c.Data["json"] = c.ResultOK("", 0) c.ServeJSON() } // @Summary 获取检测模型指定装置的自定义类型编码 // @Description 获取检测模型指定装置的自定义类型编码 // @Tags 业务管理服务 // @Accept x-www-form-urlencoded // @Produce json // @Param id formData int true "模型ID" // @Param ied_type formData string true "装置原编码" // @Success 200 {object} ResultOK 成功 // @Failure 500 {object} ResultError 失败 // @router /admin/sysmodel/get/iedtype [get] func (c *BusAdminController) GetSysModelIedTypeMapping() { id, _ := c.GetInt("id") if id == 0 { c.Data["json"] = c.ResultError("模型编号不能为空!") c.ServeJSON() return } oldtype := c.GetString("ied_type") if oldtype == "" { c.Data["json"] = c.ResultError("装置类型编码不能为空!") c.ServeJSON() return } obj := new(bo.SysCheckModelMgr) obj.SetUserInfo(c.GetCurrentUserInfo()) obj.Model = bo.T_data_model_defualt{Id: id} r := obj.GetIedtypeMapping(oldtype) c.Data["json"] = c.ResultOK(r, 0) c.ServeJSON() } // @Summary 查询检测模型列表 // @Description 查询检测模型列表。支持名称、电压等级等过滤条件 // @Tags 检测任务服务接口 // @Accept x-www-form-urlencoded // @Produce json // @Param pageno query int true "当前页码。默认为1" // @Param pagesize query int true "每页显示数据数。默认为20" // @Param id query int false "ID" // @Param vol_id query int false "电压等级ID" // @Param model_name query string false "名称" // @Param line_link_style query int false "接线方式" // @Param area_type query int false "间隔类型" // @Param is_sys query int false "模型类型。1 内置模型 2 自定义模型" // @Success 200 {object} ResultOK 成功 // @Failure 500 {object} ResultError 失败 // @router /admin/sysmodel/list [get] func (c *BusAdminController) GetSysModelList() { obj := new(bo.SysCheckModelMgr) obj.SetUserInfo(c.GetCurrentUserInfo()) obj.Model = bo.T_data_model_defualt{} obj.Model.Id, _ = c.GetInt("id") obj.Model.IsSys, _ = c.GetInt("is_sys", 1) //默认查询系统内置模型 obj.Model.VolId, _ = c.GetInt("vol_id") obj.Model.ModelName = c.GetString("model_name") obj.Model.LineLinkStyle, _ = c.GetInt("line_link_style") obj.Model.AreaType, _ = c.GetInt("area_type") pi, _ := c.GetInt("pagesize", 20) po, _ := c.GetInt("pageno", 0) if po == 0 { po, _ = c.GetInt("pageindex", 0) } if po == 0 { po = 1 } lst, cnt, err := obj.List(po, pi) if err != nil { c.Data["json"] = c.ResultError(err.Error()) c.ServeJSON() return } //如果是获取指定模型信息时,附加模型的标准装置类型信息 if obj.Model.Id > 0 { //间隔类型id syscode := new(bo.Global) codeinfo := syscode.GetCodeInfoByID(tools.IsEmpty(lst[0]["area_type"])) if codeinfo != nil { code := "area_type_" + tools.IsEmpty(codeinfo["code"]) codeinfo = syscode.GetCodeInfoByCode("area_ied_type", code) codes := strings.Split(tools.IsEmpty(codeinfo["name"]), ",") ccrows := []orm.Params{} for _, item := range codes { tmp := syscode.GetCodeInfoByCode("ied_type", item) if tmp == nil { ccrows = append(ccrows, orm.Params{"code": item, "name": item}) } else { ccrows = append(ccrows, tmp) } } lst[0]["ied_type"] = ccrows } } c.Data["json"] = c.ResultOK(lst, cnt) c.ServeJSON() } // @Summary 重新分析指定的SCD检测模型间隔 // @Description 重新分析指定的SCD检测模型间隔 // @Tags 业务管理服务 // @Accept x-www-form-urlencoded // @Produce json // @Param scd_id formData int true "SCD文件ID" // @Success 200 {object} ResultOK 成功 // @Failure 500 {object} ResultError 失败 // @router /admin/parse/check_area [post] func (c *BusAdminController) ResetCheckAreaByID() { id, _ := c.GetInt64("scd_id") if id == 0 { c.Data["json"] = c.ResultError("SCD文件ID不能为空!") c.ServeJSON() return } obj := new(bo.CheckAreaMgr) obj.SetUserInfo(c.GetCurrentUserInfo()) obj.ScdId = id err := obj.Reset() if err != nil { c.Data["json"] = c.ResultError(err.Error()) c.ServeJSON() return } c.Data["json"] = c.ResultOK("", 0) c.ServeJSON() } // @Summary 查询指定电压等级及接线方式下的检测间隔分析结果 // @Description 查询指定电压等级及接线方式下的检测间隔分析结果 // @Tags 业务管理服务 // @Accept x-www-form-urlencoded // @Produce json // @Param scd_id formData int true "SCD文件ID" // @Param vol_id formData int false "电压等级ID" // @Param link_style_id formData int false "接线方式ID" // @Success 200 {object} ResultOK 成功 // @Failure 500 {object} ResultError 失败 // @router /admin/get/check_area [get] func (c *BusAdminController) GetCheckAreaByVolID() { id, _ := c.GetInt64("scd_id") if id == 0 { c.Data["json"] = c.ResultError("SCD文件ID不能为空!") c.ServeJSON() return } volid, _ := c.GetInt("vol_id") lsid, _ := c.GetInt("link_style_id") obj := new(bo.CheckAreaMgr) obj.SetUserInfo(c.GetCurrentUserInfo()) obj.ScdId = id lst, err := obj.GetAreaListByVol(id, volid, lsid) if err != nil { c.Data["json"] = c.ResultError(err.Error()) c.ServeJSON() return } if lst == nil || len(lst) == 0 { //新分析 err = obj.Reset() if err != nil { c.Data["json"] = c.ResultError(err.Error()) c.ServeJSON() return } lst, _ = obj.GetAreaListByVol(id, volid, lsid) } //获取每个间隔下的ied列表同步返回 if lst != nil { for i, row := range lst { area_id, _ := strconv.Atoi(tools.IsEmpty(row["area_id"])) iedlst, _ := obj.GetIedList(id, area_id) if iedlst == nil { lst[i]["ieds"] = []orm.Params{} } else { lst[i]["ieds"] = iedlst } } } c.Data["json"] = c.ResultOK(lst, 0) c.ServeJSON() } // @Summary 查询指定检测间隔下的IED装置列表 // @Description 查询指定检测间隔下的IED装置列表 // @Tags 业务管理服务 // @Accept x-www-form-urlencoded // @Produce json // @Param scd_id formData int true "SCD文件ID" // @Param area_id formData int true "检测间隔ID" // @Success 200 {object} ResultOK 成功 // @Failure 500 {object} ResultError 失败 // @router /admin/get/check_area/ied [get] func (c *BusAdminController) GetCheckAreaIedByAreaID() { id, _ := c.GetInt64("scd_id") if id == 0 { c.Data["json"] = c.ResultError("SCD文件ID不能为空!") c.ServeJSON() return } area_id, _ := c.GetInt("area_id") obj := new(bo.CheckAreaMgr) obj.SetUserInfo(c.GetCurrentUserInfo()) obj.ScdId = id lst, err := obj.GetIedList(id, area_id) if err != nil { c.Data["json"] = c.ResultError(err.Error()) c.ServeJSON() return } c.Data["json"] = c.ResultOK(lst, 0) c.ServeJSON() } // @Summary 修改并保存指定检测间隔下的IED装置列表 // @Description 修改并保存指定检测间隔下的IED装置列表 // @Tags 业务管理服务 // @Accept x-www-form-urlencoded // @Produce json // @Param scd_id formData int true "SCD文件ID" // @Param area_id formData int true "检测间隔ID" // @Param ied_ids formData string true "IED装置name列表,多个ied采用逗号分隔。如:PT1001,PL1001,..." // @Success 200 {object} ResultOK 成功 // @Failure 500 {object} ResultError 失败 // @router /admin/update/check_area/ied [post] func (c *BusAdminController) SaveCheckAreaIedByAreaID() { id, _ := c.GetInt64("scd_id") if id == 0 { c.Data["json"] = c.ResultError("SCD文件ID不能为空!") c.ServeJSON() return } area_id, _ := c.GetInt("area_id") ieds := c.GetString("ied_ids") if area_id == 0 { c.Data["json"] = c.ResultError("检测间隔ID不能为空!") c.ServeJSON() return } if ieds == "" { c.Data["json"] = c.ResultError("检测间隔装置列表不能为空!") c.ServeJSON() return } obj := new(bo.CheckAreaMgr) obj.SetUserInfo(c.GetCurrentUserInfo()) obj.ScdId = id err := obj.UpdateIeds(id, area_id, ieds) if err != nil { c.Data["json"] = c.ResultError(err.Error()) c.ServeJSON() return } c.Data["json"] = c.ResultOK("", 0) c.ServeJSON() } // @Summary 设置间隔下指定装置的端子编号 // @Description 设置间隔下指定装置的端子编号。该编号只有在端子匹配表达式中存在{no}标识时才会使用 // @Tags 业务管理服务 // @Accept x-www-form-urlencoded // @Produce json // @Param area_id formData int true "间隔ID" // @Param ied_name formData string true "IED装置名称" // @Param ied_no formData string true "IED装置在特定间隔内,端子间使用的编号" // @Success 200 {object} ResultOK 成功 // @Failure 500 {object} ResultError 失败 // @router /admin/update/check_area/iedno [post] func (c *BusAdminController) SaveCheckAreaIedNoByAreaID() { area_id, _ := c.GetInt("area_id") ied_name := c.GetString("ied_name") if area_id == 0 { c.Data["json"] = c.ResultError("间隔ID不能为空!") c.ServeJSON() return } if ied_name == "" { c.Data["json"] = c.ResultError("装置名称不能为空!") c.ServeJSON() return } obj := new(bo.CheckAreaMgr) obj.SetUserInfo(c.GetCurrentUserInfo()) err := obj.SetIedNo(area_id, ied_name, c.GetString("ied_no")) if err != nil { c.Data["json"] = c.ResultError(err.Error()) c.ServeJSON() return } c.Data["json"] = c.ResultOK("", 0) c.ServeJSON() } // @Summary 获取指定模型和装置类型的功能列表 // @Description 获取指定模型和装置类型的功能列表 // @Tags 业务管理服务 // @Accept x-www-form-urlencoded // @Produce json // @Param model_id formData int true "模型ID" // @Param ied_type formData string true "装置类型" // @Success 200 {object} ResultOK 成功 // @Failure 500 {object} ResultError 失败 // @router /admin/model/function/list [get] func (c *BusAdminController) GetFuncListByIedType() { modelid, _ := c.GetInt("model_id") if modelid == 0 { c.Data["json"] = c.ResultError("模型ID不能为空!") c.ServeJSON() return } ied_type := c.GetString("ied_type") if ied_type == "" { c.Data["json"] = c.ResultError("装置类型不能为空!") c.ServeJSON() return } obj := new(bo.SysCheckModelIedFuncMgr) obj.SetUserInfo(c.GetCurrentUserInfo()) lst, err := obj.GetList(modelid, ied_type) if err != nil { c.Data["json"] = c.ResultError(err.Error()) c.ServeJSON() return } c.Data["json"] = c.ResultOK(lst, 0) c.ServeJSON() } // @Summary 获取SCD中装置实际配置的虚端子关系 // @Description 获取SCD中装置实际配置的虚端子关系 // @Tags 业务管理服务 // @Accept x-www-form-urlencoded // @Produce json // @Param scd_id formData int64 true "SCD文件ID" // @Param area_ids formData string false "指定的间隔列表,多个间隔使用逗号分隔。可以不指定,不指定时则生成全站所有装置的端子关系表" // @Param ied_name formData string false "指定的装置名称。可以不指定。" // @Success 200 {object} ResultOK 成功 // @Failure 500 {object} ResultError 失败 // @router /admin/scd/fcda/list [get] func (c *BusAdminController) GetScdIedFcdaList() { scd_id, _ := c.GetInt64("scd_id") if scd_id == 0 { c.Data["json"] = c.ResultError("SCD文件ID不能为空!") c.ServeJSON() return } areaids := c.GetString("area_ids") areaLst := []string{} if areaids != "" { areaLst = strings.Split(areaids, ",") } obj := new(bo.CheckAreaMgr) lst, err := obj.MakeExtrefReport(scd_id, areaLst, c.GetString("ied_name")) if err != nil { c.Data["json"] = c.ResultError(err.Error()) c.ServeJSON() return } c.Data["json"] = c.ResultOK(lst, len(lst)) c.ServeJSON() } // @Summary 获取指定模型和装置类型的端子列表 // @Description 获取指定模型和装置类型的端子列表 // @Tags 业务管理服务 // @Accept x-www-form-urlencoded // @Produce json // @Param model_id formData int true "模型ID" // @Param ied_type formData string true "查询的装置类型" // @Param ref_ied_type formData string true "对侧关联装置类型" // @Param sv_or_goose formData string true "信号类型。仅支持:SV或GOOSE" // @Param in_or_out formData string true "信号方向。仅支持:'输出'或'接收'" // @Success 200 {object} ResultOK 成功 // @Failure 500 {object} ResultError 失败 // @router /admin/model/function/fcda/list [get] func (c *BusAdminController) GetFuncFcdaList() { modelid, _ := c.GetInt("model_id") if modelid == 0 { c.Data["json"] = c.ResultError("模型ID不能为空!") c.ServeJSON() return } ied_type := c.GetString("ied_type") if ied_type == "" { c.Data["json"] = c.ResultError("查询的装置类型不能为空!") c.ServeJSON() return } ref_ied_type := c.GetString("ref_ied_type") if ied_type == "" { c.Data["json"] = c.ResultError("对侧关联装置类型不能为空!") c.ServeJSON() return } obj := new(bo.SysCheckModelIedFuncMgr) obj.SetUserInfo(c.GetCurrentUserInfo()) lst, err := obj.GetList(modelid, ied_type) if err != nil { c.Data["json"] = c.ResultError(err.Error()) c.ServeJSON() return } if len(lst) == 0 { c.Data["json"] = c.ResultOK("", 0) c.ServeJSON() return } funcids := []string{} for _, row := range lst { funcids = append(funcids, tools.IsEmpty(row["id"])) } fcdaMgr := new(bo.SysCheckModelIedFuncFcdaMgr) fcdaMgr.Model = bo.T_data_model_func_fcda{} fcdaMgr.Model.ModelId = modelid fcdaMgr.Model.Svorgoose = strings.ToUpper(c.GetString("sv_or_goose")) fcdaMgr.Model.Inorout = c.GetString("in_or_out") fcdaList, err := fcdaMgr.GetList(ref_ied_type, funcids) if err != nil { c.Data["json"] = c.ResultError(err.Error()) c.ServeJSON() return } c.Data["json"] = c.ResultOK(fcdaList, len(fcdaList)) c.ServeJSON() } // @Summary 保存模型装置功能及端子信息 // @Description 保存装置功能及端子信息 // @Tags 业务管理服务 // @Accept x-www-form-urlencoded // @Produce json // @Param model_id formData int true "模型ID" // @Param ied_type formData string true "装置类型代码" // @Param func_id formData int false "功能ID。编辑时必传。" // @Param func_name formData string true "功能名称。必传。" // @Param fcda_id formData int false "端子ID。编辑时必传。" // @Param fcda_name formData string true "端子名称。必传。" // @Param fcda_match_exp formData string true "端子匹配表达式。必传。" // @Param sv_or_goose formData string true "端子信号类型。必传。仅支持SV或GOOSE" // @Param in_or_out formData string true "端子信号输入输出方向。必传。仅支持中文的'接收'或'输出'" // @Success 200 {object} ResultOK 成功 // @Failure 500 {object} ResultError 失败 // @router /admin/model/function/fcda/save [post] func (c *BusAdminController) SaveFuncFcda() { modelid, _ := c.GetInt("model_id") if modelid == 0 { c.Data["json"] = c.ResultError("模型ID不能为空!") c.ServeJSON() return } ied_type := c.GetString("ied_type") func_name := c.GetString("func_name") fcda_name := c.GetString("fcda_name") fcda_match_exp := c.GetString("fcda_match_exp") func_id, _ := c.GetInt("func_id") fcda_id, _ := c.GetInt("fcda_id") svorgoose := c.GetString("sv_or_goose") inorout := c.GetString("in_or_out") if func_name == "" { c.Data["json"] = c.ResultError("功能名称不能为空!") c.ServeJSON() return } if fcda_name == "" { c.Data["json"] = c.ResultError("端子设计名称不能为空!") c.ServeJSON() return } if fcda_match_exp == "" { c.Data["json"] = c.ResultError("端子匹配关键词不能为空!") c.ServeJSON() return } if svorgoose == "" { c.Data["json"] = c.ResultError("端子信号类型不能为空!") c.ServeJSON() return } if inorout == "" { c.Data["json"] = c.ResultError("端子信号方向不能为空!") c.ServeJSON() return } mod := bo.T_data_model_func_def{} mod.Id = func_id mod.ModelId = modelid mod.IedType = ied_type mod.FuncFcdaId = fcda_id mod.FuncName = func_name mod.FcdaName = fcda_name mod.FcdaMatchExp = fcda_match_exp mod.Svorgoose = svorgoose mod.Inorout = inorout mgr := new(bo.SysCheckModelIedFuncMgr) mgr.SetUserInfo(c.GetCurrentUserInfo()) mgr.Model = mod _, _, err := mgr.Save() if err != nil { c.Data["json"] = c.ResultError(err.Error()) c.ServeJSON() return } c.Data["json"] = c.ResultOK("", 0) c.ServeJSON() } // @Summary 删除指定模型所有的装置端子 // @Description 删除指定模型所有的装置端子 // @Tags 业务管理服务 // @Accept x-www-form-urlencoded // @Produce json // @Param model_id formData int true "模型ID" // @Success 200 {object} ResultOK 成功 // @Failure 500 {object} ResultError 失败 // @router /admin/model/fcda/delall [post] func (c *BusAdminController) DelAllFuncFcda() { modelid, _ := c.GetInt("model_id") if modelid == 0 { c.Data["json"] = c.ResultError("模型ID不能为空!") c.ServeJSON() return } fcdaMgr := new(bo.SysCheckModelIedFuncMgr) fcdaMgr.SetUserInfo(c.GetCurrentUserInfo()) fcdaMgr.Model = bo.T_data_model_func_def{} fcdaMgr.Model.ModelId = modelid err := fcdaMgr.Delete() if err != nil { c.Data["json"] = c.ResultError(err.Error()) c.ServeJSON() return } c.Data["json"] = c.ResultOK("", 0) c.ServeJSON() } // @Summary 删除装置端子 // @Description 删除装置端子 // @Tags 业务管理服务 // @Accept x-www-form-urlencoded // @Produce json // @Param model_id formData int true "模型ID" // @Param fcda_id formData int true "端子ID" // @Success 200 {object} ResultOK 成功 // @Failure 500 {object} ResultError 失败 // @router /admin/model/function/fcda/del [post] func (c *BusAdminController) DelFuncFcda() { modelid, _ := c.GetInt("model_id") if modelid == 0 { c.Data["json"] = c.ResultError("模型ID不能为空!") c.ServeJSON() return } fcda_id, _ := c.GetInt("fcda_id") if fcda_id == 0 { c.Data["json"] = c.ResultError("端子ID不能为空!") c.ServeJSON() return } fcdaMgr := new(bo.SysCheckModelIedFuncFcdaMgr) fcdaMgr.SetUserInfo(c.GetCurrentUserInfo()) fcdaMgr.Model = bo.T_data_model_func_fcda{} fcdaMgr.Model.ModelId = modelid fcdaMgr.Model.Id = fcda_id err := fcdaMgr.Delete() if err != nil { c.Data["json"] = c.ResultError(err.Error()) c.ServeJSON() return } c.Data["json"] = c.ResultOK("", 0) c.ServeJSON() } // @Summary 获取模型装置端子已关联的接收端子 // @Description 获取模型装置端子已关联的接收端子 // @Tags 业务管理服务 // @Accept x-www-form-urlencoded // @Produce json // @Param model_id formData int true "模型ID" // @Param from_fcda_id formData int true "输出装置端子ID" // @Param to_ied_type formData string false "输入装置类型" // @Param goosesv formData string false "信号类型。GOOSE|SV" // @Success 200 {object} ResultOK 成功 // @Failure 500 {object} ResultError 失败 // @router /admin/model/function/fcda-ref/list [get] func (c *BusAdminController) GetFuncFcdaRef() { modelid, _ := c.GetInt("model_id") if modelid == 0 { c.Data["json"] = c.ResultError("模型ID不能为空!") c.ServeJSON() return } fcda_id, _ := c.GetInt("from_fcda_id") if fcda_id == 0 { c.Data["json"] = c.ResultError("输出装置端子ID不能为空!") c.ServeJSON() return } fcdaMgr := new(bo.SysCheckModelFcdaRalationMgr) fcdaMgr.SetUserInfo(c.GetCurrentUserInfo()) fcdaMgr.Model = bo.T_data_model_fcda_ref{} fcdaMgr.Model.ModelId = modelid fcdaMgr.Model.FromFcdaId = fcda_id fcdaMgr.Model.ToIedCode = c.GetString("to_ied_type") fcdaMgr.Model.Goosesv = c.GetString("goosesv") lst, err := fcdaMgr.GetList() if err != nil { c.Data["json"] = c.ResultError(err.Error()) c.ServeJSON() return } c.Data["json"] = c.ResultOK(lst, len(lst)) c.ServeJSON() } // @Summary 保存模型装置端子间关联关系 // @Description 保存模型装置端子间关联关系 // @Tags 业务管理服务 // @Accept x-www-form-urlencoded // @Produce json // @Param model_id formData int true "模型ID" // @Param from_ied_type formData string true "输出装置类型" // @Param to_ied_type formData string true "输入装置类型" // @Param from_fcda_id formData int false "输出装置端子ID" // @Param to_fcda_ids formData string false "输入装置端子ID" // @Param batch_fcda_ids formData json-string true "批量保存端子关系。类型为序列化的二维数组字符串。数组元素为:[[fromfcdaid,tofcdaid],...]" // @Param goosesv formData string true "信号类型。值范围:GOOSE|SV" // @Success 200 {object} ResultOK 成功 // @Failure 500 {object} ResultError 失败 // @router /admin/model/function/fcda-ref/save [post] func (c *BusAdminController) SaveFuncFcdaRef() { modelid, _ := c.GetInt("model_id") if modelid == 0 { c.Data["json"] = c.ResultError("模型ID不能为空!") c.ServeJSON() return } fcda_id, _ := c.GetInt("from_fcda_id") if fcda_id == 0 { c.Data["json"] = c.ResultError("输出装置端子ID不能为空!") c.ServeJSON() return } fcda_in_ids := c.GetString("to_fcda_ids") fcdaMgr := new(bo.SysCheckModelFcdaRalationMgr) fcdaMgr.SetUserInfo(c.GetCurrentUserInfo()) fcdaMgr.Model = bo.T_data_model_fcda_ref{} fcdaMgr.Model.ModelId = modelid fcdaMgr.Model.FromFcdaId = fcda_id fcdaMgr.Model.FromIedCode = c.GetString("from_ied_type") fcdaMgr.Model.ToIedCode = c.GetString("to_ied_type") fcdaMgr.Model.Goosesv = strings.ToUpper(c.GetString("goosesv")) if fcdaMgr.Model.FromIedCode == "" || fcdaMgr.Model.ToIedCode == "" { c.Data["json"] = c.ResultError("输入和输出装置类型不能为空!") c.ServeJSON() return } if fcdaMgr.Model.Goosesv == "" { c.Data["json"] = c.ResultError("信号类型不能为空!") c.ServeJSON() return } if fcdaMgr.Model.Goosesv != "GOOSE" && fcdaMgr.Model.Goosesv != "SV" { c.Data["json"] = c.ResultError("信号类型不正确。只能为GOOSE或SV") c.ServeJSON() return } batch_fcda_ids := c.GetString("batch_fcda_ids") if batch_fcda_ids != "" { //批量保存 fcdalist := [][]int{} err := json.Unmarshal([]byte(batch_fcda_ids), &fcdalist) if err != nil { c.Data["json"] = c.ResultError("无效的批量端子关系数据") c.ServeJSON() return } obj := new(bo.SysCheckModelIedFuncFcdaMgr) for _, item := range fcdalist { fcdainf, err := obj.One(item[0]) if err != nil { c.Data["json"] = c.ResultError(fmt.Sprintf("无效的端子ID:%d", item[0])) c.ServeJSON() return } fcdaMgr.Model.FromFuncId = fcdainf.FuncId fcdaMgr.Model.FromFcdaId = item[0] fcdainf, err = obj.One(item[1]) if err != nil { c.Data["json"] = c.ResultError(fmt.Sprintf("无效的端子ID:%d", item[1])) c.ServeJSON() return } fcdaMgr.Model.ToFcdaId = item[1] fcdaMgr.Model.ToFuncId = fcdainf.FuncId err = fcdaMgr.Save() if err != nil { c.Data["json"] = c.ResultError(err.Error()) c.ServeJSON() return } } c.Data["json"] = c.ResultOK("", 0) c.ServeJSON() return } obj := new(bo.SysCheckModelIedFuncFcdaMgr) fcdainf, er := obj.One(fcdaMgr.Model.FromFcdaId) if er != nil { c.Data["json"] = c.ResultError("无效的输出端子ID") c.ServeJSON() return } fcdaMgr.Model.FromFuncId = fcdainf.FuncId //清除输出端子的原关系 err := fcdaMgr.Delete() if err != nil { c.Data["json"] = c.ResultError(err.Error()) c.ServeJSON() return } if fcda_in_ids != "" { fcda_in_ids_1 := strings.Split(fcda_in_ids, ",") for _, k := range fcda_in_ids_1 { fcdaMgr.Model.ToFcdaId, _ = strconv.Atoi(k) //设置接收端子id fcdainf, er = obj.One(fcdaMgr.Model.ToFcdaId) if er != nil { c.Data["json"] = c.ResultError("无效的接收端子ID") c.ServeJSON() return } //清除接收端子的原关系 fcdaMgr.Model.FromFcdaId = 0 fcdaMgr.Delete() fcdaMgr.Model.ToFuncId = fcdainf.FuncId //建立新的端子关系 fcdaMgr.Model.FromFcdaId = fcda_id //还原输出端子id err := fcdaMgr.Save() if err != nil { c.Data["json"] = c.ResultError(err.Error()) c.ServeJSON() return } } } c.Data["json"] = c.ResultOK("", 0) c.ServeJSON() } // @Summary 删除端子之间的关联关系 // @Description 删除端子之间的关联关系 // @Tags 业务管理服务 // @Accept x-www-form-urlencoded // @Produce json // @Param model_id formData int true "模型ID" // @Param from_fcda_id formData int true "输入端子ID" // @Param to_fcda_id formData int true "输出端子ID" // @Success 200 {object} ResultOK 成功 // @Failure 500 {object} ResultError 失败 // @router /admin/model/function/fcda-ref/del [post] func (c *BusAdminController) DelFuncFcdaRef() { fcdaMgr := new(bo.SysCheckModelFcdaRalationMgr) fcdaMgr.SetUserInfo(c.GetCurrentUserInfo()) fcdaMgr.Model = bo.T_data_model_fcda_ref{} fcdaMgr.Model.ModelId, _ = c.GetInt("model_id", 0) fcdaMgr.Model.FromFcdaId, _ = c.GetInt("from_fcda_id", 0) fcdaMgr.Model.ToFcdaId, _ = c.GetInt("to_fcda_id") if fcdaMgr.Model.ModelId == 0 { c.Data["json"] = c.ResultError("模型ID不能为空!") c.ServeJSON() return } if fcdaMgr.Model.FromFcdaId == 0 { c.Data["json"] = c.ResultError("输入端子ID不能为空!") c.ServeJSON() return } if fcdaMgr.Model.ToFcdaId == 0 { c.Data["json"] = c.ResultError("接收端子ID不能为空") c.ServeJSON() return } //清除原关系 err := fcdaMgr.Delete() if err != nil { c.Data["json"] = c.ResultError(err.Error()) c.ServeJSON() return } c.Data["json"] = c.ResultOK("", 0) c.ServeJSON() }