Jelajahi Sumber

单船申报导出功能

git-svn-id: https://192.168.57.71/svn/jsgkj@1802 931142cf-59ea-a443-aa0e-51397b428577
ld_xuhx 8 tahun lalu
induk
melakukan
a7a301ccdb

+ 203 - 1
gkjsjy/trunk/src/com/xt/jygl/gkjygl/cghzyxxgl/dcsb/ctl/DcsbCtl.java

@@ -1,5 +1,6 @@
 package com.xt.jygl.gkjygl.cghzyxxgl.dcsb.ctl;
 
+import java.io.IOException;
 import java.text.ParseException;
 import java.text.SimpleDateFormat;
 import java.util.ArrayList;
@@ -12,7 +13,9 @@ import javax.persistence.criteria.CriteriaBuilder.In;
 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 org.activiti.engine.ActivitiException;
 import org.springframework.beans.BeanUtils;
@@ -366,7 +369,206 @@ public class DcsbCtl extends BaseWebCtl {
 		putPageInfo(model, page, list);
 		return "gkjygl/cghzyxxgl/dcsb/dcsbmain";
 	}
+	//导出
+	@RequestMapping(value="/exportExcelAll")
+	@ResponseBody
+	public String exportExcelAll(HttpServletResponse response,SimplePageRequest page, Model model, final String gkjyr, final String szdid, final String szgkid, final String szgqid, final String zypmc, final String bh, final String hwzl, final String shzt, final String menuid, final Date zysjq, final String dydlid, final Date zysjz, final HttpServletRequest request) throws JsonProcessingException {
+		final Map<String, Object> cacheSCmap = CacheSearchCondition.cacheSCmap(request, "dcsb");
+		// 查询条件
+				Specification<DcsbEntity> spec = new Specification<DcsbEntity>() {
+					@Override
+					public Predicate toPredicate(Root<DcsbEntity> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
+						List<Predicate> list = new ArrayList<Predicate>();
+						if (StringUtils.isNotEmpty(gkjyr)) {
+							list.add(cb.like(root.get("ssjyr").get("gkjyr").as(String.class), "%" + gkjyr + "%"));
+						} else if (isGET(request)) {
+							String v = (String) CacheSearchCondition.cacheSCmapVal(cacheSCmap, "gkjyr");
+							if (StringUtils.isNotEmpty(v)) {
+								list.add(cb.like(root.get("ssjyr").get("gkjyr").as(String.class), "%" + v + "%"));
+							}
+						}
+
+						if (StringUtils.isNotEmpty(szdid)) {
+							list.add(cb.like(root.get("szd").get("id").as(String.class), "%" + szdid + "%"));
+						} else if (isGET(request)) {
+							String v = (String) CacheSearchCondition.cacheSCmapVal(cacheSCmap, "szdid");
+							if (StringUtils.isNotEmpty(v)) {
+								list.add(cb.like(root.get("szd").get("id").as(String.class), "%" + v + "%"));
+							}
+						}
+
+						if (StringUtils.isNotEmpty(szgkid)) {
+							list.add(cb.like(root.get("szgk").get("id").as(String.class), "%" + szgkid + "%"));
+						} else if (isGET(request)) {
+							String v = (String) CacheSearchCondition.cacheSCmapVal(cacheSCmap, "szgkid");
+							if (StringUtils.isNotEmpty(v)) {
+								list.add(cb.like(root.get("szgk").get("id").as(String.class), "%" + v + "%"));
+							}
+						}
+
+						if (StringUtils.isNotEmpty(szgqid)) {
+							list.add(cb.like(root.get("szgq").get("id").as(String.class), "%" + szgqid + "%"));
+						} else if (isGET(request)) {
+							String v = (String) CacheSearchCondition.cacheSCmapVal(cacheSCmap, "szgqid");
+							if (StringUtils.isNotEmpty(v)) {
+								list.add(cb.like(root.get("szgq").get("id").as(String.class), "%" + v + "%"));
+							}
+						}
+
+						if (StringUtils.isNotEmpty(zypmc)) {
+							list.add(cb.like(root.get("zypmc").as(String.class), "%" + zypmc + "%"));
+						} else if (isGET(request)) {
+							String v = (String) CacheSearchCondition.cacheSCmapVal(cacheSCmap, "zypmc");
+							if (StringUtils.isNotEmpty(v)) {
+								list.add(cb.like(root.get("zypmc").as(String.class), "%" + v + "%"));
+							}
+						}
+
+						if (StringUtils.isNotEmpty(dydlid)) {
+							list.add(cb.equal(root.get("hwzl").get("id").as(String.class), dydlid));
+						} else if (isGET(request)) {
+
+							CacheSearchCondition.predicateList(list, cacheSCmap, root, cb, "id", "hwzl", "dydlid");
+						}
+
+						if (StringUtils.isNotEmpty(shzt)) {
+							list.add(cb.like(root.get("shzt").as(String.class), "%" + shzt + "%"));
+						} else if (isGET(request)) {
+							String v = (String) CacheSearchCondition.cacheSCmapVal(cacheSCmap, "shzt");
+							if (StringUtils.isNotEmpty(v)) {
+								list.add(cb.like(root.get("shzt").as(String.class), "%" + v + "%"));
+							}
+						}
+
+						if (null != zysjq && !"".equals(zysjq)) {
+							list.add(cb.greaterThanOrEqualTo(root.get("zysjq").as(Date.class), zysjq));
+							/*
+							 * if (StringUtils.isNotEmpty(new
+							 * SimpleDateFormat("yyyy-MM-dd").format(zysjq))) { } else
+							 * if (isGET(request)) { String v = (String)
+							 * CacheSearchCondition.cacheSCmapVal(cacheSCmap, "zysjq");
+							 * if (StringUtils.isNotEmpty(new
+							 * SimpleDateFormat("yyyy-MM-dd").format(v))) {
+							 * list.add(cb.equal(root.get("zysjq").as(Date.class), v));
+							 * } }
+							 */
+						} else {
+							String v = (String) CacheSearchCondition.cacheSCmapVal(cacheSCmap, "zysjq");
+							if (!StringUtils.isEmpty(v)) {
+								try {
+									Date d = new SimpleDateFormat("yyyy-MM-dd").parse(v);
+									list.add(cb.greaterThanOrEqualTo(root.get("zysjq").as(Date.class), d));
+								} catch (ParseException e) {
+									// TODO Auto-generated catch block
+									e.printStackTrace();
+								}
+							}
+						}
+						if (null != zysjz && !"".equals(zysjz)) {
+							list.add(cb.lessThanOrEqualTo(root.get("zysjz").as(Date.class), zysjz));
+							/*
+							 * if (StringUtils.isNotEmpty(new
+							 * SimpleDateFormat("yyyy-MM-dd").format(zysjz))) { } else
+							 * if (isGET(request)) { String v = (String)
+							 * CacheSearchCondition.cacheSCmapVal(cacheSCmap, "zysjz");
+							 * if (StringUtils.isNotEmpty(v)) {
+							 * list.add(cb.lessThanOrEqualTo
+							 * (root.get("zysjz").as(Date.class), new
+							 * SimpleDateFormat("yyyy-MM-dd").parse(v))); } }
+							 */
+						} else {
+							String v = (String) CacheSearchCondition.cacheSCmapVal(cacheSCmap, "zysjz");
+							if (!StringUtils.isEmpty(v)) {
+								try {
+									Date d = new SimpleDateFormat("yyyy-MM-dd").parse(v);
+									list.add(cb.lessThanOrEqualTo(root.get("zysjz").as(Date.class), d));
+								} catch (ParseException e) {
+									e.printStackTrace();
+								}
+							}
+						}
+						// 经营人只能查看自己企业下的数据,非经营人只能查看自己所在地的数据
+						if (isJyr()) {
+							list.add(cb.like(root.get("ssjyr").get("id").as(String.class), "%" + getSsjyr().getId() + "%"));
+						} else {
+							In<String> in = cb.in(root.get("szgq").get("id").as(String.class));
+							@SuppressWarnings("unchecked")
+							List<String> gqlist = (List<String>) Utils.getSession().getAttribute("gqList");
+							if (gqlist != null && gqlist.size() > 0) {
+								for (int i = 0; i < gqlist.size(); i++) {
+									in.value(gqlist.get(i));
+								}
+								list.add(in);
+							}
+							list.add(cb.notEqual(root.get("recordStatus").as(Integer.class), BaseEntity.RECORD_STATE_VALID));
+						}
+						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[] {}));
+					}
+				};
+				String user1 = (String) Utils.getSession().getAttribute("userpre");
+				String user2 = SecUtils.getCurrUser().getId();
+				if (user2 != null) {
+					if (!user2.equals(user1)) {
+						SearchCondition.dcsbpage = 1;
+						SearchCondition.dcsbjyr = "";
+						SearchCondition.dcsbszd = "";
+						SearchCondition.dcsbszgk = "";
+						SearchCondition.dcsbszgq = "";
+						SearchCondition.dcsbzypmc = "";
+						SearchCondition.dcsbhwzl = "";
+						SearchCondition.dcsbshzt = "";
+						SearchCondition.dcsbzysjq = null;
+						SearchCondition.dcsbzysjz = null;
+					}
+				}
+				Utils.getSession().setAttribute("userpre", user2);
 
+				
+				List<DcsbEntity> list = query.findAll(spec,DcsbEntity.class);
+				List<DcsbVo> voList = new ArrayList<DcsbVo>();
+				for (DcsbEntity entity : list) {
+					DcsbVo vo = new DcsbVo();
+					if (entity != null) {
+						BeanUtils.copyProperties(entity, vo);
+						vo.setSsjyr(entity.getSsjyr() != null ? entity.getSsjyr().getGkjyr() : "");
+						vo.setSzgk(entity.getSzgk() != null ? entity.getSzgk().getGkmc() : "");
+						vo.setSzgq(entity.getSzgq() != null ? entity.getSzgq().getGqmc() : "");
+						if (entity.getShzt() != null) {
+							vo.setShztzw(securityMgr.codeService().findOne(entity.getShzt()).getText());
+						}
+						if (entity.getHwzl() != null) {
+							vo.setHwzlzw(securityMgr.codeService().findOne(entity.getHwzl().getId()).getText());
+						}
+						if ((dcsbService.getTaskByUserAndBusKey(SecUtils.getCurrUser().getId().toString(), entity.getId().toString()) != null) || dcsbService.getCandidateTaskByUserAndBusKey(SecUtils.getCurrUser().getId().toString(), entity.getId().toString()) != null) {
+							List<TaskInfoEntity> lists = taskInfoService.findByBusIdAndBusKeyAndRecordStatus(entity.getId(), DcsbEntity.PROCESS_DEFINITION_KEY);
+							if (lists != null & lists.size() > 0) {
+								TaskInfoEntity taskinfo = lists.get(0);
+								if ("申请".equals(taskinfo.getCurrName())) {
+									vo.setTaskState("TH");
+								} else {
+									vo.setTaskState(Constants.IS_MY_TASK);
+
+								}
+							}
+
+						}
+						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");// 组装附件名称和格式
+				dcsbService.exportExcelAll(voList, outputStream);
+			} catch (IOException e) {
+					e.printStackTrace();
+			}			
+		return null;
+	}
+	
 	// 货物种类
 	@RequestMapping(value = "/selectHwzl")
 	@ResponseBody
@@ -503,7 +705,7 @@ public class DcsbCtl extends BaseWebCtl {
 
 		return "gkjygl/cghzyxxgl/dcsb/dcsbedit";
 	}
-
+	
 	// 保存
 	@RequestMapping(value = "/save")
 	@ResponseBody

+ 12 - 0
gkjsjy/trunk/src/com/xt/jygl/gkjygl/cghzyxxgl/dcsb/service/DcsbService.java

@@ -2,7 +2,13 @@ package com.xt.jygl.gkjygl.cghzyxxgl.dcsb.service;
 
 import java.util.List;
 
+import javax.servlet.ServletOutputStream;
+
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
+
 import com.xt.jygl.gkjygl.cghzyxxgl.dcsb.entity.DcsbEntity;
+import com.xt.jygl.gkjygl.cghzyxxgl.dcsb.vo.DcsbVo;
+import com.xt.jygl.gkjygl.gkjyr.xkzxx.vo.XkzxxVo;
 import com.xt.jygl.workflow.service.BaseWorkFlowService;
 
 public interface DcsbService extends BaseWorkFlowService {
@@ -112,4 +118,10 @@ public interface DcsbService extends BaseWorkFlowService {
 	 * 单船申报统计表格,查询货物种类第二大类时数据
 	 */
 	public List<Object> dcsbtjbg2(String sTime, String eTime, String hwzldedl, String nwmid, String szdid, String szgkid, String szgqid, String jcgid,String qyxzid,String fwlxid);
+	/**
+	 *  导出数据
+	 * */
+	public void exportExcelAll(List<DcsbVo> voList, ServletOutputStream outputStream);
+	
+	public void setXkzxxSheet(List<DcsbVo> voList, ServletOutputStream outputStream, XSSFWorkbook workBook);
 }

+ 98 - 0
gkjsjy/trunk/src/com/xt/jygl/gkjygl/cghzyxxgl/dcsb/service/impl/DcsbServiceImpl.java

@@ -19,6 +19,7 @@ import javax.net.ssl.SSLSession;
 import javax.net.ssl.SSLSocket;
 import javax.net.ssl.TrustManager;
 import javax.net.ssl.X509TrustManager;
+import javax.servlet.ServletOutputStream;
 
 import org.apache.http.HttpEntity;
 import org.apache.http.HttpResponse;
@@ -35,15 +36,23 @@ import org.apache.http.impl.client.DefaultHttpClient;
 import org.apache.http.message.BasicNameValuePair;
 import org.apache.http.params.CoreConnectionPNames;
 import org.apache.http.util.EntityUtils;
+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.Constants;
+import com.xt.jygl.common.ExportUtil;
 import com.xt.jygl.common.GlobalData;
 import com.xt.jygl.gkjcxx.gq.service.GqService;
 import com.xt.jygl.gkjygl.cghzyxxgl.dcsb.dao.DcsbDao;
 import com.xt.jygl.gkjygl.cghzyxxgl.dcsb.entity.DcsbEntity;
 import com.xt.jygl.gkjygl.cghzyxxgl.dcsb.service.DcsbService;
+import com.xt.jygl.gkjygl.cghzyxxgl.dcsb.vo.DcsbVo;
+import com.xt.jygl.gkjygl.gkjyr.xkzxx.vo.XkzxxVo;
 import com.xt.jygl.workflow.entity.TaskInfoEntity;
 import com.xt.jygl.workflow.param.WorkFlowParam;
 import com.xt.jygl.workflow.service.impl.BaseWorkFlowServiceImpl;
@@ -671,4 +680,93 @@ public class DcsbServiceImpl extends BaseWorkFlowServiceImpl<DcsbEntity, String>
 		// TODO Auto-generated method stub
 		return dao.findByGqids(gqids);
 	}
+	
+	/**
+	 * 导出数据
+	 * */
+	@Override
+	public void exportExcelAll(List<DcsbVo> voList, ServletOutputStream outputStream){
+		// 创建一个workbook 对应一个excel应用文件
+				XSSFWorkbook workBook = new XSSFWorkbook();
+				setXkzxxSheet(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();
+					}
+				}
+	}
+	
+	@Override
+	public void setXkzxxSheet(List<DcsbVo> voList, ServletOutputStream outputStream, XSSFWorkbook workBook) {
+		String[] titles = { "序号", "港口经营人", "作业品名称", "作业数量(吨)", "货物种类第一大类", "所在港口", "所在港区", "报告时间", "当前状态" };
+		// 在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]);
+		}
+		//时间格式
+		//将建成时间精确到天
+		SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");//小写的mm表示的是分钟  
+		// 构建表体数据
+		if (voList != null && voList.size() > 0) {
+			SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
+			for (int j = 0; j < voList.size(); j++) {
+				XSSFRow bodyRow = sheet.createRow(j + 1);
+				DcsbVo xkzxx = voList.get(j);
+				// 序号
+				cell = bodyRow.createCell(0);
+				cell.setCellStyle(bodyStyle);
+				cell.setCellValue(j + 1);
+
+				cell = bodyRow.createCell(1);
+				cell.setCellStyle(bodyStyle);
+				cell.setCellValue(voList.get(j).getSsjyr());
+				
+				cell = bodyRow.createCell(2);
+				cell.setCellStyle(bodyStyle);
+				cell.setCellValue(voList.get(j).getZypmc());
+				
+				cell = bodyRow.createCell(3);
+				cell.setCellStyle(bodyStyle);
+				cell.setCellValue(voList.get(j).getZysl());
+				
+				cell = bodyRow.createCell(4);
+				cell.setCellStyle(bodyStyle);
+				cell.setCellValue(voList.get(j).getHwzlzw());
+				
+				cell = bodyRow.createCell(5);
+				cell.setCellStyle(bodyStyle);
+				cell.setCellValue(voList.get(j).getSzgk());
+				
+				cell = bodyRow.createCell(6);
+				cell.setCellStyle(bodyStyle);
+				cell.setCellValue(voList.get(j).getSzgq());
+				
+				cell = bodyRow.createCell(7);
+				cell.setCellStyle(bodyStyle);
+				
+				cell.setCellValue(sdf.format(voList.get(j).getBgsj()));
+
+				cell = bodyRow.createCell(8);
+				cell.setCellStyle(bodyStyle);
+				cell.setCellValue(voList.get(j).getShztzw());
+			}
+		}
+	}
 }