Răsfoiți Sursa

git-svn-id: https://192.168.57.71/svn/jsgkj@1803 931142cf-59ea-a443-aa0e-51397b428577

ld_guxl 8 ani în urmă
părinte
comite
548df5009f

+ 12 - 0
gkjsjy/trunk/WebContent/WEB-INF/pages/ggfwxxgl/hxhbgl/hxhbglmain.jsp

@@ -25,6 +25,15 @@
 		function showgq(){
 			initgqSelect('szgqsel','',$('.szdselectpicker').val(),$('.gkselectpicker').val(),null,'80%');
 		}
+		function exportExcelAll(data1,data2,data3,data4,data5,data6){
+			location.href=$.app+"/hxhbgl/exportExcelAll?ssjyr="+data1+"&szdid="+data2+"&szgkid="+data3+"&szgqid="+data4+"&hxlrsjq="+data5+"&hxlrsjz="+data6;
+			$.alert({
+       		    title: '提示',
+			    content: '导出数据中,请耐心等待!',
+			    confirm: function(){
+			    	  }
+			});
+		} 
 	</script>
 
 </head>
@@ -115,6 +124,9 @@
 						   		<i class="glyphicon glyphicon-plus"></i>新增
 						   	</a>
 						   	</authz:hasPermission>
+						   	<a class="btn btn-default btn-sm" href="#"  onclick="exportExcelAll('${ssjyr}','${szd}','${szgk}','${szgq}','${hxlrsjq}','${hxlrsjz}')">
+						   		<i class="glyphicon glyphicon-download-alt"></i>全部导出
+						   	</a>
 		                </td>
 		        	</tr>
 				</table>

+ 88 - 0
gkjsjy/trunk/src/com/xt/jygl/ggfwxxgl/hxhbgl/ctl/HxhbglCtl.java

@@ -1,5 +1,6 @@
 package com.xt.jygl.ggfwxxgl.hxhbgl.ctl;
 
+import java.io.IOException;
 import java.text.ParseException;
 import java.text.SimpleDateFormat;
 import java.util.ArrayList;
@@ -11,7 +12,9 @@ import javax.persistence.criteria.CriteriaBuilder;
 import javax.persistence.criteria.CriteriaQuery;
 import javax.persistence.criteria.Predicate;
 import javax.persistence.criteria.Root;
+import javax.servlet.ServletOutputStream;
 import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
 
 import net.sf.json.JSONObject;
 
@@ -303,4 +306,89 @@ public class HxhbglCtl extends BaseWebCtl {
 		model.addAttribute("menuid", menuid);
 		return "ggfwxxgl/hxhbgl/hxhbgladd";
 	}
+	
+	/**
+	 * 导出全部数据到excel
+	 * 
+	 * @param response
+	 * @return
+	 */
+	@RequestMapping(value = "/exportExcelAll")
+	public String exportExcelAll(HttpServletResponse response, final String ssjyr, final String szdid, final String szgkid, final String szgqid, final String hxlrsjq, final String hxlrsjz) {
+		// 查詢條件
+		Specification<HxhbglEntity> spec = new Specification<HxhbglEntity>() {
+
+			@Override
+			public Predicate toPredicate(Root<HxhbglEntity> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
+				List<Predicate> list = new ArrayList<Predicate>();
+				if (StringUtils.isNotEmpty(szdid)) {
+					list.add(cb.like(root.get("szd").get("id").as(String.class), "%" + szdid + "%"));
+				}
+				if (StringUtils.isNotEmpty(szgkid)) {
+					list.add(cb.like(root.get("szgk").get("id").as(String.class), "%" + szgkid + "%"));
+				}
+				if (StringUtils.isNotEmpty(szgqid)) {
+					list.add(cb.like(root.get("szgq").get("id").as(String.class), "%" + szgqid + "%"));
+				}
+				if (StringUtils.isNotEmpty(ssjyr)) {
+					list.add(cb.like(root.get("ssjyr").get("gkjyr").as(String.class), "%" + ssjyr + "%"));
+				}
+				SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+				Date date;
+				if (StringUtils.isNotEmpty(hxlrsjq)) {
+					try {
+						date = sdf.parse(hxlrsjq + " 00:00:00");
+					} catch (ParseException e) {
+						// TODO Auto-generated catch block
+						date = null;
+						e.printStackTrace();
+					}
+					list.add(cb.greaterThanOrEqualTo(root.get("createDateTime").as(Date.class), date));
+				}
+				if (StringUtils.isNotEmpty(hxlrsjz)) {
+					try {
+						date = sdf.parse(hxlrsjz + " 23:59:59");
+					} catch (ParseException e) {
+
+						date = null;
+						e.printStackTrace();
+					}
+					list.add(cb.lessThanOrEqualTo(root.get("createDateTime").as(Date.class), date));
+				}
+				// 经营人只能查看自己企业下的数据,非经营人只能查看自己所在地的数据
+				if (isJyr()) {
+					list.add(cb.like(root.get("ssjyr").get("id").as(String.class), "%" + getSsjyr().getId() + "%"));
+				} else {
+					list.add(cb.like(root.get("szd").get("id").as(String.class), "%" + SecUtils.getCurrUser().getSzd().getId() + "%"));
+				}
+				list.add(cb.notEqual(root.get("recordStatus").as(Integer.class), BaseEntity.RECORD_STATE_DELETE));
+				list.add(cb.notEqual(root.get("recordStatus").as(Integer.class), BaseEntity.RECORE_STATE_COPY));
+				return cb.and(list.toArray(new Predicate[] {}));
+			}
+		};
+		List<HxhbglEntity> list = query.findAll(spec, HxhbglEntity.class);
+		List<HxhbglVo> voList = new ArrayList<HxhbglVo>();
+		for (HxhbglEntity entity : list) {
+			HxhbglVo vo = new HxhbglVo();
+			if (null != entity) {
+				BeanUtils.copyProperties(entity, vo);
+				vo.setSsjyrzw(entity.getSsjyr() != null ? entity.getSsjyr().getGkjyr() : "");
+				vo.setSsgkglbmzw(entity.getSsgkglbm() != null ? entity.getSsgkglbm().getGkglbmqc() : "");
+				String rq = entity.getYear() + "-" + entity.getMonth();
+				vo.setRq(rq);
+				voList.add(vo);
+			}
+		}
+		response.setContentType("application/binary;charset=iso-8859-1");
+		try {
+			ServletOutputStream outputStream = response.getOutputStream();
+			String fileName = new String(("航线航班管理信息全部").getBytes(), "iso-8859-1");
+			response.setHeader("Content-disposition", "attachment; filename=" + fileName + ".xlsx");// 组装附件名称和格式
+			String[] titles = { "序号", "所属经营人", "所属港口管理部门", "日期 ", "内贸集装箱吞吐量(TEU)", "外贸集装箱吞吐量(TEU)", "远洋航线条数", "远洋航线航班数", "远洋航线备注", "近洋航线条数", "近洋航线航班数", "近洋航线备注", "外贸内支线条数", "外贸内支线航班数", "外贸内支线备注", "内贸航线条数", "内贸航线航班数", "内贸航线备注" };
+			hxhbglService.exportExcelAll(voList, titles, outputStream);
+		} catch (IOException e) {
+			e.printStackTrace();
+		}
+		return null;
+	}
 }

+ 7 - 0
gkjsjy/trunk/src/com/xt/jygl/ggfwxxgl/hxhbgl/service/HxhbglService.java

@@ -1,6 +1,11 @@
 package com.xt.jygl.ggfwxxgl.hxhbgl.service;
 
+import java.util.List;
+
+import javax.servlet.ServletOutputStream;
+
 import com.xt.jygl.ggfwxxgl.hxhbgl.entity.HxhbglEntity;
+import com.xt.jygl.ggfwxxgl.hxhbgl.vo.HxhbglVo;
 
 public interface HxhbglService {
 	void delete(String id);
@@ -13,4 +18,6 @@ public interface HxhbglService {
 	 * 逻辑删除一条数据
 	 */
 	public void logicDelete(String id);
+
+	public void exportExcelAll(List<HxhbglVo> voList, String[] titles, ServletOutputStream outputStream);
 }

+ 126 - 0
gkjsjy/trunk/src/com/xt/jygl/ggfwxxgl/hxhbgl/service/impl/HxhbglServiceImpl.java

@@ -1,11 +1,23 @@
 package com.xt.jygl.ggfwxxgl.hxhbgl.service.impl;
 
+import java.io.IOException;
+import java.util.List;
+
+import javax.servlet.ServletOutputStream;
+
+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.ggfwxxgl.hxhbgl.entity.HxhbglEntity;
 import com.xt.jygl.ggfwxxgl.hxhbgl.service.HxhbglService;
+import com.xt.jygl.ggfwxxgl.hxhbgl.vo.HxhbglVo;
 import com.xtframe.sec.common.SecRepository;
 
 @Service
@@ -19,5 +31,119 @@ public class HxhbglServiceImpl extends JyglBaseService<HxhbglEntity, String> imp
 		// TODO Auto-generated method stub
 		return this.dao;
 	}
+	
+	@Override
+	public void exportExcelAll(List<HxhbglVo> voList, String[] titles, ServletOutputStream outputStream) {
+		// 创建一个workbook 对应一个excel应用文件
+		XSSFWorkbook workBook = new XSSFWorkbook();
+		// 在workbook中添加一个sheet,对应Excel文件中的sheet
+		XSSFSheet sheet = workBook.createSheet("航线航班管理信息");
+		ExportUtil exportUtil = new ExportUtil(workBook, sheet);
+		XSSFCellStyle headStyle = exportUtil.getHeadStyle();
+		XSSFCellStyle bodyStyle = exportUtil.getBodyStyle();
+		// 构建表头
+		XSSFRow headRow = sheet.createRow(0);
+		XSSFCell cell = null;
+		for (int i = 0; i < titles.length; i++) {
+			cell = headRow.createCell(i);
+			cell.setCellStyle(headStyle);
+			cell.setCellValue(titles[i]);
+		}
+		// 构建表体数据
+		if (voList != null && voList.size() > 0) {
+			for (int j = 0; j < voList.size(); j++) {
+				XSSFRow bodyRow = sheet.createRow(j + 1);
+				HxhbglVo vo = voList.get(j);
+				// 序号
+				cell = bodyRow.createCell(0);
+				cell.setCellStyle(bodyStyle);
+				cell.setCellValue(j + 1);
+				
+				cell = bodyRow.createCell(1);
+				cell.setCellStyle(bodyStyle);
+				cell.setCellValue(vo.getSsjyrzw());
+
+				cell = bodyRow.createCell(2);
+				cell.setCellStyle(bodyStyle);
+				cell.setCellValue(vo.getSsgkglbmzw());
+				
+				cell = bodyRow.createCell(3);
+				cell.setCellStyle(bodyStyle);
+				cell.setCellValue(vo.getRq());
+				
+				cell = bodyRow.createCell(4);
+				cell.setCellStyle(bodyStyle);
+				cell.setCellValue(vo.getNmjzxttl() != null ? vo.getNmjzxttl().toString() : "");
+				
+				cell = bodyRow.createCell(5);
+				cell.setCellStyle(bodyStyle);
+				cell.setCellValue(vo.getWmjzxttl() != null ? vo.getWmjzxttl().toString() : "");
+				
+
+				cell = bodyRow.createCell(6);
+				cell.setCellStyle(bodyStyle);
+				cell.setCellValue(vo.getYyhxts() != null ? vo.getYyhxts().toString() : "");
+				
+				cell = bodyRow.createCell(7);
+				cell.setCellStyle(bodyStyle);
+				cell.setCellValue(vo.getYyhxhbs() != null ? vo.getYyhxhbs().toString() : "");
+				
+				cell = bodyRow.createCell(8);
+				cell.setCellStyle(bodyStyle);
+				cell.setCellValue(vo.getYyhxbz() != null ? vo.getYyhxbz().toString() : "");
+				
+				cell = bodyRow.createCell(9);
+				cell.setCellStyle(bodyStyle);
+				cell.setCellValue(vo.getJyhxts() != null ? vo.getJyhxts().toString() : "");
+				
+				cell = bodyRow.createCell(10);
+				cell.setCellStyle(bodyStyle);
+				cell.setCellValue(vo.getJyhxhbs() != null ? vo.getJyhxhbs().toString() : "");
+				
+				cell = bodyRow.createCell(11);
+				cell.setCellStyle(bodyStyle);
+				cell.setCellValue(vo.getJyhxbz() != null ? vo.getJyhxbz().toString() : "");
+				
+				cell = bodyRow.createCell(12);
+				cell.setCellStyle(bodyStyle);
+				cell.setCellValue(vo.getNzxts() != null ? vo.getNzxts().toString() : "");
+				
+				cell = bodyRow.createCell(13);
+				cell.setCellStyle(bodyStyle);
+				cell.setCellValue(vo.getNzxhbs() != null ? vo.getNzxhbs().toString() : "");
+				
+				cell = bodyRow.createCell(14);
+				cell.setCellStyle(bodyStyle);
+				cell.setCellValue(vo.getNzxbz() != null ? vo.getNzxbz().toString() : "");
+				
+				cell = bodyRow.createCell(15);
+				cell.setCellStyle(bodyStyle);
+				cell.setCellValue(vo.getNmhxts() != null ? vo.getNmhxts().toString() : "");
+				
+				cell = bodyRow.createCell(16);
+				cell.setCellStyle(bodyStyle);
+				cell.setCellValue(vo.getNmhxhbs() != null ? vo.getNmhxhbs().toString() : "");
+				
+				cell = bodyRow.createCell(17);
+				cell.setCellStyle(bodyStyle);
+				cell.setCellValue(vo.getNmhxbz() != null ? vo.getNmhxbz().toString() : "");
+				
+			}
+		}
+		try {
+			workBook.write(outputStream);
+			outputStream.flush();
+			outputStream.close();
+		} catch (IOException e) {
+			e.printStackTrace();
+		} finally {
+			try {
+				outputStream.close();
+			} catch (IOException e) {
+				e.printStackTrace();
+			}
+		}
+
+	}
 
 }