作者 唐旭辉

Merge branch 'dev' of http://gitlab.fjmaimaimai.com/mmm-go/partnermg into dev

... ... @@ -10,6 +10,8 @@ import (
type UpdatePartnerInfoCommand struct {
// 合伙人Id
Id int64 `json:"id"`
// 合伙人姓名
PartnerName string `json:"partnerName"`
// 状态(1:启用或者0:禁用)
Status int `json:"status"`
// 合伙类别 (1.研发合伙人 2.业务合伙人 3.事业)
... ... @@ -33,7 +35,6 @@ func (command *UpdatePartnerInfoCommand) ValidateCommand() error {
if command.RegionInfo == nil {
return lib.ThrowError(lib.ARG_ERROR, "区域必填")
}
if command.Id == 0 {
return lib.ThrowError(lib.ARG_ERROR, "合伙人id错误")
}
... ...
... ... @@ -44,7 +44,10 @@ func (PartnerInfoService *PartnerInfoService) CreatePartnerInfo(cmd *command.Cre
//检查账号是否存在
var (
partnerInfoDao *dao.PartnerInfoDao
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())
... ...
... ... @@ -106,6 +106,7 @@ func (c *PartnerInfoController) UpdatePartnerInfo() {
//用与适配前端定义的数据结构
type Parameter struct {
ID int64 `json:"id"`
PartnerName string `json:"partnerName"`
PartnerType []*domain.PartnerCategory `json:"partnerType"`
Area string `json:"area"`
State int `json:"state"`
... ... @@ -132,6 +133,7 @@ func (c *PartnerInfoController) UpdatePartnerInfo() {
companyId := c.GetUserCompany()
cmd := partnerInfoCmd.UpdatePartnerInfoCommand{
Id: param.ID,
PartnerName: param.PartnerName,
Status: param.State,
PartnerCategory: param.PartnerType,
CooperateTime: cooperateTime,
... ... @@ -216,7 +218,7 @@ func (c *PartnerInfoController) GetPartnerInfo() {
/**
* @Author SteveChan
* @Description //TODO 移除合伙人
* @Description // 移除合伙人
* @Date 15:31 2020/12/29
* @Param
* @return
... ... @@ -357,6 +359,9 @@ func (c *PartnerInfoController) ListPartnerInfo() {
}
resp = append(resp, m)
}
if len(resp) == 0 {
resp = []map[string]interface{}{}
}
c.ResponsePageList(resp, count, param.PageNumber)
return
}
... ...
此 diff 太大无法显示。