Upload servlet

package com.fendou.archive.service.impl;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;

import com.fendou.archive.dao.ArchiveDao;
import com.fendou.archive.dao.UserDao;
import com.fendou.archive.po.Archive;
import com.fendou.archive.po.CArchive;
import com.fendou.archive.po.User;
import com.fendou.archive.service.vo.ArchiveVo;
import com.fendou.authority.dao.CommonDao;
import com.fendou.authority.dao.DepartmentDao;
import com.fendou.authority.dao.MajorDao;
import com.fendou.authority.po.Common;
import com.fendou.authority.po.Department;
import com.fendou.authority.po.Major;
import com.fendou.common.ConvertUtils;
import com.fendou.engage.dao.IResumeDao;
import com.fendou.platform.PageUtil;
import com.fendou.salary.dao.ISalaryStandardDao;
import com.fendou.salary.po.SalaryStandard;

public class ArchiveServiceDaoImpl implements ArchiveServiceDao {
   
 private ArchiveDao archivedao;
 private DepartmentDao deptDao;
 private MajorDao majorDao;
 private CommonDao commondao;
 private ISalaryStandardDao iSalaryStandardDao;
 private UserDao userdao;
    private Department department;   //作为全局,为了,审核时,要user要set部门。
 public void setUserdao(UserDao userdao) {
  this.userdao = userdao;
 }
 public void setiSalaryStandardDao(ISalaryStandardDao iSalaryStandardDao) {
  this.iSalaryStandardDao = iSalaryStandardDao;
 }
 public void setArchivedao(ArchiveDao archivedao) {
  this.archivedao = archivedao;
 }
 public void setDeptDao(DepartmentDao deptDao) {
  this.deptDao = deptDao;
 }

 public void setMajorDao(MajorDao majorDao) {
  this.majorDao = majorDao;
 }

 public void setCommondao(CommonDao commondao) {
  this.commondao = commondao;
 }

 
     /*
     * (non-Javadoc)
     * @see com.fendou.archive.service.impl.ArchiveServiceDao#addArchive(com.fendou.archive.service.vo.ArchiveVo, java.lang.String, java.lang.String, java.lang.String, java.lang.String)
     */
 
 public void addArchive(ArchiveVo archivevo,String path,String IpTimeStamp,String name1,String name2) {
  Archive archive=new Archive();
  ConvertUtils.convertVoToPo(archivevo, archive);
  try {
   /*
    * 转换日期
    */
   Date date = new Date();
   SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
   archive.setBirthday(sdf.parse(archivevo.getBirth()));
   
   /*
    * 转换部门
    */
           int deptId = archivevo.getDepartmentId();
           department = (Department) deptDao.get(deptId);
           archive.setDepartment(department);
          
           /*
    * 职位转换
    */
   int majorId = archivevo.getMajorId();
   Major major = (Major) majorDao.get(Major.class,majorId);
   archive.setMajor(major);
   
   /*
    *  公共属性
    */
   int nationalityId = archivevo.getNationalityId();
   Common nationality = (Common) commondao.get(nationalityId);
   archive.setNationality(nationality);
   
   int partyId  =archivevo.getPartyId();
   Common party = (Common) commondao.get(partyId);
   archive.setParty(party);
   
   int educatedDegreeId = archivevo.getEducatedDegreeId();
   Common educatedDegree = (Common)commondao.get(educatedDegreeId);
   archive.setEducatedDegree(educatedDegree);
   
   int raceId = archivevo.getRaceId();
   Common race =(Common)commondao.get(raceId);
   archive.setRace(race);
   
   int religionId=archivevo.getReligionId();
   Common religion=(Common)commondao.get(religionId);
   archive.setReligion(religion);
   
   int sexId = archivevo.getSexId();
   Common sex=(Common)commondao.get(sexId);
   archive.setSex(sex);
   
   int salaryId =archivevo.getSalaryStandardId();
   SalaryStandard  s =iSalaryStandardDao.isSalaryStandard(salaryId);
   archive.setSalaryStandard(s);
   if(!archivevo.getUid().equals("") &&archivevo.getUid()!=null){
       archive.setRegister(userdao.get(Integer.parseInt(archivevo.getUid())));
   }   
   
     
     
   /**
    * 档案附件和照片上传
    */
   Upload(archivevo, path, IpTimeStamp, name1,name2);
   
   archive.setRegistTime(new Date());
   archive.setState("0");//表示未审核。
   archive.setFileStatus("1");//1表示一个状态,
   archive.setPicture("../images/uploadpicture/"+IpTimeStamp+name1);
   archive.setAttachment("../images/uploadpicture/"+IpTimeStamp+name1);
            archivedao.addArchive(archive);
      
  
  } catch (ParseException e) {
   e.printStackTrace();
  } catch (FileNotFoundException e) { 
   e.printStackTrace();
  } catch (IOException e) { 
   e.printStackTrace();
  } catch (Exception e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  }
  
  
  
 }
 /**
  * upload
  * @param archivevo
  * @param path
  * @param IpTimeStamp
  * @param ext
  * @throws FileNotFoundException
  * @throws IOException
  */
 public void Upload(ArchiveVo archivevo, String path, String IpTimeStamp,
   String name1,String name2) throws FileNotFoundException, IOException {
  
  if(archivevo.getAttachments()!=null && archivevo.getPictures()!=null){
   
   InputStream contentStram = archivevo.getPictures().getInputStream();
     File file = new File(path.concat("images/uploadpicture/"),IpTimeStamp+name1);
     FileOutputStream fos = new FileOutputStream(file);
     byte[] buf = new byte[1024];
     int length=0;
    while((length=contentStram.read(buf))!=-1){
     fos.write(buf,0,length); 
    }
    contentStram.close();
    fos.flush();
    fos.close();
   
    InputStream contentStram2 = archivevo.getAttachments().getInputStream();
    File file2 = new File(path.concat("images/uploadpicture/"),IpTimeStamp+name2);
    FileOutputStream fos2 = new FileOutputStream(file2);
    byte[] buf2 = new byte[1024];
     int length2=0;
    while((length2=contentStram2.read(buf2))!=-1){
      fos2.write(buf2,0,length2); 
     }
    contentStram2.close();
    fos2.flush();
    fos2.close();
  }if(archivevo.getAttachments()!=null && archivevo.getPictures()==null){
   
   InputStream contentStram2 = archivevo.getAttachments().getInputStream();
   File file2 = new File(path.concat("images/uploadpicture/"),IpTimeStamp+name2);
   FileOutputStream fos2 = new FileOutputStream(file2);
   byte[] buf2 = new byte[1024];
    int length2=0;
   while((length2=contentStram2.read(buf2))!=-1){
     fos2.write(buf2,0,length2); 
    }
   contentStram2.close();
   fos2.flush();
   fos2.close(); 
  }if(archivevo.getAttachments()==null && archivevo.getPictures()!=null){
    InputStream contentStram = archivevo.getPictures().getInputStream();
    File file = new File(path.concat("images/uploadpicture/"),IpTimeStamp+name1);
    FileOutputStream fos = new FileOutputStream(file);
    byte[] buf = new byte[1024];
    int length=0;
   while((length=contentStram.read(buf))!=-1){
    fos.write(buf,0,length); 
   }
   contentStram.close();
   fos.flush();
   fos.close();
  }
   
  }
  
  
 
 public void deleteArchive(int id) {
  archivedao.deleteArchive(id);
 }
 
 public void deleteCArchive(int cid) {
  archivedao.deleteCArchive(cid); 
 }
 
 public void updateArchive(ArchiveVo archivevo, Archive archive,String path, String IpTimeStamp,
   String name1,String name2) {
  ConvertUtils.convertVoToPo(archivevo, archive);
   /*
    * 转换日期
    */
   Date date = new Date();
   SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
   try {
    archive.setBirthday(sdf.parse(archivevo.getBirth()));
   
   
   /*
    * 转换部门
    */
           int deptId = archivevo.getDepartmentId();
           Department department = (Department) deptDao.get(deptId);
           archive.setDepartment(department);
          
           /*
    * 职位转换
    */
   int majorId = archivevo.getMajorId();
   Major major = (Major) majorDao.get(Major.class,majorId);
   archive.setMajor(major);
   
   /*
    *  公共属性
    */
   int nationalityId = archivevo.getNationalityId();
   Common nationality = (Common) commondao.get(nationalityId);
   archive.setNationality(nationality);
   
   int partyId  =archivevo.getPartyId();
   Common party = (Common) commondao.get(partyId);
   archive.setParty(party);
   
   int educatedDegreeId = archivevo.getEducatedDegreeId();
   Common educatedDegree = (Common)commondao.get(educatedDegreeId);
   archive.setEducatedDegree(educatedDegree);
   
   int raceId = archivevo.getRaceId();
   Common race =(Common)commondao.get(raceId);
   archive.setRace(race);
   
   int religionId=archivevo.getReligionId();
   Common religion=(Common)commondao.get(religionId);
   archive.setReligion(religion);
   
   int salaryId =archivevo.getSalaryStandardId();
   SalaryStandard  s =iSalaryStandardDao.isSalaryStandard(salaryId);
   archive.setSalaryStandard(s);
   if(!archivevo.getUid().equals("") && archivevo.getUid()!=null){
      archive.setChanger(userdao.get(Integer.parseInt(archivevo.getUid())));
   }
   archive.setChangeTime(new Date());
   
   
   /**
    * 档案
             */
            Upload(archivevo, path, IpTimeStamp, name1,name2);
   archive.setChangeTime(new Date());
   archive.setPicture("../images/uploadpicture/"+IpTimeStamp+name1);
   archive.setAttachment("../images/uploadpicture/"+IpTimeStamp+name1);
   archivedao.updateArchive(archive);
   
   
   } catch (ParseException e) {
    e.printStackTrace();
   } catch (FileNotFoundException e) {
    e.printStackTrace();
   } catch (IOException e) {
    e.printStackTrace();
   } catch (Exception e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
   }
 }

 public void updateState(int id ,int userId,String info) {
  Archive archive = new Archive();
  archive=archivedao.get(id);
  
  if("1".equals(info)){
     archive.setState("1");
       if(userId!=0){
          archive.setChecker(userdao.get(userId));
       }
    
  }else if("2".equals(info)){
      archive.setState("2"); //通过
      if(userId!=0){
          archive.setChecker(userdao.get(userId));
       }
      User user = new User();
      user.setDepartment(department);
      user.setArchive(archive);
      user.setCreateTime(new Date());
      user.setUpdateTime(new Date());
      user.setStatus("0");
  
      //把此对象放入档案中,建立关系。
         userdao.addUser(user);
  }
  archivedao.updateState(archive);

 }
 
 public List<?> getAll() {
  return archivedao.getAll();
 }
 public List<?> searchPage(PageUtil page, String hql) {
  return archivedao.searchPage(page, hql);
 }
 public int totalcount(String hql) {
    return archivedao.totalcount(hql);
 }
 
 public Archive get(int id) {
  return archivedao.get(id);
 }
 
 public CArchive getC(int cid) {
  return archivedao.getC(cid);
 }
 public void updateFileState(int id,String info) {
  Archive archive = new Archive();
  archive=archivedao.get(id);
  if("0".equals(info)){
   archive.setFileStatus("0");//表示删除
  }else if("1".equals(info)){
   archive.setFileStatus("1");//表示恢复
  }
  archivedao.updateArchive(archive);
 }
 
 public void addCarchive(CArchive carchive,int uid) {
  
  
  //carchive.setCheckStatus(checkStatus)
  carchive.setChanger(userdao.get(uid));
  carchive.setChangeTime(new Date());
  archivedao.addCArchive(carchive);
 }
 public void addresumetoArchive(Archive archive) {
  archivedao.addArchive(archive);
  
 }
 //QBC
 public List<Archive> selectByQBC(HashMap<Object, Object> filter,
   String Currentpage) {
  return archivedao.selectByQBC(filter, Currentpage);
 }
 public PageUtil getPageUtil() {
  return archivedao.getPageUtil();
 }

}

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值