作者 庄敏学

本地存储删除判断

... ... @@ -34,6 +34,6 @@ KqConsumerConf:
Name: KqConsumer
Brokers:
- 47.97.5.102:9092
Group: bchart_dev
Group: bchart_local
Topic: allied_creation_metadata_table_sync_notice
Processors: 1
... ...
... ... @@ -61,8 +61,27 @@ func (l *UpdateChartLogic) UpdateChart(req *types.ChartUpdateRequest) (resp *typ
if chartSetting, err = l.svcCtx.ChartSettingRepository.UpdateWithVersion(l.ctx, conn, chartSetting); err != nil {
return err
}
err = l.SyncTableData(tenantId, conn, chartSetting.DataSourceIds, oldDataSource)
return err
}, true); err != nil {
return nil, xerr.NewErrMsgErr("创建失败", err)
}
return
}
func (l *UpdateChartLogic) SyncTableData(tenantId int64, conn transaction.Conn, newDataSourceIds, oldDataSourceIds []int64) error {
if len(newDataSourceIds) > 0 {
for _, sourceId := range newDataSourceIds {
pusher := &types.SyncTableDataPusher{
CompanyId: tenantId,
ObjectId: int(sourceId),
}
mBytes, _ := json.Marshal(pusher)
_, _ = l.svcCtx.Redis.LpushCtx(l.ctx, l.svcCtx.Config.Name+":table_data", string(mBytes))
}
}
//对比更新前后数据源
left, right := lo.Difference(chartSetting.DataSourceIds, oldDataSource)
left, right := lo.Difference(newDataSourceIds, oldDataSourceIds)
//同步
if len(left) > 0 {
for _, sourceId := range left {
... ... @@ -84,12 +103,22 @@ func (l *UpdateChartLogic) UpdateChart(req *types.ChartUpdateRequest) (resp *typ
if err != nil {
return err
}
//是否远程已删除
objectTable, err := l.svcCtx.ObjectTableRepository.FindOne(l.ctx, conn, int(sourceId))
if err == nil && objectTable.Id > 0 && objectTable.RemoteDeleted == 1 {
//删除表
_, err = l.svcCtx.ObjectTableRepository.Delete(l.ctx, conn, &domain.ObjectTable{Id: int(sourceId)})
if err != nil {
return err
}
//删除字段
_, err = l.svcCtx.ObjectFieldRepository.Delete(l.ctx, conn, &domain.ObjectField{Id: sourceId})
if err != nil {
return err
}
}
return nil
}, true); err != nil {
return nil, xerr.NewErrMsgErr("创建失败", err)
}
return
}
}
return nil
}
... ...
... ... @@ -64,7 +64,7 @@ func (logic *ByteNoticeLogic) handleNotice(conn transaction.Conn, notice *domain
if notice.StructChanged {
request := bytelib.ObjectTableSearchRequest{
Token: accessToken,
Module: bytelib.ModuleDigitalCenter,
Module: bytelib.ModuleChartTemplate,
}
if notice.ObjectType == "导入模块" {
request.TableTypes = []string{bytelib.MainTable, bytelib.SubTable, bytelib.SideTable}
... ... @@ -164,7 +164,6 @@ func (logic *ByteNoticeLogic) handleDelete(conn transaction.Conn, notice *domain
if err != nil {
return err
}
}
//是否有使用数据源
used, err := logic.svcCtx.ChartSettingRepository.CheckUseDataSource(logic.ctx, conn, notice.TableId)
if err == nil && !used {
... ... @@ -172,6 +171,17 @@ func (logic *ByteNoticeLogic) handleDelete(conn transaction.Conn, notice *domain
if err != nil {
return err
}
//删除表
_, err = logic.svcCtx.ObjectTableRepository.Delete(logic.ctx, conn, objectTable)
if err != nil {
return err
}
//删除字段
_, err = logic.svcCtx.ObjectFieldRepository.Delete(logic.ctx, conn, &domain.ObjectField{Id: int64(objectTable.Id)})
if err != nil {
return err
}
}
}
return nil
}
... ...
... ... @@ -2,6 +2,7 @@ package repository
import (
"context"
"fmt"
"github.com/jinzhu/copier"
"github.com/pkg/errors"
"github.com/tiptok/gocomm/pkg/cache"
... ... @@ -143,7 +144,7 @@ func (repository *ChartSettingRepository) Find(ctx context.Context, conn transac
// CheckUseDataSource 检验是否使用数据源
func (repository *ChartSettingRepository) CheckUseDataSource(ctx context.Context, conn transaction.Conn, objectId int) (bool, error) {
var count int64
err := conn.DB().Model(&models.ChartSetting{}).Where("data_source_ids::jsonb @>'[?]'", objectId).Count(&count).Error
err := conn.DB().Model(&models.ChartSetting{}).Where(fmt.Sprintf("data_source_ids::jsonb @>'[%v]'", objectId)).Count(&count).Error
if err != nil {
return false, err
}
... ...