作者 yangfu

chore: domainService code optimize

@@ -33,8 +33,7 @@ func (ptr *FlushDataTableService) Flush(ctx *domain.Context, fileId int, table * @@ -33,8 +33,7 @@ func (ptr *FlushDataTableService) Flush(ctx *domain.Context, fileId int, table *
33 table = NewTable(domain.ExcelTable, file.FileInfo.Name, table.DataFields, table.RowCount).WithContext(ctx) 33 table = NewTable(domain.ExcelTable, file.FileInfo.Name, table.DataFields, table.RowCount).WithContext(ctx)
34 // 通知底层保存、进行回调 34 // 通知底层保存、进行回调
35 var response *domain.DataSaveTable 35 var response *domain.DataSaveTable
36 - response, err = ByteCore.SaveTable(domain.ReqSaveTable{FileId: fileId, Table: table})  
37 - if err != nil { 36 + if response, err = ByteCore.SaveTable(domain.ReqSaveTable{FileId: fileId, Table: table}); err != nil {
38 return nil, err 37 return nil, err
39 } 38 }
40 // 来自源文件的 39 // 来自源文件的
@@ -154,12 +153,11 @@ func NewTable(tableType domain.TableType, fileName string, dataFields []*domain. @@ -154,12 +153,11 @@ func NewTable(tableType domain.TableType, fileName string, dataFields []*domain.
154 153
155 func NewCopyTable(tableType domain.TableType, fileName string, dataFields []*domain.Field, rowCount int) *domain.Table { 154 func NewCopyTable(tableType domain.TableType, fileName string, dataFields []*domain.Field, rowCount int) *domain.Table {
156 var table = &domain.Table{} 155 var table = &domain.Table{}
157 - // New Table  
158 table.TableType = tableType.ToString() 156 table.TableType = tableType.ToString()
159 table.Name = fileName 157 table.Name = fileName
160 - table.SQLName = pin(fileName) //SQLTableName() 158 + table.SQLName = pin(fileName)
161 table.PK = PK() 159 table.PK = PK()
162 - if table.TableType == domain.CalculateItem.ToString() { //table.TableType == domain.CalculateTable.ToString() || 160 + if table.TableType == domain.CalculateItem.ToString() {
163 table.PK = nil 161 table.PK = nil
164 } 162 }
165 table.DataFieldIndex = len(dataFields) 163 table.DataFieldIndex = len(dataFields)
@@ -192,7 +190,7 @@ func DataField(name string, sqlType string, flag int, index int) *domain.Field { @@ -192,7 +190,7 @@ func DataField(name string, sqlType string, flag int, index int) *domain.Field {
192 return &domain.Field{ 190 return &domain.Field{
193 Index: index, 191 Index: index,
194 Name: name, 192 Name: name,
195 - SQLName: fmt.Sprintf("%v_c%d", pin(name), index), //fieldName(index), 193 + SQLName: fmt.Sprintf("%v_c%d", pin(name), index),
196 SQLType: sqlType, 194 SQLType: sqlType,
197 Description: "", 195 Description: "",
198 Flag: flag, 196 Flag: flag,
@@ -25,19 +25,17 @@ func (ptr *GenerateMainTableService) GenerateTable(ctx *domain.Context, fileId i @@ -25,19 +25,17 @@ func (ptr *GenerateMainTableService) GenerateTable(ctx *domain.Context, fileId i
25 return nil, fmt.Errorf("文件未校验") 25 return nil, fmt.Errorf("文件未校验")
26 } 26 }
27 duplicateTable, err := tableRepository.FindOne(map[string]interface{}{"context": ctx, "tableName": tableName, 27 duplicateTable, err := tableRepository.FindOne(map[string]interface{}{"context": ctx, "tableName": tableName,
28 - "tableTypes":[]string{string(domain.MainTable),string(domain.SubTable),string(domain.SideTable)}}) 28 + "tableTypes": []string{string(domain.MainTable), string(domain.SubTable), string(domain.SideTable)}})
29 if err == nil && duplicateTable != nil { 29 if err == nil && duplicateTable != nil {
30 return nil, fmt.Errorf("表名称重复") 30 return nil, fmt.Errorf("表名称重复")
31 } 31 }
32 32
33 mainTable := NewTable(domain.MainTable, tableName, table.DataFields, table.RowCount). 33 mainTable := NewTable(domain.MainTable, tableName, table.DataFields, table.RowCount).
34 - WithContext(ctx).  
35 - WithPrefix(domain.MainTable.ToString())  
36 - _, err = tableRepository.Save(mainTable)  
37 - if err != nil { 34 + WithContext(ctx).
  35 + WithPrefix(domain.MainTable.ToString())
  36 + if _, err = tableRepository.Save(mainTable); err != nil {
38 return nil, err 37 return nil, err
39 } 38 }
40 -  
41 // 日志 39 // 日志
42 if err = FastLog(ptr.transactionContext, domain.CommonLog, mainTable.TableId, &GenerateMainTableLog{ 40 if err = FastLog(ptr.transactionContext, domain.CommonLog, mainTable.TableId, &GenerateMainTableLog{
43 LogEntry: domain.NewLogEntry(tableName, domain.MainTable.ToString(), domain.GenerateMainTable, ctx), 41 LogEntry: domain.NewLogEntry(tableName, domain.MainTable.ToString(), domain.GenerateMainTable, ctx),
@@ -91,7 +91,7 @@ type Log interface { @@ -91,7 +91,7 @@ type Log interface {
91 91
92 var _ Log = (*FileUploadSuccessLog)(nil) 92 var _ Log = (*FileUploadSuccessLog)(nil)
93 93
94 -// 1.1文件上传成功 94 +// FileUploadSuccessLog 1.1文件上传成功
95 type FileUploadSuccessLog struct { 95 type FileUploadSuccessLog struct {
96 domain.LogEntry 96 domain.LogEntry
97 } 97 }
@@ -100,7 +100,7 @@ func (l *FileUploadSuccessLog) Content() string { @@ -100,7 +100,7 @@ func (l *FileUploadSuccessLog) Content() string {
100 return fmt.Sprintf("上传成功") 100 return fmt.Sprintf("上传成功")
101 } 101 }
102 102
103 -// 1.2文件上传失败 103 +// FileUploadFailLog 1.2文件上传失败
104 type FileUploadFailLog struct { 104 type FileUploadFailLog struct {
105 domain.LogEntry 105 domain.LogEntry
106 Reason string 106 Reason string
@@ -110,7 +110,7 @@ func (l *FileUploadFailLog) Content() string { @@ -110,7 +110,7 @@ func (l *FileUploadFailLog) Content() string {
110 return fmt.Sprintf("上传失败,失败原因:%s", l.Reason) 110 return fmt.Sprintf("上传失败,失败原因:%s", l.Reason)
111 } 111 }
112 112
113 -// 2.文件校验 113 +// FileVerifyLog 2.文件校验
114 type FileVerifyLog struct { 114 type FileVerifyLog struct {
115 domain.LogEntry 115 domain.LogEntry
116 // 错误信息 116 // 错误信息
@@ -127,7 +127,7 @@ func (l *FileVerifyLog) Content() string { @@ -127,7 +127,7 @@ func (l *FileVerifyLog) Content() string {
127 return msg 127 return msg
128 } 128 }
129 129
130 -// 3.主表生成日志 130 +// GenerateMainTableLog 3.主表生成日志
131 type GenerateMainTableLog struct { 131 type GenerateMainTableLog struct {
132 domain.LogEntry 132 domain.LogEntry
133 // 表名 133 // 表名
@@ -141,7 +141,7 @@ func (l *GenerateMainTableLog) Content() string { @@ -141,7 +141,7 @@ func (l *GenerateMainTableLog) Content() string {
141 return msg 141 return msg
142 } 142 }
143 143
144 -// 4.主表拆分 144 +// SpiltMainTableLog 4.主表拆分
145 type SpiltMainTableLog struct { 145 type SpiltMainTableLog struct {
146 domain.LogEntry 146 domain.LogEntry
147 Reserve []*domain.Field 147 Reserve []*domain.Field
@@ -175,7 +175,7 @@ func (l *SpiltMainTableLog) fieldNames(fields []*domain.Field) []string { @@ -175,7 +175,7 @@ func (l *SpiltMainTableLog) fieldNames(fields []*domain.Field) []string {
175 return names 175 return names
176 } 176 }
177 177
178 -// 5.分表编辑 178 +// SubTableEditLog 5.分表编辑
179 type SubTableEditLog struct { 179 type SubTableEditLog struct {
180 domain.LogEntry 180 domain.LogEntry
181 181
@@ -208,7 +208,7 @@ func (l *SubTableEditLog) fieldNames(fields []*domain.Field) []string { @@ -208,7 +208,7 @@ func (l *SubTableEditLog) fieldNames(fields []*domain.Field) []string {
208 return names 208 return names
209 } 209 }
210 210
211 -// 6.表复制日志 211 +// CopyTableLog 6.表复制日志
212 type CopyTableLog struct { 212 type CopyTableLog struct {
213 domain.LogEntry 213 domain.LogEntry
214 // 表名 214 // 表名
@@ -220,7 +220,7 @@ func (l *CopyTableLog) Content() string { @@ -220,7 +220,7 @@ func (l *CopyTableLog) Content() string {
220 return msg 220 return msg
221 } 221 }
222 222
223 -// 7.编辑记录 223 +// RowAddLog 7.编辑记录
224 type RowAddLog struct { 224 type RowAddLog struct {
225 domain.LogEntry 225 domain.LogEntry
226 } 226 }
@@ -239,10 +239,8 @@ type RowUpdateLog struct { @@ -239,10 +239,8 @@ type RowUpdateLog struct {
239 239
240 func (l *RowUpdateLog) Content() string { 240 func (l *RowUpdateLog) Content() string {
241 change := "" 241 change := ""
242 - //index := l.Number + l.Where.Offset()  
243 for _, f := range l.FieldValue { 242 for _, f := range l.FieldValue {
244 if f.OldValue != f.Value { 243 if f.OldValue != f.Value {
245 - //change += fmt.Sprintf("%v字段%v行的值从%v更改为%v;", f.Field.Name, index, f.OldValue, f.Value)  
246 change += fmt.Sprintf("【%v】字段的值从“%v”更改为“%v”;", f.Field.Name, f.OldValue, f.Value) 244 change += fmt.Sprintf("【%v】字段的值从“%v”更改为“%v”;", f.Field.Name, f.OldValue, f.Value)
247 } 245 }
248 } 246 }
@@ -261,7 +259,6 @@ type RowRemoveLog struct { @@ -261,7 +259,6 @@ type RowRemoveLog struct {
261 259
262 func (l *RowRemoveLog) Content() string { 260 func (l *RowRemoveLog) Content() string {
263 index := l.DeleteRowCount 261 index := l.DeleteRowCount
264 - //msg := fmt.Sprintf("删除%v行数据;筛选件:%v",index,"")  
265 msg := fmt.Sprintf("删除%v行数据;", index) 262 msg := fmt.Sprintf("删除%v行数据;", index)
266 filters := make([]string, 0) 263 filters := make([]string, 0)
267 inArgs := func(args []string) string { 264 inArgs := func(args []string) string {
@@ -281,7 +278,7 @@ func (l *RowRemoveLog) Content() string { @@ -281,7 +278,7 @@ func (l *RowRemoveLog) Content() string {
281 return msg 278 return msg
282 } 279 }
283 280
284 -// 8.表删除日志 281 +// DeleteTableLog 8.表删除日志
285 type DeleteTableLog struct { 282 type DeleteTableLog struct {
286 domain.LogEntry 283 domain.LogEntry
287 // 表名 284 // 表名
@@ -302,7 +299,7 @@ func (l *DeleteTableLog) Content() string { @@ -302,7 +299,7 @@ func (l *DeleteTableLog) Content() string {
302 return msg 299 return msg
303 } 300 }
304 301
305 -// 9.数据追加日志 302 +// AppendDataToTableLog 9.数据追加日志
306 type AppendDataToTableLog struct { 303 type AppendDataToTableLog struct {
307 domain.LogEntry 304 domain.LogEntry
308 Table *domain.Table 305 Table *domain.Table
@@ -323,7 +320,8 @@ func (l *AppendDataToTableLog) Content() string { @@ -323,7 +320,8 @@ func (l *AppendDataToTableLog) Content() string {
323 return msg 320 return msg
324 } 321 }
325 322
326 -/*步骤日志*/ 323 +/* *********************************************步骤日志************************************************** */
  324 +
327 type ExcelTableEditLog struct { 325 type ExcelTableEditLog struct {
328 domain.LogEntry 326 domain.LogEntry
329 // 操作名称 327 // 操作名称
@@ -957,14 +957,6 @@ func (ptr *QuerySetService) Copy(ctx *domain.Context, querySetId int, t string, @@ -957,14 +957,6 @@ func (ptr *QuerySetService) Copy(ctx *domain.Context, querySetId int, t string,
957 if err != nil { 957 if err != nil {
958 return nil, err 958 return nil, err
959 } 959 }
960 - //if len(formulasGenerateResponse.FormulaName) > 0 && formulasGenerateResponse.FormulaName != table.SQLName {  
961 - //copyTable.SQLName = formulasGenerateResponse.FormulaName  
962 - //tableRepository, _ := repository.NewTableRepository(ptr.transactionContext)  
963 - //copyTable, err = tableRepository.Save(copyTable)  
964 - //if err != nil {  
965 - // return nil, err  
966 - //}  
967 - //}  
968 copy.QuerySetInfo.BindTableId = copyTable.TableId 960 copy.QuerySetInfo.BindTableId = copyTable.TableId
969 } 961 }
970 copy, err = querySetRepository.Save(copy) 962 copy, err = querySetRepository.Save(copy)
@@ -28,8 +28,8 @@ func (ptr *QuerySetService) LoadCalculateSetData(ctx *domain.Context, qs *domain @@ -28,8 +28,8 @@ func (ptr *QuerySetService) LoadCalculateSetData(ctx *domain.Context, qs *domain
28 // 加载Tables数据 28 // 加载Tables数据
29 q := queryComponents[0] 29 q := queryComponents[0]
30 cells := q.Layout.LayoutCells() 30 cells := q.Layout.LayoutCells()
31 - if len(cells)==0{  
32 - return res,nil 31 + if len(cells) == 0 {
  32 + return res, nil
33 } 33 }
34 dataTables, err = ptr.LoadDataTables(ctx, cells) 34 dataTables, err = ptr.LoadDataTables(ctx, cells)
35 if err != nil { 35 if err != nil {
@@ -107,7 +107,7 @@ func CellsLocationAdjust(cells []*domain.LayoutCell) { @@ -107,7 +107,7 @@ func CellsLocationAdjust(cells []*domain.LayoutCell) {
107 } 107 }
108 //move = cell.Length 108 //move = cell.Length
109 //c = cell 109 //c = cell
110 - if max(move, cell.Length) != move && c==nil { 110 + if max(move, cell.Length) != move && c == nil {
111 c = cell 111 c = cell
112 } 112 }
113 move = max(move, cell.Length) 113 move = max(move, cell.Length)
@@ -118,9 +118,9 @@ func CellsLocationAdjust(cells []*domain.LayoutCell) { @@ -118,9 +118,9 @@ func CellsLocationAdjust(cells []*domain.LayoutCell) {
118 } 118 }
119 119
120 func CellsLocationAdjustV1(cells []*domain.LayoutCell) { 120 func CellsLocationAdjustV1(cells []*domain.LayoutCell) {
121 - yList:=cellsRange(cells,"y")  
122 - xList:=cellsRange(cells,"x")  
123 - for i := 0; i <len(yList); i++ { 121 + yList := cellsRange(cells, "y")
  122 + xList := cellsRange(cells, "x")
  123 + for i := 0; i < len(yList); i++ {
124 j := yList[i] 124 j := yList[i]
125 move := 0 125 move := 0
126 var c *domain.LayoutCell 126 var c *domain.LayoutCell
@@ -138,7 +138,7 @@ func CellsLocationAdjustV1(cells []*domain.LayoutCell) { @@ -138,7 +138,7 @@ func CellsLocationAdjustV1(cells []*domain.LayoutCell) {
138 } 138 }
139 ChangeLocation(cells, domain.DirectionRight, j, move, c) 139 ChangeLocation(cells, domain.DirectionRight, j, move, c)
140 } 140 }
141 - for j := 0; j <len(xList); j++ { 141 + for j := 0; j < len(xList); j++ {
142 i := xList[j] 142 i := xList[j]
143 move := 0 143 move := 0
144 var c *domain.LayoutCell 144 var c *domain.LayoutCell
@@ -149,7 +149,7 @@ func CellsLocationAdjustV1(cells []*domain.LayoutCell) { @@ -149,7 +149,7 @@ func CellsLocationAdjustV1(cells []*domain.LayoutCell) {
149 if cell.Direction != domain.DirectionDown { 149 if cell.Direction != domain.DirectionDown {
150 continue 150 continue
151 } 151 }
152 - if max(move, cell.Length) != move && c==nil { 152 + if max(move, cell.Length) != move && c == nil {
153 c = cell 153 c = cell
154 } 154 }
155 move = max(move, cell.Length) 155 move = max(move, cell.Length)
@@ -158,16 +158,16 @@ func CellsLocationAdjustV1(cells []*domain.LayoutCell) { @@ -158,16 +158,16 @@ func CellsLocationAdjustV1(cells []*domain.LayoutCell) {
158 } 158 }
159 } 159 }
160 160
161 -func cellsRange(cells []*domain.LayoutCell,direction string)[]int{  
162 - list:=collection.NewSet()  
163 - for i:=range cells{  
164 - if strings.ToLower(direction)=="x"{ 161 +func cellsRange(cells []*domain.LayoutCell, direction string) []int {
  162 + list := collection.NewSet()
  163 + for i := range cells {
  164 + if strings.ToLower(direction) == "x" {
165 list.Add(cells[i].X) 165 list.Add(cells[i].X)
166 - }else{ 166 + } else {
167 list.Add(cells[i].Y) 167 list.Add(cells[i].Y)
168 } 168 }
169 } 169 }
170 - sortList :=list.KeysInt() 170 + sortList := list.KeysInt()
171 sort.Ints(sortList) 171 sort.Ints(sortList)
172 return sortList 172 return sortList
173 } 173 }
@@ -200,7 +200,7 @@ func FastTable(table *domain.Table) (*domain.DataTable, error) { @@ -200,7 +200,7 @@ func FastTable(table *domain.Table) (*domain.DataTable, error) {
200 Select: table.Fields(false), 200 Select: table.Fields(false),
201 } 201 }
202 options.SetDefaultOrder() 202 options.SetDefaultOrder()
203 - options.SetOffsetLimit(1,10000) 203 + options.SetOffsetLimit(1, 10000)
204 var dataTable *domain.DataTable 204 var dataTable *domain.DataTable
205 dataTable, err = FastDataTable(options) 205 dataTable, err = FastDataTable(options)
206 if err != nil { 206 if err != nil {
@@ -260,7 +260,7 @@ func (ptr *QuerySetService) LoadDataTables(ctx *domain.Context, cells []*domain. @@ -260,7 +260,7 @@ func (ptr *QuerySetService) LoadDataTables(ctx *domain.Context, cells []*domain.
260 260
261 func DataLayout(res *domain.DataTable, cells []*domain.LayoutCell) (*domain.DataTable, error) { 261 func DataLayout(res *domain.DataTable, cells []*domain.LayoutCell) (*domain.DataTable, error) {
262 dt := &DataLayoutDataTable{ 262 dt := &DataLayoutDataTable{
263 - DataTable: res, 263 + DataTable: res,
264 unprocessed: cells, 264 unprocessed: cells,
265 } 265 }
266 dt.Init(DefaultExpandNum) 266 dt.Init(DefaultExpandNum)
@@ -349,7 +349,6 @@ func (d *DataLayoutDataTable) addByLocation(cell *domain.LayoutCell, blockData [ @@ -349,7 +349,6 @@ func (d *DataLayoutDataTable) addByLocation(cell *domain.LayoutCell, blockData [
349 } 349 }
350 350
351 func (d *DataLayoutDataTable) changeUnProcessedLocation(lastCell *domain.LayoutCell, length int) { 351 func (d *DataLayoutDataTable) changeUnProcessedLocation(lastCell *domain.LayoutCell, length int) {
352 - // log.Logger.Info("修改定位点")  
353 for _, cell := range d.unprocessed { 352 for _, cell := range d.unprocessed {
354 switch lastCell.Direction { 353 switch lastCell.Direction {
355 case domain.DirectionRight: 354 case domain.DirectionRight:
@@ -361,7 +360,6 @@ func (d *DataLayoutDataTable) changeUnProcessedLocation(lastCell *domain.LayoutC @@ -361,7 +360,6 @@ func (d *DataLayoutDataTable) changeUnProcessedLocation(lastCell *domain.LayoutC
361 cell.X += length - 1 360 cell.X += length - 1
362 } 361 }
363 } 362 }
364 - // log.Logger.Info(fmt.Sprintf("%s %s X:%d Y:%d", cell.Data.Field.SQLName, cell.Direction, cell.X, cell.Y))  
365 } 363 }
366 } 364 }
367 365
@@ -29,9 +29,6 @@ func (ptr *CopyDataTableService) CopyTable(ctx *domain.Context, tableId int, tab @@ -29,9 +29,6 @@ func (ptr *CopyDataTableService) CopyTable(ctx *domain.Context, tableId int, tab
29 if err != nil { 29 if err != nil {
30 return nil, err 30 return nil, err
31 } 31 }
32 - //if !(table.TableType == domain.MainTable.ToString() || table.TableType == domain.SubTable.ToString()) {  
33 - // return nil, fmt.Errorf("主表、分表才允许复制")  
34 - //}  
35 var mainTable *domain.Table 32 var mainTable *domain.Table
36 dataFields := table.DataFields 33 dataFields := table.DataFields
37 if table.TableType == domain.SubTable.ToString() { 34 if table.TableType == domain.SubTable.ToString() {
@@ -65,7 +65,6 @@ func (ptr *UpdateTableStructService) UpdateTableStruct(ctx *domain.Context, tabl @@ -65,7 +65,6 @@ func (ptr *UpdateTableStructService) UpdateTableStruct(ctx *domain.Context, tabl
65 defer func() { 65 defer func() {
66 AsyncEvent(domain.NewEventTable(ctx, domain.TableDataEditEvent).WithTable(table)) 66 AsyncEvent(domain.NewEventTable(ctx, domain.TableDataEditEvent).WithTable(table))
67 }() 67 }()
68 - // Log  
69 // 日志 68 // 日志
70 if err = FastLog(ptr.transactionContext, domain.CommonLog, table.TableId, &SubTableEditLog{ 69 if err = FastLog(ptr.transactionContext, domain.CommonLog, table.TableId, &SubTableEditLog{
71 LogEntry: domain.NewLogEntry(table.Name, table.TableType, domain.EditSubTable, ctx), 70 LogEntry: domain.NewLogEntry(table.Name, table.TableType, domain.EditSubTable, ctx),