作者 yangfu

refactor: 优化数据同步

@@ -79,23 +79,24 @@ func (term *TerminalManager) DownEntityEvent(e event.Event) error { @@ -79,23 +79,24 @@ func (term *TerminalManager) DownEntityEvent(e event.Event) error {
79 func (term *TerminalManager) SyncUser(e event.Event) error { 79 func (term *TerminalManager) SyncUser(e event.Event) error {
80 user := e.Get("user") 80 user := e.Get("user")
81 userBase := e.Get("userBase") 81 userBase := e.Get("userBase")
82 - if user != nil && userBase == nil {  
83 - assertUser := user.(*domain.User)  
84 - if assertUser.Ext.DepName != "制造中心" {  
85 - log.Logger.Debug("【TerminalManager】 当前用户部门不是 [制造中心] 不进行同步", map[string]interface{}{"user": user})  
86 - return nil  
87 - }  
88 - term.BroadcastDownEntity(NewUpdateUserDownEntity(generateSn(), assertUser.Ext.IcCardNumber, assertUser.Ext.UserName))  
89 - return nil  
90 - } 82 + //if user != nil && userBase == nil {
  83 + // assertUser := user.(*domain.User)
  84 + // if assertUser.Ext.DepName != "制造中心" {
  85 + // log.Logger.Debug("【TerminalManager】 当前用户部门不是 [制造中心] 不进行同步", map[string]interface{}{"user": user})
  86 + // return nil
  87 + // }
  88 + // term.BroadcastDownEntity(NewUpdateUserDownEntity(generateSn(), assertUser.Ext.IcCardNumber, assertUser.Ext.UserName))
  89 + // return nil
  90 + //}
91 if user != nil && userBase != nil { 91 if user != nil && userBase != nil {
92 assertUser := user.(*domain.User) 92 assertUser := user.(*domain.User)
93 assertUserBase := userBase.(*domain.UserBase) 93 assertUserBase := userBase.(*domain.UserBase)
94 - if assertUser.Ext.DepName != "制造中心" {  
95 - log.Logger.Debug("【TerminalManager】 当前用户部门不是 [制造中心] 不进行同步", map[string]interface{}{"user": user})  
96 - return nil  
97 - } 94 + //if assertUser.Ext.DepName != "制造中心" {
  95 + // log.Logger.Debug("【TerminalManager】 当前用户部门不是 [制造中心] 不进行同步", map[string]interface{}{"user": user})
  96 + // return nil
  97 + //}
98 if len(assertUser.Ext.IcCardNumber) == 0 { 98 if len(assertUser.Ext.IcCardNumber) == 0 {
  99 + log.Logger.Debug("【TerminalManager】 当前用户ICCard未设置 不进行同步", map[string]interface{}{"user": user})
99 return nil 100 return nil
100 } 101 }
101 term.BroadcastDownEntity(NewUpdateUserDownEntity(generateSn(), assertUser.Ext.IcCardNumber, assertUserBase.UserInfo.UserName)) 102 term.BroadcastDownEntity(NewUpdateUserDownEntity(generateSn(), assertUser.Ext.IcCardNumber, assertUserBase.UserInfo.UserName))
@@ -25,7 +25,7 @@ func (userService *UserService) SyncToAttendanceMachine(cmd *command.SyncToAtten @@ -25,7 +25,7 @@ func (userService *UserService) SyncToAttendanceMachine(cmd *command.SyncToAtten
25 transactionContext.RollbackTransaction() 25 transactionContext.RollbackTransaction()
26 }() 26 }()
27 userRepository, _, _ := factory.FastPgUser(transactionContext, 0) 27 userRepository, _, _ := factory.FastPgUser(transactionContext, 0)
28 - orgRepository, _, _ := factory.FastPgOrg(transactionContext, 0) 28 + //orgRepository, _, _ := factory.FastPgOrg(transactionContext, 0)
29 var users []*domain.User 29 var users []*domain.User
30 // 指定用户进行同步 30 // 指定用户进行同步
31 if len(cmd.Users) > 0 { 31 if len(cmd.Users) > 0 {
@@ -34,11 +34,11 @@ func (userService *UserService) SyncToAttendanceMachine(cmd *command.SyncToAtten @@ -34,11 +34,11 @@ func (userService *UserService) SyncToAttendanceMachine(cmd *command.SyncToAtten
34 return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error()) 34 return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
35 } 35 }
36 } else { 36 } else {
37 - org, _ := orgRepository.FindOne(map[string]interface{}{"companyId": cmd.OperateInfo.CompanyId, "orgName": "制造中心"})  
38 - if org == nil {  
39 - return nil, nil  
40 - }  
41 - _, users, err = userRepository.Find(map[string]interface{}{"companyId": cmd.OperateInfo.CompanyId, "inDepartmentIds": []int64{org.OrgId}}) 37 + //org, _ := orgRepository.FindOne(map[string]interface{}{"companyId": cmd.OperateInfo.CompanyId, "orgName": "制造中心"})
  38 + //if org == nil {
  39 + // return nil, nil
  40 + //}
  41 + _, users, err = userRepository.Find(map[string]interface{}{"companyId": cmd.OperateInfo.CompanyId, "icCardNumberNotEqual": ""})
42 if err != nil { 42 if err != nil {
43 return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error()) 43 return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
44 } 44 }
@@ -237,6 +237,9 @@ func (repository *UserRepository) Find(queryOptions map[string]interface{}) (int @@ -237,6 +237,9 @@ func (repository *UserRepository) Find(queryOptions map[string]interface{}) (int
237 if v, ok := queryOptions["cooperationCompany"]; ok && len(v.(string)) > 0 { 237 if v, ok := queryOptions["cooperationCompany"]; ok && len(v.(string)) > 0 {
238 query.Where(fmt.Sprintf(`cooperation_info->>'cooperationCompany' like '%%%v%%'`, v)) 238 query.Where(fmt.Sprintf(`cooperation_info->>'cooperationCompany' like '%%%v%%'`, v))
239 } 239 }
  240 + if _, ok := queryOptions["icCardNumberNotEqual"]; ok {
  241 + query.Where(fmt.Sprintf(`ext->>'icCardNumber' <> '%v'`, ""))
  242 + }
240 query.SetOffsetAndLimit(domain.MaxQueryRow) 243 query.SetOffsetAndLimit(domain.MaxQueryRow)
241 query.SetOrderDirect("user_id", "DESC") 244 query.SetOrderDirect("user_id", "DESC")
242 if count, err := query.SelectAndCount(); err != nil { 245 if count, err := query.SelectAndCount(); err != nil {