...
|
...
|
@@ -23,7 +23,7 @@ func NewPartnerInfoService(options map[string]interface{}) *PartnerInfoService { |
|
|
|
|
|
/**
|
|
|
* @Author SteveChan
|
|
|
* @Description //TODO 创建合伙人,判断编号是否重复
|
|
|
* @Description // 创建合伙人
|
|
|
* @Date 15:42 2020/12/29
|
|
|
* @Param
|
|
|
* @return
|
...
|
...
|
@@ -51,6 +51,7 @@ func (PartnerInfoService *PartnerInfoService) CreatePartnerInfo(cmd *command.Cre |
|
|
}); err != nil {
|
|
|
return nil, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
|
|
|
ok, err := partnerInfoDao.PartnerAccountExist(cmd.Account, cmd.CompanyId)
|
|
|
if err != nil {
|
|
|
return nil, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())
|
...
|
...
|
@@ -59,6 +60,15 @@ 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
|
...
|
...
|
@@ -74,6 +84,7 @@ func (PartnerInfoService *PartnerInfoService) CreatePartnerInfo(cmd *command.Cre |
|
|
}); err != nil {
|
|
|
return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
|
|
|
var ids []int64
|
|
|
for _, partnerCategory := range cmd.PartnerCategory {
|
|
|
ids = append(ids, partnerCategory.Id)
|
...
|
...
|
@@ -85,6 +96,13 @@ func (PartnerInfoService *PartnerInfoService) CreatePartnerInfo(cmd *command.Cre |
|
|
e := fmt.Sprintf("获取合伙人分类数据失败:%s", err)
|
|
|
return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, e)
|
|
|
}
|
|
|
for i, category := range categories {
|
|
|
for _, partnerCategory := range cmd.PartnerCategory {
|
|
|
if category.Id == partnerCategory.Id {
|
|
|
categories[i].Code = partnerCategory.Code
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
newPartnerInfo := domain.PartnerInfo{
|
|
|
Partner: domain.Partner{
|
...
|
...
|
@@ -99,6 +117,7 @@ func (PartnerInfoService *PartnerInfoService) CreatePartnerInfo(cmd *command.Cre |
|
|
CooperateTime: cmd.CooperateTime,
|
|
|
CompanyId: cmd.CompanyId,
|
|
|
PartnerCategoryInfos: categories,
|
|
|
Remark: cmd.Remark,
|
|
|
}
|
|
|
if err = partnerInfoRepository.Save(&newPartnerInfo); err != nil {
|
|
|
return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
|
...
|
...
|
@@ -120,7 +139,7 @@ func (PartnerInfoService *PartnerInfoService) CreatePartnerInfo(cmd *command.Cre |
|
|
|
|
|
/**
|
|
|
* @Author SteveChan
|
|
|
* @Description //TODO 返回合伙人,增加合伙人编号字段
|
|
|
* @Description // 返回合伙人,增加合伙人编号字段
|
|
|
* @Date 15:43 2020/12/29
|
|
|
* @Param
|
|
|
* @return
|
...
|
...
|
@@ -129,6 +148,7 @@ func (PartnerInfoService *PartnerInfoService) GetPartnerInfo(q query.GetPartnerI |
|
|
var (
|
|
|
transactionContext, _ = factory.CreateTransactionContext(nil)
|
|
|
)
|
|
|
|
|
|
if err = q.ValidateQuery(); err != nil {
|
|
|
return nil, lib.ThrowError(lib.ARG_ERROR, err.Error())
|
|
|
}
|
...
|
...
|
@@ -138,17 +158,21 @@ func (PartnerInfoService *PartnerInfoService) GetPartnerInfo(q query.GetPartnerI |
|
|
defer func() {
|
|
|
transactionContext.RollbackTransaction()
|
|
|
}()
|
|
|
|
|
|
var (
|
|
|
PartnerInfoRepository domain.PartnerInfoRepository
|
|
|
categoryRepository domain.PartnerCategoryRepository
|
|
|
categories []domain.PartnerCategory
|
|
|
partnerData *domain.PartnerInfo
|
|
|
)
|
|
|
|
|
|
if PartnerInfoRepository, err = factory.CreatePartnerInfoRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
}); err != nil {
|
|
|
return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
|
|
|
// 获取合伙人数据
|
|
|
partnerData, err = PartnerInfoRepository.FindOne(domain.PartnerFindOneQuery{
|
|
|
UserId: q.Id, CompanyId: q.CompanyId,
|
|
|
})
|
...
|
...
|
@@ -158,6 +182,8 @@ func (PartnerInfoService *PartnerInfoService) GetPartnerInfo(q query.GetPartnerI |
|
|
if !partnerData.IsCompany(q.CompanyId) {
|
|
|
return nil, lib.ThrowError(lib.BUSINESS_ERROR, "企业信息异常操作")
|
|
|
}
|
|
|
|
|
|
// 获取合伙人类别
|
|
|
if categoryRepository, err = factory.CreatePartnerCategoryRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
}); err != nil {
|
...
|
...
|
@@ -174,17 +200,31 @@ func (PartnerInfoService *PartnerInfoService) GetPartnerInfo(q query.GetPartnerI |
|
|
if err != nil {
|
|
|
return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
for i, category := range categories {
|
|
|
for _, partnerCategory := range partnerData.PartnerCategoryInfos {
|
|
|
if category.Id == partnerCategory.Id {
|
|
|
categories[i].Code = partnerCategory.Code
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
partnerData.PartnerCategoryInfos = categories
|
|
|
err = transactionContext.CommitTransaction()
|
|
|
return partnerData, nil
|
|
|
}
|
|
|
|
|
|
//UpdatePartnerInfo 更新合伙人
|
|
|
/**
|
|
|
* @Author SteveChan
|
|
|
* @Description // 更新合伙人
|
|
|
* @Date 00:07 2020/12/30
|
|
|
* @Param
|
|
|
* @return
|
|
|
**/
|
|
|
func (PartnerInfoService *PartnerInfoService) UpdatePartnerInfo(cmd *command.UpdatePartnerInfoCommand) (err error) {
|
|
|
var (
|
|
|
transactionContext, _ = factory.CreateTransactionContext(nil)
|
|
|
)
|
|
|
|
|
|
if err = cmd.ValidateCommand(); err != nil {
|
|
|
return application.ThrowError(application.ARG_ERROR, err.Error())
|
|
|
}
|
...
|
...
|
@@ -194,32 +234,62 @@ func (PartnerInfoService *PartnerInfoService) UpdatePartnerInfo(cmd *command.Upd |
|
|
defer func() {
|
|
|
transactionContext.RollbackTransaction()
|
|
|
}()
|
|
|
|
|
|
var (
|
|
|
partnerInfoRepository domain.PartnerInfoRepository
|
|
|
categoryRepository domain.PartnerCategoryRepository
|
|
|
categorys []domain.PartnerCategory
|
|
|
categories []domain.PartnerCategory
|
|
|
partnerInfoDao *dao.PartnerInfoDao
|
|
|
)
|
|
|
|
|
|
if partnerInfoDao, err = factory.CreatePartnerInfoDao(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
}); err != nil {
|
|
|
return lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
|
|
|
if partnerInfoRepository, err = factory.CreatePartnerInfoRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
}); err != nil {
|
|
|
return lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
|
|
|
if categoryRepository, err = factory.CreatePartnerCategoryRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
}); err != nil {
|
|
|
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.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+"已存在")
|
|
|
}
|
|
|
}
|
|
|
|
|
|
var ids []int64
|
|
|
for _, partnerCategory := range cmd.PartnerCategory {
|
|
|
ids = append(ids, partnerCategory.Id)
|
|
|
}
|
|
|
_, categorys, err = categoryRepository.Find(domain.PartnerCategoryFindQuery{
|
|
|
|
|
|
_, categories, err = categoryRepository.Find(domain.PartnerCategoryFindQuery{
|
|
|
Ids: ids,
|
|
|
})
|
|
|
if err != nil {
|
|
|
e := fmt.Sprintf("获取合伙人分类数据失败:%s", err)
|
|
|
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, e)
|
|
|
}
|
|
|
|
|
|
for i, category := range categories {
|
|
|
for _, partnerCategory := range cmd.PartnerCategory {
|
|
|
if category.Id == partnerCategory.Id {
|
|
|
categories[i].Code = partnerCategory.Code
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
partnerInfo, err := partnerInfoRepository.FindOne(domain.PartnerFindOneQuery{
|
|
|
UserId: cmd.Id,
|
|
|
CompanyId: cmd.CompanyId,
|
...
|
...
|
@@ -230,11 +300,14 @@ func (PartnerInfoService *PartnerInfoService) UpdatePartnerInfo(cmd *command.Upd |
|
|
if !partnerInfo.IsCompany(cmd.CompanyId) {
|
|
|
return lib.ThrowError(lib.BUSINESS_ERROR, "异常操作")
|
|
|
}
|
|
|
|
|
|
partnerInfo.Salesman = cmd.Salesman
|
|
|
partnerInfo.Status = cmd.Status
|
|
|
partnerInfo.RegionInfo = *cmd.RegionInfo
|
|
|
partnerInfo.CooperateTime = cmd.CooperateTime
|
|
|
partnerInfo.PartnerCategoryInfos = categorys
|
|
|
partnerInfo.PartnerCategoryInfos = categories
|
|
|
partnerInfo.Remark = cmd.Remark
|
|
|
|
|
|
if err = partnerInfoRepository.Save(partnerInfo); err != nil {
|
|
|
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
...
|
...
|
@@ -254,7 +327,13 @@ func (PartnerInfoService *PartnerInfoService) UpdatePartnerInfo(cmd *command.Upd |
|
|
return
|
|
|
}
|
|
|
|
|
|
// ListPartnerInfo 合伙人列表
|
|
|
/**
|
|
|
* @Author SteveChan
|
|
|
* @Description //合伙人列表,返回合伙人编号
|
|
|
* @Date 00:07 2020/12/30
|
|
|
* @Param
|
|
|
* @return
|
|
|
**/
|
|
|
func (PartnerInfoService *PartnerInfoService) ListPartnerInfo(listPartnerInfoQuery *query.ListPartnerInfoQuery) (int, []domain.PartnerInfo, error) {
|
|
|
var (
|
|
|
transactionContext, _ = factory.CreateTransactionContext(nil)
|
...
|
...
|
@@ -318,6 +397,7 @@ func (PartnerInfoService *PartnerInfoService) ListPartnerInfo(listPartnerInfoQue |
|
|
var categoryInPartner []domain.PartnerCategory
|
|
|
for _, vv := range partnerInfos[i].PartnerCategoryInfos {
|
|
|
if categoryData, ok := categoriesMap[vv.Id]; ok {
|
|
|
categoryData.Code = vv.Code
|
|
|
categoryInPartner = append(categoryInPartner, categoryData)
|
|
|
}
|
|
|
}
|
...
|
...
|
@@ -350,6 +430,23 @@ func (PartnerInfoService *PartnerInfoService) RemovePartnerInfo(cmd command.Remo |
|
|
transactionContext.RollbackTransaction()
|
|
|
}()
|
|
|
|
|
|
var (
|
|
|
partnerInfoRepository domain.PartnerInfoRepository
|
|
|
)
|
|
|
|
|
|
if partnerInfoRepository, err = factory.CreatePartnerInfoRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
}); err != nil {
|
|
|
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
|
|
|
// 判断合伙人是否有业务数据
|
|
|
|
|
|
if err = partnerInfoRepository.Remove(cmd.Id); err != nil {
|
|
|
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
|
|
|
transactionContext.CommitTransaction()
|
|
|
return nil
|
|
|
}
|
|
|
|
...
|
...
|
|