Commit 72a10b61 authored by brent's avatar brent

modify debit

parent a8d691ab
...@@ -69,7 +69,7 @@ func (server *FundsController) Recharge() { ...@@ -69,7 +69,7 @@ func (server *FundsController) Recharge() {
// return // return
//} //}
tradeTime := fmt.Sprintf(time.Now().Format(format)) tradeTime := fmt.Sprintf(time.Now().UTC().Format(format))
//fundsData := models.Funds{ //fundsData := models.Funds{
// Id: max + 1, // Id: max + 1,
// Uid: info.UserID, // Uid: info.UserID,
...@@ -250,36 +250,6 @@ func (server *FundsController) IncomeAndExpense() { ...@@ -250,36 +250,6 @@ func (server *FundsController) IncomeAndExpense() {
return return
} }
//qs := postgres.GetOrmer().QueryTable("funds")
//infoQs := qs.Filter("id", 1)
timeCondition := ""
if appRequest.StartTime != "" && appRequest.EndTime != "" {
temp, _ := time.Parse(layout, appRequest.StartTime)
startTime := fmt.Sprintf(temp.Format(format))
temp, _ = time.Parse(layout, appRequest.EndTime)
endTime := fmt.Sprintf(temp.Format(format))
timeCondition = fmt.Sprintf("time >= '%s' and time <= '%s'", startTime, endTime)
// //infoQs = qs.Filter("trade_time__gte", startTime).Filter("trade_time__lte", endTime)
}
if appRequest.TradeType != 0 {
if timeCondition != "" {
timeCondition = timeCondition + " and"
}
timeCondition = fmt.Sprintf("%s trade_type = %d", timeCondition, appRequest.TradeType)
}
if appRequest.TradeFlow != 0 {
if timeCondition != "" {
timeCondition = timeCondition + " and"
}
timeCondition = fmt.Sprintf("%s trade_flow = %d", timeCondition, appRequest.TradeFlow)
}
if appRequest.TradeChannel != 0 {
if timeCondition != "" {
timeCondition = timeCondition + " and"
}
timeCondition = fmt.Sprintf("%s trade_channel = %d", timeCondition, appRequest.TradeChannel)
}
countQB, _ := orm.NewQueryBuilder("mysql") countQB, _ := orm.NewQueryBuilder("mysql")
countQB.Select("count(*)"). countQB.Select("count(*)").
From("funds").Where("uid != '0'") From("funds").Where("uid != '0'")
...@@ -294,12 +264,16 @@ func (server *FundsController) IncomeAndExpense() { ...@@ -294,12 +264,16 @@ func (server *FundsController) IncomeAndExpense() {
} }
if appRequest.StartTime != "" && appRequest.EndTime != "" { if appRequest.StartTime != "" && appRequest.EndTime != "" {
temp, _ := time.Parse(layout, appRequest.StartTime) start, _ := time.Parse(layout, appRequest.StartTime)
startTime := fmt.Sprintf(temp.Format(format)) startTime := fmt.Sprintf(start.Format(format))
temp, _ = time.Parse(layout, appRequest.EndTime) end, _ := time.Parse(layout, appRequest.EndTime)
endTime := fmt.Sprintf(temp.Format(format)) endTime := fmt.Sprintf(end.Format(format))
countQB.And(fmt.Sprintf("time >= '%s'", startTime)).And(fmt.Sprintf("time <= '%s'", endTime)) if end.Before(start) {
queryQB.And(fmt.Sprintf("time >= '%s'", startTime)).And(fmt.Sprintf("time <= '%s'", endTime)) server.respond(models.BusinessFailed, "起始时间不能大于结束时间")
return
}
countQB.And(fmt.Sprintf("trade_time >= '%s'", startTime)).And(fmt.Sprintf("trade_time <= '%s'", endTime))
queryQB.And(fmt.Sprintf("trade_time >= '%s'", startTime)).And(fmt.Sprintf("trade_time <= '%s'", endTime))
} }
if appRequest.TradeType != 0 { if appRequest.TradeType != 0 {
countQB.And(fmt.Sprintf("trade_type = %d", appRequest.TradeType)) countQB.And(fmt.Sprintf("trade_type = %d", appRequest.TradeType))
......
...@@ -41,14 +41,14 @@ func (server *TaskController) Bills() { ...@@ -41,14 +41,14 @@ func (server *TaskController) Bills() {
currentTime := time.Now() currentTime := time.Now()
if appRequest.EndTime == "" { if appRequest.EndTime == "" {
endTime := time.Date(currentTime.Year(), currentTime.Month(), currentTime.Day(), 23, 59, 59, 0, currentTime.Location()) endTime := time.Date(currentTime.Year(), currentTime.Month(), currentTime.Day(), 23, 59, 59, 0, time.UTC)
appRequest.EndTime = fmt.Sprintf(endTime.Format(format)) appRequest.EndTime = fmt.Sprintf(endTime.Format(format))
} }
if appRequest.StartTime == "" { if appRequest.StartTime == "" {
temp := fmt.Sprintf("-%dh", 24*7) temp := fmt.Sprintf("-%dh", 24*7)
m, _ := time.ParseDuration(temp) m, _ := time.ParseDuration(temp)
tempTime := currentTime.Add(m) tempTime := currentTime.Add(m)
tempTime = time.Date(tempTime.Year(), tempTime.Month(), tempTime.Day(), 0, 0, 0, 0, tempTime.Location()) tempTime = time.Date(tempTime.Year(), tempTime.Month(), tempTime.Day(), 0, 0, 0, 0, time.UTC)
appRequest.StartTime = fmt.Sprintf(tempTime.Format(format)) appRequest.StartTime = fmt.Sprintf(tempTime.Format(format))
} }
startTimeIn, _ := time.Parse(layout, appRequest.StartTime) startTimeIn, _ := time.Parse(layout, appRequest.StartTime)
...@@ -393,14 +393,14 @@ func (server *TaskController) TasksPerDay() { ...@@ -393,14 +393,14 @@ func (server *TaskController) TasksPerDay() {
} }
currentTime := time.Now() currentTime := time.Now()
if appRequest.EndTime == "" { if appRequest.EndTime == "" {
endTime := time.Date(currentTime.Year(), currentTime.Month(), currentTime.Day(), 23, 59, 59, 0, currentTime.Location()) endTime := time.Date(currentTime.Year(), currentTime.Month(), currentTime.Day(), 23, 59, 59, 0, time.UTC)
appRequest.EndTime = fmt.Sprintf(endTime.Format(format)) appRequest.EndTime = fmt.Sprintf(endTime.Format(format))
} }
if appRequest.StartTime == "" { if appRequest.StartTime == "" {
temp := fmt.Sprintf("-%dh", 24*7) temp := fmt.Sprintf("-%dh", 24*7)
m, _ := time.ParseDuration(temp) m, _ := time.ParseDuration(temp)
tempTime := currentTime.Add(m) tempTime := currentTime.Add(m)
tempTime = time.Date(tempTime.Year(), tempTime.Month(), tempTime.Day(), 0, 0, 0, 0, tempTime.Location()) tempTime = time.Date(tempTime.Year(), tempTime.Month(), tempTime.Day(), 0, 0, 0, 0, time.UTC)
appRequest.StartTime = fmt.Sprintf(tempTime.Format(format)) appRequest.StartTime = fmt.Sprintf(tempTime.Format(format))
} }
startTimeIn, _ := time.Parse(tempLayout, appRequest.StartTime) startTimeIn, _ := time.Parse(tempLayout, appRequest.StartTime)
...@@ -433,7 +433,7 @@ func (server *TaskController) TasksPerDay() { ...@@ -433,7 +433,7 @@ func (server *TaskController) TasksPerDay() {
} }
sql := fmt.Sprintf("%s SAMPLE BY 1d ALIGN TO CALENDAR;", countQB.String()) sql := fmt.Sprintf("%s SAMPLE BY 1d ALIGN TO CALENDAR;", countQB.String())
endDateIn := time.Date(endTimeIn.Year(), endTimeIn.Month(), endTimeIn.Day(), 0, 0, 0, 0, endTimeIn.Location()) endDateIn := time.Date(endTimeIn.Year(), endTimeIn.Month(), endTimeIn.Day(), 0, 0, 0, 0, time.UTC)
endDate := fmt.Sprintf(endDateIn.Format(format)) endDate := fmt.Sprintf(endDateIn.Format(format))
dates := utils.SplitDate(startTime, endDate, format) dates := utils.SplitDate(startTime, endDate, format)
...@@ -651,14 +651,14 @@ func (server *TaskController) UserTasksPerDay() { ...@@ -651,14 +651,14 @@ func (server *TaskController) UserTasksPerDay() {
} }
currentTime := time.Now() currentTime := time.Now()
if appRequest.EndTime == "" { if appRequest.EndTime == "" {
endTime := time.Date(currentTime.Year(), currentTime.Month(), currentTime.Day(), 23, 59, 59, 0, currentTime.Location()) endTime := time.Date(currentTime.Year(), currentTime.Month(), currentTime.Day(), 23, 59, 59, 0, time.UTC)
appRequest.EndTime = fmt.Sprintf(endTime.Format(format)) appRequest.EndTime = fmt.Sprintf(endTime.Format(format))
} }
if appRequest.StartTime == "" { if appRequest.StartTime == "" {
temp := fmt.Sprintf("-%dh", 24*7) temp := fmt.Sprintf("-%dh", 24*7)
m, _ := time.ParseDuration(temp) m, _ := time.ParseDuration(temp)
tempTime := currentTime.Add(m) tempTime := currentTime.Add(m)
tempTime = time.Date(tempTime.Year(), tempTime.Month(), tempTime.Day(), 0, 0, 0, 0, tempTime.Location()) tempTime = time.Date(tempTime.Year(), tempTime.Month(), tempTime.Day(), 0, 0, 0, 0, time.UTC)
appRequest.StartTime = fmt.Sprintf(tempTime.Format(format)) appRequest.StartTime = fmt.Sprintf(tempTime.Format(format))
} }
startTimeIn, _ := time.Parse(tempLayout, appRequest.StartTime) startTimeIn, _ := time.Parse(tempLayout, appRequest.StartTime)
...@@ -680,7 +680,7 @@ func (server *TaskController) UserTasksPerDay() { ...@@ -680,7 +680,7 @@ func (server *TaskController) UserTasksPerDay() {
} }
sql := fmt.Sprintf("%s SAMPLE BY 1d ALIGN TO CALENDAR;", countQB.String()) sql := fmt.Sprintf("%s SAMPLE BY 1d ALIGN TO CALENDAR;", countQB.String())
endDateIn := time.Date(endTimeIn.Year(), endTimeIn.Month(), endTimeIn.Day(), 0, 0, 0, 0, endTimeIn.Location()) endDateIn := time.Date(endTimeIn.Year(), endTimeIn.Month(), endTimeIn.Day(), 0, 0, 0, 0, time.UTC)
endDate := fmt.Sprintf(endDateIn.Format(format)) endDate := fmt.Sprintf(endDateIn.Format(format))
dates := utils.SplitDate(startTime, endDate, format) dates := utils.SplitDate(startTime, endDate, format)
//sql := fmt.Sprintf("SELECT time,count(*) FROM tasks WHERE uid='%d' and time >= '%s' and time <= '%s' SAMPLE BY 1d ALIGN TO CALENDAR;", info.UserID, startTime, endTime) //sql := fmt.Sprintf("SELECT time,count(*) FROM tasks WHERE uid='%d' and time >= '%s' and time <= '%s' SAMPLE BY 1d ALIGN TO CALENDAR;", info.UserID, startTime, endTime)
...@@ -710,6 +710,80 @@ func (server *TaskController) UserTasksPerDay() { ...@@ -710,6 +710,80 @@ func (server *TaskController) UserTasksPerDay() {
server.respond(http.StatusOK, "", counts) server.respond(http.StatusOK, "", counts)
} }
func (server *TaskController) UserTasksPerPeriod() {
info, err := server.Check()
if err != nil {
server.respond(http.StatusUnauthorized, err.Error())
return
}
body := server.Ctx.Input.RequestBody
appRequest := models.AppRequest{}
err = json.Unmarshal(body, &appRequest) //解析body中数据
logs.Debug("appRequest", appRequest)
//if err != nil {
// server.respond(models.NoRequestBody, err.Error())
// return
//}
period := 7
if appRequest.Period != 0 {
period = appRequest.Period
}
if period != 365 {
period = period - 1
}
currentTime := time.Now()
end := time.Date(currentTime.Year(), currentTime.Month(), currentTime.Day(), 23, 59, 59, 0, time.UTC)
temp := fmt.Sprintf("-%dh", 24*period)
m, _ := time.ParseDuration(temp)
tempTime := currentTime.Add(m)
tempTime = time.Date(tempTime.Year(), tempTime.Month(), tempTime.Day(), 0, 0, 0, 0, time.UTC)
startTime := fmt.Sprintf(tempTime.Format(format))
endTime := fmt.Sprintf(end.Format(format))
countQB, _ := orm.NewQueryBuilder("mysql")
countQB.Select("count(*)", "time").
From("tasks").Where(fmt.Sprintf("time >= '%s'", startTime)).And(fmt.Sprintf("time <= '%s'", endTime))
if info.Role != 1 && info.Role != 2 {
countQB.And(fmt.Sprintf("uid = %d", info.UserID))
}
sql := fmt.Sprintf("%s SAMPLE BY 1d ALIGN TO CALENDAR;", countQB.String())
endDateIn := time.Date(end.Year(), end.Month(), end.Day(), 0, 0, 0, 0, time.UTC)
endDate := fmt.Sprintf(endDateIn.Format(format))
dates := utils.SplitDate(startTime, endDate, format)
if period == 365 {
sql = fmt.Sprintf("%s SAMPLE BY 1M ALIGN TO CALENDAR;", countQB.String())
if tempTime.Day() != 1 {
tempTime = tempTime.AddDate(0, 1, 0)
}
dates = utils.YearMonthRange(tempTime, endDateIn, format)
}
counts, err := postgres.CountTasks(sql)
if err != nil {
server.respond(models.BusinessFailed, err.Error())
return
}
for _, value := range dates {
tempDate := findTime(counts, value)
if tempDate != nil {
reTask := models.TaskCount{
Type: "0",
Time: *tempDate,
Count: "0",
ApiPath: "",
}
counts = append(counts, reTask)
}
}
sort.Slice(counts, func(i, j int) bool {
return counts[i].Time.Before(counts[j].Time)
})
server.respond(http.StatusOK, "", counts)
}
func (server *TaskController) UserTaskTypePerDay() { func (server *TaskController) UserTaskTypePerDay() {
info, err := server.Check() info, err := server.Check()
if err != nil { if err != nil {
...@@ -738,14 +812,14 @@ func (server *TaskController) UserTaskTypePerDay() { ...@@ -738,14 +812,14 @@ func (server *TaskController) UserTaskTypePerDay() {
} }
currentTime := time.Now() currentTime := time.Now()
if appRequest.EndTime == "" { if appRequest.EndTime == "" {
endTime := time.Date(currentTime.Year(), currentTime.Month(), currentTime.Day(), 23, 59, 59, 0, currentTime.Location()) endTime := time.Date(currentTime.Year(), currentTime.Month(), currentTime.Day(), 23, 59, 59, 0, time.UTC)
appRequest.EndTime = fmt.Sprintf(endTime.Format(format)) appRequest.EndTime = fmt.Sprintf(endTime.Format(format))
} }
if appRequest.StartTime == "" { if appRequest.StartTime == "" {
temp := fmt.Sprintf("-%dh", 24*7) temp := fmt.Sprintf("-%dh", 24*7)
m, _ := time.ParseDuration(temp) m, _ := time.ParseDuration(temp)
tempTime := currentTime.Add(m) tempTime := currentTime.Add(m)
tempTime = time.Date(tempTime.Year(), tempTime.Month(), tempTime.Day(), 0, 0, 0, 0, tempTime.Location()) tempTime = time.Date(tempTime.Year(), tempTime.Month(), tempTime.Day(), 0, 0, 0, 0, time.UTC)
appRequest.StartTime = fmt.Sprintf(tempTime.Format(format)) appRequest.StartTime = fmt.Sprintf(tempTime.Format(format))
} }
startTimeIn, _ := time.Parse(tempLayout, appRequest.StartTime) startTimeIn, _ := time.Parse(tempLayout, appRequest.StartTime)
...@@ -766,7 +840,7 @@ func (server *TaskController) UserTaskTypePerDay() { ...@@ -766,7 +840,7 @@ func (server *TaskController) UserTaskTypePerDay() {
} }
sql := fmt.Sprintf("%s SAMPLE BY 1d ALIGN TO CALENDAR;", countQB.String()) sql := fmt.Sprintf("%s SAMPLE BY 1d ALIGN TO CALENDAR;", countQB.String())
endDateIn := time.Date(endTimeIn.Year(), endTimeIn.Month(), endTimeIn.Day(), 0, 0, 0, 0, endTimeIn.Location()) endDateIn := time.Date(endTimeIn.Year(), endTimeIn.Month(), endTimeIn.Day(), 0, 0, 0, 0, time.UTC)
endDate := fmt.Sprintf(endDateIn.Format(format)) endDate := fmt.Sprintf(endDateIn.Format(format))
dates := utils.SplitDate(startTime, endDate, format) dates := utils.SplitDate(startTime, endDate, format)
//sql := fmt.Sprintf("SELECT type, time,count(*) FROM tasks WHERE uid='%d' and time >= '%s' and time <= '%s' SAMPLE BY 1d ALIGN TO CALENDAR;", info.UserID, startTime, endTime) //sql := fmt.Sprintf("SELECT type, time,count(*) FROM tasks WHERE uid='%d' and time >= '%s' and time <= '%s' SAMPLE BY 1d ALIGN TO CALENDAR;", info.UserID, startTime, endTime)
...@@ -852,16 +926,23 @@ func (server *TaskController) UserTaskTypePercentage() { ...@@ -852,16 +926,23 @@ func (server *TaskController) UserTaskTypePercentage() {
if appRequest.EndTime == "" && appRequest.StartTime == "" { if appRequest.EndTime == "" && appRequest.StartTime == "" {
tempLayout = format tempLayout = format
} }
period := 7
if appRequest.Period != 0 {
period = appRequest.Period
}
if period != 365 {
period = period - 1
}
currentTime := time.Now() currentTime := time.Now()
if appRequest.EndTime == "" { if appRequest.EndTime == "" {
endTime := time.Date(currentTime.Year(), currentTime.Month(), currentTime.Day(), 23, 59, 59, 0, currentTime.Location()) endTime := time.Date(currentTime.Year(), currentTime.Month(), currentTime.Day(), 23, 59, 59, 0, time.UTC)
appRequest.EndTime = fmt.Sprintf(endTime.Format(format)) appRequest.EndTime = fmt.Sprintf(endTime.Format(format))
} }
if appRequest.StartTime == "" { if appRequest.StartTime == "" {
temp := fmt.Sprintf("-%dh", 24*7) temp := fmt.Sprintf("-%dh", 24*period)
m, _ := time.ParseDuration(temp) m, _ := time.ParseDuration(temp)
tempTime := currentTime.Add(m) tempTime := currentTime.Add(m)
tempTime = time.Date(tempTime.Year(), tempTime.Month(), tempTime.Day(), 0, 0, 0, 0, tempTime.Location()) tempTime = time.Date(tempTime.Year(), tempTime.Month(), tempTime.Day(), 0, 0, 0, 0, time.UTC)
appRequest.StartTime = fmt.Sprintf(tempTime.Format(format)) appRequest.StartTime = fmt.Sprintf(tempTime.Format(format))
} }
startTimeIn, _ := time.Parse(tempLayout, appRequest.StartTime) startTimeIn, _ := time.Parse(tempLayout, appRequest.StartTime)
...@@ -942,14 +1023,14 @@ func (server *TaskController) UserFeePerDay() { ...@@ -942,14 +1023,14 @@ func (server *TaskController) UserFeePerDay() {
} }
currentTime := time.Now() currentTime := time.Now()
if appRequest.EndTime == "" { if appRequest.EndTime == "" {
endTime := time.Date(currentTime.Year(), currentTime.Month(), currentTime.Day(), 23, 59, 59, 0, currentTime.Location()) endTime := time.Date(currentTime.Year(), currentTime.Month(), currentTime.Day(), 23, 59, 59, 0, time.UTC)
appRequest.EndTime = fmt.Sprintf(endTime.Format(format)) appRequest.EndTime = fmt.Sprintf(endTime.Format(format))
} }
if appRequest.StartTime == "" { if appRequest.StartTime == "" {
temp := fmt.Sprintf("-%dh", 24*7) temp := fmt.Sprintf("-%dh", 24*7)
m, _ := time.ParseDuration(temp) m, _ := time.ParseDuration(temp)
tempTime := currentTime.Add(m) tempTime := currentTime.Add(m)
tempTime = time.Date(tempTime.Year(), tempTime.Month(), tempTime.Day(), 0, 0, 0, 0, tempTime.Location()) tempTime = time.Date(tempTime.Year(), tempTime.Month(), tempTime.Day(), 0, 0, 0, 0, time.UTC)
appRequest.StartTime = fmt.Sprintf(tempTime.Format(format)) appRequest.StartTime = fmt.Sprintf(tempTime.Format(format))
} }
startTimeIn, _ := time.Parse(tempLayout, appRequest.StartTime) startTimeIn, _ := time.Parse(tempLayout, appRequest.StartTime)
...@@ -971,7 +1052,7 @@ func (server *TaskController) UserFeePerDay() { ...@@ -971,7 +1052,7 @@ func (server *TaskController) UserFeePerDay() {
} }
sql := fmt.Sprintf("%s SAMPLE BY 1d ALIGN TO CALENDAR;", countQB.String()) sql := fmt.Sprintf("%s SAMPLE BY 1d ALIGN TO CALENDAR;", countQB.String())
endDateIn := time.Date(endTimeIn.Year(), endTimeIn.Month(), endTimeIn.Day(), 0, 0, 0, 0, endTimeIn.Location()) endDateIn := time.Date(endTimeIn.Year(), endTimeIn.Month(), endTimeIn.Day(), 0, 0, 0, 0, time.UTC)
endDate := fmt.Sprintf(endDateIn.Format(format)) endDate := fmt.Sprintf(endDateIn.Format(format))
dates := utils.SplitDate(startTime, endDate, format) dates := utils.SplitDate(startTime, endDate, format)
...@@ -1030,14 +1111,14 @@ func (server *TaskController) UserFee() { ...@@ -1030,14 +1111,14 @@ func (server *TaskController) UserFee() {
//} //}
//currentTime := time.Now() //currentTime := time.Now()
//if appRequest.EndTime == "" { //if appRequest.EndTime == "" {
// endTime := time.Date(currentTime.Year(), currentTime.Month(), currentTime.Day(), 23, 59, 59, 0, currentTime.Location()) // endTime := time.Date(currentTime.Year(), currentTime.Month(), currentTime.Day(), 23, 59, 59, 0, time.UTC)
// appRequest.EndTime = fmt.Sprintf(endTime.Format(format)) // appRequest.EndTime = fmt.Sprintf(endTime.Format(format))
//} //}
//if appRequest.StartTime == "" { //if appRequest.StartTime == "" {
// temp := fmt.Sprintf("-%dh", 24*7) // temp := fmt.Sprintf("-%dh", 24*7)
// m, _ := time.ParseDuration(temp) // m, _ := time.ParseDuration(temp)
// tempTime := currentTime.Add(m) // tempTime := currentTime.Add(m)
// tempTime = time.Date(tempTime.Year(), tempTime.Month(), tempTime.Day(), 0, 0, 0, 0, tempTime.Location()) // tempTime = time.Date(tempTime.Year(), tempTime.Month(), tempTime.Day(), 0, 0, 0, 0, time.UTC)
// appRequest.StartTime = fmt.Sprintf(tempTime.Format(format)) // appRequest.StartTime = fmt.Sprintf(tempTime.Format(format))
//} //}
//startTimeIn, _ := time.Parse(tempLayout, appRequest.StartTime) //startTimeIn, _ := time.Parse(tempLayout, appRequest.StartTime)
...@@ -1060,7 +1141,7 @@ func (server *TaskController) UserFee() { ...@@ -1060,7 +1141,7 @@ func (server *TaskController) UserFee() {
//sql := fmt.Sprintf("%s SAMPLE BY 1d ALIGN TO CALENDAR;", countQB.String()) //sql := fmt.Sprintf("%s SAMPLE BY 1d ALIGN TO CALENDAR;", countQB.String())
sql := countQB.String() sql := countQB.String()
//endDateIn := time.Date(endTimeIn.Year(), endTimeIn.Month(), endTimeIn.Day(), 0, 0, 0, 0, endTimeIn.Location()) //endDateIn := time.Date(endTimeIn.Year(), endTimeIn.Month(), endTimeIn.Day(), 0, 0, 0, 0, time.UTC)
//endDate := fmt.Sprintf(endDateIn.Format(format)) //endDate := fmt.Sprintf(endDateIn.Format(format))
//dates := utils.SplitDate(startTime, endDate, format) //dates := utils.SplitDate(startTime, endDate, format)
...@@ -1119,14 +1200,14 @@ func (server *TaskController) UserTaskTypeFeePerDay() { ...@@ -1119,14 +1200,14 @@ func (server *TaskController) UserTaskTypeFeePerDay() {
} }
currentTime := time.Now() currentTime := time.Now()
if appRequest.EndTime == "" { if appRequest.EndTime == "" {
endTime := time.Date(currentTime.Year(), currentTime.Month(), currentTime.Day(), 23, 59, 59, 0, currentTime.Location()) endTime := time.Date(currentTime.Year(), currentTime.Month(), currentTime.Day(), 23, 59, 59, 0, time.UTC)
appRequest.EndTime = fmt.Sprintf(endTime.Format(format)) appRequest.EndTime = fmt.Sprintf(endTime.Format(format))
} }
if appRequest.StartTime == "" { if appRequest.StartTime == "" {
temp := fmt.Sprintf("-%dh", 24*7) temp := fmt.Sprintf("-%dh", 24*7)
m, _ := time.ParseDuration(temp) m, _ := time.ParseDuration(temp)
tempTime := currentTime.Add(m) tempTime := currentTime.Add(m)
tempTime = time.Date(tempTime.Year(), tempTime.Month(), tempTime.Day(), 0, 0, 0, 0, tempTime.Location()) tempTime = time.Date(tempTime.Year(), tempTime.Month(), tempTime.Day(), 0, 0, 0, 0, time.UTC)
appRequest.StartTime = fmt.Sprintf(tempTime.Format(format)) appRequest.StartTime = fmt.Sprintf(tempTime.Format(format))
} }
startTimeIn, _ := time.Parse(tempLayout, appRequest.StartTime) startTimeIn, _ := time.Parse(tempLayout, appRequest.StartTime)
...@@ -1148,7 +1229,7 @@ func (server *TaskController) UserTaskTypeFeePerDay() { ...@@ -1148,7 +1229,7 @@ func (server *TaskController) UserTaskTypeFeePerDay() {
} }
sql := fmt.Sprintf("%s SAMPLE BY 1d ALIGN TO CALENDAR;", countQB.String()) sql := fmt.Sprintf("%s SAMPLE BY 1d ALIGN TO CALENDAR;", countQB.String())
endDateIn := time.Date(endTimeIn.Year(), endTimeIn.Month(), endTimeIn.Day(), 0, 0, 0, 0, endTimeIn.Location()) endDateIn := time.Date(endTimeIn.Year(), endTimeIn.Month(), endTimeIn.Day(), 0, 0, 0, 0, time.UTC)
endDate := fmt.Sprintf(endDateIn.Format(format)) endDate := fmt.Sprintf(endDateIn.Format(format))
dates := utils.SplitDate(startTime, endDate, format) dates := utils.SplitDate(startTime, endDate, format)
...@@ -1226,14 +1307,14 @@ func (server *TaskController) UserTaskTypeFeePercentage() { ...@@ -1226,14 +1307,14 @@ func (server *TaskController) UserTaskTypeFeePercentage() {
} }
currentTime := time.Now() currentTime := time.Now()
if appRequest.EndTime == "" { if appRequest.EndTime == "" {
endTime := time.Date(currentTime.Year(), currentTime.Month(), currentTime.Day(), 23, 59, 59, 0, currentTime.Location()) endTime := time.Date(currentTime.Year(), currentTime.Month(), currentTime.Day(), 23, 59, 59, 0, time.UTC)
appRequest.EndTime = fmt.Sprintf(endTime.Format(format)) appRequest.EndTime = fmt.Sprintf(endTime.Format(format))
} }
if appRequest.StartTime == "" { if appRequest.StartTime == "" {
temp := fmt.Sprintf("-%dh", 24*7) temp := fmt.Sprintf("-%dh", 24*7)
m, _ := time.ParseDuration(temp) m, _ := time.ParseDuration(temp)
tempTime := currentTime.Add(m) tempTime := currentTime.Add(m)
tempTime = time.Date(tempTime.Year(), tempTime.Month(), tempTime.Day(), 0, 0, 0, 0, tempTime.Location()) tempTime = time.Date(tempTime.Year(), tempTime.Month(), tempTime.Day(), 0, 0, 0, 0, time.UTC)
appRequest.StartTime = fmt.Sprintf(tempTime.Format(format)) appRequest.StartTime = fmt.Sprintf(tempTime.Format(format))
} }
startTimeIn, _ := time.Parse(tempLayout, appRequest.StartTime) startTimeIn, _ := time.Parse(tempLayout, appRequest.StartTime)
......
...@@ -22,3 +22,16 @@ func SplitDate(beginDate, endDate, format string) []string { ...@@ -22,3 +22,16 @@ func SplitDate(beginDate, endDate, format string) []string {
dlist = append(dlist, endDate) dlist = append(dlist, endDate)
return dlist return dlist
} }
func YearMonthRange(start, end time.Time, format string) []string {
// 创建年月数组
start = time.Date(start.Year(), start.Month(), 1, 0, 0, 0, 0, start.Location())
yms := make([]string, 0)
// 遍历每个月
for t := start; t.Before(end); t = t.AddDate(0, 1, 0) {
yms = append(yms, t.Format(format))
}
return yms
}
...@@ -60,6 +60,27 @@ func main() { ...@@ -60,6 +60,27 @@ func main() {
//dates := utils.SplitDate(startTimeStr, endTimeStr, "2006-01-02T15:04:05.000000Z") //dates := utils.SplitDate(startTimeStr, endTimeStr, "2006-01-02T15:04:05.000000Z")
//logs.Debug("dates = ", dates) //logs.Debug("dates = ", dates)
//currentTime := time.Now()
////start := time.Date(2023, 4, 1, 0, 0, 0, 0, currentTime.Location())
//end := time.Date(2024, 4, 1, 0, 0, 0, 0, currentTime.Location())
//
////currentTime := time.Now()
////end := time.Date(currentTime.Year(), currentTime.Month(), currentTime.Day(), 23, 59, 59, 0, time.UTC)
//temp := fmt.Sprintf("-%dh", 24*365)
//m, _ := time.ParseDuration(temp)
//tempTime := end.Add(m)
//if tempTime.Day() != 1 {
// tempTime = tempTime.AddDate(0, 1, 0)
//}
//tempTime = time.Date(tempTime.Year(), tempTime.Month(), tempTime.Day(), 0, 0, 0, 0, time.UTC)
////endDateIn := time.Date(end.Year(), end.Month(), end.Day(), 0, 0, 0, 0, time.UTC)
////endDate := fmt.Sprintf(endDateIn.Format("2006-01-02T15:04:05.000000Z"))
//
//months := yearMonthRange(tempTime, end)
//for _, month := range months {
// fmt.Println(month)
//}
cronjob.Start() cronjob.Start()
mysql.GetMysqlInstace() mysql.GetMysqlInstace()
//postgres.Query("") //postgres.Query("")
...@@ -77,3 +98,44 @@ func main() { ...@@ -77,3 +98,44 @@ func main() {
//} //}
//logs.Debug("id = ", id) //logs.Debug("id = ", id)
} }
func yearMonthRange(start, end time.Time) []string {
// 创建年月数组
start = time.Date(start.Year(), start.Month(), 1, 0, 0, 0, 0, start.Location())
//end = time.Date(end.Year(), end.Month(), 1, 0, 0, 0, 0, end.Location())
yms := make([]string, 0)
// 遍历每个月
temp := end.AddDate(0, 1, 0)
for t := start; t.Compare(end) <= 0; t = t.AddDate(0, 1, 0) {
temp = end.AddDate(0, 1, 0)
yms = append(yms, t.Format("2006-01-02T15:04:05.000000Z"))
}
fmt.Println(temp)
return yms
}
func dayRange(start, end time.Time) []time.Time {
// 创建天数组
days := make([]time.Time, 0)
// 遍历每一天
for t := start; t.Before(end.AddDate(0, 0, 1)); t = t.AddDate(0, 0, 1) {
days = append(days, t)
}
return days
}
func monthRange(start, end time.Time) []time.Month {
// 创建月份数组
months := make([]time.Month, 0)
// 遍历每个月
for t := start; t.Before(end.AddDate(0, 1, 0)); t = t.AddDate(0, 1, 0) {
months = append(months, t.Month())
}
return months
}
...@@ -63,6 +63,9 @@ type AppRequest struct { ...@@ -63,6 +63,9 @@ type AppRequest struct {
//显卡列表 //显卡列表
Type int `json:"type,omitempty"` Type int `json:"type,omitempty"`
//任务柱状图
Period int `json:"period,omitempty"`
} }
type EnumType struct { type EnumType struct {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment