feat:优化项目信息
This commit is contained in:
@ -45,6 +45,12 @@ type (
|
||||
Researchs []string `json:"researchs"`
|
||||
Area string `json:"area"`
|
||||
}
|
||||
// ExpertPatent 专家专利信息
|
||||
ExpertPatent struct {
|
||||
ID string `json:"id"`
|
||||
*model.ManageExpertPatent
|
||||
IsBind bool `json:"is_bind"`
|
||||
}
|
||||
)
|
||||
|
||||
// Instance 首页信息
|
||||
@ -191,6 +197,97 @@ func (c *Expert) Form(params *BasicParams, other *config.IdentityForExpert) erro
|
||||
return model2.Create(mManageExpert.ManageExpert)
|
||||
}
|
||||
|
||||
// Patent 专利信息
|
||||
func (c *Expert) Patent(id uint64, title, applyName string) ([]*ExpertPatent, error) {
|
||||
mManageExpert := model.NewManageExpert()
|
||||
|
||||
out, err := mManageExpert.Basic(id)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else if out == nil || out.ID <= 0 {
|
||||
return nil, errors.New("操作错误,未找到对应的专家信息")
|
||||
}
|
||||
// 查看专利信息
|
||||
patents := make([]*model.ManageExpertPatent, 0)
|
||||
|
||||
where := []*model2.ModelWhere{
|
||||
//model2.NewWhereFindInSet("p.apply_name", out.ResearchName),
|
||||
model2.NewWhereFindInSet("p.inventor", out.Name),
|
||||
}
|
||||
if title != "" {
|
||||
where = append(where, model2.NewWhereLike("p.title", title))
|
||||
}
|
||||
if applyName != "" {
|
||||
where = append(where, model2.NewWhereFindInSet("p.apply_name", applyName))
|
||||
}
|
||||
if patents, err = mManageExpert.Patents(where...); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
list := make([]*ExpertPatent, 0)
|
||||
|
||||
for _, v := range patents {
|
||||
list = append(list, &ExpertPatent{
|
||||
ID: v.GetEncodeID(),
|
||||
ManageExpertPatent: v,
|
||||
IsBind: v.UserPatentCount > 0,
|
||||
})
|
||||
}
|
||||
return list, nil
|
||||
}
|
||||
|
||||
// PatentBind 专利认领绑定
|
||||
func (c *Expert) PatentBind(id uint64, patentID []uint64) error {
|
||||
mUserExpert := model.NewUserExpert()
|
||||
|
||||
uids := make([]uint64, 0)
|
||||
|
||||
err := model2.Pluck(mUserExpert.UserExpert, "uid", &uids, model2.NewWhere("expert_id", id),
|
||||
model2.NewWhere("invalid_status", model2.InvalidStatusForNot))
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if len(uids) <= 0 {
|
||||
return nil
|
||||
}
|
||||
data := make([]*model2.UserPatent, 0)
|
||||
|
||||
for _, uid := range uids {
|
||||
for _, v := range patentID {
|
||||
data = append(data, &model2.UserPatent{
|
||||
UID: uid,
|
||||
PatentID: v,
|
||||
})
|
||||
}
|
||||
}
|
||||
if len(data) > 0 {
|
||||
return model2.Creates(model.NewUserPatent().UserPatent, data)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// PatentUnbind 专利认领解绑
|
||||
func (c *Expert) PatentUnbind(id uint64, patentID []uint64) error {
|
||||
mUserExpert := model.NewUserExpert()
|
||||
|
||||
uids := make([]uint64, 0)
|
||||
|
||||
err := model2.Pluck(mUserExpert.UserExpert, "uid", &uids, model2.NewWhere("expert_id", id),
|
||||
model2.NewWhere("invalid_status", model2.InvalidStatusForNot))
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if len(uids) <= 0 {
|
||||
return nil
|
||||
}
|
||||
return model2.DeleteWhere(model.NewUserPatent().UserPatent, []*model2.ModelWhere{
|
||||
model2.NewWhereIn("uid", uids),
|
||||
model2.NewWhereIn("patent_id", patentID),
|
||||
})
|
||||
}
|
||||
|
||||
func NewExpert() ExpertHandle {
|
||||
return func(session *session.Admin) *Expert {
|
||||
return &Expert{session}
|
||||
|
Reference in New Issue
Block a user