public Boolean ImportSQLText(MultipartFile file, HttpServletResponse response){
try {
ServletOutputStream outputStream = response.getOutputStream();
response.setContentType("application/octet-stream");
response.addHeader("Content-Disposition", "attachment;fileName="+ URLEncoder.encode("sql.txt","UTF-8"));
InputStreamReader is=new InputStreamReader(file.getInputStream());
BufferedReader br=new BufferedReader(is);
String line=br.readLine();
List<String> list=new ArrayList<>();
while (line != null){
list.add(line);
line=br.readLine();
}
List<String> endList = getEndList(list);
String str= System.getProperty("line.separator");
byte[] bytes = endList.stream().collect(Collectors.joining(str)).getBytes();
outputStream.write(bytes);
br.close();
is.close();
outputStream.close();
return Boolean.TRUE;
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return Boolean.FALSE;
}
public List<String> getEndList(List<String> list){
List<CustomerMergeApplyDO> customerMergeApplyDOS = customerMergeApplyManager.lambdaQuery()
.select(CustomerMergeApplyDO::getTargetCustomerCode,CustomerMergeApplyDO::getTargetCustomerUserId,
CustomerMergeApplyDO::getSourceCustomerCode,CustomerMergeApplyDO::getSourceCustomerUserId,
CustomerMergeApplyDO::getCode,CustomerMergeApplyDO::getTargetCustomerName, CustomerMergeApplyDO::getSourceCustomerName)
.eq(CustomerMergeApplyDO::getBizDataStatus, DICT_NO)
.list();
if(CollectionUtil.isEmpty(customerMergeApplyDOS)){
Collections.emptyList();
}
List<CustomerMergeApplysDTO> customerMergeApplysDTOS = convertTo(customerMergeApplyDOS, CustomerMergeApplysDTO.class);
getTargetCustomerCodeInfo(customerMergeApplysDTOS);
List<String> endList=new ArrayList<>();
for(CustomerMergeApplysDTO customerMergeApplys: customerMergeApplysDTOS){
String sqlStr=replaceAll(list.stream().collect(Collectors.joining("~")),customerMergeApplys);
List<String> stringList = Arrays.asList(sqlStr.split("~"));
endList.addAll(stringList);
}
return endList;
}
public String replaceAll(String str,CustomerMergeApplysDTO customerMergeApplys){
return
str.replace("#{object.targetCustomerUserId}", StringUtils.toString(customerMergeApplys.getTargetCustomerUserId()))
.replace("#{object.targetCustomerCode}",StringUtils.toString(customerMergeApplys.getTargetCustomerCode()))
.replace("#{object.targetCustomerId}",StringUtils.toString(customerMergeApplys.getTargetCustomerId()))
.replace("#{object.targetMobile}",StringUtils.toString(customerMergeApplys.getTargetMobile()))
.replace("#{object.targetCustomerName}",StringUtils.toString(customerMergeApplys.getTargetCustomerName()))
.replace("#{object.targetCustomerUserCode}",StringUtils.toString(customerMergeApplys.getTargetCustomerUserCode()))
.replace("#{object.targetUserCode}",StringUtils.toString(customerMergeApplys.getTargetUserCode()))
.replace("#{object.targetUserId}",StringUtils.toString(customerMergeApplys.getTargetUserId()))
.replace("#{object.targetUsername}",StringUtils.toString(customerMergeApplys.getTargetUsername()))
.replace("#{object.sourceCustomerCode}",StringUtils.toString(customerMergeApplys.getSourceCustomerCode()))
.replace("#{object.sourceCustomerUserId}",StringUtils.toString(customerMergeApplys.getSourceCustomerUserId()))
.replace("#{object.sourceCustomerName}",StringUtils.toString(customerMergeApplys.getSourceCustomerName()))
.replace("#{object.sourceUserCode}",StringUtils.toString(customerMergeApplys.getSourceUserCode()))
.replace("#{object.sourceUserId}",StringUtils.toString(customerMergeApplys.getSourceUserId()));
}