12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034 |
- /*
- * @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, 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
- 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)
- }
- 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 "装置类型"
- // @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
- }
- 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
- }
- 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(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)
- 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()
- }
- // @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()
- }
|