作者 yangfu

Merge remote-tracking branch 'origin/test' into dev

@@ -64,7 +64,7 @@ func terminalReport(cmd *command.TerminalReportCommand, transactionContext appli @@ -64,7 +64,7 @@ func terminalReport(cmd *command.TerminalReportCommand, transactionContext appli
64 log.Logger.Debug(fmt.Sprintf("【TerminalManager】 收到上行命令 command:%v table:%v content:%v", cmd.Command, cmd.Table, cmd.Content)) 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 }
@@ -238,7 +238,7 @@ func (handler ZKClockHandler) Attendance(entity AttLOGUpEntity) (DownEntity, err @@ -238,7 +238,7 @@ func (handler ZKClockHandler) Attendance(entity AttLOGUpEntity) (DownEntity, err
238 sendQuery = true 238 sendQuery = true
239 } 239 }
240 if sendQuery { 240 if sendQuery {
241 - 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)})
242 } 242 }
243 return nil, nil 243 return nil, nil
244 } 244 }
@@ -263,7 +263,7 @@ func (handler ZKClockHandler) BioData(entity BIODATAEntity) (DownEntity, error) @@ -263,7 +263,7 @@ func (handler ZKClockHandler) BioData(entity BIODATAEntity) (DownEntity, error)
263 userBase.UserInfo.FacePortrait = entity.Tmp 263 userBase.UserInfo.FacePortrait = entity.Tmp
264 updateFlag = true 264 updateFlag = true
265 if len(GlobalTerminalManager.TerminalDeviceList) >= 1 { //TODO:后期移除掉,多台设备时才进行广播 265 if len(GlobalTerminalManager.TerminalDeviceList) >= 1 { //TODO:后期移除掉,多台设备时才进行广播
266 - event.Fire(DownEntityEvent, map[string]interface{}{"entity": NewUpdateUserFacePortraitDownEntity(generateSn(), entity.Pin, entity.Tmp)}) 266 + event.Fire(DownEntityEvent, map[string]interface{}{"entity": NewUpdateUserFacePortraitDownEntity(generateSn(), entity.Pin, entity.Tmp, entity.CompanyId)})
267 } 267 }
268 } 268 }
269 // 请求 人脸识别-指纹 269 // 请求 人脸识别-指纹
@@ -271,7 +271,7 @@ func (handler ZKClockHandler) BioData(entity BIODATAEntity) (DownEntity, error) @@ -271,7 +271,7 @@ func (handler ZKClockHandler) BioData(entity BIODATAEntity) (DownEntity, error)
271 userBase.UserInfo.FingerprintPortrait = entity.Tmp 271 userBase.UserInfo.FingerprintPortrait = entity.Tmp
272 updateFlag = true 272 updateFlag = true
273 if len(GlobalTerminalManager.TerminalDeviceList) >= 1 { 273 if len(GlobalTerminalManager.TerminalDeviceList) >= 1 {
274 - event.Fire(DownEntityEvent, map[string]interface{}{"entity": NewUpdateUserFingerprintPortraitDownEntity(generateSn(), entity.Pin, entity.Tmp)}) 274 + event.Fire(DownEntityEvent, map[string]interface{}{"entity": NewUpdateUserFingerprintPortraitDownEntity(generateSn(), entity.Pin, entity.Tmp, entity.CompanyId)})
275 } 275 }
276 } 276 }
277 if updateFlag { 277 if updateFlag {
@@ -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,19 @@ func (term *TerminalManager) DownEntityEvent(e event.Event) error { @@ -79,32 +84,19 @@ 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 {
99 log.Logger.Debug("【TerminalManager】 当前用户ICCard未设置 不进行同步", map[string]interface{}{"user": user}) 91 log.Logger.Debug("【TerminalManager】 当前用户ICCard未设置 不进行同步", map[string]interface{}{"user": user})
100 return nil 92 return nil
101 } 93 }
102 term.BroadcastDownEntity(NewUpdateUserDownEntity(generateSn(), assertUser.Ext.IcCardNumber, assertUserBase.UserInfo.UserName)) 94 term.BroadcastDownEntity(NewUpdateUserDownEntity(generateSn(), assertUser.Ext.IcCardNumber, assertUserBase.UserInfo.UserName))
103 if len(assertUserBase.UserInfo.FacePortrait) > 0 { 95 if len(assertUserBase.UserInfo.FacePortrait) > 0 {
104 - term.BroadcastDownEntity(NewUpdateUserFacePortraitDownEntity(generateSn(), assertUser.Ext.IcCardNumber, assertUserBase.UserInfo.FacePortrait)) 96 + term.BroadcastDownEntity(NewUpdateUserFacePortraitDownEntity(generateSn(), assertUser.Ext.IcCardNumber, assertUserBase.UserInfo.FacePortrait, assertUser.CompanyId))
105 } 97 }
106 if len(assertUserBase.UserInfo.FingerprintPortrait) > 0 { 98 if len(assertUserBase.UserInfo.FingerprintPortrait) > 0 {
107 - term.BroadcastDownEntity(NewUpdateUserFingerprintPortraitDownEntity(generateSn(), assertUser.Ext.IcCardNumber, assertUserBase.UserInfo.FingerprintPortrait)) 99 + term.BroadcastDownEntity(NewUpdateUserFingerprintPortraitDownEntity(generateSn(), assertUser.Ext.IcCardNumber, assertUserBase.UserInfo.FingerprintPortrait, assertUser.CompanyId))
108 } 100 }
109 } 101 }
110 return nil 102 return nil
@@ -117,7 +109,7 @@ func (term *TerminalManager) EnableUser(e event.Event) error { @@ -117,7 +109,7 @@ func (term *TerminalManager) EnableUser(e event.Event) error {
117 if assertUser.EnableStatus == int(domain.UserStatusEnable) { 109 if assertUser.EnableStatus == int(domain.UserStatusEnable) {
118 term.SyncUser(e) 110 term.SyncUser(e)
119 } else if assertUser.EnableStatus == int(domain.UserStatusDisable) { 111 } else if assertUser.EnableStatus == int(domain.UserStatusDisable) {
120 - term.BroadcastDownEntity(NewDeleteDownEntity(generateSn(), assertUser.Ext.IcCardNumber, string(UserInfo))) 112 + term.BroadcastDownEntity(NewDeleteDownEntity(generateSn(), assertUser.Ext.IcCardNumber, string(UserInfo), assertUser.CompanyId))
121 } 113 }
122 } 114 }
123 return nil 115 return nil
@@ -133,12 +125,14 @@ func (term *TerminalManager) UpdateUser(e event.Event) error { @@ -133,12 +125,14 @@ func (term *TerminalManager) UpdateUser(e event.Event) error {
133 125
134 type TerminalDevice struct { 126 type TerminalDevice struct {
135 Id string 127 Id string
  128 + CompanyId int64
136 DownEntityList *list.List 129 DownEntityList *list.List
137 } 130 }
138 131
139 -func NewTerminalDevice(terminalId string) *TerminalDevice { 132 +func NewTerminalDevice(terminalId string, companyId int64) *TerminalDevice {
140 return &TerminalDevice{ 133 return &TerminalDevice{
141 Id: terminalId, 134 Id: terminalId,
  135 + CompanyId: companyId,
142 DownEntityList: list.New(), 136 DownEntityList: list.New(),
143 } 137 }
144 } 138 }
@@ -159,9 +153,25 @@ func (device *TerminalDevice) PopDownEntity() (DownEntity, bool) { @@ -159,9 +153,25 @@ func (device *TerminalDevice) PopDownEntity() (DownEntity, bool) {
159 func (device *TerminalDevice) AddDownEntity(downEntity interface{}) { 153 func (device *TerminalDevice) AddDownEntity(downEntity interface{}) {
160 v, ok := downEntity.(DownEntity) 154 v, ok := downEntity.(DownEntity)
161 var cmd string 155 var cmd string
162 - if ok {  
163 - cmd = v.DownCommand() 156 + if !ok {
  157 + return
  158 + }
  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 + }
164 } 167 }
165 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})
166 device.DownEntityList.PushBack(downEntity) 169 device.DownEntityList.PushBack(downEntity)
167 } 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,  
102 - Pin: pin, 118 + Sn: sn,
  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,