|
@@ -0,0 +1,1106 @@
|
|
|
+package services
|
|
|
+//
|
|
|
+//import (
|
|
|
+// "encoding/json"
|
|
|
+// "fmt"
|
|
|
+// "hongze/hongtao3_watch/global"
|
|
|
+// "hongze/hongtao3_watch/models/index"
|
|
|
+// "hongze/hongtao3_watch/utils"
|
|
|
+// "strconv"
|
|
|
+// "strings"
|
|
|
+// "sync"
|
|
|
+// "time"
|
|
|
+//
|
|
|
+// "github.com/rdlucklib/rdluck_tools/paging"
|
|
|
+// "github.com/xuri/excelize/v2"
|
|
|
+//)
|
|
|
+//
|
|
|
+//// Merge 合并指标
|
|
|
+//func Merge() {
|
|
|
+// fmt.Println("merge start")
|
|
|
+// /*
|
|
|
+// 年底,季度,存放在一个excel中
|
|
|
+// 月度30个指标存一个excel
|
|
|
+// 周度25个指标存放一个excel
|
|
|
+// 日度20个指标存一个excel
|
|
|
+// */
|
|
|
+// //年度->38
|
|
|
+// IndexYearMerge()
|
|
|
+// //季度->5
|
|
|
+// IndexSeasonMerge()
|
|
|
+// //月度->86
|
|
|
+// IndexMonthMerge()
|
|
|
+// //周度->292
|
|
|
+// IndexWeekMerge()
|
|
|
+// //日度->114
|
|
|
+// IndexDayMerge()
|
|
|
+// //merge_file_path
|
|
|
+// fmt.Println("merge end")
|
|
|
+//}
|
|
|
+//
|
|
|
+////年度
|
|
|
+//func IndexYearMerge() {
|
|
|
+// frequency := "年度"
|
|
|
+// fileName := "year" + ".xlsx" //保存的文件名称
|
|
|
+// yearIndexFilePath := utils.IndexMsergeSaveDir + fileName
|
|
|
+//
|
|
|
+// var err error
|
|
|
+//
|
|
|
+// indexObj := new(index.BaseFromMysteelChemicalIndex)
|
|
|
+// yearList, err := indexObj.GetIndexByFrequency(frequency)
|
|
|
+// if err != nil {
|
|
|
+// fmt.Println("GetIndexByFrequency Err:" + err.Error())
|
|
|
+// return
|
|
|
+// }
|
|
|
+//
|
|
|
+// if len(yearList) <= 0 {
|
|
|
+// return
|
|
|
+// }
|
|
|
+//
|
|
|
+// commentResult, err := GetIndexComment(yearIndexFilePath, yearList, 1)
|
|
|
+// if err != nil {
|
|
|
+// fmt.Println("GetIndexComment Err:" + err.Error())
|
|
|
+// return
|
|
|
+// }
|
|
|
+// if utils.FileIsExist(yearIndexFilePath) { //修改文件
|
|
|
+// fileObj, err := excelize.OpenFile(yearIndexFilePath)
|
|
|
+// if err != nil {
|
|
|
+// fmt.Println("打开文件失败,Err:" + err.Error())
|
|
|
+// return
|
|
|
+// }
|
|
|
+//
|
|
|
+// fileObj.DeleteComment("Sheet1", "A1")
|
|
|
+// fileObj.AddComment("Sheet1", "A1", commentResult)
|
|
|
+// if err := fileObj.SaveAs(yearIndexFilePath); err != nil {
|
|
|
+// fmt.Println("保存失败,Err:" + err.Error())
|
|
|
+// fileObj.Close()
|
|
|
+// return
|
|
|
+// }
|
|
|
+// fileObj.Close()
|
|
|
+// } else { //新增文件
|
|
|
+// templatePath := utils.IndexSaveDir + "index_template.xlsx"
|
|
|
+// templateFile, err := excelize.OpenFile(templatePath)
|
|
|
+// if err != nil {
|
|
|
+// fmt.Println("打开文件失败,Err:" + err.Error())
|
|
|
+// return
|
|
|
+// }
|
|
|
+// templateFile.DeleteComment("Sheet1", "A1")
|
|
|
+// templateFile.AddComment("Sheet1", "A1", commentResult)
|
|
|
+// if err := templateFile.SaveAs(yearIndexFilePath); err != nil {
|
|
|
+// fmt.Println("保存失败,Err:" + err.Error())
|
|
|
+// templateFile.Close()
|
|
|
+// return
|
|
|
+// }
|
|
|
+// templateFile.Close()
|
|
|
+// }
|
|
|
+// //刷新数据
|
|
|
+// //MysteelChemicalRefresh(yearIndexFilePath)
|
|
|
+// AddIndexRefreshToLpush(yearIndexFilePath)
|
|
|
+//}
|
|
|
+//
|
|
|
+////季度
|
|
|
+//func IndexSeasonMerge() {
|
|
|
+// frequency := "季度"
|
|
|
+// fileName := "season" + ".xlsx" //保存的文件名称
|
|
|
+// seasonIndexFilePath := utils.IndexMsergeSaveDir + fileName
|
|
|
+//
|
|
|
+// var err error
|
|
|
+//
|
|
|
+// indexObj := new(index.BaseFromMysteelChemicalIndex)
|
|
|
+// seasonList, err := indexObj.GetIndexByFrequency(frequency)
|
|
|
+// if err != nil {
|
|
|
+// fmt.Println("GetIndexByFrequency Err:" + err.Error())
|
|
|
+// return
|
|
|
+// }
|
|
|
+//
|
|
|
+// if len(seasonList) <= 0 {
|
|
|
+// return
|
|
|
+// }
|
|
|
+//
|
|
|
+// commentResult, err := GetIndexComment(seasonIndexFilePath, seasonList, 1)
|
|
|
+// if err != nil {
|
|
|
+// fmt.Println("GetIndexComment Err:" + err.Error())
|
|
|
+// return
|
|
|
+// }
|
|
|
+// if utils.FileIsExist(seasonIndexFilePath) { //修改文件
|
|
|
+// fileObj, err := excelize.OpenFile(seasonIndexFilePath)
|
|
|
+// if err != nil {
|
|
|
+// fmt.Println("打开文件失败,Err:" + err.Error())
|
|
|
+// return
|
|
|
+// }
|
|
|
+//
|
|
|
+// fileObj.DeleteComment("Sheet1", "A1")
|
|
|
+// fileObj.AddComment("Sheet1", "A1", commentResult)
|
|
|
+// if err := fileObj.SaveAs(seasonIndexFilePath); err != nil {
|
|
|
+// fmt.Println("保存失败,Err:" + err.Error())
|
|
|
+// fileObj.Close()
|
|
|
+// return
|
|
|
+// }
|
|
|
+// fileObj.Close()
|
|
|
+// } else { //新增文件
|
|
|
+// templatePath := utils.IndexSaveDir + "index_template.xlsx"
|
|
|
+// templateFile, err := excelize.OpenFile(templatePath)
|
|
|
+// if err != nil {
|
|
|
+// fmt.Println("打开文件失败,Err:" + err.Error())
|
|
|
+// return
|
|
|
+// }
|
|
|
+// templateFile.DeleteComment("Sheet1", "A1")
|
|
|
+// templateFile.AddComment("Sheet1", "A1", commentResult)
|
|
|
+// if err := templateFile.SaveAs(seasonIndexFilePath); err != nil {
|
|
|
+// fmt.Println("保存失败,Err:" + err.Error())
|
|
|
+// templateFile.Close()
|
|
|
+// return
|
|
|
+// }
|
|
|
+// templateFile.Close()
|
|
|
+// }
|
|
|
+// //刷新数据
|
|
|
+// //MysteelChemicalRefresh(seasonIndexFilePath)
|
|
|
+// AddIndexRefreshToLpush(seasonIndexFilePath)
|
|
|
+//}
|
|
|
+//
|
|
|
+////月度
|
|
|
+////func IndexMonthMerge() {
|
|
|
+//// frequency := "月度"
|
|
|
+//// filePre := "month"
|
|
|
+//// pageSize := 30
|
|
|
+//// var err error
|
|
|
+////
|
|
|
+//// indexObj := new(index.BaseFromMysteelChemicalIndex)
|
|
|
+//// total, err := indexObj.GetIndexByFrequencyCount(frequency)
|
|
|
+//// if err != nil {
|
|
|
+//// fmt.Println("GetIndexByFrequencyCount Err:" + err.Error())
|
|
|
+//// return
|
|
|
+//// }
|
|
|
+////
|
|
|
+//// maxFileIndexItem, err := indexObj.GetMaxFileIndex(frequency)
|
|
|
+//// if err != nil {
|
|
|
+//// fmt.Println("GetMaxFileIndex Err:" + err.Error())
|
|
|
+//// return
|
|
|
+//// }
|
|
|
+////
|
|
|
+//// maxFileIndex := maxFileIndexItem.FileIndex
|
|
|
+//// if maxFileIndex <= 0 {
|
|
|
+//// maxFileIndex = 1
|
|
|
+//// }
|
|
|
+////
|
|
|
+//// fileName := filePre + "_" + strconv.Itoa(maxFileIndex) + ".xlsx" //保存的文件名称
|
|
|
+//// monthIndexFilePath := utils.IndexMsergeSaveDir + fileName
|
|
|
+////
|
|
|
+//// indexTotal, err := indexObj.GetIndexCountByMergeFilePath(monthIndexFilePath)
|
|
|
+//// if err != nil {
|
|
|
+//// fmt.Println("GetIndexCountByMergeFilePath Err:" + err.Error())
|
|
|
+//// return
|
|
|
+//// }
|
|
|
+////
|
|
|
+//// if (indexTotal > int64(pageSize)/2) && maxFileIndex != 1 {
|
|
|
+//// maxFileIndex += 1
|
|
|
+//// }
|
|
|
+////
|
|
|
+//// fmt.Println("maxFileIndex:", maxFileIndex)
|
|
|
+//// totalPage := paging.PageCount(int(total), pageSize)
|
|
|
+//// fmt.Println("total:", total)
|
|
|
+//// fmt.Println("totalPage:", totalPage)
|
|
|
+//// for i := 1; i <= totalPage; i++ {
|
|
|
+////
|
|
|
+//// offset := (i - 1) * pageSize
|
|
|
+////
|
|
|
+//// fileName = filePre + "_" + strconv.Itoa(maxFileIndex) + ".xlsx" //保存的文件名称
|
|
|
+//// monthIndexFilePath := utils.IndexMsergeSaveDir + fileName
|
|
|
+//// fmt.Println(monthIndexFilePath)
|
|
|
+////
|
|
|
+//// fmt.Println(offset, pageSize)
|
|
|
+//// pageList, err := indexObj.GetIndexByFrequencyPage(frequency, offset, pageSize)
|
|
|
+//// if err != nil {
|
|
|
+//// fmt.Println("GetIndexByFrequency Err:" + err.Error())
|
|
|
+//// return
|
|
|
+//// }
|
|
|
+////
|
|
|
+//// commentResult, err := GetIndexComment(monthIndexFilePath, pageList, maxFileIndex)
|
|
|
+//// if err != nil {
|
|
|
+//// fmt.Println("GetIndexComment Err:" + err.Error())
|
|
|
+//// return
|
|
|
+//// }
|
|
|
+//// if utils.FileIsExist(monthIndexFilePath) { //修改文件
|
|
|
+//// fileObj, err := excelize.OpenFile(monthIndexFilePath)
|
|
|
+//// if err != nil {
|
|
|
+//// fmt.Println("打开文件失败,Err:" + err.Error())
|
|
|
+//// return
|
|
|
+//// }
|
|
|
+////
|
|
|
+//// fileObj.DeleteComment("Sheet1", "A1")
|
|
|
+//// fileObj.AddComment("Sheet1", "A1", commentResult)
|
|
|
+//// if err := fileObj.SaveAs(monthIndexFilePath); err != nil {
|
|
|
+//// fmt.Println("保存失败,Err:" + err.Error())
|
|
|
+//// fileObj.Close()
|
|
|
+//// return
|
|
|
+//// }
|
|
|
+//// fileObj.Close()
|
|
|
+//// } else { //新增文件
|
|
|
+//// templatePath := utils.IndexSaveDir + "index_template.xlsx"
|
|
|
+//// templateFile, err := excelize.OpenFile(templatePath)
|
|
|
+//// if err != nil {
|
|
|
+//// fmt.Println("打开文件失败,Err:" + err.Error())
|
|
|
+//// return
|
|
|
+//// }
|
|
|
+//// templateFile.DeleteComment("Sheet1", "A1")
|
|
|
+//// templateFile.AddComment("Sheet1", "A1", commentResult)
|
|
|
+//// if err := templateFile.SaveAs(monthIndexFilePath); err != nil {
|
|
|
+//// fmt.Println("保存失败,Err:" + err.Error())
|
|
|
+//// templateFile.Close()
|
|
|
+//// return
|
|
|
+//// }
|
|
|
+//// templateFile.Close()
|
|
|
+//// }
|
|
|
+//// maxFileIndex += 1
|
|
|
+//// time.Sleep(1 * time.Second)
|
|
|
+//// }
|
|
|
+////}
|
|
|
+//
|
|
|
+//func IndexMonthMerge() {
|
|
|
+// frequency := "月度"
|
|
|
+// filePre := "month"
|
|
|
+// pageSize := 30
|
|
|
+// err := indexMerge(frequency, filePre, pageSize)
|
|
|
+// if err != nil {
|
|
|
+// fmt.Println("合并月度指标失败,err:", err)
|
|
|
+// }
|
|
|
+//}
|
|
|
+//
|
|
|
+////日度
|
|
|
+////func IndexDayMerge() {
|
|
|
+//// frequency := "日度"
|
|
|
+//// filePre := "day"
|
|
|
+//// pageSize := 30
|
|
|
+//// var err error
|
|
|
+////
|
|
|
+//// indexObj := new(index.BaseFromMysteelChemicalIndex)
|
|
|
+//// total, err := indexObj.GetIndexByFrequencyCount(frequency)
|
|
|
+//// if err != nil {
|
|
|
+//// fmt.Println("GetIndexByFrequencyCount Err:" + err.Error())
|
|
|
+//// return
|
|
|
+//// }
|
|
|
+////
|
|
|
+//// maxFileIndexItem, err := indexObj.GetMaxFileIndex(frequency)
|
|
|
+//// if err != nil {
|
|
|
+//// fmt.Println("GetMaxFileIndex Err:" + err.Error())
|
|
|
+//// return
|
|
|
+//// }
|
|
|
+////
|
|
|
+//// maxFileIndex := maxFileIndexItem.FileIndex
|
|
|
+//// if maxFileIndex <= 0 {
|
|
|
+//// maxFileIndex = 1
|
|
|
+//// }
|
|
|
+////
|
|
|
+//// fileName := filePre + "_" + strconv.Itoa(maxFileIndex) + ".xlsx" //保存的文件名称
|
|
|
+//// monthIndexFilePath := utils.IndexMsergeSaveDir + fileName
|
|
|
+////
|
|
|
+//// indexTotal, err := indexObj.GetIndexCountByMergeFilePath(monthIndexFilePath)
|
|
|
+//// if err != nil {
|
|
|
+//// fmt.Println("GetIndexCountByMergeFilePath Err:" + err.Error())
|
|
|
+//// return
|
|
|
+//// }
|
|
|
+////
|
|
|
+//// if (indexTotal > int64(pageSize)/2) && maxFileIndex != 1 {
|
|
|
+//// maxFileIndex += 1
|
|
|
+//// }
|
|
|
+////
|
|
|
+//// fmt.Println("maxFileIndex:", maxFileIndex)
|
|
|
+//// totalPage := paging.PageCount(int(total), pageSize)
|
|
|
+//// fmt.Println("total:", total)
|
|
|
+//// fmt.Println("totalPage:", totalPage)
|
|
|
+//// for i := 1; i <= totalPage; i++ {
|
|
|
+////
|
|
|
+//// offset := (i - 1) * pageSize
|
|
|
+////
|
|
|
+//// fileName = filePre + "_" + strconv.Itoa(maxFileIndex) + ".xlsx" //保存的文件名称
|
|
|
+//// monthIndexFilePath := utils.IndexMsergeSaveDir + fileName
|
|
|
+//// fmt.Println(monthIndexFilePath)
|
|
|
+////
|
|
|
+//// fmt.Println(offset, pageSize)
|
|
|
+//// pageList, err := indexObj.GetIndexByFrequencyPage(frequency, offset, pageSize)
|
|
|
+//// if err != nil {
|
|
|
+//// fmt.Println("GetIndexByFrequency Err:" + err.Error())
|
|
|
+//// return
|
|
|
+//// }
|
|
|
+////
|
|
|
+//// commentResult, err := GetIndexComment(monthIndexFilePath, pageList, maxFileIndex)
|
|
|
+//// if err != nil {
|
|
|
+//// fmt.Println("GetIndexComment Err:" + err.Error())
|
|
|
+//// return
|
|
|
+//// }
|
|
|
+//// if utils.FileIsExist(monthIndexFilePath) { //修改文件
|
|
|
+//// fileObj, err := excelize.OpenFile(monthIndexFilePath)
|
|
|
+//// if err != nil {
|
|
|
+//// fmt.Println("打开文件失败,Err:" + err.Error())
|
|
|
+//// return
|
|
|
+//// }
|
|
|
+////
|
|
|
+//// fileObj.DeleteComment("Sheet1", "A1")
|
|
|
+//// fileObj.AddComment("Sheet1", "A1", commentResult)
|
|
|
+//// if err := fileObj.SaveAs(monthIndexFilePath); err != nil {
|
|
|
+//// fmt.Println("保存失败,Err:" + err.Error())
|
|
|
+//// fileObj.Close()
|
|
|
+//// return
|
|
|
+//// }
|
|
|
+//// fileObj.Close()
|
|
|
+//// } else { //新增文件
|
|
|
+//// templatePath := utils.IndexSaveDir + "index_template.xlsx"
|
|
|
+//// templateFile, err := excelize.OpenFile(templatePath)
|
|
|
+//// if err != nil {
|
|
|
+//// fmt.Println("打开文件失败,Err:" + err.Error())
|
|
|
+//// return
|
|
|
+//// }
|
|
|
+//// templateFile.DeleteComment("Sheet1", "A1")
|
|
|
+//// templateFile.AddComment("Sheet1", "A1", commentResult)
|
|
|
+//// if err := templateFile.SaveAs(monthIndexFilePath); err != nil {
|
|
|
+//// fmt.Println("保存失败,Err:" + err.Error())
|
|
|
+//// templateFile.Close()
|
|
|
+//// return
|
|
|
+//// }
|
|
|
+//// templateFile.Close()
|
|
|
+//// }
|
|
|
+//// maxFileIndex += 1
|
|
|
+//// time.Sleep(1 * time.Second)
|
|
|
+//// }
|
|
|
+////}
|
|
|
+//
|
|
|
+//// IndexDayMerge 日度指标合并
|
|
|
+//func IndexDayMerge() {
|
|
|
+// frequency := "日度"
|
|
|
+// filePre := "day"
|
|
|
+// pageSize := 30 //每个excel表需要的指标数
|
|
|
+// err := indexMerge(frequency, filePre, pageSize)
|
|
|
+// if err != nil {
|
|
|
+// fmt.Println("合并日度指标失败,err:", err)
|
|
|
+// }
|
|
|
+//}
|
|
|
+//
|
|
|
+//// IndexWeekMerge 周度指标合并
|
|
|
+//func IndexWeekMerge() {
|
|
|
+// frequency := "周度"
|
|
|
+// filePre := "week"
|
|
|
+// pageSize := 30 //每个excel表需要的指标数
|
|
|
+// err := indexMerge(frequency, filePre, pageSize)
|
|
|
+// if err != nil {
|
|
|
+// fmt.Println("合并周度指标失败,err:", err)
|
|
|
+// }
|
|
|
+//}
|
|
|
+//
|
|
|
+////func IndexWeekMerge() {
|
|
|
+//// frequency := "周度"
|
|
|
+//// filePre := "week"
|
|
|
+//// pageSize := 30 //每个excel表需要的指标数
|
|
|
+//// firstIndexCount := pageSize //第一个添加的excel表需要的指标数
|
|
|
+//// var err error
|
|
|
+////
|
|
|
+//// indexObj := new(index.BaseFromMysteelChemicalIndex)
|
|
|
+////
|
|
|
+//// // 获取未合并的指标总数量
|
|
|
+//// total, err := indexObj.GetNoMergeIndexByFrequencyCount(frequency)
|
|
|
+//// if err != nil {
|
|
|
+//// fmt.Println("GetIndexByFrequencyCount Err:" + err.Error())
|
|
|
+//// return
|
|
|
+//// }
|
|
|
+//// //未合并的指标总数量小于等于0,说明没有需要合并的指标
|
|
|
+//// if total <=0{
|
|
|
+//// return
|
|
|
+//// }
|
|
|
+////
|
|
|
+//// // 获取最大的文件编号下标
|
|
|
+//// maxFileIndexItem, err := indexObj.GetMaxFileIndex(frequency)
|
|
|
+//// if err != nil {
|
|
|
+//// fmt.Println("GetMaxFileIndex Err:" + err.Error())
|
|
|
+//// return
|
|
|
+//// }
|
|
|
+////
|
|
|
+//// maxFileIndex := maxFileIndexItem.FileIndex
|
|
|
+//// if maxFileIndex <= 0 {
|
|
|
+//// maxFileIndex = 1
|
|
|
+//// }
|
|
|
+////
|
|
|
+//// fileName := filePre + "_" + strconv.Itoa(maxFileIndex) + ".xlsx" //保存的文件名称
|
|
|
+//// maxMergeIndexFilePath := utils.IndexMsergeSaveDir + fileName
|
|
|
+////
|
|
|
+//// // 根据文件下标获取该文件下标已经存在多少的指标
|
|
|
+//// indexTotal, err := indexObj.GetIndexCountByMergeFilePath(maxMergeIndexFilePath)
|
|
|
+//// if err != nil {
|
|
|
+//// fmt.Println("GetIndexCountByMergeFilePath Err:" + err.Error())
|
|
|
+//// return
|
|
|
+//// }
|
|
|
+////
|
|
|
+//// // 如果最近的excel表的指标数量 少于 每页需要的指标数
|
|
|
+//// if int(indexTotal) < pageSize {
|
|
|
+//// // 最近的excel表的待添加指标数 = 每页需要的指标数 - 已经添加的指标
|
|
|
+//// firstIndexCount = pageSize - int(indexTotal)
|
|
|
+//// }
|
|
|
+////
|
|
|
+//// fmt.Println("maxFileIndex:", maxFileIndex)
|
|
|
+////
|
|
|
+//// // 除去第一个excel表的剩余需要添加的指标数量
|
|
|
+//// nextTotal := int(total)-firstIndexCount
|
|
|
+//// // 总文件数
|
|
|
+//// totalPage := paging.PageCount(nextTotal, pageSize)
|
|
|
+//// totalPage = totalPage+1 //需要加上除去在外面的指标(第一张excel)
|
|
|
+//// fmt.Println("total:", total)
|
|
|
+//// fmt.Println("totalPage:", totalPage)
|
|
|
+//// for i := 1; i <= totalPage; i++ {
|
|
|
+//// //offset := (i - 1) * pageSize
|
|
|
+////
|
|
|
+//// fileName = filePre + "_" + strconv.Itoa(maxFileIndex) + ".xlsx" //保存的文件名称
|
|
|
+//// mergeIndexFilePath := utils.IndexMsergeSaveDir + fileName
|
|
|
+//// fmt.Println(mergeIndexFilePath)
|
|
|
+////
|
|
|
+//// var list []*index.BaseFromMysteelChemicalIndex
|
|
|
+//// // 需要查询的指标数
|
|
|
+//// size := pageSize
|
|
|
+//// if i == 1{
|
|
|
+//// size = firstIndexCount // 第一页需要合并的新指标数
|
|
|
+////
|
|
|
+//// // 第一页需要的指标列表
|
|
|
+//// tmpList ,tmpErr := indexObj.GetIndexByFrequencyListByMergeFilePath(frequency,mergeIndexFilePath)
|
|
|
+//// if tmpErr != nil{
|
|
|
+//// fmt.Println("GetIndexByFrequencyListByMergeFilePath Err:" + err.Error())
|
|
|
+//// return
|
|
|
+//// }
|
|
|
+//// list = tmpList
|
|
|
+//// }
|
|
|
+//// fmt.Println("需要查询",size,"个指标")
|
|
|
+////
|
|
|
+//// //fmt.Println(offset, pageSize)
|
|
|
+////
|
|
|
+//// // 当下需要合并到excel的指标
|
|
|
+//// pageList, err := indexObj.GetNoMergeIndexByFrequencyPage(frequency, size)
|
|
|
+//// if err != nil {
|
|
|
+//// fmt.Println("GetIndexByFrequency Err:" + err.Error())
|
|
|
+//// return
|
|
|
+//// }
|
|
|
+////
|
|
|
+//// if len(list)>0{
|
|
|
+//// pageList = append(pageList,list...)
|
|
|
+//// }
|
|
|
+////
|
|
|
+//// commentResult, err := GetIndexComment(mergeIndexFilePath, pageList, maxFileIndex)
|
|
|
+//// if err != nil {
|
|
|
+//// fmt.Println("GetIndexComment Err:" + err.Error())
|
|
|
+//// return
|
|
|
+//// }
|
|
|
+//// if utils.FileIsExist(mergeIndexFilePath) { //修改文件
|
|
|
+//// fileObj, err := excelize.OpenFile(mergeIndexFilePath)
|
|
|
+//// if err != nil {
|
|
|
+//// fmt.Println("打开文件失败,Err:" + err.Error())
|
|
|
+//// return
|
|
|
+//// }
|
|
|
+////
|
|
|
+//// fileObj.DeleteComment("Sheet1", "A1")
|
|
|
+//// fileObj.AddComment("Sheet1", "A1", commentResult)
|
|
|
+//// if err := fileObj.SaveAs(mergeIndexFilePath); err != nil {
|
|
|
+//// fmt.Println("保存失败,Err:" + err.Error())
|
|
|
+//// fileObj.Close()
|
|
|
+//// return
|
|
|
+//// }
|
|
|
+//// fileObj.Close()
|
|
|
+//// } else { //新增文件
|
|
|
+//// templatePath := utils.IndexSaveDir + "index_template.xlsx"
|
|
|
+//// templateFile, err := excelize.OpenFile(templatePath)
|
|
|
+//// if err != nil {
|
|
|
+//// fmt.Println("打开文件失败,Err:" + err.Error())
|
|
|
+//// return
|
|
|
+//// }
|
|
|
+//// templateFile.DeleteComment("Sheet1", "A1")
|
|
|
+//// templateFile.AddComment("Sheet1", "A1", commentResult)
|
|
|
+//// if err := templateFile.SaveAs(mergeIndexFilePath); err != nil {
|
|
|
+//// fmt.Println("保存失败,Err:" + err.Error())
|
|
|
+//// templateFile.Close()
|
|
|
+//// return
|
|
|
+//// }
|
|
|
+//// templateFile.Close()
|
|
|
+//// }
|
|
|
+//// maxFileIndex += 1
|
|
|
+//// time.Sleep(1 * time.Second)
|
|
|
+//// }
|
|
|
+////}
|
|
|
+//
|
|
|
+//// indexMerge 指标合并
|
|
|
+//// @params frequency string 频度
|
|
|
+//// @params filePre string 文件名前缀
|
|
|
+//// @params pageSize int 每个excel表中的指标数量
|
|
|
+//func indexMerge(frequency, filePre string, pageSize int) (err error) {
|
|
|
+// firstIndexCount := pageSize //第一个添加的excel表需要的指标数
|
|
|
+// indexObj := new(index.BaseFromMysteelChemicalIndex)
|
|
|
+//
|
|
|
+// // 获取未合并的指标总数量
|
|
|
+// total, err := indexObj.GetNoMergeIndexByFrequencyCount(frequency)
|
|
|
+// if err != nil {
|
|
|
+// fmt.Println("GetIndexByFrequencyCount Err:" + err.Error())
|
|
|
+// return
|
|
|
+// }
|
|
|
+// //未合并的指标总数量小于等于0,说明没有需要合并的指标
|
|
|
+// if total <= 0 {
|
|
|
+// return
|
|
|
+// }
|
|
|
+//
|
|
|
+// // 获取最大的文件编号下标
|
|
|
+// maxFileIndexItem, err := indexObj.GetMaxFileIndex(frequency)
|
|
|
+// if err != nil {
|
|
|
+// fmt.Println("GetMaxFileIndex Err:" + err.Error())
|
|
|
+// return
|
|
|
+// }
|
|
|
+//
|
|
|
+// maxFileIndex := maxFileIndexItem.FileIndex
|
|
|
+// if maxFileIndex <= 0 {
|
|
|
+// maxFileIndex = 1
|
|
|
+// }
|
|
|
+//
|
|
|
+// fileName := filePre + "_" + strconv.Itoa(maxFileIndex) + ".xlsx" //保存的文件名称
|
|
|
+// maxMergeIndexFilePath := utils.IndexMsergeSaveDir + fileName
|
|
|
+//
|
|
|
+// // 根据文件下标获取该文件下标已经存在多少的指标
|
|
|
+// indexTotal, err := indexObj.GetIndexCountByMergeFilePath(maxMergeIndexFilePath)
|
|
|
+// if err != nil {
|
|
|
+// fmt.Println("GetIndexCountByMergeFilePath Err:" + err.Error())
|
|
|
+// return
|
|
|
+// }
|
|
|
+//
|
|
|
+// // 如果最近的excel表的指标数量 少于 每页需要的指标数
|
|
|
+// if int(indexTotal) < pageSize {
|
|
|
+// // 最近的excel表的待添加指标数 = 每页需要的指标数 - 已经添加的指标
|
|
|
+// firstIndexCount = pageSize - int(indexTotal)
|
|
|
+// }
|
|
|
+//
|
|
|
+// fmt.Println("maxFileIndex:", maxFileIndex)
|
|
|
+//
|
|
|
+// // 除去第一个excel表的剩余需要添加的指标数量
|
|
|
+// nextTotal := int(total) - firstIndexCount
|
|
|
+// // 总文件数
|
|
|
+// totalPage := paging.PageCount(nextTotal, pageSize)
|
|
|
+// totalPage = totalPage + 1 //需要加上除去在外面的指标(第一张excel)
|
|
|
+// fmt.Println("total:", total)
|
|
|
+// fmt.Println("totalPage:", totalPage)
|
|
|
+// for i := 1; i <= totalPage; i++ {
|
|
|
+// //offset := (i - 1) * pageSize
|
|
|
+//
|
|
|
+// fileName = filePre + "_" + strconv.Itoa(maxFileIndex) + ".xlsx" //保存的文件名称
|
|
|
+// mergeIndexFilePath := utils.IndexMsergeSaveDir + fileName
|
|
|
+// fmt.Println(mergeIndexFilePath)
|
|
|
+//
|
|
|
+// //var list []*index.BaseFromMysteelChemicalIndex
|
|
|
+// // 需要查询的指标数
|
|
|
+// size := pageSize
|
|
|
+// if i == 1 {
|
|
|
+// size = firstIndexCount // 第一页需要合并的新指标数
|
|
|
+//
|
|
|
+// // 第一页需要的指标列表
|
|
|
+// //tmpList, tmpErr := indexObj.GetIndexByFrequencyListByMergeFilePath(frequency, mergeIndexFilePath)
|
|
|
+// //if tmpErr != nil {
|
|
|
+// // fmt.Println("GetIndexByFrequencyListByMergeFilePath Err:" + tmpErr.Error())
|
|
|
+// // err = tmpErr
|
|
|
+// // return
|
|
|
+// //}
|
|
|
+// //list = tmpList
|
|
|
+// }
|
|
|
+// fmt.Println("需要查询", size, "个指标")
|
|
|
+//
|
|
|
+// //fmt.Println(offset, pageSize)
|
|
|
+//
|
|
|
+// // 当下需要合并到excel的指标
|
|
|
+// pageList, tmpErr := indexObj.GetNoMergeIndexByFrequencyPage(frequency, size)
|
|
|
+// if tmpErr != nil {
|
|
|
+// fmt.Println("GetIndexByFrequency Err:" + tmpErr.Error())
|
|
|
+// err = tmpErr
|
|
|
+// return
|
|
|
+// }
|
|
|
+//
|
|
|
+// //if len(list) > 0 {
|
|
|
+// // pageList = append(pageList, list...)
|
|
|
+// //}
|
|
|
+//
|
|
|
+// commentResult, tmpErr := GetIndexComment(mergeIndexFilePath, pageList, maxFileIndex)
|
|
|
+// if tmpErr != nil {
|
|
|
+// fmt.Println("GetIndexComment Err:" + tmpErr.Error())
|
|
|
+// err = tmpErr
|
|
|
+// return
|
|
|
+// }
|
|
|
+// if utils.FileIsExist(mergeIndexFilePath) { //修改文件
|
|
|
+// fileObj, tmpErr := excelize.OpenFile(mergeIndexFilePath)
|
|
|
+// if tmpErr != nil {
|
|
|
+// fmt.Println("打开文件失败,Err:" + tmpErr.Error())
|
|
|
+// err = tmpErr
|
|
|
+// return
|
|
|
+// }
|
|
|
+//
|
|
|
+// fileObj.DeleteComment("Sheet1", "A1")
|
|
|
+// fileObj.AddComment("Sheet1", "A1", commentResult)
|
|
|
+// if err = fileObj.SaveAs(mergeIndexFilePath); err != nil {
|
|
|
+// fmt.Println("保存失败,Err:" + err.Error())
|
|
|
+// fileObj.Close()
|
|
|
+// return
|
|
|
+// }
|
|
|
+// fileObj.Close()
|
|
|
+// } else { //新增文件
|
|
|
+// templatePath := utils.IndexSaveDir + "index_template.xlsx"
|
|
|
+// templateFile, tmpErr := excelize.OpenFile(templatePath)
|
|
|
+// if tmpErr != nil {
|
|
|
+// fmt.Println("打开文件失败,Err:" + tmpErr.Error())
|
|
|
+// err = tmpErr
|
|
|
+// return
|
|
|
+// }
|
|
|
+// templateFile.DeleteComment("Sheet1", "A1")
|
|
|
+// templateFile.AddComment("Sheet1", "A1", commentResult)
|
|
|
+// if err = templateFile.SaveAs(mergeIndexFilePath); err != nil {
|
|
|
+// fmt.Println("保存失败,Err:" + err.Error())
|
|
|
+// templateFile.Close()
|
|
|
+// return
|
|
|
+// }
|
|
|
+// templateFile.Close()
|
|
|
+// }
|
|
|
+// maxFileIndex += 1
|
|
|
+// time.Sleep(1 * time.Second)
|
|
|
+// //刷新数据
|
|
|
+// //MysteelChemicalRefresh(mergeIndexFilePath)
|
|
|
+// AddIndexRefreshToLpush(mergeIndexFilePath)
|
|
|
+// }
|
|
|
+// return
|
|
|
+//}
|
|
|
+//
|
|
|
+//func GetIndexComment(indexFilePath string, list []*index.BaseFromMysteelChemicalIndex, fileIndex int) (commentResult string, err error) {
|
|
|
+// runMode := "release"
|
|
|
+// indexInfo := new(IndexObj)
|
|
|
+// if utils.FileIsExist(indexFilePath) { //文件存在
|
|
|
+// fmt.Println("utils.FileIsExist")
|
|
|
+// getCommentStr := GetComment(indexFilePath)
|
|
|
+// fmt.Println(getCommentStr)
|
|
|
+//
|
|
|
+// err = json.Unmarshal([]byte(getCommentStr), &indexInfo)
|
|
|
+// if err != nil {
|
|
|
+// fmt.Println("json.Unmarshal err:" + err.Error())
|
|
|
+// return
|
|
|
+// }
|
|
|
+// } else { //文件不存在,
|
|
|
+// indexInfo.BlankValue = "0"
|
|
|
+// indexInfo.CanMark = true
|
|
|
+// indexInfo.ChartLineType = "0"
|
|
|
+// indexInfo.DateBlock = 0
|
|
|
+// indexInfo.DateBlockCount = 1
|
|
|
+// indexInfo.DateFormat = 0
|
|
|
+// indexInfo.DateTimeTag = "637973605613980000"
|
|
|
+// indexInfo.EndDate = ""
|
|
|
+// indexInfo.ExportType = 0
|
|
|
+// indexInfo.HasDescription = true
|
|
|
+// indexInfo.HasEmptyRows = false
|
|
|
+// indexInfo.HasFrequency = true
|
|
|
+// indexInfo.HasIndexID = true
|
|
|
+// indexInfo.HasLastDate = true
|
|
|
+// indexInfo.HasSourceName = true
|
|
|
+// indexInfo.HasTimeInterval = true
|
|
|
+// indexInfo.HasUnit = true
|
|
|
+// indexInfo.HasUpdateDate = true
|
|
|
+// indexInfo.IsCreateChart = false
|
|
|
+// indexInfo.IsDataSort = true
|
|
|
+// indexInfo.IsNewSheet = false
|
|
|
+// indexInfo.IsNewWorkbook = false
|
|
|
+// indexInfo.Position = "A1"
|
|
|
+// indexInfo.ShowBlankLines = false
|
|
|
+// indexInfo.StartDate = ""
|
|
|
+// indexInfo.Transpose = false
|
|
|
+// indexInfo.UpdateMode = 1
|
|
|
+// indexInfo.LookModel.IsLast = false
|
|
|
+// indexInfo.LookModel.LookValue = 0
|
|
|
+// indexInfo.LookModel.LookType = 0
|
|
|
+// indexInfo.Ver = 3
|
|
|
+// }
|
|
|
+// modelsList := make([]IndexModels, 0)
|
|
|
+// startDate := "1990-01-01"
|
|
|
+//
|
|
|
+// indexObj := new(index.BaseFromMysteelChemicalIndex)
|
|
|
+//
|
|
|
+// modelsList = append(modelsList, indexInfo.Models...)
|
|
|
+//
|
|
|
+// for k, v := range list {
|
|
|
+// fmt.Println(k, v)
|
|
|
+// item := new(IndexModels)
|
|
|
+// item.DataFormat = 0
|
|
|
+// if v.IndexName == "" {
|
|
|
+// item.DataStartDate = startDate
|
|
|
+// } else {
|
|
|
+// item.DataStartDate = v.StartDate.Format(utils.FormatDate)
|
|
|
+// }
|
|
|
+// item.DefineName = ""
|
|
|
+// item.DefineUnit = ""
|
|
|
+// item.DisplayIndexCode = v.IndexCode
|
|
|
+// item.IndexCode = v.IndexCode
|
|
|
+// item.IndexFormula = v.IndexCode
|
|
|
+// item.PointValue = 0
|
|
|
+// item.UnionStart = ""
|
|
|
+// modelsList = append(modelsList, *item)
|
|
|
+//
|
|
|
+// indexObj.IndexCode = v.IndexCode
|
|
|
+// indexObj.MergeFilePath = indexFilePath
|
|
|
+// indexObj.FileIndex = fileIndex
|
|
|
+//
|
|
|
+// updateColsArr := make([]string, 0)
|
|
|
+// updateColsArr = append(updateColsArr, "merge_file_path")
|
|
|
+// updateColsArr = append(updateColsArr, "file_index")
|
|
|
+//
|
|
|
+// err = indexObj.Update(runMode, updateColsArr)
|
|
|
+// if err != nil {
|
|
|
+// fmt.Println("indexObj.Update err:" + err.Error())
|
|
|
+// return
|
|
|
+// }
|
|
|
+// }
|
|
|
+//
|
|
|
+// indexInfo.Models = modelsList
|
|
|
+//
|
|
|
+// indexStr, err := json.Marshal(indexInfo)
|
|
|
+// if err != nil {
|
|
|
+// fmt.Println("json.Marshal err:" + err.Error())
|
|
|
+// return
|
|
|
+// }
|
|
|
+// text := string(indexStr)
|
|
|
+// text = strings.Trim(text, "{")
|
|
|
+//
|
|
|
+// commentMap := make(map[string]interface{})
|
|
|
+// commentMap["author"] = "{"
|
|
|
+// commentMap["text"] = text
|
|
|
+// //commentMap["text"] = commentItem
|
|
|
+//
|
|
|
+// commentJson, err := json.Marshal(commentMap)
|
|
|
+// if err != nil {
|
|
|
+// fmt.Println("json.Marshal err:" + err.Error())
|
|
|
+// }
|
|
|
+// commentResult = string(commentJson)
|
|
|
+// return
|
|
|
+//}
|
|
|
+//
|
|
|
+//type IndexObj struct {
|
|
|
+// BlankValue string `json:"BlankValue"`
|
|
|
+// CanMark bool `json:"CanMark"`
|
|
|
+// ChartLineType string `json:"ChartLineType"`
|
|
|
+// DateBlock int64 `json:"DateBlock"`
|
|
|
+// DateBlockCount int64 `json:"DateBlockCount"`
|
|
|
+// DateFormat int64 `json:"DateFormat"`
|
|
|
+// DateTimeTag string `json:"DateTimeTag"`
|
|
|
+// EndDate string `json:"EndDate"`
|
|
|
+// ExportType int64 `json:"ExportType"`
|
|
|
+// HasDescription bool `json:"HasDescription"`
|
|
|
+// HasEmptyRows bool `json:"HasEmptyRows"`
|
|
|
+// HasFrequency bool `json:"HasFrequency"`
|
|
|
+// HasIndexID bool `json:"HasIndexID"`
|
|
|
+// HasLastDate bool `json:"HasLastDate"`
|
|
|
+// HasSourceName bool `json:"HasSourceName"`
|
|
|
+// HasTimeInterval bool `json:"HasTimeInterval"`
|
|
|
+// HasUnit bool `json:"HasUnit"`
|
|
|
+// HasUpdateDate bool `json:"HasUpdateDate"`
|
|
|
+// IsCreateChart bool `json:"IsCreateChart"`
|
|
|
+// IsDataSort bool `json:"IsDataSort"`
|
|
|
+// IsNewSheet bool `json:"IsNewSheet"`
|
|
|
+// IsNewWorkbook bool `json:"IsNewWorkbook"`
|
|
|
+// Models []IndexModels `json:"Models"`
|
|
|
+// Position string `json:"Position"`
|
|
|
+// RangeData string `json:"RangeData"`
|
|
|
+// ShowBlankLines bool `json:"ShowBlankLines"`
|
|
|
+// StartDate string `json:"StartDate"`
|
|
|
+// Transpose bool `json:"Transpose"`
|
|
|
+// UpdateMode int64 `json:"UpdateMode"`
|
|
|
+// LookModel struct {
|
|
|
+// IsLast bool `json:"IsLast"`
|
|
|
+// LookValue int64 `json:"LookValue"`
|
|
|
+// LookType int64 `json:"lookType"`
|
|
|
+// } `json:"lookModel"`
|
|
|
+// Ver int64 `json:"ver"`
|
|
|
+//}
|
|
|
+//
|
|
|
+//type IndexModels struct {
|
|
|
+// DataFormat int64 `json:"DataFormat"`
|
|
|
+// DataStartDate string `json:"DataStartDate"`
|
|
|
+// DefineName string `json:"DefineName"`
|
|
|
+// DefineUnit string `json:"DefineUnit"`
|
|
|
+// DisplayIndexCode string `json:"DisplayIndexCode"`
|
|
|
+// IndexCode string `json:"IndexCode"`
|
|
|
+// IndexFormula string `json:"IndexFormula"`
|
|
|
+// PointValue int64 `json:"PointValue"`
|
|
|
+// UnionStart string `json:"UnionStart"`
|
|
|
+//}
|
|
|
+//
|
|
|
+//func DataAnalysis(filePath string) {
|
|
|
+//
|
|
|
+// runMode := "debug"
|
|
|
+// //runMode = "release"
|
|
|
+//
|
|
|
+// fmt.Println("filePath:", filePath)
|
|
|
+// time.Sleep(1 * time.Second)
|
|
|
+// if !utils.FileIsExist(filePath) {
|
|
|
+// fmt.Println("filePath is not exist:" + filePath)
|
|
|
+// return
|
|
|
+// }
|
|
|
+// //读取文件内容
|
|
|
+// global.LOG.Info("WatchFile:" + filePath)
|
|
|
+// f, err := excelize.OpenFile(filePath)
|
|
|
+// global.LOG.Info("OpenFile:" + filePath)
|
|
|
+// if err != nil {
|
|
|
+// fmt.Println("OpenFile:" + filePath + ",Err:" + err.Error())
|
|
|
+// return
|
|
|
+// }
|
|
|
+// defer func() {
|
|
|
+// if err := f.Close(); err != nil {
|
|
|
+// fmt.Println("FileClose Err:" + err.Error())
|
|
|
+// return
|
|
|
+// }
|
|
|
+// }()
|
|
|
+//
|
|
|
+// indexObj := new(index.BaseFromMysteelChemicalIndex)
|
|
|
+// var wg = sync.WaitGroup{}
|
|
|
+// wg.Add(1)
|
|
|
+// go func() {
|
|
|
+// sheetList := f.GetSheetList()
|
|
|
+// for _, sv := range sheetList {
|
|
|
+// rows, err := f.GetRows(sv)
|
|
|
+// if err != nil {
|
|
|
+// fmt.Println("f.GetRows:err:" + err.Error())
|
|
|
+// return
|
|
|
+// }
|
|
|
+// var nameArr []string
|
|
|
+// unitArr := make([]string, 0)
|
|
|
+// sourceArr := make([]string, 0)
|
|
|
+// codeArr := make([]string, 0)
|
|
|
+// frequencyArr := make([]string, 0)
|
|
|
+// dateArr := make([]string, 0)
|
|
|
+// describeArr := make([]string, 0)
|
|
|
+// endDateArr := make([]string, 0)
|
|
|
+// updateArr := make([]string, 0)
|
|
|
+// indexDateArr := make([]string, 0)
|
|
|
+//
|
|
|
+// dataMap := make(map[string][]string)
|
|
|
+//
|
|
|
+// var nameLen int
|
|
|
+// for rk, row := range rows {
|
|
|
+// if rk == 0 {
|
|
|
+// continue
|
|
|
+// }
|
|
|
+// if rk == 1 {
|
|
|
+// for ck, colCell := range row {
|
|
|
+// if ck >= 1 {
|
|
|
+// nameArr = append(nameArr, colCell)
|
|
|
+// }
|
|
|
+// }
|
|
|
+// nameLen = len(nameArr)
|
|
|
+// unitArr = make([]string, nameLen)
|
|
|
+// sourceArr = make([]string, nameLen)
|
|
|
+// codeArr = make([]string, nameLen)
|
|
|
+// frequencyArr = make([]string, nameLen)
|
|
|
+// dateArr = make([]string, nameLen)
|
|
|
+// describeArr = make([]string, nameLen)
|
|
|
+// endDateArr = make([]string, nameLen)
|
|
|
+// updateArr = make([]string, nameLen)
|
|
|
+// } else if rk == 2 {
|
|
|
+// for ck, colCell := range row {
|
|
|
+// if ck >= 1 {
|
|
|
+// unitArr[ck-1] = colCell
|
|
|
+// }
|
|
|
+// }
|
|
|
+// } else if rk == 3 {
|
|
|
+// for ck, colCell := range row {
|
|
|
+// if ck >= 1 {
|
|
|
+// //sourceArr = append(sourceArr, colCell)
|
|
|
+// sourceArr[ck-1] = colCell
|
|
|
+// }
|
|
|
+// }
|
|
|
+// } else if rk == 4 {
|
|
|
+// for ck, colCell := range row {
|
|
|
+// if ck >= 1 {
|
|
|
+// //codeArr = append(codeArr, colCell)
|
|
|
+// codeArr[ck-1] = colCell
|
|
|
+// }
|
|
|
+// }
|
|
|
+// } else if rk == 5 {
|
|
|
+// for ck, colCell := range row {
|
|
|
+// if ck >= 1 {
|
|
|
+// //frequencyArr = append(frequencyArr, colCell)
|
|
|
+// frequencyArr[ck-1] = colCell
|
|
|
+// }
|
|
|
+// }
|
|
|
+// } else if rk == 6 {
|
|
|
+// for ck, colCell := range row {
|
|
|
+// if ck >= 1 {
|
|
|
+// //dateArr = append(dateArr, colCell)
|
|
|
+// dateArr[ck-1] = colCell
|
|
|
+// }
|
|
|
+// }
|
|
|
+// } else if rk == 7 {
|
|
|
+// for ck, colCell := range row {
|
|
|
+// if ck >= 1 {
|
|
|
+// //describeArr = append(describeArr, colCell)
|
|
|
+// describeArr[ck-1] = colCell
|
|
|
+// }
|
|
|
+// }
|
|
|
+// } else if rk == 8 {
|
|
|
+// for ck, colCell := range row {
|
|
|
+// if ck >= 1 {
|
|
|
+// //endDateArr = append(endDateArr, colCell)
|
|
|
+// endDateArr[ck-1] = colCell
|
|
|
+// }
|
|
|
+// }
|
|
|
+// } else if rk == 9 {
|
|
|
+// for ck, colCell := range row {
|
|
|
+// if ck >= 1 {
|
|
|
+// //updateArr = append(updateArr, colCell)
|
|
|
+// updateArr[ck-1] = colCell
|
|
|
+// }
|
|
|
+// }
|
|
|
+// } else {
|
|
|
+// var date string
|
|
|
+// dataArr := make([]string, nameLen)
|
|
|
+// for ck, colCell := range row {
|
|
|
+// if ck == 0 {
|
|
|
+// date = colCell
|
|
|
+// indexDateArr = append(indexDateArr, date)
|
|
|
+// } else {
|
|
|
+// if colCell != "" {
|
|
|
+// dataArr[ck-1] = colCell
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
+// dataMap[date] = dataArr
|
|
|
+// }
|
|
|
+// }
|
|
|
+//
|
|
|
+// var indexId int64
|
|
|
+// existDataMap := make(map[string]string)
|
|
|
+// for k, v := range nameArr {
|
|
|
+// indexName := v
|
|
|
+// indexCode := codeArr[k]
|
|
|
+// unit := unitArr[k]
|
|
|
+// source := sourceArr[k]
|
|
|
+// describe := describeArr[k]
|
|
|
+// dateStr := dateArr[k]
|
|
|
+// frequency := frequencyArr[k]
|
|
|
+// //判断指标是否存在
|
|
|
+// var isAdd int
|
|
|
+// item, err := indexObj.GetIndexItem(runMode, indexCode)
|
|
|
+// if err != nil {
|
|
|
+// if err.Error() == "record not found" {
|
|
|
+// isAdd = 1
|
|
|
+// } else {
|
|
|
+// isAdd = -1
|
|
|
+// fmt.Println("GetIndexItem Err:" + err.Error())
|
|
|
+// return
|
|
|
+// }
|
|
|
+// }
|
|
|
+// if item != nil && item.BaseFromMysteelChemicalIndexId > 0 {
|
|
|
+// fmt.Println("item:", item)
|
|
|
+// isAdd = 2
|
|
|
+// } else {
|
|
|
+// isAdd = 1
|
|
|
+// }
|
|
|
+//
|
|
|
+// var startDate, endDate string
|
|
|
+// startEndArr := strings.Split(dateStr, "~")
|
|
|
+// if len(startEndArr) >= 2 {
|
|
|
+// startDate = startEndArr[0]
|
|
|
+// endDate = startEndArr[1]
|
|
|
+// }
|
|
|
+//
|
|
|
+// if !strings.Contains(frequency, "度") {
|
|
|
+// frequency = frequency + "度"
|
|
|
+// }
|
|
|
+//
|
|
|
+// indexItem := new(index.BaseFromMysteelChemicalIndex)
|
|
|
+// if isAdd == 1 {
|
|
|
+// indexItem.IndexCode = indexCode
|
|
|
+// indexItem.IndexName = indexName
|
|
|
+// indexItem.Unit = unit
|
|
|
+// indexItem.Source = source
|
|
|
+// indexItem.Describe = describe
|
|
|
+// indexItem.StartDate, _ = time.ParseInLocation(utils.FormatDate, startDate, time.Local)
|
|
|
+// indexItem.EndDate, _ = time.ParseInLocation(utils.FormatDate, endDate, time.Local)
|
|
|
+// indexItem.Frequency = frequency
|
|
|
+// indexItem.FilePath = filePath
|
|
|
+// indexItem.MergeFilePath = filePath
|
|
|
+// err = indexItem.Add(runMode)
|
|
|
+// if err != nil {
|
|
|
+// fmt.Println("indexItem.add err:" + err.Error())
|
|
|
+// return
|
|
|
+// }
|
|
|
+// indexId = indexObj.BaseFromMysteelChemicalIndexId
|
|
|
+// } else if isAdd == 2 {
|
|
|
+// indexItem.IndexCode = indexCode
|
|
|
+// indexItem.IndexName = indexName
|
|
|
+// indexItem.Unit = unit
|
|
|
+// indexItem.Source = source
|
|
|
+// indexItem.Describe = describe
|
|
|
+// indexItem.StartDate, _ = time.ParseInLocation(utils.FormatDate, startDate, time.Local)
|
|
|
+// indexItem.EndDate, _ = time.ParseInLocation(utils.FormatDate, endDate, time.Local)
|
|
|
+// indexItem.Frequency = frequency
|
|
|
+// indexItem.FilePath = filePath
|
|
|
+// indexItem.ModifyTime = time.Now()
|
|
|
+// indexId = item.BaseFromMysteelChemicalIndexId
|
|
|
+// //修改数据
|
|
|
+// updateColsArr := make([]string, 0)
|
|
|
+// updateColsArr = append(updateColsArr, "index_name")
|
|
|
+// updateColsArr = append(updateColsArr, "unit")
|
|
|
+// updateColsArr = append(updateColsArr, "source")
|
|
|
+// updateColsArr = append(updateColsArr, "frequency")
|
|
|
+// updateColsArr = append(updateColsArr, "start_date")
|
|
|
+// updateColsArr = append(updateColsArr, "end_date")
|
|
|
+// updateColsArr = append(updateColsArr, "describe")
|
|
|
+// updateColsArr = append(updateColsArr, "end_date")
|
|
|
+// updateColsArr = append(updateColsArr, "modify_time")
|
|
|
+// updateColsArr = append(updateColsArr, "file_path")
|
|
|
+//
|
|
|
+// err = indexItem.Update(runMode, updateColsArr)
|
|
|
+// if err != nil {
|
|
|
+// fmt.Println("indexObj.Update err:" + err.Error())
|
|
|
+// return
|
|
|
+// }
|
|
|
+//
|
|
|
+// dataObj := new(index.BaseFromMysteelChemicalData)
|
|
|
+// //获取已存在的所有数据
|
|
|
+// dataList, err := dataObj.GetIndexDataList(runMode, indexCode)
|
|
|
+// if err != nil {
|
|
|
+// fmt.Println("GetIndexDataList Err:" + err.Error())
|
|
|
+// return
|
|
|
+// }
|
|
|
+// fmt.Println("dataListLen:", len(dataList))
|
|
|
+// for _, v := range dataList {
|
|
|
+// dateStr := v.DataTime.Format(utils.FormatDate)
|
|
|
+// existDataMap[dateStr] = v.Value
|
|
|
+// }
|
|
|
+// }
|
|
|
+//
|
|
|
+// dataList := make([]index.BaseFromMysteelChemicalData, 0)
|
|
|
+// for _, dv := range indexDateArr {
|
|
|
+// dataArr := dataMap[dv]
|
|
|
+// dataVal := dataArr[k]
|
|
|
+// updateDate := updateArr[k]
|
|
|
+// if dataVal != "" {
|
|
|
+// if _, ok := existDataMap[dv]; !ok {
|
|
|
+// dateTime, err := time.ParseInLocation(utils.FormatDate, dv, time.Local)
|
|
|
+// if err != nil {
|
|
|
+// fmt.Println("time.ParseInLocation Err:" + err.Error())
|
|
|
+// return
|
|
|
+// }
|
|
|
+// dataItem := new(index.BaseFromMysteelChemicalData)
|
|
|
+// dataItem.BaseFromMysteelChemicalIndexId = indexId
|
|
|
+// dataItem.IndexCode = indexCode
|
|
|
+// dataItem.DataTime = dateTime
|
|
|
+// dataItem.Value = dataVal
|
|
|
+// dataItem.UpdateDate = updateDate
|
|
|
+// dataItem.CreateTime = time.Now()
|
|
|
+// dataItem.ModifyTime = time.Now()
|
|
|
+// dataList = append(dataList, *dataItem)
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
+// if len(dataList) > 0 {
|
|
|
+// dataObj := new(index.BaseFromMysteelChemicalData)
|
|
|
+// err = dataObj.Add(runMode, dataList)
|
|
|
+// if err != nil {
|
|
|
+// fmt.Println("dataObj.Add() Err:" + err.Error())
|
|
|
+// return
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
+// wg.Done()
|
|
|
+// }()
|
|
|
+// wg.Wait()
|
|
|
+//}
|