feat:完善项目
This commit is contained in:
@ -224,7 +224,7 @@ func (*Sys) AboutDetail(c *gin.Context) {
|
||||
api.APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
data, err := sys.NewAbout()(api.GetSession()(c).(*session.Admin)).Instance(form.Convert())
|
||||
data, err := sys.NewAbout()(api.GetSession()(c).(*session.Admin)).Detail(form.Convert())
|
||||
api.APIResponse(err, data)(c)
|
||||
}
|
||||
|
||||
@ -234,7 +234,7 @@ func (*Sys) AboutForm(c *gin.Context) {
|
||||
api.TenantIDStringForm
|
||||
ParentID string `json:"parent_id" form:"parent_id"`
|
||||
Title string `json:"title" form:"title" binding:"required"`
|
||||
Content string `json:"content" form:"content" binding:"required"`
|
||||
Content string `json:"content" form:"content"`
|
||||
Sort int `json:"sort" form:"sort"`
|
||||
}{}
|
||||
if err := api.Bind(form)(c); err != nil {
|
||||
@ -251,13 +251,12 @@ func (*Sys) AboutForm(c *gin.Context) {
|
||||
}
|
||||
|
||||
func (*Sys) AboutDelete(c *gin.Context) {
|
||||
form := &struct {
|
||||
api.TenantIDStringForm
|
||||
}{}
|
||||
form := new(api.IDStringForm)
|
||||
|
||||
if err := api.Bind(form)(c); err != nil {
|
||||
api.APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
data, err := sys.NewAbout()(api.GetSession()(c).(*session.Admin)).Instance(form.Convert())
|
||||
api.APIResponse(err, data)(c)
|
||||
err := sys.NewAbout()(api.GetSession()(c).(*session.Admin)).Delete(form.Convert())
|
||||
api.APIResponse(err)(c)
|
||||
}
|
||||
|
131
app/api/admin/api/technology.go
Normal file
131
app/api/admin/api/technology.go
Normal file
@ -0,0 +1,131 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"SciencesServer/app/api/admin/controller/technology"
|
||||
"SciencesServer/app/basic/api"
|
||||
"SciencesServer/app/session"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
type Technology struct{}
|
||||
|
||||
func (*Technology) Patent(c *gin.Context) {
|
||||
form := &struct {
|
||||
api.TenantIDStringForm
|
||||
Title string `json:"title" form:"title"`
|
||||
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 := technology.NewPatent()(api.GetSession()(c).(*session.Admin)).Instance(form.Convert(), form.Title, form.IPCCode,
|
||||
form.Page, form.PageSize)
|
||||
api.APIResponse(err, data)(c)
|
||||
}
|
||||
|
||||
func (*Technology) PatentDetail(c *gin.Context) {
|
||||
form := new(api.IDStringForm)
|
||||
|
||||
if err := api.Bind(form)(c); err != nil {
|
||||
api.APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
data, err := technology.NewPatent()(api.GetSession()(c).(*session.Admin)).Detail(form.Convert())
|
||||
api.APIResponse(err, data)(c)
|
||||
}
|
||||
|
||||
func (*Technology) PatentForm(c *gin.Context) {
|
||||
form := &struct {
|
||||
api.IDStringForm
|
||||
api.TenantIDStringForm
|
||||
Kind int `json:"kind" form:"kind" binding:"kind"`
|
||||
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"`
|
||||
ApplyName string `json:"apply_name" form:"apply_name" binding:"required"`
|
||||
ApplyAddress string `json:"apply_address" form:"apply_address" binding:"required"`
|
||||
ApplyAt string `json:"apply_at" form:"apply_at" binding:"required"`
|
||||
OpenCode string `json:"open_code" form:"open_code" binding:"required"`
|
||||
OpenAt string `json:"open_at" form:"open_at" binding:"required"`
|
||||
IPCCode string `json:"ipc_code" form:"ipc_code"`
|
||||
Inventor string `json:"inventor" form:"inventor"`
|
||||
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"`
|
||||
}{}
|
||||
if err := api.Bind(form)(c); err != nil {
|
||||
api.APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
err := technology.NewPatent()(api.GetSession()(c).(*session.Admin)).Form(&technology.PatentParams{
|
||||
ID: form.IDStringForm.Convert(), TenantID: form.TenantIDStringForm.Convert(),
|
||||
Kind: form.Kind, Title: form.Title, FileUrl: (&api.FileForm{File: form.FileUrl}).FilterURL(),
|
||||
ApplyCode: form.ApplyCode, ApplyName: form.ApplyName, ApplyAddress: form.ApplyAddress, ApplyAt: form.ApplyAt,
|
||||
OpenCode: form.OpenCode, OpenAt: form.OpenAt, Inventor: form.Inventor, IPCCode: form.IPCCode,
|
||||
Description: form.Description, PrincipalClaim: form.PrincipalClaim,
|
||||
ShelfStatus: form.ShelfStatus, Status: form.Status,
|
||||
})
|
||||
api.APIResponse(err)(c)
|
||||
}
|
||||
|
||||
func (*Technology) PatentBind(c *gin.Context) {
|
||||
form := &struct {
|
||||
api.IDStringForm
|
||||
UID string `json:"uid" form:"uid" binding:"required"`
|
||||
}{}
|
||||
if err := api.Bind(form)(c); err != nil {
|
||||
api.APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
err := technology.NewPatent()(api.GetSession()(c).(*session.Admin)).Bind(form.Convert(),
|
||||
(&api.IDStringForm{ID: form.UID}).Convert())
|
||||
api.APIResponse(err)(c)
|
||||
}
|
||||
|
||||
func (*Technology) PatentDelete(c *gin.Context) {
|
||||
form := new(api.IDStringForm)
|
||||
|
||||
if err := api.Bind(form)(c); err != nil {
|
||||
api.APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
err := technology.NewPatent()(api.GetSession()(c).(*session.Admin)).Delete(form.Convert())
|
||||
api.APIResponse(err)(c)
|
||||
}
|
||||
|
||||
func (*Technology) PatentIPC(c *gin.Context) {
|
||||
data, err := technology.NewPatent()(api.GetSession()(c).(*session.Admin)).IPC()
|
||||
api.APIResponse(err, data)(c)
|
||||
}
|
||||
|
||||
func (*Technology) PatentIPCForm(c *gin.Context) {
|
||||
form := &struct {
|
||||
api.IDStringForm
|
||||
ParentID string `json:"parent_id" form:"parent_id"`
|
||||
IPC string `json:"ipc" form:"ipc" binding:"required"`
|
||||
Industrys []string `json:"industrys" form:"industrys"`
|
||||
}{}
|
||||
if err := api.Bind(form)(c); err != nil {
|
||||
api.APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
err := technology.NewPatent()(api.GetSession()(c).(*session.Admin)).IPCForm(&technology.PatentIPCParams{
|
||||
ID: form.Convert(), ParentID: (&api.IDStringForm{ID: form.ParentID}).Convert(),
|
||||
IPC: form.IPC, Industrys: form.Industrys,
|
||||
})
|
||||
api.APIResponse(err)(c)
|
||||
}
|
||||
|
||||
func (*Technology) PatentIPCDelete(c *gin.Context) {
|
||||
form := new(api.IDStringForm)
|
||||
|
||||
if err := api.Bind(form)(c); err != nil {
|
||||
api.APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
err := technology.NewPatent()(api.GetSession()(c).(*session.Admin)).IPCDelete(form.Convert())
|
||||
api.APIResponse(err)(c)
|
||||
}
|
@ -23,7 +23,7 @@ type ExamineManageInfo struct {
|
||||
}
|
||||
|
||||
// examineHandle 审核处理
|
||||
var examineHandle = map[int]func(uint64) (*ExamineManageInfo, error){
|
||||
var examineHandle = map[int]func(id, tenantID uint64) (*ExamineManageInfo, error){
|
||||
config.TenantUserIdentityForCompany: examineCompany,
|
||||
config.TenantUserIdentityForExpert: examineExpert,
|
||||
config.TenantUserIdentityForResearch: examineResearch,
|
||||
@ -33,21 +33,23 @@ var examineHandle = map[int]func(uint64) (*ExamineManageInfo, error){
|
||||
func checkManage(IModel model2.IModel, id uint64) error {
|
||||
IModel.SetID(id)
|
||||
|
||||
if isExist, err := model2.FirstField(IModel, []string{"id", "examine_status"}); err != nil {
|
||||
if isExist, err := model2.FirstField(IModel, []string{"id", "tenant_id", "examine_status"}); err != nil {
|
||||
return err
|
||||
} else if !isExist {
|
||||
return errors.New("数据信息不存在")
|
||||
return errors.New("操作错误,数据信息不存在")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func examineCompany(id uint64) (*ExamineManageInfo, error) {
|
||||
func examineCompany(id, tenantID uint64) (*ExamineManageInfo, error) {
|
||||
mManageCompany := model.NewManageCompany()
|
||||
|
||||
err := checkManage(mManageCompany.ManageCompany, id)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else if tenantID > 0 && mManageCompany.TenantID != tenantID {
|
||||
return nil, errors.New("操作错误,无权限操作")
|
||||
} else if mManageCompany.Examine.ExamineStatus != model2.ExamineStatusForOngoing {
|
||||
return nil, errors.New("操作错误,当前入驻信息已审核")
|
||||
}
|
||||
@ -61,13 +63,15 @@ func examineCompany(id uint64) (*ExamineManageInfo, error) {
|
||||
return &ExamineManageInfo{IModel: mManageCompany.ManageCompany, UIDs: uids}, nil
|
||||
}
|
||||
|
||||
func examineExpert(id uint64) (*ExamineManageInfo, error) {
|
||||
func examineExpert(id, tenantID uint64) (*ExamineManageInfo, error) {
|
||||
mManageExpert := model.NewManageExpert()
|
||||
|
||||
err := checkManage(mManageExpert.ManageExpert, id)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else if tenantID > 0 && mManageExpert.TenantID != tenantID {
|
||||
return nil, errors.New("操作错误,无权限操作")
|
||||
} else if mManageExpert.Examine.ExamineStatus != model2.ExamineStatusForOngoing {
|
||||
return nil, errors.New("操作错误,当前入驻信息已审核")
|
||||
}
|
||||
@ -81,13 +85,15 @@ func examineExpert(id uint64) (*ExamineManageInfo, error) {
|
||||
return &ExamineManageInfo{IModel: mManageExpert.ManageExpert, UIDs: uids}, nil
|
||||
}
|
||||
|
||||
func examineResearch(id uint64) (*ExamineManageInfo, error) {
|
||||
func examineResearch(id, tenantID uint64) (*ExamineManageInfo, error) {
|
||||
mManageResearch := model.NewManageResearch()
|
||||
|
||||
err := checkManage(mManageResearch.ManageResearch, id)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else if tenantID > 0 && mManageResearch.TenantID != tenantID {
|
||||
return nil, errors.New("操作错误,无权限操作")
|
||||
} else if mManageResearch.Examine.ExamineStatus != model2.ExamineStatusForOngoing {
|
||||
return nil, errors.New("操作错误,当前入驻信息已审核")
|
||||
}
|
||||
@ -102,13 +108,15 @@ func examineResearch(id uint64) (*ExamineManageInfo, error) {
|
||||
return &ExamineManageInfo{IModel: mManageResearch.ManageResearch, UIDs: uids}, nil
|
||||
}
|
||||
|
||||
func examineLaboratory(id uint64) (*ExamineManageInfo, error) {
|
||||
func examineLaboratory(id, tenantID uint64) (*ExamineManageInfo, error) {
|
||||
mManageLaboratory := model.NewManageLaboratory()
|
||||
|
||||
err := checkManage(mManageLaboratory.ManageLaboratory, id)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else if tenantID > 0 && mManageLaboratory.TenantID != tenantID {
|
||||
return nil, errors.New("操作错误,无权限操作")
|
||||
} else if mManageLaboratory.Examine.ExamineStatus != model2.ExamineStatusForOngoing {
|
||||
return nil, errors.New("操作错误,当前入驻信息已审核")
|
||||
}
|
||||
@ -123,13 +131,15 @@ func examineLaboratory(id uint64) (*ExamineManageInfo, error) {
|
||||
return &ExamineManageInfo{IModel: mManageLaboratory.ManageLaboratory, UIDs: uids}, nil
|
||||
}
|
||||
|
||||
func examineAgent(id uint64) (*ExamineManageInfo, error) {
|
||||
func examineAgent(id, tenantID uint64) (*ExamineManageInfo, error) {
|
||||
mManageAgent := model.NewManageAgent()
|
||||
|
||||
err := checkManage(mManageAgent.ManageAgent, id)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else if tenantID > 0 && mManageAgent.TenantID != tenantID {
|
||||
return nil, errors.New("操作错误,无权限操作")
|
||||
} else if mManageAgent.Examine.ExamineStatus != model2.ExamineStatusForOngoing {
|
||||
return nil, errors.New("操作错误,当前入驻信息已审核")
|
||||
}
|
||||
@ -149,22 +159,20 @@ func (c *Examine) Launch(id uint64, identity, status int) error {
|
||||
_status := model2.ExamineStatusKind(status)
|
||||
|
||||
if _status != model2.ExamineStatusForRefuse && _status != model2.ExamineStatusForAgree {
|
||||
return errors.New("未知的审核模式")
|
||||
return errors.New("操作错误,未知的审核模式")
|
||||
}
|
||||
handle, has := examineHandle[identity]
|
||||
|
||||
if !has {
|
||||
return errors.New("未知的身份信息")
|
||||
return errors.New("操作错误,未知的身份信息")
|
||||
}
|
||||
data, err := handle(id)
|
||||
data, err := handle(id, c.TenantID)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return orm.GetDB().Transaction(func(tx *gorm.DB) error {
|
||||
if err = model2.Updates(data.IModel, map[string]interface{}{
|
||||
"examine_status": status, "updated_at": time.Now(),
|
||||
}, tx); err != nil {
|
||||
if err = model2.Updates(data.IModel, map[string]interface{}{"examine_status": status, "updated_at": time.Now()}, tx); err != nil {
|
||||
return err
|
||||
}
|
||||
// 拒绝后,不执行以下数据
|
||||
@ -181,7 +189,6 @@ func (c *Examine) Launch(id uint64, identity, status int) error {
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
mUserIdentity := model.NewUserIdentity()
|
||||
|
||||
identitys := make([]*model2.UserIdentity, 0)
|
||||
@ -215,8 +222,6 @@ func (c *Examine) Launch(id uint64, identity, status int) error {
|
||||
|
||||
func NewExamine() ExamineHandle {
|
||||
return func(session *session.Admin) *Examine {
|
||||
return &Examine{
|
||||
Admin: session,
|
||||
}
|
||||
return &Examine{Admin: session}
|
||||
}
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ import (
|
||||
model2 "SciencesServer/app/common/model"
|
||||
"SciencesServer/app/session"
|
||||
"errors"
|
||||
"time"
|
||||
)
|
||||
|
||||
type About struct {
|
||||
@ -18,7 +19,9 @@ type (
|
||||
AboutInfo struct {
|
||||
ID string `json:"id"`
|
||||
ParentID string `json:"parent_id"`
|
||||
Title string `json:"title"`
|
||||
Area string `json:"area"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
Children []*AboutInfo `json:"children"`
|
||||
}
|
||||
// AboutDetailInfo 详细信息
|
||||
@ -44,7 +47,9 @@ func (c *About) tree(src []*model.SysAboutInfo, parentID uint64) []*AboutInfo {
|
||||
out = append(out, &AboutInfo{
|
||||
ID: v.GetEncodeID(),
|
||||
ParentID: (&model2.Model{ID: v.ParentID}).GetEncodeID(),
|
||||
Title: v.Title,
|
||||
Area: v.FormatBasic(),
|
||||
UpdatedAt: v.UpdatedAt,
|
||||
Children: c.tree(src, v.ID),
|
||||
})
|
||||
}
|
||||
|
322
app/api/admin/controller/technology/patent.go
Normal file
322
app/api/admin/controller/technology/patent.go
Normal file
@ -0,0 +1,322 @@
|
||||
package technology
|
||||
|
||||
import (
|
||||
"SciencesServer/app/api/admin/model"
|
||||
"SciencesServer/app/basic/config"
|
||||
"SciencesServer/app/basic/controller"
|
||||
model2 "SciencesServer/app/common/model"
|
||||
"SciencesServer/app/session"
|
||||
"SciencesServer/serve/orm"
|
||||
"SciencesServer/utils"
|
||||
"errors"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
// Patent 专利信息
|
||||
type Patent struct {
|
||||
*session.Admin
|
||||
}
|
||||
|
||||
type PatentHandle func(session *session.Admin) *Patent
|
||||
|
||||
type (
|
||||
// PatentInfo 专利信息
|
||||
PatentInfo struct {
|
||||
ID string `json:"id"`
|
||||
UID string `json:"uid"`
|
||||
}
|
||||
// PatentDetailInfo 专利详细信息
|
||||
PatentDetailInfo struct {
|
||||
ID string `json:"id"`
|
||||
*model2.SysPatent
|
||||
}
|
||||
// PatentParams 专利参数信息
|
||||
PatentParams struct {
|
||||
ID, TenantID uint64
|
||||
Kind int
|
||||
Title, FileUrl string
|
||||
ApplyCode, ApplyName, ApplyAddress, ApplyAt,
|
||||
OpenCode, OpenAt string
|
||||
Inventor, IPCCode, Description, PrincipalClaim string
|
||||
ShelfStatus, Status int
|
||||
}
|
||||
// PatentIPCInfo 专利IPC信息
|
||||
PatentIPCInfo struct {
|
||||
ID string `json:"id"`
|
||||
ParentID string `json:"parent_id"`
|
||||
Industrys []string `json:"industrys"`
|
||||
IndustrysTitle []string `json:"industrys_title"`
|
||||
}
|
||||
// PatentIPCParams 专利IPC参数信息
|
||||
PatentIPCParams struct {
|
||||
ID, ParentID uint64
|
||||
IPC string
|
||||
Industrys []string `json:"industrys"`
|
||||
}
|
||||
)
|
||||
|
||||
func (c *Patent) tree() {
|
||||
|
||||
}
|
||||
|
||||
func (c *Patent) ipcTree(src []*model2.SysPatentClassify, parentID uint64) []*PatentIPCInfo {
|
||||
out := make([]*PatentIPCInfo, 0)
|
||||
|
||||
for _, v := range src {
|
||||
if v.ParentID == parentID {
|
||||
industrys := v.GetIndustryAttribute()
|
||||
industrysTitle := make([]string, 0)
|
||||
|
||||
for _, v := range industrys {
|
||||
industrysTitle = append(industrysTitle, config.GetIndustryInfo(v, "-", "/"))
|
||||
}
|
||||
out = append(out, &PatentIPCInfo{
|
||||
ID: v.GetEncodeID(),
|
||||
ParentID: (&model2.Model{ID: v.ParentID}).GetEncodeID(),
|
||||
Industrys: industrys,
|
||||
IndustrysTitle: industrysTitle,
|
||||
})
|
||||
}
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
func (c *PatentParams) checkParams(iModel *model.SysPatent, condition map[string]interface{}) error {
|
||||
isExist, err := iModel.IsExistParams(condition)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
} else if isExist {
|
||||
return errors.New("操作错误,申请号或公开(公告)号已存在")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Instance 首页信息
|
||||
func (c *Patent) Instance(tenantID uint64, title, ipc string, page, pageSize int) (*controller.ReturnPages, error) {
|
||||
mSysPatent := model.NewSysPatent()
|
||||
|
||||
where := make([]*model2.ModelWhere, 0)
|
||||
|
||||
if title != "" {
|
||||
where = append(where, model2.NewWhereLike("p.title", title))
|
||||
}
|
||||
if ipc != "" {
|
||||
where = append(where, model2.NewWhereLike("p.ipc", ipc))
|
||||
}
|
||||
var count int64
|
||||
|
||||
out, err := mSysPatent.Patent(page, pageSize, &count, where...)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &controller.ReturnPages{Data: out, Count: count}, nil
|
||||
}
|
||||
|
||||
// Detail 详细信息
|
||||
func (c *Patent) Detail(id uint64) (*PatentDetailInfo, error) {
|
||||
mSysPatent := model.NewSysPatent()
|
||||
mSysPatent.ID = id
|
||||
|
||||
isExist, err := model2.First(mSysPatent.SysPatent)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else if !isExist {
|
||||
return nil, errors.New("操作错误,专利信息不存在或已被删除")
|
||||
}
|
||||
return &PatentDetailInfo{ID: mSysPatent.GetEncodeID(), SysPatent: mSysPatent.SysPatent}, nil
|
||||
}
|
||||
|
||||
// Form 数据操作
|
||||
func (c *Patent) Form(params *PatentParams) error {
|
||||
mSysPatent := model.NewSysPatent()
|
||||
|
||||
_condition := make(map[string]interface{}, 0)
|
||||
|
||||
if params.ID > 0 {
|
||||
mSysPatent.ID = params.ID
|
||||
|
||||
isExist, err := model2.FirstField(mSysPatent.SysPatent, []string{"id", "tenant_id", "apply_code", "ipc_code", "created_at"})
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
} else if !isExist {
|
||||
return errors.New("操作错误,专利信息不存在或已被删除")
|
||||
}
|
||||
if mSysPatent.ApplyCode != params.ApplyCode {
|
||||
_condition["apply_code"] = params.ApplyCode
|
||||
}
|
||||
if mSysPatent.IPCCode != params.IPCCode {
|
||||
_condition["ipc_code"] = params.IPCCode
|
||||
}
|
||||
if len(_condition) > 0 {
|
||||
if isExist, err = mSysPatent.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)
|
||||
|
||||
if mSysPatent.ID > 0 {
|
||||
return model2.Updates(mSysPatent.SysPatent, mSysPatent.SysPatent)
|
||||
}
|
||||
_condition["apply_code"] = params.ApplyCode
|
||||
_condition["ipc_code"] = params.IPCCode
|
||||
|
||||
if isExist, err := mSysPatent.IsExistParams(_condition); err != nil {
|
||||
return err
|
||||
} else if isExist {
|
||||
return errors.New("操作错误,申请号或公开(公告)号已存在")
|
||||
}
|
||||
return model2.Create(mSysPatent.SysPatent)
|
||||
}
|
||||
|
||||
// Bind 绑定信息
|
||||
func (c *Patent) Bind(id, uid uint64) error {
|
||||
mSysPatent := model.NewSysPatent()
|
||||
mSysPatent.ID = id
|
||||
|
||||
isExist, err := model2.FirstField(mSysPatent.SysPatent, []string{"id", "tenant_id"})
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
} else if !isExist {
|
||||
return errors.New("操作错误,专利信息不存在或已被删除")
|
||||
}
|
||||
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)
|
||||
})
|
||||
}
|
||||
|
||||
// Delete 删除操作
|
||||
func (c *Patent) Delete(id uint64) error {
|
||||
mSysPatent := model.NewSysPatent()
|
||||
mSysPatent.ID = id
|
||||
|
||||
isExist, err := model2.FirstField(mSysPatent.SysPatent, []string{"id", "tenant_id"})
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
} else if !isExist {
|
||||
return errors.New("操作错误,专利信息不存在或已被删除")
|
||||
}
|
||||
return model2.Delete(mSysPatent.SysPatent)
|
||||
}
|
||||
|
||||
// IPC IPC信息
|
||||
func (c *Patent) IPC() ([]*PatentIPCInfo, error) {
|
||||
mSysPatentClassify := model.NewSysPatentClassify()
|
||||
out := make([]*model2.SysPatentClassify, 0)
|
||||
|
||||
if err := model2.Scan(mSysPatentClassify.SysPatentClassify, &out); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return c.ipcTree(out, 0), nil
|
||||
}
|
||||
|
||||
// IPCForm IPC数据操作
|
||||
func (c *Patent) IPCForm(params *PatentIPCParams) error {
|
||||
mSysPatentClassify := model.NewSysPatentClassify()
|
||||
|
||||
if params.ID > 0 {
|
||||
mSysPatentClassify.ID = params.ID
|
||||
|
||||
isExist, err := model2.FirstField(mSysPatentClassify.SysPatentClassify, []string{"id", "created_at"})
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
} else if !isExist {
|
||||
return errors.New("操作错误,IPC信息不存在或已被删除")
|
||||
}
|
||||
}
|
||||
mSysPatentClassify.SetIndustryDetailAttribute(params.Industrys)
|
||||
// 查询上级元素
|
||||
if params.ParentID > 0 {
|
||||
mPSysPatentClassify := model.NewSysPatentClassify()
|
||||
mPSysPatentClassify.ID = params.ParentID
|
||||
|
||||
isExist, err := model2.FirstField(mPSysPatentClassify.SysPatentClassify, []string{"id", "industry"})
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
} else if !isExist {
|
||||
return errors.New("操作错误,IPC父级信息不存在或已被删除")
|
||||
}
|
||||
_identitys := mPSysPatentClassify.GetIndustryDetailAttribute()
|
||||
|
||||
for _, v := range params.Industrys {
|
||||
if utils.InArray(v, _identitys) {
|
||||
continue
|
||||
}
|
||||
_identitys = append(_identitys, v)
|
||||
}
|
||||
mSysPatentClassify.SetIndustryDetailAttribute(_identitys)
|
||||
}
|
||||
mSysPatentClassify.ParentID = params.ParentID
|
||||
mSysPatentClassify.IPC = params.IPC
|
||||
mSysPatentClassify.SetIndustryAttribute(params.Industrys)
|
||||
|
||||
if mSysPatentClassify.ID > 0 {
|
||||
return model2.Updates(mSysPatentClassify.SysPatentClassify, mSysPatentClassify.SysPatentClassify)
|
||||
}
|
||||
|
||||
return model2.Create(mSysPatentClassify.SysPatentClassify)
|
||||
}
|
||||
|
||||
// IPCDelete IPC删除操作
|
||||
func (c *Patent) IPCDelete(id uint64) error {
|
||||
mSysPatentClassify := model.NewSysPatentClassify()
|
||||
mSysPatentClassify.ID = id
|
||||
|
||||
isExist, err := model2.FirstField(mSysPatentClassify.SysPatentClassify, []string{"id", "created_at"})
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
} else if !isExist {
|
||||
return errors.New("操作错误,IPC信息不存在或已被删除")
|
||||
}
|
||||
return model2.Delete(mSysPatentClassify.SysPatentClassify)
|
||||
}
|
||||
|
||||
func NewPatent() PatentHandle {
|
||||
return func(session *session.Admin) *Patent {
|
||||
return &Patent{
|
||||
Admin: session,
|
||||
}
|
||||
}
|
||||
}
|
@ -17,7 +17,7 @@ type SysAboutInfo struct {
|
||||
|
||||
func (m *SysAbout) About(where ...*model.ModelWhere) ([]*SysAboutInfo, error) {
|
||||
db := orm.GetDB().Table(m.TableName()+" AS a").
|
||||
Select("a.id", "a.parent_id", "a.title", "t.province", "t.city").
|
||||
Select("a.id", "a.parent_id", "a.title", "t.province", "t.city", "a.updated_at").
|
||||
Joins(fmt.Sprintf("LEFT JOIN %s AS t ON a.tenant_id = t.id", model.NewSysTenant().TableName())).
|
||||
Where("a.is_deleted = ?", model.DeleteStatusForNot)
|
||||
|
||||
|
59
app/api/admin/model/sys_patent.go
Normal file
59
app/api/admin/model/sys_patent.go
Normal file
@ -0,0 +1,59 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"SciencesServer/app/common/model"
|
||||
"SciencesServer/serve/orm"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
// SysPatent 专利信息
|
||||
type SysPatent struct {
|
||||
*model.SysPatent
|
||||
}
|
||||
|
||||
// SysPatentInfo 专利信息
|
||||
type SysPatentInfo struct {
|
||||
*model.SysPatent
|
||||
UID string `json:"uid"`
|
||||
}
|
||||
|
||||
func (m *SysPatent) IsExistParams(params map[string]interface{}) (bool, error) {
|
||||
var count int64
|
||||
db := orm.GetDB().Table(m.TableName())
|
||||
|
||||
if len(params) > 0 {
|
||||
for k, v := range params {
|
||||
db = db.Or(fmt.Sprintf("%s = %v AND is_deleted = %d", k, v, model.DeleteStatusForNot))
|
||||
}
|
||||
}
|
||||
err := db.Count(&count).Error
|
||||
return count > 0, err
|
||||
}
|
||||
|
||||
// Patent 专利信息
|
||||
func (m *SysPatent) Patent(page, pageSize int, count *int64, where ...*model.ModelWhere) ([]*SysPatentInfo, 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").
|
||||
Joins(fmt.Sprintf("LEFT JOIN %s AS u ON p.id = u.tenant_id AND u.is_deleted = %d",
|
||||
model.NewUserPatent().TableName(), model.DeleteStatusForNot))
|
||||
|
||||
if len(where) > 0 {
|
||||
for _, wo := range where {
|
||||
db = db.Where(wo.Condition, wo.Value)
|
||||
}
|
||||
}
|
||||
out := make([]*SysPatentInfo, 0)
|
||||
|
||||
if err := db.Count(count).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := db.Order("p.id " + model.OrderModeToDesc).Offset((page - 1) * pageSize).Limit(pageSize).Scan(&out).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func NewSysPatent() *SysPatent {
|
||||
return &SysPatent{model.NewSysPatent()}
|
||||
}
|
11
app/api/admin/model/sys_patent_classify.go
Normal file
11
app/api/admin/model/sys_patent_classify.go
Normal file
@ -0,0 +1,11 @@
|
||||
package model
|
||||
|
||||
import "SciencesServer/app/common/model"
|
||||
|
||||
type SysPatentClassify struct {
|
||||
*model.SysPatentClassify
|
||||
}
|
||||
|
||||
func NewSysPatentClassify() *SysPatentClassify {
|
||||
return &SysPatentClassify{model.NewSysPatentClassify()}
|
||||
}
|
11
app/api/admin/model/user_patent.go
Normal file
11
app/api/admin/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()}
|
||||
}
|
@ -55,7 +55,7 @@ type (
|
||||
)
|
||||
|
||||
// add 新增专利信息
|
||||
func (c *PatentParams) add(uid uint64, local string) error {
|
||||
func (c *PatentParams) add(uid uint64) error {
|
||||
mSysPatent := model.NewSysPatent()
|
||||
isExist, err := mSysPatent.IsExistParams(map[string]interface{}{
|
||||
"apply_code": c.ApplyCode, "open_code": c.OpenCode,
|
||||
@ -86,7 +86,6 @@ func (c *PatentParams) add(uid uint64, local string) error {
|
||||
}
|
||||
|
||||
mUserPatent := model.NewUserPatent()
|
||||
mUserPatent.Local.Local = local
|
||||
mUserPatent.UID = uid
|
||||
mUserPatent.PatentID = mSysPatent.ID
|
||||
|
||||
@ -259,7 +258,7 @@ func (c *Patent) Form(params *PatentParams) error {
|
||||
if params.ID > 0 {
|
||||
return params.edit(c.UID)
|
||||
}
|
||||
return params.add(c.UID, c.local)
|
||||
return params.add(c.UID)
|
||||
|
||||
}
|
||||
|
||||
|
@ -225,6 +225,8 @@ func FirstWhere(model IModel, where ...*ModelWhere) (bool, error) {
|
||||
for _, wo := range where {
|
||||
db = db.Where(wo.Condition, wo.Value)
|
||||
}
|
||||
} else {
|
||||
db = db.Where(fmt.Sprintf("%s = %d", FieldsForID, model.GetID()))
|
||||
}
|
||||
if db.Migrator().HasColumn(model, FieldsForDeleted) {
|
||||
db = db.Where(FieldsForDeleted, DeleteStatusForNot)
|
||||
@ -245,6 +247,8 @@ func FirstField(model IModel, fields []string, where ...*ModelWhere) (bool, erro
|
||||
for _, wo := range where {
|
||||
db = db.Where(wo.Condition, wo.Value)
|
||||
}
|
||||
} else {
|
||||
db = db.Where(fmt.Sprintf("%s = %d", FieldsForID, model.GetID()))
|
||||
}
|
||||
if db.Migrator().HasColumn(model, FieldsForDeleted) {
|
||||
db = db.Where(FieldsForDeleted, DeleteStatusForNot)
|
||||
|
@ -3,6 +3,7 @@ package model
|
||||
// SysPatent 专利信息数据模型
|
||||
type SysPatent struct {
|
||||
Model
|
||||
ModelTenant
|
||||
Kind SysParentKind `gorm:"column:kind;index:idx_sys_patent_kind;type:tinyint(1);default:0;comment:专利类型" json:"kind"`
|
||||
Title string `gorm:"column:title;type:varchar(100);default:'';comment:名称标题" json:"title"`
|
||||
FileUrl string `gorm:"column:file_url;type:varchar(255);default:'';comment:文件地址" json:"file_url"`
|
||||
|
@ -1,8 +1,13 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
)
|
||||
|
||||
// SysPatentClassify 专利分类信息数据模型
|
||||
type SysPatentClassify struct {
|
||||
Model
|
||||
ParentID uint64 `gorm:"column:parent_id;type:int;default:0;comment:父级ID" json:"parent_id"`
|
||||
IPC string `gorm:"column:ipc;type:varchar(18);default:'';comment:IPC主分类号" json:"ipc"`
|
||||
Industry string `gorm:"column:industry;type:varchar(255);default:'';comment:行业领域" json:"-"`
|
||||
IndustryDetail string `gorm:"column:industry_detail;type:varchar(255);default:'';comment:详细行业领域,包含父级领域信息" json:"industry_detail"`
|
||||
@ -14,6 +19,28 @@ func (m *SysPatentClassify) TableName() string {
|
||||
return "sys_patent_classify"
|
||||
}
|
||||
|
||||
func (m *SysPatentClassify) GetIndustryAttribute() []string {
|
||||
out := make([]string, 0)
|
||||
_ = json.Unmarshal([]byte(m.Industry), &out)
|
||||
return out
|
||||
}
|
||||
|
||||
func (m *SysPatentClassify) SetIndustryAttribute(value []string) {
|
||||
_bytes, _ := json.Marshal(value)
|
||||
m.Industry = string(_bytes)
|
||||
}
|
||||
|
||||
func (m *SysPatentClassify) GetIndustryDetailAttribute() []string {
|
||||
out := make([]string, 0)
|
||||
_ = json.Unmarshal([]byte(m.IndustryDetail), &out)
|
||||
return out
|
||||
}
|
||||
|
||||
func (m *SysPatentClassify) SetIndustryDetailAttribute(value []string) {
|
||||
_bytes, _ := json.Marshal(value)
|
||||
m.IndustryDetail = string(_bytes)
|
||||
}
|
||||
|
||||
func NewSysPatentClassify() *SysPatentClassify {
|
||||
return &SysPatentClassify{}
|
||||
}
|
||||
|
@ -3,7 +3,6 @@ package model
|
||||
// UserPatent 用户专利信息数据模型
|
||||
type UserPatent struct {
|
||||
Model
|
||||
Local
|
||||
UID uint64 `gorm:"column:uid;type:int;default:0;comment:用户uuid" json:"-"`
|
||||
PatentID uint64 `gorm:"column:patent_id;type:int(11);default:0;comment:专利ID" json:"-"`
|
||||
ModelDeleted
|
||||
|
@ -301,6 +301,20 @@ func registerAdminAPI(app *gin.Engine) {
|
||||
service.POST("/message/handle", _api.MessageHandle)
|
||||
service.POST("/message/delete", _api.MessageDelete)
|
||||
}
|
||||
// Technology 科技管理
|
||||
technology := v1.Group("/technology")
|
||||
{
|
||||
_api := new(api1.Technology)
|
||||
technology.POST("/patent", _api.Patent)
|
||||
technology.POST("/patent/detail", _api.PatentDetail)
|
||||
technology.POST("/patent/add", _api.PatentForm)
|
||||
technology.POST("/patent/edit", _api.PatentForm)
|
||||
technology.POST("/patent/delete", _api.PatentDelete)
|
||||
technology.GET("/patent/ipc", _api.PatentIPC)
|
||||
technology.POST("/patent/add", _api.PatentIPCForm)
|
||||
technology.POST("/patent/edit", _api.PatentIPCForm)
|
||||
technology.POST("/patent/delete", _api.PatentIPCDelete)
|
||||
}
|
||||
// Activity 活动管理
|
||||
activity := v1.Group("/activity")
|
||||
{
|
||||
|
@ -49,3 +49,24 @@ func ArrayStrings(src interface{}) []string {
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
func ArrayUnique(src interface{}) []interface{} {
|
||||
val := reflect.ValueOf(src)
|
||||
|
||||
kind := val.Kind()
|
||||
|
||||
out := make([]interface{}, 0)
|
||||
|
||||
if kind == reflect.Slice || kind == reflect.Array {
|
||||
for i := 0; i < val.Len(); i++ {
|
||||
for _, v := range out {
|
||||
if v == val.Index(i).Interface() {
|
||||
goto BREAK
|
||||
}
|
||||
}
|
||||
out = append(out, val.Index(i).Interface())
|
||||
BREAK:
|
||||
}
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
Reference in New Issue
Block a user