日期:2014-05-17 浏览次数:20746 次
//导出数据至txt(符合搜索条件的数据)
public String export(){
//对选项进行处理,组成一个personalinfo list
String[] idArray=pids.split(",");
List<Personalinfo> npList=new ArrayList<Personalinfo>();
for (int i = 0; i < idArray.length; i++) {
Personalinfo p=personalinfoBIZ.findById(Integer.parseInt(idArray[i]));
npList.add(p);
}
Date date=new Date();
SimpleDateFormat df=new SimpleDateFormat("yyyyMMddHHmmss");
String extime=df.format(date);
//System.out.println("共"+npList.size()+"条数据");
File dirFile = new File("c:\\wuxi\\police");
if(!dirFile.exists()){
dirFile.mkdirs();
}
//查找文件,如果不存在,就创建
File file = new File("c:\\wuxi\\police\\"+extime+"police.txt");
if(!file.exists()){
try {
file.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
PrintWriter out=null;
try {
out = new PrintWriter(new BufferedWriter(new FileWriter("c:\\wuxi\\police\\"+extime+"police.txt")));
for(int i=0;i<npList.size();i++){
String content="";
Personalinfo nperson=npList.get(i);
Boolean nstatus=nperson.getStatus();
//动作标识
if(nstatus==true){
content+="T~";
}else {
content+="F~";
}
//人员编号(组织机构代码+身份证号码)
//若要改成根据id查询 需添加外键关系 personalinfo users之间
Users nusers=(Users)usersBIZ.findByRealName(nperson.getRecorder()).get(0);
content+=nusers.getOrg().getCode();
content+=np