feat:优化项目信息,待测试修改
This commit is contained in:
@ -40,7 +40,7 @@ type (
|
||||
// PatentDetailInfo 专利详细信息
|
||||
PatentDetailInfo struct {
|
||||
ID string `json:"id"`
|
||||
*model2.SysPatent
|
||||
*model2.TechnologyPatent
|
||||
}
|
||||
// PatentParams 专利参数信息
|
||||
PatentParams struct {
|
||||
@ -56,8 +56,9 @@ type (
|
||||
|
||||
// add 新增专利信息
|
||||
func (c *PatentParams) add(tenantID, uid uint64) error {
|
||||
mSysPatent := model.NewSysPatent()
|
||||
isExist, err := mSysPatent.IsExistParams(map[string]interface{}{
|
||||
mTechnologyPatent := model.NewTechnologyPatent()
|
||||
|
||||
isExist, err := mTechnologyPatent.IsExistParams(map[string]interface{}{
|
||||
"apply_code": c.ApplyCode, "open_code": c.OpenCode,
|
||||
})
|
||||
if err != nil {
|
||||
@ -66,114 +67,117 @@ func (c *PatentParams) add(tenantID, uid uint64) error {
|
||||
return errors.New("操作错误,申请号或公开(公告)号已存在")
|
||||
}
|
||||
return orm.GetDB().Transaction(func(tx *gorm.DB) error {
|
||||
mSysPatent.Kind = model2.SysParentKind(c.Kind)
|
||||
mSysPatent.TenantID = tenantID
|
||||
mSysPatent.Title = c.Title
|
||||
mSysPatent.FileUrl = c.FileUrl
|
||||
mSysPatent.ApplyCode = c.ApplyCode
|
||||
mSysPatent.ApplyAt = c.ApplyAt
|
||||
mSysPatent.OpenCode = c.OpenCode
|
||||
mSysPatent.OpenAt = c.OpenAt
|
||||
mSysPatent.ApplyName = c.ApplyName
|
||||
mSysPatent.ApplyAddress = c.ApplyAddress
|
||||
mSysPatent.Inventor = c.Inventor
|
||||
mSysPatent.Description = c.Description
|
||||
mSysPatent.PrincipalClaim = c.PrincipalClaim
|
||||
mSysPatent.IPCCode = c.IPCCode
|
||||
mSysPatent.Status = model2.SysParentStatus(c.Status)
|
||||
mTechnologyPatent.Kind = model2.SysParentKind(c.Kind)
|
||||
mTechnologyPatent.TenantID = tenantID
|
||||
mTechnologyPatent.UID = uid
|
||||
mTechnologyPatent.Title = c.Title
|
||||
mTechnologyPatent.FileUrl = c.FileUrl
|
||||
mTechnologyPatent.ApplyCode = c.ApplyCode
|
||||
mTechnologyPatent.ApplyAt = c.ApplyAt
|
||||
mTechnologyPatent.OpenCode = c.OpenCode
|
||||
mTechnologyPatent.OpenAt = c.OpenAt
|
||||
mTechnologyPatent.ApplyName = c.ApplyName
|
||||
mTechnologyPatent.ApplyAddress = c.ApplyAddress
|
||||
mTechnologyPatent.Inventor = c.Inventor
|
||||
mTechnologyPatent.Description = c.Description
|
||||
mTechnologyPatent.PrincipalClaim = c.PrincipalClaim
|
||||
mTechnologyPatent.IPCCode = c.IPCCode
|
||||
mTechnologyPatent.Status = model2.SysParentStatus(c.Status)
|
||||
|
||||
if err = model2.Create(mSysPatent.SysPatent, tx); err != nil {
|
||||
if err = model2.Create(mTechnologyPatent.TechnologyPatent, tx); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
mUserPatent := model.NewUserPatent()
|
||||
mUserPatent.UID = uid
|
||||
mUserPatent.PatentID = mSysPatent.ID
|
||||
|
||||
return model2.Create(mUserPatent.UserPatent, tx)
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
// edit 删除专利信息
|
||||
func (c *PatentParams) edit(uid uint64) error {
|
||||
mUserPatent := model.NewUserPatent()
|
||||
mUserPatent.ID = c.ID
|
||||
mTechnologyPatent := model.NewTechnologyPatent()
|
||||
mTechnologyPatent.ID = c.ID
|
||||
|
||||
isExist, err := model2.FirstField(mUserPatent.UserPatent, []string{"id", "uid", "patent_id"})
|
||||
isExist, err := model2.FirstField(mTechnologyPatent.TechnologyPatent, []string{"id", "uid", "apply_code", "open_code"})
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
} else if !isExist {
|
||||
return errors.New("操作错误,用户专利信息不存在或已被删除")
|
||||
} else if mUserPatent.UID != uid {
|
||||
return errors.New("无权限操作")
|
||||
}
|
||||
mSysPatent := model.NewSysPatent()
|
||||
mSysPatent.ID = mUserPatent.PatentID
|
||||
|
||||
if isExist, err = model2.FirstField(mSysPatent.SysPatent, []string{"id", "apply_code", "open_code"}); err != nil {
|
||||
return err
|
||||
} else if !isExist {
|
||||
return errors.New("操作错误,专利信息不存在或已被删除")
|
||||
} else if mTechnologyPatent.UID != uid {
|
||||
return errors.New("操作错误,无权限操作")
|
||||
}
|
||||
_condition := make(map[string]interface{}, 0)
|
||||
|
||||
if mSysPatent.ApplyCode != c.ApplyCode {
|
||||
if mTechnologyPatent.ApplyCode != c.ApplyCode {
|
||||
_condition["apply_code"] = c.ApplyCode
|
||||
}
|
||||
if mSysPatent.OpenCode != c.OpenCode {
|
||||
if mTechnologyPatent.OpenCode != c.OpenCode {
|
||||
_condition["open_code"] = c.OpenCode
|
||||
|
||||
}
|
||||
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(c.Kind)
|
||||
mSysPatent.Title = c.Title
|
||||
mSysPatent.FileUrl = c.FileUrl
|
||||
mSysPatent.ApplyCode = c.ApplyCode
|
||||
mSysPatent.ApplyAt = c.ApplyAt
|
||||
mSysPatent.OpenCode = c.OpenCode
|
||||
mSysPatent.OpenAt = c.OpenAt
|
||||
mSysPatent.ApplyName = c.ApplyName
|
||||
mSysPatent.ApplyAddress = c.ApplyAddress
|
||||
mSysPatent.Inventor = c.Inventor
|
||||
mSysPatent.Description = c.Description
|
||||
mSysPatent.PrincipalClaim = c.PrincipalClaim
|
||||
mSysPatent.IPCCode = c.IPCCode
|
||||
mSysPatent.Status = model2.SysParentStatus(c.Status)
|
||||
return model2.Updates(mSysPatent.SysPatent, mSysPatent.SysPatent)
|
||||
mTechnologyPatent.Kind = model2.SysParentKind(c.Kind)
|
||||
mTechnologyPatent.Title = c.Title
|
||||
mTechnologyPatent.FileUrl = c.FileUrl
|
||||
mTechnologyPatent.ApplyCode = c.ApplyCode
|
||||
mTechnologyPatent.ApplyAt = c.ApplyAt
|
||||
mTechnologyPatent.OpenCode = c.OpenCode
|
||||
mTechnologyPatent.OpenAt = c.OpenAt
|
||||
mTechnologyPatent.ApplyName = c.ApplyName
|
||||
mTechnologyPatent.ApplyAddress = c.ApplyAddress
|
||||
mTechnologyPatent.Inventor = c.Inventor
|
||||
mTechnologyPatent.Description = c.Description
|
||||
mTechnologyPatent.PrincipalClaim = c.PrincipalClaim
|
||||
mTechnologyPatent.IPCCode = c.IPCCode
|
||||
mTechnologyPatent.Status = model2.SysParentStatus(c.Status)
|
||||
return model2.Updates(mTechnologyPatent.TechnologyPatent, mTechnologyPatent.TechnologyPatent)
|
||||
}
|
||||
|
||||
// List 列表信息
|
||||
func (c *Patent) List(kind int, title, applyCode, openCode, ipcCode string, page, pageSize int) (*controller.ReturnPages, error) {
|
||||
mUserPatent := model.NewUserPatent()
|
||||
mTechnologyPatent := model.NewTechnologyPatent()
|
||||
|
||||
where := []*model2.ModelWhere{
|
||||
model2.NewWhere("u.uid", c.UID),
|
||||
where := []*model2.ModelWhereOrder{
|
||||
&model2.ModelWhereOrder{
|
||||
Where: model2.NewWhere("uid", c.UID),
|
||||
},
|
||||
}
|
||||
if kind <= 0 {
|
||||
where = append(where, model2.NewWhere("p.kind", kind))
|
||||
where = append(where, &model2.ModelWhereOrder{
|
||||
Where: model2.NewWhere("kind", kind),
|
||||
})
|
||||
}
|
||||
if title != "" {
|
||||
where = append(where, model2.NewWhereLike("p.title", title))
|
||||
where = append(where, &model2.ModelWhereOrder{
|
||||
Where: model2.NewWhereLike("title", title),
|
||||
})
|
||||
}
|
||||
if applyCode != "" {
|
||||
where = append(where, model2.NewWhereLike("p.apply_code", applyCode))
|
||||
where = append(where, &model2.ModelWhereOrder{
|
||||
Where: model2.NewWhereLike("apply_code", applyCode),
|
||||
})
|
||||
}
|
||||
if openCode != "" {
|
||||
where = append(where, model2.NewWhereLike("p.open_code", openCode))
|
||||
where = append(where, &model2.ModelWhereOrder{
|
||||
Where: model2.NewWhereLike("open_code", openCode),
|
||||
})
|
||||
}
|
||||
if ipcCode != "" {
|
||||
where = append(where, model2.NewWhereLike("p.ipc_code", ipcCode))
|
||||
where = append(where, &model2.ModelWhereOrder{
|
||||
Where: model2.NewWhereLike("ipc_code", ipcCode),
|
||||
})
|
||||
}
|
||||
var count int64
|
||||
|
||||
out, err := mUserPatent.Patents(page, pageSize, &count, where...)
|
||||
out := make([]*model2.TechnologyPatent, 0)
|
||||
|
||||
err := model2.PagesFields(mTechnologyPatent.TechnologyPatent, out, []string{"id", "title", "apply_code",
|
||||
"apply_name", "apply_at", "shelf", "status", "created_at"}, page, pageSize, &count, where...)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -212,11 +216,11 @@ func (c *Patent) Match(title string, industrys, keywords []string) (*controller.
|
||||
val := v.(*service.ESAchievement)
|
||||
ids = append(ids, val.ID)
|
||||
}
|
||||
mSysPatent := model.NewSysPatent()
|
||||
mTechnologyPatent := model.NewTechnologyPatent()
|
||||
|
||||
patents := make([]*model2.SysPatent, 0)
|
||||
|
||||
if err = model2.ScanFields(mSysPatent.SysPatent, &patents, []string{"id", "kind", "title", "description", "apply_at"}, &model2.ModelWhereOrder{
|
||||
if err = model2.ScanFields(mTechnologyPatent.TechnologyPatent, &patents, []string{"id", "kind", "title", "description", "apply_at"}, &model2.ModelWhereOrder{
|
||||
Where: model2.NewWhereIn("id", ids),
|
||||
Order: model2.NewOrder("id", model2.OrderModeToDesc),
|
||||
}); err != nil {
|
||||
@ -234,25 +238,17 @@ func (c *Patent) Match(title string, industrys, keywords []string) (*controller.
|
||||
|
||||
// Detail 详细信息
|
||||
func (c *Patent) Detail(id uint64) (*PatentDetailInfo, error) {
|
||||
mUserPatent := model.NewUserPatent()
|
||||
mUserPatent.ID = id
|
||||
mTechnologyPatent := model.NewTechnologyPatent()
|
||||
mTechnologyPatent.ID = id
|
||||
|
||||
isExist, err := model2.FirstField(mUserPatent.UserPatent, []string{"id", "uid", "patent_id"})
|
||||
isExist, err := model2.First(mTechnologyPatent.TechnologyPatent)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else if !isExist {
|
||||
return nil, errors.New("操作错误,用户专利信息不存在或已被删除")
|
||||
return nil, errors.New("操作错误,专利信息不存在或已被删除")
|
||||
}
|
||||
mSysPatent := model.NewSysPatent()
|
||||
mSysPatent.ID = mUserPatent.PatentID
|
||||
|
||||
_, err = model2.First(mSysPatent.SysPatent)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &PatentDetailInfo{ID: mUserPatent.GetEncodeID(), SysPatent: mSysPatent.SysPatent}, nil
|
||||
return &PatentDetailInfo{ID: mTechnologyPatent.GetEncodeID(), TechnologyPatent: mTechnologyPatent.TechnologyPatent}, nil
|
||||
}
|
||||
|
||||
func (c *Patent) Form(params *PatentParams) error {
|
||||
@ -265,49 +261,38 @@ func (c *Patent) Form(params *PatentParams) error {
|
||||
|
||||
// Shelf 上下架操作
|
||||
func (c *Patent) Shelf(id uint64, status int) error {
|
||||
mUserPatent := model.NewUserPatent()
|
||||
mUserPatent.ID = id
|
||||
mTechnologyPatent := model.NewTechnologyPatent()
|
||||
mTechnologyPatent.ID = id
|
||||
|
||||
isExist, err := model2.FirstField(mUserPatent.UserPatent, []string{"id", "uid", "patent_id"})
|
||||
isExist, err := model2.FirstField(mTechnologyPatent.TechnologyPatent, []string{"id", "uid"})
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
} else if !isExist {
|
||||
return errors.New("操作错误,用户专利信息不存在或已被删除")
|
||||
} else if mUserPatent.UID != c.UID {
|
||||
return errors.New("无权限操作")
|
||||
return errors.New("操作错误,专利信息不存在或已被删除")
|
||||
} else if mTechnologyPatent.UID != c.UID {
|
||||
return errors.New("操作错误,无权限操作")
|
||||
}
|
||||
mSysPatent := model.NewSysPatent()
|
||||
mSysPatent.ID = mUserPatent.PatentID
|
||||
|
||||
return model2.Updates(mSysPatent.SysPatent, map[string]interface{}{
|
||||
return model2.Updates(mTechnologyPatent.TechnologyPatent, map[string]interface{}{
|
||||
"shelf": status, "updated_at": time.Now(),
|
||||
})
|
||||
}
|
||||
|
||||
// Delete 删除操作
|
||||
func (c *Patent) Delete(id uint64) error {
|
||||
mUserPatent := model.NewUserPatent()
|
||||
mUserPatent.ID = id
|
||||
mTechnologyPatent := model.NewTechnologyPatent()
|
||||
mTechnologyPatent.ID = id
|
||||
|
||||
isExist, err := model2.FirstField(mUserPatent.UserPatent, []string{"id", "uid", "patent_id"})
|
||||
isExist, err := model2.FirstField(mTechnologyPatent.TechnologyPatent, []string{"id", "uid"})
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
} else if !isExist {
|
||||
return errors.New("操作错误,用户专利信息不存在或已被删除")
|
||||
} else if mUserPatent.UID != c.UID {
|
||||
return errors.New("无权限操作")
|
||||
return errors.New("操作错误,专利信息不存在或已被删除")
|
||||
} else if mTechnologyPatent.UID != c.UID {
|
||||
return errors.New("操作错误,无权限操作")
|
||||
}
|
||||
return orm.GetDB().Transaction(func(tx *gorm.DB) error {
|
||||
if err = model2.Delete(mUserPatent.UserPatent); err != nil {
|
||||
return err
|
||||
}
|
||||
mSysPatent := model.NewSysPatent()
|
||||
mSysPatent.ID = mUserPatent.PatentID
|
||||
|
||||
return model2.Delete(mSysPatent.SysPatent)
|
||||
})
|
||||
return model2.Delete(mTechnologyPatent.TechnologyPatent)
|
||||
}
|
||||
|
||||
func NewPatent() PatentHandle {
|
||||
|
Reference in New Issue
Block a user