feat:优化项目信息,待测试修改
This commit is contained in:
@ -6,11 +6,10 @@ import (
|
||||
"SciencesServer/app/basic/controller"
|
||||
model2 "SciencesServer/app/common/model"
|
||||
"SciencesServer/app/session"
|
||||
"SciencesServer/serve/orm"
|
||||
"SciencesServer/utils"
|
||||
"errors"
|
||||
"fmt"
|
||||
"gorm.io/gorm"
|
||||
"time"
|
||||
)
|
||||
|
||||
// Patent 专利信息
|
||||
@ -30,7 +29,7 @@ type (
|
||||
// PatentDetailInfo 专利详细信息
|
||||
PatentDetailInfo struct {
|
||||
ID string `json:"id"`
|
||||
*model2.SysPatent
|
||||
*model2.TechnologyPatent
|
||||
}
|
||||
// PatentParams 专利参数信息
|
||||
PatentParams struct {
|
||||
@ -57,7 +56,7 @@ type (
|
||||
}
|
||||
)
|
||||
|
||||
func (c *Patent) ipcTree(src []*model2.SysPatentClassify, parentID uint64) []*PatentIPCInfo {
|
||||
func (c *Patent) ipcTree(src []*model2.TechnologyPatentClassify, parentID uint64) []*PatentIPCInfo {
|
||||
out := make([]*PatentIPCInfo, 0)
|
||||
|
||||
for _, v := range src {
|
||||
@ -79,7 +78,7 @@ func (c *Patent) ipcTree(src []*model2.SysPatentClassify, parentID uint64) []*Pa
|
||||
return out
|
||||
}
|
||||
|
||||
func (c *PatentParams) checkParams(iModel *model.SysPatent, condition map[string]interface{}) error {
|
||||
func (c *PatentParams) checkParams(iModel *model.TechnologyPatent, condition map[string]interface{}) error {
|
||||
isExist, err := iModel.IsExistParams(condition)
|
||||
|
||||
if err != nil {
|
||||
@ -92,10 +91,17 @@ func (c *PatentParams) checkParams(iModel *model.SysPatent, condition map[string
|
||||
|
||||
// Instance 首页信息
|
||||
func (c *Patent) Instance(tenantID uint64, title, ipc string, page, pageSize int) (*controller.ReturnPages, error) {
|
||||
mSysPatent := model.NewSysPatent()
|
||||
mSysPatent := model.NewTechnologyPatent()
|
||||
|
||||
where := make([]*model2.ModelWhere, 0)
|
||||
|
||||
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))
|
||||
}
|
||||
if title != "" {
|
||||
where = append(where, model2.NewWhereLike("p.title", title))
|
||||
}
|
||||
@ -123,140 +129,152 @@ func (c *Patent) Instance(tenantID uint64, title, ipc string, page, pageSize int
|
||||
|
||||
// Detail 详细信息
|
||||
func (c *Patent) Detail(id uint64) (*PatentDetailInfo, error) {
|
||||
mSysPatent := model.NewSysPatent()
|
||||
mSysPatent.ID = id
|
||||
mTechnologyPatent := model.NewTechnologyPatent()
|
||||
mTechnologyPatent.ID = id
|
||||
|
||||
isExist, err := model2.First(mSysPatent.SysPatent)
|
||||
isExist, err := model2.First(mTechnologyPatent.TechnologyPatent)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else if !isExist {
|
||||
return nil, errors.New("操作错误,专利信息不存在或已被删除")
|
||||
}
|
||||
return &PatentDetailInfo{ID: mSysPatent.GetEncodeID(), SysPatent: mSysPatent.SysPatent}, nil
|
||||
return &PatentDetailInfo{ID: mTechnologyPatent.GetEncodeID(),
|
||||
TechnologyPatent: mTechnologyPatent.TechnologyPatent}, nil
|
||||
}
|
||||
|
||||
// Form 数据操作
|
||||
func (c *Patent) Form(params *PatentParams) error {
|
||||
mSysPatent := model.NewSysPatent()
|
||||
mTechnologyPatent := model.NewTechnologyPatent()
|
||||
|
||||
_condition := make(map[string]interface{}, 0)
|
||||
|
||||
if params.ID > 0 {
|
||||
mSysPatent.ID = params.ID
|
||||
mTechnologyPatent.ID = params.ID
|
||||
|
||||
isExist, err := model2.FirstField(mSysPatent.SysPatent, []string{"id", "tenant_id", "apply_code", "ipc_code", "created_at"})
|
||||
isExist, err := model2.FirstField(mTechnologyPatent.TechnologyPatent, []string{"id", "tenant_id", "uid", "apply_code", "ipc_code", "created_at"})
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
} else if !isExist {
|
||||
return errors.New("操作错误,专利信息不存在或已被删除")
|
||||
} else if c.TenantID > 0 && mTechnologyPatent.TenantID > 0 && c.TenantID != mTechnologyPatent.TenantID {
|
||||
return errors.New("操作错误,无权限操作")
|
||||
}
|
||||
if mSysPatent.ApplyCode != params.ApplyCode {
|
||||
if mTechnologyPatent.ApplyCode != params.ApplyCode {
|
||||
_condition["apply_code"] = params.ApplyCode
|
||||
}
|
||||
if mSysPatent.IPCCode != params.IPCCode {
|
||||
if mTechnologyPatent.IPCCode != params.IPCCode {
|
||||
_condition["ipc_code"] = params.IPCCode
|
||||
}
|
||||
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(params.Kind)
|
||||
mSysPatent.Title = params.Title
|
||||
mSysPatent.FileUrl = params.FileUrl
|
||||
mSysPatent.ApplyCode = params.ApplyCode
|
||||
mSysPatent.ApplyAt = params.ApplyAt
|
||||
mSysPatent.OpenCode = params.OpenCode
|
||||
mSysPatent.OpenAt = params.OpenAt
|
||||
mSysPatent.ApplyName = params.ApplyName
|
||||
mSysPatent.ApplyAddress = params.ApplyAddress
|
||||
mSysPatent.Inventor = params.Inventor
|
||||
mSysPatent.Description = params.Description
|
||||
mSysPatent.PrincipalClaim = params.PrincipalClaim
|
||||
mSysPatent.IPCCode = params.IPCCode
|
||||
mSysPatent.ShelfStatus = model2.ShelfStatusKind(params.ShelfStatus)
|
||||
mSysPatent.Status = model2.SysParentStatus(params.Status)
|
||||
mTechnologyPatent.Kind = model2.SysParentKind(params.Kind)
|
||||
mTechnologyPatent.Title = params.Title
|
||||
mTechnologyPatent.FileUrl = params.FileUrl
|
||||
mTechnologyPatent.ApplyCode = params.ApplyCode
|
||||
mTechnologyPatent.ApplyAt = params.ApplyAt
|
||||
mTechnologyPatent.OpenCode = params.OpenCode
|
||||
mTechnologyPatent.OpenAt = params.OpenAt
|
||||
mTechnologyPatent.ApplyName = params.ApplyName
|
||||
mTechnologyPatent.ApplyAddress = params.ApplyAddress
|
||||
mTechnologyPatent.Inventor = params.Inventor
|
||||
mTechnologyPatent.Description = params.Description
|
||||
mTechnologyPatent.PrincipalClaim = params.PrincipalClaim
|
||||
mTechnologyPatent.IPCCode = params.IPCCode
|
||||
mTechnologyPatent.ShelfStatus = model2.ShelfStatusKind(params.ShelfStatus)
|
||||
mTechnologyPatent.Status = model2.SysParentStatus(params.Status)
|
||||
|
||||
if mSysPatent.ID > 0 {
|
||||
return model2.Updates(mSysPatent.SysPatent, mSysPatent.SysPatent)
|
||||
if mTechnologyPatent.ID > 0 {
|
||||
return model2.Updates(mTechnologyPatent.TechnologyPatent, mTechnologyPatent.TechnologyPatent)
|
||||
}
|
||||
_condition["apply_code"] = params.ApplyCode
|
||||
_condition["ipc_code"] = params.IPCCode
|
||||
|
||||
if isExist, err := mSysPatent.IsExistParams(_condition); err != nil {
|
||||
if isExist, err := mTechnologyPatent.IsExistParams(_condition); err != nil {
|
||||
return err
|
||||
} else if isExist {
|
||||
return errors.New("操作错误,申请号或公开(公告)号已存在")
|
||||
}
|
||||
return model2.Create(mSysPatent.SysPatent)
|
||||
mTechnologyPatent.TenantID = c.TenantID
|
||||
return model2.Create(mTechnologyPatent.TechnologyPatent)
|
||||
}
|
||||
|
||||
// Bind 绑定信息
|
||||
func (c *Patent) Bind(id, uid uint64) error {
|
||||
mSysPatent := model.NewSysPatent()
|
||||
mSysPatent.ID = id
|
||||
mTechnologyPatent := model.NewTechnologyPatent()
|
||||
mTechnologyPatent.ID = id
|
||||
|
||||
isExist, err := model2.FirstField(mSysPatent.SysPatent, []string{"id", "tenant_id"})
|
||||
isExist, err := model2.FirstField(mTechnologyPatent.TechnologyPatent, []string{"id", "uid", "tenant_id"})
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
} else if !isExist {
|
||||
return errors.New("操作错误,专利信息不存在或已被删除")
|
||||
} else if c.TenantID > 0 && mTechnologyPatent.TenantID > 0 && c.TenantID != mTechnologyPatent.TenantID {
|
||||
return errors.New("操作错误,无权限操作")
|
||||
}
|
||||
mUserPatent := model.NewUserPatent()
|
||||
|
||||
if isExist, err = model2.FirstField(mUserPatent.UserPatent, []string{"id", "uid"}, model2.NewWhere("patent_id", id)); err != nil {
|
||||
if err = model2.Updates(mTechnologyPatent.TechnologyPatent, map[string]interface{}{
|
||||
"uid": uid, "updated_at": time.Now(),
|
||||
}); 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)
|
||||
})
|
||||
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)
|
||||
//})
|
||||
}
|
||||
|
||||
func (c *Patent) Shelf(id uint64) error {
|
||||
return controller.NewShelf(controller.WithShelfSessionAdmin(c.Admin)).Handle(model2.NewSysPatent(), id)
|
||||
return controller.NewShelf(controller.WithShelfSessionAdmin(c.Admin)).Handle(model2.NewTechnologyPatent(), id)
|
||||
}
|
||||
|
||||
// Delete 删除操作
|
||||
func (c *Patent) Delete(id uint64) error {
|
||||
mSysPatent := model.NewSysPatent()
|
||||
mSysPatent.ID = id
|
||||
mTechnologyPatent := model.NewTechnologyPatent()
|
||||
mTechnologyPatent.ID = id
|
||||
|
||||
isExist, err := model2.FirstField(mSysPatent.SysPatent, []string{"id", "tenant_id"})
|
||||
isExist, err := model2.FirstField(mTechnologyPatent.TechnologyPatent, []string{"id", "uid", "tenant_id"})
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
} else if !isExist {
|
||||
return errors.New("操作错误,专利信息不存在或已被删除")
|
||||
} else if c.TenantID > 0 && mSysPatent.TenantID != c.TenantID {
|
||||
} else if c.TenantID > 0 && mTechnologyPatent.TenantID > 0 && c.TenantID != mTechnologyPatent.TenantID {
|
||||
return errors.New("操作错误,无权限操作")
|
||||
}
|
||||
return model2.Delete(mSysPatent.SysPatent)
|
||||
return model2.Delete(mTechnologyPatent.TechnologyPatent)
|
||||
}
|
||||
|
||||
// IPC IPC信息
|
||||
func (c *Patent) IPC() ([]*PatentIPCInfo, error) {
|
||||
mSysPatentClassify := model.NewSysPatentClassify()
|
||||
out := make([]*model2.SysPatentClassify, 0)
|
||||
mTechnologyPatentClassify := model.NewTechnologyPatentClassify()
|
||||
out := make([]*model2.TechnologyPatentClassify, 0)
|
||||
|
||||
if err := model2.Scan(mSysPatentClassify.SysPatentClassify, &out); err != nil {
|
||||
if err := model2.Scan(mTechnologyPatentClassify.TechnologyPatentClassify, &out); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return c.ipcTree(out, 0), nil
|
||||
@ -264,12 +282,12 @@ func (c *Patent) IPC() ([]*PatentIPCInfo, error) {
|
||||
|
||||
// IPCForm IPC数据操作
|
||||
func (c *Patent) IPCForm(params *PatentIPCParams) error {
|
||||
mSysPatentClassify := model.NewSysPatentClassify()
|
||||
mTechnologyPatentClassify := model.NewTechnologyPatentClassify()
|
||||
|
||||
if params.ID > 0 {
|
||||
mSysPatentClassify.ID = params.ID
|
||||
mTechnologyPatentClassify.ID = params.ID
|
||||
|
||||
isExist, err := model2.FirstField(mSysPatentClassify.SysPatentClassify, []string{"id", "created_at"})
|
||||
isExist, err := model2.FirstField(mTechnologyPatentClassify.TechnologyPatentClassify, []string{"id", "created_at"})
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
@ -277,20 +295,20 @@ func (c *Patent) IPCForm(params *PatentIPCParams) error {
|
||||
return errors.New("操作错误,IPC信息不存在或已被删除")
|
||||
}
|
||||
}
|
||||
mSysPatentClassify.SetIndustryDetailAttribute(params.Industrys)
|
||||
mTechnologyPatentClassify.SetIndustryDetailAttribute(params.Industrys)
|
||||
// 查询上级元素
|
||||
if params.ParentID > 0 {
|
||||
mPSysPatentClassify := model.NewSysPatentClassify()
|
||||
mPSysPatentClassify.ID = params.ParentID
|
||||
mPTechnologyPatentClassify := model.NewTechnologyPatentClassify()
|
||||
mPTechnologyPatentClassify.ID = params.ParentID
|
||||
|
||||
isExist, err := model2.FirstField(mPSysPatentClassify.SysPatentClassify, []string{"id", "industry"})
|
||||
isExist, err := model2.FirstField(mPTechnologyPatentClassify.TechnologyPatentClassify, []string{"id", "industry"})
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
} else if !isExist {
|
||||
return errors.New("操作错误,IPC父级信息不存在或已被删除")
|
||||
}
|
||||
_identitys := mPSysPatentClassify.GetIndustryDetailAttribute()
|
||||
_identitys := mPTechnologyPatentClassify.GetIndustryDetailAttribute()
|
||||
|
||||
for _, v := range params.Industrys {
|
||||
if utils.InArray(v, _identitys) {
|
||||
@ -298,32 +316,31 @@ func (c *Patent) IPCForm(params *PatentIPCParams) error {
|
||||
}
|
||||
_identitys = append(_identitys, v)
|
||||
}
|
||||
mSysPatentClassify.SetIndustryDetailAttribute(_identitys)
|
||||
mTechnologyPatentClassify.SetIndustryDetailAttribute(_identitys)
|
||||
}
|
||||
mSysPatentClassify.ParentID = params.ParentID
|
||||
mSysPatentClassify.IPC = params.IPC
|
||||
mSysPatentClassify.SetIndustryAttribute(params.Industrys)
|
||||
mTechnologyPatentClassify.ParentID = params.ParentID
|
||||
mTechnologyPatentClassify.IPC = params.IPC
|
||||
mTechnologyPatentClassify.SetIndustryAttribute(params.Industrys)
|
||||
|
||||
if mSysPatentClassify.ID > 0 {
|
||||
return model2.Updates(mSysPatentClassify.SysPatentClassify, mSysPatentClassify.SysPatentClassify)
|
||||
if mTechnologyPatentClassify.ID > 0 {
|
||||
return model2.Updates(mTechnologyPatentClassify.TechnologyPatentClassify, mTechnologyPatentClassify.TechnologyPatentClassify)
|
||||
}
|
||||
|
||||
return model2.Create(mSysPatentClassify.SysPatentClassify)
|
||||
return model2.Create(mTechnologyPatentClassify.TechnologyPatentClassify)
|
||||
}
|
||||
|
||||
// IPCDelete IPC删除操作
|
||||
func (c *Patent) IPCDelete(id uint64) error {
|
||||
mSysPatentClassify := model.NewSysPatentClassify()
|
||||
mSysPatentClassify.ID = id
|
||||
mTechnologyPatentClassify := model.NewTechnologyPatentClassify()
|
||||
mTechnologyPatentClassify.ID = id
|
||||
|
||||
isExist, err := model2.FirstField(mSysPatentClassify.SysPatentClassify, []string{"id", "created_at"})
|
||||
isExist, err := model2.FirstField(mTechnologyPatentClassify.TechnologyPatentClassify, []string{"id", "created_at"})
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
} else if !isExist {
|
||||
return errors.New("操作错误,IPC信息不存在或已被删除")
|
||||
}
|
||||
return model2.Delete(mSysPatentClassify.SysPatentClassify)
|
||||
return model2.Delete(mTechnologyPatentClassify.TechnologyPatentClassify)
|
||||
}
|
||||
|
||||
func NewPatent() PatentHandle {
|
||||
|
Reference in New Issue
Block a user