|
@@ -24,15 +24,36 @@ type EdbDataPython struct {
|
|
|
}
|
|
|
|
|
|
// AddPythonEdb 新增python运算指标
|
|
|
-func AddPythonEdb(edbInfoId int, edbCode string, item services.EdbDataFromPython) (err error) {
|
|
|
+func AddPythonEdb(edbInfoId int, edbCode string, item services.EdbDataFromPython, edbInfoList []*EdbInfo) (err error) {
|
|
|
var errMsg string
|
|
|
o := orm.NewOrm()
|
|
|
defer func() {
|
|
|
if err != nil {
|
|
|
- go utils.SendEmail(utils.APP_NAME_CN+"【"+utils.RunMode+"】"+"失败提醒", " 同花顺数据获取失败:err:"+errMsg, utils.EmailSendToUsers)
|
|
|
+ go utils.SendEmail(utils.APP_NAME_CN+"【"+utils.RunMode+"】"+"失败提醒", " python代码运算数据获取失败:err:"+errMsg, utils.EmailSendToUsers)
|
|
|
}
|
|
|
}()
|
|
|
|
|
|
+ //添加指标关系
|
|
|
+ for _, tmpEdbInfo := range edbInfoList {
|
|
|
+ calculateMappingItem := new(EdbInfoCalculateMapping)
|
|
|
+ calculateMappingItem.CreateTime = time.Now()
|
|
|
+ calculateMappingItem.ModifyTime = time.Now()
|
|
|
+ calculateMappingItem.Sort = 1
|
|
|
+ calculateMappingItem.EdbCode = edbCode
|
|
|
+ calculateMappingItem.EdbInfoId = edbInfoId
|
|
|
+ calculateMappingItem.FromEdbInfoId = tmpEdbInfo.EdbInfoId
|
|
|
+ calculateMappingItem.FromEdbCode = tmpEdbInfo.EdbCode
|
|
|
+ calculateMappingItem.FromEdbName = tmpEdbInfo.EdbName
|
|
|
+ calculateMappingItem.FromSource = tmpEdbInfo.Source
|
|
|
+ calculateMappingItem.FromSourceName = tmpEdbInfo.SourceName
|
|
|
+ calculateMappingItem.Source = tmpEdbInfo.Source
|
|
|
+ calculateMappingItem.SourceName = tmpEdbInfo.SourceName
|
|
|
+ _, err = o.Insert(calculateMappingItem)
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
var isAdd bool
|
|
|
addSql := ` INSERT INTO edb_data_python (edb_info_id,edb_code,data_time,value,create_time,modify_time,data_timestamp) values `
|
|
|
for k, dateTimeStr := range item.Date {
|
|
@@ -225,6 +246,63 @@ func RefreshAllPythonEdb(edbInfo *EdbInfo, item services.EdbDataFromPython) (err
|
|
|
return
|
|
|
}
|
|
|
|
|
|
+// EditEdbInfoCalculateMapping 更新关联关系表
|
|
|
+func EditEdbInfoCalculateMapping(edbInfoId int, edbCode string, edbInfoList []*EdbInfo) (err error) {
|
|
|
+ o := orm.NewOrm()
|
|
|
+
|
|
|
+ var existCondition string
|
|
|
+ var existPars []interface{}
|
|
|
+ existCondition += " AND edb_info_id=? "
|
|
|
+ existPars = append(existPars, edbInfoId)
|
|
|
+
|
|
|
+ //查询出所有的关联指标
|
|
|
+ existList, err := GetEdbInfoCalculateListByCondition(existCondition, existPars)
|
|
|
+ if err != nil {
|
|
|
+ err = fmt.Errorf("判断指标是否改变失败,Err:" + err.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ existEdbInfoIdMap := make(map[int]int)
|
|
|
+ for _, v := range existList {
|
|
|
+ existEdbInfoIdMap[v.FromEdbInfoId] = v.FromEdbInfoId
|
|
|
+ }
|
|
|
+ //添加指标关系
|
|
|
+ for _, tmpEdbInfo := range edbInfoList {
|
|
|
+ if _, ok := existEdbInfoIdMap[tmpEdbInfo.EdbInfoId]; ok {
|
|
|
+ //如果存在,那么就移除map里面的东西
|
|
|
+ delete(existEdbInfoIdMap, tmpEdbInfo.EdbInfoId)
|
|
|
+ } else {
|
|
|
+ calculateMappingItem := new(EdbInfoCalculateMapping)
|
|
|
+ calculateMappingItem.CreateTime = time.Now()
|
|
|
+ calculateMappingItem.ModifyTime = time.Now()
|
|
|
+ calculateMappingItem.Sort = 1
|
|
|
+ calculateMappingItem.EdbCode = edbCode
|
|
|
+ calculateMappingItem.EdbInfoId = edbInfoId
|
|
|
+ calculateMappingItem.FromEdbInfoId = tmpEdbInfo.EdbInfoId
|
|
|
+ calculateMappingItem.FromEdbCode = tmpEdbInfo.EdbCode
|
|
|
+ calculateMappingItem.FromEdbName = tmpEdbInfo.EdbName
|
|
|
+ calculateMappingItem.FromSource = tmpEdbInfo.Source
|
|
|
+ calculateMappingItem.FromSourceName = tmpEdbInfo.SourceName
|
|
|
+ calculateMappingItem.Source = tmpEdbInfo.Source
|
|
|
+ calculateMappingItem.SourceName = tmpEdbInfo.SourceName
|
|
|
+ _, err = o.Insert(calculateMappingItem)
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ for _, v := range existEdbInfoIdMap {
|
|
|
+ //删除,计算指标关联的,基础指标的关联关系
|
|
|
+ sql := ` DELETE FROM edb_info_calculate_mapping WHERE edb_info_id = ? and from_edb_info_id=?`
|
|
|
+ _, err = o.Raw(sql, edbInfoId, v).Exec()
|
|
|
+ if err != nil {
|
|
|
+ err = errors.New("删除计算指标关联关系失败,Err:" + err.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
// GetAllEdbDataPythonByEdbInfoId 根据指标id获取全部的数据
|
|
|
func GetAllEdbDataPythonByEdbInfoId(edbInfoId int) (items []*EdbDataPython, err error) {
|
|
|
o := orm.NewOrm()
|
|
@@ -264,3 +342,45 @@ type AddPythonEdbReq struct {
|
|
|
ClassifyId int `description:"分类id"`
|
|
|
PythonCode string `description:"python代码"`
|
|
|
}
|
|
|
+
|
|
|
+// AnalysisPythonCode 解析Python代码,获取关联code
|
|
|
+func AnalysisPythonCode(pythonCode, edbName string) (edbInfoList []*EdbInfo) {
|
|
|
+ tmpEdbCodeList := make([]string, 0) //临时指标code
|
|
|
+ edbCodeLen := 0 //指标数
|
|
|
+
|
|
|
+ tmpList := strings.Split(pythonCode, "\n")
|
|
|
+ for _, v := range tmpList {
|
|
|
+ if strings.Contains(v, "edb_code") {
|
|
|
+ edbCodeLen++
|
|
|
+ tmpCodeStrList := strings.Split(v, "edb_code")
|
|
|
+ if len(tmpCodeStrList) > 1 {
|
|
|
+ //根据单引号获取
|
|
|
+ tmpCodeStrList2 := strings.Split(tmpCodeStrList[1], "'")
|
|
|
+ if len(tmpCodeStrList2) > 1 {
|
|
|
+ if tmpCodeStrList2[1] != "" {
|
|
|
+ tmpEdbCodeList = append(tmpEdbCodeList, tmpCodeStrList2[1])
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //根据双引号获取
|
|
|
+ tmpCodeStrList3 := strings.Split(tmpCodeStrList[1], `"`)
|
|
|
+ if len(tmpCodeStrList3) > 1 {
|
|
|
+ if tmpCodeStrList3[1] != "" {
|
|
|
+ tmpEdbCodeList = append(tmpEdbCodeList, tmpCodeStrList3[1])
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ for _, v := range tmpEdbCodeList {
|
|
|
+ fmt.Println(v)
|
|
|
+ item, _ := GetEdbInfoOnlyByEdbCode(v)
|
|
|
+ if item != nil {
|
|
|
+ edbInfoList = append(edbInfoList, item)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if len(edbInfoList) != edbCodeLen {
|
|
|
+ //code匹配失败,需要短信提醒
|
|
|
+ go utils.SendEmail(utils.APP_NAME_CN+"%s【"+utils.RunMode+"】"+"失败提醒", fmt.Sprintf("python代码关联指标匹配失败,指标名称:%s;实际关联%d个,匹配上%d个", edbName, edbCodeLen, len(edbInfoList)), utils.EmailSendToUsers)
|
|
|
+ }
|
|
|
+ return
|
|
|
+}
|