feat:优化项目信息

This commit is contained in:
henry
2022-02-08 18:26:40 +08:00
parent 17dd9bea7f
commit 1cec70ebee
11 changed files with 151 additions and 66 deletions

View File

@ -8,11 +8,12 @@
环境和依赖
----
- Go>=1.15
- Go >= 1.15
- [Gin](https://github.com/gin-gonic/gin) - Web Router
- [Gorm.v2](https://github.com/go-gorm/gorm) - Data Engine
- [Cacbin](https://github.com/casbin/casbin) - Auth(RBAC)
- [Redis](https://github.com/redis/redis)
- [Elasticsearch](https://github.com/olivere/elastic) - ESSearchV7
项目编译和运行
----

View File

@ -41,7 +41,7 @@ func (*Technology) PatentForm(c *gin.Context) {
form := &struct {
api.IDStringForm
api.TenantIDStringForm
Kind int `json:"kind" form:"kind" binding:"kind"`
Kind int `json:"kind" form:"kind" binding:"required"`
Title string `json:"title" form:"title" binding:"required"`
FileUrl string `json:"file_url" form:"file_url"`
ApplyCode string `json:"apply_code" form:"apply_code" binding:"required"`
@ -55,7 +55,7 @@ func (*Technology) PatentForm(c *gin.Context) {
PrincipalClaim string `json:"principal_claim" form:"principal_claim"`
Description string `json:"description" form:"description"`
ShelfStatus int `json:"shelf_status" form:"shelf_status" binding:"required"`
Status int `json:"status" form:"status" binding:"required"`
Status int `json:"status" form:"status"`
}{}
if err := api.Bind(form)(c); err != nil {
api.APIFailure(err.(error))(c)

View File

@ -130,7 +130,13 @@ func (c *Achievement) Examine(id uint64, status int, remark string) error {
// Shelf 上下架
func (c *Achievement) Shelf(id uint64) error {
return controller.NewShelf(controller.WithShelfSessionAdmin(c.Admin)).Handle(model2.NewTechnologyAchievement(), id)
return controller.NewShelf(controller.WithShelfSessionAdmin(c.Admin)).Handle(model2.NewTechnologyAchievement(), id, func(kind model2.ShelfStatusKind) error {
manage := service.NewESAchievement(
service.WithAchievementID(id),
service.WithAchievementShow(int(kind)),
)
return manage.Update()
})
}
func (c *Achievement) Delete(id uint64) error {

View File

@ -5,10 +5,11 @@ import (
"SciencesServer/app/basic/config"
"SciencesServer/app/basic/controller"
model2 "SciencesServer/app/common/model"
"SciencesServer/app/service"
"SciencesServer/app/session"
"SciencesServer/utils"
"errors"
"fmt"
"strings"
"time"
)
@ -22,9 +23,8 @@ type PatentHandle func(session *session.Admin) *Patent
type (
// PatentInfo 专利信息
PatentInfo struct {
ID string `json:"id"`
UID string `json:"uid"`
*model.SysPatentInfo
ID string `json:"id"`
*model.TechnologyPatentInfo
}
// PatentDetailInfo 专利详细信息
PatentDetailInfo struct {
@ -98,7 +98,6 @@ func (c *Patent) Instance(tenantID uint64, title, ipc string, page, pageSize int
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))
}
@ -119,9 +118,8 @@ func (c *Patent) Instance(tenantID uint64, title, ipc string, page, pageSize int
for _, v := range out {
list = append(list, &PatentInfo{
ID: v.GetEncodeID(),
UID: fmt.Sprintf("%d", v.UID),
SysPatentInfo: v,
ID: v.GetEncodeID(),
TechnologyPatentInfo: v,
})
}
return &controller.ReturnPages{Data: list, Count: count}, nil
@ -191,8 +189,32 @@ func (c *Patent) Form(params *PatentParams) error {
mTechnologyPatent.ShelfStatus = model2.ShelfStatusKind(params.ShelfStatus)
mTechnologyPatent.Status = model2.TechnologyPatentStatus(params.Status)
// 查询IPCCode信息
mTechnologyPatentClassify := model.NewTechnologyPatentClassify()
isExist, err := model2.FirstField(mTechnologyPatentClassify.TechnologyPatentClassify, []string{"id", "industry_detail"},
model2.NewWhere("ipc", params.IPCCode))
_industrys := make([]string, 0)
if err != nil {
return err
} else if isExist {
for _, v := range mTechnologyPatentClassify.GetIndustryDetailAttribute() {
_industrys = append(_industrys, config.GetIndustryInfo(v, "-", "-").Value)
}
}
manage := service.NewESPatent(
service.WithPatentTitle(mTechnologyPatent.Title),
service.WithPatentIndustry(strings.Join(_industrys, "")),
service.WithPatentShow(params.Status),
)
if mTechnologyPatent.ID > 0 {
return model2.Updates(mTechnologyPatent.TechnologyPatent, mTechnologyPatent.TechnologyPatent)
if err = model2.Updates(mTechnologyPatent.TechnologyPatent, mTechnologyPatent.TechnologyPatent); err != nil {
return err
}
_ = manage.Update()
return nil
}
_condition["apply_code"] = params.ApplyCode
_condition["ipc_code"] = params.IPCCode
@ -203,7 +225,13 @@ func (c *Patent) Form(params *PatentParams) error {
return errors.New("操作错误,申请号或公开(公告)号已存在")
}
mTechnologyPatent.TenantID = c.TenantID
return model2.Create(mTechnologyPatent.TechnologyPatent)
if err := model2.Create(mTechnologyPatent.TechnologyPatent); err != nil {
return err
}
service.WithPatentID(mTechnologyPatent.ID)(manage)
return manage.Create()
}
// Bind 绑定信息
@ -226,30 +254,17 @@ func (c *Patent) Bind(id, uid uint64) error {
return err
}
return nil
//mUserPatent := model.NewUserPatent()
//if isExist, err = model2.FirstField(mUserPatent.UserPatent, []string{"id", "uid"}, model2.NewWhere("patent_id", id)); err != nil {
// return err
//} else if !isExist {
// mUserPatent.UID = uid
// mUserPatent.PatentID = id
// return model2.Create(mUserPatent.UserPatent)
//}
//if mUserPatent.UID == uid {
// return nil
//}
//return orm.GetDB().Transaction(func(tx *gorm.DB) error {
// if err = model2.DeleteWhere(mUserPatent.UserPatent, []*model2.ModelWhere{model2.NewWhere("patent_id", id)}); err != nil {
// return err
// }
// mUserPatent.UID = uid
// mUserPatent.PatentID = id
// return model2.Create(mUserPatent.UserPatent, tx)
//})
}
// Shelf 上下架操作
func (c *Patent) Shelf(id uint64) error {
return controller.NewShelf(controller.WithShelfSessionAdmin(c.Admin)).Handle(model2.NewTechnologyPatent(), id)
return controller.NewShelf(controller.WithShelfSessionAdmin(c.Admin)).Handle(model2.NewTechnologyPatent(), id, func(kind model2.ShelfStatusKind) error {
manage := service.NewESPatent(
service.WithPatentID(id),
service.WithPatentShow(int(kind)),
)
return manage.Update()
})
}
// Delete 删除操作
@ -266,7 +281,14 @@ func (c *Patent) Delete(id uint64) error {
} else if c.TenantID > 0 && mTechnologyPatent.TenantID > 0 && c.TenantID != mTechnologyPatent.TenantID {
return errors.New("操作错误,无权限操作")
}
return model2.Delete(mTechnologyPatent.TechnologyPatent)
err = model2.Delete(mTechnologyPatent.TechnologyPatent)
if err != nil {
return err
}
_ = service.NewESPatent(service.WithPatentID(mTechnologyPatent.ID)).Delete()
return nil
}
// IPC IPC信息

View File

@ -105,7 +105,7 @@ func (c *Product) Examine(id uint64, status int, remark string) error {
// Shelf 上下架操作
func (c *Product) Shelf(id uint64) error {
return controller.NewShelf(controller.WithShelfSessionAdmin(c.Admin)).Handle(model2.NewTechnologyProduct(), id)
return controller.NewShelf(controller.WithShelfSessionAdmin(c.Admin)).Handle(model2.NewTechnologyProduct(), id, nil)
}
// Delete 删除操作

View File

@ -59,8 +59,7 @@ func (c *Project) Instance(tenantID uint64, title string, page, pageSize int) (*
// Shelf 上下架操作
func (c *Project) Shelf(id uint64) error {
return controller.NewShelf(controller.WithShelfSessionAdmin(c.Admin)).
Handle(model2.NewTechnologyProject(), id)
return controller.NewShelf(controller.WithShelfSessionAdmin(c.Admin)).Handle(model2.NewTechnologyProject(), id, nil)
}
// Delete 删除操作

View File

@ -12,15 +12,16 @@ type TechnologyPatent struct {
*model.TechnologyPatent
}
// SysPatentInfo 专利信息
type SysPatentInfo struct {
// TechnologyPatentInfo 专利信息
type TechnologyPatentInfo struct {
model.Model
model.ModelTenant
Title string `json:"title"`
ApplyCode string `json:"apply_code"`
ApplyAt string `json:"apply_at"`
ApplyName string `json:"apply_name"`
Inventor string `json:"inventor"`
Kind model.TechnologyPatentKind `json:"kind"`
Title string `json:"title"`
ApplyCode string `json:"apply_code"`
ApplyAt string `json:"apply_at"`
ApplyName string `json:"apply_name"`
Inventor string `json:"inventor"`
model.Shelf
UID uint64 `json:"-"`
CreatedAt time.Time `json:"created_at"`
@ -32,7 +33,7 @@ func (m *TechnologyPatent) IsExistParams(params map[string]interface{}) (bool, e
if len(params) > 0 {
for k, v := range params {
db = db.Or(fmt.Sprintf("%s = %v AND is_deleted = %d", k, v, model.DeleteStatusForNot))
db = db.Or(fmt.Sprintf("%s = '%v' AND is_deleted = %d", k, v, model.DeleteStatusForNot))
}
}
err := db.Count(&count).Error
@ -40,17 +41,18 @@ func (m *TechnologyPatent) IsExistParams(params map[string]interface{}) (bool, e
}
// Patent 专利信息
func (m *TechnologyPatent) Patent(page, pageSize int, count *int64, where ...*model.ModelWhere) ([]*SysPatentInfo, error) {
func (m *TechnologyPatent) Patent(page, pageSize int, count *int64, where ...*model.ModelWhere) ([]*TechnologyPatentInfo, error) {
db := orm.GetDB().Table(m.TableName()+" AS p").
Select("p.id", "p.title", "p.apply_code", "p.inventor", "p.apply_name", "p.apply_at", "u.uid",
"p.shelf_status", "p.created_at")
Select("p.id", "p.kind", "p.title", "p.apply_code", "p.inventor", "p.apply_name", "p.apply_at",
"p.shelf_status", "p.created_at").
Where("p.is_deleted = ?", model.DeleteStatusForNot)
if len(where) > 0 {
for _, wo := range where {
db = db.Where(wo.Condition, wo.Value)
}
}
out := make([]*SysPatentInfo, 0)
out := make([]*TechnologyPatentInfo, 0)
if err := db.Count(count).Error; err != nil {
return nil, err

View File

@ -208,9 +208,17 @@ func (c *Achievement) Shelf(id uint64, status int) error {
} else if mTechnologyAchievement.ShelfStatus == model2.ShelfStatusKind(status) {
return errors.New("操作错误,无需变更上下架状态")
}
return model2.Updates(mTechnologyAchievement.TechnologyAchievement, map[string]interface{}{
if err = model2.Updates(mTechnologyAchievement.TechnologyAchievement, map[string]interface{}{
"shelf_status": status, "updated_at": time.Now(),
})
}); err != nil {
return err
}
manage := service.NewESAchievement(
service.WithAchievementID(mTechnologyAchievement.ID),
service.WithAchievementShow(status),
)
return manage.Update()
}
// Delete 删除操作
@ -227,7 +235,14 @@ func (c *Achievement) Delete(id uint64) error {
} else if mTechnologyAchievement.UID != c.UID {
return errors.New("无权限操作")
}
return model2.Delete(mTechnologyAchievement.TechnologyAchievement)
if err = model2.Delete(mTechnologyAchievement.TechnologyAchievement); err != nil {
return err
}
manage := service.NewESAchievement(
service.WithAchievementID(mTechnologyAchievement.ID),
)
return manage.Delete()
}
func NewAchievement() AchievementHandle {

View File

@ -33,10 +33,11 @@ func WithShelfSessionEnterprise(session *session.Enterprise) ShelfOption {
}
}
func (c *Shelf) Handle(iModel model.IModel, id uint64) error {
func (c *Shelf) Handle(iModel model.IModel, id uint64, callback func(kind model.ShelfStatusKind) error) error {
if c.Admin == nil && c.Enterprise == nil {
return errors.New("操作错误,未知的人员操作")
}
iModel.SetID(id)
out := new(IModelInfo)
err := model.ScanFields(iModel, out, []string{"id", "tenant_id", "uid", "shelf_status"},
@ -57,14 +58,22 @@ func (c *Shelf) Handle(iModel model.IModel, id uint64) error {
return errors.New("操作错误,无权限操作")
}
}
shelfStatus := model.ShelfStatusForUp
if out.ShelfStatus == model.ShelfStatusForUp {
shelfStatus = model.ShelfStatusForDown
}
values := map[string]interface{}{
"shelf_status": model.ShelfStatusForUp,
"shelf_status": shelfStatus,
"updated_at": time.Now(),
}
if out.ShelfStatus == model.ShelfStatusForUp {
values["shelf_status"] = model.ShelfStatusForDown
if err := model.Updates(iModel, values); err != nil {
return err
}
return model.Updates(iModel, values)
if callback != nil {
return callback(shelfStatus)
}
return nil
}
func NewShelf(options ...ShelfOption) *Shelf {

View File

@ -29,7 +29,7 @@ type PPatent struct {
PrincipalClaim string `gorm:"column:principal_claim;type:text;comment:主权项" json:"principal_claim"`
IPCCode string `gorm:"column:ipc_code;type:varchar(50);default:'';comment:IPC主分类号" json:"ipc_code"`
Shelf
Status SysParentStatus `gorm:"column:status;type:tinyint(1);default:1;comment:专利状态(1授权2实审3公开)" json:"-"`
Status TechnologyPatentStatus `gorm:"column:status;type:tinyint(1);default:1;comment:专利状态(1授权2实审3公开)" json:"-"`
ModelDeleted
ModelAt
}
@ -89,7 +89,7 @@ func TestRecoveryPatent(t *testing.T) {
mysql := mysql()
mSysPatent := new(SysPatent)
mSysPatent := new(PPatent)
now := time.Now()
@ -105,17 +105,17 @@ func TestRecoveryPatent(t *testing.T) {
return
}
t.Log(len(src))
out := make([]*SysPatent, 0)
out := make([]*TechnologyPatent, 0)
for _, v := range src {
kind := SysParentKindForInvent
kind := TechnologyPatentKindForInvent
if v.Kind == "实用新型" {
kind = SysParentKindForNewPractical
kind = TechnologyPatentKindForNewPractical
} else if v.Kind == "外观设计" {
kind = SysParentKindForDesign
kind = TechnologyPatentKindForDesign
}
data := &SysPatent{
data := &TechnologyPatent{
Kind: kind,
Title: v.Title,
FileUrl: v.FileUrl,

View File

@ -11,6 +11,7 @@ type ESAchievement struct {
Title string `json:"title"` // 成果名称
Industry string `json:"industry"` // 行业领域
Keyword string `json:"keyword"` // 关键词
IsShow int `json:"is_show"` // 展示
}
type ESAchievementOption func(achievement *ESAchievement)
@ -24,6 +25,24 @@ func (this *ESAchievement) Create() error {
return es.Create(this.Index(), fmt.Sprintf("%d", this.ID), _bytes)
}
func (this *ESAchievement) Update() error {
_map := make(map[string]interface{}, 0)
if this.Title != "" {
_map["title"] = this.Title
}
if this.Industry != "" {
_map["industry"] = this.Industry
}
if this.Keyword != "" {
_map["keyword"] = this.Keyword
}
if this.IsShow != 0 {
_map["is_show"] = this.IsShow
}
return es.Update(this.Index(), fmt.Sprintf("%d", this.ID), _map)
}
func (this *ESAchievement) Search(page, pageSize int) (interface{}, int64, error) {
termParams := make(map[string]interface{}, 0)
mustParams := make(map[string]interface{}, 0)
@ -37,12 +56,18 @@ func (this *ESAchievement) Search(page, pageSize int) (interface{}, int64, error
if this.Keyword != "" {
mustParams["keyword"] = this.Keyword
}
termParams["is_show"] = 1
return es.Search(this, this.Index(), &es.SearchParams{
TermParams: termParams,
MustParams: mustParams,
}, page, pageSize)
}
func (this *ESAchievement) Delete() error {
return es.Delete(this.Index(), fmt.Sprintf("%d", this.ID))
}
func WithAchievementID(id uint64) ESAchievementOption {
return func(achievement *ESAchievement) {
achievement.ID = id
@ -67,6 +92,12 @@ func WithAchievementKeyword(keyword string) ESAchievementOption {
}
}
func WithAchievementShow(show int) ESAchievementOption {
return func(achievement *ESAchievement) {
achievement.IsShow = show
}
}
func NewESAchievement(options ...ESAchievementOption) *ESAchievement {
out := new(ESAchievement)