|
|
@@ -7,22 +7,153 @@ import (
|
|
|
"encoding/json"
|
|
|
"fmt"
|
|
|
"io"
|
|
|
+ "math/rand"
|
|
|
"net/http"
|
|
|
+ "os"
|
|
|
+ "time"
|
|
|
|
|
|
"github.com/beego/beego/v2/client/orm"
|
|
|
beego "github.com/beego/beego/v2/server/web"
|
|
|
)
|
|
|
|
|
|
+func init() {
|
|
|
+ // 启动后台协程定期更新电调模型数据
|
|
|
+ go func() {
|
|
|
+ // 初始化延迟1秒执行,避免系统启动时的资源竞争
|
|
|
+ time.Sleep(1 * time.Second)
|
|
|
+
|
|
|
+ // 定时每5秒获取一次数据
|
|
|
+ ticker := time.NewTicker(5 * time.Second)
|
|
|
+ defer ticker.Stop()
|
|
|
+
|
|
|
+ for {
|
|
|
+ select {
|
|
|
+ case <-ticker.C:
|
|
|
+ updateElectricalData()
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }()
|
|
|
+}
|
|
|
+
|
|
|
+// updateElectricalData 从电调服务获取数据并更新模型
|
|
|
+func updateElectricalData() {
|
|
|
+ defer func() {
|
|
|
+ if r := recover(); r != nil {
|
|
|
+ fmt.Printf("更新电调数据时发生错误: %v\n", r)
|
|
|
+ }
|
|
|
+ }()
|
|
|
+
|
|
|
+ // 获取 ElectricModelManager 单例实例
|
|
|
+ manager := models.GetInstance()
|
|
|
+
|
|
|
+ // 获取模型列表副本,避免长时间持有锁
|
|
|
+ manager.Mutex.RLock()
|
|
|
+ modelsCopy := make(map[string]models.EViewMapModel)
|
|
|
+ for k, v := range manager.Models {
|
|
|
+ modelsCopy[k] = v
|
|
|
+ }
|
|
|
+ manager.Mutex.RUnlock()
|
|
|
+
|
|
|
+ // 如果 Models 为空,不进行任何处理
|
|
|
+ if len(modelsCopy) == 0 {
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ // 遍历已有模型并分别更新
|
|
|
+ for _, viewMapModel := range modelsCopy {
|
|
|
+ if len(viewMapModel.Models) > 0 && time.Since(viewMapModel.LastBatchUpdate) >= 5*time.Second {
|
|
|
+ // 获取第一个模型作为参考来构建请求参数
|
|
|
+ firstModel := viewMapModel.Models[0]
|
|
|
+
|
|
|
+ // 从配置获取电调服务地址
|
|
|
+ electricalIP, err := beego.AppConfig.String("ElectricalIP")
|
|
|
+ if err != nil {
|
|
|
+ fmt.Printf("读取电调服务IP配置失败: %v\n", err)
|
|
|
+ continue
|
|
|
+ }
|
|
|
+
|
|
|
+ electricalPort, err := beego.AppConfig.Int("ElectricalPort")
|
|
|
+ if err != nil {
|
|
|
+ fmt.Printf("读取电调服务端口配置失败: %v\n", err)
|
|
|
+ continue
|
|
|
+ }
|
|
|
+
|
|
|
+ // 构造电调服务地址
|
|
|
+ electricalAddr := fmt.Sprintf("http://%s:%d/ServerCtrl/AllEqpmtList", electricalIP, electricalPort)
|
|
|
+
|
|
|
+ // 准备请求数据
|
|
|
+ type RequestData struct {
|
|
|
+ LineID int `json:"lineID"`
|
|
|
+ StationID int `json:"StationID"`
|
|
|
+ ViewID int `json:"ViewID"`
|
|
|
+ }
|
|
|
+ reqData := RequestData{
|
|
|
+ LineID: firstModel.LineID,
|
|
|
+ StationID: firstModel.StationID,
|
|
|
+ ViewID: firstModel.ViewID,
|
|
|
+ }
|
|
|
+
|
|
|
+ // 将请求数据转换为JSON
|
|
|
+ reqBody, err := json.Marshal(reqData)
|
|
|
+ if err != nil {
|
|
|
+ fmt.Printf("构造请求数据失败: %v\n", err)
|
|
|
+ continue
|
|
|
+ }
|
|
|
+
|
|
|
+ // 发送POST请求获取数据
|
|
|
+ resp, err := http.Post(electricalAddr, "application/json", bytes.NewBuffer(reqBody))
|
|
|
+ if err != nil {
|
|
|
+ fmt.Printf("调用电调服务获取所有设备列表接口失败: %v\n", err)
|
|
|
+ continue
|
|
|
+ }
|
|
|
+
|
|
|
+ // 读取响应体
|
|
|
+ bodyBytes, err := io.ReadAll(resp.Body)
|
|
|
+ resp.Body.Close()
|
|
|
+ if err != nil {
|
|
|
+ fmt.Printf("读取电调服务响应失败: %v\n", err)
|
|
|
+ continue
|
|
|
+ }
|
|
|
+
|
|
|
+ // 检查响应状态
|
|
|
+ if resp.StatusCode != http.StatusOK {
|
|
|
+ fmt.Printf("电调服务返回异常状态码: %d,响应内容: %s\n", resp.StatusCode, string(bodyBytes))
|
|
|
+ continue
|
|
|
+ }
|
|
|
+
|
|
|
+ // 解析JSON响应
|
|
|
+ var result map[string]interface{}
|
|
|
+ if err := json.Unmarshal(bodyBytes, &result); err != nil {
|
|
|
+ fmt.Printf("解析电调服务响应失败: %v\n", err)
|
|
|
+ continue
|
|
|
+ }
|
|
|
+
|
|
|
+ // 检查是否有data字段
|
|
|
+ if data, exists := result["data"]; exists {
|
|
|
+ // 解析data中的设备列表并更新到模型管理器
|
|
|
+ var equipments []models.DiandiaoModel
|
|
|
+ if equipBytes, err := json.Marshal(data); err == nil {
|
|
|
+ if err := json.Unmarshal(equipBytes, &equipments); err == nil {
|
|
|
+ // 更新总包设备数据 (在更新时加锁)
|
|
|
+ manager.UpdateBatchData(equipments)
|
|
|
+ fmt.Printf("成功更新线路%d车站%d视图%d的电调模型数据\n", firstModel.LineID, firstModel.StationID, firstModel.ViewID)
|
|
|
+ } else {
|
|
|
+ fmt.Printf("解析设备列表失败: %v\n", err)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
type EDispatchController struct {
|
|
|
beego.Controller
|
|
|
}
|
|
|
|
|
|
// /courserun/eqpmtstatus 更新电调设备状态
|
|
|
func (c *EDispatchController) Eqpmtstatus() {
|
|
|
- var req struct {
|
|
|
- UserName string `json:"userName"`
|
|
|
- Password string `json:"password"`
|
|
|
- }
|
|
|
+ var req models.DiandiaoModel
|
|
|
+
|
|
|
requestBody := c.Ctx.Input.RequestBody
|
|
|
println("Request Body:", string(requestBody))
|
|
|
if err := json.Unmarshal(c.Ctx.Input.RequestBody, &req); err != nil {
|
|
|
@@ -35,6 +166,12 @@ func (c *EDispatchController) Eqpmtstatus() {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
+ // 获取 ElectricModelManager 单例实例
|
|
|
+ manager := models.GetInstance()
|
|
|
+
|
|
|
+ // 更新单个设备数据
|
|
|
+ manager.UpdateSingleDevice(req)
|
|
|
+
|
|
|
c.Data["json"] = map[string]interface{}{
|
|
|
"code": 200,
|
|
|
"msg": "更新电调设备状态",
|
|
|
@@ -42,11 +179,18 @@ func (c *EDispatchController) Eqpmtstatus() {
|
|
|
c.ServeJSON()
|
|
|
}
|
|
|
|
|
|
+// /courserun/add_ctrl_log 添加电调控制日志
|
|
|
// /courserun/add_ctrl_log 添加电调控制日志
|
|
|
func (c *EDispatchController) Addctrllog() {
|
|
|
var req struct {
|
|
|
- UserName string `json:"userName"`
|
|
|
- Password string `json:"password"`
|
|
|
+ CtrlType int `json:"CtrlType"`
|
|
|
+ CtrlFrom int `json:"CtrlFrom"`
|
|
|
+ CtrlUser string `json:"CtrlUser"`
|
|
|
+ Param1 string `json:"Param1"`
|
|
|
+ Param2 string `json:"Param2"`
|
|
|
+ Param3 string `json:"Param3"`
|
|
|
+ Param4 string `json:"Param4"`
|
|
|
+ Param5 string `json:"Param5"`
|
|
|
}
|
|
|
requestBody := c.Ctx.Input.RequestBody
|
|
|
println("Request Body:", string(requestBody))
|
|
|
@@ -59,6 +203,95 @@ func (c *EDispatchController) Addctrllog() {
|
|
|
c.ServeJSON()
|
|
|
return
|
|
|
}
|
|
|
+
|
|
|
+ // 获取数据库连接
|
|
|
+ o := orm.NewOrm()
|
|
|
+
|
|
|
+ // 查找当前正在运行的课程
|
|
|
+ var runningCourse models.CourseRunLog
|
|
|
+ err := o.QueryTable(new(models.CourseRunLog)).
|
|
|
+ Filter("CourseTime", 0).
|
|
|
+ OrderBy("-RunLogID").
|
|
|
+ One(&runningCourse)
|
|
|
+
|
|
|
+ if err != nil {
|
|
|
+ c.Ctx.Output.SetStatus(400)
|
|
|
+ c.Data["json"] = map[string]interface{}{
|
|
|
+ "code": 400,
|
|
|
+ "msg": "查找当前运行课程失败: " + err.Error(),
|
|
|
+ }
|
|
|
+ c.ServeJSON()
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ // 查找当前运行课程中最大的RunOperID
|
|
|
+ var maxOperLog models.CourseOperLog
|
|
|
+ var runOperID int
|
|
|
+ err = o.QueryTable(new(models.CourseOperLog)).
|
|
|
+ Filter("RunLogID", runningCourse.RunLogID).
|
|
|
+ OrderBy("-RunOperID").
|
|
|
+ One(&maxOperLog)
|
|
|
+
|
|
|
+ if err != nil && err != orm.ErrNoRows {
|
|
|
+ c.Ctx.Output.SetStatus(500)
|
|
|
+ c.Data["json"] = map[string]interface{}{
|
|
|
+ "code": 500,
|
|
|
+ "msg": "查询操作日志失败: " + err.Error(),
|
|
|
+ }
|
|
|
+ c.ServeJSON()
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ if err == orm.ErrNoRows {
|
|
|
+ // 如果没有找到记录,则从1开始
|
|
|
+ runOperID = 1
|
|
|
+ } else {
|
|
|
+ // 找到记录,则取最大值加1
|
|
|
+ runOperID = maxOperLog.RunOperID + 1
|
|
|
+ }
|
|
|
+
|
|
|
+ runDateTime, err := time.ParseInLocation("2006-01-02 15:04:05", runningCourse.RunDateTime, time.Local)
|
|
|
+ if err != nil {
|
|
|
+ c.Data["json"] = map[string]interface{}{
|
|
|
+ "code": 500,
|
|
|
+ "msg": "解析课程开始时间失败: " + err.Error(),
|
|
|
+ "runStatus": 0,
|
|
|
+ "data": nil,
|
|
|
+ }
|
|
|
+ c.ServeJSON()
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ // 计算从课程开始到现在的秒数,减去暂停累计时间
|
|
|
+ operTime := int(time.Since(runDateTime).Seconds()) - runningCourse.PauseTotalTime
|
|
|
+
|
|
|
+ // 创建操作日志记录
|
|
|
+ operLog := models.CourseOperLog{
|
|
|
+ RunLogID: runningCourse.RunLogID,
|
|
|
+ RunCourseID: runningCourse.RunCourseID,
|
|
|
+ RunOperID: runOperID,
|
|
|
+ OperName: req.CtrlUser,
|
|
|
+ OperTime: operTime,
|
|
|
+ OperScore: 0, // 默认分数为0
|
|
|
+ OperParam1: req.Param1,
|
|
|
+ OperParam2: req.Param2,
|
|
|
+ OperParam3: req.Param3,
|
|
|
+ OperParam4: req.Param4,
|
|
|
+ OperParam5: req.Param5,
|
|
|
+ }
|
|
|
+
|
|
|
+ // 插入操作日志记录到数据库
|
|
|
+ _, err = o.Insert(&operLog)
|
|
|
+ if err != nil {
|
|
|
+ c.Ctx.Output.SetStatus(500)
|
|
|
+ c.Data["json"] = map[string]interface{}{
|
|
|
+ "code": 500,
|
|
|
+ "msg": "插入操作日志失败: " + err.Error(),
|
|
|
+ }
|
|
|
+ c.ServeJSON()
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
c.Data["json"] = map[string]interface{}{
|
|
|
"code": 200,
|
|
|
"msg": "添加操作日志成功",
|
|
|
@@ -146,9 +379,159 @@ func (c *EDispatchController) SubSysStatus() {
|
|
|
|
|
|
c.ServeJSON()
|
|
|
}
|
|
|
+func (c *EDispatchController) UpdateTestStatus() {
|
|
|
+
|
|
|
+}
|
|
|
|
|
|
// /serverCtrl/alleqpmtlist 获取所有设备列表
|
|
|
func (c *EDispatchController) AllEqpmtList() {
|
|
|
+ c.Ctx.Output.Header("Access-Control-Allow-Origin", "*")
|
|
|
+ // 定义与testStatus.json文件匹配的结构体
|
|
|
+ type jsonData struct {
|
|
|
+ DataID string `json:"dataId"`
|
|
|
+ DataName string `json:"dataName"`
|
|
|
+ Value string `json:"value"`
|
|
|
+ ID string `json:"id"`
|
|
|
+ }
|
|
|
+
|
|
|
+ // 读取testStatus.json文件
|
|
|
+ filePath := "static/testStatus.json"
|
|
|
+ data, err := os.ReadFile(filePath)
|
|
|
+ if err != nil {
|
|
|
+ c.Ctx.Output.SetStatus(500)
|
|
|
+ c.Data["json"] = map[string]interface{}{
|
|
|
+ "code": 500,
|
|
|
+ "msg": "读取文件失败: " + err.Error(),
|
|
|
+ }
|
|
|
+ c.ServeJSON()
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ // 解析JSON数据
|
|
|
+ var jsonDataList []jsonData
|
|
|
+ err = json.Unmarshal(data, &jsonDataList)
|
|
|
+ if err != nil {
|
|
|
+ c.Ctx.Output.SetStatus(500)
|
|
|
+ c.Data["json"] = map[string]interface{}{
|
|
|
+ "code": 500,
|
|
|
+ "msg": "解析JSON失败: " + err.Error(),
|
|
|
+ }
|
|
|
+ c.ServeJSON()
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ // 转换为EquipmentData结构体
|
|
|
+ type EquipmentData struct {
|
|
|
+ DataID string `json:"dataId"`
|
|
|
+ DataName string `json:"dataName"`
|
|
|
+ Value string `json:"value"`
|
|
|
+ ID string `json:"id"`
|
|
|
+ }
|
|
|
+ //动态生成值 1-3改变
|
|
|
+
|
|
|
+ // 初始化随机数种子
|
|
|
+ rand.Seed(time.Now().UnixNano())
|
|
|
+
|
|
|
+ // 生成1-3之间的随机数
|
|
|
+ nValue := rand.Intn(3) + 1
|
|
|
+
|
|
|
+ var equipmentDataList []EquipmentData
|
|
|
+ for _, item := range jsonDataList {
|
|
|
+ equipment := EquipmentData{
|
|
|
+ DataID: item.DataID,
|
|
|
+ DataName: item.DataName,
|
|
|
+ Value: fmt.Sprintf("%d", nValue),
|
|
|
+ ID: item.ID,
|
|
|
+ }
|
|
|
+ equipmentDataList = append(equipmentDataList, equipment)
|
|
|
+ }
|
|
|
+
|
|
|
+ // 返回结果
|
|
|
+ c.Data["json"] = equipmentDataList
|
|
|
+ c.ServeJSON()
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+// /serverCtrl/alleqpmtlist 获取所有设备列表
|
|
|
+func (c *EDispatchController) AllEqpmtList2() {
|
|
|
+ c.Ctx.Output.Header("Access-Control-Allow-Origin", "*")
|
|
|
+ // 定义与testStatus.json文件匹配的结构体
|
|
|
+ type jsonData struct {
|
|
|
+ DataID string `json:"dataId"`
|
|
|
+ DataName string `json:"dataName"`
|
|
|
+ Value string `json:"value"`
|
|
|
+ ID string `json:"id"`
|
|
|
+ }
|
|
|
+
|
|
|
+ // 读取testStatus.json文件
|
|
|
+ filePath := "static/testStatus.json"
|
|
|
+ data, err := os.ReadFile(filePath)
|
|
|
+ if err != nil {
|
|
|
+ c.Ctx.Output.SetStatus(500)
|
|
|
+ c.Data["json"] = map[string]interface{}{
|
|
|
+ "code": 500,
|
|
|
+ "msg": "读取文件失败: " + err.Error(),
|
|
|
+ }
|
|
|
+ c.ServeJSON()
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ // 解析JSON数据
|
|
|
+ var jsonDataList []jsonData
|
|
|
+ err = json.Unmarshal(data, &jsonDataList)
|
|
|
+ if err != nil {
|
|
|
+ c.Ctx.Output.SetStatus(500)
|
|
|
+ c.Data["json"] = map[string]interface{}{
|
|
|
+ "code": 500,
|
|
|
+ "msg": "解析JSON失败: " + err.Error(),
|
|
|
+ }
|
|
|
+ c.ServeJSON()
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ // 转换为EquipmentData结构体
|
|
|
+ type EquipmentData struct {
|
|
|
+ DataID string `json:"dataId"`
|
|
|
+ DataName string `json:"dataName"`
|
|
|
+ Value string `json:"value"`
|
|
|
+ ID string `json:"id"`
|
|
|
+ }
|
|
|
+ //动态生成值 1-3改变
|
|
|
+
|
|
|
+ // 初始化随机数种子
|
|
|
+ rand.Seed(time.Now().UnixNano())
|
|
|
+
|
|
|
+ // 生成1-3之间的随机数
|
|
|
+ nValue := rand.Intn(3) + 1
|
|
|
+
|
|
|
+ var equipmentDataList []EquipmentData
|
|
|
+ for _, item := range jsonDataList {
|
|
|
+ equipment := EquipmentData{
|
|
|
+ DataID: item.DataID,
|
|
|
+ DataName: item.DataName,
|
|
|
+ Value: fmt.Sprintf("%d", nValue),
|
|
|
+ ID: item.ID,
|
|
|
+ }
|
|
|
+ equipmentDataList = append(equipmentDataList, equipment)
|
|
|
+ }
|
|
|
+
|
|
|
+ // 返回结果
|
|
|
+ c.Data["json"] = equipmentDataList
|
|
|
+ c.ServeJSON()
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+// /serverCtrl/alleqpmtlist 获取所有设备列表
|
|
|
+func (c *EDispatchController) AllEqpmtList_bak() {
|
|
|
+ c.Ctx.Output.Header("Access-Control-Allow-Origin", "*")
|
|
|
+ // 转换缓存数据为指定格式
|
|
|
+ type EquipmentData struct {
|
|
|
+ DataID string `json:"dataId"`
|
|
|
+ DataName string `json:"dataName"`
|
|
|
+ Value string `json:"value"`
|
|
|
+ ID string `json:"id"`
|
|
|
+ }
|
|
|
+
|
|
|
// 从配置文件读取电调服务IP和端口
|
|
|
electricalIP, err := beego.AppConfig.String("ElectricalIP")
|
|
|
if err != nil {
|
|
|
@@ -212,6 +595,44 @@ func (c *EDispatchController) AllEqpmtList() {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ // 生成请求key
|
|
|
+ model := models.DiandiaoModel{
|
|
|
+ LineID: lineID,
|
|
|
+ StationID: 0,
|
|
|
+ ViewID: 0,
|
|
|
+ }
|
|
|
+ key := model.GenerateModelKey()
|
|
|
+
|
|
|
+ // 获取 ElectricModelManager 单例实例
|
|
|
+ manager := models.GetInstance()
|
|
|
+
|
|
|
+ // 检查缓存中是否存在对应key的数据,且最后更新时间在5秒内
|
|
|
+ if viewMapModel, exists := manager.GetModelByKey(key); exists {
|
|
|
+ // 检查最后总包更新时间是否在5秒内
|
|
|
+ if time.Since(viewMapModel.LastBatchUpdate) <= 5*time.Second || time.Since(viewMapModel.LastDeviceUpdate) <= 5*time.Second {
|
|
|
+
|
|
|
+ var equipmentsData []EquipmentData
|
|
|
+ for _, model := range viewMapModel.Models {
|
|
|
+ equip := EquipmentData{
|
|
|
+ DataID: model.EqpmtID,
|
|
|
+ ID: model.EqpmtID,
|
|
|
+ Value: fmt.Sprintf("%d", model.Status),
|
|
|
+ DataName: model.StatusName,
|
|
|
+ }
|
|
|
+ equipmentsData = append(equipmentsData, equip)
|
|
|
+ }
|
|
|
+
|
|
|
+ // 使用缓存数据
|
|
|
+ c.Data["json"] = map[string]interface{}{
|
|
|
+ "code": 200,
|
|
|
+ "msg": "获取所有设备列表成功(缓存)",
|
|
|
+ "data": equipmentsData,
|
|
|
+ }
|
|
|
+ c.ServeJSON()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
// 准备请求数据
|
|
|
type RequestData struct {
|
|
|
LineID int `json:"lineID"`
|
|
|
@@ -281,21 +702,47 @@ func (c *EDispatchController) AllEqpmtList() {
|
|
|
} else {
|
|
|
// 如果是JSON格式,检查是否有data字段
|
|
|
if data, exists := result["data"]; exists {
|
|
|
- // 如果电调返回的数据中有data字段,直接使用它
|
|
|
+ // 解析data中的设备列表并更新到模型管理器
|
|
|
+ var equipments []models.DiandiaoModel
|
|
|
+ if equipBytes, err := json.Marshal(data); err == nil {
|
|
|
+ if err := json.Unmarshal(equipBytes, &equipments); err == nil {
|
|
|
+ // 更新总包设备数据
|
|
|
+ manager.UpdateBatchData(equipments)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ var equipmentsData []EquipmentData
|
|
|
+ for _, equip := range equipments {
|
|
|
+ equipmentData := EquipmentData{
|
|
|
+ DataID: equip.EqpmtID,
|
|
|
+ DataName: equip.StatusName,
|
|
|
+ Value: fmt.Sprintf("%d", equip.Status),
|
|
|
+ ID: equip.EqpmtID,
|
|
|
+ }
|
|
|
+ equipmentsData = append(equipmentsData, equipmentData)
|
|
|
+ }
|
|
|
+
|
|
|
+ // 返回响应
|
|
|
c.Data["json"] = map[string]interface{}{
|
|
|
"code": 200,
|
|
|
"msg": "获取所有设备列表成功",
|
|
|
- "data": data,
|
|
|
+ "data": equipmentsData,
|
|
|
}
|
|
|
} else {
|
|
|
// 如果没有data字段,返回整个响应
|
|
|
c.Data["json"] = map[string]interface{}{
|
|
|
- "code": 200,
|
|
|
- "msg": "获取所有设备列表成功",
|
|
|
- "data": result,
|
|
|
+ "code": 500,
|
|
|
+ "msg": "获取所有设备列表失败",
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
c.ServeJSON()
|
|
|
}
|
|
|
+
|
|
|
+func (c *EDispatchController) Options() {
|
|
|
+ c.Ctx.Output.Header("Access-Control-Allow-Origin", "*")
|
|
|
+ c.Ctx.Output.Header("Access-Control-Allow-Methods", "GET,POST,PUT,DELETE,OPTIONS")
|
|
|
+ c.Ctx.Output.Header("Access-Control-Allow-Headers", "Content-Type,Authorization")
|
|
|
+ c.Ctx.ResponseWriter.WriteHeader(200)
|
|
|
+}
|