作者 yangfu

feat:用户增加IC卡、员工类型

@@ -41,6 +41,10 @@ type CreateUserCommand struct { @@ -41,6 +41,10 @@ type CreateUserCommand struct {
41 Avatar string `cname:"头像" json:"avatar"` 41 Avatar string `cname:"头像" json:"avatar"`
42 // 邮箱 42 // 邮箱
43 Email string `cname:"邮箱" json:"email"` 43 Email string `cname:"邮箱" json:"email"`
  44 + // 员工类型 1:固定 2:派遣 3.临时
  45 + EmployeeType int `cname:"员工类型" json:"employeeType" valid:"Required"`
  46 + // IC卡号
  47 + IcCardNumber string `cname:"IC卡号" json:"icCardNumber,omitempty"`
44 48
45 // 运营管理扩展 49 // 运营管理扩展
46 // 部门 50 // 部门
@@ -36,6 +36,10 @@ type UpdateUserCommand struct { @@ -36,6 +36,10 @@ type UpdateUserCommand struct {
36 Avatar string `cname:"头像" json:"avatar"` 36 Avatar string `cname:"头像" json:"avatar"`
37 // 邮箱 37 // 邮箱
38 Email string `cname:"邮箱" json:"email"` 38 Email string `cname:"邮箱" json:"email"`
  39 + // 员工类型 1:固定 2:派遣 3.临时
  40 + EmployeeType int `name:"员工类型" json:"employeeType" valid:"Required"`
  41 + // IC卡号
  42 + IcCardNumber string `json:"icCardNumber,omitempty"`
39 43
40 // 运营管理扩展 44 // 运营管理扩展
41 // 部门 45 // 部门
@@ -73,7 +73,12 @@ func (dto *UserDto) LoadDto(user *domain.User, company *domain.Company) error { @@ -73,7 +73,12 @@ func (dto *UserDto) LoadDto(user *domain.User, company *domain.Company) error {
73 dto.UserInfo = &domain.UserInfo{ 73 dto.UserInfo = &domain.UserInfo{
74 UserName: user.Ext.UserName, 74 UserName: user.Ext.UserName,
75 Phone: user.Ext.Phone, 75 Phone: user.Ext.Phone,
  76 + IcCardNumber: user.Ext.IcCardNumber,
  77 + EmployeeType: user.Ext.EmployeeType,
76 } 78 }
  79 + } else {
  80 + dto.UserInfo.IcCardNumber = user.Ext.IcCardNumber
  81 + dto.UserInfo.EmployeeType = user.Ext.EmployeeType
77 } 82 }
78 if len(dto.UserRole) == 0 { 83 if len(dto.UserRole) == 0 {
79 dto.UserRole = make([]*domain.Role, 0) 84 dto.UserRole = make([]*domain.Role, 0)
@@ -274,6 +274,8 @@ func (userService *UserService) CreateUser(createUserCommand *command.CreateUser @@ -274,6 +274,8 @@ func (userService *UserService) CreateUser(createUserCommand *command.CreateUser
274 Phone: createUserCommand.Phone, 274 Phone: createUserCommand.Phone,
275 UserName: createUserCommand.UserName, 275 UserName: createUserCommand.UserName,
276 DepName: createUserCommand.DepartmentName, 276 DepName: createUserCommand.DepartmentName,
  277 + IcCardNumber: createUserCommand.IcCardNumber,
  278 + EmployeeType: createUserCommand.EmployeeType,
277 }, 279 },
278 CreatedAt: time.Now(), 280 CreatedAt: time.Now(),
279 UpdatedAt: time.Now(), 281 UpdatedAt: time.Now(),
@@ -705,7 +707,7 @@ func (userService *UserService) UpdateUser(updateUserCommand *command.UpdateUser @@ -705,7 +707,7 @@ func (userService *UserService) UpdateUser(updateUserCommand *command.UpdateUser
705 defer func() { 707 defer func() {
706 transactionContext.RollbackTransaction() 708 transactionContext.RollbackTransaction()
707 }() 709 }()
708 - _, user, err := factory.FastPgUser(transactionContext, updateUserCommand.UserId, factory.WithDataAuthRequired(), factory.WithOperator(updateUserCommand.OperateInfo)) 710 + _, user, err := factory.FastPgUser(transactionContext, updateUserCommand.UserId, factory.WithOperator(updateUserCommand.OperateInfo)) //, factory.WithDataAuthRequired()
709 if err != nil { 711 if err != nil {
710 return nil, err 712 return nil, err
711 } 713 }
@@ -729,6 +731,8 @@ func (userService *UserService) UpdateUser(updateUserCommand *command.UpdateUser @@ -729,6 +731,8 @@ func (userService *UserService) UpdateUser(updateUserCommand *command.UpdateUser
729 Email: updateUserCommand.Email, 731 Email: updateUserCommand.Email,
730 DepartmentName: updateUserCommand.DepartmentName, 732 DepartmentName: updateUserCommand.DepartmentName,
731 } 733 }
  734 + user.Ext.EmployeeType = updateUserCommand.EmployeeType
  735 + user.Ext.IcCardNumber = updateUserCommand.IcCardNumber
732 736
733 updateUserService, _ := factory.CreatePgUpdateUserService(map[string]interface{}{ 737 updateUserService, _ := factory.CreatePgUpdateUserService(map[string]interface{}{
734 "transactionContext": transactionContext, 738 "transactionContext": transactionContext,
@@ -12,4 +12,9 @@ type Ext struct { @@ -12,4 +12,9 @@ type Ext struct {
12 DepName string `json:"depName,omitempty"` 12 DepName string `json:"depName,omitempty"`
13 // 父级部门名称 13 // 父级部门名称
14 ParentDepName string `json:"parentDepName,omitempty"` 14 ParentDepName string `json:"parentDepName,omitempty"`
  15 +
  16 + // 员工类型 1:固定 2:派遣 3.临时
  17 + EmployeeType int `json:"employeeType,omitempty"`
  18 + // IC卡号
  19 + IcCardNumber string `json:"icCardNumber,omitempty"`
15 } 20 }
@@ -314,6 +314,10 @@ type BatchAddUserItem struct { @@ -314,6 +314,10 @@ type BatchAddUserItem struct {
314 CooperationCompany string `json:"cooperationCompany"` 314 CooperationCompany string `json:"cooperationCompany"`
315 // 共创到期时间 (yyyy-MM-dd) cooperationDeadline 315 // 共创到期时间 (yyyy-MM-dd) cooperationDeadline
316 CooperationDeadline string `json:"cooperationDeadline"` 316 CooperationDeadline string `json:"cooperationDeadline"`
  317 + // 员工类型 1:固定 2:派遣 3.临时
  318 + EmployeeType string `json:"employeeType,omitempty"`
  319 + // IC卡号
  320 + IcCardNumber string `json:"icCardNumber,omitempty"`
317 321
318 // 失败理由 322 // 失败理由
319 FailReason string `json:"failReason"` 323 FailReason string `json:"failReason"`
@@ -328,3 +332,16 @@ func (item *BatchAddUserItem) Status() int { @@ -328,3 +332,16 @@ func (item *BatchAddUserItem) Status() int {
328 } 332 }
329 return 1 333 return 1
330 } 334 }
  335 +
  336 +func (item *BatchAddUserItem) GetEmployeeType() int {
  337 + if item.EmployeeType == "固定" {
  338 + return 1
  339 + }
  340 + if item.EmployeeType == "派遣" {
  341 + return 2
  342 + }
  343 + if item.EmployeeType == "临时" {
  344 + return 3
  345 + }
  346 + return 1
  347 +}
@@ -11,6 +11,11 @@ type UserInfo struct { @@ -11,6 +11,11 @@ type UserInfo struct {
11 // 邮箱 11 // 邮箱
12 Email string `json:"email,omitempty"` 12 Email string `json:"email,omitempty"`
13 13
  14 + // 员工类型 1:固定 2:派遣 3.临时
  15 + EmployeeType int `json:"employeeType,omitempty"`
  16 + // IC卡号
  17 + IcCardNumber string `json:"icCardNumber,omitempty"`
  18 +
14 Referer string `json:"-"` 19 Referer string `json:"-"`
15 // 部门 20 // 部门
16 DepartmentName string `cname:"部门" json:"-"` 21 DepartmentName string `cname:"部门" json:"-"`
@@ -142,6 +142,8 @@ func (ptr *PgBatchAddUserService) BatchAddUser2(optUser *domain.OperateInfo, use @@ -142,6 +142,8 @@ func (ptr *PgBatchAddUserService) BatchAddUser2(optUser *domain.OperateInfo, use
142 Phone: user.Phone, 142 Phone: user.Phone,
143 UserName: user.UserName, 143 UserName: user.UserName,
144 OrgName: org.OrgName, 144 OrgName: org.OrgName,
  145 + EmployeeType: user.GetEmployeeType(),
  146 + IcCardNumber: user.IcCardNumber,
145 }, 147 },
146 CreatedAt: time.Now(), 148 CreatedAt: time.Now(),
147 UpdatedAt: time.Now(), 149 UpdatedAt: time.Now(),
@@ -202,6 +204,12 @@ func (ptr *PgBatchAddUserService) preCheck2(user *domain.BatchAddUserItem) error @@ -202,6 +204,12 @@ func (ptr *PgBatchAddUserService) preCheck2(user *domain.BatchAddUserItem) error
202 if len(user.Phone) == 0 || len(user.Phone) != 11 { 204 if len(user.Phone) == 0 || len(user.Phone) != 11 {
203 return fmt.Errorf("导入的手机号不是有效手机号") 205 return fmt.Errorf("导入的手机号不是有效手机号")
204 } 206 }
  207 + if len(user.EmployeeType) == 0 {
  208 + return fmt.Errorf("导入的员工类型为空值")
  209 + }
  210 + if !(user.EmployeeType == "固定" || user.EmployeeType == "派遣" || user.EmployeeType == "临时") {
  211 + return fmt.Errorf("导入的员工类型有误")
  212 + }
205 return nil 213 return nil
206 } 214 }
207 215
@@ -68,6 +68,13 @@ func (ptr *PgCreateUserService) CreateUser(optUser *domain.User, newUser *domain @@ -68,6 +68,13 @@ func (ptr *PgCreateUserService) CreateUser(optUser *domain.User, newUser *domain
68 } 68 }
69 } 69 }
70 70
  71 + // 判断企业内IC卡号唯一
  72 + if len(newUser.Ext.IcCardNumber) > 0 {
  73 + if u, e := userRepository.FindOne(map[string]interface{}{"companyId": newUser.CompanyId, "icCardNumber": newUser.Ext.IcCardNumber}); e == nil && u != nil {
  74 + return nil, fmt.Errorf("IC卡号在该企业内已存在,请重新输入")
  75 + }
  76 + }
  77 +
71 // 3.建账号 78 // 3.建账号
72 if userBase == nil { 79 if userBase == nil {
73 createUserAccountService, _ := NewPgCreateUserAccountService(ptr.transactionContext) 80 createUserAccountService, _ := NewPgCreateUserAccountService(ptr.transactionContext)
@@ -80,6 +80,13 @@ func (ptr *PgUpdateUserService) UpdateUser(optUser *domain.OperateInfo, user *do @@ -80,6 +80,13 @@ func (ptr *PgUpdateUserService) UpdateUser(optUser *domain.OperateInfo, user *do
80 return nil, fmt.Errorf("用户编号在该企业内已存在,请重新输入") 80 return nil, fmt.Errorf("用户编号在该企业内已存在,请重新输入")
81 } 81 }
82 82
  83 + // 判断企业内IC卡号唯一
  84 + if len(user.Ext.IcCardNumber) > 0 {
  85 + if u, e := userRepository.FindOne(map[string]interface{}{"companyId": user.CompanyId, "icCardNumber": user.Ext.IcCardNumber}); e == nil && u != nil && u.UserId != user.UserId {
  86 + return nil, fmt.Errorf("IC卡号在该企业内已存在,请重新输入")
  87 + }
  88 + }
  89 +
83 user.UserRole = userRole 90 user.UserRole = userRole
84 user.UserOrg = userOrg 91 user.UserOrg = userOrg
85 if org != nil { 92 if org != nil {
@@ -92,6 +99,8 @@ func (ptr *PgUpdateUserService) UpdateUser(optUser *domain.OperateInfo, user *do @@ -92,6 +99,8 @@ func (ptr *PgUpdateUserService) UpdateUser(optUser *domain.OperateInfo, user *do
92 } 99 }
93 user.Ext.Phone = userBase.UserInfo.Phone 100 user.Ext.Phone = userBase.UserInfo.Phone
94 user.Ext.UserName = userBase.UserInfo.UserName 101 user.Ext.UserName = userBase.UserInfo.UserName
  102 + //user.Ext.EmployeeType = userInfo.EmployeeType
  103 + //user.Ext.IcCardNumber = userInfo.IcCardNumber
95 user.UpdatedAt = time.Now() 104 user.UpdatedAt = time.Now()
96 if err = user.SetEnableStatus(enableStatus); err != nil { 105 if err = user.SetEnableStatus(enableStatus); err != nil {
97 return nil, err 106 return nil, err
@@ -169,6 +169,7 @@ func (repository *UserRepository) FindOne(queryOptions map[string]interface{}) ( @@ -169,6 +169,7 @@ func (repository *UserRepository) FindOne(queryOptions map[string]interface{}) (
169 query.SetWhereByQueryOption("user_code = ?", "userCode") 169 query.SetWhereByQueryOption("user_code = ?", "userCode")
170 query.SetWhereByQueryOption("user_id != ?", "notEqualUserId") 170 query.SetWhereByQueryOption("user_id != ?", "notEqualUserId")
171 query.SetWhereByQueryOption("user_type & ? > 0", "userType") 171 query.SetWhereByQueryOption("user_type & ? > 0", "userType")
  172 + query.SetWhereByQueryOption("ext->>'icCardNumber'=?", "icCardNumber")
172 if err := query.First(); err != nil { 173 if err := query.First(); err != nil {
173 if err.Error() == "pg: no rows in result set" { 174 if err.Error() == "pg: no rows in result set" {
174 return nil, fmt.Errorf("没有此资源") 175 return nil, fmt.Errorf("没有此资源")