/* * @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" ) //业务管理服务 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") if new_name == "" { 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} obj.Model.Id = id err, newid := obj.Copy(new_name) 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") 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 } 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 } c.Data["json"] = c.ResultOK(lst, 0) c.ServeJSON() }