...
|
...
|
@@ -3,6 +3,7 @@ package service |
|
|
import (
|
|
|
"container/list"
|
|
|
"github.com/gookit/event"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/domain"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/log"
|
|
|
"sync"
|
|
|
)
|
...
|
...
|
@@ -28,7 +29,7 @@ func (term *TerminalManager) GetDevice(terminalId string) (*TerminalDevice, bool |
|
|
if !ok {
|
|
|
device := NewTerminalDevice(terminalId)
|
|
|
term.TerminalDevices.Store(terminalId, device)
|
|
|
log.Logger.Debug("【TerminalManager】 add new device:"+terminalId, map[string]interface{}{"device": device})
|
|
|
log.Logger.Debug("【TerminalManager】 终端上线 add new device:"+terminalId, map[string]interface{}{"device": device})
|
|
|
term.TerminalDeviceList = append(term.TerminalDeviceList, device)
|
|
|
return nil, false
|
|
|
}
|
...
|
...
|
@@ -56,6 +57,10 @@ func (term *TerminalManager) AddDownEntityByDevice(sn string, entity interface{} |
|
|
}
|
|
|
|
|
|
func (term *TerminalManager) BroadcastDownEntity(downEntity interface{}) {
|
|
|
if len(term.TerminalDeviceList) == 0 {
|
|
|
log.Logger.Debug("【TerminalManager】 当前在线终端:0 广播命令退出")
|
|
|
return
|
|
|
}
|
|
|
for i := range term.TerminalDeviceList {
|
|
|
term.TerminalDeviceList[i].AddDownEntity(downEntity)
|
|
|
}
|
...
|
...
|
@@ -64,7 +69,6 @@ func (term *TerminalManager) BroadcastDownEntity(downEntity interface{}) { |
|
|
// Listen Event
|
|
|
|
|
|
func (term *TerminalManager) DownEntityEvent(e event.Event) error {
|
|
|
//fmt.Printf("handle down entity event: %s\n", e.Name())
|
|
|
entity := e.Get("entity")
|
|
|
if entity != nil {
|
|
|
term.BroadcastDownEntity(entity)
|
...
|
...
|
@@ -72,6 +76,60 @@ func (term *TerminalManager) DownEntityEvent(e event.Event) error { |
|
|
return nil
|
|
|
}
|
|
|
|
|
|
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)
|
|
|
assertUserBase := userBase.(*domain.UserBase)
|
|
|
if assertUser.Ext.DepName != "制造中心" {
|
|
|
log.Logger.Debug("【TerminalManager】 当前用户部门不是 [制造中心] 不进行同步", map[string]interface{}{"user": user})
|
|
|
return nil
|
|
|
}
|
|
|
if len(assertUser.Ext.IcCardNumber) == 0 {
|
|
|
return nil
|
|
|
}
|
|
|
if len(assertUserBase.UserInfo.FacePortrait) > 0 {
|
|
|
term.BroadcastDownEntity(NewUpdateUserFacePortraitDownEntity(generateSn(), assertUser.Ext.IcCardNumber, assertUserBase.UserInfo.FacePortrait))
|
|
|
}
|
|
|
if len(assertUserBase.UserInfo.FingerprintPortrait) > 0 {
|
|
|
term.BroadcastDownEntity(NewUpdateUserFingerprintPortraitDownEntity(generateSn(), assertUser.Ext.IcCardNumber, assertUserBase.UserInfo.FingerprintPortrait))
|
|
|
}
|
|
|
term.BroadcastDownEntity(NewUpdateUserDownEntity(generateSn(), assertUser.Ext.IcCardNumber, assertUserBase.UserInfo.UserName))
|
|
|
}
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
func (term *TerminalManager) EnableUser(e event.Event) error {
|
|
|
user := e.Get("user")
|
|
|
if user != nil {
|
|
|
assertUser := user.(*domain.User)
|
|
|
if assertUser.EnableStatus == int(domain.UserStatusEnable) {
|
|
|
term.SyncUser(e)
|
|
|
} else if assertUser.EnableStatus == int(domain.UserStatusDisable) {
|
|
|
term.BroadcastDownEntity(NewDeleteDownEntity(generateSn(), assertUser.Ext.IcCardNumber, string(UserInfo)))
|
|
|
}
|
|
|
}
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
func (term *TerminalManager) CreateUser(e event.Event) error {
|
|
|
return term.SyncUser(e)
|
|
|
}
|
|
|
|
|
|
func (term *TerminalManager) UpdateUser(e event.Event) error {
|
|
|
return term.EnableUser(e)
|
|
|
}
|
|
|
|
|
|
type TerminalDevice struct {
|
|
|
Id string
|
|
|
DownEntityList *list.List
|
...
|
...
|
@@ -91,13 +149,18 @@ func (device *TerminalDevice) PopDownEntity() (DownEntity, bool) { |
|
|
}
|
|
|
device.DownEntityList.Remove(element)
|
|
|
if v, ok := element.Value.(DownEntity); ok {
|
|
|
log.Logger.Debug("【TerminalManager】 pop down entity to Sender", map[string]interface{}{"entity": v})
|
|
|
log.Logger.Debug("【TerminalManager】 发送命令 pop down entity to Sender cmd:"+v.DownCommand(), map[string]interface{}{"entity": v})
|
|
|
return v, ok
|
|
|
}
|
|
|
return nil, false
|
|
|
}
|
|
|
|
|
|
func (device *TerminalDevice) AddDownEntity(downEntity interface{}) {
|
|
|
log.Logger.Debug("【TerminalManager】 add down entity to Profile", map[string]interface{}{"entity": downEntity})
|
|
|
v, ok := downEntity.(DownEntity)
|
|
|
var cmd string
|
|
|
if ok {
|
|
|
cmd = v.DownCommand()
|
|
|
}
|
|
|
log.Logger.Debug("【TerminalManager】 添加命令 add down entity to Profile cmd:"+cmd, map[string]interface{}{"entity": downEntity})
|
|
|
device.DownEntityList.PushBack(downEntity)
|
|
|
} |
...
|
...
|
|