作者 yangfu

计算集标题

@@ -25,7 +25,15 @@ type FileDto struct { @@ -25,7 +25,15 @@ type FileDto struct {
25 // 表ID 25 // 表ID
26 TableId int `json:"tableId"` 26 TableId int `json:"tableId"`
27 // 允许表生成标识 1:允许生成分表 0:不允许 27 // 允许表生成标识 1:允许生成分表 0:不允许
28 - AllowTableGenerateFlag int `json:"allowTableGenerateFlag"` 28 + AllowTableGenerateFlag int `json:"-"`
  29 + // 允许表处理标识 1:允许 0:不允许
  30 + AllowTableProcessFlag int `json:"-"`
  31 + // 允许表导出标识 1:允许 0:不允许
  32 + AllowTableExportFlag int `json:"-"`
  33 + // 标志位 1:可校验 2:可分表生成 4:导出
  34 + Flag int `json:"-"`
  35 + // 标志位 1:可校验 2:可分表生成 4:导出
  36 + Flags []int `json:"flags"`
29 } 37 }
30 38
31 func (d *FileDto) Load(f *domain.File) *FileDto { 39 func (d *FileDto) Load(f *domain.File) *FileDto {
@@ -40,13 +48,40 @@ func (d *FileDto) Load(f *domain.File) *FileDto { @@ -40,13 +48,40 @@ func (d *FileDto) Load(f *domain.File) *FileDto {
40 d.Time = xtime.New(f.UpdatedAt).Local().Format("2006-01-02 15:04:05") 48 d.Time = xtime.New(f.UpdatedAt).Local().Format("2006-01-02 15:04:05")
41 d.HeaderRow = domain.GetHeaderRow(f.FileInfo.HeaderRow) 49 d.HeaderRow = domain.GetHeaderRow(f.FileInfo.HeaderRow)
42 d.AppKey = f.AppKey 50 d.AppKey = f.AppKey
  51 + //d.AllowTableProcessFlag = 1
  52 + //d.AllowTableExportFlag = 1
  53 + d.AddFlag(5) // 默认可以 校验、导出
43 if len(f.AppKey) > 0 && f.FileInfo.TableId > 0 { 54 if len(f.AppKey) > 0 && f.FileInfo.TableId > 0 {
44 d.TableId = f.FileInfo.TableId 55 d.TableId = f.FileInfo.TableId
45 - d.AllowTableGenerateFlag = 1 56 + //d.AllowTableGenerateFlag = 1
  57 + d.AddFlag(2) // 可分表生成
  58 + d.RemoveFlag(1) // 不可校验
  59 + //d.RemoveFlag(4) // 不可校验
  60 + //d.AllowTableProcessFlag = 0
  61 + //d.AllowTableExportFlag = 0
  62 + }
  63 + for i := 1; i <= 4; i = i << 1 {
  64 + if i&d.Flag == i {
  65 + d.Flags = append(d.Flags, i)
  66 + }
46 } 67 }
47 return d 68 return d
48 } 69 }
49 70
  71 +func (d *FileDto) AddFlag(flag int) {
  72 + if d.Flag&flag == flag {
  73 + return
  74 + }
  75 + d.Flag |= flag
  76 +}
  77 +
  78 +func (d *FileDto) RemoveFlag(flag int) {
  79 + if d.Flag&flag != flag {
  80 + return
  81 + }
  82 + d.Flag ^= flag
  83 +}
  84 +
50 type AppDto struct { 85 type AppDto struct {
51 AppId int64 `json:"appId"` 86 AppId int64 `json:"appId"`
52 AppKey string `json:"appKey"` 87 AppKey string `json:"appKey"`
@@ -50,6 +50,13 @@ type LayoutCellData struct { @@ -50,6 +50,13 @@ type LayoutCellData struct {
50 50
51 func (l *LayoutRuleItem) LayoutCells() []*LayoutCell { 51 func (l *LayoutRuleItem) LayoutCells() []*LayoutCell {
52 var cells = make([]*LayoutCell, 0) 52 var cells = make([]*LayoutCell, 0)
  53 + // 排序
  54 + sort.SliceStable(l.Cells, func(i, j int) bool {
  55 + if l.Cells[i].Position.X == l.Cells[j].Position.X {
  56 + return l.Cells[i].Position.Y < l.Cells[j].Position.Y
  57 + }
  58 + return l.Cells[i].Position.X < l.Cells[j].Position.X
  59 + })
53 for _, item := range l.Cells { 60 for _, item := range l.Cells {
54 item.X = item.Position.X 61 item.X = item.Position.X
55 item.Y = item.Position.Y 62 item.Y = item.Position.Y
@@ -303,7 +303,9 @@ func DataLayout(res *domain.DataTable, cells []*domain.LayoutCell) (*domain.Data @@ -303,7 +303,9 @@ func DataLayout(res *domain.DataTable, cells []*domain.LayoutCell) (*domain.Data
303 dt.processed = append(dt.processed, cell) 303 dt.processed = append(dt.processed, cell)
304 dt.LastCell = cell 304 dt.LastCell = cell
305 } 305 }
306 - dt.Shrink() 306 + if err := dt.Shrink(); err != nil {
  307 + return nil, err
  308 + }
307 return dt.DataTable, nil 309 return dt.DataTable, nil
308 } 310 }
309 311
@@ -444,16 +446,16 @@ func (d *DataLayoutDataTable) Shrink() error { @@ -444,16 +446,16 @@ func (d *DataLayoutDataTable) Shrink() error {
444 // }) 446 // })
445 //} 447 //}
446 // 默认计算集第一行作为标题 448 // 默认计算集第一行作为标题
447 - if len(data) > 1 { 449 + if len(data) >= 1 {
448 d.DataTable.Data = data[1:] 450 d.DataTable.Data = data[1:]
449 columnMap := collection.NewSet() 451 columnMap := collection.NewSet()
450 for i := 0; i < len(data[0]); i++ { 452 for i := 0; i < len(data[0]); i++ {
451 - if len(data[0][i]) == 0 {  
452 - return fmt.Errorf("计算集标题不能为空")  
453 - }  
454 - if columnMap.Contains(data[0][i]) {  
455 - return fmt.Errorf("计算集列重复:%v", data[0][i])  
456 - } 453 + //if len(data[0][i]) == 0 {
  454 + // return fmt.Errorf("计算集标题第%d列不能为空", i+1)
  455 + //}
  456 + //if columnMap.Contains(data[0][i]) {
  457 + // return fmt.Errorf("计算集第%d列重复:%v", i+1, data[0][i])
  458 + //}
457 columnMap.Add(data[0][i]) 459 columnMap.Add(data[0][i])
458 d.DataTable.Fields = append(d.DataTable.Fields, &domain.Field{ 460 d.DataTable.Fields = append(d.DataTable.Fields, &domain.Field{
459 Name: data[0][i], 461 Name: data[0][i],