package cn.hs.dpl.web.action;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.sql.Timestamp;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.scheduling.quartz.QuartzJobBean;
import cn.hs.dpl.service.IMenuService;
import cn.hs.dpl.utils.LoggerUtil;
/**
* 关于版本自动定制化的Action
* @author bWX62796
*
*/
public class TimerAction extends QuartzJobBean {
//版本定制化service
private IMenuService menuService;
public void setMenuService(IMenuService menuService) {
this.menuService = menuService;
}
/**
* 自动化的版本定制化
* @return
* @throws Exception
*/
@Override
protected void executeInternal(JobExecutionContext arg0)
throws JobExecutionException {
System.out.println("开始版本定制化...");
LoggerUtil.tranceINFO("版本自动定制化...");
String xmlString = menuService.addAutoRule();
BufferedInputStream in = null;
BufferedOutputStream out = null;
String temp = Thread.currentThread().getContextClassLoader().getResource("").getPath() ;
temp = temp.substring(0, temp.lastIndexOf("WEB-INF")); //WEB-INF 上一級就是項目的根目錄
String uploadPath = temp + "\\auto_version";
File file = new File(uploadPath);
try {
in = new BufferedInputStream(new ByteArrayInputStream(xmlString.getBytes("UTF-8")));
//File file = new File(uploadPath);
if(!file.exists()) {
file.mkdir();
}
out = new BufferedOutputStream( new FileOutputStream( uploadPath+ File.separator + new Timestamp(System.currentTimeMillis()).toString().substring(0, 10) +"_rule.xml"));
int j = 0;
while ( ( j = in.read() ) != -1 ) {
out.write(j);
}
} catch (Exception e) {
e.printStackTrace();
}
finally {
if(in != null){
try {
in.close();
} catch (IOException e) {
e.printStackTrace();
}
}
if(out!= null){
try {
out.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
}