时间计算的问题

This commit is contained in:
wh_zcy 2022-09-19 11:57:39 +08:00
parent 4430a3d7f5
commit 400827f108
7 changed files with 46 additions and 25 deletions

View File

@ -54,7 +54,7 @@ func NewMainWindow(ui *UIImpl) MainWindow {
ui.obs.AddListener(observer.EVENT_PING, observer.Listener{
OnNotify: func(data interface{}, args ...interface{}) {
logrus.Debug("即将服务器断开链接")
logrus.Debug("即将服务器断开链接")
conf := dialog.NewConfirm("链接中断", data.(error).Error(), func(
b bool) {
if b {
@ -320,20 +320,17 @@ func (ui *MainWindowImpl) createMainWindowMenu() *fyne.MainMenu {
// createRoleWindowPopUp
func (ui *MainWindowImpl) createRoleWindowPopUp() {
nickname := widget.NewEntry()
c := container.NewHBox(
nickname,
widget.NewButton(common.BUTTON_RANDOM, func() {
c := container.NewBorder(nil, nil, nil,
widget.NewButtonWithIcon("", theme.ViewRefreshIcon(), func() {
nickname.SetText(randomdata.SillyName())
}),
nickname,
)
items := []*widget.FormItem{
widget.NewFormItem(common.LABEL_NICKNAME, c),
}
dialog.ShowForm(common.FORM_TITLE_CREATEROLE, common.BUTTON_OK, common.BUTTON_CANCEL, items, func(b bool) {
if !b {
return
} else {
d := dialog.NewForm(common.FORM_TITLE_CREATEROLE, common.BUTTON_OK, common.BUTTON_CANCEL, items, func(b bool) {
if nickname.Text != "" {
logrus.WithField("nickname", nickname.Text).Debug("submit crete role")
if code := ui.pttService.CreateRole(nickname.Text); code != pb.ErrorCode_Success {
@ -346,8 +343,9 @@ func (ui *MainWindowImpl) createRoleWindowPopUp() {
ui.tb.toolbar.Show()
}
}
}
}, ui.w)
d.Resize(fyne.NewSize(300, 200))
d.Show()
}
// NewWelcomeLabel

View File

@ -101,6 +101,8 @@ type (
ITask interface {
//初始化 日常/周常/成就
InitTaskAll(uid string)
// 初始化指定的任务
InitTaskByTag(uid string, taskTag TaskTag)
//清空任务
ResetTask(uid string, taskTag TaskTag)
//任务通知

1
go.mod
View File

@ -17,6 +17,7 @@ require (
github.com/golang-jwt/jwt v3.2.2+incompatible
github.com/golang/protobuf v1.5.2
github.com/gorilla/websocket v1.4.2
github.com/jinzhu/now v1.1.5
github.com/json-iterator/go v1.1.12
github.com/modern-go/reflect2 v1.0.2
github.com/nacos-group/nacos-sdk-go v1.1.2

2
go.sum
View File

@ -422,6 +422,8 @@ github.com/influxdata/influxdb1-client v0.0.0-20220302092344-a9ab5670611c h1:qSH
github.com/influxdata/influxdb1-client v0.0.0-20220302092344-a9ab5670611c/go.mod h1:qj24IKcXYK6Iy9ceXlo3Tc+vtHo9lIhSX5JddghvEPo=
github.com/jackmordaunt/icns/v2 v2.2.1/go.mod h1:6aYIB9eSzyfHHMKqDf17Xrs1zetQPReAkiUSHzdw4cI=
github.com/jellevandenhooff/dkim v0.0.0-20150330215556-f50fe3d243e1/go.mod h1:E0B/fFc00Y+Rasa88328GlI/XbtyysCtTHZS8h7IrBU=
github.com/jinzhu/now v1.1.5 h1:/o9tlHleP7gOFmsnYNz3RGnqzefHA47wQpKrrdTIwXQ=
github.com/jinzhu/now v1.1.5/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8=
github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k=
github.com/jmespath/go-jmespath v0.4.0 h1:BEgLn5cpjn8UN1mAw4NjwDrS35OdebyEtFe+9YPoQUg=
github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHWvzYPziyZiYoo=

View File

@ -61,6 +61,20 @@ func (this *ModuleTask) InitTaskAll(uid string) {
this.modelTaskActive.initActiveReward(uid)
}
// 初始化指定的任务
func (this *ModuleTask) InitTaskByTag(uid string, taskTag comm.TaskTag) {
switch taskTag {
case comm.TASK_DAILY:
this.modelTask.initTask(uid, comm.TASK_DAILY)
this.modelTaskActive.initActiveReward(uid)
case comm.TASK_WEEKLY:
this.modelTask.initTask(uid, comm.TASK_WEEKLY)
this.modelTaskActive.initActiveReward(uid)
case comm.TASK_ACHIEVE:
this.modelTask.initTask(uid, comm.TASK_ACHIEVE)
}
}
// 清除缓存
func (this *ModuleTask) CleanTask(session comm.IUserSession) {
this.modelTask.BatchDelLists(session.GetUserId())
@ -100,7 +114,6 @@ func (this *ModuleTask) ResetTask(uid string, taskTag comm.TaskTag) {
this.resetActive(uid, taskTag)
this.modelTask.clearTask(uid, taskTag)
this.modelTaskActive.clearTask(uid, taskTag)
this.InitTaskAll(uid)
}
//任务处理

View File

@ -111,9 +111,11 @@ func (this *apiComp) Login(session comm.IUserSession, req *pb.UserLoginReq) (cod
this.module.modelExpand.updateLoginDay(user.Uid, lastLoginTime)
//清空日常
this.module.ModuleTask.ResetTask(user.Uid, comm.TASK_DAILY)
this.module.ModuleTask.InitTaskByTag(user.Uid, comm.TASK_DAILY)
//清周常
if utils.IsAfterWeek(user.Logintime) {
if utils.IsAfterWeek(lastLoginTime) {
this.module.ModuleTask.ResetTask(user.Uid, comm.TASK_WEEKLY)
this.module.ModuleTask.InitTaskByTag(user.Uid, comm.TASK_WEEKLY)
}
// 清理点赞
this.module.ModuleFriend.ResetFriend(user.Uid)

View File

@ -2,6 +2,8 @@ package utils
import (
"time"
"github.com/jinzhu/now"
)
// 判断时间点处于今天
@ -14,11 +16,12 @@ func IsToday(d int64) bool {
//判断是否大于1周
func IsAfterWeek(d int64) bool {
tt := time.Unix(d, 0)
now := time.Now()
if !tt.Before(now) {
nowt := time.Now()
if !tt.Before(nowt) {
return false
}
return now.Sub(tt) >= time.Hour*24*7
at := now.With(tt).AddDate(0, 0, 7).Unix()
return nowt.Unix() >= at
}
// 获取当前时间戳下一天0点时间戳