Merge pull request #1508 from KeRan213539/develop

导出查询结果增加dataId条件,修复导入失败的问题
This commit is contained in:
Fury Zhu 2019-07-09 14:07:35 +08:00 committed by GitHub
commit 627331ef12
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 29 additions and 15 deletions

View File

@ -27,7 +27,6 @@ import com.alibaba.nacos.config.server.service.PersistService;
import com.alibaba.nacos.config.server.service.trace.ConfigTraceService;
import com.alibaba.nacos.config.server.utils.*;
import com.alibaba.nacos.config.server.utils.event.EventDispatcher;
import com.google.common.base.Joiner;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.time.DateFormatUtils;
import org.slf4j.Logger;
@ -402,14 +401,14 @@ public class ConfigController {
@ResponseBody
public ResponseEntity<byte[]> exportConfig(HttpServletRequest request,
HttpServletResponse response,
@RequestParam("group") String group,
@RequestParam(value = "dataId", required = false) String dataId,
@RequestParam(value = "group", required = false) String group,
@RequestParam(value = "appName", required = false) String appName,
@RequestParam(value = "tenant", required = false,
defaultValue = StringUtils.EMPTY) String tenant,
@RequestParam(value = "ids", required = false)List<Long> ids) {
ids.removeAll(Collections.singleton(null));
String idsStr = Joiner.on(",").join(ids);
List<ConfigInfo> dataList = persistService.findAllConfigInfo4Export(group, tenant, appName, idsStr);
List<ConfigInfo> dataList = persistService.findAllConfigInfo4Export(dataId, group, tenant, appName, ids);
List<ZipUtils.ZipItem> zipItemList = new ArrayList<>();
StringBuilder metaData = null;
for(ConfigInfo ci : dataList){
@ -544,8 +543,7 @@ public class ConfigController {
}
ids.removeAll(Collections.singleton(null));
String idsStr = Joiner.on(",").join(ids);
List<ConfigInfo> queryedDataList = persistService.findAllConfigInfo4Export(null, null, null, idsStr);
List<ConfigInfo> queryedDataList = persistService.findAllConfigInfo4Export(null,null, null, null, ids);
if(queryedDataList == null || queryedDataList.isEmpty()){
failedData.put("succCount", 0);

View File

@ -3298,16 +3298,28 @@ public class PersistService {
* @param group
* @return Collection of ConfigInfo objects
*/
public List<ConfigInfo> findAllConfigInfo4Export(final String group, final String tenant,
final String appName, final String ids) {
public List<ConfigInfo> findAllConfigInfo4Export(final String dataId, final String group, final String tenant,
final String appName, final List<Long> ids) {
String tenantTmp = StringUtils.isBlank(tenant) ? StringUtils.EMPTY : tenant;
StringBuilder where = new StringBuilder(" where ");
List<String> paramList = new ArrayList<>();
if(StringUtils.isNotBlank(ids)){
where.append(" id in (").append(ids).append(") ");
List<Object> paramList = new ArrayList<>();
if(!CollectionUtils.isEmpty(ids)){
where.append(" id in (");
for (int i = 0; i < ids.size(); i++) {
if (i != 0) {
where.append(", ");
}
where.append("?");
paramList.add(ids.get(i));
}
where.append(") ");
} else {
where.append(" tenant_id=? ");
paramList.add(tenantTmp);
if (!StringUtils.isBlank(dataId)) {
where.append(" and data_id like ? ");
paramList.add(generateLikeArgument(dataId));
}
if (StringUtils.isNotBlank(group)) {
where.append(" and group_id=? ");
paramList.add(group);

View File

@ -115,7 +115,10 @@ public class ZipUtils {
ZipItem metaDataItem = null;
try (ZipInputStream zipIn = new ZipInputStream(new ByteArrayInputStream(source))) {
ZipEntry entry;
while ((entry = zipIn.getNextEntry()) != null && !entry.isDirectory()) {
while ((entry = zipIn.getNextEntry()) != null) {
if(entry.isDirectory()){
continue;
}
try (ByteArrayOutputStream out = new ByteArrayOutputStream()) {
byte[] buffer = new byte[1024];
int offset;

View File

@ -673,9 +673,10 @@ class ConfigurationManagement extends React.Component {
}
exportData() {
let url = `v1/cs/configs?export=true&group=${this.group}&tenant=${getParams(
'namespace'
)}&appName=${this.appName}&ids=`;
let url =
`v1/cs/configs?export=true&group=${this.group}&tenant=${getParams('namespace')}&appName=${
this.appName
}&ids=&dataId=` + this.dataId;
window.location.href = url;
}