From b22f0805e7e2c24c57377e8b7fbcc240ad02b6ed Mon Sep 17 00:00:00 2001 From: godLei6 <603785348@qq.com> Date: Tue, 22 Oct 2024 10:56:37 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E5=8D=8F=E8=AE=AE?= =?UTF-8?q?=E6=9C=8D=E5=8A=A1=E5=99=A8=E7=8A=B6=E6=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- go.mod | 2 +- .../staticEvent/{static.go => halfHour.go} | 22 ++++++------- .../internal/event/staticEvent/oneMinute.go | 31 +++++++++++++++++++ .../repo/relationDB/protocolService.go | 8 +++++ service/dmsvr/internal/startup/init.go | 25 ++++++++++++--- 5 files changed, 72 insertions(+), 16 deletions(-) rename service/dmsvr/internal/event/staticEvent/{static.go => halfHour.go} (90%) create mode 100644 service/dmsvr/internal/event/staticEvent/oneMinute.go diff --git a/go.mod b/go.mod index 3ae0dd3c7..a2f314f90 100644 --- a/go.mod +++ b/go.mod @@ -7,7 +7,7 @@ go 1.21.4 require ( gitee.com/unitedrhino/core v1.0.0 - gitee.com/unitedrhino/share v1.0.8 + gitee.com/unitedrhino/share v1.0.9 gitee.com/unitedrhino/squirrel v1.20.5 github.com/dgraph-io/ristretto v0.1.0 github.com/dop251/goja v0.0.0-20230402114112-623f9dda9079 diff --git a/service/dmsvr/internal/event/staticEvent/static.go b/service/dmsvr/internal/event/staticEvent/halfHour.go similarity index 90% rename from service/dmsvr/internal/event/staticEvent/static.go rename to service/dmsvr/internal/event/staticEvent/halfHour.go index 4deb3da4e..a6075e2c8 100644 --- a/service/dmsvr/internal/event/staticEvent/static.go +++ b/service/dmsvr/internal/event/staticEvent/halfHour.go @@ -18,21 +18,21 @@ import ( "time" ) -type StaticHandle struct { +type HalfHourHandle struct { svcCtx *svc.ServiceContext ctx context.Context logx.Logger } -func NewStaticHandle(ctx context.Context, svcCtx *svc.ServiceContext) *StaticHandle { - return &StaticHandle{ +func NewHalfHourHandle(ctx context.Context, svcCtx *svc.ServiceContext) *HalfHourHandle { + return &HalfHourHandle{ svcCtx: svcCtx, Logger: logx.WithContext(ctx), ctx: ctx, } } -func (l *StaticHandle) Handle() error { //产品品类设备数量统计 +func (l *HalfHourHandle) Handle() error { //产品品类设备数量统计 w := sync.WaitGroup{} w.Add(6) utils.Go(l.ctx, func() { @@ -86,7 +86,7 @@ func (l *StaticHandle) Handle() error { //产品品类设备数量统计 w.Wait() return nil } -func (l *StaticHandle) AreaDeviceStatic() error { //区域下的设备数量统计 +func (l *HalfHourHandle) AreaDeviceStatic() error { //区域下的设备数量统计 ret, err := l.svcCtx.AreaM.AreaInfoIndex(l.ctx, &sys.AreaInfoIndexReq{}) if err != nil { return err @@ -101,7 +101,7 @@ func (l *StaticHandle) AreaDeviceStatic() error { //区域下的设备数量统 var count atomic.Int64 -func (l *StaticHandle) DeviceOnlineFix() error { //设备在线修复 +func (l *HalfHourHandle) DeviceOnlineFix() error { //设备在线修复 nc := count.Add(1) if nc/2 == 1 { //1小时处理一次 return nil @@ -130,7 +130,7 @@ func (l *StaticHandle) DeviceOnlineFix() error { //设备在线修复 return nil } -func (l *StaticHandle) DeviceExp() error { //设备过期处理 +func (l *HalfHourHandle) DeviceExp() error { //设备过期处理 { //有效期到了之后不启用 err := relationDB.NewDeviceInfoRepo(l.ctx).UpdateWithField(l.ctx, relationDB.DeviceFilter{ExpTime: stores.CmpAnd(stores.CmpLte(time.Now()), stores.CmpIsNull(false))}, @@ -149,7 +149,7 @@ func (l *StaticHandle) DeviceExp() error { //设备过期处理 } return nil } -func (l *StaticHandle) DeviceAbnormalRecover() error { //设备上下线异常恢复 +func (l *HalfHourHandle) DeviceAbnormalRecover() error { //设备上下线异常恢复 now := time.Now() dis, err := relationDB.NewDeviceInfoRepo(l.ctx).FindByFilter(l.ctx, relationDB.DeviceFilter{ Statuses: []int64{def.DeviceStatusAbnormal}, @@ -189,7 +189,7 @@ func (l *StaticHandle) DeviceAbnormalRecover() error { //设备上下线异常 return nil } -func (l *StaticHandle) DeviceAbnormalSet() error { //设备上下线异常设置 +func (l *HalfHourHandle) DeviceAbnormalSet() error { //设备上下线异常设置 now := time.Now() dis, err := relationDB.NewDeviceInfoRepo(l.ctx).FindByFilter(l.ctx, relationDB.DeviceFilter{ LastLoginTime: &def.TimeRange{ @@ -232,7 +232,7 @@ func (l *StaticHandle) DeviceAbnormalSet() error { //设备上下线异常设置 return nil } -func (l *StaticHandle) DeviceMsgCount() error { //产品品类设备数量统计 +func (l *HalfHourHandle) DeviceMsgCount() error { //产品品类设备数量统计 end := time.Now() var fm = end.Minute() / 30 * 30 var countData []*relationDB.DmDeviceMsgCount @@ -273,7 +273,7 @@ func (l *StaticHandle) DeviceMsgCount() error { //产品品类设备数量统计 return nil } -func (l *StaticHandle) ProductCategoryStatic() error { //产品品类设备数量统计 +func (l *HalfHourHandle) ProductCategoryStatic() error { //产品品类设备数量统计 pcDB := relationDB.NewProductCategoryRepo(l.ctx) pcs, err := pcDB.FindByFilter(l.ctx, relationDB.ProductCategoryFilter{}, nil) if err != nil { diff --git a/service/dmsvr/internal/event/staticEvent/oneMinute.go b/service/dmsvr/internal/event/staticEvent/oneMinute.go new file mode 100644 index 000000000..ea5450cea --- /dev/null +++ b/service/dmsvr/internal/event/staticEvent/oneMinute.go @@ -0,0 +1,31 @@ +package staticEvent + +import ( + "context" + "gitee.com/unitedrhino/share/stores" + "gitee.com/unitedrhino/things/service/dmsvr/internal/repo/relationDB" + "gitee.com/unitedrhino/things/service/dmsvr/internal/svc" + "github.com/zeromicro/go-zero/core/logx" +) + +type OneMinuteHandle struct { + svcCtx *svc.ServiceContext + ctx context.Context + logx.Logger +} + +func NewOneMinuteHandle(ctx context.Context, svcCtx *svc.ServiceContext) *OneMinuteHandle { + return &OneMinuteHandle{ + svcCtx: svcCtx, + Logger: logx.WithContext(ctx), + ctx: ctx, + } +} + +func (l *OneMinuteHandle) Handle() error { //产品品类设备数量统计 + err := stores.WithNoDebug(l.ctx, relationDB.NewProtocolServiceRepo).DownStatus(l.ctx) + if err != nil { + l.Error(err) + } + return nil +} diff --git a/service/dmsvr/internal/repo/relationDB/protocolService.go b/service/dmsvr/internal/repo/relationDB/protocolService.go index 460b3eac2..aa3c46f5f 100644 --- a/service/dmsvr/internal/repo/relationDB/protocolService.go +++ b/service/dmsvr/internal/repo/relationDB/protocolService.go @@ -2,9 +2,11 @@ package relationDB import ( "context" + "gitee.com/unitedrhino/share/def" "gitee.com/unitedrhino/share/stores" "gorm.io/gorm" "gorm.io/gorm/clause" + "time" ) /* @@ -82,6 +84,12 @@ func (p ProtocolServiceRepo) Update(ctx context.Context, data *DmProtocolService return stores.ErrFmt(err) } +func (p ProtocolServiceRepo) DownStatus(ctx context.Context) error { + err := p.db.WithContext(ctx).Model(DmProtocolService{}).Where("status = ? and updated_time