|
@@ -6,10 +6,12 @@ import (
|
|
|
"hongze/mysteel_watch/global"
|
|
|
"hongze/mysteel_watch/models/index"
|
|
|
"hongze/mysteel_watch/utils"
|
|
|
+ "strconv"
|
|
|
"strings"
|
|
|
"sync"
|
|
|
"time"
|
|
|
|
|
|
+ "github.com/rdlucklib/rdluck_tools/paging"
|
|
|
"github.com/xuri/excelize/v2"
|
|
|
)
|
|
|
|
|
@@ -48,7 +50,7 @@ func IndexYearMerge() {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
- commentResult, err := GetIndexComment(yearIndexFilePath, yearList)
|
|
|
+ commentResult, err := GetIndexComment(yearIndexFilePath, yearList, 1)
|
|
|
if err != nil {
|
|
|
fmt.Println("GetIndexComment Err:" + err.Error())
|
|
|
return
|
|
@@ -102,7 +104,7 @@ func IndexSeasonMerge() {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
- commentResult, err := GetIndexComment(seasonIndexFilePath, seasonList)
|
|
|
+ commentResult, err := GetIndexComment(seasonIndexFilePath, seasonList, 1)
|
|
|
if err != nil {
|
|
|
fmt.Println("GetIndexComment Err:" + err.Error())
|
|
|
return
|
|
@@ -141,11 +143,208 @@ func IndexSeasonMerge() {
|
|
|
//处理excel数据
|
|
|
}
|
|
|
|
|
|
-func GetIndexComment(yearIndexFilePath string, list []*index.BaseFromMysteelChemicalIndex) (commentResult string, err error) {
|
|
|
+//月度
|
|
|
+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 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)
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+func GetIndexComment(indexFilePath string, list []*index.BaseFromMysteelChemicalIndex, fileIndex int) (commentResult string, err error) {
|
|
|
+ runMode := "release"
|
|
|
indexInfo := new(IndexObj)
|
|
|
- if utils.FileIsExist(yearIndexFilePath) { //文件存在
|
|
|
+ if utils.FileIsExist(indexFilePath) { //文件存在
|
|
|
fmt.Println("utils.FileIsExist")
|
|
|
- getCommentStr := GetComment(yearIndexFilePath)
|
|
|
+ getCommentStr := GetComment(indexFilePath)
|
|
|
fmt.Println(getCommentStr)
|
|
|
|
|
|
err = json.Unmarshal([]byte(getCommentStr), &indexInfo)
|
|
@@ -189,6 +388,8 @@ func GetIndexComment(yearIndexFilePath string, list []*index.BaseFromMysteelChem
|
|
|
modelsList := make([]IndexModels, 0)
|
|
|
startDate := "1990-01-01"
|
|
|
|
|
|
+ indexObj := new(index.BaseFromMysteelChemicalIndex)
|
|
|
+
|
|
|
for k, v := range list {
|
|
|
fmt.Println(k, v)
|
|
|
item := new(IndexModels)
|
|
@@ -206,6 +407,20 @@ func GetIndexComment(yearIndexFilePath string, list []*index.BaseFromMysteelChem
|
|
|
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
|