作者 陈志颖

refactor:优化共创项目详情查询条件

@@ -10,7 +10,9 @@ import ( @@ -10,7 +10,9 @@ import (
10 10
11 type GetCooperationProjectQuery struct { 11 type GetCooperationProjectQuery struct {
12 // 共创项目ID 12 // 共创项目ID
13 - CooperationProjectId int64 `cname:"共创项目ID" json:"cooperationProjectId" valid:"Required"` 13 + CooperationProjectId int64 `cname:"共创项目ID" json:"cooperationProjectId"`
  14 + // 共创项目编号
  15 + CooperationProjectNumber string `cname:"共创项目编号" json:"cooperationProjectNumber"`
14 // 公司ID,通过集成REST上下文获取 16 // 公司ID,通过集成REST上下文获取
15 CompanyId int64 `cname:"公司ID" json:"companyId" valid:"Required"` 17 CompanyId int64 `cname:"公司ID" json:"companyId" valid:"Required"`
16 // 组织机构ID 18 // 组织机构ID
@@ -22,7 +24,9 @@ type GetCooperationProjectQuery struct { @@ -22,7 +24,9 @@ type GetCooperationProjectQuery struct {
22 } 24 }
23 25
24 func (getCooperationProjectQuery *GetCooperationProjectQuery) Valid(validation *validation.Validation) { 26 func (getCooperationProjectQuery *GetCooperationProjectQuery) Valid(validation *validation.Validation) {
25 - //validation.SetError("CustomValid", "未实现的自定义认证") 27 + if getCooperationProjectQuery.CooperationProjectId == 0 && getCooperationProjectQuery.CooperationProjectNumber == "" {
  28 + validation.Error("共创项目ID和共创项目编号不能同时为空")
  29 + }
26 } 30 }
27 31
28 func (getCooperationProjectQuery *GetCooperationProjectQuery) ValidateQuery() error { 32 func (getCooperationProjectQuery *GetCooperationProjectQuery) ValidateQuery() error {
@@ -222,7 +222,7 @@ func (cooperationProjectService *CooperationProjectService) GetCooperationProjec @@ -222,7 +222,7 @@ func (cooperationProjectService *CooperationProjectService) GetCooperationProjec
222 } else { 222 } else {
223 cooperationProjectRepository = value 223 cooperationProjectRepository = value
224 } 224 }
225 - cooperationProject, err := cooperationProjectRepository.FindOne(map[string]interface{}{"cooperationProjectId": getCooperationProjectQuery.CooperationProjectId}) 225 + cooperationProject, err := cooperationProjectRepository.FindOne(tool_funs.SimpleStructToMap(getCooperationProjectQuery))
226 if err != nil { 226 if err != nil {
227 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 227 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
228 } 228 }
@@ -50,12 +50,6 @@ func (dao *CooperationProjectDao) CheckUndertakerTypesUncheckedAvailable(queryOp @@ -50,12 +50,6 @@ func (dao *CooperationProjectDao) CheckUndertakerTypesUncheckedAvailable(queryOp
50 if orgId, ok := queryOptions["orgId"]; ok && orgId.(int64) != 0 { 50 if orgId, ok := queryOptions["orgId"]; ok && orgId.(int64) != 0 {
51 query = query.Where(`cooperation_contract.org @> '{"orgId":"?"}'`, orgId) 51 query = query.Where(`cooperation_contract.org @> '{"orgId":"?"}'`, orgId)
52 } 52 }
53 - if user, ok := queryOptions["user"]; ok && user.(bool) != false {  
54 - query = query.Where("user_type = ?", 1)  
55 - }  
56 - if partner, ok := queryOptions["partner"]; ok && partner.(bool) != false {  
57 - query = query.Where("user_type = ?", 2)  
58 - }  
59 if count, err := query.SelectAndCount(); err != nil { 53 if count, err := query.SelectAndCount(); err != nil {
60 return false, err 54 return false, err
61 } else { 55 } else {
@@ -65,6 +59,12 @@ func (dao *CooperationProjectDao) CheckUndertakerTypesUncheckedAvailable(queryOp @@ -65,6 +59,12 @@ func (dao *CooperationProjectDao) CheckUndertakerTypesUncheckedAvailable(queryOp
65 var cooperationContractUndertakerModels []*models.CooperationContractUndertaker 59 var cooperationContractUndertakerModels []*models.CooperationContractUndertaker
66 queryUndertaker := tx.Model(&cooperationContractUndertakerModels) 60 queryUndertaker := tx.Model(&cooperationContractUndertakerModels)
67 queryUndertaker.Where("cooperation_contract_number = ?", cooperationContractModel.CooperationContractNumber) 61 queryUndertaker.Where("cooperation_contract_number = ?", cooperationContractModel.CooperationContractNumber)
  62 + if user, ok := queryOptions["user"]; ok && user.(bool) != false {
  63 + query = query.Where("user_type = ?", 1)
  64 + }
  65 + if partner, ok := queryOptions["partner"]; ok && partner.(bool) != false {
  66 + query = query.Where("user_type = ?", 2)
  67 + }
68 ok, err2 := queryUndertaker.Exists() 68 ok, err2 := queryUndertaker.Exists()
69 return !ok, err2 69 return !ok, err2
70 } 70 }
@@ -204,9 +204,11 @@ func (repository *CooperationProjectRepository) FindOne(queryOptions map[string] @@ -204,9 +204,11 @@ func (repository *CooperationProjectRepository) FindOne(queryOptions map[string]
204 cooperationProjectModel := new(models.CooperationProject) 204 cooperationProjectModel := new(models.CooperationProject)
205 query := sqlbuilder.BuildQuery(tx.Model(cooperationProjectModel), queryOptions) 205 query := sqlbuilder.BuildQuery(tx.Model(cooperationProjectModel), queryOptions)
206 if cooperationProjectNumber, ok := queryOptions["cooperationProjectNumber"]; ok && cooperationProjectNumber != "" { 206 if cooperationProjectNumber, ok := queryOptions["cooperationProjectNumber"]; ok && cooperationProjectNumber != "" {
207 - query.Where("cooperation_project_number = ?", cooperationProjectNumber) 207 + query.Where("cooperation_project.cooperation_project_number = ?", cooperationProjectNumber)
  208 + }
  209 + if cooperationProjectId, ok := queryOptions["cooperationProjectId"]; ok && cooperationProjectId.(int64) != 0 {
  210 + query.Where("cooperation_project.cooperation_project_id = ?", cooperationProjectId)
208 } 211 }
209 - query.SetWhereByQueryOption("cooperation_project.cooperation_project_id = ?", "cooperationProjectId")  
210 if err := query.First(); err != nil { 212 if err := query.First(); err != nil {
211 if err.Error() == "pg: no rows in result set" { 213 if err.Error() == "pg: no rows in result set" {
212 return nil, fmt.Errorf("没有此资源") 214 return nil, fmt.Errorf("没有此资源")
@@ -61,6 +61,8 @@ func (controller *CooperationProjectController) GetCooperationProject() { @@ -61,6 +61,8 @@ func (controller *CooperationProjectController) GetCooperationProject() {
61 getCooperationProjectQuery.UserBaseId = header.UserBaseId 61 getCooperationProjectQuery.UserBaseId = header.UserBaseId
62 cooperationProjectId, _ := controller.GetInt64(":cooperationProjectId") 62 cooperationProjectId, _ := controller.GetInt64(":cooperationProjectId")
63 getCooperationProjectQuery.CooperationProjectId = cooperationProjectId 63 getCooperationProjectQuery.CooperationProjectId = cooperationProjectId
  64 + cooperationProjectNumber := controller.GetString("cooperationProjectNumber")
  65 + getCooperationProjectQuery.CooperationProjectNumber = cooperationProjectNumber
64 data, err := cooperationProjectService.GetCooperationProject(getCooperationProjectQuery) 66 data, err := cooperationProjectService.GetCooperationProject(getCooperationProjectQuery)
65 controller.Response(data, err) 67 controller.Response(data, err)
66 } 68 }