导出查询结果增加dataId条件,修复导入失败的问题
This commit is contained in:
parent
551f64ba84
commit
a39d288d15
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user