作者 陈志颖

fix:合伙人类重复判断

@@ -45,6 +45,9 @@ func (PartnerInfoService *PartnerInfoService) CreatePartnerInfo(cmd *command.Cre @@ -45,6 +45,9 @@ func (PartnerInfoService *PartnerInfoService) CreatePartnerInfo(cmd *command.Cre
45 //检查账号是否存在 45 //检查账号是否存在
46 var ( 46 var (
47 partnerInfoDao *dao.PartnerInfoDao 47 partnerInfoDao *dao.PartnerInfoDao
  48 + partnerInfoRepository domain.PartnerInfoRepository
  49 + categoryRepository domain.PartnerCategoryRepository
  50 + categories []domain.PartnerCategory
48 ) 51 )
49 if partnerInfoDao, err = factory.CreatePartnerInfoDao(map[string]interface{}{ 52 if partnerInfoDao, err = factory.CreatePartnerInfoDao(map[string]interface{}{
50 "transactionContext": transactionContext, 53 "transactionContext": transactionContext,
@@ -60,20 +63,6 @@ func (PartnerInfoService *PartnerInfoService) CreatePartnerInfo(cmd *command.Cre @@ -60,20 +63,6 @@ func (PartnerInfoService *PartnerInfoService) CreatePartnerInfo(cmd *command.Cre
60 return nil, lib.ThrowError(lib.BUSINESS_ERROR, "账号已存在") 63 return nil, lib.ThrowError(lib.BUSINESS_ERROR, "账号已存在")
61 } 64 }
62 65
63 - // 编号去重  
64 - for _, partnerCategory := range cmd.PartnerCategory {  
65 - if ok, err := partnerInfoDao.PartnerCodeExist(partnerCategory.Id, partnerCategory.Code, cmd.CompanyId, 0); err != nil {  
66 - return nil, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())  
67 - } else if ok {  
68 - return nil, lib.ThrowError(lib.BUSINESS_ERROR, "合伙类型"+""+"编号"+partnerCategory.Code+"已存在")  
69 - }  
70 - }  
71 -  
72 - var (  
73 - partnerInfoRepository domain.PartnerInfoRepository  
74 - categoryRepository domain.PartnerCategoryRepository  
75 - categories []domain.PartnerCategory  
76 - )  
77 if partnerInfoRepository, err = factory.CreatePartnerInfoRepository(map[string]interface{}{ 66 if partnerInfoRepository, err = factory.CreatePartnerInfoRepository(map[string]interface{}{
78 "transactionContext": transactionContext, 67 "transactionContext": transactionContext,
79 }); err != nil { 68 }); err != nil {
@@ -85,6 +74,40 @@ func (PartnerInfoService *PartnerInfoService) CreatePartnerInfo(cmd *command.Cre @@ -85,6 +74,40 @@ func (PartnerInfoService *PartnerInfoService) CreatePartnerInfo(cmd *command.Cre
85 return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error()) 74 return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
86 } 75 }
87 76
  77 + // 获取合伙人类型
  78 + var categoryMap = make(map[int64]string)
  79 + _, categories, err = categoryRepository.Find(domain.PartnerCategoryFindQuery{
  80 + Ids: []int64{},
  81 + })
  82 + if err != nil {
  83 + e := fmt.Sprintf("获取合伙人分类数据失败:%s", err)
  84 + return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, e)
  85 + }
  86 + if len(categories) > 0 {
  87 + for _, category := range categories {
  88 + categoryMap[category.Id] = category.Name
  89 + }
  90 + }
  91 +
  92 + // id去重
  93 + num := make(map[int64]bool)
  94 + for _, partnerCategory := range cmd.PartnerCategory {
  95 + if !num[partnerCategory.Id] {
  96 + num[partnerCategory.Id] = true
  97 + } else {
  98 + return nil, lib.ThrowError(lib.BUSINESS_ERROR, "合伙类型不能重复")
  99 + }
  100 + }
  101 +
  102 + // 编号去重
  103 + for _, partnerCategory := range cmd.PartnerCategory {
  104 + if ok, err := partnerInfoDao.PartnerCodeExist(partnerCategory.Id, partnerCategory.Code, cmd.CompanyId, 0); err != nil {
  105 + return nil, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())
  106 + } else if ok {
  107 + return nil, lib.ThrowError(lib.BUSINESS_ERROR, categoryMap[partnerCategory.Id]+"编号"+partnerCategory.Code+"已存在")
  108 + }
  109 + }
  110 +
88 var ids []int64 111 var ids []int64
89 for _, partnerCategory := range cmd.PartnerCategory { 112 for _, partnerCategory := range cmd.PartnerCategory {
90 ids = append(ids, partnerCategory.Id) 113 ids = append(ids, partnerCategory.Id)
@@ -260,12 +283,37 @@ func (PartnerInfoService *PartnerInfoService) UpdatePartnerInfo(cmd *command.Upd @@ -260,12 +283,37 @@ func (PartnerInfoService *PartnerInfoService) UpdatePartnerInfo(cmd *command.Upd
260 return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error()) 283 return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
261 } 284 }
262 285
  286 + // 获取合伙人类型
  287 + var categoryMap = make(map[int64]string)
  288 + _, categories, err = categoryRepository.Find(domain.PartnerCategoryFindQuery{
  289 + Ids: []int64{},
  290 + })
  291 + if err != nil {
  292 + e := fmt.Sprintf("获取合伙人分类数据失败:%s", err)
  293 + return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, e)
  294 + }
  295 + if len(categories) > 0 {
  296 + for _, category := range categories {
  297 + categoryMap[category.Id] = category.Name
  298 + }
  299 + }
  300 +
  301 + // id去重
  302 + num := make(map[int64]bool)
  303 + for _, partnerCategory := range cmd.PartnerCategory {
  304 + if !num[partnerCategory.Id] {
  305 + num[partnerCategory.Id] = true
  306 + } else {
  307 + return lib.ThrowError(lib.BUSINESS_ERROR, "合伙类型不能重复")
  308 + }
  309 + }
  310 +
263 // 编号去重 311 // 编号去重
264 for _, partnerCategory := range cmd.PartnerCategory { 312 for _, partnerCategory := range cmd.PartnerCategory {
265 if ok, err := partnerInfoDao.PartnerCodeExist(partnerCategory.Id, partnerCategory.Code, cmd.CompanyId, cmd.Id); err != nil { 313 if ok, err := partnerInfoDao.PartnerCodeExist(partnerCategory.Id, partnerCategory.Code, cmd.CompanyId, cmd.Id); err != nil {
266 return lib.ThrowError(lib.TRANSACTION_ERROR, err.Error()) 314 return lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())
267 } else if ok { 315 } else if ok {
268 - return lib.ThrowError(lib.BUSINESS_ERROR, "编号"+partnerCategory.Code+"已存在") 316 + return lib.ThrowError(lib.BUSINESS_ERROR, categoryMap[partnerCategory.Id]+"编号"+partnerCategory.Code+"已存在")
269 } 317 }
270 } 318 }
271 319
@@ -216,7 +216,7 @@ func (c *PartnerInfoController) GetPartnerInfo() { @@ -216,7 +216,7 @@ func (c *PartnerInfoController) GetPartnerInfo() {
216 216
217 /** 217 /**
218 * @Author SteveChan 218 * @Author SteveChan
219 - * @Description //TODO 移除合伙人 219 + * @Description // 移除合伙人
220 * @Date 15:31 2020/12/29 220 * @Date 15:31 2020/12/29
221 * @Param 221 * @Param
222 * @return 222 * @return