123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131 |
- /*
- * @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 "新模型名称"
- // @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 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 获取指定模型和装置类型的功能列表
- // @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 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()
- }
|