作者 王勇

初始化进港服务,新舱单

... ... @@ -31,15 +31,15 @@ spring:
# mybatis配置
mybatis:
mapper-locations: classpath:mapper/*.xml
type-aliases-package: com.sunyo.wlpt.cgonms.provide.domain
type-aliases-package: com.sunyo.wlpt.cgonms.arrival.domain
# 日志配置
logging:
config: config/logback-dev.xml
level:
com.sunyo.wlpt.cgonms.provide.mapper: debug
com.sunyo.wlpt.cgonms.arrival.mapper: debug
logback:
appname: cgonms-provide
appname: cgonms-arrival
logdir: ./log
... ...
... ... @@ -3,6 +3,7 @@ package com.sunyo.wlpt.cgonms.arrival.controller;
import com.sunyo.wlpt.cgonms.arrival.domain.*;
import com.sunyo.wlpt.cgonms.arrival.feign.GetCgoAsmFeign;
import com.sunyo.wlpt.cgonms.arrival.feign.GetTransportFeign;
import com.sunyo.wlpt.cgonms.arrival.response.ResultJson;
import com.sunyo.wlpt.cgonms.arrival.response.ResultWs;
import com.sunyo.wlpt.cgonms.arrival.service.*;
import com.sunyo.wlpt.cgonms.arrival.thread.ExitThreadPoolFactory;
... ... @@ -70,10 +71,11 @@ public class NmsController {
final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
@GetMapping("/getInfo")
public void getData(
public ResultJson getData(
@RequestParam(value = "flightDate", required = false) Date flightDate,
@RequestParam(value = "flightNo", required = false) String flightNo,
HttpServletRequest request) {
ResultJson resultJson = new ResultJson();
/* 获取token */
String sid = request.getHeader("Authorization");
log.info("token的值:" + sid);
... ... @@ -160,6 +162,10 @@ public class NmsController {
/*websocket,发送全部数据 */
String resultJs = GsonUtils.toJsonStr(new ResultWs("获取数据,完成", resultList, "200", resultList.size(), resultList.size()));
sendMsgByWebsocket(resultJs, sid);
resultJson.setCode("200");
resultJson.setData(resultList);
return resultJson;
}
/**
... ... @@ -170,7 +176,7 @@ public class NmsController {
* @param threadPool 线程池
* @return
*/
private ResultArrivalData threadJob(ResultArrivalData result, CountDownLatch latch, ThreadPoolExecutor threadPool) {
public ResultArrivalData threadJob(ResultArrivalData result, CountDownLatch latch, ThreadPoolExecutor threadPool) {
Runnable run = new Runnable() {
@Override
public void run() {
... ... @@ -222,7 +228,7 @@ public class NmsController {
/**
* 获取代理人的相关数据
*/
ResultArrivalData asmInfo = new ResultArrivalData();
asmInfo = getCgoAsmFeign.getInfo(result.getWaybillNoMaster());
//设置结算代理人
... ... @@ -234,7 +240,7 @@ public class NmsController {
//设置二级类名称
result.setTwoTypeName(asmInfo.getTwoTypeName());
//设置一级类名称
result.setTypeName(asmInfo.getTypeName());
result.setTypeName(asmInfo.getTypeName());*/
} catch (Exception e) {
latch.countDown();
e.printStackTrace();
... ...
package com.sunyo.wlpt.cgonms.arrival.excle;
import com.sunyo.wlpt.cgonms.arrival.response.ResultJson;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
/**
* @author 子诚
* Description:定时任务每天凌晨4点,删除一周前的excel文件夹下的excel文件
* 时间:2020/6/5 17:11
*/
@RequestMapping("/arrival")
@RestController
public class DeleteExcel {
@Resource
private DeleteExpiredFile deleteExpiredFile;
/**
* 每天凌晨4点,执行定时任务,删除缓存的文件
*
* @return
*/
@Scheduled(cron = "0 0 4 * * ? ")
@GetMapping("/delete")
public ResultJson deleteExcel() {
ResultJson result = new ResultJson();
try {
deleteExpiredFile.deleteExpiredFileTask();
result.setMsg("清除一周前的文件,成功");
result.setCode("200");
} catch (Exception e) {
result.setMsg("清除一周前的文件,失败");
result.setCode("400");
}
return result;
}
}
... ...
package com.sunyo.wlpt.cgonms.arrival.excle;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import java.io.File;
/**
* @author 子诚
* Description:删除静态资源文件夹excel(与src同级)下的一个星期之前的excel文件
* 时间:2020/6/5 16:47
*/
@Slf4j
@Component
public class DeleteExpiredFile {
/**
* 文件夹地址
*/
@Value("${path.dir}")
private String dir;
/**
* 设置时间间隔
*/
@Value("${delete.timeInterval}")
long timeInterval;
public void deleteExpiredFileTask() {
String path = dir + "/";
File file = new File(path);
deleteExpiredFile(file);
}
/**
* 判断是文件还是文件夹?
*
* @param file 文件或者文件夹
*/
private void deleteExpiredFile(File file) {
//如果文件或者文件夹不存在
if (!file.exists()) {
return;
}
// 如果不是文件夹
if (!file.isDirectory()) {
determineExpiredFile(file);
}
// 如果是文件夹,遍历文件夹中的所有文件
else {
for (File f : file.listFiles()) {
deleteExpiredFile(f);
log.info("删除了文件" + f);
}
}
}
/**
* 删除七天(一周)前的所有文件
*
* @param file 文件
*/
private void determineExpiredFile(File file) {
// 取出存在文件最后的操作时间
long lastModifiedTime = file.lastModified();
// 当前时间的时间戳
long currentTime = System.currentTimeMillis();
// 设置时间范围
// long timeInterval = 7 * 24 * 60 * 60 * 1000;
// 删除七天(一周)前的所有文件
if (currentTime - lastModifiedTime > timeInterval) {
file.delete();
}
}
}
... ...
package com.sunyo.wlpt.cgonms.arrival.excle;
import com.sunyo.wlpt.cgonms.arrival.response.ResultJson;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.net.InetAddress;
/**
* @author 子诚
* Description:
* 时间:2020/6/4 19:10
*/
@Slf4j
@RestController
@RequestMapping("/arrival")
public class DownExcel {
@Value("${server.port}")
private String port;
@GetMapping("/downExcel")
public ResultJson downExcel() throws Exception {
ResultJson result = new ResultJson();
//获取当前服务器的ip地址
String ip = InetAddress.getLocalHost().getHostAddress();
String address = "http://" + ip + ":" + port + "/exit/";
result.setCode("200");
result.setMsg(address);
return result;
}
}
... ...
package com.sunyo.wlpt.cgonms.arrival.excle;
import com.sunyo.wlpt.cgonms.arrival.domain.ResultArrivalData;
import com.sunyo.wlpt.cgonms.arrival.response.ResultJson;
import lombok.extern.slf4j.Slf4j;
import org.apache.poi.hssf.usermodel.*;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.UUID;
/**
* @author 子诚
* Description:导入Excel到静态资源文件夹excel(与src同级)
* 时间:2020/5/29 10:04
*/
@Slf4j
@RestController
@RequestMapping("/arrival")
public class ExitExcel {
@Value("${path.dir}")
private String dir;
@PostMapping("/excel")
public ResultJson getExit(@RequestBody List<ResultArrivalData> exitInfoList, HttpServletResponse httpServletResponse) {
ResultJson result = new ResultJson();
String title = exportExcel(exitInfoList, httpServletResponse);
result.setMsg(title);
result.setCode("200");
return result;
}
private String exportExcel(List<ResultArrivalData> exitInfoList, HttpServletResponse response) {
// 设置文件名
String title = "";
try {
// 创建工作簿
HSSFWorkbook workbook = new HSSFWorkbook();
// 创建表
HSSFSheet sheet = workbook.createSheet("export");
// 创建行
HSSFRow row = sheet.createRow(0);
// 创建单元格样式
HSSFCellStyle cellStyle = workbook.createCellStyle();
// 表头
String[] head = {
"运单号",
"件数",
"重量",
"计费重量",
"体积",
"品名",
"二级品类",
"一级品类",
"货物目的站",
"货物目的国家/地区",
"所属洲",
"航空公司",
"航班号",
"航班日期",
"航班时间",
"航班计划日期",
"航班计划时间",
"航段",
"机号",
"机型",
"最大业载",
"运单发货人",
"运单收货人",
"订舱代理人",
"结算代理人",
"自定义项"
};
HSSFCell cell;
// 设置表头
for (Integer i = 0; i < head.length; i++) {
cell = row.createCell(i);
cell.setCellValue(head[i]);
cell.setCellStyle(cellStyle);
// 设置单元格宽度
// 256*width+184
sheet.setColumnWidth(i, 4000);
if (i == 14 || i == 16) {
sheet.setColumnWidth(i, 6000);
}
if (i == 21 || i == 22) {
sheet.setColumnWidth(i, 10000);
}
}
// 设置表格内容
// for (Integer i = 0; i < exitInfoList.size(); i++) {
// row = sheet.createRow(i + 1);
// ResultArrivalData resultExitData = exitInfoList.get(i);
// // 这里是内容设置,替换则自己的数据即可
// String[] excelTitle = new String[27];
//
// //取出数据,运单号
// excelTitle[0] = resultExitData.getWaybillNoMaster();
// //件数
// excelTitle[1] = resultExitData.getTallyTotalPiece();
// //重量
// excelTitle[2] = resultExitData.getTallyTotalWeight();
// //计费重量
// excelTitle[3] = String.valueOf(resultExitData.getTotalGrossWeightMeasure());
// //体积
// excelTitle[4] = String.valueOf(resultExitData.getVolumeMeasure());
// //品名
// excelTitle[5] = resultExitData.getSdCargoName();
// //二级品类
// excelTitle[6] = resultExitData.getTwoTypeName();
// //一级品类
// excelTitle[7] = resultExitData.getTypeName();
// //货物目的站
// excelTitle[8] = resultExitData.getAimStation();
// //货物目的国家/地区
// excelTitle[9] = resultExitData.getCountry();
// //所属洲
// excelTitle[10] = resultExitData.getAreaDescChn();
// //航空公司
// excelTitle[11] = resultExitData.getAirCompany();
// //航班号
// excelTitle[12] = resultExitData.getFlightNo();
// //航班日期
// excelTitle[13] = isNullShort(resultExitData.getFlightDate());
// //航班时间
// excelTitle[14] = isNullLong(resultExitData.getFlightTime());
// //航班计划日期
// excelTitle[15] = isNullShort(resultExitData.getFlightPlanDate());
// //航班计划时间
// excelTitle[16] = isNullLong(resultExitData.getFlightPlanTime());
// //航段
// excelTitle[17] = resultExitData.getSegment();
// //机号
// excelTitle[18] = resultExitData.getCfNo();
// //机型
// excelTitle[19] = resultExitData.getCfTp();
// //最大业载
// excelTitle[20] = "";
// //运单发货人
// excelTitle[21] = resultExitData.getShipperName();
// //运单收货人
// excelTitle[22] = resultExitData.getConsigneeName();
// //订舱代理人(代理人全称)
// excelTitle[23] = resultExitData.getOrderName();
// //结算代理人(代理人全程)
// excelTitle[24] = resultExitData.getCountName();
// //自定义项
// excelTitle[25] = "";
//
// for (Integer j = 0; j < excelTitle.length; j++) {
// row.createCell(j).setCellValue(excelTitle[j]);
// }
// }
String file_name = UUID.randomUUID().toString().replaceAll("-", "");
// 设置文件名
title = file_name + ".xls";
String filePath = dir + "/" + title;
/**
* 创建文件夹
*/
File testFile = new File(filePath);
File fileParent = testFile.getParentFile();
if (!fileParent.exists()) {
// 能创建多级目录
fileParent.mkdirs();
}
try {
FileOutputStream fos = new FileOutputStream(filePath);
workbook.write(fos);
fos.flush();
fos.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
} catch (Exception e) {
e.printStackTrace();
}
return title;
}
/**
* 时间戳转换成字符串
*/
public static String getDateToLong(long time) {
Date d = new Date(time);
SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
return sf.format(d);
}
/**
* 时间戳转换成字符串
*/
public static String getDateToShort(long time) {
Date d = new Date(time);
SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd");
return sf.format(d);
}
/**
* 判断传递来的时间,是否为空,为null,则返回"",不为空,则规范格式 "yyyy-MM-dd"
*
* @param time Date类型时间
* @return
*/
public static String isNullShort(Date time) {
if (null == time) {
return "";
} else {
return getDateToShort(time.getTime());
}
}
/**
* 判断传递来的时间,是否为空,为null,则返回"",不为空,则规范格式 "yyyy-MM-dd HH:mm:ss"
*
* @param time Date类型时间
* @return
*/
public static String isNullLong(Date time) {
if (null == time) {
return "";
} else {
return getDateToLong(time.getTime());
}
}
}
... ...
... ... @@ -3,26 +3,26 @@
<mapper namespace="com.sunyo.wlpt.cgonms.arrival.mapper.ResultArrivalDataMapper">
<resultMap id="BaseResultMap" type="com.sunyo.wlpt.cgonms.arrival.domain.ResultArrivalData">
<!--@mbg.generated-->
<!--@Table ARRIVEDMASTER-->
<!--@Table ORIGINMANIFESTMASTER-->
<result column="AUTOID" jdbcType="VARCHAR" property="autoId"/>
<result column="WAYBILLNOMASTER" jdbcType="VARCHAR" property="waybillNoMaster"/>
<result column="FLIGHTNO" jdbcType="VARCHAR" property="flightNo"/>
<result column="FLIGHTDATE" jdbcType="TIMESTAMP" property="flightDate"/>
<result column="FLIGHT_DATE" jdbcType="TIMESTAMP" property="flightDate"/>
<result column="ORIGINATINGSTATION" jdbcType="VARCHAR" property="originatingStation"/>
<result column="DESTINATIONSTATION" jdbcType="VARCHAR" property="destinationStation"/>
<result column="TOTALPIECEQUANTITY" jdbcType="VARCHAR" property="totalPiece"/>
<result column="ARRIVEDTOTALWEIGHT" jdbcType="VARCHAR" property="totalWeight"/>
<result column="TOTALPIECE" jdbcType="VARCHAR" property="totalPiece"/>
<result column="TOTALWEIGHT" jdbcType="VARCHAR" property="totalWeight"/>
</resultMap>
<sql id="Base_Column_List">
<!--@mbg.generated-->
AUTOID, WAYBILLNOMASTER, FLIGHTNO, FLIGHTDATE, ORIGINATINGSTATION, DESTINATIONSTATION,
TOTALPIECEQUANTITY, ARRIVEDTOTALWEIGHT
AUTOID, WAYBILLNOMASTER, FLIGHTNO, FLIGHT_DATE, ORIGINATINGSTATION, DESTINATIONSTATION,
TOTALPIECE, TOTALWEIGHT
</sql>
<select id="getResultArrivalDataInfo" parameterType="com.sunyo.wlpt.cgonms.arrival.domain.ResultArrivalData"
resultMap="BaseResultMap">
select
<include refid="Base_Column_List"/>
from ARRIVEDMASTER
from ORIGINMANIFESTMASTER
where 1=1
<!-- 航班号 -->
<if test="flightNo!=null and flightNo!=''">
... ... @@ -30,7 +30,7 @@
</if>
<!-- 航班日期 -->
<if test="flightDate!=null">
AND FLIGHTDATE = #{flightDate,jdbcType=DATE}
AND FLIGHT_DATE = #{flightDate,jdbcType=DATE}
</if>
</select>
</mapper>
... ...