作者 陈志颖

feat:共创申请增加批量审核

@@ -10,6 +10,7 @@ import ( @@ -10,6 +10,7 @@ import (
10 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/application/factory" 10 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/application/factory"
11 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain" 11 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain"
12 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain/service" 12 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain/service"
  13 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/utils"
13 "strconv" 14 "strconv"
14 "time" 15 "time"
15 ) 16 )
@@ -152,6 +153,7 @@ func (cooperationApplicationService *CooperationApplicationService) ApprovalCoop @@ -152,6 +153,7 @@ func (cooperationApplicationService *CooperationApplicationService) ApprovalCoop
152 defer func() { 153 defer func() {
153 _ = transactionContext.RollbackTransaction() 154 _ = transactionContext.RollbackTransaction()
154 }() 155 }()
  156 + // 共创申请仓储初始化
155 var cooperationApplicationRepository domain.CooperationApplicationRepository 157 var cooperationApplicationRepository domain.CooperationApplicationRepository
156 if value, err := factory.CreateCooperationApplicationRepository(map[string]interface{}{ 158 if value, err := factory.CreateCooperationApplicationRepository(map[string]interface{}{
157 "transactionContext": transactionContext, 159 "transactionContext": transactionContext,
@@ -164,6 +166,7 @@ func (cooperationApplicationService *CooperationApplicationService) ApprovalCoop @@ -164,6 +166,7 @@ func (cooperationApplicationService *CooperationApplicationService) ApprovalCoop
164 if err != nil { 166 if err != nil {
165 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "共创申请ID类型错误") 167 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "共创申请ID类型错误")
166 } 168 }
  169 + // 获取共创申请
167 cooperationApplication, err := cooperationApplicationRepository.FindOne(map[string]interface{}{"cooperationApplicationId": approvalCooperationApplicationCommand.CooperationApplicationId}) 170 cooperationApplication, err := cooperationApplicationRepository.FindOne(map[string]interface{}{"cooperationApplicationId": approvalCooperationApplicationCommand.CooperationApplicationId})
168 if err != nil { 171 if err != nil {
169 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 172 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
@@ -199,10 +202,45 @@ func (cooperationApplicationService *CooperationApplicationService) BatchApprova @@ -199,10 +202,45 @@ func (cooperationApplicationService *CooperationApplicationService) BatchApprova
199 defer func() { 202 defer func() {
200 _ = transactionContext.RollbackTransaction() 203 _ = transactionContext.RollbackTransaction()
201 }() 204 }()
202 - if err := transactionContext.CommitTransaction(); err != nil {  
203 - return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 205 + // 共创申请仓储初始化
  206 + var cooperationApplicationRepository domain.CooperationApplicationRepository
  207 + if value, err := factory.CreateCooperationApplicationRepository(map[string]interface{}{
  208 + "transactionContext": transactionContext,
  209 + }); err != nil {
  210 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  211 + } else {
  212 + cooperationApplicationRepository = value
  213 + }
  214 + cooperationApplicationIds, err := utils.SliceAtoi(batchApprovalCooperationApplicationCommand.CooperationApplicationIds)
  215 + if err != nil {
  216 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "共创申请ID列表类型错误")
  217 + }
  218 + if count, cooperationApplications, err := cooperationApplicationRepository.Find(map[string]interface{}{
  219 + "cooperationApplicationIds": cooperationApplicationIds,
  220 + }); err != nil {
  221 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  222 + } else {
  223 + if count > 0 {
  224 + for i, _ := range cooperationApplications {
  225 + cooperationApplications[i].CooperationApplicationDescription = batchApprovalCooperationApplicationCommand.CooperationApplicationVerifyDescription
  226 + if batchApprovalCooperationApplicationCommand.Action == 1 { // 同意
  227 + cooperationApplications[i].CooperationApplicationStatus = 2
  228 + } else if batchApprovalCooperationApplicationCommand.Action == 2 { // 拒绝
  229 + cooperationApplications[i].CooperationApplicationStatus = 3
  230 + }
  231 + }
  232 + cooperationApplicationsApproved, err := cooperationApplicationRepository.UpdateMany(cooperationApplications)
  233 + if err != nil {
  234 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  235 + }
  236 + if err := transactionContext.CommitTransaction(); err != nil {
  237 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  238 + }
  239 + return cooperationApplicationsApproved, nil
  240 + } else {
  241 + return map[string]interface{}{}, nil
  242 + }
204 } 243 }
205 - return nil, nil  
206 } 244 }
207 245
208 // OneClickApprovalCooperationApplication 一键审核共创申请 246 // OneClickApprovalCooperationApplication 一键审核共创申请
@@ -256,8 +294,6 @@ func (cooperationApplicationService *CooperationApplicationService) CreateCooper @@ -256,8 +294,6 @@ func (cooperationApplicationService *CooperationApplicationService) CreateCooper
256 } 294 }
257 if cooperationProject == nil { 295 if cooperationProject == nil {
258 return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", createCooperationApplicationCommand.CooperationProjectNumber)) 296 return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", createCooperationApplicationCommand.CooperationProjectNumber))
259 - } else {  
260 -  
261 } 297 }
262 298
263 // 用户REST服务初始化 299 // 用户REST服务初始化
@@ -534,7 +570,7 @@ func (cooperationApplicationService *CooperationApplicationService) UpdateCooper @@ -534,7 +570,7 @@ func (cooperationApplicationService *CooperationApplicationService) UpdateCooper
534 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 570 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
535 } 571 }
536 if cooperationApplication == nil { 572 if cooperationApplication == nil {
537 - return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updateCooperationApplicationCommand.CooperationApplicationId))) 573 + return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", strconv.FormatInt(updateCooperationApplicationCommand.CooperationApplicationId, 10)))
538 } 574 }
539 if err := cooperationApplication.Update(tool_funs.SimpleStructToMap(updateCooperationApplicationCommand)); err != nil { 575 if err := cooperationApplication.Update(tool_funs.SimpleStructToMap(updateCooperationApplicationCommand)); err != nil {
540 return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error()) 576 return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
@@ -226,6 +226,9 @@ func (repository *CooperationApplicationRepository) Find(queryOptions map[string @@ -226,6 +226,9 @@ func (repository *CooperationApplicationRepository) Find(queryOptions map[string
226 if cooperationApplicationStatus, ok := queryOptions["cooperationApplicationStatus"]; ok && cooperationApplicationStatus.(int32) != 0 { 226 if cooperationApplicationStatus, ok := queryOptions["cooperationApplicationStatus"]; ok && cooperationApplicationStatus.(int32) != 0 {
227 query.Where("cooperation_application_status = ?", cooperationApplicationStatus) 227 query.Where("cooperation_application_status = ?", cooperationApplicationStatus)
228 } 228 }
  229 + if cooperationApplicationIds, ok := queryOptions["cooperationApplicationIds"]; ok && len(cooperationApplicationIds.([]int64)) > 0 {
  230 + query.Where("cooperation_application_id IN (?)", pg.In(cooperationApplicationIds))
  231 + }
229 offsetLimitFlag := true 232 offsetLimitFlag := true
230 if offsetLimit, ok := queryOptions["offsetLimit"]; ok { 233 if offsetLimit, ok := queryOptions["offsetLimit"]; ok {
231 offsetLimitFlag = offsetLimit.(bool) 234 offsetLimitFlag = offsetLimit.(bool)