...
|
...
|
@@ -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+"已存在")
|
|
|
}
|
|
|
}
|
|
|
|
...
|
...
|
@@ -301,6 +349,7 @@ func (PartnerInfoService *PartnerInfoService) UpdatePartnerInfo(cmd *command.Upd |
|
|
return lib.ThrowError(lib.BUSINESS_ERROR, "异常操作")
|
|
|
}
|
|
|
|
|
|
partnerInfo.Partner.PartnerName = cmd.PartnerName
|
|
|
partnerInfo.Salesman = cmd.Salesman
|
|
|
partnerInfo.Status = cmd.Status
|
|
|
partnerInfo.RegionInfo = *cmd.RegionInfo
|
...
|
...
|
@@ -411,7 +460,7 @@ func (PartnerInfoService *PartnerInfoService) ListPartnerInfo(listPartnerInfoQue |
|
|
|
|
|
/**
|
|
|
* @Author SteveChan
|
|
|
* @Description //TODO 移除合伙人
|
|
|
* @Description // 移除合伙人
|
|
|
* @Date 16:40 2020/12/29
|
|
|
* @Param
|
|
|
* @return
|
...
|
...
|
@@ -432,6 +481,8 @@ func (PartnerInfoService *PartnerInfoService) RemovePartnerInfo(cmd command.Remo |
|
|
|
|
|
var (
|
|
|
partnerInfoRepository domain.PartnerInfoRepository
|
|
|
orderBaseRepository domain.OrderBaseRepository
|
|
|
orders []domain.OrderBase
|
|
|
)
|
|
|
|
|
|
if partnerInfoRepository, err = factory.CreatePartnerInfoRepository(map[string]interface{}{
|
...
|
...
|
@@ -440,7 +491,19 @@ func (PartnerInfoService *PartnerInfoService) RemovePartnerInfo(cmd command.Remo |
|
|
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
|
|
|
if orderBaseRepository, err = factory.CreateOrderBaseRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
}); err != nil {
|
|
|
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
|
|
|
// 判断合伙人是否有业务数据
|
|
|
orders, _, err = orderBaseRepository.Find(domain.OrderBaseFindQuery{
|
|
|
PartnerId: cmd.Id,
|
|
|
})
|
|
|
if len(orders) > 0 {
|
|
|
return lib.ThrowError(lib.BUSINESS_ERROR, "该合伙人有业务数据,不可删除!")
|
|
|
}
|
|
|
|
|
|
if err = partnerInfoRepository.Remove(cmd.Id); err != nil {
|
|
|
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
|
...
|
...
|
|