@ -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信息