作者 陈志颖

fix:共创项目查询条件

@@ -5,7 +5,7 @@ import "os" @@ -5,7 +5,7 @@ import "os"
5 const SERVICE_NAME = "allied-creation-cooperation" 5 const SERVICE_NAME = "allied-creation-cooperation"
6 6
7 // LOG_TYPE 日志相关设置 7 // LOG_TYPE 日志相关设置
8 -var LOG_TYPE = "terminal" // file, terminal, es 8 +var LOG_TYPE = "console" // file, console, es
9 var LOG_FRAMEWORK = "beego" // beego logrus 9 var LOG_FRAMEWORK = "beego" // beego logrus
10 var LOG_LEVEL = "debug" 10 var LOG_LEVEL = "debug"
11 var LOG_FILE = "app.log" 11 var LOG_FILE = "app.log"
@@ -3,6 +3,8 @@ package repository @@ -3,6 +3,8 @@ package repository
3 import ( 3 import (
4 "fmt" 4 "fmt"
5 "github.com/go-pg/pg/v10" 5 "github.com/go-pg/pg/v10"
  6 + "github.com/go-pg/pg/v10/orm"
  7 + query2 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/application/cooperationProject/query"
6 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/utils" 8 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/utils"
7 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/log" 9 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/log"
8 "time" 10 "time"
@@ -266,6 +268,39 @@ func (repository *CooperationProjectRepository) Find(queryOptions map[string]int @@ -266,6 +268,39 @@ func (repository *CooperationProjectRepository) Find(queryOptions map[string]int
266 if cooperationProjectUndertakerType, ok := queryOptions["cooperationProjectUndertakerType"]; ok && cooperationProjectUndertakerType.(int32) != 0 { 268 if cooperationProjectUndertakerType, ok := queryOptions["cooperationProjectUndertakerType"]; ok && cooperationProjectUndertakerType.(int32) != 0 {
267 query.Where(`cooperation_project.cooperation_project_undertaker_types @> '{?}'`, cooperationProjectUndertakerType) 269 query.Where(`cooperation_project.cooperation_project_undertaker_types @> '{?}'`, cooperationProjectUndertakerType)
268 } 270 }
  271 + if cooperationProjectUndertakerTypes, ok := queryOptions["cooperationProjectUndertakerTypes"]; ok && len(cooperationProjectUndertakerTypes.([]int32)) > 0 {
  272 + query.WhereGroup(func(q *orm.Query) (*orm.Query, error) {
  273 + for _, cooperationProjectUndertakerType := range cooperationProjectUndertakerTypes.([]int32) {
  274 + q.WhereOr(`cooperation_project.cooperation_project_undertaker_types @> '{?}'`, cooperationProjectUndertakerType)
  275 + }
  276 + return q, nil
  277 + })
  278 + }
  279 + if searchCooperationProjectExtQueries, ok := queryOptions["searchCooperationProjectExtQueries"]; ok && len(searchCooperationProjectExtQueries.([]*query2.SearchCooperationProjectExtQuery)) > 0 {
  280 + for _, searchCooperationProjectExtQuery := range searchCooperationProjectExtQueries.([]*query2.SearchCooperationProjectExtQuery) {
  281 + query.WhereOrGroup(func(q *orm.Query) (*orm.Query, error) {
  282 + if searchCooperationProjectExtQuery.ExtCompanyId != 0 {
  283 + q.Where("company->>'companyId' = '?'", searchCooperationProjectExtQuery.ExtCompanyId)
  284 + }
  285 + if searchCooperationProjectExtQuery.ExtOrgId != 0 {
  286 + q.Where("org->>'orgId' = '?'", searchCooperationProjectExtQuery.ExtOrgId)
  287 + }
  288 + if len(searchCooperationProjectExtQuery.ExtOrgIds) > 0 {
  289 + newOrgIds := utils.SliceItoa(searchCooperationProjectExtQuery.ExtOrgIds)
  290 + q.Where("org->>'orgId' in (?)", pg.In(newOrgIds))
  291 + }
  292 + if len(searchCooperationProjectExtQuery.ExtCooperationProjectUndertakerTypes) > 0 {
  293 + q.WhereGroup(func(q *orm.Query) (*orm.Query, error) {
  294 + for _, cooperationProjectUndertakerType := range searchCooperationProjectExtQuery.ExtCooperationProjectUndertakerTypes {
  295 + q.WhereOr(`cooperation_project.cooperation_project_undertaker_types @> '{?}'`, cooperationProjectUndertakerType)
  296 + }
  297 + return q, nil
  298 + })
  299 + }
  300 + return q, nil
  301 + })
  302 + }
  303 + }
269 if departmentName, ok := queryOptions["departmentName"]; ok && departmentName != "" { 304 if departmentName, ok := queryOptions["departmentName"]; ok && departmentName != "" {
270 query.Where("department->>'departmentName' like ? ", fmt.Sprintf("%%%s%%", departmentName)) 305 query.Where("department->>'departmentName' like ? ", fmt.Sprintf("%%%s%%", departmentName))
271 } 306 }