作者 陈志颖

fix:修复编辑模式时,模式名称校验问题

@@ -358,6 +358,7 @@ func (cooperationModeService *CooperationModeService) UpdateCooperationMode(upda @@ -358,6 +358,7 @@ func (cooperationModeService *CooperationModeService) UpdateCooperationMode(upda
358 } else { 358 } else {
359 cooperationModeRepository = value 359 cooperationModeRepository = value
360 } 360 }
  361 +
361 // 共创模式DAO初始化 362 // 共创模式DAO初始化
362 var cooperationModeDao *dao.CooperationModeDao 363 var cooperationModeDao *dao.CooperationModeDao
363 if value, err := factory.CreateCooperationModeDao(map[string]interface{}{ 364 if value, err := factory.CreateCooperationModeDao(map[string]interface{}{
@@ -367,23 +368,27 @@ func (cooperationModeService *CooperationModeService) UpdateCooperationMode(upda @@ -367,23 +368,27 @@ func (cooperationModeService *CooperationModeService) UpdateCooperationMode(upda
367 } else { 368 } else {
368 cooperationModeDao = value 369 cooperationModeDao = value
369 } 370 }
  371 +
  372 + cooperationMode, err := cooperationModeRepository.FindOne(map[string]interface{}{"cooperationModeId": updateCooperationModeCommand.CooperationModeId})
  373 + if err != nil {
  374 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "共创模式不存在")
  375 + }
  376 + if cooperationMode == nil {
  377 + return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", strconv.FormatInt(updateCooperationModeCommand.CooperationModeId, 10)))
  378 + }
  379 +
370 // 校验共创模式名称唯一性 380 // 校验共创模式名称唯一性
  381 + if cooperationMode.CooperationModeName != updateCooperationModeCommand.CooperationModeName {
371 nameAvailable, _ := cooperationModeDao.CheckModeNameAvailable(map[string]interface{}{ 382 nameAvailable, _ := cooperationModeDao.CheckModeNameAvailable(map[string]interface{}{
372 "companyId": updateCooperationModeCommand.CompanyId, 383 "companyId": updateCooperationModeCommand.CompanyId,
373 "orgId": updateCooperationModeCommand.OrgId, 384 "orgId": updateCooperationModeCommand.OrgId,
374 "cooperationModeName": updateCooperationModeCommand.CooperationModeName, 385 "cooperationModeName": updateCooperationModeCommand.CooperationModeName,
375 }) 386 })
376 if !nameAvailable { 387 if !nameAvailable {
377 - return nil, application.ThrowError(application.TRANSACTION_ERROR, "模式名称已存在") 388 + return nil, application.ThrowError(application.BUSINESS_ERROR, "模式名称已存在")
378 } 389 }
379 -  
380 - cooperationMode, err := cooperationModeRepository.FindOne(map[string]interface{}{"cooperationModeId": updateCooperationModeCommand.CooperationModeId})  
381 - if err != nil {  
382 - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "共创模式不存在")  
383 - }  
384 - if cooperationMode == nil {  
385 - return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", strconv.FormatInt(updateCooperationModeCommand.CooperationModeId, 10)))  
386 } 390 }
  391 +
387 if err := cooperationMode.Update(tool_funs.SimpleStructToMap(updateCooperationModeCommand)); err != nil { 392 if err := cooperationMode.Update(tool_funs.SimpleStructToMap(updateCooperationModeCommand)); err != nil {
388 return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error()) 393 return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
389 } 394 }