feat:完善入驻信息管理
This commit is contained in:
@ -10,12 +10,12 @@ type Config struct{}
|
|||||||
|
|
||||||
func (a *Config) Identity(c *gin.Context) {
|
func (a *Config) Identity(c *gin.Context) {
|
||||||
data := config.NewConfig().Identity()
|
data := config.NewConfig().Identity()
|
||||||
api.APISuccess(data)
|
api.APISuccess(data)(c)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *Config) Transaction(c *gin.Context) {
|
func (a *Config) Transaction(c *gin.Context) {
|
||||||
data := config.NewConfig().Transaction()
|
data := config.NewConfig().Transaction()
|
||||||
api.APISuccess(data)
|
api.APISuccess(data)(c)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *Config) Industry(c *gin.Context) {
|
func (a *Config) Industry(c *gin.Context) {
|
||||||
|
@ -32,7 +32,8 @@ func (c *settledForm) bind() *settled.BasicParams {
|
|||||||
|
|
||||||
// Index 入驻信息
|
// Index 入驻信息
|
||||||
func (*Settled) Index(c *gin.Context) {
|
func (*Settled) Index(c *gin.Context) {
|
||||||
settled.NewInstance()(api.GetSession()(c).(*session.Enterprise), api.GetLocal()(c).(string)).Index()
|
data, err := settled.NewInstance()(api.GetSession()(c).(*session.Enterprise), api.GetLocal()(c).(string)).Index()
|
||||||
|
api.APIResponse(err, data)(c)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Company 公司入驻信息
|
// Company 公司入驻信息
|
||||||
@ -106,6 +107,17 @@ func (*Settled) Agent(c *gin.Context) {
|
|||||||
api.APIFailure(err.(error))(c)
|
api.APIFailure(err.(error))(c)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
credentialImages := make([]string, 0)
|
||||||
|
|
||||||
|
for _, image := range form.CredentialImages {
|
||||||
|
credentialImages = append(credentialImages, (&api.ImageForm{Image: image}).FilterImageURL())
|
||||||
|
}
|
||||||
|
|
||||||
|
form.CredentialImages = credentialImages
|
||||||
|
form.IDImage.Front = (&api.ImageForm{Image: form.IDImage.Front}).FilterImageURL()
|
||||||
|
form.IDImage.Behind = (&api.ImageForm{Image: form.IDImage.Behind}).FilterImageURL()
|
||||||
|
form.IDImage.Hold = (&api.ImageForm{Image: form.IDImage.Hold}).FilterImageURL()
|
||||||
|
|
||||||
err := settled.NewAgent()(api.GetSession()(c).(*session.Enterprise), api.GetLocal()(c).(string)).
|
err := settled.NewAgent()(api.GetSession()(c).(*session.Enterprise), api.GetLocal()(c).(string)).
|
||||||
Launch(form.settledForm.bind(), &form.IdentityForAgent)
|
Launch(form.settledForm.bind(), &form.IdentityForAgent)
|
||||||
api.APIResponse(err)(c)
|
api.APIResponse(err)(c)
|
||||||
|
@ -53,6 +53,11 @@ func (c *Agent) Launch(params *BasicParams, other *config.IdentityForAgent) erro
|
|||||||
mManageAgent.Name = params.Name
|
mManageAgent.Name = params.Name
|
||||||
mManageAgent.Mobile = params.Mobile
|
mManageAgent.Mobile = params.Mobile
|
||||||
mManageAgent.IDCard = other.IDCard
|
mManageAgent.IDCard = other.IDCard
|
||||||
|
mManageAgent.SetIDImageAttribute(&model2.ManageAgentIDImage{
|
||||||
|
Front: other.IDImage.Front,
|
||||||
|
Behind: other.IDImage.Behind,
|
||||||
|
Hold: other.IDImage.Hold,
|
||||||
|
})
|
||||||
mManageAgent.SetIndustryAttribute(params.Industrys)
|
mManageAgent.SetIndustryAttribute(params.Industrys)
|
||||||
mManageAgent.SetKeywordAttribute(params.Keywords)
|
mManageAgent.SetKeywordAttribute(params.Keywords)
|
||||||
mManageAgent.WorkExperience = other.WorkExperience
|
mManageAgent.WorkExperience = other.WorkExperience
|
||||||
|
@ -1,7 +1,13 @@
|
|||||||
package settled
|
package settled
|
||||||
|
|
||||||
import "SciencesServer/app/session"
|
import (
|
||||||
|
"SciencesServer/app/api/enterprise/model"
|
||||||
|
"SciencesServer/app/basic/config"
|
||||||
|
model2 "SciencesServer/app/common/model"
|
||||||
|
"SciencesServer/app/session"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Instance 首页信息
|
||||||
type Instance struct {
|
type Instance struct {
|
||||||
*session.Enterprise
|
*session.Enterprise
|
||||||
local string
|
local string
|
||||||
@ -9,8 +15,77 @@ type Instance struct {
|
|||||||
|
|
||||||
type InstanceHandle func(session *session.Enterprise, local string) *Instance
|
type InstanceHandle func(session *session.Enterprise, local string) *Instance
|
||||||
|
|
||||||
func (c *Instance) Index() {
|
type InstanceInfo struct {
|
||||||
|
Identity int `json:"identity"` // 所有身份
|
||||||
|
ExamineIdentity map[int]model2.ExamineStatusKind `json:"examine_identity"` // 审核中信息
|
||||||
|
SelectIdentity int `json:"select_identity"` // 当前选择的身份
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Instance) company() (bool, model2.ExamineStatusKind, error) {
|
||||||
|
mUserCompany := model.NewUserCompany()
|
||||||
|
out, err := mUserCompany.Company(c.UID)
|
||||||
|
return out.ID > 0, out.ExamineStatus, err
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Instance) expert() (bool, model2.ExamineStatusKind, error) {
|
||||||
|
mUserExpert := model.NewUserExpert()
|
||||||
|
out, err := mUserExpert.Expert(c.UID)
|
||||||
|
return out.ID > 0, out.ExamineStatus, err
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Instance) research() (bool, model2.ExamineStatusKind, error) {
|
||||||
|
mUserResearch := model.NewUserResearch()
|
||||||
|
out, err := mUserResearch.Research(c.UID)
|
||||||
|
return out.ID > 0, out.ExamineStatus, err
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Instance) laboratory() (bool, model2.ExamineStatusKind, error) {
|
||||||
|
mUserLaboratory := model.NewUserLaboratory()
|
||||||
|
out, err := mUserLaboratory.Laboratory(c.UID)
|
||||||
|
return out.ID > 0, out.ExamineStatus, err
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Instance) agent() (bool, model2.ExamineStatusKind, error) {
|
||||||
|
mUserAgent := model.NewUserAgent()
|
||||||
|
out, err := mUserAgent.Agent(c.UID)
|
||||||
|
return out.ID > 0, out.ExamineStatus, err
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Instance) Index() (*InstanceInfo, error) {
|
||||||
|
out := &InstanceInfo{
|
||||||
|
Identity: c.Identity,
|
||||||
|
ExamineIdentity: make(map[int]model2.ExamineStatusKind, 0),
|
||||||
|
SelectIdentity: c.SelectIdentity,
|
||||||
|
}
|
||||||
|
isExist := false
|
||||||
|
var kind model2.ExamineStatusKind
|
||||||
|
var err error
|
||||||
|
|
||||||
|
// 查询其他信息
|
||||||
|
for k := range config.TenantUserIdentityData {
|
||||||
|
if k&c.SelectIdentity > 0 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if k == config.TenantUserIdentityForCompany {
|
||||||
|
isExist, kind, err = c.company()
|
||||||
|
} else if k == config.TenantUserIdentityForExpert {
|
||||||
|
isExist, kind, err = c.expert()
|
||||||
|
} else if k == config.TenantUserIdentityForResearch {
|
||||||
|
isExist, kind, err = c.research()
|
||||||
|
} else if k == config.TenantUserIdentityForLaboratory {
|
||||||
|
isExist, kind, err = c.laboratory()
|
||||||
|
} else if k == config.TenantUserIdentityForAgent {
|
||||||
|
isExist, kind, err = c.agent()
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if !isExist {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
out.ExamineIdentity[k] = kind
|
||||||
|
}
|
||||||
|
return out, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewInstance() InstanceHandle {
|
func NewInstance() InstanceHandle {
|
||||||
|
@ -1,11 +1,27 @@
|
|||||||
package model
|
package model
|
||||||
|
|
||||||
import "SciencesServer/app/common/model"
|
import (
|
||||||
|
"SciencesServer/app/common/model"
|
||||||
|
"SciencesServer/serve/orm"
|
||||||
|
"fmt"
|
||||||
|
)
|
||||||
|
|
||||||
type UserAgent struct {
|
type UserAgent struct {
|
||||||
*model.UserAgent
|
*model.UserAgent
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (m *UserAgent) Agent(uid uint64) (*UserSettledInfo, error) {
|
||||||
|
out := new(UserSettledInfo)
|
||||||
|
|
||||||
|
err := orm.GetDB().Table(m.TableName()+" AS u").
|
||||||
|
Select("u.id", "c.examine_status").
|
||||||
|
Joins(fmt.Sprintf("LEFT JOIN %s AS c ON u.agent_id = c.id", model.NewManageAgent().TableName())).
|
||||||
|
Where("u.uid = ?", uid).
|
||||||
|
Where("u.is_deleted = ? AND u.invalid_status = ?", model.DeleteStatusForNot, model.InvalidStatusForNot).
|
||||||
|
Scan(out).Error
|
||||||
|
return out, err
|
||||||
|
}
|
||||||
|
|
||||||
func NewUserAgent() *UserAgent {
|
func NewUserAgent() *UserAgent {
|
||||||
return &UserAgent{model.NewUserAgent()}
|
return &UserAgent{model.NewUserAgent()}
|
||||||
}
|
}
|
||||||
|
@ -1,11 +1,33 @@
|
|||||||
package model
|
package model
|
||||||
|
|
||||||
import "SciencesServer/app/common/model"
|
import (
|
||||||
|
"SciencesServer/app/common/model"
|
||||||
|
"SciencesServer/serve/orm"
|
||||||
|
"fmt"
|
||||||
|
)
|
||||||
|
|
||||||
type UserCompany struct {
|
type UserCompany struct {
|
||||||
*model.UserCompany
|
*model.UserCompany
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type UserSettledInfo struct {
|
||||||
|
ID uint64 `json:"id"`
|
||||||
|
model.Examine
|
||||||
|
}
|
||||||
|
|
||||||
|
// Company 公司信息
|
||||||
|
func (m *UserCompany) Company(uid uint64) (*UserSettledInfo, error) {
|
||||||
|
out := new(UserSettledInfo)
|
||||||
|
|
||||||
|
err := orm.GetDB().Table(m.TableName()+" AS u").
|
||||||
|
Select("u.id", "c.examine_status").
|
||||||
|
Joins(fmt.Sprintf("LEFT JOIN %s AS c ON u.company_id = c.id", model.NewManageCompany().TableName())).
|
||||||
|
Where("u.uid = ?", uid).
|
||||||
|
Where("u.is_deleted = ? AND u.invalid_status = ?", model.DeleteStatusForNot, model.InvalidStatusForNot).
|
||||||
|
Scan(out).Error
|
||||||
|
return out, err
|
||||||
|
}
|
||||||
|
|
||||||
func NewUserCompany() *UserCompany {
|
func NewUserCompany() *UserCompany {
|
||||||
return &UserCompany{model.NewUserCompany()}
|
return &UserCompany{model.NewUserCompany()}
|
||||||
}
|
}
|
||||||
|
@ -1,11 +1,27 @@
|
|||||||
package model
|
package model
|
||||||
|
|
||||||
import "SciencesServer/app/common/model"
|
import (
|
||||||
|
"SciencesServer/app/common/model"
|
||||||
|
"SciencesServer/serve/orm"
|
||||||
|
"fmt"
|
||||||
|
)
|
||||||
|
|
||||||
type UserExpert struct {
|
type UserExpert struct {
|
||||||
*model.UserExpert
|
*model.UserExpert
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (m *UserExpert) Expert(uid uint64) (*UserSettledInfo, error) {
|
||||||
|
out := new(UserSettledInfo)
|
||||||
|
|
||||||
|
err := orm.GetDB().Table(m.TableName()+" AS u").
|
||||||
|
Select("u.id", "c.examine_status").
|
||||||
|
Joins(fmt.Sprintf("LEFT JOIN %s AS c ON u.expert_id = c.id", model.NewManageExpert().TableName())).
|
||||||
|
Where("u.uid = ?", uid).
|
||||||
|
Where("u.is_deleted = ? AND u.invalid_status = ?", model.DeleteStatusForNot, model.InvalidStatusForNot).
|
||||||
|
Scan(out).Error
|
||||||
|
return out, err
|
||||||
|
}
|
||||||
|
|
||||||
func NewUserExpert() *UserExpert {
|
func NewUserExpert() *UserExpert {
|
||||||
return &UserExpert{model.NewUserExpert()}
|
return &UserExpert{model.NewUserExpert()}
|
||||||
}
|
}
|
||||||
|
@ -1,11 +1,27 @@
|
|||||||
package model
|
package model
|
||||||
|
|
||||||
import "SciencesServer/app/common/model"
|
import (
|
||||||
|
"SciencesServer/app/common/model"
|
||||||
|
"SciencesServer/serve/orm"
|
||||||
|
"fmt"
|
||||||
|
)
|
||||||
|
|
||||||
type UserLaboratory struct {
|
type UserLaboratory struct {
|
||||||
*model.UserLaboratory
|
*model.UserLaboratory
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (m *UserLaboratory) Laboratory(uid uint64) (*UserSettledInfo, error) {
|
||||||
|
out := new(UserSettledInfo)
|
||||||
|
|
||||||
|
err := orm.GetDB().Table(m.TableName()+" AS u").
|
||||||
|
Select("u.id", "c.examine_status").
|
||||||
|
Joins(fmt.Sprintf("LEFT JOIN %s AS c ON u.laboratory_id = c.id", model.NewManageLaboratory().TableName())).
|
||||||
|
Where("u.uid = ?", uid).
|
||||||
|
Where("u.is_deleted = ? AND u.invalid_status = ?", model.DeleteStatusForNot, model.InvalidStatusForNot).
|
||||||
|
Scan(out).Error
|
||||||
|
return out, err
|
||||||
|
}
|
||||||
|
|
||||||
func NewUserLaboratory() *UserLaboratory {
|
func NewUserLaboratory() *UserLaboratory {
|
||||||
return &UserLaboratory{model.NewUserLaboratory()}
|
return &UserLaboratory{model.NewUserLaboratory()}
|
||||||
}
|
}
|
||||||
|
@ -1,11 +1,27 @@
|
|||||||
package model
|
package model
|
||||||
|
|
||||||
import "SciencesServer/app/common/model"
|
import (
|
||||||
|
"SciencesServer/app/common/model"
|
||||||
|
"SciencesServer/serve/orm"
|
||||||
|
"fmt"
|
||||||
|
)
|
||||||
|
|
||||||
type UserResearch struct {
|
type UserResearch struct {
|
||||||
*model.UserResearch
|
*model.UserResearch
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (m *UserResearch) Research(uid uint64) (*UserSettledInfo, error) {
|
||||||
|
out := new(UserSettledInfo)
|
||||||
|
|
||||||
|
err := orm.GetDB().Table(m.TableName()+" AS u").
|
||||||
|
Select("u.id", "c.examine_status").
|
||||||
|
Joins(fmt.Sprintf("LEFT JOIN %s AS c ON u.research_id = c.id", model.NewManageResearch().TableName())).
|
||||||
|
Where("u.uid = ?", uid).
|
||||||
|
Where("u.is_deleted = ? AND u.invalid_status = ?", model.DeleteStatusForNot, model.InvalidStatusForNot).
|
||||||
|
Scan(out).Error
|
||||||
|
return out, err
|
||||||
|
}
|
||||||
|
|
||||||
func NewUserResearch() *UserResearch {
|
func NewUserResearch() *UserResearch {
|
||||||
return &UserResearch{model.NewUserResearch()}
|
return &UserResearch{model.NewUserResearch()}
|
||||||
}
|
}
|
||||||
|
@ -45,6 +45,12 @@ type (
|
|||||||
IDCard string `json:"id_card" form:"id_card" binding:"required"` // 身份证号
|
IDCard string `json:"id_card" form:"id_card" binding:"required"` // 身份证号
|
||||||
WorkExperience string `json:"work_experience" form:"work_experience" binding:"required"` // 工作经历
|
WorkExperience string `json:"work_experience" form:"work_experience" binding:"required"` // 工作经历
|
||||||
WorkPlace string `json:"work_place" form:"work_place" binding:"required"` // 工作地点
|
WorkPlace string `json:"work_place" form:"work_place" binding:"required"` // 工作地点
|
||||||
|
// ManageAgentIDImage 身份证信息
|
||||||
|
IDImage struct {
|
||||||
|
Front string `json:"front" form:"front" binding:"required"`
|
||||||
|
Behind string `json:"behind" form:"behind" binding:"required"`
|
||||||
|
Hold string `json:"hold" form:"hold" binding:"required"`
|
||||||
|
} `json:"id_image" form:"id_image" binding:"required"`
|
||||||
CredentialImages []string `json:"credential_images" form:"credential_images"` // 资格证书
|
CredentialImages []string `json:"credential_images" form:"credential_images"` // 资格证书
|
||||||
Longitude float64 `json:"longitude" form:"longitude"` // 经度
|
Longitude float64 `json:"longitude" form:"longitude"` // 经度
|
||||||
Latitude float64 `json:"latitude" form:"latitude"` // 纬度
|
Latitude float64 `json:"latitude" form:"latitude"` // 纬度
|
||||||
|
@ -113,10 +113,10 @@ type InvalidStatus struct {
|
|||||||
type InvalidStatusKind int
|
type InvalidStatusKind int
|
||||||
|
|
||||||
const (
|
const (
|
||||||
// InvalidStatusForNot 未失效
|
|
||||||
InvalidStatusForNot InvalidStatusKind = iota
|
|
||||||
// InvalidStatusForYes 已失效
|
// InvalidStatusForYes 已失效
|
||||||
InvalidStatusForYes
|
InvalidStatusForYes InvalidStatusKind = iota - 1
|
||||||
|
// InvalidStatusForNot 未失效
|
||||||
|
InvalidStatusForNot
|
||||||
)
|
)
|
||||||
|
|
||||||
type Area struct {
|
type Area struct {
|
||||||
|
@ -1,6 +1,9 @@
|
|||||||
package model
|
package model
|
||||||
|
|
||||||
import "SciencesServer/utils"
|
import (
|
||||||
|
"SciencesServer/utils"
|
||||||
|
"encoding/json"
|
||||||
|
)
|
||||||
|
|
||||||
// ManageAgent 经纪人入驻信息管理
|
// ManageAgent 经纪人入驻信息管理
|
||||||
type ManageAgent struct {
|
type ManageAgent struct {
|
||||||
@ -9,18 +12,22 @@ type ManageAgent struct {
|
|||||||
Name string `gorm:"column:name;type:varchar(30);default:'';comment:姓名" json:"name"`
|
Name string `gorm:"column:name;type:varchar(30);default:'';comment:姓名" json:"name"`
|
||||||
Mobile string `gorm:"column:mobile;type:varchar(15);default:'';comment:联系方式" json:"mobile"`
|
Mobile string `gorm:"column:mobile;type:varchar(15);default:'';comment:联系方式" json:"mobile"`
|
||||||
IDCard string `gorm:"column:id_card;type:varchar(18);default:'';comment:身份证号" json:"id_card"`
|
IDCard string `gorm:"column:id_card;type:varchar(18);default:'';comment:身份证号" json:"id_card"`
|
||||||
|
IDImage string `gorm:"column:id_image;type:text;comment:身份证图片" json:"-"`
|
||||||
Industry string `gorm:"column:industry;type:varchar(255);default:'';comment:行业领域" json:"industry"`
|
Industry string `gorm:"column:industry;type:varchar(255);default:'';comment:行业领域" json:"industry"`
|
||||||
Keyword string `gorm:"column:keyword;type:varchar(255);default:'';comment:关键词" json:"-"`
|
Keyword string `gorm:"column:keyword;type:varchar(255);default:'';comment:关键词" json:"-"`
|
||||||
WorkExperience string `gorm:"column:work_experience;type:varchar(255);default:'';comment:工作经历" json:"work_experience"`
|
WorkExperience string `gorm:"column:work_experience;type:varchar(255);default:'';comment:工作经历" json:"work_experience"`
|
||||||
WorkPlace string `gorm:"column:work_place;type:varchar(255);default:0;comment:工作地点" json:"work_place"`
|
WorkPlace string `gorm:"column:work_place;type:varchar(255);default:0;comment:工作地点" json:"work_place"`
|
||||||
IDImage string `gorm:"column:id_image;type:text;comment:身份证图片" json:"-"`
|
|
||||||
CredentialImage string `gorm:"column:credential_image;type:varchar(255);default:'';comment:资格证书" json:"credential_image"`
|
CredentialImage string `gorm:"column:credential_image;type:varchar(255);default:'';comment:资格证书" json:"credential_image"`
|
||||||
Examine
|
Examine
|
||||||
ModelDeleted
|
ModelDeleted
|
||||||
ModelAt
|
ModelAt
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ManageAgentIDImage 身份证信息
|
||||||
type ManageAgentIDImage struct {
|
type ManageAgentIDImage struct {
|
||||||
|
Front string `json:"front"`
|
||||||
|
Behind string `json:"behind"`
|
||||||
|
Hold string `json:"hold"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *ManageAgent) TableName() string {
|
func (m *ManageAgent) TableName() string {
|
||||||
@ -47,6 +54,17 @@ func (m *ManageAgent) SetKeywordAttribute(value []string) {
|
|||||||
m.Keyword = utils.AnyToJSON(value)
|
m.Keyword = utils.AnyToJSON(value)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (m *ManageAgent) GetIDImageAttribute() *ManageAgentIDImage {
|
||||||
|
out := new(ManageAgentIDImage)
|
||||||
|
_ = json.Unmarshal([]byte(m.IDImage), out)
|
||||||
|
return out
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *ManageAgent) SetIDImageAttribute(value *ManageAgentIDImage) {
|
||||||
|
_bytes, _ := json.Marshal(value)
|
||||||
|
m.IDImage = string(_bytes)
|
||||||
|
}
|
||||||
|
|
||||||
func (m *ManageAgent) GetCredentialImageAttribute() []string {
|
func (m *ManageAgent) GetCredentialImageAttribute() []string {
|
||||||
out := make([]string, 0)
|
out := make([]string, 0)
|
||||||
_ = utils.FromJSON(m.CredentialImage, &out)
|
_ = utils.FromJSON(m.CredentialImage, &out)
|
||||||
|
@ -1,32 +1,144 @@
|
|||||||
package model
|
package model
|
||||||
|
|
||||||
import (
|
import (
|
||||||
GormEngine "github.com/belief428/gorm-engine"
|
"SciencesServer/serve/orm"
|
||||||
"github.com/belief428/gorm-engine/engine"
|
"SciencesServer/serve/orm/logic"
|
||||||
"github.com/belief428/gorm-engine/logic"
|
"SciencesServer/utils"
|
||||||
|
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
|
"strings"
|
||||||
|
"testing"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
// PPatent 专利信息数据模型
|
||||||
_db *gorm.DB
|
type PPatent struct {
|
||||||
)
|
Model
|
||||||
|
Kind string `gorm:"column:kind;type:tinyint(1);default:0;comment:专利类型" json:"kind"`
|
||||||
func mysql() logic.IEngine {
|
Title string `gorm:"column:title;type:varchar(255);default:'';comment:名称标题" json:"title"`
|
||||||
return &engine.MConfig{
|
FileUrl string `gorm:"column:file_url;type:varchar(255);default:'';comment:文件地址" json:"file_url"`
|
||||||
User: "appuser", Password: "ABCabc01!",
|
ApplyCode string `gorm:"column:apply_code;type:varchar(50);default:'';comment:申请号" json:"apply_code"`
|
||||||
Host: "192.168.99.188", Port: 3306,
|
ApplyAt string `gorm:"column:apply_at;type:varchar(30);default:'';comment:申请日" json:"apply_at"`
|
||||||
DBName: "iot", Parameters: "charset=utf8mb4,utf8&parseTime=True&loc=Asia%2FShanghai",
|
OpenCode string `gorm:"column:open_code;type:varchar(50);default:'';comment:公开(公告)号" json:"open_code"`
|
||||||
}
|
OpenAt string `gorm:"column:open_at;type:varchar(30);default:'';comment:公开(公告)日" json:"open_at"`
|
||||||
|
ApplyName string `gorm:"column:apply_name;type:varchar(100);default:'';comment:申请(专利权)人" json:"apply_name"`
|
||||||
|
ApplyAddress string `gorm:"column:apply_address;type:varchar(255);default:'';comment:申请人地址" json:"apply_address"`
|
||||||
|
Inventor string `gorm:"column:inventor;type:varchar(100);default:'';comment:发明人" json:"inventor"`
|
||||||
|
Description string `gorm:"column:description;type:text;comment:摘要" json:"description"`
|
||||||
|
PrincipalClaim string `gorm:"column:principal_claim;type:text;comment:主权项" json:"principal_claim"`
|
||||||
|
IPCCode string `gorm:"column:ipc_code;type:varchar(50);default:'';comment:IPC主分类号" json:"ipc_code"`
|
||||||
|
Shelf
|
||||||
|
Status SysParentStatus `gorm:"column:status;type:tinyint(1);default:1;comment:专利状态(1:授权,2:实审,3:公开)" json:"-"`
|
||||||
|
ModelDeleted
|
||||||
|
ModelAt
|
||||||
}
|
}
|
||||||
|
|
||||||
func _init() {
|
func (m *PPatent) TableName() string {
|
||||||
_db = GormEngine.NewEngine()(1, &GormEngine.EngineConfig{
|
return "manage_patent"
|
||||||
Debug: true,
|
}
|
||||||
TablePrefix: "",
|
|
||||||
Complex: false,
|
func mysql() *gorm.DB {
|
||||||
MaxIdleConns: 50,
|
instance := orm.NewInstance(
|
||||||
MaxOpenConns: 150,
|
orm.WithDebug(true),
|
||||||
MaxLifetime: 3600,
|
orm.WithDBMode("mysql"),
|
||||||
}).Start(mysql())
|
orm.WithTablePrefix(""),
|
||||||
|
orm.WithSingularTable(false),
|
||||||
|
orm.WithMaxIdleConns(3600),
|
||||||
|
orm.WithMaxOpenConns(2000),
|
||||||
|
orm.WithMaxLifetime(1000),
|
||||||
|
orm.WithMysqlOption(&logic.Mysql{
|
||||||
|
User: "appuser", Password: "ABCabc01!", Host: "192.168.0.188", Port: 3306,
|
||||||
|
DBName: "sciences", Parameters: "charset=utf8mb4,utf8&parseTime=True&loc=Local",
|
||||||
|
}),
|
||||||
|
).Init()
|
||||||
|
return instance.Engine
|
||||||
|
}
|
||||||
|
|
||||||
|
func sqlite() *gorm.DB {
|
||||||
|
instance := orm.NewInstance(
|
||||||
|
orm.WithDebug(true),
|
||||||
|
orm.WithDBMode("sqlite"),
|
||||||
|
orm.WithTablePrefix(""),
|
||||||
|
orm.WithSingularTable(false),
|
||||||
|
orm.WithMaxIdleConns(3600),
|
||||||
|
orm.WithMaxOpenConns(2000),
|
||||||
|
orm.WithMaxLifetime(1000),
|
||||||
|
orm.WithSqliteOption(&logic.Sqlite{Path: "../../../lib",
|
||||||
|
Name: "data.db"}),
|
||||||
|
).Init()
|
||||||
|
return instance.Engine
|
||||||
|
}
|
||||||
|
|
||||||
|
func filter(src string) string {
|
||||||
|
src = utils.ReplaceAllCompile(src, "\t", "")
|
||||||
|
src = utils.ReplaceAllCompile(src, "\n", "")
|
||||||
|
src = strings.TrimLeft(src, " ")
|
||||||
|
src = strings.TrimRight(src, " ")
|
||||||
|
return src
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestRecoveryPatent(t *testing.T) {
|
||||||
|
src := make([]*PPatent, 0)
|
||||||
|
sqlite := sqlite()
|
||||||
|
|
||||||
|
var err error
|
||||||
|
|
||||||
|
page := 1
|
||||||
|
|
||||||
|
mysql := mysql()
|
||||||
|
|
||||||
|
mSysPatent := new(SysPatent)
|
||||||
|
|
||||||
|
now := time.Now()
|
||||||
|
|
||||||
|
limit := 100
|
||||||
|
|
||||||
|
for {
|
||||||
|
if err = sqlite.Offset((page - 1) * limit).Limit(limit).Find(&src).Error; err != nil {
|
||||||
|
t.Error("Sqlite:" + err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if len(src) <= 0 {
|
||||||
|
t.Log("执行结束")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
t.Log(len(src))
|
||||||
|
out := make([]*SysPatent, 0)
|
||||||
|
|
||||||
|
for _, v := range src {
|
||||||
|
kind := SysParentKindForInvent
|
||||||
|
|
||||||
|
if v.Kind == "实用新型" {
|
||||||
|
kind = SysParentKindForNewPractical
|
||||||
|
} else if v.Kind == "外观设计" {
|
||||||
|
kind = SysParentKindForDesign
|
||||||
|
}
|
||||||
|
data := &SysPatent{
|
||||||
|
Kind: kind,
|
||||||
|
Title: v.Title,
|
||||||
|
FileUrl: v.FileUrl,
|
||||||
|
ApplyCode: v.ApplyCode,
|
||||||
|
ApplyAt: v.ApplyAt,
|
||||||
|
OpenCode: v.OpenCode,
|
||||||
|
OpenAt: v.OpenAt,
|
||||||
|
ApplyName: filter(v.ApplyName),
|
||||||
|
ApplyAddress: filter(v.ApplyAddress),
|
||||||
|
Inventor: filter(v.Inventor),
|
||||||
|
Description: filter(v.Description),
|
||||||
|
PrincipalClaim: filter(v.PrincipalClaim),
|
||||||
|
IPCCode: v.IPCCode,
|
||||||
|
Shelf: Shelf{ShelfStatus: 1},
|
||||||
|
ModelAt: ModelAt{
|
||||||
|
CreatedAt: now, UpdatedAt: now,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
out = append(out, data)
|
||||||
|
}
|
||||||
|
src = make([]*PPatent, 0)
|
||||||
|
page++
|
||||||
|
|
||||||
|
if err = mysql.Table(mSysPatent.TableName()).Create(out).Error; err != nil {
|
||||||
|
t.Error("Mysql:" + err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -10,9 +10,9 @@ type SysPatent struct {
|
|||||||
ApplyAt string `gorm:"column:apply_at;type:varchar(30);default:'';comment:申请日" json:"apply_at"`
|
ApplyAt string `gorm:"column:apply_at;type:varchar(30);default:'';comment:申请日" json:"apply_at"`
|
||||||
OpenCode string `gorm:"column:open_code;type:varchar(50);default:'';comment:公开(公告)号" json:"open_code"`
|
OpenCode string `gorm:"column:open_code;type:varchar(50);default:'';comment:公开(公告)号" json:"open_code"`
|
||||||
OpenAt string `gorm:"column:open_at;type:varchar(30);default:'';comment:公开(公告)日" json:"open_at"`
|
OpenAt string `gorm:"column:open_at;type:varchar(30);default:'';comment:公开(公告)日" json:"open_at"`
|
||||||
ApplyName string `gorm:"column:apply_name;type:varchar(100);default:'';comment:申请(专利权)人" json:"apply_name"`
|
ApplyName string `gorm:"column:apply_name;type:varchar(255);default:'';comment:申请(专利权)人" json:"apply_name"`
|
||||||
ApplyAddress string `gorm:"column:apply_address;type:varchar(255);default:'';comment:申请人地址" json:"apply_address"`
|
ApplyAddress string `gorm:"column:apply_address;type:varchar(255);default:'';comment:申请人地址" json:"apply_address"`
|
||||||
Inventor string `gorm:"column:inventor;type:varchar(100);default:'';comment:发明人" json:"inventor"`
|
Inventor string `gorm:"column:inventor;type:varchar(255);default:'';comment:发明人" json:"inventor"`
|
||||||
Description string `gorm:"column:description;type:text;comment:摘要" json:"description"`
|
Description string `gorm:"column:description;type:text;comment:摘要" json:"description"`
|
||||||
PrincipalClaim string `gorm:"column:principal_claim;type:text;comment:主权项" json:"principal_claim"`
|
PrincipalClaim string `gorm:"column:principal_claim;type:text;comment:主权项" json:"principal_claim"`
|
||||||
IPCCode string `gorm:"column:ipc_code;type:varchar(50);default:'';comment:IPC主分类号" json:"ipc_code"`
|
IPCCode string `gorm:"column:ipc_code;type:varchar(50);default:'';comment:IPC主分类号" json:"ipc_code"`
|
||||||
|
@ -11,8 +11,8 @@ import (
|
|||||||
"SciencesServer/serve/es"
|
"SciencesServer/serve/es"
|
||||||
"SciencesServer/serve/logger"
|
"SciencesServer/serve/logger"
|
||||||
"SciencesServer/serve/orm"
|
"SciencesServer/serve/orm"
|
||||||
|
"SciencesServer/serve/orm/logic"
|
||||||
"SciencesServer/serve/web"
|
"SciencesServer/serve/web"
|
||||||
"SciencesServer/task"
|
|
||||||
"SciencesServer/tools"
|
"SciencesServer/tools"
|
||||||
"SciencesServer/utils"
|
"SciencesServer/utils"
|
||||||
"strings"
|
"strings"
|
||||||
@ -50,8 +50,6 @@ func (this *Serve) Run() {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
cache.Init()
|
cache.Init()
|
||||||
//orm.Init()
|
|
||||||
// TODO:待优化完善
|
|
||||||
orm.NewInstance(
|
orm.NewInstance(
|
||||||
orm.WithDebug(config.SettingInfo.Engine.Debug),
|
orm.WithDebug(config.SettingInfo.Engine.Debug),
|
||||||
orm.WithDBMode(config.SettingInfo.Engine.DBMode),
|
orm.WithDBMode(config.SettingInfo.Engine.DBMode),
|
||||||
@ -60,9 +58,14 @@ func (this *Serve) Run() {
|
|||||||
orm.WithMaxIdleConns(config.SettingInfo.Engine.MaxIdleConns),
|
orm.WithMaxIdleConns(config.SettingInfo.Engine.MaxIdleConns),
|
||||||
orm.WithMaxOpenConns(config.SettingInfo.Engine.MaxOpenConns),
|
orm.WithMaxOpenConns(config.SettingInfo.Engine.MaxOpenConns),
|
||||||
orm.WithMaxLifetime(config.SettingInfo.Engine.MaxLifetime),
|
orm.WithMaxLifetime(config.SettingInfo.Engine.MaxLifetime),
|
||||||
//orm.WithMysqlUser(config.SettingInfo.Engine.Mysql.User),
|
orm.WithMysqlOption(&logic.Mysql{
|
||||||
).Init()
|
User: config.SettingInfo.Engine.Mysql.User, Password: config.SettingInfo.Engine.Mysql.Password,
|
||||||
task.Init()
|
Host: config.SettingInfo.Engine.Mysql.Host, Port: config.SettingInfo.Engine.Mysql.Port,
|
||||||
|
DBName: config.SettingInfo.Engine.Mysql.DBName, Parameters: config.SettingInfo.Engine.Mysql.Parameters,
|
||||||
|
}),
|
||||||
|
orm.WithSqliteOption(&logic.Sqlite{Path: config.SettingInfo.Engine.Sqlite.Path, Name: config.SettingInfo.Engine.Sqlite.Name}),
|
||||||
|
).Init().Local()
|
||||||
|
//task.Init()
|
||||||
common.Init()
|
common.Init()
|
||||||
cron.Init()
|
cron.Init()
|
||||||
app.Init()
|
app.Init()
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
name: 中科元
|
name: 中科元
|
||||||
# domain 域名
|
# domain 域名
|
||||||
domain: http://192.168.0.144:8000
|
domain: http://192.168.0.145:8000
|
||||||
# token有效时间(秒)
|
# token有效时间(秒)
|
||||||
token_effect_time: 604800
|
token_effect_time: 604800
|
||||||
# multiple_login 多地登录
|
# multiple_login 多地登录
|
||||||
@ -39,7 +39,7 @@ engine:
|
|||||||
user: appuser
|
user: appuser
|
||||||
password: ABCabc01!
|
password: ABCabc01!
|
||||||
db_name: sciences
|
db_name: sciences
|
||||||
parameters: charset=utf8mb4,utf8&parseTime=True&loc=Asia%2FShanghai
|
parameters: charset=utf8mb4,utf8&parseTime=True&loc=Local
|
||||||
# SQLITE 配置
|
# SQLITE 配置
|
||||||
sqlite:
|
sqlite:
|
||||||
path: data
|
path: data
|
||||||
|
@ -142,6 +142,7 @@ func registerEnterpriseAPI(app *gin.Engine) {
|
|||||||
{
|
{
|
||||||
_api := new(api2.Config)
|
_api := new(api2.Config)
|
||||||
configV1.GET("/area", _api.Area)
|
configV1.GET("/area", _api.Area)
|
||||||
|
configV1.GET("/identity", _api.Identity)
|
||||||
}
|
}
|
||||||
// Account 账号管理
|
// Account 账号管理
|
||||||
accountV1 := v1.Group("/account")
|
accountV1 := v1.Group("/account")
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package orm
|
package orm
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"SciencesServer/config"
|
|
||||||
"SciencesServer/serve/orm/logic"
|
"SciencesServer/serve/orm/logic"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
@ -16,20 +15,18 @@ import (
|
|||||||
|
|
||||||
var (
|
var (
|
||||||
orm *gorm.DB
|
orm *gorm.DB
|
||||||
|
|
||||||
engines = map[string]func() logic.IEngine{
|
|
||||||
"mysql": mysql, "sqlite": sqlite,
|
|
||||||
}
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type Instance struct {
|
type Instance struct {
|
||||||
|
Engine *gorm.DB
|
||||||
|
|
||||||
debug bool
|
debug bool
|
||||||
dbMode string
|
dbMode string
|
||||||
tablePrefix string
|
tablePrefix string
|
||||||
singularTable bool
|
singularTable bool
|
||||||
maxIdleConns, maxOpenConns, maxLifetime int
|
maxIdleConns, maxOpenConns, maxLifetime int
|
||||||
*logic.Mysql
|
mysql *logic.Mysql
|
||||||
*logic.Sqlite
|
sqlite *logic.Sqlite
|
||||||
}
|
}
|
||||||
|
|
||||||
type Option func(instance *Instance)
|
type Option func(instance *Instance)
|
||||||
@ -76,29 +73,36 @@ func WithMaxLifetime(maxLifetime int) Option {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func WithMysqlOption(user string) Option {
|
func WithMysqlOption(option *logic.Mysql) Option {
|
||||||
return func(instance *Instance) {
|
return func(instance *Instance) {
|
||||||
instance.Mysql.User = user
|
instance.mysql = option
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func WithSqliteOption(user string) Option {
|
func WithSqliteOption(option *logic.Sqlite) Option {
|
||||||
return func(instance *Instance) {
|
return func(instance *Instance) {
|
||||||
instance.Mysql.User = user
|
instance.sqlite = option
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *Instance) Init() {
|
func (this *Instance) Init() *Instance {
|
||||||
handle, has := engines[this.dbMode]
|
var engine logic.IEngine
|
||||||
|
|
||||||
if !has {
|
switch this.dbMode {
|
||||||
panic(fmt.Sprintf("Unknown Engine Mode:%d", config.SettingInfo.Engine.DBMode))
|
case "mysql":
|
||||||
|
engine = this.mysql
|
||||||
|
break
|
||||||
|
case "sqlite":
|
||||||
|
engine = this.sqlite
|
||||||
|
break
|
||||||
|
default:
|
||||||
|
panic(fmt.Sprintf("Unknown Engine Mode:%d", this.dbMode))
|
||||||
}
|
}
|
||||||
option := &gorm.Config{
|
option := &gorm.Config{
|
||||||
DisableForeignKeyConstraintWhenMigrating: true,
|
DisableForeignKeyConstraintWhenMigrating: true,
|
||||||
NamingStrategy: schema.NamingStrategy{
|
NamingStrategy: schema.NamingStrategy{
|
||||||
TablePrefix: config.SettingInfo.Engine.TablePrefix,
|
TablePrefix: this.tablePrefix,
|
||||||
SingularTable: !config.SettingInfo.Engine.Complex,
|
SingularTable: this.singularTable,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
if this.debug {
|
if this.debug {
|
||||||
@ -112,17 +116,23 @@ func (this *Instance) Init() {
|
|||||||
},
|
},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
db, err := gorm.Open(handle().DSN(), option)
|
db, err := gorm.Open(engine.DSN(), option)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic("Orm Open Error:" + err.Error())
|
panic("Orm Init Error:" + err.Error())
|
||||||
}
|
}
|
||||||
_db, _ := db.DB()
|
_db, _ := db.DB()
|
||||||
_db.SetMaxIdleConns(config.SettingInfo.Engine.MaxIdleConns)
|
_db.SetMaxIdleConns(this.maxIdleConns)
|
||||||
_db.SetMaxOpenConns(config.SettingInfo.Engine.MaxOpenConns)
|
_db.SetMaxOpenConns(this.maxOpenConns)
|
||||||
_db.SetConnMaxLifetime(time.Duration(config.SettingInfo.Engine.MaxLifetime) * time.Second)
|
_db.SetConnMaxLifetime(time.Duration(this.maxLifetime) * time.Second)
|
||||||
|
|
||||||
orm = db
|
this.Engine = db
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *Instance) Local() *Instance {
|
||||||
|
orm = this.Engine
|
||||||
|
return this
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewInstance(option ...Option) *Instance {
|
func NewInstance(option ...Option) *Instance {
|
||||||
@ -134,18 +144,6 @@ func NewInstance(option ...Option) *Instance {
|
|||||||
return instance
|
return instance
|
||||||
}
|
}
|
||||||
|
|
||||||
func mysql() logic.IEngine {
|
|
||||||
return &logic.Mysql{
|
|
||||||
User: config.SettingInfo.Engine.Mysql.User, Password: config.SettingInfo.Engine.Mysql.Password,
|
|
||||||
Host: config.SettingInfo.Engine.Mysql.Host, Port: config.SettingInfo.Engine.Mysql.Port,
|
|
||||||
DBName: config.SettingInfo.Engine.Mysql.DBName, Parameters: config.SettingInfo.Engine.Mysql.Parameters,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func sqlite() logic.IEngine {
|
|
||||||
return &logic.Sqlite{Path: config.SettingInfo.Engine.Sqlite.Path, Name: config.SettingInfo.Engine.Sqlite.Name}
|
|
||||||
}
|
|
||||||
|
|
||||||
func GetDB() *gorm.DB {
|
func GetDB() *gorm.DB {
|
||||||
return orm
|
return orm
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user