feat:完善信息
This commit is contained in:
@ -9,7 +9,6 @@ import (
|
||||
"SciencesServer/app/service"
|
||||
"SciencesServer/config"
|
||||
"SciencesServer/serve/orm"
|
||||
"SciencesServer/utils"
|
||||
"errors"
|
||||
"fmt"
|
||||
"time"
|
||||
@ -25,7 +24,6 @@ type (
|
||||
// InstanceInfo 租户信息
|
||||
InstanceInfo struct {
|
||||
*model.SysTenantInfo
|
||||
Config *model2.SysTenantConfig `json:"config"`
|
||||
}
|
||||
// InstanceParams 租户参数信息
|
||||
InstanceParams struct {
|
||||
@ -72,7 +70,7 @@ func basic(id uint64) func(args ...interface{}) (interface{}, error) {
|
||||
}
|
||||
return &InstanceInfo{SysTenantInfo: &model.SysTenantInfo{
|
||||
SysTenant: mSysTenant.SysTenant,
|
||||
}, Config: mSysTenant.ConfigInfo()}, nil
|
||||
}}, nil
|
||||
}
|
||||
}
|
||||
|
||||
@ -165,7 +163,7 @@ func (c *Instance) List(name string, status, page, pageSize int) (*controller.Re
|
||||
for _, v := range out {
|
||||
v.Image.Image = v.Image.Analysis(config.SettingInfo.Domain)
|
||||
|
||||
list = append(list, &InstanceInfo{SysTenantInfo: v, Config: v.ConfigInfo()})
|
||||
list = append(list, &InstanceInfo{SysTenantInfo: v})
|
||||
}
|
||||
return &controller.ReturnPages{Data: list, Page: page, TotalCount: count}, nil
|
||||
}
|
||||
@ -194,8 +192,6 @@ func (c *Instance) Add(params *InstanceParams) error {
|
||||
if err = orm.GetDB().Transaction(func(tx *gorm.DB) error {
|
||||
mSysTenant.Image.Image = params.Image
|
||||
mSysTenant.Name = params.Name
|
||||
mSysTenant.Config = utils.AnyToJSON(&model2.SysTenantConfig{MaxDevices: 0, MaxCustomer: 0, Protocol: 0})
|
||||
mSysTenant.Deadline = utils.DateTimeToTime(params.Deadline + " 23:59:59")
|
||||
mSysTenant.Remark = params.Remark
|
||||
|
||||
if err = model2.Create(mSysTenant.SysTenant, tx); err != nil {
|
||||
@ -220,7 +216,6 @@ func (c *Instance) Add(params *InstanceParams) error {
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
service.Publish(config.EventForRedisListProduce, config.RedisKeyForTenant, mSysTenant.Key)
|
||||
|
||||
return nil
|
||||
}
|
||||
@ -338,20 +333,9 @@ func (c *Instance) Renewal(id uint64, deadline string) error {
|
||||
updates := make(map[string]interface{}, 0)
|
||||
updates["updated_at"] = now
|
||||
|
||||
_deadline := utils.DateTimeToTime(deadline + " 23:59:59")
|
||||
|
||||
if _deadline.Before(mSysTenant.Deadline) {
|
||||
return errors.New("续期时间异常")
|
||||
}
|
||||
updates["deadline"] = _deadline
|
||||
|
||||
if mSysTenant.Status != model2.SysTenantStatusForNormal && _deadline.After(now) {
|
||||
updates["status"] = model2.SysTenantStatusForNormal
|
||||
}
|
||||
if err = model2.Updates(mSysTenant.SysTenant, updates); err != nil {
|
||||
return err
|
||||
}
|
||||
service.Publish(config.EventForRedisListProduce, config.RedisKeyForTenant, mSysTenant.Key)
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -372,19 +356,8 @@ func (c *Instance) StartUp(id uint64) error {
|
||||
} else if c.TenantID != mSysTenant.ParentID {
|
||||
return errors.New("不可启用其他租户/公司客户")
|
||||
}
|
||||
} else if mSysTenant.Status == model2.SysTenantStatusForNormal {
|
||||
return errors.New("该租户/公司/客户已是启用状态")
|
||||
}
|
||||
status := model2.SysTenantStatusForNormal
|
||||
|
||||
now := time.Now()
|
||||
|
||||
if mSysTenant.Deadline.Before(now) {
|
||||
status = model2.SysTenantStatusForExpired
|
||||
}
|
||||
if err = model2.Updates(mSysTenant.SysTenant, map[string]interface{}{
|
||||
"status": status, "updated_at": now,
|
||||
}); err != nil {
|
||||
if err = model2.Updates(mSysTenant.SysTenant, map[string]interface{}{}); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
@ -392,31 +365,31 @@ func (c *Instance) StartUp(id uint64) error {
|
||||
|
||||
// Disable 禁用处理
|
||||
func (c *Instance) Disable(id uint64) error {
|
||||
mSysTenant := model.NewSysTenant()
|
||||
mSysTenant.ID = id
|
||||
//mSysTenant := model.NewSysTenant()
|
||||
//mSysTenant.ID = id
|
||||
//
|
||||
//isExist, err := model2.FirstWhere(mSysTenant.SysTenant)
|
||||
|
||||
isExist, err := model2.FirstWhere(mSysTenant.SysTenant)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
} else if !isExist {
|
||||
return errors.New("租户/公司/客户信息不存在")
|
||||
} else if c.TenantID > 0 {
|
||||
if mSysTenant.ParentID <= 0 {
|
||||
return errors.New("非超级管理员,不可操作")
|
||||
} else if c.TenantID != mSysTenant.ParentID {
|
||||
return errors.New("不可启用其他租户/公司/客户")
|
||||
}
|
||||
} else if mSysTenant.Status == model2.SysTenantStatusForDisable {
|
||||
return errors.New("该租户/公司/客户已是禁用状态")
|
||||
}
|
||||
if err = model2.Updates(mSysTenant.SysTenant, map[string]interface{}{
|
||||
"status": model2.SysTenantStatusForDisable, "updated_at": time.Now(),
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
// TODO:推送用户强制退出,并强行删除所有产品数据
|
||||
service.Publish(config.EventForRedisListDestroy, config.RedisKeyForTenant, mSysTenant.Key)
|
||||
//if err != nil {
|
||||
// return err
|
||||
//} else if !isExist {
|
||||
// return errors.New("租户/公司/客户信息不存在")
|
||||
//} else if c.TenantID > 0 {
|
||||
// if mSysTenant.ParentID <= 0 {
|
||||
// return errors.New("非超级管理员,不可操作")
|
||||
// } else if c.TenantID != mSysTenant.ParentID {
|
||||
// return errors.New("不可启用其他租户/公司/客户")
|
||||
// }
|
||||
//} else if mSysTenant.Status == model2.SysTenantStatusForDisable {
|
||||
// return errors.New("该租户/公司/客户已是禁用状态")
|
||||
//}
|
||||
//if err = model2.Updates(mSysTenant.SysTenant, map[string]interface{}{
|
||||
// "status": model2.SysTenantStatusForDisable, "updated_at": time.Now(),
|
||||
//}); err != nil {
|
||||
// return err
|
||||
//}
|
||||
//// TODO:推送用户强制退出,并强行删除所有产品数据
|
||||
//service.Publish(config.EventForRedisListDestroy, config.RedisKeyForTenant, mSysTenant.Key)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user