|
@@ -1,11 +1,15 @@
|
|
|
package watch
|
|
|
|
|
|
import (
|
|
|
+ "encoding/json"
|
|
|
"fmt"
|
|
|
"hongze/mysteel_watch/global"
|
|
|
"hongze/mysteel_watch/models/index"
|
|
|
+ "hongze/mysteel_watch/models"
|
|
|
"hongze/mysteel_watch/utils"
|
|
|
+ "io/ioutil"
|
|
|
"log"
|
|
|
+ "net/http"
|
|
|
"os"
|
|
|
"path/filepath"
|
|
|
"strings"
|
|
@@ -594,6 +598,92 @@ func mysteelIndexHandle(runMode, indexName, indexCode, unit, source, frequency,
|
|
|
fmt.Println("dataObj.Add() Err:" + err.Error())
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ go syncEdbDataMysteelChemical(runMode, indexCode)
|
|
|
+}
|
|
|
+
|
|
|
+func syncEdbDataMysteelChemical(runMode, indexCode string) {
|
|
|
+ indexObj := new(models.EdbInfo)
|
|
|
+ var isAdd int
|
|
|
+ item, err := indexObj.GetEdbInfoItem(runMode, indexCode)
|
|
|
+ if err != nil {
|
|
|
+ if err.Error() == "record not found" {
|
|
|
+ isAdd = 1
|
|
|
+ } else {
|
|
|
+ isAdd = -1
|
|
|
+ fmt.Println("GetEdbInfoItem Err:" + err.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if item != nil && item.EdbInfoId > 0 {
|
|
|
+ fmt.Println("item:", item)
|
|
|
+ isAdd = 2
|
|
|
+ } else {
|
|
|
+ isAdd = 1 //
|
|
|
+ }
|
|
|
+
|
|
|
+ if isAdd == 1 { //新增
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ param := make(map[string]interface{})
|
|
|
+ param["EdbCode"] = indexCode
|
|
|
+ param["EdbInfoId"] = item.EdbInfoId
|
|
|
+ param["StartDate"] = item.EndDate
|
|
|
+ postRefreshEdbData(param)
|
|
|
+}
|
|
|
+
|
|
|
+type BaseResponse struct {
|
|
|
+ Ret int
|
|
|
+ Msg string
|
|
|
+ ErrMsg string
|
|
|
+ ErrCode string
|
|
|
+ Data interface{}
|
|
|
+ Success bool `description:"true 执行成功,false 执行失败"`
|
|
|
+ IsSendEmail bool `json:"-" description:"true 发送邮件,false 不发送邮件"`
|
|
|
+ IsAddLog bool `json:"-" description:"true 新增操作日志,false 不新增操作日志" `
|
|
|
+}
|
|
|
+
|
|
|
+// postRefreshEdbData 刷新指标数据
|
|
|
+func postRefreshEdbData(param map[string]interface{}) (resp *BaseResponse, err error) {
|
|
|
+ urlStr := "mysteel_chemical/refresh"
|
|
|
+ EDB_LIB_URL := "http://47.102.213.75:8300/edbapi/"
|
|
|
+
|
|
|
+ postUrl := EDB_LIB_URL + urlStr
|
|
|
+ postData, err := json.Marshal(param)
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ result, err := HttpPost(postUrl, string(postData), "application/json")
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ global.LOG.Info(" Refresh Result: " + string(result))
|
|
|
+ err = json.Unmarshal(result, &resp)
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ return resp, nil
|
|
|
+}
|
|
|
+
|
|
|
+func HttpPost(url, postData string, params ...string) ([]byte, error) {
|
|
|
+ body := ioutil.NopCloser(strings.NewReader(postData))
|
|
|
+ client := &http.Client{}
|
|
|
+ req, err := http.NewRequest("POST", url, body)
|
|
|
+ if err != nil {
|
|
|
+ return nil, err
|
|
|
+ }
|
|
|
+ contentType := "application/x-www-form-urlencoded;charset=utf-8"
|
|
|
+ if len(params) > 0 && params[0] != "" {
|
|
|
+ contentType = params[0]
|
|
|
+ }
|
|
|
+ req.Header.Set("Content-Type", contentType)
|
|
|
+ req.Header.Set("authorization", utils.MD5(utils.APP_EDB_LIB_NAME_EN+utils.EDB_LIB_Md5_KEY))
|
|
|
+ resp, err := client.Do(req)
|
|
|
+ defer resp.Body.Close()
|
|
|
+ b, err := ioutil.ReadAll(resp.Body)
|
|
|
+ fmt.Println("HttpPost:" + string(b))
|
|
|
+ return b, err
|
|
|
}
|
|
|
|
|
|
/*
|