init
This commit is contained in:
@ -3,7 +3,6 @@ package api
|
|||||||
import (
|
import (
|
||||||
account2 "SciencesServer/app/api/enterprise/controller/account"
|
account2 "SciencesServer/app/api/enterprise/controller/account"
|
||||||
"SciencesServer/app/basic/api"
|
"SciencesServer/app/basic/api"
|
||||||
"SciencesServer/app/service"
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -12,7 +11,7 @@ type Account struct{}
|
|||||||
type (
|
type (
|
||||||
accountLoginForm struct {
|
accountLoginForm struct {
|
||||||
Mode int `json:"mode" form:"mode" binding:"required"`
|
Mode int `json:"mode" form:"mode" binding:"required"`
|
||||||
Mobile string `json:"mobile" form:"mobile"`
|
Account string `json:"account" form:"account"`
|
||||||
Captcha string `json:"captcha" form:"captcha"`
|
Captcha string `json:"captcha" form:"captcha"`
|
||||||
Password string `json:"password" form:"password"`
|
Password string `json:"password" form:"password"`
|
||||||
}
|
}
|
||||||
@ -37,11 +36,11 @@ func (a *Account) Login(c *gin.Context) {
|
|||||||
Captcha: struct {
|
Captcha: struct {
|
||||||
Mobile string
|
Mobile string
|
||||||
Captcha string
|
Captcha string
|
||||||
}{Mobile: form.Mobile, Captcha: form.Captcha},
|
}{Mobile: form.Account, Captcha: form.Captcha},
|
||||||
Password: struct {
|
Password: struct {
|
||||||
Mobile string
|
Account string
|
||||||
Password string
|
Password string
|
||||||
}{Mobile: form.Mobile, Password: form.Password},
|
}{Account: form.Account, Password: form.Password},
|
||||||
})
|
})
|
||||||
api.APIResponse(err, data)(c)
|
api.APIResponse(err, data)(c)
|
||||||
}
|
}
|
||||||
@ -60,18 +59,20 @@ func (a *Account) Register(c *gin.Context) {
|
|||||||
api.APIResponse(err, data)(c)
|
api.APIResponse(err, data)(c)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *Account) BindMobile(c *gin.Context) {
|
func (*Account) Authorize(c *gin.Context) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func (*Account) BindMobile(c *gin.Context) {
|
||||||
//account.NewOther()().BindMobile()
|
//account.NewOther()().BindMobile()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *Account) Logout(c *gin.Context) {
|
func (*Account) Logout(c *gin.Context) {
|
||||||
handle := api.GetSession()(c)
|
// 因跳过中间键,故只能自己去获取token用户信息
|
||||||
|
//token := c.GetHeader(config.APIRequestToken)
|
||||||
|
|
||||||
session := new(service.SessionEnterprise)
|
//session, _ := service.NewAuthToken(token).Auth()
|
||||||
|
|
||||||
if handle != nil {
|
err := account2.NewLogout()(nil).Launch()
|
||||||
session = handle.(*service.SessionEnterprise)
|
|
||||||
}
|
|
||||||
err := account2.NewLogout()(session).Launch()
|
|
||||||
api.APIResponse(err)(c)
|
api.APIResponse(err)(c)
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@ type (
|
|||||||
Mobile, Captcha string
|
Mobile, Captcha string
|
||||||
}
|
}
|
||||||
Password struct {
|
Password struct {
|
||||||
Mobile, Password string
|
Account, Password string
|
||||||
}
|
}
|
||||||
Platform struct {
|
Platform struct {
|
||||||
OpenID string
|
OpenID string
|
||||||
@ -88,13 +88,13 @@ RETURNS:
|
|||||||
|
|
||||||
// loginForPassword 密码登陆
|
// loginForPassword 密码登陆
|
||||||
func loginForPassword(params *LoginParams, local string) (*InstanceLoginParams, error) {
|
func loginForPassword(params *LoginParams, local string) (*InstanceLoginParams, error) {
|
||||||
if !utils.ValidateMobile(params.Password.Mobile) {
|
if !utils.ValidateMobile(params.Password.Account) {
|
||||||
return nil, errors.New("手机号码格式异常")
|
return nil, errors.New("手机号码格式异常")
|
||||||
}
|
}
|
||||||
mUserInstance := model3.NewUserInstance()
|
mUserInstance := model3.NewUserInstance()
|
||||||
|
|
||||||
isExist, err := model2.FirstField(mUserInstance.UserInstance, []string{"id", "uuid", "mobile", "password", "salt", "status"},
|
isExist, err := model2.FirstField(mUserInstance.UserInstance, []string{"id", "uuid", "mobile", "password", "salt", "status"},
|
||||||
model2.NewWhere("mobile", params.Password.Mobile), model2.NewWhere("local", local))
|
model2.NewWhere("mobile", params.Password.Account), model2.NewWhere("local", local))
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -13,7 +13,7 @@ type Logout struct {
|
|||||||
type LogoutHandle func(enterprise *service.SessionEnterprise) *Logout
|
type LogoutHandle func(enterprise *service.SessionEnterprise) *Logout
|
||||||
|
|
||||||
func (c *Logout) Launch() error {
|
func (c *Logout) Launch() error {
|
||||||
if c.UID > 0 {
|
if c.SessionEnterprise != nil && c.UID > 0 {
|
||||||
service.Publish(config.EventForRedisHashDestroy, config.RedisKeyForAccount, utils.UintToString(c.UID))
|
service.Publish(config.EventForRedisHashDestroy, config.RedisKeyForAccount, utils.UintToString(c.UID))
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
@ -62,6 +62,7 @@ func (c *Register) Launch(params *RegisterParams) (*InstanceLoginReturn, error)
|
|||||||
return nil, errors.New("当前手机号码已注册")
|
return nil, errors.New("当前手机号码已注册")
|
||||||
}
|
}
|
||||||
mUserInstance.Local.Local = c.local
|
mUserInstance.Local.Local = c.local
|
||||||
|
mUserInstance.Source = model2.UserInstanceSourceForLocal
|
||||||
mUserInstance.Password = utils.GetRandomString(12)
|
mUserInstance.Password = utils.GetRandomString(12)
|
||||||
mUserInstance.Mobile = params.Mobile
|
mUserInstance.Mobile = params.Mobile
|
||||||
mUserInstance.Password = params.Password
|
mUserInstance.Password = params.Password
|
||||||
|
@ -24,7 +24,7 @@ type (
|
|||||||
|
|
||||||
// Expert 专家数据
|
// Expert 专家数据
|
||||||
func (m *UserManage) Expert(page, pageSize int, count *int64, where ...*model.ModelWhere) ([]*UserManageForExpert, error) {
|
func (m *UserManage) Expert(page, pageSize int, count *int64, where ...*model.ModelWhere) ([]*UserManageForExpert, error) {
|
||||||
query := orm.GetDB().Table(m.TableName()+" AS m").
|
db := orm.GetDB().Table(m.TableName()+" AS m").
|
||||||
Select(strings.Join([]string{"m.id", "m.name", "u.mobile", "m.identity_info"}, ",")).
|
Select(strings.Join([]string{"m.id", "m.name", "u.mobile", "m.identity_info"}, ",")).
|
||||||
Joins(fmt.Sprintf("LEFT JOIN %s AS u ON m.uid = u.uuid", model.NewUserInstance().TableName())).
|
Joins(fmt.Sprintf("LEFT JOIN %s AS u ON m.uid = u.uuid", model.NewUserInstance().TableName())).
|
||||||
Where("m.is_deleted = ?", model.DeleteStatusForNot).
|
Where("m.is_deleted = ?", model.DeleteStatusForNot).
|
||||||
@ -34,13 +34,13 @@ func (m *UserManage) Expert(page, pageSize int, count *int64, where ...*model.Mo
|
|||||||
|
|
||||||
if len(where) > 0 {
|
if len(where) > 0 {
|
||||||
for _, v := range where {
|
for _, v := range where {
|
||||||
query = query.Where(v.Condition, v.Value)
|
db = db.Where(v.Condition, v.Value)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if err := query.Count(count).Error; err != nil {
|
if err := db.Count(count).Error; err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if err := query.Order("m.id " + model.OrderModeToDesc).Offset((page - 1) * pageSize).Limit(pageSize).Scan(&out).Error; err != nil {
|
if err := db.Order("m.id " + model.OrderModeToDesc).Offset((page - 1) * pageSize).Limit(pageSize).Scan(&out).Error; err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return out, nil
|
return out, nil
|
||||||
|
@ -3,6 +3,7 @@ package api
|
|||||||
import (
|
import (
|
||||||
"SciencesServer/app/api/manage/controller"
|
"SciencesServer/app/api/manage/controller"
|
||||||
"SciencesServer/app/service"
|
"SciencesServer/app/service"
|
||||||
|
"SciencesServer/config"
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
)
|
)
|
||||||
@ -77,13 +78,11 @@ func (a *Account) Login(c *gin.Context) {
|
|||||||
* }
|
* }
|
||||||
*/
|
*/
|
||||||
func (a *Account) Logout(c *gin.Context) {
|
func (a *Account) Logout(c *gin.Context) {
|
||||||
handle := getSession()(c)
|
// 因跳过中间键,故只能自己去获取token用户信息
|
||||||
|
token := c.GetHeader(config.APIRequestToken)
|
||||||
|
|
||||||
session := new(service.Session)
|
session, _ := service.NewAuthToken(token).Auth()
|
||||||
|
|
||||||
if handle != nil {
|
|
||||||
session = handle.(*service.Session)
|
|
||||||
}
|
|
||||||
err := controller.NewAccount()(session).Logout()
|
err := controller.NewAccount()(session).Logout()
|
||||||
APIResponse(err)(c)
|
APIResponse(err)(c)
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,9 @@
|
|||||||
package api
|
package api
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"SciencesServer/app/api/manage/controller/manage"
|
||||||
"SciencesServer/app/basic/api"
|
"SciencesServer/app/basic/api"
|
||||||
|
"SciencesServer/app/service"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -11,7 +13,26 @@ func (*Manage) Company(c *gin.Context) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (*Manage) CompanyExamine(c *gin.Context) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
func (*Manage) Expert(c *gin.Context) {
|
func (*Manage) Expert(c *gin.Context) {
|
||||||
|
form := &struct {
|
||||||
|
Name string `json:"name" form:"name"`
|
||||||
|
Status int `json:"status" form:"status"`
|
||||||
|
api.PageForm
|
||||||
|
}{}
|
||||||
|
if err := api.Bind(form)(c); err != nil {
|
||||||
|
api.APIFailure(err.(error))(c)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
data, err := manage.NewInstance()(api.GetSession()(c).(*service.Session), api.GetLocal()(c).(string)).
|
||||||
|
Expert(form.Name, form.Status, form.Page, form.PageSize)
|
||||||
|
api.APIResponse(err, data)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (*Manage) ExpertExamine(c *gin.Context) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -27,9 +48,13 @@ func (*Menu) Examine(c *gin.Context) {
|
|||||||
form := &struct {
|
form := &struct {
|
||||||
api.IDStringForm
|
api.IDStringForm
|
||||||
Identity int `json:"identity" form:"identity" binding:"required"`
|
Identity int `json:"identity" form:"identity" binding:"required"`
|
||||||
|
Status int `json:"status" form:"status" binding:"required"`
|
||||||
}{}
|
}{}
|
||||||
if err := api.Bind(form)(c); err != nil {
|
if err := api.Bind(form)(c); err != nil {
|
||||||
api.APIFailure(err.(error))(c)
|
api.APIFailure(err.(error))(c)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
err := manage.NewExamine()(api.GetSession()(c).(*service.Session), api.GetLocal()(c).(string)).
|
||||||
|
Launch(form.Convert(), form.Identity, form.Status)
|
||||||
|
api.APIResponse(err)
|
||||||
}
|
}
|
||||||
|
@ -57,7 +57,9 @@ func (c *Account) Login(account, password, captchaKey, captchaValue, equipment,
|
|||||||
|
|
||||||
// Logout 退出请求
|
// Logout 退出请求
|
||||||
func (c *Account) Logout() error {
|
func (c *Account) Logout() error {
|
||||||
service.Publish(config.EventForRedisHashDestroy, config.RedisKeyForAccount, utils.UintToString(c.UID))
|
if c.Session != nil && c.UID > 0 {
|
||||||
|
service.Publish(config.EventForRedisHashDestroy, config.RedisKeyForAccount, utils.UintToString(c.UID))
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -28,8 +28,10 @@ type ExamineManageInfo struct {
|
|||||||
|
|
||||||
// examineHandle 审核处理
|
// examineHandle 审核处理
|
||||||
var examineHandle = map[int]func(uint64) (*ExamineManageInfo, error){
|
var examineHandle = map[int]func(uint64) (*ExamineManageInfo, error){
|
||||||
config.TenantUserIdentityForCompany: examineCompany,
|
config.TenantUserIdentityForCompany: examineCompany,
|
||||||
config.TenantUserIdentityForExpert: examineExpert,
|
config.TenantUserIdentityForExpert: examineExpert,
|
||||||
|
config.TenantUserIdentityForResearch: examineResearch,
|
||||||
|
config.TenantUserIdentityForLaboratory: examineLaboratory,
|
||||||
}
|
}
|
||||||
|
|
||||||
func checkManage(IModel model2.IModel, id uint64) error {
|
func checkManage(IModel model2.IModel, id uint64) error {
|
||||||
@ -56,7 +58,7 @@ func examineCompany(id uint64) (*ExamineManageInfo, error) {
|
|||||||
return &ExamineManageInfo{
|
return &ExamineManageInfo{
|
||||||
IModel: mManageCompany.ManageCompany, UID: mManageCompany.UID,
|
IModel: mManageCompany.ManageCompany, UID: mManageCompany.UID,
|
||||||
IdentityInfo: &model2.UserIdentityForCompany{
|
IdentityInfo: &model2.UserIdentityForCompany{
|
||||||
Industry: mManageCompany.Industry, Keyword: mManageCompany.Keyword,
|
Industry: mManageCompany.Industry, Keyword: mManageCompany.Keyword, CreatedAt: time.Now(),
|
||||||
},
|
},
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
@ -75,6 +77,45 @@ func examineExpert(id uint64) (*ExamineManageInfo, error) {
|
|||||||
IModel: mManageExpert.ManageExpert, UID: mManageExpert.UID,
|
IModel: mManageExpert.ManageExpert, UID: mManageExpert.UID,
|
||||||
IdentityInfo: &model2.UserIdentityForExpert{
|
IdentityInfo: &model2.UserIdentityForExpert{
|
||||||
Industry: mManageExpert.Industry, Keyword: mManageExpert.Keyword, Research: mManageExpert.Research,
|
Industry: mManageExpert.Industry, Keyword: mManageExpert.Keyword, Research: mManageExpert.Research,
|
||||||
|
CreatedAt: time.Now(),
|
||||||
|
},
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func examineResearch(id uint64) (*ExamineManageInfo, error) {
|
||||||
|
mManageResearch := model.NewManageResearch()
|
||||||
|
|
||||||
|
err := checkManage(mManageResearch.ManageResearch, id)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
} else if mManageResearch.Status != model2.ExamineStatusForOngoing {
|
||||||
|
return nil, errors.New("当前入住信息已审核")
|
||||||
|
}
|
||||||
|
return &ExamineManageInfo{
|
||||||
|
IModel: mManageResearch.ManageResearch, UID: mManageResearch.UID,
|
||||||
|
IdentityInfo: &model2.UserIdentityForResearch{
|
||||||
|
Name: mManageResearch.Name, Industry: mManageResearch.Industry, Keyword: mManageResearch.Keyword,
|
||||||
|
Research: mManageResearch.Research, CreatedAt: time.Now(),
|
||||||
|
},
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func examineLaboratory(id uint64) (*ExamineManageInfo, error) {
|
||||||
|
mManageLaboratory := model.NewManageLaboratory()
|
||||||
|
|
||||||
|
err := checkManage(mManageLaboratory.ManageLaboratory, id)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
} else if mManageLaboratory.Status != model2.ExamineStatusForOngoing {
|
||||||
|
return nil, errors.New("当前入住信息已审核")
|
||||||
|
}
|
||||||
|
return &ExamineManageInfo{
|
||||||
|
IModel: mManageLaboratory.ManageLaboratory, UID: mManageLaboratory.UID,
|
||||||
|
IdentityInfo: &model2.UserIdentityForLaboratory{
|
||||||
|
Name: mManageLaboratory.Name, Industry: mManageLaboratory.Industry, Keyword: mManageLaboratory.Keyword,
|
||||||
|
Research: mManageLaboratory.Research, CreatedAt: time.Now(),
|
||||||
},
|
},
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
@ -96,7 +137,6 @@ func (c *Examine) Launch(id uint64, identity, status int) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
return orm.GetDB().Transaction(func(tx *gorm.DB) error {
|
return orm.GetDB().Transaction(func(tx *gorm.DB) error {
|
||||||
if err = model2.Updates(data.IModel, map[string]interface{}{
|
if err = model2.Updates(data.IModel, map[string]interface{}{
|
||||||
"status": status, "updated_at": time.Now(),
|
"status": status, "updated_at": time.Now(),
|
||||||
|
@ -1,14 +1,91 @@
|
|||||||
package manage
|
package manage
|
||||||
|
|
||||||
import "SciencesServer/app/service"
|
import (
|
||||||
|
"SciencesServer/app/api/manage/controller"
|
||||||
|
"SciencesServer/app/api/manage/model"
|
||||||
|
"SciencesServer/app/basic/config"
|
||||||
|
model2 "SciencesServer/app/common/model"
|
||||||
|
"SciencesServer/app/service"
|
||||||
|
"gorm.io/gorm"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
type Instance struct {
|
type Instance struct {
|
||||||
*service.Session
|
*service.Session
|
||||||
|
gorm.Model
|
||||||
local string
|
local string
|
||||||
}
|
}
|
||||||
|
|
||||||
type InstanceHandle func(session *service.Session, local string) *Instance
|
type InstanceHandle func(session *service.Session, local string) *Instance
|
||||||
|
|
||||||
|
type (
|
||||||
|
// InstanceForExpert 专家信息
|
||||||
|
InstanceForExpert struct {
|
||||||
|
ID string `json:"id"`
|
||||||
|
Name string `json:"name"`
|
||||||
|
Industry []string `json:"industry"`
|
||||||
|
ResearchName string `json:"research_name"`
|
||||||
|
LaboratoryName string `json:"laboratory_name"`
|
||||||
|
Address string `json:"address"`
|
||||||
|
CreatedAt time.Time `json:"created_at"`
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
func (c *Instance) Company(name string, status int, page, pageSize int) {
|
||||||
|
mManageCompany := model.NewManageCompany()
|
||||||
|
|
||||||
|
where := make([]*model2.ModelWhere, 0)
|
||||||
|
|
||||||
|
if name != "" {
|
||||||
|
where = append(where, model2.NewWhereLike("name", name))
|
||||||
|
}
|
||||||
|
|
||||||
|
var count int64
|
||||||
|
|
||||||
|
mManageCompany.Companys(page, pageSize, &count)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Expert 专家信息
|
||||||
|
func (c *Instance) Expert(name string, status int, page, pageSize int) (*controller.ReturnPages, error) {
|
||||||
|
mManageExpert := model.NewManageExpert()
|
||||||
|
|
||||||
|
where := make([]*model2.ModelWhere, 0)
|
||||||
|
|
||||||
|
if name != "" {
|
||||||
|
where = append(where, model2.NewWhereLike("name", name))
|
||||||
|
}
|
||||||
|
var count int64
|
||||||
|
|
||||||
|
out, err := mManageExpert.Experts(page, pageSize, &count, where...)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
list := make([]*InstanceForExpert, 0)
|
||||||
|
|
||||||
|
for _, v := range out {
|
||||||
|
industry := make([]string, 0)
|
||||||
|
|
||||||
|
for _, v := range strings.Split(v.Industry, ";") {
|
||||||
|
industry = append(industry, config.GetIndustryInfo(v, "-"))
|
||||||
|
}
|
||||||
|
// 研究机构,实验室
|
||||||
|
researchName := v.LaboratoryName
|
||||||
|
laboratoryName := ""
|
||||||
|
|
||||||
|
if v.LaboratoryName != "" {
|
||||||
|
researchName = v.ResearchName
|
||||||
|
laboratoryName = v.LaboratoryName
|
||||||
|
}
|
||||||
|
list = append(list, &InstanceForExpert{ID: v.GetEncodeID(), Name: v.Name, Industry: industry,
|
||||||
|
ResearchName: researchName, LaboratoryName: laboratoryName,
|
||||||
|
Address: v.FormatBasic(), CreatedAt: v.CreatedAt,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
return &controller.ReturnPages{Data: list, Count: count}, nil
|
||||||
|
}
|
||||||
|
|
||||||
func NewInstance() InstanceHandle {
|
func NewInstance() InstanceHandle {
|
||||||
return func(session *service.Session, local string) *Instance {
|
return func(session *service.Session, local string) *Instance {
|
||||||
return &Instance{
|
return &Instance{
|
||||||
|
@ -1,11 +1,17 @@
|
|||||||
package model
|
package model
|
||||||
|
|
||||||
import "SciencesServer/app/common/model"
|
import (
|
||||||
|
"SciencesServer/app/common/model"
|
||||||
|
)
|
||||||
|
|
||||||
type ManageCompany struct {
|
type ManageCompany struct {
|
||||||
*model.ManageCompany
|
*model.ManageCompany
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (m *ManageCompany) Companys(page, pageSize int, count *int64, where ...*model.ModelWhere) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
func NewManageCompany() *ManageCompany {
|
func NewManageCompany() *ManageCompany {
|
||||||
return &ManageCompany{}
|
return &ManageCompany{}
|
||||||
}
|
}
|
||||||
|
@ -1,11 +1,50 @@
|
|||||||
package model
|
package model
|
||||||
|
|
||||||
import "SciencesServer/app/common/model"
|
import (
|
||||||
|
"SciencesServer/app/common/model"
|
||||||
|
"SciencesServer/serve/orm"
|
||||||
|
"fmt"
|
||||||
|
)
|
||||||
|
|
||||||
type ManageExpert struct {
|
type ManageExpert struct {
|
||||||
*model.ManageExpert
|
*model.ManageExpert
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type ManageExpertInfo struct {
|
||||||
|
*model.ManageExpert
|
||||||
|
Name string `json:"name"`
|
||||||
|
ResearchName string `json:"research_name"`
|
||||||
|
LaboratoryName string `json:"laboratory_name"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// Experts 专家信息
|
||||||
|
func (m *ManageExpert) Experts(page, pageSize int, count *int64, where ...*model.ModelWhere) ([]*ManageExpertInfo, error) {
|
||||||
|
mUserInstance := model.NewUserInstance()
|
||||||
|
mSysTenant := model.NewSysTenant()
|
||||||
|
|
||||||
|
db := orm.GetDB().Table(m.TableName()+" AS e").
|
||||||
|
Select("e.*", "u.name", "l.name AS laboratory_name", "r.name AS research_name").
|
||||||
|
Joins(fmt.Sprintf("LEFT JOIN %s AS u ON e.uid = u.uuid", mUserInstance.TableName())).
|
||||||
|
Joins(fmt.Sprintf("LEFT JOIN %s AS l ON e.tenant_id = l.id", mSysTenant.TableName())).
|
||||||
|
Joins(fmt.Sprintf("LEFT JOIN %s AS r ON l.parent_id = r.id", mSysTenant.TableName())).
|
||||||
|
Where("")
|
||||||
|
|
||||||
|
if len(where) > 0 {
|
||||||
|
for _, v := range where {
|
||||||
|
db = db.Where(v.Condition, v.Value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
out := make([]*ManageExpertInfo, 0)
|
||||||
|
|
||||||
|
if err := db.Count(count).Error; err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if err := db.Order("e.id " + model.OrderModeToDesc).Offset((page - 1) * pageSize).Limit(pageSize).Scan(&out).Error; err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return out, nil
|
||||||
|
}
|
||||||
|
|
||||||
func NewManageExpert() *ManageExpert {
|
func NewManageExpert() *ManageExpert {
|
||||||
return &ManageExpert{model.NewManageExpert()}
|
return &ManageExpert{model.NewManageExpert()}
|
||||||
}
|
}
|
||||||
|
@ -21,7 +21,6 @@ type (
|
|||||||
Job string `json:"job" form:"job"`
|
Job string `json:"job" form:"job"`
|
||||||
Title string `json:"title" form:"title"`
|
Title string `json:"title" form:"title"`
|
||||||
WorkAt string `json:"work_at" form:"work_at"`
|
WorkAt string `json:"work_at" form:"work_at"`
|
||||||
Keyword string `json:"keyword" form:"keyword"`
|
|
||||||
Research string `json:"research" form:"research"` // 研究方向
|
Research string `json:"research" form:"research"` // 研究方向
|
||||||
}
|
}
|
||||||
// IdentityForResearch 研究机构
|
// IdentityForResearch 研究机构
|
||||||
@ -32,9 +31,9 @@ type (
|
|||||||
}
|
}
|
||||||
// IdentityForLaboratory 实验室
|
// IdentityForLaboratory 实验室
|
||||||
IdentityForLaboratory struct {
|
IdentityForLaboratory struct {
|
||||||
TenantID uint64 `json:"tenant_id" form:"tenant_id"`
|
TenantID uint64 `json:"tenant_id" form:"tenant_id"`
|
||||||
Longitude float64 `json:"longitude" form:"longitude"` // 经度
|
Longitude float64 `json:"longitude" form:"longitude"` // 经度
|
||||||
Latitude float64 `json:"latitude" form:"latitude"` // 纬度
|
Latitude float64 `json:"latitude" form:"latitude"` // 纬度
|
||||||
Research map[int]string `json:"research" form:"research"` // 研究领域方向
|
Research string `json:"research" form:"research"` // 研究领域方向
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
@ -1,7 +1,9 @@
|
|||||||
package model
|
package model
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"SciencesServer/config"
|
||||||
"SciencesServer/utils"
|
"SciencesServer/utils"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Gender struct {
|
type Gender struct {
|
||||||
@ -108,6 +110,23 @@ type Area struct {
|
|||||||
Address string `gorm:"column:address;type:varchar(255);default:null;comment:详细地址" json:"address"`
|
Address string `gorm:"column:address;type:varchar(255);default:null;comment:详细地址" json:"address"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (m *Area) FormatBasic() string {
|
||||||
|
address := make([]string, 0)
|
||||||
|
address = append(address, config.SettingAreaInfo[config.DefaultChinaAreaCode][m.Province])
|
||||||
|
|
||||||
|
if m.City != "" {
|
||||||
|
address = append(address, config.SettingAreaInfo[m.Province][m.City])
|
||||||
|
}
|
||||||
|
if m.District != "" {
|
||||||
|
address = append(address, config.SettingAreaInfo[m.City][m.District])
|
||||||
|
}
|
||||||
|
return strings.Join(address, "-")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *Area) FormatDetail() string {
|
||||||
|
return m.FormatBasic() + ";" + m.Address
|
||||||
|
}
|
||||||
|
|
||||||
// Position 坐标信息
|
// Position 坐标信息
|
||||||
type Position struct {
|
type Position struct {
|
||||||
Longitude float64 `json:"longitude"` // 经度
|
Longitude float64 `json:"longitude"` // 经度
|
||||||
|
@ -10,23 +10,34 @@ import (
|
|||||||
type UserInstance struct {
|
type UserInstance struct {
|
||||||
Model
|
Model
|
||||||
Local
|
Local
|
||||||
UUID uint64 `gorm:"column:uuid;uniqueIndex:idx_tenant_user_uuid;type:int;default:0;comment:用户唯一UUID" json:"-"`
|
UUID uint64 `gorm:"column:-;uniqueIndex:idx_tenant_user_uuid;type:int;default:0;comment:用户唯一UUID" json:"-"`
|
||||||
Name string `gorm:"column:name;type:varchar(20);default:null;comment:真实姓名" json:"name"`
|
Source UserInstanceSource `gorm:"column:source;type:tinyint(1);default:1;comment:账号来源" json:"source"`
|
||||||
Mobile string `gorm:"column:mobile;index:idx_user_instance_mobile;type:varchar(15);default:null;comment:联系方式" json:"mobile"`
|
Name string `gorm:"column:name;type:varchar(20);default:null;comment:真实姓名" json:"name"`
|
||||||
Identity int `gorm:"column:identity;type:int(8);default:0;comment:身份信息" json:"-"`
|
Mobile string `gorm:"column:mobile;index:idx_user_instance_mobile;type:varchar(15);default:null;comment:联系方式" json:"mobile"`
|
||||||
Password string `gorm:"column:password;type:varchar(100);default:null;comment:密码" json:"-"`
|
Identity int `gorm:"column:identity;type:int(8);default:0;comment:身份信息" json:"-"`
|
||||||
Salt string `gorm:"column:salt;type:varchar(10);default:null;comment:盐值" json:"-"`
|
Password string `gorm:"column:password;type:varchar(100);default:null;comment:密码" json:"-"`
|
||||||
|
Salt string `gorm:"column:salt;type:varchar(10);default:null;comment:盐值" json:"-"`
|
||||||
AccountStatus
|
AccountStatus
|
||||||
ModelDeleted
|
ModelDeleted
|
||||||
ModelAt
|
ModelAt
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// UserInstanceSource 账号来源
|
||||||
|
type UserInstanceSource int
|
||||||
|
|
||||||
|
const (
|
||||||
|
// UserInstanceSourceForLocal 本地注册
|
||||||
|
UserInstanceSourceForLocal UserInstanceSource = iota + 1
|
||||||
|
// UserInstanceSourceForWechat 微信登陆
|
||||||
|
UserInstanceSourceForWechat
|
||||||
|
)
|
||||||
|
|
||||||
func (m *UserInstance) TableName() string {
|
func (m *UserInstance) TableName() string {
|
||||||
return "user_instance"
|
return "user_instance"
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *UserInstance) BeforeCreate(db *gorm.DB) error {
|
func (m *UserInstance) BeforeCreate(db *gorm.DB) error {
|
||||||
m.NewPassword()
|
m.SetPasswordAttribute()
|
||||||
snowflake, _ := utils.NewSnowflake(1)
|
snowflake, _ := utils.NewSnowflake(1)
|
||||||
m.UUID = uint64(snowflake.GetID())
|
m.UUID = uint64(snowflake.GetID())
|
||||||
m.Status = AccountStatusForEnable
|
m.Status = AccountStatusForEnable
|
||||||
@ -34,7 +45,7 @@ func (m *UserInstance) BeforeCreate(db *gorm.DB) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *UserInstance) NewPassword() {
|
func (m *UserInstance) SetPasswordAttribute() {
|
||||||
m.Salt = utils.GetRandomString(8)
|
m.Salt = utils.GetRandomString(8)
|
||||||
m.Password = utils.HashString([]byte(utils.Md5String(m.Password, m.Salt)))
|
m.Password = utils.HashString([]byte(utils.Md5String(m.Password, m.Salt)))
|
||||||
}
|
}
|
||||||
|
@ -32,14 +32,32 @@ type IUserIdentity interface {
|
|||||||
type (
|
type (
|
||||||
// UserIdentityForCompany 公司信息
|
// UserIdentityForCompany 公司信息
|
||||||
UserIdentityForCompany struct {
|
UserIdentityForCompany struct {
|
||||||
Industry string `json:"industry"`
|
Industry string `json:"industry"`
|
||||||
Keyword string `json:"keyword"`
|
Keyword string `json:"keyword"`
|
||||||
|
CreatedAt time.Time `json:"created_at"`
|
||||||
}
|
}
|
||||||
// UserIdentityForExpert 专家信息
|
// UserIdentityForExpert 专家信息
|
||||||
UserIdentityForExpert struct {
|
UserIdentityForExpert struct {
|
||||||
Industry string `json:"industry"`
|
Industry string `json:"industry"`
|
||||||
Keyword string `json:"keyword"`
|
Keyword string `json:"keyword"`
|
||||||
Research string `json:"research"`
|
Research string `json:"research"`
|
||||||
|
CreatedAt time.Time `json:"created_at"`
|
||||||
|
}
|
||||||
|
// UserIdentityForResearch 研究机构信息
|
||||||
|
UserIdentityForResearch struct {
|
||||||
|
Name string `json:"name"`
|
||||||
|
Industry string `json:"industry"`
|
||||||
|
Keyword string `json:"keyword"`
|
||||||
|
Research string `json:"research"`
|
||||||
|
CreatedAt time.Time `json:"created_at"`
|
||||||
|
}
|
||||||
|
// UserIdentityForLaboratory 实验室信息
|
||||||
|
UserIdentityForLaboratory struct {
|
||||||
|
Name string `json:"name"`
|
||||||
|
Industry string `json:"industry"`
|
||||||
|
Keyword string `json:"keyword"`
|
||||||
|
Research string `json:"research"`
|
||||||
|
CreatedAt time.Time `json:"created_at"`
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -53,6 +71,16 @@ func (this *UserIdentityForExpert) Analysis(src string) interface{} {
|
|||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (this *UserIdentityForResearch) Analysis(src string) interface{} {
|
||||||
|
utils.FromJSON(src, this)
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *UserIdentityForLaboratory) Analysis(src string) interface{} {
|
||||||
|
utils.FromJSON(src, this)
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
type UserManageSelected int
|
type UserManageSelected int
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
47
app/service/authToken.go
Normal file
47
app/service/authToken.go
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
package service
|
||||||
|
|
||||||
|
import (
|
||||||
|
"SciencesServer/config"
|
||||||
|
cache2 "SciencesServer/serve/cache"
|
||||||
|
"SciencesServer/utils"
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
type AuthToken struct {
|
||||||
|
Token string `json:"token"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *AuthToken) Auth() (*Session, error) {
|
||||||
|
tokenInfo := utils.JWTDecrypt(this.Token)
|
||||||
|
|
||||||
|
if tokenInfo == nil || len(tokenInfo) <= 0 {
|
||||||
|
return nil, errors.New("Token无效")
|
||||||
|
}
|
||||||
|
expTimestamp := utils.StringToInt64(fmt.Sprintf("%v", tokenInfo["exp"]))
|
||||||
|
expTime := time.Unix(expTimestamp, 0)
|
||||||
|
ok := expTime.After(time.Now())
|
||||||
|
|
||||||
|
if !ok {
|
||||||
|
return nil, errors.New("Token过期")
|
||||||
|
}
|
||||||
|
cache, _ := cache2.Cache.HGet(config.RedisKeyForAccount, fmt.Sprintf("%v", tokenInfo[config.TokenForUID]))
|
||||||
|
|
||||||
|
if cache == "" {
|
||||||
|
return nil, errors.New("用户未登录或已退出")
|
||||||
|
}
|
||||||
|
session := new(Session)
|
||||||
|
_ = session.UnmarshalBinary([]byte(cache))
|
||||||
|
|
||||||
|
if !config.SettingInfo.MultipleLogin && session.Token != this.Token {
|
||||||
|
return nil, errors.New("登录失效,已在其他地方登录!")
|
||||||
|
}
|
||||||
|
return session, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewAuthToken(token string) *AuthToken {
|
||||||
|
return &AuthToken{
|
||||||
|
Token: token,
|
||||||
|
}
|
||||||
|
}
|
@ -68,4 +68,4 @@ upload:
|
|||||||
log:
|
log:
|
||||||
file: log/logs.log
|
file: log/logs.log
|
||||||
least_day: 7
|
least_day: 7
|
||||||
level: info # debug | info | warn | error
|
level: debug # debug | info | warn | error
|
@ -11,6 +11,7 @@ import (
|
|||||||
func registerAPI(app *gin.Engine) {
|
func registerAPI(app *gin.Engine) {
|
||||||
apiPrefix := "/api"
|
apiPrefix := "/api"
|
||||||
g := app.Group(apiPrefix)
|
g := app.Group(apiPrefix)
|
||||||
|
|
||||||
// 登录验证
|
// 登录验证
|
||||||
g.Use(NeedLogin(AddSkipperURL([]string{
|
g.Use(NeedLogin(AddSkipperURL([]string{
|
||||||
apiPrefix + "/captcha",
|
apiPrefix + "/captcha",
|
||||||
|
@ -4,13 +4,9 @@ import (
|
|||||||
"SciencesServer/app/service"
|
"SciencesServer/app/service"
|
||||||
"SciencesServer/config"
|
"SciencesServer/config"
|
||||||
"SciencesServer/serve/cache"
|
"SciencesServer/serve/cache"
|
||||||
cache2 "SciencesServer/serve/cache"
|
|
||||||
"SciencesServer/utils"
|
"SciencesServer/utils"
|
||||||
"fmt"
|
|
||||||
"net/http"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
|
"net/http"
|
||||||
)
|
)
|
||||||
|
|
||||||
// SkipperURL 跳过验证
|
// SkipperURL 跳过验证
|
||||||
@ -41,34 +37,10 @@ func NeedLogin(skipperURL ...SkipperURL) gin.HandlerFunc {
|
|||||||
c.Abort()
|
c.Abort()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
tokenInfo := utils.JWTDecrypt(token)
|
session, err := service.NewAuthToken(token).Auth()
|
||||||
|
|
||||||
if tokenInfo == nil || len(tokenInfo) <= 0 {
|
if err != nil {
|
||||||
c.JSON(http.StatusUnauthorized, gin.H{"message": "Token无效"})
|
c.JSON(http.StatusUnauthorized, gin.H{"message": err.Error()})
|
||||||
c.Abort()
|
|
||||||
return
|
|
||||||
}
|
|
||||||
expTimestamp := utils.StringToInt64(fmt.Sprintf("%v", tokenInfo["exp"]))
|
|
||||||
expTime := time.Unix(expTimestamp, 0)
|
|
||||||
ok := expTime.After(time.Now())
|
|
||||||
|
|
||||||
if !ok {
|
|
||||||
c.JSON(http.StatusUnauthorized, gin.H{"message": "Token过期"})
|
|
||||||
c.Abort()
|
|
||||||
return
|
|
||||||
}
|
|
||||||
cache, _ := cache2.Cache.HGet(config.RedisKeyForAccount, fmt.Sprintf("%v", tokenInfo[config.TokenForUID]))
|
|
||||||
|
|
||||||
if cache == "" {
|
|
||||||
c.JSON(http.StatusUnauthorized, gin.H{"message": "用户未登录或已退出"})
|
|
||||||
c.Abort()
|
|
||||||
return
|
|
||||||
}
|
|
||||||
session := new(service.Session)
|
|
||||||
_ = session.UnmarshalBinary([]byte(cache))
|
|
||||||
|
|
||||||
if !config.SettingInfo.MultipleLogin && session.Token != token {
|
|
||||||
c.JSON(http.StatusUnauthorized, gin.H{"message": "登录失效,已在其他地方登录!"})
|
|
||||||
c.Abort()
|
c.Abort()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -42,18 +42,18 @@ func (this *Logger) Load() {
|
|||||||
func (this *Logger) Init(option *Option) *Logger {
|
func (this *Logger) Init(option *Option) *Logger {
|
||||||
this.Option = option
|
this.Option = option
|
||||||
|
|
||||||
logger = log.New()
|
_logger := log.New()
|
||||||
logger.SetFormatter(&log.JSONFormatter{TimestampFormat: "2006-01-02 15:04:05"})
|
_logger.SetFormatter(&log.JSONFormatter{TimestampFormat: "2006-01-02 15:04:05"})
|
||||||
logger.SetReportCaller(true)
|
_logger.SetReportCaller(true)
|
||||||
logger.AddHook(NewHook(this.File, 0, this.LeastDay))
|
_logger.AddHook(NewHook(this.File, 0, this.LeastDay))
|
||||||
|
|
||||||
if this.IsStdout {
|
if this.IsStdout {
|
||||||
logger.SetOutput(io.MultiWriter(os.Stdout))
|
_logger.SetOutput(io.MultiWriter(os.Stdout))
|
||||||
}
|
}
|
||||||
logger.SetFormatter(formatter(true))
|
_logger.SetFormatter(formatter(true))
|
||||||
logger.SetLevel(this.level())
|
_logger.SetLevel(this.level())
|
||||||
|
|
||||||
this.Logger = logger
|
this.Logger = _logger
|
||||||
|
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user