From 295ca23dcc63a857329857e365b10d59ce093498 Mon Sep 17 00:00:00 2001 From: henry Date: Mon, 24 Jan 2022 11:28:21 +0800 Subject: [PATCH] =?UTF-8?q?feat=EF=BC=9A=E5=AE=8C=E5=96=84=E4=BF=A1?= =?UTF-8?q?=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/admin/api/technology.go | 44 +++++++++++ .../controller/technology/achievement.go | 5 ++ app/api/admin/controller/technology/patent.go | 5 +- .../admin/controller/technology/product.go | 16 ++-- .../admin/controller/technology/project.go | 14 +++- app/basic/controller/shelf.go | 77 +++++++++++++++++++ router/address.go | 4 + utils/array_test.go | 9 ++- 8 files changed, 159 insertions(+), 15 deletions(-) create mode 100644 app/basic/controller/shelf.go diff --git a/app/api/admin/api/technology.go b/app/api/admin/api/technology.go index ae0559f..cd83965 100644 --- a/app/api/admin/api/technology.go +++ b/app/api/admin/api/technology.go @@ -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) diff --git a/app/api/admin/controller/technology/achievement.go b/app/api/admin/controller/technology/achievement.go index e217f45..f2a7311 100644 --- a/app/api/admin/controller/technology/achievement.go +++ b/app/api/admin/controller/technology/achievement.go @@ -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 diff --git a/app/api/admin/controller/technology/patent.go b/app/api/admin/controller/technology/patent.go index 9519e12..a1c3df7 100644 --- a/app/api/admin/controller/technology/patent.go +++ b/app/api/admin/controller/technology/patent.go @@ -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 删除操作 diff --git a/app/api/admin/controller/technology/product.go b/app/api/admin/controller/technology/product.go index c523212..0f5086b 100644 --- a/app/api/admin/controller/technology/product.go +++ b/app/api/admin/controller/technology/product.go @@ -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() diff --git a/app/api/admin/controller/technology/project.go b/app/api/admin/controller/technology/project.go index 9c6d862..7bec80e 100644 --- a/app/api/admin/controller/technology/project.go +++ b/app/api/admin/controller/technology/project.go @@ -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() diff --git a/app/basic/controller/shelf.go b/app/basic/controller/shelf.go new file mode 100644 index 0000000..2979f62 --- /dev/null +++ b/app/basic/controller/shelf.go @@ -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 +} diff --git a/router/address.go b/router/address.go index 1fb1b2c..cf41218 100644 --- a/router/address.go +++ b/router/address.go @@ -354,6 +354,7 @@ func registerAdminAPI(app *gin.Engine) { technology.POST("/patent/add", _api.PatentForm) technology.POST("/patent/edit", _api.PatentForm) technology.POST("/patent/bind", _api.PatentBind) + technology.POST("/patent/shelf", _api.PatentShelf) technology.POST("/patent/delete", _api.PatentDelete) technology.GET("/patent/ipc", _api.PatentIPC) technology.POST("/patent/ipc/add", _api.PatentIPCForm) @@ -365,16 +366,19 @@ func registerAdminAPI(app *gin.Engine) { technology.POST("/product", _api.Product) technology.POST("/product/examine", _api.ProductExamine) technology.POST("/product/detail", _api.ProductDetail) + technology.POST("/product/shelf", _api.ProductShelf) technology.POST("/product/delete", _api.ProductDelete) technology.POST("/achievement", _api.Achievement) technology.POST("/achievement/examine", _api.AchievementExamine) technology.POST("/achievement/detail", _api.AchievementDetail) + technology.POST("/achievement/shelf", _api.AchievementShelf) technology.POST("/achievement/delete", _api.AchievementDelete) technology.POST("/demand", _api.Demand) technology.POST("/demand/examine", _api.DemandExamine) technology.POST("/demand/detail", _api.DemandDetail) technology.POST("/demand/delete", _api.DemandDelete) technology.POST("/project", _api.Project) + technology.POST("/project/shelf", _api.ProjectShelf) technology.POST("/project/delete", _api.ProjectDelete) } // Activity 活动管理 diff --git a/utils/array_test.go b/utils/array_test.go index 08c26c6..844268c 100644 --- a/utils/array_test.go +++ b/utils/array_test.go @@ -16,9 +16,14 @@ func TestArrayFlip(t *testing.T) { //out := ArrayFlip(flip) //t.Logf("out:%v\n", out) - d := a & b & c - t.Log(d) + //d := a & b & c + //t.Log(d) + a := make([]int, 5) + t.Log(a) + t.Log(a[4]) + a = append(a, []int{1, 2, 3, 4, 5, 6, 7, 8, 9}...) + t.Log(a) } func TestArrayStrings(t *testing.T) {