feat:增加专利模型数据
This commit is contained in:
27
app/api/enterprise/api/sys.go
Normal file
27
app/api/enterprise/api/sys.go
Normal file
@ -0,0 +1,27 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"SciencesServer/app/api/enterprise/controller/sys"
|
||||
"SciencesServer/app/basic/api"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
type Sys struct{}
|
||||
|
||||
func (*Sys) Patent(c *gin.Context) {
|
||||
form := &struct {
|
||||
Kind int `json:"kind" form:"kind"`
|
||||
Title string `json:"title" form:"title"`
|
||||
ApplyCode string `json:"apply_code" form:"apply_code"`
|
||||
OpenCode string `json:"open_code" form:"open_code"`
|
||||
IPCCode string `json:"ipc_code" form:"ipc_code"`
|
||||
api.PageForm
|
||||
}{}
|
||||
if err := api.Bind(form)(c); err != nil {
|
||||
api.APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
data, err := sys.NewPatent()(nil).
|
||||
List(form.Kind, form.Title, form.ApplyCode, form.OpenCode, form.IPCCode, form.Page, form.PageSize)
|
||||
api.APIResponse(err, data)(c)
|
||||
}
|
@ -158,3 +158,14 @@ func (*User) BackUnbind(c *gin.Context) {
|
||||
err := user.NewBank()(api.GetSession()(c).(*session.Enterprise)).Unbind(form.Convert())
|
||||
api.APIResponse(err)
|
||||
}
|
||||
|
||||
func (*User) Patent(c *gin.Context) {
|
||||
form := &struct {
|
||||
Title string `json:"title" form:"title"`
|
||||
api.PageForm
|
||||
}{}
|
||||
if err := api.Bind(form)(c); err != nil {
|
||||
api.APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
97
app/api/enterprise/controller/sys/patent.go
Normal file
97
app/api/enterprise/controller/sys/patent.go
Normal file
@ -0,0 +1,97 @@
|
||||
package sys
|
||||
|
||||
import (
|
||||
"SciencesServer/app/api/enterprise/model"
|
||||
"SciencesServer/app/basic/controller"
|
||||
model2 "SciencesServer/app/common/model"
|
||||
"SciencesServer/app/session"
|
||||
"SciencesServer/utils"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// Patent 专利信息
|
||||
type Patent struct {
|
||||
*session.Enterprise
|
||||
}
|
||||
|
||||
type PatentHandle func(session *session.Enterprise) *Patent
|
||||
|
||||
type (
|
||||
// PatentInfo 专利信息
|
||||
PatentInfo struct {
|
||||
ID string `json:"id"`
|
||||
Kind model2.SysParentKind `json:"kind"`
|
||||
Title string `json:"title"`
|
||||
}
|
||||
)
|
||||
|
||||
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) {
|
||||
mSysPatent := model.NewSysPatent()
|
||||
|
||||
where := []*model2.ModelWhereOrder{&model2.ModelWhereOrder{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.SysPatent, 0)
|
||||
|
||||
var count int64
|
||||
|
||||
if err := model2.Pages(mSysPatent.SysPatent, &out, 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,
|
||||
})
|
||||
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 NewPatent() PatentHandle {
|
||||
return func(session *session.Enterprise) *Patent {
|
||||
return &Patent{Enterprise: session}
|
||||
}
|
||||
}
|
@ -120,7 +120,7 @@ func (c *Instance) Form(params *InstanceParams) error {
|
||||
func (c *Instance) Shelf(id uint64, status int) error {
|
||||
mTechnologyInstance := model.NewTechnologyInstance()
|
||||
mTechnologyInstance.ID = id
|
||||
isExist, err := model2.FirstField(mTechnologyInstance.TechnologyInstance, []string{"id", "m_uid", "shelf_status", "status"})
|
||||
isExist, err := model2.FirstField(mTechnologyInstance.TechnologyInstance, []string{"id", "m_uid", "shelf", "status"})
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
@ -130,11 +130,11 @@ func (c *Instance) Shelf(id uint64, status int) error {
|
||||
return errors.New("操作错误,无权限操作")
|
||||
} else if mTechnologyInstance.Status != model2.TechnologyInstanceStatusForAgree {
|
||||
return errors.New("操作错误,当前状态不允许处理上下架")
|
||||
} else if mTechnologyInstance.ShelfStatus.ShelfStatus == model2.ShelfStatusKind(status) {
|
||||
} else if mTechnologyInstance.ShelfStatus.Shelf == model2.ShelfStatusKind(status) {
|
||||
return errors.New("操作错误,状态异常")
|
||||
}
|
||||
if err = model2.Updates(mTechnologyInstance.TechnologyInstance, map[string]interface{}{
|
||||
"shelf_status": status, "updated_at": time.Now(),
|
||||
"shelf": status, "updated_at": time.Now(),
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -158,11 +158,11 @@ func (c *Product) Shelf(id uint64, status int) error {
|
||||
return errors.New("操作错误,产品信息不存在或已被删除")
|
||||
} else if mTechnologyProduct.MUid != c.ManageUID {
|
||||
return errors.New("无权限操作")
|
||||
} else if mTechnologyProduct.ShelfStatus.ShelfStatus == model2.ShelfStatusKind(status) {
|
||||
} else if mTechnologyProduct.ShelfStatus.Shelf == model2.ShelfStatusKind(status) {
|
||||
return errors.New("操作错误,无需变更上下架状态")
|
||||
}
|
||||
return model2.Updates(mTechnologyProduct.TechnologyProduct, map[string]interface{}{
|
||||
"shelf_status": status, "updated_at": time.Now(),
|
||||
"shelf": status, "updated_at": time.Now(),
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -1 +1,15 @@
|
||||
package tenant
|
||||
|
||||
import "SciencesServer/app/session"
|
||||
|
||||
type Instance struct {
|
||||
*session.Enterprise
|
||||
}
|
||||
|
||||
type InstanceHandle func(session *session.Enterprise) *Instance
|
||||
|
||||
func NewInstance() InstanceHandle {
|
||||
return func(session *session.Enterprise) *Instance {
|
||||
return &Instance{Enterprise: session}
|
||||
}
|
||||
}
|
||||
|
105
app/api/enterprise/controller/user/patent.go
Normal file
105
app/api/enterprise/controller/user/patent.go
Normal file
@ -0,0 +1,105 @@
|
||||
package user
|
||||
|
||||
import (
|
||||
"SciencesServer/app/api/enterprise/model"
|
||||
"SciencesServer/app/basic/controller"
|
||||
model2 "SciencesServer/app/common/model"
|
||||
"SciencesServer/app/session"
|
||||
"SciencesServer/serve/orm"
|
||||
"errors"
|
||||
"gorm.io/gorm"
|
||||
"time"
|
||||
)
|
||||
|
||||
type Patent struct {
|
||||
*session.Enterprise
|
||||
local string
|
||||
}
|
||||
|
||||
type PatentHandle func(session *session.Enterprise, local string) *Patent
|
||||
|
||||
type (
|
||||
// PatentParams 专利参数信息
|
||||
PatentParams struct {
|
||||
ID uint64
|
||||
Title string
|
||||
}
|
||||
)
|
||||
|
||||
func (c *PatentParams) add() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *PatentParams) edit() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *Patent) List(kind int, title, applyCode, openCode, ipcCode string, page, pageSize int) (*controller.ReturnPages, error) {
|
||||
return &controller.ReturnPages{
|
||||
Data: nil,
|
||||
Count: 0,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (c *Patent) Form(params *PatentParams) error {
|
||||
if params.ID <= 0 {
|
||||
return params.add()
|
||||
}
|
||||
return params.edit()
|
||||
}
|
||||
|
||||
// Shelf 上下架操作
|
||||
func (c *Patent) Shelf(id uint64, status int) error {
|
||||
mUserPatent := model.NewUserPatent()
|
||||
mUserPatent.ID = id
|
||||
|
||||
isExist, err := model2.FirstField(mUserPatent.UserPatent, []string{"id", "uid", "patent_id"})
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
} else if !isExist {
|
||||
return errors.New("操作错误,用户专利信息不存在或已被删除")
|
||||
} else if mUserPatent.UID != c.UID {
|
||||
return errors.New("无权限操作")
|
||||
}
|
||||
mSysPatent := model.NewSysPatent()
|
||||
mSysPatent.ID = mUserPatent.PatentID
|
||||
|
||||
return model2.Updates(mSysPatent.SysPatent, map[string]interface{}{
|
||||
"shelf": status, "updated_at": time.Now(),
|
||||
})
|
||||
}
|
||||
|
||||
// Delete 删除操作
|
||||
func (c *Patent) Delete(id uint64) error {
|
||||
mUserPatent := model.NewUserPatent()
|
||||
mUserPatent.ID = id
|
||||
|
||||
isExist, err := model2.FirstField(mUserPatent.UserPatent, []string{"id", "uid", "patent_id"})
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
} else if !isExist {
|
||||
return errors.New("操作错误,用户专利信息不存在或已被删除")
|
||||
} else if mUserPatent.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)
|
||||
})
|
||||
}
|
||||
|
||||
func NewPatent() PatentHandle {
|
||||
return func(session *session.Enterprise, local string) *Patent {
|
||||
return &Patent{
|
||||
Enterprise: session,
|
||||
local: local,
|
||||
}
|
||||
}
|
||||
}
|
12
app/api/enterprise/model/sys_patent.go
Normal file
12
app/api/enterprise/model/sys_patent.go
Normal file
@ -0,0 +1,12 @@
|
||||
package model
|
||||
|
||||
import "SciencesServer/app/common/model"
|
||||
|
||||
// SysPatent 专利信息
|
||||
type SysPatent struct {
|
||||
*model.SysPatent
|
||||
}
|
||||
|
||||
func NewSysPatent() *SysPatent {
|
||||
return &SysPatent{model.NewSysPatent()}
|
||||
}
|
11
app/api/enterprise/model/user_patent.go
Normal file
11
app/api/enterprise/model/user_patent.go
Normal file
@ -0,0 +1,11 @@
|
||||
package model
|
||||
|
||||
import "SciencesServer/app/common/model"
|
||||
|
||||
type UserPatent struct {
|
||||
*model.UserPatent
|
||||
}
|
||||
|
||||
func NewUserPatent() *UserPatent {
|
||||
return &UserPatent{model.NewUserPatent()}
|
||||
}
|
Reference in New Issue
Block a user