可劲儿折腾SIDE,让它不停的跑SAS代码...突然发现每次SAS output中显示的时间都一样,好像都是SAS Server Manager的启动时间。直接在SAS系统上运行可不是这个效果(其实这不是个BUG,SAS系统里面的Output中的时间就是SAS Session启动的时间,而不是执行SAS代码的时间,是我看错了 ...如果想让它显示每次SAS代码的执行时间,可以把它替换掉)
我把下列代码改了改:
package com.grs.app.side.service;
import com.grs.app.side.domain.SasResultWrapper;
import com.grs.app.slink.facade.ICommandFacade;
import com.grs.app.slink.result.ICommandResult;
import com.grs.app.slink.server.ServerManager;
public class SasService {
public SasResultWrapper run(String code) throws Exception {
ServerManager manager = ServerManager.getInstance();
ICommandFacade facade = manager.getCommandFacade();
ICommandResult result = facade.doExecBaseCode(code);
String log = result.getLog();
SasResultWrapper sasResult = new SasResultWrapper();
sasResult.setRetCode(result.getRetCode());
sasResult.setRetMsg(result.getRetMsg());
sasResult.setLog(result.getLog());
sasResult.setData(result.getData());
String output = result.getOutput();
sasResult.setOutput(output);
return sasResult;
}
}
更新后的代码如下:
package com.grs.app.side.service;
import com.grs.app.side.domain.SasResultWrapper;
import com.grs.app.slink.facade.ICommandFacade;
import com.grs.app.slink.result.ICommandResult;
import com.grs.app.slink.server.ServerManager;
public class SasService {
public SasResultWrapper run(String code) throws Exception {
ServerManager manager = ServerManager.getInstance();
ICommandFacade facade = manager.getCommandFacade();
ICommandResult result = facade.doExecBaseCode(code);
String log = result.getLog();
SasResultWrapper sasResult = new SasResultWrapper();
sasResult.setRetCode(result.getRetCode());
sasResult.setRetMsg(result.getRetMsg());
sasResult.setLog(result.getLog());
sasResult.setData(result.getData());
String output = result.getOutput();
// Bug fixed: the date is always when the backend started. Replace it with the current date ==>
// sasResult.setOutput(output);
int indexOfNewLine = output.indexOf("\r\n\r\n");
if (-1 != indexOfNewLine) {
String part1 = output.substring(0, indexOfNewLine);
String part2 = output.substring(indexOfNewLine);
part1 = part1.replaceAll("\\d{1,2}:\\d{1,2}\\s\\w+,\\s\\w+\\s\\d+,\\s\\d{4}", new java.text.SimpleDateFormat("HH:mm EEEE, MMMM d, yyyy").format(new java.util.Date()));
sasResult.setOutput(part1 + part2);
}
// Bug fixed: the date is always when the backend started. Replace it with the current date <==
return sasResult;
}
}
关键点在于正则表达式
\d{1,2}:\d{1,2}\s\w+,\s\w+\s\d+,\s\d{4}
和时间格式
HH:mm EEEE, MMMM d, yyyy
的使用。