feat:完善项目信息

This commit is contained in:
henry
2022-01-05 18:40:08 +08:00
parent 53c1f3912b
commit 7488e9526b
15 changed files with 317 additions and 313 deletions

View File

@ -98,25 +98,25 @@ func (a *Tenant) MemberBind(c *gin.Context) {
Mobile string `json:"mobile" form:"mobile" binding:"required"` Mobile string `json:"mobile" form:"mobile" binding:"required"`
Password string `json:"password" form:"password" binding:"required"` Password string `json:"password" form:"password" binding:"required"`
}{} }{}
if err := bind(form)(c); err != nil { if err := api.Bind(form)(c); err != nil {
APIFailure(err.(error))(c) api.APIFailure(err.(error))(c)
return return
} }
err := tenant.NewMember()(api.GetSession()(c).(*session.Admin)).Form((&api.IDStringForm{ID: form.TenantID}).Convert(), err := tenant.NewMember()(api.GetSession()(c).(*session.Admin)).Form((&api.IDStringForm{ID: form.TenantID}).Convert(),
&tenant.MemberParams{Mobile: form.Mobile, Password: form.Password}) &tenant.MemberParams{Mobile: form.Mobile, Password: form.Password})
APIResponse(err)(c) api.APIResponse(err)(c)
} }
func (a *Tenant) Menu(c *gin.Context) { func (a *Tenant) Menu(c *gin.Context) {
form := &struct { form := &struct {
TenantID uint64 `json:"tenant_id" form:"tenant_id" binding:"required"` TenantID uint64 `json:"tenant_id" form:"tenant_id" binding:"required"`
}{} }{}
if err := bind(form)(c); err != nil { if err := api.Bind(form)(c); err != nil {
APIFailure(err.(error))(c) api.APIFailure(err.(error))(c)
return return
} }
data, err := tenant.NewMenu()(getSession()(c).(*service.Session)).List(form.TenantID) data, err := tenant.NewMenu()(getSession()(c).(*service.Session)).List(form.TenantID)
APIResponse(err, data)(c) api.APIResponse(err, data)(c)
} }
func (a *Tenant) MenuBind(c *gin.Context) { func (a *Tenant) MenuBind(c *gin.Context) {
@ -124,12 +124,12 @@ func (a *Tenant) MenuBind(c *gin.Context) {
TenantID uint64 `json:"tenant_id" form:"tenant_id" binding:"required"` TenantID uint64 `json:"tenant_id" form:"tenant_id" binding:"required"`
MenuIDs []uint64 `json:"menu_ids" form:"menu_ids" binding:"required"` MenuIDs []uint64 `json:"menu_ids" form:"menu_ids" binding:"required"`
}{} }{}
if err := bind(form)(c); err != nil { if err := api.Bind(form)(c); err != nil {
APIFailure(err.(error))(c) api.APIFailure(err.(error))(c)
return return
} }
err := tenant.NewMenu()(getSession()(c).(*service.Session)).Bind(form.TenantID, form.MenuIDs) err := tenant.NewMenu()(getSession()(c).(*service.Session)).Bind(form.TenantID, form.MenuIDs)
APIResponse(err)(c) api.APIResponse(err)(c)
} }
func (a *Tenant) AuthBind(c *gin.Context) { func (a *Tenant) AuthBind(c *gin.Context) {
@ -137,10 +137,10 @@ func (a *Tenant) AuthBind(c *gin.Context) {
TenantID uint64 `json:"tenant_id" form:"tenant_id" binding:"required"` TenantID uint64 `json:"tenant_id" form:"tenant_id" binding:"required"`
AuthIDs []uint64 `json:"auth_ids" form:"auth_ids" binding:"required"` AuthIDs []uint64 `json:"auth_ids" form:"auth_ids" binding:"required"`
}{} }{}
if err := bind(form)(c); err != nil { if err := api.Bind(form)(c); err != nil {
APIFailure(err.(error))(c) api.APIFailure(err.(error))(c)
return return
} }
err := tenant.NewAuth()(getSession()(c).(*service.Session)).Bind(form.TenantID, form.AuthIDs) err := tenant.NewAuth()(getSession()(c).(*service.Session)).Bind(form.TenantID, form.AuthIDs)
APIResponse(err)(c) api.APIResponse(err)(c)
} }

View File

@ -2,6 +2,7 @@ package api
import ( import (
user2 "SciencesServer/app/api/admin/controller/user" user2 "SciencesServer/app/api/admin/controller/user"
"SciencesServer/app/basic/api"
"SciencesServer/app/service" "SciencesServer/app/service"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
@ -39,7 +40,7 @@ func (a *User) List(c *gin.Context) {
APIFailure(err.(error))(c) APIFailure(err.(error))(c)
return return
} }
data, err := user2.NewInstance()(getSession()(c).(*service.Session)).List(form.Name, form.Mobile, form.Status, form.Page, form.PageSize) data, err := user2.NewInstance()(getSession()(c).(*service.Session)).Index(form.Name, form.Mobile, form.Status, form.Page, form.PageSize)
APIResponse(err, data)(c) APIResponse(err, data)(c)
} }
@ -148,18 +149,18 @@ func (a *User) Edit(c *gin.Context) {
* "data": null * "data": null
* } * }
*/ */
func (a *User) QuickPassword(c *gin.Context) { func (a *User) Password(c *gin.Context) {
form := &struct { form := &struct {
idForm api.IDStringForm
Password string `json:"password" form:"password" binding:"required"` Password string `json:"password" form:"password" binding:"required"`
RepeatPwd string `json:"repeat_pwd" form:"repeat_pwd" binding:"required"` RepeatPwd string `json:"repeat_pwd" form:"repeat_pwd" binding:"required"`
}{} }{}
if err := bind(form)(c); err != nil { if err := api.Bind(form)(c); err != nil {
APIFailure(err.(error))(c) api.APIFailure(err.(error))(c)
return return
} }
err := user2.NewInstance()(getSession()(c).(*service.Session)).Password(form.ID, form.Password, form.RepeatPwd) err := user2.NewInstance()(getSession()(c).(*service.Session)).Password(form.Convert(), form.Password, form.RepeatPwd)
APIResponse(err)(c) api.APIResponse(err)(c)
} }
/** /**
@ -186,7 +187,7 @@ func (a *User) QuickPassword(c *gin.Context) {
* "data": null * "data": null
* } * }
*/ */
func (a *User) EditPassword(c *gin.Context) { func (a *User) PasswordEdit(c *gin.Context) {
form := &struct { form := &struct {
OldPwd string `json:"original_pwd" form:"original_pwd" binding:"required"` OldPwd string `json:"original_pwd" form:"original_pwd" binding:"required"`
Password string `json:"password" form:"password" binding:"required"` Password string `json:"password" form:"password" binding:"required"`

View File

@ -68,7 +68,7 @@ func loginForSmsCaptcha(params *AccountLoginParams, tenantID uint64) (*model.Sys
mSysUser := model.NewSysUser() mSysUser := model.NewSysUser()
isExist, err := model2.FirstField(mSysUser.SysUser, []string{ isExist, err := model2.FirstField(mSysUser.SysUser, []string{
"id", "tenant_id", "name", "mobile", "is_admin", "status", "id", "uuid", "tenant_id", "name", "mobile", "is_admin", "status",
}, model2.NewWhere("tenant_id", tenantID), model2.NewWhere("mobile", params.Account)) }, model2.NewWhere("tenant_id", tenantID), model2.NewWhere("mobile", params.Account))
if err != nil { if err != nil {
@ -105,7 +105,7 @@ func (c *Account) Login(mode int, params *AccountLoginParams, equipment, ip stri
_session.Token = utils.JWTEncrypt(config.SettingInfo.TokenEffectTime, map[string]interface{}{config.TokenForUID: _uid}) _session.Token = utils.JWTEncrypt(config.SettingInfo.TokenEffectTime, map[string]interface{}{config.TokenForUID: _uid})
service.Publish(config.EventForRedisHashProduce, config.RedisKeyForAccountAdmin, _uid, _session) service.Publish(config.EventForRedisHashProduce, config.RedisKeyForAccountAdmin, _uid, _session)
service.Publish(config.EventForAccountLoginProduce, data.TenantID, _session.UID, equipment, ip) service.Publish(config.EventForAccountLoginProduce, data.TenantID, data.ID, equipment, ip)
return &AccountLoginResponse{Token: _session.Token, EffectTime: config.SettingInfo.TokenEffectTime}, nil return &AccountLoginResponse{Token: _session.Token, EffectTime: config.SettingInfo.TokenEffectTime}, nil
} }

View File

@ -2,16 +2,13 @@ package user
import ( import (
"SciencesServer/app/api/admin/controller" "SciencesServer/app/api/admin/controller"
model3 "SciencesServer/app/api/admin/model" "SciencesServer/app/api/admin/model"
model2 "SciencesServer/app/common/model" model2 "SciencesServer/app/common/model"
"SciencesServer/app/service" "SciencesServer/app/service"
"SciencesServer/serve/orm" "SciencesServer/config"
"SciencesServer/utils" "SciencesServer/utils"
"errors" "errors"
"strings"
"time" "time"
"gorm.io/gorm"
) )
type Instance struct{ *controller.Platform } type Instance struct{ *controller.Platform }
@ -21,16 +18,18 @@ type InstanceHandle func(session *service.Session) *Instance
type ( type (
// InstanceInfo 基本信息 // InstanceInfo 基本信息
InstanceInfo struct { InstanceInfo struct {
ID string `json:"id"`
InstanceUserInfo
Gender model2.GenderKind `json:"gender"`
IsAdmin model2.SysUserAdministrator `json:"is_admin"`
CreatedAt time.Time `json:"created_at"`
}
// InstanceUserInfo 用户信息
InstanceUserInfo struct {
UID string `json:"uid"` UID string `json:"uid"`
Name string `json:"name"` Name string `json:"name"`
Email string `json:"email"` Email string `json:"email"`
Mobile string `json:"mobile"` Mobile string `json:"mobile"`
Remark string `json:"remark"`
}
// InstanceUserInfo 用户信息
InstanceUserInfo struct {
*model3.SysUserTenantUser
UID string `json:"uid"`
} }
) )
@ -43,45 +42,64 @@ type InstanceForm struct {
} }
// Info 用户信息 // Info 用户信息
func (c *Instance) Info() (*InstanceInfo, error) { func (c *Instance) Info() (*InstanceUserInfo, error) {
mSysUser := model3.NewSysUser() mSysUser := model.NewSysUser()
_, err := model2.FirstWhere(mSysUser.SysUser, model2.NewWhere("uuid", c.UID)) _, err := model2.FirstWhere(mSysUser.SysUser, model2.NewWhere("uuid", c.UID))
if err != nil { if err != nil {
return nil, err return nil, err
} }
return &InstanceInfo{ return &InstanceUserInfo{
UID: mSysUser.UUIDString(), Name: mSysUser.Name, Email: mSysUser.Email, Mobile: mSysUser.Mobile, Remark: mSysUser.Remark, UID: mSysUser.UUIDString(), Name: mSysUser.Name, Email: mSysUser.Email, Mobile: mSysUser.Mobile,
}, nil }, nil
} }
// List 列表信息 // Index 列表信息
func (c *Instance) List(name, mobile string, status, page, pageSize int) (*controller.ReturnPages, error) { func (c *Instance) Index(name, mobile string, status, page, pageSize int) (*controller.ReturnPages, error) {
mSysUserTenant := model3.NewSysUserTenant() where := []*model2.ModelWhereOrder{&model2.ModelWhereOrder{
Where: model2.NewWhere("tenant_id", c.TenantID),
where := []*model2.ModelWhere{model2.NewWhere("u_t.tenant_id", c.TenantID)} Order: model2.NewOrder("id", model2.OrderModeToDesc),
}}
if name != "" { if name != "" {
where = append(where, model2.NewWhereLike("u.name", name)) where = append(where, &model2.ModelWhereOrder{
Where: model2.NewWhereLike("name", name),
})
} }
if mobile != "" { if mobile != "" {
where = append(where, model2.NewWhereLike("u.mobile", mobile)) where = append(where, &model2.ModelWhereOrder{
Where: model2.NewWhereLike("mobile", mobile),
})
} }
if status > 0 { if status > 0 {
where = append(where, model2.NewWhere("u_t.status", status)) where = append(where, &model2.ModelWhereOrder{
Where: model2.NewWhere("status", status),
})
} }
mSysUser := model.NewSysUser()
out := make([]*model2.SysUser, 0)
var count int64 var count int64
out, err := mSysUserTenant.User(page, pageSize, &count, where...) if err := model2.PagesFields(mSysUser.SysUser, out, []string{"id", "uid", "account", "name", "mobile", "gender",
"is_admin", "created_at"}, page, pageSize, &count, where...); err != nil {
if err != nil {
return nil, err return nil, err
} }
list := make([]*InstanceUserInfo, 0) list := make([]*InstanceInfo, 0)
for _, v := range out { for _, v := range out {
list = append(list, &InstanceUserInfo{SysUserTenantUser: v, UID: utils.UintToString(v.UID)}) list = append(list, &InstanceInfo{ID: v.GetEncodeID(),
InstanceUserInfo: InstanceUserInfo{
UID: v.UUIDString(),
Name: v.Name,
Email: v.Email,
Mobile: v.Mobile,
},
Gender: v.Gender.Gender,
IsAdmin: v.IsAdmin,
CreatedAt: v.CreatedAt,
})
} }
return &controller.ReturnPages{Data: list, Count: count}, nil return &controller.ReturnPages{Data: list, Count: count}, nil
} }
@ -89,20 +107,18 @@ func (c *Instance) List(name, mobile string, status, page, pageSize int) (*contr
// Add 添加用户 // Add 添加用户
func (c *Instance) Add(params *InstanceForm) error { func (c *Instance) Add(params *InstanceForm) error {
if utils.ValidateMobile(params.Mobile) { if utils.ValidateMobile(params.Mobile) {
return errors.New("手机号码格式错误") return errors.New("操作错误,手机号码格式错误")
} }
mSysUser := model3.NewSysUser() mSysUser := model.NewSysUser()
// 查询登录账户或手机号码是否注册 // 查询登录账户或手机号码是否注册
var count int64 var count int64
err := model2.Count(mSysUser.SysUser, &count, model2.NewWhere("account", params.Account)) err := model2.Count(mSysUser.SysUser, &count, model2.NewWhere("mobile", params.Mobile),
model2.NewWhere("tenant_id", c.TenantID))
if err != nil { if err != nil {
return err return err
} }
if err = model2.Count(mSysUser.SysUser, &count, model2.NewWhere("mobile", params.Mobile)); err != nil {
return err
}
mSysUser.Account = params.Account mSysUser.Account = params.Account
mSysUser.Name = params.Name mSysUser.Name = params.Name
mSysUser.Mobile = params.Mobile mSysUser.Mobile = params.Mobile
@ -110,136 +126,111 @@ func (c *Instance) Add(params *InstanceForm) error {
mSysUser.Password = params.Password mSysUser.Password = params.Password
mSysUser.Remark = params.Remark mSysUser.Remark = params.Remark
return orm.GetDB().Transaction(func(tx *gorm.DB) error { return model2.Create(mSysUser.SysUser)
if err = model2.Create(mSysUser.SysUser, tx); err != nil {
return err
}
mSysUserTenant := model3.NewSysUserTenant()
mSysUserTenant.TenantID = c.TenantID
mSysUserTenant.UID = mSysUser.UUID
if len(params.Departments) > 0 {
mSysUserTenant.Department = strings.Join(utils.ArrayStrings(params.Departments), ",")
}
if len(params.Roles) > 0 {
mSysUserTenant.Role = strings.Join(utils.ArrayStrings(params.Roles), ",")
}
mSysUserTenant.Identity = model2.SysUserTenantIdentityForSystemUser
if err = model2.Create(mSysUserTenant.SysUserTenant, tx); err != nil {
return err
}
return nil
})
} }
// Edit 修改用户信息 // Edit 修改用户信息
func (c *Instance) Edit(params *InstanceForm) error { func (c *Instance) Edit(params *InstanceForm) error {
if utils.ValidateMobile(params.Mobile) { mSysUser := model.NewSysUser()
return errors.New("手机号码格式错误") mSysUser.ID = params.ID
}
mSysUserTenant := model3.NewSysUserTenant()
mSysUserTenant.ID = params.ID
isExist, err := model2.FirstField(mSysUserTenant.SysUserTenant, []string{"id", "tenant_id", "identity"}) isExist, err := model2.First(mSysUser.SysUser)
if err != nil { if err != nil {
return nil return nil
} else if !isExist { } else if !isExist {
return errors.New("用户信息不存在") return errors.New("操作错误,用户信息不存在或已被删除")
} else if mSysUserTenant.TenantID != c.TenantID { } else if c.TenantID > 0 && mSysUser.TenantID != c.TenantID {
return errors.New("不可修改他人用户信息") return errors.New("操作错误,无权限操作")
} }
// 查询用户信息 if mSysUser.Mobile != params.Mobile {
mSysUser := model3.NewSysUser() if utils.ValidateMobile(params.Mobile) {
return errors.New("操作错误,手机号码格式错误")
if isExist, err = model2.FirstWhere(mSysUser.SysUser, model2.NewWhere("uuid", mSysUserTenant.UID)); err != nil { }
return err
} else if !isExist {
return errors.New("用户信息不存在")
}
if params.Mobile != mSysUser.Mobile {
var count int64 var count int64
if err = model2.Count(mSysUser.SysUser, &count, model2.NewWhere("mobile", params.Mobile)); err != nil { if err = model2.Count(mSysUser.SysUser, &count, model2.NewWhere("mobile", params.Mobile),
return err model2.NewWhere("tenant_id", c.TenantID)); err != nil {
return nil
} else if count > 0 { } else if count > 0 {
return errors.New("手机号码已注册") return errors.New("操作错误,当前手机号码已注册")
} }
mSysUser.Mobile = params.Mobile
} }
now := time.Now() mSysUser.Account = params.Account
return orm.GetDB().Transaction(func(tx *gorm.DB) error { mSysUser.Name = params.Name
if err = model2.Updates(mSysUserTenant.SysUserTenant, map[string]interface{}{ mSysUser.Gender.Gender = model2.GenderKind(params.Gender)
"department": strings.Join(utils.ArrayStrings(params.Departments), ","), mSysUser.Remark = params.Remark
"role": strings.Join(utils.ArrayStrings(params.Roles), ","),
"updated_at": now, return model2.Updates(mSysUser.SysUser, mSysUser.SysUser)
}, tx); err != nil {
return err
}
if err = model2.Updates(mSysUser.SysUser, map[string]interface{}{
"name": params.Name, "mobile": params.Mobile, "gender": params.Gender, "remark": params.Remark, "updated_at": now,
}, tx); err != nil {
return err
}
return nil
})
} }
func (c *Instance) Password(id uint64, password, repeatPwd string) error { func (c *Instance) Password(id uint64, password, repeatPwd string) error {
if password != repeatPwd { if password != repeatPwd {
return errors.New("两次密码不一致") return errors.New("操作错误,两次密码输入不一致")
} }
mSysUserTenant := model3.NewSysUserTenant() mSysUser := model.NewSysUser()
mSysUserTenant.ID = id
isExist, err := model2.FirstField(mSysUserTenant.SysUserTenant, []string{"id", "tenant_id", "identity"}) isExist, err := model2.FirstField(mSysUser.SysUser, []string{"id", "uuid", "is_admin"})
if err != nil { if err != nil {
return nil return nil
} else if !isExist { } else if !isExist {
return errors.New("用户信息不存在") return errors.New("操作错误,用户信息不存在或已被删除")
} else if mSysUserTenant.TenantID != c.TenantID { } else if c.TenantID > 0 && mSysUser.TenantID != c.TenantID {
return errors.New("不可修改他人用户密码") return errors.New("操作错误,无权限操作")
} }
mSysUser := model3.NewSysUser()
mSysUser.Password = password mSysUser.Password = password
mSysUser.Pass() mSysUser.Pass()
if err = model2.UpdatesWhere(mSysUser.SysUser, map[string]interface{}{ return model2.Updates(mSysUser.SysUser, map[string]interface{}{
"password": mSysUser.Password, "salt": mSysUser.Salt, "updated_at": time.Now(), "password": mSysUser.Password, "salt": mSysUser.Salt, "updated_at": time.Now(),
}, []*model2.ModelWhere{ })
model2.NewWhere("uuid", mSysUserTenant.UID), }
}); err != nil {
// PasswordEdit 主动修改密码
func (c *Person) PasswordEdit(oldPassword, password, repeatPwd string) error {
if password != repeatPwd {
return errors.New("操作错误,两次密码输入不一致")
}
mSysUser := model.NewSysUser()
_, err := model2.FirstField(mSysUser.SysUser, []string{"id", "uuid", "is_admin"}, model2.NewWhere("uuid", c.UID))
if err != nil {
return err return err
} }
return nil if !mSysUser.ValidatePassword(oldPassword) {
return errors.New("操作错误,旧密码输入错误")
}
mSysUser.Password = password
mSysUser.Pass()
return model2.Updates(mSysUser.SysUser, map[string]interface{}{
"password": mSysUser.Password, "salt": mSysUser.Salt, "updated_at": time.Now(),
})
} }
func (c *Instance) Delete(id uint64) error { func (c *Instance) Delete(id uint64) error {
mSysUserTenant := model3.NewSysUserTenant() mSysUser := model.NewSysUser()
mSysUserTenant.ID = id mSysUser.ID = id
isExist, err := model2.FirstField(mSysUserTenant.SysUserTenant, []string{"id", "tenant_id", "identity"}) isExist, err := model2.FirstField(mSysUser.SysUser, []string{"id", "uuid", "is_admin"})
if err != nil { if err != nil {
return nil return nil
} else if !isExist { } else if !isExist {
return errors.New("用户信息不存在") return errors.New("操作错误,用户信息不存在或已被删除")
} else if mSysUserTenant.TenantID != c.TenantID { } else if c.TenantID > 0 && mSysUser.TenantID != c.TenantID {
return errors.New("不可删除他人用户信息") return errors.New("操作错误,无权限操作")
} else if mSysUser.IsAdminUser() {
return errors.New("操作错误,超管用户不允许删除")
} }
return orm.GetDB().Transaction(func(tx *gorm.DB) error { if err = model2.Delete(mSysUser.SysUser); err != nil {
if err = model2.Delete(mSysUserTenant.SysUserTenant, tx); err != nil { return err
return err }
} service.Publish(config.EventForRedisHashDestroy, config.RedisKeyForAccountAdmin, utils.UintToString(mSysUser.UUID))
mSysUser := model3.NewSysUser() return nil
if err = model2.DeleteWhere(mSysUser.SysUser, []*model2.ModelWhere{
model2.NewWhere("uuid", mSysUserTenant.UID),
}, tx); err != nil {
return err
}
return nil
})
} }
func NewInstance() InstanceHandle { func NewInstance() InstanceHandle {

View File

@ -3,8 +3,7 @@ package user
import ( import (
"SciencesServer/app/api/admin/controller" "SciencesServer/app/api/admin/controller"
menu2 "SciencesServer/app/api/admin/controller/menu" menu2 "SciencesServer/app/api/admin/controller/menu"
model3 "SciencesServer/app/api/admin/model" "SciencesServer/app/api/admin/model"
model2 "SciencesServer/app/common/model"
"SciencesServer/app/service" "SciencesServer/app/service"
) )
@ -14,23 +13,24 @@ type MenuHandle func(session *service.Session) *Menu
// List 菜单列表 // List 菜单列表
func (c *Menu) List() (interface{}, error) { func (c *Menu) List() (interface{}, error) {
mSysMenu := model3.NewSysMenu() mSysMenu := model.NewSysMenu()
if c.IsAdmin { if c.IsAdmin {
return menu2.MenuForSystem(mSysMenu) return menu2.MenuForSystem(mSysMenu)
} }
mSysUserTenant := model3.NewSysUserTenant() //mSysUserTenant := model.NewSysUserTenant()
//
if isExist, err := model2.FirstField(mSysUserTenant.SysUserTenant, []string{"id", "identity"}, //if isExist, err := model2.FirstField(mSysUserTenant.SysUserTenant, []string{"id", "identity"},
model2.NewWhere("tenant_id", c.TenantID), model2.NewWhere("uid", c.UID)); err != nil { // model2.NewWhere("tenant_id", c.TenantID), model2.NewWhere("uid", c.UID)); err != nil {
return nil, err // return nil, err
} else if !isExist { //} else if !isExist {
return nil, nil // return nil, nil
} //}
if mSysUserTenant.Identity == model2.SysUserTenantIdentityForSystemAdmin { //if mSysUserTenant.Identity == model2.SysUserTenantIdentityForSystemAdmin {
return menu2.MenuForTenant(mSysMenu, c.TenantID) // return menu2.MenuForTenant(mSysMenu, c.TenantID)
} //}
return menu2.MenuForUser(mSysMenu, c.TenantID, c.UID) //return menu2.MenuForUser(mSysMenu, c.TenantID, c.UID)
return nil, nil
} }
func NewMenu() MenuHandle { func NewMenu() MenuHandle {

View File

@ -24,7 +24,7 @@ func (m *SysUser) IsAdminUser() bool {
func (m *SysUser) GetByAccountOrMobile(account string, tenantID uint64) (bool, error) { func (m *SysUser) GetByAccountOrMobile(account string, tenantID uint64) (bool, error) {
db := orm.GetDB().Table(m.TableName()). db := orm.GetDB().Table(m.TableName()).
Select("id", "tenant_id", "name", "mobile", "password", "salt", "is_admin", "status"). Select("id", "uuid", "tenant_id", "name", "mobile", "password", "salt", "is_admin", "status").
Where("tenant_id = ?", tenantID). Where("tenant_id = ?", tenantID).
Where("(account = ? OR mobile = ?)", account, account). Where("(account = ? OR mobile = ?)", account, account).
Where("is_deleted = ?", model.DeleteStatusForNot) Where("is_deleted = ?", model.DeleteStatusForNot)

View File

@ -1,83 +0,0 @@
package model
import (
"SciencesServer/app/common/model"
"SciencesServer/serve/orm"
"fmt"
)
type SysUserTenant struct {
*model.SysUserTenant
}
type (
// SysUserTenantBasic 基本信息
SysUserTenantBasic struct {
ID uint64 `json:"id"`
Name string `json:"name"`
Mobile string `json:"mobile"`
Status model.AccountStatus `json:"status"`
}
// SysUserTenantUser 用户信息
SysUserTenantUser struct {
*SysUserTenantBasic
UID uint64 `json:"uid"`
Email string `json:"email"`
Identity model.SysUserTenantIdentity `json:"identity"`
Remark string `json:"remark"`
}
)
// Member 成员信息
func (m *SysUserTenant) Member(page, pageSize int, count *int64, where ...*model.ModelWhere) ([]*SysUserTenantBasic, error) {
mSysUser := NewSysUser()
db := orm.GetDB().Table(m.TableName()+" AS u_t").
Select("u_t.id, u.name, u.mobile, u_t.status").
Joins(fmt.Sprintf("LEFT JOIN %s AS u ON u_t.uid = u.uuid", mSysUser.TableName())).
Where("u_t.is_deleted = ? AND u.is_deleted = ?", model.DeleteStatusForNot, model.DeleteStatusForNot)
if len(where) > 0 {
for _, wo := range where {
db = db.Where(wo.Condition, wo.Value)
}
}
out := make([]*SysUserTenantBasic, 0)
if err := db.Count(count).Error; err != nil {
return nil, err
}
if err := db.Order("u_t.id " + model.OrderModeToDesc).Offset((page - 1) * pageSize).Limit(pageSize).Scan(&out).Error; err != nil {
return nil, err
}
return out, nil
}
// User 用户信息
func (m *SysUserTenant) User(page, pageSize int, count *int64, where ...*model.ModelWhere) ([]*SysUserTenantUser, error) {
mSysUser := NewSysUser()
db := orm.GetDB().Table(m.TableName()+" AS u_t").
Select("u_t.id, u_t.uid, u.name, u.mobile, u.email, u_t.identity, u_t.status, u.remark, u_t.created_at").
Joins(fmt.Sprintf("LEFT JOIN %s AS u ON u_t.uid = u.uuid", mSysUser.TableName())).
Where("u_t.is_deleted = ? AND u.is_deleted = ?", model.DeleteStatusForNot, model.DeleteStatusForNot)
if len(where) > 0 {
for _, wo := range where {
db = db.Where(wo.Condition, wo.Value)
}
}
out := make([]*SysUserTenantUser, 0)
if err := db.Count(count).Error; err != nil {
return nil, err
}
if err := db.Order("u_t.id " + model.OrderModeToDesc).Offset((page - 1) * pageSize).Limit(pageSize).Scan(&out).Error; err != nil {
return nil, err
}
return out, nil
}
func NewSysUserTenant() *SysUserTenant {
return &SysUserTenant{SysUserTenant: model.NewSysUserTenant()}
}

View File

@ -1 +1,21 @@
package api package api
import (
"SciencesServer/app/api/website/controller"
"SciencesServer/app/basic/api"
"github.com/gin-gonic/gin"
)
type Config struct{}
func (*Config) Area(c *gin.Context) {
form := &struct {
Code string `json:"code" form:"code"`
}{}
if err := api.Bind(form)(c); err != nil {
api.APIFailure(err.(error))(c)
return
}
data := controller.NewConfig()(nil).Area(form.Code)
api.APIResponse(nil, data)(c)
}

View File

@ -9,6 +9,71 @@ import (
type Index struct{} type Index struct{}
func (*Index) Instance(c *gin.Context) { func (*Index) Instance(c *gin.Context) {
data, err := controller.NewIndex()(nil, "").Instance() data, err := controller.NewIndex()(nil).Instance()
api.APIResponse(err, data)(c)
}
func (*Index) DistributionExpert(c *gin.Context) {
form := &struct {
Province string `json:"province" form:"province"`
City string `json:"city" form:"city"`
}{}
if err := api.Bind(form)(c); err != nil {
api.APIFailure(err.(error))(c)
return
}
data, err := controller.NewIndex()(nil).DistributionExpert(form.Province, form.City)
api.APIResponse(err, data)(c)
}
func (*Index) DistributionLaboratory(c *gin.Context) {
form := &struct {
Province string `json:"province" form:"province"`
City string `json:"city" form:"city"`
}{}
if err := api.Bind(form)(c); err != nil {
api.APIFailure(err.(error))(c)
return
}
data, err := controller.NewIndex()(nil).DistributionLaboratory(form.Province, form.City)
api.APIResponse(err, data)(c)
}
func (*Index) DistributionDemand(c *gin.Context) {
form := &struct {
Province string `json:"province" form:"province"`
City string `json:"city" form:"city"`
}{}
if err := api.Bind(form)(c); err != nil {
api.APIFailure(err.(error))(c)
return
}
data, err := controller.NewIndex()(nil).DistributionDemand(form.Province, form.City)
api.APIResponse(err, data)(c)
}
func (*Index) DistributionPatent(c *gin.Context) {
form := &struct {
Province string `json:"province" form:"province"`
City string `json:"city" form:"city"`
}{}
if err := api.Bind(form)(c); err != nil {
api.APIFailure(err.(error))(c)
return
}
data, err := controller.NewIndex()(nil).DistributionPatent(form.Province, form.City)
api.APIResponse(err, data)(c)
}
func (*Index) DistributionAchievement(c *gin.Context) {
form := &struct {
Province string `json:"province" form:"province"`
City string `json:"city" form:"city"`
}{}
if err := api.Bind(form)(c); err != nil {
api.APIFailure(err.(error))(c)
return
}
data, err := controller.NewIndex()(nil).DistributionAchievement(form.Province, form.City)
api.APIResponse(err, data)(c) api.APIResponse(err, data)(c)
} }

View File

@ -1,19 +1,29 @@
package controller package controller
import ( import (
"SciencesServer/app/service" "SciencesServer/app/basic/config"
"SciencesServer/app/session"
config2 "SciencesServer/config"
) )
type Config struct{ *service.Session } type Config struct{ *session.Admin }
type ConfigHandle func(session *service.Session) *Config type ConfigHandle func(session *session.Admin) *Config
func (c *Config) Basic() { func (c *Config) Basic() {
} }
// Area 区域信息
func (c *Config) Area(key string) map[string]string {
if key == "" {
key = config2.DefaultChinaAreaCode
}
return config.MemoryForAreaInfo[key]
}
func NewConfig() ConfigHandle { func NewConfig() ConfigHandle {
return func(session *service.Session) *Config { return func(session *session.Admin) *Config {
return &Config{Session: session} return &Config{Admin: session}
} }
} }

View File

@ -12,10 +12,9 @@ import (
type Index struct { type Index struct {
*service.Session *service.Session
local string
} }
type IndexHandle func(session *service.Session, local string) *Index type IndexHandle func(session *service.Session) *Index
type ( type (
// InstanceInfo 首页信息 // InstanceInfo 首页信息
@ -152,10 +151,10 @@ func (c *Index) static() (*InstanceStaticInfo, error) {
return out, nil return out, nil
} }
// distributionExpert 专家分布 // DistributionExpert 专家分布
func (c *Index) distributionExpert() (map[string]*InstanceDistributionDetailInfo, error) { func (c *Index) DistributionExpert(province, city string) (map[string]*InstanceDistributionDetailInfo, error) {
mManageExpert := model.NewManageExpert() mManageExpert := model.NewManageExpert()
out, err := mManageExpert.Distribution() out, err := mManageExpert.Distribution(province, city)
if err != nil { if err != nil {
return nil, err return nil, err
@ -163,8 +162,8 @@ func (c *Index) distributionExpert() (map[string]*InstanceDistributionDetailInfo
return c.distribution(out), nil return c.distribution(out), nil
} }
// distributionLaboratory 实验室分布 // DistributionLaboratory 实验室分布
func (c *Index) distributionLaboratory() (map[string]*InstanceDistributionDetailInfo, error) { func (c *Index) DistributionLaboratory(province, city string) (map[string]*InstanceDistributionDetailInfo, error) {
mManageLaboratory := model.NewManageLaboratory() mManageLaboratory := model.NewManageLaboratory()
out, err := mManageLaboratory.Distribution() out, err := mManageLaboratory.Distribution()
@ -174,8 +173,8 @@ func (c *Index) distributionLaboratory() (map[string]*InstanceDistributionDetail
return c.distribution(out), nil return c.distribution(out), nil
} }
// distributionDemand 需求信息 // DistributionDemand 需求信息
func (c *Index) distributionDemand() (map[string]*InstanceDistributionDetailInfo, error) { func (c *Index) DistributionDemand(province, city string) (map[string]*InstanceDistributionDetailInfo, error) {
mTechnologyDemand := model.NewTechnologyDemand() mTechnologyDemand := model.NewTechnologyDemand()
out, err := mTechnologyDemand.Distribution() out, err := mTechnologyDemand.Distribution()
@ -185,8 +184,8 @@ func (c *Index) distributionDemand() (map[string]*InstanceDistributionDetailInfo
return c.distribution(out), nil return c.distribution(out), nil
} }
// distributionPatent 专利信息 // DistributionPatent 专利信息
func (c *Index) distributionPatent() (map[string]*InstanceDistributionDetailInfo, error) { func (c *Index) DistributionPatent(province, city string) (map[string]*InstanceDistributionDetailInfo, error) {
mSysPatent := model.NewSysPatent() mSysPatent := model.NewSysPatent()
out, err := mSysPatent.Distribution() out, err := mSysPatent.Distribution()
@ -196,8 +195,8 @@ func (c *Index) distributionPatent() (map[string]*InstanceDistributionDetailInfo
return c.distribution(out), nil return c.distribution(out), nil
} }
// distributionAchievement 技术成果信息 // DistributionAchievement 技术成果信息
func (c *Index) distributionAchievement() (map[string]*InstanceDistributionDetailInfo, error) { func (c *Index) DistributionAchievement(province, city string) (map[string]*InstanceDistributionDetailInfo, error) {
mSysPatent := model.NewSysPatent() mSysPatent := model.NewSysPatent()
out, err := mSysPatent.Distribution() out, err := mSysPatent.Distribution()
@ -218,34 +217,13 @@ func (c *Index) Instance() (*InstanceInfo, error) {
if out.InstanceStaticInfo, err = c.static(); err != nil { if out.InstanceStaticInfo, err = c.static(); err != nil {
return nil, err return nil, err
} }
// 专家区域分布信息
if out.Distribution.Expert, err = c.distributionExpert(); err != nil {
return nil, err
}
// 实验室区域分布信息
if out.Distribution.Laboratory, err = c.distributionLaboratory(); err != nil {
return nil, err
}
// 需求信息区域分布信息
if out.Distribution.Demand, err = c.distributionDemand(); err != nil {
return nil, err
}
// 专利信息区域分布信息
if out.Distribution.Patent, err = c.distributionPatent(); err != nil {
return nil, err
}
// 成果信息区域分布信息
if out.Distribution.Achievement, err = c.distributionAchievement(); err != nil {
return nil, err
}
return out, nil return out, nil
} }
func NewIndex() IndexHandle { func NewIndex() IndexHandle {
return func(session *service.Session, local string) *Index { return func(session *service.Session) *Index {
return &Index{ return &Index{
Session: session, Session: session,
local: local,
} }
} }
} }

View File

@ -74,13 +74,14 @@ FROM %s AS u LEFT JOIN %s AS p ON u.parent_id = p.id WHERE u.is_deleted = %d AND
} }
// Distribution 分布信息 // Distribution 分布信息
func (m *ManageExpert) Distribution() ([]*DataAreaDistributionInfo, error) { func (m *ManageExpert) Distribution(province, city string) ([]*DataAreaDistributionInfo, error) {
out := make([]*DataAreaDistributionInfo, 0) out := make([]*DataAreaDistributionInfo, 0)
err := orm.GetDB().Table(m.TableName()). db := orm.GetDB().Table(m.TableName()).
Select("province", "city", "GROUP_CONCAT(industry SEPARATOR '&') AS industry"). Select("province", "city", "district", "GROUP_CONCAT(industry SEPARATOR '&') AS industry").
Group("province").Group("city"). Group("province").Group("city").Group("district")
Order("province "+model.OrderModeToAsc).Order("city "+model.OrderModeToAsc).
err := db.Order("province "+model.OrderModeToAsc).Order("city "+model.OrderModeToAsc).Order("district "+model.OrderModeToAsc).
Where("examine_status = ?", model.ExamineStatusForAgree). Where("examine_status = ?", model.ExamineStatusForAgree).
Scan(&out).Error Scan(&out).Error

View File

@ -32,8 +32,12 @@ func GetSession() ApiHandle {
func GetTenantID() ApiHandle { func GetTenantID() ApiHandle {
return func(c *gin.Context) interface{} { return func(c *gin.Context) interface{} {
value, _ := c.Get(config.ContentForTenantID) _, isExist := c.Get(config.ContentForTenantID)
return value //value
if !isExist {
return 0
}
return uint64(0)
} }
} }

View File

@ -30,9 +30,9 @@ func (this *Instance) Handle() {
if !db.Migrator().HasTable(v.iModel) { if !db.Migrator().HasTable(v.iModel) {
err := db.Migrator().CreateTable(v.iModel) err := db.Migrator().CreateTable(v.iModel)
if err != nil { if err != nil {
successCount++
} else {
failureCount++ failureCount++
} else {
successCount++
} }
if v.iValues != nil && v.iValues() != nil { if v.iValues != nil && v.iValues() != nil {
db.Table(v.iModel.TableName()).Create(v.iValues()) db.Table(v.iModel.TableName()).Create(v.iValues())
@ -47,8 +47,9 @@ func (this *Instance) Handle() {
&synchronized{iModel: model.NewSysConfig()}, &synchronized{iModel: model.NewSysConfig()},
&synchronized{iModel: model.NewSysMenu()}, &synchronized{iModel: model.NewSysAuth()}, &synchronized{iModel: model.NewSysMenu()}, &synchronized{iModel: model.NewSysAuth()},
&synchronized{iModel: model.NewSysUser(), iValues: func() interface{} { &synchronized{iModel: model.NewSysUser(), iValues: func() interface{} {
return &model.SysUser{Account: "admin", Name: "商挈智能", Mobile: "13888888888", Password: utils.Md5String("123456"), return &model.SysUser{Account: "admin", Name: "商挈智能", Mobile: "13888888888",
IsAdmin: model.SysUserAdministratorForAdmin, Remark: "超级管理员"} Password: utils.Md5String("123456"),
IsAdmin: model.SysUserAdministratorForAdmin, Remark: "超级管理员"}
}}, }},
&synchronized{iModel: model.NewSysUserRole()}, &synchronized{iModel: model.NewSysUserTenant()}, &synchronized{iModel: model.NewSysUserRole()}, &synchronized{iModel: model.NewSysUserTenant()},
&synchronized{iModel: model.NewSysDepartment()}, &synchronized{iModel: model.NewSysDepartment()},
@ -141,7 +142,10 @@ func (this *Instance) Handle() {
&synchronized{iModel: model.NewActivityInstance()}, &synchronized{iModel: model.NewActivityApply()}, &synchronized{iModel: model.NewActivityInstance()}, &synchronized{iModel: model.NewActivityApply()},
&synchronized{iModel: model.NewActivityExamine()}, &synchronized{iModel: model.NewActivityJoin()}, &synchronized{iModel: model.NewActivityExamine()}, &synchronized{iModel: model.NewActivityJoin()},
) )
fmt.Printf("========================\n=== 数据迁移,成功【%d】失败【%d】 ===\n========================\n", successCount, failureCount) fmt.Println("=== 数据迁移 ===")
fmt.Printf("=== 成功【%d】 ===\n", successCount)
fmt.Printf("=== 失败【%d】 ===\n", failureCount)
fmt.Println("========================")
} }
func WithGormDBOption(db *gorm.DB) Option { func WithGormDBOption(db *gorm.DB) Option {

View File

@ -28,6 +28,17 @@ func registerAPI(app *gin.Engine) {
{ {
_api := new(api2.Index) _api := new(api2.Index)
indexV1.GET("", _api.Instance) indexV1.GET("", _api.Instance)
indexV1.GET("/distribution/expert", _api.DistributionExpert)
indexV1.GET("/distribution/laboratory", _api.DistributionLaboratory)
indexV1.GET("/distribution/demand", _api.DistributionDemand)
indexV1.GET("/distribution/patent", _api.DistributionPatent)
indexV1.GET("/distribution/achievement", _api.DistributionAchievement)
}
// Config 首页信息管理
configV1 := v1.Group("/config")
{
_api := new(api2.Config)
configV1.POST("area", _api.Area)
} }
// User 用户信息管理 // User 用户信息管理
userV1 := v1.Group("/user") userV1 := v1.Group("/user")
@ -121,11 +132,13 @@ func registerAdminAPI(app *gin.Engine) {
apiPrefix := "/admin" apiPrefix := "/admin"
g := app.Group(apiPrefix) g := app.Group(apiPrefix)
v1 := g.Group("/v1")
// 登录验证 // 登录验证
g.Use(NeedLogin(config.RedisKeyForAccountAdmin, session.NewAdmin(), AddSkipperURL([]string{ g.Use(NeedLogin(config.RedisKeyForAccountAdmin, session.NewAdmin(), AddSkipperURL([]string{
apiPrefix + "/captcha", apiPrefix + "/v1/captcha",
apiPrefix + "/account/login", apiPrefix + "/v1/account/login",
apiPrefix + "/account/logout", apiPrefix + "/v1/account/logout",
}...))) }...)))
// 权限验证 // 权限验证
//g.Use(NeedPermission(AddSkipperURL([]string{ //g.Use(NeedPermission(AddSkipperURL([]string{
@ -134,18 +147,18 @@ func registerAdminAPI(app *gin.Engine) {
// apiPrefix + "/account/logout", // apiPrefix + "/account/logout",
//}...))) //}...)))
// Captcha 验证码 // Captcha 验证码
g.GET("/captcha", new(api1.Captcha).Captcha) v1.GET("/captcha", new(api1.Captcha).Captcha)
// Upload 上传管理 // Upload 上传管理
g.POST("/upload", new(api.Upload).Upload) v1.POST("/upload", new(api.Upload).Upload)
// Account 账户管理 // Account 账户管理
account := g.Group("/account") account := v1.Group("/account")
{ {
_api := new(api1.Account) _api := new(api1.Account)
account.POST("/login", _api.Login) account.POST("/login", _api.Login)
account.POST("/logout", _api.Logout) account.POST("/logout", _api.Logout)
} }
// User 用户管理 // User 用户管理
user := g.Group("/user") user := v1.Group("/user")
{ {
_api := new(api1.User) _api := new(api1.User)
user.GET("/info", _api.Info) user.GET("/info", _api.Info)
@ -154,13 +167,13 @@ func registerAdminAPI(app *gin.Engine) {
user.POST("/add", _api.Add) user.POST("/add", _api.Add)
user.POST("/edit", _api.Edit) user.POST("/edit", _api.Edit)
user.POST("/delete", _api.Delete) user.POST("/delete", _api.Delete)
user.POST("/edit/password", _api.EditPassword) user.POST("/password", _api.Password)
user.POST("/password/quick", _api.QuickPassword) user.POST("/password/edit", _api.PasswordEdit)
user.POST("/role", _api.Role) user.POST("/role", _api.Role)
user.POST("/role/bind", _api.RoleBind) user.POST("/role/bind", _api.RoleBind)
} }
// Tenant 租户管理 // Tenant 租户管理
tenant := g.Group("/tenant") tenant := v1.Group("/tenant")
{ {
_api := new(api1.Tenant) _api := new(api1.Tenant)
tenant.POST("/", _api.Instance) tenant.POST("/", _api.Instance)
@ -174,7 +187,7 @@ func registerAdminAPI(app *gin.Engine) {
tenant.POST("/auth/bind", _api.AuthBind) tenant.POST("/auth/bind", _api.AuthBind)
} }
// Menu 菜单管理 // Menu 菜单管理
menu := g.Group("/menu") menu := v1.Group("/menu")
{ {
_api := new(api1.Menu) _api := new(api1.Menu)
menu.GET("/list", _api.List) menu.GET("/list", _api.List)
@ -184,13 +197,13 @@ func registerAdminAPI(app *gin.Engine) {
menu.POST("/delete", _api.Delete) menu.POST("/delete", _api.Delete)
} }
// Auth 权限管理 // Auth 权限管理
auth := g.Group("/auth") auth := v1.Group("/auth")
{ {
_api := new(api1.Auth) _api := new(api1.Auth)
auth.POST("/list", _api.List) auth.POST("/list", _api.List)
} }
// Department 部门管理 // Department 部门管理
department := g.Group("/department") department := v1.Group("/department")
{ {
_api := new(api1.Department) _api := new(api1.Department)
department.GET("/list", _api.List) department.GET("/list", _api.List)
@ -200,7 +213,7 @@ func registerAdminAPI(app *gin.Engine) {
department.POST("/delete", _api.Delete) department.POST("/delete", _api.Delete)
} }
// Role 角色管理 // Role 角色管理
role := g.Group("/role") role := v1.Group("/role")
{ {
_api := new(api1.Role) _api := new(api1.Role)
role.POST("/list", _api.List) role.POST("/list", _api.List)
@ -215,7 +228,7 @@ func registerAdminAPI(app *gin.Engine) {
role.POST("/auth/bind", _api.AuthBind) role.POST("/auth/bind", _api.AuthBind)
} }
// Logs 日志管理 // Logs 日志管理
log := g.Group("/log") log := v1.Group("/log")
{ {
_api := new(api1.Log) _api := new(api1.Log)
log.POST("/login", _api.Login) log.POST("/login", _api.Login)