作者 yangfu

refactor: 优化数据同步

... ... @@ -79,23 +79,24 @@ func (term *TerminalManager) DownEntityEvent(e event.Event) error {
func (term *TerminalManager) SyncUser(e event.Event) error {
user := e.Get("user")
userBase := e.Get("userBase")
if user != nil && userBase == nil {
assertUser := user.(*domain.User)
if assertUser.Ext.DepName != "制造中心" {
log.Logger.Debug("【TerminalManager】 当前用户部门不是 [制造中心] 不进行同步", map[string]interface{}{"user": user})
return nil
}
term.BroadcastDownEntity(NewUpdateUserDownEntity(generateSn(), assertUser.Ext.IcCardNumber, assertUser.Ext.UserName))
return nil
}
//if user != nil && userBase == nil {
// assertUser := user.(*domain.User)
// if assertUser.Ext.DepName != "制造中心" {
// log.Logger.Debug("【TerminalManager】 当前用户部门不是 [制造中心] 不进行同步", map[string]interface{}{"user": user})
// return nil
// }
// term.BroadcastDownEntity(NewUpdateUserDownEntity(generateSn(), assertUser.Ext.IcCardNumber, assertUser.Ext.UserName))
// return nil
//}
if user != nil && userBase != nil {
assertUser := user.(*domain.User)
assertUserBase := userBase.(*domain.UserBase)
if assertUser.Ext.DepName != "制造中心" {
log.Logger.Debug("【TerminalManager】 当前用户部门不是 [制造中心] 不进行同步", map[string]interface{}{"user": user})
return nil
}
//if assertUser.Ext.DepName != "制造中心" {
// log.Logger.Debug("【TerminalManager】 当前用户部门不是 [制造中心] 不进行同步", map[string]interface{}{"user": user})
// return nil
//}
if len(assertUser.Ext.IcCardNumber) == 0 {
log.Logger.Debug("【TerminalManager】 当前用户ICCard未设置 不进行同步", map[string]interface{}{"user": user})
return nil
}
term.BroadcastDownEntity(NewUpdateUserDownEntity(generateSn(), assertUser.Ext.IcCardNumber, assertUserBase.UserInfo.UserName))
... ...
... ... @@ -25,7 +25,7 @@ func (userService *UserService) SyncToAttendanceMachine(cmd *command.SyncToAtten
transactionContext.RollbackTransaction()
}()
userRepository, _, _ := factory.FastPgUser(transactionContext, 0)
orgRepository, _, _ := factory.FastPgOrg(transactionContext, 0)
//orgRepository, _, _ := factory.FastPgOrg(transactionContext, 0)
var users []*domain.User
// 指定用户进行同步
if len(cmd.Users) > 0 {
... ... @@ -34,11 +34,11 @@ func (userService *UserService) SyncToAttendanceMachine(cmd *command.SyncToAtten
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
} else {
org, _ := orgRepository.FindOne(map[string]interface{}{"companyId": cmd.OperateInfo.CompanyId, "orgName": "制造中心"})
if org == nil {
return nil, nil
}
_, users, err = userRepository.Find(map[string]interface{}{"companyId": cmd.OperateInfo.CompanyId, "inDepartmentIds": []int64{org.OrgId}})
//org, _ := orgRepository.FindOne(map[string]interface{}{"companyId": cmd.OperateInfo.CompanyId, "orgName": "制造中心"})
//if org == nil {
// return nil, nil
//}
_, users, err = userRepository.Find(map[string]interface{}{"companyId": cmd.OperateInfo.CompanyId, "icCardNumberNotEqual": ""})
if err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
... ...
... ... @@ -237,6 +237,9 @@ func (repository *UserRepository) Find(queryOptions map[string]interface{}) (int
if v, ok := queryOptions["cooperationCompany"]; ok && len(v.(string)) > 0 {
query.Where(fmt.Sprintf(`cooperation_info->>'cooperationCompany' like '%%%v%%'`, v))
}
if _, ok := queryOptions["icCardNumberNotEqual"]; ok {
query.Where(fmt.Sprintf(`ext->>'icCardNumber' <> '%v'`, ""))
}
query.SetOffsetAndLimit(domain.MaxQueryRow)
query.SetOrderDirect("user_id", "DESC")
if count, err := query.SelectAndCount(); err != nil {
... ...