diff --git a/sgzb-api/sgzb-api-system/src/main/java/com/bonus/sgzb/base/api/domain/MaMachine.java b/sgzb-api/sgzb-api-system/src/main/java/com/bonus/sgzb/base/api/domain/MaMachine.java
index 9ec5ffc8..c922057a 100644
--- a/sgzb-api/sgzb-api-system/src/main/java/com/bonus/sgzb/base/api/domain/MaMachine.java
+++ b/sgzb-api/sgzb-api-system/src/main/java/com/bonus/sgzb/base/api/domain/MaMachine.java
@@ -226,4 +226,10 @@ public class MaMachine extends BaseEntity {
private String maTypeName;
+ @ApiModelProperty(value = "绑定IOT设备数量")
+ private Integer IotNum;
+
+ @ApiModelProperty(value = "Iot定位设备编号")
+ private String iotCode;
+
}
diff --git a/sgzb-common/sgzb-common-core/pom.xml b/sgzb-common/sgzb-common-core/pom.xml
index a9d7f429..36acdd3b 100644
--- a/sgzb-common/sgzb-common-core/pom.xml
+++ b/sgzb-common/sgzb-common-core/pom.xml
@@ -10,7 +10,7 @@
4.0.0
sgzb-common-core
-
+
sgzb-common-core核心模块
@@ -22,7 +22,7 @@
org.springframework.cloud
spring-cloud-starter-openfeign
-
+
org.springframework.cloud
@@ -63,6 +63,7 @@
com.fasterxml.jackson.core
jackson-databind
+ 2.13.5
@@ -113,11 +114,15 @@
swagger-annotations
-
+
org.projectlombok
lombok
+
+ org.apache.httpcomponents
+ httpclient
+
diff --git a/sgzb-common/sgzb-common-core/src/main/java/com/bonus/sgzb/common/core/constant/HttpStatus.java b/sgzb-common/sgzb-common-core/src/main/java/com/bonus/sgzb/common/core/constant/HttpStatus.java
index d8b2a125..4d047578 100644
--- a/sgzb-common/sgzb-common-core/src/main/java/com/bonus/sgzb/common/core/constant/HttpStatus.java
+++ b/sgzb-common/sgzb-common-core/src/main/java/com/bonus/sgzb/common/core/constant/HttpStatus.java
@@ -2,7 +2,7 @@ package com.bonus.sgzb.common.core.constant;
/**
* 返回状态码
- *
+ *
* @author ruoyi
*/
public class HttpStatus
@@ -91,4 +91,31 @@ public class HttpStatus
* 系统警告消息
*/
public static final int WARN = 601;
+
+ /**
+ *iot设备登录地址
+ */
+ public static final String LOGIN_URL = "http://gps51.com/webapi?action=login";
+
+ /**
+ *iot设备定位地址
+ */
+ public static final String LAST_POSITION_URL = "http://gps51.com/webapi?action=lastposition&token=";
+
+ /**
+ *iot查询行程地址
+ */
+ public static final String QUERY_TRIPS_URL = "http://gps51.com/webapi?action=querytrips&token=";
+
+ /**
+ *iot查询停留点地址
+ */
+ public static final String REPORT_PARK_DETAIL_BY_TIME_URL = "http://gps51.com/webapi?action=reportparkdetailbytime&token=";
+
+ /**
+ *iot报警地址
+ */
+ public static final String REPORT_ALARM_URL = "http://gps51.com/webapi?action=reportalarm&token=";
+
+
}
diff --git a/sgzb-common/sgzb-common-core/src/main/java/com/bonus/sgzb/common/core/constant/TokenConstants.java b/sgzb-common/sgzb-common-core/src/main/java/com/bonus/sgzb/common/core/constant/TokenConstants.java
index 534ebe30..ef6e675a 100644
--- a/sgzb-common/sgzb-common-core/src/main/java/com/bonus/sgzb/common/core/constant/TokenConstants.java
+++ b/sgzb-common/sgzb-common-core/src/main/java/com/bonus/sgzb/common/core/constant/TokenConstants.java
@@ -2,7 +2,7 @@ package com.bonus.sgzb.common.core.constant;
/**
* Token的Key常量
- *
+ *
* @author ruoyi
*/
public class TokenConstants
@@ -22,4 +22,10 @@ public class TokenConstants
*/
public final static String SECRET = "abcdefghijklmnopqrstuvwxyz";
+
+ /**
+ * IOT设备登录token有效期
+ */
+ public static final String TOKEN_LOCATION = "token_location";
+
}
diff --git a/sgzb-common/sgzb-common-core/src/main/java/com/bonus/sgzb/common/core/constant/UserConstants.java b/sgzb-common/sgzb-common-core/src/main/java/com/bonus/sgzb/common/core/constant/UserConstants.java
index 1efbd51d..d01a4df7 100644
--- a/sgzb-common/sgzb-common-core/src/main/java/com/bonus/sgzb/common/core/constant/UserConstants.java
+++ b/sgzb-common/sgzb-common-core/src/main/java/com/bonus/sgzb/common/core/constant/UserConstants.java
@@ -2,7 +2,7 @@ package com.bonus.sgzb.common.core.constant;
/**
* 用户常量信息
- *
+ *
* @author ruoyi
*/
public class UserConstants
@@ -92,4 +92,24 @@ public class UserConstants
* 手机1天限制
*/
public static final String MOBILE_PHONE_1D_LIMIT_DIR = "mobilePhoneDay:";
+
+ /**
+ *登录类型 :"USER","DEVICE"
+ */
+ public static final String IOT_TYPE = "USER";
+
+ /**
+ *登录来源 :"ANDROID","IPHONE","WEB","WEIXIN"
+ */
+ public static final String IOT_FROM = "WEB";
+
+ /**
+ *登录名
+ */
+ public static final String IOT_USERNAME = "omni-demo";
+
+ /**
+ *密码,采用md5加密
+ */
+ public static final String IOT_PASSWORD = "7d8609761efffc818e5ed11531ea2507";
}
diff --git a/sgzb-common/sgzb-common-core/src/main/java/com/bonus/sgzb/common/core/utils/StringHelper.java b/sgzb-common/sgzb-common-core/src/main/java/com/bonus/sgzb/common/core/utils/StringHelper.java
index 6ef72519..96c06858 100644
--- a/sgzb-common/sgzb-common-core/src/main/java/com/bonus/sgzb/common/core/utils/StringHelper.java
+++ b/sgzb-common/sgzb-common-core/src/main/java/com/bonus/sgzb/common/core/utils/StringHelper.java
@@ -3,6 +3,7 @@ package com.bonus.sgzb.common.core.utils;
import org.apache.commons.lang3.StringUtils;
import java.io.*;
+import java.math.BigDecimal;
import java.sql.Blob;
import java.sql.SQLException;
import java.util.List;
@@ -31,7 +32,7 @@ public class StringHelper {
/**
* 集合转数组
- *
+ *
* @param list
* @param separator
* @return
@@ -97,7 +98,7 @@ public class StringHelper {
/**
* blob中文乱码转码
- *
+ *
* @param content
* @return
*/
@@ -113,7 +114,7 @@ public class StringHelper {
/**
* unicode转字符串
- *
+ *
* @param unicode
* @return
*/
@@ -161,7 +162,7 @@ public class StringHelper {
/**
* unicode 转字符串
- *
+ *
* @param unicode 全为 Unicode 的字符串
* @return
*/
@@ -226,4 +227,23 @@ public class StringHelper {
return !isEmpty(str);
}
+ /**
+ * 类型转换
+ * @param res
+ * @return
+ */
+ public static Long conversionLong(String res) {
+ if (res == null) {
+ return null;
+ }
+ return Long.valueOf(res);
+ }
+
+ public static BigDecimal conversionBigDecimal(String res) {
+ if (res == null) {
+ return null;
+ }
+ return new BigDecimal(res);
+ }
+
}
diff --git a/sgzb-modules/sgzb-base/src/main/java/com/bonus/sgzb/base/service/impl/MaMachineServiceImpl.java b/sgzb-modules/sgzb-base/src/main/java/com/bonus/sgzb/base/service/impl/MaMachineServiceImpl.java
index 55f5f2a5..010d8dbe 100644
--- a/sgzb-modules/sgzb-base/src/main/java/com/bonus/sgzb/base/service/impl/MaMachineServiceImpl.java
+++ b/sgzb-modules/sgzb-base/src/main/java/com/bonus/sgzb/base/service/impl/MaMachineServiceImpl.java
@@ -6,10 +6,8 @@ import com.bonus.sgzb.base.api.domain.MaLabelBind;
import com.bonus.sgzb.base.api.domain.SltAgreementApply;
import com.bonus.sgzb.base.domain.BmProjectLot;
import com.bonus.sgzb.base.domain.MaPropSet;
-import com.bonus.sgzb.base.mapper.MaLabelBindMapper;
-import com.bonus.sgzb.base.mapper.MaMachineMapper;
-import com.bonus.sgzb.base.mapper.MaPropInfoMapper;
-import com.bonus.sgzb.base.mapper.MaTypeMapper;
+import com.bonus.sgzb.base.domain.vo.IotRecordVo;
+import com.bonus.sgzb.base.mapper.*;
import com.bonus.sgzb.base.service.MaMachineService;
import com.bonus.sgzb.common.core.constant.Constants;
import com.bonus.sgzb.common.core.exception.ServiceException;
@@ -18,6 +16,7 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
+import java.util.ArrayList;
import java.util.Date;
import java.util.List;
@@ -36,6 +35,8 @@ public class MaMachineServiceImpl implements MaMachineService {
@Resource
private MaPropInfoMapper maPropInfoMapper;
+ @Resource
+ private IotMachineMapper iotMachineMapper;
@Override
public List getMaMachine(MaMachine maMachine) {
@@ -45,7 +46,28 @@ public class MaMachineServiceImpl implements MaMachineService {
if (maMachine.getMaType() != null && ("2").equals(maMachine.getMaType())) {
maMachine.setMaTypeName(Constants.TS);
}
- return maMachineMapper.getMaMachine(maMachine);
+
+ List listMaMachine = new ArrayList<>();
+ listMaMachine =maMachineMapper.getMaMachine(maMachine);
+ if (listMaMachine.size() > 0){
+ for (MaMachine ma : listMaMachine) {
+ //根据机具编码查询iot设备
+ List iotRecordVoList = iotMachineMapper.selectList(ma.getMaCode());
+ ma.setIotNum(iotRecordVoList.size());
+ //判断是否绑定了iot设备
+ if (iotRecordVoList.size()>0){
+ for (int i = 0; i < iotRecordVoList.size(); i++) {
+ //保存定位iot设备编码
+ if ("125".equals(iotRecordVoList.get(i).getIotType())){
+ ma.setIotCode(iotRecordVoList.get(i).getIotCode());
+ }
+ }
+ }
+ }
+ }
+
+
+ return listMaMachine;
}
/**
diff --git a/sgzb-modules/sgzb-material/pom.xml b/sgzb-modules/sgzb-material/pom.xml
index 1298bb91..55b39d09 100644
--- a/sgzb-modules/sgzb-material/pom.xml
+++ b/sgzb-modules/sgzb-material/pom.xml
@@ -137,4 +137,4 @@
-
\ No newline at end of file
+
diff --git a/sgzb-modules/sgzb-material/src/main/java/com/bonus/sgzb/material/config/ExceptionEnum.java b/sgzb-modules/sgzb-material/src/main/java/com/bonus/sgzb/material/config/ExceptionEnum.java
index 8f844a74..b7443d57 100644
--- a/sgzb-modules/sgzb-material/src/main/java/com/bonus/sgzb/material/config/ExceptionEnum.java
+++ b/sgzb-modules/sgzb-material/src/main/java/com/bonus/sgzb/material/config/ExceptionEnum.java
@@ -20,8 +20,10 @@ public enum ExceptionEnum {
DELETE_TO_DATABASE(500, "删除失败,请联系管理员!!!"),
BIND_TO_DATABASE(500, "绑定失败,请联系管理员!!!"),
UN_BIND_TO_DATABASE(500, "解绑失败,请联系管理员!!!"),
- UPDATE_TO_DATABASE(500, "修改失败,请联系管理员!!!");
+ UPDATE_TO_DATABASE(500, "修改失败,请联系管理员!!!"),
+ RETURN_DATA_IS_EMPTY(501, "返回数据为空!!"),
+ IOT_ENCODING_ERROR(502, "输入的IOT编码有误,请输入正确的编码!!!");
private Integer code;
private String msg;
diff --git a/sgzb-modules/sgzb-material/src/main/java/com/bonus/sgzb/material/controller/IotMachineController.java b/sgzb-modules/sgzb-material/src/main/java/com/bonus/sgzb/material/controller/IotMachineController.java
index 53955838..992fa8f4 100644
--- a/sgzb-modules/sgzb-material/src/main/java/com/bonus/sgzb/material/controller/IotMachineController.java
+++ b/sgzb-modules/sgzb-material/src/main/java/com/bonus/sgzb/material/controller/IotMachineController.java
@@ -4,6 +4,7 @@ import com.bonus.sgzb.common.core.web.controller.BaseController;
import com.bonus.sgzb.common.core.web.domain.AjaxResult;
import com.bonus.sgzb.common.core.web.page.TableDataInfo;
import com.bonus.sgzb.material.domain.IotDto;
+import com.bonus.sgzb.material.domain.IotLocationVo;
import com.bonus.sgzb.material.domain.IotRecordVo;
import com.bonus.sgzb.material.domain.IotVo;
import com.bonus.sgzb.material.service.IotMachineService;
@@ -17,8 +18,8 @@ import javax.annotation.Resource;
import java.util.List;
/**
- * @Author
- * @create 2024/8/5
+ * @Author ma_sh
+ * @create 2024/7/4 16:23
* iot设备管理控制层
*/
@Api(tags = " iot设备管理控制层")
@@ -82,6 +83,18 @@ public class IotMachineController extends BaseController {
return iotMachineService.bind(iotDto);
}
+ /**
+ * 绑定设备APP
+ * @param iotDto
+ * @return
+ */
+ @ApiOperation("App绑定设备")
+ @PostMapping("/bindApp")
+ public AjaxResult bindApp(@Validated @RequestBody IotDto iotDto) {
+ log.info("绑定设备传参:{}", iotDto);
+ return iotMachineService.bindApp(iotDto);
+ }
+
/**
* 解绑设备
* @param iotDto
@@ -146,4 +159,32 @@ public class IotMachineController extends BaseController {
return AjaxResult.success(list);
}
+
+ @ApiOperation("获取定位")
+ @PostMapping("/getLocation")
+ public AjaxResult getLocation(@Validated @RequestBody IotDto iotDto) {
+ log.info("获取定位接口:{}", iotDto);
+ return iotMachineService.getLocation(iotDto);
+ }
+
+ @ApiOperation("查询行程")
+ @PostMapping("/searchItinerary")
+ public AjaxResult searchItinerary(@Validated @RequestBody IotLocationVo iotLocationVo) {
+ log.info("查询行程接口:{}", iotLocationVo);
+ return iotMachineService.searchItinerary(iotLocationVo);
+ }
+
+ @ApiOperation("查询停留点")
+ @PostMapping("/reportParkDetailByTime")
+ public AjaxResult reportParkDetailByTime(@Validated @RequestBody IotLocationVo iotLocationVo) {
+ log.info("查询停留点接口:{}", iotLocationVo);
+ return iotMachineService.reportParkDetailByTime(iotLocationVo);
+ }
+
+ @ApiOperation("报警记录")
+ @PostMapping("/reportAlarm")
+ public AjaxResult reportAlarm(@Validated @RequestBody IotLocationVo iotLocationVo) {
+ log.info("报警记录接口:{}", iotLocationVo);
+ return iotMachineService.reportAlarm(iotLocationVo);
+ }
}
diff --git a/sgzb-modules/sgzb-material/src/main/java/com/bonus/sgzb/material/service/IotMachineService.java b/sgzb-modules/sgzb-material/src/main/java/com/bonus/sgzb/material/service/IotMachineService.java
index c6da37c9..6a4aad51 100644
--- a/sgzb-modules/sgzb-material/src/main/java/com/bonus/sgzb/material/service/IotMachineService.java
+++ b/sgzb-modules/sgzb-material/src/main/java/com/bonus/sgzb/material/service/IotMachineService.java
@@ -2,6 +2,7 @@ package com.bonus.sgzb.material.service;
import com.bonus.sgzb.common.core.web.domain.AjaxResult;
import com.bonus.sgzb.material.domain.IotDto;
+import com.bonus.sgzb.material.domain.IotLocationVo;
import com.bonus.sgzb.material.domain.IotRecordVo;
import com.bonus.sgzb.material.domain.IotVo;
@@ -76,4 +77,39 @@ public interface IotMachineService {
* @return
*/
List getRecordList(IotDto iotDto);
+
+ /**
+ * 获取设备定位
+ * @param iotDto
+ * @return
+ */
+ AjaxResult getLocation(IotDto iotDto);
+
+ /**
+ * 查询行程
+ * @param iotLocationVo
+ * @return
+ */
+ AjaxResult searchItinerary(IotLocationVo iotLocationVo);
+
+ /**
+ * 查询停留点
+ * @param iotLocationVo
+ * @return
+ */
+ AjaxResult reportParkDetailByTime(IotLocationVo iotLocationVo);
+
+ /**
+ * App绑定设备
+ * @param iotDto
+ * @return
+ */
+ AjaxResult bindApp(IotDto iotDto);
+
+ /**
+ * 报警记录
+ * @param iotLocationVo
+ * @return
+ */
+ AjaxResult reportAlarm(IotLocationVo iotLocationVo);
}
diff --git a/sgzb-modules/sgzb-material/src/main/java/com/bonus/sgzb/material/service/impl/IotMachineServiceImpl.java b/sgzb-modules/sgzb-material/src/main/java/com/bonus/sgzb/material/service/impl/IotMachineServiceImpl.java
index 3e739fed..ced481ba 100644
--- a/sgzb-modules/sgzb-material/src/main/java/com/bonus/sgzb/material/service/impl/IotMachineServiceImpl.java
+++ b/sgzb-modules/sgzb-material/src/main/java/com/bonus/sgzb/material/service/impl/IotMachineServiceImpl.java
@@ -1,6 +1,14 @@
package com.bonus.sgzb.material.service.impl;
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson2.JSONObject;
+import com.bonus.sgzb.common.core.constant.HttpStatus;
+import com.bonus.sgzb.common.core.constant.TokenConstants;
+import com.bonus.sgzb.common.core.utils.HttpHelper;
+import com.bonus.sgzb.common.core.utils.StringHelper;
import com.bonus.sgzb.common.core.web.domain.AjaxResult;
+import com.bonus.sgzb.common.redis.service.RedisService;
import com.bonus.sgzb.common.security.utils.SecurityUtils;
import com.bonus.sgzb.material.config.ExceptionEnum;
import com.bonus.sgzb.material.config.FieldGenerator;
@@ -13,7 +21,11 @@ import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;
import javax.annotation.Resource;
+import java.util.ArrayList;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
+import java.util.concurrent.TimeUnit;
/**
* iot设备管理实现层
@@ -26,6 +38,9 @@ public class IotMachineServiceImpl implements IotMachineService {
@Resource
private IotMachineMapper iotMachineMapper;
+ @Resource
+ private RedisService redisService;
+
/**
* 添加设备-保存
*
@@ -265,4 +280,265 @@ public class IotMachineServiceImpl implements IotMachineService {
return iotRecordList;
}
+ /**
+ * 获取定位
+ * @param iotDto
+ * @return
+ */
+ @Override
+ public AjaxResult getLocation(IotDto iotDto) {
+ log.info("getLocation:{}", iotDto);
+ if (iotDto == null || iotDto.getIotId() == null) {
+ throw new RuntimeException(ExceptionEnum.PARAM_NULL.getMsg());
+ }
+ List list=new ArrayList<>();
+ Map map=new HashMap<>();
+ //从redis中获取token
+ String redisCode = redisService.getCacheObject(TokenConstants.TOKEN_LOCATION);
+ //如果token为空,先去调登录接口,获取token
+ if (redisCode == null){
+ redisCode = HttpHelper.getIotToken();
+ redisService.setCacheObject(TokenConstants.TOKEN_LOCATION,redisCode,23L, TimeUnit.HOURS);
+ }
+ map.clear();
+ list.add(iotDto.getIotId().toString());
+ map.put("deviceids",list);
+ String param = JSON.toJSONString(map);
+ String res = HttpHelper.doPost(HttpStatus.LAST_POSITION_URL+redisCode,param);
+ //对返回的结果进行解析
+ IotLocationVo iotLocationVo = resultDataHandler(res);
+ log.info("resultDataHandler:{}", iotLocationVo);
+ return AjaxResult.success(iotLocationVo);
+ }
+
+ /**
+ * 查询行程
+ * @param iotLocationVo
+ * @return
+ */
+ @Override
+ public AjaxResult searchItinerary(IotLocationVo iotLocationVo) {
+ log.info("searchItinerary:{}", iotLocationVo);
+ if (iotLocationVo == null || iotLocationVo.getBeginTime() == null || iotLocationVo.getEndTime() == null) {
+ throw new RuntimeException(ExceptionEnum.PARAM_NULL.getMsg());
+ }
+ Map map=new HashMap<>();
+ //从redis中获取token
+ String redisCode = redisService.getCacheObject(TokenConstants.TOKEN_LOCATION);
+ //如果token为空,先去调登录接口,获取token
+ if (redisCode == null){
+ redisCode = HttpHelper.getIotToken();
+ redisService.setCacheObject(TokenConstants.TOKEN_LOCATION,redisCode,23L, TimeUnit.HOURS);
+ }
+ map.clear();
+ map.put("deviceid",iotLocationVo.getIotId());
+ map.put("begintime",iotLocationVo.getBeginTime());
+ map.put("endtime",iotLocationVo.getEndTime());
+ String param = JSON.toJSONString(map);
+ String res = HttpHelper.doPost(HttpStatus.QUERY_TRIPS_URL+redisCode,param);
+ return AjaxResult.success(res);
+ }
+
+ /**
+ * 查询停留点
+ * @param iotLocationVo
+ * @return
+ */
+ @Override
+ public AjaxResult reportParkDetailByTime(IotLocationVo iotLocationVo) {
+
+ log.info("reportParkDetailByTime:{}", iotLocationVo);
+ if (iotLocationVo == null || iotLocationVo.getBeginTime() == null || iotLocationVo.getEndTime() == null) {
+ throw new RuntimeException(ExceptionEnum.PARAM_NULL.getMsg());
+ }
+ Map map=new HashMap<>();
+ //从redis中获取token
+ String redisCode = redisService.getCacheObject(TokenConstants.TOKEN_LOCATION);
+ //如果token为空,先去调登录接口,获取token
+ if (redisCode == null){
+ redisCode = HttpHelper.getIotToken();
+ redisService.setCacheObject(TokenConstants.TOKEN_LOCATION,redisCode,23L, TimeUnit.HOURS);
+ }
+ map.clear();
+ map.put("deviceid",iotLocationVo.getIotId());
+ map.put("begintime",iotLocationVo.getBeginTime());
+ map.put("endtime",iotLocationVo.getEndTime());
+ String param = JSON.toJSONString(map);
+ String res = HttpHelper.doPost(HttpStatus.REPORT_PARK_DETAIL_BY_TIME_URL+redisCode,param);
+ //对返回的结果进行解析
+ List iotLocationVoList = resultReportParkDetailByTime(res);
+ log.info("resultDataHandler:{}", iotLocationVo);
+ return AjaxResult.success(iotLocationVoList);
+ }
+
+ /**
+ * 解析停留点返回报文
+ * @param res
+ * @return
+ */
+ private List resultReportParkDetailByTime(String res) {
+ if (res == null) {
+ throw new RuntimeException(ExceptionEnum.RETURN_DATA_IS_EMPTY.getMsg());
+ }
+ List iotLocationVoList = new ArrayList<>();
+ JSONObject object = JSONObject.parseObject(res);
+ String cause = object.getString("cause");
+ String status = object.getString("status");
+ if ("OK".equals(cause) && "0".equals(status)) {
+ String records = object.getString("records");
+ //判断返回结果是否为空
+ if (records != null){
+ JSONArray jsonArray = JSON.parseArray(records);
+ for (int i = 0; i < jsonArray.size(); i++) {
+ IotLocationVo iotLocationVo = new IotLocationVo();
+ JSONObject jsonObject = JSONObject.from(jsonArray.getJSONObject(i));
+ iotLocationVo.setBeginTime(jsonObject.getString("starttime"));
+ iotLocationVo.setEndTime(jsonObject.getString("endtime"));
+ iotLocationVo.setAddress(jsonObject.getString("address"));
+ iotLocationVoList.add(iotLocationVo);
+ }
+ }
+ }
+ return iotLocationVoList;
+ }
+
+ /**
+ * 绑定设备APP
+ * @param iotDto
+ * @return
+ */
+ @Override
+ @Transactional(rollbackFor = Exception.class)
+ public AjaxResult bindApp(IotDto iotDto) {
+ if (iotDto == null || iotDto.getIotCode() == null || iotDto.getMaCode() == null) {
+ return AjaxResult.error(ExceptionEnum.PARAM_NULL.getCode(), ExceptionEnum.PARAM_NULL.getMsg());
+ }
+
+ iotDto.setBinder(SecurityUtils.getLoginUser().getUserid().toString());
+ //根据输入的iot编码查询iot设备
+ IotVo iotVo = iotMachineMapper.selectIotCode(iotDto);
+ if (iotVo == null) {
+ return AjaxResult.error(ExceptionEnum.IOT_ENCODING_ERROR.getCode(), ExceptionEnum.IOT_ENCODING_ERROR.getMsg());
+ }
+ iotDto.setIotId(iotVo.getIotId());
+ int res;
+ try {
+ //绑定设备
+ res = iotMachineMapper.bind(iotDto);
+ if (res == 0) {
+ throw new RuntimeException(ExceptionEnum.BIND_TO_DATABASE.getMsg());
+ }
+ //更新绑定状态
+ res = iotMachineMapper.updateBindStatus(iotDto);
+ if (res == 0) {
+ throw new RuntimeException(ExceptionEnum.UPDATE_TO_DATABASE.getMsg());
+ }
+ } catch (Exception e) {
+ log.error("设备绑定异常:{}", e.getMessage());
+ // 添加事务回滚逻辑,保证全部成功或者全部失败
+ TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
+ return AjaxResult.error(ExceptionEnum.UPDATE_TO_DATABASE.getCode(), ExceptionEnum.UPDATE_TO_DATABASE.getMsg());
+ }
+ return AjaxResult.success(ExceptionEnum.SUCCESS.getMsg(), res);
+ }
+
+ /**
+ * 报警记录
+ * @param iotLocationVo
+ * @return
+ */
+ @Override
+ public AjaxResult reportAlarm(IotLocationVo iotLocationVo) {
+ log.info("reportAlarm:{}", iotLocationVo);
+ if (iotLocationVo == null || iotLocationVo.getIotId() == null || iotLocationVo.getBeginTime() == null || iotLocationVo.getEndTime() == null) {
+ throw new RuntimeException(ExceptionEnum.PARAM_NULL.getMsg());
+ }
+
+ Map map=new HashMap<>();
+ List list=new ArrayList<>();
+ //从redis中获取token
+ String redisCode = redisService.getCacheObject(TokenConstants.TOKEN_LOCATION);
+ //如果token为空,先去调登录接口,获取token
+ if (redisCode == null){
+ redisCode = HttpHelper.getIotToken();
+ redisService.setCacheObject(TokenConstants.TOKEN_LOCATION,redisCode,23L, TimeUnit.HOURS);
+ }
+ map.clear();
+ list.add(iotLocationVo.getIotId().toString());
+ map.put("devices",list);
+ map.put("startday",iotLocationVo.getBeginTime());
+ map.put("endday",iotLocationVo.getEndTime());
+ //报警类型
+ map.put("needalarm","");
+ String param = JSON.toJSONString(map);
+ String res = HttpHelper.doPost(HttpStatus.REPORT_ALARM_URL+redisCode,param);
+ //对返回的结果进行解析
+ List iotLocationVoList = resultReportAlarm(res);
+ log.info("resultDataHandler:{}", iotLocationVo);
+ return AjaxResult.success(iotLocationVoList);
+ }
+
+ /**
+ * 解析报警返回报文
+ * @param res
+ * @return
+ */
+ private List resultReportAlarm(String res) {
+ if (res == null) {
+ throw new RuntimeException(ExceptionEnum.RETURN_DATA_IS_EMPTY.getMsg());
+ }
+ List iotLocationVoList = new ArrayList<>();
+ JSONObject object = JSONObject.parseObject(res);
+ String cause = object.getString("cause");
+ String status = object.getString("status");
+ if ("OK".equals(cause) && "0".equals(status)) {
+ String records = object.getString("alarmrecords");
+ //判断返回结果是否为空
+ if (records != null){
+ JSONArray jsonArray = JSON.parseArray(records);
+ for (int i = 0; i < jsonArray.size(); i++) {
+ JSONObject jsonObject = JSONObject.from(jsonArray.getJSONObject(i));
+ IotLocationVo iotLocationVo = new IotLocationVo();
+ iotLocationVo.setStartAlarmTime(jsonObject.getString("startalarmtime"));
+ iotLocationVo.setStartAlarm(jsonObject.getString("stralarm"));
+ iotLocationVoList.add(iotLocationVo);
+ }
+ }
+ }
+ return iotLocationVoList;
+ }
+
+
+ /**
+ * 解析定位返回报文
+ * @param res
+ * @return
+ */
+ private IotLocationVo resultDataHandler(String res) {
+ if (res == null) {
+ throw new RuntimeException(ExceptionEnum.RETURN_DATA_IS_EMPTY.getMsg());
+ }
+ IotLocationVo iotLocationVo = new IotLocationVo();
+ JSONObject object = JSONObject.parseObject(res);
+ String status = object.getString("status");
+ String cause = object.getString("cause");
+ if ("0".equals(status) && "OK".equals(cause)) {
+ String records = object.getString("records");
+ //判断返回结果是否为空
+ if (records != null){
+ JSONArray jsonArray = JSON.parseArray(records);
+ for (int i = 0; i < jsonArray.size(); i++) {
+ JSONObject jsonObject = JSONObject.from(jsonArray.getJSONObject(i));
+ iotLocationVo.setIotId(StringHelper.conversionLong(jsonObject.getString("deviceid")));
+ iotLocationVo.setCallat(StringHelper.conversionBigDecimal(jsonObject.getString("callat")));
+ iotLocationVo.setCallon(StringHelper.conversionBigDecimal(jsonObject.getString("callon")));
+ }
+ }
+ }
+ return iotLocationVo;
+ }
+
+
+
+
}
diff --git a/sgzb-modules/sgzb-material/src/main/resources/mapper/material/IotMachineMapper.xml b/sgzb-modules/sgzb-material/src/main/resources/mapper/material/IotMachineMapper.xml
index e02e716e..306aa208 100644
--- a/sgzb-modules/sgzb-material/src/main/resources/mapper/material/IotMachineMapper.xml
+++ b/sgzb-modules/sgzb-material/src/main/resources/mapper/material/IotMachineMapper.xml
@@ -1,7 +1,7 @@
+ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
+ "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
@@ -78,33 +78,37 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
iot_machine
WHERE
del_flag = '0'
- AND qr_code = #{qrCode}
+ AND qr_code = #{qrCode}
@@ -164,7 +168,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
sys_dic
WHERE
status = '0'
- AND p_id = '124'
+ AND p_id = '124'