作者 tangxuhui
FROM 192.168.0.243:5000/mmm/allied-creation-user:20210809
ENV APP_DIR $GOPATH/src/project-20210825
ENV APP_DIR $GOPATH/src/project-20210906
RUN mkdir -p $APP_DIR
WORKDIR $APP_DIR/
COPY ./pkg pkg
... ...
... ... @@ -65,10 +65,15 @@ func (userService *UserService) BatchAdd2(batchAddCommand *command.BatchAdd2Comm
batchAddUserService, _ := factory.CreateBatchAddUserService(map[string]interface{}{
"transactionContext": transactionContext,
})
if err = batchAddUserService.BatchAddUser2(batchAddCommand.OperateInfo, batchAddCommand.Users, batchAddCommand.Password); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
var failRows []*domain.BatchAddUserItem
if failRows, err = batchAddUserService.BatchAddUser2(batchAddCommand.OperateInfo, batchAddCommand.Users, batchAddCommand.Password); err != nil {
return batchAddCommand.Users, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if len(failRows) != 0 {
return map[string]interface{}{
"failRows": failRows,
}, nil //有错误行,回滚
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
... ... @@ -414,7 +419,7 @@ func (userService *UserService) GetUserAccessMenus(getUserAccessMenusQuery *quer
"transactionContext": transactionContext,
})
menus, err := roleAccessMenusService.AccessMenus(nil, user.UserRoleIds(), domain.AccessMenusOptions{
menus, err := roleAccessMenusService.AccessMenus(getUserAccessMenusQuery.OperateInfo, user.UserRoleIds(), domain.AccessMenusOptions{
CompanyId: user.CompanyId,
MenuCategory: getUserAccessMenusQuery.MenuCategory,
OrgId: getUserAccessMenusQuery.OrgId,
... ...
... ... @@ -5,5 +5,5 @@ import "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/domain"
// PgBatchAddUserService 批量添加用户服务
type PgBatchAddUserService interface {
BatchAddUser(optUser *domain.OperateInfo, users []*domain.User, password string) error
BatchAddUser2(optUser *domain.OperateInfo, users []*domain.BatchAddUserItem, password string) error
BatchAddUser2(optUser *domain.OperateInfo, users []*domain.BatchAddUserItem, password string) ([]*domain.BatchAddUserItem, error)
}
... ...
... ... @@ -294,21 +294,24 @@ type BatchAddUserItem struct {
// 用户类型 1:企业内部用户(内部添加) 2:共创用户 1024:企业注册用户(注册添加)
UserType int `json:"userType,omitempty"`
// 用户姓名
UserName string `json:"userName,omitempty"`
UserName string `json:"userName"`
// 手机号码
Phone string `json:"phone,omitempty"`
Phone string `json:"phone"`
// 邮箱
Email string `json:"email,omitempty"`
Email string `json:"email"`
// 用户编号 企业内标识
UserCode string `json:"userCode,omitempty"`
UserCode string `json:"userCode"`
// 组织编码
Org string `json:"org,omitempty"`
Org string `json:"org"`
// 部门编码
Department string `json:"department,omitempty"`
Department string `json:"department"`
// 状态(1:启用 2:禁用 3:注销)
EnableStatus int `json:"enableStatus,omitempty"`
// 共创公司 cooperationCompany
CooperationCompany string `json:"cooperationCompany"`
// 共创到期时间 (yyyy-MM-dd) cooperationDeadline
CooperationDeadline time.Time `json:"cooperationDeadline"`
// 失败理由
FailReason string `json:"failReason"`
}
... ...
... ... @@ -34,7 +34,7 @@ func (ptr *PgBatchAddOrgService) BatchAddOrg(optUser *domain.OperateInfo, orgLis
CompanyId: optUser.CompanyId,
OrgCode: item.OrgCode,
OrgName: item.OrgName,
IsOrg: domain.IsOrgFlag,
IsOrg: domain.IsNotOrgFlag,
ParentId: 0,
OrgStatus: domain.OrgStatusEnable,
CreatedAt: time.Now(),
... ...
... ... @@ -82,17 +82,18 @@ func (ptr *PgBatchAddUserService) BatchAddUser(optUser *domain.OperateInfo, user
return nil
}
func (ptr *PgBatchAddUserService) BatchAddUser2(optUser *domain.OperateInfo, users []*domain.BatchAddUserItem, password string) error {
func (ptr *PgBatchAddUserService) BatchAddUser2(optUser *domain.OperateInfo, users []*domain.BatchAddUserItem, password string) ([]*domain.BatchAddUserItem, error) {
var (
err error
)
var failRows = make([]*domain.BatchAddUserItem, 0)
orgRepository, err := repository.NewOrgRepository(ptr.transactionContext)
if err != nil {
return err
return failRows, err
}
_, orgs, err := orgRepository.Find(map[string]interface{}{"companyId": optUser.CompanyId, "limit": 10000})
if err != nil {
return err
return failRows, err
}
var mapOrg = make(map[string]*domain.Org)
for i := range orgs {
... ... @@ -103,15 +104,24 @@ func (ptr *PgBatchAddUserService) BatchAddUser2(optUser *domain.OperateInfo, use
for i := range users {
user := users[i]
if err = ptr.preCheck2(user); err != nil {
return err
user.FailReason = err.Error()
failRows = append(failRows, user)
continue
//return err
}
var org, dep *domain.Org
var ok bool
if org, ok = mapOrg[user.Org]; !ok {
return fmt.Errorf("导入的组织机构不存在:" + user.Org)
user.FailReason = "导入的组织机构不存在:" + user.Org
failRows = append(failRows, user)
continue
//return fmt.Errorf("导入的组织机构不存在:" + user.Org)
}
if dep, ok = mapOrg[user.Department]; !ok {
return fmt.Errorf("导入的所属部门不存在:" + user.Department)
user.FailReason = "导入的所属部门不存在:" + user.Department
failRows = append(failRows, user)
continue
//return fmt.Errorf("导入的所属部门不存在:" + user.Department)
}
newUser := &domain.User{
CompanyId: user.CompanyId,
... ... @@ -143,10 +153,13 @@ func (ptr *PgBatchAddUserService) BatchAddUser2(optUser *domain.OperateInfo, use
UpdatedAt: time.Now(),
}
if newUser, err = createUserService.CreateUser(nil, newUser, password); err != nil {
return fmt.Errorf("%v %v", user.UserName, err.Error())
user.FailReason = err.Error()
failRows = append(failRows, user)
continue
//return fmt.Errorf("%v %v", user.UserName, err.Error())
}
}
return nil
return failRows, nil
}
func (ptr *PgBatchAddUserService) preCheck(user *domain.User) error {
... ...