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
// SysIndustry 行业领域数据模型
type SysIndustry struct {
Model
ModelDeleted
ModelAt
}
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
}{Mobile: form.Mobile, Password: form.Password},
})
api.APIResponse(err, data)
api.APIResponse(err, data)(c)
}
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,
Password: form.Password, RepeatPass: form.RepeatPass, Identity: form.Identity,
})
api.APIResponse(err, data)
api.APIResponse(err, data)(c)
}
func (a *Account) BindMobile() {

View File

@ -2,17 +2,34 @@ package api
import (
"SciencesServer/app/basic/api"
"SciencesServer/app/enterprise/controller"
"SciencesServer/app/enterprise/controller/config"
"github.com/gin-gonic/gin"
)
type Config struct{}
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)
}
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)).
List(form.Title, form.Page, form.PageSize)
api.APIResponse(err, data)
api.APIResponse(err, data)(c)
}
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,
Keyword: form.Keyword, Tags: form.Tags, Remark: form.Remark,
})
api.APIResponse(err)
api.APIResponse(err)(c)
}
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,
Keyword: form.Keyword, Tags: form.Tags, Remark: form.Remark,
})
api.APIResponse(err)
api.APIResponse(err)(c)
}
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)).
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) {
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) {
@ -28,5 +28,5 @@ func (a *User) SwitchIdentity(c *gin.Context) {
return
}
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) {
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"},
model2.NewWhere("uid", c.UID), model2.NewWhere("identity", c.SelectIdentity))
if err != nil {
return nil, err
} else if isExist {
resp.Name = mUserTenant.Name
resp.Email = mUserTenant.Email
resp.Job = mUserTenant.Job
resp.FixedPhone = mUserTenant.FixedPhone
resp.Name = mUserManage.Name
resp.Email = mUserManage.Email
resp.Job = mUserManage.Job
resp.FixedPhone = mUserManage.FixedPhone
}
return resp, nil
}
@ -68,9 +68,9 @@ func (c *Instance) SwitchIdentity(identity int) error {
}
// 已存在相应的身份,更新最后
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))
if err != nil {
@ -79,22 +79,22 @@ func (c *Instance) SwitchIdentity(identity int) error {
// 查询用户身份信息
now := time.Now()
if mUserTenant.ID > 0 {
if mUserManage.ID > 0 {
if err = orm.GetDB().Transaction(func(tx *gorm.DB) error {
if err = model2.UpdatesWhere(mUserTenant.UserTenant, map[string]interface{}{
"selected": model2.UserTenantSelectedForNo, "updated_at": now,
if err = model2.UpdatesWhere(mUserManage.UserManage, map[string]interface{}{
"selected": model2.UserManageSelectedForNo, "updated_at": now,
}, []*model2.ModelWhere{model2.NewWhere("uid", c.TenantUID)}, tx); err != nil {
return err
}
return model2.Updates(mUserTenant.UserTenant, map[string]interface{}{
"selected": model2.UserTenantSelectedForYes, "updated_at": now,
return model2.Updates(mUserManage.UserManage, map[string]interface{}{
"selected": model2.UserManageSelectedForYes, "updated_at": now,
}, tx)
}); err != nil {
return err
}
}
c.TenantID = mUserTenant.TenantID
c.TenantUID = mUserTenant.UUID
c.TenantID = mUserManage.TenantID
c.TenantUID = mUserManage.UUID
}
c.SelectIdentity = identity
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.EventForSysLogProduce, event.NewSysLogProduce())
// 开启权限
service.NewAuth().Register()(config.SettingInfo.Engine.DBMode, orm.GetDB(), model.NewSysAuthRule().TableName())
}

View File

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

View File

@ -14,13 +14,16 @@ const (
const (
TokenForUID string = "uid"
TokenForSession string = "session"
ContentForLocal string = "local"
)
const (
APIRequestToken string = "x-token"
)
const (
ContentForLocal string = "local"
)
const (
EventForRedisHashProduce string = "redis_hash_produce"
EventForRedisHashDestroy string = "redis_hash_destroy"
@ -31,3 +34,7 @@ const (
EventForAccountLoginProduce string = "account_login_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 (
api2 "SciencesServer/app/api/api"
api3 "SciencesServer/app/enterprise/api"
"github.com/gin-gonic/gin"
)
func register(app *gin.Engine) {
func registerAPi(app *gin.Engine) {
apiPrefix := "/api"
g := app.Group(apiPrefix)
// 登录验证
@ -112,3 +113,14 @@ func register(app *gin.Engine) {
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"))
// 注册路由
register(app)
registerAPi(app)
registerEnterprise(app)
app.MaxMultipartMemory = 4 << 20

View File

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