refactor: 视图编辑时检验title是否重复

This commit is contained in:
wangjiahao 2022-04-02 20:09:45 +08:00
parent 77a5ba4baf
commit 71b3422ead
11 changed files with 113 additions and 60 deletions

View File

@ -39,7 +39,7 @@ public interface ExtChartViewMapper {
void copyToCache(@Param("id") String id ); void copyToCache(@Param("id") String id );
void deleteCacheWithPanel(@Param("panelId") String panelId ); void deleteCacheWithPanel(@Param("viewIds") List<String> viewIds,@Param("panelId") String panelId );
void deleteViewCache(@Param("viewId") String viewId ); void deleteViewCache(@Param("viewId") String viewId );
@ -48,4 +48,6 @@ public interface ExtChartViewMapper {
int updateToCache(@Param("viewId") String viewId ); int updateToCache(@Param("viewId") String viewId );
void copyCache(@Param("sourceViewId") String sourceViewId,@Param("newViewId") String newViewId); void copyCache(@Param("sourceViewId") String sourceViewId,@Param("newViewId") String newViewId);
void deleteNoUseView(@Param("viewIds") List<String> viewIds,@Param("panelId") String panelId );
} }

View File

@ -152,23 +152,23 @@
chart_view_cache.id = #{sourceViewId} chart_view_cache.id = #{sourceViewId}
</insert> </insert>
<!-- <select id="searchOne" resultMap="BaseResultMapDTO">--> <!-- <select id="searchOne" resultMap="BaseResultMapDTO">-->
<!-- select--> <!-- select-->
<!-- id, `name`, scene_id, table_id, `type`, title, create_by, create_time, update_time,--> <!-- id, `name`, scene_id, table_id, `type`, title, create_by, create_time, update_time,-->
<!-- style_priority,x_axis, y_axis, custom_attr, custom_style, custom_filter, snapshot--> <!-- style_priority,x_axis, y_axis, custom_attr, custom_style, custom_filter, snapshot-->
<!-- from chart_view--> <!-- from chart_view-->
<!-- <where>--> <!-- <where>-->
<!-- <if test="sceneId != null">--> <!-- <if test="sceneId != null">-->
<!-- and scene_id = #{sceneId,jdbcType=VARCHAR}--> <!-- and scene_id = #{sceneId,jdbcType=VARCHAR}-->
<!-- </if>--> <!-- </if>-->
<!-- <if test="id != null">--> <!-- <if test="id != null">-->
<!-- and id = #{id,jdbcType=VARCHAR}--> <!-- and id = #{id,jdbcType=VARCHAR}-->
<!-- </if>--> <!-- </if>-->
<!-- </where>--> <!-- </where>-->
<!-- <if test="sort != null">--> <!-- <if test="sort != null">-->
<!-- order by ${sort}--> <!-- order by ${sort}-->
<!-- </if>--> <!-- </if>-->
<!-- </select>--> <!-- </select>-->
<select id="search" resultMap="BaseResultMapDTO"> <select id="search" resultMap="BaseResultMapDTO">
select select
@ -407,7 +407,7 @@
</delete> </delete>
<select id="searchViewsWithPanelId" resultMap="BaseResultMapDTO"> <select id="searchViewsWithPanelId" resultMap="BaseResultMapDTO">
SELECT * FROM chart_view SELECT * FROM chart_view
WHERE WHERE
id IN ( id IN (
@ -421,12 +421,14 @@
</select> </select>
<delete id="deleteCacheWithPanel"> <delete id="deleteCacheWithPanel">
DELETE cvc delete from chart_view_cache
FROM where scene_id = #{panelId}
chart_view_cache cvc <if test="viewIds != null and viewIds.size() > 0">
INNER JOIN panel_view pv ON cvc.id = pv.chart_view_id and id not in
WHERE <foreach collection="viewIds" item="viewId" open='(' separator=',' close=')'>
pv.panel_id = #{panelId} #{viewId}
</foreach>
</if>
</delete> </delete>
<delete id="deleteViewCache"> <delete id="deleteViewCache">
delete from chart_view_cache where id = #{viewId} delete from chart_view_cache where id = #{viewId}
@ -434,35 +436,35 @@
<update id="copyCacheToView"> <update id="copyCacheToView">
UPDATE chart_view cv, UPDATE chart_view cv,
chart_view_cache cve chart_view_cache cve
SET cv.`name` = cve.`name`, SET cv.`name` = cve.`name`,
cv.title = cve.title, cv.title = cve.title,
cv.scene_id = cve.scene_id, cv.scene_id = cve.scene_id,
cv.table_id = cve.table_id, cv.table_id = cve.table_id,
cv.`type` = cve.`type`, cv.`type` = cve.`type`,
cv.render = cve.render, cv.render = cve.render,
cv.result_count = cve.result_count, cv.result_count = cve.result_count,
cv.result_mode = cve.result_mode, cv.result_mode = cve.result_mode,
cv.create_by = cve.create_by, cv.create_by = cve.create_by,
cv.create_time = cve.create_time, cv.create_time = cve.create_time,
cv.update_time = cve.update_time, cv.update_time = cve.update_time,
cv.style_priority = cve.style_priority, cv.style_priority = cve.style_priority,
cv.chart_type = cve.chart_type, cv.chart_type = cve.chart_type,
cv.is_plugin = cve.is_plugin, cv.is_plugin = cve.is_plugin,
cv.x_axis = cve.x_axis, cv.x_axis = cve.x_axis,
cv.x_axis_ext = cve.x_axis_ext, cv.x_axis_ext = cve.x_axis_ext,
cv.y_axis = cve.y_axis, cv.y_axis = cve.y_axis,
cv.y_axis_ext = cve.y_axis_ext, cv.y_axis_ext = cve.y_axis_ext,
cv.ext_stack = cve.ext_stack, cv.ext_stack = cve.ext_stack,
cv.ext_bubble = cve.ext_bubble, cv.ext_bubble = cve.ext_bubble,
cv.custom_attr = cve.custom_attr, cv.custom_attr = cve.custom_attr,
cv.custom_style = cve.custom_style, cv.custom_style = cve.custom_style,
cv.custom_filter = cve.custom_filter, cv.custom_filter = cve.custom_filter,
cv.drill_fields = cve.drill_fields, cv.drill_fields = cve.drill_fields,
cv.senior = cve.senior, cv.senior = cve.senior,
cv.SNAPSHOT = cve.SNAPSHOT, cv.SNAPSHOT = cve.SNAPSHOT,
cv.data_from = cve.data_from cv.data_from = cve.data_from
where cve.id = cv.id and cv.id in where cve.id = cv.id and cv.id in
<foreach collection="viewIds" item="viewId" open='(' separator=',' close=')'> <foreach collection="viewIds" item="viewId" open='(' separator=',' close=')'>
#{viewId} #{viewId}
</foreach> </foreach>
@ -500,4 +502,15 @@
cv.data_from = cve.data_from cv.data_from = cve.data_from
where cve.id = cv.id and cv.id =#{viewId} where cve.id = cv.id and cv.id =#{viewId}
</update> </update>
<delete id="deleteNoUseView">
delete from chart_view
where scene_id = #{panelId}
<if test="viewIds != null and viewIds.size() > 0">
and id not in
<foreach collection="viewIds" item="viewId" open='(' separator=',' close=')'>
#{viewId}
</foreach>
</if>
</delete>
</mapper> </mapper>

View File

@ -155,4 +155,10 @@ public class ChartViewController {
chartViewCacheService.refreshCache(id); chartViewCacheService.refreshCache(id);
} }
@ApiOperation("校验视图Title")
@PostMapping("/checkTitle")
public String checkTitle( @RequestBody ChartViewCacheRequest request) {
return chartViewService.checkTitle(request);
}
} }

View File

@ -115,6 +115,16 @@ public class ChartViewService {
return getOne(chartView.getId(), "panel_edit"); return getOne(chartView.getId(), "panel_edit");
} }
public String checkTitle(ChartViewCacheRequest chartView){
ChartViewCacheExample example = new ChartViewCacheExample();
example.createCriteria().andTitleEqualTo(chartView.getTitle()).andSceneIdEqualTo(chartView.getSceneId()).andIdNotEqualTo(chartView.getId());
List<ChartViewCache> result = chartViewCacheMapper.selectByExample(example);
if(CollectionUtils.isNotEmpty(result)){
return "fail";
}else{
return "success";
}
}
public ChartViewWithBLOBs newOne(ChartViewWithBLOBs chartView) { public ChartViewWithBLOBs newOne(ChartViewWithBLOBs chartView) {
long timestamp = System.currentTimeMillis(); long timestamp = System.currentTimeMillis();
@ -1030,7 +1040,7 @@ public class ChartViewService {
extChartViewMapper.chartCopy(newChartId, id, panelId); extChartViewMapper.chartCopy(newChartId, id, panelId);
extChartViewMapper.copyCache(id,newChartId); extChartViewMapper.copyCache(id,newChartId);
extPanelGroupExtendDataMapper.copyExtendData(id,newChartId,panelId); extPanelGroupExtendDataMapper.copyExtendData(id,newChartId,panelId);
chartViewCacheService.refreshCache(id); chartViewCacheService.refreshCache(newChartId);
return newChartId; return newChartId;
} }
@ -1061,7 +1071,7 @@ public class ChartViewService {
} }
public void initViewCache(String panelId) { public void initViewCache(String panelId) {
extChartViewMapper.deleteCacheWithPanel(panelId); extChartViewMapper.deleteCacheWithPanel(null,panelId);
} }
} }

View File

@ -127,9 +127,10 @@ public class PanelViewService {
//将视图从cache表中更新到正式表中 //将视图从cache表中更新到正式表中
viewIds = panelViewInsertDTOList.stream().map(panelView ->panelView.getChartViewId()).collect(Collectors.toList()); viewIds = panelViewInsertDTOList.stream().map(panelView ->panelView.getChartViewId()).collect(Collectors.toList());
extChartViewMapper.copyCacheToView(viewIds); extChartViewMapper.copyCacheToView(viewIds);
extChartViewMapper.deleteCacheWithPanel(panelId);
} }
} }
extChartViewMapper.deleteCacheWithPanel(viewIds,panelId);
extChartViewMapper.deleteNoUseView(viewIds,panelId);
panelGroup.setMobileLayout(mobileLayout); panelGroup.setMobileLayout(mobileLayout);
return viewIds; return viewIds;
} }

View File

@ -108,3 +108,12 @@ export function resetViewCache(viewId, panelId) {
loading: false loading: false
}) })
} }
export function checkTitle(data) {
return request({
url: '/chart/view/checkTitle',
method: 'post',
data: data,
loading: false
})
}

View File

@ -653,6 +653,7 @@ export default {
kettle_setting: 'Kettle Setting' kettle_setting: 'Kettle Setting'
}, },
chart: { chart: {
title_repeat: 'The Title Already Exist',
save_snapshot: 'Save Snapshot', save_snapshot: 'Save Snapshot',
datalist: 'Chart', datalist: 'Chart',
add_group: 'Add Group', add_group: 'Add Group',

View File

@ -655,6 +655,7 @@ export default {
kettle_setting: 'Kettle 設置' kettle_setting: 'Kettle 設置'
}, },
chart: { chart: {
title_repeat: '当前标题已存在',
save_snapshot: '保存縮略圖', save_snapshot: '保存縮略圖',
datalist: '視圖', datalist: '視圖',
add_group: '添加分組', add_group: '添加分組',

View File

@ -656,6 +656,7 @@ export default {
kettle_setting: 'Kettle 设置' kettle_setting: 'Kettle 设置'
}, },
chart: { chart: {
title_repeat: '当前标题已存在',
save_snapshot: '保存缩略图', save_snapshot: '保存缩略图',
datalist: '视图', datalist: '视图',
add_group: '添加分组', add_group: '添加分组',

View File

@ -50,6 +50,7 @@
<script> <script>
import { COLOR_PANEL, DEFAULT_TITLE_STYLE } from '../../chart/chart' import { COLOR_PANEL, DEFAULT_TITLE_STYLE } from '../../chart/chart'
import { checkTitle } from '@/api/chart/chart'
export default { export default {
name: 'TitleSelector', name: 'TitleSelector',
@ -114,10 +115,18 @@ export default {
this.titleForm.title = this.chart.title this.titleForm.title = this.chart.title
return return
} }
if (!this.titleForm.show) { checkTitle({ id: this.chart.id, title: this.titleForm.title, sceneId: this.chart.sceneId }).then((rsp) => {
this.isSetting = false if (rsp.data === 'success') {
} if (!this.titleForm.show) {
this.$emit('onTextChange', this.titleForm) this.isSetting = false
}
this.$emit('onTextChange', this.titleForm)
} else {
this.$error(this.$t('chart.title_repeat'))
this.titleForm.title = this.chart.title
return
}
})
}, },
inputOnInput: function(e) { inputOnInput: function(e) {
this.$forceUpdate() this.$forceUpdate()

View File

@ -877,7 +877,7 @@
@onLegendChange="onLegendChange" @onLegendChange="onLegendChange"
/> />
</el-collapse-item> </el-collapse-item>
<el-collapse-item v-if="chart.customStyle && chart.customStyle.background" name="background" :title="$t('chart.background')"> <el-collapse-item v-if="chart.customStyle && view.customStyle.background" name="background" :title="$t('chart.background')">
<background-color-selector <background-color-selector
:param="param" :param="param"
class="attr-selector" class="attr-selector"