feat:完善项目信息

This commit is contained in:
henry
2022-01-13 17:48:41 +08:00
parent 4637a5fb4b
commit 27cb063a6c
11 changed files with 85 additions and 79 deletions

View File

@ -45,6 +45,12 @@ type (
}
)
func (c *Instance) checkIsExist(iModel model2.IModel, where ...*model2.ModelWhere) (bool, error) {
var count int64
err := model2.Count(iModel, &count, where...)
return count > 0, err
}
// Index 首页列表信息
func (c *Instance) Index(name string, page, pageSize int) (*controller.ReturnPages, error) {
mSysTenant := model.NewSysTenant()
@ -110,6 +116,8 @@ func (c *Instance) Select() (map[string]*InstanceSelectInfo, error) {
func (c *Instance) Form(params *InstanceParams) error {
mSysTenant := model.NewSysTenant()
isExist := false
if params.ID > 0 {
mSysTenant.ID = params.ID
@ -122,7 +130,12 @@ func (c *Instance) Form(params *InstanceParams) error {
}
if mSysTenant.Province != params.Area.Province || mSysTenant.City != params.Area.City {
// TODO:查询区域是否存在租户平台
if isExist, err = c.checkIsExist(mSysTenant.SysTenant, model2.NewWhere("province", params.Area.Province),
model2.NewWhere("city", params.Area.City)); err != nil {
return err
} else if isExist {
return errors.New("操作错误,该区域下已存在平台信息")
}
}
}
mSysTenant.Name = params.Name
@ -137,10 +150,21 @@ func (c *Instance) Form(params *InstanceParams) error {
if mSysTenant.ID > 0 {
return model2.Updates(mSysTenant.SysTenant, mSysTenant.SysTenant)
}
if !utils.ValidateUrl(params.Domain) {
return errors.New("操作错误,域名地址信息错误")
}
mSysTenant.Key = utils.GetRandomString(12)
mSysTenant.Domain = params.Domain
if err := model2.Create(mSysTenant.SysTenant); err != nil {
var err error
if isExist, err = c.checkIsExist(mSysTenant.SysTenant, model2.NewWhere("province", params.Area.Province),
model2.NewWhere("city", params.Area.City)); err != nil {
return err
} else if isExist {
return errors.New("操作错误,该区域下已存在平台信息")
}
if err = model2.Create(mSysTenant.SysTenant); err != nil {
return err
}
_session := session.NewTenant()