Create & Init Project...
This commit is contained in:
38
app/admin/main/aegis/model/business/BUILD
Normal file
38
app/admin/main/aegis/model/business/BUILD
Normal file
@ -0,0 +1,38 @@
|
||||
package(default_visibility = ["//visibility:public"])
|
||||
|
||||
load(
|
||||
"@io_bazel_rules_go//go:def.bzl",
|
||||
"go_library",
|
||||
)
|
||||
|
||||
go_library(
|
||||
name = "go_default_library",
|
||||
srcs = [
|
||||
"business.go",
|
||||
"config.go",
|
||||
],
|
||||
importpath = "go-common/app/admin/main/aegis/model/business",
|
||||
tags = ["automanaged"],
|
||||
visibility = ["//visibility:public"],
|
||||
deps = [
|
||||
"//app/admin/main/aegis/model:go_default_library",
|
||||
"//app/admin/main/aegis/model/common:go_default_library",
|
||||
"//app/admin/main/aegis/model/middleware:go_default_library",
|
||||
"//library/log:go_default_library",
|
||||
"//library/time:go_default_library",
|
||||
],
|
||||
)
|
||||
|
||||
filegroup(
|
||||
name = "package-srcs",
|
||||
srcs = glob(["**"]),
|
||||
tags = ["automanaged"],
|
||||
visibility = ["//visibility:private"],
|
||||
)
|
||||
|
||||
filegroup(
|
||||
name = "all-srcs",
|
||||
srcs = [":package-srcs"],
|
||||
tags = ["automanaged"],
|
||||
visibility = ["//visibility:public"],
|
||||
)
|
217
app/admin/main/aegis/model/business/business.go
Normal file
217
app/admin/main/aegis/model/business/business.go
Normal file
@ -0,0 +1,217 @@
|
||||
package business
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"reflect"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"go-common/app/admin/main/aegis/model"
|
||||
"go-common/app/admin/main/aegis/model/common"
|
||||
"go-common/library/log"
|
||||
xtime "go-common/library/time"
|
||||
)
|
||||
|
||||
const (
|
||||
// StateEnable 正常
|
||||
StateEnable = int8(0)
|
||||
// StateDisable 删除
|
||||
StateDisable = int8(1)
|
||||
|
||||
// TypeIframe .
|
||||
TypeIframe = int8(0)
|
||||
// TypeSubmit 提交接口配置
|
||||
TypeSubmit = int8(1)
|
||||
// TypeAction 预留给前端组件配置
|
||||
TypeAction = int8(2)
|
||||
// TypeManagerBID 角色配置
|
||||
TypeManagerBID = int8(3)
|
||||
// TypeReverse 保留字配置
|
||||
TypeReverse = int8(4)
|
||||
// TypeAttribute 属性位配置
|
||||
TypeAttribute = int8(5)
|
||||
// TypeDeleteState 删除状态配置
|
||||
TypeDeleteState = int8(6)
|
||||
// TypeFiler 敏感词过滤
|
||||
TypeFiler = int8(7)
|
||||
// TypeBizBID 业务级别用户角色
|
||||
TypeBizBID = int8(8)
|
||||
// TypeAdapter 适配器配置
|
||||
TypeAdapter = int8(9)
|
||||
// TypeRscListAdapter 资源列表适配器
|
||||
TypeRscListAdapter = int8(10)
|
||||
// 中间件配置,用于前后端交互的自定义数据逻辑处理
|
||||
TypeMiddleware = int8(11)
|
||||
// TypeTempCodes 临时错误码
|
||||
TypeTempCodes = int8(12)
|
||||
// TypeCallback TODO 提交接口v2版本,为了兼容线上的TypeSubmit。待v2上线后,再去掉该配置,改为TypeSubmit
|
||||
TypeCallback = int8(13)
|
||||
|
||||
// MngBIDMID 任务用户角色: {"manager_id":1, "flow_id":12}
|
||||
MngBIDMID = "manager_id"
|
||||
// MngBIDFlow .
|
||||
MngBIDFlow = "flow_id"
|
||||
// BizBIDMngID 业务用户角色: {"manager_id":1, "admin":12}
|
||||
BizBIDMngID = "manager_id"
|
||||
// BizBIDAdmin .
|
||||
BizBIDAdmin = "admin"
|
||||
// AccessBiz .
|
||||
AccessBiz = "access_biz"
|
||||
// AccessFlow .
|
||||
AccessFlow = "access_flow"
|
||||
)
|
||||
|
||||
// Business .
|
||||
type Business struct {
|
||||
ID int64 `json:"id" gorm:"primary_key" form:"id"`
|
||||
TP int64 `json:"type" gorm:"column:type" form:"type"`
|
||||
Name string `json:"name" gorm:"column:name" form:"name" validate:"max=10"`
|
||||
Desc string `json:"desc" gorm:"column:desc" form:"desc" validate:"max=160"`
|
||||
Developer string `json:"developer" gorm:"column:developer" form:"developer"`
|
||||
UID int64 `json:"uid" gorm:"column:uid"`
|
||||
Attribute int64 `json:"attribute" gorm:"column:attribute" form:"attribute"`
|
||||
State int64 `json:"state" gorm:"column:state" form:"state"`
|
||||
UserName string `json:"username" gorm:"-"`
|
||||
Ctime xtime.Time `json:"ctime" gorm:"column:ctime"`
|
||||
Mtime xtime.Time `json:"mtime" gorm:"column:mtime"`
|
||||
}
|
||||
|
||||
// IAdapter .
|
||||
type IAdapter interface {
|
||||
AdaptString(val string) string
|
||||
AdaptInt64(val int64) int64
|
||||
}
|
||||
|
||||
// Adapter 业务适配器
|
||||
type Adapter struct {
|
||||
Name string `json:"name"`
|
||||
Rule string `json:"rule"`
|
||||
Value string `json:"value"`
|
||||
Compare string `json:"compare"`
|
||||
}
|
||||
|
||||
// AdaptString .
|
||||
func (a Adapter) AdaptString(val string) string {
|
||||
return val
|
||||
}
|
||||
|
||||
// AdaptInt .
|
||||
func (a Adapter) AdaptInt(val int64) int64 {
|
||||
switch a.Rule {
|
||||
case "not":
|
||||
if strconv.FormatInt(val, 10) != a.Compare {
|
||||
if v, e := strconv.ParseInt(a.Value, 10, 64); e != nil {
|
||||
log.Error("AdaptInt strconv.ParseInt(%s)", a.Value)
|
||||
} else {
|
||||
val = v
|
||||
}
|
||||
}
|
||||
default:
|
||||
log.Error("AdaptInt unsupported rule(%s)", a.Rule)
|
||||
}
|
||||
return val
|
||||
}
|
||||
|
||||
// AdaptAddOpt ..
|
||||
func AdaptAddOpt(opt *model.AddOption, adps []*Adapter) {
|
||||
if len(adps) == 0 || opt == nil {
|
||||
return
|
||||
}
|
||||
|
||||
log.Info("AdaptAddOpt before opt(%+v)", opt)
|
||||
v := reflect.ValueOf(opt).Elem()
|
||||
for _, adp := range adps {
|
||||
val := v.FieldByName(adp.Name)
|
||||
if !val.CanSet() {
|
||||
log.Error("AdaptAddOpt field(%s) can't set", adp.Name)
|
||||
return
|
||||
}
|
||||
|
||||
switch val.Kind() {
|
||||
case reflect.String:
|
||||
val.SetString(adp.AdaptString(val.String()))
|
||||
case reflect.Int8, reflect.Int64, reflect.Int:
|
||||
val.SetInt(adp.AdaptInt(val.Int()))
|
||||
default:
|
||||
log.Error("AdaptAddOpt unsupported adp(%+v) type(%v)", adp, val.Kind())
|
||||
}
|
||||
}
|
||||
log.Info("AdaptAddOpt after opt(%+v)", opt)
|
||||
}
|
||||
|
||||
// AdaptUpdateOpt ..
|
||||
func AdaptUpdateOpt(opt *model.UpdateOption, adps []*Adapter) {
|
||||
if len(adps) == 0 || opt == nil {
|
||||
return
|
||||
}
|
||||
|
||||
log.Info("AdaptUpdateOpt before opt(%+v)", opt)
|
||||
for _, adp := range adps {
|
||||
key := strings.ToLower(adp.Name)
|
||||
if iv, ok := opt.Update[key]; ok {
|
||||
switch reflect.TypeOf(iv).Kind() {
|
||||
case reflect.String:
|
||||
opt.Update[key] = adp.AdaptString(iv.(string))
|
||||
case reflect.Int8, reflect.Int64, reflect.Int:
|
||||
intv, err := strconv.Atoi(fmt.Sprint(iv))
|
||||
if err != nil {
|
||||
log.Error("AdaptUpdateOpt unsupported adp(%+v)", adp)
|
||||
continue
|
||||
}
|
||||
opt.Update[key] = adp.AdaptInt(int64(intv))
|
||||
default:
|
||||
log.Error("AdaptUpdateOpt unsupported adp(%+v)", adp)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
log.Info("AdaptUpdateOpt after opt(%+v)", opt)
|
||||
}
|
||||
|
||||
// TableName .
|
||||
func (t *Business) TableName() string {
|
||||
return "business"
|
||||
}
|
||||
|
||||
// OptList .
|
||||
type OptList struct {
|
||||
common.Pager
|
||||
TP int8 `form:"type"`
|
||||
}
|
||||
|
||||
// ListBusiness .
|
||||
type ListBusiness struct {
|
||||
common.Pager
|
||||
Business []*Business `json:"business"`
|
||||
}
|
||||
|
||||
// BizItem .
|
||||
type BizItem struct {
|
||||
BizID int64 `json:"business_id"`
|
||||
BizName string `json:"business_name"`
|
||||
BizType int64 `json:"biz_type"`
|
||||
Flows map[int64]string `json:"flows"`
|
||||
}
|
||||
|
||||
// FlowItem .
|
||||
type FlowItem struct {
|
||||
FlowID int64 `json:"flow_id"`
|
||||
NetID int64 `json:"net_id"`
|
||||
Name string `json:"name"`
|
||||
ChName string `json:"ch_name"`
|
||||
}
|
||||
|
||||
// BizItemArr .
|
||||
type BizItemArr []*BizItem
|
||||
|
||||
func (a BizItemArr) Len() int {
|
||||
return len(a)
|
||||
}
|
||||
|
||||
func (a BizItemArr) Less(i, j int) bool {
|
||||
return a[i].BizID < a[j].BizID
|
||||
}
|
||||
|
||||
func (a BizItemArr) Swap(i, j int) {
|
||||
a[i], a[j] = a[j], a[i]
|
||||
}
|
87
app/admin/main/aegis/model/business/config.go
Normal file
87
app/admin/main/aegis/model/business/config.go
Normal file
@ -0,0 +1,87 @@
|
||||
package business
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
"go-common/app/admin/main/aegis/model/middleware"
|
||||
"go-common/library/log"
|
||||
xtime "go-common/library/time"
|
||||
)
|
||||
|
||||
// BizCFG .
|
||||
type BizCFG struct {
|
||||
ID int64 `json:"id" gorm:"primary_key" form:"id"`
|
||||
BusinessID int64 `json:"business_id" gorm:"column:business_id" form:"business_id"`
|
||||
TP int8 `json:"type" gorm:"column:type" form:"type"`
|
||||
Config string `json:"config" gorm:"column:config" form:"config"`
|
||||
State int64 `json:"state" gorm:"column:state" form:"state"`
|
||||
Ctime xtime.Time `json:"ctime" gorm:"column:ctime"`
|
||||
Mtime xtime.Time `json:"mtime" gorm:"column:mtime"`
|
||||
}
|
||||
|
||||
// TableName .
|
||||
func (t *BizCFG) TableName() string {
|
||||
return "business_config"
|
||||
}
|
||||
|
||||
// FormatMngBID .
|
||||
func (t *BizCFG) FormatMngBID() (biz int64, roles map[int64][]int64, err error) {
|
||||
var (
|
||||
cfgs []map[string]int64
|
||||
)
|
||||
|
||||
if t.TP != TypeManagerBID || t.Config == "" {
|
||||
return
|
||||
}
|
||||
|
||||
biz = t.BusinessID
|
||||
roles = map[int64][]int64{}
|
||||
if err = json.Unmarshal([]byte(t.Config), &cfgs); err != nil {
|
||||
log.Error("FormatMngBID json.Unmarshal(%+v) error(%v)", t, err)
|
||||
return
|
||||
}
|
||||
|
||||
for _, item := range cfgs {
|
||||
if item[MngBIDMID] <= 0 || item[MngBIDFlow] <= 0 {
|
||||
continue
|
||||
}
|
||||
if _, exist := roles[item[MngBIDMID]]; !exist {
|
||||
roles[item[MngBIDMID]] = []int64{}
|
||||
}
|
||||
roles[item[MngBIDMID]] = append(roles[item[MngBIDMID]], item[MngBIDFlow])
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// FormatBizBID .
|
||||
func (t *BizCFG) FormatBizBID() (biz int64, roles map[string]int64, err error) {
|
||||
if t.TP != TypeBizBID || t.Config == "" {
|
||||
return
|
||||
}
|
||||
|
||||
biz = t.BusinessID
|
||||
if err = json.Unmarshal([]byte(t.Config), &roles); err != nil {
|
||||
log.Error("FormatBizBID json.Unmarshal(%+v) error(%v)", t, err)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
//FormatAggregate 聚合配置
|
||||
func (t *BizCFG) FormatAggregate() (cfgs []*middleware.Aggregate, err error) {
|
||||
if t.TP != TypeMiddleware || t.Config == "" {
|
||||
return
|
||||
}
|
||||
|
||||
cfgs = []*middleware.Aggregate{}
|
||||
if err = json.Unmarshal([]byte(t.Config), &cfgs); err != nil {
|
||||
log.Error("FormatAggregate json.Unmarshal error(%+v)", err)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// ManagerRole .
|
||||
type ManagerRole struct {
|
||||
FlowID int64 `json:"flow_id"`
|
||||
MngBid int64 `json:"manager_bid"`
|
||||
}
|
Reference in New Issue
Block a user