...
|
...
|
@@ -2,7 +2,9 @@ package service |
|
|
|
|
|
import (
|
|
|
"container/list"
|
|
|
"fmt"
|
|
|
"github.com/gookit/event"
|
|
|
"github.com/linmadan/egglib-go/utils/json"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/domain"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/log"
|
|
|
"sync"
|
...
|
...
|
@@ -24,12 +26,16 @@ func NewTerminalManager() *TerminalManager { |
|
|
}
|
|
|
}
|
|
|
|
|
|
func (term *TerminalManager) GetDevice(terminalId string) (*TerminalDevice, bool) {
|
|
|
func (term *TerminalManager) GetDevice(terminalId string, params ...interface{}) (*TerminalDevice, bool) {
|
|
|
device, ok := term.TerminalDevices.Load(terminalId)
|
|
|
if !ok {
|
|
|
device := NewTerminalDevice(terminalId)
|
|
|
var companyId int64
|
|
|
if len(params) > 0 {
|
|
|
companyId = params[0].(int64)
|
|
|
}
|
|
|
device := NewTerminalDevice(terminalId, companyId)
|
|
|
term.TerminalDevices.Store(terminalId, device)
|
|
|
log.Logger.Debug("【TerminalManager】 终端上线 add new device:"+terminalId, map[string]interface{}{"device": device})
|
|
|
log.Logger.Debug(fmt.Sprintf("【TerminalManager】 终端上线 add new device:%v", terminalId), map[string]interface{}{"device": device})
|
|
|
term.TerminalDeviceList = append(term.TerminalDeviceList, device)
|
|
|
return nil, false
|
|
|
}
|
...
|
...
|
@@ -38,7 +44,6 @@ func (term *TerminalManager) GetDevice(terminalId string) (*TerminalDevice, bool |
|
|
}
|
|
|
return nil, false
|
|
|
}
|
|
|
|
|
|
func (term *TerminalManager) PopDownEntityByDevice(sn string) (DownEntity, bool) {
|
|
|
device, ok := term.GetDevice(sn)
|
|
|
if !ok {
|
...
|
...
|
@@ -79,32 +84,20 @@ 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)
|
|
|
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 {
|
|
|
log.Logger.Debug("【TerminalManager】 当前用户ICCard未设置 不进行同步", map[string]interface{}{"user": user})
|
|
|
return nil
|
|
|
}
|
|
|
term.BroadcastDownEntity(NewUpdateUserDownEntity(generateSn(), assertUser.Ext.IcCardNumber, assertUserBase.UserInfo.UserName))
|
|
|
if len(assertUserBase.UserInfo.FacePortrait) > 0 {
|
|
|
term.BroadcastDownEntity(NewUpdateUserFacePortraitDownEntity(generateSn(), assertUser.Ext.IcCardNumber, assertUserBase.UserInfo.FacePortrait))
|
|
|
term.BroadcastDownEntity(NewUpdateUserFacePortraitDownEntity(generateSn(), assertUser.Ext.IcCardNumber, assertUserBase.UserInfo.FacePortrait, assertUser.CompanyId))
|
|
|
}
|
|
|
if len(assertUserBase.UserInfo.FingerprintPortrait) > 0 {
|
|
|
term.BroadcastDownEntity(NewUpdateUserFingerprintPortraitDownEntity(generateSn(), assertUser.Ext.IcCardNumber, assertUserBase.UserInfo.FingerprintPortrait))
|
|
|
term.BroadcastDownEntity(NewUpdateUserFingerprintPortraitDownEntity(generateSn(), assertUser.Ext.IcCardNumber, assertUserBase.UserInfo.FingerprintPortrait, assertUser.CompanyId))
|
|
|
}
|
|
|
term.BroadcastDownEntity(NewUpdateUserDownEntity(generateSn(), assertUser.Ext.IcCardNumber, assertUserBase.UserInfo.UserName))
|
|
|
}
|
|
|
return nil
|
|
|
}
|
...
|
...
|
@@ -116,7 +109,7 @@ func (term *TerminalManager) EnableUser(e event.Event) error { |
|
|
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)))
|
|
|
term.BroadcastDownEntity(NewDeleteDownEntity(generateSn(), assertUser.Ext.IcCardNumber, string(UserInfo), assertUser.CompanyId))
|
|
|
}
|
|
|
}
|
|
|
return nil
|
...
|
...
|
@@ -132,12 +125,14 @@ func (term *TerminalManager) UpdateUser(e event.Event) error { |
|
|
|
|
|
type TerminalDevice struct {
|
|
|
Id string
|
|
|
CompanyId int64
|
|
|
DownEntityList *list.List
|
|
|
}
|
|
|
|
|
|
func NewTerminalDevice(terminalId string) *TerminalDevice {
|
|
|
func NewTerminalDevice(terminalId string, companyId int64) *TerminalDevice {
|
|
|
return &TerminalDevice{
|
|
|
Id: terminalId,
|
|
|
CompanyId: companyId,
|
|
|
DownEntityList: list.New(),
|
|
|
}
|
|
|
}
|
...
|
...
|
@@ -158,9 +153,25 @@ func (device *TerminalDevice) PopDownEntity() (DownEntity, bool) { |
|
|
func (device *TerminalDevice) AddDownEntity(downEntity interface{}) {
|
|
|
v, ok := downEntity.(DownEntity)
|
|
|
var cmd string
|
|
|
if ok {
|
|
|
cmd = v.DownCommand()
|
|
|
if !ok {
|
|
|
return
|
|
|
}
|
|
|
cmd = v.DownCommand()
|
|
|
options := objectJsonToMap(downEntity)
|
|
|
if v, ok := options["CompanyId"]; ok {
|
|
|
companyId, ok := v.(int64)
|
|
|
if ok && device.CompanyId != companyId {
|
|
|
log.Logger.Debug("【TerminalManager】 丢弃命令(公司不匹配) cmd:"+cmd, map[string]interface{}{"entity": downEntity, "device": device})
|
|
|
return
|
|
|
}
|
|
|
}
|
|
|
log.Logger.Debug("【TerminalManager】 添加命令 add down entity to Profile cmd:"+cmd, map[string]interface{}{"entity": downEntity})
|
|
|
device.DownEntityList.PushBack(downEntity)
|
|
|
}
|
|
|
|
|
|
func objectJsonToMap(v interface{}) map[string]interface{} {
|
|
|
result := make(map[string]interface{})
|
|
|
data := json.MarshalToString(v)
|
|
|
json.UnmarshalFromString(data, &result)
|
|
|
return result
|
|
|
} |
...
|
...
|
|