|
@@ -6,6 +6,7 @@ import (
|
|
|
"eta/eta_index_lib/services/alarm_msg"
|
|
|
"eta/eta_index_lib/utils"
|
|
|
"fmt"
|
|
|
+ "strconv"
|
|
|
"strings"
|
|
|
"time"
|
|
|
)
|
|
@@ -20,12 +21,24 @@ func HandleYongyiIndex(req *models.HandleYongyiExcelDataReq) (err error) {
|
|
|
go alarm_msg.SendAlarmMsg(msg, 3)
|
|
|
}
|
|
|
}()
|
|
|
+ // 查询所有的一级分类
|
|
|
+ classifyObj := new(models.BaseFromYongyiClassify)
|
|
|
+ classifyList, err := classifyObj.GetParentClassify()
|
|
|
+ if err != nil {
|
|
|
+ err = fmt.Errorf("查询一级目录信息失败 Err:%s", err)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ classifyMap := make(map[string]int, 0)
|
|
|
+ for _, v := range classifyList {
|
|
|
+ classifyMap[v.ClassifyName] = int(v.ClassifyId)
|
|
|
+ }
|
|
|
+
|
|
|
for _, v := range req.List {
|
|
|
if v.IndexName == "" || v.IndexCode == "" {
|
|
|
errMsgList = append(errMsgList, fmt.Sprintf("新增指标异常,指标编码%s或者指标ID%s为空:", v.IndexCode, v.IndexName))
|
|
|
continue
|
|
|
}
|
|
|
- err = handleYongyiIndex(v, req.TerminalCode)
|
|
|
+ err = handleYongyiIndex(v, req.TerminalCode, classifyMap)
|
|
|
if err != nil {
|
|
|
errMsgList = append(errMsgList, fmt.Sprintf("新增指标异常,指标编码:%s, Err: %s", v.IndexCode, err))
|
|
|
return
|
|
@@ -34,7 +47,7 @@ func HandleYongyiIndex(req *models.HandleYongyiExcelDataReq) (err error) {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
-func handleYongyiIndex(req *models.HandleYongyiExcelData, terminalCode string) (err error) {
|
|
|
+func handleYongyiIndex(req *models.HandleYongyiExcelData, terminalCode string, classifyMap map[string]int) (err error) {
|
|
|
indexName := req.IndexName
|
|
|
indexCode := req.IndexCode
|
|
|
excelDataMap := req.ExcelDataMap
|
|
@@ -65,13 +78,15 @@ func handleYongyiIndex(req *models.HandleYongyiExcelData, terminalCode string) (
|
|
|
var classifyId int64
|
|
|
now := time.Now()
|
|
|
if req.ClassifyName != "" {
|
|
|
+ classifyParentId := 0
|
|
|
+ classifyParentId, _ = classifyMap[req.Frequency]
|
|
|
classifyObj, err = classifyObj.GetByClassifyName(req.ClassifyName)
|
|
|
if err != nil {
|
|
|
if err.Error() == utils.ErrNoRow() {
|
|
|
//新增分类
|
|
|
classifyObj = &models.BaseFromYongyiClassify{
|
|
|
ClassifyName: req.ClassifyName,
|
|
|
- ParentId: 0,
|
|
|
+ ParentId: classifyParentId,
|
|
|
SysUserId: 0,
|
|
|
SysUserRealName: "",
|
|
|
Level: 1,
|
|
@@ -91,6 +106,14 @@ func handleYongyiIndex(req *models.HandleYongyiExcelData, terminalCode string) (
|
|
|
}
|
|
|
} else {
|
|
|
classifyId = classifyObj.ClassifyId
|
|
|
+ classifyObj.ModifyTime = now
|
|
|
+ classifyObj.Sort = req.ClassifySort
|
|
|
+ classifyObj.ParentId = classifyParentId
|
|
|
+ e := classifyObj.Update([]string{"ParentId", "Sort", "ModifyTime"})
|
|
|
+ if e != nil {
|
|
|
+ fmt.Println("classifyObj Update Err:" + e.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -131,6 +154,7 @@ func handleYongyiIndex(req *models.HandleYongyiExcelData, terminalCode string) (
|
|
|
}
|
|
|
indexObj.YongyiIndexId = indexId
|
|
|
} else if isAdd == 2 {
|
|
|
+ indexId = item.YongyiIndexId
|
|
|
if item.TerminalCode == `` && terminalCode != `` {
|
|
|
item.TerminalCode = terminalCode
|
|
|
err = item.Update([]string{"TerminalCode"})
|
|
@@ -176,7 +200,6 @@ func handleYongyiIndex(req *models.HandleYongyiExcelData, terminalCode string) (
|
|
|
dateStr := v.DataTime
|
|
|
exitDataMap[dateStr] = v
|
|
|
}
|
|
|
- indexId = item.YongyiIndexId
|
|
|
|
|
|
// 遍历excel数据,然后跟现有的数据做校验,不存在则入库
|
|
|
for date, value := range excelDataMap {
|
|
@@ -208,9 +231,23 @@ func handleYongyiIndex(req *models.HandleYongyiExcelData, terminalCode string) (
|
|
|
dataItem.ModifyTime = time.Now()
|
|
|
dataItem.DataTimestamp = timestamp
|
|
|
addDataList = append(addDataList, dataItem)
|
|
|
+ if len(addDataList) > 500 {
|
|
|
+ err = dataObj.AddMulti(addDataList)
|
|
|
+ if err != nil {
|
|
|
+ err = fmt.Errorf("批量新增指标失败 Err:%s", err)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ addDataList = make([]*models.BaseFromYongyiData, 0)
|
|
|
+ }
|
|
|
}
|
|
|
} else {
|
|
|
if findData != nil && findData.Value != value && !strings.Contains(value, "#N/A") { //修改数据
|
|
|
+ // 过滤0.50和0.5的比较
|
|
|
+ oldV, _ := strconv.ParseFloat(findData.Value, 64)
|
|
|
+ newV, _ := strconv.ParseFloat(value, 64)
|
|
|
+ if oldV == newV {
|
|
|
+ continue
|
|
|
+ }
|
|
|
dataObj.YongyiDataId = findData.YongyiDataId
|
|
|
dataObj.Value = value
|
|
|
dataObj.ModifyTime = time.Now()
|