...
|
...
|
@@ -21,7 +21,13 @@ func NewPartnerInfoService(options map[string]interface{}) *PartnerInfoService { |
|
|
return newPartnerInfoService
|
|
|
}
|
|
|
|
|
|
// CreatePartnerInfo 创建合伙人
|
|
|
/**
|
|
|
* @Author SteveChan
|
|
|
* @Description //TODO 创建合伙人,判断编号是否重复
|
|
|
* @Date 15:42 2020/12/29
|
|
|
* @Param
|
|
|
* @return
|
|
|
**/
|
|
|
func (PartnerInfoService *PartnerInfoService) CreatePartnerInfo(cmd *command.CreatePartnerInfoCommand) (data *domain.PartnerInfo, err error) {
|
|
|
var (
|
|
|
transactionContext, _ = factory.CreateTransactionContext(nil)
|
...
|
...
|
@@ -35,16 +41,17 @@ func (PartnerInfoService *PartnerInfoService) CreatePartnerInfo(cmd *command.Cre |
|
|
defer func() {
|
|
|
transactionContext.RollbackTransaction()
|
|
|
}()
|
|
|
|
|
|
//检查账号是否存在
|
|
|
var (
|
|
|
partnerinfoDao *dao.PartnerInfoDao
|
|
|
partnerInfoDao *dao.PartnerInfoDao
|
|
|
)
|
|
|
if partnerinfoDao, err = factory.CreatePartnerInfoDao(map[string]interface{}{
|
|
|
if partnerInfoDao, err = factory.CreatePartnerInfoDao(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
}); err != nil {
|
|
|
return nil, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
ok, err := partnerinfoDao.PartnerAccountExist(cmd.Account, cmd.CompanyId)
|
|
|
ok, err := partnerInfoDao.PartnerAccountExist(cmd.Account, cmd.CompanyId)
|
|
|
if err != nil {
|
|
|
return nil, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
...
|
...
|
@@ -55,7 +62,7 @@ func (PartnerInfoService *PartnerInfoService) CreatePartnerInfo(cmd *command.Cre |
|
|
var (
|
|
|
partnerInfoRepository domain.PartnerInfoRepository
|
|
|
categoryRepository domain.PartnerCategoryRepository
|
|
|
categorys []domain.PartnerCategory
|
|
|
categories []domain.PartnerCategory
|
|
|
)
|
|
|
if partnerInfoRepository, err = factory.CreatePartnerInfoRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
...
|
...
|
@@ -67,13 +74,18 @@ func (PartnerInfoService *PartnerInfoService) CreatePartnerInfo(cmd *command.Cre |
|
|
}); err != nil {
|
|
|
return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
_, categorys, err = categoryRepository.Find(domain.PartnerCategoryFindQuery{
|
|
|
Ids: cmd.PartnerCategory,
|
|
|
var ids []int64
|
|
|
for _, partnerCategory := range cmd.PartnerCategory {
|
|
|
ids = append(ids, partnerCategory.Id)
|
|
|
}
|
|
|
_, categories, err = categoryRepository.Find(domain.PartnerCategoryFindQuery{
|
|
|
Ids: ids,
|
|
|
})
|
|
|
if err != nil {
|
|
|
e := fmt.Sprintf("获取合伙人分类数据失败:%s", err)
|
|
|
return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, e)
|
|
|
}
|
|
|
|
|
|
newPartnerInfo := domain.PartnerInfo{
|
|
|
Partner: domain.Partner{
|
|
|
Account: cmd.Account,
|
...
|
...
|
@@ -86,7 +98,7 @@ func (PartnerInfoService *PartnerInfoService) CreatePartnerInfo(cmd *command.Cre |
|
|
Salesman: cmd.Salesman,
|
|
|
CooperateTime: cmd.CooperateTime,
|
|
|
CompanyId: cmd.CompanyId,
|
|
|
PartnerCategoryInfos: categorys,
|
|
|
PartnerCategoryInfos: categories,
|
|
|
}
|
|
|
if err = partnerInfoRepository.Save(&newPartnerInfo); err != nil {
|
|
|
return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
|
...
|
...
|
@@ -106,7 +118,13 @@ func (PartnerInfoService *PartnerInfoService) CreatePartnerInfo(cmd *command.Cre |
|
|
return &newPartnerInfo, nil
|
|
|
}
|
|
|
|
|
|
// GetPartnerInfo 返回合伙人
|
|
|
/**
|
|
|
* @Author SteveChan
|
|
|
* @Description //TODO 返回合伙人,增加合伙人编号字段
|
|
|
* @Date 15:43 2020/12/29
|
|
|
* @Param
|
|
|
* @return
|
|
|
**/
|
|
|
func (PartnerInfoService *PartnerInfoService) GetPartnerInfo(q query.GetPartnerInfoQuery) (data *domain.PartnerInfo, err error) {
|
|
|
var (
|
|
|
transactionContext, _ = factory.CreateTransactionContext(nil)
|
...
|
...
|
@@ -123,7 +141,7 @@ func (PartnerInfoService *PartnerInfoService) GetPartnerInfo(q query.GetPartnerI |
|
|
var (
|
|
|
PartnerInfoRepository domain.PartnerInfoRepository
|
|
|
categoryRepository domain.PartnerCategoryRepository
|
|
|
categorys []domain.PartnerCategory
|
|
|
categories []domain.PartnerCategory
|
|
|
partnerData *domain.PartnerInfo
|
|
|
)
|
|
|
if PartnerInfoRepository, err = factory.CreatePartnerInfoRepository(map[string]interface{}{
|
...
|
...
|
@@ -145,19 +163,19 @@ func (PartnerInfoService *PartnerInfoService) GetPartnerInfo(q query.GetPartnerI |
|
|
}); err != nil {
|
|
|
return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
categoryIds := []int64{}
|
|
|
var categoryIds []int64
|
|
|
for _, v := range partnerData.PartnerCategoryInfos {
|
|
|
categoryIds = append(categoryIds, v.Id)
|
|
|
}
|
|
|
if len(categoryIds) > 0 {
|
|
|
_, categorys, err = categoryRepository.Find(domain.PartnerCategoryFindQuery{
|
|
|
_, categories, err = categoryRepository.Find(domain.PartnerCategoryFindQuery{
|
|
|
Ids: categoryIds,
|
|
|
})
|
|
|
if err != nil {
|
|
|
return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
}
|
|
|
partnerData.PartnerCategoryInfos = categorys
|
|
|
partnerData.PartnerCategoryInfos = categories
|
|
|
err = transactionContext.CommitTransaction()
|
|
|
return partnerData, nil
|
|
|
}
|
...
|
...
|
@@ -191,15 +209,20 @@ func (PartnerInfoService *PartnerInfoService) UpdatePartnerInfo(cmd *command.Upd |
|
|
}); err != nil {
|
|
|
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
var ids []int64
|
|
|
for _, partnerCategory := range cmd.PartnerCategory {
|
|
|
ids = append(ids, partnerCategory.Id)
|
|
|
}
|
|
|
_, categorys, err = categoryRepository.Find(domain.PartnerCategoryFindQuery{
|
|
|
Ids: cmd.PartnerCategory,
|
|
|
Ids: ids,
|
|
|
})
|
|
|
if err != nil {
|
|
|
e := fmt.Sprintf("获取合伙人分类数据失败:%s", err)
|
|
|
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, e)
|
|
|
}
|
|
|
partnerInfo, err := partnerInfoRepository.FindOne(domain.PartnerFindOneQuery{
|
|
|
UserId: cmd.Id, CompanyId: cmd.CompanyId,
|
|
|
UserId: cmd.Id,
|
|
|
CompanyId: cmd.CompanyId,
|
|
|
})
|
|
|
if err != nil {
|
|
|
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
|
...
|
...
|
@@ -246,14 +269,13 @@ func (PartnerInfoService *PartnerInfoService) ListPartnerInfo(listPartnerInfoQue |
|
|
return 0, nil, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
defer func() {
|
|
|
|
|
|
transactionContext.RollbackTransaction()
|
|
|
|
|
|
}()
|
|
|
|
|
|
var (
|
|
|
partnerInfoRepository domain.PartnerInfoRepository
|
|
|
categoryRepository domain.PartnerCategoryRepository
|
|
|
categorys []domain.PartnerCategory
|
|
|
categories []domain.PartnerCategory
|
|
|
)
|
|
|
if partnerInfoRepository, err = factory.CreatePartnerInfoRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
...
|
...
|
@@ -271,8 +293,8 @@ func (PartnerInfoService *PartnerInfoService) ListPartnerInfo(listPartnerInfoQue |
|
|
PartnerName: listPartnerInfoQuery.PartnerName,
|
|
|
CompanyId: listPartnerInfoQuery.CompanyId,
|
|
|
}
|
|
|
if listPartnerInfoQuery.Partnertype > 0 {
|
|
|
queryOption.PartnerCategory = []int{listPartnerInfoQuery.Partnertype}
|
|
|
if listPartnerInfoQuery.PartnerType > 0 {
|
|
|
queryOption.PartnerCategory = []int{listPartnerInfoQuery.PartnerType}
|
|
|
}
|
|
|
// RegionInfo
|
|
|
if len(listPartnerInfoQuery.RegionInfo) > 0 {
|
...
|
...
|
@@ -284,18 +306,18 @@ func (PartnerInfoService *PartnerInfoService) ListPartnerInfo(listPartnerInfoQue |
|
|
if count, err = partnerInfoRepository.CountAll(queryOption); err != nil {
|
|
|
return 0, nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
_, categorys, err = categoryRepository.Find(domain.PartnerCategoryFindQuery{})
|
|
|
_, categories, err = categoryRepository.Find(domain.PartnerCategoryFindQuery{})
|
|
|
if err != nil {
|
|
|
return count, partnerInfos, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
categorysMap := make(map[int64]domain.PartnerCategory)
|
|
|
for i := range categorys {
|
|
|
categorysMap[categorys[i].Id] = categorys[i]
|
|
|
categoriesMap := make(map[int64]domain.PartnerCategory)
|
|
|
for i := range categories {
|
|
|
categoriesMap[categories[i].Id] = categories[i]
|
|
|
}
|
|
|
for i := range partnerInfos {
|
|
|
categoryInPartner := []domain.PartnerCategory{}
|
|
|
var categoryInPartner []domain.PartnerCategory
|
|
|
for _, vv := range partnerInfos[i].PartnerCategoryInfos {
|
|
|
if categoryData, ok := categorysMap[vv.Id]; ok {
|
|
|
if categoryData, ok := categoriesMap[vv.Id]; ok {
|
|
|
categoryInPartner = append(categoryInPartner, categoryData)
|
|
|
}
|
|
|
}
|
...
|
...
|
@@ -307,6 +329,30 @@ func (PartnerInfoService *PartnerInfoService) ListPartnerInfo(listPartnerInfoQue |
|
|
return count, partnerInfos, nil
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* @Author SteveChan
|
|
|
* @Description //TODO 移除合伙人
|
|
|
* @Date 16:40 2020/12/29
|
|
|
* @Param
|
|
|
* @return
|
|
|
**/
|
|
|
func (PartnerInfoService *PartnerInfoService) RemovePartnerInfo(cmd command.RemovePartnerInfoCommand) (err error) {
|
|
|
var (
|
|
|
transactionContext, _ = factory.CreateTransactionContext(nil)
|
|
|
)
|
|
|
if err = cmd.ValidateCommand(); err != nil {
|
|
|
return application.ThrowError(application.ARG_ERROR, err.Error())
|
|
|
}
|
|
|
if err = transactionContext.StartTransaction(); err != nil {
|
|
|
return err
|
|
|
}
|
|
|
defer func() {
|
|
|
transactionContext.RollbackTransaction()
|
|
|
}()
|
|
|
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
func (PartnerInfoService *PartnerInfoService) UpdateStatus(cmd command.StatusPartnerInfoCommand) (err error) {
|
|
|
if len(cmd.Ids) == 0 {
|
|
|
return nil
|
...
|
...
|
@@ -324,14 +370,14 @@ func (PartnerInfoService *PartnerInfoService) UpdateStatus(cmd command.StatusPar |
|
|
transactionContext.RollbackTransaction()
|
|
|
}()
|
|
|
var (
|
|
|
partnerinfoDao *dao.PartnerInfoDao
|
|
|
partnerInfoDao *dao.PartnerInfoDao
|
|
|
)
|
|
|
if partnerinfoDao, err = factory.CreatePartnerInfoDao(map[string]interface{}{
|
|
|
if partnerInfoDao, err = factory.CreatePartnerInfoDao(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
}); err != nil {
|
|
|
return lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
err = partnerinfoDao.UpdatePartnerStatus(cmd.Ids, cmd.CompanyId, cmd.Status)
|
|
|
err = partnerInfoDao.UpdatePartnerStatus(cmd.Ids, cmd.CompanyId, cmd.Status)
|
|
|
if err != nil {
|
|
|
e := fmt.Sprintf("更新合伙人(id=%v)的数据失败;%s", cmd.Ids, err)
|
|
|
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, e)
|
...
|
...
|
|