Commit d084ab98 authored by 李洪明's avatar 李洪明

添加上传进出厂记录

parent 323c891f
package com.bme.access.upload.job; package com.bme.access.upload.job;
import com.bme.access.upload.common.HttpUtils; import com.bme.access.upload.common.HttpUtils;
import com.bme.access.upload.module.service.LoginService;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.http.HttpEntity; import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse; import org.apache.http.HttpResponse;
import org.apache.http.util.EntityUtils; import org.apache.http.util.EntityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.EnableScheduling; import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled; import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
...@@ -15,10 +17,12 @@ import org.springframework.stereotype.Component; ...@@ -15,10 +17,12 @@ import org.springframework.stereotype.Component;
public class HeartBeatJob { public class HeartBeatJob {
private final static String HEART_BEAT_URL = "https://dctapi.soszyzg.com/dct/heartbeat"; private final static String HEART_BEAT_URL = "https://dctapi.soszyzg.com/dct/heartbeat";
@Autowired
@Scheduled(cron = "0 0/1 * * * ?") private LoginService loginService;
@Scheduled(cron = "0 */30 * * * ?")
public void heartBeat() { public void heartBeat() {
try { try {
loginService.login();
HttpUtils.sendGet(HEART_BEAT_URL, null, null); HttpUtils.sendGet(HEART_BEAT_URL, null, null);
} catch (Exception e) { } catch (Exception e) {
log.error("心跳协议(每半个小时调用一次): {}", e); log.error("心跳协议(每半个小时调用一次): {}", e);
......
...@@ -74,7 +74,7 @@ public class UploadDataNewTask { ...@@ -74,7 +74,7 @@ public class UploadDataNewTask {
try { try {
transportDateService.uploadTransportDate(); transportDateService.uploadTransportDate();
} catch (Exception e) { } catch (Exception e) {
log.error("上传进出场货物异常: {}", e); log.error("上传货物异常: {}", e);
} }
} }
......
...@@ -45,10 +45,10 @@ public class InAndOutDateService { ...@@ -45,10 +45,10 @@ public class InAndOutDateService {
} }
log.info("本次循环上传大于{}的数据", uploadTime); log.info("本次循环上传大于{}的数据", uploadTime);
String endTime = LocalDateTime.now().minusMinutes(2).format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")); String endTime = LocalDateTime.now().minusMinutes(2).format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
this.getAndUploadInAndOutDate(uploadTime, endTime, Boolean.TRUE); this.getAndUploadInAndOutDate(uploadTime, endTime);
} }
public List<InAndOutDateUrl> getAndUploadInAndOutDate(String startTime, String endTime, Boolean flag) { public void getAndUploadInAndOutDate(String startTime, String endTime) {
log.info("执行进出场记录上传线程"); log.info("执行进出场记录上传线程");
List<InAndOutDateUrl> inAndOutDateUrlList = inAndOutDateUrlMapper.selectInAndOutDateUrl(startTime, endTime); List<InAndOutDateUrl> inAndOutDateUrlList = inAndOutDateUrlMapper.selectInAndOutDateUrl(startTime, endTime);
if (!CollectionUtils.isEmpty(inAndOutDateUrlList)){ if (!CollectionUtils.isEmpty(inAndOutDateUrlList)){
...@@ -65,11 +65,7 @@ public class InAndOutDateService { ...@@ -65,11 +65,7 @@ public class InAndOutDateService {
try { try {
String bodyJson = JSONObject.toJSONString(inAndOutDate); String bodyJson = JSONObject.toJSONString(inAndOutDate);
HttpUtils.sendPost(IN_AND_OUT_DATE_URL, null, null, bodyJson); HttpUtils.sendPost(IN_AND_OUT_DATE_URL, null, null, bodyJson);
if (flag){ dataUploadTimeMapper.updateUploadTimeByType(inAndOutDateUrl.getInOutTime(), 103);
dataUploadTimeMapper.updateUploadTimeByType(inAndOutDateUrl.getInOutTime(), 103);
}
// 防止连接超时
Thread.sleep(50);
} catch (Exception e) { } catch (Exception e) {
log.info("过车记录上传失败,重新上传一次{}", e.getMessage()); log.info("过车记录上传失败,重新上传一次{}", e.getMessage());
try { try {
...@@ -80,23 +76,18 @@ public class InAndOutDateService { ...@@ -80,23 +76,18 @@ public class InAndOutDateService {
inAndOutDateUrl.setMsg(ex.getMessage()); inAndOutDateUrl.setMsg(ex.getMessage());
inAndOutDateUploadFailMapper.insertInAndOutFail(inAndOutDateUrl); inAndOutDateUploadFailMapper.insertInAndOutFail(inAndOutDateUrl);
} finally { } finally {
if (flag){
dataUploadTimeMapper.updateUploadTimeByType(inAndOutDateUrl.getInOutTime(), 103);
}
}
} finally {
if (flag){
dataUploadTimeMapper.updateUploadTimeByType(inAndOutDateUrl.getInOutTime(), 103); dataUploadTimeMapper.updateUploadTimeByType(inAndOutDateUrl.getInOutTime(), 103);
} }
} finally {
dataUploadTimeMapper.updateUploadTimeByType(inAndOutDateUrl.getInOutTime(), 103);
} }
} }
if (!CollectionUtils.isEmpty(inAndOutDateUrlList) && flag){ if (!CollectionUtils.isEmpty(inAndOutDateUrlList)){
log.info("本次循环上传完成,再次更新最后的上传时间{}", inAndOutDateUrlList.get(inAndOutDateUrlList.size() - 1).getInOutTime()); log.info("本次循环上传完成,再次更新最后的上传时间{}", inAndOutDateUrlList.get(inAndOutDateUrlList.size() - 1).getInOutTime());
dataUploadTimeMapper.updateUploadTimeByType(inAndOutDateUrlList.get(inAndOutDateUrlList.size() - 1).getInOutTime(), 103); dataUploadTimeMapper.updateUploadTimeByType(inAndOutDateUrlList.get(inAndOutDateUrlList.size() - 1).getInOutTime(), 103);
} else { } else {
log.info("本次循环无数据上传"); log.info("本次循环无数据上传");
} }
return inAndOutDateUrlList;
} }
private InAndOutDate convertInAndOutDate(InAndOutDateUrl inAndOutDateUrl) { private InAndOutDate convertInAndOutDate(InAndOutDateUrl inAndOutDateUrl) {
......
...@@ -43,10 +43,10 @@ public class TransportDateService { ...@@ -43,10 +43,10 @@ public class TransportDateService {
} }
log.info("本次循环上传大于{}的数据", uploadTime); log.info("本次循环上传大于{}的数据", uploadTime);
String endTime = LocalDateTime.now().minusMinutes(2).format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")); String endTime = LocalDateTime.now().minusMinutes(2).format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
this.getAndUploadTransportDate(uploadTime, endTime, Boolean.TRUE); this.getAndUploadTransportDate(uploadTime, endTime);
} }
public void getAndUploadTransportDate(String startTime, String endTime, Boolean flag) { public void getAndUploadTransportDate(String startTime, String endTime) {
log.info("执行进出厂货物上传"); log.info("执行进出厂货物上传");
List<TransportDate> transportDateList = transportDateMapper.selectTransportDate(startTime, endTime); List<TransportDate> transportDateList = transportDateMapper.selectTransportDate(startTime, endTime);
if (!CollectionUtils.isEmpty(transportDateList)){ if (!CollectionUtils.isEmpty(transportDateList)){
...@@ -63,11 +63,7 @@ public class TransportDateService { ...@@ -63,11 +63,7 @@ public class TransportDateService {
try { try {
String bodyJson = JSONObject.toJSONString(materialInfo); String bodyJson = JSONObject.toJSONString(materialInfo);
HttpUtils.sendPost(CARGO_URL, null, null, bodyJson); HttpUtils.sendPost(CARGO_URL, null, null, bodyJson);
if (flag){ dataUploadTimeMapper.updateUploadTimeByType(transportDate.getInoutTime(), 104);
dataUploadTimeMapper.updateUploadTimeByType(transportDate.getInoutTime(), 104);
}
// 防止连接超时
Thread.sleep(50);
} catch (Exception e) { } catch (Exception e) {
log.info("货物上传失败,重新上传一次{}", e.getMessage()); log.info("货物上传失败,重新上传一次{}", e.getMessage());
try { try {
...@@ -78,17 +74,13 @@ public class TransportDateService { ...@@ -78,17 +74,13 @@ public class TransportDateService {
transportDate.setMsg(ex.getMessage()); transportDate.setMsg(ex.getMessage());
transportDateUploadFailMapper.insertTransportDateFail(transportDate); transportDateUploadFailMapper.insertTransportDateFail(transportDate);
} finally { } finally {
if (flag){
dataUploadTimeMapper.updateUploadTimeByType(transportDate.getInoutTime(), 104);
}
}
} finally {
if (flag){
dataUploadTimeMapper.updateUploadTimeByType(transportDate.getInoutTime(), 104); dataUploadTimeMapper.updateUploadTimeByType(transportDate.getInoutTime(), 104);
} }
} finally {
dataUploadTimeMapper.updateUploadTimeByType(transportDate.getInoutTime(), 104);
} }
} }
if (!CollectionUtils.isEmpty(transportDateList) && flag){ if (!CollectionUtils.isEmpty(transportDateList)){
log.info("本次循环上传完成,再次更新最后的上传时间{}", transportDateList.get(transportDateList.size() - 1).getInoutTime()); log.info("本次循环上传完成,再次更新最后的上传时间{}", transportDateList.get(transportDateList.size() - 1).getInoutTime());
dataUploadTimeMapper.updateUploadTimeByType(transportDateList.get(transportDateList.size() - 1).getInoutTime(), 104); dataUploadTimeMapper.updateUploadTimeByType(transportDateList.get(transportDateList.size() - 1).getInoutTime(), 104);
} else { } else {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment