From eea7c349a05bb2f36f8bc940b4c1001811e780b9 Mon Sep 17 00:00:00 2001 From: DengBiao <2319963317@qq.com> Date: Mon, 29 Jan 2024 14:55:20 +0800 Subject: [PATCH] update --- .../one_circles_auto_release_green_energy.go | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/rule/one_circles/one_circles_auto_release_green_energy.go b/rule/one_circles/one_circles_auto_release_green_energy.go index df4cb3d..4584af2 100644 --- a/rule/one_circles/one_circles_auto_release_green_energy.go +++ b/rule/one_circles/one_circles_auto_release_green_energy.go @@ -4,6 +4,7 @@ import ( "code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/db" "code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/db/model" "code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/md" + "code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/utils/cache" "errors" "fmt" "github.com/shopspring/decimal" @@ -11,13 +12,26 @@ import ( "xorm.io/xorm" ) +const LockKey = "auto_release_exchange_green_energy_lock_key" + // AutoReleaseExchangeGreenEnergy 结算绿色能量自动释放成可用绿色能量 func AutoReleaseExchangeGreenEnergy(engine *xorm.Engine, masterId string) (err error) { now := time.Now() - if now.Hour() > 1 && now.Hour() > 8 { + if now.Hour() > 1 && now.Hour() < 8 { //TODO::只在凌晨一点 ~ 凌晨 8 点运行 return errors.New("非运行时间") } + //TODO::增加“悲观锁”防止串行 + getString, _ := cache.GetString(LockKey) + //if err != nil { + // return err + //} + if getString != "" { + fmt.Println("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!", "上一次结算未执行完") + return errors.New("上一次结算未执行完") + } + cache.SetEx(LockKey, "running", 3600*8) //8小时 + //1、查找 `one_circles_green_energy_basic_setting` 基础设置 && `one_circles_public_platoon_basic_setting` 基础设置 oneCirclesGreenEnergyBasicSetting, err := db.OneCirclesGreenEnergyBasicSettingGetOneByParams(engine, map[string]interface{}{ "key": "is_open",