|
@@ -0,0 +1,605 @@
|
|
|
+package com.usky.service.Impl;
|
|
|
+
|
|
|
+import com.usky.controller.HtController;
|
|
|
+import com.usky.entity.Sp_Lora_Device;
|
|
|
+import com.usky.entity.Sp_Lora_WAN;
|
|
|
+import com.usky.entity.Yt_Lora_Data;
|
|
|
+import com.usky.service.HtService;
|
|
|
+import com.usky.service.SendWXService;
|
|
|
+import com.usky.utils.HttpClientUtilWX;
|
|
|
+import org.apache.http.NameValuePair;
|
|
|
+import org.apache.http.message.BasicNameValuePair;
|
|
|
+import org.apache.log4j.Logger;
|
|
|
+import org.hibernate.Query;
|
|
|
+import org.hibernate.SQLQuery;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+import org.springframework.util.CollectionUtils;
|
|
|
+
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
+import java.io.BufferedInputStream;
|
|
|
+import java.io.Serializable;
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.sql.Timestamp;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
+import java.util.*;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @Author zhangzilong
|
|
|
+ * @Description //TODO
|
|
|
+ * @Date $ $
|
|
|
+ * @Param $
|
|
|
+ * @return $
|
|
|
+ */
|
|
|
+@Service
|
|
|
+@Transactional
|
|
|
+public class HtServiceImpl extends BaseServieImpl implements HtService {
|
|
|
+ private static final Logger LOGGER = Logger.getLogger(HtServiceImpl.class);
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private SendWXService sendWXService;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public int saveLora(Sp_Lora_WAN sp_lora_wan) {
|
|
|
+ int i = (int) getSession().save(sp_lora_wan);
|
|
|
+ return i;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @return void
|
|
|
+ * @Author zhangzilong
|
|
|
+ * @Description //烟感
|
|
|
+ * @Date 10:24 2020/3/13
|
|
|
+ * @Param * @param tab
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public void cretTab1(String tab) {
|
|
|
+ System.out.println("创建表明" + tab);
|
|
|
+
|
|
|
+ String sql = "CREATE TABLE IF NOT EXISTS `" + tab + "` (`id` int(25) NOT NULL AUTO_INCREMENT,`wan_id` int(25) NOT NULL COMMENT '网关表主键id',`device_id` varchar(50) NOT NULL COMMENT '设备编号',`owner_code` varchar(50) NOT NULL DEFAULT '' COMMENT '设备唯一标识',`version` varchar(11) NOT NULL DEFAULT '' COMMENT '协议版本',`frame` varchar(11) NOT NULL DEFAULT '' COMMENT '发送失败帧计算',`smog` varchar(11) NOT NULL DEFAULT '' COMMENT '烟雾浓度',`battery` varchar(11) NOT NULL DEFAULT '' COMMENT '电量',`TData` varchar(11) NOT NULL DEFAULT '' COMMENT '温度',`event_time` varchar(50) NOT NULL COMMENT '数据上报时间',`status` varchar(11) NOT NULL DEFAULT '' COMMENT '设备状态;0:设备心跳。1:设备自检。2:火灾报警。3:温度报警。4:烟感电量低。5:防拆报警。6:发射电路故障。',`time` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00' ON UPDATE CURRENT_TIMESTAMP COMMENT '入库时间',PRIMARY KEY (`id`)) ENGINE=InnoDB AUTO_INCREMENT=58 DEFAULT CHARSET=utf8;";
|
|
|
+ SQLQuery qry = this.getSession().createSQLQuery(sql);
|
|
|
+
|
|
|
+ int i = qry.executeUpdate();
|
|
|
+ System.out.println("创建表返回值" + i);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @return void
|
|
|
+ * @Author zhangzilong
|
|
|
+ * @Description //液位
|
|
|
+ * @Date 10:24 2020/3/13
|
|
|
+ * @Param * @param tab
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public void cretTab2(String tab) {
|
|
|
+ System.out.println("创建表明" + tab);
|
|
|
+
|
|
|
+ String sql = "CREATE TABLE IF NOT EXISTS `" + tab + "` (`id` int(25) NOT NULL AUTO_INCREMENT,`wan_id` int(25) NOT NULL COMMENT '网关表主键id',`device_id` varchar(50) NOT NULL COMMENT '设备编号',`owner_code` varchar(50) NOT NULL COMMENT '设备唯一编号',`length` varchar(11) NOT NULL COMMENT '长度',`device_type` varchar(11) NOT NULL COMMENT '设备类型。0:未知设备。1:无线智能消防栓监测终端。2:无线远程压力采集终端。3:无线远程液位采集终端',`send_freq` varchar(11) NOT NULL COMMENT '发送频率',`update_time` varchar(11) NOT NULL COMMENT '设置时间更新。0:关闭时间更新。1:开启时间更新',`device_status` varchar(11) NOT NULL COMMENT '设备状态。0:未知设备状态。1:设备状态正常。2:设备倾斜,可能被撞。3:设备有加速度,可能被盗。',`battery_level` varchar(11) NOT NULL COMMENT '电池电量',`battery_status` varchar(11) NOT NULL COMMENT '电池状态。1:电量过低。2:电量正常。',`value_status` varchar(11) NOT NULL COMMENT '数值状态。0:数值正常。1:低压超限。2:高压超限。3:波动变化超限。4:设备故障。',`value_unit` varchar(11) NOT NULL COMMENT '数值单位',`event_time` varchar(50) NOT NULL COMMENT '数据上报时间',`sample_value` varchar(11) NOT NULL COMMENT '结果值',`time` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00' ON UPDATE CURRENT_TIMESTAMP COMMENT '时间',PRIMARY KEY (`id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8;";
|
|
|
+ SQLQuery qry = this.getSession().createSQLQuery(sql);
|
|
|
+ int i = qry.executeUpdate();
|
|
|
+ System.out.println("创建表返回值" + i);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void saveYG(String payload, String num, String tab, String loraWanId, String devid,String time) {
|
|
|
+
|
|
|
+ //协议版本
|
|
|
+ String version = payload.substring(2, 4);
|
|
|
+ // String head = payload.substring(0, 24);
|
|
|
+ //消息体
|
|
|
+ String str = payload.substring(24, 58);
|
|
|
+ String end = payload.substring(58, payload.length());
|
|
|
+
|
|
|
+
|
|
|
+ System.out.println((str.length() / 2));
|
|
|
+ //告警识别
|
|
|
+ String type = "0";
|
|
|
+ //wx
|
|
|
+ String evt = "";
|
|
|
+ int count = 0;
|
|
|
+ int a = 0;
|
|
|
+ int b = 0;
|
|
|
+ //key名称
|
|
|
+ String info = "";
|
|
|
+ Map<String, String> map = new HashMap<>();
|
|
|
+ map.put("status", "0");
|
|
|
+ map.put("frame", "0");
|
|
|
+ map.put("smog", "0");
|
|
|
+ map.put("battery", "0");
|
|
|
+ map.put("TData", "0");
|
|
|
+ for (int i = 0; i <= str.length(); i++) {
|
|
|
+ for (int j = 1; j <= 3; j++) {
|
|
|
+ if (j == 1) {
|
|
|
+ String s = str.substring(a, a + 2);
|
|
|
+ if (s.equals("17")) {
|
|
|
+ info = "17";
|
|
|
+ } else if (s.equals("14")) {
|
|
|
+ info = "14";
|
|
|
+ } else if (s.equals("0B")) {
|
|
|
+ info = "0B";
|
|
|
+ } else if (s.equals("24")) {
|
|
|
+ info = "24";
|
|
|
+ } else if (s.equals("01")) {
|
|
|
+ info = "01";
|
|
|
+ } else if (s.equals("02")) {
|
|
|
+ info = "02";
|
|
|
+ } else if (s.equals("19")) {
|
|
|
+ info = "19";
|
|
|
+ } else {
|
|
|
+ info = "未知状态";
|
|
|
+ }
|
|
|
+ str = str.substring(a + 2, str.length());
|
|
|
+ } else if (j == 2) {
|
|
|
+ if (str.length() < (a + 2)) {
|
|
|
+ System.out.println("???????????????" + "未知的类型");
|
|
|
+ } else {
|
|
|
+ String s = str.substring(a, a + 2);
|
|
|
+ if (s.equals("01")) {
|
|
|
+ b = 2;
|
|
|
+ } else {
|
|
|
+ b = 4;
|
|
|
+ }
|
|
|
+ str = str.substring(a + 2, str.length());
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if (str.length() < (a + b)) {
|
|
|
+ System.out.println("???????????????" + "未知的类型");
|
|
|
+ } else {
|
|
|
+
|
|
|
+ String s = str.substring(a, a + b);
|
|
|
+ if (info.equals("17")) {
|
|
|
+ //失败帧
|
|
|
+ String s1 = String.valueOf(Integer.parseInt(s, 16));
|
|
|
+ map.put("frame", s1);
|
|
|
+ } else if (info.equals("14")) {
|
|
|
+ //烟雾浓度
|
|
|
+ String s1 = String.valueOf(Integer.parseInt(s, 16));
|
|
|
+ map.put("smog", s1);
|
|
|
+ } else if (info.equals("0B")) {
|
|
|
+ //温度值
|
|
|
+ String s1 = String.valueOf(Integer.parseInt(s, 16));
|
|
|
+ map.put("TData", s1);
|
|
|
+ } else if (info.equals("19")) {
|
|
|
+ type = "1";
|
|
|
+ //设备自检
|
|
|
+ String s1 = String.valueOf(Integer.parseInt(s, 16));
|
|
|
+ map.put("status", "1");
|
|
|
+ evt = "y12";
|
|
|
+ } else if (info.equals("24")) {
|
|
|
+ //设备电量
|
|
|
+ String s1 = String.valueOf(Integer.parseInt(s, 16));
|
|
|
+ map.put("battery", s1);
|
|
|
+ } else if (info.equals("01")) {
|
|
|
+ type = "1";
|
|
|
+ //火灾报警
|
|
|
+ if (s.equals("01")) {
|
|
|
+ //火灾
|
|
|
+ map.put("status", "2");
|
|
|
+ evt = "y07";
|
|
|
+ } else if (s.equals("02")) {
|
|
|
+ //温度
|
|
|
+ map.put("status", "3");
|
|
|
+ evt = "y08";
|
|
|
+ }
|
|
|
+ } else if (info.equals("02")) {
|
|
|
+ type = "1";
|
|
|
+ //告警
|
|
|
+ if (s.equals("02")) {
|
|
|
+ //电量低
|
|
|
+ map.put("status", "4");
|
|
|
+ evt = "y09";
|
|
|
+ } else if (s.equals("03")) {
|
|
|
+ //防拆报警
|
|
|
+ map.put("status", "5");
|
|
|
+ evt = "y10";
|
|
|
+ } else if (s.equals("07")) {
|
|
|
+ //发射电路故障
|
|
|
+ map.put("status", "6");
|
|
|
+ evt = "y11";
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ System.out.println("!!!!!未知参数");
|
|
|
+ }
|
|
|
+ str = str.substring(a + b, str.length());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ Date date = new Date();
|
|
|
+ Timestamp timeStamep = new Timestamp(date.getTime());
|
|
|
+//保存设备表
|
|
|
+ String sql = "INSERT INTO `" + tab + "` VALUES (null," + loraWanId + ",'" + devid + "','" + num + "','" + version + "','" + map.get("frame") + "','" + map.get("smog") + "','" + map.get("battery") + "','" + map.get("TData") + "','" + time+ "','" + map.get("status") + "',null)";
|
|
|
+ SQLQuery qry = getSession().createSQLQuery(sql);
|
|
|
+ int i = qry.executeUpdate();
|
|
|
+
|
|
|
+
|
|
|
+//保存告警表
|
|
|
+ if ("1".equals(type)) {
|
|
|
+ LOGGER.info("********************************告警数据上传告警表sp_yj2017*" );
|
|
|
+ String sql1 = "INSERT INTO `sp_yj2017` VALUES (null, 'jindun fume','" + devid + "', '" + timeStamep + "', '', '', '00', '" + map.get("status") + "', '" + map.get("smog") + "', '', '" + map.get("battery") + "', '" + map.get("TData") + "', '', '0000-00-00 00:00:00', '', '', '', '', '', 0, '');";
|
|
|
+ SQLQuery qry1 = getSession().createSQLQuery(sql1);
|
|
|
+ int i1 = qry1.executeUpdate();
|
|
|
+ System.out.println("保存告警表");
|
|
|
+ sendWXService.YGsendWX(devid, loraWanId, timeStamep.toString(), evt);
|
|
|
+ //this.YGsendWX(devid, loraWanId, timeStamep.toString(), evt);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void YGsendWX(String devid, String loraWanId, String timeStamep, String evt) {
|
|
|
+ LOGGER.info("********************************告警数据上传微信*" );
|
|
|
+ List<NameValuePair> nameValuePairsList = new ArrayList<>();
|
|
|
+ StringBuffer sb = new StringBuffer();
|
|
|
+ String sql="SELECT company FROM sp_owner where owner_code='"+devid+"'";
|
|
|
+ SQLQuery query = getSession().createSQLQuery(sql);
|
|
|
+ List list = query.list();
|
|
|
+ Object o = list.get(0);
|
|
|
+ for (Object b : list) {
|
|
|
+ System.out.println("b = " + b.toString());
|
|
|
+ }
|
|
|
+ String s = o.toString();
|
|
|
+ String sql1="SELECT phone from sp_owner_phone where data2 like'%6%' and owner_code='"+s+"'";
|
|
|
+ Query query1 = getSession().createSQLQuery(sql1);
|
|
|
+ List list1 = query1.list();
|
|
|
+// for (Object b : list1) {
|
|
|
+// System.out.println("b111 = " + b.toString());
|
|
|
+// }
|
|
|
+ if (list1 != null && list1.size()>0){
|
|
|
+ for (Object sp : list1) {
|
|
|
+ sb.append(sp);
|
|
|
+ sb.append(",");
|
|
|
+ // System.out.println("sp = " + sp);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
+ String time = df.format(new Date());
|
|
|
+ BasicNameValuePair basicNameValuePair1 = new BasicNameValuePair("IMEI",devid);
|
|
|
+ // BasicNameValuePair basicNameValuePair2 = new BasicNameValuePair("phone",sb.toString());
|
|
|
+ BasicNameValuePair basicNameValuePair2 = new BasicNameValuePair("phone",sb.toString());
|
|
|
+ BasicNameValuePair basicNameValuePair3 = new BasicNameValuePair("insert_id",loraWanId);
|
|
|
+ BasicNameValuePair basicNameValuePair4 = new BasicNameValuePair("time",time);
|
|
|
+ BasicNameValuePair basicNameValuePair = new BasicNameValuePair("evt",evt);
|
|
|
+ nameValuePairsList.add(basicNameValuePair);
|
|
|
+ nameValuePairsList.add(basicNameValuePair1);
|
|
|
+ nameValuePairsList.add(basicNameValuePair2);
|
|
|
+ nameValuePairsList.add(basicNameValuePair3);
|
|
|
+ nameValuePairsList.add(basicNameValuePair4);
|
|
|
+
|
|
|
+ String url ="http://iot.usky.cn/jdxf/wxapp2.php/Home/Waterwarn/bj";
|
|
|
+ HttpClientUtilWX.doFromPost(url,null,nameValuePairsList);
|
|
|
+ System.out.println("发送微信");
|
|
|
+ LOGGER.info("********************************告警数据上传微信完成*" );
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public int saveLoradata(String devid, String s) {
|
|
|
+ Yt_Lora_Data lr = new Yt_Lora_Data();
|
|
|
+ lr.setDevice_code(devid);
|
|
|
+ lr.setService(s);
|
|
|
+ int i = (int)getSession().save(lr);
|
|
|
+ System.out.println("i = " + i);
|
|
|
+ return i;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public String getStr(HttpServletRequest request)throws Exception {
|
|
|
+ //解析数据
|
|
|
+ StringBuffer str = new StringBuffer();
|
|
|
+
|
|
|
+ BufferedInputStream in = new BufferedInputStream(request.getInputStream());
|
|
|
+ int i;
|
|
|
+ char c;
|
|
|
+ while ((i = in.read()) != -1) {
|
|
|
+ c = (char) i;
|
|
|
+ str.append(c);
|
|
|
+ }
|
|
|
+
|
|
|
+ //数据体
|
|
|
+ String s = str.toString();
|
|
|
+ return s;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @return void
|
|
|
+ * @Author zhangzilong
|
|
|
+ * @Description //查询是否存在设备表 不在则为新注册 需生成唯一标识保存sp_owner
|
|
|
+ * @Date 10:09 2020/3/12
|
|
|
+ * @Param * @param map
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public String query(HashMap<String, String> map) {
|
|
|
+//根据类型和设备id判断是否为新设备
|
|
|
+ String sql = "SELECT owner_code FROM sp_lora_device where dwtype ='" + map.get("dwtype") + "' and deviceid='" + map.get("deviceid") + "' and company=" + map.get("company") + "";
|
|
|
+ SQLQuery qry = this.getSession().createSQLQuery(sql);
|
|
|
+ List list = qry.list();
|
|
|
+ //新设备要注册
|
|
|
+ if (CollectionUtils.isEmpty(list)) {
|
|
|
+ //新设备 注册
|
|
|
+ String s = this.saveLoraDev(map);
|
|
|
+
|
|
|
+ return s;
|
|
|
+ } else {
|
|
|
+ String o = String.valueOf(list.get(0));
|
|
|
+ //已注册设备不管 返回唯一码
|
|
|
+ return o;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @return void
|
|
|
+ * @Author zhangzilong
|
|
|
+ * @Description 新注册
|
|
|
+ * @Date 10:50 2020/3/12
|
|
|
+ * @Param * @param map
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public String saveLoraDev(HashMap<String, String> map) {
|
|
|
+ //根据类型和单位 查询num
|
|
|
+ String num;
|
|
|
+ String sql = "SELECT max(number) FROM sp_lora_device where dwtype ='" + map.get("dwtype") + "' and company='" + map.get("company") + "'";
|
|
|
+ SQLQuery qry = this.getSession().createSQLQuery(sql);
|
|
|
+ List list = qry.list();
|
|
|
+ //此单位此设备类型第一个
|
|
|
+ Object o = list.get(0);
|
|
|
+ if (o == null) {
|
|
|
+ num = "10000001";
|
|
|
+ } else {
|
|
|
+
|
|
|
+
|
|
|
+ int i = Integer.parseInt(o.toString());
|
|
|
+
|
|
|
+ num = String.valueOf(i + 1);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ String company = map.get("company");
|
|
|
+ String dwtype = map.get("dwtype");
|
|
|
+ // String deviceid = map.get("deviceid");
|
|
|
+ Sp_Lora_Device device = new Sp_Lora_Device();
|
|
|
+ device.setCompany(company);
|
|
|
+ device.setDwtype(dwtype);
|
|
|
+ device.setDeviceid(map.get("deviceid"));
|
|
|
+ SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
+ device.setCreat_time(df.format(new Date()));
|
|
|
+ device.setNumber(num);
|
|
|
+ String code = "yt" + dwtype + company+"_" + num;
|
|
|
+ device.setOwner_code(code);
|
|
|
+ getSession().save(device);
|
|
|
+
|
|
|
+
|
|
|
+ //存入sp_owner
|
|
|
+
|
|
|
+
|
|
|
+ return code;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @param num
|
|
|
+ * @param tab
|
|
|
+ * @param loraWanId
|
|
|
+ * @param devid
|
|
|
+ * @return void
|
|
|
+ * @Author zhangzilong
|
|
|
+ * @Description //解析液位和压力
|
|
|
+ * @Date 13:14 2020/3/13
|
|
|
+ * @Param * @param payload
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public void save02and03(String payload, String num, String tab, String loraWanId, String devid,String time) {
|
|
|
+
|
|
|
+ Map<String, String> map = new HashMap<>();
|
|
|
+ Map<String, String> map1 = new HashMap<>();
|
|
|
+// map.put("Sample_Value", s2);
|
|
|
+// map.put("Value_Unit", "M");
|
|
|
+// map1.put("Value_Status", "LL4");
|
|
|
+// map.put("Battery_Level", s);
|
|
|
+// map.put("Device_Status", "0");
|
|
|
+// map.put("Update_Time", "0");
|
|
|
+// map.put("Send_Freq", "未知时间");
|
|
|
+// map.put("Device_Type", "0");
|
|
|
+// map.put("length", s1);
|
|
|
+ //告警状态
|
|
|
+ String status="0";
|
|
|
+
|
|
|
+ //长度
|
|
|
+ String length = payload.substring(0, 2);
|
|
|
+ ;
|
|
|
+ String s1 = String.valueOf(Integer.parseInt(length, 16));
|
|
|
+ map.put("length", s1);
|
|
|
+ //设备类型
|
|
|
+ String Device_Type = payload.substring(2, 4);
|
|
|
+ //发送频率
|
|
|
+ String Send_Freq = payload.substring(4, 6);
|
|
|
+ //时间更新
|
|
|
+ String Update_Time = payload.substring(6, 8);
|
|
|
+ //设备状态
|
|
|
+ String Device_Status = payload.substring(8, 10);
|
|
|
+ //电池电量
|
|
|
+ String Battery_Level = payload.substring(10, 12);
|
|
|
+ //电池状态
|
|
|
+ String Battery_Status = payload.substring(12, 14);
|
|
|
+ //数值状态
|
|
|
+ String Value_Status = payload.substring(14, 15);
|
|
|
+ //数值单位
|
|
|
+ String Value_Unit = payload.substring(15, 16);
|
|
|
+ //小数位数
|
|
|
+ String Decimal_Digits = payload.substring(16, 17);
|
|
|
+ //采样数值
|
|
|
+ String Sample_Value = payload.substring(17, payload.length());
|
|
|
+
|
|
|
+ //设备类型
|
|
|
+ if ("01".equals(Device_Type)) {
|
|
|
+ map.put("Device_Type", "1");
|
|
|
+ } else if ("02".equals(Device_Type)) {
|
|
|
+ map.put("Device_Type", "2");
|
|
|
+ } else if ("03".equals(Device_Type)) {
|
|
|
+ map.put("Device_Type", "3");
|
|
|
+ } else {
|
|
|
+ map.put("Device_Type", "0");
|
|
|
+ }
|
|
|
+
|
|
|
+ //发送频率保存
|
|
|
+ if (Send_Freq.equals("0A")) {
|
|
|
+ map.put("Send_Freq", "10min");
|
|
|
+ } else if (Send_Freq.equals("14")) {
|
|
|
+ map.put("Send_Freq", "20min");
|
|
|
+ } else if (Send_Freq.equals("1E")) {
|
|
|
+ map.put("Send_Freq", "30min");
|
|
|
+ } else if (Send_Freq.equals("3C")) {
|
|
|
+ map.put("Send_Freq", "1h");
|
|
|
+ } else if (Send_Freq.equals("78")) {
|
|
|
+ map.put("Send_Freq", "2h");
|
|
|
+ } else if (Send_Freq.equals("B4")) {
|
|
|
+ map.put("Send_Freq", "3h");
|
|
|
+ } else {
|
|
|
+ map.put("Send_Freq", "未知时间");
|
|
|
+ }
|
|
|
+
|
|
|
+ //时间更新Update_Time 暂未使用
|
|
|
+ if ("01".equals(Update_Time)) {
|
|
|
+ map.put("Update_Time", "1");
|
|
|
+ } else {
|
|
|
+ map.put("Update_Time", "0");
|
|
|
+ }
|
|
|
+
|
|
|
+ //设备状态保存
|
|
|
+ if (Device_Status.equals("01")) {
|
|
|
+ map.put("Device_Status", "1");
|
|
|
+ } else if (Device_Status.equals("02")) {
|
|
|
+ map.put("Device_Status", "2");
|
|
|
+ status="1";
|
|
|
+ } else if (Device_Status.equals("03")) {
|
|
|
+ map.put("Device_Status", "3");
|
|
|
+ status="1";
|
|
|
+ } else {
|
|
|
+ map.put("Device_Status", "0");
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ //Battery_Level电池状态保存 进制换算
|
|
|
+ String s = String.valueOf(Integer.parseInt(Battery_Level, 16));
|
|
|
+ map.put("Battery_Level", s);
|
|
|
+
|
|
|
+ //电池状态暂未使用Battery_Status
|
|
|
+ if (Battery_Status.equals("01")) {
|
|
|
+ map.put("Battery_Status", "1");
|
|
|
+ status="1";
|
|
|
+ } else if (Battery_Status.equals("02")) {
|
|
|
+ map.put("Battery_Status", "2");
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ //数值状态保存
|
|
|
+ if (Value_Status.equals("0")) {
|
|
|
+ map.put("Value_Status", "0");
|
|
|
+
|
|
|
+ if ("02".equals(Device_Type)) {
|
|
|
+ map1.put("Value_Status", "WP0");
|
|
|
+ } else if ("03".equals(Device_Type)) {
|
|
|
+ map1.put("Value_Status", "LL0");
|
|
|
+ }
|
|
|
+
|
|
|
+ } else if (Value_Status.equals("1")) {
|
|
|
+ status="1";
|
|
|
+ map.put("Value_Status", "1");
|
|
|
+ //压力
|
|
|
+ if ("02".equals(Device_Type)) {
|
|
|
+ map1.put("Value_Status", "WP1");
|
|
|
+ } else if ("03".equals(Device_Type)) {
|
|
|
+ map1.put("Value_Status", "LL1");
|
|
|
+ }
|
|
|
+ } else if (Value_Status.equals("2")) {
|
|
|
+ status="1";
|
|
|
+ map.put("Value_Status", "2");
|
|
|
+
|
|
|
+ if ("02".equals(Device_Type)) {
|
|
|
+ map1.put("Value_Status", "WP2");
|
|
|
+ } else if ("03".equals(Device_Type)) {
|
|
|
+ map1.put("Value_Status", "LL2");
|
|
|
+ }
|
|
|
+ } else if (Value_Status.equals("3")) {
|
|
|
+ status="1";
|
|
|
+ map.put("Value_Status", "3");
|
|
|
+
|
|
|
+ if ("02".equals(Device_Type)) {
|
|
|
+ map1.put("Value_Status", "WP3");
|
|
|
+ } else if ("03".equals(Device_Type)) {
|
|
|
+ map1.put("Value_Status", "LL3");
|
|
|
+ }
|
|
|
+ } else if (Value_Status.equals("4")) {
|
|
|
+ status="1";
|
|
|
+ map.put("Value_Status", "4");
|
|
|
+
|
|
|
+ if ("02".equals(Device_Type)) {
|
|
|
+ map1.put("Value_Status", "WP4");
|
|
|
+ } else if ("03".equals(Device_Type)) {
|
|
|
+ map1.put("Value_Status", "LL4");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ //数值单位保存
|
|
|
+ if (Value_Unit.equals("1")) {
|
|
|
+ map.put("Value_Unit", "MPa");
|
|
|
+ } else if (Value_Unit.equals("2")) {
|
|
|
+ map.put("Value_Unit", "Bar");
|
|
|
+ } else if (Value_Unit.equals("3")) {
|
|
|
+ map.put("Value_Unit", "KPa");
|
|
|
+ } else if (Value_Unit.equals("4")) {
|
|
|
+ map.put("Value_Unit", "M");
|
|
|
+ }
|
|
|
+
|
|
|
+ //采样数值
|
|
|
+ BigDecimal maxlng1 = new BigDecimal(Sample_Value);
|
|
|
+
|
|
|
+ double minlat = maxlng1.doubleValue();
|
|
|
+ double a = 0;
|
|
|
+ //小数位数
|
|
|
+ if (Decimal_Digits.equals("1")) {
|
|
|
+ a = minlat / 10;
|
|
|
+ } else if (Decimal_Digits.equals("2")) {
|
|
|
+ a = minlat / 100;
|
|
|
+ } else if (Decimal_Digits.equals("3")) {
|
|
|
+ a = minlat / 1000;
|
|
|
+ } else if (Decimal_Digits.equals("4")) {
|
|
|
+ a = minlat / 10000;
|
|
|
+ }
|
|
|
+ //四舍五入保留三位保存数值
|
|
|
+ double result = new BigDecimal(a).setScale(3, BigDecimal.ROUND_HALF_UP).doubleValue();
|
|
|
+ //System.out.println("result="+result);
|
|
|
+ String s2 = String.valueOf(result);
|
|
|
+ map.put("Sample_Value", s2);
|
|
|
+
|
|
|
+//更新时间
|
|
|
+ Date date = new Date();
|
|
|
+ Timestamp timeStamep = new Timestamp(date.getTime());
|
|
|
+//保存
|
|
|
+ String sql = "INSERT INTO `" + tab + "` VALUES (null, '" + loraWanId + "', '" + devid + "','" + num + "', '" + map.get("length") + "', '" + map.get("Device_Type") + "', '" + map.get("Send_Freq") + "', '" + map.get("Update_Time") + "', '" + map.get("Device_Status") + "', '" + map.get("Battery_Level") + "', '" + map.get("Battery_Status") + "', '" + map.get("Value_Status") + "', '" + map.get("Value_Unit") + "', '" + time + "', '" + map.get("Sample_Value") + "', null);";
|
|
|
+ SQLQuery qry = getSession().createSQLQuery(sql);
|
|
|
+ int i = qry.executeUpdate();
|
|
|
+
|
|
|
+
|
|
|
+//保存到sp_sj2017
|
|
|
+ if ("1".equals(status)) {
|
|
|
+ LOGGER.info("********************************告警数据上传告警表sp_sj2017*" );
|
|
|
+ System.out.println("有告警信息");
|
|
|
+ String sql1 = "INSERT INTO `sp_sj2017` VALUES (null, 'tp_water_pressure','" + devid + "', '" + timeStamep + "', '', '', '', '" + map1.get("Value_Status") + "', '" + map.get("Battery_Level") + "', '', '" + map.get("Sample_Value") + "', '', '', '0000-00-00 00:00:00', '', '', '', '', '0', '', '');";
|
|
|
+ SQLQuery qry1 = getSession().createSQLQuery(sql1);
|
|
|
+ int i1 = qry1.executeUpdate();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+}
|