...
|
...
|
@@ -82,6 +82,73 @@ func (ptr *PgBatchAddUserService) BatchAddUser(optUser *domain.OperateInfo, user |
|
|
return nil
|
|
|
}
|
|
|
|
|
|
func (ptr *PgBatchAddUserService) BatchAddUser2(optUser *domain.OperateInfo, users []*domain.BatchAddUserItem, password string) error {
|
|
|
var (
|
|
|
err error
|
|
|
)
|
|
|
orgRepository, err := repository.NewOrgRepository(ptr.transactionContext)
|
|
|
if err != nil {
|
|
|
return err
|
|
|
}
|
|
|
_, orgs, err := orgRepository.Find(map[string]interface{}{"companyId": optUser.CompanyId})
|
|
|
if err != nil {
|
|
|
return err
|
|
|
}
|
|
|
var mapOrg = make(map[string]*domain.Org)
|
|
|
for i := range orgs {
|
|
|
mapOrg[orgs[i].OrgCode] = orgs[i]
|
|
|
}
|
|
|
|
|
|
createUserService, _ := NewPgCreateUserService(ptr.transactionContext)
|
|
|
for i := range users {
|
|
|
user := users[i]
|
|
|
if err = ptr.preCheck2(user); err != nil {
|
|
|
return err
|
|
|
}
|
|
|
var org, dep *domain.Org
|
|
|
var ok bool
|
|
|
if org, ok = mapOrg[user.Org]; !ok {
|
|
|
return fmt.Errorf("导入的组织机构不存在:" + user.Org)
|
|
|
}
|
|
|
if dep, ok = mapOrg[user.Department]; !ok {
|
|
|
return fmt.Errorf("导入的所属部门不存在:" + user.Department)
|
|
|
}
|
|
|
newUser := &domain.User{
|
|
|
CompanyId: user.CompanyId,
|
|
|
UserType: user.UserType,
|
|
|
UserCode: user.UserCode,
|
|
|
OrganizationId: org.OrgId,
|
|
|
DepartmentId: dep.OrgId,
|
|
|
UserOrg: []*domain.Org{},
|
|
|
UserRole: []*domain.Role{},
|
|
|
FavoriteMenus: []string{},
|
|
|
CooperationInfo: &domain.CooperationInfo{
|
|
|
CooperationCompany: user.CooperationCompany,
|
|
|
CooperationDeadline: user.CooperationDeadline,
|
|
|
},
|
|
|
UserInfo: &domain.UserInfo{
|
|
|
UserName: user.UserName,
|
|
|
Phone: user.Phone,
|
|
|
Avatar: "",
|
|
|
Email: user.Email,
|
|
|
},
|
|
|
EnableStatus: int(domain.UserStatusEnable),
|
|
|
Ext: &domain.Ext{
|
|
|
Phone: user.Phone,
|
|
|
UserName: user.UserName,
|
|
|
OrgName: org.OrgName,
|
|
|
DepName: dep.OrgName,
|
|
|
},
|
|
|
CreatedAt: time.Now(),
|
|
|
UpdatedAt: time.Now(),
|
|
|
}
|
|
|
if newUser, err = createUserService.CreateUser(nil, newUser, password); err != nil {
|
|
|
return err
|
|
|
}
|
|
|
}
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
func (ptr *PgBatchAddUserService) preCheck(user *domain.User) error {
|
|
|
if len(user.UserInfo.UserName) == 0 {
|
|
|
return fmt.Errorf("导入的用户姓名为空值")
|
...
|
...
|
@@ -98,6 +165,22 @@ func (ptr *PgBatchAddUserService) preCheck(user *domain.User) error { |
|
|
return nil
|
|
|
}
|
|
|
|
|
|
func (ptr *PgBatchAddUserService) preCheck2(user *domain.BatchAddUserItem) error {
|
|
|
if len(user.UserName) == 0 {
|
|
|
return fmt.Errorf("导入的用户姓名为空值")
|
|
|
}
|
|
|
if len(user.Phone) == 0 {
|
|
|
return fmt.Errorf("导入的手机号不是有效手机号")
|
|
|
}
|
|
|
//if len(user.Org) == 0 {
|
|
|
// return fmt.Errorf("导入的组织机构不存在")
|
|
|
//}
|
|
|
//if len(user.Department) == 0 && user.UserType == domain.UserTypeEmployee {
|
|
|
// return fmt.Errorf("导入的所属部门不存在")
|
|
|
//}
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
func NewPgBatchAddUserService(transactionContext *pgTransaction.TransactionContext) (*PgBatchAddUserService, error) {
|
|
|
if transactionContext == nil {
|
|
|
return nil, fmt.Errorf("transactionContext参数不能为nil")
|
...
|
...
|
|