Browse Source

wifi热点分布统计数据导出

jun.zhou 9 years ago
parent
commit
04db6fb42c

+ 80 - 17
src/main/java/com/cloudcross/ssp/web/back/main/ap/ApmacController.java

@@ -817,6 +817,17 @@ public class ApmacController extends SimpleController {
 		}
 	}
 	
+	/**
+	 * wifi热点分布查询
+	 * @param model
+	 * @param cn
+	 * @param cnCity
+	 * @param placeId
+	 * @param placeName
+	 * @param page
+	 * @param searchValue
+	 * @return
+	 */
 	@RequestMapping("/wifisum")
 	public String queryWifiSumList(Model model,String cn,String cnCity,Integer placeId,
 			String placeName,@RequestParam(defaultValue = "1") int page,String searchValue){
@@ -834,15 +845,16 @@ public class ApmacController extends SimpleController {
 			model.addAttribute("cnCity", "市");
 		}
 		if(placeId != null && !"".equals(placeId)){
-			condition.put("place", placeId);
+			condition.put("placeId", placeId);
 			model.addAttribute("placeId", placeId);
 			model.addAttribute("placeName", placeName);
 		}else{
 			model.addAttribute("placeName", "数据场景");
 		}
 		if(searchValue != null && !"".equals(searchValue)){
+			model.addAttribute("searchValue", searchValue);
 			searchValue = "%"+searchValue+"%";
-			condition.put("searchValue", searchValue);
+			condition.put("searchValue", searchValue);	
 		}
 		Integer count = this.wifiSumService.queryWifiSumCountByCondition(condition);
 		Pager pager = new Pager();
@@ -856,46 +868,97 @@ public class ApmacController extends SimpleController {
 	}
 	
 	/**
-	 * 数据导出
-	 * @param model
+	 *wifi热点分布导出
+	 * 创建人:zhoujun
+	 * 创建时间:2015.12.18 11:43
+	 * 注意:前端get请求提交,参数要转码  如:String str = new String(str.getBytes("ISO-8859-1"),"UTF-8");
+	 * @param response
 	 * @param cn
 	 * @param cnCity
 	 * @param placeId
 	 * @param placeName
-	 * @param page
 	 * @param searchValue
 	 */
 	@RequestMapping("/exportWifiSumExcel")
-	public void queryWifiSumExport(Model model,String cn,String cnCity,Integer placeId,
-			String placeName,@RequestParam(defaultValue = "1") int page,String searchValue){
-		Map<String,Object>condition = new HashMap<String,Object>();
+	public void queryWifiSumExport(HttpServletResponse response,String cn,String cnCity,Integer placeId,
+			String placeName,String searchValue){
+		Map<String,Object>condition = new HashMap<String,Object>();//存放查询条件
+		Map<String,Object>map = new HashMap<String,Object>();//存放导出excel显示的参数
 		if(cn != null && !"".equals(cn)){
+			try {
+				cn = new String(cn.getBytes("ISO-8859-1"),"UTF-8");
+			} catch (UnsupportedEncodingException e) {
+				// TODO Auto-generated catch block
+				e.printStackTrace();
+			}
 			condition.put("cn", cn);
-			model.addAttribute("cn", cn);
+			map.put("cn", cn);
 		}else{
-			model.addAttribute("cn", "省");
+			map.put("cn", "全部");
 		}
 		if(cnCity != null && !"".equals(cnCity)){
+			try {
+				cnCity = new String(cnCity.getBytes("ISO-8859-1"),"UTF-8");
+			} catch (UnsupportedEncodingException e) {
+				// TODO Auto-generated catch block
+				e.printStackTrace();
+			}
 			condition.put("cnCity", cnCity);
-			model.addAttribute("cnCity", cnCity);
+			map.put("cnCity", cnCity);
 		}else{
-			model.addAttribute("cnCity", "市");
+			map.put("cnCity", "全部");
 		}
 		if(placeId != null && !"".equals(placeId)){
-			condition.put("place", placeId);
-			model.addAttribute("placeId", placeId);
-			model.addAttribute("placeName", placeName);
+			condition.put("placeId", placeId);
+			try {
+				placeName = new String(placeName.getBytes("ISO-8859-1"),"UTF-8");
+			} catch (UnsupportedEncodingException e) {
+				// TODO Auto-generated catch block
+				e.printStackTrace();
+			}
+			map.put("placeName", placeName);
 		}else{
-			model.addAttribute("placeName", "数据场景");
+			map.put("placeName", "全部");
 		}
 		if(searchValue != null && !"".equals(searchValue)){
+			try {
+				searchValue = new String(searchValue.getBytes("ISO-8859-1"),"UTF-8");
+			} catch (UnsupportedEncodingException e) {
+				// TODO Auto-generated catch block
+				e.printStackTrace();
+			}
+			map.put("searchValue", searchValue);
 			searchValue = "%"+searchValue+"%";
 			condition.put("searchValue", searchValue);
+		}else{
+			map.put("searchValue", "请输入查询条件");
 		}
 		
 		List<WifiSum> wifiSumList = this.wifiSumService.queryWifiSumByExport(condition);
 		
-		model.addAttribute("wifiSumList", wifiSumList);
+		map.put("dataList", wifiSumList);
+		response.reset();
+		// Content-Type:application/vnd.ms-excel;charset=utf8或者text/xml;charset=utf8
+		response.setContentType("application/vnd.ms-excel;charset=utf8");
+		// 设置excel文件名称
+		SimpleDateFormat df2 = new SimpleDateFormat("yyyyMMddHHmmss");
+		String fileName = "report" + df2.format(new Date());
+		response.setHeader("Content-Disposition", "attachment;filename="+ fileName + ".xls");
+		// 需要对excel的列的总数进行指定
+		int column = 4;
+		map.put("dataSize", (wifiSumList.size() + 100));
+		map.put("column", column);
+
+		String excelTemplate = templateProcessor.processTemplate("excel/wifiSumList.ftl", map);
+		try {
+			PrintWriter out = response.getWriter();
+			out.write(excelTemplate);
+			out.flush();
+			out.close();
+		} catch (IOException e) {
+			// TODO Auto-generated catch block
+			e.printStackTrace();
+		}
 		
 	}
 }

+ 91 - 0
src/main/resources/template/excel/wifiSumList.ftl

@@ -0,0 +1,91 @@
+<?xml version="1.0"?>
+<?mso-application progid="Excel.Sheet"?>
+<Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet"
+ xmlns:o="urn:schemas-microsoft-com:office:office"
+ xmlns:x="urn:schemas-microsoft-com:office:excel"
+ xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet"
+ xmlns:html="http://www.w3.org/TR/REC-html40">
+ <DocumentProperties xmlns="urn:schemas-microsoft-com:office:office">
+  <Author>adnetwork</Author>
+  <LastAuthor>adnetwork</LastAuthor>
+  <Created>2014-10-15T06:05:44Z</Created>
+  <Version>14.00</Version>
+ </DocumentProperties>
+ <OfficeDocumentSettings xmlns="urn:schemas-microsoft-com:office:office">
+  <AllowPNG/>
+ </OfficeDocumentSettings>
+ <ExcelWorkbook xmlns="urn:schemas-microsoft-com:office:excel">
+  <WindowHeight>5130</WindowHeight>
+  <WindowWidth>16155</WindowWidth>
+  <WindowTopX>240</WindowTopX>
+  <WindowTopY>45</WindowTopY>
+  <ProtectStructure>False</ProtectStructure>
+  <ProtectWindows>False</ProtectWindows>
+ </ExcelWorkbook>
+ <Styles>
+  <Style ss:ID="Default" ss:Name="Normal">
+   <Alignment ss:Vertical="Center"/>
+   <Borders/>
+   <Font ss:FontName="宋体" x:CharSet="134" ss:Size="11" ss:Color="#000000"/>
+   <Interior/>
+   <NumberFormat/>
+   <Protection/>
+  </Style>
+  <Style ss:ID="s63" ss:Name="超链接">
+   <Font ss:FontName="宋体" x:CharSet="134" ss:Size="11" ss:Color="#0000FF"
+    ss:Underline="Single"/>
+  </Style>
+  <Style ss:ID="s65">
+   <NumberFormat ss:Format="Short Date"/>
+  </Style>
+  <Style ss:ID="s66">
+   <NumberFormat ss:Format="0%"/>
+  </Style>
+ </Styles>
+ <Worksheet ss:Name="Sheet1">
+  <Table ss:ExpandedColumnCount="${column!}" ss:ExpandedRowCount="<#if dataSize??>${dataSize+2}<#else>2</#if>" x:FullColumns="1"
+   x:FullRows="1" ss:DefaultColumnWidth="54" ss:DefaultRowHeight="13.5">
+   <Column ss:AutoFitWidth="0" ss:Width="114"/>
+   <Column ss:AutoFitWidth="0" ss:Width="95.25"/>
+   <Column ss:AutoFitWidth="0" ss:Width="93" ss:Span="1"/>
+   <Column ss:Index="5" ss:AutoFitWidth="0" ss:Width="74.25"/>
+   <Column ss:Width="63"/>
+   <Row>
+    <Cell ss:MergeAcross="12"><Data ss:Type="String">省:${cn!}   市:${cnCity!}    数聚场景:${placeName!}  搜索:${searchValue!}	</Data></Cell>
+   </Row>
+   <Row>
+	    <Cell><Data ss:Type="String">省</Data></Cell>
+	    <Cell><Data ss:Type="String">市</Data></Cell>
+	    <Cell><Data ss:Type="String">数聚场景</Data></Cell>
+	    <Cell><Data ss:Type="String">热点个数</Data></Cell>
+   </Row>
+<#if dataList ??>
+     <#list dataList as wifiSum>   
+		   <Row>
+		   <Cell><Data ss:Type="String">${wifiSum.cn!}</Data></Cell>
+		   <Cell><Data ss:Type="String">${wifiSum.cnCity!}</Data></Cell>
+		   <Cell><Data ss:Type="String">${wifiSum.placeName!}</Data></Cell>
+		   <Cell><Data ss:Type="String">${wifiSum.num!}</Data></Cell>
+		   </Row>
+	 </#list>
+  </#if>   
+  </Table>
+  <WorksheetOptions xmlns="urn:schemas-microsoft-com:office:excel">
+   <PageSetup>
+    <Header x:Margin="0.3"/>
+    <Footer x:Margin="0.3"/>
+    <PageMargins x:Bottom="0.75" x:Left="0.7" x:Right="0.7" x:Top="0.75"/>
+   </PageSetup>
+   <Selected/>
+   <Panes>
+    <Pane>
+     <Number>3</Number>
+     <ActiveRow>7</ActiveRow>
+     <ActiveCol>8</ActiveCol>
+    </Pane>
+   </Panes>
+   <ProtectObjects>False</ProtectObjects>
+   <ProtectScenarios>False</ProtectScenarios>
+  </WorksheetOptions>
+ </Worksheet>
+</Workbook>

+ 1 - 1
src/main/webapp/assets/js/back/apApmac.js

@@ -143,7 +143,7 @@ function exportExcel_wifiSum(){
 	if(searchValue == "请输入关键字"){
 		searchValue = "";
 	}
-	var param = "?cn="+$("#cn").val()+"&cnCity="+$("#cnCity").val()+"&placeId="+$("#placeId").val()+"&searchValue="+searchValue;
+	var param = "?cn="+$("#cn").val()+"&cnCity="+$("#cnCity").val()+"&placeId="+$("#placeId").val()+"&placeName="+$("#placeName").val()+"&searchValue="+searchValue;
 	$("#exportExcel").attr("href",$("#ctx").val()+"/back/main/ap/apmac/exportWifiSumExcel"+param);
 	return false;
 }