95bfd776ed941133cdedc594ba52c005c3809b66.svn-base 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. package UIM.WGJ;
  2. import org.apache.ibatis.session.SqlSession;
  3. import com.alibaba.excel.EasyExcel;
  4. import CoreFS.SA01.CoreIComponent;
  5. import CoreFS.SA06.CoreReturnObject;
  6. import QCM.COMMUNAL.VO.ExcelWGJ;
  7. import java.io.File;
  8. import java.io.FileInputStream;
  9. import java.io.FileNotFoundException;
  10. import java.io.FileOutputStream;
  11. import java.io.IOException;
  12. import java.io.InputStream;
  13. import java.net.URLDecoder;
  14. import java.text.DecimalFormat;
  15. import java.text.SimpleDateFormat;
  16. import java.util.ArrayList;
  17. import java.util.HashMap;
  18. import java.util.Iterator;
  19. import java.util.LinkedHashMap;
  20. import java.util.List;
  21. import java.util.Map;
  22. public class ImportEasyExcelUtil extends CoreIComponent{
  23. CoreReturnObject cro = new CoreReturnObject();
  24. SqlSession SqlSession =
  25. QCM.COMMUNAL.SqlSessionBuilder.openSqlSession();
  26. QCM.COMMUNAL.OrderSqMapper mapper = SqlSession.getMapper(QCM.COMMUNAL.OrderSqMapper.class);
  27. public CoreReturnObject dateImport(byte[] bdate,String fileUrl,String opman){
  28. CoreReturnObject cro = new CoreReturnObject();
  29. SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  30. SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd");
  31. try{
  32. String fileName = fileUrl;
  33. if (!fileName.substring(fileName.lastIndexOf(".")).equals(".xls")
  34. && !fileName.substring(fileName.lastIndexOf(".")).equals(".xlsx")){
  35. cro.setV_errCode(-1);
  36. cro.setV_errMsg("请导入xls或者xlsx类型的EXCEL文件");
  37. throw new Exception("请导入xls或者xlsx类型的EXCEL文件");
  38. }
  39. String path = this.getClass().getClassLoader().getResource("/").getPath().replaceFirst("classes/", "excelConfig/");
  40. path =URLDecoder.decode(path,"utf-8");
  41. String pathFileName = null;
  42. if(fileName.substring(fileName.lastIndexOf(".")).equals(".xls")){
  43. pathFileName = path+"temp3.xls";
  44. }
  45. if(fileName.substring(fileName.lastIndexOf(".")).equals(".xlsx")){
  46. pathFileName = path+"temp3.xlsx";
  47. }
  48. File file = new File(pathFileName);
  49. FileOutputStream out = new FileOutputStream(file);
  50. out.write(bdate);
  51. out.close();
  52. EasyExcel.read(pathFileName,ExcelWGJ.class,new ExcelModelListener(opman)).sheet().doRead();
  53. }catch(Exception e){
  54. e.printStackTrace();
  55. SqlSession.rollback();
  56. SqlSession.close();
  57. cro.setV_errCode(-1);
  58. cro.setV_errMsg("导入外购卷失败"+e.getMessage());
  59. return cro;
  60. }
  61. cro.setV_errCode(1);
  62. return cro;
  63. }
  64. }