feat:完善信息

This commit is contained in:
henry
2021-10-13 14:35:24 +08:00
parent 21dc62ba8e
commit 8866b83cfb
16 changed files with 4728 additions and 46 deletions

View File

@ -1,6 +1,10 @@
package model package model
// SysIndustry 行业领域数据模型
type SysIndustry struct { type SysIndustry struct {
Model
ModelDeleted
ModelAt
} }
func (*SysIndustry) TableName() string { func (*SysIndustry) TableName() string {

View File

@ -0,0 +1,16 @@
package model
// SysResearch 研究领域数据模型
type SysResearch struct {
Model
ModelDeleted
ModelAt
}
func (*SysResearch) TableName() string {
return "sys_research"
}
func NewSysResearch() *SysResearch {
return &SysResearch{}
}

View File

@ -43,7 +43,7 @@ func (a *Account) Login(c *gin.Context) {
Password string Password string
}{Mobile: form.Mobile, Password: form.Password}, }{Mobile: form.Mobile, Password: form.Password},
}) })
api.APIResponse(err, data) api.APIResponse(err, data)(c)
} }
func (a *Account) Register(c *gin.Context) { func (a *Account) Register(c *gin.Context) {
@ -57,7 +57,7 @@ func (a *Account) Register(c *gin.Context) {
Name: form.Name, Mobile: form.Mobile, Captcha: form.Captcha, Name: form.Name, Mobile: form.Mobile, Captcha: form.Captcha,
Password: form.Password, RepeatPass: form.RepeatPass, Identity: form.Identity, Password: form.Password, RepeatPass: form.RepeatPass, Identity: form.Identity,
}) })
api.APIResponse(err, data) api.APIResponse(err, data)(c)
} }
func (a *Account) BindMobile() { func (a *Account) BindMobile() {

View File

@ -2,17 +2,34 @@ package api
import ( import (
"SciencesServer/app/basic/api" "SciencesServer/app/basic/api"
"SciencesServer/app/enterprise/controller" "SciencesServer/app/enterprise/controller/config"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
) )
type Config struct{} type Config struct{}
func (a *Config) Identity(c *gin.Context) { func (a *Config) Identity(c *gin.Context) {
data := controller.NewConfig().Identity() data := config.NewConfig().Identity()
api.APISuccess(data)
}
func (a *Config) Transaction(c *gin.Context) {
data := config.NewConfig().Transaction()
api.APISuccess(data) api.APISuccess(data)
} }
func (a *Config) Industry(c *gin.Context) { func (a *Config) Industry(c *gin.Context) {
} }
func (a *Config) Area(c *gin.Context) {
form := &struct {
Key string `json:"key" form:"key"`
}{}
if err := api.Bind(form)(c); err != nil {
api.APIFailure(err.(error))(c)
return
}
data := config.NewConfig().Area(form.Key)
api.APIResponse(nil, data)(c)
}

View File

@ -33,7 +33,7 @@ func (a *Technology) Paper(c *gin.Context) {
} }
data, err := technology.NewPaper()(api.GetSession()(c).(*service.SessionEnterprise), api.GetLocal()(c).(uint64)). data, err := technology.NewPaper()(api.GetSession()(c).(*service.SessionEnterprise), api.GetLocal()(c).(uint64)).
List(form.Title, form.Page, form.PageSize) List(form.Title, form.Page, form.PageSize)
api.APIResponse(err, data) api.APIResponse(err, data)(c)
} }
func (a *Technology) PaperAdd(c *gin.Context) { func (a *Technology) PaperAdd(c *gin.Context) {
@ -48,7 +48,7 @@ func (a *Technology) PaperAdd(c *gin.Context) {
Title: form.Title, Ext: form.Ext, Author: form.Author, PublishAt: form.PublishAt, Title: form.Title, Ext: form.Ext, Author: form.Author, PublishAt: form.PublishAt,
Keyword: form.Keyword, Tags: form.Tags, Remark: form.Remark, Keyword: form.Keyword, Tags: form.Tags, Remark: form.Remark,
}) })
api.APIResponse(err) api.APIResponse(err)(c)
} }
func (a *Technology) PaperEdit(c *gin.Context) { func (a *Technology) PaperEdit(c *gin.Context) {
@ -65,7 +65,7 @@ func (a *Technology) PaperEdit(c *gin.Context) {
ID: form.Convert(), Title: form.Title, Ext: form.Ext, Author: form.Author, PublishAt: form.PublishAt, ID: form.Convert(), Title: form.Title, Ext: form.Ext, Author: form.Author, PublishAt: form.PublishAt,
Keyword: form.Keyword, Tags: form.Tags, Remark: form.Remark, Keyword: form.Keyword, Tags: form.Tags, Remark: form.Remark,
}) })
api.APIResponse(err) api.APIResponse(err)(c)
} }
func (a *Technology) PaperDelete(c *gin.Context) { func (a *Technology) PaperDelete(c *gin.Context) {
@ -77,5 +77,5 @@ func (a *Technology) PaperDelete(c *gin.Context) {
} }
err := technology.NewPaper()(api.GetSession()(c).(*service.SessionEnterprise), api.GetLocal()(c).(uint64)). err := technology.NewPaper()(api.GetSession()(c).(*service.SessionEnterprise), api.GetLocal()(c).(uint64)).
Delete(form.Convert()) Delete(form.Convert())
api.APIResponse(err) api.APIResponse(err)(c)
} }

View File

@ -16,7 +16,7 @@ func (a *User) Info(c *gin.Context) {
func (a *User) Detail(c *gin.Context) { func (a *User) Detail(c *gin.Context) {
data, err := user.NewInstance()(api.GetSession()(c).(*service.SessionEnterprise)).Detail() data, err := user.NewInstance()(api.GetSession()(c).(*service.SessionEnterprise)).Detail()
api.APIResponse(err, data) api.APIResponse(err, data)(c)
} }
func (a *User) SwitchIdentity(c *gin.Context) { func (a *User) SwitchIdentity(c *gin.Context) {
@ -28,5 +28,5 @@ func (a *User) SwitchIdentity(c *gin.Context) {
return return
} }
err := user.NewInstance()(api.GetSession()(c).(*service.SessionEnterprise)).SwitchIdentity(form.Identity) err := user.NewInstance()(api.GetSession()(c).(*service.SessionEnterprise)).SwitchIdentity(form.Identity)
api.APIResponse(err) api.APIResponse(err)(c)
} }

View File

@ -1,15 +0,0 @@
package controller
import (
"SciencesServer/app/basic/config"
)
type Config struct{}
func (c *Config) Identity() map[int]string {
return config.TenantUserIdentityData
}
func NewConfig() *Config {
return &Config{}
}

View File

@ -0,0 +1,50 @@
package config
import (
"SciencesServer/app/basic/config"
config2 "SciencesServer/config"
)
type Config struct{}
// Basic 基础配置信息
func (c *Config) Basic() {
}
// Config 配置信息
func (c *Config) Config() {
}
// Identity 身份信息
func (c *Config) Identity() map[int]string {
return config.TenantUserIdentityData
}
// Transaction 交易信息
func (c *Config) Transaction() map[int]string {
return config.TechnologyTransactionData
}
// Industry 行业信息
func (c *Config) Industry() {
}
// Research 研究领域信息
func (c *Config) Research() {
}
// Area 区域信息
func (c *Config) Area(key string) map[string]string {
if key == "" {
key = config2.DefaultChinaAreaCode
}
return config2.SettingAreaInfo[key]
}
func NewConfig() *Config {
return &Config{}
}

View File

@ -41,19 +41,19 @@ func (c *Instance) Info() *InstanceInfo {
func (c *Instance) Detail() (*InstanceDetailInfo, error) { func (c *Instance) Detail() (*InstanceDetailInfo, error) {
resp := &InstanceDetailInfo{InstanceInfo: InstanceInfo{Name: c.Name, Identity: c.Identity, SelectIdentity: c.SelectIdentity}} resp := &InstanceDetailInfo{InstanceInfo: InstanceInfo{Name: c.Name, Identity: c.Identity, SelectIdentity: c.SelectIdentity}}
mUserTenant := model.NewUserTenant() mUserManage := model.NewUserManage()
isExist, err := model2.FirstField(mUserTenant.UserTenant, []string{"id", "tenant_id", "uuid", "name", isExist, err := model2.FirstField(mUserManage.UserManage, []string{"id", "tenant_id", "uuid", "name",
"email", "job", "fixed_phone", "other"}, "email", "job", "fixed_phone", "other"},
model2.NewWhere("uid", c.UID), model2.NewWhere("identity", c.SelectIdentity)) model2.NewWhere("uid", c.UID), model2.NewWhere("identity", c.SelectIdentity))
if err != nil { if err != nil {
return nil, err return nil, err
} else if isExist { } else if isExist {
resp.Name = mUserTenant.Name resp.Name = mUserManage.Name
resp.Email = mUserTenant.Email resp.Email = mUserManage.Email
resp.Job = mUserTenant.Job resp.Job = mUserManage.Job
resp.FixedPhone = mUserTenant.FixedPhone resp.FixedPhone = mUserManage.FixedPhone
} }
return resp, nil return resp, nil
} }
@ -68,9 +68,9 @@ func (c *Instance) SwitchIdentity(identity int) error {
} }
// 已存在相应的身份,更新最后 // 已存在相应的身份,更新最后
if c.Identity&identity > 0 { if c.Identity&identity > 0 {
mUserTenant := model.NewUserTenant() mUserManage := model.NewUserManage()
// 查询用户身份 // 查询用户身份
_, err := model2.FirstField(mUserTenant.UserTenant, []string{"id", "tenant_id", "name", "uuid"}, _, err := model2.FirstField(mUserManage.UserManage, []string{"id", "tenant_id", "name", "uuid"},
model2.NewWhere("uid", c.UID), model2.NewWhere("identity", identity)) model2.NewWhere("uid", c.UID), model2.NewWhere("identity", identity))
if err != nil { if err != nil {
@ -79,22 +79,22 @@ func (c *Instance) SwitchIdentity(identity int) error {
// 查询用户身份信息 // 查询用户身份信息
now := time.Now() now := time.Now()
if mUserTenant.ID > 0 { if mUserManage.ID > 0 {
if err = orm.GetDB().Transaction(func(tx *gorm.DB) error { if err = orm.GetDB().Transaction(func(tx *gorm.DB) error {
if err = model2.UpdatesWhere(mUserTenant.UserTenant, map[string]interface{}{ if err = model2.UpdatesWhere(mUserManage.UserManage, map[string]interface{}{
"selected": model2.UserTenantSelectedForNo, "updated_at": now, "selected": model2.UserManageSelectedForNo, "updated_at": now,
}, []*model2.ModelWhere{model2.NewWhere("uid", c.TenantUID)}, tx); err != nil { }, []*model2.ModelWhere{model2.NewWhere("uid", c.TenantUID)}, tx); err != nil {
return err return err
} }
return model2.Updates(mUserTenant.UserTenant, map[string]interface{}{ return model2.Updates(mUserManage.UserManage, map[string]interface{}{
"selected": model2.UserTenantSelectedForYes, "updated_at": now, "selected": model2.UserManageSelectedForYes, "updated_at": now,
}, tx) }, tx)
}); err != nil { }); err != nil {
return err return err
} }
} }
c.TenantID = mUserTenant.TenantID c.TenantID = mUserManage.TenantID
c.TenantUID = mUserTenant.UUID c.TenantUID = mUserManage.UUID
} }
c.SelectIdentity = identity c.SelectIdentity = identity
service.Publish(config2.EventForAccountLoginProduce, config2.RedisKeyForAccount, c.UIDToString(), c.SessionEnterprise) service.Publish(config2.EventForAccountLoginProduce, config2.RedisKeyForAccount, c.UIDToString(), c.SessionEnterprise)

View File

@ -19,6 +19,6 @@ func Init() {
service.Subscribe(config.EventForAccountLoginProduce, event.NewAccountUserLoginProduce()) service.Subscribe(config.EventForAccountLoginProduce, event.NewAccountUserLoginProduce())
// 日志录入监听 // 日志录入监听
service.Subscribe(config.EventForSysLogProduce, event.NewSysLogProduce()) service.Subscribe(config.EventForSysLogProduce, event.NewSysLogProduce())
// 开启权限
service.NewAuth().Register()(config.SettingInfo.Engine.DBMode, orm.GetDB(), model.NewSysAuthRule().TableName()) service.NewAuth().Register()(config.SettingInfo.Engine.DBMode, orm.GetDB(), model.NewSysAuthRule().TableName())
} }

View File

@ -3,6 +3,7 @@ package config
var ( var (
SettingInfo = new(Setting) SettingInfo = new(Setting)
RPCServerSettingInfo = new(RPCServerSetting) RPCServerSettingInfo = new(RPCServerSetting)
SettingAreaInfo = make(map[string]map[string]string, 0)
) )
// Mysql 配置 // Mysql 配置

View File

@ -14,13 +14,16 @@ const (
const ( const (
TokenForUID string = "uid" TokenForUID string = "uid"
TokenForSession string = "session" TokenForSession string = "session"
ContentForLocal string = "local"
) )
const ( const (
APIRequestToken string = "x-token" APIRequestToken string = "x-token"
) )
const (
ContentForLocal string = "local"
)
const ( const (
EventForRedisHashProduce string = "redis_hash_produce" EventForRedisHashProduce string = "redis_hash_produce"
EventForRedisHashDestroy string = "redis_hash_destroy" EventForRedisHashDestroy string = "redis_hash_destroy"
@ -31,3 +34,7 @@ const (
EventForAccountLoginProduce string = "account_login_produce" EventForAccountLoginProduce string = "account_login_produce"
EventForSysLogProduce string = "sys_log_produce" EventForSysLogProduce string = "sys_log_produce"
) )
const (
DefaultChinaAreaCode string = "86"
)

4576
file/area.json Normal file

File diff suppressed because it is too large Load Diff

View File

@ -2,11 +2,12 @@ package router
import ( import (
api2 "SciencesServer/app/api/api" api2 "SciencesServer/app/api/api"
api3 "SciencesServer/app/enterprise/api"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
) )
func register(app *gin.Engine) { func registerAPi(app *gin.Engine) {
apiPrefix := "/api" apiPrefix := "/api"
g := app.Group(apiPrefix) g := app.Group(apiPrefix)
// 登录验证 // 登录验证
@ -112,3 +113,14 @@ func register(app *gin.Engine) {
log.POST("/login", _api.Login) log.POST("/login", _api.Login)
} }
} }
func registerEnterprise(app *gin.Engine) {
apiPrefix := "/enterprise"
g := app.Group(apiPrefix)
// Config 配置管理
config := g.Group("/config")
{
_api := new(api3.Config)
config.GET("/area", _api.Area)
}
}

View File

@ -55,7 +55,8 @@ func (this *Router) Init() *gin.Engine {
} }
app.StaticFS("/upload", http.Dir("./upload")) app.StaticFS("/upload", http.Dir("./upload"))
// 注册路由 // 注册路由
register(app) registerAPi(app)
registerEnterprise(app)
app.MaxMultipartMemory = 4 << 20 app.MaxMultipartMemory = 4 << 20

View File

@ -1,7 +1,20 @@
package tools package tools
import "SciencesServer/tools/ip" import (
"SciencesServer/config"
"SciencesServer/lib"
"SciencesServer/tools/ip"
)
func Init() { func initIP() {
_ = ip.Load("./file/ip_chunzhen.txt") _ = ip.Load("./file/ip_chunzhen.txt")
} }
func initJSON() {
lib.LoadConfig("./file/area.json", &config.SettingAreaInfo)
}
func Init() {
initIP()
initJSON()
}