feat:优化项目信息,待测试修改

This commit is contained in:
henry
2022-02-06 18:01:32 +08:00
parent c8578940bf
commit a25464289f
25 changed files with 404 additions and 483 deletions

View File

@ -6,11 +6,10 @@ import (
"SciencesServer/app/basic/controller"
model2 "SciencesServer/app/common/model"
"SciencesServer/app/session"
"SciencesServer/serve/orm"
"SciencesServer/utils"
"errors"
"fmt"
"gorm.io/gorm"
"time"
)
// Patent 专利信息
@ -30,7 +29,7 @@ type (
// PatentDetailInfo 专利详细信息
PatentDetailInfo struct {
ID string `json:"id"`
*model2.SysPatent
*model2.TechnologyPatent
}
// PatentParams 专利参数信息
PatentParams struct {
@ -57,7 +56,7 @@ type (
}
)
func (c *Patent) ipcTree(src []*model2.SysPatentClassify, parentID uint64) []*PatentIPCInfo {
func (c *Patent) ipcTree(src []*model2.TechnologyPatentClassify, parentID uint64) []*PatentIPCInfo {
out := make([]*PatentIPCInfo, 0)
for _, v := range src {
@ -79,7 +78,7 @@ func (c *Patent) ipcTree(src []*model2.SysPatentClassify, parentID uint64) []*Pa
return out
}
func (c *PatentParams) checkParams(iModel *model.SysPatent, condition map[string]interface{}) error {
func (c *PatentParams) checkParams(iModel *model.TechnologyPatent, condition map[string]interface{}) error {
isExist, err := iModel.IsExistParams(condition)
if err != nil {
@ -92,10 +91,17 @@ func (c *PatentParams) checkParams(iModel *model.SysPatent, condition map[string
// Instance 首页信息
func (c *Patent) Instance(tenantID uint64, title, ipc string, page, pageSize int) (*controller.ReturnPages, error) {
mSysPatent := model.NewSysPatent()
mSysPatent := model.NewTechnologyPatent()
where := make([]*model2.ModelWhere, 0)
if c.TenantID > 0 {
where = append(where, model2.NewWhere("p.tenant_id", c.TenantID))
}
if tenantID > 0 {
where = append(where, model2.NewWhere("p.tenant_id", tenantID))
}
if title != "" {
where = append(where, model2.NewWhereLike("p.title", title))
}
@ -123,140 +129,152 @@ func (c *Patent) Instance(tenantID uint64, title, ipc string, page, pageSize int
// Detail 详细信息
func (c *Patent) Detail(id uint64) (*PatentDetailInfo, error) {
mSysPatent := model.NewSysPatent()
mSysPatent.ID = id
mTechnologyPatent := model.NewTechnologyPatent()
mTechnologyPatent.ID = id
isExist, err := model2.First(mSysPatent.SysPatent)
isExist, err := model2.First(mTechnologyPatent.TechnologyPatent)
if err != nil {
return nil, err
} else if !isExist {
return nil, errors.New("操作错误,专利信息不存在或已被删除")
}
return &PatentDetailInfo{ID: mSysPatent.GetEncodeID(), SysPatent: mSysPatent.SysPatent}, nil
return &PatentDetailInfo{ID: mTechnologyPatent.GetEncodeID(),
TechnologyPatent: mTechnologyPatent.TechnologyPatent}, nil
}
// Form 数据操作
func (c *Patent) Form(params *PatentParams) error {
mSysPatent := model.NewSysPatent()
mTechnologyPatent := model.NewTechnologyPatent()
_condition := make(map[string]interface{}, 0)
if params.ID > 0 {
mSysPatent.ID = params.ID
mTechnologyPatent.ID = params.ID
isExist, err := model2.FirstField(mSysPatent.SysPatent, []string{"id", "tenant_id", "apply_code", "ipc_code", "created_at"})
isExist, err := model2.FirstField(mTechnologyPatent.TechnologyPatent, []string{"id", "tenant_id", "uid", "apply_code", "ipc_code", "created_at"})
if err != nil {
return err
} else if !isExist {
return errors.New("操作错误,专利信息不存在或已被删除")
} else if c.TenantID > 0 && mTechnologyPatent.TenantID > 0 && c.TenantID != mTechnologyPatent.TenantID {
return errors.New("操作错误,无权限操作")
}
if mSysPatent.ApplyCode != params.ApplyCode {
if mTechnologyPatent.ApplyCode != params.ApplyCode {
_condition["apply_code"] = params.ApplyCode
}
if mSysPatent.IPCCode != params.IPCCode {
if mTechnologyPatent.IPCCode != params.IPCCode {
_condition["ipc_code"] = params.IPCCode
}
if len(_condition) > 0 {
if isExist, err = mSysPatent.IsExistParams(_condition); err != nil {
if isExist, err = mTechnologyPatent.IsExistParams(_condition); err != nil {
return err
} else if isExist {
return errors.New("操作错误,申请号或公开(公告)号已存在")
}
}
}
mSysPatent.Kind = model2.SysParentKind(params.Kind)
mSysPatent.Title = params.Title
mSysPatent.FileUrl = params.FileUrl
mSysPatent.ApplyCode = params.ApplyCode
mSysPatent.ApplyAt = params.ApplyAt
mSysPatent.OpenCode = params.OpenCode
mSysPatent.OpenAt = params.OpenAt
mSysPatent.ApplyName = params.ApplyName
mSysPatent.ApplyAddress = params.ApplyAddress
mSysPatent.Inventor = params.Inventor
mSysPatent.Description = params.Description
mSysPatent.PrincipalClaim = params.PrincipalClaim
mSysPatent.IPCCode = params.IPCCode
mSysPatent.ShelfStatus = model2.ShelfStatusKind(params.ShelfStatus)
mSysPatent.Status = model2.SysParentStatus(params.Status)
mTechnologyPatent.Kind = model2.SysParentKind(params.Kind)
mTechnologyPatent.Title = params.Title
mTechnologyPatent.FileUrl = params.FileUrl
mTechnologyPatent.ApplyCode = params.ApplyCode
mTechnologyPatent.ApplyAt = params.ApplyAt
mTechnologyPatent.OpenCode = params.OpenCode
mTechnologyPatent.OpenAt = params.OpenAt
mTechnologyPatent.ApplyName = params.ApplyName
mTechnologyPatent.ApplyAddress = params.ApplyAddress
mTechnologyPatent.Inventor = params.Inventor
mTechnologyPatent.Description = params.Description
mTechnologyPatent.PrincipalClaim = params.PrincipalClaim
mTechnologyPatent.IPCCode = params.IPCCode
mTechnologyPatent.ShelfStatus = model2.ShelfStatusKind(params.ShelfStatus)
mTechnologyPatent.Status = model2.SysParentStatus(params.Status)
if mSysPatent.ID > 0 {
return model2.Updates(mSysPatent.SysPatent, mSysPatent.SysPatent)
if mTechnologyPatent.ID > 0 {
return model2.Updates(mTechnologyPatent.TechnologyPatent, mTechnologyPatent.TechnologyPatent)
}
_condition["apply_code"] = params.ApplyCode
_condition["ipc_code"] = params.IPCCode
if isExist, err := mSysPatent.IsExistParams(_condition); err != nil {
if isExist, err := mTechnologyPatent.IsExistParams(_condition); err != nil {
return err
} else if isExist {
return errors.New("操作错误,申请号或公开(公告)号已存在")
}
return model2.Create(mSysPatent.SysPatent)
mTechnologyPatent.TenantID = c.TenantID
return model2.Create(mTechnologyPatent.TechnologyPatent)
}
// Bind 绑定信息
func (c *Patent) Bind(id, uid uint64) error {
mSysPatent := model.NewSysPatent()
mSysPatent.ID = id
mTechnologyPatent := model.NewTechnologyPatent()
mTechnologyPatent.ID = id
isExist, err := model2.FirstField(mSysPatent.SysPatent, []string{"id", "tenant_id"})
isExist, err := model2.FirstField(mTechnologyPatent.TechnologyPatent, []string{"id", "uid", "tenant_id"})
if err != nil {
return err
} else if !isExist {
return errors.New("操作错误,专利信息不存在或已被删除")
} else if c.TenantID > 0 && mTechnologyPatent.TenantID > 0 && c.TenantID != mTechnologyPatent.TenantID {
return errors.New("操作错误,无权限操作")
}
mUserPatent := model.NewUserPatent()
if isExist, err = model2.FirstField(mUserPatent.UserPatent, []string{"id", "uid"}, model2.NewWhere("patent_id", id)); err != nil {
if err = model2.Updates(mTechnologyPatent.TechnologyPatent, map[string]interface{}{
"uid": uid, "updated_at": time.Now(),
}); err != nil {
return err
} else if !isExist {
mUserPatent.UID = uid
mUserPatent.PatentID = id
return model2.Create(mUserPatent.UserPatent)
}
if mUserPatent.UID == uid {
return nil
}
return orm.GetDB().Transaction(func(tx *gorm.DB) error {
if err = model2.DeleteWhere(mUserPatent.UserPatent, []*model2.ModelWhere{model2.NewWhere("patent_id", id)}); err != nil {
return err
}
mUserPatent.UID = uid
mUserPatent.PatentID = id
return model2.Create(mUserPatent.UserPatent, tx)
})
return nil
//mUserPatent := model.NewUserPatent()
//if isExist, err = model2.FirstField(mUserPatent.UserPatent, []string{"id", "uid"}, model2.NewWhere("patent_id", id)); err != nil {
// return err
//} else if !isExist {
// mUserPatent.UID = uid
// mUserPatent.PatentID = id
// return model2.Create(mUserPatent.UserPatent)
//}
//if mUserPatent.UID == uid {
// return nil
//}
//return orm.GetDB().Transaction(func(tx *gorm.DB) error {
// if err = model2.DeleteWhere(mUserPatent.UserPatent, []*model2.ModelWhere{model2.NewWhere("patent_id", id)}); err != nil {
// return err
// }
// mUserPatent.UID = uid
// mUserPatent.PatentID = id
// return model2.Create(mUserPatent.UserPatent, tx)
//})
}
func (c *Patent) Shelf(id uint64) error {
return controller.NewShelf(controller.WithShelfSessionAdmin(c.Admin)).Handle(model2.NewSysPatent(), id)
return controller.NewShelf(controller.WithShelfSessionAdmin(c.Admin)).Handle(model2.NewTechnologyPatent(), id)
}
// Delete 删除操作
func (c *Patent) Delete(id uint64) error {
mSysPatent := model.NewSysPatent()
mSysPatent.ID = id
mTechnologyPatent := model.NewTechnologyPatent()
mTechnologyPatent.ID = id
isExist, err := model2.FirstField(mSysPatent.SysPatent, []string{"id", "tenant_id"})
isExist, err := model2.FirstField(mTechnologyPatent.TechnologyPatent, []string{"id", "uid", "tenant_id"})
if err != nil {
return err
} else if !isExist {
return errors.New("操作错误,专利信息不存在或已被删除")
} else if c.TenantID > 0 && mSysPatent.TenantID != c.TenantID {
} else if c.TenantID > 0 && mTechnologyPatent.TenantID > 0 && c.TenantID != mTechnologyPatent.TenantID {
return errors.New("操作错误,无权限操作")
}
return model2.Delete(mSysPatent.SysPatent)
return model2.Delete(mTechnologyPatent.TechnologyPatent)
}
// IPC IPC信息
func (c *Patent) IPC() ([]*PatentIPCInfo, error) {
mSysPatentClassify := model.NewSysPatentClassify()
out := make([]*model2.SysPatentClassify, 0)
mTechnologyPatentClassify := model.NewTechnologyPatentClassify()
out := make([]*model2.TechnologyPatentClassify, 0)
if err := model2.Scan(mSysPatentClassify.SysPatentClassify, &out); err != nil {
if err := model2.Scan(mTechnologyPatentClassify.TechnologyPatentClassify, &out); err != nil {
return nil, err
}
return c.ipcTree(out, 0), nil
@ -264,12 +282,12 @@ func (c *Patent) IPC() ([]*PatentIPCInfo, error) {
// IPCForm IPC数据操作
func (c *Patent) IPCForm(params *PatentIPCParams) error {
mSysPatentClassify := model.NewSysPatentClassify()
mTechnologyPatentClassify := model.NewTechnologyPatentClassify()
if params.ID > 0 {
mSysPatentClassify.ID = params.ID
mTechnologyPatentClassify.ID = params.ID
isExist, err := model2.FirstField(mSysPatentClassify.SysPatentClassify, []string{"id", "created_at"})
isExist, err := model2.FirstField(mTechnologyPatentClassify.TechnologyPatentClassify, []string{"id", "created_at"})
if err != nil {
return err
@ -277,20 +295,20 @@ func (c *Patent) IPCForm(params *PatentIPCParams) error {
return errors.New("操作错误IPC信息不存在或已被删除")
}
}
mSysPatentClassify.SetIndustryDetailAttribute(params.Industrys)
mTechnologyPatentClassify.SetIndustryDetailAttribute(params.Industrys)
// 查询上级元素
if params.ParentID > 0 {
mPSysPatentClassify := model.NewSysPatentClassify()
mPSysPatentClassify.ID = params.ParentID
mPTechnologyPatentClassify := model.NewTechnologyPatentClassify()
mPTechnologyPatentClassify.ID = params.ParentID
isExist, err := model2.FirstField(mPSysPatentClassify.SysPatentClassify, []string{"id", "industry"})
isExist, err := model2.FirstField(mPTechnologyPatentClassify.TechnologyPatentClassify, []string{"id", "industry"})
if err != nil {
return err
} else if !isExist {
return errors.New("操作错误IPC父级信息不存在或已被删除")
}
_identitys := mPSysPatentClassify.GetIndustryDetailAttribute()
_identitys := mPTechnologyPatentClassify.GetIndustryDetailAttribute()
for _, v := range params.Industrys {
if utils.InArray(v, _identitys) {
@ -298,32 +316,31 @@ func (c *Patent) IPCForm(params *PatentIPCParams) error {
}
_identitys = append(_identitys, v)
}
mSysPatentClassify.SetIndustryDetailAttribute(_identitys)
mTechnologyPatentClassify.SetIndustryDetailAttribute(_identitys)
}
mSysPatentClassify.ParentID = params.ParentID
mSysPatentClassify.IPC = params.IPC
mSysPatentClassify.SetIndustryAttribute(params.Industrys)
mTechnologyPatentClassify.ParentID = params.ParentID
mTechnologyPatentClassify.IPC = params.IPC
mTechnologyPatentClassify.SetIndustryAttribute(params.Industrys)
if mSysPatentClassify.ID > 0 {
return model2.Updates(mSysPatentClassify.SysPatentClassify, mSysPatentClassify.SysPatentClassify)
if mTechnologyPatentClassify.ID > 0 {
return model2.Updates(mTechnologyPatentClassify.TechnologyPatentClassify, mTechnologyPatentClassify.TechnologyPatentClassify)
}
return model2.Create(mSysPatentClassify.SysPatentClassify)
return model2.Create(mTechnologyPatentClassify.TechnologyPatentClassify)
}
// IPCDelete IPC删除操作
func (c *Patent) IPCDelete(id uint64) error {
mSysPatentClassify := model.NewSysPatentClassify()
mSysPatentClassify.ID = id
mTechnologyPatentClassify := model.NewTechnologyPatentClassify()
mTechnologyPatentClassify.ID = id
isExist, err := model2.FirstField(mSysPatentClassify.SysPatentClassify, []string{"id", "created_at"})
isExist, err := model2.FirstField(mTechnologyPatentClassify.TechnologyPatentClassify, []string{"id", "created_at"})
if err != nil {
return err
} else if !isExist {
return errors.New("操作错误IPC信息不存在或已被删除")
}
return model2.Delete(mSysPatentClassify.SysPatentClassify)
return model2.Delete(mTechnologyPatentClassify.TechnologyPatentClassify)
}
func NewPatent() PatentHandle {

View File

@ -53,13 +53,13 @@ func (m *ManageExpert) Experts(page, pageSize int, count *int64, where ...*model
Joins(fmt.Sprintf("LEFT JOIN %s AS r ON e.research_id = r.id", model.NewManageResearch().TableName())).
Joins(fmt.Sprintf("LEFT JOIN %s AS l ON e.laboratory_id = l.id", model.NewManageLaboratory().TableName())).
Joins(fmt.Sprintf("LEFT JOIN %s AS t ON e.tenant_id = t.id", model.NewSysTenant().TableName())).
Joins(fmt.Sprintf("LEFT JOIN (SELECT u.expert_id, SUM(t_a.count) AS achievement_count, SUM(u_p.count) AS patent_count FROM %s AS u "+
Joins(fmt.Sprintf("LEFT JOIN (SELECT u.expert_id, SUM(t_a.count) AS achievement_count, SUM(p.count) AS patent_count FROM %s AS u "+
"LEFT JOIN (SELECT uid, COUNT(id) AS count FROM %s WHERE is_deleted = %d AND status = %d GROUP BY uid) AS t_a ON u.uid = t_a.uid "+
"LEFT JOIN (SELECT uid, COUNT(id) AS count FROM %s WHERE is_deleted = %d GROUP BY uid) AS u_p ON u.uid = u_p.uid "+
" WHERE u.is_deleted = %d AND u.invalid_status = %d GROUP BY u.expert_id) AS u ON e.id = u.expert_id",
"LEFT JOIN (SELECT uid, COUNT(id) AS count FROM %s WHERE is_deleted = %d GROUP BY uid) AS p ON u.uid = p.uid "+
"WHERE u.is_deleted = %d AND u.invalid_status = %d GROUP BY u.expert_id) AS u ON e.id = u.expert_id",
model.NewUserExpert().TableName(),
model.NewTechnologyAchievement().TableName(), model.DeleteStatusForNot, model.TechnologyStatusKindForAgree,
model.NewUserPatent().TableName(), model.DeleteStatusForNot,
model.NewTechnologyPatent().TableName(), model.DeleteStatusForNot,
model.DeleteStatusForNot, model.InvalidStatusForNot)).
Where("e.is_deleted = ?", model.DeleteStatusForNot)

View File

@ -7,9 +7,9 @@ import (
"time"
)
// SysPatent 专利信息
type SysPatent struct {
*model.SysPatent
// TechnologyPatent 专利信息
type TechnologyPatent struct {
*model.TechnologyPatent
}
// SysPatentInfo 专利信息
@ -26,7 +26,7 @@ type SysPatentInfo struct {
CreatedAt time.Time `json:"created_at"`
}
func (m *SysPatent) IsExistParams(params map[string]interface{}) (bool, error) {
func (m *TechnologyPatent) IsExistParams(params map[string]interface{}) (bool, error) {
var count int64
db := orm.GetDB().Table(m.TableName())
@ -40,12 +40,10 @@ func (m *SysPatent) IsExistParams(params map[string]interface{}) (bool, error) {
}
// Patent 专利信息
func (m *SysPatent) Patent(page, pageSize int, count *int64, where ...*model.ModelWhere) ([]*SysPatentInfo, error) {
func (m *TechnologyPatent) Patent(page, pageSize int, count *int64, where ...*model.ModelWhere) ([]*SysPatentInfo, error) {
db := orm.GetDB().Table(m.TableName()+" AS p").
Select("p.id", "p.title", "p.apply_code", "p.inventor", "p.apply_name", "p.apply_at", "u.uid",
"p.shelf_status", "p.created_at").
Joins(fmt.Sprintf("LEFT JOIN %s AS u ON p.id = u.patent_id AND u.is_deleted = %d",
model.NewUserPatent().TableName(), model.DeleteStatusForNot))
"p.shelf_status", "p.created_at")
if len(where) > 0 {
for _, wo := range where {
@ -63,6 +61,6 @@ func (m *SysPatent) Patent(page, pageSize int, count *int64, where ...*model.Mod
return out, nil
}
func NewSysPatent() *SysPatent {
return &SysPatent{model.NewSysPatent()}
func NewTechnologyPatent() *TechnologyPatent {
return &TechnologyPatent{model.NewTechnologyPatent()}
}

View File

@ -1,11 +0,0 @@
package model
import "SciencesServer/app/common/model"
type UserPatent struct {
*model.UserPatent
}
func NewUserPatent() *UserPatent {
return &UserPatent{model.NewUserPatent()}
}