Commit 85400688 authored by zhuangzhuang's avatar zhuangzhuang

3.23--修改数据查询的逻辑以及绑定tdl,解绑tdl

parent 497ef35e
...@@ -14,9 +14,9 @@ public class LocationMessageVo { ...@@ -14,9 +14,9 @@ public class LocationMessageVo {
private String endCity; private String endCity;
private String startTime; private Long startTime;
private String endTime; private Long endTime;
private Long alarmTime; private Long alarmTime;
...@@ -68,19 +68,19 @@ public class LocationMessageVo { ...@@ -68,19 +68,19 @@ public class LocationMessageVo {
this.endCity = endCity; this.endCity = endCity;
} }
public String getStartTime() { public Long getStartTime() {
return startTime; return startTime;
} }
public void setStartTime(String startTime) { public void setStartTime(Long startTime) {
this.startTime = startTime; this.startTime = startTime;
} }
public String getEndTime() { public Long getEndTime() {
return endTime; return endTime;
} }
public void setEndTime(String endTime) { public void setEndTime(Long endTime) {
this.endTime = endTime; this.endTime = endTime;
} }
......
package com.example.tdl.domain.vo;
public class ResultAlarmLog {
private String transportationNo;
private String routeName;
private String description;
private Float data;
private Long alarmTime;
public String getTransportationNo() {
return transportationNo;
}
public void setTransportationNo(String transportationNo) {
this.transportationNo = transportationNo;
}
public String getRouteName() {
return routeName;
}
public void setRouteName(String routeName) {
this.routeName = routeName;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public Float getData() {
return data;
}
public void setData(Float data) {
this.data = data;
}
public Long getAlarmTime() {
return alarmTime;
}
public void setAlarmTime(Long alarmTime) {
this.alarmTime = alarmTime;
}
}
...@@ -6,12 +6,12 @@ public class ResultCircuit { ...@@ -6,12 +6,12 @@ public class ResultCircuit {
private String startCity; private String startCity;
private String startTime; private Long startTime;
private String endCity; private String endCity;
private String endTime; private Long endTime;
private String gatewaySN; private String gatewaySN;
...@@ -19,7 +19,7 @@ public class ResultCircuit { ...@@ -19,7 +19,7 @@ public class ResultCircuit {
private String TDLSN; private String TDLSN;
private String BatteryVoltage; private String batteryVoltage;
private String lastTime; private String lastTime;
...@@ -43,11 +43,11 @@ public class ResultCircuit { ...@@ -43,11 +43,11 @@ public class ResultCircuit {
this.startCity = startCity; this.startCity = startCity;
} }
public String getStartTime() { public Long getStartTime() {
return startTime; return startTime;
} }
public void setStartTime(String startTime) { public void setStartTime(Long startTime) {
this.startTime = startTime; this.startTime = startTime;
} }
...@@ -59,11 +59,11 @@ public class ResultCircuit { ...@@ -59,11 +59,11 @@ public class ResultCircuit {
this.endCity = endCity; this.endCity = endCity;
} }
public String getEndTime() { public Long getEndTime() {
return endTime; return endTime;
} }
public void setEndTime(String endTime) { public void setEndTime(Long endTime) {
this.endTime = endTime; this.endTime = endTime;
} }
...@@ -92,11 +92,11 @@ public class ResultCircuit { ...@@ -92,11 +92,11 @@ public class ResultCircuit {
} }
public String getBatteryVoltage() { public String getBatteryVoltage() {
return BatteryVoltage; return batteryVoltage;
} }
public void setBatteryVoltage(String batteryVoltage) { public void setBatteryVoltage(String batteryVoltage) {
BatteryVoltage = batteryVoltage; this.batteryVoltage = batteryVoltage;
} }
public String getLastTime() { public String getLastTime() {
......
...@@ -15,7 +15,7 @@ public class ResultCircuitVo { ...@@ -15,7 +15,7 @@ public class ResultCircuitVo {
private String startAddress; private String startAddress;
private String startTime; private Long startTime;
private String endLongitude; private String endLongitude;
...@@ -25,7 +25,7 @@ public class ResultCircuitVo { ...@@ -25,7 +25,7 @@ public class ResultCircuitVo {
private String endAddress; private String endAddress;
private String endTime; private Long endTime;
private String transport; private String transport;
...@@ -43,34 +43,34 @@ public class ResultCircuitVo { ...@@ -43,34 +43,34 @@ public class ResultCircuitVo {
private String remark; private String remark;
private String createTime; private Long createTime;
private String evaluate; private String evaluate;
private String evaluateRemark; private String evaluateRemark;
public String getEvaluate() { public String getTransportationNo() {
return evaluate; return transportationNo;
} }
public void setEvaluate(String evaluate) { public void setTransportationNo(String transportationNo) {
this.evaluate = evaluate; this.transportationNo = transportationNo;
} }
public String getEvaluateRemark() { public String getRouteNumber() {
return evaluateRemark; return routeNumber;
} }
public void setEvaluateRemark(String evaluateRemark) { public void setRouteNumber(String routeNumber) {
this.evaluateRemark = evaluateRemark; this.routeNumber = routeNumber;
} }
public String getCreateTime() { public String getRouteName() {
return createTime; return routeName;
} }
public void setCreateTime(String createTime) { public void setRouteName(String routeName) {
this.createTime = createTime; this.routeName = routeName;
} }
public String getStartLongitude() { public String getStartLongitude() {
...@@ -89,6 +89,14 @@ public class ResultCircuitVo { ...@@ -89,6 +89,14 @@ public class ResultCircuitVo {
this.startLatitude = startLatitude; this.startLatitude = startLatitude;
} }
public String getStartCity() {
return startCity;
}
public void setStartCity(String startCity) {
this.startCity = startCity;
}
public String getStartAddress() { public String getStartAddress() {
return startAddress; return startAddress;
} }
...@@ -97,6 +105,14 @@ public class ResultCircuitVo { ...@@ -97,6 +105,14 @@ public class ResultCircuitVo {
this.startAddress = startAddress; this.startAddress = startAddress;
} }
public Long getStartTime() {
return startTime;
}
public void setStartTime(Long startTime) {
this.startTime = startTime;
}
public String getEndLongitude() { public String getEndLongitude() {
return endLongitude; return endLongitude;
} }
...@@ -113,6 +129,14 @@ public class ResultCircuitVo { ...@@ -113,6 +129,14 @@ public class ResultCircuitVo {
this.endLatitude = endLatitude; this.endLatitude = endLatitude;
} }
public String getEndCity() {
return endCity;
}
public void setEndCity(String endCity) {
this.endCity = endCity;
}
public String getEndAddress() { public String getEndAddress() {
return endAddress; return endAddress;
} }
...@@ -121,6 +145,14 @@ public class ResultCircuitVo { ...@@ -121,6 +145,14 @@ public class ResultCircuitVo {
this.endAddress = endAddress; this.endAddress = endAddress;
} }
public Long getEndTime() {
return endTime;
}
public void setEndTime(Long endTime) {
this.endTime = endTime;
}
public String getTransport() { public String getTransport() {
return transport; return transport;
} }
...@@ -129,6 +161,14 @@ public class ResultCircuitVo { ...@@ -129,6 +161,14 @@ public class ResultCircuitVo {
this.transport = transport; this.transport = transport;
} }
public String getAlarmType() {
return alarmType;
}
public void setAlarmType(String alarmType) {
this.alarmType = alarmType;
}
public String getBoxNo() { public String getBoxNo() {
return boxNo; return boxNo;
} }
...@@ -161,83 +201,43 @@ public class ResultCircuitVo { ...@@ -161,83 +201,43 @@ public class ResultCircuitVo {
this.transportationType = transportationType; this.transportationType = transportationType;
} }
public String getRemark() { public int getCircuitState() {
return remark; return circuitState;
}
public void setRemark(String remark) {
this.remark = remark;
}
public String getTransportationNo() {
return transportationNo;
}
public void setTransportationNo(String transportationNo) {
this.transportationNo = transportationNo;
}
public String getRouteNumber() {
return routeNumber;
}
public void setRouteNumber(String routeNumber) {
this.routeNumber = routeNumber;
}
public String getRouteName() {
return routeName;
}
public void setRouteName(String routeName) {
this.routeName = routeName;
}
public String getStartCity() {
return startCity;
}
public void setStartCity(String startCity) {
this.startCity = startCity;
}
public String getStartTime() {
return startTime;
} }
public void setStartTime(String startTime) { public void setCircuitState(int circuitState) {
this.startTime = startTime; this.circuitState = circuitState;
} }
public String getEndCity() { public String getRemark() {
return endCity; return remark;
} }
public void setEndCity(String endCity) { public void setRemark(String remark) {
this.endCity = endCity; this.remark = remark;
} }
public String getEndTime() { public Long getCreateTime() {
return endTime; return createTime;
} }
public void setEndTime(String endTime) { public void setCreateTime(Long createTime) {
this.endTime = endTime; this.createTime = createTime;
} }
public String getAlarmType() { public String getEvaluate() {
return alarmType; return evaluate;
} }
public void setAlarmType(String alarmType) { public void setEvaluate(String evaluate) {
this.alarmType = alarmType; this.evaluate = evaluate;
} }
public int getCircuitState() { public String getEvaluateRemark() {
return circuitState; return evaluateRemark;
} }
public void setCircuitState(int circuitState) { public void setEvaluateRemark(String evaluateRemark) {
this.circuitState = circuitState; this.evaluateRemark = evaluateRemark;
} }
} }
\ No newline at end of file
...@@ -2,6 +2,7 @@ package com.example.tdl.mapper; ...@@ -2,6 +2,7 @@ package com.example.tdl.mapper;
import com.example.tdl.domain.vo.AddAlarmLogVo; import com.example.tdl.domain.vo.AddAlarmLogVo;
import com.example.tdl.domain.vo.AlarmLogVo; import com.example.tdl.domain.vo.AlarmLogVo;
import com.example.tdl.domain.vo.ResultAlarmLog;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
import java.util.List; import java.util.List;
...@@ -17,7 +18,7 @@ public interface AlarmLogMapper { ...@@ -17,7 +18,7 @@ public interface AlarmLogMapper {
//新增报警数据 //新增报警数据
int addAlarmLog(AddAlarmLogVo addAlarmLogVo); int addAlarmLog(AddAlarmLogVo addAlarmLogVo);
List<AlarmLogVo> getByTransportationNo(String transportationNo); List<ResultAlarmLog> getByTransportationNo(String transportationNo);
Integer getCount(); Integer getCount();
} }
package com.example.tdl.mapper;
import com.example.tdl.domain.vo.ResultGatewayVo;
import org.apache.ibatis.annotations.Mapper;
@Mapper
public interface TDLLogMapper {
ResultGatewayVo getByNo(String transportationNo);
}
...@@ -11,6 +11,7 @@ import com.google.gson.Gson; ...@@ -11,6 +11,7 @@ import com.google.gson.Gson;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
import com.google.gson.JsonParser; import com.google.gson.JsonParser;
import com.google.gson.JsonSyntaxException; import com.google.gson.JsonSyntaxException;
import org.apache.commons.lang3.StringUtils;
import org.eclipse.paho.client.mqttv3.*; import org.eclipse.paho.client.mqttv3.*;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.expression.spel.ast.NullLiteral; import org.springframework.expression.spel.ast.NullLiteral;
...@@ -179,7 +180,7 @@ public class MqttListener implements MqttCallback { ...@@ -179,7 +180,7 @@ public class MqttListener implements MqttCallback {
//checkIn数据解析,true即发送休眠信息;false发送config信息 //checkIn数据解析,true即发送休眠信息;false发送config信息
public Integer parseData(String message,String SN,String Type){ public Integer parseData(String message,String SN,String Type){
CheckInVo checkInVo = new Gson().fromJson(message,CheckInVo.class); CheckInVo checkInVo = new Gson().fromJson(message,CheckInVo.class);
if(checkInVo.getDevList().size() == 0){ if(StringUtils.isEmpty(checkInVo.getDevList()==null ? "" :checkInVo.getDevList().toString())){
return 1;//重发 return 1;//重发
} }
//有设备信息 //有设备信息
......
...@@ -2,6 +2,7 @@ package com.example.tdl.service; ...@@ -2,6 +2,7 @@ package com.example.tdl.service;
import com.example.tdl.domain.vo.AddAlarmLogVo; import com.example.tdl.domain.vo.AddAlarmLogVo;
import com.example.tdl.domain.vo.AlarmLogVo; import com.example.tdl.domain.vo.AlarmLogVo;
import com.example.tdl.domain.vo.ResultAlarmLog;
import com.example.tdl.mapper.AlarmLogMapper; import com.example.tdl.mapper.AlarmLogMapper;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
...@@ -26,7 +27,7 @@ public class AlarmLogService { ...@@ -26,7 +27,7 @@ public class AlarmLogService {
return alarmLogMapper.addAlarmLog(addAlarmLogVo); return alarmLogMapper.addAlarmLog(addAlarmLogVo);
} }
public List<AlarmLogVo> getByTransportationNo(String transportationNo){ public List<ResultAlarmLog> getByTransportationNo(String transportationNo){
return alarmLogMapper.getByTransportationNo(transportationNo); return alarmLogMapper.getByTransportationNo(transportationNo);
} }
......
package com.example.tdl.service;
import com.example.tdl.domain.vo.ResultGatewayVo;
import com.example.tdl.mapper.TDLLogMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
public class TDLLogService {
@Autowired
private TDLLogMapper tdlLogMapper;
public ResultGatewayVo getByNo(String transportationNo){
return tdlLogMapper.getByNo(transportationNo);
}
}
...@@ -6,6 +6,7 @@ import org.springframework.stereotype.Service; ...@@ -6,6 +6,7 @@ import org.springframework.stereotype.Service;
@Service @Service
public class InfoRedisService extends RedisService { public class InfoRedisService extends RedisService {
@SuppressWarnings({ "unchecked", "rawtypes" }) @SuppressWarnings({ "unchecked", "rawtypes" })
@Autowired @Autowired
public InfoRedisService(RedisTemplate infoRedisTemplate) { public InfoRedisService(RedisTemplate infoRedisTemplate) {
......
...@@ -230,7 +230,7 @@ public class CircuitController { ...@@ -230,7 +230,7 @@ public class CircuitController {
} }
if (StringUtils.isEmpty(addCircuitVo.getContainerNo())){ if (StringUtils.isEmpty(addCircuitVo.getContainerNo())){
fb.setCode(0); fb.setCode(0);
fb.setMessage("集装箱号不能为空"); fb.setMessage("集装箱号/车牌号不能为空");
return gson.toJson(fb); return gson.toJson(fb);
} }
if (StringUtils.isEmpty(addCircuitVo.getDeliveryAddress())){ if (StringUtils.isEmpty(addCircuitVo.getDeliveryAddress())){
...@@ -506,7 +506,7 @@ public class CircuitController { ...@@ -506,7 +506,7 @@ public class CircuitController {
} }
if (StringUtils.isEmpty(updateCircuitInfo.getContainerNo())){ if (StringUtils.isEmpty(updateCircuitInfo.getContainerNo())){
fb.setCode(0); fb.setCode(0);
fb.setMessage("集装箱号不能为空"); fb.setMessage("集装箱号/车牌号不能为空");
return gson.toJson(fb); return gson.toJson(fb);
} }
if (StringUtils.isEmpty(updateCircuitInfo.getDeliveryAddress())){ if (StringUtils.isEmpty(updateCircuitInfo.getDeliveryAddress())){
......
...@@ -6,20 +6,19 @@ import com.alibaba.fastjson.JSONObject; ...@@ -6,20 +6,19 @@ import com.alibaba.fastjson.JSONObject;
import com.example.tdl.domain.dto.CommFeedback; import com.example.tdl.domain.dto.CommFeedback;
import com.example.tdl.domain.vo.*; import com.example.tdl.domain.vo.*;
import com.example.tdl.service.*; import com.example.tdl.service.*;
import com.example.tdl.service.redis.InfoRedisService;
import com.example.tdl.service.redis.RealRedisService; import com.example.tdl.service.redis.RealRedisService;
import com.example.tdl.service.redis.RedisService;
import com.google.gson.Gson; import com.google.gson.Gson;
import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams; import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.influxdb.dto.Query; import org.influxdb.dto.Query;
import org.influxdb.dto.QueryResult; import org.influxdb.dto.QueryResult;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
...@@ -28,6 +27,7 @@ import org.springframework.data.influxdb.InfluxDBTemplate; ...@@ -28,6 +27,7 @@ import org.springframework.data.influxdb.InfluxDBTemplate;
import java.text.ParseException; import java.text.ParseException;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.*; import java.util.*;
@RestController @RestController
...@@ -38,9 +38,6 @@ public class DataController { ...@@ -38,9 +38,6 @@ public class DataController {
CommFeedback fb = new CommFeedback(); CommFeedback fb = new CommFeedback();
@Autowired
private GatewayService gatewayService;
@Autowired @Autowired
private TDLDeviceService tdlDeviceService; private TDLDeviceService tdlDeviceService;
...@@ -50,6 +47,9 @@ public class DataController { ...@@ -50,6 +47,9 @@ public class DataController {
@Autowired @Autowired
private RealRedisService realRedisService; private RealRedisService realRedisService;
@Autowired
private InfoRedisService infoRedisService;
@Autowired @Autowired
private InfluxDBTemplate influxDBTemplate; private InfluxDBTemplate influxDBTemplate;
...@@ -59,6 +59,9 @@ public class DataController { ...@@ -59,6 +59,9 @@ public class DataController {
@Autowired @Autowired
private CircuitService circuitService; private CircuitService circuitService;
@Autowired
private TDLLogService tdlLogService;
private final static String database ="original"; private final static String database ="original";
//获取实时数据 //获取实时数据
...@@ -126,28 +129,86 @@ public class DataController { ...@@ -126,28 +129,86 @@ public class DataController {
public Object getLocation(@RequestBody String transportationNo){ public Object getLocation(@RequestBody String transportationNo){
JSONObject jsonObject= JSON.parseObject(transportationNo); JSONObject jsonObject= JSON.parseObject(transportationNo);
transportationNo=jsonObject.getString("transportationNo"); transportationNo=jsonObject.getString("transportationNo");
//获取gateway的信息 //根据运输编号获取线路信息
ResultGatewayVo gatewayVo = circuitService.getByNo(transportationNo); ResultCircuitVo resultCircuitVo = circuitService.getByTransportationNo(transportationNo);
if(gatewayVo==null){ if(resultCircuitVo.getEndTime() !=0 && infoRedisService.hasHashKey("TransportConfig",transportationNo)){
fb.setCode(0); Object ret = infoRedisService.getHash("TransportConfig",transportationNo);
fb.setMessage("该线路未绑定设备"); return ret;
return gson.toJson(fb); }else{
} //获取gateway的信息
String device = gatewayVo.getType() +"_" +gatewayVo.getSN(); ResultGatewayVo gatewayVo = new ResultGatewayVo();
//获取tdl信息 if(resultCircuitVo.getEndTime() == 0){
// List<String> devList = tdlDeviceService.getByGatewaySN(gatewayVo.getSN(),gatewayVo.getType()); gatewayVo = circuitService.getByNo(transportationNo);
String sql = "SELECT \"lng\",\"lat\" FROM \"tdl_policy\".\""+device+"\"ORDER BY time "; }else{
QueryResult queryResult = influxDBTemplate.query(new Query(sql,database)); gatewayVo = tdlLogService.getByNo(transportationNo);
//解析经纬度数据 }
List<LocationDataVo> locationDataVos = new ArrayList<>(); if(gatewayVo==null){
if(queryResult.getResults().get(0).getSeries() != null){ fb.setCode(0);
locationDataVos=getLocation(queryResult); fb.setMessage("该线路未绑定设备");
return gson.toJson(fb);
}
String device = gatewayVo.getType() +"_" +gatewayVo.getSN();
Long startTime = resultCircuitVo.getStartTime() *1000000l;
//获取tdl信息
String sql = "SELECT \"lng\",\"lat\" FROM \"tdl_policy\".\""+device+"\"where time >= "+startTime +" ORDER BY time ";
QueryResult queryResult = influxDBTemplate.query(new Query(sql,database));
//解析经纬度数据
List<LocationDataVo> locationDataVos = new ArrayList<>();
if(queryResult.getResults().get(0).getSeries() != null){
locationDataVos=getLocation(queryResult);
}
//获取震动的数据
String sql2 = "SELECT \"b\" FROM \"tdl_policy\".\""+device+"\"where time >= "+startTime +" ORDER BY time";
QueryResult queryResult2 = influxDBTemplate.query(new Query(sql2,database));
List<String> timeList = new ArrayList<>();
if(queryResult2.getResults().get(0).getSeries() != null){
//获取震动的时间戳
timeList = getTime(queryResult2);
}
//获取震动数据的坐标
String sql3 ="";
for(String time : timeList){
Long t = Long.valueOf(time) *1000000l;
sql3 = "SELECT \"lng\",\"lat\" FROM \"tdl_policy\".\""+device+"\" where time >= "+startTime +" and time<="+ t +" ORDER BY time desc limit 1;" +sql3;
}
QueryResult queryResult3 = influxDBTemplate.query(new Query(sql3,database));
List<String> time= new ArrayList<>();
if(queryResult3.getResults() !=null){
time = getShockLocation(queryResult3);
}
List<LocationDataVo> locationDataVoList =new ArrayList<>();
for(LocationDataVo locationDataVo :locationDataVos){
if(time.contains(locationDataVo.getTime())){
locationDataVo.setError(1);
locationDataVoList.add(locationDataVo);
}else{
locationDataVo.setError(0);
locationDataVoList.add(locationDataVo);
}
}
//如果是已经完结保存到redis中
if(resultCircuitVo.getEndTime() != 0){
infoRedisService.setHash("TransportConfig",transportationNo,locationDataVoList.toString(),60*30);
}
return gson.toJson(locationDataVoList);
} }
return gson.toJson(locationDataVos);
} }
//根据运输编号获取路线以及设备信息 //根据运输编号获取路线以及设备信息
@ApiOperation(value = "获取路线以及设备信息",notes = "获取路线以及设备信息" +
"transportationNo:运输编号" +
"startCity:启运城市" +
"startTime:开始时间" +
"endCity:目的城市" +
"endTime:结束时间(未结束为\"\")" +
"gatewaySN:网关编号" +
"battery:网关点量" +
"TDLSN:tdl编号" +
"batteryVoltage:tdl电压" +
"lastTime:运输时长(未结束为\"\")" +
"circuitState:运输状态(0--未开始,1--运输中,2--完成)" +
"remark:备注信息")
@PostMapping("/getCircuit") @PostMapping("/getCircuit")
@ApiImplicitParams({ @ApiImplicitParams({
@ApiImplicitParam(paramType="header", name = "Account_token", value = "token", required = true, dataType = "String"), @ApiImplicitParam(paramType="header", name = "Account_token", value = "token", required = true, dataType = "String"),
...@@ -162,16 +223,17 @@ public class DataController { ...@@ -162,16 +223,17 @@ public class DataController {
resultCircuit.setStartCity(resultCircuitVo.getStartCity()); resultCircuit.setStartCity(resultCircuitVo.getStartCity());
resultCircuit.setStartTime(resultCircuitVo.getStartTime()); resultCircuit.setStartTime(resultCircuitVo.getStartTime());
resultCircuit.setEndCity(resultCircuitVo.getEndCity()); resultCircuit.setEndCity(resultCircuitVo.getEndCity());
if(StringUtils.isEmpty(resultCircuitVo.getEndTime())){ ResultGatewayVo gatewayVo = new ResultGatewayVo();
resultCircuit.setEndTime(""); if(resultCircuitVo.getEndTime() == 0){
resultCircuit.setLastTime(""); resultCircuit.setEndTime(null);
resultCircuit.setLastTime(null);
gatewayVo = circuitService.getByNo(transportationNo);
}else{ }else{
resultCircuit.setEndTime(resultCircuitVo.getEndTime()); resultCircuit.setEndTime(resultCircuitVo.getEndTime());
//int i = differentDaysByMillisecond(Long.valueOf(resultCircuitVo.getStartTime()),Long.valueOf(resultCircuitVo.getEndTime())) +1; resultCircuit.setLastTime(getDistanceTime(resultCircuit.getStartTime(),resultCircuit.getEndTime()));
resultCircuit.setLastTime(3+"days"); gatewayVo = tdlLogService.getByNo(transportationNo);
} }
//获取gateway的信息 //获取gateway的信息
ResultGatewayVo gatewayVo = circuitService.getByNo(transportationNo);
if(gatewayVo==null){ if(gatewayVo==null){
fb.setCode(0); fb.setCode(0);
fb.setMessage("该线路未绑定设备"); fb.setMessage("该线路未绑定设备");
...@@ -179,7 +241,9 @@ public class DataController { ...@@ -179,7 +241,9 @@ public class DataController {
} }
resultCircuit.setGatewaySN(gatewayVo.getSN()); resultCircuit.setGatewaySN(gatewayVo.getSN());
String device = gatewayVo.getType() +"_" +gatewayVo.getSN(); String device = gatewayVo.getType() +"_" +gatewayVo.getSN();
String sql = "SELECT \"battery\" FROM \"tdl_policy\".\""+device+"\" ORDER BY time desc limit 1"; Long startTime = resultCircuitVo.getStartTime() *1000000l;
//获取tdl信息
String sql = "SELECT \"battery\" FROM \"tdl_policy\".\""+device+"\" where time >= "+startTime +" ORDER BY time desc limit 1";
QueryResult queryResult = influxDBTemplate.query(new Query(sql,database)); QueryResult queryResult = influxDBTemplate.query(new Query(sql,database));
if(queryResult.getResults().get(0).getSeries() != null){ if(queryResult.getResults().get(0).getSeries() != null){
List<List<Object>> values = getValues(queryResult); List<List<Object>> values = getValues(queryResult);
...@@ -198,7 +262,7 @@ public class DataController { ...@@ -198,7 +262,7 @@ public class DataController {
return gson.toJson(fb); return gson.toJson(fb);
} }
for(int i = 0;i<devList.size();i++){ for(int i = 0;i<devList.size();i++){
String sql2 = "SELECT \"b\" FROM \"tdl_policy\".\""+device+"\" where \"tdl\"=\'tdl-"+devList.get(i)+"\' ORDER BY time desc limit 1"; String sql2 = "SELECT \"b\" FROM \"tdl_policy\".\""+device+"\" where \"tdl\"=\'tdl-"+devList.get(i)+"\'and time >= "+startTime +" ORDER BY time desc limit 1";
QueryResult queryResult2 = influxDBTemplate.query(new Query(sql2,database)); QueryResult queryResult2 = influxDBTemplate.query(new Query(sql2,database));
if(queryResult2.getResults().get(0).getSeries() != null){ if(queryResult2.getResults().get(0).getSeries() != null){
List<List<Object>> values = getValues(queryResult2); List<List<Object>> values = getValues(queryResult2);
...@@ -208,12 +272,17 @@ public class DataController { ...@@ -208,12 +272,17 @@ public class DataController {
} }
} }
} }
resultCircuit.setCircuitState(resultCircuitVo.getCircuitState());
return gson.toJson(resultCircuit); return gson.toJson(resultCircuit);
} }
//获取温度数据 //获取温度数据
@ApiOperation(value = "获取温度数据",notes = "获取温度数据") @ApiOperation(value = "获取温度数据",notes = "获取温度数据" +
"TDLSN:tdl编号" +
"temperatureDataVos:" +
"time:时间" +
"value:温度数据")
@PostMapping("/getTemperature") @PostMapping("/getTemperature")
@ApiImplicitParams({ @ApiImplicitParams({
@ApiImplicitParam(paramType="header", name = "Account_token", value = "token", required = true, dataType = "String"), @ApiImplicitParam(paramType="header", name = "Account_token", value = "token", required = true, dataType = "String"),
...@@ -221,11 +290,18 @@ public class DataController { ...@@ -221,11 +290,18 @@ public class DataController {
public Object getTemperature(@RequestBody String transportationNo){ public Object getTemperature(@RequestBody String transportationNo){
JSONObject jsonObject= JSON.parseObject(transportationNo); JSONObject jsonObject= JSON.parseObject(transportationNo);
transportationNo=jsonObject.getString("transportationNo"); transportationNo=jsonObject.getString("transportationNo");
ResultGatewayVo gatewayVo = circuitService.getByNo(transportationNo); ResultCircuitVo resultCircuitVo = circuitService.getByTransportationNo(transportationNo);
ResultGatewayVo gatewayVo = new ResultGatewayVo();
if(resultCircuitVo.getEndTime() == 0){
gatewayVo = circuitService.getByNo(transportationNo);
}else{
gatewayVo = tdlLogService.getByNo(transportationNo);
}
String device = gatewayVo.getType() +"_" +gatewayVo.getSN(); String device = gatewayVo.getType() +"_" +gatewayVo.getSN();
//获取tdl信息 //获取tdl信息
List<String> devList = tdlDeviceService.getByGatewaySN(gatewayVo.getSN(),gatewayVo.getType()); List<String> devList = tdlDeviceService.getByGatewaySN(gatewayVo.getSN(),gatewayVo.getType());
String devcie=gatewayVo.getType()+"_"+gatewayVo.getSN() ; String devcie=gatewayVo.getType()+"_"+gatewayVo.getSN() ;
Long startTime = resultCircuitVo.getStartTime() *1000000l;
//SELECT "h" FROM "tdl_policy"."WTD93LG_20180314" WHERE "tdl" = 'tdl-0A0B0C0D0F' ORDER BY time DESC //SELECT "h" FROM "tdl_policy"."WTD93LG_20180314" WHERE "tdl" = 'tdl-0A0B0C0D0F' ORDER BY time DESC
if(devList.size() == 0){ if(devList.size() == 0){
fb.setCode(0); fb.setCode(0);
...@@ -236,7 +312,7 @@ public class DataController { ...@@ -236,7 +312,7 @@ public class DataController {
for( int i =0;i<devList.size();i++){ for( int i =0;i<devList.size();i++){
Temperature temperature = new Temperature(); Temperature temperature = new Temperature();
temperature.setTDLSN(devList.get(i)); temperature.setTDLSN(devList.get(i));
String sql = "SELECT \"t\" FROM \"tdl_policy\".\""+devcie+"\" where \"tdl\"=\'"+devList.get(i)+"\' ORDER BY time "; String sql = "SELECT \"t\" FROM \"tdl_policy\".\""+devcie+"\" where \"tdl\"=\'"+devList.get(i)+"\' and time >="+startTime + " ORDER BY time ";
QueryResult queryResult = influxDBTemplate.query(new Query(sql,database)); QueryResult queryResult = influxDBTemplate.query(new Query(sql,database));
List<TemperatureDataVo> temperatureDataVos = new ArrayList<>(); List<TemperatureDataVo> temperatureDataVos = new ArrayList<>();
if(queryResult.getResults().get(0).getSeries() != null){ if(queryResult.getResults().get(0).getSeries() != null){
...@@ -266,8 +342,15 @@ public class DataController { ...@@ -266,8 +342,15 @@ public class DataController {
public Object getHumidity(@RequestBody String transportationNo){ public Object getHumidity(@RequestBody String transportationNo){
JSONObject jsonObject= JSON.parseObject(transportationNo); JSONObject jsonObject= JSON.parseObject(transportationNo);
transportationNo=jsonObject.getString("transportationNo"); transportationNo=jsonObject.getString("transportationNo");
ResultGatewayVo gatewayVo = circuitService.getByNo(transportationNo); ResultCircuitVo resultCircuitVo = circuitService.getByTransportationNo(transportationNo);
ResultGatewayVo gatewayVo = new ResultGatewayVo();
if(resultCircuitVo.getEndTime() == 0){
gatewayVo = circuitService.getByNo(transportationNo);
}else{
gatewayVo = tdlLogService.getByNo(transportationNo);
}
String device = gatewayVo.getType() +"_" +gatewayVo.getSN(); String device = gatewayVo.getType() +"_" +gatewayVo.getSN();
Long startTime = resultCircuitVo.getStartTime() *1000000l;
//获取tdl信息 //获取tdl信息
List<String> devList = tdlDeviceService.getByGatewaySN(gatewayVo.getSN(),gatewayVo.getType()); List<String> devList = tdlDeviceService.getByGatewaySN(gatewayVo.getSN(),gatewayVo.getType());
String devcie=gatewayVo.getType()+"_"+gatewayVo.getSN() ; String devcie=gatewayVo.getType()+"_"+gatewayVo.getSN() ;
...@@ -280,7 +363,7 @@ public class DataController { ...@@ -280,7 +363,7 @@ public class DataController {
for( int i =0;i<devList.size();i++){ for( int i =0;i<devList.size();i++){
Humidity humidity = new Humidity(); Humidity humidity = new Humidity();
humidity.setTDLSN(devList.get(i)); humidity.setTDLSN(devList.get(i));
String sql = "SELECT \"h\" FROM \"tdl_policy\".\""+devcie+"\" where \"tdl\"=\'"+devList.get(i)+"\' ORDER BY time "; String sql = "SELECT \"h\" FROM \"tdl_policy\".\""+devcie+"\" where \"tdl\"=\'"+devList.get(i)+"\' and time >="+startTime+" ORDER BY time ";
QueryResult queryResult = influxDBTemplate.query(new Query(sql,database)); QueryResult queryResult = influxDBTemplate.query(new Query(sql,database));
List<HumidityDataVo> humidityDataVos = new ArrayList<>(); List<HumidityDataVo> humidityDataVos = new ArrayList<>();
if(queryResult.getResults().get(0).getSeries() != null){ if(queryResult.getResults().get(0).getSeries() != null){
...@@ -310,8 +393,15 @@ public class DataController { ...@@ -310,8 +393,15 @@ public class DataController {
public Object getTiltAngle(@RequestBody String transportationNo){ public Object getTiltAngle(@RequestBody String transportationNo){
JSONObject jsonObject= JSON.parseObject(transportationNo); JSONObject jsonObject= JSON.parseObject(transportationNo);
transportationNo=jsonObject.getString("transportationNo"); transportationNo=jsonObject.getString("transportationNo");
ResultGatewayVo gatewayVo = circuitService.getByNo(transportationNo); ResultCircuitVo resultCircuitVo = circuitService.getByTransportationNo(transportationNo);
ResultGatewayVo gatewayVo = new ResultGatewayVo();
if(resultCircuitVo.getEndTime() == 0){
gatewayVo = circuitService.getByNo(transportationNo);
}else{
gatewayVo = tdlLogService.getByNo(transportationNo);
}
String device = gatewayVo.getType() +"_" +gatewayVo.getSN(); String device = gatewayVo.getType() +"_" +gatewayVo.getSN();
Long startTime = resultCircuitVo.getStartTime() *1000000l;
//获取tdl信息 //获取tdl信息
List<String> devList = tdlDeviceService.getByGatewaySN(gatewayVo.getSN(),gatewayVo.getType()); List<String> devList = tdlDeviceService.getByGatewaySN(gatewayVo.getSN(),gatewayVo.getType());
String devcie=gatewayVo.getType()+"_"+gatewayVo.getSN() ; String devcie=gatewayVo.getType()+"_"+gatewayVo.getSN() ;
...@@ -324,7 +414,7 @@ public class DataController { ...@@ -324,7 +414,7 @@ public class DataController {
for( int i =0;i<devList.size();i++){ for( int i =0;i<devList.size();i++){
TiltAngle tiltAngle = new TiltAngle(); TiltAngle tiltAngle = new TiltAngle();
tiltAngle.setTDLSN(devList.get(i)); tiltAngle.setTDLSN(devList.get(i));
String sql = "SELECT \"ta\" FROM \"tdl_policy\".\""+devcie+"\" where \"tdl\"=\'"+devList.get(i)+"\' ORDER BY time "; String sql = "SELECT \"ta\" FROM \"tdl_policy\".\""+devcie+"\" where \"tdl\"=\'"+devList.get(i)+"\' and time >="+startTime+" ORDER BY time ";
QueryResult queryResult = influxDBTemplate.query(new Query(sql,database)); QueryResult queryResult = influxDBTemplate.query(new Query(sql,database));
List<TiltAngleVo> tiltAngleVos = new ArrayList<>(); List<TiltAngleVo> tiltAngleVos = new ArrayList<>();
if(queryResult.getResults().get(0).getSeries() != null){ if(queryResult.getResults().get(0).getSeries() != null){
...@@ -353,8 +443,15 @@ public class DataController { ...@@ -353,8 +443,15 @@ public class DataController {
public Object getShockEnergy(@RequestBody String transportationNo){ public Object getShockEnergy(@RequestBody String transportationNo){
JSONObject jsonObject= JSON.parseObject(transportationNo); JSONObject jsonObject= JSON.parseObject(transportationNo);
transportationNo=jsonObject.getString("transportationNo"); transportationNo=jsonObject.getString("transportationNo");
ResultGatewayVo gatewayVo = circuitService.getByNo(transportationNo); ResultCircuitVo resultCircuitVo = circuitService.getByTransportationNo(transportationNo);
ResultGatewayVo gatewayVo = new ResultGatewayVo();
if(resultCircuitVo.getEndTime() == 0){
gatewayVo = circuitService.getByNo(transportationNo);
}else{
gatewayVo = tdlLogService.getByNo(transportationNo);
}
String device = gatewayVo.getType() +"_" +gatewayVo.getSN(); String device = gatewayVo.getType() +"_" +gatewayVo.getSN();
Long startTime = resultCircuitVo.getStartTime() *1000000l;
//获取tdl信息 //获取tdl信息
List<String> devList = tdlDeviceService.getByGatewaySN(gatewayVo.getSN(),gatewayVo.getType()); List<String> devList = tdlDeviceService.getByGatewaySN(gatewayVo.getSN(),gatewayVo.getType());
String devcie=gatewayVo.getType()+"_"+gatewayVo.getSN() ; String devcie=gatewayVo.getType()+"_"+gatewayVo.getSN() ;
...@@ -367,7 +464,7 @@ public class DataController { ...@@ -367,7 +464,7 @@ public class DataController {
for( int i =0;i<devList.size();i++){ for( int i =0;i<devList.size();i++){
ShockEnergy shockEnergy = new ShockEnergy(); ShockEnergy shockEnergy = new ShockEnergy();
shockEnergy.setTDLSN(devList.get(i)); shockEnergy.setTDLSN(devList.get(i));
String sql = "SELECT \"a0\" FROM \"tdl_policy\".\""+devcie+"\" where \"tdl\"=\'"+devList.get(i)+"\' ORDER BY time "; String sql = "SELECT \"a0\" FROM \"tdl_policy\".\""+devcie+"\" where \"tdl\"=\'"+devList.get(i)+"\' and time >="+startTime+" ORDER BY time ";
QueryResult queryResult = influxDBTemplate.query(new Query(sql,database)); QueryResult queryResult = influxDBTemplate.query(new Query(sql,database));
List<ShockEnergyVo> shockEnergyVos = new ArrayList<>(); List<ShockEnergyVo> shockEnergyVos = new ArrayList<>();
if(queryResult.getResults().get(0).getSeries() != null){ if(queryResult.getResults().get(0).getSeries() != null){
...@@ -388,7 +485,6 @@ public class DataController { ...@@ -388,7 +485,6 @@ public class DataController {
} }
//根据运输编号获取所有的报警数据 //根据运输编号获取所有的报警数据
@ApiOperation(value = "根据运输编号获取所有的报警数据????",notes = "根据运输编号获取所有的报警数据") @ApiOperation(value = "根据运输编号获取所有的报警数据????",notes = "根据运输编号获取所有的报警数据")
@PostMapping("/getAlarmData") @PostMapping("/getAlarmData")
...@@ -399,14 +495,25 @@ public class DataController { ...@@ -399,14 +495,25 @@ public class DataController {
JSONObject jsonObject= JSON.parseObject(transportationNo); JSONObject jsonObject= JSON.parseObject(transportationNo);
transportationNo=jsonObject.getString("transportationNo"); transportationNo=jsonObject.getString("transportationNo");
//根据运输编号获取报警信息 //根据运输编号获取报警信息
List<AlarmLogVo> alarmLogVoList = alarmLogService.getByTransportationNo(transportationNo); List<ResultAlarmLog> alarmLogVoList = alarmLogService.getByTransportationNo(transportationNo);
return gson.toJson(alarmLogVoList); return gson.toJson(alarmLogVoList);
} }
//根据时间获取经纬度信息 //根据时间获取经纬度信息
@ApiOperation(value = "获取震动能量",notes = "获取震动能量") @ApiOperation(value = "根据时间获取经纬度信息",notes = "根据时间获取经纬度信息" +
"transportationNo:运输编号" +
"TDLSN:tdl编号" +
"gatewaySN:网关编号" +
"startCity:出发城市" +
"endCity:目的城市" +
"startTime:出发时间" +
"endTime:到达时间" +
"alarmTime:报警时间" +
"alarmType:报警类型" +
"alarmValue:报警值" +
"lng:经度" +
"lat:纬度")
@PostMapping("/getLocationByTime") @PostMapping("/getLocationByTime")
@ApiImplicitParams({ @ApiImplicitParams({
@ApiImplicitParam(paramType="header", name = "Account_token", value = "token", required = true, dataType = "String"), @ApiImplicitParam(paramType="header", name = "Account_token", value = "token", required = true, dataType = "String"),
...@@ -414,8 +521,13 @@ public class DataController { ...@@ -414,8 +521,13 @@ public class DataController {
public Object getLocationByTime(@RequestBody LocationVo locationVo ){ public Object getLocationByTime(@RequestBody LocationVo locationVo ){
//获取线路信息 //获取线路信息
//获取网关以及tdl信息 //获取网关以及tdl信息
ResultGatewayVo gatewayVo = circuitService.getByNo(locationVo.getTransportationNo());
ResultCircuitVo resultCircuitVo = circuitService.getByTransportationNo(locationVo.getTransportationNo()); ResultCircuitVo resultCircuitVo = circuitService.getByTransportationNo(locationVo.getTransportationNo());
ResultGatewayVo gatewayVo = new ResultGatewayVo();
if(resultCircuitVo.getEndTime() == 0){
gatewayVo = circuitService.getByNo(locationVo.getTransportationNo());
}else{
gatewayVo = tdlLogService.getByNo(locationVo.getTransportationNo());
}
String device = gatewayVo.getType() +"_" +gatewayVo.getSN(); String device = gatewayVo.getType() +"_" +gatewayVo.getSN();
//获取tdl信息 //获取tdl信息
List<String> devList = tdlDeviceService.getByGatewaySN(gatewayVo.getSN(),gatewayVo.getType()); List<String> devList = tdlDeviceService.getByGatewaySN(gatewayVo.getSN(),gatewayVo.getType());
...@@ -438,8 +550,8 @@ public class DataController { ...@@ -438,8 +550,8 @@ public class DataController {
messageVo.setAlarmTime(Long.valueOf(parseTime(value.get(0).toString()))); messageVo.setAlarmTime(Long.valueOf(parseTime(value.get(0).toString())));
messageVo.setAlarmType(locationVo.getAlarmType()); messageVo.setAlarmType(locationVo.getAlarmType());
messageVo.setAlarmValue(locationVo.getVlaue()); messageVo.setAlarmValue(locationVo.getVlaue());
messageVo.setLng(value.get(1)==null ? "": value.get(1).toString()); messageVo.setLng(value.get(1)==null ? "" : value.get(1).toString());
messageVo.setLat(value.get(2)==null ? "" :value.get(2).toString()); messageVo.setLat(value.get(2)==null ? "" : value.get(2).toString());
locationDataVos.add(messageVo); locationDataVos.add(messageVo);
} }
} }
...@@ -456,13 +568,20 @@ public class DataController { ...@@ -456,13 +568,20 @@ public class DataController {
JSONObject jsonObject= JSON.parseObject(transportationNo); JSONObject jsonObject= JSON.parseObject(transportationNo);
transportationNo=jsonObject.getString("transportationNo"); transportationNo=jsonObject.getString("transportationNo");
//获取网关以及tdl信息 //获取网关以及tdl信息
ResultGatewayVo gatewayVo = circuitService.getByNo(transportationNo); ResultCircuitVo resultCircuitVo = circuitService.getByTransportationNo(transportationNo);
ResultGatewayVo gatewayVo = new ResultGatewayVo();
if(resultCircuitVo.getEndTime() == 0){
gatewayVo = circuitService.getByNo(transportationNo);
}else{
gatewayVo = tdlLogService.getByNo(transportationNo);
}
String device = gatewayVo.getType() +"_" +gatewayVo.getSN(); String device = gatewayVo.getType() +"_" +gatewayVo.getSN();
Long startTime = resultCircuitVo.getStartTime() *1000000l;
//获取tdl信息 //获取tdl信息
List<String> devList = tdlDeviceService.getByGatewaySN(gatewayVo.getSN(),gatewayVo.getType()); List<String> devList = tdlDeviceService.getByGatewaySN(gatewayVo.getSN(),gatewayVo.getType());
String devcie=gatewayVo.getType()+"_"+gatewayVo.getSN() ; String devcie=gatewayVo.getType()+"_"+gatewayVo.getSN() ;
//SELECT "h" FROM "tdl_policy"."WTD93LG_20180314" WHERE "tdl" = 'tdl-0A0B0C0D0F' ORDER BY time DESC //SELECT "h" FROM "tdl_policy"."WTD93LG_20180314" WHERE "tdl" = 'tdl-0A0B0C0D0F' ORDER BY time DESC
String sql = "SELECT \"t\",\"h\",\"p\",\"a0\",\"ta\" FROM \"tdl_policy\".\""+devcie+"\" where \"tdl\" = \'"+devList.get(0)+"\' ORDER BY time "; String sql = "SELECT \"t\",\"h\",\"p\",\"a0\",\"ta\" FROM \"tdl_policy\".\""+devcie+"\" where \"tdl\" = \'"+devList.get(0)+"\' and time>="+startTime+" ORDER BY time ";
QueryResult queryResult = influxDBTemplate.query(new Query(sql,database)); QueryResult queryResult = influxDBTemplate.query(new Query(sql,database));
//解析经纬度数据 //解析经纬度数据
List<DeviceDataVo> deviceDataVos = new ArrayList<>(); List<DeviceDataVo> deviceDataVos = new ArrayList<>();
...@@ -472,6 +591,7 @@ public class DataController { ...@@ -472,6 +591,7 @@ public class DataController {
return gson.toJson(deviceDataVos); return gson.toJson(deviceDataVos);
} }
//解析数据 //解析数据
public List<LocationDataVo> getLocation(QueryResult queryResult){ public List<LocationDataVo> getLocation(QueryResult queryResult){
List<List<Object>> values = getValues(queryResult); List<List<Object>> values = getValues(queryResult);
...@@ -481,7 +601,7 @@ public class DataController { ...@@ -481,7 +601,7 @@ public class DataController {
historyData.setTime(parseTime(value.get(0).toString())); historyData.setTime(parseTime(value.get(0).toString()));
historyData.setLng(Double.parseDouble(value.get(1).toString())); historyData.setLng(Double.parseDouble(value.get(1).toString()));
historyData.setLat(Double.parseDouble(value.get(2).toString())); historyData.setLat(Double.parseDouble(value.get(2).toString()));
historyData.setError(0);//没有预警 historyData.setError(0);
historyDataList.add(historyData); historyDataList.add(historyData);
} }
return historyDataList; return historyDataList;
...@@ -582,7 +702,7 @@ public class DataController { ...@@ -582,7 +702,7 @@ public class DataController {
String dateResult =null; String dateResult =null;
try { try {
dateResult = dateToStamp(time); dateResult = dateToStamp(time);
} catch (Exception e) { } catch (ParseException e) {
e.printStackTrace(); e.printStackTrace();
logger.info(e.toString()); logger.info(e.toString());
fb.setCode(0); fb.setCode(0);
...@@ -592,11 +712,97 @@ public class DataController { ...@@ -592,11 +712,97 @@ public class DataController {
} }
//判断两个时间相差多少 //判断两个时间相差多少
public static int differentDaysByMillisecond(Long date1,Long date2){ public static String getDistanceTime(Long time1, Long time2) {
int days = (int) ((date2-date1) / (1000*3600*24)) ; //获取当前时区,将时间戳转化成日期时间格式
return days; Date t1 = new Date(time1);
Date t2 = new Date(time2);
int days = differentDays(t1,t2);
if(days>0){
return days +"天";
}else{
return "a little minute";
}
}
public static int differentDays(Date date1,Date date2) {
Calendar cal1 = Calendar.getInstance();
cal1.setTime(date1);
Calendar cal2 = Calendar.getInstance();
cal2.setTime(date2);
int day1= cal1.get(Calendar.DAY_OF_YEAR);
int day2 = cal2.get(Calendar.DAY_OF_YEAR);
int year1 = cal1.get(Calendar.YEAR);
int year2 = cal2.get(Calendar.YEAR);
if(year1 != year2) { //不同年
int timeDistance = 0 ;
for(int i = year1 ; i < year2 ; i ++) {
if(i%4==0 && i%100!=0 || i%400==0) { //闰年
timeDistance += 366;
} else{ //不是闰年
timeDistance += 365;
}
}
return timeDistance + (day2-day1) ;
} else{
return day2-day1;
}
}
//将时间戳转成时间
public static String timeStamp2Date(Long seconds) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
return sdf.format(new Date(seconds));
}
//解析震动时间
public List<String> getTime(QueryResult queryResult){
List<List<Object>> values = getValues(queryResult);
List<String> time = new ArrayList<>();
for(List<Object> value:values){
try {
time.add(UTCToCST(value.get(0).toString()));
}catch (Exception e){
e.printStackTrace();
logger.info(e.toString());
}
}
return time;
}
public String UTCToCST(String UTCStr) throws ParseException {
Date date =null ;
if(UTCStr.length() !=20 ) {
date = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'").parse(UTCStr);
}else{
date = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'").parse(UTCStr);
}
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
calendar.set(Calendar.HOUR, calendar.get(Calendar.HOUR) + 8);
//calendar.getTime() 返回的是Date类型,也可以使用calendar.getTimeInMillis()获取时间戳
//format的格式可以任意
return String.valueOf(calendar.getTimeInMillis());
} }
public List<String> getShockLocation(QueryResult queryResult){
List<List<Object>> values = new ArrayList<>();
for(QueryResult.Result result : queryResult.getResults()){
if(result.getSeries() !=null){
for (QueryResult.Series series : result.getSeries()) {
if(series !=null){
values.add(series.getValues().get(0));
}
}
}
}
List<String> timeList = new ArrayList<>();
for(List<Object> value:values){
timeList.add(parseTime(value.get(0).toString()));
}
return timeList;
}
} }
\ No newline at end of file
...@@ -106,9 +106,6 @@ public class EquipmentBindingController { ...@@ -106,9 +106,6 @@ public class EquipmentBindingController {
return gson.toJson(fb); return gson.toJson(fb);
} }
@ApiOperation(value = "重置tdl",notes = "重置tdl") @ApiOperation(value = "重置tdl",notes = "重置tdl")
@ApiImplicitParams({ @ApiImplicitParams({
@ApiImplicitParam(paramType="header", name = "Account_token", value = "token", required = true, dataType = "String"), @ApiImplicitParam(paramType="header", name = "Account_token", value = "token", required = true, dataType = "String"),
...@@ -137,6 +134,7 @@ public class EquipmentBindingController { ...@@ -137,6 +134,7 @@ public class EquipmentBindingController {
map.put("message",gson.toJson(configCMDVo)); map.put("message",gson.toJson(configCMDVo));
map.put("untie",untie); map.put("untie",untie);
map.put("TDLSN",TDLSN); map.put("TDLSN",TDLSN);
map.put("endTime",System.currentTimeMillis());
configService.updateConfig(map); configService.updateConfig(map);
Map<Object,Object> msg=new HashMap<>(); Map<Object,Object> msg=new HashMap<>();
msg.put("msg",map.get("msg")); msg.put("msg",map.get("msg"));
......
...@@ -6,6 +6,10 @@ ...@@ -6,6 +6,10 @@
select routeName,description,data,alarmTime from alarm_log order by alarmTime desc limit 10; select routeName,description,data,alarmTime from alarm_log order by alarmTime desc limit 10;
</select> </select>
<select id="getByTransportationNo" resultType="com.example.tdl.domain.vo.ResultAlarmLog" parameterType="String">
select transportationNo,routeName,description,data,alarmTime from alarm_log where transportationNo=#{transportationNo,jdbcType=VARCHAR};
</select>
<!--根据条件获取报警数据--> <!--根据条件获取报警数据-->
<select id="getAlarmLog" resultType="com.example.tdl.domain.vo.AlarmLogVo"> <select id="getAlarmLog" resultType="com.example.tdl.domain.vo.AlarmLogVo">
select routeName,description,data,alarmTime select routeName,description,data,alarmTime
...@@ -26,7 +30,6 @@ ...@@ -26,7 +30,6 @@
) )
</insert> </insert>
<select id="getCount" resultType="java.lang.Integer"> <select id="getCount" resultType="java.lang.Integer">
select count(DISTINCT transportationNo) from alarm_log select count(DISTINCT transportationNo) from alarm_log
</select> </select>
......
...@@ -179,7 +179,7 @@ ...@@ -179,7 +179,7 @@
GROUP BY routes GROUP BY routes
order BY c.id order BY c.id
</select> </select>
<select id="getByContainerNo" parameterType="String" resultType="com.example.tdl.domain.vo.ResultCircuitVo"> <select id="getByContainerNo" parameterType="String" resultType="com.example.tdl.domain.vo.ResultCircuitVo">
SELECT transportationNo,routeNumber,routeName,startLongitude,startLatitude,(select city from city_config where id=r.start_id) startCity, SELECT transportationNo,routeNumber,routeName,startLongitude,startLatitude,(select city from city_config where id=r.start_id) startCity,
startAddress,startTime,endLongitude,endLatitude,(select city from city_config where id=r.end_id) endCity,endAddress,endTime,transport, startAddress,startTime,endLongitude,endLatitude,(select city from city_config where id=r.end_id) endCity,endAddress,endTime,transport,
......
...@@ -47,6 +47,7 @@ ...@@ -47,6 +47,7 @@
#{message,mode=IN,jdbcType=VARCHAR}, #{message,mode=IN,jdbcType=VARCHAR},
#{untie,mode=IN,jdbcType=INTEGER}, #{untie,mode=IN,jdbcType=INTEGER},
#{TDLSN,mode=IN,jdbcType=VARCHAR}, #{TDLSN,mode=IN,jdbcType=VARCHAR},
#{endTime,mode=IN,jdbcType=BIGINT},
#{msg,mode=OUT,jdbcType=VARCHAR} #{msg,mode=OUT,jdbcType=VARCHAR}
) )
} }
......
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.example.tdl.mapper.TDLLogMapper">
<select id="getByNo" parameterType="String" resultType="com.example.tdl.domain.vo.ResultGatewayVo">
select gatewaySN SN,gatewayType type from tdl_gateway_log
where transportationNo = #{transportationNo,jdbcType=VARCHAR}
GROUP BY gatewaySN
</select>
</mapper>
\ No newline at end of file
...@@ -47,6 +47,7 @@ ...@@ -47,6 +47,7 @@
<mapper resource="mapper/TopicMapper.xml"/> <mapper resource="mapper/TopicMapper.xml"/>
<mapper resource="mapper/TopicConfigMapper.xml"/> <mapper resource="mapper/TopicConfigMapper.xml"/>
<mapper resource="mapper/CityConfigMapper.xml"/> <mapper resource="mapper/CityConfigMapper.xml"/>
<mapper resource="mapper/TDLLogMapper.xml"/>
<mapper resource="mapper/UserRouteMapper.xml"/> <mapper resource="mapper/UserRouteMapper.xml"/>
</mappers> </mappers>
</configuration> </configuration>
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