作者 yangfu

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

... ... @@ -41,6 +41,10 @@ type CreateUserCommand struct {
Avatar string `cname:"头像" json:"avatar"`
// 邮箱
Email string `cname:"邮箱" json:"email"`
// 员工类型 1:固定 2:派遣 3.临时
EmployeeType int `cname:"员工类型" json:"employeeType" valid:"Required"`
// IC卡号
IcCardNumber string `cname:"IC卡号" json:"icCardNumber,omitempty"`
// 运营管理扩展
// 部门
... ...
... ... @@ -36,6 +36,10 @@ type UpdateUserCommand struct {
Avatar string `cname:"头像" json:"avatar"`
// 邮箱
Email string `cname:"邮箱" json:"email"`
// 员工类型 1:固定 2:派遣 3.临时
EmployeeType int `name:"员工类型" json:"employeeType" valid:"Required"`
// IC卡号
IcCardNumber string `json:"icCardNumber,omitempty"`
// 运营管理扩展
// 部门
... ...
... ... @@ -71,9 +71,14 @@ func (dto *UserDto) LoadDto(user *domain.User, company *domain.Company) error {
}
if user.UserInfo == nil {
dto.UserInfo = &domain.UserInfo{
UserName: user.Ext.UserName,
Phone: user.Ext.Phone,
UserName: user.Ext.UserName,
Phone: user.Ext.Phone,
IcCardNumber: user.Ext.IcCardNumber,
EmployeeType: user.Ext.EmployeeType,
}
} else {
dto.UserInfo.IcCardNumber = user.Ext.IcCardNumber
dto.UserInfo.EmployeeType = user.Ext.EmployeeType
}
if len(dto.UserRole) == 0 {
dto.UserRole = make([]*domain.Role, 0)
... ...
... ... @@ -271,9 +271,11 @@ func (userService *UserService) CreateUser(createUserCommand *command.CreateUser
UserInfo: nweUserInfo,
EnableStatus: createUserCommand.EnableStatus,
Ext: &domain.Ext{
Phone: createUserCommand.Phone,
UserName: createUserCommand.UserName,
DepName: createUserCommand.DepartmentName,
Phone: createUserCommand.Phone,
UserName: createUserCommand.UserName,
DepName: createUserCommand.DepartmentName,
IcCardNumber: createUserCommand.IcCardNumber,
EmployeeType: createUserCommand.EmployeeType,
},
CreatedAt: time.Now(),
UpdatedAt: time.Now(),
... ... @@ -705,7 +707,7 @@ func (userService *UserService) UpdateUser(updateUserCommand *command.UpdateUser
defer func() {
transactionContext.RollbackTransaction()
}()
_, user, err := factory.FastPgUser(transactionContext, updateUserCommand.UserId, factory.WithDataAuthRequired(), factory.WithOperator(updateUserCommand.OperateInfo))
_, user, err := factory.FastPgUser(transactionContext, updateUserCommand.UserId, factory.WithOperator(updateUserCommand.OperateInfo)) //, factory.WithDataAuthRequired()
if err != nil {
return nil, err
}
... ... @@ -729,6 +731,8 @@ func (userService *UserService) UpdateUser(updateUserCommand *command.UpdateUser
Email: updateUserCommand.Email,
DepartmentName: updateUserCommand.DepartmentName,
}
user.Ext.EmployeeType = updateUserCommand.EmployeeType
user.Ext.IcCardNumber = updateUserCommand.IcCardNumber
updateUserService, _ := factory.CreatePgUpdateUserService(map[string]interface{}{
"transactionContext": transactionContext,
... ...
... ... @@ -12,4 +12,9 @@ type Ext struct {
DepName string `json:"depName,omitempty"`
// 父级部门名称
ParentDepName string `json:"parentDepName,omitempty"`
// 员工类型 1:固定 2:派遣 3.临时
EmployeeType int `json:"employeeType,omitempty"`
// IC卡号
IcCardNumber string `json:"icCardNumber,omitempty"`
}
... ...
... ... @@ -314,6 +314,10 @@ type BatchAddUserItem struct {
CooperationCompany string `json:"cooperationCompany"`
// 共创到期时间 (yyyy-MM-dd) cooperationDeadline
CooperationDeadline string `json:"cooperationDeadline"`
// 员工类型 1:固定 2:派遣 3.临时
EmployeeType string `json:"employeeType,omitempty"`
// IC卡号
IcCardNumber string `json:"icCardNumber,omitempty"`
// 失败理由
FailReason string `json:"failReason"`
... ... @@ -328,3 +332,16 @@ func (item *BatchAddUserItem) Status() int {
}
return 1
}
func (item *BatchAddUserItem) GetEmployeeType() int {
if item.EmployeeType == "固定" {
return 1
}
if item.EmployeeType == "派遣" {
return 2
}
if item.EmployeeType == "临时" {
return 3
}
return 1
}
... ...
... ... @@ -11,6 +11,11 @@ type UserInfo struct {
// 邮箱
Email string `json:"email,omitempty"`
// 员工类型 1:固定 2:派遣 3.临时
EmployeeType int `json:"employeeType,omitempty"`
// IC卡号
IcCardNumber string `json:"icCardNumber,omitempty"`
Referer string `json:"-"`
// 部门
DepartmentName string `cname:"部门" json:"-"`
... ...
... ... @@ -139,9 +139,11 @@ func (ptr *PgBatchAddUserService) BatchAddUser2(optUser *domain.OperateInfo, use
},
EnableStatus: user.Status(),
Ext: &domain.Ext{
Phone: user.Phone,
UserName: user.UserName,
OrgName: org.OrgName,
Phone: user.Phone,
UserName: user.UserName,
OrgName: org.OrgName,
EmployeeType: user.GetEmployeeType(),
IcCardNumber: user.IcCardNumber,
},
CreatedAt: time.Now(),
UpdatedAt: time.Now(),
... ... @@ -202,6 +204,12 @@ func (ptr *PgBatchAddUserService) preCheck2(user *domain.BatchAddUserItem) error
if len(user.Phone) == 0 || len(user.Phone) != 11 {
return fmt.Errorf("导入的手机号不是有效手机号")
}
if len(user.EmployeeType) == 0 {
return fmt.Errorf("导入的员工类型为空值")
}
if !(user.EmployeeType == "固定" || user.EmployeeType == "派遣" || user.EmployeeType == "临时") {
return fmt.Errorf("导入的员工类型有误")
}
return nil
}
... ...
... ... @@ -68,6 +68,13 @@ func (ptr *PgCreateUserService) CreateUser(optUser *domain.User, newUser *domain
}
}
// 判断企业内IC卡号唯一
if len(newUser.Ext.IcCardNumber) > 0 {
if u, e := userRepository.FindOne(map[string]interface{}{"companyId": newUser.CompanyId, "icCardNumber": newUser.Ext.IcCardNumber}); e == nil && u != nil {
return nil, fmt.Errorf("IC卡号在该企业内已存在,请重新输入")
}
}
// 3.建账号
if userBase == nil {
createUserAccountService, _ := NewPgCreateUserAccountService(ptr.transactionContext)
... ...
... ... @@ -80,6 +80,13 @@ func (ptr *PgUpdateUserService) UpdateUser(optUser *domain.OperateInfo, user *do
return nil, fmt.Errorf("用户编号在该企业内已存在,请重新输入")
}
// 判断企业内IC卡号唯一
if len(user.Ext.IcCardNumber) > 0 {
if u, e := userRepository.FindOne(map[string]interface{}{"companyId": user.CompanyId, "icCardNumber": user.Ext.IcCardNumber}); e == nil && u != nil && u.UserId != user.UserId {
return nil, fmt.Errorf("IC卡号在该企业内已存在,请重新输入")
}
}
user.UserRole = userRole
user.UserOrg = userOrg
if org != nil {
... ... @@ -92,6 +99,8 @@ func (ptr *PgUpdateUserService) UpdateUser(optUser *domain.OperateInfo, user *do
}
user.Ext.Phone = userBase.UserInfo.Phone
user.Ext.UserName = userBase.UserInfo.UserName
//user.Ext.EmployeeType = userInfo.EmployeeType
//user.Ext.IcCardNumber = userInfo.IcCardNumber
user.UpdatedAt = time.Now()
if err = user.SetEnableStatus(enableStatus); err != nil {
return nil, err
... ...
... ... @@ -169,6 +169,7 @@ func (repository *UserRepository) FindOne(queryOptions map[string]interface{}) (
query.SetWhereByQueryOption("user_code = ?", "userCode")
query.SetWhereByQueryOption("user_id != ?", "notEqualUserId")
query.SetWhereByQueryOption("user_type & ? > 0", "userType")
query.SetWhereByQueryOption("ext->>'icCardNumber'=?", "icCardNumber")
if err := query.First(); err != nil {
if err.Error() == "pg: no rows in result set" {
return nil, fmt.Errorf("没有此资源")
... ...