Commit 130d36da34d84b37863e34ea1cb8bca7be264b72

Authored by 娄高锋
1 parent 6ed39e84

LGF 行车路单批量导出

src/main/java/com/bsth/controller/DownloadController.java
@@ -39,9 +39,8 @@ public class DownloadController @@ -39,9 +39,8 @@ public class DownloadController
39 39
40 @RequestMapping("download2") 40 @RequestMapping("download2")
41 public ResponseEntity<byte[]> download2(String fileName) throws IOException { 41 public ResponseEntity<byte[]> download2(String fileName) throws IOException {
42 -// fileName = fileName+".xls";  
43 String fileNames=URLDecoder.decode(fileName,"UTF-8"); 42 String fileNames=URLDecoder.decode(fileName,"UTF-8");
44 - fileNames =fileNames + ".xls"; 43 + fileNames = fileNames + ".xls";
45 String moudelPath = this.getClass().getResource("/").getPath()+ "static/pages/forms/export/"+fileNames; 44 String moudelPath = this.getClass().getResource("/").getPath()+ "static/pages/forms/export/"+fileNames;
46 System.out.println(moudelPath); 45 System.out.println(moudelPath);
47 // String path="D:\\export\\target\\"+jName+".xls"; 46 // String path="D:\\export\\target\\"+jName+".xls";
@@ -76,4 +75,26 @@ public class DownloadController @@ -76,4 +75,26 @@ public class DownloadController
76 os.flush(); 75 os.flush();
77 os.close(); 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,4 +434,10 @@ public class ScheduleRealInfoController extends BaseController&lt;ScheduleRealInfo,
434 public List<Map<String, Object>> scheduleDailyExport(@RequestParam Map<String, Object> map){ 434 public List<Map<String, Object>> scheduleDailyExport(@RequestParam Map<String, Object> map){
435 return scheduleRealInfoService.scheduleDailyExport(map); 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,4 +146,6 @@ public interface ScheduleRealInfoService extends BaseService&lt;ScheduleRealInfo, L
146 List<Map<String, Object>> scheduleDailyQp(String line ,String date); 146 List<Map<String, Object>> scheduleDailyQp(String line ,String date);
147 147
148 List<Map<String, Object>> scheduleDailyExport(Map<String, Object> map); 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 package com.bsth.service.realcontrol.impl; 1 package com.bsth.service.realcontrol.impl;
2 2
  3 +import com.alibaba.fastjson.JSON;
3 import com.alibaba.fastjson.JSONArray; 4 import com.alibaba.fastjson.JSONArray;
4 import com.alibaba.fastjson.JSONObject; 5 import com.alibaba.fastjson.JSONObject;
5 import com.bsth.common.ResponseCode; 6 import com.bsth.common.ResponseCode;
@@ -54,10 +55,17 @@ import org.slf4j.LoggerFactory; @@ -54,10 +55,17 @@ import org.slf4j.LoggerFactory;
54 import org.springframework.beans.factory.annotation.Autowired; 55 import org.springframework.beans.factory.annotation.Autowired;
55 import org.springframework.stereotype.Service; 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 import java.text.DecimalFormat; 63 import java.text.DecimalFormat;
58 import java.text.ParseException; 64 import java.text.ParseException;
59 import java.text.SimpleDateFormat; 65 import java.text.SimpleDateFormat;
60 import java.util.*; 66 import java.util.*;
  67 +import java.util.zip.ZipEntry;
  68 +import java.util.zip.ZipOutputStream;
61 69
62 @Service 70 @Service
63 public class ScheduleRealInfoServiceImpl extends BaseServiceImpl<ScheduleRealInfo, Long> 71 public class ScheduleRealInfoServiceImpl extends BaseServiceImpl<ScheduleRealInfo, Long>
@@ -124,6 +132,9 @@ public class ScheduleRealInfoServiceImpl extends BaseServiceImpl&lt;ScheduleRealInf @@ -124,6 +132,9 @@ public class ScheduleRealInfoServiceImpl extends BaseServiceImpl&lt;ScheduleRealInf
124 } 132 }
125 133
126 private final static long DAY_TIME = 1000 * 60 * 60 * 24L; 134 private final static long DAY_TIME = 1000 * 60 * 60 * 24L;
  135 +
  136 + private static int BUF_SIZE = 1024;
  137 +
127 private static DateTimeFormatter fmtyyyyMMdd = DateTimeFormat.forPattern("yyyy-MM-dd"); 138 private static DateTimeFormatter fmtyyyyMMdd = DateTimeFormat.forPattern("yyyy-MM-dd");
128 139
129 @Override 140 @Override
@@ -525,7 +536,6 @@ public class ScheduleRealInfoServiceImpl extends BaseServiceImpl&lt;ScheduleRealInf @@ -525,7 +536,6 @@ public class ScheduleRealInfoServiceImpl extends BaseServiceImpl&lt;ScheduleRealInf
525 map.put("fast", ""); 536 map.put("fast", "");
526 map.put("slow", ""); 537 map.put("slow", "");
527 } 538 }
528 - System.out.println(map);  
529 listMap.add(map); 539 listMap.add(map);
530 } catch (Exception e) { 540 } catch (Exception e) {
531 e.printStackTrace(); 541 e.printStackTrace();
@@ -3136,5 +3146,64 @@ public class ScheduleRealInfoServiceImpl extends BaseServiceImpl&lt;ScheduleRealInf @@ -3136,5 +3146,64 @@ public class ScheduleRealInfoServiceImpl extends BaseServiceImpl&lt;ScheduleRealInf
3136 3146
3137 return new ArrayList<Map<String, Object>>(); 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 \ No newline at end of file 3210 \ No newline at end of file
src/main/resources/static/pages/forms/statement/waybill.html
@@ -39,7 +39,7 @@ @@ -39,7 +39,7 @@
39 <input class="btn btn-default" type="button" id="query" value="查询"/> 39 <input class="btn btn-default" type="button" id="query" value="查询"/>
40 <input class="btn btn-default" type="button" id="export" value="导出"/> 40 <input class="btn btn-default" type="button" id="export" value="导出"/>
41 <input class="btn btn-default" type="button" id="print" value="打印"/> 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 </div> 43 </div>
44 </form> 44 </form>
45 </div> 45 </div>
@@ -148,9 +148,9 @@ @@ -148,9 +148,9 @@
148 */ 148 */
149 149
150 var date = ''; 150 var date = '';
151 - var line =''; 151 + var line ='';
152 $("#query").on("click",function(){ 152 $("#query").on("click",function(){
153 - line = $("#line").val(); 153 + line = $("#line").val();
154 date = $("#date").val(); 154 date = $("#date").val();
155 $(".hidden").removeClass("hidden"); 155 $(".hidden").removeClass("hidden");
156 $get('/realSchedule/queryUserInfo',{line:line,date:date,state:2},function(result){ 156 $get('/realSchedule/queryUserInfo',{line:line,date:date,state:2},function(result){
@@ -192,7 +192,6 @@ @@ -192,7 +192,6 @@
192 }); 192 });
193 193
194 }); 194 });
195 -  
196 $("#export").on("click",function(){ 195 $("#export").on("click",function(){
197 if(params.length < 1){ 196 if(params.length < 1){
198 return; 197 return;
@@ -207,9 +206,17 @@ @@ -207,9 +206,17 @@
207 }); 206 });
208 207
209 $("#exportMore").on("click",function(){ 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