Commit ff916343 authored by zhuangzhuang's avatar zhuangzhuang

3.20--修改首页获取线路信息接口,优化实时数据接口

parent 28cd574a
...@@ -203,9 +203,9 @@ public class RedisConfig extends CachingConfigurerSupport{ ...@@ -203,9 +203,9 @@ public class RedisConfig extends CachingConfigurerSupport{
* @return * @return
*/ */
@Bean @Bean
public RedisTemplate<String, String> redisTemplate() { public RedisTemplate<String, String> infoRedisTemplate() {
StringRedisTemplate template = new StringRedisTemplate(redisConnectionFactory(0)); StringRedisTemplate template = new StringRedisTemplate(redisConnectionFactory(0));
JsonRedisSerializer(template, true); JsonRedisSerializer(template, false);
return template; return template;
} }
......
package com.example.tdl.domain.vo;
public class CircuitVo {
private String transportationNo;
private String routeName;
private String startLongitude;
private String startLatitude;
private String startCity;
private String startTime;
private String endLongitude;
private String endLatitude;
private String endCity;
private String endTime;
private String transport;
private String boxNo;
private String containerNo;
private String deliveryAddress;
private String transportationType;
private int circuitState;
private String remark;
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 getStartLongitude() {
return startLongitude;
}
public void setStartLongitude(String startLongitude) {
this.startLongitude = startLongitude;
}
public String getStartLatitude() {
return startLatitude;
}
public void setStartLatitude(String startLatitude) {
this.startLatitude = startLatitude;
}
public String getStartCity() {
return startCity;
}
public void setStartCity(String startCity) {
this.startCity = startCity;
}
public String getStartTime() {
return startTime;
}
public void setStartTime(String startTime) {
this.startTime = startTime;
}
public String getEndLongitude() {
return endLongitude;
}
public void setEndLongitude(String endLongitude) {
this.endLongitude = endLongitude;
}
public String getEndLatitude() {
return endLatitude;
}
public void setEndLatitude(String endLatitude) {
this.endLatitude = endLatitude;
}
public String getEndCity() {
return endCity;
}
public void setEndCity(String endCity) {
this.endCity = endCity;
}
public String getEndTime() {
return endTime;
}
public void setEndTime(String endTime) {
this.endTime = endTime;
}
public String getTransport() {
return transport;
}
public void setTransport(String transport) {
this.transport = transport;
}
public String getBoxNo() {
return boxNo;
}
public void setBoxNo(String boxNo) {
this.boxNo = boxNo;
}
public String getContainerNo() {
return containerNo;
}
public void setContainerNo(String containerNo) {
this.containerNo = containerNo;
}
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 int getCircuitState() {
return circuitState;
}
public void setCircuitState(int circuitState) {
this.circuitState = circuitState;
}
public String getRemark() {
return remark;
}
public void setRemark(String remark) {
this.remark = remark;
}
}
...@@ -12,7 +12,7 @@ public class HomePageDataVo { ...@@ -12,7 +12,7 @@ public class HomePageDataVo {
private Integer alarmed;//报警线路 private Integer alarmed;//报警线路
private List<ResultRouteVo> routeVoList;//线路列表 private List<CircuitVo> routeVoList;//线路列表
//报警列表 //报警列表
private List<AlarmLogVo> alarmLogVoList; private List<AlarmLogVo> alarmLogVoList;
...@@ -51,11 +51,11 @@ public class HomePageDataVo { ...@@ -51,11 +51,11 @@ public class HomePageDataVo {
this.alarmed = alarmed; this.alarmed = alarmed;
} }
public List<ResultRouteVo> getRouteVoList() { public List<CircuitVo> getRouteVoList() {
return routeVoList; return routeVoList;
} }
public void setRouteVoList(List<ResultRouteVo> routeVoList) { public void setRouteVoList(List<CircuitVo> routeVoList) {
this.routeVoList = routeVoList; this.routeVoList = routeVoList;
} }
......
package com.example.tdl.domain.vo;
public class ResultCircuit {
private String transportationNo;
private String startCity;
private String startTime;
private String endCity;
private String endTime;
private String gatewaySN;
private String battery;
private String TDLSN;
private String BatteryVoltage;
private String lastTime;
private int circuitState;
private String remark;
public String getTransportationNo() {
return transportationNo;
}
public void setTransportationNo(String transportationNo) {
this.transportationNo = transportationNo;
}
public String getStartCity() {
return startCity;
}
public void setStartCity(String startCity) {
this.startCity = startCity;
}
public String getStartTime() {
return startTime;
}
public void setStartTime(String startTime) {
this.startTime = startTime;
}
public String getEndCity() {
return endCity;
}
public void setEndCity(String endCity) {
this.endCity = endCity;
}
public String getEndTime() {
return endTime;
}
public void setEndTime(String endTime) {
this.endTime = endTime;
}
public String getGatewaySN() {
return gatewaySN;
}
public void setGatewaySN(String gatewaySN) {
this.gatewaySN = gatewaySN;
}
public String getBattery() {
return battery;
}
public void setBattery(String battery) {
this.battery = battery;
}
public String getTDLSN() {
return TDLSN;
}
public void setTDLSN(String TDLSN) {
this.TDLSN = TDLSN;
}
public String getBatteryVoltage() {
return BatteryVoltage;
}
public void setBatteryVoltage(String batteryVoltage) {
BatteryVoltage = batteryVoltage;
}
public String getLastTime() {
return lastTime;
}
public void setLastTime(String lastTime) {
this.lastTime = lastTime;
}
public int getCircuitState() {
return circuitState;
}
public void setCircuitState(int circuitState) {
this.circuitState = circuitState;
}
public String getRemark() {
return remark;
}
public void setRemark(String remark) {
this.remark = remark;
}
}
...@@ -18,4 +18,6 @@ public interface AlarmLogMapper { ...@@ -18,4 +18,6 @@ public interface AlarmLogMapper {
int addAlarmLog(AddAlarmLogVo addAlarmLogVo); int addAlarmLog(AddAlarmLogVo addAlarmLogVo);
List<AlarmLogVo> getByTransportationNo(String transportationNo); List<AlarmLogVo> getByTransportationNo(String transportationNo);
Integer getCount();
} }
...@@ -10,6 +10,8 @@ import java.util.Map; ...@@ -10,6 +10,8 @@ import java.util.Map;
public interface CircuitMapper { public interface CircuitMapper {
List<ResultCircuitVo> getAll(); List<ResultCircuitVo> getAll();
List<CircuitVo> getDistinct();
List<ResultCircuitVo> getByTerm(CircuitTermVo circuitTermVo); List<ResultCircuitVo> getByTerm(CircuitTermVo circuitTermVo);
int addCircuit(Map<Object,Object> map); int addCircuit(Map<Object,Object> map);
...@@ -23,4 +25,12 @@ public interface CircuitMapper { ...@@ -23,4 +25,12 @@ public interface CircuitMapper {
ResultCircuitVo getByTransportationNo(String transportation); ResultCircuitVo getByTransportationNo(String transportation);
ResultGatewayVo getByNo(String transportationNo); ResultGatewayVo getByNo(String transportationNo);
Integer getOnRoute();
Integer getComplted();
Integer getCount();
List<CircuitVo> getByTime(String time);
} }
...@@ -30,5 +30,9 @@ public class AlarmLogService { ...@@ -30,5 +30,9 @@ public class AlarmLogService {
return alarmLogMapper.getByTransportationNo(transportationNo); return alarmLogMapper.getByTransportationNo(transportationNo);
} }
public Integer getCount(){
return alarmLogMapper.getCount();
}
} }
...@@ -19,6 +19,10 @@ public class CircuitService { ...@@ -19,6 +19,10 @@ public class CircuitService {
return circuitMapper.getAll(); return circuitMapper.getAll();
} }
public List<CircuitVo> getDistinct(){
return circuitMapper.getDistinct();
}
public List<ResultCircuitVo> getByTerm(CircuitTermVo circuitTermVo){ public List<ResultCircuitVo> getByTerm(CircuitTermVo circuitTermVo){
return circuitMapper.getByTerm(circuitTermVo); return circuitMapper.getByTerm(circuitTermVo);
} }
...@@ -47,4 +51,21 @@ public class CircuitService { ...@@ -47,4 +51,21 @@ public class CircuitService {
return circuitMapper.getByNo(transportationNo); return circuitMapper.getByNo(transportationNo);
} }
public Integer getOnRoute(){
return circuitMapper.getOnRoute();
}
public Integer getComplted(){
return circuitMapper.getComplted();
}
public Integer getCount(){
return circuitMapper.getCount();
}
public List<CircuitVo> getByTime(String time){
return circuitMapper.getByTime(time);
}
} }
...@@ -5,6 +5,7 @@ import org.slf4j.LoggerFactory; ...@@ -5,6 +5,7 @@ import org.slf4j.LoggerFactory;
import org.springframework.data.redis.core.HashOperations; import org.springframework.data.redis.core.HashOperations;
import org.springframework.data.redis.core.RedisTemplate; import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ValueOperations; import org.springframework.data.redis.core.ValueOperations;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
import java.io.Serializable; import java.io.Serializable;
...@@ -12,6 +13,7 @@ import java.util.Map; ...@@ -12,6 +13,7 @@ import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
@Service
public class RedisService { public class RedisService {
final static Logger logger = LoggerFactory.getLogger(RedisService.class); final static Logger logger = LoggerFactory.getLogger(RedisService.class);
...@@ -76,11 +78,13 @@ public class RedisService { ...@@ -76,11 +78,13 @@ public class RedisService {
} }
public Object getHashKeys(String key) { public Object getHashKeys(String key) {
Object result = null; String ret="{error}";
Object result = ret;
try { try {
HashOperations<Serializable, Object, Object> hash = redisTemplate.opsForHash(); HashOperations<String, Object, Object> hash= redisTemplate.opsForHash();
//HashOperations<Serializable, Object, Object> hash = redisTemplate.opsForHash();
result = hash.keys(key); result = hash.keys(key);
} catch (Exception e) { }catch (Exception e){
e.printStackTrace(); e.printStackTrace();
logger.error("redis获取hash 所有key发生错误", this); logger.error("redis获取hash 所有key发生错误", this);
} }
......
package com.example.tdl.web; 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.AlarmLogVo; import com.example.tdl.domain.vo.*;
import com.example.tdl.domain.vo.HomePageDataVo;
import com.example.tdl.domain.vo.ResultRouteVo;
import com.example.tdl.domain.vo.TermVo;
import com.example.tdl.service.AlarmLogService; import com.example.tdl.service.AlarmLogService;
import com.example.tdl.service.CircuitService;
import com.example.tdl.service.RouteService; import com.example.tdl.service.RouteService;
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 io.swagger.models.auth.In;
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;
...@@ -28,7 +27,7 @@ public class HomePageController { ...@@ -28,7 +27,7 @@ public class HomePageController {
CommFeedback fb = new CommFeedback(); CommFeedback fb = new CommFeedback();
@Autowired @Autowired
private RouteService routeService; private CircuitService circuitService;
@Autowired @Autowired
private AlarmLogService alarmLogServcie; private AlarmLogService alarmLogServcie;
...@@ -40,23 +39,22 @@ public class HomePageController { ...@@ -40,23 +39,22 @@ public class HomePageController {
"complted:已完成数量" + "complted:已完成数量" +
"alarmed: 报警数量" + "alarmed: 报警数量" +
"routeVoList: " + "routeVoList: " +
"routeNumber:路由编号(R+TyyyyMMdd+运输方式+四位随机数)"+ "transportationNo:线路编号(R+TyyyyMMdd+运输方式+四位随机数)"+
"routeName:路由名称(出发地-启运地)"+ "routeName:路由名称(出发地-启运地)"+
"abbreviation:名称缩写(出发地-启运地-运输方式)"+
"startLongitude:启运经度"+ "startLongitude:启运经度"+
"startLatitude:启运纬度"+ "startLatitude:启运纬度"+
"startCounrty:启运国"+
"startProvince:启运省"+
"startCity:启运市"+ "startCity:启运市"+
"startAddress:启运地址"+ "startTime:开始时间"+
"endLongitude:目的经度"+ "endLongitude:目的经度"+
"endLatitude:目的纬度"+ "endLatitude:目的纬度"+
"endCounrty:目的国"+
"endProvince:目的省"+
"endCity:目的市"+ "endCity:目的市"+
"endAddress:目的地址"+ "endTime:结束时间"+
"transport:运输方式(T铁路,G汽运,H海运,K空运,D快递)"+ "transport:运输方式(T铁路,G汽运,H海运,K空运,D快递)"+
"transportRemark:运输方式备注"+ "boxNo:箱单号" +
"containerNo:集装箱号/车牌号" +
"deliveryAddress:交付地点" +
"transportationType:运输类型" +
"circuitState:线路状态"+
"remark:备注" + "remark:备注" +
"alarmLogVoList :"+ "alarmLogVoList :"+
"routeName:线路名称"+ "routeName:线路名称"+
...@@ -69,38 +67,50 @@ public class HomePageController { ...@@ -69,38 +67,50 @@ public class HomePageController {
}) })
public Object getAll(){ public Object getAll(){
HomePageDataVo dataVo = new HomePageDataVo(); HomePageDataVo dataVo = new HomePageDataVo();
//获取所有的路线 //获取所有的线路信息
// List<ResultRouteVo> routeVos = routeService.getAll();//所有的路线 List<CircuitVo> resultCircuitVos = circuitService.getDistinct();
//List<ResultRouteVo> routeVoList = routeService.getAllRoute();//当天的数量
//获取所有的报警 //获取所有的报警
List<AlarmLogVo> alarmLogVos = alarmLogServcie.getAll(); List<AlarmLogVo> alarmLogVos = alarmLogServcie.getAll();
// 获取所有的路线数量 // 获取所有的路线数量
// dataVo.setRouteVoList(routeVos);//路线列表 dataVo.setRouteVoList(resultCircuitVos);//路线列表
dataVo.setAlarmLogVoList(alarmLogVos);//报警列表 dataVo.setAlarmLogVoList(alarmLogVos);//报警列表
// dataVo.setSum(routeVos.size());//总数量 Integer sum = circuitService.getCount();
dataVo.setOnRoute(0);//在途数量 dataVo.setSum(sum);//总数量
dataVo.setComplted(0);//已完成数量 Integer onRoute = circuitService.getOnRoute();
dataVo.setAlarmed(0);//报警数量 dataVo.setOnRoute(onRoute);//在途数量
//获取已经完成的数量
Integer finished = circuitService.getComplted();
dataVo.setComplted(finished);//已完成数量
Integer alarmed = alarmLogServcie.getCount();
dataVo.setAlarmed(alarmed);//报警数量
return gson.toJson(dataVo); return gson.toJson(dataVo);
} }
//根据条件获取路线数据(所有的) //根据条件获取路线数据(所有的)
@ApiOperation(value = "根据条件获取运输数据",notes = "传值:" +
"time:时间(1,3,7,30...)" +
"evaluation:评价" )
@PostMapping("/getByTerm") @PostMapping("/getByTerm")
@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"),
}) })
public Object getByTerm(@RequestBody TermVo termVo){ public Object getByTerm(@RequestBody TermVo termVo){
HomePageDataVo dataVo = new HomePageDataVo(); HomePageDataVo dataVo = new HomePageDataVo();
List<ResultRouteVo> routeVos = routeService.getAll();//所有的路线 List<CircuitVo> resultCircuitVoList = circuitService.getByTime(termVo.getTime());//所有的路线
// List<ResultRouteVo> routeVoList = routeService.getAllRoute(termVo.getTime());//根据条件获取数据
List<AlarmLogVo> alarmLogVos = alarmLogServcie.getAlarmLog(termVo.getTime()); List<AlarmLogVo> alarmLogVos = alarmLogServcie.getAlarmLog(termVo.getTime());
dataVo.setRouteVoList(routeVos);//路线列表 dataVo.setRouteVoList(resultCircuitVoList);//路线列表
dataVo.setAlarmLogVoList(alarmLogVos);//报警列表 dataVo.setAlarmLogVoList(alarmLogVos);//报警列表
dataVo.setSum(routeVos.size());//总数量 Integer sum = circuitService.getCount();
dataVo.setOnRoute(0);//在途数量 dataVo.setSum(sum);//总数量
dataVo.setComplted(0);//已完成数量 //获取已经完成的数量
dataVo.setAlarmed(0);//报警数量 Integer onRoute = circuitService.getOnRoute();
dataVo.setOnRoute(onRoute);//在途数量
//获取已经完成的数量
Integer finished = circuitService.getComplted();
dataVo.setComplted(finished);//已完成数量
Integer alarmed = alarmLogServcie.getCount();
dataVo.setAlarmed(alarmed);//报警数量
return gson.toJson(dataVo); return gson.toJson(dataVo);
} }
......
spring.datasource.url=jdbc:mysql://HostTest-mysql:3306/cy?useUnicode=true&characterEncoding=utf-8&useSSL=false spring.datasource.url=jdbc:mysql://housetest-mysql:3306/tdlCloud?useUnicode=true&characterEncoding=utf-8&useSSL=false
spring.datasource.username=root
spring.datasource.password=37774020
# Redisַ # Redisַ
spring.redis.host=HostTest-redis tdl.redis.host=housetest-redis
spring.redis.port=6379
tdl.influxdb.host=http://HostTest-influxdb:8086 # InfluxDB
spring.influxdb.url=http://housetest-influxdb:8086
# Logging
logging.config=classpath:logback.xml
...@@ -25,4 +25,9 @@ ...@@ -25,4 +25,9 @@
#{alarmTime,jdbcType=INTEGER} #{alarmTime,jdbcType=INTEGER}
) )
</insert> </insert>
<select id="getCount" resultType="java.lang.Integer">
select count(DISTINCT transportationNo) from alarm_log
</select>
</mapper> </mapper>
\ No newline at end of file
...@@ -8,6 +8,19 @@ ...@@ -8,6 +8,19 @@
from circuit c,route r WHERE c.route_id=r.id AND r.state=1 AND c.state=1 order BY c.id DESC from circuit c,route r WHERE c.route_id=r.id AND r.state=1 AND c.state=1 order BY c.id DESC
</select> </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,
(select city from city_config where id=r.end_id) endCity,endTime,transport,boxNo,containerNo,deliveryAddress,
transportationType,circuitState,c.remark ,SUBSTRING_INDEX(routeName,'_',2) routes
from circuit c,route r
WHERE c.route_id=r.id
AND r.state=1
AND c.state=1
GROUP BY routes
order BY c.id
</select>
<select id="getByTerm" resultType="com.example.tdl.domain.vo.ResultCircuitVo" parameterType="com.example.tdl.domain.vo.CircuitTermVo"> <select id="getByTerm" resultType="com.example.tdl.domain.vo.ResultCircuitVo" parameterType="com.example.tdl.domain.vo.CircuitTermVo">
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,
...@@ -137,4 +150,29 @@ ...@@ -137,4 +150,29 @@
SELECT SN,`name`,type,state,bConfig,useScene,from_unixtime((createTime/1000),'%Y-%m-%d %T') createTime,from_unixtime((updateTime/1000),'%Y-%m-%d %T') updateTime SELECT SN,`name`,type,state,bConfig,useScene,from_unixtime((createTime/1000),'%Y-%m-%d %T') createTime,from_unixtime((updateTime/1000),'%Y-%m-%d %T') updateTime
from gateway WHERE id=(SELECT gateway_id from tdldevice where circuit_id =(SELECT id from circuit WHERE transportationNo=#{transportationNo,jdbcType=VARCHAR})) from gateway WHERE id=(SELECT gateway_id from tdldevice where circuit_id =(SELECT id from circuit WHERE transportationNo=#{transportationNo,jdbcType=VARCHAR}))
</select> </select>
<select id="getOnRoute" resultType="java.lang.Integer">
select count( startTime) from circuit where circuitState=1
</select>
<select id="getComplted" resultType="java.lang.Integer">
select count(id) from circuit where circuitState=2
</select>
<select id="getCount" resultType="java.lang.Integer">
select count(id) from circuit
</select>
<select id="getByTime" 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,
(select city from city_config where id=r.end_id) endCity,endTime,transport,boxNo,containerNo,deliveryAddress,
transportationType,circuitState,c.remark ,SUBSTRING_INDEX(routeName,'_',2) routes
from circuit c,route r
WHERE c.route_id=r.id
AND r.state=1
AND c.state=1
AND DATE_SUB(CURDATE(), INTERVAL #{time,jdbcType=VARCHAR} DAY) &lt;= date(FROM_UNIXTIME(createTime/1000,'%Y-%m-%d %H:%i:%s'))
GROUP BY routes
order BY c.id
</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