feat:优化项目信息
This commit is contained in:
@ -25,7 +25,7 @@ type (
|
||||
// PatentInfo 专利信息
|
||||
PatentInfo struct {
|
||||
ID string `json:"id"`
|
||||
*model.UserPatentInfo
|
||||
*model.TechnologyPatentExpertInfo
|
||||
}
|
||||
// PatentMatchInfo 专利匹配信息
|
||||
PatentMatchInfo struct {
|
||||
@ -83,13 +83,23 @@ func (c *PatentParams) add(tenantID, uid uint64) error {
|
||||
if err = model2.Create(mTechnologyPatent.TechnologyPatent, tx); err != nil {
|
||||
return err
|
||||
}
|
||||
mUserPatent := model.NewUserPatent()
|
||||
mUserPatent.UID = uid
|
||||
mUserPatent.PatentID = mTechnologyPatent.ID
|
||||
// 查询当前的专家信息
|
||||
mUserExpert := model.NewUserExpert()
|
||||
|
||||
if err = model2.Create(mUserPatent.UserPatent, tx); err != nil {
|
||||
if isExist, err = model2.FirstField(mUserExpert.UserExpert, []string{"id", "expert_id"}, model2.NewWhere("uid", uid),
|
||||
model2.NewWhere("invalid_status", model2.InvalidStatusForNot)); err != nil {
|
||||
return err
|
||||
} else if !isExist {
|
||||
return errors.New("操作错误,无专家信息")
|
||||
}
|
||||
mTechnologyPatentExpert := model.NewTechnologyPatentExpert()
|
||||
mTechnologyPatentExpert.ExpertID = mUserExpert.ExpertID
|
||||
mTechnologyPatentExpert.PatentID = mTechnologyPatent.ID
|
||||
|
||||
if err = model2.Create(mTechnologyPatentExpert.TechnologyPatentExpert, tx); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
manage := service.NewESPatent(
|
||||
service.WithPatentID(mTechnologyPatent.ID),
|
||||
service.WithPatentTitle(mTechnologyPatent.Title),
|
||||
@ -116,20 +126,31 @@ func (c *PatentParams) add(tenantID, uid uint64) error {
|
||||
|
||||
// edit 删除专利信息
|
||||
func (c *PatentParams) edit(uid uint64) error {
|
||||
mUserPatent := model.NewUserPatent()
|
||||
mUserPatent.ID = c.ID
|
||||
mTechnologyPatentExpert := model.NewTechnologyPatentExpert()
|
||||
mTechnologyPatentExpert.ID = c.ID
|
||||
|
||||
isExist, err := model2.FirstField(mUserPatent.UserPatent, []string{"id", "uid", "patent_id"})
|
||||
isExist, err := model2.FirstField(mTechnologyPatentExpert.TechnologyPatentExpert, []string{"id", "expert_id", "patent_id"})
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
} else if !isExist {
|
||||
return errors.New("操作错误,用户专利信息不存在或已被删除")
|
||||
} else if mUserPatent.UID != uid {
|
||||
}
|
||||
// 查询当前用户是否存在对应的专家信息
|
||||
mUserExpert := model.NewUserExpert()
|
||||
|
||||
var count int64
|
||||
|
||||
if err = model2.Count(mUserExpert.UserExpert, &count, model2.NewWhere("uid", uid),
|
||||
model2.NewWhere("expert_id", mTechnologyPatentExpert.ExpertID),
|
||||
model2.NewWhere("invalid_status", model2.InvalidStatusForNot),
|
||||
); err != nil {
|
||||
return err
|
||||
} else if count > 0 {
|
||||
return errors.New("操作错误,无权限操作")
|
||||
}
|
||||
mTechnologyPatent := model.NewTechnologyPatent()
|
||||
mTechnologyPatent.ID = mUserPatent.PatentID
|
||||
mTechnologyPatent.ID = mTechnologyPatentExpert.PatentID
|
||||
|
||||
if isExist, err = model2.FirstField(mTechnologyPatent.TechnologyPatent, []string{"id", "apply_code", "open_code", "created_at"}); err != nil {
|
||||
return err
|
||||
@ -180,9 +201,21 @@ func (c *PatentParams) edit(uid uint64) error {
|
||||
|
||||
// List 列表信息
|
||||
func (c *Patent) List(kind int, title, applyCode, openCode, ipcCode string, page, pageSize int) (*controller.ReturnPages, error) {
|
||||
mUserPatent := model.NewUserPatent()
|
||||
// 查询当前用户对应的专家信息
|
||||
mUserExpert := model.NewUserExpert()
|
||||
|
||||
where := []*model2.ModelWhere{model2.NewWhere("u.uid", c.UID)}
|
||||
isExist, err := model2.LastWhere(mUserExpert.UserExpert, []string{"id", "expert_id"},
|
||||
model2.NewWhere("uid", c.UID),
|
||||
model2.NewWhere("invalid_status", model2.InvalidStatusForNot),
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else if !isExist {
|
||||
return nil, nil
|
||||
}
|
||||
mTechnologyPatentExpert := model.NewTechnologyPatentExpert()
|
||||
|
||||
where := []*model2.ModelWhere{model2.NewWhere("u.expert_id", mUserExpert.ExpertID)}
|
||||
|
||||
if kind <= 0 {
|
||||
where = append(where, model2.NewWhere("p.kind", kind))
|
||||
@ -201,16 +234,16 @@ func (c *Patent) List(kind int, title, applyCode, openCode, ipcCode string, page
|
||||
}
|
||||
var count int64
|
||||
|
||||
out, err := mUserPatent.Patent(page, pageSize, &count, where...)
|
||||
out := make([]*model.TechnologyPatentExpertInfo, 0)
|
||||
|
||||
if err != nil {
|
||||
if out, err = mTechnologyPatentExpert.Patent(page, pageSize, &count, where...); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
list := make([]*PatentInfo, 0)
|
||||
|
||||
for _, v := range out {
|
||||
list = append(list, &PatentInfo{
|
||||
ID: v.GetEncodeID(), UserPatentInfo: v,
|
||||
ID: v.GetEncodeID(), TechnologyPatentExpertInfo: v,
|
||||
})
|
||||
}
|
||||
return &controller.ReturnPages{Data: list, Count: count}, nil
|
||||
@ -281,20 +314,18 @@ func (c *Patent) Form(params *PatentParams) error {
|
||||
|
||||
// Delete 删除操作
|
||||
func (c *Patent) Delete(id uint64) error {
|
||||
mUserPatent := model.NewUserPatent()
|
||||
mUserPatent.ID = id
|
||||
mTechnologyPatentExpert := model.NewTechnologyPatentExpert()
|
||||
mTechnologyPatentExpert.ID = id
|
||||
|
||||
isExist, err := model2.FirstField(mUserPatent.UserPatent, []string{"id", "uid", "patent_id"})
|
||||
isExist, err := model2.FirstField(mTechnologyPatentExpert.TechnologyPatentExpert, []string{"id", "patent_id"})
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
} else if !isExist {
|
||||
return errors.New("操作错误,用户专利信息不存在或已被删除")
|
||||
} else if mUserPatent.UID != c.UID {
|
||||
return errors.New("操作错误,无权限操作")
|
||||
}
|
||||
// 只删除关联关系
|
||||
if err = model2.Delete(mUserPatent.UserPatent); err != nil {
|
||||
if err = model2.Delete(mTechnologyPatentExpert.TechnologyPatentExpert); err != nil {
|
||||
return err
|
||||
}
|
||||
//mTechnologyPatent := model.NewTechnologyPatent()
|
||||
|
@ -7,12 +7,12 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
type UserPatent struct {
|
||||
*model.UserPatent
|
||||
type TechnologyPatentExpert struct {
|
||||
*model.TechnologyPatentExpert
|
||||
}
|
||||
|
||||
// UserPatentInfo 用户专利信息
|
||||
type UserPatentInfo struct {
|
||||
// TechnologyPatentExpertInfo 用户专利信息
|
||||
type TechnologyPatentExpertInfo struct {
|
||||
model.Model
|
||||
Title string `json:"title"`
|
||||
ApplyCode string `json:"apply_code"`
|
||||
@ -24,7 +24,7 @@ type UserPatentInfo struct {
|
||||
}
|
||||
|
||||
// Patent 专利信息
|
||||
func (m *UserPatent) Patent(page, pageSize int, count *int64, where ...*model.ModelWhere) ([]*UserPatentInfo, error) {
|
||||
func (m *TechnologyPatentExpert) Patent(page, pageSize int, count *int64, where ...*model.ModelWhere) ([]*TechnologyPatentExpertInfo, error) {
|
||||
db := orm.GetDB().Table(m.TableName()+" AS u").
|
||||
Select("u.id", "p.title", "p.apply_code", "p.apply_name", "p.apply_at", "p.status", "p.created_at").
|
||||
Joins(fmt.Sprintf("LEFT JOIN %s AS p ON u.patent_id = p.id", model.NewTechnologyPatent().TableName())).
|
||||
@ -35,7 +35,7 @@ func (m *UserPatent) Patent(page, pageSize int, count *int64, where ...*model.Mo
|
||||
db = db.Where(v.Condition, v.Value)
|
||||
}
|
||||
}
|
||||
out := make([]*UserPatentInfo, 0)
|
||||
out := make([]*TechnologyPatentExpertInfo, 0)
|
||||
|
||||
if err := db.Count(count).Error; err != nil {
|
||||
return nil, err
|
||||
@ -46,6 +46,6 @@ func (m *UserPatent) Patent(page, pageSize int, count *int64, where ...*model.Mo
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func NewUserPatent() *UserPatent {
|
||||
return &UserPatent{model.NewUserPatent()}
|
||||
func NewTechnologyPatentExpert() *TechnologyPatentExpert {
|
||||
return &TechnologyPatentExpert{model.NewTechnologyPatentExpert()}
|
||||
}
|
Reference in New Issue
Block a user