|
@@ -1,16 +1,29 @@
|
|
|
package com.xt.jygl.gkyxtjyfx.hxhbtj.service.impl;
|
|
|
|
|
|
+import java.io.IOException;
|
|
|
+import java.text.DecimalFormat;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
|
|
|
+import javax.servlet.ServletOutputStream;
|
|
|
+
|
|
|
+import org.apache.poi.ss.util.CellRangeAddress;
|
|
|
+import org.apache.poi.xssf.usermodel.XSSFCell;
|
|
|
+import org.apache.poi.xssf.usermodel.XSSFCellStyle;
|
|
|
+import org.apache.poi.xssf.usermodel.XSSFRow;
|
|
|
+import org.apache.poi.xssf.usermodel.XSSFSheet;
|
|
|
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
+import com.xt.jygl.common.ExportUtil;
|
|
|
import com.xt.jygl.common.service.JyglBaseService;
|
|
|
+import com.xt.jygl.gkjcxx.mt.vo.MtVo;
|
|
|
import com.xt.jygl.gkyxtjyfx.hxhbtj.dao.HxhbtjDao;
|
|
|
import com.xt.jygl.gkyxtjyfx.hxhbtj.entity.HxhbtjEntity;
|
|
|
import com.xt.jygl.gkyxtjyfx.hxhbtj.service.HxhbtjService;
|
|
|
+import com.xt.jygl.gkyxtjyfx.hxhbtj.vo.HxhbtjVo;
|
|
|
import com.xtframe.sec.common.SecRepository;
|
|
|
|
|
|
@Service
|
|
@@ -59,10 +72,203 @@ public class HxhbtjServiceImpl extends JyglBaseService<HxhbtjEntity, String> imp
|
|
|
sb.append(" from ");
|
|
|
sb.append(" (select t.dq dq,nvl(sum(t.yyhxts), 0) a1,nvl(sum(t.yyhxhbs), 0) a2,nvl(sum(t.jyhxts), 0) a3,nvl(sum(t.jyhxhbs), 0) a4,");
|
|
|
sb.append(" nvl(sum(t.nzxts), 0) a5,nvl(sum(t.nzxhbs), 0) a6, nvl(sum(t.nmhxts), 0) a7,nvl(sum(t.nmhxhbs), 0) a8 ");
|
|
|
- sb.append(" from GK_OPERATION_JSJY_HXHBTJ t where t.rq = :rq group by t.dq) a") ;
|
|
|
- sb.append(" right join gk_operation_jsjy_code d on a.dq = d.id where d.pid = 82 order by d.sortno asc");
|
|
|
- params.put("rq", rq);
|
|
|
+ sb.append(" from GK_OPERATION_JSJY_HXHBTJ t where t.rq = :rq group by t.dq) a");
|
|
|
+ sb.append(" right join gk_operation_jsjy_code d on a.dq = d.id where d.pid = 82 order by d.sortno asc");
|
|
|
+ params.put("rq", rq);
|
|
|
return (List<Object>) dao.nativeQuery(sb.toString(), params);
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public void exportExcelAll(List<HxhbtjVo> voList, ServletOutputStream outputStream) {
|
|
|
+ // 创建一个workbook 对应一个excel应用文件
|
|
|
+ XSSFWorkbook workBook = new XSSFWorkbook();
|
|
|
+ setSheet(voList, outputStream, workBook);
|
|
|
+ try {
|
|
|
+ workBook.write(outputStream);
|
|
|
+ outputStream.flush();
|
|
|
+ outputStream.close();
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ } finally {
|
|
|
+ try {
|
|
|
+ outputStream.close();
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 用户实现excel的实现
|
|
|
+ * */
|
|
|
+ public void setSheet(List<HxhbtjVo> voList, ServletOutputStream outputStream, XSSFWorkbook workBook) {
|
|
|
+ //設置titile
|
|
|
+ String[] titles = {"航线","航班"};
|
|
|
+
|
|
|
+ // 在workbook中添加一个sheet,对应Excel文件中的sheet
|
|
|
+ XSSFSheet mtSheet = workBook.createSheet("航线航班统计");
|
|
|
+ ExportUtil exportUtil = new ExportUtil(workBook, mtSheet);
|
|
|
+ XSSFCellStyle headStyle = exportUtil.getHeadStyle();
|
|
|
+ XSSFCellStyle bodyStyle = exportUtil.getBodyStyle();
|
|
|
+ // 构建表头
|
|
|
+ XSSFRow headRow = mtSheet.createRow(0);
|
|
|
+
|
|
|
+ //第一行
|
|
|
+ XSSFCell cell = null;
|
|
|
+ cell=headRow.createCell(0);
|
|
|
+ cell.setCellValue("地区");
|
|
|
+ cell.setCellStyle(headStyle);
|
|
|
+
|
|
|
+ cell=headRow.createCell(1);
|
|
|
+ cell.setCellValue("远洋航线");
|
|
|
+ cell.setCellStyle(headStyle);
|
|
|
+ cell=headRow.createCell(2);
|
|
|
+ cell.setCellValue("");
|
|
|
+ cell.setCellStyle(headStyle);
|
|
|
+
|
|
|
+ cell=headRow.createCell(3);
|
|
|
+ cell.setCellValue("近洋航线");
|
|
|
+ cell.setCellStyle(headStyle);
|
|
|
+ cell=headRow.createCell(4);
|
|
|
+ cell.setCellValue("");
|
|
|
+ cell.setCellStyle(headStyle);
|
|
|
+
|
|
|
+ cell=headRow.createCell(5);
|
|
|
+ cell.setCellValue("外贸内支线");
|
|
|
+ cell.setCellStyle(headStyle);
|
|
|
+ cell=headRow.createCell(6);
|
|
|
+ cell.setCellValue("");
|
|
|
+ cell.setCellStyle(headStyle);
|
|
|
+
|
|
|
+ cell=headRow.createCell(7);
|
|
|
+ cell.setCellValue("内贸航线");
|
|
|
+ cell.setCellStyle(headStyle);
|
|
|
+ cell=headRow.createCell(8);
|
|
|
+ cell.setCellValue("");
|
|
|
+ cell.setCellStyle(headStyle);
|
|
|
+ // 构建表头
|
|
|
+ XSSFRow headRow2 = mtSheet.createRow(1);
|
|
|
+ cell=headRow2.createCell(0);
|
|
|
+ cell.setCellValue("");
|
|
|
+ cell.setCellStyle(headStyle);
|
|
|
+ for(int i=1;i<8;i=i+2){
|
|
|
+ cell=headRow2.createCell(i);
|
|
|
+ cell.setCellValue(titles[0]);
|
|
|
+ cell.setCellStyle(headStyle);
|
|
|
+
|
|
|
+ cell=headRow2.createCell(i+1);
|
|
|
+ cell.setCellValue(titles[1]);
|
|
|
+ cell.setCellStyle(headStyle);
|
|
|
+ }
|
|
|
+ mtSheet.addMergedRegion(new CellRangeAddress(0, 1, 0, 0));
|
|
|
+ mtSheet.addMergedRegion(new CellRangeAddress(0, 0, 1, 2));
|
|
|
+ mtSheet.addMergedRegion(new CellRangeAddress(0, 0, 3, 4));
|
|
|
+ mtSheet.addMergedRegion(new CellRangeAddress(0, 0, 5, 6));
|
|
|
+ mtSheet.addMergedRegion(new CellRangeAddress(0, 0, 7, 8));
|
|
|
+
|
|
|
+ //创建8个对象用来接收各航线中的数据
|
|
|
+ double yyhx,yyhb,jyhx,jyhb,wmnhx,wmnhb,nmhx,nmhb;
|
|
|
+ yyhb=0.0;
|
|
|
+ yyhx=0.0;
|
|
|
+ jyhx=0.0;
|
|
|
+ jyhb=0.0;
|
|
|
+ wmnhx=0.0;
|
|
|
+ wmnhb=0.0;
|
|
|
+ nmhx=0.0;
|
|
|
+ nmhb=0.0;
|
|
|
+ // 构建表体数据
|
|
|
+ DecimalFormat df = new DecimalFormat("######0.0");
|
|
|
+ if (voList != null && voList.size() > 0) {
|
|
|
+ for (int j = 0; j < voList.size(); j++) {
|
|
|
+ XSSFRow bodyRow = mtSheet.createRow(j + 2);
|
|
|
+ HxhbtjVo hb=voList.get(j);
|
|
|
+
|
|
|
+ cell = bodyRow.createCell(0);
|
|
|
+ cell.setCellStyle(bodyStyle);
|
|
|
+ cell.setCellValue(hb.getSzd());
|
|
|
+
|
|
|
+ cell = bodyRow.createCell(1);
|
|
|
+ cell.setCellStyle(bodyStyle);
|
|
|
+ cell.setCellValue(df.format(Double.parseDouble(hb.getYyhxts())));
|
|
|
+ yyhx=yyhx+Double.parseDouble(hb.getYyhxts());
|
|
|
+
|
|
|
+ cell = bodyRow.createCell(2);
|
|
|
+ cell.setCellStyle(bodyStyle);
|
|
|
+ cell.setCellValue(df.format(Double.parseDouble(hb.getYyhxhbs())));
|
|
|
+ yyhb=yyhb+Double.parseDouble(hb.getYyhxhbs());
|
|
|
+
|
|
|
+ cell = bodyRow.createCell(3);
|
|
|
+ cell.setCellStyle(bodyStyle);
|
|
|
+ cell.setCellValue(df.format(Double.parseDouble(hb.getJyhxts())));
|
|
|
+ jyhx=jyhx+Double.parseDouble(hb.getJyhxts());
|
|
|
+
|
|
|
+ cell = bodyRow.createCell(4);
|
|
|
+ cell.setCellStyle(bodyStyle);
|
|
|
+ cell.setCellValue(df.format(Double.parseDouble(hb.getJyhxhbs())));
|
|
|
+ jyhb=jyhb+Double.parseDouble(hb.getJyhxhbs());
|
|
|
+
|
|
|
+ cell = bodyRow.createCell(5);
|
|
|
+ cell.setCellStyle(bodyStyle);
|
|
|
+ cell.setCellValue(df.format(Double.parseDouble(hb.getNzxts())));
|
|
|
+ wmnhx=wmnhx+Double.parseDouble(hb.getNzxts());
|
|
|
+
|
|
|
+ cell = bodyRow.createCell(6);
|
|
|
+ cell.setCellStyle(bodyStyle);
|
|
|
+ cell.setCellValue(df.format(Double.parseDouble(hb.getNzxhbs())));
|
|
|
+ wmnhb=wmnhb+Double.parseDouble(hb.getNzxhbs());
|
|
|
+
|
|
|
+ cell = bodyRow.createCell(7);
|
|
|
+ cell.setCellStyle(bodyStyle);
|
|
|
+ cell.setCellValue(df.format(Double.parseDouble(hb.getNmhxts())));
|
|
|
+ nmhx=nmhx+Double.parseDouble(hb.getNmhxts());
|
|
|
+
|
|
|
+ cell = bodyRow.createCell(8);
|
|
|
+ cell.setCellStyle(bodyStyle);
|
|
|
+ cell.setCellValue(df.format(Double.parseDouble(hb.getNmhxhbs())));
|
|
|
+ nmhb=nmhb+Double.parseDouble(hb.getNmhxhbs());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //生成合计行
|
|
|
+ if (voList != null && voList.size() > 0) {
|
|
|
+ XSSFRow bodyRow = mtSheet.createRow(voList.size() + 2);
|
|
|
+ cell = bodyRow.createCell(0);
|
|
|
+ cell.setCellStyle(bodyStyle);
|
|
|
+ cell.setCellValue("合计");
|
|
|
+
|
|
|
+ cell = bodyRow.createCell(1);
|
|
|
+ cell.setCellStyle(bodyStyle);
|
|
|
+ cell.setCellValue(yyhx);
|
|
|
+
|
|
|
+
|
|
|
+ cell = bodyRow.createCell(2);
|
|
|
+ cell.setCellStyle(bodyStyle);
|
|
|
+ cell.setCellValue(yyhb);
|
|
|
+
|
|
|
+ cell = bodyRow.createCell(3);
|
|
|
+ cell.setCellStyle(bodyStyle);
|
|
|
+ cell.setCellValue(jyhx);
|
|
|
+
|
|
|
+ cell = bodyRow.createCell(4);
|
|
|
+ cell.setCellStyle(bodyStyle);
|
|
|
+ cell.setCellValue(jyhb);
|
|
|
+
|
|
|
+ cell = bodyRow.createCell(5);
|
|
|
+ cell.setCellStyle(bodyStyle);
|
|
|
+ cell.setCellValue(wmnhx);
|
|
|
+
|
|
|
+
|
|
|
+ cell = bodyRow.createCell(6);
|
|
|
+ cell.setCellStyle(bodyStyle);
|
|
|
+ cell.setCellValue(wmnhb);
|
|
|
+
|
|
|
+ cell = bodyRow.createCell(7);
|
|
|
+ cell.setCellStyle(bodyStyle);
|
|
|
+ cell.setCellValue(nmhx);
|
|
|
+
|
|
|
+ cell = bodyRow.createCell(8);
|
|
|
+ cell.setCellStyle(bodyStyle);
|
|
|
+ cell.setCellValue(nmhb);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|