feat:优化项目信息,待测试修改

This commit is contained in:
henry
2022-02-06 18:01:32 +08:00
parent c8578940bf
commit a25464289f
25 changed files with 404 additions and 483 deletions

View File

@ -23,12 +23,12 @@ type (
// PatentInfo 专利信息
PatentInfo struct {
ID string `json:"id"`
*model.PatentInstance
*model.TechnologyPatentBasicInfo
}
// PatentInstance 专利信息
PatentInstance struct {
ID string `json:"id"`
*model.SysPatentInfo
*model.TechnologyPatentInfo
}
// PaperInstance 论文信息
PaperInstance struct {
@ -113,23 +113,30 @@ func project(uids []uint64, page, pageSize int) (*controller.ReturnPages, error)
// patent 专利信息
func patent(uids []uint64, page, pageSize int) (*controller.ReturnPages, error) {
mUserPatent := model.NewUserPatent()
mTechnologyPatent := model.NewTechnologyPatent()
var count int64
out := make([]*model.TechnologyPatentBasicInfo, 0)
out, err := mUserPatent.Instance(page, pageSize, &count, model2.NewWhereIn("u_p.uid", uids))
if err != nil {
if err := model2.PagesFields(mTechnologyPatent.TechnologyPatent, &out, []string{
"id", "title", "apply_at", "description",
}, page, pageSize, &count, &model2.ModelWhereOrder{
Where: model2.NewWhere("uid", uids),
Order: model2.NewOrder("id", model2.OrderModeToDesc),
}, &model2.ModelWhereOrder{
Where: model2.NewWhere("shelf_status", model2.ShelfStatusForUp),
}); err != nil {
return nil, err
}
list := make([]*PatentInfo, 0)
for _, v := range out {
list = append(list, &PatentInfo{
ID: v.GetEncodeID(), PatentInstance: v,
ID: v.GetEncodeID(), TechnologyPatentBasicInfo: v,
})
}
return &controller.ReturnPages{Data: list, Count: count}, nil
}
func paper(uids []uint64, page, pageSize int) (*controller.ReturnPages, error) {
mTechnologyPaper := model.NewTechnologyPaper()
@ -204,17 +211,17 @@ func cooperateDetail(id uint64) (*CooperateDetailInfo, error) {
Paper: make([]*PaperInstance, 0),
}
// 专利信息
mSysPatent := model.NewSysPatent()
mTechnologyPatent := model.NewTechnologyPatent()
patents := make([]*model.SysPatentInfo, 0)
patents := make([]*model.TechnologyPatentInfo, 0)
if patents, err = mSysPatent.Instance(model2.NewWhereIn("p.id", mManageCooperateEnterprise.GetPatentAttribute())); err != nil {
if patents, err = mTechnologyPatent.Instance(model2.NewWhereIn("p.id", mManageCooperateEnterprise.GetPatentAttribute())); err != nil {
return nil, err
}
for _, v := range patents {
out.Patent = append(out.Patent, &PatentInstance{
ID: v.GetEncodeID(),
SysPatentInfo: v,
ID: v.GetEncodeID(),
TechnologyPatentInfo: v,
})
}
// 论文信息

View File

@ -40,7 +40,7 @@ func (c *Patent) filter(src string) string {
}
func (c *Patent) List(kind int, title, applyCode, openCode, ipcCode string, page, pageSize int) (*controller.ReturnPages, error) {
mSysPatent := model.NewSysPatent()
mTechnologyPatent := model.NewTechnologyPatent()
where := []*model2.ModelWhereOrder{&model2.ModelWhereOrder{
Where: model2.NewWhere("shelf_status", model2.ShelfStatusForUp),
@ -76,7 +76,7 @@ func (c *Patent) List(kind int, title, applyCode, openCode, ipcCode string, page
var count int64
if err := model2.PagesFields(mSysPatent.SysPatent, &out, []string{"id", "title", "apply_code", "apply_name", "apply_at", "created_at"}, page, pageSize, &count); err != nil {
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
}

View File

@ -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 {

View File

@ -97,22 +97,20 @@ func (c *Project) Form(params *ProjectParams) error {
// Shelf 上下架操作
func (c *Project) 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("无权限操作")
} 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": status, "updated_at": time.Now(),
})
}

View File

@ -35,21 +35,19 @@ type ManageExpertInstanceInfo struct {
Introduce string `json:"introduce"`
}
// Expert 专家信息
// Instance 专家信息
func (m *ManageExpert) Instance(limit int, where ...*model.ModelWhere) ([]*ManageExpertInstanceInfo, error) {
// 专利信息
mSysPatent := model.NewSysPatent()
// 用户专利信息
mUserPatent := model.NewUserPatent()
mTechnologyPatent := model.NewTechnologyPatent()
db := orm.GetDB().Table(m.TableName()+" AS e").
Select("e.id", "e.name", "e.industry", "e.school", "e.major", "e.keyword",
"p.title AS patent_title").
Joins(fmt.Sprintf("LEFT JOIN %s AS e_u ON e.id = p.patent_id AND e_u.invalid_status = %d AND e_u.is_deleted = %d",
model.NewUserExpert().TableName(), model.InvalidStatusForNot, model.DeleteStatusForNot)).
Joins(fmt.Sprintf(`LEFT JOIN (SELECT u.uid, SUBSTRING_INDEX(GROUP_CONCAT(p.title ORDER BY p.id DESC SEPARATOR '&&'), '&&', %d) AS title
FROM %s AS u LEFT JOIN %s AS p ON u.parent_id = p.id WHERE u.is_deleted = %d AND p.shelf_status = %d) AS p ON e_u.uid = p.uid`,
limit, mUserPatent.TableName(), mSysPatent.TableName(), model.DeleteStatusForNot, model.ShelfStatusForUp)).
Joins(fmt.Sprintf(`LEFT JOIN (SELECT uid, SUBSTRING_INDEX(GROUP_CONCAT(title ORDER BY id DESC SEPARATOR '&&'), '&&', %d) AS title
FROM %s WHERE is_deleted = %d AND shelf_status = %d) AS p ON e_u.uid = p.uid`,
limit, mTechnologyPatent.TableName(), model.DeleteStatusForNot, model.ShelfStatusForUp)).
Where("e.examine_status = ?", model.ExamineStatusForAgree).
Where("e.is_deleted = ?", model.DeleteStatusForNot)
@ -69,18 +67,16 @@ FROM %s AS u LEFT JOIN %s AS p ON u.parent_id = p.id WHERE u.is_deleted = %d AND
// Detail 专家信息
func (m *ManageExpert) Detail(limit int, id uint64) (*ManageExpertInstanceInfo, error) {
// 专利信息
mSysPatent := model.NewSysPatent()
// 用户专利信息
mUserPatent := model.NewUserPatent()
mTechnologyPatent := model.NewTechnologyPatent()
db := orm.GetDB().Table(m.TableName()+" AS e").
Select("e.id", "e.name", "e.industry", "e.school", "e.major", "e.keyword", "e.research", "e.introduce",
"p.title AS patent_title").
Joins(fmt.Sprintf("LEFT JOIN %s AS e_u ON e.id = p.patent_id AND e_u.invalid_status = %d AND e_u.is_deleted = %d",
model.NewUserExpert().TableName(), model.InvalidStatusForNot, model.DeleteStatusForNot)).
Joins(fmt.Sprintf(`LEFT JOIN (SELECT u.uid, SUBSTRING_INDEX(GROUP_CONCAT(p.title ORDER BY p.id DESC SEPARATOR '&&'), '&&', %d) AS title
FROM %s AS u LEFT JOIN %s AS p ON u.parent_id = p.id WHERE u.is_deleted = %d AND p.shelf_status = %d) AS p ON e_u.uid = p.uid`,
limit, mUserPatent.TableName(), mSysPatent.TableName(), model.DeleteStatusForNot, model.ShelfStatusForUp)).
Joins(fmt.Sprintf(`LEFT JOIN (SELECT uid, SUBSTRING_INDEX(GROUP_CONCAT(title ORDER BY id DESC SEPARATOR '&&'), '&&', %d) AS title
FROM %s WHERE is_deleted = %d AND shelf_status = %d) AS p ON e_u.uid = p.uid`,
limit, mTechnologyPatent.TableName(), model.DeleteStatusForNot, model.ShelfStatusForUp)).
Where("e.id = ?", id)
out := new(ManageExpertInstanceInfo)

View File

@ -6,12 +6,12 @@ import (
"fmt"
)
// SysPatent 专利信息
type SysPatent struct {
*model.SysPatent
// TechnologyPatent 专利信息
type TechnologyPatent struct {
*model.TechnologyPatent
}
type SysPatentInfo struct {
type TechnologyPatentInfo struct {
model.Model
Kind model.SysParentKind `json:"kind"`
Title string `json:"title"`
@ -19,12 +19,18 @@ type SysPatentInfo struct {
ApplyAt string `json:"apply_at"`
}
type TechnologyPatentBasicInfo struct {
model.Model
Title string `json:"title"`
ApplyAt string `json:"apply_at"`
}
// Instance 专利信息
func (m *SysPatent) Instance(where ...*model.ModelWhere) ([]*SysPatentInfo, error) {
func (m *TechnologyPatent) Instance(where ...*model.ModelWhere) ([]*TechnologyPatentInfo, error) {
db := orm.GetDB().Table(m.TableName()+" AS p").
Select("p.id", "p.title", "LEFT(p.description, 80) AS description", "p.apply_at").
Joins(fmt.Sprintf("LEFT JOIN %s AS c ON p.ipc_code = c.ipc AND c.is_deleted = %d",
model.NewSysPatentClassify().TableName(), model.DeleteStatusForNot)).
model.NewTechnologyPatentClassify().TableName(), model.DeleteStatusForNot)).
Where("p.shelf_status = ?", model.ShelfStatusForUp).
Where("p.is_deleted = ?", model.DeleteStatusForNot)
@ -33,7 +39,7 @@ func (m *SysPatent) Instance(where ...*model.ModelWhere) ([]*SysPatentInfo, erro
db = db.Where(v.Condition, v.Value)
}
}
out := make([]*SysPatentInfo, 0)
out := make([]*TechnologyPatentInfo, 0)
if err := db.Scan(&out).Error; err != nil {
return nil, err
@ -41,7 +47,7 @@ func (m *SysPatent) Instance(where ...*model.ModelWhere) ([]*SysPatentInfo, erro
return out, nil
}
func (m *SysPatent) IsExistParams(params map[string]interface{}) (bool, error) {
func (m *TechnologyPatent) IsExistParams(params map[string]interface{}) (bool, error) {
var count int64
db := orm.GetDB().Table(m.TableName())
@ -54,6 +60,6 @@ func (m *SysPatent) IsExistParams(params map[string]interface{}) (bool, error) {
return count > 0, err
}
func NewSysPatent() *SysPatent {
return &SysPatent{model.NewSysPatent()}
func NewTechnologyPatent() *TechnologyPatent {
return &TechnologyPatent{model.NewTechnologyPatent()}
}

View File

@ -1,72 +0,0 @@
package model
import (
"SciencesServer/app/common/model"
"SciencesServer/serve/orm"
"fmt"
)
type UserPatent struct {
*model.UserPatent
}
type (
// PatentInstance 专利信息
PatentInstance struct {
model.Model
Title string `json:"title"`
ApplyAt string `json:"apply_at"`
}
)
// Patent 专利信息
func (m *UserPatent) Instance(page, pageSize int, count *int64, where ...*model.ModelWhere) ([]*PatentInstance, error) {
db := orm.GetDB().Table(m.TableName()+" AS u_p").
Select("p.id", "p.title", "p.apply_at", "p.description").
Joins(fmt.Sprintf("LEFT JOIN %s AS p ON u_p.patent_id = p.id",
model.NewSysPatent().TableName())).
Where("u_p.is_deleted = ?", model.DeleteStatusForNot).
Where("p.shelf_status = ?", model.ShelfStatusForUp)
if len(where) > 0 {
for _, wo := range where {
db = db.Where(wo.Condition, wo.Value)
}
}
out := make([]*PatentInstance, 0)
if err := db.Count(count).Error; err != nil {
return nil, err
}
if err := db.Order("p.id " + model.OrderModeToDesc).Offset((page - 1) * pageSize).Limit(pageSize).Scan(&out).Error; err != nil {
return nil, err
}
return out, nil
}
// Patents 专利信息
func (m *UserPatent) Patents(page, pageSize int, count *int64, where ...*model.ModelWhere) ([]*model.SysPatent, error) {
db := orm.GetDB().Table(m.TableName()+" AS u").
Select("u.id", "p.title", "p.apply_code", "p.apply_name", "p.apply_at", "shelf", "status", "u.created_at").
Joins(fmt.Sprintf("LEFT JOIN %s AS p ON u.patent_id = p.id", model.NewSysPatent().TableName())).
Where("u.is_deleted = ? AND p.is_deleted = ?", model.DeleteStatusForNot, model.DeleteStatusForNot)
if len(where) > 0 {
for _, wo := range where {
db = db.Where(wo.Condition, wo.Value)
}
}
out := make([]*model.SysPatent, 0)
if err := db.Count(count).Error; err != nil {
return nil, err
}
if err := db.Order("u.id " + model.OrderModeToDesc).Offset((page - 1) * pageSize).Limit(pageSize).Scan(&out).Error; err != nil {
return nil, err
}
return out, nil
}
func NewUserPatent() *UserPatent {
return &UserPatent{model.NewUserPatent()}
}