作者 yangfu

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

... ... @@ -11,6 +11,7 @@ require (
github.com/gavv/httpexpect v2.0.0+incompatible
github.com/go-pg/pg/v10 v10.9.0
github.com/google/go-querystring v1.1.0 // indirect
github.com/gookit/event v1.0.6
github.com/imkira/go-interpol v1.1.0 // indirect
github.com/linmadan/egglib-go v0.0.0-20210313060205-8b5e456b11f7
github.com/mattn/go-colorable v0.1.8 // indirect
... ... @@ -19,7 +20,7 @@ require (
github.com/onsi/gomega v1.11.0
github.com/sergi/go-diff v1.2.0 // indirect
github.com/smartystreets/goconvey v1.6.4 // indirect
github.com/stretchr/testify v1.7.0
github.com/stretchr/testify v1.7.1
github.com/tal-tech/go-queue v1.0.5
github.com/tal-tech/go-zero v1.0.27
github.com/valyala/fasthttp v1.23.0 // indirect
... ...
... ... @@ -164,6 +164,8 @@ github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm4
github.com/google/uuid v1.0.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/google/uuid v1.1.1 h1:Gkbcsh/GbpXz7lPftLA3P6TYMwjCLYm83jiFQZF/3gY=
github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/gookit/event v1.0.6 h1:/U95T1tBzt9RSSi23pg4VR3B9VWkyM4xv8TXAGi60IQ=
github.com/gookit/event v1.0.6/go.mod h1:7Udf/q/HQcrK9XE4JZUvbqi46rI1V8r/Pvao2NbPajA=
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1 h1:EGx4pi6eqNxGaHF6qqu48+N2wcFQ5qg5FXgOdqsJ5d8=
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
github.com/gorilla/websocket v0.0.0-20170926233335-4201258b820c/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ=
... ... @@ -348,8 +350,9 @@ github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UV
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.1 h1:5TQK59W5E3v0r2duFAb7P95B6hEeOyEnHRa8MjYSMTY=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/syndtr/goleveldb v0.0.0-20160425020131-cfa635847112/go.mod h1:Z4AUp2Km+PwemOoO/VB5AOx9XSsIItzFjoJlOSiYmn0=
github.com/syndtr/goleveldb v0.0.0-20181127023241-353a9fca669c/go.mod h1:Z4AUp2Km+PwemOoO/VB5AOx9XSsIItzFjoJlOSiYmn0=
github.com/tal-tech/go-queue v1.0.5 h1:cd2o0lPjAFJKIXuEbQvsGypUhzz6FLib4FVVAyxsMtY=
... ...
... ... @@ -26,6 +26,8 @@ type CreateMenuCommand struct {
IsPublish int `json:"isPublish" valid:"Required"`
// 启用状态(启用:1 禁用:2),默认启用
EnableStatus int `json:"enableStatus" `
// 外链接(需要菜单跳转的时候使用)
Link string `json:"link"`
}
func (createMenuCommand *CreateMenuCommand) Valid(validation *validation.Validation) {
... ...
... ... @@ -29,6 +29,8 @@ type UpdateMenuCommand struct {
IsPublish int `json:"isPublish,omitempty"`
// 启用状态(启用:1 禁用:2),默认启用
EnableStatus int `json:"enableStatus"`
// 外链接(需要菜单跳转的时候使用)
Link string `json:"link"`
}
func (updateMenuCommand *UpdateMenuCommand) Valid(validation *validation.Validation) {
... ...
package command
import (
"fmt"
"reflect"
"strings"
"github.com/beego/beego/v2/core/validation"
)
type TerminalReportCommand struct {
TerminalType string `json:"terminalType"`
TerminalId string `json:"terminalId"`
Command string `json:"command"`
Content string `json:"content"`
Table string `json:"table"`
CompanyId int64 `json:"companyId"`
OrgId int64 `json:"orgId"`
}
func (terminalReportCommand *TerminalReportCommand) Valid(validation *validation.Validation) {
}
func (terminalReportCommand *TerminalReportCommand) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(terminalReportCommand)
if err != nil {
return err
}
if !b {
elem := reflect.TypeOf(terminalReportCommand).Elem()
for _, validErr := range valid.Errors {
field, isExist := elem.FieldByName(validErr.Field)
if isExist {
return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1))
} else {
return fmt.Errorf(validErr.Message)
}
}
}
return nil
}
... ...
package service
import (
"bytes"
"fmt"
"github.com/beego/beego/v2/adapter/utils"
"github.com/gookit/event"
"github.com/linmadan/egglib-go/core/application"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/application/factory"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/application/terminal/command"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/log"
"io"
)
var GlobalTerminalManager *TerminalManager
func init() {
GlobalTerminalManager = NewTerminalManager()
event.On(domain.UserCreateEvent, event.ListenerFunc(GlobalTerminalManager.SyncUser))
event.On(domain.UserUpdateEvent, event.ListenerFunc(GlobalTerminalManager.SyncUser))
event.On(domain.UserEnableEvent, event.ListenerFunc(GlobalTerminalManager.EnableUser))
event.On(domain.UserSyncEvent, event.ListenerFunc(GlobalTerminalManager.SyncUser))
event.On(DownEntityEvent, event.ListenerFunc(GlobalTerminalManager.DownEntityEvent))
}
type TerminalService struct {
}
func NewTerminalService(options map[string]interface{}) *TerminalService {
newUserService := &TerminalService{}
return newUserService
}
func (svr *TerminalService) TerminalReport(cmd *command.TerminalReportCommand) (interface{}, error) {
if err := cmd.ValidateCommand(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
}
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if err := transactionContext.StartTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
defer func() {
transactionContext.RollbackTransaction()
}()
response, err := terminalReport(cmd, transactionContext)
if err != nil {
log.Logger.Error(err.Error())
return nil, err
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return response, nil
}
func terminalReport(cmd *command.TerminalReportCommand, transactionContext application.TransactionContext) (interface{}, error) {
var (
response string = "OK"
)
switch cmd.Command {
case "getrequest":
device, ok := GlobalTerminalManager.GetDevice(cmd.TerminalId)
if !ok || device == nil {
break
}
if downEntity, ok := device.PopDownEntity(); ok && downEntity != nil {
response = downEntity.DownCommand()
}
break
case "cdata":
parseEntities := ParseData(cmd)
var (
down DownEntity
err error
handler Handler = ZKClockHandler{TransactionContext: transactionContext}
)
for _, entity := range parseEntities {
switch TableType(cmd.Table) {
case AttLOG:
down, err = handler.Attendance(entity.(AttLOGUpEntity))
case BIODATA:
down, err = handler.BioData(entity.(BIODATAEntity))
case OPERLOG:
//if v, ok := entity.(USEREntity); ok {
// down, err = handler.ReportUser(v)
//}
if v, ok := entity.(BIODATAEntity); ok {
down, err = handler.BioData(v)
}
}
if err != nil {
log.Logger.Error(err.Error())
continue
}
if down != nil {
response = down.DownCommand()
}
break
}
case "devicecmd":
log.Logger.Debug("【TerminalManager】 收到命令应答 cmd : " + cmd.Content)
}
return map[string]interface{}{
"response": response,
}, nil
}
func ParseData(cmd *command.TerminalReportCommand) []interface{} {
result := make([]interface{}, 0)
buf := bytes.NewBufferString(cmd.Content)
for {
line, err := buf.ReadBytes('\n')
if err == io.EOF {
break
}
if err != nil {
log.Logger.Error(err.Error())
break
}
switch TableType(cmd.Table) {
case AttLOG:
columns := bytes.Split(line, ([]byte)("\t"))
if len(columns) != 11 { //10 + 1 空格
continue
}
result = append(result, AttLOGUpEntity{
Pin: string(columns[0]),
CompanyId: cmd.CompanyId,
OrgId: cmd.OrgId,
})
case BIODATA:
/*BIODATA Pin=3\tNo=0\tIndex=0\tValid=1\tDuress=0\tType=9\tMajorVer=39\tMinorVer=1\tFormat=
0\tTmp=apUBEBABQo4JACcBAWiOADA7dP4pU9F31Uxom7NAGjM4eO/8X5Ee4uahkIT11c3188+VguMsd3oCO0O29efRyxofdLiohI4QL7woK3U*/
columns := readLineToMap(line, "BIODATA")
result = append(result, BIODATAEntity{
Pin: columns["Pin"],
No: columns["No"],
Index: columns["Index"],
Duress: columns["Duress"],
Type: columns["Type"],
MinorVer: columns["MinorVer"],
MajorVer: columns["MajorVer"],
Format: columns["Format"],
Tmp: columns["Tmp"],
CompanyId: cmd.CompanyId,
OrgId: cmd.OrgId,
})
case OPERLOG:
if bytes.HasPrefix(line, []byte("FP")) {
/*
FP PIN=3 FID=6 Size=1336 Valid=1 TMP=SqtTUzIxAAAD6O8ECA
*/
columns := readLineToMap(line, "FP")
result = append(result, BIODATAEntity{
Pin: columns["PIN"],
Type: fmt.Sprintf("%v", BioDataType1),
Tmp: columns["TMP"],
CompanyId: cmd.CompanyId,
OrgId: cmd.OrgId,
})
} else if bytes.HasPrefix(line, []byte("USER")) {
/*
USER PIN=3 Name=杨xx Pri=14 Passwd= Card=3731588478 Grp=1 TZ=0000000100000000 Verify=-1 ViceCard= StartDatetime=0 EndDatetime=0
*/
columns := readLineToMap(line, "USER")
name := columns["Name"] //GbkToUtf8(columns["Name"])
result = append(result, USEREntity{
OPERLOGType: "USER",
Pin: columns["PIN"],
Name: name,
CompanyId: cmd.CompanyId,
OrgId: cmd.OrgId,
})
}
}
}
return result
}
func readLineToMap(line []byte, prefix string) map[string]string {
var result = make(map[string]string)
line = bytes.TrimLeft(line, prefix)
line = bytes.TrimSpace(line)
columns := bytes.Fields(line)
for i := range columns {
kv := bytes.SplitN(columns[i], []byte("="), 2)
if len(kv) < 2 {
continue
}
//if string(kv[0]) == "Name" {
// log.Logger.Debug(fmt.Sprintf("%x", kv[1]))
// log.Logger.Debug(fmt.Sprintf("%v", kv[1]))
// log.Logger.Debug(fmt.Sprintf("%s", string(kv[1])))
//}
result[string(kv[0])] = string(kv[1])
}
return result
}
type Handler interface {
Attendance(entity AttLOGUpEntity) (DownEntity, error)
BioData(entity BIODATAEntity) (DownEntity, error)
ReportUser(entity USEREntity) (DownEntity, error)
}
type ZKClockHandler struct {
TransactionContext application.TransactionContext
}
func (handler ZKClockHandler) Attendance(entity AttLOGUpEntity) (DownEntity, error) {
var (
userRepository, _, _ = factory.FastPgUser(handler.TransactionContext, 0)
userBaseRepository, _, _ = factory.FastPgUserBase(handler.TransactionContext, 0)
user *domain.User
userBase *domain.UserBase
err error
)
if user, err = userRepository.FindOne(map[string]interface{}{"companyId": entity.CompanyId, "orgId": entity.OrgId, "icCardNumber": entity.Pin}); err != nil {
return nil, err
}
if userBase, err = userBaseRepository.FindOne(map[string]interface{}{"userBaseId": user.UserBaseId}); err != nil {
return nil, err
}
var sendQuery bool
// 请求 人脸识别-用户画像
if len(userBase.UserInfo.FacePortrait) == 0 {
sendQuery = true
//event.Fire(DownEntityEvent, map[string]interface{}{"entity": NewQueryBIODATADownEntity(generateSn(), entity.Pin, BioDataType2)})
}
// 请求 人脸识别-指纹
if len(userBase.UserInfo.FingerprintPortrait) == 0 {
sendQuery = true
}
if sendQuery {
event.Fire(DownEntityEvent, map[string]interface{}{"entity": NewQueryUserInfoDownEntity(generateSn(), entity.Pin)})
}
return nil, nil
}
func (handler ZKClockHandler) BioData(entity BIODATAEntity) (DownEntity, error) {
var (
userRepository, _, _ = factory.FastPgUser(handler.TransactionContext, 0)
userBaseRepository, _, _ = factory.FastPgUserBase(handler.TransactionContext, 0)
user *domain.User
userBase *domain.UserBase
err error
updateFlag bool
)
if user, err = userRepository.FindOne(map[string]interface{}{"companyId": entity.CompanyId, "orgId": entity.OrgId, "icCardNumber": entity.Pin}); err != nil {
return nil, err
}
if userBase, err = userBaseRepository.FindOne(map[string]interface{}{"userBaseId": user.UserBaseId}); err != nil {
return nil, err
}
// 请求 人脸识别-用户画像
if len(userBase.UserInfo.FacePortrait) == 0 && len(entity.Tmp) > 0 && entity.Type == "9" {
userBase.UserInfo.FacePortrait = entity.Tmp
updateFlag = true
}
// 请求 人脸识别-指纹
if len(userBase.UserInfo.FingerprintPortrait) == 0 && len(entity.Tmp) > 0 && entity.Type == "1" {
userBase.UserInfo.FingerprintPortrait = entity.Tmp
updateFlag = true
}
if updateFlag {
_, err = userBaseRepository.Save(userBase)
if err != nil {
log.Logger.Error(err.Error())
}
}
return nil, err
}
func (handler ZKClockHandler) ReportUser(entity USEREntity) (DownEntity, error) {
var (
userRepository, _, _ = factory.FastPgUser(handler.TransactionContext, 0)
userBaseRepository, _, _ = factory.FastPgUserBase(handler.TransactionContext, 0)
user *domain.User
userBase *domain.UserBase
err error
updateFlag bool
)
if user, err = userRepository.FindOne(map[string]interface{}{"companyId": entity.CompanyId, "orgId": entity.OrgId, "icCardNumber": entity.Pin}); err != nil {
return nil, err
}
if userBase, err = userBaseRepository.FindOne(map[string]interface{}{"userBaseId": user.UserBaseId}); err != nil {
return nil, err
}
// 请求 人脸识别-用户画像
//if len(entity.Pin) > 0 && userBase.UserInfo.Pin != entity.Pin {
// updateFlag = true
// userBase.UserInfo.Pin = entity.Pin
//}
if updateFlag {
_, err = userBaseRepository.Save(userBase)
}
return nil, err
}
func generateSn() string {
return string(utils.RandomCreateBytes(10))
}
... ...
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"
)
var (
DownEntityEvent = "down_entity"
)
type TerminalManager struct {
TerminalDeviceList []*TerminalDevice
TerminalDevices sync.Map
}
func NewTerminalManager() *TerminalManager {
return &TerminalManager{
TerminalDeviceList: make([]*TerminalDevice, 0),
TerminalDevices: sync.Map{},
}
}
func (term *TerminalManager) GetDevice(terminalId string) (*TerminalDevice, bool) {
device, ok := term.TerminalDevices.Load(terminalId)
if !ok {
device := NewTerminalDevice(terminalId)
term.TerminalDevices.Store(terminalId, device)
log.Logger.Debug("【TerminalManager】 终端上线 add new device:"+terminalId, map[string]interface{}{"device": device})
term.TerminalDeviceList = append(term.TerminalDeviceList, device)
return nil, false
}
if v, ok := device.(*TerminalDevice); ok {
return v, ok
}
return nil, false
}
func (term *TerminalManager) PopDownEntityByDevice(sn string) (DownEntity, bool) {
device, ok := term.GetDevice(sn)
if !ok {
return nil, false
}
return device.PopDownEntity()
}
func (term *TerminalManager) AddDownEntityByDevice(sn string, entity interface{}) bool {
device, ok := term.GetDevice(sn)
if !ok {
return false
}
device.AddDownEntity(entity)
return true
}
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)
}
}
// Listen Event
func (term *TerminalManager) DownEntityEvent(e event.Event) error {
entity := e.Get("entity")
if entity != nil {
term.BroadcastDownEntity(entity)
}
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
}
func NewTerminalDevice(terminalId string) *TerminalDevice {
return &TerminalDevice{
Id: terminalId,
DownEntityList: list.New(),
}
}
func (device *TerminalDevice) PopDownEntity() (DownEntity, bool) {
element := device.DownEntityList.Front()
if element == nil {
return nil, false
}
device.DownEntityList.Remove(element)
if v, ok := element.Value.(DownEntity); ok {
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{}) {
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)
}
... ...
package service
import "fmt"
type TableType string
var (
AttLOG TableType = "ATTLOG" // AttLOG 打卡记录
UserInfo TableType = "USERINFO" // 用户信息
FingerTMP TableType = "FINGERTMP" //指纹
Face TableType = "FACE" //脸部
OPERLOG TableType = "OPERLOG" //操作记录
BIODATA TableType = "BIODATA" //一体化数据 (人脸识别等)
)
// AttLOGUpEntity 打卡记录实体 - 上行命令
type AttLOGUpEntity struct {
Pin string
Time string
Status string
Verify string
Workcode string
Reserved1 string
Reserved2 string
MaskFlag string
Temperature string
ConvTemperature string
CompanyId int64 `json:"companyId"`
OrgId int64 `json:"orgId"`
}
// FPEntity 指纹 - 上行命令 OPERLOG
type FPEntity struct {
OPERLOGType string //"FP" "USER" "BIODATA"
Pin string
TFID string
TSize string
TValid string
TTMP string
CompanyId int64 `json:"companyId"`
OrgId int64 `json:"orgId"`
}
// USEREntity 用户 - 上行命令 OPERLOG
type USEREntity struct {
OPERLOGType string //"FP" "USER" "BIODATA"
Pin string `json:"pin"`
Name string `json:"Name"`
Pri string `json:"Pri"`
Passwd string `json:"Passwd"`
Grp string `json:"Grp"`
TZ string `json:"TZ"`
Verify string `json:"Verify"`
ViceCard string `json:"ViceCard"`
StartDatetime string `json:"StartDatetime"`
EndDatetime string `json:"EndDatetime"`
CompanyId int64 `json:"companyId"`
OrgId int64 `json:"orgId"`
}
// BIODATAEntity 一体化数据实体 - 上行命令 BIODATA
type BIODATAEntity struct {
Pin string `json:"pin"`
No string `json:"tNo"`
Index string `json:"tIndex"`
Valid string `json:"tValid"`
Duress string `json:"tDuress"`
Type string `json:"tType"`
MajorVer string `json:"tMajorVer"`
MinorVer string `json:"tMinorVer"`
Format string `json:"tFormat"`
Tmp string `json:"Tmp"`
CompanyId int64 `json:"companyId"`
OrgId int64 `json:"orgId"`
}
type DownEntity interface {
DownCommand() string
}
func QueryUserInfoRequest(sn string, entity AttLOGUpEntity) string {
return fmt.Sprintf("C:%v:DATA QUERY USERINFO PIN=%v", sn, entity.Pin)
}
// QueryUserInfoDownEntity 查询用户信息-下行命令
type QueryUserInfoDownEntity struct {
Sn string
Pin string
}
func (entity QueryUserInfoDownEntity) DownCommand() string {
return fmt.Sprintf("C:%v:DATA QUERY USERINFO PIN=%v", entity.Sn, entity.Pin)
}
func NewQueryUserInfoDownEntity(sn string, pin string) QueryUserInfoDownEntity {
return QueryUserInfoDownEntity{
Sn: sn,
Pin: pin,
}
}
type BioDataType int
var (
BioDataType0 BioDataType = 0 //通用
BioDataType1 BioDataType = 1 //指纹
BioDataType2 BioDataType = 0 //面部
BioDataType3 BioDataType = 3 //声纹
BioDataType4 BioDataType = 4 //虹膜
BioDataType5 BioDataType = 5 //视网膜
BioDataType6 BioDataType = 6 //掌纹
BioDataType7 BioDataType = 7 //指静脉
BioDataType8 BioDataType = 8 //手掌
BioDataType9 BioDataType = 9 //可见光面部
)
// QueryBioDataDownEntity 查询一体化-下行命令
type QueryBioDataDownEntity struct {
Sn string
Pin string
Type BioDataType
}
func (entity QueryBioDataDownEntity) DownCommand() string {
return fmt.Sprintf("C:%v:DATA QUERY BIODATA Type=%v PIN=%v", entity.Sn, entity.Type, entity.Pin)
}
func NewQueryBIODATADownEntity(sn string, pin string, t BioDataType) QueryBioDataDownEntity {
return QueryBioDataDownEntity{
Sn: sn,
Pin: pin,
Type: t,
}
}
// DeleteDownEntity 删除-下行命令
type DeleteDownEntity struct {
Sn string
Pin string
Table string
}
func (entity DeleteDownEntity) DownCommand() string {
return fmt.Sprintf("C:%v:DATA DELETE %v PIN=%v", entity.Sn, entity.Table, entity.Pin)
}
func NewDeleteDownEntity(sn string, pin string, t string) DeleteDownEntity {
return DeleteDownEntity{
Sn: sn,
Pin: pin,
Table: t,
}
}
// UpdateUserDownEntity 更新用户-下行命令
type UpdateUserDownEntity struct {
Sn string
Pin string
Name string
Card string
}
func (entity UpdateUserDownEntity) DownCommand() string {
return fmt.Sprintf("C:%v:DATA UPDATE USERINFO PIN=%v\tName=%v\tCard=%v", entity.Sn, entity.Pin, entity.Name, entity.Pin)
}
func NewUpdateUserDownEntity(sn string, pin string, name string) UpdateUserDownEntity {
return UpdateUserDownEntity{
Sn: sn,
Pin: pin,
Name: name,
}
}
// UpdateUserFacePortraitDownEntity 更新用户-人脸识别 -下行命令
type UpdateUserFacePortraitDownEntity struct {
Sn string
Pin string
FacePortrait string
}
func (entity UpdateUserFacePortraitDownEntity) DownCommand() string {
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)
}
func NewUpdateUserFacePortraitDownEntity(sn string, pin string, facePortrait string) UpdateUserFacePortraitDownEntity {
return UpdateUserFacePortraitDownEntity{
Sn: sn,
Pin: pin,
FacePortrait: facePortrait,
}
}
// UpdateUserFingerprintPortraitDownEntity 更新用户-指纹 -下行命令
type UpdateUserFingerprintPortraitDownEntity struct {
Sn string
Pin string
FingerprintPortrait string
}
func (entity UpdateUserFingerprintPortraitDownEntity) DownCommand() string {
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)
}
func NewUpdateUserFingerprintPortraitDownEntity(sn string, pin string, fingerprintPortrait string) UpdateUserFingerprintPortraitDownEntity {
return UpdateUserFingerprintPortraitDownEntity{
Sn: sn,
Pin: pin,
FingerprintPortrait: fingerprintPortrait,
}
}
... ...
package command
import (
"fmt"
"github.com/beego/beego/v2/core/validation"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/domain"
"reflect"
"strings"
)
type SyncToAttendanceMachineCommand struct {
OperateInfo *domain.OperateInfo `json:"-"`
// 用户关联的角色
Users []int64 `cname:"用户关联的角色" json:"userIds" valid:"Required"`
}
func (syncToAttendance *SyncToAttendanceMachineCommand) Valid(validation *validation.Validation) {
//validation.SetError("CustomValid", "未实现的自定义认证")
}
func (syncToAttendance *SyncToAttendanceMachineCommand) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(syncToAttendance)
if err != nil {
return err
}
if !b {
elem := reflect.TypeOf(syncToAttendance).Elem()
for _, validErr := range valid.Errors {
field, isExist := elem.FieldByName(validErr.Field)
if isExist {
return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1))
} else {
return fmt.Errorf(validErr.Message)
}
}
}
return nil
}
... ...
... ... @@ -34,6 +34,8 @@ type Menu struct {
//IsPublish int `json:"isPublish,omitempty"`
// 启用状态(启用:1 禁用:2),默认启用
EnableStatus int `json:"enableStatus,omitempty"`
// 外链接(需要菜单跳转的时候使用)
Link string `json:"link"`
}
func (dto *UserAccessMenuDto) LoadDto(menus []*domain.Menu) error {
... ... @@ -49,6 +51,7 @@ func (dto *UserAccessMenuDto) LoadDto(menus []*domain.Menu) error {
Sort: v.Sort,
EnableStatus: v.EnableStatus,
ParentPath: v.ParentPath,
Link: v.Link,
})
}
... ...
package service
import (
"github.com/gookit/event"
"github.com/linmadan/egglib-go/core/application"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/application/factory"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/application/user/command"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/log"
)
func (userService *UserService) SyncToAttendanceMachine(cmd *command.SyncToAttendanceMachineCommand) (interface{}, error) {
if err := cmd.ValidateCommand(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
}
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if err := transactionContext.StartTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
defer func() {
transactionContext.RollbackTransaction()
}()
userRepository, _, _ := factory.FastPgUser(transactionContext, 0)
_, users, err := userRepository.Find(map[string]interface{}{"companyId": cmd.OperateInfo.CompanyId, "inUserIds": cmd.Users})
if err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
for i := range users {
_, userBase, err := factory.FastPgUserBase(transactionContext, users[i].UserBaseId)
if err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
if err, _ := event.Fire(domain.UserSyncEvent, event.M{"user": users[i], "userBase": userBase}); err != nil {
log.Logger.Error(err.Error())
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return struct{}{}, nil
}
... ...
... ... @@ -2,6 +2,7 @@ package service
import (
"fmt"
"github.com/gookit/event"
"github.com/linmadan/egglib-go/core/application"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/application/factory"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/application/user/command"
... ... @@ -66,7 +67,7 @@ func (userService *UserService) BatchAdd2(batchAddCommand *command.BatchAdd2Comm
"transactionContext": transactionContext,
})
var failRows []*domain.BatchAddUserItem
if failRows, err = batchAddUserService.BatchAddUser2(batchAddCommand.OperateInfo, batchAddCommand.Users, batchAddCommand.Password); err != nil {
if failRows, err = batchAddUserService.BatchAddUser(batchAddCommand.OperateInfo, batchAddCommand.Users, batchAddCommand.Password); err != nil {
return batchAddCommand.Users, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if len(failRows) != 0 {
... ... @@ -110,6 +111,9 @@ func (userService *UserService) BatchEnable(batchEnableCommand *command.BatchEna
if _, err := userRepository.Save(user); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if err, _ := event.Fire(domain.UserEnableEvent, map[string]interface{}{"user": user}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
}
}
... ...
... ... @@ -68,9 +68,10 @@ type Menu struct {
ParentPath string `json:"parentPath,omitempty"`
// 菜单是否公开状态,[1:显示],[2:隐藏],默认显示
IsPublish int `json:"isPublish,omitempty"`
// 启用状态(启用:1 禁用:2),默认启用
// 启用状态(启用:1 禁用:2),默认启用 (移除不使用,现在只有is_publish状态)
EnableStatus int `json:"enableStatus,omitempty"`
// 外链接(需要菜单跳转的时候使用)
Link string `json:"link"`
// 父级菜单名称
ParentMenuName string `json:"parentMenuName,omitempty"`
}
... ...
... ... @@ -3,6 +3,8 @@ package domain
import (
"fmt"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/constant"
"strconv"
"strings"
"time"
)
... ... @@ -44,7 +46,7 @@ type Org struct {
OrgStatus int `json:"orgStatus,omitempty"`
// 父级ID
ParentId int64 `json:"parentId,omitempty"`
// 父级节点路径("0,11,12,")
// 父级节点路径("11,12") 注意:parent_id为0时 parentPath "",公司级别的组织没有父级组织
ParentPath string `json:"parentPath,omitempty"`
// 企业id
... ... @@ -197,6 +199,23 @@ func (org *Org) ID() string {
return org.GetFullPath()
}
func (org *Org) IsChild(pid int64) bool {
paths := strings.Split(org.ParentPath, PathSegment)
pidStr := strconv.FormatInt(pid, 10)
if org.OrgId == pid {
return true
}
if org.ParentId == pid {
return true
}
for _, v := range paths {
if strings.EqualFold(pidStr, v) {
return true
}
}
return false
}
/***** 2.缓存模块 *****/
func (m *Org) CacheKeyFunc() string {
... ...
... ... @@ -4,6 +4,5 @@ import "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/domain"
// PgBatchAddUserService 批量添加用户服务
type PgBatchAddUserService interface {
BatchAddUser(optUser *domain.OperateInfo, users []*domain.User, password string) error
BatchAddUser2(optUser *domain.OperateInfo, users []*domain.BatchAddUserItem, password string) ([]*domain.BatchAddUserItem, error)
BatchAddUser(optUser *domain.OperateInfo, users []*domain.BatchAddUserItem, password string) ([]*domain.BatchAddUserItem, error)
}
... ...
... ... @@ -26,6 +26,14 @@ const (
UserStatusDestroy UserStatus = 3
)
const (
UserUpdateEvent = "user_update"
UserDeleteEvent = "user_delete"
UserCreateEvent = "user_create"
UserEnableEvent = "user_enable" //禁用启用事件
UserSyncEvent = "user_sync" // 用户同步
)
// 用户
type User struct {
// 用户Id 用户唯一标识
... ...
... ... @@ -13,9 +13,16 @@ type UserInfo struct {
// 员工类型 1:固定 2:派遣 3.临时
EmployeeType int `json:"employeeType,omitempty"`
// IC卡号
// IC卡号 = Pin
IcCardNumber string `json:"icCardNumber,omitempty"`
// 面部识别
FacePortrait string `json:"facePortrait,omitempty"`
// 指纹识别
FingerprintPortrait string `json:"fingerprintPortrait,omitempty"`
// 打卡机标识
// Pin string `json:"pin"`
Referer string `json:"-"`
// 部门
DepartmentName string `cname:"部门" json:"-"`
... ...
... ... @@ -18,71 +18,71 @@ type PgBatchAddUserService struct {
// optUser 操作用户
// users 待添加用户列表数据
// password 密码
func (ptr *PgBatchAddUserService) BatchAddUser(optUser *domain.OperateInfo, users []*domain.User, password string) error {
var (
err error
)
orgRepository, err := repository.NewOrgRepository(ptr.transactionContext)
if err != nil {
return err
}
_, orgs, err := orgRepository.Find(map[string]interface{}{"companyId": optUser.CompanyId})
if err != nil {
return err
}
var mapOrg = make(map[int64]*domain.Org)
for i := range orgs {
mapOrg[orgs[i].OrgId] = orgs[i]
}
createUserService, _ := NewPgCreateUserService(ptr.transactionContext)
for i := range users {
user := users[i]
if err = ptr.preCheck(user); err != nil {
return err
}
newUser := &domain.User{
CompanyId: user.CompanyId,
UserType: user.UserType,
UserCode: user.UserCode,
OrganizationId: user.OrganizationId,
DepartmentId: user.DepartmentId,
UserOrg: []*domain.Org{},
UserRole: []*domain.Role{},
FavoriteMenus: []string{},
CooperationInfo: user.CooperationInfo,
UserInfo: user.UserInfo,
EnableStatus: int(domain.UserStatusEnable),
Ext: &domain.Ext{
Phone: user.UserInfo.Phone,
UserName: user.UserInfo.UserName,
},
CreatedAt: time.Now(),
UpdatedAt: time.Now(),
}
if user.OrganizationId > 0 {
if v, ok := mapOrg[user.OrganizationId]; ok && v.CompanyId == user.CompanyId {
newUser.Ext.OrgName = v.OrgName
} else {
return fmt.Errorf("导入的组织机构不存在")
}
}
if user.DepartmentId > 0 {
if v, ok := mapOrg[user.DepartmentId]; ok && v.CompanyId == user.CompanyId {
newUser.Ext.DepName = v.OrgName
} else {
return fmt.Errorf("导入的所属部门不存在")
}
}
if newUser, err = createUserService.CreateUser(nil, newUser, password); err != nil {
return err
}
}
return nil
}
//func (ptr *PgBatchAddUserService) BatchAddUser(optUser *domain.OperateInfo, users []*domain.User, password string) error {
// var (
// err error
// )
// orgRepository, err := repository.NewOrgRepository(ptr.transactionContext)
// if err != nil {
// return err
// }
// _, orgs, err := orgRepository.Find(map[string]interface{}{"companyId": optUser.CompanyId})
// if err != nil {
// return err
// }
// var mapOrg = make(map[int64]*domain.Org)
// for i := range orgs {
// mapOrg[orgs[i].OrgId] = orgs[i]
// }
//
// createUserService, _ := NewPgCreateUserService(ptr.transactionContext)
// for i := range users {
// user := users[i]
// if err = ptr.preCheck(user); err != nil {
// return err
// }
// newUser := &domain.User{
// CompanyId: user.CompanyId,
// UserType: user.UserType,
// UserCode: user.UserCode,
// OrganizationId: user.OrganizationId,
// DepartmentId: user.DepartmentId,
// UserOrg: []*domain.Org{},
// UserRole: []*domain.Role{},
// FavoriteMenus: []string{},
// CooperationInfo: user.CooperationInfo,
// UserInfo: user.UserInfo,
// EnableStatus: int(domain.UserStatusEnable),
// Ext: &domain.Ext{
// Phone: user.UserInfo.Phone,
// UserName: user.UserInfo.UserName,
// },
// CreatedAt: time.Now(),
// UpdatedAt: time.Now(),
// }
// if user.OrganizationId > 0 {
// if v, ok := mapOrg[user.OrganizationId]; ok && v.CompanyId == user.CompanyId {
// newUser.Ext.OrgName = v.OrgName
// } else {
// return fmt.Errorf("导入的组织机构不存在")
// }
// }
// if user.DepartmentId > 0 {
// if v, ok := mapOrg[user.DepartmentId]; ok && v.CompanyId == user.CompanyId {
// newUser.Ext.DepName = v.OrgName
// } else {
// return fmt.Errorf("导入的所属部门不存在")
// }
// }
//
// if newUser, err = createUserService.CreateUser(nil, newUser, password); err != nil {
// return err
// }
// }
// return nil
//}
func (ptr *PgBatchAddUserService) BatchAddUser2(optUser *domain.OperateInfo, users []*domain.BatchAddUserItem, password string) ([]*domain.BatchAddUserItem, error) {
func (ptr *PgBatchAddUserService) BatchAddUser(optUser *domain.OperateInfo, users []*domain.BatchAddUserItem, password string) ([]*domain.BatchAddUserItem, error) {
var (
err error
)
... ... @@ -99,6 +99,10 @@ func (ptr *PgBatchAddUserService) BatchAddUser2(optUser *domain.OperateInfo, use
for i := range orgs {
mapOrg[orgs[i].OrgCode] = orgs[i]
}
optUserOrg, err := orgRepository.FindOne(map[string]interface{}{"orgId": optUser.OrgId})
if err != nil {
return failRows, err
}
createUserService, _ := NewPgCreateUserService(ptr.transactionContext)
for i := range users {
... ... @@ -108,23 +112,31 @@ func (ptr *PgBatchAddUserService) BatchAddUser2(optUser *domain.OperateInfo, use
failRows = append(failRows, user)
continue
}
var org, dep *domain.Org
var org = optUserOrg
var dep *domain.Org
var ok bool
if org, ok = mapOrg[user.Org]; !ok {
user.FailReason = "导入的组织机构不存在:" + user.Org
failRows = append(failRows, user)
continue
}
// 使用导入用户的组织作为默认组织
//if org, ok = mapOrg[user.Org]; !ok {
// user.FailReason = "导入的组织机构不存在:" + user.Org
// failRows = append(failRows, user)
// continue
//}
if dep, ok = mapOrg[user.Department]; !ok && user.UserType != domain.UserTypeCooperation {
user.FailReason = "导入的所属部门不存在:" + user.Department
failRows = append(failRows, user)
continue
}
//TODO:子部门判断
//if dep != nil && !dep.IsChild(optUser.OrgId) {
// user.FailReason = fmt.Sprintf("导入的所属部门不是当前登录组织(%v)的子部门:%v", optUserOrg.OrgName, user.Department)
// failRows = append(failRows, user)
// continue
//}
newUser := &domain.User{
CompanyId: user.CompanyId,
UserType: user.UserType,
UserCode: user.UserCode,
OrganizationId: org.OrgId,
OrganizationId: optUser.OrgId,
UserOrg: []*domain.Org{},
UserRole: []*domain.Role{},
FavoriteMenus: []string{},
... ... @@ -172,24 +184,24 @@ func (ptr *PgBatchAddUserService) BatchAddUser2(optUser *domain.OperateInfo, use
return failRows, nil
}
func (ptr *PgBatchAddUserService) preCheck(user *domain.User) error {
if len(user.UserCode) == 0 {
return fmt.Errorf("导入的用户编码为空值")
}
if len(user.UserInfo.UserName) == 0 {
return fmt.Errorf("导入的用户姓名为空值")
}
if len(user.UserInfo.Phone) == 0 || len(user.UserInfo.Phone) != 11 {
return fmt.Errorf("导入的手机号不是有效手机号")
}
if user.OrganizationId == 0 {
return fmt.Errorf("导入的组织机构不存在")
}
if user.DepartmentId == 0 && user.UserType == domain.UserTypeEmployee {
return fmt.Errorf("导入的所属部门不存在")
}
return nil
}
//func (ptr *PgBatchAddUserService) preCheck(user *domain.User) error {
// if len(user.UserCode) == 0 {
// return fmt.Errorf("导入的用户编码为空值")
// }
// if len(user.UserInfo.UserName) == 0 {
// return fmt.Errorf("导入的用户姓名为空值")
// }
// if len(user.UserInfo.Phone) == 0 || len(user.UserInfo.Phone) != 11 {
// return fmt.Errorf("导入的手机号不是有效手机号")
// }
// if user.OrganizationId == 0 {
// return fmt.Errorf("导入的组织机构不存在")
// }
// if user.DepartmentId == 0 && user.UserType == domain.UserTypeEmployee {
// return fmt.Errorf("导入的所属部门不存在")
// }
// return nil
//}
func (ptr *PgBatchAddUserService) preCheck2(user *domain.BatchAddUserItem) error {
if len(user.UserCode) == 0 {
... ...
... ... @@ -2,6 +2,7 @@ package domainService
import (
"fmt"
"github.com/gookit/event"
pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/infrastructure/repository"
... ... @@ -96,6 +97,10 @@ func (ptr *PgCreateUserService) CreateUser(optUser *domain.User, newUser *domain
return nil, err
}
}
// 新建用户事件
if err, _ := event.Fire(domain.UserCreateEvent, event.M{"user": newUser, "userBase": userBase}); err != nil {
return nil, err
}
return user, nil
}
... ...
... ... @@ -22,6 +22,7 @@ type PgRoleAccessMenusService struct {
func (ptr *PgRoleAccessMenusService) AccessMenus(options *domain.OperateInfo, roleIds []int64, option domain.AccessMenusOptions) ([]*domain.Menu, error) {
var err error
var menus []*domain.Menu
var hasAdminRole bool = false
menuIdSet := hashset.New()
if len(roleIds) == 0 {
return menus, nil
... ... @@ -34,6 +35,9 @@ func (ptr *PgRoleAccessMenusService) AccessMenus(options *domain.OperateInfo, ro
if role, _ = roleRepository.FindOne(map[string]interface{}{"roleId": roleIds[i]}); role == nil {
continue
}
if role.RoleType&domain.RoleTypeAdmin > 0 {
hasAdminRole = true
}
// 只要当前登录组织的有权限菜单
if option.OrgId > 0 && option.OrgId != role.OrgId {
continue
... ... @@ -66,7 +70,7 @@ func (ptr *PgRoleAccessMenusService) AccessMenus(options *domain.OperateInfo, ro
if err != nil {
return nil, err
}
_, alias, err := customizeMenuRepository.Find(map[string]interface{}{"companyId": option.CompanyId})
_, menuAlias, err := customizeMenuRepository.Find(map[string]interface{}{"companyId": option.CompanyId})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
... ... @@ -75,17 +79,22 @@ func (ptr *PgRoleAccessMenusService) AccessMenus(options *domain.OperateInfo, ro
var mapMenus = make(map[int64]*domain.Menu)
for i := range menus {
menus[i].EnableStatus = domain.MenuStatusDisable
if menus[i].IsPublish == domain.MenuPublic && hasAdminRole {
menus[i].EnableStatus = domain.MenuStatusEnable //管理员角色,返回所有权限
}
mapMenus[menus[i].MenuId] = menus[i]
}
for i := range alias {
if v, ok := mapMenus[alias[i].MenuId]; ok {
v.MenuName = alias[i].MenuAlias // 设置别名
v.Sort = alias[i].Sort
// 4.1.设置别名
for i := range menuAlias {
if v, ok := mapMenus[menuAlias[i].MenuId]; ok {
v.MenuName = menuAlias[i].MenuAlias
v.Sort = menuAlias[i].Sort
}
}
// 4.2.设置菜单权限状态
values := menuIdSet.Values()
for i := range values {
menuId := (values[i]).(int64) // 设置菜单权限状态
menuId := (values[i]).(int64)
if v, ok := mapMenus[menuId]; ok {
v.EnableStatus = domain.MenuStatusEnable
}
... ...
... ... @@ -2,6 +2,7 @@ package domainService
import (
"fmt"
"github.com/gookit/event"
pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/infrastructure/repository"
... ... @@ -108,6 +109,10 @@ func (ptr *PgUpdateUserService) UpdateUser(optUser *domain.OperateInfo, user *do
if user, err = userRepository.Save(user); err != nil {
return nil, err
}
// 新建用户事件
if err, _ := event.Fire(domain.UserUpdateEvent, event.M{"user": user, "userBase": userBase}); err != nil {
return nil, err
}
return user, nil
}
... ...
... ... @@ -28,6 +28,8 @@ type Menu struct {
IsPublish int `comment:"菜单是否公开状态,[2:隐藏],[1:显示],默认显示"`
// 启用状态(启用:1 禁用:2),默认启用
EnableStatus int `comment:"启用状态(启用:1 禁用:2),默认启用"`
// 外链接(需要菜单跳转的时候使用)
Link string `json:"link"`
// 删除时间
//DeletedAt time.Time `comment:"删除时间"`
}
... ...
... ... @@ -21,5 +21,6 @@ func TransformToMenuDomainModelFromPgModels(menuModel *models.Menu) (*domain.Men
ParentPath: menuModel.ParentPath,
IsPublish: menuModel.IsPublish,
EnableStatus: menuModel.EnableStatus,
Link: menuModel.Link,
}, nil
}
... ...
... ... @@ -204,6 +204,9 @@ func (repository *UserRepository) Find(queryOptions map[string]interface{}) (int
}
query.SetWhereByQueryOption("company_id=?", "companyId")
query.SetWhereByQueryOption("organization_id=?", "organizationId")
if v, ok := queryOptions["inUserIds"]; ok && len(v.([]int64)) > 0 {
query.Where(`user_id in (?)`, pg.In(v))
}
if v, ok := queryOptions["inOrgIds"]; ok && len(v.([]int64)) > 0 {
query.Where(`organization_id in (?)`, pg.In(v))
}
... ...
package controllers
import (
"github.com/linmadan/egglib-go/web/beego"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/application/terminal/command"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/application/terminal/service"
)
type TerminalController struct {
beego.BaseController
}
func (controller *TerminalController) TerminalReport() {
service := service.NewTerminalService(nil)
terminalReportCommand := &command.TerminalReportCommand{}
controller.Unmarshal(terminalReportCommand)
data, err := service.TerminalReport(terminalReportCommand)
controller.Response(data, err)
}
... ...
... ... @@ -179,3 +179,12 @@ func (controller *UserController) UpdateAdminUser() {
data, err := userService.UpdateAdminUser(updateUserCommand)
controller.Response(data, err)
}
func (controller *UserController) SyncToAttendanceMachine() {
userService := service.NewUserService(nil)
cmd := &command.SyncToAttendanceMachineCommand{}
Must(controller.Unmarshal(cmd))
cmd.OperateInfo = ParseOperateInfo(controller.BaseController)
data, err := userService.SyncToAttendanceMachine(cmd)
controller.Response(data, err)
}
... ...
package routers
import (
"github.com/beego/beego/v2/server/web"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/port/beego/controllers"
)
func init() {
web.Router("/terminal/report", &controllers.TerminalController{}, "Post:TerminalReport")
}
... ...
... ... @@ -21,6 +21,8 @@ func init() {
web.Router("/user/cooperator", &controllers.UserController{}, "Post:CreateCooperator")
web.Router("/user/cooperator/:userId", &controllers.UserController{}, "Put:UpdateCooperator")
web.Router("/user/sync-to-attendance-machine", &controllers.UserController{}, "Post:SyncToAttendanceMachine")
web.Router("/admin-user/", &controllers.UserController{}, "Post:CreateAdminUser")
web.Router("/admin-user/:userId", &controllers.UserController{}, "Put:UpdateAdminUser")
}
... ...