@ -1,11 +1,18 @@
package DataexDAO
import (
"dsDataex/GenXorm/models"
"dsDataex/MyService/MySwagger"
"dsDataex/Utils/CacheUtil"
"dsDataex/Utils/DbUtil"
"dsDataex/Utils/ErrorConst"
"dsDataex/Utils/LogUtil"
"encoding/json"
"fmt"
uuid "github.com/satori/go.uuid"
"html"
"strings"
"time"
)
//数据库
@ -256,9 +263,55 @@ func CheckConsumeOrgID(consumeType int, consumeOrgid string,orgID string) (bool,
return false , "数据权限校验不通过,无权访问此机构下属数据" , nil
}
func SaveDataError ( fails [ ] MySwagger . FailResult , esData string ) ( bool , string , error ) {
func SaveDataError ( fails [ ] MySwagger . FailResult , datas [ ] MySwagg er. Data , Sy stemId string , DatasourceId string ) ( bool , string , error ) {
error := new ( models . TDataexError )
error . Id = strings . ToLower ( uuid . NewV4 ( ) . String ( ) )
for no := 0 ; no < len ( datas ) ; no ++ {
if datas [ no ] . DataID == fails [ 0 ] . FailID {
error . SystemId = SystemId
error . DatasourceId = DatasourceId
error . OrgId = datas [ no ] . OrgID
error . DataId = datas [ no ] . DataID
bytes , _ := json . Marshal ( datas [ no ] . Data )
error . DataContent = string ( bytes )
}
}
error . ErrorInfo = fails [ 0 ] . FailReason
var createTime = time . Now ( )
error . CreateTime = createTime
error . DeleteFlag = - 1
error . EnableFlag = 1
_ , err := db . Insert ( error )
fmt . Println ( "[DataexDAO] ES Error :" , fails [ 0 ] . FailReason )
if err != nil {
fmt . Println ( "[DataexDAO] MySQL Error :" , err )
LogUtil . Error ( ErrorConst . SqlUpdateError , "SaveDataError, 数据库操作发生严重错误: " + err . Error ( ) )
}
if len ( fails ) > 1 {
var sqls [ ] string
var sql string
for no := 1 ; no < len ( fails ) ; no ++ {
sql = "insert into t_dataex_error (id,system_id,datasource_id,create_time,delete_flag,enable_flag) values ('" + strings . ToLower ( uuid . NewV4 ( ) . String ( ) ) + "','" + SystemId + "','" + DatasourceId + "','" + createTime . Format ( "2006-01-02 15:04:05" ) + "',-1,1)"
sqls = append ( sqls , sql )
}
DbUtil . Engine . Sqls ( sqls ) . Execute ( )
}
return true , "数据添加成功" , nil
}