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}
|
||||
|
@ -33,6 +33,11 @@ type (
|
||||
ID string `json:"id"`
|
||||
*model2.TechnologyPatent
|
||||
}
|
||||
// PatentFilterInfo 专利筛选信息
|
||||
PatentFilterInfo struct {
|
||||
Experts []*string
|
||||
Patents []*PatentInfo `json:"patents"`
|
||||
}
|
||||
// PatentParams 专利参数信息
|
||||
PatentParams struct {
|
||||
ID, TenantID uint64
|
||||
@ -92,17 +97,11 @@ func (c *PatentParams) checkParams(iModel *model.TechnologyPatent, condition map
|
||||
}
|
||||
|
||||
// Instance 首页信息
|
||||
func (c *Patent) Instance(tenantID uint64, title, ipc string, page, pageSize int) (*controller.ReturnPages, error) {
|
||||
func (c *Patent) Instance(title, ipc string, page, pageSize int) (*controller.ReturnPages, error) {
|
||||
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))
|
||||
}
|
||||
@ -158,14 +157,12 @@ func (c *Patent) Form(params *PatentParams) error {
|
||||
return err
|
||||
} else if !isExist {
|
||||
return errors.New("操作错误,专利信息不存在或已被删除")
|
||||
} else if c.TenantID > 0 && mTechnologyPatent.TenantID > 0 && c.TenantID != mTechnologyPatent.TenantID {
|
||||
return errors.New("操作错误,无权限操作")
|
||||
}
|
||||
if mTechnologyPatent.ApplyCode != params.ApplyCode {
|
||||
_condition["apply_code"] = params.ApplyCode
|
||||
}
|
||||
if mTechnologyPatent.IPCCode != params.IPCCode {
|
||||
_condition["ipc_code"] = params.IPCCode
|
||||
_condition["open_code"] = params.OpenCode
|
||||
}
|
||||
if len(_condition) > 0 {
|
||||
if isExist, err = mTechnologyPatent.IsExistParams(_condition); err != nil {
|
||||
@ -217,14 +214,13 @@ func (c *Patent) Form(params *PatentParams) error {
|
||||
return nil
|
||||
}
|
||||
_condition["apply_code"] = params.ApplyCode
|
||||
_condition["ipc_code"] = params.IPCCode
|
||||
_condition["open_code"] = params.OpenCode
|
||||
|
||||
if isExist, err := mTechnologyPatent.IsExistParams(_condition); err != nil {
|
||||
return err
|
||||
} else if isExist {
|
||||
return errors.New("操作错误,申请号或公开(公告)号已存在")
|
||||
}
|
||||
mTechnologyPatent.TenantID = c.TenantID
|
||||
|
||||
if err := model2.Create(mTechnologyPatent.TechnologyPatent); err != nil {
|
||||
return err
|
||||
@ -234,6 +230,39 @@ func (c *Patent) Form(params *PatentParams) error {
|
||||
return manage.Create()
|
||||
}
|
||||
|
||||
// Filter 筛选信息
|
||||
func (c *Patent) Filter(applyName, inventor string) (*PatentFilterInfo, error) {
|
||||
// 查询用户专家信息
|
||||
mManageResearch := model.NewManageResearch()
|
||||
researchIDs := make([]uint64, 0)
|
||||
|
||||
err := model2.Pluck(mManageResearch.ManageResearch, "id", &researchIDs, model2.NewWhere("name", applyName),
|
||||
model2.NewWhere("examine_status", model2.ExamineStatusForAgree))
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(researchIDs) > 0 {
|
||||
// 查询科研机构下专家信息
|
||||
mManageExpert := model.NewManageExpert()
|
||||
|
||||
experts := make([]*model2.ManageExpert, 0)
|
||||
|
||||
if err = model2.ScanFields(mManageExpert.ManageExpert, &experts, []string{"id", "uid", "name", "mobile"},
|
||||
&model2.ModelWhereOrder{
|
||||
Where: model2.NewWhere("name", inventor),
|
||||
}, &model2.ModelWhereOrder{
|
||||
Where: model2.NewWhere("examine_status", model2.ExamineStatusForAgree),
|
||||
}, &model2.ModelWhereOrder{
|
||||
Where: model2.NewWhereIn("research_id", researchIDs),
|
||||
}); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
}
|
||||
return &PatentFilterInfo{}, nil
|
||||
}
|
||||
|
||||
// Bind 绑定信息
|
||||
func (c *Patent) Bind(id, uid uint64) error {
|
||||
mTechnologyPatent := model.NewTechnologyPatent()
|
||||
@ -245,8 +274,6 @@ func (c *Patent) Bind(id, uid uint64) error {
|
||||
return err
|
||||
} else if !isExist {
|
||||
return errors.New("操作错误,专利信息不存在或已被删除")
|
||||
} else if c.TenantID > 0 && mTechnologyPatent.TenantID > 0 && c.TenantID != mTechnologyPatent.TenantID {
|
||||
return errors.New("操作错误,无权限操作")
|
||||
}
|
||||
if err = model2.Updates(mTechnologyPatent.TechnologyPatent, map[string]interface{}{
|
||||
"uid": uid, "updated_at": time.Now(),
|
||||
@ -267,8 +294,6 @@ func (c *Patent) Delete(id uint64) error {
|
||||
return err
|
||||
} else if !isExist {
|
||||
return errors.New("操作错误,专利信息不存在或已被删除")
|
||||
} else if c.TenantID > 0 && mTechnologyPatent.TenantID > 0 && c.TenantID != mTechnologyPatent.TenantID {
|
||||
return errors.New("操作错误,无权限操作")
|
||||
}
|
||||
if err = orm.GetDB().Transaction(func(tx *gorm.DB) error {
|
||||
if err = model2.Delete(mTechnologyPatent.TechnologyPatent, tx); err != nil {
|
||||
|
Reference in New Issue
Block a user