Commit b8d0e060 authored by zhuangzhuang's avatar zhuangzhuang

3.30--将线路报警传入redis,增加报警,手机端新增线路接口

parent 521b63a3
...@@ -84,14 +84,14 @@ public class GWConfigWorker implements Callable<String>, MqttCallback { ...@@ -84,14 +84,14 @@ public class GWConfigWorker implements Callable<String>, MqttCallback {
this.clientpwd = mclientpwd; this.clientpwd = mclientpwd;
} }
public GWConfigWorker(String type,String sn, String CMD,Boolean flag) throws Exception{ public GWConfigWorker(String type,String SN, String CMD,Boolean flag) throws Exception{
this.SN = sn; this.SN = SN;
this.Type = type; this.Type = type;
this.Device = Type + "_" + SN; this.Device = Type + "_" + SN;
this.ConfigCMD = CMD; this.ConfigCMD = CMD;
this.NeedResp = flag; this.NeedResp = flag;
this.ConfigTopic = "GW/" + Type + "/" + SN + PUB_TOPIC; this.ConfigTopic = "TDL/" + Type + "/" + SN + PUB_TOPIC;
this.RespTopic = "GW/" + Type + "/" + SN + SUB_TOPIC; this.RespTopic = "TDL/" + Type + "/" + SN + SUB_TOPIC;
} }
@Override @Override
...@@ -214,4 +214,13 @@ public class GWConfigWorker implements Callable<String>, MqttCallback { ...@@ -214,4 +214,13 @@ public class GWConfigWorker implements Callable<String>, MqttCallback {
mqttAsyncClient.publish(ConfigTopic,msg); mqttAsyncClient.publish(ConfigTopic,msg);
} }
public void GCConfigClose(){
try {
mqttAsyncClient.disconnect();
}catch (Exception e){
e.printStackTrace();
}
}
} }
...@@ -22,9 +22,9 @@ public class MyWebMvcConfigurer extends WebMvcConfigurerAdapter { ...@@ -22,9 +22,9 @@ public class MyWebMvcConfigurer extends WebMvcConfigurerAdapter {
@Override @Override
public void addInterceptors(InterceptorRegistry registry) { public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(loginInterceptor()) registry.addInterceptor(loginInterceptor()).excludePathPatterns("/alarmLog/**")
.excludePathPatterns("/login/**"); .excludePathPatterns("/login/**");
registry.addInterceptor(permissionInterceptor()).excludePathPatterns("/login/**"); registry.addInterceptor(permissionInterceptor()).excludePathPatterns("/login/**").excludePathPatterns("/alarmLog/add");
super.addInterceptors(registry); super.addInterceptors(registry);
} }
} }
package com.example.tdl.domain.vo; package com.example.tdl.domain.vo;
import java.util.List;
public class AddAlarmLogVo { public class AddAlarmLogVo {
private String transportationNo; private Integer mode;
private String TDLSN; private String gSN;
private String description; private String gType;
private Float data; private Long ts;
private Long alarmTime; private List<AlarmData> alarm;
public AddAlarmLogVo() { public static class AlarmData {
} private String TDLSN;
private String desp;
private Float value;
private Long ts;
public AlarmData() {
}
public AlarmData(String TDLSN, String desp, Float value, Long ts) {
this.TDLSN = TDLSN;
this.desp = desp;
this.value = value;
this.ts = ts;
}
public String getTDLSN() {
return TDLSN;
}
public void setTDLSN(String TDLSN) {
this.TDLSN = TDLSN;
}
public String getDesp() {
return desp;
}
public void setDesp(String desp) {
this.desp = desp;
}
public Float getValue() {
return value;
}
public void setValue(Float value) {
this.value = value;
}
public Long getTs() {
return ts;
}
public AddAlarmLogVo(String transportationNo, String TDLSN, String description, Float data, Long alarmTime) { public void setTs(Long ts) {
this.transportationNo = transportationNo; this.ts = ts;
this.TDLSN = TDLSN; }
this.description = description;
this.data = data;
this.alarmTime = alarmTime;
} }
public String getTransportationNo() { public Integer getMode() {
return transportationNo; return mode;
} }
public void setTransportationNo(String transportationNo) { public void setMode(Integer mode) {
this.transportationNo = transportationNo; this.mode = mode;
} }
public String getTDLSN() { public String getgSN() {
return TDLSN; return gSN;
} }
public void setTDLSN(String TDLSN) { public void setgSN(String gSN) {
this.TDLSN = TDLSN; this.gSN = gSN;
} }
public String getDescription() { public String getgType() {
return description; return gType;
} }
public void setDescription(String description) { public void setgType(String gType) {
this.description = description; this.gType = gType;
} }
public Float getData() { public Long getTs() {
return data; return ts;
} }
public void setData(Float data) { public void setTs(Long ts) {
this.data = data; this.ts = ts;
} }
public Long getAlarmTime() { public List<AlarmData> getAlarm() {
return alarmTime; return alarm;
} }
public void setAlarmTime(Long alarmTime) { public void setAlarm(List<AlarmData> alarm) {
this.alarmTime = alarmTime; this.alarm = alarm;
} }
} }
package com.example.tdl.domain.vo;
public class AddCircuit {
private String cargoNo;//货物编号
private String plateNo;//车牌号
private String cargoName;
private String transportation;
private StartAddressVo startAddressVo;
private EndAddressVo endAddressVo;
private String deliveryAddress;
private String transportationType;
private String remark;
public String getCargoNo() {
return cargoNo;
}
public void setCargoNo(String cargoNo) {
this.cargoNo = cargoNo;
}
public String getPlateNo() {
return plateNo;
}
public void setPlateNo(String plateNo) {
this.plateNo = plateNo;
}
public String getCargoName() {
return cargoName;
}
public void setCargoName(String cargoName) {
this.cargoName = cargoName;
}
public String getTransportation() {
return transportation;
}
public void setTransportation(String transportation) {
this.transportation = transportation;
}
public StartAddressVo getStartAddressVo() {
return startAddressVo;
}
public void setStartAddressVo(StartAddressVo startAddressVo) {
this.startAddressVo = startAddressVo;
}
public EndAddressVo getEndAddressVo() {
return endAddressVo;
}
public void setEndAddressVo(EndAddressVo endAddressVo) {
this.endAddressVo = endAddressVo;
}
public String getDeliveryAddress() {
return deliveryAddress;
}
public void setDeliveryAddress(String deliveryAddress) {
this.deliveryAddress = deliveryAddress;
}
public String getTransportationType() {
return transportationType;
}
public void setTransportationType(String transportationType) {
this.transportationType = transportationType;
}
public String getRemark() {
return remark;
}
public void setRemark(String remark) {
this.remark = remark;
}
}
...@@ -41,4 +41,14 @@ public class LocationDataVo { ...@@ -41,4 +41,14 @@ public class LocationDataVo {
public void setError(Integer error) { public void setError(Integer error) {
this.error = error; this.error = error;
} }
@Override
public String toString() {
return "{" +
"\"time\""+":\"" + time + '\"' +
",\"lng\""+":" + lng +
",\" lat\""+":" + lat +
", \"error\""+":" + error +
'}';
}
} }
...@@ -6,7 +6,7 @@ public class AlarmLog { ...@@ -6,7 +6,7 @@ public class AlarmLog {
private String transportationNo; private String transportationNo;
private String routeName; private String TDLSN;
private String description; private String description;
...@@ -14,6 +14,16 @@ public class AlarmLog { ...@@ -14,6 +14,16 @@ public class AlarmLog {
private Long alarmTime; private Long alarmTime;
private String classify;
public AlarmLog(String transportationNo, String TDLSN, String description, Float data, Long alarmTime, String classify) {
this.transportationNo = transportationNo;
this.TDLSN = TDLSN;
this.description = description;
this.data = data;
this.alarmTime = alarmTime;
this.classify = classify;
}
public Integer getId() { public Integer getId() {
return id; return id;
...@@ -31,12 +41,12 @@ public class AlarmLog { ...@@ -31,12 +41,12 @@ public class AlarmLog {
this.transportationNo = transportationNo; this.transportationNo = transportationNo;
} }
public String getRouteName() { public String getTDLSN() {
return routeName; return TDLSN;
} }
public void setRouteName(String routeName) { public void setTDLSN(String TDLSN) {
this.routeName = routeName; this.TDLSN = TDLSN;
} }
public String getDescription() { public String getDescription() {
...@@ -62,4 +72,12 @@ public class AlarmLog { ...@@ -62,4 +72,12 @@ public class AlarmLog {
public void setAlarmTime(Long alarmTime) { public void setAlarmTime(Long alarmTime) {
this.alarmTime = alarmTime; this.alarmTime = alarmTime;
} }
public String getClassify() {
return classify;
}
public void setClassify(String classify) {
this.classify = classify;
}
} }
...@@ -4,6 +4,7 @@ import com.example.tdl.domain.vo.AddAlarmLogVo; ...@@ -4,6 +4,7 @@ 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.HistogramData; import com.example.tdl.domain.vo.HistogramData;
import com.example.tdl.domain.vo.ResultAlarmLog; import com.example.tdl.domain.vo.ResultAlarmLog;
import com.example.tdl.entity.AlarmLog;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Param;
...@@ -18,7 +19,7 @@ public interface AlarmLogMapper { ...@@ -18,7 +19,7 @@ public interface AlarmLogMapper {
List<AlarmLogVo> getAlarmLog(String time); List<AlarmLogVo> getAlarmLog(String time);
//新增报警数据 //新增报警数据
int addAlarmLog(AddAlarmLogVo addAlarmLogVo); int addAlarmLog(AlarmLog addAlarmLogVo);
List<ResultAlarmLog> getByTransportationNo(String transportationNo); List<ResultAlarmLog> getByTransportationNo(String transportationNo);
......
...@@ -17,6 +17,8 @@ public interface CircuitMapper { ...@@ -17,6 +17,8 @@ public interface CircuitMapper {
int addCircuit(Map<Object,Object> map); int addCircuit(Map<Object,Object> map);
int add(Map<Object,Object> map);
int updateCircuit(Map<Object,Object> map); int updateCircuit(Map<Object,Object> map);
int updateEndTime(UpdateCircuitVo updateCircuitVo); int updateEndTime(UpdateCircuitVo updateCircuitVo);
......
...@@ -28,4 +28,6 @@ public interface GatewayMapper { ...@@ -28,4 +28,6 @@ public interface GatewayMapper {
String getBySN(String SN); String getBySN(String SN);
Integer updateState(GatewayState gatewayState); Integer updateState(GatewayState gatewayState);
String getTransportationNo(@Param("SN") String SN,@Param("type") String type);
} }
...@@ -25,4 +25,7 @@ public interface TDLDeviceMapper { ...@@ -25,4 +25,7 @@ public interface TDLDeviceMapper {
ResultTDLDeviceVo getByTDLSN(String TDLSN); ResultTDLDeviceVo getByTDLSN(String TDLSN);
List<String> getByGatewaySN(@Param("SN") String SN, @Param("type") String type); List<String> getByGatewaySN(@Param("SN") String SN, @Param("type") String type);
List<String> getTdlSN(@Param("SN") String SN, @Param("type") String type);
} }
...@@ -124,52 +124,52 @@ public class MqttListener implements MqttCallback { ...@@ -124,52 +124,52 @@ public class MqttListener implements MqttCallback {
public void messageArrived(String topic, MqttMessage mqttMessage) throws Exception { public void messageArrived(String topic, MqttMessage mqttMessage) throws Exception {
String Message = mqttMessage.toString(); String Message = mqttMessage.toString();
Long timestamp = System.currentTimeMillis(); Long timestamp = System.currentTimeMillis();
try { String[] tmparray = topic.split("/");
String[] tmparray = topic.split("/"); String Type = tmparray[1];
String Type = tmparray[1]; String SN = tmparray[2];
String SN = tmparray[2]; if(SN.matches("^[0-9]*$")){
Integer flag = parseData(Message,SN,Type); try {
// String ConfigData ="{\"action\":\"config\"}"; Integer flag = parseData(Message,SN,Type);
String ConfigData; // String ConfigData ="{\"action\":\"config\"}";
Future<String> result = null; String ConfigData;
GWConfigWorker gcconfig = null; Future<String> result = null;
if(flag == 0){ GWConfigWorker gcconfig = null;
ConfigCMDVo configCMDVo = new ConfigCMDVo(); if(flag == 0){
configCMDVo.setAction("sleep"); ConfigCMDVo configCMDVo = new ConfigCMDVo();
configCMDVo.setT(System.currentTimeMillis()/1000l); configCMDVo.setAction("sleep");
ConfigData = new Gson().toJson(configCMDVo); configCMDVo.setT(System.currentTimeMillis()/1000l);
gcconfig = new GWConfigWorker(Type,SN,ConfigData, false); ConfigData = new Gson().toJson(configCMDVo);
}else if(flag == 2){ gcconfig = new GWConfigWorker(Type,SN,ConfigData, false);
ConfigCMDVo configCMDVo = new ConfigCMDVo(); }else if(flag == 2){
configCMDVo.setAction("end"); ConfigCMDVo configCMDVo = new ConfigCMDVo();
configCMDVo.setT(System.currentTimeMillis()/1000l); configCMDVo.setAction("end");
ConfigData = new Gson().toJson(configCMDVo); configCMDVo.setT(System.currentTimeMillis()/1000l);
gcconfig = new GWConfigWorker(Type,SN,ConfigData, true); ConfigData = new Gson().toJson(configCMDVo);
}else if(flag == 1){ gcconfig = new GWConfigWorker(Type,SN,ConfigData, true);
ConfigData = configService.getConfig(SN,Type).getMessage(); }else if(flag == 1){
gcconfig = new GWConfigWorker(Type,SN,ConfigData, true); ConfigData = configService.getConfig(SN,Type).getMessage();
} gcconfig = new GWConfigWorker(Type,SN,ConfigData,true);
}
gcconfig.SetMqttConfig(mqttconfig.getUrl(),mqttconfig.getPort(), gcconfig.SetMqttConfig(mqttconfig.getUrl(),mqttconfig.getPort(),
mqttconfig.getUsername(), mqttconfig.getPassword(),mqttconfig.getQos(), mqttconfig.getUsername(), mqttconfig.getPassword(),mqttconfig.getQos(),
mqttconfig.getCacrt(),mqttconfig.getClientkey(), mqttconfig.getClientcrt(),mqttconfig.getClientpwd()); mqttconfig.getCacrt(),mqttconfig.getClientkey(), mqttconfig.getClientcrt(),mqttconfig.getClientpwd());
result = configthreadPool.submit(gcconfig); result = configthreadPool.submit(gcconfig);
// while (result.isDone()) // while (result.isDone())
// { // {
// String respcmd = result.get(); // String respcmd = result.get();
// } // }
// futureMap.put(timestamp.toString(),result); // futureMap.put(timestamp.toString(),result);
} catch (JsonSyntaxException e) {
} catch (JsonSyntaxException e) { e.printStackTrace();
e.printStackTrace(); System.out.println("mqttAsyncClient: message " + Message + " received syntax error.");
System.out.println("mqttAsyncClient: message " + Message + " received syntax error."); } catch (IllegalStateException e) {
} catch (IllegalStateException e) { e.printStackTrace();
e.printStackTrace(); System.out.println("mqttAsyncClient: " + e);
System.out.println("mqttAsyncClient: " + e); } catch (Exception e) {
} catch (Exception e) { e.printStackTrace();
e.printStackTrace(); System.out.println(e.toString());
System.out.println(e.toString()); }
} }
} }
......
...@@ -4,6 +4,7 @@ import com.example.tdl.domain.vo.AddAlarmLogVo; ...@@ -4,6 +4,7 @@ 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.HistogramData; import com.example.tdl.domain.vo.HistogramData;
import com.example.tdl.domain.vo.ResultAlarmLog; import com.example.tdl.domain.vo.ResultAlarmLog;
import com.example.tdl.entity.AlarmLog;
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;
...@@ -24,7 +25,7 @@ public class AlarmLogService { ...@@ -24,7 +25,7 @@ public class AlarmLogService {
return alarmLogMapper.getAlarmLog(time); return alarmLogMapper.getAlarmLog(time);
} }
public int addAlarmLog(AddAlarmLogVo addAlarmLogVo){ public int addAlarmLog(AlarmLog addAlarmLogVo){
return alarmLogMapper.addAlarmLog(addAlarmLogVo); return alarmLogMapper.addAlarmLog(addAlarmLogVo);
} }
......
...@@ -26,6 +26,10 @@ public class CircuitService { ...@@ -26,6 +26,10 @@ public class CircuitService {
return circuitMapper.addCircuit(map); return circuitMapper.addCircuit(map);
} }
public int add(Map<Object,Object> map){
return circuitMapper.add(map);
}
public int updateCircuit(Map<Object,Object> map){ public int updateCircuit(Map<Object,Object> map){
return circuitMapper.updateCircuit(map); return circuitMapper.updateCircuit(map);
} }
......
...@@ -50,4 +50,8 @@ public class GatewayService { ...@@ -50,4 +50,8 @@ public class GatewayService {
public Boolean updateState(GatewayState gatewayState){ public Boolean updateState(GatewayState gatewayState){
return gatewayMapper.updateState(gatewayState)==1; return gatewayMapper.updateState(gatewayState)==1;
} }
public String getTransportationNo(String SN,String type){
return gatewayMapper.getTransportationNo(SN,type);
}
} }
...@@ -42,4 +42,8 @@ public class TDLDeviceService { ...@@ -42,4 +42,8 @@ public class TDLDeviceService {
public List<String> getByGatewaySN(String SN,String type){ public List<String> getByGatewaySN(String SN,String type){
return tdlDeviceMapper.getByGatewaySN(SN,type); return tdlDeviceMapper.getByGatewaySN(SN,type);
} }
public List<String> getTdlSN(String SN,String type){
return tdlDeviceMapper.getTdlSN(SN,type);
}
} }
...@@ -2,7 +2,9 @@ package com.example.tdl.web; ...@@ -2,7 +2,9 @@ package com.example.tdl.web;
import com.example.tdl.domain.dto.CommFeedback; import com.example.tdl.domain.dto.CommFeedback;
import com.example.tdl.domain.vo.AddAlarmLogVo; import com.example.tdl.domain.vo.AddAlarmLogVo;
import com.example.tdl.entity.AlarmLog;
import com.example.tdl.service.AlarmLogService; import com.example.tdl.service.AlarmLogService;
import com.example.tdl.service.GatewayService;
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;
...@@ -25,45 +27,57 @@ public class AlarmLogController { ...@@ -25,45 +27,57 @@ public class AlarmLogController {
@Autowired @Autowired
private AlarmLogService alarmLogServcie; private AlarmLogService alarmLogServcie;
@Autowired
private GatewayService gatewayService;
//新增报警消息 //新增报警消息
@PostMapping("/addAlarmLog") @RequestMapping(value = "/addAlarmLog",method = RequestMethod.POST)
@ApiImplicitParams({ public String addAlarmLog(@RequestBody AddAlarmLogVo addAlarmLogVo){
@ApiImplicitParam(paramType="header", name = "Account_token", value = "token", required = true, dataType = "String"), if(StringUtils.isEmpty(addAlarmLogVo.getgSN())){
})
public Object addAlarmLog(@RequestBody AddAlarmLogVo addAlarmLogVo){
if(StringUtils.isEmpty(addAlarmLogVo.getTransportationNo())){
fb.setCode(0);
fb.setMessage("运输编号不能为空");
return gson.toJson(fb);
}
if(StringUtils.isEmpty(addAlarmLogVo.getTDLSN())){
fb.setCode(0); fb.setCode(0);
fb.setMessage("路由名称不能为空"); fb.setMessage("网关序列号不能为空");
return gson.toJson(fb);
} }
if(StringUtils.isEmpty(addAlarmLogVo.getDescription())){ if(StringUtils.isEmpty(addAlarmLogVo.getgType())){
fb.setCode(0); fb.setCode(0);
fb.setMessage("报警描述不能为空"); fb.setMessage("网关类型不能为空");
return gson.toJson(fb);
} }
if(addAlarmLogVo.getData() == null){ if(addAlarmLogVo.getAlarm()==null){
fb.setCode(0); fb.setCode(0);
fb.setMessage("报警数据不能为空"); fb.setMessage("报警数据不能为空");
return gson.toJson(fb);
} }
if(addAlarmLogVo.getAlarmTime() == null){ if(addAlarmLogVo.getTs() == null){
fb.setCode(0); fb.setCode(0);
fb.setMessage("报警时间不能为空"); fb.setMessage("时间不能为空");
return gson.toJson(fb);
} }
//获取报警的线路信息 //根据gateway的信息获取线路信息
int i= alarmLogServcie.addAlarmLog(addAlarmLogVo); String transportationNo = gatewayService.getTransportationNo(addAlarmLogVo.getgSN(),addAlarmLogVo.getgType());
if(i == 0){ for(int i = 0;i<addAlarmLogVo.getAlarm().size();i++){
fb.setCode(0); // String classify="";
fb.setMessage("添加成功"); // if(addAlarmLogVo.getAlarm().get(i).getDesp().contains("温度")){
}else{ // classify = "1";
fb.setCode(0); // } else if(addAlarmLogVo.getAlarm().get(i).getDesp().contains("湿度")){
fb.setMessage("添加失败"); // classify = "2";
// } else if(addAlarmLogVo.getAlarm().get(i).getDesp().contains("震动")){
// classify = "3";
// } else if(addAlarmLogVo.getAlarm().get(i).getDesp().contains("倾角")){
// classify = "4";
// }
//// else if(addAlarmLogVo.getAlarm().get(i).getDesp().contains("光爆")){
//// classify = "5";
//// }
// else if(addAlarmLogVo.getAlarm().get(i).getDesp().contains("离线")){
// classify = "6";
// }
// AlarmLog alarmLog = new AlarmLog(transportationNo,addAlarmLogVo.getAlarm().get(i).getTDLSN(),addAlarmLogVo.getAlarm().get(i).getDesp(),addAlarmLogVo.getAlarm().get(i).getValue(),addAlarmLogVo.getAlarm().get(i).getTs()*1000,classify);
AlarmLog alarmLog = new AlarmLog(transportationNo,addAlarmLogVo.getAlarm().get(i).getTDLSN(),"温度异常",addAlarmLogVo.getAlarm().get(i).getValue(),addAlarmLogVo.getAlarm().get(i).getTs()*1000,"1");
int a = alarmLogServcie.addAlarmLog(alarmLog);
if(a == 0){
fb.setCode(0);
fb.setMessage("添加失败");
}else{
fb.setCode(1);
fb.setMessage("添加成功");
}
} }
return gson.toJson(fb); return gson.toJson(fb);
} }
......
...@@ -6,6 +6,7 @@ import com.alibaba.fastjson.JSONObject; ...@@ -6,6 +6,7 @@ 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.AlarmRedisService;
import com.example.tdl.service.redis.TokenRedisService; import com.example.tdl.service.redis.TokenRedisService;
import com.google.gson.Gson; import com.google.gson.Gson;
import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParam;
...@@ -45,6 +46,20 @@ public class CircuitController { ...@@ -45,6 +46,20 @@ public class CircuitController {
@Autowired @Autowired
private AlarmLogService alarmLogService; private AlarmLogService alarmLogService;
@Autowired
private AlarmRedisService alarmRedisService;
@Autowired
private AlarmService alarmService;
List<String> list = new ArrayList<String>(){{
add("T");
add("h");
add("a0");
add("ta");
}};
//获取线路信息 //获取线路信息
@ApiOperation(value = "获取线路信息",notes = "获取线路信息,返回值说明:" + @ApiOperation(value = "获取线路信息",notes = "获取线路信息,返回值说明:" +
" transportationNo:运输编号," + " transportationNo:运输编号," +
...@@ -131,7 +146,7 @@ public class CircuitController { ...@@ -131,7 +146,7 @@ public class CircuitController {
"lat:纬度" + "lat:纬度" +
"postCode:邮编"+ "postCode:邮编"+
"compTime:预计结束时间,(传时间戳)}" + "compTime:预计结束时间,(传时间戳)}" +
" gSN:网关编号," + " SN:网关编号," +
" tdlAlarmList: " + " tdlAlarmList: " +
"{TDLSN:tdl编号," + "{TDLSN:tdl编号," +
" alarmType:报警类型,}" + " alarmType:报警类型,}" +
...@@ -373,7 +388,8 @@ public class CircuitController { ...@@ -373,7 +388,8 @@ public class CircuitController {
} }
alarmTypeVar =alarmTypeVar + addCircuitVo.getTdlAlarmList().get(j).getAlarmType() +" "; alarmTypeVar =alarmTypeVar + addCircuitVo.getTdlAlarmList().get(j).getAlarmType() +" ";
TDLSNVar =TDLSNVar + addCircuitVo.getTdlAlarmList().get(j).getTDLSN() +" "; TDLSNVar =TDLSNVar + addCircuitVo.getTdlAlarmList().get(j).getTDLSN() +" ";
devList.add(addCircuitVo.getTdlAlarmList().get(j).getTDLSN()); devList.add("tdl-"+addCircuitVo.getTdlAlarmList().get(j).getTDLSN());
saveAlarmRule("TDL/"+type+"/" +addCircuitVo.getSN()+"/Data",addCircuitVo.getTdlAlarmList().get(j).getTDLSN(),addCircuitVo.getTdlAlarmList().get(j).getAlarmType());
} }
if(StringUtils.isEmpty(addCircuitVo.getCargoNo())){ if(StringUtils.isEmpty(addCircuitVo.getCargoNo())){
...@@ -394,7 +410,7 @@ public class CircuitController { ...@@ -394,7 +410,7 @@ public class CircuitController {
//根据sn获取type //根据sn获取type
ConfigCMDVo configCMDVo = new ConfigCMDVo("config",5,15,devList,1); ConfigCMDVo configCMDVo = new ConfigCMDVo("config",5,15,devList,1);
Map<Object,Object> map=new HashMap<>(); Map<Object,Object> map=new HashMap<>();
String transportation = "汽运"; String transportation = "公路";
String transportationType="本地运输"; String transportationType="本地运输";
map.put("transportationNo",getTransportNo(transportation,transportationType)); map.put("transportationNo",getTransportNo(transportation,transportationType));
map.put("startTime",time); map.put("startTime",time);
...@@ -408,7 +424,7 @@ public class CircuitController { ...@@ -408,7 +424,7 @@ public class CircuitController {
map.put("transportationType",transportationType); map.put("transportationType",transportationType);
map.put("createTime",time); map.put("createTime",time);
map.put("remark",addCircuitVo.getRemark()); map.put("remark",addCircuitVo.getRemark());
map.put("counts",addCircuitVo.getAddressVoList()== null ? 0 : addCircuitVo.getAddressVoList().size()); map.put("counts",addCircuitVo.getAddressVoList()== null ? 2 : addCircuitVo.getAddressVoList().size()+2);
map.put("countryVar",countryVar); map.put("countryVar",countryVar);
map.put("cityVar",cityVar); map.put("cityVar",cityVar);
map.put("addressDetailVar",addressDetailVar); map.put("addressDetailVar",addressDetailVar);
...@@ -433,6 +449,7 @@ public class CircuitController { ...@@ -433,6 +449,7 @@ public class CircuitController {
if (msg.get("msg").equals("添加线路成功")){ if (msg.get("msg").equals("添加线路成功")){
fb.setCode(1); fb.setCode(1);
fb.setMessage("添加线路成功"); fb.setMessage("添加线路成功");
}else { }else {
fb.setCode(0); fb.setCode(0);
fb.setMessage(msg.get("msg").toString()); fb.setMessage(msg.get("msg").toString());
...@@ -441,6 +458,241 @@ public class CircuitController { ...@@ -441,6 +458,241 @@ public class CircuitController {
} }
@ApiOperation(value = "添加线路信息----mobile",notes = "添加线路信息," +
" cargoNo:货物编号," +
" plateNo:车牌号," +
" cargoName:货物别名," +
" transportation:运输方式,(公路,铁路,海运,空运,快递)" +
" startAddressVo: 启运城市,包含" +
"{country:国家," +
"city:城市," +
"addressDetail:详细地址," +
"lng:经度," +
"lat:纬度," +
"postCode:邮编,"+
"expTime:预计开始时间,(13位时间戳)}" +
" endAddressVo: 目的城市,包含" +
"{country:国家," +
"city:城市," +
"addressDetail:详细地址," +
"lng:经度," +
"lat:纬度," +
"postCode:邮编,"+
"compTime:预计结束时间,(13位时间戳)}" +
" deliveryAddress:交付地点,(站点,仓库,港口)" +
" transportationType:运输类型,(本地运输,国际运输)" +
" remark:备注,")
@ApiImplicitParams({
@ApiImplicitParam(paramType="header", name = "Account_token", value = "token", required = true, dataType = "String"),
})
@RequestMapping(value="/add",method = RequestMethod.POST)
public Object add(@RequestBody AddCircuit addCircuitVo){
if(StringUtils.isEmpty(addCircuitVo.getCargoNo())){
fb.setCode(0);
fb.setMessage("货物编号不能为空");
return gson.toJson(fb);
}
if(StringUtils.isEmpty(addCircuitVo.getPlateNo())){
fb.setCode(0);
fb.setMessage("车牌号不能为空");
return gson.toJson(fb);
}
if(StringUtils.isEmpty(addCircuitVo.getCargoName())){
fb.setCode(0);
fb.setMessage("货物别名不能为空");
return gson.toJson(fb);
}
if(StringUtils.isEmpty(addCircuitVo.getTransportation())){
fb.setCode(0);
fb.setMessage("运输方式不能为空");
return gson.toJson(fb);
}
if(StringUtils.isEmpty(addCircuitVo.getStartAddressVo().getCountry())){
fb.setCode(0);
fb.setMessage("出发国家不能为空");
return gson.toJson(fb);
}
if (StringUtils.isEmpty(addCircuitVo.getStartAddressVo().getCity())){
fb.setCode(0);
fb.setMessage("出发城市不能为空");
return gson.toJson(fb);
}
if (StringUtils.isEmpty(addCircuitVo.getStartAddressVo().getAddressDetail())){
fb.setCode(0);
fb.setMessage("出发具体地址不能为空");
return gson.toJson(fb);
}
if (StringUtils.isEmpty(addCircuitVo.getStartAddressVo().getLat())){
fb.setCode(0);
fb.setMessage("出发地纬度不能为空");
return gson.toJson(fb);
}
if(!addCircuitVo.getStartAddressVo().getLat().matches("^-?(([1-9])((\\.\\d{1,6})?)|([1-8]\\d)((\\.\\d{1,6})?)|90)$")){
fb.setCode(0);
fb.setMessage("出发地纬度的范围为-90~90");
return gson.toJson(fb);
}
if (StringUtils.isEmpty(addCircuitVo.getStartAddressVo().getLng())){
fb.setCode(0);
fb.setMessage("出发地经度不能为空");
return gson.toJson(fb);
}
if(!addCircuitVo.getStartAddressVo().getLng().matches("^-?(([1-9]\\d?)((\\.\\d{1,6})?)|(1[1-7]\\d)((\\.\\d{1,6})?)|180)$")) {
fb.setCode(0);
fb.setMessage("出发地经度的范围为-180~180");
return gson.toJson(fb);
}
if (StringUtils.isEmpty(addCircuitVo.getStartAddressVo().getPostCode())){
fb.setCode(0);
fb.setMessage("出发地邮编不能为空");
return gson.toJson(fb);
}
if (addCircuitVo.getStartAddressVo().getExpTime()==null){
fb.setCode(0);
fb.setMessage("出发地预计出发时间不能为空");
return gson.toJson(fb);
}
if(StringUtils.isEmpty(addCircuitVo.getEndAddressVo().getCountry())){
fb.setCode(0);
fb.setMessage("目的地国家不能为空");
return gson.toJson(fb);
}
if (StringUtils.isEmpty(addCircuitVo.getEndAddressVo().getCity())){
fb.setCode(0);
fb.setMessage("目的地城市不能为空");
return gson.toJson(fb);
}
if (StringUtils.isEmpty(addCircuitVo.getEndAddressVo().getAddressDetail())){
fb.setCode(0);
fb.setMessage("目的地具体地址不能为空");
return gson.toJson(fb);
}
if (StringUtils.isEmpty(addCircuitVo.getEndAddressVo().getLat())){
fb.setCode(0);
fb.setMessage("目的地纬度不能为空");
return gson.toJson(fb);
}
if(!addCircuitVo.getEndAddressVo().getLat().matches("^-?(([1-9])((\\.\\d{1,6})?)|([1-8]\\d)((\\.\\d{1,6})?)|90)$")){
fb.setCode(0);
fb.setMessage("目的地纬度的范围为-90~90");
return gson.toJson(fb);
}
if (StringUtils.isEmpty(addCircuitVo.getEndAddressVo().getLng())){
fb.setCode(0);
fb.setMessage("目的地经度不能为空");
return gson.toJson(fb);
}
if(!addCircuitVo.getEndAddressVo().getLng().matches("^-?(([1-9]\\d?)((\\.\\d{1,6})?)|(1[1-7]\\d)((\\.\\d{1,6})?)|180)$")) {
fb.setCode(0);
fb.setMessage("目的地经度的范围为-180~180");
return gson.toJson(fb);
}
if (StringUtils.isEmpty(addCircuitVo.getEndAddressVo().getPostCode())){
fb.setCode(0);
fb.setMessage("目的地邮编不能为空");
return gson.toJson(fb);
}
if (addCircuitVo.getEndAddressVo().getCompTime()==null){
fb.setCode(0);
fb.setMessage("目的地预计到达时间不能为空");
return gson.toJson(fb);
}
if(StringUtils.isEmpty(addCircuitVo.getDeliveryAddress())){
fb.setCode(0);
fb.setMessage("交付地点不能为空");
return gson.toJson(fb);
}
if(StringUtils.isEmpty(addCircuitVo.getTransportationType())){
fb.setCode(0);
fb.setMessage("运输类型不能为空");
return gson.toJson(fb);
}
Long time = System.currentTimeMillis();
String countryVar=addCircuitVo.getStartAddressVo().getCountry()+" "+addCircuitVo.getEndAddressVo().getCountry() +" ";
String cityVar=addCircuitVo.getStartAddressVo().getCity()+ " "+addCircuitVo.getEndAddressVo().getCity() +" ";
String addressDetailVar=addCircuitVo.getStartAddressVo().getAddressDetail() +" "+addCircuitVo.getEndAddressVo().getAddressDetail() +" ";
String lngVar=addCircuitVo.getStartAddressVo().getLng()+" "+ addCircuitVo.getEndAddressVo().getLng() +" ";
String latVar = addCircuitVo.getStartAddressVo().getLat()+" "+ addCircuitVo.getEndAddressVo().getLat() +" ";
String postCodeVar = addCircuitVo.getStartAddressVo().getPostCode()+" "+ addCircuitVo.getEndAddressVo().getPostCode() +" ";
String expTimeVar = addCircuitVo.getStartAddressVo().getExpTime()+" "+"0 ";
String compTimeVar = "0 "+addCircuitVo.getEndAddressVo().getCompTime() +" ";
String arrivalTimeVar="0 0 ";
String startTimeVar="0 0 ";
//根据sn获取type
Map<Object,Object> map=new HashMap<>();
map.put("transportationNo",getTransportNo(addCircuitVo.getTransportation(),addCircuitVo.getTransportationType()));
// map.put("startTime",time);
map.put("expTime",addCircuitVo.getStartAddressVo().getExpTime());
map.put("compTime",addCircuitVo.getEndAddressVo().getCompTime());
map.put("cargoNo",addCircuitVo.getCargoNo());
map.put("cargoName",addCircuitVo.getCargoName());
map.put("plateNo",addCircuitVo.getPlateNo());
map.put("deliveryAddress",addCircuitVo.getDeliveryAddress());
map.put("transportation",addCircuitVo.getTransportation());
map.put("transportationType",addCircuitVo.getTransportationType());
map.put("createTime",time);
map.put("remark",addCircuitVo.getRemark());
map.put("counts",2);
map.put("countryVar",countryVar);
map.put("cityVar",cityVar);
map.put("addressDetailVar",addressDetailVar);
map.put("lngVar",lngVar);
map.put("latVar",latVar);
map.put("postCodeVar",postCodeVar);
map.put("arrivalTimeVar",arrivalTimeVar);
map.put("startTimeVar",startTimeVar);
map.put("expTimeVar",expTimeVar);
map.put("compTimeVar",compTimeVar);
circuitService.add(map);
Map<Object,Object> msg=new HashMap<>();
msg.put("msg",map.get("msg"));
if (msg.get("msg").equals("线路添加成功")){
fb.setCode(1);
fb.setMessage("添加线路成功");
}else {
fb.setCode(0);
fb.setMessage(msg.get("msg").toString());
}
return gson.toJson(fb);
}
//获取已有线路
@ApiOperation(value = "添加线路信息----mobile",notes = "添加线路信息," +
" cargoNo:货物编号," +
" plateNo:车牌号," +
" cargoName:货物别名," +
" transportation:运输方式,(公路,铁路,海运,空运,快递)" +
" startAddressVo: 启运城市,包含" +
"{country:国家," +
"city:城市," +
"addressDetail:详细地址," +
"lng:经度," +
"lat:纬度," +
"postCode:邮编,"+
"expTime:预计开始时间,(13位时间戳)}" +
" endAddressVo: 目的城市,包含" +
"{country:国家," +
"city:城市," +
"addressDetail:详细地址," +
"lng:经度," +
"lat:纬度," +
"postCode:邮编,"+
"compTime:预计结束时间,(13位时间戳)}" +
" deliveryAddress:交付地点,(站点,仓库,港口)" +
" transportationType:运输类型,(本地运输,国际运输)" +
" remark:备注,")
@ApiImplicitParams({
@ApiImplicitParam(paramType="header", name = "Account_token", value = "token", required = true, dataType = "String"),
})
@RequestMapping(value="/getExsitCircuit",method = RequestMethod.GET)
public Object getExsitCircuit(){
return gson.toJson(fb);
}
//修改线路结束时间 //修改线路结束时间
@ApiOperation(value = "修改线路结束时间",notes = "修改线路结束时间,传值说明:" + @ApiOperation(value = "修改线路结束时间",notes = "修改线路结束时间,传值说明:" +
" transportationNo:运输编号," + " transportationNo:运输编号," +
...@@ -478,7 +730,7 @@ public class CircuitController { ...@@ -478,7 +730,7 @@ public class CircuitController {
//根据车牌号查线路 //根据车牌号查线路
@ApiOperation(value = "根据车牌号查线路",notes = "根据车牌号查线路,返回值说明:" + @ApiOperation(value = "根据车牌号查线路---mobile",notes = "根据车牌号查线路,返回值说明:" +
" transportationNo:运输编号," + " transportationNo:运输编号," +
" cargoNo:货物编号" + " cargoNo:货物编号" +
" startCity:起运城市," + " startCity:起运城市," +
...@@ -502,7 +754,7 @@ public class CircuitController { ...@@ -502,7 +754,7 @@ public class CircuitController {
//评价 //评价
@ApiOperation(value = "评价",notes = "评价线路传值说明:" + @ApiOperation(value = "评价---mobile",notes = "评价线路传值说明:" +
" transportationNo:运输编号," + " transportationNo:运输编号," +
" evaluate:评分," + " evaluate:评分," +
" evaluateRemark:评分备注") " evaluateRemark:评分备注")
...@@ -540,7 +792,7 @@ public class CircuitController { ...@@ -540,7 +792,7 @@ public class CircuitController {
//根据运输状态查询线路信息 //根据运输状态查询线路信息
@ApiOperation(value = "根据运输状态查询线路信息",notes = "根据运输状态查询线路信息,传值说明:{\"circuitState\":2} ,circuitState:线路状态(0未开始,1运输中,2完成),返回值说明:" + @ApiOperation(value = "根据运输状态查询线路信息---mobile",notes = "根据运输状态查询线路信息,传值说明:{\"circuitState\":2} ,circuitState:线路状态(0未开始,1运输中,2完成),返回值说明:" +
" transportationNo:运输编号," + " transportationNo:运输编号," +
" cargoNo:货物编号" + " cargoNo:货物编号" +
" startCity:起运城市," + " startCity:起运城市," +
...@@ -738,7 +990,7 @@ public class CircuitController { ...@@ -738,7 +990,7 @@ public class CircuitController {
transportationNo = transportationNo+"HUN"; transportationNo = transportationNo+"HUN";
} }
transportationNo=transportationNo+new SimpleDateFormat("yyyyMMdd").format(new Date()); transportationNo=transportationNo+new SimpleDateFormat("yyyyMMdd").format(new Date());
if(transportation.equals("汽运")){ if(transportation.equals("公路")){
transportationNo = transportationNo +"G"; transportationNo = transportationNo +"G";
} else if (transportation.equals("铁路")){ } else if (transportation.equals("铁路")){
transportationNo = transportationNo +"T"; transportationNo = transportationNo +"T";
...@@ -777,6 +1029,38 @@ public class CircuitController { ...@@ -777,6 +1029,38 @@ public class CircuitController {
return day + "天" + hour + "小时" + min + "分钟" +sec +"秒"; return day + "天" + hour + "小时" + min + "分钟" +sec +"秒";
} }
//将报警规则存到redis中
public void saveAlarmRule(String topic,String TDLSN,String alarmType){
ResultAlarmVo alarmVo = alarmService.getByTypeAndScene(alarmType,"运输");
for(String alias :list){
List<AlarmRuleVo> alarmRuleVos = new ArrayList<>();
AlarmRuleVo alarmRuleVo = new AlarmRuleVo();
if(alias.equals("T")){
alarmRuleVo.setMinval(String.valueOf(alarmVo.getTemMin()));
alarmRuleVo.setMaxval(String.valueOf(alarmVo.getTemMax()));
alarmRuleVo.setMode("twoway");
alarmRuleVo.setPriority("1");
}else if(alias.equals("h")){
alarmRuleVo.setMinval(String.valueOf(alarmVo.getHumidityMin()));
alarmRuleVo.setMaxval(String.valueOf(alarmVo.getHumidityMax()));
alarmRuleVo.setMode("twoway");
alarmRuleVo.setPriority("1");
}else if(alias.equals("ta")){
alarmRuleVo.setMinval(String.valueOf(alarmVo.getTilt()));
alarmRuleVo.setMode("equal");
alarmRuleVo.setPriority("1");
}else if(alias.equals("a0")){
alarmRuleVo.setMinval(String.valueOf(alarmVo.getShock()));
alarmRuleVo.setMode("equal");
alarmRuleVo.setPriority("1");
}
alarmRuleVos.add(alarmRuleVo);
//向redis中写入报警信息
alarmRedisService.hmSet(topic,"TDL-" +TDLSN+"_" +alias,gson.toJson(alarmRuleVos));
}
}
// 修改线路信息 // 修改线路信息
// @ApiOperation(value = "修改线路信息",notes = "修改线路信息,传值说明:" + // @ApiOperation(value = "修改线路信息",notes = "修改线路信息,传值说明:" +
......
...@@ -41,11 +41,6 @@ public class DataController { ...@@ -41,11 +41,6 @@ public class DataController {
@Autowired @Autowired
private TDLDeviceService tdlDeviceService; private TDLDeviceService tdlDeviceService;
@Autowired
private ProbesService probesService;
@Autowired
private RealRedisService realRedisService;
@Autowired @Autowired
private InfoRedisService infoRedisService; private InfoRedisService infoRedisService;
...@@ -53,9 +48,6 @@ public class DataController { ...@@ -53,9 +48,6 @@ public class DataController {
@Autowired @Autowired
private InfluxDBTemplate influxDBTemplate; private InfluxDBTemplate influxDBTemplate;
@Autowired
private AlarmLogService alarmLogService;
@Autowired @Autowired
private CircuitService circuitService; private CircuitService circuitService;
...@@ -78,40 +70,52 @@ public class DataController { ...@@ -78,40 +70,52 @@ public class DataController {
transportationNo=jsonObject.getString("transportationNo"); transportationNo=jsonObject.getString("transportationNo");
//根据运输编号获取线路信息 //根据运输编号获取线路信息
ResultCircuitVo resultCircuitVo = circuitService.getByTransportationNo(transportationNo); ResultCircuitVo resultCircuitVo = circuitService.getByTransportationNo(transportationNo);
if(resultCircuitVo.getEndTime() !=0 && infoRedisService.hasHashKey("TransportConfig",transportationNo)){ List<LocationDataVo> locationDataVoList =new ArrayList<>();
if(resultCircuitVo.getStartTime() == null || resultCircuitVo.getStartTime() == 0){
return gson.toJson(locationDataVoList);
}
Long startTime = resultCircuitVo.getStartTime() *1000000l;
if(resultCircuitVo.getEndTime() !=null && infoRedisService.hasHashKey("TransportConfig",transportationNo)){
Object ret = infoRedisService.getHash("TransportConfig",transportationNo); Object ret = infoRedisService.getHash("TransportConfig",transportationNo);
return ret; return ret;
}
//获取gateway的信息
ResultGatewayVo gatewayVo = tdlLogService.getByNo(transportationNo);
if(gatewayVo==null){
return gson.toJson(locationDataVoList);
}
String device = gatewayVo.getType() +"_" +gatewayVo.getSN();
String sql ="";
if(resultCircuitVo.getEndTime() != null && resultCircuitVo.getEndTime() != 0){
Long time = resultCircuitVo.getEndTime()*1000000l;
sql = "SELECT \"lng\",\"lat\" FROM \"tdl_policy\".\""+device+"\"where time >= "+startTime +" and time<= "+time+" ORDER BY time ";
}else{ }else{
//获取gateway的信息 sql = "SELECT \"lng\",\"lat\" FROM \"tdl_policy\".\""+device+"\"where time >= "+startTime +" ORDER BY time ";
ResultGatewayVo gatewayVo = new ResultGatewayVo(); }
if(resultCircuitVo.getEndTime() == 0){ //获取tdl信息
gatewayVo = circuitService.getByNo(transportationNo);
}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 sql2 ="";
String device = gatewayVo.getType() +"_" +gatewayVo.getSN(); if(resultCircuitVo.getEndTime() != null && resultCircuitVo.getEndTime() != 0){
Long startTime = resultCircuitVo.getStartTime() *1000000l; Long time = resultCircuitVo.getEndTime()*1000000l;
//获取tdl信息 sql2 = "SELECT \"a0\" FROM \"tdl_policy\".\""+device+"\"where time >= "+startTime +" and time<=" +time+ " ORDER BY time";
String sql = "SELECT \"lng\",\"lat\" FROM \"tdl_policy\".\""+device+"\"where time >= "+startTime +" ORDER BY time "; }else{
QueryResult queryResult = influxDBTemplate.query(new Query(sql,database)); sql2 = "SELECT \"a0\" FROM \"tdl_policy\".\""+device+"\"where time >= "+startTime +" ORDER BY time";
//解析经纬度数据 }
List<LocationDataVo> locationDataVos = new ArrayList<>();
if(queryResult.getResults().get(0).getSeries() != null){ QueryResult queryResult2 = influxDBTemplate.query(new Query(sql2,database));
locationDataVos=getLocation(queryResult); List<String> timeList = new ArrayList<>();
} if(queryResult2.getResults().get(0).getSeries() != null){
//获取震动的数据 //获取震动的时间戳
String sql2 = "SELECT \"b\" FROM \"tdl_policy\".\""+device+"\"where time >= "+startTime +" ORDER BY time"; timeList = getTime(queryResult2);
QueryResult queryResult2 = influxDBTemplate.query(new Query(sql2,database)); }
List<String> timeList = new ArrayList<>(); if(timeList.size()>0){
if(queryResult2.getResults().get(0).getSeries() != null){
//获取震动的时间戳
timeList = getTime(queryResult2);
}
//获取震动数据的坐标 //获取震动数据的坐标
String sql3 =""; String sql3 ="";
for(String time : timeList){ for(String time : timeList){
...@@ -123,7 +127,6 @@ public class DataController { ...@@ -123,7 +127,6 @@ public class DataController {
if(queryResult3.getResults() !=null){ if(queryResult3.getResults() !=null){
time = getShockLocation(queryResult3); time = getShockLocation(queryResult3);
} }
List<LocationDataVo> locationDataVoList =new ArrayList<>();
for(LocationDataVo locationDataVo :locationDataVos){ for(LocationDataVo locationDataVo :locationDataVos){
if(time.contains(locationDataVo.getTime())){ if(time.contains(locationDataVo.getTime())){
locationDataVo.setError(1); locationDataVo.setError(1);
...@@ -134,10 +137,20 @@ public class DataController { ...@@ -134,10 +137,20 @@ public class DataController {
} }
} }
//如果是已经完结保存到redis中 //如果是已经完结保存到redis中
if(resultCircuitVo.getEndTime() != 0){ if(resultCircuitVo.getEndTime() != null && resultCircuitVo.getEndTime() != 0){
infoRedisService.setHash("TransportConfig",transportationNo,locationDataVoList.toString(),60*30); Map<Object,Object> map=new HashMap<>();
map.put(transportationNo,locationDataVoList.toString());
infoRedisService.setHash("TransportConfig",map,System.currentTimeMillis());
} }
return gson.toJson(locationDataVoList); return gson.toJson(locationDataVoList);
}else{
//如果是已经完结保存到redis中
if (resultCircuitVo.getEndTime() != null && resultCircuitVo.getEndTime() != 0) {
Map<Object, Object> map = new HashMap<>();
map.put(transportationNo, locationDataVos.toString());
infoRedisService.setHash("TransportConfig", map,System.currentTimeMillis());
}
return gson.toJson(locationDataVos);
} }
} }
...@@ -154,16 +167,10 @@ public class DataController { ...@@ -154,16 +167,10 @@ public class DataController {
JSONObject jsonObject= JSON.parseObject(transportationNo); JSONObject jsonObject= JSON.parseObject(transportationNo);
transportationNo=jsonObject.getString("transportationNo"); transportationNo=jsonObject.getString("transportationNo");
ResultCircuitVo resultCircuitVo = circuitService.getByTransportationNo(transportationNo); ResultCircuitVo resultCircuitVo = circuitService.getByTransportationNo(transportationNo);
ResultGatewayVo gatewayVo = new ResultGatewayVo(); ResultGatewayVo gatewayVo = tdlLogService.getByNo(transportationNo);
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() ;
Long startTime = resultCircuitVo.getStartTime() *1000000l; Long startTime = resultCircuitVo.getStartTime() *1000000l;
if(devList.size() == 0){ if(devList.size() == 0){
fb.setCode(0); fb.setCode(0);
...@@ -171,7 +178,7 @@ public class DataController { ...@@ -171,7 +178,7 @@ public class DataController {
return gson.toJson(fb); return gson.toJson(fb);
} }
List<String> list = new ArrayList<String>(){{ List<String> list = new ArrayList<String>(){{
add("\"t\""); add("\"T\"");
add("\"h\""); add("\"h\"");
add("\"p\""); add("\"p\"");
add("\"a0\""); add("\"a0\"");
...@@ -179,7 +186,7 @@ public class DataController { ...@@ -179,7 +186,7 @@ public class DataController {
//add("\"t\""); //add("\"t\"");
}}; }};
Map<String,String> map = new HashMap<>(); Map<String,String> map = new HashMap<>();
map.put("\"t\"","temp"); map.put("\"T\"","temp");
map.put("\"h\"","humidity"); map.put("\"h\"","humidity");
map.put("\"p\"","pressure"); map.put("\"p\"","pressure");
map.put("\"a0\"","shockEnergy"); map.put("\"a0\"","shockEnergy");
...@@ -191,8 +198,10 @@ public class DataController { ...@@ -191,8 +198,10 @@ public class DataController {
List<HistoryDataVo> historyDataVoList = new ArrayList<>(); List<HistoryDataVo> historyDataVoList = new ArrayList<>();
for( int i =0;i<devList.size();i++){ for( int i =0;i<devList.size();i++){
HistoryDataVo historyDataVo = new HistoryDataVo(); HistoryDataVo historyDataVo = new HistoryDataVo();
historyDataVo.setTDLSN(devList.get(i)); String TDLSN=devList.get(i).replace("TDL-","").trim();
String sql = "SELECT "+list.get(i)+" FROM \"tdl_policy\".\""+devcie+"\" where \"tdl\"=\'"+devList.get(i)+"\' and time >="+startTime + " ORDER BY time "; historyDataVo.setTDLSN(devList.get(i).replace("TDL-","").trim());
//String sql = "SELECT \"T\" FROM \"tdl_policy\".\"WTD93LG_17110198\" where \"tdl\"=\'TDL-1707010057708\' and time >=1522306792692000000 ORDER BY time";
String sql = "SELECT "+list.get(j)+" FROM \"tdl_policy\".\""+device+"\" 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<HistoryData> historyData = new ArrayList<>(); List<HistoryData> historyData = new ArrayList<>();
if(queryResult.getResults().get(0).getSeries() != null){ if(queryResult.getResults().get(0).getSeries() != null){
......
...@@ -109,7 +109,7 @@ public class EquipmentBindingController { ...@@ -109,7 +109,7 @@ public class EquipmentBindingController {
map.put("resp",null); map.put("resp",null);
map.put("state",1); map.put("state",1);
map.put("untie",false); map.put("untie",false);
map.put("TDLSN",bindingVo.getTDLSN()); map.put("TDLSN","tdl-"+bindingVo.getTDLSN());
map.put("createTime",System.currentTimeMillis()); map.put("createTime",System.currentTimeMillis());
configService.addConfig(map); configService.addConfig(map);
Map<Object,Object> msg=new HashMap<>(); Map<Object,Object> msg=new HashMap<>();
...@@ -143,7 +143,7 @@ public class EquipmentBindingController { ...@@ -143,7 +143,7 @@ public class EquipmentBindingController {
} }
alarmRuleVos.add(alarmRuleVo); alarmRuleVos.add(alarmRuleVo);
//向redis中写入报警信息 //向redis中写入报警信息
alarmRedisService.hmSet("TDL/"+bindingVo.getType()+"/" +bindingVo.getSN()+"/Data","tdl-" +bindingVo.getTDLSN()+"_" +alias,gson.toJson(alarmRuleVos)); alarmRedisService.hmSet("TDL/"+bindingVo.getType()+"/" +bindingVo.getSN()+"/Data","TDL-" +bindingVo.getTDLSN()+"_" +alias,gson.toJson(alarmRuleVos));
} }
}else{ }else{
fb.setCode(0); fb.setCode(0);
......
...@@ -339,11 +339,11 @@ public class GatewayController { ...@@ -339,11 +339,11 @@ public class GatewayController {
if (device.getState() == 0) { if (device.getState() == 0) {
//挂载 //挂载
String sr = HttpRequester.sendPost("http://127.0.0.1:8079/witium/addMount", gson.toJson(new GatewaySNAndTypeVo(device.getSN(), device.getType()))); String sr = HttpRequester.sendPost("http://192.168.1.171:8079/witium/addMount", gson.toJson(new GatewaySNAndTypeVo(device.getSN(), device.getType())));
device.setState(1); device.setState(1);
} else if (device.getState() == 1) { } else if (device.getState() == 1) {
//卸载 //卸载
String sr = HttpRequester.sendPost("http://127.0.0.1:8079/witium/delMount", gson.toJson(new GatewaySNAndTypeVo(device.getSN(), device.getType()))); String sr = HttpRequester.sendPost("http://192.168.1.171:8079/witium/delMount", gson.toJson(new GatewaySNAndTypeVo(device.getSN(), device.getType())));
device.setState(0); device.setState(0);
infoRedisService.delHashKey("DeviceConfig", device.getType() + "_" + device.getSN()); infoRedisService.delHashKey("DeviceConfig", device.getType() + "_" + device.getSN());
infoRedisService.delHashKey("SubTopic", device.getType() + "_" + device.getSN()); infoRedisService.delHashKey("SubTopic", device.getType() + "_" + device.getSN());
......
...@@ -81,8 +81,8 @@ public class LoginController { ...@@ -81,8 +81,8 @@ public class LoginController {
fb.setMessage("添加日志失败"); fb.setMessage("添加日志失败");
} }
} catch (Exception e) { } catch (Exception e) {
// e.printStackTrace(); e.printStackTrace();
// logger.info(e.toString()); logger.info(e.toString());
fb.setCode(0); fb.setCode(0);
fb.setMessage("用户名或密码错误"); fb.setMessage("用户名或密码错误");
} }
......
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
order by alarmTime desc; order by alarmTime desc;
</select> </select>
<insert id="addAlarmLog" parameterType="com.example.tdl.domain.vo.AddAlarmLogVo"> <insert id="addAlarmLog" parameterType="com.example.tdl.entity.AlarmLog">
insert into alarm_log insert into alarm_log
values( values(
null, null,
...@@ -27,7 +27,8 @@ ...@@ -27,7 +27,8 @@
#{TDLSN,jdbcType=VARCHAR}, #{TDLSN,jdbcType=VARCHAR},
#{description,jdbcType=VARCHAR}, #{description,jdbcType=VARCHAR},
#{data,jdbcType=FLOAT}, #{data,jdbcType=FLOAT},
#{alarmTime,jdbcType=INTEGER} #{alarmTime,jdbcType=INTEGER},
#{classify,jdbcType=VARCHAR}
) )
</insert> </insert>
...@@ -43,22 +44,22 @@ ...@@ -43,22 +44,22 @@
</select> </select>
<select id = "getByCount" parameterType="String" resultType="com.example.tdl.domain.vo.HistogramData" > <select id = "getByCount" parameterType="String" resultType="com.example.tdl.domain.vo.HistogramData" >
SELECT classify,count(description) FROM alarm_log WHERE classify = "温度" SELECT classify,count(description) FROM alarm_log WHERE classify = "1"
AND DATE_SUB(CURDATE(), INTERVAL #{time,jdbcType=VARCHAR} DAY) &lt;= date(FROM_UNIXTIME(alarmTime/1000,'%Y-%m-%d %H:%i:%s')) AND DATE_SUB(CURDATE(), INTERVAL #{time,jdbcType=VARCHAR} DAY) &lt;= date(FROM_UNIXTIME(alarmTime/1000,'%Y-%m-%d %H:%i:%s'))
UNION ALL UNION ALL
SELECT classify,count(description) FROM alarm_log WHERE classify = "震动" SELECT classify,count(description) FROM alarm_log WHERE classify = "3"
AND DATE_SUB(CURDATE(), INTERVAL #{time,jdbcType=VARCHAR} DAY) &lt;= date(FROM_UNIXTIME(alarmTime/1000,'%Y-%m-%d %H:%i:%s')) AND DATE_SUB(CURDATE(), INTERVAL #{time,jdbcType=VARCHAR} DAY) &lt;= date(FROM_UNIXTIME(alarmTime/1000,'%Y-%m-%d %H:%i:%s'))
UNION ALL UNION ALL
SELECT classify,count(description) FROM alarm_log WHERE classify = "湿度" SELECT classify,count(description) FROM alarm_log WHERE classify = "2"
AND DATE_SUB(CURDATE(), INTERVAL #{time,jdbcType=VARCHAR} DAY) &lt;= date(FROM_UNIXTIME(alarmTime/1000,'%Y-%m-%d %H:%i:%s')) AND DATE_SUB(CURDATE(), INTERVAL #{time,jdbcType=VARCHAR} DAY) &lt;= date(FROM_UNIXTIME(alarmTime/1000,'%Y-%m-%d %H:%i:%s'))
UNION ALL UNION ALL
SELECT classify,count(description) FROM alarm_log WHERE classify = "光爆" SELECT classify,count(description) FROM alarm_log WHERE classify = "5"
AND DATE_SUB(CURDATE(), INTERVAL #{time,jdbcType=VARCHAR} DAY) &lt;= date(FROM_UNIXTIME(alarmTime/1000,'%Y-%m-%d %H:%i:%s')) AND DATE_SUB(CURDATE(), INTERVAL #{time,jdbcType=VARCHAR} DAY) &lt;= date(FROM_UNIXTIME(alarmTime/1000,'%Y-%m-%d %H:%i:%s'))
UNION ALL UNION ALL
SELECT classify,count(description) FROM alarm_log WHERE classify = "延迟" SELECT classify,count(description) FROM alarm_log WHERE classify = "4"
AND DATE_SUB(CURDATE(), INTERVAL #{time,jdbcType=VARCHAR} DAY) &lt;= date(FROM_UNIXTIME(alarmTime/1000,'%Y-%m-%d %H:%i:%s')) AND DATE_SUB(CURDATE(), INTERVAL #{time,jdbcType=VARCHAR} DAY) &lt;= date(FROM_UNIXTIME(alarmTime/1000,'%Y-%m-%d %H:%i:%s'))
UNION ALL UNION ALL
SELECT classify,count(description) FROM alarm_log WHERE classify = "离线" SELECT classify,count(description) FROM alarm_log WHERE classify = "6"
AND DATE_SUB(CURDATE(), INTERVAL #{time,jdbcType=VARCHAR} DAY) &lt;= date(FROM_UNIXTIME(alarmTime/1000,'%Y-%m-%d %H:%i:%s')) AND DATE_SUB(CURDATE(), INTERVAL #{time,jdbcType=VARCHAR} DAY) &lt;= date(FROM_UNIXTIME(alarmTime/1000,'%Y-%m-%d %H:%i:%s'))
UNION ALL UNION ALL
SELECT classify,count(description) FROM alarm_log WHERE classify = "倾角" SELECT classify,count(description) FROM alarm_log WHERE classify = "倾角"
......
...@@ -68,6 +68,41 @@ ...@@ -68,6 +68,41 @@
]]> ]]>
</insert> </insert>
<insert id="add" parameterType="java.util.Map" statementType="CALLABLE">
<![CDATA[
{
call pro_addOneCircuit(
#{transportationNo,mode=IN,jdbcType=VARCHAR},
#{startTime,mode=IN,jdbcType=BIGINT},
#{expTime,mode=IN,jdbcType=BIGINT},
#{compTime,mode=IN,jdbcType=BIGINT},
#{cargoNo,mode=IN,jdbcType=VARCHAR},
#{cargoName,mode=IN,jdbcType=VARCHAR},
#{plateNo,mode=IN,jdbcType=VARCHAR},
#{deliveryAddress,mode=IN,jdbcType=VARCHAR},
#{transportation,mode=IN,jdbcType=VARCHAR},
#{transportationType,mode=IN,jdbcType=VARCHAR},
#{createTime,mode=IN,jdbcType=BIGINT},
#{remark,mode=IN,jdbcType=VARCHAR},
#{counts,mode=IN,jdbcType=INTEGER},
#{countryVar,mode=IN,jdbcType=VARCHAR},
#{cityVar,mode=IN,jdbcType=VARCHAR},
#{addressDetailVar,mode=IN,jdbcType=VARCHAR},
#{lngVar,mode=IN,jdbcType=VARCHAR},
#{latVar,mode=IN,jdbcType=VARCHAR},
#{postCodeVar,mode=IN,jdbcType=VARCHAR},
#{arrivalTimeVar,mode=IN,jdbcType=VARCHAR},
#{startTimeVar,mode=IN,jdbcType=VARCHAR},
#{expTimeVar,mode=IN,jdbcType=BIGINT},
#{compTimeVar,mode=IN,jdbcType=VARCHAR},
#{msg,mode=OUT,jdbcType=VARCHAR}
)
}
]]>
</insert>
<!--修改线路信息--> <!--修改线路信息-->
<update id="updateCircuit" parameterType="java.util.Map" statementType="CALLABLE"> <update id="updateCircuit" parameterType="java.util.Map" statementType="CALLABLE">
<![CDATA[ <![CDATA[
...@@ -135,7 +170,10 @@ ...@@ -135,7 +170,10 @@
<!--根据线路编号获取线路信息--> <!--根据线路编号获取线路信息-->
<select id="getByTransportationNo" resultType="com.example.tdl.domain.vo.ResultCircuitVo" parameterType="String"> <select id="getByTransportationNo" resultType="com.example.tdl.domain.vo.ResultCircuitVo" parameterType="String">
SELECT c.transportationNo,cargoNo,(SELECT city from city WHERE id =(SELECT city_id from circuit_transfer WHERE circuit_id=c.id ORDER BY sequence LIMIT 1)) startCity,startTime,(SELECT city from city WHERE id =(SELECT city_id from circuit_transfer WHERE circuit_id=c.id ORDER BY sequence DESC LIMIT 1)) endCity,endTime,circuitState,(SELECT alarmType FROM alarm WHERE id IN (SELECT alarm_id from tdl_gateway_log WHERE transportationNo=c.transportationNo)) alarmType,(select GROUP_CONCAT(classify) from alarm_log al where al.transportationNo = c.transportationNo) alarm,evaluate SELECT c.transportationNo,cargoNo,(SELECT city from city WHERE id =(SELECT city_id from circuit_transfer WHERE circuit_id=c.id ORDER BY sequence LIMIT 1)) startCity,
startTime,(SELECT city from city WHERE id =(SELECT city_id from circuit_transfer WHERE circuit_id=c.id ORDER BY sequence DESC LIMIT 1)) endCity,endTime,circuitState,
(SELECT alarmType FROM alarm WHERE id IN (SELECT alarm_id from tdl_gateway_log WHERE transportationNo=c.transportationNo)) alarmType,(select GROUP_CONCAT(classify)
from alarm_log al where al.transportationNo = c.transportationNo) alarm,ifnull(evaluate,"") evaluate
from circuit c where c.state=1 from circuit c where c.state=1
AND c.transportationNo=#{transportationNo,jdbcType=VARCHAR} AND c.transportationNo=#{transportationNo,jdbcType=VARCHAR}
</select> </select>
......
...@@ -27,7 +27,7 @@ ...@@ -27,7 +27,7 @@
<!--获取绑定消息--> <!--获取绑定消息-->
<select id="getConfig" parameterType="String" resultType="com.example.tdl.domain.vo.ConfigVo"> <select id="getConfig" parameterType="String" resultType="com.example.tdl.domain.vo.ConfigVo">
select gSN,gType,message,flag,resp,state,untie from config where gSN= #{gSN,jdbcType=VARCHAR} and gType=#{gType,jdbcType=VARCHAR} and state = 1; select gSN,gType,message,flag,resp,state,untie from config where gSN= #{gSN,jdbcType=VARCHAR} and gType=#{gType,jdbcType=VARCHAR} and state = 1
</select> </select>
<!--绑定回复--> <!--绑定回复-->
......
...@@ -76,6 +76,12 @@ ...@@ -76,6 +76,12 @@
AND type=#{type,jdbcType=VARCHAR} AND type=#{type,jdbcType=VARCHAR}
</update> </update>
<select id="getTransportationNo" parameterType="String" resultType="String">
select transportationNo from circuit where id = (select circuit_id from tdldevice
where gateway_id =(SELECT id from gateway where SN=#{SN,jdbcType=VARCHAR}
AND type=#{type,jdbcType=VARCHAR}))
</select>
<!-- <insert id="addGateway" parameterType="com.example.tdl.domain.vo.AddGatewayVo"> <!-- <insert id="addGateway" parameterType="com.example.tdl.domain.vo.AddGatewayVo">
INSERT into gateway VALUES ( INSERT into gateway VALUES (
......
...@@ -57,6 +57,16 @@ ...@@ -57,6 +57,16 @@
</select> </select>
<select id="getByGatewaySN" parameterType="String" resultType="String"> <select id="getByGatewaySN" parameterType="String" resultType="String">
select TDLSN from tdldevice t,gateway g where t.gateway_id = g.id and g.SN =#{SN,jdbcType=VARCHAR} and g.type=#{type,jdbcType=VARCHAR} select CONCAT("TDL-",TDLSN) TDLSN from tdldevice t,gateway g
where t.gateway_id = g.id
and g.SN =#{SN,jdbcType=VARCHAR}
and g.type=#{type,jdbcType=VARCHAR}
</select>
<select id="getTdlSN" parameterType="String" resultType="String">
select TDLSN from tdldevice t,gateway g
where t.gateway_id = g.id
and g.SN =#{SN,jdbcType=VARCHAR}
and g.type=#{type,jdbcType=VARCHAR}
</select> </select>
</mapper> </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