作者 yangfu

Merge branch 'test'

... ... @@ -36,7 +36,7 @@ func (tableEventService *TableEventService) DigitalPlatformEventSubscribe(ctx *d
data := cmd.EventTable
tableId := 0
switch data.Type {
case domain.TableDataImportEvent, domain.TableDataEditEvent, domain.TableDeleteEvent:
case domain.TableDataImportEvent, domain.TableDataEditEvent, domain.TableDeleteEvent, domain.TableStructEditEvent:
tableId = data.Table.TableId
case domain.QuerySetUpdateEvent, domain.QuerySetUpdateRenameEvent:
tableId = data.QuerySet.QuerySetInfo.BindTableId
... ... @@ -102,7 +102,7 @@ func (tableEventService *TableEventService) DigitalPlatformEventSubscribe(ctx *d
querySetRepository, _, _ := factory.FastPgQuerySet(transactionContext, 0)
var mapTableQuerySet = make(map[int]*domain.QuerySet)
if len(tree) > 0 && cmd.EventTable.QuerySet != nil {
if len(tree) > 0 { // && cmd.EventTable.QuerySet != nil
_, querySets, _ := querySetRepository.Find(map[string]interface{}{
"types": []string{domain.SchemaTable.ToString(), domain.CalculateItem.ToString(), domain.CalculateSet.ToString()},
"bindTableIds": tree,
... ...
... ... @@ -37,7 +37,7 @@ func (tableEventService *TableEventService) Handler(ctx *domain.Context, cmd *co
data := cmd.EventTable
tableId := 0
switch data.Type {
case domain.TableDataImportEvent, domain.TableDataEditEvent, domain.TableDeleteEvent:
case domain.TableDataImportEvent, domain.TableDataEditEvent, domain.TableDeleteEvent, domain.TableStructEditEvent:
tableId = data.Table.TableId
case domain.QuerySetUpdateEvent:
tableId = data.QuerySet.QuerySetInfo.BindTableId
... ... @@ -92,7 +92,7 @@ func (tableEventService *TableEventService) HandlerTableAffectedMarkToConflictSt
data := cmd.EventTable
tableId := 0
switch data.Type {
case domain.TableDataEditEvent:
case domain.TableStructEditEvent, domain.TableDeleteEvent:
tableId = data.Table.TableId
case domain.QuerySetUpdateEvent, domain.QuerySetUpdateRenameEvent:
tableId = data.QuerySet.QuerySetInfo.BindTableId
... ...
... ... @@ -25,7 +25,15 @@ type FileDto struct {
// 表ID
TableId int `json:"tableId"`
// 允许表生成标识 1:允许生成分表 0:不允许
AllowTableGenerateFlag int `json:"allowTableGenerateFlag"`
AllowTableGenerateFlag int `json:"-"`
// 允许表处理标识 1:允许 0:不允许
AllowTableProcessFlag int `json:"-"`
// 允许表导出标识 1:允许 0:不允许
AllowTableExportFlag int `json:"-"`
// 标志位 1:可校验 2:可分表生成 4:导出
Flag int `json:"-"`
// 标志位 1:可校验 2:可分表生成 4:导出
Flags []int `json:"flags"`
}
func (d *FileDto) Load(f *domain.File) *FileDto {
... ... @@ -40,13 +48,40 @@ func (d *FileDto) Load(f *domain.File) *FileDto {
d.Time = xtime.New(f.UpdatedAt).Local().Format("2006-01-02 15:04:05")
d.HeaderRow = domain.GetHeaderRow(f.FileInfo.HeaderRow)
d.AppKey = f.AppKey
//d.AllowTableProcessFlag = 1
//d.AllowTableExportFlag = 1
d.AddFlag(5) // 默认可以 校验、导出
if len(f.AppKey) > 0 && f.FileInfo.TableId > 0 {
d.TableId = f.FileInfo.TableId
d.AllowTableGenerateFlag = 1
//d.AllowTableGenerateFlag = 1
d.AddFlag(2) // 可分表生成
d.RemoveFlag(1) // 不可校验
//d.RemoveFlag(4) // 不可校验
//d.AllowTableProcessFlag = 0
//d.AllowTableExportFlag = 0
}
for i := 1; i <= 4; i = i << 1 {
if i&d.Flag == i {
d.Flags = append(d.Flags, i)
}
}
return d
}
func (d *FileDto) AddFlag(flag int) {
if d.Flag&flag == flag {
return
}
d.Flag |= flag
}
func (d *FileDto) RemoveFlag(flag int) {
if d.Flag&flag != flag {
return
}
d.Flag ^= flag
}
type AppDto struct {
AppId int64 `json:"appId"`
AppKey string `json:"appKey"`
... ...
... ... @@ -15,7 +15,7 @@ type CreateQuerySetCommand struct {
// 标识
Flag string `cname:"标识" json:"flag" valid:"Required"`
// 名称
Name string `cname:"名称" json:"name" valid:"Required"`
Name string `cname:"名称" json:"name"`
// 父级ID
ParentId int `cname:"父级ID" json:"parentId,omitempty"`
}
... ...
... ... @@ -98,8 +98,10 @@ func (querySetService *QuerySetService) CreateQuerySet(ctx *domain.Context, crea
Name: createQuerySetCommand.Name,
ParentId: createQuerySetCommand.ParentId,
}
svr, _ := factory.FastQuerySetServices(transactionContext)
if len(createQuerySetCommand.Name) == 0 {
createQuerySetCommand.Name = fmt.Sprintf("%s%s", domain.EnumsDescription(domain.ObjectTypeMap, createQuerySetCommand.Type), utils.Krand(5, utils.KC_RAND_KIND_NUM))
}
var querySet *domain.QuerySet
if querySet, err = svr.Create(ctx, newQuerySet); err != nil {
return nil, factory.FastError(err)
... ...
... ... @@ -35,7 +35,7 @@ func (d *TableDto) Load(m *domain.Table) *TableDto {
d.Modules = make([]int, 0)
if m.TableInfo != nil {
//d.Module = m.TableInfo.ApplyOnModule
for i := 1; i <= 3; i++ {
for i := 1; i <= 4; i++ {
if m.TableInfo.ApplyOnModule&(1<<(i-1)) > 0 {
d.Modules = append(d.Modules, 1<<(i-1))
}
... ...
... ... @@ -24,7 +24,7 @@ type SearchTableQuery struct {
// 返回结构信息
ReturnDetailStructInfo bool `cname:"返回具体的结构信息 默认不返回" json:"returnDetailStructInfo"`
// 排除分组项,只返回一级列表;默认 false 不排除,连分组也返回
ReturnGroupItem bool `cname:"排除分组" json:"returnGroupItem"`
ReturnGroupItem *bool `cname:"排除分组" json:"returnGroupItem"`
// 排除指定表
ExcludeTables []int `cname:"排除指定表" json:"excludeTables"`
Context *domain.Context
... ...
package service
import (
"fmt"
"github.com/linmadan/egglib-go/core/application"
"gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/application/factory"
"gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/application/table/dto"
... ... @@ -56,7 +55,7 @@ func (tableService *TableService) TableObjectSearch(searchQuery *query.SearchTab
querySetMapById = make(map[int]*domain.QuerySet)
querySetMapByTableId = make(map[int]*domain.QuerySet)
)
if searchQuery.ReturnGroupItem {
if searchQuery.ReturnGroupItem != nil && *searchQuery.ReturnGroupItem {
for _, qs := range querySets {
querySetMapById[qs.QuerySetId] = qs
}
... ... @@ -84,6 +83,10 @@ func (tableService *TableService) TableObjectSearch(searchQuery *query.SearchTab
if filterTableByFilterRule(t, searchQuery) {
continue
}
// 默认关闭的都不返回(拆解、计算)
if t.Status == domain.StatusOff {
continue
}
if !domain.TableType(t.TableType).TableIsSplitByGroup() {
response = append(response, t)
continue
... ... @@ -121,9 +124,10 @@ func (tableService *TableService) TableObjectSearch(searchQuery *query.SearchTab
sort.Slice(response, func(i, j int) bool {
item1 := response[i]
item2 := response[j]
k1 := fmt.Sprintf("%v-%v-%v", item1.TableType, item1.ParentId, item1.Id)
k2 := fmt.Sprintf("%v-%v-%v", item2.TableType, item2.ParentId, item2.Id)
return k1 < k2
//k1 := fmt.Sprintf("%v-%v-%v", item1.TableType, item1.ParentId, item1.Id)
//k2 := fmt.Sprintf("%v-%v-%v", item2.TableType, item2.ParentId, item2.Id)
//return k1 < k2
return item1.Id < item2.Id
})
return map[string]interface{}{
"count": len(response),
... ...
... ... @@ -540,8 +540,9 @@ const (
)
const (
ModuleAll = ModuleDigitalCenter | ModuleQuerySetCenter | ModuleCalculateCenter
ModuleAll = ModuleDigitalCenter | ModuleQuerySetCenter | ModuleCalculateCenter | ModuleChartTemplate
ModuleDigitalCenter = 1
ModuleQuerySetCenter = 2
ModuleCalculateCenter = 4
ModuleChartTemplate = 8
)
... ...
... ... @@ -10,6 +10,7 @@ func (et EventType) ToString() string {
const (
TableDataEditEvent EventType = "table.data.edit"
TableStructEditEvent EventType = "table.struct.edit"
TableDataImportEvent EventType = "table.data.import"
TableDeleteEvent EventType = "table.delete"
QuerySetUpdateEvent EventType = "table.query.set.update"
... ...
... ... @@ -50,6 +50,13 @@ type LayoutCellData struct {
func (l *LayoutRuleItem) LayoutCells() []*LayoutCell {
var cells = make([]*LayoutCell, 0)
// 排序
sort.SliceStable(l.Cells, func(i, j int) bool {
if l.Cells[i].Position.X == l.Cells[j].Position.X {
return l.Cells[i].Position.Y < l.Cells[j].Position.Y
}
return l.Cells[i].Position.X < l.Cells[j].Position.X
})
for _, item := range l.Cells {
item.X = item.Position.X
item.Y = item.Position.Y
... ...
package domain
type TableInfo struct {
// 应用于模块 1:数控中心 2:拆解模块 4:计算模块
// 应用于模块 1:数控中心 2:拆解模块 4:计算模块 8:图表模板
ApplyOnModule int `json:"module"`
// 依赖关联的表
DependencyTables []int `json:"dependencyTables"`
... ...
... ... @@ -43,14 +43,16 @@ func (ptr *QuerySetService) Create(ctx *domain.Context, qs *domain.QuerySet) (*d
Name: qs.Name,
ParentId: qs.ParentId,
PinName: pinFull(qs.Name),
Status: domain.StatusOn,
Status: domain.StatusOff,
QuerySetInfo: &domain.QuerySetInfo{},
QueryComponents: make([]*domain.QueryComponent, 0),
CreatedAt: time.Now(),
UpdatedAt: time.Now(),
Context: ctx,
}
if qs.Flag == domain.FlagGroup {
newQuerySet.Status = domain.StatusOn
}
querySetRepository, err := repository.NewQuerySetRepository(ptr.transactionContext)
// check parent
options := map[string]interface{}{
... ... @@ -1039,7 +1041,7 @@ func copyQuerySet(qs *domain.QuerySet, t string, groupId int, name string) *doma
Name: name,
PinName: pinFull(name),
ParentId: groupId,
Status: qs.Status,
Status: domain.StatusOff,
QuerySetInfo: qs.QuerySetInfo,
QueryComponents: qs.QueryComponents,
Sort: 0,
... ...
... ... @@ -303,7 +303,9 @@ func DataLayout(res *domain.DataTable, cells []*domain.LayoutCell) (*domain.Data
dt.processed = append(dt.processed, cell)
dt.LastCell = cell
}
dt.Shrink()
if err := dt.Shrink(); err != nil {
return nil, err
}
return dt.DataTable, nil
}
... ... @@ -419,7 +421,7 @@ func (d *DataLayoutDataTable) BlockData(cells *domain.LayoutCell) ([]string, int
return values, len(values)
}
func (d *DataLayoutDataTable) Shrink() {
func (d *DataLayoutDataTable) Shrink() error {
x := d.PointEnd.X - d.PointBegin.X
y := d.PointEnd.Y - d.PointBegin.Y
data := make([][]string, x+1)
... ... @@ -443,6 +445,26 @@ func (d *DataLayoutDataTable) Shrink() {
SQLType: domain.String.ToString(),
})
}
// 默认计算集第一行作为标题
//if len(data) >= 1 {
// d.DataTable.Data = data[1:]
// columnMap := collection.NewSet()
// for i := 0; i < len(data[0]); i++ {
// if len(data[0][i]) == 0 {
// return fmt.Errorf("计算集标题第%d列不能为空", i+1)
// }
// if columnMap.Contains(data[0][i]) {
// return fmt.Errorf("计算集第%d列重复:%v", i+1, data[0][i])
// }
// columnMap.Add(data[0][i])
// d.DataTable.Fields = append(d.DataTable.Fields, &domain.Field{
// Name: data[0][i],
// SQLName: fmt.Sprintf("col%d", i),
// SQLType: domain.String.ToString(),
// })
// }
//}
return nil
}
func (d *DataLayoutDataTable) Expand(cell *domain.LayoutCell, length int) error {
... ...
... ... @@ -66,7 +66,7 @@ func (ptr *UpdateTableStructService) UpdateTableStruct(ctx *domain.Context, tabl
}
}
defer func() {
AsyncEvent(domain.NewEventTable(ctx, domain.TableDataEditEvent).WithTable(table))
AsyncEvent(domain.NewEventTable(ctx, domain.TableStructEditEvent).WithTable(table))
}()
// 日志
if err = FastLog(ptr.transactionContext, domain.CommonLog, table.TableId, &SubTableEditLog{
... ...
package utils
import (
"math/rand"
"time"
)
const (
KC_RAND_KIND_NUM = 0 // 纯数字
KC_RAND_KIND_LOWER = 1 // 小写字母
KC_RAND_KIND_UPPER = 2 // 大写字母
KC_RAND_KIND_ALL = 3 // 数字、大小写字母
)
// 随机字符串
func Krand(size int, kind int) string {
ikind, kinds, result := kind, [][]int{[]int{10, 48}, []int{26, 97}, []int{26, 65}}, make([]byte, size)
is_all := kind > 2 || kind < 0
rand.Seed(time.Now().UnixNano())
for i := 0; i < size; i++ {
if is_all { // random ikind
ikind = rand.Intn(3)
}
scope, base := kinds[ikind][0], kinds[ikind][1]
result[i] = uint8(base + rand.Intn(scope))
}
return string(result)
}
... ...
... ... @@ -156,6 +156,10 @@ func (controller *TableController) TableObjectSearch() {
tableService := service.NewTableService(nil)
cmd := &query.SearchTableQuery{}
Must(controller.Unmarshal(cmd))
defaultReturnGroup := true
if cmd.ReturnGroupItem == nil {
cmd.ReturnGroupItem = &defaultReturnGroup
}
cmd.Context = ParseContext(controller.BaseController)
data, err := tableService.TableObjectSearch(cmd)
controller.Response(data, err)
... ...
... ... @@ -11,6 +11,7 @@ func Start() {
func RegisterEvent() {
event.On(domain.TableDataEditEvent.ToString(), event.ListenerFunc(tableDataChangeHandler), event.High)
event.On(domain.TableStructEditEvent.ToString(), event.ListenerFunc(tableDataChangeHandler), event.High)
event.On(domain.TableDataImportEvent.ToString(), event.ListenerFunc(tableDataChangeHandler), event.High)
event.On(domain.TableDeleteEvent.ToString(), event.ListenerFunc(tableDataChangeHandler), event.High)
event.On(domain.QuerySetUpdateEvent.ToString(), event.ListenerFunc(tableDataChangeHandler), event.High)
... ...