Commit 2190f566 authored by chenying's avatar chenying

2018.12.19

(1)添加ABB首页数据接口
parent 8c237834
package com.example.tdl.domain.vo;
public class CircuitABBVo {
private String transportationNo;
private String gatewaySN;
private String TDLSN;
private String cargoNo;
private String cargoName;
private Integer circuitState;
private Boolean isAlarm;
private Long bindTime;
private String lng;
private String lat;
private String time;
public Long getBindTime() {
return bindTime;
}
public void setBindTime(Long bindTime) {
this.bindTime = bindTime;
}
public Integer getCircuitState() {
return circuitState;
}
public void setCircuitState(Integer circuitState) {
this.circuitState = circuitState;
}
public String getTransportationNo() {
return transportationNo;
}
public void setTransportationNo(String transportationNo) {
this.transportationNo = transportationNo;
}
public String getGatewaySN() {
return gatewaySN;
}
public void setGatewaySN(String gatewaySN) {
this.gatewaySN = gatewaySN;
}
public String getTDLSN() {
return TDLSN;
}
public void setTDLSN(String TDLSN) {
this.TDLSN = TDLSN;
}
public String getCargoNo() {
return cargoNo;
}
public void setCargoNo(String cargoNo) {
this.cargoNo = cargoNo;
}
public String getCargoName() {
return cargoName;
}
public void setCargoName(String cargoName) {
this.cargoName = cargoName;
}
public String getLng() {
return lng;
}
public void setLng(String lng) {
this.lng = lng;
}
public String getLat() {
return lat;
}
public void setLat(String lat) {
this.lat = lat;
}
public Boolean getAlarm() {
return isAlarm;
}
public void setAlarm(Boolean alarm) {
isAlarm = alarm;
}
public String getTime() {
return time;
}
public void setTime(String time) {
this.time = time;
}
}
......@@ -5,6 +5,8 @@ import java.util.List;
public class CircuitMessageForABBVo {
private String transportationNo;//运输编号
private Integer circuitState;
private String routeName;//线路
private String cargoName;//货物名称
......@@ -55,8 +57,9 @@ public class CircuitMessageForABBVo {
public CircuitMessageForABBVo() {
}
public CircuitMessageForABBVo(String transportationNo,String routeName,String cargoName,String transportation,String alarmType) {
public CircuitMessageForABBVo(String transportationNo,Integer circuitState,String routeName,String cargoName,String transportation,String alarmType) {
this.transportationNo = transportationNo;
this.circuitState = circuitState;
this.routeName = routeName;
this.cargoName = cargoName;
this.transportation = transportation;
......@@ -72,6 +75,14 @@ public class CircuitMessageForABBVo {
this.alarmLogList = alarmLogList;
}
public Integer getCircuitState() {
return circuitState;
}
public void setCircuitState(Integer circuitState) {
this.circuitState = circuitState;
}
public String getRouteName() {
return routeName;
}
......
......@@ -2,7 +2,6 @@ package com.example.tdl.domain.vo;
public class HistogramData {
private String classify;
private Integer count;
......
package com.example.tdl.domain.vo;
import java.util.List;
public class HomePageDataABBVo {
private Integer sum;//总线路
private Integer onRoute;//在途数量
private Integer alarmed;//报警数量
private Integer bump;//颠簸异常
private List<AlarmLogVo> alarmLogVos;
private List<CircuitABBVo> circuitABBVos;
private List<ResultWarehouseVo> warehouseVoList;
private List<HistogramData> histogramDataList;
public Integer getSum() {
return sum;
}
public void setSum(Integer sum) {
this.sum = sum;
}
public Integer getOnRoute() {
return onRoute;
}
public void setOnRoute(Integer onRoute) {
this.onRoute = onRoute;
}
public Integer getAlarmed() {
return alarmed;
}
public void setAlarmed(Integer alarmed) {
this.alarmed = alarmed;
}
public Integer getBump() {
return bump;
}
public void setBump(Integer bump) {
this.bump = bump;
}
public List<AlarmLogVo> getAlarmLogVos() {
return alarmLogVos;
}
public void setAlarmLogVos(List<AlarmLogVo> alarmLogVos) {
this.alarmLogVos = alarmLogVos;
}
public List<CircuitABBVo> getCircuitABBVos() {
return circuitABBVos;
}
public void setCircuitABBVos(List<CircuitABBVo> circuitABBVos) {
this.circuitABBVos = circuitABBVos;
}
public List<ResultWarehouseVo> getWarehouseVoList() {
return warehouseVoList;
}
public void setWarehouseVoList(List<ResultWarehouseVo> warehouseVoList) {
this.warehouseVoList = warehouseVoList;
}
public List<HistogramData> getHistogramDataList() {
return histogramDataList;
}
public void setHistogramDataList(List<HistogramData> histogramDataList) {
this.histogramDataList = histogramDataList;
}
}
......@@ -27,6 +27,8 @@ public interface AlarmLogMapper {
List<HistogramData> getByCount(@Param("time")String time,@Param("companyNo") String companyNo);
List<HistogramData> getByCountForABB(@Param("time")String time,@Param("companyNo") String companyNo);
Integer getByTime(@Param("transportationNo") String transportationNo,@Param("startTime") Long startTime, @Param("endTime") Long endTime);
List<ResultAlarmLogVo> getAlarm(AlarmTermVo alarmTermVo);
......
......@@ -31,4 +31,10 @@ public interface CircuitABBMapper {
List<ResultCircuitForABBVo> getByCompanyNoAndCircuitState(String companyNo);
Integer getCount(@Param("time") String time,@Param("endTime") Long endTime,@Param("companyNo") String companyNo);
Integer getOnRoute(@Param("companyNo") String companyNo);
List<CircuitABBVo> getForHomePage(@Param("companyNo") String companyNo);
}
......@@ -46,6 +46,9 @@ public class AlarmLogService {
return alarmLogMapper.getByCount(time,companyNo);
}
public List<HistogramData> getByCountForABB(String time,String companyNo){
return alarmLogMapper.getByCountForABB(time,companyNo);
}
public Integer getByTime(String transportationNo,Long startTime,Long endTime){
return alarmLogMapper.getByTime(transportationNo,startTime,endTime);
......
......@@ -59,4 +59,15 @@ public class CircuitABBService {
return circuitABBMapper.getByCompanyNoAndCircuitState(companyNo);
}
public Integer getCount(String time,Long startTime,String companyNo){
return circuitABBMapper.getCount(time,startTime,companyNo);
}
public Integer getOnRoute(String companyNo){
return circuitABBMapper.getOnRoute(companyNo);
}
public List<CircuitABBVo> getForHomePage(String companyNo){
return circuitABBMapper.getForHomePage(companyNo);
}
}
......@@ -265,7 +265,7 @@ public class CircuitABBController {
fb.setMessage(i18n.getMessage(request,"noCircuit"));
return gson.toJson(fb);
}
CircuitMessageForABBVo messageVo = new CircuitMessageForABBVo(circuitVo.getTransportationNo(),circuitVo.getRouteName(),circuitVo.getCargoName(),circuitVo.getTransportation(),circuitVo.getAlarmType());
CircuitMessageForABBVo messageVo = new CircuitMessageForABBVo(circuitVo.getTransportationNo(),circuitVo.getCircuitState(),circuitVo.getRouteName(),circuitVo.getCargoName(),circuitVo.getTransportation(),circuitVo.getAlarmType());
//获取gateway信息
TDLLogVo gatewayVo = tdlLogService.getByTransportationNo(transportationNo);
List<String> TDL= tdlLogService.getTdlSN(transportationNo);
......
......@@ -4,11 +4,8 @@ import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.example.tdl.domain.dto.CommFeedback;
import com.example.tdl.domain.vo.*;
import com.example.tdl.service.AlarmLogService;
import com.example.tdl.service.CircuitService;
import com.example.tdl.service.*;
import com.example.tdl.service.TDLLogService;
import com.example.tdl.service.WarehouseService;
import com.example.tdl.service.redis.InfoRedisService;
import com.example.tdl.service.redis.TokenRedisService;
import com.google.gson.Gson;
......@@ -42,6 +39,9 @@ public class HomePageController {
@Autowired
private CircuitService circuitService;
@Autowired
private CircuitABBService circuitABBService;
@Autowired
private AlarmLogService alarmLogServcie;
......@@ -171,6 +171,114 @@ public class HomePageController {
return gson.toJson(dataVo);
}
//获取当天所有的设备数据
@ApiOperation(value = "获取所有的运输数据",notes = "获取运输设备数据:" +
" sum:总数量;" +
" onRoute:在途数量;" +
" alarmed: 报警数量;" +
" bump:颠簸数量;" +
" alarmLogABBVos : {" +
" transportationNo:线路编号;" +
" description:报警描述;" +
" data:数值;" +
" alarmTime:报警时间;" +
" }" +
" circuitABBVos:{" +
" transportationNo:运输编号;" +
" gatewaySN:网关编号;" +
" TDLSN:传感器编号;" +
" cargoNo:货物编号;" +
" cargoName:货物名;" +
" lng:当前经度;" +
" lat:当前纬度;" +
" isAlarm:该线路是否发生过报警;" +
" time:当前时间;" +
" }" +
" warehouseVoList:{" +
" warehouseNo:仓库编号;" +
" img:仓库图片;" +
" warehouseName:仓库名;" +
" country:国家;" +
" city:城市;" +
" regions:区域;" +
" addressDetail:地址;" +
" regionName:区域名;" +
" lng:经度;" +
" lat:纬度;" +
" property:属性;" +
" type:类型;" +
" hardwareLevel:硬件等级;" +
" areaIndoor:室内平面面积;" +
" areaRack:货架面积;" +
" areaOutdoor:室外面积;" +
" areaPlanIndoor:实际室内面积;" +
" office:办事处;" +
" timeZone:时区;" +
" warehouseInfo:基础描述;" +
" companyNo:公司编号;" +
" companyName:公司名;" +
" remark:当前时间;" +
" }" +
" histogramDataList{" +
" classify: 种类(1-温度,2-湿度,3-震动,4-倾角,5-延误,6-离线)" +
" count:数量" +
" }")
@PostMapping("/getAllForABB")
@ApiImplicitParams({
@ApiImplicitParam(paramType="header", name = "Account_token", value = "token", required = true, dataType = "String"),
@ApiImplicitParam(paramType="header", name = "AccountLanguage", value = "language", required = false, dataType = "String"),
})
public Object getAllForABB(@RequestBody String time, HttpServletRequest request){
String datum = tokenRedisService.get("TOKEN_" +request.getHeader("Account_token"));
UserRedisVo user = gson.fromJson(datum,UserRedisVo.class);
time=(String) JSON.parseObject(time).get("time");
time = time.replace("天","").trim();
//获取数量
HomePageDataABBVo dataVo = new HomePageDataABBVo();
//获取所有的线路数量
dataVo.setSum(circuitABBService.getCount(time,System.currentTimeMillis()/1000l,user.getCompanyNo()));//总数量
//获取近几天的线路信息
dataVo.setOnRoute(circuitABBService.getOnRoute(user.getCompanyNo()));//在途数量
dataVo.setAlarmed(alarmLogServcie.getCount(time,user.getCompanyNo()));//报警数量
dataVo.setBump(alarmLogServcie.getBumpCount(time,user.getCompanyNo())); //获取颠簸数量
dataVo.setAlarmLogVos(alarmLogServcie.getAlarmLog(time,user.getCompanyNo()));//报警列表
dataVo.setWarehouseVoList(warehouseService.getAll(user.getCompanyNo()));
//获取设备的当前位置
List<CircuitABBVo> circuitVos = circuitABBService.getForHomePage(user.getCompanyNo());
Integer num = 0;
for(int i = 0;i<circuitVos.size();i++){
ResultGatewayVo gatewayVo = tdlLogService.getByNo(circuitVos.get(i).getTransportationNo());
String device = gatewayVo.getType() + "_" + gatewayVo.getSN();
Object data = infoRedisService.getHash("DeviceOnline",device);
if(data !=null){
OnlineVo onlineVo = gson.fromJson(data.toString(),OnlineVo.class);
if(onlineVo.getOnline() == 0){
num =num +1;
}
}
if(gatewayVo!=null&&circuitVos.get(i).getBindTime()!=null){
Long startTime = circuitVos.get(i).getBindTime() * 1000000l;
String sql = "SELECT \"lng\",\"lat\" FROM \"tdl_policy\".\"" + device + "\" where time >= " + startTime + " ORDER BY time desc limit 1";
QueryResult queryResult = influxDBTemplate.query(new Query(sql, database));
if (queryResult.getResults().get(0).getSeries() != null) {
circuitVos.get(i).setTime(parseTime(queryResult.getResults().get(0).getSeries().get(0).getValues().get(0).get(0).toString()));
circuitVos.get(i).setLng(queryResult.getResults().get(0).getSeries().get(0).getValues().get(0).get(1).toString());
circuitVos.get(i).setLat(queryResult.getResults().get(0).getSeries().get(0).getValues().get(0).get(2).toString());
}
}else {
circuitVos.get(i).setTime(null);
circuitVos.get(i).setLng(null);
circuitVos.get(i).setLat(null);
}
}
List<HistogramData> list = alarmLogServcie.getByCountForABB(time,user.getCompanyNo());//获取报警柱状图
list.add(new HistogramData("6",num));
dataVo.setHistogramDataList(list);
dataVo.setCircuitABBVos(circuitVos);
return gson.toJson(dataVo);
}
//获取当天所有的设备数据
......
......@@ -77,6 +77,24 @@
AND DATE_SUB(CURDATE(), INTERVAL #{time,jdbcType=VARCHAR} DAY) &lt;= date(FROM_UNIXTIME(alarmTime/1000,'%Y-%m-%d %H:%i:%s'))
</select>
<select id = "getByCountForABB" parameterType="String" resultType="com.example.tdl.domain.vo.HistogramData" >
SELECT ifnull(classify,"1") classify,count(description) count FROM alarm_log WHERE classify = "1"
and transportationNo in (select transportationNo from circuit where company_id =(select id from company where companyNo =#{companyNo,jdbcType=VARCHAR}))
AND DATE_SUB(CURDATE(), INTERVAL #{time,jdbcType=VARCHAR} DAY) &lt;= date(FROM_UNIXTIME(alarmTime/1000,'%Y-%m-%d %H:%i:%s'))
UNION ALL
SELECT ifnull(classify,"2") classify,count(description) count FROM alarm_log WHERE classify = "2"
and transportationNo in (select transportationNo from circuit where company_id =(select id from company where companyNo =#{companyNo,jdbcType=VARCHAR}))
AND DATE_SUB(CURDATE(), INTERVAL #{time,jdbcType=VARCHAR} DAY) &lt;= date(FROM_UNIXTIME(alarmTime/1000,'%Y-%m-%d %H:%i:%s'))
UNION ALL
SELECT ifnull(classify,"3") classify,count(description) count FROM alarm_log WHERE classify = "3"
and transportationNo in (select transportationNo from circuit where company_id =(select id from company where companyNo =#{companyNo,jdbcType=VARCHAR}))
AND DATE_SUB(CURDATE(), INTERVAL #{time,jdbcType=VARCHAR} DAY) &lt;= date(FROM_UNIXTIME(alarmTime/1000,'%Y-%m-%d %H:%i:%s'))
UNION ALL
SELECT ifnull(classify,"4") classify,count(description) count FROM alarm_log WHERE classify = "4"
and transportationNo in (select transportationNo from circuit where company_id =(select id from company where companyNo =#{companyNo,jdbcType=VARCHAR}))
AND DATE_SUB(CURDATE(), INTERVAL #{time,jdbcType=VARCHAR} DAY) &lt;= date(FROM_UNIXTIME(alarmTime/1000,'%Y-%m-%d %H:%i:%s'))
</select>
<select id="getByTime" resultType="java.lang.Integer">
select count(id) from alarm_log
where transportationNo= #{transportationNo,jdbcType=VARCHAR}
......
......@@ -143,5 +143,27 @@
AND company_id=(SELECT id from company where companyNo=#{companyNo,jdbcType=VARCHAR})
</select>
<!--总数量-->
<select id="getCount" resultType="java.lang.Integer">
select count(id) from circuit
where company_id=(SELECT id from company where companyNo=#{companyNo,jdbcType=VARCHAR})
AND state =1
and DATE_SUB(CURDATE(), INTERVAL #{time,jdbcType=VARCHAR} DAY) &lt;= date(FROM_UNIXTIME(ifnull(endTime/1000, #{endTime,jdbcType=BIGINT}),'%Y-%m-%d %H:%i:%s'))
</select>
<!-- 运输中数量-->
<select id="getOnRoute" resultType="java.lang.Integer" parameterType="String">
select count(transportationNo) from circuit where circuitState=1 AND state = 1
AND company_id=(SELECT id from company where companyNo=#{companyNo,jdbcType=VARCHAR})
</select>
<select id="getForHomePage" parameterType="java.lang.String" resultType="com.example.tdl.domain.vo.CircuitABBVo">
SELECT c.transportationNo,t.gatewaySN,t.TDLSN,cargoNo,cargoName,circuitState,IF(a.num>0,1,0) isAlarm,c.startTime
from circuit c LEFT JOIN (SELECT DISTINCT TDLSN,gatewaySN,gatewayType,transportationNo FROM tdl_gateway_log) t
ON c.transportationNo=t.transportationNo LEFT JOIN (SELECT COUNT(id) num,transportationNo FROM alarm_log) a
ON a.transportationNo=c.transportationNo
where c.state=1
and c.circuitState = 1
AND company_id=(SELECT id from company where companyNo=#{companyNo,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