From 35de9164a66fd641ba9ddc58448403eea952fa58 Mon Sep 17 00:00:00 2001 From: henry Date: Thu, 17 Mar 2022 12:11:38 +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/controller/manage/agent.go | 16 +++++++++------- app/api/enterprise/api/activity.go | 2 +- app/common/migrate/instance.go | 2 +- utils/array.go | 20 +++++++++++++++++++- utils/convert.go | 4 ++++ 5 files changed, 34 insertions(+), 10 deletions(-) diff --git a/app/api/admin/controller/manage/agent.go b/app/api/admin/controller/manage/agent.go index 8e73bc5..a70973b 100644 --- a/app/api/admin/controller/manage/agent.go +++ b/app/api/admin/controller/manage/agent.go @@ -91,16 +91,18 @@ func (c *Agent) Instance(tenantID uint64, name string, status int, page, pageSiz Total int `json:"total"` Complete int `json:"complete"` }{} - // 筛选处理需求信息 - for _, val := range strings.Split(v.Demand, ";") { - objs := strings.Split(val, ":") + if v.Demand != "" { + // 筛选处理需求信息 + for _, val := range strings.Split(v.Demand, ";") { + objs := strings.Split(val, ":") - count := utils.StringToInt(objs[1]) + count := utils.StringToInt(objs[1]) - if model2.TechnologyDemandServiceStatus(utils.StringToInt(objs[0])) == model2.TechnologyDemandServiceStatusForClosedQuestions { - demand.Complete = count + if model2.TechnologyDemandServiceStatus(utils.StringToInt(objs[0])) == model2.TechnologyDemandServiceStatusForClosedQuestions { + demand.Complete = count + } + demand.Total += count } - demand.Total += count } list = append(list, &AgentInfo{ ID: v.GetEncodeID(), Name: v.Name, Mobile: v.Mobile, Industrys: industrys, diff --git a/app/api/enterprise/api/activity.go b/app/api/enterprise/api/activity.go index d188854..a389f3a 100644 --- a/app/api/enterprise/api/activity.go +++ b/app/api/enterprise/api/activity.go @@ -70,7 +70,7 @@ func (*Activity) ApplyDelete(c *gin.Context) { func (*Activity) Joins(c *gin.Context) { form := &struct { Title string `json:"title" form:"title"` - Status int `json:"status" form:"status"` // 1:未开始,2:进行中,3:已结束 + Status int `json:"status" form:"status"` api.PageForm }{} if err := api.Bind(form)(c); err != nil { diff --git a/app/common/migrate/instance.go b/app/common/migrate/instance.go index 433bf23..034ab70 100644 --- a/app/common/migrate/instance.go +++ b/app/common/migrate/instance.go @@ -139,7 +139,7 @@ func (this *Instance) Handle() { &synchronized{iModel: model.NewTechnologyProject()}, &synchronized{iModel: model.NewTechnologyTopic()}, &synchronized{iModel: model.NewTechnologyDemandService()}, &synchronized{iModel: model.NewTechnologyDemandServiceProgress()}, &synchronized{iModel: model.NewTechnologyPatent()}, &synchronized{iModel: model.NewTechnologyPatentExpert()}, &synchronized{iModel: model.NewTechnologyPatentClassify()}, - &synchronized{iModel: model.NewServiceDocking()}, + &synchronized{iModel: model.NewServiceDocking()}, &synchronized{iModel: model.NewServiceDemand()}, &synchronized{iModel: model.NewServiceMessage()}, &synchronized{iModel: model.NewServiceMessageLog()}, &synchronized{iModel: model.NewServiceSolutionCase()}, &synchronized{iModel: model.NewServiceSolutionCaseKind()}, &synchronized{iModel: model.NewServiceInnovate()}, &synchronized{iModel: model.NewServiceInnovateKind()}, diff --git a/utils/array.go b/utils/array.go index 7d7798a..ac8659c 100644 --- a/utils/array.go +++ b/utils/array.go @@ -5,16 +5,34 @@ import ( "reflect" ) +// [1,2,3, 4, 5,6,7] +// 7 +// mid: 3 func InArray(search, needle interface{}) bool { val := reflect.ValueOf(needle) kind := val.Kind() if kind == reflect.Slice || kind == reflect.Array { - for i := 0; i < val.Len(); i++ { + _length := val.Len() + + if _length <= 0 { + return false + } else if _length == 1 { + return val.Index(0).Interface() == search + } + mid := _length >> 1 + + for i := 0; i < mid; i++ { if val.Index(i).Interface() == search { return true } + if val.Index((_length-1)-i).Interface() == search { + return true + } + } + if _length%2 > 0 { + return val.Index(mid+1).Interface() == search } } return false diff --git a/utils/convert.go b/utils/convert.go index 1831c40..3bfa183 100644 --- a/utils/convert.go +++ b/utils/convert.go @@ -84,6 +84,10 @@ func StructToMap(s interface{}, m map[string]interface{}) { fieldNum := tRef.NumField() for index := 0; index < fieldNum; index++ { + if mark, isExist := tRef.Field(index).Tag.Lookup("json"); isExist { + m[mark] = vRef.FieldByName(tRef.Field(index).Name).Interface() + continue + } m[tRef.Field(index).Name] = vRef.FieldByName(tRef.Field(index).Name).Interface() } }