作者 yangfu

chore: domainService code optimize

... ... @@ -33,8 +33,7 @@ func (ptr *FlushDataTableService) Flush(ctx *domain.Context, fileId int, table *
table = NewTable(domain.ExcelTable, file.FileInfo.Name, table.DataFields, table.RowCount).WithContext(ctx)
// 通知底层保存、进行回调
var response *domain.DataSaveTable
response, err = ByteCore.SaveTable(domain.ReqSaveTable{FileId: fileId, Table: table})
if err != nil {
if response, err = ByteCore.SaveTable(domain.ReqSaveTable{FileId: fileId, Table: table}); err != nil {
return nil, err
}
// 来自源文件的
... ... @@ -154,12 +153,11 @@ func NewTable(tableType domain.TableType, fileName string, dataFields []*domain.
func NewCopyTable(tableType domain.TableType, fileName string, dataFields []*domain.Field, rowCount int) *domain.Table {
var table = &domain.Table{}
// New Table
table.TableType = tableType.ToString()
table.Name = fileName
table.SQLName = pin(fileName) //SQLTableName()
table.SQLName = pin(fileName)
table.PK = PK()
if table.TableType == domain.CalculateItem.ToString() { //table.TableType == domain.CalculateTable.ToString() ||
if table.TableType == domain.CalculateItem.ToString() {
table.PK = nil
}
table.DataFieldIndex = len(dataFields)
... ... @@ -192,7 +190,7 @@ func DataField(name string, sqlType string, flag int, index int) *domain.Field {
return &domain.Field{
Index: index,
Name: name,
SQLName: fmt.Sprintf("%v_c%d", pin(name), index), //fieldName(index),
SQLName: fmt.Sprintf("%v_c%d", pin(name), index),
SQLType: sqlType,
Description: "",
Flag: flag,
... ...
... ... @@ -25,7 +25,7 @@ func (ptr *GenerateMainTableService) GenerateTable(ctx *domain.Context, fileId i
return nil, fmt.Errorf("文件未校验")
}
duplicateTable, err := tableRepository.FindOne(map[string]interface{}{"context": ctx, "tableName": tableName,
"tableTypes":[]string{string(domain.MainTable),string(domain.SubTable),string(domain.SideTable)}})
"tableTypes": []string{string(domain.MainTable), string(domain.SubTable), string(domain.SideTable)}})
if err == nil && duplicateTable != nil {
return nil, fmt.Errorf("表名称重复")
}
... ... @@ -33,11 +33,9 @@ func (ptr *GenerateMainTableService) GenerateTable(ctx *domain.Context, fileId i
mainTable := NewTable(domain.MainTable, tableName, table.DataFields, table.RowCount).
WithContext(ctx).
WithPrefix(domain.MainTable.ToString())
_, err = tableRepository.Save(mainTable)
if err != nil {
if _, err = tableRepository.Save(mainTable); err != nil {
return nil, err
}
// 日志
if err = FastLog(ptr.transactionContext, domain.CommonLog, mainTable.TableId, &GenerateMainTableLog{
LogEntry: domain.NewLogEntry(tableName, domain.MainTable.ToString(), domain.GenerateMainTable, ctx),
... ...
... ... @@ -91,7 +91,7 @@ type Log interface {
var _ Log = (*FileUploadSuccessLog)(nil)
// 1.1文件上传成功
// FileUploadSuccessLog 1.1文件上传成功
type FileUploadSuccessLog struct {
domain.LogEntry
}
... ... @@ -100,7 +100,7 @@ func (l *FileUploadSuccessLog) Content() string {
return fmt.Sprintf("上传成功")
}
// 1.2文件上传失败
// FileUploadFailLog 1.2文件上传失败
type FileUploadFailLog struct {
domain.LogEntry
Reason string
... ... @@ -110,7 +110,7 @@ func (l *FileUploadFailLog) Content() string {
return fmt.Sprintf("上传失败,失败原因:%s", l.Reason)
}
// 2.文件校验
// FileVerifyLog 2.文件校验
type FileVerifyLog struct {
domain.LogEntry
// 错误信息
... ... @@ -127,7 +127,7 @@ func (l *FileVerifyLog) Content() string {
return msg
}
// 3.主表生成日志
// GenerateMainTableLog 3.主表生成日志
type GenerateMainTableLog struct {
domain.LogEntry
// 表名
... ... @@ -141,7 +141,7 @@ func (l *GenerateMainTableLog) Content() string {
return msg
}
// 4.主表拆分
// SpiltMainTableLog 4.主表拆分
type SpiltMainTableLog struct {
domain.LogEntry
Reserve []*domain.Field
... ... @@ -175,7 +175,7 @@ func (l *SpiltMainTableLog) fieldNames(fields []*domain.Field) []string {
return names
}
// 5.分表编辑
// SubTableEditLog 5.分表编辑
type SubTableEditLog struct {
domain.LogEntry
... ... @@ -208,7 +208,7 @@ func (l *SubTableEditLog) fieldNames(fields []*domain.Field) []string {
return names
}
// 6.表复制日志
// CopyTableLog 6.表复制日志
type CopyTableLog struct {
domain.LogEntry
// 表名
... ... @@ -220,7 +220,7 @@ func (l *CopyTableLog) Content() string {
return msg
}
// 7.编辑记录
// RowAddLog 7.编辑记录
type RowAddLog struct {
domain.LogEntry
}
... ... @@ -239,10 +239,8 @@ type RowUpdateLog struct {
func (l *RowUpdateLog) Content() string {
change := ""
//index := l.Number + l.Where.Offset()
for _, f := range l.FieldValue {
if f.OldValue != f.Value {
//change += fmt.Sprintf("%v字段%v行的值从%v更改为%v;", f.Field.Name, index, f.OldValue, f.Value)
change += fmt.Sprintf("【%v】字段的值从“%v”更改为“%v”;", f.Field.Name, f.OldValue, f.Value)
}
}
... ... @@ -261,7 +259,6 @@ type RowRemoveLog struct {
func (l *RowRemoveLog) Content() string {
index := l.DeleteRowCount
//msg := fmt.Sprintf("删除%v行数据;筛选件:%v",index,"")
msg := fmt.Sprintf("删除%v行数据;", index)
filters := make([]string, 0)
inArgs := func(args []string) string {
... ... @@ -281,7 +278,7 @@ func (l *RowRemoveLog) Content() string {
return msg
}
// 8.表删除日志
// DeleteTableLog 8.表删除日志
type DeleteTableLog struct {
domain.LogEntry
// 表名
... ... @@ -302,7 +299,7 @@ func (l *DeleteTableLog) Content() string {
return msg
}
// 9.数据追加日志
// AppendDataToTableLog 9.数据追加日志
type AppendDataToTableLog struct {
domain.LogEntry
Table *domain.Table
... ... @@ -323,7 +320,8 @@ func (l *AppendDataToTableLog) Content() string {
return msg
}
/*步骤日志*/
/* *********************************************步骤日志************************************************** */
type ExcelTableEditLog struct {
domain.LogEntry
// 操作名称
... ...
... ... @@ -957,14 +957,6 @@ func (ptr *QuerySetService) Copy(ctx *domain.Context, querySetId int, t string,
if err != nil {
return nil, err
}
//if len(formulasGenerateResponse.FormulaName) > 0 && formulasGenerateResponse.FormulaName != table.SQLName {
//copyTable.SQLName = formulasGenerateResponse.FormulaName
//tableRepository, _ := repository.NewTableRepository(ptr.transactionContext)
//copyTable, err = tableRepository.Save(copyTable)
//if err != nil {
// return nil, err
//}
//}
copy.QuerySetInfo.BindTableId = copyTable.TableId
}
copy, err = querySetRepository.Save(copy)
... ...
... ... @@ -28,8 +28,8 @@ func (ptr *QuerySetService) LoadCalculateSetData(ctx *domain.Context, qs *domain
// 加载Tables数据
q := queryComponents[0]
cells := q.Layout.LayoutCells()
if len(cells)==0{
return res,nil
if len(cells) == 0 {
return res, nil
}
dataTables, err = ptr.LoadDataTables(ctx, cells)
if err != nil {
... ... @@ -107,7 +107,7 @@ func CellsLocationAdjust(cells []*domain.LayoutCell) {
}
//move = cell.Length
//c = cell
if max(move, cell.Length) != move && c==nil {
if max(move, cell.Length) != move && c == nil {
c = cell
}
move = max(move, cell.Length)
... ... @@ -118,9 +118,9 @@ func CellsLocationAdjust(cells []*domain.LayoutCell) {
}
func CellsLocationAdjustV1(cells []*domain.LayoutCell) {
yList:=cellsRange(cells,"y")
xList:=cellsRange(cells,"x")
for i := 0; i <len(yList); i++ {
yList := cellsRange(cells, "y")
xList := cellsRange(cells, "x")
for i := 0; i < len(yList); i++ {
j := yList[i]
move := 0
var c *domain.LayoutCell
... ... @@ -138,7 +138,7 @@ func CellsLocationAdjustV1(cells []*domain.LayoutCell) {
}
ChangeLocation(cells, domain.DirectionRight, j, move, c)
}
for j := 0; j <len(xList); j++ {
for j := 0; j < len(xList); j++ {
i := xList[j]
move := 0
var c *domain.LayoutCell
... ... @@ -149,7 +149,7 @@ func CellsLocationAdjustV1(cells []*domain.LayoutCell) {
if cell.Direction != domain.DirectionDown {
continue
}
if max(move, cell.Length) != move && c==nil {
if max(move, cell.Length) != move && c == nil {
c = cell
}
move = max(move, cell.Length)
... ... @@ -158,16 +158,16 @@ func CellsLocationAdjustV1(cells []*domain.LayoutCell) {
}
}
func cellsRange(cells []*domain.LayoutCell,direction string)[]int{
list:=collection.NewSet()
for i:=range cells{
if strings.ToLower(direction)=="x"{
func cellsRange(cells []*domain.LayoutCell, direction string) []int {
list := collection.NewSet()
for i := range cells {
if strings.ToLower(direction) == "x" {
list.Add(cells[i].X)
}else{
} else {
list.Add(cells[i].Y)
}
}
sortList :=list.KeysInt()
sortList := list.KeysInt()
sort.Ints(sortList)
return sortList
}
... ... @@ -200,7 +200,7 @@ func FastTable(table *domain.Table) (*domain.DataTable, error) {
Select: table.Fields(false),
}
options.SetDefaultOrder()
options.SetOffsetLimit(1,10000)
options.SetOffsetLimit(1, 10000)
var dataTable *domain.DataTable
dataTable, err = FastDataTable(options)
if err != nil {
... ... @@ -349,7 +349,6 @@ func (d *DataLayoutDataTable) addByLocation(cell *domain.LayoutCell, blockData [
}
func (d *DataLayoutDataTable) changeUnProcessedLocation(lastCell *domain.LayoutCell, length int) {
// log.Logger.Info("修改定位点")
for _, cell := range d.unprocessed {
switch lastCell.Direction {
case domain.DirectionRight:
... ... @@ -361,7 +360,6 @@ func (d *DataLayoutDataTable) changeUnProcessedLocation(lastCell *domain.LayoutC
cell.X += length - 1
}
}
// log.Logger.Info(fmt.Sprintf("%s %s X:%d Y:%d", cell.Data.Field.SQLName, cell.Direction, cell.X, cell.Y))
}
}
... ...
... ... @@ -29,9 +29,6 @@ func (ptr *CopyDataTableService) CopyTable(ctx *domain.Context, tableId int, tab
if err != nil {
return nil, err
}
//if !(table.TableType == domain.MainTable.ToString() || table.TableType == domain.SubTable.ToString()) {
// return nil, fmt.Errorf("主表、分表才允许复制")
//}
var mainTable *domain.Table
dataFields := table.DataFields
if table.TableType == domain.SubTable.ToString() {
... ...
... ... @@ -65,7 +65,6 @@ func (ptr *UpdateTableStructService) UpdateTableStruct(ctx *domain.Context, tabl
defer func() {
AsyncEvent(domain.NewEventTable(ctx, domain.TableDataEditEvent).WithTable(table))
}()
// Log
// 日志
if err = FastLog(ptr.transactionContext, domain.CommonLog, table.TableId, &SubTableEditLog{
LogEntry: domain.NewLogEntry(table.Name, table.TableType, domain.EditSubTable, ctx),
... ...