Commit 53d9af0e authored by 耿迪迪's avatar 耿迪迪

新加流量计上报 gengdidi

parent bc0ee344
......@@ -28,6 +28,9 @@ public class TDeviceReportData {
/** 工况累计量 */
private BigDecimal workingConditionAccumulation;
/** 逆向标况累计量 */
private BigDecimal backingStandardConditionAccumulation;
/** 剩余量 */
private BigDecimal residualQuantity;
......
......@@ -14,6 +14,12 @@ public class FlowmeterDecryReportedDataStrategy {
return new FlowmeterDecryptReportedData(reportedDataStr,"天信CPU卡式体积修正仪");
case "b2":
return new Tian5cFlowmeterDecryptReportedData(reportedDataStr,"天津市第五机床厂C型体积积算仪(天五C型)");
case "b3":
return new JiangsuyuanruiFlowmeterDecryptReportedData(reportedDataStr,"江苏远睿气体腰轮流量计");
case "b4":
return new SitedaFlowmeterDecryptReportedData(reportedDataStr,"思达特AS气体超声流量计");
case "b5":
return new FumaFlowmeterDecryptReportedData(reportedDataStr,"裕顺仪表(富马)智能型流量计");
default:
return null;
}
......
package com.zehong.gassdevicereport.netty.decryptreported.flowmeter;
import com.zehong.gassdevicereport.entity.TDeviceReportData;
import com.zehong.gassdevicereport.utils.HexUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.math.BigDecimal;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
/**
* @author zehong
* 接收富马(裕顺仪表)气体流量计上报数据
*/
public class FumaFlowmeterDecryptReportedData implements DecryptReportedData{
private Logger logger = LoggerFactory.getLogger(FumaFlowmeterDecryptReportedData.class);
private String reportedDataStr;
private String deviceType;
public FumaFlowmeterDecryptReportedData(String reportedDataStr, String deviceType) {
this.reportedDataStr = reportedDataStr;
this.deviceType = deviceType;
}
@Override
public TDeviceReportData getReportedData(){
try {
TDeviceReportData tDeviceReportData = new TDeviceReportData();
//设备编号
tDeviceReportData.setDeviceNum(getDeviceNum());
//设备上报时间
Date reportedTime = getReportedTime();
tDeviceReportData.setReportTime(reportedTime);
//标方累积流量
double standardConditionAccumulation =HexUtils.hexToFloat(reportedDataStr.substring(48, 56));
tDeviceReportData.setStandardConditionAccumulation(new BigDecimal(standardConditionAccumulation));
//标方瞬时流量
float standardConditionFlow = HexUtils.hexToFloat(reportedDataStr.substring(56, 64));
tDeviceReportData.setStandardConditionFlow(new BigDecimal(standardConditionFlow));
// 压力
float pressure = HexUtils.hexToFloat(reportedDataStr.substring(64, 72));
tDeviceReportData.setPressure(new BigDecimal(pressure));
// 温度
float temperature = HexUtils.hexToFloat(reportedDataStr.substring(72, 80));
tDeviceReportData.setTemperature(new BigDecimal(temperature));
//通讯字段
String communicationStatus = getCommunicationStatus();
tDeviceReportData.setCommunicationStatus(communicationStatus);
tDeviceReportData.setDeviceStatus(deviceType);
return tDeviceReportData;
} catch (Exception e) {
logger.error("上报数据组装数据报错!"+e);
}
return null;
}
/**
* 获取设备编号
* @return
*/
private String getDeviceNum(){
String deviceNum = reportedDataStr.substring(0,36);
StringBuilder deviceNumStr = new StringBuilder("");
for(int i = 0; i < deviceNum.length(); i+=2){
String code = deviceNum.substring(i,i+2);
byte codeByte = HexUtils.hexToByte(code);
deviceNumStr.append(codeByte);
}
return deviceNumStr.toString();
}
/**
* 获取上报时间
* @return
* @throws ParseException
*/
private Date getReportedTime() throws ParseException {
String reportTime = reportedDataStr.substring(36,48);
if("00".equals(reportTime.substring(0,2))){
return new Date();
}
StringBuilder timeStr = new StringBuilder("");
timeStr.append(reportTime.substring(0,2));
timeStr.append("-");
timeStr.append(reportTime.substring(2,4));
timeStr.append("-");
timeStr.append(reportTime.substring(4,6));
timeStr.append(" ");
timeStr.append(reportTime.substring(6,8));
timeStr.append(":");
timeStr.append(reportTime.substring(8,10));
timeStr.append(":");
timeStr.append(reportTime.substring(10,12));
return new SimpleDateFormat("yy-MM-dd HH:mm:ss").parse(timeStr.toString());
}
/**
* 通讯字
* @return
*/
private String getCommunicationStatus(){
String communicationStatus = reportedDataStr.substring(80, 84);
StringBuilder communicationStatusStr = new StringBuilder("");
communicationStatusStr.append( HexUtils.hexToByte(communicationStatus.substring(0,2)));
communicationStatusStr.append( HexUtils.hexToByte(communicationStatus.substring(2,4)));
return communicationStatusStr.toString();
}
}
package com.zehong.gassdevicereport.netty.decryptreported.flowmeter;
import com.zehong.gassdevicereport.entity.TDeviceReportData;
import com.zehong.gassdevicereport.utils.HexUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.math.BigDecimal;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
/**
* @author zehong
* 接收江苏远睿气体腰轮流量计上报数据
*/
public class JiangsuyuanruiFlowmeterDecryptReportedData implements DecryptReportedData{
private Logger logger = LoggerFactory.getLogger(JiangsuyuanruiFlowmeterDecryptReportedData.class);
private String reportedDataStr;
private String deviceType;
public JiangsuyuanruiFlowmeterDecryptReportedData(String reportedDataStr, String deviceType) {
this.reportedDataStr = reportedDataStr;
this.deviceType = deviceType;
}
@Override
public TDeviceReportData getReportedData(){
try {
TDeviceReportData tDeviceReportData = new TDeviceReportData();
//设备编号
tDeviceReportData.setDeviceNum(getDeviceNum());
//设备上报时间
Date reportedTime = getReportedTime();
tDeviceReportData.setReportTime(reportedTime);
// 累计流量
double standardConditionAccumulation = HexUtils.hexToDouble(reportedDataStr.substring(48, 64));
tDeviceReportData.setStandardConditionAccumulation(new BigDecimal(standardConditionAccumulation));
// 标况瞬时流量
float standardConditionFlow = HexUtils.hexToFloat(reportedDataStr.substring(64, 72));
tDeviceReportData.setStandardConditionFlow(new BigDecimal(standardConditionFlow));
// 工况瞬时流量
float workingConditionFlow = HexUtils.hexToFloat(reportedDataStr.substring(72, 80));
tDeviceReportData.setWorkingConditionFlow(new BigDecimal(workingConditionFlow));
// 温度
float temperature = HexUtils.hexToFloat(reportedDataStr.substring(80, 88));
tDeviceReportData.setTemperature(new BigDecimal(temperature));
// 压力
float pressure = HexUtils.hexToFloat(reportedDataStr.substring(88, 96));
tDeviceReportData.setPressure(new BigDecimal(pressure));
//通讯字段
String communicationStatus = getCommunicationStatus();
tDeviceReportData.setCommunicationStatus(communicationStatus);
tDeviceReportData.setDeviceStatus(deviceType);
return tDeviceReportData;
} catch (Exception e) {
logger.error("上报数据组装数据报错!"+e);
}
return null;
}
/**
* 获取设备编号
* @return
*/
private String getDeviceNum(){
String deviceNum = reportedDataStr.substring(0,36);
StringBuilder deviceNumStr = new StringBuilder("");
for(int i = 0; i < deviceNum.length(); i+=2){
String code = deviceNum.substring(i,i+2);
byte codeByte = HexUtils.hexToByte(code);
deviceNumStr.append(codeByte);
}
return deviceNumStr.toString();
}
/**
* 获取上报时间
* @return
* @throws ParseException
*/
private Date getReportedTime() throws ParseException {
String reportTime = reportedDataStr.substring(36,48);
if("00".equals(reportTime.substring(0,2))){
return new Date();
}
StringBuilder timeStr = new StringBuilder("");
timeStr.append(reportTime.substring(0,2));
timeStr.append("-");
timeStr.append(reportTime.substring(2,4));
timeStr.append("-");
timeStr.append(reportTime.substring(4,6));
timeStr.append(" ");
timeStr.append(reportTime.substring(6,8));
timeStr.append(":");
timeStr.append(reportTime.substring(8,10));
timeStr.append(":");
timeStr.append(reportTime.substring(10,12));
return new SimpleDateFormat("yy-MM-dd HH:mm:ss").parse(timeStr.toString());
}
/**
* 通讯字
* @return
*/
private String getCommunicationStatus(){
String communicationStatus = reportedDataStr.substring(96, 100);
StringBuilder communicationStatusStr = new StringBuilder("");
communicationStatusStr.append( HexUtils.hexToByte(communicationStatus.substring(0,2)));
communicationStatusStr.append( HexUtils.hexToByte(communicationStatus.substring(2,4)));
return communicationStatusStr.toString();
}
}
package com.zehong.gassdevicereport.netty.decryptreported.flowmeter;
import com.zehong.gassdevicereport.entity.TDeviceReportData;
import com.zehong.gassdevicereport.utils.HexUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.math.BigDecimal;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
/**
* @author zehong
* 接收思达特AS气体超声流量计上报数据
*/
public class SitedaFlowmeterDecryptReportedData implements DecryptReportedData{
private Logger logger = LoggerFactory.getLogger(SitedaFlowmeterDecryptReportedData.class);
private String reportedDataStr;
private String deviceType;
public SitedaFlowmeterDecryptReportedData(String reportedDataStr, String deviceType) {
this.reportedDataStr = reportedDataStr;
this.deviceType = deviceType;
}
@Override
public TDeviceReportData getReportedData(){
try {
TDeviceReportData tDeviceReportData = new TDeviceReportData();
//设备编号
tDeviceReportData.setDeviceNum(getDeviceNum());
//设备上报时间
Date reportedTime = getReportedTime();
tDeviceReportData.setReportTime(reportedTime);
//正工况累积流量
double workingConditionAccumulation = HexUtils.hexToFloat(reportedDataStr.substring(48, 56));
tDeviceReportData.setWorkingConditionAccumulation(new BigDecimal(workingConditionAccumulation));
//正标况累积流量
double standardConditionAccumulation =HexUtils.hexToFloat(reportedDataStr.substring(56, 64));
tDeviceReportData.setStandardConditionAccumulation(new BigDecimal(standardConditionAccumulation));
//逆标况累积流量
double backingStandardConditionAccumulation = HexUtils.hexToFloat(reportedDataStr.substring(64, 72));
tDeviceReportData.setBackingStandardConditionAccumulation(new BigDecimal(backingStandardConditionAccumulation));
// 工况瞬时流量
float workingConditionFlow = HexUtils.hexToFloat(reportedDataStr.substring(72, 80));
tDeviceReportData.setWorkingConditionFlow(new BigDecimal(workingConditionFlow));
// 标况瞬时流量
float standardConditionFlow = HexUtils.hexToFloat(reportedDataStr.substring(80, 88));
tDeviceReportData.setStandardConditionFlow(new BigDecimal(standardConditionFlow));
// 压力
float pressure = HexUtils.hexToFloat(reportedDataStr.substring(88, 96));
tDeviceReportData.setPressure(new BigDecimal(pressure));
// 温度
float temperature = HexUtils.hexToFloat(reportedDataStr.substring(96, 104));
tDeviceReportData.setTemperature(new BigDecimal(temperature));
//通讯字段
String communicationStatus = getCommunicationStatus();
tDeviceReportData.setCommunicationStatus(communicationStatus);
tDeviceReportData.setDeviceStatus(deviceType);
return tDeviceReportData;
} catch (Exception e) {
logger.error("上报数据组装数据报错!"+e);
}
return null;
}
/**
* 获取设备编号
* @return
*/
private String getDeviceNum(){
String deviceNum = reportedDataStr.substring(0,36);
StringBuilder deviceNumStr = new StringBuilder("");
for(int i = 0; i < deviceNum.length(); i+=2){
String code = deviceNum.substring(i,i+2);
byte codeByte = HexUtils.hexToByte(code);
deviceNumStr.append(codeByte);
}
return deviceNumStr.toString();
}
/**
* 获取上报时间
* @return
* @throws ParseException
*/
private Date getReportedTime() throws ParseException {
String reportTime = reportedDataStr.substring(36,48);
if("00".equals(reportTime.substring(0,2))){
return new Date();
}
StringBuilder timeStr = new StringBuilder("");
timeStr.append(reportTime.substring(0,2));
timeStr.append("-");
timeStr.append(reportTime.substring(2,4));
timeStr.append("-");
timeStr.append(reportTime.substring(4,6));
timeStr.append(" ");
timeStr.append(reportTime.substring(6,8));
timeStr.append(":");
timeStr.append(reportTime.substring(8,10));
timeStr.append(":");
timeStr.append(reportTime.substring(10,12));
return new SimpleDateFormat("yy-MM-dd HH:mm:ss").parse(timeStr.toString());
}
/**
* 通讯字
* @return
*/
private String getCommunicationStatus(){
String communicationStatus = reportedDataStr.substring(104, 108);
StringBuilder communicationStatusStr = new StringBuilder("");
communicationStatusStr.append( HexUtils.hexToByte(communicationStatus.substring(0,2)));
communicationStatusStr.append( HexUtils.hexToByte(communicationStatus.substring(2,4)));
return communicationStatusStr.toString();
}
}
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.zehong.gassdevicereport.dao.TDeviceReportDataDao">
<resultMap type="TDeviceReportData" id="TDeviceReportDataResult">
<result property="deviceReportDataId" column="device_report_data_id" />
<result property="deviceNum" column="device_num" />
<result property="standardConditionAccumulation" column="standard_condition_accumulation" />
<result property="workingConditionAccumulation" column="working_condition_accumulation" />
<result property="backingStandardConditionAccumulation" column="backing_standard_condition_accumulation" />
<result property="residualQuantity" column="residual_quantity" />
<result property="standardConditionFlow" column="standard_condition_flow" />
<result property="workingConditionFlow" column="working_condition_flow" />
......@@ -22,15 +23,16 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</resultMap>
<sql id="selectTDeviceReportDataVo">
select device_report_data_id, device_num, standard_condition_accumulation, working_condition_accumulation, residual_quantity, standard_condition_flow, working_condition_flow, temperature, pressure, report_time, communication_status, device_status, create_time, update_time from t_device_report_data
select device_report_data_id, device_num, standard_condition_accumulation, working_condition_accumulation, backing_standard_condition_accumulation, residual_quantity, standard_condition_flow, working_condition_flow, temperature, pressure, report_time, communication_status, device_status, create_time, update_time from t_device_report_data
</sql>
<select id="selectTDeviceReportDataList" parameterType="TDeviceReportData" resultMap="TDeviceReportDataResult">
<include refid="selectTDeviceReportDataVo"/>
<where>
<if test="deviceNum != null "> and device_num = #{deviceNum}</if>
<where>
<if test="deviceNum != null and deviceNum != ''"> and device_num = #{deviceNum}</if>
<if test="standardConditionAccumulation != null "> and standard_condition_accumulation = #{standardConditionAccumulation}</if>
<if test="workingConditionAccumulation != null "> and working_condition_accumulation = #{workingConditionAccumulation}</if>
<if test="backingStandardConditionAccumulation != null "> and backing_standard_condition_accumulation = #{backingStandardConditionAccumulation}</if>
<if test="residualQuantity != null "> and residual_quantity = #{residualQuantity}</if>
<if test="standardConditionFlow != null "> and standard_condition_flow = #{standardConditionFlow}</if>
<if test="workingConditionFlow != null "> and working_condition_flow = #{workingConditionFlow}</if>
......@@ -41,18 +43,19 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="deviceStatus != null and deviceStatus != ''"> and device_status = #{deviceStatus}</if>
</where>
</select>
<select id="selectTDeviceReportDataById" parameterType="Long" resultMap="TDeviceReportDataResult">
<include refid="selectTDeviceReportDataVo"/>
where device_report_data_id = #{deviceReportDataId}
</select>
<insert id="insertTDeviceReportData" parameterType="TDeviceReportData" useGeneratedKeys="true" keyProperty="deviceReportDataId">
insert into t_device_report_data
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="deviceNum != null">device_num,</if>
<if test="standardConditionAccumulation != null">standard_condition_accumulation,</if>
<if test="workingConditionAccumulation != null">working_condition_accumulation,</if>
<if test="backingStandardConditionAccumulation != null">backing_standard_condition_accumulation,</if>
<if test="residualQuantity != null">residual_quantity,</if>
<if test="standardConditionFlow != null">standard_condition_flow,</if>
<if test="workingConditionFlow != null">working_condition_flow,</if>
......@@ -63,11 +66,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="deviceStatus != null">device_status,</if>
<if test="createTime != null">create_time,</if>
<if test="updateTime != null">update_time,</if>
</trim>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="deviceNum != null">#{deviceNum},</if>
<if test="standardConditionAccumulation != null">#{standardConditionAccumulation},</if>
<if test="workingConditionAccumulation != null">#{workingConditionAccumulation},</if>
<if test="backingStandardConditionAccumulation != null">#{backingStandardConditionAccumulation},</if>
<if test="residualQuantity != null">#{residualQuantity},</if>
<if test="standardConditionFlow != null">#{standardConditionFlow},</if>
<if test="workingConditionFlow != null">#{workingConditionFlow},</if>
......@@ -78,7 +82,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="deviceStatus != null">#{deviceStatus},</if>
<if test="createTime != null">#{createTime},</if>
<if test="updateTime != null">#{updateTime},</if>
</trim>
</trim>
</insert>
<update id="updateTDeviceReportData" parameterType="TDeviceReportData">
......@@ -87,6 +91,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="deviceNum != null">device_num = #{deviceNum},</if>
<if test="standardConditionAccumulation != null">standard_condition_accumulation = #{standardConditionAccumulation},</if>
<if test="workingConditionAccumulation != null">working_condition_accumulation = #{workingConditionAccumulation},</if>
<if test="backingStandardConditionAccumulation != null">backing_standard_condition_accumulation = #{backingStandardConditionAccumulation},</if>
<if test="residualQuantity != null">residual_quantity = #{residualQuantity},</if>
<if test="standardConditionFlow != null">standard_condition_flow = #{standardConditionFlow},</if>
<if test="workingConditionFlow != null">working_condition_flow = #{workingConditionFlow},</if>
......@@ -106,7 +111,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</delete>
<delete id="deleteTDeviceReportDataByIds" parameterType="String">
delete from t_device_report_data where device_report_data_id in
delete from t_device_report_data where device_report_data_id in
<foreach item="deviceReportDataId" collection="array" open="(" separator="," close=")">
#{deviceReportDataId}
</foreach>
......
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