Files
2021-10-15 15:06:02 +08:00

155 lines
4.6 KiB
Go

package technology
import (
"SciencesServer/app/api/enterprise/model"
"SciencesServer/app/api/manage/controller"
model2 "SciencesServer/app/common/model"
"SciencesServer/app/service"
"SciencesServer/utils"
"errors"
"time"
)
// Patent 专利管理
type Patent struct {
*service.SessionEnterprise
local string
}
type PatentHandle func(enterprise *service.SessionEnterprise, local string) *Patent
type (
// PatentInfo 专利信息
PatentInfo struct {
ID string `json:"id"`
Title string `json:"title"`
ApplyCode string `json:"apply_code"` // 申请号
ApplyName string `json:"apply_name"` // 申请人
ApplyAt time.Time `json:"apply_at"` // 申请时间
Inventor string `json:"inventor"` // 发明人
}
// PatentDetailInfo 专利详细信息
PatentDetailInfo struct {
ID string `json:"id"`
*model2.TechnologyPatent
}
// PatentParams 专利参数信息
PatentParams struct {
ID uint64
Title, IPCCode, CPCCode, ApplyCode, ApplyName, ApplyAddress, ApplyZipCode,
Inventor, PriorityCode, OpenCode, ApplyAt, PriorityAt, OpenAt string
}
)
// List 列表信息
func (c *Patent) List(title string, page, pageSize int) (*controller.ReturnPages, error) {
mTechnologyPatent := model.NewTechnologyPatent()
where := []*model2.ModelWhereOrder{&model2.ModelWhereOrder{
Where: model2.NewWhere("uid", c.ManageUID),
Order: model2.NewOrder("id", model2.OrderModeToDesc),
}}
if title != "" {
where = append(where, &model2.ModelWhereOrder{
Where: model2.NewWhereLike("title", title),
})
}
out := make([]*model2.TechnologyPatent, 0)
var count int64
if err := model2.PagesFields(mTechnologyPatent.TechnologyPatent, &out, []string{"id", "title", "apply_code", "inventor",
"apply_name", "apply_at"}, page, pageSize, &count, where...); err != nil {
return nil, err
}
list := make([]*PatentInfo, 0)
for _, v := range out {
list = append(list, &PatentInfo{
ID: v.GetEncodeID(), Title: v.Title, ApplyCode: v.ApplyCode, ApplyName: v.ApplyName,
ApplyAt: v.ApplyAt, Inventor: v.Inventor,
})
}
return &controller.ReturnPages{Data: list, Count: count}, nil
}
// Detail 详细信息
func (c *Patent) Detail(id uint64) (*PatentDetailInfo, error) {
mTechnologyPatent := model.NewTechnologyPatent()
mTechnologyPatent.ID = id
isExist, err := model2.First(mTechnologyPatent.TechnologyPatent)
if err != nil {
return nil, err
} else if !isExist {
return nil, errors.New("操作错误,专利信息不存在")
}
return &PatentDetailInfo{
ID: mTechnologyPatent.GetEncodeID(), TechnologyPatent: mTechnologyPatent.TechnologyPatent,
}, nil
}
func (c *Patent) Form(params *PatentParams) error {
mTechnologyPatent := model.NewTechnologyPatent()
if params.ID > 0 {
mTechnologyPatent.ID = params.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.ManageUID {
return errors.New("无权限操作")
}
}
mTechnologyPatent.Title = params.Title
mTechnologyPatent.IPCCode = params.IPCCode
mTechnologyPatent.CPCCode = params.CPCCode
mTechnologyPatent.ApplyCode = params.ApplyCode
mTechnologyPatent.ApplyName = params.ApplyName
mTechnologyPatent.ApplyZipCode = params.ApplyZipCode
mTechnologyPatent.ApplyAt = utils.DataTimeToDate(params.ApplyAt)
mTechnologyPatent.Inventor = params.Inventor
mTechnologyPatent.PriorityCode = params.PriorityCode
mTechnologyPatent.PriorityAt = utils.DataTimeToDate(params.PriorityAt)
mTechnologyPatent.OpenCode = params.OpenCode
mTechnologyPatent.OpenAt = utils.DataTimeToDate(params.OpenAt)
if mTechnologyPatent.ID > 0 {
mTechnologyPatent.UpdatedAt = time.Now()
return model2.Updates(mTechnologyPatent.TechnologyPatent, mTechnologyPatent.TechnologyPatent)
}
mTechnologyPatent.TenantID = c.TenantID
mTechnologyPatent.Local.Local = c.local
mTechnologyPatent.UID = c.ManageUID
return model2.Create(mTechnologyPatent.TechnologyPatent)
}
// Delete 删除操作
func (c *Patent) Delete(id uint64) 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.ManageUID {
return errors.New("无权限操作")
}
return model2.Delete(mTechnologyPatent.TechnologyPatent)
}
func NewPatent() PatentHandle {
return func(enterprise *service.SessionEnterprise, local string) *Patent {
return &Patent{SessionEnterprise: enterprise, local: local}
}
}