Commit ea73153ec92dc0aaa1351563ba503c2b006bc1a2

Authored by 潘钊
2 parents d88f216c e7dd94bb

Merge branch 'minhang' of http://222.66.0.204:8090/panzhaov5/bsth_control into minhang

src/main/java/com/bsth/controller/DownloadController.java
... ... @@ -39,9 +39,8 @@ public class DownloadController
39 39  
40 40 @RequestMapping("download2")
41 41 public ResponseEntity<byte[]> download2(String fileName) throws IOException {
42   -// fileName = fileName+".xls";
43 42 String fileNames=URLDecoder.decode(fileName,"UTF-8");
44   - fileNames =fileNames + ".xls";
  43 + fileNames = fileNames + ".xls";
45 44 String moudelPath = this.getClass().getResource("/").getPath()+ "static/pages/forms/export/"+fileNames;
46 45 System.out.println(moudelPath);
47 46 // String path="D:\\export\\target\\"+jName+".xls";
... ... @@ -76,4 +75,26 @@ public class DownloadController
76 75 os.flush();
77 76 os.close();
78 77 }
  78 +
  79 + @RequestMapping("downloadList")
  80 + public void downloadList(HttpServletResponse response,String fileName)
  81 + throws IOException {
  82 +// String fileNames=URLDecoder.decode(fileName,"UTF-8");
  83 + fileName =fileName + ".zip";
  84 + String moudelPath = this.getClass().getResource("/").getPath()+ "static/pages/forms/export/"+fileName;
  85 + File file = new File(moudelPath);// path是根据日志路径和文件名拼接出来的
  86 +// String filename = file.getName();// 获取日志文件名称
  87 + InputStream fis = new BufferedInputStream(new FileInputStream(moudelPath));
  88 + byte[] buffer = new byte[fis.available()];
  89 + fis.read(buffer);
  90 + fis.close();
  91 + response.reset();
  92 + response.addHeader("Content-Disposition", "attachment;filename=" + new String(fileName.replaceAll(" ", "").getBytes("utf-8"),"iso8859-1"));
  93 + response.addHeader("Content-Length", "" + file.length());
  94 + OutputStream os = new BufferedOutputStream(response.getOutputStream());
  95 + response.setContentType("application/octet-stream");
  96 + os.write(buffer);// 输出文件
  97 + os.flush();
  98 + os.close();
  99 + }
79 100 }
... ...
src/main/java/com/bsth/controller/realcontrol/ScheduleRealInfoController.java
... ... @@ -434,4 +434,10 @@ public class ScheduleRealInfoController extends BaseController&lt;ScheduleRealInfo,
434 434 public List<Map<String, Object>> scheduleDailyExport(@RequestParam Map<String, Object> map){
435 435 return scheduleRealInfoService.scheduleDailyExport(map);
436 436 }
  437 +
  438 + @RequestMapping(value = "exportWaybillMore", method = RequestMethod.POST)
  439 + public Map<String, Object> exportWaybillMore(@RequestParam Map<String, Object> map){
  440 + return scheduleRealInfoService.exportWaybillMore(map);
  441 + }
  442 +
437 443 }
... ...
src/main/java/com/bsth/service/realcontrol/ScheduleRealInfoService.java
... ... @@ -146,4 +146,6 @@ public interface ScheduleRealInfoService extends BaseService&lt;ScheduleRealInfo, L
146 146 List<Map<String, Object>> scheduleDailyQp(String line ,String date);
147 147  
148 148 List<Map<String, Object>> scheduleDailyExport(Map<String, Object> map);
  149 +
  150 + Map<String, Object> exportWaybillMore(Map<String, Object> map);
149 151 }
... ...
src/main/java/com/bsth/service/realcontrol/impl/ScheduleRealInfoServiceImpl.java
1 1 package com.bsth.service.realcontrol.impl;
2 2  
  3 +import com.alibaba.fastjson.JSON;
3 4 import com.alibaba.fastjson.JSONArray;
4 5 import com.alibaba.fastjson.JSONObject;
5 6 import com.bsth.common.ResponseCode;
... ... @@ -54,10 +55,17 @@ import org.slf4j.LoggerFactory;
54 55 import org.springframework.beans.factory.annotation.Autowired;
55 56 import org.springframework.stereotype.Service;
56 57  
  58 +import java.io.BufferedInputStream;
  59 +import java.io.BufferedOutputStream;
  60 +import java.io.File;
  61 +import java.io.FileInputStream;
  62 +import java.io.FileOutputStream;
57 63 import java.text.DecimalFormat;
58 64 import java.text.ParseException;
59 65 import java.text.SimpleDateFormat;
60 66 import java.util.*;
  67 +import java.util.zip.ZipEntry;
  68 +import java.util.zip.ZipOutputStream;
61 69  
62 70 @Service
63 71 public class ScheduleRealInfoServiceImpl extends BaseServiceImpl<ScheduleRealInfo, Long>
... ... @@ -124,6 +132,9 @@ public class ScheduleRealInfoServiceImpl extends BaseServiceImpl&lt;ScheduleRealInf
124 132 }
125 133  
126 134 private final static long DAY_TIME = 1000 * 60 * 60 * 24L;
  135 +
  136 + private static int BUF_SIZE = 1024;
  137 +
127 138 private static DateTimeFormatter fmtyyyyMMdd = DateTimeFormat.forPattern("yyyy-MM-dd");
128 139  
129 140 @Override
... ... @@ -525,7 +536,6 @@ public class ScheduleRealInfoServiceImpl extends BaseServiceImpl&lt;ScheduleRealInf
525 536 map.put("fast", "");
526 537 map.put("slow", "");
527 538 }
528   - System.out.println(map);
529 539 listMap.add(map);
530 540 } catch (Exception e) {
531 541 e.printStackTrace();
... ... @@ -3136,5 +3146,64 @@ public class ScheduleRealInfoServiceImpl extends BaseServiceImpl&lt;ScheduleRealInf
3136 3146  
3137 3147 return new ArrayList<Map<String, Object>>();
3138 3148 }
  3149 +
  3150 + @Override
  3151 + public Map<String, Object> exportWaybillMore(Map<String, Object> map) {
  3152 + String date = map.get("date").toString();
  3153 + String line = map.get("line").toString();
  3154 + List<List> lists = JSON.parseArray(map.get("strs").toString(), List.class);
  3155 + String path = this.getClass().getResource("/").getPath()+"static/pages/forms/export/";
  3156 + SimpleDateFormat sdfMonth = new SimpleDateFormat("yyyy-MM-dd"),
  3157 + sdfSimple = new SimpleDateFormat("yyyyMMdd");
  3158 + int num = 0;
  3159 + File file = null;
  3160 + try {
  3161 + while (true) {
  3162 + String fileUrl = path+"行车路单"+sdfSimple.format(sdfMonth.parse(date));
  3163 + file = new File(fileUrl + (num == 0 ? "/" : "(" + num + ")/"));
  3164 + if(file.exists()){
  3165 + num++;
  3166 + } else {
  3167 + break;
  3168 + }
  3169 + }
  3170 + file.mkdirs();
  3171 +
  3172 + for(List<String> list : lists){
  3173 + String jName = list.get(0);
  3174 + String clZbh = list.get(1);
  3175 + String lpName = list.get(2);
  3176 + this.exportWaybill(jName, clZbh, lpName, date, line);
  3177 + File temp = new File(path+date+"-"+jName+"-"+clZbh+"-"+lpName+"-行车路单.xls");
  3178 + String fileName = file.getName();
  3179 + temp.renameTo(new File(path + fileName + "/" + temp.getName()));
  3180 +
  3181 + File[] listFiles = file.listFiles();
  3182 + ZipOutputStream zos = new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(path+file.getName()+".zip")));
  3183 +// zos.setEncoding("gbk");
  3184 +// zos.putNextEntry(new ZipEntry(fileName + "/"));
  3185 + for(int i = 0; i < listFiles.length; i++){
  3186 + zos.putNextEntry(new ZipEntry(fileName+"/"+listFiles[i].getName()));
  3187 + BufferedInputStream bis = new BufferedInputStream(new FileInputStream(listFiles[i]));
  3188 + BufferedOutputStream bos = new BufferedOutputStream(zos);
  3189 + int bytesRead = 0;
  3190 + for(byte[] buffer = new byte[BUF_SIZE]; ((bytesRead = bis.read(buffer, 0, BUF_SIZE)) != -1);){
  3191 +// zos.write(buffer, 0, bytesRead);
  3192 +// zos.flush();
  3193 + bos.write(buffer, 0, bytesRead);
  3194 + bos.flush();
  3195 + }
  3196 + }
  3197 + zos.close();
  3198 + }
  3199 +
  3200 + } catch (Exception e) {
  3201 + // TODO: handle exception
  3202 + e.printStackTrace();
  3203 + }
  3204 +
  3205 + map.put("fileName", file.getName());
  3206 + return map;
  3207 + }
3139 3208  
3140 3209 }
3141 3210 \ No newline at end of file
... ...
src/main/resources/static/pages/forms/statement/waybill.html
... ... @@ -39,7 +39,7 @@
39 39 <input class="btn btn-default" type="button" id="query" value="查询"/>
40 40 <input class="btn btn-default" type="button" id="export" value="导出"/>
41 41 <input class="btn btn-default" type="button" id="print" value="打印"/>
42   -<!-- <input class="btn btn-default" type="button" id="exportMore" value="批量导出"/> -->
  42 + <input class="btn btn-default" type="button" id="exportMore" value="批量导出"/>
43 43 </div>
44 44 </form>
45 45 </div>
... ... @@ -148,9 +148,9 @@
148 148 */
149 149  
150 150 var date = '';
151   - var line ='';
  151 + var line ='';
152 152 $("#query").on("click",function(){
153   - line = $("#line").val();
  153 + line = $("#line").val();
154 154 date = $("#date").val();
155 155 $(".hidden").removeClass("hidden");
156 156 $get('/realSchedule/queryUserInfo',{line:line,date:date,state:2},function(result){
... ... @@ -192,7 +192,6 @@
192 192 });
193 193  
194 194 });
195   -
196 195 $("#export").on("click",function(){
197 196 if(params.length < 1){
198 197 return;
... ... @@ -207,9 +206,17 @@
207 206 });
208 207  
209 208 $("#exportMore").on("click",function(){
210   - return;
211   - $post('/realSchedule/exportWaybillMore',{date:date},function(result){
212   - window.open("/downloadFile/download?fileName="+jName);
  209 + if($("#info tbody tr td").length <= 1)
  210 + return;
  211 + var param = new Array();
  212 + $("#info tbody tr").each(function(index){
  213 + param[index] = new Array();
  214 + $(this).children().each(function(i){
  215 + param[index][i] = $(this).text().split("\\")[0];
  216 + });
  217 + });
  218 + $post('/realSchedule/exportWaybillMore',{date:date,line:line,strs:JSON.stringify(param)},function(result){
  219 + window.open("/downloadFile/downloadList?fileName="+result.fileName);
213 220 });
214 221 });
215 222  
... ...
src/main/resources/static/pages/forms/statement/waybillQp.html
... ... @@ -164,6 +164,8 @@
164 164 $("#info tbody").on("click","tr",function(){
165 165 if($(this).children().size() < 1){
166 166 return;
  167 + } else if($(this).children().children().html() == "没有找到相关数据"){
  168 + return;
167 169 }
168 170 $(this).children().each(function(index){
169 171 params[index] = $(this).text();
... ... @@ -209,10 +211,18 @@
209 211 });
210 212  
211 213 $("#exportMore").on("click",function(){
212   - return;
213   - $post('/realSchedule/exportWaybillMore',{date:date},function(result){
214   - window.open("/downloadFile/download?fileName="+jName);
  214 + if($("#info tbody").children().size() < 1){
  215 + return;
  216 + } else if($("#info tbody tr td").children().html() == "没有找到相关数据"){
  217 + return;
  218 + }
  219 + var param = new Array();
  220 + $("#info tbody tr").each(function(index){
  221 + param[index] = $(this).txet();
215 222 });
  223 +// $post('/realSchedule/exportWaybillQpMore',{date:date},function(result){
  224 +// window.open("/downloadFile/downloadList?fileName="+result.fileName);
  225 +// });
216 226 });
217 227  
218 228 function getTime(list){
... ... @@ -323,7 +333,7 @@
323 333 {{/each}}
324 334 {{if list.length == 0}}
325 335 <tr>
326   - <td colspan="14"><h6 class="muted">没有找到相关数据</h6></td>
  336 + <td colspan="15"><h6 class="muted">没有找到相关数据</h6></td>
327 337 </tr>
328 338 {{/if}}
329 339 </script>
... ...