Commit e7af9e90 authored by zhuangzhuang's avatar zhuangzhuang

5.4--修改按条件查询以及获取线路详情的返回值

parent e5bc0ba6
......@@ -111,9 +111,18 @@ public class GWConfigWorker implements Callable<String>, MqttCallback {
}
//获取数据
publish(ConfigCMD,ConfigTopic);
//判断是否睡眠
// if(!NeedResp){
// //睡眠,休息60秒,结束连接
// Thread.sleep(60*1000l);
// mqttAsyncClient.disconnect();
// }
} catch (MqttException e){
e.printStackTrace();
System.out.println("Error: " + e.getMessage());
} catch (Exception e) {
e.printStackTrace();
System.out.println("Error: " + e.getMessage());
}
}
@Override
......@@ -173,10 +182,9 @@ public class GWConfigWorker implements Callable<String>, MqttCallback {
//解析Message消息
RespVo respVo = new Gson().fromJson(Message,RespVo.class);
if(respVo.getResponse().equals("config")){
System.out.print(gson.toJson(respVo));
//配置回复
configService.bindiSuccess(SN,Type,respVo.getStatus());
}else{
}else if(respVo.getResponse().equals("end")){
//解绑回复
if(respVo.getStatus() ==0 || respVo.getStatus() == 1){
configService.delConfig(SN,Type);
......
package com.example.tdl.domain.vo;
public class CircuitMessage {
private String transportationNo;//运输编号
private String routeName;//线路
private String cargoName;//货物名称
private String plateNo;//车牌号
private String transportation;//运输方式
private String evaluate;//运输评价
private Integer circuitState;
private Long startTime;
private Long endTime;
private String alarmType;//预警类型
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 getCargoName() {
return cargoName;
}
public void setCargoName(String cargoName) {
this.cargoName = cargoName;
}
public String getPlateNo() {
return plateNo;
}
public void setPlateNo(String plateNo) {
this.plateNo = plateNo;
}
public String getTransportation() {
return transportation;
}
public void setTransportation(String transportation) {
this.transportation = transportation;
}
public String getEvaluate() {
return evaluate;
}
public void setEvaluate(String evaluate) {
this.evaluate = evaluate;
}
public Integer getCircuitState() {
return circuitState;
}
public void setCircuitState(Integer circuitState) {
this.circuitState = circuitState;
}
public Long getStartTime() {
return startTime;
}
public void setStartTime(Long startTime) {
this.startTime = startTime;
}
public Long getEndTime() {
return endTime;
}
public void setEndTime(Long endTime) {
this.endTime = endTime;
}
public String getAlarmType() {
return alarmType;
}
public void setAlarmType(String alarmType) {
this.alarmType = alarmType;
}
}
......@@ -4,38 +4,70 @@ import java.util.List;
public class CircuitMessageVo {
private String transportationNo;
private String transportationNo;//运输编号
private String cargoNo;//货物编号
private String routeName;//线路
private String startCity;
private String cargoName;//货物名称
private String endCity;
private String plateNo;//车牌号
private Integer circuitState;
private String transportation;//运输方式
private String evaluate;
private String evaluate;//运输评价
private String SN;
private String alarmType;//预警类型
private String TDLSN;
private String SN;//网关编号
private List<ResultCityVo> list;
private List<ResultAlarmLog> alarmLogList;
private List<TDL> tdlList;
public static class TDL {
private String tdlsn;
private Double batteryVoltage;
public TDL() {
}
public TDL(String tdlsn, Double batteryVoltage) {
this.tdlsn = tdlsn;
this.batteryVoltage = batteryVoltage;
}
public String getTdlsn() {
return tdlsn;
}
public void setTdlsn(String tdlsn) {
this.tdlsn = tdlsn;
}
public Double getBatteryVoltage() {
return batteryVoltage;
}
public void setBatteryVoltage(Double batteryVoltage) {
this.batteryVoltage = batteryVoltage;
}
}
public CircuitMessageVo() {
}
public CircuitMessageVo(String transportationNo, String cargoNo, String startCity, String endCity, Integer circuitState, String evaluate, String SN, String TDLSN, List<ResultAlarmLog> alarmLogList) {
public CircuitMessageVo(String transportationNo, String routeName, String cargoName, String plateNo, String transportation, String evaluate, String alarmType, String SN, List<ResultAlarmLog> alarmLogList) {
this.transportationNo = transportationNo;
this.cargoNo = cargoNo;
this.startCity = startCity;
this.endCity = endCity;
this.circuitState = circuitState;
this.routeName = routeName;
this.cargoName = cargoName;
this.plateNo = plateNo;
this.transportation = transportation;
this.evaluate = evaluate;
this.alarmType = alarmType;
this.SN = SN;
this.TDLSN = TDLSN;
this.alarmLogList = alarmLogList;
}
......@@ -47,36 +79,44 @@ public class CircuitMessageVo {
this.transportationNo = transportationNo;
}
public String getCargoNo() {
return cargoNo;
public String getRouteName() {
return routeName;
}
public void setRouteName(String routeName) {
this.routeName = routeName;
}
public String getCargoName() {
return cargoName;
}
public void setCargoNo(String cargoNo) {
this.cargoNo = cargoNo;
public void setCargoName(String cargoName) {
this.cargoName = cargoName;
}
public String getStartCity() {
return startCity;
public String getPlateNo() {
return plateNo;
}
public void setStartCity(String startCity) {
this.startCity = startCity;
public void setPlateNo(String plateNo) {
this.plateNo = plateNo;
}
public String getEndCity() {
return endCity;
public String getTransportation() {
return transportation;
}
public void setEndCity(String endCity) {
this.endCity = endCity;
public void setTransportation(String transportation) {
this.transportation = transportation;
}
public Integer getCircuitState() {
return circuitState;
public String getAlarmType() {
return alarmType;
}
public void setCircuitState(Integer circuitState) {
this.circuitState = circuitState;
public void setAlarmType(String alarmType) {
this.alarmType = alarmType;
}
public String getEvaluate() {
......@@ -95,14 +135,6 @@ public class CircuitMessageVo {
this.SN = SN;
}
public String getTDLSN() {
return TDLSN;
}
public void setTDLSN(String TDLSN) {
this.TDLSN = TDLSN;
}
public List<ResultCityVo> getList() {
return list;
}
......@@ -118,4 +150,12 @@ public class CircuitMessageVo {
public void setAlarmLogList(List<ResultAlarmLog> alarmLogList) {
this.alarmLogList = alarmLogList;
}
public List<TDL> getTdlList() {
return tdlList;
}
public void setTdlList(List<TDL> tdlList) {
this.tdlList = tdlList;
}
}
......@@ -11,6 +11,8 @@ public class CircuitTermVo {
private Long endTime;
private String time;
public String getCompanyName() {
return companyName;
}
......@@ -50,4 +52,12 @@ public class CircuitTermVo {
public void setEndTime(Long endTime) {
this.endTime = endTime;
}
public String getTime() {
return time;
}
public void setTime(String time) {
this.time = time;
}
}
......@@ -55,4 +55,6 @@ public interface CircuitMapper {
ResultGatewayVo getByNo(String transportationNo);
List<ResultCircuitVo> getByTime(String companyName);
CircuitMessage getMessage(String transportationNo);
}
......@@ -15,4 +15,6 @@ public interface TDLLogMapper {
List<String> getTdlSN(String transportationNo);
String getSN(String transportationNo);
}
......@@ -121,6 +121,7 @@ public class MqttListener implements MqttCallback {
// clientReconnect();
}
private void clearOvertimeConfig(Long ts){
try {
for(String key : futureMap.keySet()){
......@@ -149,7 +150,7 @@ public class MqttListener implements MqttCallback {
if(SN.matches("^[0-9]*$")){
try {
Integer flag = parseData(Message,SN,Type);
System.out.print(System.currentTimeMillis()+"------"+flag +"------");
// System.out.print(System.currentTimeMillis()+"------"+flag +"------");
String ConfigData;
Future<String> result = null;
GWConfigWorker gcconfig = null;
......@@ -173,13 +174,12 @@ public class MqttListener implements MqttCallback {
mqttconfig.getUsername(), mqttconfig.getPassword(),mqttconfig.getQos(),
mqttconfig.getCacrt(),mqttconfig.getClientkey(), mqttconfig.getClientcrt(),mqttconfig.getClientpwd());
result = configthreadPool.submit(gcconfig);
futureMap.put(Type+"_"+SN+"_"+timestamp,result);
// while (result.isDone())
// {
// String respcmd = result.get();
// }
//
} catch (JsonSyntaxException e) {
e.printStackTrace();
System.out.println("mqttAsyncClient: message " + Message + " received syntax error.");
......
......@@ -107,6 +107,11 @@ public class CircuitService {
return circuitMapper.getByTime(companyName);
}
public CircuitMessage getMessage(String transportationNo){
return circuitMapper.getMessage(transportationNo);
}
// public List<CircuitVo> getDistinct(){
// return circuitMapper.getDistinct();
// }
......
......@@ -27,4 +27,8 @@ public class TDLLogService {
return tdlLogMapper.getTdlSN(transportationNo);
}
public String getSN(String transportationNo){
return tdlLogMapper.getSN(transportationNo);
}
}
......@@ -15,12 +15,17 @@ import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.apache.ibatis.jdbc.Null;
import org.influxdb.dto.Query;
import org.influxdb.dto.QueryResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.influxdb.InfluxDBTemplate;
import org.springframework.web.bind.annotation.*;
import javax.print.DocFlavor;
import javax.servlet.http.HttpServletRequest;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.concurrent.Callable;
......@@ -71,6 +76,11 @@ public class CircuitController {
@Autowired
private InfoRedisService infoRedisService;
@Autowired
private InfluxDBTemplate influxDBTemplate;
private final static String database ="original";
List<String> list = new ArrayList<String>(){{
add("T");
add("h");
......@@ -168,7 +178,8 @@ public class CircuitController {
" cargoNo:货物编号" +
" startTime:出发时间,(时间戳)" +
" endTime:目的时间,(时间戳)" +
" circuitState:线路状态(0未开始,1运输中,2完成),"+
" circuitState:线路状态(0未开始,1运输中,2完成)," +
" time:日期"+
"返回值说明:" +
" transportationNo:运输编号," +
" cargoNo:货物编号" +
......@@ -201,6 +212,16 @@ public class CircuitController {
if(circuitTermVo.getEndTime()==null){
circuitTermVo.setEndTime(null);
}
if(circuitTermVo.getStartTime()!=null && circuitTermVo.getEndTime()!=null && circuitTermVo.getStartTime()>circuitTermVo.getEndTime()){
fb.setCode(0);
fb.setMessage("开始时间不能大于结束时间");
return gson.toJson(fb);
}
if(StringUtils.isEmpty(circuitTermVo.getTime())){
circuitTermVo.setTime(null);
}else{
circuitTermVo.setTime(circuitTermVo.getTime().replace("天","").trim());
}
circuitTermVo.setCompanyName(user.getCompanyName());
return circuitService.getByTerm(circuitTermVo);
}
......@@ -1107,36 +1128,34 @@ public class CircuitController {
@ApiOperation(value = "根据线路编号获取线路详细信息",notes = "根据线路编号获取线路详细信息,传值说明:" +
" transportationNo:运输编号; " +
"返回值说明:" +
" transportationNo:运输编号" +
" cargoNo:货物编号" +
" cargoName:货物别名" +
" startCity:出发城市" +
" endCity:目的城市" +
" circuitState:线路状态" +
" evaluate:评价" +
" SN:gateway序列号" +
" TDLSN:TDLSN序列号" +
" list:" +
" {city:城市" +
" time:到达时间/发车时间" +
" last:运行时长" +
" alarmCount:报警数" +
" type:1--出发时间;2--目的时间}" +
" alarmLogList:" +
" transportationNo:运输编号" +
" TDLSN:tag序列号" +
" description:报警描述" +
" data:数值" +
" alarmTime:报警时间" +
" classify:分类" )
" transportationNo:运输编号," +
" routeName:线路," +
" cargoName:货物别名," +
" transportation:运输方式," +
" evaluate:评价," +
" alarmType:预警类型," +
" SN:gateway序列号," +
" tdlList:{" +
" tdlsn:TDLSN序列号" +
" batteryVoltage:电池电压}," +
" list:{" +
" city:城市;" +
" time:到达时间/发车时间;" +
" last:运行时长;" +
" alarmCount:报警数;" +
" type:1--出发时间;2--目的时间}," +
" alarmLogList:{" +
" transportationNo:运输编号;" +
" TDLSN:tag序列号;" +
" description:报警描述;" +
" data:数值;" +
" alarmTime:报警时间;" +
" classify:分类}" )
@ApiImplicitParams({
@ApiImplicitParam(paramType="header", name = "Account_token", value = "token", required = true, dataType = "String"),
})
@PostMapping("/getDetails")
public Object getDetails(@RequestBody String transportationNo,HttpServletRequest request) {
String token = request.getHeader("Account_token");
String datum = tokenRedisService.get("TOKEN_" +token);
UserRedisVo user = gson.fromJson(datum,UserRedisVo.class);
public Object getDetails(@RequestBody String transportationNo) {
if(StringUtils.isEmpty(transportationNo)){
fb.setCode(0);
fb.setMessage("线路编号不能为空");
......@@ -1145,14 +1164,49 @@ public class CircuitController {
JSONObject jsonObject= JSON.parseObject(transportationNo);
transportationNo=(String)jsonObject.get("transportationNo");
//获取线路信息
ResultCircuitVo resultCircuitVo = circuitService.getByTransportationNo(transportationNo,user.getCompanyName());
if(resultCircuitVo == null){
CircuitMessage circuitVo = circuitService.getMessage(transportationNo);
if(circuitVo == null){
fb.setCode(0);
fb.setMessage("该线路不存在");
return gson.toJson(fb);
}
//获取gateway信息
TDLLogVo gatewayVo = tdlLogService.getByTransportationNo(transportationNo);
if(gatewayVo == null){
fb.setCode(0);
fb.setMessage("该线路不存在");
return gson.toJson(fb);
}
List<ResultAlarmLog> alarmLogList= alarmLogService.getByTransportationNo(transportationNo);
CircuitMessageVo messageVo = new CircuitMessageVo(resultCircuitVo.getTransportationNo(),resultCircuitVo.getCargoNo(),resultCircuitVo.getStartCity(),resultCircuitVo.getEndCity(),resultCircuitVo.getCircuitState(),resultCircuitVo.getEvaluate(),resultCircuitVo.getSN(),resultCircuitVo.getTDLSN(),alarmLogList);
CircuitMessageVo messageVo = new CircuitMessageVo(circuitVo.getTransportationNo(),circuitVo.getRouteName(),circuitVo.getCargoName(),circuitVo.getPlateNo(),circuitVo.getTransportation(),circuitVo.getEvaluate(),circuitVo.getAlarmType(),gatewayVo.getgSN(),alarmLogList);
List<String> TDL= tdlLogService.getTdlSN(transportationNo);
if(TDL.size() == 0){
fb.setCode(0);
fb.setMessage("该线路不存在");
return gson.toJson(fb);
}
List<CircuitMessageVo.TDL> tdlList = new ArrayList<>();
for(int i=0;i<TDL.size();i++){
CircuitMessageVo.TDL tdl = new CircuitMessageVo.TDL();
String sql ="";
if(circuitVo.getEndTime() !=null && circuitVo.getEndTime()!=0){
sql = "SELECT \"b\" FROM \"tdl_policy\".\""+gatewayVo.getgType()+"_"+gatewayVo.getgSN()+"\" where \"tdl\"='"+TDL.get(i)+"' and time >="+circuitVo.getStartTime() + " and time<="+circuitVo.getEndTime() *1000000l+" ORDER BY time desc limit 1" ;
}else{
sql = "SELECT \"b\" FROM \"tdl_policy\".\""+gatewayVo.getgType()+"_"+gatewayVo.getgSN()+"\" where \"tdl\"='"+TDL.get(i)+"' and time >="+circuitVo.getStartTime() +" ORDER BY time desc limit 1";
}
QueryResult queryResult = influxDBTemplate.query(new Query(sql,database));
if(queryResult == null){
fb.setCode(0);
fb.setMessage("该线路不存在");
return gson.toJson(fb);
}
tdl.setTdlsn(TDL.get(i).replace("TDL-","").trim());
DecimalFormat df = new DecimalFormat("######0.0");
String value = queryResult.getResults().get(0).getSeries().get(0).getValues().get(0).get(1) ==null ? "" :queryResult.getResults().get(0).getSeries().get(0).getValues().get(0).get(1).toString();
tdl.setBatteryVoltage(Double.valueOf(df.format(Double.valueOf(value))));
tdlList.add(tdl);
}
messageVo.setTdlList(tdlList);
//获取线路情况
List<CircuitTransferVo> list =circuitTransferService.getCity(transportationNo);
if(list == null){
......
......@@ -137,7 +137,7 @@ public class HomePageController {
}
QueryResult queryResult = influxDBTemplate.query(new Query(sql, database));
if (queryResult.getResults().get(0).getSeries() != null) {
String value = queryResult.getResults().get(0).getSeries().get(0).getValues().get(0).get(0).toString();
circuitVo.setTime(parseTime(queryResult.getResults().get(0).getSeries().get(0).getValues().get(0).get(0).toString()));
circuitVo.setLng(queryResult.getResults().get(0).getSeries().get(0).getValues().get(0).get(1).toString());
circuitVo.setLat(queryResult.getResults().get(0).getSeries().get(0).getValues().get(0).get(2).toString());
......@@ -150,6 +150,8 @@ public class HomePageController {
return gson.toJson(dataVo);
}
//获取当天所有的设备数据
@ApiOperation(value = "获取所有的运输数据",notes = "获取运输设备数据:" +
"onRoute:在途数量;" +
......@@ -171,7 +173,6 @@ public class HomePageController {
}
//解析时间
public String parseTime(String time){
String dateResult =null;
......
......@@ -201,6 +201,7 @@ public class UserController {
userVo.setUserNumber(userNumber);
userVo.setCreateTime(System.currentTimeMillis());
userVo.setUpdateTime(System.currentTimeMillis());
userVo.setPassword(DigestUtils.sha256Hex(userVo.getPassword()));
int a=userService.addUser(userVo);
if (a>0){
fb.setCode(1);
......@@ -387,8 +388,6 @@ public class UserController {
UserRedisVo userRedisVo = gson.fromJson(datum,UserRedisVo.class);
//获取当前登录者的天气
String ip = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest().getRemoteAddr();
//获取当前公司的公司编号
return new UserNameVo(userRedisVo.getUserName(),System.currentTimeMillis() +"",ip);
}
......
......@@ -7,7 +7,7 @@ spring.datasource.driver-class-name=com.mysql.jdbc.Driver
threadpool.corepoolsize = 30
threadpool.maxpoolsize = 50
server.port=8099
server.port=8092
management.security.enabled=false
......@@ -40,7 +40,7 @@ logging.config=classpath:logback.xml
# Mqtt
tdl.mqtt.url = ssl://192.168.1.14
tdl.mqtt.url = ssl://192.168.1.11
tdl.mqtt.port = 8883
tdl.mqtt.username = ugen
tdl.mqtt.password = ugen
......
......@@ -21,17 +21,20 @@
from circuit c
where c.state=1
AND company_id=(SELECT id from company where companyName=#{companyName,jdbcType=VARCHAR})
<if test="time !=null">
AND DATE_SUB(CURDATE(), INTERVAL #{time,jdbcType=VARCHAR} DAY) &lt;= date(FROM_UNIXTIME(createTime/1000,'%Y-%m-%d %H:%i:%s'))
</if>
<if test="circuitState!=null">
AND circuitState=#{circuitState,jdbcType=INTEGER}
AND c.circuitState=#{circuitState,jdbcType=INTEGER}
</if>
<if test="cargoNo!=null">
AND cargoNo like CONCAT(CONCAT('%',#{cargoNo,jdbcType=VARCHAR}),'%')
AND c.cargoNo like CONCAT(CONCAT('%',#{cargoNo,jdbcType=VARCHAR}),'%')
</if>
<if test="startTime!=null">
AND startTime &gt;= #{startTime,jdbcType=BIGINT}
AND c.startTime &gt;= #{startTime,jdbcType=BIGINT}
</if>
<if test="endTime!=null">
AND endTime &lt;= #{endTime,jdbcType=BIGINT}
AND c.endTime &lt;= #{endTime,jdbcType=BIGINT}
</if>
</select>
......@@ -331,6 +334,19 @@
and company_id = (SELECT id from company where companyName=#{companyName,jdbcType=VARCHAR})
and circuitState = 1
</select>
<select id="getMessage" parameterType="String" resultType="com.example.tdl.domain.vo.CircuitMessage">
select c.transportationNo,CONCAT_WS("-",(SELECT city from city WHERE id =(SELECT city_id from circuit_transfer WHERE circuit_id=c.id AND sequence =LEFT(s.sequence,1))),(SELECT city from city WHERE id =(SELECT city_id from circuit_transfer WHERE circuit_id=c.id AND sequence=RIGHT(s.sequence,1)))) routeName,
cargoName,plateNo,transportation,IFNULL(evaluate,"") evaluate,circuitState,startTime,endTime,
(SELECT alarmType FROM alarm WHERE id IN (SELECT alarm_id from tdl_gateway_log WHERE transportationNo=c.transportationNo)) alarmType
from circuit c,(SELECT GROUP_CONCAT(sequence) sequence from circuit_transfer where circuit_id=(SELECT id from circuit where transportationNo=#{transportationNo,jdbcType=VARCHAR})) s
where c.state = 1
and c.transportationNo=#{transportationNo,jdbcType=VARCHAR}
</select>
<!--
<select id="getDistinct" resultType="com.example.tdl.domain.vo.CircuitVo">
SELECT transportationNo,routeName,startLongitude,startLatitude,(select city from city_config where id=r.start_id) startCity,startTime,endLongitude,endLatitude,
......
......@@ -57,7 +57,10 @@
<!--解绑成功-->
<update id="delConfig" parameterType="String">
update config set state = 0 where gSN= #{gSN,jdbcType=VARCHAR} and gType=#{gType,jdbcType=VARCHAR} and state = 1;
update config set state = 0
where gSN= #{gSN,jdbcType=VARCHAR}
and gType=#{gType,jdbcType=VARCHAR}
and state = 1;
</update>
<!--<insert id="addConfig" parameterType="com.example.tdl.domain.vo.ConfigVo">-->
......
......@@ -18,4 +18,11 @@
from tdl_gateway_log
where transportationNo = #{transportationNo,jdbcType=VARCHAR}
</select>
<select id="getSN" parameterType="String" resultType="String">
select DISTINCT gatewaySN
from tdl_gateway_log
where transportationNo = #{transportationNo,jdbcType=VARCHAR}
</select>
</mapper>
\ No newline at end of file
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