feat:优化项目信息

This commit is contained in:
henry
2022-02-09 11:06:59 +08:00
parent 1cec70ebee
commit 2d8be509b7
15 changed files with 217 additions and 285 deletions

View File

@ -1,110 +0,0 @@
package sys
import (
"SciencesServer/app/api/enterprise/model"
"SciencesServer/app/basic/controller"
model2 "SciencesServer/app/common/model"
"SciencesServer/app/session"
"SciencesServer/utils"
"strings"
"time"
)
// Patent 专利信息
type Patent struct {
*session.Enterprise
}
type PatentHandle func(session *session.Enterprise) *Patent
type (
// PatentInfo 专利信息
PatentInfo struct {
ID string `json:"id"`
Kind model2.TechnologyPatentKind `json:"kind"`
Title string `json:"title"`
ApplyName string `json:"apply_name"`
ApplyCode string `json:"apply_code"`
ApplyAt string `json:"apply_at"`
Inventor string `json:"inventor"`
CreatedAt time.Time `json:"created_at"`
}
)
func (c *Patent) filter(src string) string {
src = utils.ReplaceAllCompile(src, "\t", "")
src = utils.ReplaceAllCompile(src, "\n", "")
src = strings.TrimLeft(src, " ")
src = strings.TrimRight(src, " ")
return src
}
func (c *Patent) List(kind int, title, applyCode, openCode, ipcCode string, page, pageSize int) (*controller.ReturnPages, error) {
mTechnologyPatent := model.NewTechnologyPatent()
where := []*model2.ModelWhereOrder{&model2.ModelWhereOrder{
Where: model2.NewWhere("shelf_status", model2.ShelfStatusForUp),
Order: model2.NewOrder("id", model2.OrderModeToDesc),
}}
if kind <= 0 {
where = append(where, &model2.ModelWhereOrder{
Where: model2.NewWhere("kind", kind),
})
}
if title != "" {
where = append(where, &model2.ModelWhereOrder{
Where: model2.NewWhereLike("title", title),
})
}
if applyCode != "" {
where = append(where, &model2.ModelWhereOrder{
Where: model2.NewWhereLike("apply_code", applyCode),
})
}
if openCode != "" {
where = append(where, &model2.ModelWhereOrder{
Where: model2.NewWhereLike("open_code", openCode),
})
}
if ipcCode != "" {
where = append(where, &model2.ModelWhereOrder{
Where: model2.NewWhereLike("ipc_code", ipcCode),
})
}
out := make([]*model2.TechnologyPatent, 0)
var count int64
if err := model2.PagesFields(mTechnologyPatent.TechnologyPatent, &out, []string{"id", "title", "apply_code", "apply_name", "apply_at", "created_at"}, page, pageSize, &count); err != nil {
return nil, err
}
list := make([]*PatentInfo, 0)
for _, v := range out {
list = append(list, &PatentInfo{
ID: v.GetEncodeID(), Kind: v.Kind, Title: v.Title,
ApplyName: v.ApplyName, ApplyCode: v.ApplyCode, ApplyAt: v.ApplyAt,
CreatedAt: v.CreatedAt,
})
//v.ApplyName = c.filter(v.ApplyName)
//v.ApplyAddress = c.filter(v.ApplyAddress)
//v.Inventor = c.filter(v.Inventor)
//v.Description = c.filter(v.Description)
}
return &controller.ReturnPages{
Data: out,
Count: count,
}, nil
}
func (c *Patent) Select() {
}
func NewPatent() PatentHandle {
return func(session *session.Enterprise) *Patent {
return &Patent{Enterprise: session}
}
}

View File

@ -1,7 +1,6 @@
package technology
import (
"SciencesServer/app/api/enterprise/controller/sys"
"SciencesServer/app/api/enterprise/model"
"SciencesServer/app/basic/config"
"SciencesServer/app/basic/controller"
@ -12,7 +11,6 @@ import (
"errors"
"gorm.io/gorm"
"strings"
"time"
)
// Patent 专利管理
@ -26,9 +24,8 @@ type PatentHandle func(session *session.Enterprise, tenantID uint64) *Patent
type (
// PatentInfo 专利信息
PatentInfo struct {
*sys.PatentInfo
ShelfStatus model2.ShelfStatusKind
Status model2.TechnologyPatentStatus
ID string `json:"id"`
*model.UserPatentInfo
}
// PatentMatchInfo 专利匹配信息
PatentMatchInfo struct {
@ -70,7 +67,6 @@ func (c *PatentParams) add(tenantID, uid uint64) error {
return orm.GetDB().Transaction(func(tx *gorm.DB) error {
mTechnologyPatent.Kind = model2.TechnologyPatentKind(c.Kind)
mTechnologyPatent.TenantID = tenantID
mTechnologyPatent.UID = uid
mTechnologyPatent.Title = c.Title
mTechnologyPatent.FileUrl = c.FileUrl
mTechnologyPatent.ApplyCode = c.ApplyCode
@ -88,6 +84,13 @@ 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
if err = model2.Create(mUserPatent.UserPatent, tx); err != nil {
return err
}
manage := service.NewESPatent(
service.WithPatentID(mTechnologyPatent.ID),
service.WithPatentTitle(mTechnologyPatent.Title),
@ -114,18 +117,26 @@ func (c *PatentParams) add(tenantID, uid uint64) error {
// edit 删除专利信息
func (c *PatentParams) edit(uid uint64) error {
mTechnologyPatent := model.NewTechnologyPatent()
mTechnologyPatent.ID = c.ID
mUserPatent := model.NewUserPatent()
mUserPatent.ID = c.ID
isExist, err := model2.FirstField(mTechnologyPatent.TechnologyPatent, []string{"id", "uid", "apply_code", "open_code", "created_at"})
isExist, err := model2.FirstField(mUserPatent.UserPatent, []string{"id", "uid", "patent_id"})
if err != nil {
return err
} else if !isExist {
return errors.New("操作错误,专利信息不存在或已被删除")
} else if mTechnologyPatent.UID != uid {
return errors.New("操作错误,用户专利信息不存在或已被删除")
} else if mUserPatent.UID != uid {
return errors.New("操作错误,无权限操作")
}
mTechnologyPatent := model.NewTechnologyPatent()
mTechnologyPatent.ID = mUserPatent.PatentID
if isExist, err = model2.FirstField(mTechnologyPatent.TechnologyPatent, []string{"id", "apply_code", "open_code", "created_at"}); err != nil {
return err
} else if !isExist {
return errors.New("操作错误,专利信息不存在或已被删除")
}
_condition := make(map[string]interface{}, 0)
if mTechnologyPatent.ApplyCode != c.ApplyCode {
@ -133,7 +144,6 @@ func (c *PatentParams) edit(uid uint64) error {
}
if mTechnologyPatent.OpenCode != c.OpenCode {
_condition["open_code"] = c.OpenCode
}
if len(_condition) > 0 {
if isExist, err = mTechnologyPatent.IsExistParams(_condition); err != nil {
@ -171,44 +181,28 @@ 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) {
mTechnologyPatent := model.NewTechnologyPatent()
mUserPatent := model.NewUserPatent()
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.ModelWhereOrder{
Where: model2.NewWhere("kind", kind),
})
where = append(where, model2.NewWhere("p.kind", kind))
}
if title != "" {
where = append(where, &model2.ModelWhereOrder{
Where: model2.NewWhereLike("title", title),
})
where = append(where, model2.NewWhereLike("p.title", title))
}
if applyCode != "" {
where = append(where, &model2.ModelWhereOrder{
Where: model2.NewWhereLike("apply_code", applyCode),
})
where = append(where, model2.NewWhereLike("p.apply_code", applyCode))
}
if openCode != "" {
where = append(where, &model2.ModelWhereOrder{
Where: model2.NewWhereLike("open_code", openCode),
})
where = append(where, model2.NewWhereLike("p.open_code", openCode))
}
if ipcCode != "" {
where = append(where, &model2.ModelWhereOrder{
Where: model2.NewWhereLike("ipc_code", ipcCode),
})
where = append(where, model2.NewWhereLike("p.ipc_code", ipcCode))
}
var count int64
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...)
out, err := mUserPatent.Patent(page, pageSize, &count, where...)
if err != nil {
return nil, err
@ -217,11 +211,7 @@ func (c *Patent) List(kind int, title, applyCode, openCode, ipcCode string, page
for _, v := range out {
list = append(list, &PatentInfo{
PatentInfo: &sys.PatentInfo{
ID: v.GetEncodeID(), Title: v.Title, ApplyCode: v.ApplyCode, ApplyName: v.ApplyName,
ApplyAt: v.ApplyAt, Inventor: v.Inventor,
},
ShelfStatus: v.ShelfStatus, Status: v.Status,
ID: v.GetEncodeID(), UserPatentInfo: v,
})
}
return &controller.ReturnPages{Data: list, Count: count}, nil
@ -290,53 +280,40 @@ func (c *Patent) Form(params *PatentParams) error {
}
// Shelf 上下架操作
func (c *Patent) Shelf(id uint64, status int) error {
mTechnologyPatent := model.NewTechnologyPatent()
mTechnologyPatent.ID = id
isExist, err := model2.FirstField(mTechnologyPatent.TechnologyPatent, []string{"id", "uid"})
if err != nil {
return err
} else if !isExist {
return errors.New("操作错误,专利信息不存在或已被删除")
} else if mTechnologyPatent.UID != c.UID {
return errors.New("操作错误,无权限操作")
}
if err = model2.Updates(mTechnologyPatent.TechnologyPatent, map[string]interface{}{
"shelf": status, "updated_at": time.Now(),
}); err != nil {
return err
}
manage := service.NewESPatent(
service.WithPatentID(mTechnologyPatent.ID),
service.WithPatentShow(status),
)
return manage.Update()
}
// Delete 删除操作
func (c *Patent) Delete(id uint64) error {
mTechnologyPatent := model.NewTechnologyPatent()
mTechnologyPatent.ID = id
mUserPatent := model.NewUserPatent()
mUserPatent.ID = id
isExist, err := model2.FirstField(mTechnologyPatent.TechnologyPatent, []string{"id", "uid"})
isExist, err := model2.FirstField(mUserPatent.UserPatent, []string{"id", "uid", "patent_id"})
if err != nil {
return err
} else if !isExist {
return errors.New("操作错误,专利信息不存在或已被删除")
} else if mTechnologyPatent.UID != c.UID {
return errors.New("操作错误,用户专利信息不存在或已被删除")
} else if mUserPatent.UID != c.UID {
return errors.New("操作错误,无权限操作")
}
if err = model2.Delete(mTechnologyPatent.TechnologyPatent); err != nil {
// 只删除关联关系
if err = model2.Delete(mUserPatent.UserPatent); err != nil {
return err
}
manage := service.NewESPatent(
service.WithPatentID(mTechnologyPatent.ID),
)
return manage.Delete()
//mTechnologyPatent := model.NewTechnologyPatent()
//mTechnologyPatent.ID = mUserPatent.PatentID
//
//if isExist, err := model2.FirstField(mTechnologyPatent.TechnologyPatent, []string{"id"}); err != nil {
// return err
//} else if !isExist {
// return errors.New("操作错误,专利信息不存在或已被删除")
//}
//if err = model2.Delete(mTechnologyPatent.TechnologyPatent); err != nil {
// return err
//}
//manage := service.NewESPatent(
// service.WithPatentID(mTechnologyPatent.ID),
//)
//return manage.Delete()
return nil
}
func NewPatent() PatentHandle {

View File

@ -97,20 +97,20 @@ func (c *Project) Form(params *ProjectParams) error {
// Shelf 上下架操作
func (c *Project) Shelf(id uint64, status int) error {
mTechnologyPatent := model.NewTechnologyPatent()
mTechnologyPatent.ID = id
mTechnologyProject := model.NewTechnologyProject()
mTechnologyProject.ID = id
isExist, err := model2.FirstField(mTechnologyPatent.TechnologyPatent, []string{"id", "uid"})
isExist, err := model2.FirstField(mTechnologyProject.TechnologyProject, []string{"id", "uid"})
if err != nil {
return err
} else if !isExist {
return errors.New("操作错误,项目信息不存在或已被删除")
} else if mTechnologyPatent.UID != c.UID {
} else if mTechnologyProject.UID != c.UID {
return errors.New("操作错误,无权限操作")
}
return model2.Updates(mTechnologyPatent.TechnologyPatent, map[string]interface{}{
return model2.Updates(mTechnologyProject.TechnologyProject, map[string]interface{}{
"shelf_status": status, "updated_at": time.Now(),
})
}