...
|
...
|
@@ -61,35 +61,64 @@ func (l *UpdateChartLogic) UpdateChart(req *types.ChartUpdateRequest) (resp *typ |
|
|
if chartSetting, err = l.svcCtx.ChartSettingRepository.UpdateWithVersion(l.ctx, conn, chartSetting); err != nil {
|
|
|
return err
|
|
|
}
|
|
|
//对比更新前后数据源
|
|
|
left, right := lo.Difference(chartSetting.DataSourceIds, oldDataSource)
|
|
|
//同步
|
|
|
if len(left) > 0 {
|
|
|
for _, sourceId := range left {
|
|
|
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))
|
|
|
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(newDataSourceIds, oldDataSourceIds)
|
|
|
//同步
|
|
|
if len(left) > 0 {
|
|
|
for _, sourceId := range left {
|
|
|
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))
|
|
|
}
|
|
|
//删除
|
|
|
if len(right) > 0 {
|
|
|
for _, sourceId := range right {
|
|
|
//验证其他图表是否使用
|
|
|
used, err := l.svcCtx.ChartSettingRepository.CheckUseDataSource(l.ctx, conn, int(sourceId))
|
|
|
if err == nil && !used { //未使用,删除
|
|
|
err = l.svcCtx.ObjectTableDataRepository.DropTable(l.ctx, conn, int(sourceId))
|
|
|
}
|
|
|
//删除
|
|
|
if len(right) > 0 {
|
|
|
for _, sourceId := range right {
|
|
|
//验证其他图表是否使用
|
|
|
used, err := l.svcCtx.ChartSettingRepository.CheckUseDataSource(l.ctx, conn, int(sourceId))
|
|
|
if err == nil && !used { //未使用,删除
|
|
|
err = l.svcCtx.ObjectTableDataRepository.DropTable(l.ctx, conn, int(sourceId))
|
|
|
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
|
|
|
} |
...
|
...
|
|