瀏覽代碼

update

master
DengBiao 10 月之前
父節點
當前提交
eea7c349a0
共有 1 個檔案被更改,包括 15 行新增1 行删除
  1. +15
    -1
      rule/one_circles/one_circles_auto_release_green_energy.go

+ 15
- 1
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",


Loading…
取消
儲存