...
|
...
|
@@ -4,8 +4,6 @@ import ( |
|
|
"context"
|
|
|
"encoding/json"
|
|
|
"fmt"
|
|
|
"github.com/pkg/errors"
|
|
|
"github.com/zeromicro/go-zero/core/stores/redis"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/api/internal/svc"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/api/internal/types"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/interanl/pkg/db/transaction"
|
...
|
...
|
@@ -125,37 +123,13 @@ func (logic *ByteNoticeLogic) handleNotice(conn transaction.Conn, notice *domain |
|
|
}
|
|
|
//数据变更
|
|
|
if notice.DataChanged {
|
|
|
tableDataPreview, err := logic.svcCtx.ByteMetadataService.TableDataPreview(logic.ctx, &bytelib.TableDataPreviewRequest{
|
|
|
Token: accessToken,
|
|
|
ObjectId: int64(notice.TableId),
|
|
|
ObjectType: bytelib.ObjectMetaTable,
|
|
|
Where: &bytelib.TableQueryWhere{
|
|
|
PageNumber: 1,
|
|
|
PageSize: bytelib.MaxPageSize,
|
|
|
},
|
|
|
UseCache: true,
|
|
|
HiddenData: false,
|
|
|
})
|
|
|
if err != nil {
|
|
|
return err
|
|
|
}
|
|
|
//加锁,避免图表在请求读取本地数据时报错
|
|
|
key := logic.svcCtx.Config.Name + ":bytelib:" + fmt.Sprintf("%v", tableDataPreview.ObjectId)
|
|
|
lock := redis.NewRedisLock(logic.svcCtx.Redis, key)
|
|
|
// 设置过期时间
|
|
|
lock.SetExpire(10 * 60)
|
|
|
acquire, err := lock.Acquire()
|
|
|
fmt.Println(acquire, err)
|
|
|
defer lock.Release()
|
|
|
err = logic.svcCtx.ObjectTableDataRepository.InsertWithTableData(logic.ctx, conn, bytelib.TableData(tableDataPreview))
|
|
|
if err != nil {
|
|
|
return err
|
|
|
}
|
|
|
//更新标记本地存储
|
|
|
err = logic.updateTableWithLocal(conn, int(tableDataPreview.ObjectId))
|
|
|
if err != nil {
|
|
|
return err
|
|
|
data := &types.SyncTableDataPusher{
|
|
|
CompanyId: notice.CompanyId,
|
|
|
ObjectId: notice.TableId,
|
|
|
}
|
|
|
mBytes, _ := json.Marshal(data)
|
|
|
_, err := logic.svcCtx.Redis.LpushCtx(logic.ctx, logic.svcCtx.Config.Name+":table_data", string(mBytes))
|
|
|
return err
|
|
|
}
|
|
|
return nil
|
|
|
}
|
...
|
...
|
@@ -191,6 +165,14 @@ func (logic *ByteNoticeLogic) handleDelete(conn transaction.Conn, notice *domain |
|
|
return err
|
|
|
}
|
|
|
}
|
|
|
//是否有使用数据源
|
|
|
used, err := logic.svcCtx.ChartSettingRepository.CheckUseDataSource(logic.ctx, conn, notice.TableId)
|
|
|
if err == nil && !used {
|
|
|
err = logic.svcCtx.ObjectTableDataRepository.DropTable(logic.ctx, conn, notice.TableId)
|
|
|
if err != nil {
|
|
|
return err
|
|
|
}
|
|
|
}
|
|
|
return nil
|
|
|
}
|
|
|
|
...
|
...
|
@@ -227,14 +209,3 @@ func (logic *ByteNoticeLogic) saveFields(conn transaction.Conn, objectField *dom |
|
|
return logic.svcCtx.ObjectFieldRepository.Insert(logic.ctx, conn, objectField)
|
|
|
}
|
|
|
} |
|
|
|
|
|
// updateTableWithLocal 更新表标记本地存储
|
|
|
func (logic *ByteNoticeLogic) updateTableWithLocal(conn transaction.Conn, tableId int) error {
|
|
|
objectTable, err := logic.svcCtx.ObjectTableRepository.FindOneByTableId(logic.ctx, conn, tableId)
|
|
|
if err == nil && objectTable.Id > 0 {
|
|
|
objectTable.IsLocal = true
|
|
|
_, err = logic.svcCtx.ObjectTableRepository.Update(logic.ctx, conn, objectTable)
|
|
|
return err
|
|
|
}
|
|
|
return errors.New("表不存在")
|
|
|
} |
...
|
...
|
|