作者 王勇

下载excel,功能,基础架子

@@ -160,10 +160,10 @@ public class CgoNmsController { @@ -160,10 +160,10 @@ public class CgoNmsController {
160 */ 160 */
161 // if (result.getWaybillNoMaster() != null && result.getWaybillNoMaster() != "") { } 161 // if (result.getWaybillNoMaster() != null && result.getWaybillNoMaster() != "") { }
162 ResultExitData asmInfo = getCgoAsmFeign.getInfo(result.getWaybillNoMaster()); 162 ResultExitData asmInfo = getCgoAsmFeign.getInfo(result.getWaybillNoMaster());
163 - //设置代理人全称  
164 - result.setFullName(asmInfo.getFullName());  
165 - //设置货主类型  
166 - result.setTheShipperType(asmInfo.getTheShipperType()); 163 + //设置结算代理人
  164 + result.setCountName(asmInfo.getCountName());
  165 + //设置订舱代理人
  166 + result.setOrderName(asmInfo.getOrderName());
167 //设置品名 167 //设置品名
168 result.setSdCargoName(asmInfo.getSdCargoName()); 168 result.setSdCargoName(asmInfo.getSdCargoName());
169 //设置二级类名称 169 //设置二级类名称
@@ -100,9 +100,9 @@ public class NmsController { @@ -100,9 +100,9 @@ public class NmsController {
100 String sid = request.getHeader("Authorization"); 100 String sid = request.getHeader("Authorization");
101 log.info("token的值:" + sid); 101 log.info("token的值:" + sid);
102 final String startTime = sdf.format(new Date()); 102 final String startTime = sdf.format(new Date());
103 - System.out.println("开始时间:" + startTime); 103 + ResultWs resultStart = new ResultWs("数据开始获取,开始时间:"+ startTime);
  104 +
104 sendMsgByWebsocket("开始时间:" + startTime, sid); 105 sendMsgByWebsocket("开始时间:" + startTime, sid);
105 - System.out.println("出港数据,开始获取");  
106 ResultJson resultJson = new ResultJson(); 106 ResultJson resultJson = new ResultJson();
107 107
108 /** 108 /**
1 package com.sunyo.wlpt.cgonms.provide.excle; 1 package com.sunyo.wlpt.cgonms.provide.excle;
2 2
3 import com.sunyo.wlpt.cgonms.provide.domain.ResultExitData; 3 import com.sunyo.wlpt.cgonms.provide.domain.ResultExitData;
4 -import com.sunyo.wlpt.cgonms.provide.domain.ResultExitDataList;  
5 import lombok.extern.slf4j.Slf4j; 4 import lombok.extern.slf4j.Slf4j;
6 import org.apache.poi.hssf.usermodel.*; 5 import org.apache.poi.hssf.usermodel.*;
  6 +import org.springframework.beans.factory.annotation.Value;
7 import org.springframework.web.bind.annotation.PostMapping; 7 import org.springframework.web.bind.annotation.PostMapping;
8 import org.springframework.web.bind.annotation.RequestBody; 8 import org.springframework.web.bind.annotation.RequestBody;
9 import org.springframework.web.bind.annotation.RequestMapping; 9 import org.springframework.web.bind.annotation.RequestMapping;
@@ -11,23 +11,14 @@ import org.springframework.web.bind.annotation.RestController; @@ -11,23 +11,14 @@ import org.springframework.web.bind.annotation.RestController;
11 11
12 import javax.servlet.http.HttpServletResponse; 12 import javax.servlet.http.HttpServletResponse;
13 import java.io.*; 13 import java.io.*;
  14 +import java.text.SimpleDateFormat;
14 import java.util.List; 15 import java.util.List;
  16 +import java.util.UUID;
15 17
16 -import lombok.extern.slf4j.Slf4j;  
17 -import oracle.sql.DATE;  
18 -import org.springframework.beans.factory.annotation.Autowired;  
19 -import org.springframework.web.bind.annotation.*;  
20 -  
21 -import javax.servlet.http.HttpServletResponse;  
22 -import java.net.URLEncoder;  
23 -import java.nio.charset.StandardCharsets;  
24 -import java.util.HashMap;  
25 -import java.util.List;  
26 -import java.util.Map;  
27 18
28 /** 19 /**
29 * @author 子诚 20 * @author 子诚
30 - * Description: 21 + * Description:导入Excel到本地
31 * 时间:2020/5/29 10:04 22 * 时间:2020/5/29 10:04
32 */ 23 */
33 @Slf4j 24 @Slf4j
@@ -35,6 +26,14 @@ import java.util.Map; @@ -35,6 +26,14 @@ import java.util.Map;
35 @RequestMapping("/exit") 26 @RequestMapping("/exit")
36 public class ExitExcel { 27 public class ExitExcel {
37 28
  29 + @Value("${path.disc}")
  30 + private String disc;
  31 + @Value("${path.dir}")
  32 + private String dir;
  33 +
  34 + final SimpleDateFormat sdfShort = new SimpleDateFormat("yyyy-MM-dd");
  35 + final SimpleDateFormat sdfLong = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  36 +
38 @PostMapping("/excel") 37 @PostMapping("/excel")
39 public void getExit(@RequestBody List<ResultExitData> exitInfoList, HttpServletResponse httpServletResponse) { 38 public void getExit(@RequestBody List<ResultExitData> exitInfoList, HttpServletResponse httpServletResponse) {
40 exportExcel(exitInfoList, httpServletResponse); 39 exportExcel(exitInfoList, httpServletResponse);
@@ -121,13 +120,13 @@ public class ExitExcel { @@ -121,13 +120,13 @@ public class ExitExcel {
121 //航班号 120 //航班号
122 excelTitle[12] = ResultExitData.getFlightNo(); 121 excelTitle[12] = ResultExitData.getFlightNo();
123 //航班日期 122 //航班日期
124 - excelTitle[13] = String.valueOf(ResultExitData.getFlightDate()); 123 + excelTitle[13] = sdfShort.format(ResultExitData.getFlightDate());
125 //航班时间 124 //航班时间
126 - excelTitle[14] = String.valueOf(ResultExitData.getFlightTime()); 125 + excelTitle[14] = sdfLong.format(ResultExitData.getFlightTime());
127 //航班计划日期 126 //航班计划日期
128 - excelTitle[15] = String.valueOf(ResultExitData.getFlightPlanDate()); 127 + excelTitle[15] = sdfShort.format(ResultExitData.getFlightPlanDate());
129 //航班计划时间 128 //航班计划时间
130 - excelTitle[16] = String.valueOf(ResultExitData.getFlightPlanTime()); 129 + excelTitle[16] = sdfLong.format(ResultExitData.getFlightPlanTime());
131 //航段 130 //航段
132 excelTitle[17] = ResultExitData.getSegment(); 131 excelTitle[17] = ResultExitData.getSegment();
133 //机号 132 //机号
@@ -151,9 +150,21 @@ public class ExitExcel { @@ -151,9 +150,21 @@ public class ExitExcel {
151 row.createCell(j).setCellValue(excelTitle[j]); 150 row.createCell(j).setCellValue(excelTitle[j]);
152 } 151 }
153 } 152 }
  153 +
  154 + String file_name= UUID.randomUUID().toString().replaceAll("-", "");
154 // 设置文件名 155 // 设置文件名
155 - String title = "export.xls";  
156 - String filePath = "H:" + File.separator + title; 156 + String title = file_name+".xls";
  157 +
  158 + String filePath = disc+":" + File.separator + dir + File.separator + title;
  159 + /**
  160 + * 创建文件夹
  161 + */
  162 + File testFile = new File(filePath);
  163 + File fileParent = testFile.getParentFile();
  164 + if (!fileParent.exists()) {
  165 + // 能创建多级目录
  166 + fileParent.mkdirs();
  167 + }
157 try { 168 try {
158 FileOutputStream fos = new FileOutputStream(filePath); 169 FileOutputStream fos = new FileOutputStream(filePath);
159 workbook.write(fos); 170 workbook.write(fos);
@@ -164,6 +175,5 @@ public class ExitExcel { @@ -164,6 +175,5 @@ public class ExitExcel {
164 } catch (IOException e) { 175 } catch (IOException e) {
165 e.printStackTrace(); 176 e.printStackTrace();
166 } 177 }
167 -  
168 } 178 }
169 } 179 }
@@ -42,6 +42,15 @@ public class ResultWs<T> implements Serializable { @@ -42,6 +42,15 @@ public class ResultWs<T> implements Serializable {
42 this.status = status; 42 this.status = status;
43 } 43 }
44 44
  45 + public ResultWs(String message, String status) {
  46 + this.message = message;
  47 + this.status = status;
  48 + }
  49 +
  50 + public ResultWs(String message) {
  51 + this.message = message;
  52 + }
  53 +
45 public ResultWs(String sid, String message, T data, String status) { 54 public ResultWs(String sid, String message, T data, String status) {
46 this.sid = sid; 55 this.sid = sid;
47 this.message = message; 56 this.message = message;
1 -package com.sunyo.wlpt.cgonms.provide.socket;  
2 -  
3 -  
4 -import com.alibaba.fastjson.JSONObject;  
5 -import lombok.extern.slf4j.Slf4j;  
6 -import org.apache.ibatis.annotations.Param;  
7 -import org.springframework.stereotype.Component;  
8 -import org.springframework.web.bind.annotation.RequestBody;  
9 -  
10 -import javax.websocket.*;  
11 -import javax.websocket.server.ServerEndpoint;  
12 -import java.io.IOException;  
13 -import java.util.concurrent.CopyOnWriteArraySet;  
14 -import java.util.concurrent.atomic.AtomicInteger;  
15 -  
16 -/**  
17 - * @author 子诚  
18 - * Description:WebSocket服务端  
19 - * 时间:2020/5/28 11:24  
20 - */  
21 -//@Component  
22 -@Slf4j  
23 -//@ServerEndpoint(value = "/websocket")  
24 -public class WebSocketServer {  
25 - /**  
26 - * 在线数量  
27 - */  
28 - private static final AtomicInteger OnlineCount = new AtomicInteger(0);  
29 -  
30 - /**  
31 - * concurrent包的线程安全Set,用来存放每个客户端对应的Session对象。  
32 - */  
33 - private static CopyOnWriteArraySet<Session> SessionSet = new CopyOnWriteArraySet<>();  
34 -  
35 -  
36 - /**  
37 - * 连接建立成功调用的方法  
38 - */  
39 - @OnOpen  
40 - public void onOpen(Session session) throws IOException {  
41 - SessionSet.add(session);  
42 - // 在线数量,加1  
43 - int cnt = OnlineCount.incrementAndGet();  
44 - log.info("有连接加入,当前连接数为:{}", cnt);  
45 - SendMessage(session, "服务端回消息:连接成功");  
46 - }  
47 -  
48 - /**  
49 - * 连接关闭调用的方法  
50 - */  
51 - @OnClose  
52 - public void onClose(Session session) {  
53 - SessionSet.remove(session);  
54 - // 在线数量,减1  
55 - int cnt = OnlineCount.decrementAndGet();  
56 - log.info("有连接关闭,当前连接数为:{}", cnt);  
57 - }  
58 -  
59 - /**  
60 - * 收到客户端消息后调用的方法  
61 - *  
62 - * @param message 客户端发送过来的消息  
63 - */  
64 - @OnMessage  
65 - public void onMessage(String message, Session session) throws IOException {  
66 - log.info("来自客户端的消息:{}", message);  
67 -  
68 -// JSONObject jsonObject = JSONObject.parseObject(message);  
69 -// Object flightNo = jsonObject.get("flightNo");  
70 -// Object flightDate = jsonObject.get("flightDate");  
71 -// log.info("flight: {},flightDate: {}", flightNo,flightDate);  
72 - SendMessage(session, "服务端收到消息,消息内容:" + message);  
73 - }  
74 -  
75 - /**  
76 - * 出现错误  
77 - */  
78 - @OnError  
79 - public void onError(Session session, Throwable error) {  
80 - log.error("发生错误:{},Session ID: {}", error.getMessage(), session.getId());  
81 - }  
82 -  
83 - /**  
84 - * 发送消息,实践表明,每次浏览器刷新,session会发生变化。  
85 - *  
86 - * @param session session  
87 - * @param message 消息  
88 - */  
89 - private static void SendMessage(Session session, String message) throws IOException {  
90 -  
91 - session.getBasicRemote().sendText(String.format("%s (From Server,Session ID=%s)", message, session.getId()));  
92 -  
93 - }  
94 -  
95 - /**  
96 - * 群发消息  
97 - *  
98 - * @param message 消息  
99 - */  
100 - public static void BroadCastInfo(String message) throws IOException {  
101 - for (Session session : SessionSet) {  
102 - if (session.isOpen()) {  
103 - SendMessage(session, message);  
104 - }  
105 - }  
106 - }  
107 -  
108 - /**  
109 - * 指定Session发送消息  
110 - *  
111 - * @param sessionId sessionId  
112 - * @param message 消息  
113 - */  
114 - public static void SendMessage(String sessionId, String message) throws IOException {  
115 - Session session = null;  
116 - for (Session s : SessionSet) {  
117 - if (s.getId().equals(sessionId)) {  
118 - session = s;  
119 - break;  
120 - }  
121 - }  
122 - if (session != null) {  
123 - SendMessage(session, message);  
124 - } else {  
125 - log.warn("没有找到你指定ID的会话:{}", sessionId);  
126 - }  
127 - }  
128 -  
129 -}  
@@ -80,3 +80,9 @@ management: @@ -80,3 +80,9 @@ management:
80 show-details: always 80 show-details: always
81 shutdown: 81 shutdown:
82 enabled: true 82 enabled: true
  83 +
  84 +path:
  85 + # 盘的位置
  86 + disc: H
  87 + # 文件夹的位置,就一个文件夹
  88 + dir: exitExcel