跨月支持

cross-mouth
Your Name 2024-07-26 17:22:20 +08:00
parent e663e4e29a
commit fec5d416b0
2 changed files with 32 additions and 11 deletions

View File

@ -9,10 +9,6 @@ import (
"time" "time"
) )
var nowMouth = time.Now().Month().String()
var nowDay = time.Now().Day()
var M = dateToChinese(nowMouth)
func JsonDeal(file string, remindList []string, closeList []string) (r, c []string) { func JsonDeal(file string, remindList []string, closeList []string) (r, c []string) {
emailJson, err := os.ReadFile(file) emailJson, err := os.ReadFile(file)
if err != nil { if err != nil {
@ -54,7 +50,11 @@ func GetSheetName(file string) (remindList, closeList []string, err error) {
//遍历所有工作表的A2格 //遍历所有工作表的A2格
sheets := f.GetSheetMap() sheets := f.GetSheetMap()
var sheetName string var sheetName string
for _, s := range sheets { var bSheet string //上月sheet
var nowMouth = time.Now().Month().String()
var nowDay = time.Now().Day()
var M = dateToChinese(nowMouth)
for key, s := range sheets {
//// 读取A2单元格的值 //// 读取A2单元格的值
a2value, err := f.GetCellValue(s, "A2") a2value, err := f.GetCellValue(s, "A2")
if err != nil { if err != nil {
@ -63,21 +63,42 @@ func GetSheetName(file string) (remindList, closeList []string, err error) {
} }
//检查月份是否与当前月份相等 //检查月份是否与当前月份相等
//如果与当前时间的月份相等则记录工作表名称 //如果与当前时间的月份相等则记录工作表名称
if a2value == M { if a2value == M && key != 0 {
sheetName = s sheetName = s
bSheet = sheets[key-1]
} else if a2value == M && key == 0 {
sheetName = s
bSheet = ""
} }
} }
rows, _ := f.GetRows(sheetName) rows, _ := f.GetRows(sheetName)
for i, row := range rows { for i, row := range rows {
log.Printf("按行读取excel中的值:索引:%v,行值:%v\n", i, row) log.Printf("按行读取excel中的值:索引:%v,行值:%v\n", i, row)
if i == nowDay { if i == nowDay && nowDay == 1 {
nowRow := cleanSlice(row)
remindList = append(remindList, nowRow[3], nowRow[4])
log.Println("第一分支判断提醒列表:", remindList)
if len(bSheet) != 0 {
brows, _ := f.GetRows(bSheet)
bMRow := brows[len(brows)-1] //上月最后一天
closeList = append(closeList, cleanSlice(bMRow)[2], cleanSlice(bMRow)[3])
} else if len(bSheet) == 0 {
log.Println("没有上个月的excel或者上个月excel的未按顺序排列")
closeList = append(closeList, "", "")
}
} else if i == nowDay && nowDay == 2 {
nowRow := cleanSlice(row) nowRow := cleanSlice(row)
remindList = append(remindList, nowRow[2], nowRow[3]) remindList = append(remindList, nowRow[2], nowRow[3])
log.Println("第二分支判断提醒列表:", remindList)
} else if i == nowDay-1 { closeList = append(closeList, cleanSlice(rows[nowDay-1])[3], cleanSlice(rows[nowDay-1])[4])
yesterdayRow := cleanSlice(row) } else if i == nowDay && nowDay != 1 && nowDay != 2 {
closeList = append(closeList, yesterdayRow[2], yesterdayRow[3]) nowRow := cleanSlice(row)
remindList = append(remindList, nowRow[2], nowRow[3])
log.Println("第三分支判断提醒列表:", remindList)
closeList = append(closeList, cleanSlice(rows[nowDay-1])[2], cleanSlice(rows[nowDay-1])[3])
} }
} }
return remindList, closeList, nil return remindList, closeList, nil

Binary file not shown.