|
...
|
...
|
@@ -12,6 +12,7 @@ import ( |
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/domainService"
|
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/utils"
|
|
|
|
"sort"
|
|
|
|
"strings"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
|
...
|
...
|
@@ -85,6 +86,10 @@ func (productGroupService *ProductGroupService) CreateProductGroup(operateInfo * |
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "有重复的生产班组")
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := productGroupService.MemberInOtherGroup(transactionContext, newProductGroup, members); err != nil {
|
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
|
}
|
|
|
|
|
|
|
|
if productGroup, err := productGroupRepository.Save(newProductGroup); err != nil {
|
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
|
} else {
|
|
...
|
...
|
@@ -95,6 +100,39 @@ func (productGroupService *ProductGroupService) CreateProductGroup(operateInfo * |
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (ProductGroupService *ProductGroupService) MemberInOtherGroup(transactionContext application.TransactionContext, group *domain.ProductGroup, members []*domain.User) error {
|
|
|
|
if len(members) == 0 {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
productGroupRepository, _, _ := factory.FastPgProductGroup(transactionContext, 0)
|
|
|
|
_, groups, err := productGroupRepository.Find(map[string]interface{}{"companyId": group.CompanyId, "orgId": group.OrgId})
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if len(groups) == 0 {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
var userInGroups = make(map[int]*domain.User)
|
|
|
|
for _, v := range groups {
|
|
|
|
if group.ProductGroupId > 0 && v.ProductGroupId == group.ProductGroupId {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
for _, w := range v.GroupMembers {
|
|
|
|
userInGroups[w.UserId] = w
|
|
|
|
}
|
|
|
|
}
|
|
|
|
var userExists = make([]string, 0)
|
|
|
|
for _, v := range members {
|
|
|
|
if u, ok := userInGroups[v.UserId]; ok {
|
|
|
|
userExists = append(userExists, u.UserName)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if len(userExists) > 0 {
|
|
|
|
return fmt.Errorf("不可配置 用户:%v ,请先从其他生产班组中移除", strings.Join(userExists, ","))
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// 返回生产班组服务
|
|
|
|
func (productGroupService *ProductGroupService) GetProductGroup(getProductGroupQuery *query.GetProductGroupQuery) (interface{}, error) {
|
|
|
|
if err := getProductGroupQuery.ValidateQuery(); err != nil {
|
|
...
|
...
|
@@ -329,6 +367,11 @@ func (productGroupService *ProductGroupService) UpdateProductGroup(cmd *command. |
|
|
|
if err := productGroup.Update(tool_funs.SimpleStructToMap(cmd)); err != nil {
|
|
|
|
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := productGroupService.MemberInOtherGroup(transactionContext, productGroup, members); err != nil {
|
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
|
}
|
|
|
|
|
|
|
|
if productGroup, err := productGroupRepository.Save(productGroup); err != nil {
|
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
|
} else {
|
...
|
...
|
|