作者 陈志颖

合并分支 'dev' 到 'test'

fix:合伙人类重复判断



查看合并请求 !3
... ... @@ -45,6 +45,9 @@ func (PartnerInfoService *PartnerInfoService) CreatePartnerInfo(cmd *command.Cre
//检查账号是否存在
var (
partnerInfoDao *dao.PartnerInfoDao
partnerInfoRepository domain.PartnerInfoRepository
categoryRepository domain.PartnerCategoryRepository
categories []domain.PartnerCategory
)
if partnerInfoDao, err = factory.CreatePartnerInfoDao(map[string]interface{}{
"transactionContext": transactionContext,
... ... @@ -60,20 +63,6 @@ func (PartnerInfoService *PartnerInfoService) CreatePartnerInfo(cmd *command.Cre
return nil, lib.ThrowError(lib.BUSINESS_ERROR, "账号已存在")
}
// 编号去重
for _, partnerCategory := range cmd.PartnerCategory {
if ok, err := partnerInfoDao.PartnerCodeExist(partnerCategory.Id, partnerCategory.Code, cmd.CompanyId, 0); err != nil {
return nil, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())
} else if ok {
return nil, lib.ThrowError(lib.BUSINESS_ERROR, "合伙类型"+""+"编号"+partnerCategory.Code+"已存在")
}
}
var (
partnerInfoRepository domain.PartnerInfoRepository
categoryRepository domain.PartnerCategoryRepository
categories []domain.PartnerCategory
)
if partnerInfoRepository, err = factory.CreatePartnerInfoRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
... ... @@ -85,6 +74,40 @@ func (PartnerInfoService *PartnerInfoService) CreatePartnerInfo(cmd *command.Cre
return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
}
// 获取合伙人类型
var categoryMap = make(map[int64]string)
_, categories, err = categoryRepository.Find(domain.PartnerCategoryFindQuery{
Ids: []int64{},
})
if err != nil {
e := fmt.Sprintf("获取合伙人分类数据失败:%s", err)
return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, e)
}
if len(categories) > 0 {
for _, category := range categories {
categoryMap[category.Id] = category.Name
}
}
// id去重
num := make(map[int64]bool)
for _, partnerCategory := range cmd.PartnerCategory {
if !num[partnerCategory.Id] {
num[partnerCategory.Id] = true
} else {
return nil, lib.ThrowError(lib.BUSINESS_ERROR, "合伙类型不能重复")
}
}
// 编号去重
for _, partnerCategory := range cmd.PartnerCategory {
if ok, err := partnerInfoDao.PartnerCodeExist(partnerCategory.Id, partnerCategory.Code, cmd.CompanyId, 0); err != nil {
return nil, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())
} else if ok {
return nil, lib.ThrowError(lib.BUSINESS_ERROR, categoryMap[partnerCategory.Id]+"编号"+partnerCategory.Code+"已存在")
}
}
var ids []int64
for _, partnerCategory := range cmd.PartnerCategory {
ids = append(ids, partnerCategory.Id)
... ... @@ -260,12 +283,37 @@ func (PartnerInfoService *PartnerInfoService) UpdatePartnerInfo(cmd *command.Upd
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
}
// 获取合伙人类型
var categoryMap = make(map[int64]string)
_, categories, err = categoryRepository.Find(domain.PartnerCategoryFindQuery{
Ids: []int64{},
})
if err != nil {
e := fmt.Sprintf("获取合伙人分类数据失败:%s", err)
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, e)
}
if len(categories) > 0 {
for _, category := range categories {
categoryMap[category.Id] = category.Name
}
}
// id去重
num := make(map[int64]bool)
for _, partnerCategory := range cmd.PartnerCategory {
if !num[partnerCategory.Id] {
num[partnerCategory.Id] = true
} else {
return lib.ThrowError(lib.BUSINESS_ERROR, "合伙类型不能重复")
}
}
// 编号去重
for _, partnerCategory := range cmd.PartnerCategory {
if ok, err := partnerInfoDao.PartnerCodeExist(partnerCategory.Id, partnerCategory.Code, cmd.CompanyId, cmd.Id); err != nil {
return lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())
} else if ok {
return lib.ThrowError(lib.BUSINESS_ERROR, "编号"+partnerCategory.Code+"已存在")
return lib.ThrowError(lib.BUSINESS_ERROR, categoryMap[partnerCategory.Id]+"编号"+partnerCategory.Code+"已存在")
}
}
... ...
... ... @@ -216,7 +216,7 @@ func (c *PartnerInfoController) GetPartnerInfo() {
/**
* @Author SteveChan
* @Description //TODO 移除合伙人
* @Description // 移除合伙人
* @Date 15:31 2020/12/29
* @Param
* @return
... ...