feat:完善项目
This commit is contained in:
@ -129,3 +129,39 @@ func (*Technology) PatentIPCDelete(c *gin.Context) {
|
|||||||
err := technology.NewPatent()(api.GetSession()(c).(*session.Admin)).IPCDelete(form.Convert())
|
err := technology.NewPatent()(api.GetSession()(c).(*session.Admin)).IPCDelete(form.Convert())
|
||||||
api.APIResponse(err)(c)
|
api.APIResponse(err)(c)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (*Technology) Paper(c *gin.Context) {
|
||||||
|
form := &struct {
|
||||||
|
api.TenantIDStringForm
|
||||||
|
Title string `json:"title" form:"title"`
|
||||||
|
api.PageForm
|
||||||
|
}{}
|
||||||
|
if err := api.Bind(form)(c); err != nil {
|
||||||
|
api.APIFailure(err.(error))(c)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
data, err := technology.NewPaper()(api.GetSession()(c).(*session.Admin)).Instance(form.Convert(), form.Title, form.Page, form.PageSize)
|
||||||
|
api.APIResponse(err, data)(c)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (*Technology) PaperDetail(c *gin.Context) {
|
||||||
|
form := new(api.IDStringForm)
|
||||||
|
|
||||||
|
if err := api.Bind(form)(c); err != nil {
|
||||||
|
api.APIFailure(err.(error))(c)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
data, err := technology.NewPaper()(api.GetSession()(c).(*session.Admin)).Detail(form.Convert())
|
||||||
|
api.APIResponse(err, data)(c)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (*Technology) PaperDelete(c *gin.Context) {
|
||||||
|
form := new(api.IDStringForm)
|
||||||
|
|
||||||
|
if err := api.Bind(form)(c); err != nil {
|
||||||
|
api.APIFailure(err.(error))(c)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
err := technology.NewPaper()(api.GetSession()(c).(*session.Admin)).Delete(form.Convert())
|
||||||
|
api.APIResponse(err)(c)
|
||||||
|
}
|
||||||
|
113
app/api/admin/controller/technology/paper.go
Normal file
113
app/api/admin/controller/technology/paper.go
Normal file
@ -0,0 +1,113 @@
|
|||||||
|
package technology
|
||||||
|
|
||||||
|
import (
|
||||||
|
"SciencesServer/app/api/admin/model"
|
||||||
|
"SciencesServer/app/basic/controller"
|
||||||
|
model2 "SciencesServer/app/common/model"
|
||||||
|
"SciencesServer/app/session"
|
||||||
|
"errors"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Paper struct {
|
||||||
|
*session.Admin
|
||||||
|
}
|
||||||
|
|
||||||
|
type PaperHandle func(session *session.Admin) *Paper
|
||||||
|
|
||||||
|
type (
|
||||||
|
// PaperInfo 论文信息
|
||||||
|
PaperInfo struct {
|
||||||
|
ID string `json:"id"`
|
||||||
|
TenantID string `json:"tenant_id"`
|
||||||
|
*model.TechnologyPaperInfo
|
||||||
|
Area string `json:"area"`
|
||||||
|
}
|
||||||
|
// PaperDetailInfo 论文详细信息
|
||||||
|
PaperDetailInfo struct {
|
||||||
|
ID string `json:"id"`
|
||||||
|
TenantID string `json:"tenant_id"`
|
||||||
|
*model2.TechnologyPaper
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
// Instance 首页信息
|
||||||
|
func (c *Paper) Instance(tenantID uint64, title string, page, pageSize int) (*controller.ReturnPages, error) {
|
||||||
|
mTechnologyPaper := model.NewTechnologyPaper()
|
||||||
|
|
||||||
|
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))
|
||||||
|
}
|
||||||
|
var count int64
|
||||||
|
|
||||||
|
out, err := mTechnologyPaper.Paper(page, pageSize, &count, where...)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
list := make([]*PaperInfo, 0)
|
||||||
|
|
||||||
|
for _, v := range out {
|
||||||
|
list = append(list, &PaperInfo{
|
||||||
|
ID: v.GetEncodeID(),
|
||||||
|
TenantID: v.GetEncodeTenantID(),
|
||||||
|
TechnologyPaperInfo: v,
|
||||||
|
Area: v.FormatBasic(),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
return &controller.ReturnPages{Data: list, Count: count}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Detail 详细信息
|
||||||
|
func (c *Paper) Detail(id uint64) (*PaperDetailInfo, error) {
|
||||||
|
mTechnologyPaper := model.NewTechnologyPaper()
|
||||||
|
mTechnologyPaper.ID = id
|
||||||
|
|
||||||
|
isExist, err := model2.First(mTechnologyPaper.TechnologyPaper)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
} else if !isExist {
|
||||||
|
return nil, errors.New("操作错误,论文信息不存在或已被删除")
|
||||||
|
}
|
||||||
|
return &PaperDetailInfo{
|
||||||
|
ID: mTechnologyPaper.GetEncodeID(),
|
||||||
|
TenantID: mTechnologyPaper.GetEncodeTenantID(),
|
||||||
|
TechnologyPaper: mTechnologyPaper.TechnologyPaper,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Paper) Form() error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Delete 删除操作
|
||||||
|
func (c *Paper) Delete(id uint64) error {
|
||||||
|
mTechnologyPaper := model.NewTechnologyPaper()
|
||||||
|
mTechnologyPaper.ID = id
|
||||||
|
|
||||||
|
isExist, err := model2.FirstField(mTechnologyPaper.TechnologyPaper, []string{"id", "tenant_id"})
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
} else if !isExist {
|
||||||
|
return errors.New("操作错误,论文信息不存在或已被删除")
|
||||||
|
}
|
||||||
|
if c.TenantID > 0 && mTechnologyPaper.TenantID != c.TenantID {
|
||||||
|
return errors.New("操作错误,无权限操作")
|
||||||
|
}
|
||||||
|
return model2.Delete(mTechnologyPaper.TechnologyPaper)
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewPaper() PaperHandle {
|
||||||
|
return func(session *session.Admin) *Paper {
|
||||||
|
return &Paper{session}
|
||||||
|
}
|
||||||
|
}
|
@ -57,10 +57,6 @@ type (
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
func (c *Patent) tree() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *Patent) ipcTree(src []*model2.SysPatentClassify, parentID uint64) []*PatentIPCInfo {
|
func (c *Patent) ipcTree(src []*model2.SysPatentClassify, parentID uint64) []*PatentIPCInfo {
|
||||||
out := make([]*PatentIPCInfo, 0)
|
out := make([]*PatentIPCInfo, 0)
|
||||||
|
|
||||||
|
46
app/api/admin/model/technology_paper.go
Normal file
46
app/api/admin/model/technology_paper.go
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
package model
|
||||||
|
|
||||||
|
import (
|
||||||
|
"SciencesServer/app/common/model"
|
||||||
|
"SciencesServer/serve/orm"
|
||||||
|
"fmt"
|
||||||
|
)
|
||||||
|
|
||||||
|
type TechnologyPaper struct {
|
||||||
|
*model.TechnologyPaper
|
||||||
|
}
|
||||||
|
|
||||||
|
type TechnologyPaperInfo struct {
|
||||||
|
model.Model
|
||||||
|
model.ModelTenant
|
||||||
|
Title string `json:"title"`
|
||||||
|
Author string `json:"author"`
|
||||||
|
PublishAt string `json:"publish_at"`
|
||||||
|
model.Area
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *TechnologyPaper) Paper(page, pageSize int, count *int64, where ...*model.ModelWhere) ([]*TechnologyPaperInfo, error) {
|
||||||
|
db := orm.GetDB().Table(m.TableName()+" AS p").
|
||||||
|
Select("p.id", "p.title", "p.author", "a.publish_at", "p.tenant_id", "t.province", "t.city").
|
||||||
|
Joins(fmt.Sprintf("LEFT JOIN %s AS t ON p.tanant_id = t.id", model.NewSysTenant().TableName())).
|
||||||
|
Where("p.is_deleted = ?", model.DeleteStatusForNot)
|
||||||
|
|
||||||
|
if len(where) > 0 {
|
||||||
|
for _, v := range where {
|
||||||
|
db = db.Where(v.Condition, v.Value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
out := make([]*TechnologyPaperInfo, 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 NewTechnologyPaper() *TechnologyPaper {
|
||||||
|
return &TechnologyPaper{model.NewTechnologyPaper()}
|
||||||
|
}
|
@ -94,9 +94,8 @@ func (c *SolutionCase) List(kindID uint64, page, pageSize int) (*controller.Retu
|
|||||||
|
|
||||||
var count int64
|
var count int64
|
||||||
|
|
||||||
err := model2.PagesFields(mServiceSolutionCase.ServiceSolutionCase, &out, []string{"id", "title",
|
err := model2.PagesFields(mServiceSolutionCase.ServiceSolutionCase, &out, []string{"id", "title", "image", "description"},
|
||||||
"image", "description"}, page, pageSize, &count,
|
page, pageSize, &count, &model2.ModelWhereOrder{
|
||||||
&model2.ModelWhereOrder{
|
|
||||||
Where: model2.NewWhere("kind_id", kindID),
|
Where: model2.NewWhere("kind_id", kindID),
|
||||||
Order: model2.NewOrder("sort", model2.OrderModeToDesc),
|
Order: model2.NewOrder("sort", model2.OrderModeToDesc),
|
||||||
}, &model2.ModelWhereOrder{
|
}, &model2.ModelWhereOrder{
|
||||||
|
@ -8,7 +8,7 @@ import (
|
|||||||
// TechnologyPaper 科技论文数据模型
|
// TechnologyPaper 科技论文数据模型
|
||||||
type TechnologyPaper struct {
|
type TechnologyPaper struct {
|
||||||
Model
|
Model
|
||||||
Local
|
ModelTenant
|
||||||
UID uint64 `gorm:"column:uid;type:int;default:0;comment:用户uuid" json:"-"`
|
UID uint64 `gorm:"column:uid;type:int;default:0;comment:用户uuid" json:"-"`
|
||||||
Title string `gorm:"column:title;type:varchar(100);default:'';comment:题目" json:"title"`
|
Title string `gorm:"column:title;type:varchar(100);default:'';comment:题目" json:"title"`
|
||||||
Ext string `gorm:"column:ext;type:varchar(30);default:'';comment:引用格式" json:"ext"`
|
Ext string `gorm:"column:ext;type:varchar(30);default:'';comment:引用格式" json:"ext"`
|
||||||
|
@ -316,6 +316,9 @@ func registerAdminAPI(app *gin.Engine) {
|
|||||||
technology.POST("/patent/ipc/add", _api.PatentIPCForm)
|
technology.POST("/patent/ipc/add", _api.PatentIPCForm)
|
||||||
technology.POST("/patent/ipc/edit", _api.PatentIPCForm)
|
technology.POST("/patent/ipc/edit", _api.PatentIPCForm)
|
||||||
technology.POST("/patent/ipc/delete", _api.PatentIPCDelete)
|
technology.POST("/patent/ipc/delete", _api.PatentIPCDelete)
|
||||||
|
technology.POST("/paper", _api.Paper)
|
||||||
|
technology.POST("/paper/detail", _api.PaperDetail)
|
||||||
|
technology.POST("/paper/delete", _api.PaperDelete)
|
||||||
}
|
}
|
||||||
// Activity 活动管理
|
// Activity 活动管理
|
||||||
activity := v1.Group("/activity")
|
activity := v1.Group("/activity")
|
||||||
|
Reference in New Issue
Block a user