在人员信息维护节点增加批量导出员工照片实现方法

 /**
  * 批量导出照片
  * 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, "提示","导出完成");
  }
  
 }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值