...
|
...
|
@@ -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
|
|
|
} |
...
|
...
|
|