Commit 6fd17789 authored by Carit Zhu's avatar Carit Zhu 🎱

Merge branch 'tdl_bosch_carit' into 'tdl_bosch'

Tdl bosch carit

See merge request !4
parents 46b8f645 fe7adea4
Pipeline #497 passed with stage
in 0 seconds
......@@ -15,7 +15,7 @@ apply plugin: 'idea'
apply plugin: 'org.springframework.boot'
group = 'com.example'
version = '0.0.1-SNAPSHOT'
version = '1.0.1-release'
sourceCompatibility = 1.8
repositories {
......
......@@ -4,7 +4,9 @@ public class AddWarehouseGatewayVo {
private String warehouseNo;
private String gSN;
private String gSN;
private String gatewayName;
public String getWarehouseNo() {
return warehouseNo;
......@@ -21,4 +23,12 @@ public class AddWarehouseGatewayVo {
public void setgSN(String gSN) {
this.gSN = gSN;
}
public String getGatewayName() {
return gatewayName;
}
public void setGatewayName(String gatewayName) {
this.gatewayName = gatewayName;
}
}
......@@ -8,7 +8,9 @@ public class BindingVo {
private Integer mode;
private String TDLSN;
private String TDLSN;
private String TDLName;
private String transportationNo;
......@@ -48,6 +50,14 @@ public class BindingVo {
this.TDLSN = TDLSN;
}
public String getTDLName() {
return TDLName;
}
public void setTDLName(String TDLName) {
this.TDLName = TDLName;
}
public String getTransportationNo() {
return transportationNo;
}
......
......@@ -7,6 +7,8 @@ public class GatewayOnLineVo {
private String type;
private String name;
private Integer state;
private Long startTime;
......@@ -23,6 +25,14 @@ public class GatewayOnLineVo {
this.gSN = gSN;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getType() {
return type;
}
......
......@@ -3,6 +3,8 @@ package com.example.tdl.domain.vo;
public class TDLDeviceDetailVo {
private String TDLSN;
private String TDLName;
private String pressure;
private String temperature;
......@@ -23,6 +25,14 @@ public class TDLDeviceDetailVo {
this.TDLSN = TDLSN;
}
public String getTDLName() {
return TDLName;
}
public void setTDLName(String TDLName) {
this.TDLName = TDLName;
}
public String getPressure() {
return pressure;
}
......
......@@ -4,6 +4,8 @@ public class TDLDeviceVo {
private String TDLSN;
private String TDLName;
private String offsetJson;
public String getTDLSN() {
......@@ -14,6 +16,14 @@ public class TDLDeviceVo {
this.TDLSN = TDLSN;
}
public String getTDLName() {
return TDLName;
}
public void setTDLName(String TDLName) {
this.TDLName = TDLName;
}
public String getOffsetJson() {
return offsetJson;
}
......
......@@ -6,7 +6,6 @@ public class UpdateTDLDeviceVo {
private String TDLSN;
public String getTDLName() {
return TDLName;
}
......
......@@ -6,6 +6,8 @@ public class WarehouseDataVo {
private String TDLSN;
private String TDLName;
private String batteryVoltage;
private String temperature;
......@@ -24,6 +26,14 @@ public class WarehouseDataVo {
this.TDLSN = TDLSN;
}
public String getTDLName() {
return TDLName;
}
public void setTDLName(String TDLName) {
this.TDLName = TDLName;
}
public String getBatteryVoltage() {
return batteryVoltage;
}
......
......@@ -7,43 +7,52 @@ public class WarehouseGatewayDateVo {
private String type;
private String name;
private String battery;
private int state;
private List<WarehouseDataVo> warehouseDataVos;
public String getgSN() {
return gSN;
}
public String getBattery() {
return battery;
public void setgSN(String gSN) {
this.gSN = gSN;
}
public void setBattery(String battery) {
this.battery = battery;
public String getType() {
return type;
}
public int getState() {
return state;
public void setType(String type) {
this.type = type;
}
public void setState(int state) {
this.state = state;
public String getName() {
return name;
}
public String getgSN() {
return gSN;
public void setName(String name) {
this.name = name;
}
public void setgSN(String gSN) {
this.gSN = gSN;
public String getBattery() {
return battery;
}
public String getType() {
return type;
public void setBattery(String battery) {
this.battery = battery;
}
public void setType(String type) {
this.type = type;
public int getState() {
return state;
}
public void setState(int state) {
this.state = state;
}
public List<WarehouseDataVo> getWarehouseDataVos() {
......
......@@ -10,6 +10,8 @@ public class WarehouseLogVo {
private String device;
private String deviceName;
private Long createTime;
private Long endTime;
......@@ -46,6 +48,14 @@ public class WarehouseLogVo {
this.device = device;
}
public String getDeviceName() {
return deviceName;
}
public void setDeviceName(String deviceName) {
this.deviceName = deviceName;
}
public Long getCreateTime() {
return createTime;
}
......
......@@ -105,15 +105,26 @@ public class AlarmRule {
try {
String hashKey = "TDL-" + TDLSN + "_" + alias;
/* Get alarm rule from redis */
List<AlarmRuleVo> alarmRuleList;
Object hashValueObject = alarmRedisService.getHash(topic, hashKey);
List<AlarmRuleVo> alarmRuleList = gson.fromJson(hashValueObject.toString(),
new TypeToken<ArrayList<AlarmRuleVo>>() {}.getType());
/* Update offset */
if (alarmRuleList != null && alarmRuleList.size() > 0) {
alarmRuleList.get(0).setOffset(offset);
/* Write back to redis */
alarmRedisService.hmSet(topic, hashKey, gson.toJson(alarmRuleList));
if (hashValueObject != null) {
alarmRuleList = gson.fromJson(hashValueObject.toString(),
new TypeToken<ArrayList<AlarmRuleVo>>() {
}.getType());
/* Update offset */
if (alarmRuleList != null && alarmRuleList.size() > 0) {
alarmRuleList.get(0).setOffset(offset);
}
} else {
alarmRuleList = new ArrayList<>();
AlarmRuleVo alarmRuleVo = new AlarmRuleVo();
alarmRuleVo.setOffset(offset);
alarmRuleList.add(alarmRuleVo);
}
/* Write back to redis */
alarmRedisService.hmSet(topic, hashKey, gson.toJson(alarmRuleList));
} catch (JsonSyntaxException e) {
logger.error("Update offset(" + alias + ") JsonSyntaxException: " + e.getMessage());
}
......
package com.example.tdl.web;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.example.tdl.domain.dto.CommFeedback;
......@@ -12,7 +11,6 @@ import com.example.tdl.service.redis.InfoRedisService;
import com.example.tdl.service.redis.TokenRedisService;
import com.example.tdl.util.AlarmRule;
import com.google.gson.Gson;
import com.sun.org.apache.regexp.internal.RE;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
......@@ -26,10 +24,7 @@ import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.influxdb.InfluxDBTemplate;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import retrofit2.http.POST;
import javax.print.DocFlavor;
import javax.print.attribute.standard.RequestingUserName;
import javax.servlet.http.HttpServletRequest;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
......
......@@ -85,7 +85,8 @@ public class EquipmentBindingController {
" SN:gateWay编号," +
" type:gateWay类型," +
" mode:1--运输/2--仓库," +
" TDLSN:tdl编号," +
" tdlsn:tdl编号," +
" tdlname: tdl名称" +
" transportationNo:运输编号," +
" warehouseNo:仓库编号," +
" alarmType:预警类型" )
......@@ -223,6 +224,7 @@ public class EquipmentBindingController {
map.put("state",1);
map.put("untie",false);
map.put("TDLSN",bindingVo.getTDLSN());
map.put("TDLName",bindingVo.getTDLName());
map.put("createTime",System.currentTimeMillis());
configService.addConfig(map);
Map<Object,Object> msg=new HashMap<>();
......
......@@ -267,6 +267,7 @@ public class WarehouseController {
" gatewayOnLineVos: [" +
" {" +
" type: 网关类型," +
" name: 网关名称," +
" state: 在线状态(6离线,7在线)," +
" battery: 电量," +
" tdlDeviceDetailVos: [" +
......@@ -276,6 +277,7 @@ public class WarehouseController {
" humidity: 湿度," +
" time: 时间," +
" tdlsn: TDL编号" +
" tdlname: TDL名称" +
" gatewaySN:网关编号" +
" offsetJson: 校准JSON(若为空则视为全零)" +
" }" +
......@@ -319,6 +321,7 @@ public class WarehouseController {
GatewayOnLineVo gatewayOnLineVo = new GatewayOnLineVo();
gatewayOnLineVo.setgSN(list.get(a).getSN());
gatewayOnLineVo.setType(list.get(a).getType());
gatewayOnLineVo.setName(list.get(a).getDeviceName());
Object data = infoRedisService.getHash("DeviceOnline", list.get(a).getDevice() );
if(data !=null){
OnlineVo onlineVo = gson.fromJson(data.toString(),OnlineVo.class);
......@@ -364,6 +367,7 @@ public class WarehouseController {
tdlDeviceDetailVo.setHumidity("NA");
}
tdlDeviceDetailVo.setTDLSN(tdlDeviceVo.getTDLSN().replace("TDL-","").trim());
tdlDeviceDetailVo.setTDLName(tdlDeviceVo.getTDLName());
tdlDeviceDetailVo.setOffsetJson(tdlDeviceVo.getOffsetJson());
tdlDeviceDetailVos.add(tdlDeviceDetailVo);
}
......@@ -854,7 +858,8 @@ public class WarehouseController {
@ApiOperation(value="添加网关",notes = "添加网关,传值:" +
"warehouseNo:仓库编号" +
"SN:网关编号" +
"type:网关类型")
"gatewayName:网关名称"
)
@ApiImplicitParams({
@ApiImplicitParam(paramType="header", name = "Account_token", value = "token", required = true, dataType = "String"),
})
......@@ -889,6 +894,7 @@ public class WarehouseController {
map.put("warehouseNo",addWarehouseGatewayVo.getWarehouseNo());
map.put("gSN",addWarehouseGatewayVo.getgSN());
map.put("gType",type);
map.put("gName",addWarehouseGatewayVo.getGatewayName());
map.put("startTime",System.currentTimeMillis());
warehouseService.addGateway(map);
Map<Object,Object> msg=new HashMap<>();
......@@ -969,6 +975,7 @@ public class WarehouseController {
" {" +
" gSN: 网关编号," +
" type: 网关类型," +
" name: 网关名称," +
" warehouseDataVos: [" +
" {" +
" warehouseTDLDetailVos: [" +
......@@ -981,6 +988,7 @@ public class WarehouseController {
" }" +
" ]," +
" tdlsn: TDL-201802271711" +
" tdlname: tdl名称" +
" }" +
" ]" +
" }" +
......@@ -998,7 +1006,7 @@ public class WarehouseController {
}
List<WarehouseGatewayDateVo> warehouseGatewayDateVoList=new ArrayList<>();
List<GatewayOnLineVo> gatewayOnLineVos=gatewayService.getByWarehouseNo(warehouseVo.getWarehouseNo());
Long endTime = System.currentTimeMillis() +2*24*3600*1000l;
Long endTime = System.currentTimeMillis() + 2 * 24 * 3600 * 1000L;
for (int a=0;a<gatewayOnLineVos.size();a++){
if(gatewayOnLineVos.get(a) == null){
continue;
......@@ -1006,6 +1014,7 @@ public class WarehouseController {
WarehouseGatewayDateVo warehouseGatewayDateVo=new WarehouseGatewayDateVo();
warehouseGatewayDateVo.setgSN(gatewayOnLineVos.get(a).getgSN());
warehouseGatewayDateVo.setType(gatewayOnLineVos.get(a).getType());
warehouseGatewayDateVo.setName(gatewayOnLineVos.get(a).getName());
String device = gatewayOnLineVos.get(a).getType() + "_" + gatewayOnLineVos.get(a).getgSN();
String sql ="SELECT \"battery\" FROM \"tdl_policy\".\""+device +"\" where time >="+ gatewayOnLineVos.get(a).getStartTime()*1000000l+" ORDER BY time DESC LIMIT 1";
QueryResult queryResult = influxDBTemplate.query(new Query(sql, database));
......@@ -1029,15 +1038,19 @@ public class WarehouseController {
}else{
warehouseGatewayDateVo.setState(6);
}
List<String> tdls=tdlDeviceService.getByGatewaySN(gatewayOnLineVos.get(a).getgSN(),gatewayOnLineVos.get(a).getType());
List<TDLDeviceVo> tdlDeviceVoList = tdlDeviceService.getTdlByGatewaySN(
gatewayOnLineVos.get(a).getgSN(),gatewayOnLineVos.get(a).getType());
List<WarehouseDataVo> warehouseDataVos=new ArrayList<>();
for (int b=0;b<tdls.size();b++){
for (TDLDeviceVo tdlDeviceVo : tdlDeviceVoList){
List<WarehouseTDLDetailVo> warehouseTDLDetailVos=new ArrayList<>();
WarehouseDataVo warehouseDataVo=new WarehouseDataVo();
warehouseDataVo.setTDLSN(tdls.get(b).replace("TDL-","").trim());
String sqls ="SELECT \"tdl\",\"b\",\"T\",\"h\" FROM \"tdl_policy\".\""+device+"\" WHERE \"tdl\" = '"+tdls.get(b)+"' AND time >="+ gatewayOnLineVos.get(a).getStartTime()*1000000l+" and time <="+ endTime*1000000l+" ORDER BY time desc limit 1 ";
String rawTDLSN = tdlDeviceVo.getTDLSN().replace("TDL-","").trim();
warehouseDataVo.setTDLSN(rawTDLSN);
warehouseDataVo.setTDLName(tdlDeviceVo.getTDLName());
String sqls ="SELECT \"tdl\",\"b\",\"T\",\"h\" FROM \"tdl_policy\".\""+device+"\" WHERE \"tdl\" = '"+tdlDeviceVo.getTDLSN()+"' AND time >="+ gatewayOnLineVos.get(a).getStartTime()*1000000l+" and time <="+ endTime*1000000l+" ORDER BY time desc limit 1 ";
QueryResult queryResults = influxDBTemplate.query(new Query(sqls, database));
ResultAlarmVo resultAlarmVo=alarmService.getAlarmByWarehouseNo(warehouseVo.getWarehouseNo(),gatewayOnLineVos.get(a).getgSN(),tdls.get(b).replace("TDL-","").trim());
ResultAlarmVo resultAlarmVo=alarmService.getAlarmByWarehouseNo(warehouseVo.getWarehouseNo(),gatewayOnLineVos.get(a).getgSN(),rawTDLSN);
if (queryResults.getResults().get(0).getSeries() != null) {
warehouseDataVo.setTime(UTCToCST(queryResults.getResults().get(0).getSeries().get(0).getValues().get(0).get(0).toString(),warehouseVo.getOffset()==null ? "+8" : warehouseVo.getOffset()));
warehouseDataVo.setBatteryVoltage(df.format(new BigDecimal(queryResults.getResults().get(0).getSeries().get(0).getValues().get(0).get(2).toString())));
......@@ -1049,7 +1062,7 @@ public class WarehouseController {
warehouseDataVo.setTemperature("NA");
warehouseDataVo.setHumidity("NA");
}
String sql3 ="SELECT \"tdl\",\"T\",\"h\" FROM \"tdl_policy\".\""+device+"\" WHERE \"tdl\" = '"+tdls.get(b)+"' AND time >="+ gatewayOnLineVos.get(a).getStartTime()*1000000l+" and time <="+ endTime*1000000l+" ORDER BY time ";
String sql3 ="SELECT \"tdl\",\"T\",\"h\" FROM \"tdl_policy\".\""+device+"\" WHERE \"tdl\" = '"+tdlDeviceVo.getTDLSN()+"' AND time >="+ gatewayOnLineVos.get(a).getStartTime()*1000000l+" and time <="+ endTime*1000000l+" ORDER BY time ";
QueryResult queryResult3 = influxDBTemplate.query(new Query(sql3, database));
if(queryResult3.getResults().get(0).getSeries() != null){
......
......@@ -19,6 +19,7 @@
#{state,mode=IN,jdbcType=INTEGER},
#{untie,mode=IN,jdbcType=INTEGER},
#{TDLSN,mode=IN,jdbcType=VARCHAR},
#{TDLName,mode=IN,jdbcType=VARCHAR},
#{createTime,mode=IN,jdbcType=BIGINT},
#{msg,mode=OUT,jdbcType=VARCHAR}
)
......
......@@ -119,8 +119,8 @@
<!--根据仓库编号查询网关信息-->
<select id="getByWarehouseNo" parameterType="String" resultType="com.example.tdl.domain.vo.GatewayOnLineVo">
SELECT DISTINCT gatewaySN gSN, gatewayType type,createTime startTime
from tdl_gateway_log
SELECT DISTINCT tgl.gatewaySN gSN, tgl.gatewayType type, g.name, tgl.createTime startTime
from tdl_gateway_log tgl inner join gateway g on tgl.gatewaySN = g.SN and tgl.gatewayType = g.type
where warehouseNo=#{warehouseNo,jdbcType=VARCHAR}
and ISNULL(endTime)
GROUP BY gSN
......
......@@ -82,7 +82,7 @@
</select>
<select id="getTdlByGatewaySN" parameterType="String" resultType="com.example.tdl.domain.vo.TDLDeviceVo">
select CONCAT("TDL-",TDLSN) TDLSN,offsetJson from tdldevice t,gateway g
select CONCAT("TDL-",TDLSN) TDLSN, TDLName, offsetJson from tdldevice t, gateway g
where t.gateway_id = g.id
and g.SN =#{SN,jdbcType=VARCHAR}
and g.type=#{type,jdbcType=VARCHAR}
......
......@@ -61,11 +61,12 @@
AND endTime is null
</select>
<select id="getByWarehouse" parameterType="String" resultType="com.example.tdl.domain.vo.WarehouseLogVo">
select DISTINCT CONCAT(gatewaytype,"_",gatewaySN) device, tgl.gatewaySN SN,gatewaytype type,w.warehouseNo
from tdl_gateway_log tgl,warehouse w
select DISTINCT CONCAT(gatewaytype,"_",gatewaySN) device, tgl.gatewaySN SN, gatewaytype type, name deviceName, w.warehouseNo
from tdl_gateway_log tgl, warehouse w, gateway g
where tgl.warehouseNo = w.warehouseNo
and tgl.gatewaySN = g.SN
and tgl.gatewayType = g.type
and w.warehouseNo=#{warehouseNo,jdbcType=VARCHAR}
and ISNULL(endTime)
</select>
......
......@@ -155,6 +155,7 @@
#{warehouseNo,mode=IN,jdbcType=VARCHAR},
#{gSN,mode=IN,jdbcType=VARCHAR},
#{gType,mode=IN,jdbcType=VARCHAR},
#{gName,mode=IN,jdbcType=VARCHAR},
#{startTime,mode=IN,jdbcType=BIGINT},
#{msg,mode=OUT,jdbcType=VARCHAR}
)
......
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