正在显示
14 个修改的文件
包含
251 行增加
和
85 行删除
@@ -4,7 +4,6 @@ go 1.16 | @@ -4,7 +4,6 @@ go 1.16 | ||
4 | 4 | ||
5 | require ( | 5 | require ( |
6 | github.com/ajg/form v1.5.1 // indirect | 6 | github.com/ajg/form v1.5.1 // indirect |
7 | - github.com/axgle/mahonia v0.0.0-20180208002826-3358181d7394 | ||
8 | github.com/beego/beego/v2 v2.0.1 | 7 | github.com/beego/beego/v2 v2.0.1 |
9 | github.com/emirpasic/gods v1.12.0 | 8 | github.com/emirpasic/gods v1.12.0 |
10 | github.com/fasthttp-contrib/websocket v0.0.0-20160511215533-1f3b11f56072 // indirect | 9 | github.com/fasthttp-contrib/websocket v0.0.0-20160511215533-1f3b11f56072 // indirect |
@@ -21,8 +21,6 @@ github.com/alicebob/miniredis v2.5.0+incompatible/go.mod h1:8HZjEj4yU0dwhYHky+Dx | @@ -21,8 +21,6 @@ github.com/alicebob/miniredis v2.5.0+incompatible/go.mod h1:8HZjEj4yU0dwhYHky+Dx | ||
21 | github.com/andybalholm/brotli v1.0.1 h1:KqhlKozYbRtJvsPrrEeXcO+N2l6NYT5A2QAFmSULpEc= | 21 | github.com/andybalholm/brotli v1.0.1 h1:KqhlKozYbRtJvsPrrEeXcO+N2l6NYT5A2QAFmSULpEc= |
22 | github.com/andybalholm/brotli v1.0.1/go.mod h1:loMXtMfwqflxFJPmdbJO0a3KNoPuLBgiu3qAvBg8x/Y= | 22 | github.com/andybalholm/brotli v1.0.1/go.mod h1:loMXtMfwqflxFJPmdbJO0a3KNoPuLBgiu3qAvBg8x/Y= |
23 | github.com/antihax/optional v0.0.0-20180407024304-ca021399b1a6/go.mod h1:V8iCPQYkqmusNa815XgQio277wI47sdRh1dUOLdyC6Q= | 23 | github.com/antihax/optional v0.0.0-20180407024304-ca021399b1a6/go.mod h1:V8iCPQYkqmusNa815XgQio277wI47sdRh1dUOLdyC6Q= |
24 | -github.com/axgle/mahonia v0.0.0-20180208002826-3358181d7394 h1:OYA+5W64v3OgClL+IrOD63t4i/RW7RqrAVl9LTZ9UqQ= | ||
25 | -github.com/axgle/mahonia v0.0.0-20180208002826-3358181d7394/go.mod h1:Q8n74mJTIgjX4RBBcHnJ05h//6/k6foqmgE45jTQtxg= | ||
26 | github.com/beanstalkd/go-beanstalk v0.1.0/go.mod h1:/G8YTyChOtpOArwLTQPY1CHB+i212+av35bkPXXj56Y= | 24 | github.com/beanstalkd/go-beanstalk v0.1.0/go.mod h1:/G8YTyChOtpOArwLTQPY1CHB+i212+av35bkPXXj56Y= |
27 | github.com/beego/beego/v2 v2.0.1 h1:07a7Z0Ok5vbqyqh+q53sDPl9LdhKh0ZDy3gbyGrhFnE= | 25 | github.com/beego/beego/v2 v2.0.1 h1:07a7Z0Ok5vbqyqh+q53sDPl9LdhKh0ZDy3gbyGrhFnE= |
28 | github.com/beego/beego/v2 v2.0.1/go.mod h1:8zyHi1FnWO1mZLwTn62aKRIZF/aIKvkCBB2JYs+eqQI= | 26 | github.com/beego/beego/v2 v2.0.1/go.mod h1:8zyHi1FnWO1mZLwTn62aKRIZF/aIKvkCBB2JYs+eqQI= |
@@ -312,8 +310,6 @@ github.com/prometheus/procfs v0.0.2/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsT | @@ -312,8 +310,6 @@ github.com/prometheus/procfs v0.0.2/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsT | ||
312 | github.com/prometheus/procfs v0.0.8/go.mod h1:7Qr8sr6344vo1JqZ6HhLceV9o3AJ1Ff+GxbHq6oeK9A= | 310 | github.com/prometheus/procfs v0.0.8/go.mod h1:7Qr8sr6344vo1JqZ6HhLceV9o3AJ1Ff+GxbHq6oeK9A= |
313 | github.com/prometheus/procfs v0.1.3 h1:F0+tqvhOksq22sc6iCHF5WGlWjdwj92p0udFh1VFBS8= | 311 | github.com/prometheus/procfs v0.1.3 h1:F0+tqvhOksq22sc6iCHF5WGlWjdwj92p0udFh1VFBS8= |
314 | github.com/prometheus/procfs v0.1.3/go.mod h1:lV6e/gmhEcM9IjHGsFOCxxuZ+z1YqCvr4OA4YeYWdaU= | 312 | github.com/prometheus/procfs v0.1.3/go.mod h1:lV6e/gmhEcM9IjHGsFOCxxuZ+z1YqCvr4OA4YeYWdaU= |
315 | -github.com/qiniu/iconv v1.2.0 h1:2LJKwoF+4LJ3lNM+7cE3P1kNQzAI/HMZuWhkmFoY2U8= | ||
316 | -github.com/qiniu/iconv v1.2.0/go.mod h1:5bxb2h9lptZt2eHLgY+Jw4X06TMtKb6tvvok0DwSwGA= | ||
317 | github.com/rcrowley/go-metrics v0.0.0-20181016184325-3113b8401b8a h1:9ZKAASQSHhDYGoxY8uLVpewe1GDZ2vu2Tr/vTdVAkFQ= | 313 | github.com/rcrowley/go-metrics v0.0.0-20181016184325-3113b8401b8a h1:9ZKAASQSHhDYGoxY8uLVpewe1GDZ2vu2Tr/vTdVAkFQ= |
318 | github.com/rcrowley/go-metrics v0.0.0-20181016184325-3113b8401b8a/go.mod h1:bCqnVzQkZxMG4s8nGwiZ5l3QUCyqpo9Y+/ZMZ9VjZe4= | 314 | github.com/rcrowley/go-metrics v0.0.0-20181016184325-3113b8401b8a/go.mod h1:bCqnVzQkZxMG4s8nGwiZ5l3QUCyqpo9Y+/ZMZ9VjZe4= |
319 | github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg= | 315 | github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg= |
@@ -3,7 +3,6 @@ package service | @@ -3,7 +3,6 @@ package service | ||
3 | import ( | 3 | import ( |
4 | "bytes" | 4 | "bytes" |
5 | "fmt" | 5 | "fmt" |
6 | - "github.com/axgle/mahonia" | ||
7 | "github.com/beego/beego/v2/adapter/utils" | 6 | "github.com/beego/beego/v2/adapter/utils" |
8 | "github.com/gookit/event" | 7 | "github.com/gookit/event" |
9 | "github.com/linmadan/egglib-go/core/application" | 8 | "github.com/linmadan/egglib-go/core/application" |
@@ -18,26 +17,10 @@ var GlobalTerminalManager *TerminalManager | @@ -18,26 +17,10 @@ var GlobalTerminalManager *TerminalManager | ||
18 | 17 | ||
19 | func init() { | 18 | func init() { |
20 | GlobalTerminalManager = NewTerminalManager() | 19 | GlobalTerminalManager = NewTerminalManager() |
21 | - event.On(domain.UserCreateEvent, event.ListenerFunc(func(e event.Event) error { | ||
22 | - | ||
23 | - return nil | ||
24 | - })) | ||
25 | - event.On(domain.UserUpdateEvent, event.ListenerFunc(func(e event.Event) error { | ||
26 | - | ||
27 | - return nil | ||
28 | - })) | ||
29 | - event.On(domain.UserDeleteEvent, event.ListenerFunc(func(e event.Event) error { | ||
30 | - | ||
31 | - return nil | ||
32 | - })) | ||
33 | - event.On(domain.UserEnableEvent, event.ListenerFunc(func(e event.Event) error { | ||
34 | - | ||
35 | - return nil | ||
36 | - })) | ||
37 | - event.On(domain.UserEnableEvent, event.ListenerFunc(func(e event.Event) error { | ||
38 | - | ||
39 | - return nil | ||
40 | - })) | 20 | + event.On(domain.UserCreateEvent, event.ListenerFunc(GlobalTerminalManager.SyncUser)) |
21 | + event.On(domain.UserUpdateEvent, event.ListenerFunc(GlobalTerminalManager.SyncUser)) | ||
22 | + event.On(domain.UserEnableEvent, event.ListenerFunc(GlobalTerminalManager.EnableUser)) | ||
23 | + event.On(domain.UserSyncEvent, event.ListenerFunc(GlobalTerminalManager.SyncUser)) | ||
41 | event.On(DownEntityEvent, event.ListenerFunc(GlobalTerminalManager.DownEntityEvent)) | 24 | event.On(DownEntityEvent, event.ListenerFunc(GlobalTerminalManager.DownEntityEvent)) |
42 | } | 25 | } |
43 | 26 | ||
@@ -119,6 +102,8 @@ func terminalReport(cmd *command.TerminalReportCommand, transactionContext appli | @@ -119,6 +102,8 @@ func terminalReport(cmd *command.TerminalReportCommand, transactionContext appli | ||
119 | } | 102 | } |
120 | break | 103 | break |
121 | } | 104 | } |
105 | + case "devicecmd": | ||
106 | + log.Logger.Debug("【TerminalManager】 收到命令应答 cmd : " + cmd.Content) | ||
122 | } | 107 | } |
123 | 108 | ||
124 | return map[string]interface{}{ | 109 | return map[string]interface{}{ |
@@ -252,7 +237,6 @@ func (handler ZKClockHandler) Attendance(entity AttLOGUpEntity) (DownEntity, err | @@ -252,7 +237,6 @@ func (handler ZKClockHandler) Attendance(entity AttLOGUpEntity) (DownEntity, err | ||
252 | // 请求 人脸识别-指纹 | 237 | // 请求 人脸识别-指纹 |
253 | if len(userBase.UserInfo.FingerprintPortrait) == 0 { | 238 | if len(userBase.UserInfo.FingerprintPortrait) == 0 { |
254 | sendQuery = true | 239 | sendQuery = true |
255 | - //event.Fire(DownEntityEvent, map[string]interface{}{"entity": NewQueryBIODATADownEntity(generateSn(), entity.Pin, BioDataType1)}) | ||
256 | } | 240 | } |
257 | if sendQuery { | 241 | if sendQuery { |
258 | event.Fire(DownEntityEvent, map[string]interface{}{"entity": NewQueryUserInfoDownEntity(generateSn(), entity.Pin)}) | 242 | event.Fire(DownEntityEvent, map[string]interface{}{"entity": NewQueryUserInfoDownEntity(generateSn(), entity.Pin)}) |
@@ -323,33 +307,3 @@ func (handler ZKClockHandler) ReportUser(entity USEREntity) (DownEntity, error) | @@ -323,33 +307,3 @@ func (handler ZKClockHandler) ReportUser(entity USEREntity) (DownEntity, error) | ||
323 | func generateSn() string { | 307 | func generateSn() string { |
324 | return string(utils.RandomCreateBytes(10)) | 308 | return string(utils.RandomCreateBytes(10)) |
325 | } | 309 | } |
326 | - | ||
327 | -// GbkToUtf8 GBK 转 UTF-8 | ||
328 | -func GbkToUtf8(s string) string { | ||
329 | - decoder := mahonia.NewDecoder("gbk") | ||
330 | - _, data, _ := decoder.Translate([]byte(s), true) | ||
331 | - //return decoder.ConvertString(s) | ||
332 | - return string(data) | ||
333 | -} | ||
334 | - | ||
335 | -// Utf8ToGbk UTF-8 转 GBK | ||
336 | -func Utf8ToGbk(s string) string { | ||
337 | - encoder := mahonia.NewEncoder("gbk") | ||
338 | - return encoder.ConvertString(s) | ||
339 | -} | ||
340 | - | ||
341 | -func ConvertToString(src string, srcCode string, tagCode string) string { | ||
342 | - | ||
343 | - srcCoder := mahonia.NewDecoder(srcCode) | ||
344 | - | ||
345 | - srcResult := srcCoder.ConvertString(src) | ||
346 | - | ||
347 | - tagCoder := mahonia.NewDecoder(tagCode) | ||
348 | - | ||
349 | - _, cdata, _ := tagCoder.Translate([]byte(srcResult), true) | ||
350 | - | ||
351 | - result := string(cdata) | ||
352 | - | ||
353 | - return result | ||
354 | - | ||
355 | -} |
@@ -3,6 +3,7 @@ package service | @@ -3,6 +3,7 @@ package service | ||
3 | import ( | 3 | import ( |
4 | "container/list" | 4 | "container/list" |
5 | "github.com/gookit/event" | 5 | "github.com/gookit/event" |
6 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/domain" | ||
6 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/log" | 7 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/log" |
7 | "sync" | 8 | "sync" |
8 | ) | 9 | ) |
@@ -28,7 +29,7 @@ func (term *TerminalManager) GetDevice(terminalId string) (*TerminalDevice, bool | @@ -28,7 +29,7 @@ func (term *TerminalManager) GetDevice(terminalId string) (*TerminalDevice, bool | ||
28 | if !ok { | 29 | if !ok { |
29 | device := NewTerminalDevice(terminalId) | 30 | device := NewTerminalDevice(terminalId) |
30 | term.TerminalDevices.Store(terminalId, device) | 31 | term.TerminalDevices.Store(terminalId, device) |
31 | - log.Logger.Debug("【TerminalManager】 add new device:"+terminalId, map[string]interface{}{"device": device}) | 32 | + log.Logger.Debug("【TerminalManager】 终端上线 add new device:"+terminalId, map[string]interface{}{"device": device}) |
32 | term.TerminalDeviceList = append(term.TerminalDeviceList, device) | 33 | term.TerminalDeviceList = append(term.TerminalDeviceList, device) |
33 | return nil, false | 34 | return nil, false |
34 | } | 35 | } |
@@ -56,6 +57,10 @@ func (term *TerminalManager) AddDownEntityByDevice(sn string, entity interface{} | @@ -56,6 +57,10 @@ func (term *TerminalManager) AddDownEntityByDevice(sn string, entity interface{} | ||
56 | } | 57 | } |
57 | 58 | ||
58 | func (term *TerminalManager) BroadcastDownEntity(downEntity interface{}) { | 59 | func (term *TerminalManager) BroadcastDownEntity(downEntity interface{}) { |
60 | + if len(term.TerminalDeviceList) == 0 { | ||
61 | + log.Logger.Debug("【TerminalManager】 当前在线终端:0 广播命令退出") | ||
62 | + return | ||
63 | + } | ||
59 | for i := range term.TerminalDeviceList { | 64 | for i := range term.TerminalDeviceList { |
60 | term.TerminalDeviceList[i].AddDownEntity(downEntity) | 65 | term.TerminalDeviceList[i].AddDownEntity(downEntity) |
61 | } | 66 | } |
@@ -64,7 +69,6 @@ func (term *TerminalManager) BroadcastDownEntity(downEntity interface{}) { | @@ -64,7 +69,6 @@ func (term *TerminalManager) BroadcastDownEntity(downEntity interface{}) { | ||
64 | // Listen Event | 69 | // Listen Event |
65 | 70 | ||
66 | func (term *TerminalManager) DownEntityEvent(e event.Event) error { | 71 | func (term *TerminalManager) DownEntityEvent(e event.Event) error { |
67 | - //fmt.Printf("handle down entity event: %s\n", e.Name()) | ||
68 | entity := e.Get("entity") | 72 | entity := e.Get("entity") |
69 | if entity != nil { | 73 | if entity != nil { |
70 | term.BroadcastDownEntity(entity) | 74 | term.BroadcastDownEntity(entity) |
@@ -72,6 +76,60 @@ func (term *TerminalManager) DownEntityEvent(e event.Event) error { | @@ -72,6 +76,60 @@ func (term *TerminalManager) DownEntityEvent(e event.Event) error { | ||
72 | return nil | 76 | return nil |
73 | } | 77 | } |
74 | 78 | ||
79 | +func (term *TerminalManager) SyncUser(e event.Event) error { | ||
80 | + user := e.Get("user") | ||
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 | + } | ||
91 | + if user != nil && userBase != nil { | ||
92 | + assertUser := user.(*domain.User) | ||
93 | + 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 { | ||
99 | + return nil | ||
100 | + } | ||
101 | + if len(assertUserBase.UserInfo.FacePortrait) > 0 { | ||
102 | + term.BroadcastDownEntity(NewUpdateUserFacePortraitDownEntity(generateSn(), assertUser.Ext.IcCardNumber, assertUserBase.UserInfo.FacePortrait)) | ||
103 | + } | ||
104 | + if len(assertUserBase.UserInfo.FingerprintPortrait) > 0 { | ||
105 | + term.BroadcastDownEntity(NewUpdateUserFingerprintPortraitDownEntity(generateSn(), assertUser.Ext.IcCardNumber, assertUserBase.UserInfo.FingerprintPortrait)) | ||
106 | + } | ||
107 | + term.BroadcastDownEntity(NewUpdateUserDownEntity(generateSn(), assertUser.Ext.IcCardNumber, assertUserBase.UserInfo.UserName)) | ||
108 | + } | ||
109 | + return nil | ||
110 | +} | ||
111 | + | ||
112 | +func (term *TerminalManager) EnableUser(e event.Event) error { | ||
113 | + user := e.Get("user") | ||
114 | + if user != nil { | ||
115 | + assertUser := user.(*domain.User) | ||
116 | + if assertUser.EnableStatus == int(domain.UserStatusEnable) { | ||
117 | + term.SyncUser(e) | ||
118 | + } else if assertUser.EnableStatus == int(domain.UserStatusDisable) { | ||
119 | + term.BroadcastDownEntity(NewDeleteDownEntity(generateSn(), assertUser.Ext.IcCardNumber, string(UserInfo))) | ||
120 | + } | ||
121 | + } | ||
122 | + return nil | ||
123 | +} | ||
124 | + | ||
125 | +func (term *TerminalManager) CreateUser(e event.Event) error { | ||
126 | + return term.SyncUser(e) | ||
127 | +} | ||
128 | + | ||
129 | +func (term *TerminalManager) UpdateUser(e event.Event) error { | ||
130 | + return term.EnableUser(e) | ||
131 | +} | ||
132 | + | ||
75 | type TerminalDevice struct { | 133 | type TerminalDevice struct { |
76 | Id string | 134 | Id string |
77 | DownEntityList *list.List | 135 | DownEntityList *list.List |
@@ -91,13 +149,18 @@ func (device *TerminalDevice) PopDownEntity() (DownEntity, bool) { | @@ -91,13 +149,18 @@ func (device *TerminalDevice) PopDownEntity() (DownEntity, bool) { | ||
91 | } | 149 | } |
92 | device.DownEntityList.Remove(element) | 150 | device.DownEntityList.Remove(element) |
93 | if v, ok := element.Value.(DownEntity); ok { | 151 | if v, ok := element.Value.(DownEntity); ok { |
94 | - log.Logger.Debug("【TerminalManager】 pop down entity to Sender", map[string]interface{}{"entity": v}) | 152 | + log.Logger.Debug("【TerminalManager】 发送命令 pop down entity to Sender cmd:"+v.DownCommand(), map[string]interface{}{"entity": v}) |
95 | return v, ok | 153 | return v, ok |
96 | } | 154 | } |
97 | return nil, false | 155 | return nil, false |
98 | } | 156 | } |
99 | 157 | ||
100 | func (device *TerminalDevice) AddDownEntity(downEntity interface{}) { | 158 | func (device *TerminalDevice) AddDownEntity(downEntity interface{}) { |
101 | - log.Logger.Debug("【TerminalManager】 add down entity to Profile", map[string]interface{}{"entity": downEntity}) | 159 | + v, ok := downEntity.(DownEntity) |
160 | + var cmd string | ||
161 | + if ok { | ||
162 | + cmd = v.DownCommand() | ||
163 | + } | ||
164 | + log.Logger.Debug("【TerminalManager】 添加命令 add down entity to Profile cmd:"+cmd, map[string]interface{}{"entity": downEntity}) | ||
102 | device.DownEntityList.PushBack(downEntity) | 165 | device.DownEntityList.PushBack(downEntity) |
103 | } | 166 | } |
1 | -package service | ||
2 | - | ||
3 | -import ( | ||
4 | - "fmt" | ||
5 | - "github.com/stretchr/testify/assert" | ||
6 | - "testing" | ||
7 | -) | ||
8 | - | ||
9 | -func TestGbkToUtf8(t *testing.T) { | ||
10 | - input := "刘" | ||
11 | - out := Utf8ToGbk(input) | ||
12 | - t.Log("gbk:" + out) | ||
13 | - //"efbfbdeeb8a3" | ||
14 | - t.Log(fmt.Sprintf("%v", []byte(out))) | ||
15 | - out = GbkToUtf8(out) | ||
16 | - t.Log("utf8:" + out) | ||
17 | - t.Log("utf8:" + fmt.Sprintf("%v", []byte(out))) | ||
18 | - assert.Equal(t, input, out) | ||
19 | -} |
@@ -137,21 +137,79 @@ func NewQueryBIODATADownEntity(sn string, pin string, t BioDataType) QueryBioDat | @@ -137,21 +137,79 @@ func NewQueryBIODATADownEntity(sn string, pin string, t BioDataType) QueryBioDat | ||
137 | } | 137 | } |
138 | } | 138 | } |
139 | 139 | ||
140 | -// DeleteUserDownEntity 删除用户-下行命令 | ||
141 | -type DeleteUserDownEntity struct { | 140 | +// DeleteDownEntity 删除-下行命令 |
141 | +type DeleteDownEntity struct { | ||
142 | Sn string | 142 | Sn string |
143 | Pin string | 143 | Pin string |
144 | Table string | 144 | Table string |
145 | } | 145 | } |
146 | 146 | ||
147 | -func (entity DeleteUserDownEntity) DownCommand() string { | 147 | +func (entity DeleteDownEntity) DownCommand() string { |
148 | return fmt.Sprintf("C:%v:DATA DELETE %v PIN=%v", entity.Sn, entity.Table, entity.Pin) | 148 | return fmt.Sprintf("C:%v:DATA DELETE %v PIN=%v", entity.Sn, entity.Table, entity.Pin) |
149 | } | 149 | } |
150 | 150 | ||
151 | -func NewClearUserDownEntity(sn string, pin string, t string) DeleteUserDownEntity { | ||
152 | - return DeleteUserDownEntity{ | 151 | +func NewDeleteDownEntity(sn string, pin string, t string) DeleteDownEntity { |
152 | + return DeleteDownEntity{ | ||
153 | Sn: sn, | 153 | Sn: sn, |
154 | Pin: pin, | 154 | Pin: pin, |
155 | Table: t, | 155 | Table: t, |
156 | } | 156 | } |
157 | } | 157 | } |
158 | + | ||
159 | +// UpdateUserDownEntity 更新用户-下行命令 | ||
160 | +type UpdateUserDownEntity struct { | ||
161 | + Sn string | ||
162 | + Pin string | ||
163 | + Name string | ||
164 | + Card string | ||
165 | +} | ||
166 | + | ||
167 | +func (entity UpdateUserDownEntity) DownCommand() string { | ||
168 | + return fmt.Sprintf("C:%v:DATA UPDATE USERINFO PIN=%v\tName=%v\tCard=%v", entity.Sn, entity.Pin, entity.Name, entity.Pin) | ||
169 | +} | ||
170 | + | ||
171 | +func NewUpdateUserDownEntity(sn string, pin string, name string) UpdateUserDownEntity { | ||
172 | + return UpdateUserDownEntity{ | ||
173 | + Sn: sn, | ||
174 | + Pin: pin, | ||
175 | + Name: name, | ||
176 | + } | ||
177 | +} | ||
178 | + | ||
179 | +// UpdateUserFacePortraitDownEntity 更新用户-人脸识别 -下行命令 | ||
180 | +type UpdateUserFacePortraitDownEntity struct { | ||
181 | + Sn string | ||
182 | + Pin string | ||
183 | + FacePortrait string | ||
184 | +} | ||
185 | + | ||
186 | +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) | ||
188 | +} | ||
189 | + | ||
190 | +func NewUpdateUserFacePortraitDownEntity(sn string, pin string, facePortrait string) UpdateUserFacePortraitDownEntity { | ||
191 | + return UpdateUserFacePortraitDownEntity{ | ||
192 | + Sn: sn, | ||
193 | + Pin: pin, | ||
194 | + FacePortrait: facePortrait, | ||
195 | + } | ||
196 | +} | ||
197 | + | ||
198 | +// UpdateUserFingerprintPortraitDownEntity 更新用户-指纹 -下行命令 | ||
199 | +type UpdateUserFingerprintPortraitDownEntity struct { | ||
200 | + Sn string | ||
201 | + Pin string | ||
202 | + FingerprintPortrait string | ||
203 | +} | ||
204 | + | ||
205 | +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) | ||
207 | +} | ||
208 | + | ||
209 | +func NewUpdateUserFingerprintPortraitDownEntity(sn string, pin string, fingerprintPortrait string) UpdateUserFingerprintPortraitDownEntity { | ||
210 | + return UpdateUserFingerprintPortraitDownEntity{ | ||
211 | + Sn: sn, | ||
212 | + Pin: pin, | ||
213 | + FingerprintPortrait: fingerprintPortrait, | ||
214 | + } | ||
215 | +} |
1 | +package command | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | + "github.com/beego/beego/v2/core/validation" | ||
6 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/domain" | ||
7 | + "reflect" | ||
8 | + "strings" | ||
9 | +) | ||
10 | + | ||
11 | +type SyncToAttendanceMachineCommand struct { | ||
12 | + OperateInfo *domain.OperateInfo `json:"-"` | ||
13 | + // 用户关联的角色 | ||
14 | + Users []int64 `cname:"用户关联的角色" json:"userIds" valid:"Required"` | ||
15 | +} | ||
16 | + | ||
17 | +func (syncToAttendance *SyncToAttendanceMachineCommand) Valid(validation *validation.Validation) { | ||
18 | + //validation.SetError("CustomValid", "未实现的自定义认证") | ||
19 | +} | ||
20 | + | ||
21 | +func (syncToAttendance *SyncToAttendanceMachineCommand) ValidateCommand() error { | ||
22 | + valid := validation.Validation{} | ||
23 | + b, err := valid.Valid(syncToAttendance) | ||
24 | + if err != nil { | ||
25 | + return err | ||
26 | + } | ||
27 | + if !b { | ||
28 | + elem := reflect.TypeOf(syncToAttendance).Elem() | ||
29 | + for _, validErr := range valid.Errors { | ||
30 | + field, isExist := elem.FieldByName(validErr.Field) | ||
31 | + if isExist { | ||
32 | + return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1)) | ||
33 | + } else { | ||
34 | + return fmt.Errorf(validErr.Message) | ||
35 | + } | ||
36 | + } | ||
37 | + } | ||
38 | + return nil | ||
39 | +} |
pkg/application/user/service/attendance.go
0 → 100644
1 | +package service | ||
2 | + | ||
3 | +import ( | ||
4 | + "github.com/gookit/event" | ||
5 | + "github.com/linmadan/egglib-go/core/application" | ||
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" | ||
8 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/domain" | ||
9 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/log" | ||
10 | +) | ||
11 | + | ||
12 | +func (userService *UserService) SyncToAttendanceMachine(cmd *command.SyncToAttendanceMachineCommand) (interface{}, error) { | ||
13 | + if err := cmd.ValidateCommand(); err != nil { | ||
14 | + return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | ||
15 | + } | ||
16 | + transactionContext, err := factory.CreateTransactionContext(nil) | ||
17 | + if err != nil { | ||
18 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
19 | + } | ||
20 | + if err := transactionContext.StartTransaction(); err != nil { | ||
21 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
22 | + } | ||
23 | + defer func() { | ||
24 | + transactionContext.RollbackTransaction() | ||
25 | + }() | ||
26 | + userRepository, _, _ := factory.FastPgUser(transactionContext, 0) | ||
27 | + | ||
28 | + _, users, err := userRepository.Find(map[string]interface{}{"companyId": cmd.OperateInfo.CompanyId, "inUserIds": cmd.Users}) | ||
29 | + if err != nil { | ||
30 | + return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error()) | ||
31 | + } | ||
32 | + | ||
33 | + for i := range users { | ||
34 | + _, userBase, err := factory.FastPgUserBase(transactionContext, users[i].UserBaseId) | ||
35 | + if err != nil { | ||
36 | + return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error()) | ||
37 | + } | ||
38 | + if err, _ := event.Fire(domain.UserSyncEvent, event.M{"user": users[i], "userBase": userBase}); err != nil { | ||
39 | + log.Logger.Error(err.Error()) | ||
40 | + return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error()) | ||
41 | + } | ||
42 | + } | ||
43 | + | ||
44 | + if err := transactionContext.CommitTransaction(); err != nil { | ||
45 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
46 | + } | ||
47 | + return struct{}{}, nil | ||
48 | +} |
@@ -2,6 +2,7 @@ package service | @@ -2,6 +2,7 @@ package service | ||
2 | 2 | ||
3 | import ( | 3 | import ( |
4 | "fmt" | 4 | "fmt" |
5 | + "github.com/gookit/event" | ||
5 | "github.com/linmadan/egglib-go/core/application" | 6 | "github.com/linmadan/egglib-go/core/application" |
6 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/application/factory" | 7 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/application/factory" |
7 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/application/user/command" | 8 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/application/user/command" |
@@ -110,6 +111,9 @@ func (userService *UserService) BatchEnable(batchEnableCommand *command.BatchEna | @@ -110,6 +111,9 @@ func (userService *UserService) BatchEnable(batchEnableCommand *command.BatchEna | ||
110 | if _, err := userRepository.Save(user); err != nil { | 111 | if _, err := userRepository.Save(user); err != nil { |
111 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | 112 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) |
112 | } | 113 | } |
114 | + if err, _ := event.Fire(domain.UserEnableEvent, map[string]interface{}{"user": user}); err != nil { | ||
115 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
116 | + } | ||
113 | } | 117 | } |
114 | } | 118 | } |
115 | 119 |
@@ -2,6 +2,7 @@ package domainService | @@ -2,6 +2,7 @@ package domainService | ||
2 | 2 | ||
3 | import ( | 3 | import ( |
4 | "fmt" | 4 | "fmt" |
5 | + "github.com/gookit/event" | ||
5 | pgTransaction "github.com/linmadan/egglib-go/transaction/pg" | 6 | pgTransaction "github.com/linmadan/egglib-go/transaction/pg" |
6 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/domain" | 7 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/domain" |
7 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/infrastructure/repository" | 8 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/infrastructure/repository" |
@@ -96,6 +97,10 @@ func (ptr *PgCreateUserService) CreateUser(optUser *domain.User, newUser *domain | @@ -96,6 +97,10 @@ func (ptr *PgCreateUserService) CreateUser(optUser *domain.User, newUser *domain | ||
96 | return nil, err | 97 | return nil, err |
97 | } | 98 | } |
98 | } | 99 | } |
100 | + // 新建用户事件 | ||
101 | + if err, _ := event.Fire(domain.UserCreateEvent, event.M{"user": newUser, "userBase": userBase}); err != nil { | ||
102 | + return nil, err | ||
103 | + } | ||
99 | return user, nil | 104 | return user, nil |
100 | } | 105 | } |
101 | 106 |
@@ -2,6 +2,7 @@ package domainService | @@ -2,6 +2,7 @@ package domainService | ||
2 | 2 | ||
3 | import ( | 3 | import ( |
4 | "fmt" | 4 | "fmt" |
5 | + "github.com/gookit/event" | ||
5 | pgTransaction "github.com/linmadan/egglib-go/transaction/pg" | 6 | pgTransaction "github.com/linmadan/egglib-go/transaction/pg" |
6 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/domain" | 7 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/domain" |
7 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/infrastructure/repository" | 8 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/infrastructure/repository" |
@@ -108,6 +109,10 @@ func (ptr *PgUpdateUserService) UpdateUser(optUser *domain.OperateInfo, user *do | @@ -108,6 +109,10 @@ func (ptr *PgUpdateUserService) UpdateUser(optUser *domain.OperateInfo, user *do | ||
108 | if user, err = userRepository.Save(user); err != nil { | 109 | if user, err = userRepository.Save(user); err != nil { |
109 | return nil, err | 110 | return nil, err |
110 | } | 111 | } |
112 | + // 新建用户事件 | ||
113 | + if err, _ := event.Fire(domain.UserUpdateEvent, event.M{"user": user, "userBase": userBase}); err != nil { | ||
114 | + return nil, err | ||
115 | + } | ||
111 | return user, nil | 116 | return user, nil |
112 | } | 117 | } |
113 | 118 |
@@ -204,6 +204,9 @@ func (repository *UserRepository) Find(queryOptions map[string]interface{}) (int | @@ -204,6 +204,9 @@ func (repository *UserRepository) Find(queryOptions map[string]interface{}) (int | ||
204 | } | 204 | } |
205 | query.SetWhereByQueryOption("company_id=?", "companyId") | 205 | query.SetWhereByQueryOption("company_id=?", "companyId") |
206 | query.SetWhereByQueryOption("organization_id=?", "organizationId") | 206 | query.SetWhereByQueryOption("organization_id=?", "organizationId") |
207 | + if v, ok := queryOptions["inUserIds"]; ok && len(v.([]int64)) > 0 { | ||
208 | + query.Where(`user_id in (?)`, pg.In(v)) | ||
209 | + } | ||
207 | if v, ok := queryOptions["inOrgIds"]; ok && len(v.([]int64)) > 0 { | 210 | if v, ok := queryOptions["inOrgIds"]; ok && len(v.([]int64)) > 0 { |
208 | query.Where(`organization_id in (?)`, pg.In(v)) | 211 | query.Where(`organization_id in (?)`, pg.In(v)) |
209 | } | 212 | } |
@@ -179,3 +179,12 @@ func (controller *UserController) UpdateAdminUser() { | @@ -179,3 +179,12 @@ func (controller *UserController) UpdateAdminUser() { | ||
179 | data, err := userService.UpdateAdminUser(updateUserCommand) | 179 | data, err := userService.UpdateAdminUser(updateUserCommand) |
180 | controller.Response(data, err) | 180 | controller.Response(data, err) |
181 | } | 181 | } |
182 | + | ||
183 | +func (controller *UserController) SyncToAttendanceMachine() { | ||
184 | + userService := service.NewUserService(nil) | ||
185 | + cmd := &command.SyncToAttendanceMachineCommand{} | ||
186 | + Must(controller.Unmarshal(cmd)) | ||
187 | + cmd.OperateInfo = ParseOperateInfo(controller.BaseController) | ||
188 | + data, err := userService.SyncToAttendanceMachine(cmd) | ||
189 | + controller.Response(data, err) | ||
190 | +} |
@@ -21,6 +21,8 @@ func init() { | @@ -21,6 +21,8 @@ func init() { | ||
21 | web.Router("/user/cooperator", &controllers.UserController{}, "Post:CreateCooperator") | 21 | web.Router("/user/cooperator", &controllers.UserController{}, "Post:CreateCooperator") |
22 | web.Router("/user/cooperator/:userId", &controllers.UserController{}, "Put:UpdateCooperator") | 22 | web.Router("/user/cooperator/:userId", &controllers.UserController{}, "Put:UpdateCooperator") |
23 | 23 | ||
24 | + web.Router("/user/sync-to-attendance-machine", &controllers.UserController{}, "Post:SyncToAttendanceMachine") | ||
25 | + | ||
24 | web.Router("/admin-user/", &controllers.UserController{}, "Post:CreateAdminUser") | 26 | web.Router("/admin-user/", &controllers.UserController{}, "Post:CreateAdminUser") |
25 | web.Router("/admin-user/:userId", &controllers.UserController{}, "Put:UpdateAdminUser") | 27 | web.Router("/admin-user/:userId", &controllers.UserController{}, "Put:UpdateAdminUser") |
26 | } | 28 | } |
-
请 注册 或 登录 后发表评论