fix: 优化大屏、组件的复制命名,避免多次复制后名称过长

优化大屏、组件的复制命名,避免多次复制后名称过长
main
hong.yang 2 years ago
parent 9a663685e1
commit cda945ea56

@ -173,6 +173,8 @@ public class BizComponentServiceImpl extends ServiceImpl<DataRoomBizComponentDao
return fileUrl; return fileUrl;
} }
public static final String COPY_SUFFIX = "-副本";
@Override @Override
public String copy(String code) { public String copy(String code) {
BizComponentEntity copyFrom = this.getInfoByCode(code); BizComponentEntity copyFrom = this.getInfoByCode(code);
@ -181,9 +183,19 @@ public class BizComponentServiceImpl extends ServiceImpl<DataRoomBizComponentDao
} }
String oldCode = copyFrom.getCode(); String oldCode = copyFrom.getCode();
copyFrom.setId(null); copyFrom.setId(null);
copyFrom.setName(copyFrom.getName() + "_复制"); String oldName = copyFrom.getName();
// 检查是否有 -副本,有的话从-副本开始,后面全部去掉
if (oldName.contains(COPY_SUFFIX)) {
oldName = oldName.substring(0, oldName.indexOf(COPY_SUFFIX));
if (StringUtils.isBlank(oldName)) {
oldName = "组件";
}
}
copyFrom.setName(oldName + COPY_SUFFIX);
int i = 1;
while(this.checkName(null, copyFrom.getName())) { while(this.checkName(null, copyFrom.getName())) {
copyFrom.setName(copyFrom.getName() + "_复制"); copyFrom.setName(oldName + COPY_SUFFIX + i);
i++;
} }
copyFrom.setCode(CodeGenerateUtils.generate("bizComponent")); copyFrom.setCode(CodeGenerateUtils.generate("bizComponent"));
boolean copy = this.copyCoverPicture(oldCode, copyFrom.getCode()); boolean copy = this.copyCoverPicture(oldCode, copyFrom.getCode());

@ -296,6 +296,9 @@ public class DataRoomPageServiceImpl extends ServiceImpl<DataRoomPageDao, PageEn
PAGE_ENTITY_CACHE.invalidate(bigScreenEntity.getCode()); PAGE_ENTITY_CACHE.invalidate(bigScreenEntity.getCode());
} }
public static final String COPY_SUFFIX = "-副本";
@Override @Override
public String copy(PageEntity screenEntity) { public String copy(PageEntity screenEntity) {
DataRoomPageDTO config = (DataRoomPageDTO) screenEntity.getConfig(); DataRoomPageDTO config = (DataRoomPageDTO) screenEntity.getConfig();
@ -304,9 +307,18 @@ public class DataRoomPageServiceImpl extends ServiceImpl<DataRoomPageDao, PageEn
screenEntity.setCode(CodeGenerateUtils.generate(screenEntity.getType())); screenEntity.setCode(CodeGenerateUtils.generate(screenEntity.getType()));
int i = 1; int i = 1;
String oldName = screenEntity.getName(); String oldName = screenEntity.getName();
screenEntity.setName(oldName + "_复制"); // 检查是否有 -副本,有的话从-副本开始,后面全部去掉
if (oldName.contains(COPY_SUFFIX)) {
oldName = oldName.substring(0, oldName.indexOf(COPY_SUFFIX));
if (StringUtils.isBlank(oldName)) {
oldName = "大屏";
}
}
screenEntity.setName(oldName + COPY_SUFFIX);
while (checkNameRepeat(screenEntity)) { while (checkNameRepeat(screenEntity)) {
screenEntity.setName(oldName + "_复制" + i++); // 如果重复,采取 -副本1-副本2的方式
screenEntity.setName(oldName + COPY_SUFFIX + i);
i++;
} }
config.setName(screenEntity.getName()); config.setName(screenEntity.getName());
config.setCode(screenEntity.getCode()); config.setCode(screenEntity.getCode());

Loading…
Cancel
Save