/* * @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 ( "scd_check_tools/models/bo" "scd_check_tools/tools" "strconv" "strings" ) //业务管理服务 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, IsSys: 1} 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 } 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 newname formData string true "新模型名称" // @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 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 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 codeinfo := new(bo.Global).GetCodeInfoByID(tools.IsEmpty(lst[0]["area_type"])) if codeinfo != nil { code := "area_type_" + tools.IsEmpty(codeinfo["code"]) codeinfo = new(bo.Global).GetCodeInfoByCode("area_ied_type", code) lst[0]["ied_type"] = codeinfo["name"] } } 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) } 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 获取指定模型和装置类型的功能列表 // @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 获取指定模型和装置类型的端子列表 // @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/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 } 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 } fcdaList := []interface{}{} fcdaMgr := new(bo.SysCheckModelIedFuncFcdaMgr) fcdaMgr.Model = bo.T_data_model_func_fcda{} fcdaMgr.Model.ModelId = modelid for _, row := range lst { fcdaMgr.Model.FuncId, _ = strconv.Atoi(tools.IsEmpty(row["id"])) tmpLst, err := fcdaMgr.GetList() if err != nil { c.Data["json"] = c.ResultError(err.Error()) c.ServeJSON() return } for _, r := range tmpLst { fcdaList = append(fcdaList, r) } } c.Data["json"] = c.ResultOK(fcdaList, 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 "装置类型代码" // @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 "端子匹配表达式。必传。" // @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") 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 } 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 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" // @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 true "输出装置端子ID" // @Param to_fcda_ids formData string true "输入装置端子ID列表。多个ID间使用逗号分隔" // @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 } 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) fcdainf, er = obj.One(fcdaMgr.Model.ToFcdaId) if er != nil { c.Data["json"] = c.ResultError("无效的输入端子ID") c.ServeJSON() return } 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() }