/**
* 批量导出照片
* add by majie 2013-01-18
*/
public void batchExportPic(){
GeneralVO[] vos = getSelectPsnListData();
if(vos == null || vos.length == 0)
return;
//只能选择目录
getFileDirChooser().setFileSelectionMode(javax.swing.JFileChooser.DIRECTORIES_ONLY);
int userOperate = getFileDirChooser().showSaveDialog(this);
if (userOperate == 0) {// 0:保存,1:撤销
File file = getFileDirChooser().getSelectedFile();
if (file == null) {
nc.ui.pub.beans.MessageDialog.showHintDlg(this,
nc.ui.ml.NCLangRes.getInstance().getStrByID("600700",
"UPP600700-000108")/* @res "警告" */,
nc.ui.ml.NCLangRes.getInstance().getStrByID("600700",
"UPP600700-000109")/* @res "您没有选择要下载的目录!" */
);
return;
}
//文件名称,照片byte[]
Map<String,byte[]> map = new HashMap<String,byte[]>();
String id = null;
String psnname = null;
byte[] data = null;
GeneralVO[] picVO = null;
for(int i=0;i<vos.length;i++){
id = (String) vos[i].getAttributeValue("id");
psnname = (String) vos[i].getAttributeValue("psnname");
try {
picVO = HIDelegator.getPsnInf().queryByPsnPK((String) vos[i].getAttributeValue("pk_corp"),(String)vos[i].getAttributeValue("pk_psnbasdoc"));
} catch (BusinessException e) {
e.printStackTrace();
}
if(picVO != null && picVO.length > 0){
data = (byte[])picVO[0].getFieldValue("photo");
}
if(data != null && data.length > 0){
map.put(id+psnname,data);
}
}
if(map.size() == 0){
nc.ui.pub.beans.MessageDialog.showHintDlg(this, "警告","选择的员工均没有照片");
return;
}
Iterator<String> fileNames = map.keySet().iterator();
String filePath = null;
String key = null;
byte[] bts = null;
FileOutputStream outstream = null;
while(fileNames.hasNext()){
key = fileNames.next();
filePath = file+File.separator+key+".jpg";
bts = map.get(key);
try {
outstream = new FileOutputStream(filePath);
outstream.write(bts);
outstream.flush();
outstream.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
nc.ui.pub.beans.MessageDialog.showHintDlg(this, "提示","导出完成");
}
}