feat:优化项目信息
This commit is contained in:
@ -150,6 +150,46 @@ func (*Manage) ExpertExamine(c *gin.Context) {
|
||||
api.APIResponse(err)(c)
|
||||
}
|
||||
|
||||
func (*Manage) ExpertPatent(c *gin.Context) {
|
||||
form := &struct {
|
||||
api.IDStringForm
|
||||
Title string `json:"title" form:"title"`
|
||||
ApplyName string `json:"apply_name" form:"apply_name"`
|
||||
}{}
|
||||
if err := api.Bind(form)(c); err != nil {
|
||||
api.APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
data, err := manage.NewExpert()(api.GetSession()(c).(*session.Admin)).Patent(form.Convert(), form.Title, form.ApplyName)
|
||||
api.APIResponse(err, data)(c)
|
||||
}
|
||||
|
||||
func (*Manage) ExpertPatentBind(bind bool) func(c *gin.Context) {
|
||||
return func(c *gin.Context) {
|
||||
form := &struct {
|
||||
api.IDStringForm
|
||||
PatentIDs []string `json:"patent_ids" form:"patent_ids" binding:"required"`
|
||||
}{}
|
||||
if err := api.Bind(form)(c); err != nil {
|
||||
api.APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
patentIDs := make([]uint64, 0)
|
||||
|
||||
for _, v := range form.PatentIDs {
|
||||
patentIDs = append(patentIDs, (&api.IDStringForm{ID: v}).Convert())
|
||||
}
|
||||
var err error
|
||||
|
||||
if bind {
|
||||
err = manage.NewExpert()(api.GetSession()(c).(*session.Admin)).PatentBind(form.Convert(), patentIDs)
|
||||
} else {
|
||||
err = manage.NewExpert()(api.GetSession()(c).(*session.Admin)).PatentUnbind(form.Convert(), patentIDs)
|
||||
}
|
||||
api.APIResponse(err)(c)
|
||||
}
|
||||
}
|
||||
|
||||
func (*Manage) Research(c *gin.Context) {
|
||||
form := &struct {
|
||||
api.TenantIDStringForm
|
||||
|
@ -12,7 +12,6 @@ type Technology struct{}
|
||||
|
||||
func (*Technology) Patent(c *gin.Context) {
|
||||
form := &struct {
|
||||
api.TenantIDStringForm
|
||||
Title string `json:"title" form:"title"`
|
||||
IPCCode string `json:"ipc_code" form:"ipc_code"`
|
||||
api.PageForm
|
||||
@ -21,7 +20,7 @@ func (*Technology) Patent(c *gin.Context) {
|
||||
api.APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
data, err := technology.NewPatent()(api.GetSession()(c).(*session.Admin)).Instance(form.Convert(), form.Title, form.IPCCode,
|
||||
data, err := technology.NewPatent()(api.GetSession()(c).(*session.Admin)).Instance(form.Title, form.IPCCode,
|
||||
form.Page, form.PageSize)
|
||||
api.APIResponse(err, data)(c)
|
||||
}
|
||||
|
@ -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 {
|
||||
|
@ -28,8 +28,54 @@ type (
|
||||
TenantProvince string `json:"-"`
|
||||
TenantCity string `json:"-"`
|
||||
}
|
||||
// ManageExpertUser 专家用户信息
|
||||
ManageExpertUser struct {
|
||||
model.Model
|
||||
Name string `json:"name"`
|
||||
ResearchName string `json:"research_name"`
|
||||
}
|
||||
// ManageExpertPatent 专家专利信息
|
||||
ManageExpertPatent struct {
|
||||
model.Model
|
||||
Title string `json:"title"`
|
||||
ApplyName string `json:"apply_name"`
|
||||
ApplyCode string `json:"apply_code"`
|
||||
ApplyAt string `json:"apply_at"`
|
||||
Inventor string `json:"inventor"`
|
||||
UserPatentCount int64 `json:"-"`
|
||||
}
|
||||
)
|
||||
|
||||
// User 用户专家信息
|
||||
func (m *ManageExpert) User(uid uint64) (*ManageExpertUser, error) {
|
||||
db := orm.GetDB().Table(m.TableName()+" AS e").
|
||||
Select("e.id", "e.name", "r.name AS research_name").
|
||||
Joins(fmt.Sprintf("LEFT JOIN %s AS r ON e.research_id = r.id", model.NewManageResearch().TableName())).
|
||||
Where("e.uid = ?", uid).
|
||||
Where("e.examine_status = ?", model.ExamineStatusForAgree).
|
||||
Where("e.is_deleted = ?", model.DeleteStatusForNot)
|
||||
|
||||
out := new(ManageExpertUser)
|
||||
|
||||
err := db.Scan(out).Error
|
||||
|
||||
return out, err
|
||||
}
|
||||
|
||||
// User 用户专家信息
|
||||
func (m *ManageExpert) Basic(id uint64) (*ManageExpertUser, error) {
|
||||
db := orm.GetDB().Table(m.TableName()+" AS e").
|
||||
Select("e.id", "e.name", "r.name AS research_name").
|
||||
Joins(fmt.Sprintf("LEFT JOIN %s AS r ON e.research_id = r.id", model.NewManageResearch().TableName())).
|
||||
Where("e.id = ?", id)
|
||||
|
||||
out := new(ManageExpertUser)
|
||||
|
||||
err := db.Scan(out).Error
|
||||
|
||||
return out, err
|
||||
}
|
||||
|
||||
// Expert 专家信息
|
||||
func (m *ManageExpert) Expert(id uint64) (*ManageExpertDetail, error) {
|
||||
db := orm.GetDB().Table(m.TableName()+" AS e").
|
||||
@ -59,7 +105,7 @@ func (m *ManageExpert) Experts(page, pageSize int, count *int64, where ...*model
|
||||
"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.NewTechnologyPatent().TableName(), model.DeleteStatusForNot,
|
||||
model.NewUserPatent().TableName(), model.DeleteStatusForNot,
|
||||
model.DeleteStatusForNot, model.InvalidStatusForNot)).
|
||||
Where("e.is_deleted = ?", model.DeleteStatusForNot)
|
||||
|
||||
@ -80,6 +126,27 @@ func (m *ManageExpert) Experts(page, pageSize int, count *int64, where ...*model
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// Patents 专利信息
|
||||
func (m *ManageExpert) Patents(where ...*model.ModelWhere) ([]*ManageExpertPatent, error) {
|
||||
db := orm.GetDB().Table(model.NewTechnologyPatent().TableName()+" AS p").
|
||||
Select("p.id", "p.title", "p.apply_name", "p.apply_code", "p.apply_at", "p.inventor", "u.count AS user_patent_count").
|
||||
Joins(fmt.Sprintf("LEFT JOIN (SELECT patent_id, COUNT(patent_id) AS count FROM %s WHERE is_deleted = %d GROUP BY patent_id) AS u ON p.id = u.patent_id",
|
||||
model.NewUserPatent().TableName(), model.DeleteStatusForNot)).
|
||||
Where("p.is_deleted = ?", model.DeleteStatusForNot)
|
||||
|
||||
if len(where) > 0 {
|
||||
for _, v := range where {
|
||||
db = db.Where(v.Condition, v.Value)
|
||||
}
|
||||
}
|
||||
out := make([]*ManageExpertPatent, 0)
|
||||
|
||||
if err := db.Order("p.id " + model.OrderModeToDesc).Scan(&out).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func NewManageExpert() *ManageExpert {
|
||||
return &ManageExpert{model.NewManageExpert()}
|
||||
}
|
||||
|
Reference in New Issue
Block a user