正在显示
8 个修改的文件
包含
120 行增加
和
55 行删除
@@ -61,10 +61,10 @@ func terminalReport(cmd *command.TerminalReportCommand, transactionContext appli | @@ -61,10 +61,10 @@ func terminalReport(cmd *command.TerminalReportCommand, transactionContext appli | ||
61 | var ( | 61 | var ( |
62 | response string = "OK" | 62 | response string = "OK" |
63 | ) | 63 | ) |
64 | - | 64 | + log.Logger.Debug(fmt.Sprintf("【TerminalManager】 收到上行命令 command:%v table:%v content:%v", cmd.Command, cmd.Table, cmd.Content)) |
65 | switch cmd.Command { | 65 | switch cmd.Command { |
66 | case "getrequest": | 66 | case "getrequest": |
67 | - device, ok := GlobalTerminalManager.GetDevice(cmd.TerminalId) | 67 | + device, ok := GlobalTerminalManager.GetDevice(cmd.TerminalId, cmd.CompanyId) |
68 | if !ok || device == nil { | 68 | if !ok || device == nil { |
69 | break | 69 | break |
70 | } | 70 | } |
@@ -103,7 +103,6 @@ func terminalReport(cmd *command.TerminalReportCommand, transactionContext appli | @@ -103,7 +103,6 @@ func terminalReport(cmd *command.TerminalReportCommand, transactionContext appli | ||
103 | break | 103 | break |
104 | } | 104 | } |
105 | case "devicecmd": | 105 | case "devicecmd": |
106 | - log.Logger.Debug("【TerminalManager】 收到命令应答 cmd : " + cmd.Content) | ||
107 | } | 106 | } |
108 | 107 | ||
109 | return map[string]interface{}{ | 108 | return map[string]interface{}{ |
@@ -236,10 +235,10 @@ func (handler ZKClockHandler) Attendance(entity AttLOGUpEntity) (DownEntity, err | @@ -236,10 +235,10 @@ func (handler ZKClockHandler) Attendance(entity AttLOGUpEntity) (DownEntity, err | ||
236 | } | 235 | } |
237 | // 请求 人脸识别-指纹 | 236 | // 请求 人脸识别-指纹 |
238 | if len(userBase.UserInfo.FingerprintPortrait) == 0 { | 237 | if len(userBase.UserInfo.FingerprintPortrait) == 0 { |
239 | - sendQuery = true | 238 | + // sendQuery = true |
240 | } | 239 | } |
241 | if sendQuery { | 240 | if sendQuery { |
242 | - event.Fire(DownEntityEvent, map[string]interface{}{"entity": NewQueryUserInfoDownEntity(generateSn(), entity.Pin)}) | 241 | + event.Fire(DownEntityEvent, map[string]interface{}{"entity": NewQueryUserInfoDownEntity(generateSn(), entity.Pin, entity.CompanyId)}) |
243 | } | 242 | } |
244 | return nil, nil | 243 | return nil, nil |
245 | } | 244 | } |
@@ -260,14 +259,20 @@ func (handler ZKClockHandler) BioData(entity BIODATAEntity) (DownEntity, error) | @@ -260,14 +259,20 @@ func (handler ZKClockHandler) BioData(entity BIODATAEntity) (DownEntity, error) | ||
260 | return nil, err | 259 | return nil, err |
261 | } | 260 | } |
262 | // 请求 人脸识别-用户画像 | 261 | // 请求 人脸识别-用户画像 |
263 | - if len(userBase.UserInfo.FacePortrait) == 0 && len(entity.Tmp) > 0 && entity.Type == "9" { | 262 | + if len(entity.Tmp) > 0 && entity.Type == "9" { |
264 | userBase.UserInfo.FacePortrait = entity.Tmp | 263 | userBase.UserInfo.FacePortrait = entity.Tmp |
265 | updateFlag = true | 264 | updateFlag = true |
265 | + if len(GlobalTerminalManager.TerminalDeviceList) >= 1 { //TODO:后期移除掉,多台设备时才进行广播 | ||
266 | + event.Fire(DownEntityEvent, map[string]interface{}{"entity": NewUpdateUserFacePortraitDownEntity(generateSn(), entity.Pin, entity.Tmp, entity.CompanyId)}) | ||
267 | + } | ||
266 | } | 268 | } |
267 | // 请求 人脸识别-指纹 | 269 | // 请求 人脸识别-指纹 |
268 | - if len(userBase.UserInfo.FingerprintPortrait) == 0 && len(entity.Tmp) > 0 && entity.Type == "1" { | 270 | + if len(entity.Tmp) > 0 && entity.Type == "1" { |
269 | userBase.UserInfo.FingerprintPortrait = entity.Tmp | 271 | userBase.UserInfo.FingerprintPortrait = entity.Tmp |
270 | updateFlag = true | 272 | updateFlag = true |
273 | + if len(GlobalTerminalManager.TerminalDeviceList) >= 1 { | ||
274 | + event.Fire(DownEntityEvent, map[string]interface{}{"entity": NewUpdateUserFingerprintPortraitDownEntity(generateSn(), entity.Pin, entity.Tmp, entity.CompanyId)}) | ||
275 | + } | ||
271 | } | 276 | } |
272 | if updateFlag { | 277 | if updateFlag { |
273 | _, err = userBaseRepository.Save(userBase) | 278 | _, err = userBaseRepository.Save(userBase) |
@@ -2,7 +2,9 @@ package service | @@ -2,7 +2,9 @@ package service | ||
2 | 2 | ||
3 | import ( | 3 | import ( |
4 | "container/list" | 4 | "container/list" |
5 | + "fmt" | ||
5 | "github.com/gookit/event" | 6 | "github.com/gookit/event" |
7 | + "github.com/linmadan/egglib-go/utils/json" | ||
6 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/domain" | 8 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/domain" |
7 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/log" | 9 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/log" |
8 | "sync" | 10 | "sync" |
@@ -24,12 +26,16 @@ func NewTerminalManager() *TerminalManager { | @@ -24,12 +26,16 @@ func NewTerminalManager() *TerminalManager { | ||
24 | } | 26 | } |
25 | } | 27 | } |
26 | 28 | ||
27 | -func (term *TerminalManager) GetDevice(terminalId string) (*TerminalDevice, bool) { | 29 | +func (term *TerminalManager) GetDevice(terminalId string, params ...interface{}) (*TerminalDevice, bool) { |
28 | device, ok := term.TerminalDevices.Load(terminalId) | 30 | device, ok := term.TerminalDevices.Load(terminalId) |
29 | if !ok { | 31 | if !ok { |
30 | - device := NewTerminalDevice(terminalId) | 32 | + var companyId int64 |
33 | + if len(params) > 0 { | ||
34 | + companyId = params[0].(int64) | ||
35 | + } | ||
36 | + device := NewTerminalDevice(terminalId, companyId) | ||
31 | term.TerminalDevices.Store(terminalId, device) | 37 | term.TerminalDevices.Store(terminalId, device) |
32 | - log.Logger.Debug("【TerminalManager】 终端上线 add new device:"+terminalId, map[string]interface{}{"device": device}) | 38 | + log.Logger.Debug(fmt.Sprintf("【TerminalManager】 终端上线 add new device:%v", terminalId), map[string]interface{}{"device": device}) |
33 | term.TerminalDeviceList = append(term.TerminalDeviceList, device) | 39 | term.TerminalDeviceList = append(term.TerminalDeviceList, device) |
34 | return nil, false | 40 | return nil, false |
35 | } | 41 | } |
@@ -38,7 +44,6 @@ func (term *TerminalManager) GetDevice(terminalId string) (*TerminalDevice, bool | @@ -38,7 +44,6 @@ func (term *TerminalManager) GetDevice(terminalId string) (*TerminalDevice, bool | ||
38 | } | 44 | } |
39 | return nil, false | 45 | return nil, false |
40 | } | 46 | } |
41 | - | ||
42 | func (term *TerminalManager) PopDownEntityByDevice(sn string) (DownEntity, bool) { | 47 | func (term *TerminalManager) PopDownEntityByDevice(sn string) (DownEntity, bool) { |
43 | device, ok := term.GetDevice(sn) | 48 | device, ok := term.GetDevice(sn) |
44 | if !ok { | 49 | if !ok { |
@@ -79,32 +84,20 @@ func (term *TerminalManager) DownEntityEvent(e event.Event) error { | @@ -79,32 +84,20 @@ func (term *TerminalManager) DownEntityEvent(e event.Event) error { | ||
79 | func (term *TerminalManager) SyncUser(e event.Event) error { | 84 | func (term *TerminalManager) SyncUser(e event.Event) error { |
80 | user := e.Get("user") | 85 | user := e.Get("user") |
81 | userBase := e.Get("userBase") | 86 | 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 | - } | ||
91 | if user != nil && userBase != nil { | 87 | if user != nil && userBase != nil { |
92 | assertUser := user.(*domain.User) | 88 | assertUser := user.(*domain.User) |
93 | assertUserBase := userBase.(*domain.UserBase) | 89 | assertUserBase := userBase.(*domain.UserBase) |
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 { | 90 | if len(assertUser.Ext.IcCardNumber) == 0 { |
91 | + log.Logger.Debug("【TerminalManager】 当前用户ICCard未设置 不进行同步", map[string]interface{}{"user": user}) | ||
99 | return nil | 92 | return nil |
100 | } | 93 | } |
94 | + term.BroadcastDownEntity(NewUpdateUserDownEntity(generateSn(), assertUser.Ext.IcCardNumber, assertUserBase.UserInfo.UserName)) | ||
101 | if len(assertUserBase.UserInfo.FacePortrait) > 0 { | 95 | if len(assertUserBase.UserInfo.FacePortrait) > 0 { |
102 | - term.BroadcastDownEntity(NewUpdateUserFacePortraitDownEntity(generateSn(), assertUser.Ext.IcCardNumber, assertUserBase.UserInfo.FacePortrait)) | 96 | + term.BroadcastDownEntity(NewUpdateUserFacePortraitDownEntity(generateSn(), assertUser.Ext.IcCardNumber, assertUserBase.UserInfo.FacePortrait, assertUser.CompanyId)) |
103 | } | 97 | } |
104 | if len(assertUserBase.UserInfo.FingerprintPortrait) > 0 { | 98 | if len(assertUserBase.UserInfo.FingerprintPortrait) > 0 { |
105 | - term.BroadcastDownEntity(NewUpdateUserFingerprintPortraitDownEntity(generateSn(), assertUser.Ext.IcCardNumber, assertUserBase.UserInfo.FingerprintPortrait)) | 99 | + term.BroadcastDownEntity(NewUpdateUserFingerprintPortraitDownEntity(generateSn(), assertUser.Ext.IcCardNumber, assertUserBase.UserInfo.FingerprintPortrait, assertUser.CompanyId)) |
106 | } | 100 | } |
107 | - term.BroadcastDownEntity(NewUpdateUserDownEntity(generateSn(), assertUser.Ext.IcCardNumber, assertUserBase.UserInfo.UserName)) | ||
108 | } | 101 | } |
109 | return nil | 102 | return nil |
110 | } | 103 | } |
@@ -116,7 +109,7 @@ func (term *TerminalManager) EnableUser(e event.Event) error { | @@ -116,7 +109,7 @@ func (term *TerminalManager) EnableUser(e event.Event) error { | ||
116 | if assertUser.EnableStatus == int(domain.UserStatusEnable) { | 109 | if assertUser.EnableStatus == int(domain.UserStatusEnable) { |
117 | term.SyncUser(e) | 110 | term.SyncUser(e) |
118 | } else if assertUser.EnableStatus == int(domain.UserStatusDisable) { | 111 | } else if assertUser.EnableStatus == int(domain.UserStatusDisable) { |
119 | - term.BroadcastDownEntity(NewDeleteDownEntity(generateSn(), assertUser.Ext.IcCardNumber, string(UserInfo))) | 112 | + term.BroadcastDownEntity(NewDeleteDownEntity(generateSn(), assertUser.Ext.IcCardNumber, string(UserInfo), assertUser.CompanyId)) |
120 | } | 113 | } |
121 | } | 114 | } |
122 | return nil | 115 | return nil |
@@ -132,12 +125,14 @@ func (term *TerminalManager) UpdateUser(e event.Event) error { | @@ -132,12 +125,14 @@ func (term *TerminalManager) UpdateUser(e event.Event) error { | ||
132 | 125 | ||
133 | type TerminalDevice struct { | 126 | type TerminalDevice struct { |
134 | Id string | 127 | Id string |
128 | + CompanyId int64 | ||
135 | DownEntityList *list.List | 129 | DownEntityList *list.List |
136 | } | 130 | } |
137 | 131 | ||
138 | -func NewTerminalDevice(terminalId string) *TerminalDevice { | 132 | +func NewTerminalDevice(terminalId string, companyId int64) *TerminalDevice { |
139 | return &TerminalDevice{ | 133 | return &TerminalDevice{ |
140 | Id: terminalId, | 134 | Id: terminalId, |
135 | + CompanyId: companyId, | ||
141 | DownEntityList: list.New(), | 136 | DownEntityList: list.New(), |
142 | } | 137 | } |
143 | } | 138 | } |
@@ -158,9 +153,25 @@ func (device *TerminalDevice) PopDownEntity() (DownEntity, bool) { | @@ -158,9 +153,25 @@ func (device *TerminalDevice) PopDownEntity() (DownEntity, bool) { | ||
158 | func (device *TerminalDevice) AddDownEntity(downEntity interface{}) { | 153 | func (device *TerminalDevice) AddDownEntity(downEntity interface{}) { |
159 | v, ok := downEntity.(DownEntity) | 154 | v, ok := downEntity.(DownEntity) |
160 | var cmd string | 155 | var cmd string |
161 | - if ok { | 156 | + if !ok { |
157 | + return | ||
158 | + } | ||
162 | cmd = v.DownCommand() | 159 | cmd = v.DownCommand() |
160 | + options := objectJsonToMap(downEntity) | ||
161 | + if v, ok := options["CompanyId"]; ok { | ||
162 | + companyId, ok := v.(int64) | ||
163 | + if ok && device.CompanyId != companyId { | ||
164 | + log.Logger.Debug("【TerminalManager】 丢弃命令(公司不匹配) cmd:"+cmd, map[string]interface{}{"entity": downEntity, "device": device}) | ||
165 | + return | ||
166 | + } | ||
163 | } | 167 | } |
164 | log.Logger.Debug("【TerminalManager】 添加命令 add down entity to Profile cmd:"+cmd, map[string]interface{}{"entity": downEntity}) | 168 | log.Logger.Debug("【TerminalManager】 添加命令 add down entity to Profile cmd:"+cmd, map[string]interface{}{"entity": downEntity}) |
165 | device.DownEntityList.PushBack(downEntity) | 169 | device.DownEntityList.PushBack(downEntity) |
166 | } | 170 | } |
171 | + | ||
172 | +func objectJsonToMap(v interface{}) map[string]interface{} { | ||
173 | + result := make(map[string]interface{}) | ||
174 | + data := json.MarshalToString(v) | ||
175 | + json.UnmarshalFromString(data, &result) | ||
176 | + return result | ||
177 | +} |
@@ -13,6 +13,21 @@ var ( | @@ -13,6 +13,21 @@ var ( | ||
13 | BIODATA TableType = "BIODATA" //一体化数据 (人脸识别等) | 13 | BIODATA TableType = "BIODATA" //一体化数据 (人脸识别等) |
14 | ) | 14 | ) |
15 | 15 | ||
16 | +type BioDataType int | ||
17 | + | ||
18 | +var ( | ||
19 | + BioDataType0 BioDataType = 0 //通用 | ||
20 | + BioDataType1 BioDataType = 1 //指纹 | ||
21 | + BioDataType2 BioDataType = 0 //面部 | ||
22 | + BioDataType3 BioDataType = 3 //声纹 | ||
23 | + BioDataType4 BioDataType = 4 //虹膜 | ||
24 | + BioDataType5 BioDataType = 5 //视网膜 | ||
25 | + BioDataType6 BioDataType = 6 //掌纹 | ||
26 | + BioDataType7 BioDataType = 7 //指静脉 | ||
27 | + BioDataType8 BioDataType = 8 //手掌 | ||
28 | + BioDataType9 BioDataType = 9 //可见光面部 | ||
29 | +) | ||
30 | + | ||
16 | // AttLOGUpEntity 打卡记录实体 - 上行命令 | 31 | // AttLOGUpEntity 打卡记录实体 - 上行命令 |
17 | type AttLOGUpEntity struct { | 32 | type AttLOGUpEntity struct { |
18 | Pin string | 33 | Pin string |
@@ -90,39 +105,29 @@ func QueryUserInfoRequest(sn string, entity AttLOGUpEntity) string { | @@ -90,39 +105,29 @@ func QueryUserInfoRequest(sn string, entity AttLOGUpEntity) string { | ||
90 | type QueryUserInfoDownEntity struct { | 105 | type QueryUserInfoDownEntity struct { |
91 | Sn string | 106 | Sn string |
92 | Pin string | 107 | Pin string |
108 | + | ||
109 | + CompanyId int64 | ||
93 | } | 110 | } |
94 | 111 | ||
95 | func (entity QueryUserInfoDownEntity) DownCommand() string { | 112 | func (entity QueryUserInfoDownEntity) DownCommand() string { |
96 | return fmt.Sprintf("C:%v:DATA QUERY USERINFO PIN=%v", entity.Sn, entity.Pin) | 113 | return fmt.Sprintf("C:%v:DATA QUERY USERINFO PIN=%v", entity.Sn, entity.Pin) |
97 | } | 114 | } |
98 | 115 | ||
99 | -func NewQueryUserInfoDownEntity(sn string, pin string) QueryUserInfoDownEntity { | 116 | +func NewQueryUserInfoDownEntity(sn string, pin string, companyId int64) QueryUserInfoDownEntity { |
100 | return QueryUserInfoDownEntity{ | 117 | return QueryUserInfoDownEntity{ |
101 | Sn: sn, | 118 | Sn: sn, |
102 | Pin: pin, | 119 | Pin: pin, |
120 | + CompanyId: companyId, | ||
103 | } | 121 | } |
104 | } | 122 | } |
105 | 123 | ||
106 | -type BioDataType int | ||
107 | - | ||
108 | -var ( | ||
109 | - BioDataType0 BioDataType = 0 //通用 | ||
110 | - BioDataType1 BioDataType = 1 //指纹 | ||
111 | - BioDataType2 BioDataType = 0 //面部 | ||
112 | - BioDataType3 BioDataType = 3 //声纹 | ||
113 | - BioDataType4 BioDataType = 4 //虹膜 | ||
114 | - BioDataType5 BioDataType = 5 //视网膜 | ||
115 | - BioDataType6 BioDataType = 6 //掌纹 | ||
116 | - BioDataType7 BioDataType = 7 //指静脉 | ||
117 | - BioDataType8 BioDataType = 8 //手掌 | ||
118 | - BioDataType9 BioDataType = 9 //可见光面部 | ||
119 | -) | ||
120 | - | ||
121 | // QueryBioDataDownEntity 查询一体化-下行命令 | 124 | // QueryBioDataDownEntity 查询一体化-下行命令 |
122 | type QueryBioDataDownEntity struct { | 125 | type QueryBioDataDownEntity struct { |
123 | Sn string | 126 | Sn string |
124 | Pin string | 127 | Pin string |
125 | Type BioDataType | 128 | Type BioDataType |
129 | + | ||
130 | + CompanyId int64 | ||
126 | } | 131 | } |
127 | 132 | ||
128 | func (entity QueryBioDataDownEntity) DownCommand() string { | 133 | func (entity QueryBioDataDownEntity) DownCommand() string { |
@@ -142,13 +147,15 @@ type DeleteDownEntity struct { | @@ -142,13 +147,15 @@ type DeleteDownEntity struct { | ||
142 | Sn string | 147 | Sn string |
143 | Pin string | 148 | Pin string |
144 | Table string | 149 | Table string |
150 | + | ||
151 | + CompanyId int64 | ||
145 | } | 152 | } |
146 | 153 | ||
147 | func (entity DeleteDownEntity) DownCommand() string { | 154 | func (entity DeleteDownEntity) DownCommand() string { |
148 | return fmt.Sprintf("C:%v:DATA DELETE %v PIN=%v", entity.Sn, entity.Table, entity.Pin) | 155 | return fmt.Sprintf("C:%v:DATA DELETE %v PIN=%v", entity.Sn, entity.Table, entity.Pin) |
149 | } | 156 | } |
150 | 157 | ||
151 | -func NewDeleteDownEntity(sn string, pin string, t string) DeleteDownEntity { | 158 | +func NewDeleteDownEntity(sn string, pin string, t string, companyId int64) DeleteDownEntity { |
152 | return DeleteDownEntity{ | 159 | return DeleteDownEntity{ |
153 | Sn: sn, | 160 | Sn: sn, |
154 | Pin: pin, | 161 | Pin: pin, |
@@ -162,6 +169,8 @@ type UpdateUserDownEntity struct { | @@ -162,6 +169,8 @@ type UpdateUserDownEntity struct { | ||
162 | Pin string | 169 | Pin string |
163 | Name string | 170 | Name string |
164 | Card string | 171 | Card string |
172 | + | ||
173 | + CompanyId int64 | ||
165 | } | 174 | } |
166 | 175 | ||
167 | func (entity UpdateUserDownEntity) DownCommand() string { | 176 | func (entity UpdateUserDownEntity) DownCommand() string { |
@@ -181,13 +190,15 @@ type UpdateUserFacePortraitDownEntity struct { | @@ -181,13 +190,15 @@ type UpdateUserFacePortraitDownEntity struct { | ||
181 | Sn string | 190 | Sn string |
182 | Pin string | 191 | Pin string |
183 | FacePortrait string | 192 | FacePortrait string |
193 | + | ||
194 | + CompanyId int64 | ||
184 | } | 195 | } |
185 | 196 | ||
186 | func (entity UpdateUserFacePortraitDownEntity) DownCommand() string { | 197 | func (entity UpdateUserFacePortraitDownEntity) DownCommand() string { |
187 | return fmt.Sprintf("C:%v:DATA UPDATE BIODATA Pin=%v\tNo=0\tType=9\tMajorVer=39\tMinorVer=1\tFormat=0\tIndex=0\tValid=1\tDuress=0\tTmp=%v", entity.Sn, entity.Pin, entity.FacePortrait) | 198 | return fmt.Sprintf("C:%v:DATA UPDATE BIODATA Pin=%v\tNo=0\tType=9\tMajorVer=39\tMinorVer=1\tFormat=0\tIndex=0\tValid=1\tDuress=0\tTmp=%v", entity.Sn, entity.Pin, entity.FacePortrait) |
188 | } | 199 | } |
189 | 200 | ||
190 | -func NewUpdateUserFacePortraitDownEntity(sn string, pin string, facePortrait string) UpdateUserFacePortraitDownEntity { | 201 | +func NewUpdateUserFacePortraitDownEntity(sn string, pin string, facePortrait string, companyId int64) UpdateUserFacePortraitDownEntity { |
191 | return UpdateUserFacePortraitDownEntity{ | 202 | return UpdateUserFacePortraitDownEntity{ |
192 | Sn: sn, | 203 | Sn: sn, |
193 | Pin: pin, | 204 | Pin: pin, |
@@ -200,13 +211,15 @@ type UpdateUserFingerprintPortraitDownEntity struct { | @@ -200,13 +211,15 @@ type UpdateUserFingerprintPortraitDownEntity struct { | ||
200 | Sn string | 211 | Sn string |
201 | Pin string | 212 | Pin string |
202 | FingerprintPortrait string | 213 | FingerprintPortrait string |
214 | + | ||
215 | + CompanyId int64 | ||
203 | } | 216 | } |
204 | 217 | ||
205 | func (entity UpdateUserFingerprintPortraitDownEntity) DownCommand() string { | 218 | func (entity UpdateUserFingerprintPortraitDownEntity) DownCommand() string { |
206 | return fmt.Sprintf("C:%v:DATA UPDATE FINGERTMP PIN=%v\tFID=5\tSize=%v\tValid=1\tTMP=%v", entity.Sn, entity.Pin, len([]byte(entity.FingerprintPortrait)), entity.FingerprintPortrait) | 219 | return fmt.Sprintf("C:%v:DATA UPDATE FINGERTMP PIN=%v\tFID=5\tSize=%v\tValid=1\tTMP=%v", entity.Sn, entity.Pin, len([]byte(entity.FingerprintPortrait)), entity.FingerprintPortrait) |
207 | } | 220 | } |
208 | 221 | ||
209 | -func NewUpdateUserFingerprintPortraitDownEntity(sn string, pin string, fingerprintPortrait string) UpdateUserFingerprintPortraitDownEntity { | 222 | +func NewUpdateUserFingerprintPortraitDownEntity(sn string, pin string, fingerprintPortrait string, companyId int64) UpdateUserFingerprintPortraitDownEntity { |
210 | return UpdateUserFingerprintPortraitDownEntity{ | 223 | return UpdateUserFingerprintPortraitDownEntity{ |
211 | Sn: sn, | 224 | Sn: sn, |
212 | Pin: pin, | 225 | Pin: pin, |
@@ -11,7 +11,7 @@ import ( | @@ -11,7 +11,7 @@ import ( | ||
11 | type SyncToAttendanceMachineCommand struct { | 11 | type SyncToAttendanceMachineCommand struct { |
12 | OperateInfo *domain.OperateInfo `json:"-"` | 12 | OperateInfo *domain.OperateInfo `json:"-"` |
13 | // 用户关联的角色 | 13 | // 用户关联的角色 |
14 | - Users []int64 `cname:"用户关联的角色" json:"userIds" valid:"Required"` | 14 | + Users []string `cname:"用户关联的角色" json:"userIds"` |
15 | } | 15 | } |
16 | 16 | ||
17 | func (syncToAttendance *SyncToAttendanceMachineCommand) Valid(validation *validation.Validation) { | 17 | func (syncToAttendance *SyncToAttendanceMachineCommand) Valid(validation *validation.Validation) { |
@@ -6,6 +6,7 @@ import ( | @@ -6,6 +6,7 @@ import ( | ||
6 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/application/factory" | 6 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/application/factory" |
7 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/application/user/command" | 7 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/application/user/command" |
8 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/domain" | 8 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/domain" |
9 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/infrastructure/utils" | ||
9 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/log" | 10 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/log" |
10 | ) | 11 | ) |
11 | 12 | ||
@@ -24,11 +25,24 @@ func (userService *UserService) SyncToAttendanceMachine(cmd *command.SyncToAtten | @@ -24,11 +25,24 @@ func (userService *UserService) SyncToAttendanceMachine(cmd *command.SyncToAtten | ||
24 | transactionContext.RollbackTransaction() | 25 | transactionContext.RollbackTransaction() |
25 | }() | 26 | }() |
26 | userRepository, _, _ := factory.FastPgUser(transactionContext, 0) | 27 | userRepository, _, _ := factory.FastPgUser(transactionContext, 0) |
27 | - | ||
28 | - _, users, err := userRepository.Find(map[string]interface{}{"companyId": cmd.OperateInfo.CompanyId, "inUserIds": cmd.Users}) | 28 | + //orgRepository, _, _ := factory.FastPgOrg(transactionContext, 0) |
29 | + var users []*domain.User | ||
30 | + // 指定用户进行同步 | ||
31 | + if len(cmd.Users) > 0 { | ||
32 | + _, users, err = userRepository.Find(map[string]interface{}{"companyId": cmd.OperateInfo.CompanyId, "inUserIds": utils.ToArrayInt64(cmd.Users)}) | ||
29 | if err != nil { | 33 | if err != nil { |
30 | return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error()) | 34 | return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error()) |
31 | } | 35 | } |
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, "icCardNumberNotEqual": ""}) | ||
42 | + if err != nil { | ||
43 | + return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error()) | ||
44 | + } | ||
45 | + } | ||
32 | 46 | ||
33 | for i := range users { | 47 | for i := range users { |
34 | _, userBase, err := factory.FastPgUserBase(transactionContext, users[i].UserBaseId) | 48 | _, userBase, err := factory.FastPgUserBase(transactionContext, users[i].UserBaseId) |
@@ -102,18 +102,25 @@ func (userService *UserService) BatchEnable(batchEnableCommand *command.BatchEna | @@ -102,18 +102,25 @@ func (userService *UserService) BatchEnable(batchEnableCommand *command.BatchEna | ||
102 | } | 102 | } |
103 | 103 | ||
104 | for i := 0; i < len(batchEnableCommand.UserIds); i++ { | 104 | for i := 0; i < len(batchEnableCommand.UserIds); i++ { |
105 | - if user, err := userRepository.FindOne(map[string]interface{}{"userId": batchEnableCommand.UserIds[i]}); err != nil { | 105 | + var ( |
106 | + user *domain.User | ||
107 | + userBase *domain.UserBase | ||
108 | + ) | ||
109 | + user, err = userRepository.FindOne(map[string]interface{}{"userId": batchEnableCommand.UserIds[i]}) | ||
110 | + if err != nil { | ||
106 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | 111 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) |
107 | - } else { | 112 | + } |
108 | if err := user.SetEnableStatus(batchEnableCommand.EnableStatus); err != nil { | 113 | if err := user.SetEnableStatus(batchEnableCommand.EnableStatus); err != nil { |
109 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | 114 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) |
110 | } | 115 | } |
111 | if _, err := userRepository.Save(user); err != nil { | 116 | if _, err := userRepository.Save(user); err != nil { |
112 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | 117 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) |
113 | } | 118 | } |
114 | - if err, _ := event.Fire(domain.UserEnableEvent, map[string]interface{}{"user": user}); err != nil { | 119 | + if _, userBase, err = factory.FastPgUserBase(transactionContext, user.UserBaseId); err != nil { |
115 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | 120 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) |
116 | } | 121 | } |
122 | + if err, _ := event.Fire(domain.UserEnableEvent, map[string]interface{}{"user": user, "userBase": userBase}); err != nil { | ||
123 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
117 | } | 124 | } |
118 | } | 125 | } |
119 | 126 |
@@ -213,6 +213,9 @@ func (repository *UserRepository) Find(queryOptions map[string]interface{}) (int | @@ -213,6 +213,9 @@ func (repository *UserRepository) Find(queryOptions map[string]interface{}) (int | ||
213 | if v, ok := queryOptions["inCompanyIds"]; ok && len(v.([]int64)) > 0 { | 213 | if v, ok := queryOptions["inCompanyIds"]; ok && len(v.([]int64)) > 0 { |
214 | query.Where(`company_id in (?)`, pg.In(v)) | 214 | query.Where(`company_id in (?)`, pg.In(v)) |
215 | } | 215 | } |
216 | + if v, ok := queryOptions["inDepartmentIds"]; ok && len(v.([]int64)) > 0 { | ||
217 | + query.Where(`department_id in (?)`, pg.In(v)) | ||
218 | + } | ||
216 | query.SetWhereByQueryOption("user_code = ?", "userCode") | 219 | query.SetWhereByQueryOption("user_code = ?", "userCode") |
217 | query.SetWhereByQueryOption("ext->>'icCardNumber' = ?", "icCardNumber") | 220 | query.SetWhereByQueryOption("ext->>'icCardNumber' = ?", "icCardNumber") |
218 | query.SetWhereByQueryOption("user_base_id=?", "userBaseId") | 221 | query.SetWhereByQueryOption("user_base_id=?", "userBaseId") |
@@ -234,6 +237,9 @@ func (repository *UserRepository) Find(queryOptions map[string]interface{}) (int | @@ -234,6 +237,9 @@ func (repository *UserRepository) Find(queryOptions map[string]interface{}) (int | ||
234 | if v, ok := queryOptions["cooperationCompany"]; ok && len(v.(string)) > 0 { | 237 | if v, ok := queryOptions["cooperationCompany"]; ok && len(v.(string)) > 0 { |
235 | query.Where(fmt.Sprintf(`cooperation_info->>'cooperationCompany' like '%%%v%%'`, v)) | 238 | query.Where(fmt.Sprintf(`cooperation_info->>'cooperationCompany' like '%%%v%%'`, v)) |
236 | } | 239 | } |
240 | + if _, ok := queryOptions["icCardNumberNotEqual"]; ok { | ||
241 | + query.Where(fmt.Sprintf(`ext->>'icCardNumber' <> '%v'`, "")) | ||
242 | + } | ||
237 | query.SetOffsetAndLimit(domain.MaxQueryRow) | 243 | query.SetOffsetAndLimit(domain.MaxQueryRow) |
238 | query.SetOrderDirect("user_id", "DESC") | 244 | query.SetOrderDirect("user_id", "DESC") |
239 | if count, err := query.SelectAndCount(); err != nil { | 245 | if count, err := query.SelectAndCount(); err != nil { |
@@ -262,3 +262,12 @@ func CopyObject(src, dst interface{}) { | @@ -262,3 +262,12 @@ func CopyObject(src, dst interface{}) { | ||
262 | } | 262 | } |
263 | } | 263 | } |
264 | } | 264 | } |
265 | + | ||
266 | +func ToArrayInt64(inputs []string) []int64 { | ||
267 | + result := make([]int64, 0) | ||
268 | + for i := range inputs { | ||
269 | + v, _ := strconv.ParseInt(inputs[i], 10, 64) | ||
270 | + result = append(result, v) | ||
271 | + } | ||
272 | + return result | ||
273 | +} |
-
请 注册 或 登录 后发表评论