From 162537e52dbebe509baed4f50ba8bd8f6a520e15 Mon Sep 17 00:00:00 2001 From: henry Date: Mon, 6 Dec 2021 14:55:41 +0800 Subject: [PATCH] =?UTF-8?q?feat=EF=BC=9A=E5=AE=8C=E5=96=84=E5=85=A5?= =?UTF-8?q?=E9=A9=BB=E4=BF=A1=E6=81=AF=E7=AE=A1=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/enterprise/api/config.go | 4 +- app/api/enterprise/api/settled.go | 14 +- .../enterprise/controller/settled/agent.go | 5 + .../enterprise/controller/settled/instance.go | 79 ++++++++- app/api/enterprise/model/user_agent.go | 18 +- app/api/enterprise/model/user_company.go | 24 ++- app/api/enterprise/model/user_expert.go | 18 +- app/api/enterprise/model/user_laboratory.go | 18 +- app/api/enterprise/model/user_research.go | 18 +- app/basic/config/public.go | 20 ++- app/common/model/common.go | 6 +- app/common/model/manage_agent.go | 22 ++- app/common/model/model_test.go | 158 +++++++++++++++--- app/common/model/sys_patent.go | 4 +- cmd/serve/serve.go | 15 +- config.yaml | 4 +- router/address.go | 1 + serve/orm/orm.go | 68 ++++---- 18 files changed, 406 insertions(+), 90 deletions(-) diff --git a/app/api/enterprise/api/config.go b/app/api/enterprise/api/config.go index 5c411d3..8714f3f 100644 --- a/app/api/enterprise/api/config.go +++ b/app/api/enterprise/api/config.go @@ -10,12 +10,12 @@ type Config struct{} func (a *Config) Identity(c *gin.Context) { data := config.NewConfig().Identity() - api.APISuccess(data) + api.APISuccess(data)(c) } func (a *Config) Transaction(c *gin.Context) { data := config.NewConfig().Transaction() - api.APISuccess(data) + api.APISuccess(data)(c) } func (a *Config) Industry(c *gin.Context) { diff --git a/app/api/enterprise/api/settled.go b/app/api/enterprise/api/settled.go index 7df16cd..43fde27 100644 --- a/app/api/enterprise/api/settled.go +++ b/app/api/enterprise/api/settled.go @@ -32,7 +32,8 @@ func (c *settledForm) bind() *settled.BasicParams { // Index 入驻信息 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 公司入驻信息 @@ -106,6 +107,17 @@ func (*Settled) Agent(c *gin.Context) { api.APIFailure(err.(error))(c) 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)). Launch(form.settledForm.bind(), &form.IdentityForAgent) api.APIResponse(err)(c) diff --git a/app/api/enterprise/controller/settled/agent.go b/app/api/enterprise/controller/settled/agent.go index c2a51f9..03e1e4f 100644 --- a/app/api/enterprise/controller/settled/agent.go +++ b/app/api/enterprise/controller/settled/agent.go @@ -53,6 +53,11 @@ func (c *Agent) Launch(params *BasicParams, other *config.IdentityForAgent) erro mManageAgent.Name = params.Name mManageAgent.Mobile = params.Mobile 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.SetKeywordAttribute(params.Keywords) mManageAgent.WorkExperience = other.WorkExperience diff --git a/app/api/enterprise/controller/settled/instance.go b/app/api/enterprise/controller/settled/instance.go index 964e9c4..e54fc9d 100644 --- a/app/api/enterprise/controller/settled/instance.go +++ b/app/api/enterprise/controller/settled/instance.go @@ -1,7 +1,13 @@ 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 { *session.Enterprise local string @@ -9,8 +15,77 @@ type Instance struct { 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 { diff --git a/app/api/enterprise/model/user_agent.go b/app/api/enterprise/model/user_agent.go index 2c966be..dd1b46b 100644 --- a/app/api/enterprise/model/user_agent.go +++ b/app/api/enterprise/model/user_agent.go @@ -1,11 +1,27 @@ package model -import "SciencesServer/app/common/model" +import ( + "SciencesServer/app/common/model" + "SciencesServer/serve/orm" + "fmt" +) type UserAgent struct { *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 { return &UserAgent{model.NewUserAgent()} } diff --git a/app/api/enterprise/model/user_company.go b/app/api/enterprise/model/user_company.go index 4843a94..29db93f 100644 --- a/app/api/enterprise/model/user_company.go +++ b/app/api/enterprise/model/user_company.go @@ -1,11 +1,33 @@ package model -import "SciencesServer/app/common/model" +import ( + "SciencesServer/app/common/model" + "SciencesServer/serve/orm" + "fmt" +) type UserCompany struct { *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 { return &UserCompany{model.NewUserCompany()} } diff --git a/app/api/enterprise/model/user_expert.go b/app/api/enterprise/model/user_expert.go index 86db22a..ec84f8a 100644 --- a/app/api/enterprise/model/user_expert.go +++ b/app/api/enterprise/model/user_expert.go @@ -1,11 +1,27 @@ package model -import "SciencesServer/app/common/model" +import ( + "SciencesServer/app/common/model" + "SciencesServer/serve/orm" + "fmt" +) type UserExpert struct { *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 { return &UserExpert{model.NewUserExpert()} } diff --git a/app/api/enterprise/model/user_laboratory.go b/app/api/enterprise/model/user_laboratory.go index 8364dec..8ad2c8d 100644 --- a/app/api/enterprise/model/user_laboratory.go +++ b/app/api/enterprise/model/user_laboratory.go @@ -1,11 +1,27 @@ package model -import "SciencesServer/app/common/model" +import ( + "SciencesServer/app/common/model" + "SciencesServer/serve/orm" + "fmt" +) type UserLaboratory struct { *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 { return &UserLaboratory{model.NewUserLaboratory()} } diff --git a/app/api/enterprise/model/user_research.go b/app/api/enterprise/model/user_research.go index 994173b..d782853 100644 --- a/app/api/enterprise/model/user_research.go +++ b/app/api/enterprise/model/user_research.go @@ -1,11 +1,27 @@ package model -import "SciencesServer/app/common/model" +import ( + "SciencesServer/app/common/model" + "SciencesServer/serve/orm" + "fmt" +) type UserResearch struct { *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 { return &UserResearch{model.NewUserResearch()} } diff --git a/app/basic/config/public.go b/app/basic/config/public.go index 7576672..d0fae2b 100644 --- a/app/basic/config/public.go +++ b/app/basic/config/public.go @@ -41,13 +41,19 @@ type ( } // IdentityForAgent 经纪人 IdentityForAgent struct { - ResearchID uint64 `json:"research_id" form:"research_id" binding:"required"` // 科研机构ID - IDCard string `json:"id_card" form:"id_card" binding:"required"` // 身份证号 - WorkExperience string `json:"work_experience" form:"work_experience" binding:"required"` // 工作经历 - WorkPlace string `json:"work_place" form:"work_place" binding:"required"` // 工作地点 - CredentialImages []string `json:"credential_images" form:"credential_images"` // 资格证书 - Longitude float64 `json:"longitude" form:"longitude"` // 经度 - Latitude float64 `json:"latitude" form:"latitude"` // 纬度 + ResearchID uint64 `json:"research_id" form:"research_id" binding:"required"` // 科研机构ID + IDCard string `json:"id_card" form:"id_card" binding:"required"` // 身份证号 + WorkExperience string `json:"work_experience" form:"work_experience" 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"` // 资格证书 + Longitude float64 `json:"longitude" form:"longitude"` // 经度 + Latitude float64 `json:"latitude" form:"latitude"` // 纬度 } ) diff --git a/app/common/model/common.go b/app/common/model/common.go index 09e25ac..46de9db 100644 --- a/app/common/model/common.go +++ b/app/common/model/common.go @@ -113,10 +113,10 @@ type InvalidStatus struct { type InvalidStatusKind int const ( - // InvalidStatusForNot 未失效 - InvalidStatusForNot InvalidStatusKind = iota // InvalidStatusForYes 已失效 - InvalidStatusForYes + InvalidStatusForYes InvalidStatusKind = iota - 1 + // InvalidStatusForNot 未失效 + InvalidStatusForNot ) type Area struct { diff --git a/app/common/model/manage_agent.go b/app/common/model/manage_agent.go index 188bad8..eeee27c 100644 --- a/app/common/model/manage_agent.go +++ b/app/common/model/manage_agent.go @@ -1,6 +1,9 @@ package model -import "SciencesServer/utils" +import ( + "SciencesServer/utils" + "encoding/json" +) // ManageAgent 经纪人入驻信息管理 type ManageAgent struct { @@ -9,18 +12,22 @@ type ManageAgent struct { Name string `gorm:"column:name;type:varchar(30);default:'';comment:姓名" json:"name"` 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"` + IDImage string `gorm:"column:id_image;type:text;comment:身份证图片" json:"-"` Industry string `gorm:"column:industry;type:varchar(255);default:'';comment:行业领域" json:"industry"` 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"` 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"` Examine ModelDeleted ModelAt } +// ManageAgentIDImage 身份证信息 type ManageAgentIDImage struct { + Front string `json:"front"` + Behind string `json:"behind"` + Hold string `json:"hold"` } func (m *ManageAgent) TableName() string { @@ -47,6 +54,17 @@ func (m *ManageAgent) SetKeywordAttribute(value []string) { 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 { out := make([]string, 0) _ = utils.FromJSON(m.CredentialImage, &out) diff --git a/app/common/model/model_test.go b/app/common/model/model_test.go index b285d82..2f54820 100644 --- a/app/common/model/model_test.go +++ b/app/common/model/model_test.go @@ -1,32 +1,144 @@ package model import ( - GormEngine "github.com/belief428/gorm-engine" - "github.com/belief428/gorm-engine/engine" - "github.com/belief428/gorm-engine/logic" - + "SciencesServer/serve/orm" + "SciencesServer/serve/orm/logic" + "SciencesServer/utils" "gorm.io/gorm" + "strings" + "testing" + "time" ) -var ( - _db *gorm.DB -) +// PPatent 专利信息数据模型 +type PPatent struct { + Model + Kind string `gorm:"column:kind;type:tinyint(1);default:0;comment:专利类型" json:"kind"` + Title string `gorm:"column:title;type:varchar(255);default:'';comment:名称标题" json:"title"` + FileUrl string `gorm:"column:file_url;type:varchar(255);default:'';comment:文件地址" json:"file_url"` + ApplyCode string `gorm:"column:apply_code;type:varchar(50);default:'';comment:申请号" json:"apply_code"` + 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"` + 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 mysql() logic.IEngine { - return &engine.MConfig{ - User: "appuser", Password: "ABCabc01!", - Host: "192.168.99.188", Port: 3306, - DBName: "iot", Parameters: "charset=utf8mb4,utf8&parseTime=True&loc=Asia%2FShanghai", +func (m *PPatent) TableName() string { + return "manage_patent" +} + +func mysql() *gorm.DB { + instance := orm.NewInstance( + orm.WithDebug(true), + orm.WithDBMode("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 + } } } - -func _init() { - _db = GormEngine.NewEngine()(1, &GormEngine.EngineConfig{ - Debug: true, - TablePrefix: "", - Complex: false, - MaxIdleConns: 50, - MaxOpenConns: 150, - MaxLifetime: 3600, - }).Start(mysql()) -} diff --git a/app/common/model/sys_patent.go b/app/common/model/sys_patent.go index 838cf01..cc277f3 100644 --- a/app/common/model/sys_patent.go +++ b/app/common/model/sys_patent.go @@ -10,9 +10,9 @@ type SysPatent struct { 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"` 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"` - 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"` 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"` diff --git a/cmd/serve/serve.go b/cmd/serve/serve.go index b9d91dc..13363e7 100644 --- a/cmd/serve/serve.go +++ b/cmd/serve/serve.go @@ -11,8 +11,8 @@ import ( "SciencesServer/serve/es" "SciencesServer/serve/logger" "SciencesServer/serve/orm" + "SciencesServer/serve/orm/logic" "SciencesServer/serve/web" - "SciencesServer/task" "SciencesServer/tools" "SciencesServer/utils" "strings" @@ -50,8 +50,6 @@ func (this *Serve) Run() { }) }) cache.Init() - //orm.Init() - // TODO:待优化完善 orm.NewInstance( orm.WithDebug(config.SettingInfo.Engine.Debug), orm.WithDBMode(config.SettingInfo.Engine.DBMode), @@ -60,9 +58,14 @@ func (this *Serve) Run() { orm.WithMaxIdleConns(config.SettingInfo.Engine.MaxIdleConns), orm.WithMaxOpenConns(config.SettingInfo.Engine.MaxOpenConns), orm.WithMaxLifetime(config.SettingInfo.Engine.MaxLifetime), - //orm.WithMysqlUser(config.SettingInfo.Engine.Mysql.User), - ).Init() - task.Init() + orm.WithMysqlOption(&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, + }), + orm.WithSqliteOption(&logic.Sqlite{Path: config.SettingInfo.Engine.Sqlite.Path, Name: config.SettingInfo.Engine.Sqlite.Name}), + ).Init().Local() + //task.Init() common.Init() cron.Init() app.Init() diff --git a/config.yaml b/config.yaml index 42a1341..4bcd755 100644 --- a/config.yaml +++ b/config.yaml @@ -1,6 +1,6 @@ name: 中科元 # domain 域名 -domain: http://192.168.0.144:8000 +domain: http://192.168.0.145:8000 # token有效时间(秒) token_effect_time: 604800 # multiple_login 多地登录 @@ -39,7 +39,7 @@ engine: user: appuser password: ABCabc01! db_name: sciences - parameters: charset=utf8mb4,utf8&parseTime=True&loc=Asia%2FShanghai + parameters: charset=utf8mb4,utf8&parseTime=True&loc=Local # SQLITE 配置 sqlite: path: data diff --git a/router/address.go b/router/address.go index 9f70855..a754a00 100644 --- a/router/address.go +++ b/router/address.go @@ -142,6 +142,7 @@ func registerEnterpriseAPI(app *gin.Engine) { { _api := new(api2.Config) configV1.GET("/area", _api.Area) + configV1.GET("/identity", _api.Identity) } // Account 账号管理 accountV1 := v1.Group("/account") diff --git a/serve/orm/orm.go b/serve/orm/orm.go index b8b79fb..8d8841a 100644 --- a/serve/orm/orm.go +++ b/serve/orm/orm.go @@ -1,7 +1,6 @@ package orm import ( - "SciencesServer/config" "SciencesServer/serve/orm/logic" "fmt" "log" @@ -16,20 +15,18 @@ import ( var ( orm *gorm.DB - - engines = map[string]func() logic.IEngine{ - "mysql": mysql, "sqlite": sqlite, - } ) type Instance struct { + Engine *gorm.DB + debug bool dbMode string tablePrefix string singularTable bool maxIdleConns, maxOpenConns, maxLifetime int - *logic.Mysql - *logic.Sqlite + mysql *logic.Mysql + sqlite *logic.Sqlite } 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) { - instance.Mysql.User = user + instance.mysql = option } } -func WithSqliteOption(user string) Option { +func WithSqliteOption(option *logic.Sqlite) Option { return func(instance *Instance) { - instance.Mysql.User = user + instance.sqlite = option } } -func (this *Instance) Init() { - handle, has := engines[this.dbMode] +func (this *Instance) Init() *Instance { + var engine logic.IEngine - if !has { - panic(fmt.Sprintf("Unknown Engine Mode:%d", config.SettingInfo.Engine.DBMode)) + switch this.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{ DisableForeignKeyConstraintWhenMigrating: true, NamingStrategy: schema.NamingStrategy{ - TablePrefix: config.SettingInfo.Engine.TablePrefix, - SingularTable: !config.SettingInfo.Engine.Complex, + TablePrefix: this.tablePrefix, + SingularTable: this.singularTable, }, } 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 { - panic("Orm Open Error:" + err.Error()) + panic("Orm Init Error:" + err.Error()) } _db, _ := db.DB() - _db.SetMaxIdleConns(config.SettingInfo.Engine.MaxIdleConns) - _db.SetMaxOpenConns(config.SettingInfo.Engine.MaxOpenConns) - _db.SetConnMaxLifetime(time.Duration(config.SettingInfo.Engine.MaxLifetime) * time.Second) + _db.SetMaxIdleConns(this.maxIdleConns) + _db.SetMaxOpenConns(this.maxOpenConns) + _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 { @@ -134,18 +144,6 @@ func NewInstance(option ...Option) *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 { return orm }