使用了apache poi做为导出组件
选择了大概1万多条数据,选择导出后程序无反应
没有走异常catch
excel控制类:
package com.tansuo365.test1.controller.excel;
import com.google.common.io.FileBackedOutputStream;
import com.tansuo365.test1.bean.goods.Anode;
import com.tansuo365.test1.bean.goods.CalcinedCoke;
import com.tansuo365.test1.bean.goods.MAsphalt;
import com.tansuo365.test1.bean.goods.PetroleumCoke;
import com.tansuo365.test1.mapper.goods.AnodeMapper;
import com.tansuo365.test1.mapper.goods.CalcinedCokeMapper;
import com.tansuo365.test1.mapper.goods.MAsphaltMapper;
import com.tansuo365.test1.mapper.goods.PetroleumCokeMapper;
import com.tansuo365.test1.service.goods.FileUploadService;
import com.tansuo365.test1.service.goods.GoodsCommonService;
import com.tansuo365.test1.service.goods.IGoodsService;
import com.tansuo365.test1.util.*;
import io.swagger.annotations.Api;
import org.apache.commons.fileupload.FileItem;
import org.hibernate.validator.internal.util.privilegedactions.GetMethod;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.PropertySource;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.commons.CommonsMultipartFile;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.*;
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.UUID;
/**
* 用于excel导入的controller
* {@link #//importExcel 导入excel,接收excel导入,文件为uploadFile,接收文件参数String instance标识上传类型}
*/
@PropertySource(value="classpath:excel.properties")
@Api(value = "Excel导入控制层",tags = "Excel导入控制接口 ExcelController",description = "Excel导入控制层,导出使用js插件")
@RestController
@RequestMapping(value = "/excel", produces = {"text/html;charset=UTF-8;","application/msexcel;charset=UTF-8" ,"application/json;charset=UTF-8;" })
public class ExcelController {
@Autowired
private FileUploadService fileUploadService;
@Value("${excel.pack.path}")
String packPath;
@Value("${excel.unpackExcel.path}")
String unPackExcelPach;
@Value("${excel.data.path}")
String excelPath;
@Autowired
ExcelController excelController; //装载自己,用于自己的方法互相调用
@Autowired
IGoodsService iGoodsService;
@Autowired
private GoodsCommonService goodsCommonService;
@Autowired
private LogUtils logUtils;
@Autowired
private GoodsUtils goodsUtils;
@Value("${excel.date.pattern}")
private String datePattern;
@Resource
private PetroleumCokeMapper petroleumCokeMapper;
@Resource
private CalcinedCokeMapper calcinedCokeMapper;
@Resource
private MAsphaltMapper mAsphaltMapper;
@Resource
private AnodeMapper anodeMapper;
private Class C;
public Class getC() {
return this.C;
}
public void setC(Class c) {
this.C = c;
}
@PostMapping("/exporExcel") <<<导出
@ResponseBody
public String exporMemberFormExcel(@RequestParam(name = "ids", defaultValue = "") Long[] ids
,String goodsName,String fileName,HttpServletResponse res) throws IOException {
if(ids.length == 0 || ids == null){
return "noAny";
}
SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd_HHmmss");
String now = format.format(new Date().getTime());
////伪造数据,调整导出标题的时候会发生少导出两条数据的情况
Long[] ids2 = new Long[ids.length+2];
for(int i = 2;i<ids.length;i++){
ids2[i]=ids[i];
}
ids2[0] = ids[0];
ids2[1] = ids[1];
ids2[ids2.length-1] = ids[0];
ids2[ids2.length-2] = ids[1];
String uuid = UUID.randomUUID().toString();
try {
File file = new File(excelPath);
if (!file.exists())
file.mkdirs();
FileOutputStream fileOut = new FileOutputStream(excelPath+uuid+"_"+now+".xls");
iGoodsService.exportExcel(ids2, fileOut,goodsName,fileName);
//downloadExcel(res,excelPath+fileName+"_"+now+".xls",fileName+"_"+now+".xls");
return "ok"+excelPath+uuid+"_"+now+".xls";
}catch (Exception e){
e.printStackTrace();
return "error";
}
}
@RequestMapping(value = "/sendExcel.xls")//下载Excel
public void sendUploadVoice(HttpServletResponse response,HttpServletRequest request,String pathName,String name) {
//System.out.println(pathName+"\t"+name);
File file = null;
try {
//接收请求
request.setCharacterEncoding("utf-8");
response.setCharacterEncoding("utf-8");
response.setContentType("application/octet-stream");//8进制字节流
//获取文件
name = URLDecoder.decode(name, "UTF-8");
//获取文件输入流 localFileDir是服务端存储文件的路径
file = new File(pathName);
response.setContentLength((int) file.length());
response.setHeader("Accept-Ranges", "bytes");
InputStream in = new BufferedInputStream(new FileInputStream(file), 1024);
OutputStream os = new BufferedOutputStream(response.getOutputStream());
byte[] bytes = new byte[1024];
int i = 0;
while ((i = in.read(bytes)) > 0) {
os.write(bytes, 0, i);
}
os.flush();
os.close();
} catch (Exception e) {
e.printStackTrace();
}
}
@RequestMapping(value = "/deleteExcel")//导入成功后删除Excel,压缩包等垃圾文件
public String deleteExcel(String pathName) {
//System.out.println(pathName);
File file = new File(pathName);
file.delete();
File backfile = new File(unPackExcelPach);
File[] files = backfile.listFiles();
//if(files !=null){ //此方法判断错误。
if(files !=null && files.length > 0){ //此方法判断ok,需要使用数组的长度来判断文件夹是否为空。
FileUtils.delAllFile(unPackExcelPach);
}
return "ok";
}
@PostMapping("/importExcel")
@ResponseBody
public String importExcel(@RequestParam("fileExcel") MultipartFile fileExcel,
@RequestParam("goodsName") String goodsName,HttpSession session){
Integer uid = (Integer) session.getAttribute("uid");
Integer cid = (Integer) session.getAttribute("cid");
Integer fwid = (Integer) session.getAttribute("fwid");
//return "error";
//System.out.println("文件类型是:::::"+fileExcel.getContentType());
if(!fileExcel.isEmpty()){
InputStream in = null;
String fileName = null;
try {
in = fileExcel.getInputStream();
fileName = fileExcel.getOriginalFilename();
//根据名字截取到时间 2019年8月1日
System.out.println(fileName+"========EXCELNAME"+fileExcel.getName());
iGoodsService.importExcel(fileName,in,goodsName,cid,uid,fwid);
return "ok";
}catch (Exception e){
e.printStackTrace();
return "error";
}
}else{
return "error";
}
}
/**
* 压缩包自动解压并将解压的Excel文件导入数据库
* */
@PostMapping("/importPack")
@ResponseBody
public String packageExcel(@RequestParam("filePackage") MultipartFile filePackage,
@RequestParam("goodsName") String goodsName,HttpSession session) throws IOException {
if(filePackage == null)
return "error0";
boolean b = fileUploadService.packSave(filePackage);//上传压缩包文件到服务器指定的文件夹下
String packname = filePackage.getOriginalFilename();
String filepath = null;
File file = null;
if(b){
filepath = packPath + packname;//获取压缩包全路径
file = new File(filepath);//获取压缩包文件
boolean b1 = fileUploadService.jieYa(file);//解压
if(b1) {
List<File> fileSort = FileUtils.getFileSort(unPackExcelPach);//序列化文件
File fileD = null;
MultipartFile fileExcel = null;
FileItem fileItem = null;
for(int i=0;i<fileSort.size();i++){
fileD = fileSort.get(i);//获取单个文件
fileItem = FileUtils.createFileItem(fileD,"ss"+i);//把文件转化为FileItem类型
fileExcel = new CommonsMultipartFile(fileItem);//把FileItem转化为MultipartFile类型
excelController.importExcel(fileExcel,goodsName,session);//循环调用兄弟方法去导入Excel
}
return "ok"+filepath;
}
else
return "error2";
}else
return "error1";
}
}
我们开发组人少,给点钱不多,招了个感觉上不错的 能完成就是代码太生了... 我平时还干别的.气死 之前的其实我也没怎么弄过, 不过我用的js导出
service在这:
package com.tansuo365.test1.service.goods;
import com.tansuo365.test1.bean.goods.*;
import com.tansuo365.test1.bean.goods.aluminium.Al2O3;
import com.tansuo365.test1.bean.goods.aluminium.Monohydrallite;
import com.tansuo365.test1.bean.goods.aluminium.RegionAlPig;
import com.tansuo365.test1.bean.goods.aluminium.VarAlPig;
import com.tansuo365.test1.bean.goods.inout.*;
import com.tansuo365.test1.bean.goods.stoke.*;
import com.tansuo365.test1.bean.goods.storage.*;
import com.tansuo365.test1.entity.server.Sys;
import com.tansuo365.test1.mapper.goods.*;
import com.tansuo365.test1.mapper.goods.aluminium.Al2O3Mapper;
import com.tansuo365.test1.mapper.goods.aluminium.MonohydralliteMapper;
import com.tansuo365.test1.mapper.goods.aluminium.RegionAlPigMapper;
import com.tansuo365.test1.mapper.goods.aluminium.VarAlPigMapper;
import com.tansuo365.test1.mapper.goods.inout.*;
import com.tansuo365.test1.mapper.goods.stoke.*;
import com.tansuo365.test1.mapper.goods.storage.*;
import com.tansuo365.test1.util.ExcelUtil;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.PropertySource;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.servlet.http.HttpSession;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
@Service
@PropertySource(value="classpath:goods.properties")
public class GoodsServiceImpl implements IGoodsService {
@Value("${goods.anode.keyValue}")
String anode;
@Value("${goods.asphalt.keyValue}")
String asphalt;
@Value("${goods.calcined.keyValue}")
String calcined;
@Value("${goods.coke.keyValue}")
String coke;
@Value("${goods.cathode.keyValue}")
String cathode;
@Value("${goods.storage.keyValue}")
String storage;
@Value("${goods.aluminium.keyValue}")
String aluminium;
@Value("${goods.region_al.keyValue}")
String region_al;
@Value("${goods.var_al.keyValue}")
String var_al;
@Value("${goods.types.nation}")
String shiduan; //按国分有型号有进口:石油焦,锻后焦
@Value("${goods.notypes.nation}")
String notypes; //#按国分无型号有进口:煤沥青,电解铝,铝土矿,氧化铝
@Value("${goods.noInType.nation}")
String noinTypes; //#按国分无进口无型号:阳极,阴极
@Value("${goods.haveIn.monthlys}")
String haveInMon; //#按月份有进口:石油焦,锻后焦,煤沥青,电解铝,铝土矿,氧化铝
@Value("${goods.noIn.monthlys}")
String noInMon; //#按月份无进口:阳极,阴极,
@Value("${goods.stokes}")
String stoke;//铝土矿,氧化铝,电解铝 等库存信息
@Value("${goods.al.capacity}")
String capacity;//氧化铝,电解铝 产能
@Value("${goods.al.yields}")
String yield;//氧化铝,电解铝 产量
// "地区:region,省份:province,企业名称:company,规格尺寸:size,体积密度(g/cm3):e_density,耐压强度(Mpa):compressive," +
// "电阻率():room,灰分(%):ash,硫分(%):sulfur,残极率(%):canji,热膨胀系数(%):thermal,抗折强度(Mpa):flexural,真密度(g/cm3):true_density,当日报价:today_price," +
// "备注:remarks,上传人:reporter"
@Autowired
AnodeMapper anodeMapper;
@Autowired
MAsphaltMapper mAsphaltMapper;
@Autowired
CalcinedCokeMapper calcinedCokeMapper;
@Autowired
PetroleumCokeMapper petroleumCokeMapper;
@Autowired
CathodeMapper cathodeMapper;
@Autowired
Al2O3Mapper al2O3Mapper;
@Autowired
MonohydralliteMapper monohydralliteMapper;
@Autowired
RegionAlPigMapper regionAlPigMapper;
@Autowired
VarAlPigMapper varAlPigMapper;
@Autowired
AnodeStorageMapper anodeStorageMapper;
@Autowired
CalcinedStorageMapper calcinedStorageMapper;
@Autowired
CathodeStorageMapper cathodeStorageMapper;
@Autowired
MAsphaltStorageMapper mAsphaltStorageMapper;
@Autowired
PetroleumStorageMapper petroleumStorageMapper;
@Autowired
InoutAl2O3Mapper inoutAl2O3Mapper;
@Autowired
InoutAl2O3MonMapper inoutAl2O3MonMapper;
@Autowired
InoutAnodeMapper inoutAnodeMapper;
@Autowired
InoutAnodeMonMapper inoutAnodeMonMapper;
@Autowired
InoutCalcinedCokeMapper inoutCalcinedCokeMapper;
@Autowired
InoutCalcinedCokeMonMapper inoutCalcinedCokeMonMapper;
@Autowired
InoutCathodeMapper inoutCathodeMapper;
@Autowired
InoutCathodeMonMapper inoutCathodeMonMapper;
@Autowired
InoutEleAlMapper inoutEleAlMapper;
@Autowired
InoutEleAlMonMapper inoutEleAlMonMapper;
@Autowired
InoutMasphaltMapper inoutMasphaltMapper;
@Autowired
InoutMasphaltMonMapper inoutMasphaltMonMapper;
@Autowired
InoutMonohydralliteMapper inoutMonohydralliteMapper;
@Autowired
InoutMonohydralliteMonMapper inoutMonohydralliteMonMapper;
@Autowired
InoutPetroCokeMapper inoutPetroCokeMapper;
@Autowired
InoutPetroCokeMonMapper inoutPetroCokeMonMapper;
@Autowired
StokeAl2O3Mapper stokeAl2O3Mapper;
@Autowired
StokeEleAlMapper stokeEleAlMapper;
@Autowired
StokeMonohydralliteMapper stokeMonohydralliteMapper;
@Autowired
Al2O3CapacityMapper al2O3CapacityMapper;
@Autowired
Al2O3YieldMapper al2O3YieldMapper;
@Autowired
EleCapacityMapper eleCapacityMapper;
@Autowired
EleYieldMapper eleYieldMapper;
@Override
public void exportExcel(Long[] ids, OutputStream out,String goodsName,String theTitle) {
String classPaths = "";
String keyValue = "";
List list=null;
if(goodsName.equals("anode")){
keyValue = anode;
classPaths = "com.tansuo365.test1.bean.goods.Anode";
list = new ArrayList<Anode>();
for (int i = 0; i < ids.length; i++) {
Anode anode = (Anode) anodeMapper.findOne(ids[i]);
list.add(anode);
}
}else if(goodsName.equals("asphalt")){
keyValue = asphalt;
classPaths = "com.tansuo365.test1.bean.goods.MAsphalt";
list = new ArrayList<MAsphalt>();
for (int i = 0; i < ids.length; i++) {
MAsphalt asphalt = (MAsphalt) mAsphaltMapper.findOne(ids[i]);
list.add(asphalt);
}
}else if(goodsName.equals("calcined")){
keyValue = calcined;
classPaths = "com.tansuo365.test1.bean.goods.CalcinedCoke";
list = new ArrayList<CalcinedCoke>();
for (int i = 0; i < ids.length; i++) {
CalcinedCoke calcined = (CalcinedCoke) calcinedCokeMapper.findOne(ids[i]);
list.add(calcined);
}
}else if(goodsName.equals("coke")){
keyValue = coke;
classPaths = "com.tansuo365.test1.bean.goods.PetroleumCoke";
list = new ArrayList<PetroleumCoke>();
for (int i = 0; i < ids.length; i++) {
PetroleumCoke coke = (PetroleumCoke) petroleumCokeMapper.findOne(ids[i]);
list.add(coke);
}
}else if(goodsName.equals("cathode")){
keyValue = cathode;
classPaths = "com.tansuo365.test1.bean.goods.Cathode";
list = new ArrayList<Cathode>();
for (int i = 0; i < ids.length; i++) {
Cathode cathode = (Cathode) cathodeMapper.findOne(ids[i]);
list.add(cathode);
}
}else if(goodsName.equals("al2O3")){
keyValue = aluminium;
classPaths = "com.tansuo365.test1.bean.goods.aluminium.Al2O3";
list = new ArrayList<Al2O3>();
for (int i = 0; i < ids.length; i++) {
Al2O3 al2O3 = (Al2O3) al2O3Mapper.findOne(ids[i]);
//System.out.println(al2O3.toString());
list.add(al2O3);
}
}else if(goodsName.equals("monohydrallite")){
keyValue = aluminium;
classPaths = "com.tansuo365.test1.bean.goods.aluminium.Monohydrallite";
list = new ArrayList<Monohydrallite>();
for (int i = 0; i < ids.length; i++) {
Monohydrallite monohydrallite = (Monohydrallite) monohydralliteMapper.findOne(ids[i]);
list.add(monohydrallite);
}
}else if(goodsName.equals("regionAlPig")){
keyValue = region_al;
classPaths = "com.tansuo365.test1.bean.goods.aluminium.RegionAlPig";
list = new ArrayList<RegionAlPig>();
for (int i = 0; i < ids.length; i++) {
RegionAlPig regionAlPig = (RegionAlPig) regionAlPigMapper.findOne(ids[i]);
list.add(regionAlPig);
}
}else if(goodsName.equals("varAlPig")){
keyValue = var_al;
classPaths = "com.tansuo365.test1.bean.goods.aluminium.VarAlPig";
list = new ArrayList<VarAlPig>();
for (int i = 0; i < ids.length; i++) {
VarAlPig varAlPig = (VarAlPig) varAlPigMapper.findOne(ids[i]);
list.add(varAlPig);
}
}else if(goodsName.equals("anodeStorage")){
keyValue = storage;
classPaths = "com.tansuo365.test1.bean.goods.storage.AnodeStorage";
list = new ArrayList<AnodeStorage>();
for (int i = 0; i < ids.length; i++) {
AnodeStorage anodeStorage = (AnodeStorage) anodeStorageMapper.findOne(ids[i]);
list.add(anodeStorage);
}
}else if(goodsName.equals("calcinedStorage")){
keyValue = storage;
classPaths = "com.tansuo365.test1.bean.goods.storage.CalcinedStorage";
list = new ArrayList<CalcinedStorage>();
for (int i = 0; i < ids.length; i++) {
CalcinedStorage calcinedStorage = (CalcinedStorage) calcinedStorageMapper.findOne(ids[i]);
list.add(calcinedStorage);
}
}else if(goodsName.equals("cathodeStorage")){
keyValue = storage;
classPaths = "com.tansuo365.test1.bean.goods.storage.CathodeStorage";
list = new ArrayList<CathodeStorage>();
for (int i = 0; i < ids.length; i++) {
CathodeStorage cathodeStorage = (CathodeStorage) cathodeStorageMapper.findOne(ids[i]);
list.add(cathodeStorage);
}
}else if(goodsName.equals("mAsphaltStorage")){
keyValue = storage;
classPaths = "com.tansuo365.test1.bean.goods.storage.MAsphaltStorage";
list = new ArrayList<MAsphaltStorage>();
for (int i = 0; i < ids.length; i++) {
MAsphaltStorage mAsphaltStorage = (MAsphaltStorage) mAsphaltStorageMapper.findOne(ids[i]);
list.add(mAsphaltStorage);
}
}else if(goodsName.equals("petroleumStorage")){
keyValue = storage;
classPaths = "com.tansuo365.test1.bean.goods.storage.PetroleumStorage";
list = new ArrayList<PetroleumStorage>();
for (int i = 0; i < ids.length; i++) {
PetroleumStorage petroleumStorage = (PetroleumStorage) petroleumStorageMapper.findOne(ids[i]);
list.add(petroleumStorage);
}
}
else if(goodsName.equals("inoutAl2O3")){
keyValue = notypes;
classPaths = "com.tansuo365.test1.bean.goods.inout.InoutAl2O3";
list = new ArrayList<InoutAl2O3>();
for (int i = 0; i < ids.length; i++) {
InoutAl2O3 inoutAl2O3 = (InoutAl2O3) inoutAl2O3Mapper.findOne(ids[i]);
list.add(inoutAl2O3);
}
}
else if(goodsName.equals("inoutAl2O3Mon")){
keyValue = haveInMon;
classPaths = "com.tansuo365.test1.bean.goods.inout.InoutAl2O3Mon";
list = new ArrayList<InoutAl2O3Mon>();
for (int i = 0; i < ids.length; i++) {
InoutAl2O3Mon inoutAl2O3Mon = (InoutAl2O3Mon) inoutAl2O3MonMapper.selectByPrimaryKey(ids[i]);
list.add(inoutAl2O3Mon);
}
}
else if(goodsName.equals("inoutAnode")){
keyValue = noinTypes;
classPaths = "com.tansuo365.test1.bean.goods.inout.InoutAnode";
list = new ArrayList<InoutAnode>();
for (int i = 0; i < ids.length; i++) {
InoutAnode inoutAnode = (InoutAnode) inoutAnodeMapper.selectByPrimaryKey(ids[i]);
list.add(inoutAnode);
}
}
else if(goodsName.equals("inoutAnodeMon")){
keyValue = noInMon;
classPaths = "com.tansuo365.test1.bean.goods.inout.InoutAnodeMon";
list = new ArrayList<InoutAnodeMon>();
for (int i = 0; i < ids.length; i++) {
InoutAnodeMon inoutAnodeMon = (InoutAnodeMon) inoutAnodeMonMapper.selectByPrimaryKey(ids[i]);
list.add(inoutAnodeMon);
}
}
else if(goodsName.equals("inoutCalcinedCoke")){
keyValue = shiduan;
classPaths = "com.tansuo365.test1.bean.goods.inout.InoutCalcinedCoke";
list = new ArrayList<InoutCalcinedCoke>();
for (int i = 0; i < ids.length; i++) {
InoutCalcinedCoke inoutCalcinedCoke = (InoutCalcinedCoke) inoutCalcinedCokeMapper.selectByPrimaryKey(ids[i]);
list.add(inoutCalcinedCoke);
}
}
else if(goodsName.equals("inoutCalcinedCokeMon")){
keyValue = haveInMon;
classPaths = "com.tansuo365.test1.bean.goods.inout.InoutCalcinedCokeMon";
list = new ArrayList<InoutCalcinedCokeMon>();
for (int i = 0; i < ids.length; i++) {
InoutCalcinedCokeMon inoutCalcinedCokeMon = (InoutCalcinedCokeMon) inoutCalcinedCokeMonMapper.selectByPrimaryKey(ids[i]);
list.add(inoutCalcinedCokeMon);
}
}
else if(goodsName.equals("inoutCathode")){
keyValue = noinTypes;
classPaths = "com.tansuo365.test1.bean.goods.inout.InoutCathode";
list = new ArrayList<InoutCathode>();
for (int i = 0; i < ids.length; i++) {
InoutCathode inoutCathode = (InoutCathode) inoutCathodeMapper.selectByPrimaryKey(ids[i]);
list.add(inoutCathode);
}
}
else if(goodsName.equals("inoutCathodeMon")){
keyValue = noInMon;
classPaths = "com.tansuo365.test1.bean.goods.inout.InoutCathodeMon";
list = new ArrayList<InoutCathodeMon>();
for (int i = 0; i < ids.length; i++) {
InoutCathodeMon inoutCathodeMon = (InoutCathodeMon) inoutCathodeMonMapper.selectByPrimaryKey(ids[i]);
list.add(inoutCathodeMon);
}
}
else if(goodsName.equals("inoutEleAl")){
keyValue = notypes;
classPaths = "com.tansuo365.test1.bean.goods.inout.InoutEleAl";
list = new ArrayList<InoutEleAl>();
for (int i = 0; i < ids.length; i++) {
InoutEleAl inoutEleAl = (InoutEleAl) inoutEleAlMapper.selectByPrimaryKey(ids[i]);
list.add(inoutEleAl);
}
}
else if(goodsName.equals("inoutEleAlMon")){
keyValue = haveInMon;
classPaths = "com.tansuo365.test1.bean.goods.inout.InoutEleAlMon";
list = new ArrayList<InoutEleAlMon>();
for (int i = 0; i < ids.length; i++) {
InoutEleAlMon inoutEleAlMon = (InoutEleAlMon) inoutEleAlMonMapper.selectByPrimaryKey(ids[i]);
list.add(inoutEleAlMon);
}
}
else if(goodsName.equals("inoutMasphalt")){
keyValue = notypes;
classPaths = "com.tansuo365.test1.bean.goods.inout.InoutMasphalt";
list = new ArrayList<InoutMasphalt>();
for (int i = 0; i < ids.length; i++) {
InoutMasphalt inoutMasphalt = (InoutMasphalt) inoutMasphaltMapper.selectByPrimaryKey(ids[i]);
list.add(inoutMasphalt);
}
}
else if(goodsName.equals("inoutMasphaltMon")){
keyValue = haveInMon;
classPaths = "com.tansuo365.test1.bean.goods.inout.InoutMasphaltMon";
list = new ArrayList<InoutMasphaltMon>();
for (int i = 0; i < ids.length; i++) {
InoutMasphaltMon inoutMasphaltMon = (InoutMasphaltMon) inoutMasphaltMonMapper.selectByPrimaryKey(ids[i]);
list.add(inoutMasphaltMon);
}
}
else if(goodsName.equals("inoutMonohydrallite")){
keyValue = notypes;
classPaths = "com.tansuo365.test1.bean.goods.inout.InoutMonohydrallite";
list = new ArrayList<InoutMonohydrallite>();
for (int i = 0; i < ids.length; i++) {
InoutMonohydrallite inoutMonohydrallite = (InoutMonohydrallite) inoutMonohydralliteMapper.selectByPrimaryKey(ids[i]);
list.add(inoutMonohydrallite);
}
}
else if(goodsName.equals("inoutMonohydralliteMon")){
keyValue = haveInMon;
classPaths = "com.tansuo365.test1.bean.goods.inout.InoutMonohydralliteMon";
list = new ArrayList<InoutMonohydralliteMon>();
for (int i = 0; i < ids.length; i++) {
InoutMonohydralliteMon inoutMonohydralliteMon = (InoutMonohydralliteMon) inoutMonohydralliteMonMapper.selectByPrimaryKey(ids[i]);
list.add(inoutMonohydralliteMon);
}
}
else if(goodsName.equals("inoutPetroCoke")){
keyValue = shiduan;
classPaths = "com.tansuo365.test1.bean.goods.inout.InoutPetroCoke";
list = new ArrayList<InoutPetroCoke>();
for (int i = 0; i < ids.length; i++) {
InoutPetroCoke inoutPetroCoke = (InoutPetroCoke) inoutPetroCokeMapper.selectByPrimaryKey(ids[i]);
list.add(inoutPetroCoke);
}
}
else if(goodsName.equals("inoutPetroCokeMon")){
keyValue = haveInMon;
classPaths = "com.tansuo365.test1.bean.goods.inout.InoutPetroCokeMon";
list = new ArrayList<InoutPetroCokeMon>();
for (int i = 0; i < ids.length; i++) {
InoutPetroCokeMon inoutPetroCokeMon = (InoutPetroCokeMon) inoutPetroCokeMonMapper.selectByPrimaryKey(ids[i]);
list.add(inoutPetroCokeMon);
}
}
else if(goodsName.equals("stokeAl2O3")){
keyValue = stoke;
classPaths = "com.tansuo365.test1.bean.goods.stoke.StokeAl2O3";
list = new ArrayList<StokeAl2O3>();
for (int i = 0; i < ids.length; i++) {
StokeAl2O3 stokeAl2O3 = (StokeAl2O3) stokeAl2O3Mapper.selectByPrimaryKey(ids[i]);
list.add(stokeAl2O3);
}
}
else if(goodsName.equals("stokeEleAl")){
keyValue = stoke;
classPaths = "com.tansuo365.test1.bean.goods.stoke.StokeEleAl";
list = new ArrayList<StokeEleAl>();
for (int i = 0; i < ids.length; i++) {
StokeEleAl stokeEleAl = (StokeEleAl) stokeEleAlMapper.selectByPrimaryKey(ids[i]);
list.add(stokeEleAl);
}
}
else if(goodsName.equals("stokeMonohydrallite")){
keyValue = stoke;
classPaths = "com.tansuo365.test1.bean.goods.stoke.StokeMonohydrallite";
list = new ArrayList<StokeMonohydrallite>();
for (int i = 0; i < ids.length; i++) {
StokeMonohydrallite stokeMonohydrallite = (StokeMonohydrallite) stokeMonohydralliteMapper.selectByPrimaryKey(ids[i]);
list.add(stokeMonohydrallite);
}
}else if(goodsName.equals("al2O3Capacity")){
keyValue = capacity;
classPaths = "com.tansuo365.test1.bean.goods.stoke.Al2O3Capacity";
list = new ArrayList<Al2O3Capacity>();
for (int i = 0; i < ids.length; i++) {
Al2O3Capacity al2O3Capacity = (Al2O3Capacity) al2O3CapacityMapper.selectByPrimaryKey(ids[i]);
list.add(al2O3Capacity);
}
}
else if(goodsName.equals("eleCapacity")){
keyValue = capacity;
classPaths = "com.tansuo365.test1.bean.goods.stoke.EleCapacity";
list = new ArrayList<EleCapacity>();
for (int i = 0; i < ids.length; i++) {
EleCapacity eleCapacity = (EleCapacity) eleCapacityMapper.selectByPrimaryKey(ids[i]);
list.add(eleCapacity);
}
}else if(goodsName.equals("al2O3Yield")){
keyValue = yield;
classPaths = "com.tansuo365.test1.bean.goods.stoke.Al2O3Yield";
list = new ArrayList<Al2O3Yield>();
for (int i = 0; i < ids.length; i++) {
Al2O3Yield al2O3Yield = (Al2O3Yield) al2O3YieldMapper.selectByPrimaryKey(ids[i]);
list.add(al2O3Yield);
}
}
else if(goodsName.equals("eleYield")){
keyValue = yield;
classPaths = "com.tansuo365.test1.bean.goods.stoke.EleYield";
list = new ArrayList<EleYield>();
for (int i = 0; i < ids.length; i++) {
EleYield eleYield = (EleYield) eleYieldMapper.selectByPrimaryKey(ids[i]);
list.add(eleYield);
}
}
else{
System.out.println("ERROR=====================");
return;
}
System.out.println(ids.length);
try {
ExcelUtil.exportExcel(theTitle, out, ExcelUtil.getMap(keyValue),list ,
classPaths, null, null, null);
System.out.println("导出成功");
} catch (Exception e) {
System.out.println("导出失败");
e.printStackTrace();
}
}
// @Override
// public void importExcel(String fileName, InputStream in, String goodsName) {
//
//
// }
@Override
@Transactional
public void importExcel(String fileName, InputStream in, String goodsName,Integer cid,Integer uid,Integer fwid) throws Exception {
String classPaths = "";
String keyValue = "";
List list = null;
System.out.println(uid+"session打印=============="+fwid+"======================"+cid);
if(goodsName.equals("anode")){
keyValue = anode;
classPaths = "com.tansuo365.test1.bean.goods.Anode2";
//list = new ArrayList<Anode>();
list = ExcelUtil.readExcel(fileName,in,ExcelUtil.getMap(keyValue),classPaths,2);
anodeMapper.insertBatch(list,cid,uid,fwid);
}else if(goodsName.equals("asphalt")){
keyValue = asphalt;
classPaths = "com.tansuo365.test1.bean.goods.MAsphalt2";
//list = new ArrayList<MAsphalt>();
list = ExcelUtil.readExcel(fileName,in,ExcelUtil.getMap(keyValue),classPaths,2);
mAsphaltMapper.insertBatch(list,cid,uid,fwid);
}else if(goodsName.equals("calcined")){
keyValue = calcined;
classPaths = "com.tansuo365.test1.bean.goods.CalcinedCoke2";
//list = new ArrayList<CalcinedCoke>();
list = ExcelUtil.readExcel(fileName,in,ExcelUtil.getMap(keyValue),classPaths,2);
calcinedCokeMapper.insertBatch(list,cid,uid,fwid);
}else if(goodsName.equals("coke")){
keyValue = coke;
classPaths = "com.tansuo365.test1.bean.goods.PetroleumCoke2";
//list = new ArrayList<PetroleumCoke>();
list = ExcelUtil.readExcel(fileName,in,ExcelUtil.getMap(keyValue),classPaths,2);
petroleumCokeMapper.insertBatch(list,cid,uid,fwid);
} else if(goodsName.equals("cathode")){
keyValue = cathode;
classPaths = "com.tansuo365.test1.bean.goods.Cathode2";
//list = new ArrayList<Cathode>();
list = ExcelUtil.readExcel(fileName,in,ExcelUtil.getMap(keyValue),classPaths,2);
cathodeMapper.insertBatch(list,cid,uid,fwid);
}else if(goodsName.equals("al2O3")){
keyValue = aluminium;
classPaths = "com.tansuo365.test1.bean.goods.aluminium.Al2O3_2";
//list = new ArrayList<Al2O3>();
list = ExcelUtil.readExcel(fileName,in,ExcelUtil.getMap(keyValue),classPaths,2);
System.out.println(list.size()+" "+list.get(1).toString());
al2O3Mapper.insertBatch(list,cid,uid,fwid);
}else if(goodsName.equals("monohydrallite")){
keyValue = aluminium;
classPaths = "com.tansuo365.test1.bean.goods.aluminium.Monohydrallite2";
//list = new ArrayList<Monohydrallite>();
list = ExcelUtil.readExcel(fileName,in,ExcelUtil.getMap(keyValue),classPaths,2);
monohydralliteMapper.insertBatch(list,cid,uid,fwid);
}else if(goodsName.equals("regionAlPig")){
keyValue = region_al;
classPaths = "com.tansuo365.test1.bean.goods.aluminium.RegionAlPig2";
//list = new ArrayList<RegionAlPig>();
list = ExcelUtil.readExcel(fileName,in,ExcelUtil.getMap(keyValue),classPaths,2);
regionAlPigMapper.insertBatch(list,cid,uid,fwid);
}else if(goodsName.equals("varAlPig")){
keyValue = var_al;
classPaths = "com.tansuo365.test1.bean.goods.aluminium.VarAlPig2";
//list = new ArrayList<VarAlPig>();
list = ExcelUtil.readExcel(fileName,in,ExcelUtil.getMap(keyValue),classPaths,2);
varAlPigMapper.insertBatch(list,cid,uid,fwid);
}else if(goodsName.equals("anodeStorage")){
keyValue = storage;
classPaths = "com.tansuo365.test1.bean.goods.storage.AnodeStorage2";
//list = new ArrayList<AnodeStorage>();
list = ExcelUtil.readExcel(fileName,in,ExcelUtil.getMap(keyValue),classPaths,2);
anodeStorageMapper.insertBatch(list,cid,uid,fwid);
}else if(goodsName.equals("calcinedStorage")){
keyValue = storage;
classPaths = "com.tansuo365.test1.bean.goods.storage.CalcinedStorage2";
//list = new ArrayList<CalcinedStorage>();
list = ExcelUtil.readExcel(fileName,in,ExcelUtil.getMap(keyValue),classPaths,2);
System.out.println(list.size()+" "+list.get(1).toString());
calcinedStorageMapper.insertBatch(list,cid,uid,fwid);
}else if(goodsName.equals("cathodeStorage")){
keyValue = storage;
classPaths = "com.tansuo365.test1.bean.goods.storage.CathodeStorage2";
//list = new ArrayList<CathodeStorage>();
list = ExcelUtil.readExcel(fileName,in,ExcelUtil.getMap(keyValue),classPaths,2);
cathodeStorageMapper.insertBatch(list,cid,uid,fwid);
}else if(goodsName.equals("mAsphaltStorage")){
keyValue = storage;
classPaths = "com.tansuo365.test1.bean.goods.storage.MAsphaltStorage2";
list = new ArrayList<MAsphaltStorage>();
list = ExcelUtil.readExcel(fileName,in,ExcelUtil.getMap(keyValue),classPaths,2);
mAsphaltStorageMapper.insertBatch(list,cid,uid,fwid);
}else if(goodsName.equals("petroleumStorage")){
keyValue = storage;
classPaths = "com.tansuo365.test1.bean.goods.storage.PetroleumStorage2";
//list = new ArrayList<PetroleumStorage>();
list = ExcelUtil.readExcel(fileName,in,ExcelUtil.getMap(keyValue),classPaths,2);
petroleumStorageMapper.insertBatch(list,cid,uid,fwid);
}
else if(goodsName.equals("inoutAl2O3")){
keyValue = notypes;
classPaths = "com.tansuo365.test1.bean.goods.inout.InoutAl2O3";
//list = new ArrayList<InoutAl2O3>();
list = ExcelUtil.readExcel(fileName,in,ExcelUtil.getMap(keyValue),classPaths,2);
inoutAl2O3Mapper.insertBatch(list,cid,uid,fwid);
}else if(goodsName.equals("inoutAl2O3Mon")){
keyValue = haveInMon;
classPaths = "com.tansuo365.test1.bean.goods.inout.InoutAl2O3Mon";
//list = new ArrayList<InoutAl2O3Mon>();
list = ExcelUtil.readExcel(fileName,in,ExcelUtil.getMap(keyValue),classPaths,2);
inoutAl2O3MonMapper.insertBatch(list,cid,uid,fwid);
}else if(goodsName.equals("inoutAnode")){
keyValue = noinTypes;
classPaths = "com.tansuo365.test1.bean.goods.inout.InoutAnode";
//list = new ArrayList<PetroleumCoke>();
list = ExcelUtil.readExcel(fileName,in,ExcelUtil.getMap(keyValue),classPaths,2);
inoutAnodeMapper.insertBatch(list,cid,uid,fwid);
} else if(goodsName.equals("inoutAnodeMon")){
keyValue = noInMon;
classPaths = "com.tansuo365.test1.bean.goods.inout.InoutAnodeMon";
//list = new ArrayList<Cathode>();
list = ExcelUtil.readExcel(fileName,in,ExcelUtil.getMap(keyValue),classPaths,2);
inoutAnodeMonMapper.insertBatch(list,cid,uid,fwid);
}else if(goodsName.equals("inoutCalcinedCoke")){
keyValue = shiduan;
classPaths = "com.tansuo365.test1.bean.goods.inout.InoutCalcinedCoke";
//list = new ArrayList<Al2O3>();
list = ExcelUtil.readExcel(fileName,in,ExcelUtil.getMap(keyValue),classPaths,2);
//System.out.println(list.size()+" "+list.get(1).toString());
inoutCalcinedCokeMapper.insertBatch(list,cid,uid,fwid);
}else if(goodsName.equals("inoutCalcinedCokeMon")){
keyValue = haveInMon;
classPaths = "com.tansuo365.test1.bean.goods.inout.InoutCalcinedCokeMon";
//list = new ArrayList<Monohydrallite>();
list = ExcelUtil.readExcel(fileName,in,ExcelUtil.getMap(keyValue),classPaths,2);
inoutCalcinedCokeMonMapper.insertBatch(list,cid,uid,fwid);
}else if(goodsName.equals("inoutCathode")){
keyValue = noinTypes;
classPaths = "com.tansuo365.test1.bean.goods.inout.InoutCathode";
//list = new ArrayList<RegionAlPig>();
list = ExcelUtil.readExcel(fileName,in,ExcelUtil.getMap(keyValue),classPaths,2);
inoutCathodeMapper.insertBatch(list,cid,uid,fwid);
}else if(goodsName.equals("inoutCathodeMon")){
keyValue = noInMon;
classPaths = "com.tansuo365.test1.bean.goods.inout.InoutCathodeMon";
//list = new ArrayList<VarAlPig>();
list = ExcelUtil.readExcel(fileName,in,ExcelUtil.getMap(keyValue),classPaths,2);
inoutCathodeMonMapper.insertBatch(list,cid,uid,fwid);
}else if(goodsName.equals("inoutEleAl")){
keyValue = notypes;
classPaths = "com.tansuo365.test1.bean.goods.inout.InoutEleAl";
//list = new ArrayList<AnodeStorage>();
list = ExcelUtil.readExcel(fileName,in,ExcelUtil.getMap(keyValue),classPaths,2);
inoutEleAlMapper.insertBatch(list,cid,uid,fwid);
}else if(goodsName.equals("inoutEleAlMon")){
keyValue = haveInMon;
classPaths = "com.tansuo365.test1.bean.goods.inout.InoutEleAlMon";
//list = new ArrayList<CalcinedStorage>();
list = ExcelUtil.readExcel(fileName,in,ExcelUtil.getMap(keyValue),classPaths,2);
System.out.println(list.size()+" "+list.get(1).toString());
inoutEleAlMonMapper.insertBatch(list,cid,uid,fwid);
}else if(goodsName.equals("inoutMasphalt")){
keyValue = notypes;
classPaths = "com.tansuo365.test1.bean.goods.inout.inoutMasphalt";
//list = new ArrayList<CathodeStorage>();
list = ExcelUtil.readExcel(fileName,in,ExcelUtil.getMap(keyValue),classPaths,2);
inoutMasphaltMapper.insertBatch(list,cid,uid,fwid);
}else if(goodsName.equals("inoutMasphaltMon")){
keyValue = haveInMon;
classPaths = "com.tansuo365.test1.bean.goods.inout.InoutMasphaltMon";
//list = new ArrayList<MAsphaltStorage>();
list = ExcelUtil.readExcel(fileName,in,ExcelUtil.getMap(keyValue),classPaths,2);
inoutMasphaltMonMapper.insertBatch(list,cid,uid,fwid);
}else if(goodsName.equals("inoutMonohydrallite")){
keyValue = notypes;
classPaths = "com.tansuo365.test1.bean.goods.inout.InoutMonohydrallite";
//list = new ArrayList<PetroleumStorage>();
list = ExcelUtil.readExcel(fileName,in,ExcelUtil.getMap(keyValue),classPaths,2);
inoutMonohydralliteMapper.insertBatch(list,cid,uid,fwid);
}
else if(goodsName.equals("inoutMonohydralliteMon")){
keyValue = haveInMon;
classPaths = "com.tansuo365.test1.bean.goods.inout.InoutMonohydralliteMon";
//list = new ArrayList<PetroleumStorage>();
list = ExcelUtil.readExcel(fileName,in,ExcelUtil.getMap(keyValue),classPaths,2);
inoutMonohydralliteMonMapper.insertBatch(list,cid,uid,fwid);
}else if(goodsName.equals("inoutPetroCoke")){
keyValue = shiduan;
classPaths = "com.tansuo365.test1.bean.goods.inout.InoutPetroCoke";
//list = new ArrayList<PetroleumStorage>();
list = ExcelUtil.readExcel(fileName,in,ExcelUtil.getMap(keyValue),classPaths,2);
inoutPetroCokeMapper.insertBatch(list,cid,uid,fwid);
}else if(goodsName.equals("inoutPetroCokeMon")){
keyValue = haveInMon;
classPaths = "com.tansuo365.test1.bean.goods.inout.InoutPetroCokeMon";
//list = new ArrayList<PetroleumStorage>();
list = ExcelUtil.readExcel(fileName,in,ExcelUtil.getMap(keyValue),classPaths,2);
inoutPetroCokeMonMapper.insertBatch(list,cid,uid,fwid);
}
else if(goodsName.equals("stokeAl2O3")){
keyValue = stoke;
classPaths = "com.tansuo365.test1.bean.goods.stoke.StokeAl2O3";
//list = new ArrayList<PetroleumStorage>();
list = ExcelUtil.readExcel(fileName,in,ExcelUtil.getMap(keyValue),classPaths,2);
stokeAl2O3Mapper.insertBatch(list,cid,uid,fwid);
}else if(goodsName.equals("stokeEleAl")){
keyValue = stoke;
classPaths = "com.tansuo365.test1.bean.goods.stoke.StokeEleAl";
//list = new ArrayList<PetroleumStorage>();
list = ExcelUtil.readExcel(fileName,in,ExcelUtil.getMap(keyValue),classPaths,2);
stokeEleAlMapper.insertBatch(list,cid,uid,fwid);
}else if(goodsName.equals("stokeMonohydrallite")){
keyValue = stoke;
classPaths = "com.tansuo365.test1.bean.goods.stoke.StokeMonohydrallite";
//list = new ArrayList<PetroleumStorage>();
list = ExcelUtil.readExcel(fileName,in,ExcelUtil.getMap(keyValue),classPaths,2);
stokeMonohydralliteMapper.insertBatch(list,cid,uid,fwid);
}
else if(goodsName.equals("al2O3Capacity")){
keyValue = capacity;
classPaths = "com.tansuo365.test1.bean.goods.stoke.Al2O3Capacity2";
list = ExcelUtil.readExcel(fileName,in,ExcelUtil.getMap(keyValue),classPaths,2);
al2O3CapacityMapper.insertBatch(list,cid,uid,fwid);
}
else if(goodsName.equals("eleCapacity")){
keyValue = capacity;
classPaths = "com.tansuo365.test1.bean.goods.stoke.EleCapacity2";
list = ExcelUtil.readExcel(fileName,in,ExcelUtil.getMap(keyValue),classPaths,2);
eleCapacityMapper.insertBatch(list,cid,uid,fwid);
}else if(goodsName.equals("al2O3Yield")){
keyValue = yield;
classPaths = "com.tansuo365.test1.bean.goods.stoke.Al2O3Yield";
list = ExcelUtil.readExcel(fileName,in,ExcelUtil.getMap(keyValue),classPaths,2);
al2O3YieldMapper.insertBatch(list,cid,uid,fwid);
}
else if(goodsName.equals("eleYield")){
keyValue = yield;
classPaths = "com.tansuo365.test1.bean.goods.stoke.EleYield";
list = ExcelUtil.readExcel(fileName,in,ExcelUtil.getMap(keyValue),classPaths,2);
eleYieldMapper.insertBatch(list,cid,uid,fwid);
}
else{
System.out.println("ERROR=====================");
throw new Exception("没有找到对应的表,请确定所导入的Excel与该数据表相对应");
}
System.out.println("导入成功");
}
}
为什么不尝试阿里的easyExcel呢 poi好久没人维护了 容易出问题