feat:完善信息

This commit is contained in:
henry
2022-01-24 11:28:21 +08:00
parent 26271bfeff
commit 295ca23dcc
8 changed files with 159 additions and 15 deletions

View File

@ -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)

View File

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

View File

@ -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 删除操作

View File

@ -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()

View File

@ -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()

View 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
}

View File

@ -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 活动管理

View File

@ -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) {