feat:完善信息
This commit is contained in:
@ -89,6 +89,17 @@ func (*Technology) PatentExamine(c *gin.Context) {
|
||||
|
||||
}
|
||||
|
||||
func (*Technology) PatentShelf(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)).Shelf(form.Convert())
|
||||
api.APIResponse(err)(c)
|
||||
}
|
||||
|
||||
func (*Technology) PatentDelete(c *gin.Context) {
|
||||
form := new(api.IDStringForm)
|
||||
|
||||
@ -209,6 +220,17 @@ func (*Technology) ProductExamine(c *gin.Context) {
|
||||
api.APIResponse(err)(c)
|
||||
}
|
||||
|
||||
func (*Technology) ProductShelf(c *gin.Context) {
|
||||
form := new(api.IDStringForm)
|
||||
|
||||
if err := api.Bind(form)(c); err != nil {
|
||||
api.APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
err := technology.NewProduct()(api.GetSession()(c).(*session.Admin)).Shelf(form.Convert())
|
||||
api.APIResponse(err)(c)
|
||||
}
|
||||
|
||||
func (*Technology) ProductDelete(c *gin.Context) {
|
||||
form := new(api.IDStringForm)
|
||||
|
||||
@ -259,6 +281,17 @@ func (*Technology) AchievementDetail(c *gin.Context) {
|
||||
api.APIResponse(err, data)(c)
|
||||
}
|
||||
|
||||
func (*Technology) AchievementShelf(c *gin.Context) {
|
||||
form := new(api.IDStringForm)
|
||||
|
||||
if err := api.Bind(form)(c); err != nil {
|
||||
api.APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
err := technology.NewAchievement()(api.GetSession()(c).(*session.Admin)).Shelf(form.Convert())
|
||||
api.APIResponse(err)(c)
|
||||
}
|
||||
|
||||
func (*Technology) AchievementDelete(c *gin.Context) {
|
||||
form := new(api.IDStringForm)
|
||||
|
||||
@ -337,6 +370,17 @@ func (*Technology) Project(c *gin.Context) {
|
||||
api.APIResponse(err, data)(c)
|
||||
}
|
||||
|
||||
func (*Technology) ProjectShelf(c *gin.Context) {
|
||||
form := new(api.IDStringForm)
|
||||
|
||||
if err := api.Bind(form)(c); err != nil {
|
||||
api.APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
err := technology.NewProject()(api.GetSession()(c).(*session.Admin)).Shelf(form.Convert())
|
||||
api.APIResponse(err)(c)
|
||||
}
|
||||
|
||||
func (*Technology) ProjectDelete(c *gin.Context) {
|
||||
form := new(api.IDStringForm)
|
||||
|
||||
|
@ -103,6 +103,11 @@ func (c *Achievement) Examine(id uint64, status int, remark string) error {
|
||||
return handleExamine(mTechnologyAchievement.TechnologyAchievement, c.UID, model2.SysUserExamineLogKindForAchievement, status, remark)
|
||||
}
|
||||
|
||||
// Shelf 上下架
|
||||
func (c *Achievement) Shelf(id uint64) error {
|
||||
return controller.NewShelf(controller.WithShelfSessionAdmin(c.Admin)).Handle(model2.NewTechnologyAchievement(), id)
|
||||
}
|
||||
|
||||
func (c *Achievement) Delete(id uint64) error {
|
||||
mTechnologyAchievement := model.NewTechnologyAchievement()
|
||||
mTechnologyAchievement.ID = id
|
||||
|
@ -230,9 +230,8 @@ func (c *Patent) Bind(id, uid uint64) error {
|
||||
})
|
||||
}
|
||||
|
||||
// Examine 审核操作
|
||||
func (c *Patent) Examine() {
|
||||
|
||||
func (c *Patent) Shelf(id uint64) error {
|
||||
return controller.NewShelf(controller.WithShelfSessionAdmin(c.Admin)).Handle(model2.NewSysPatent(), id)
|
||||
}
|
||||
|
||||
// Delete 删除操作
|
||||
|
@ -49,13 +49,12 @@ func (c *Product) Instance(tenantID uint64, title string, page, pageSize int) (*
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
list := make([]*ProductInfo, 0)
|
||||
list := make([]*ProductInfo, len(out))
|
||||
|
||||
for _, v := range out {
|
||||
list = append(list, &ProductInfo{
|
||||
ID: v.GetEncodeID(),
|
||||
Area: v.FormatBasic(),
|
||||
})
|
||||
for k, v := range out {
|
||||
list[k] = &ProductInfo{
|
||||
ID: v.GetEncodeID(), Area: v.FormatBasic(),
|
||||
}
|
||||
}
|
||||
return &controller.ReturnPages{Data: list, Count: count}, err
|
||||
}
|
||||
@ -104,6 +103,11 @@ func (c *Product) Examine(id uint64, status int, remark string) error {
|
||||
return handleExamine(mTechnologyProduct.TechnologyProduct, c.UID, model2.SysUserExamineLogKindForProduct, status, remark)
|
||||
}
|
||||
|
||||
// Shelf 上下架操作
|
||||
func (c *Product) Shelf(id uint64) error {
|
||||
return controller.NewShelf(controller.WithShelfSessionAdmin(c.Admin)).Handle(model2.NewTechnologyProduct(), id)
|
||||
}
|
||||
|
||||
// Delete 删除操作
|
||||
func (c *Product) Delete(id uint64) error {
|
||||
mTechnologyProduct := model.NewTechnologyProduct()
|
||||
|
@ -46,17 +46,23 @@ func (c *Project) Instance(tenantID uint64, title string, page, pageSize int) (*
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
list := make([]*ProjectInstance, 0)
|
||||
list := make([]*ProjectInstance, len(out))
|
||||
|
||||
for _, v := range out {
|
||||
list = append(list, &ProjectInstance{
|
||||
for k, v := range out {
|
||||
list[k] = &ProjectInstance{
|
||||
ID: v.GetEncodeID(), TenantID: v.GetEncodeTenantID(),
|
||||
TechnologyProject: v.TechnologyProject, Area: v.FormatBasic(),
|
||||
})
|
||||
}
|
||||
}
|
||||
return &controller.ReturnPages{Data: list, Count: count}, nil
|
||||
}
|
||||
|
||||
// Shelf 上下架操作
|
||||
func (c *Project) Shelf(id uint64) error {
|
||||
return controller.NewShelf(controller.WithShelfSessionAdmin(c.Admin)).
|
||||
Handle(model2.NewTechnologyProject(), id)
|
||||
}
|
||||
|
||||
// Delete 删除操作
|
||||
func (c *Project) Delete(id uint64) error {
|
||||
mTechnologyProject := model.NewTechnologyProject()
|
||||
|
77
app/basic/controller/shelf.go
Normal file
77
app/basic/controller/shelf.go
Normal file
@ -0,0 +1,77 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"SciencesServer/app/common/model"
|
||||
"SciencesServer/app/session"
|
||||
"errors"
|
||||
"time"
|
||||
)
|
||||
|
||||
type Shelf struct {
|
||||
*session.Admin
|
||||
*session.Enterprise
|
||||
}
|
||||
|
||||
type ShelfOption func(object *Shelf)
|
||||
|
||||
type IModelInfo struct {
|
||||
model.Model
|
||||
UID uint64 `json:"uid"`
|
||||
model.ModelTenant
|
||||
model.Shelf
|
||||
}
|
||||
|
||||
func WithShelfSessionAdmin(session *session.Admin) ShelfOption {
|
||||
return func(object *Shelf) {
|
||||
object.Admin = session
|
||||
}
|
||||
}
|
||||
|
||||
func WithShelfSessionEnterprise(session *session.Enterprise) ShelfOption {
|
||||
return func(object *Shelf) {
|
||||
object.Enterprise = session
|
||||
}
|
||||
}
|
||||
|
||||
func (c *Shelf) Handle(iModel model.IModel, id uint64) error {
|
||||
if c.Admin == nil && c.Enterprise == nil {
|
||||
return errors.New("操作错误,未知的人员操作")
|
||||
}
|
||||
out := new(IModelInfo)
|
||||
|
||||
err := model.ScanFields(iModel, out, []string{"id", "tenant_id", "uid", "shelf_status"},
|
||||
&model.ModelWhereOrder{Where: model.NewWhere("id", id)})
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
} else if out.ID <= 0 {
|
||||
return errors.New("操作错误,数据信息不存在或已被删除")
|
||||
}
|
||||
|
||||
if c.Admin != nil {
|
||||
if c.Admin.TenantID > 0 && c.Admin.TenantID != out.TenantID {
|
||||
return errors.New("操作错误,无权限操作")
|
||||
}
|
||||
} else {
|
||||
if c.Enterprise.UID != out.UID {
|
||||
return errors.New("操作错误,无权限操作")
|
||||
}
|
||||
}
|
||||
values := map[string]interface{}{
|
||||
"shelf_status": model.ShelfStatusForUp,
|
||||
"updated_at": time.Now(),
|
||||
}
|
||||
if out.ShelfStatus == model.ShelfStatusForUp {
|
||||
values["shelf_status"] = model.ShelfStatusForDown
|
||||
}
|
||||
return model.Updates(iModel, values)
|
||||
}
|
||||
|
||||
func NewShelf(options ...ShelfOption) *Shelf {
|
||||
out := new(Shelf)
|
||||
|
||||
for _, option := range options {
|
||||
option(out)
|
||||
}
|
||||
return out
|
||||
}
|
Reference in New Issue
Block a user