正在显示
19 个修改的文件
包含
378 行增加
和
4 行删除
| @@ -99,6 +99,8 @@ spec: | @@ -99,6 +99,8 @@ spec: | ||
| 99 | value: "true" | 99 | value: "true" |
| 100 | - name: HTTP_PORT | 100 | - name: HTTP_PORT |
| 101 | value: "8082" | 101 | value: "8082" |
| 102 | + - name: SERVICE_ENV | ||
| 103 | + value: "dev" | ||
| 102 | - name: REDIS_HOST | 104 | - name: REDIS_HOST |
| 103 | valueFrom: | 105 | valueFrom: |
| 104 | configMapKeyRef: | 106 | configMapKeyRef: |
| @@ -102,3 +102,11 @@ func CreatePgBatchRemoveRoleService(options map[string]interface{}) (service.PgB | @@ -102,3 +102,11 @@ func CreatePgBatchRemoveRoleService(options map[string]interface{}) (service.PgB | ||
| 102 | } | 102 | } |
| 103 | return domainService.NewPgBatchRemoveRoleService(transactionContext) | 103 | return domainService.NewPgBatchRemoveRoleService(transactionContext) |
| 104 | } | 104 | } |
| 105 | + | ||
| 106 | +func CreatePgBatchAddOrgService(options map[string]interface{}) (service.PgBatchAddOrgService, error) { | ||
| 107 | + var transactionContext *pgTransaction.TransactionContext | ||
| 108 | + if value, ok := options["transactionContext"]; ok { | ||
| 109 | + transactionContext = value.(*pgTransaction.TransactionContext) | ||
| 110 | + } | ||
| 111 | + return domainService.NewPgBatchAddOrgService(transactionContext) | ||
| 112 | +} |
pkg/application/org/command/batch_add_org.go
0 → 100644
| 1 | +package command | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "fmt" | ||
| 5 | + "github.com/beego/beego/v2/core/validation" | ||
| 6 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/domain" | ||
| 7 | + "reflect" | ||
| 8 | + "strings" | ||
| 9 | +) | ||
| 10 | + | ||
| 11 | +type BatchAddCommand struct { | ||
| 12 | + OperateInfo *domain.OperateInfo `json:"-"` | ||
| 13 | + OrgList []*domain.BatchAddOrgItem `json:"orgList"` | ||
| 14 | +} | ||
| 15 | + | ||
| 16 | +func (batchAddCommand *BatchAddCommand) Valid(validation *validation.Validation) { | ||
| 17 | + //validation.SetError("CustomValid", "未实现的自定义认证") | ||
| 18 | +} | ||
| 19 | + | ||
| 20 | +func (batchAddCommand *BatchAddCommand) ValidateCommand() error { | ||
| 21 | + valid := validation.Validation{} | ||
| 22 | + b, err := valid.Valid(batchAddCommand) | ||
| 23 | + if err != nil { | ||
| 24 | + return err | ||
| 25 | + } | ||
| 26 | + if !b { | ||
| 27 | + elem := reflect.TypeOf(batchAddCommand).Elem() | ||
| 28 | + for _, validErr := range valid.Errors { | ||
| 29 | + field, isExist := elem.FieldByName(validErr.Field) | ||
| 30 | + if isExist { | ||
| 31 | + return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1)) | ||
| 32 | + } else { | ||
| 33 | + return fmt.Errorf(validErr.Message) | ||
| 34 | + } | ||
| 35 | + } | ||
| 36 | + } | ||
| 37 | + return nil | ||
| 38 | +} |
| @@ -16,6 +16,35 @@ import ( | @@ -16,6 +16,35 @@ import ( | ||
| 16 | type OrgService struct { | 16 | type OrgService struct { |
| 17 | } | 17 | } |
| 18 | 18 | ||
| 19 | +// 批量添加用户 | ||
| 20 | +func (orgService *OrgService) BatchAdd(batchAddCommand *command.BatchAddCommand) (interface{}, error) { | ||
| 21 | + if err := batchAddCommand.ValidateCommand(); err != nil { | ||
| 22 | + return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | ||
| 23 | + } | ||
| 24 | + transactionContext, err := factory.CreateTransactionContext(nil) | ||
| 25 | + if err != nil { | ||
| 26 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
| 27 | + } | ||
| 28 | + if err := transactionContext.StartTransaction(); err != nil { | ||
| 29 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
| 30 | + } | ||
| 31 | + defer func() { | ||
| 32 | + transactionContext.RollbackTransaction() | ||
| 33 | + }() | ||
| 34 | + | ||
| 35 | + batchAddOrgService, _ := factory.CreatePgBatchAddOrgService(map[string]interface{}{ | ||
| 36 | + "transactionContext": transactionContext, | ||
| 37 | + }) | ||
| 38 | + if err = batchAddOrgService.BatchAddOrg(batchAddCommand.OperateInfo, batchAddCommand.OrgList); err != nil { | ||
| 39 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
| 40 | + } | ||
| 41 | + | ||
| 42 | + if err := transactionContext.CommitTransaction(); err != nil { | ||
| 43 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
| 44 | + } | ||
| 45 | + return struct{}{}, nil | ||
| 46 | +} | ||
| 47 | + | ||
| 19 | // 创建组织 | 48 | // 创建组织 |
| 20 | func (orgService *OrgService) CreateOrg(createOrgCommand *command.CreateOrgCommand) (interface{}, error) { | 49 | func (orgService *OrgService) CreateOrg(createOrgCommand *command.CreateOrgCommand) (interface{}, error) { |
| 21 | if err := createOrgCommand.ValidateCommand(); err != nil { | 50 | if err := createOrgCommand.ValidateCommand(); err != nil { |
| @@ -12,7 +12,7 @@ import ( | @@ -12,7 +12,7 @@ import ( | ||
| 12 | type BatchAddCommand struct { | 12 | type BatchAddCommand struct { |
| 13 | OperateInfo *domain.OperateInfo `json:"-"` | 13 | OperateInfo *domain.OperateInfo `json:"-"` |
| 14 | // 用户类型 1:企业内部用户(内部添加) 2:共创用户 1024:企业注册用户(注册添加) | 14 | // 用户类型 1:企业内部用户(内部添加) 2:共创用户 1024:企业注册用户(注册添加) |
| 15 | - UserType int `cname:"用户类型" json:"userType" valid:"Required"` | 15 | + //UserType int `cname:"用户类型" json:"userType" valid:"Required"` |
| 16 | // 用户列表 | 16 | // 用户列表 |
| 17 | Users []*domain.User `cname:"用户列表" json:"users,omitempty"` | 17 | Users []*domain.User `cname:"用户列表" json:"users,omitempty"` |
| 18 | // 密码 | 18 | // 密码 |
pkg/application/user/command/batch_add2.go
0 → 100644
| 1 | +package command | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "fmt" | ||
| 5 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/domain" | ||
| 6 | + "reflect" | ||
| 7 | + "strings" | ||
| 8 | + | ||
| 9 | + "github.com/beego/beego/v2/core/validation" | ||
| 10 | +) | ||
| 11 | + | ||
| 12 | +type BatchAdd2Command struct { | ||
| 13 | + OperateInfo *domain.OperateInfo `json:"-"` | ||
| 14 | + // 用户列表 | ||
| 15 | + Users []*domain.BatchAddUserItem `cname:"用户列表" json:"users,omitempty"` | ||
| 16 | + // 密码 | ||
| 17 | + Password string `cname:"密码" json:"password" valid:"Required"` | ||
| 18 | +} | ||
| 19 | + | ||
| 20 | +func (batchAddCommand *BatchAdd2Command) Valid(validation *validation.Validation) { | ||
| 21 | + //validation.SetError("CustomValid", "未实现的自定义认证") | ||
| 22 | +} | ||
| 23 | + | ||
| 24 | +func (batchAddCommand *BatchAdd2Command) ValidateCommand() error { | ||
| 25 | + valid := validation.Validation{} | ||
| 26 | + b, err := valid.Valid(batchAddCommand) | ||
| 27 | + if err != nil { | ||
| 28 | + return err | ||
| 29 | + } | ||
| 30 | + if !b { | ||
| 31 | + elem := reflect.TypeOf(batchAddCommand).Elem() | ||
| 32 | + for _, validErr := range valid.Errors { | ||
| 33 | + field, isExist := elem.FieldByName(validErr.Field) | ||
| 34 | + if isExist { | ||
| 35 | + return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1)) | ||
| 36 | + } else { | ||
| 37 | + return fmt.Errorf(validErr.Message) | ||
| 38 | + } | ||
| 39 | + } | ||
| 40 | + } | ||
| 41 | + return nil | ||
| 42 | +} |
| @@ -45,6 +45,35 @@ func (userService *UserService) BatchAdd(batchAddCommand *command.BatchAddComman | @@ -45,6 +45,35 @@ func (userService *UserService) BatchAdd(batchAddCommand *command.BatchAddComman | ||
| 45 | return nil, nil | 45 | return nil, nil |
| 46 | } | 46 | } |
| 47 | 47 | ||
| 48 | +// 批量添加用户 | ||
| 49 | +func (userService *UserService) BatchAdd2(batchAddCommand *command.BatchAdd2Command) (interface{}, error) { | ||
| 50 | + if err := batchAddCommand.ValidateCommand(); err != nil { | ||
| 51 | + return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | ||
| 52 | + } | ||
| 53 | + transactionContext, err := factory.CreateTransactionContext(nil) | ||
| 54 | + if err != nil { | ||
| 55 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
| 56 | + } | ||
| 57 | + if err := transactionContext.StartTransaction(); err != nil { | ||
| 58 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
| 59 | + } | ||
| 60 | + defer func() { | ||
| 61 | + transactionContext.RollbackTransaction() | ||
| 62 | + }() | ||
| 63 | + | ||
| 64 | + batchAddUserService, _ := factory.CreateBatchAddUserService(map[string]interface{}{ | ||
| 65 | + "transactionContext": transactionContext, | ||
| 66 | + }) | ||
| 67 | + if err = batchAddUserService.BatchAddUser2(batchAddCommand.OperateInfo, batchAddCommand.Users, batchAddCommand.Password); err != nil { | ||
| 68 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
| 69 | + } | ||
| 70 | + | ||
| 71 | + if err := transactionContext.CommitTransaction(); err != nil { | ||
| 72 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
| 73 | + } | ||
| 74 | + return nil, nil | ||
| 75 | +} | ||
| 76 | + | ||
| 48 | // 批量修改启用状态 | 77 | // 批量修改启用状态 |
| 49 | func (userService *UserService) BatchEnable(batchEnableCommand *command.BatchEnableCommand) (interface{}, error) { | 78 | func (userService *UserService) BatchEnable(batchEnableCommand *command.BatchEnableCommand) (interface{}, error) { |
| 50 | if err := batchEnableCommand.ValidateCommand(); err != nil { | 79 | if err := batchEnableCommand.ValidateCommand(); err != nil { |
| @@ -47,5 +47,6 @@ func init() { | @@ -47,5 +47,6 @@ func init() { | ||
| 47 | if os.Getenv("HTTP_PORT") != "" { | 47 | if os.Getenv("HTTP_PORT") != "" { |
| 48 | HTTP_PORT, _ = strconv.Atoi(os.Getenv("HTTP_PORT")) | 48 | HTTP_PORT, _ = strconv.Atoi(os.Getenv("HTTP_PORT")) |
| 49 | } | 49 | } |
| 50 | - CACHE_PREFIX = fmt.Sprintf("%v-%v", SERVICE_NAME, SERVICE_ENV) | 50 | + SERVICE_NAME = fmt.Sprintf("%v-%v", SERVICE_NAME, SERVICE_ENV) |
| 51 | + CACHE_PREFIX = SERVICE_NAME | ||
| 51 | } | 52 | } |
| @@ -205,3 +205,16 @@ func (m *Org) CacheKeyFunc() string { | @@ -205,3 +205,16 @@ func (m *Org) CacheKeyFunc() string { | ||
| 205 | } | 205 | } |
| 206 | return fmt.Sprintf("%v:cache:org:id:%v", constant.CACHE_PREFIX, m.OrgId) | 206 | return fmt.Sprintf("%v:cache:org:id:%v", constant.CACHE_PREFIX, m.OrgId) |
| 207 | } | 207 | } |
| 208 | + | ||
| 209 | +/***** 3.批量添加组织项 *****/ | ||
| 210 | + | ||
| 211 | +type BatchAddOrgItem struct { | ||
| 212 | + // 组织编码 | ||
| 213 | + OrgCode string `json:"orgCode,omitempty"` | ||
| 214 | + // 父级组织编码 | ||
| 215 | + ParentOrgCode string `json:"parentOrgCode,omitempty"` | ||
| 216 | + // 组织名称 | ||
| 217 | + OrgName string `json:"orgName,omitempty"` | ||
| 218 | + // 企业id | ||
| 219 | + CompanyId int64 `json:"companyId,omitempty"` | ||
| 220 | +} |
| @@ -5,4 +5,5 @@ import "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/domain" | @@ -5,4 +5,5 @@ import "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/domain" | ||
| 5 | // PgBatchAddUserService 批量添加用户服务 | 5 | // PgBatchAddUserService 批量添加用户服务 |
| 6 | type PgBatchAddUserService interface { | 6 | type PgBatchAddUserService interface { |
| 7 | BatchAddUser(optUser *domain.OperateInfo, users []*domain.User, password string) error | 7 | BatchAddUser(optUser *domain.OperateInfo, users []*domain.User, password string) error |
| 8 | + BatchAddUser2(optUser *domain.OperateInfo, users []*domain.BatchAddUserItem, password string) error | ||
| 8 | } | 9 | } |
| @@ -284,3 +284,30 @@ func (user *User) CacheKeyFunc() string { | @@ -284,3 +284,30 @@ func (user *User) CacheKeyFunc() string { | ||
| 284 | func (user *User) BelongOrg() int64 { | 284 | func (user *User) BelongOrg() int64 { |
| 285 | return user.OrganizationId | 285 | return user.OrganizationId |
| 286 | } | 286 | } |
| 287 | + | ||
| 288 | +/***** 4.批量添加组织项 *****/ | ||
| 289 | + | ||
| 290 | +type BatchAddUserItem struct { | ||
| 291 | + // 企业id | ||
| 292 | + CompanyId int64 `json:"companyId,omitempty"` | ||
| 293 | + // 用户类型 1:企业内部用户(内部添加) 2:共创用户 1024:企业注册用户(注册添加) | ||
| 294 | + UserType int `json:"userType,omitempty"` | ||
| 295 | + // 用户姓名 | ||
| 296 | + UserName string `json:"userName,omitempty"` | ||
| 297 | + // 手机号码 | ||
| 298 | + Phone string `json:"phone,omitempty"` | ||
| 299 | + // 邮箱 | ||
| 300 | + Email string `json:"email,omitempty"` | ||
| 301 | + // 用户编号 企业内标识 | ||
| 302 | + UserCode string `json:"userCode,omitempty"` | ||
| 303 | + // 组织编码 | ||
| 304 | + Org string `json:"org,omitempty"` | ||
| 305 | + // 部门编码 | ||
| 306 | + Department string `json:"department,omitempty"` | ||
| 307 | + // 状态(1:启用 2:禁用 3:注销) | ||
| 308 | + EnableStatus int `json:"enableStatus,omitempty"` | ||
| 309 | + // 共创公司 cooperationCompany | ||
| 310 | + CooperationCompany string `json:"cooperationCompany"` | ||
| 311 | + // 共创到期时间 (yyyy-MM-dd) cooperationDeadline | ||
| 312 | + CooperationDeadline time.Time `json:"cooperationDeadline"` | ||
| 313 | +} |
| 1 | +package domainService | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "fmt" | ||
| 5 | + pgTransaction "github.com/linmadan/egglib-go/transaction/pg" | ||
| 6 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/domain" | ||
| 7 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/infrastructure/repository" | ||
| 8 | + "time" | ||
| 9 | +) | ||
| 10 | + | ||
| 11 | +// PgBatchAddOrgService 批量创建组织服务 | ||
| 12 | +type PgBatchAddOrgService struct { | ||
| 13 | + transactionContext *pgTransaction.TransactionContext | ||
| 14 | +} | ||
| 15 | + | ||
| 16 | +func (ptr *PgBatchAddOrgService) BatchAddOrg(optUser *domain.OperateInfo, orgList []*domain.BatchAddOrgItem) error { | ||
| 17 | + var ( | ||
| 18 | + err error | ||
| 19 | + ) | ||
| 20 | + orgRepository, err := repository.NewOrgRepository(ptr.transactionContext) | ||
| 21 | + if err != nil { | ||
| 22 | + return err | ||
| 23 | + } | ||
| 24 | + _, orgs, err := orgRepository.Find(map[string]interface{}{"companyId": optUser.CompanyId}) | ||
| 25 | + if err != nil { | ||
| 26 | + return err | ||
| 27 | + } | ||
| 28 | + var mapOrg = make(map[string]*domain.Org) | ||
| 29 | + for i := range orgs { | ||
| 30 | + mapOrg[orgs[i].OrgCode] = orgs[i] | ||
| 31 | + } | ||
| 32 | + | ||
| 33 | + createOrgService, _ := NewPgCreateOrgService(ptr.transactionContext) | ||
| 34 | + for i := range orgList { | ||
| 35 | + item := orgList[i] | ||
| 36 | + orgItem := &domain.Org{ | ||
| 37 | + CompanyId: optUser.CompanyId, | ||
| 38 | + OrgCode: item.OrgCode, | ||
| 39 | + OrgName: item.OrgName, | ||
| 40 | + IsOrg: domain.IsOrgFlag, | ||
| 41 | + ParentId: 0, | ||
| 42 | + OrgStatus: domain.OrgStatusEnable, | ||
| 43 | + CreatedAt: time.Now(), | ||
| 44 | + UpdatedAt: time.Now(), | ||
| 45 | + Ext: &domain.Ext{}, | ||
| 46 | + } | ||
| 47 | + if v, ok := mapOrg[item.ParentOrgCode]; !ok { | ||
| 48 | + return fmt.Errorf(fmt.Sprintf("找不到组织:%v", item.OrgCode)) | ||
| 49 | + } else { | ||
| 50 | + orgItem.ParentId = v.OrgId | ||
| 51 | + } | ||
| 52 | + | ||
| 53 | + orgItem, err = createOrgService.CreateOrg(optUser, orgItem) | ||
| 54 | + if err != nil { | ||
| 55 | + return err | ||
| 56 | + } | ||
| 57 | + if _, ok := mapOrg[orgItem.OrgCode]; !ok { | ||
| 58 | + mapOrg[orgItem.OrgCode] = orgItem | ||
| 59 | + } | ||
| 60 | + } | ||
| 61 | + return err | ||
| 62 | +} | ||
| 63 | + | ||
| 64 | +func NewPgBatchAddOrgService(transactionContext *pgTransaction.TransactionContext) (*PgBatchAddOrgService, error) { | ||
| 65 | + if transactionContext == nil { | ||
| 66 | + return nil, fmt.Errorf("transactionContext参数不能为nil") | ||
| 67 | + } else { | ||
| 68 | + return &PgBatchAddOrgService{ | ||
| 69 | + transactionContext: transactionContext, | ||
| 70 | + }, nil | ||
| 71 | + } | ||
| 72 | +} |
| @@ -82,6 +82,73 @@ func (ptr *PgBatchAddUserService) BatchAddUser(optUser *domain.OperateInfo, user | @@ -82,6 +82,73 @@ func (ptr *PgBatchAddUserService) BatchAddUser(optUser *domain.OperateInfo, user | ||
| 82 | return nil | 82 | return nil |
| 83 | } | 83 | } |
| 84 | 84 | ||
| 85 | +func (ptr *PgBatchAddUserService) BatchAddUser2(optUser *domain.OperateInfo, users []*domain.BatchAddUserItem, password string) error { | ||
| 86 | + var ( | ||
| 87 | + err error | ||
| 88 | + ) | ||
| 89 | + orgRepository, err := repository.NewOrgRepository(ptr.transactionContext) | ||
| 90 | + if err != nil { | ||
| 91 | + return err | ||
| 92 | + } | ||
| 93 | + _, orgs, err := orgRepository.Find(map[string]interface{}{"companyId": optUser.CompanyId}) | ||
| 94 | + if err != nil { | ||
| 95 | + return err | ||
| 96 | + } | ||
| 97 | + var mapOrg = make(map[string]*domain.Org) | ||
| 98 | + for i := range orgs { | ||
| 99 | + mapOrg[orgs[i].OrgCode] = orgs[i] | ||
| 100 | + } | ||
| 101 | + | ||
| 102 | + createUserService, _ := NewPgCreateUserService(ptr.transactionContext) | ||
| 103 | + for i := range users { | ||
| 104 | + user := users[i] | ||
| 105 | + if err = ptr.preCheck2(user); err != nil { | ||
| 106 | + return err | ||
| 107 | + } | ||
| 108 | + var org, dep *domain.Org | ||
| 109 | + var ok bool | ||
| 110 | + if org, ok = mapOrg[user.Org]; !ok { | ||
| 111 | + return fmt.Errorf("导入的组织机构不存在:" + user.Org) | ||
| 112 | + } | ||
| 113 | + if dep, ok = mapOrg[user.Department]; !ok { | ||
| 114 | + return fmt.Errorf("导入的所属部门不存在:" + user.Department) | ||
| 115 | + } | ||
| 116 | + newUser := &domain.User{ | ||
| 117 | + CompanyId: user.CompanyId, | ||
| 118 | + UserType: user.UserType, | ||
| 119 | + UserCode: user.UserCode, | ||
| 120 | + OrganizationId: org.OrgId, | ||
| 121 | + DepartmentId: dep.OrgId, | ||
| 122 | + UserOrg: []*domain.Org{}, | ||
| 123 | + UserRole: []*domain.Role{}, | ||
| 124 | + FavoriteMenus: []string{}, | ||
| 125 | + CooperationInfo: &domain.CooperationInfo{ | ||
| 126 | + CooperationCompany: user.CooperationCompany, | ||
| 127 | + CooperationDeadline: user.CooperationDeadline, | ||
| 128 | + }, | ||
| 129 | + UserInfo: &domain.UserInfo{ | ||
| 130 | + UserName: user.UserName, | ||
| 131 | + Phone: user.Phone, | ||
| 132 | + Avatar: "", | ||
| 133 | + Email: user.Email, | ||
| 134 | + }, | ||
| 135 | + EnableStatus: int(domain.UserStatusEnable), | ||
| 136 | + Ext: &domain.Ext{ | ||
| 137 | + Phone: user.Phone, | ||
| 138 | + UserName: user.UserName, | ||
| 139 | + OrgName: org.OrgName, | ||
| 140 | + DepName: dep.OrgName, | ||
| 141 | + }, | ||
| 142 | + CreatedAt: time.Now(), | ||
| 143 | + UpdatedAt: time.Now(), | ||
| 144 | + } | ||
| 145 | + if newUser, err = createUserService.CreateUser(nil, newUser, password); err != nil { | ||
| 146 | + return err | ||
| 147 | + } | ||
| 148 | + } | ||
| 149 | + return nil | ||
| 150 | +} | ||
| 151 | + | ||
| 85 | func (ptr *PgBatchAddUserService) preCheck(user *domain.User) error { | 152 | func (ptr *PgBatchAddUserService) preCheck(user *domain.User) error { |
| 86 | if len(user.UserInfo.UserName) == 0 { | 153 | if len(user.UserInfo.UserName) == 0 { |
| 87 | return fmt.Errorf("导入的用户姓名为空值") | 154 | return fmt.Errorf("导入的用户姓名为空值") |
| @@ -98,6 +165,22 @@ func (ptr *PgBatchAddUserService) preCheck(user *domain.User) error { | @@ -98,6 +165,22 @@ func (ptr *PgBatchAddUserService) preCheck(user *domain.User) error { | ||
| 98 | return nil | 165 | return nil |
| 99 | } | 166 | } |
| 100 | 167 | ||
| 168 | +func (ptr *PgBatchAddUserService) preCheck2(user *domain.BatchAddUserItem) error { | ||
| 169 | + if len(user.UserName) == 0 { | ||
| 170 | + return fmt.Errorf("导入的用户姓名为空值") | ||
| 171 | + } | ||
| 172 | + if len(user.Phone) == 0 { | ||
| 173 | + return fmt.Errorf("导入的手机号不是有效手机号") | ||
| 174 | + } | ||
| 175 | + //if len(user.Org) == 0 { | ||
| 176 | + // return fmt.Errorf("导入的组织机构不存在") | ||
| 177 | + //} | ||
| 178 | + //if len(user.Department) == 0 && user.UserType == domain.UserTypeEmployee { | ||
| 179 | + // return fmt.Errorf("导入的所属部门不存在") | ||
| 180 | + //} | ||
| 181 | + return nil | ||
| 182 | +} | ||
| 183 | + | ||
| 101 | func NewPgBatchAddUserService(transactionContext *pgTransaction.TransactionContext) (*PgBatchAddUserService, error) { | 184 | func NewPgBatchAddUserService(transactionContext *pgTransaction.TransactionContext) (*PgBatchAddUserService, error) { |
| 102 | if transactionContext == nil { | 185 | if transactionContext == nil { |
| 103 | return nil, fmt.Errorf("transactionContext参数不能为nil") | 186 | return nil, fmt.Errorf("transactionContext参数不能为nil") |
| @@ -4,7 +4,7 @@ import ( | @@ -4,7 +4,7 @@ import ( | ||
| 4 | "context" | 4 | "context" |
| 5 | "fmt" | 5 | "fmt" |
| 6 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/infrastructure/pg/models" | 6 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/infrastructure/pg/models" |
| 7 | - "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/log" | 7 | + "log" |
| 8 | "reflect" | 8 | "reflect" |
| 9 | 9 | ||
| 10 | "github.com/go-pg/pg/v10" | 10 | "github.com/go-pg/pg/v10" |
| @@ -61,7 +61,8 @@ func (hook SqlGeneratePrintHook) AfterQuery(c context.Context, q *pg.QueryEvent) | @@ -61,7 +61,8 @@ func (hook SqlGeneratePrintHook) AfterQuery(c context.Context, q *pg.QueryEvent) | ||
| 61 | if err != nil { | 61 | if err != nil { |
| 62 | return err | 62 | return err |
| 63 | } | 63 | } |
| 64 | - log.Logger.Debug(string(sqlStr)) | 64 | + //log.Logger.Debug(string(sqlStr)) |
| 65 | + log.Println(string(sqlStr)) | ||
| 65 | return nil | 66 | return nil |
| 66 | } | 67 | } |
| 67 | 68 |
| @@ -89,3 +89,12 @@ func (controller *OrgController) SearchOrg() { | @@ -89,3 +89,12 @@ func (controller *OrgController) SearchOrg() { | ||
| 89 | data, err := orgService.ListOrg(listOrgQuery) | 89 | data, err := orgService.ListOrg(listOrgQuery) |
| 90 | controller.Response(data, err) | 90 | controller.Response(data, err) |
| 91 | } | 91 | } |
| 92 | + | ||
| 93 | +func (controller *OrgController) BatchAdd() { | ||
| 94 | + orgService := service.NewOrgService(nil) | ||
| 95 | + batchAddCommand := &command.BatchAddCommand{} | ||
| 96 | + Must(controller.Unmarshal(batchAddCommand)) | ||
| 97 | + batchAddCommand.OperateInfo = ParseOperateInfo(controller.BaseController) | ||
| 98 | + data, err := orgService.BatchAdd(batchAddCommand) | ||
| 99 | + controller.Response(data, err) | ||
| 100 | +} |
| @@ -93,6 +93,15 @@ func (controller *UserController) BatchAdd() { | @@ -93,6 +93,15 @@ func (controller *UserController) BatchAdd() { | ||
| 93 | controller.Response(data, err) | 93 | controller.Response(data, err) |
| 94 | } | 94 | } |
| 95 | 95 | ||
| 96 | +func (controller *UserController) BatchAdd2() { | ||
| 97 | + userService := service.NewUserService(nil) | ||
| 98 | + batchAddCommand := &command.BatchAdd2Command{} | ||
| 99 | + Must(controller.Unmarshal(batchAddCommand)) | ||
| 100 | + batchAddCommand.OperateInfo = ParseOperateInfo(controller.BaseController) | ||
| 101 | + data, err := userService.BatchAdd2(batchAddCommand) | ||
| 102 | + controller.Response(data, err) | ||
| 103 | +} | ||
| 104 | + | ||
| 96 | func (controller *UserController) BatchEnable() { | 105 | func (controller *UserController) BatchEnable() { |
| 97 | userService := service.NewUserService(nil) | 106 | userService := service.NewUserService(nil) |
| 98 | batchEnableCommand := &command.BatchEnableCommand{} | 107 | batchEnableCommand := &command.BatchEnableCommand{} |
| @@ -13,4 +13,5 @@ func init() { | @@ -13,4 +13,5 @@ func init() { | ||
| 13 | web.Router("/org/search", &controllers.OrgController{}, "Post:SearchOrg") | 13 | web.Router("/org/search", &controllers.OrgController{}, "Post:SearchOrg") |
| 14 | web.Router("/org/:orgId/sub-department", &controllers.OrgController{}, "Get:GetOrgSubDepartment") | 14 | web.Router("/org/:orgId/sub-department", &controllers.OrgController{}, "Get:GetOrgSubDepartment") |
| 15 | web.Router("/org/enable", &controllers.OrgController{}, "Post:EnableOrg") | 15 | web.Router("/org/enable", &controllers.OrgController{}, "Post:EnableOrg") |
| 16 | + web.Router("/org/batch-add", &controllers.OrgController{}, "Post:BatchAdd") | ||
| 16 | } | 17 | } |
| @@ -14,6 +14,7 @@ func init() { | @@ -14,6 +14,7 @@ func init() { | ||
| 14 | web.Router("/user/:userId/access-menus", &controllers.UserController{}, "Get:GetUserAccessMenus") | 14 | web.Router("/user/:userId/access-menus", &controllers.UserController{}, "Get:GetUserAccessMenus") |
| 15 | web.Router("/user/:userId/profile", &controllers.UserController{}, "Get:GetUserProfile") | 15 | web.Router("/user/:userId/profile", &controllers.UserController{}, "Get:GetUserProfile") |
| 16 | web.Router("/user/batch-add", &controllers.UserController{}, "Post:BatchAdd") | 16 | web.Router("/user/batch-add", &controllers.UserController{}, "Post:BatchAdd") |
| 17 | + web.Router("/user/batch-add2", &controllers.UserController{}, "Post:BatchAdd2") | ||
| 17 | web.Router("/user/batch-enable", &controllers.UserController{}, "Post:BatchEnable") | 18 | web.Router("/user/batch-enable", &controllers.UserController{}, "Post:BatchEnable") |
| 18 | web.Router("/user/batch-reset-password", &controllers.UserController{}, "Post:BatchResetPassword") | 19 | web.Router("/user/batch-reset-password", &controllers.UserController{}, "Post:BatchResetPassword") |
| 19 | web.Router("/user/:userId/base-info", &controllers.UserController{}, "Put:UpdateUsersBase") | 20 | web.Router("/user/:userId/base-info", &controllers.UserController{}, "Put:UpdateUsersBase") |
-
请 注册 或 登录 后发表评论