|
@@ -16,6 +16,8 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
+import java.util.Date;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
|
|
@@ -34,26 +36,31 @@ public class EnvDeviceEquipmentController {
|
|
|
IEnvTopicService topicService;
|
|
|
|
|
|
@PostMapping("/listByUnit")
|
|
|
- public Result listByUnit(@RequestBody Map<String, String> map, HttpServletRequest request){
|
|
|
- return deviceRegisterService.listByUnit(map,request);
|
|
|
+ public Result listByUnit(@RequestBody Map<String, String> map, HttpServletRequest request) {
|
|
|
+ return deviceRegisterService.listByUnit(map, request);
|
|
|
}
|
|
|
+
|
|
|
private static final RateLimiter limiter = RateLimiter.create(0.3);
|
|
|
+
|
|
|
@PostMapping("/update")
|
|
|
- public Result update(@RequestBody EnvDeviceEquipment envDeviceEquipment){
|
|
|
+ public Result update(@RequestBody EnvDeviceEquipment envDeviceEquipment) {
|
|
|
try {
|
|
|
+ Date date = new Date();
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
+ System.out.println("----这个是开始请求的时间:"+sdf.format(date));
|
|
|
envDeviceEquipmentService.updateById(envDeviceEquipment);
|
|
|
EnvDeviceEquipment byId = envDeviceEquipmentService.getById(envDeviceEquipment.getId());
|
|
|
String deviceCode = byId.getDeviceCode();
|
|
|
- System.out.println("设备"+deviceCode);
|
|
|
+ System.out.println("设备" + deviceCode);
|
|
|
QueryWrapper<EnvDeviceRegister> queryWrapper = new QueryWrapper<>();
|
|
|
- queryWrapper.eq("device_code",deviceCode);
|
|
|
+ queryWrapper.eq("device_code", deviceCode);
|
|
|
EnvDeviceRegister one = deviceRegisterService.getOne(queryWrapper);
|
|
|
String chipId = one.getChipId();
|
|
|
- log.info("-------获取设备编码:"+chipId);
|
|
|
+ log.info("-------获取设备编码:" + chipId);
|
|
|
// PublishMQTT publishMQTT = new PublishMQTT();
|
|
|
log.info("-----开始配置消息----");
|
|
|
QueryWrapper<EnvDeviceEquipment> queryWrapper1 = new QueryWrapper<>();
|
|
|
- queryWrapper1.eq("device_code",deviceCode).orderByDesc("equipment_port");
|
|
|
+ queryWrapper1.eq("device_code", deviceCode).orderByDesc("equipment_port");
|
|
|
List<EnvDeviceEquipment> list = envDeviceEquipmentService.list(queryWrapper1);
|
|
|
StringBuilder deviceStatus = new StringBuilder();
|
|
|
for (EnvDeviceEquipment envDeviceEquipment1 : list) {
|
|
@@ -61,95 +68,132 @@ public class EnvDeviceEquipmentController {
|
|
|
}
|
|
|
String s = deviceStatus.toString();
|
|
|
int i = Integer.parseInt(s, 2);
|
|
|
- JSONObject jsonObject =new JSONObject();
|
|
|
- jsonObject.put("dev_ctrl",i);
|
|
|
- log.info("消息配置完成开始发送:"+jsonObject.toJSONString());
|
|
|
- PublishMQTTTree publishMQTTTree = new PublishMQTTTree();
|
|
|
+ JSONObject jsonObject = new JSONObject();
|
|
|
+ jsonObject.put("dev_ctrl", i);
|
|
|
+ log.info("消息配置完成开始发送:" + jsonObject.toJSONString());
|
|
|
+ PublishMQTTTree publishMQTTTree = new PublishMQTTTree();
|
|
|
Boolean start = publishMQTTTree.start("tcp://115.238.57.190:1883", "test" + chipId, "admin", "admin", "huimv_down_" + chipId, jsonObject.toJSONString());
|
|
|
- if (start){
|
|
|
- return new Result(10000,"修改成功",false);
|
|
|
- }else {
|
|
|
- return new Result(10001,"配置失败,请稍后配置",false);
|
|
|
+
|
|
|
+ if (start) {
|
|
|
+ Thread.sleep(2500);//线程等待3秒
|
|
|
+ EnvDeviceEquipment byId1 = envDeviceEquipmentService.getById(envDeviceEquipment.getId());
|
|
|
+ Date updateTime = byId1.getUpdateTime();
|
|
|
+ System.out.println("-----这个是修改后的时间:"+updateTime);
|
|
|
+// updateTime.setTime(updateTime.getTime()+5*1000);
|
|
|
+ int i1 = updateTime.compareTo(date);
|
|
|
+ if (byId1.getMark() == 1 && i1 > 0) {
|
|
|
+ QueryWrapper<EnvDeviceEquipment> queryWrapper2 = new QueryWrapper<>();
|
|
|
+ queryWrapper2.eq("device_code", deviceCode).orderByDesc("equipment_port");
|
|
|
+ List<EnvDeviceEquipment> list1 = envDeviceEquipmentService.list(queryWrapper2);
|
|
|
+ for (EnvDeviceEquipment equipment : list1) {
|
|
|
+ equipment.setMark(0);
|
|
|
+ envDeviceEquipmentService.updateById(equipment);
|
|
|
+ }
|
|
|
+ return new Result(10000, "修改成功", true);
|
|
|
+ } else {
|
|
|
+ if (envDeviceEquipment.getUploadStart() == 1) {
|
|
|
+ envDeviceEquipment.setUploadStart(0);
|
|
|
+ } else {
|
|
|
+ envDeviceEquipment.setUploadStart(1);
|
|
|
+ }
|
|
|
+ envDeviceEquipmentService.updateById(envDeviceEquipment);
|
|
|
+ return new Result(10001, "设备掉线,请等待设备重连", false);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if (envDeviceEquipment.getUploadStart() == 1) {
|
|
|
+ envDeviceEquipment.setUploadStart(0);
|
|
|
+ } else {
|
|
|
+ envDeviceEquipment.setUploadStart(1);
|
|
|
+ }
|
|
|
+ envDeviceEquipmentService.updateById(envDeviceEquipment);
|
|
|
+ return new Result(10001, "网络连接超时,请等待5秒后重试", false);
|
|
|
}
|
|
|
|
|
|
- }catch (Exception e){
|
|
|
- System.out.println("22222222222"+e);
|
|
|
- return new Result(10001,"修改失败",false);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ /* if (start){
|
|
|
+ envDeviceEquipmentService.updateById(envDeviceEquipment);
|
|
|
+ return new Result(10000, "修改成功", true);
|
|
|
+ }else {
|
|
|
+ return new Result(10001, "配置失败,请稍后配置", false);
|
|
|
+ }*/
|
|
|
+
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+ System.out.println("22222222222" + e);
|
|
|
+ return new Result(10001, "修改失败", false);
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@PostMapping("/remove")
|
|
|
- public Result remove(@RequestBody Map<String, String> map){
|
|
|
+ public Result remove(@RequestBody Map<String, String> map) {
|
|
|
try {
|
|
|
String id = map.get("id");
|
|
|
envDeviceEquipmentService.removeById(id);
|
|
|
- return new Result(10000,"删除成功",true);
|
|
|
- }catch (Exception e){
|
|
|
- return new Result(10001,"删除失败",false);
|
|
|
+ return new Result(10000, "删除成功", true);
|
|
|
+ } catch (Exception e) {
|
|
|
+ return new Result(10001, "删除失败", false);
|
|
|
}
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * @Method : getEquipment
|
|
|
+ * @Method : getEquipment
|
|
|
* @Description :
|
|
|
- * @Params : [farmCode,binding]
|
|
|
- * @Return : com.huimv.common.utils.Result
|
|
|
- *
|
|
|
- * @Author : ZhuoNing
|
|
|
- * @Date : 2022/10/27
|
|
|
- * @Time : 17:54
|
|
|
+ * @Params : [farmCode,binding]
|
|
|
+ * @Return : com.huimv.common.utils.Result
|
|
|
+ * @Author : ZhuoNing
|
|
|
+ * @Date : 2022/10/27
|
|
|
+ * @Time : 17:54
|
|
|
*/
|
|
|
@PostMapping("/getEquipment")
|
|
|
- public com.huimv.common.utils.Result getEquipment(@RequestBody Map<String,String> paramsMap){
|
|
|
+ public com.huimv.common.utils.Result getEquipment(@RequestBody Map<String, String> paramsMap) {
|
|
|
return envDeviceEquipmentService.getEquipment(paramsMap);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * @Method : getShowRoomEquipment
|
|
|
+ * @Method : getShowRoomEquipment
|
|
|
* @Description :
|
|
|
- * @Params : [unitId,binding]
|
|
|
- * @Return : com.huimv.common.utils.Result
|
|
|
- *
|
|
|
- * @Author : ZhuoNing
|
|
|
- * @Date : 2022/10/27
|
|
|
- * @Time : 18:09
|
|
|
+ * @Params : [unitId,binding]
|
|
|
+ * @Return : com.huimv.common.utils.Result
|
|
|
+ * @Author : ZhuoNing
|
|
|
+ * @Date : 2022/10/27
|
|
|
+ * @Time : 18:09
|
|
|
*/
|
|
|
@PostMapping("/getShowRoomEquipment")
|
|
|
- public com.huimv.common.utils.Result getShowRoomEquipment(@RequestBody Map<String,String> paramsMap){
|
|
|
+ public com.huimv.common.utils.Result getShowRoomEquipment(@RequestBody Map<String, String> paramsMap) {
|
|
|
return envDeviceEquipmentService.getShowRoomEquipment(paramsMap);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * @Method : setEquipmentStatus
|
|
|
+ * @Method : setEquipmentStatus
|
|
|
* @Description :
|
|
|
- * @Params : [farmCode,deviceCode,port,status]
|
|
|
- * @Return : com.huimv.common.utils.Result
|
|
|
- *
|
|
|
- * @Author : ZhuoNing
|
|
|
- * @Date : 2022/10/27
|
|
|
- * @Time : 17:55
|
|
|
+ * @Params : [farmCode,deviceCode,port,status]
|
|
|
+ * @Return : com.huimv.common.utils.Result
|
|
|
+ * @Author : ZhuoNing
|
|
|
+ * @Date : 2022/10/27
|
|
|
+ * @Time : 17:55
|
|
|
*/
|
|
|
@PostMapping("/setEquipmentStatus")
|
|
|
- public com.huimv.common.utils.Result setEquipmentStatus(@RequestBody Map<String,String> paramsMap){
|
|
|
+ public com.huimv.common.utils.Result setEquipmentStatus(@RequestBody Map<String, String> paramsMap) {
|
|
|
return envDeviceEquipmentService.setEquipmentStatus(paramsMap);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * @Method : setShowRoomEquipmentStatus
|
|
|
- * @Description :
|
|
|
- * @Params : [id,status]
|
|
|
- * @Return : com.huimv.common.utils.Result
|
|
|
- *
|
|
|
- * @Author : ZhuoNing
|
|
|
- * @Date : 2022/10/27
|
|
|
- * @Time : 19:01
|
|
|
+ * @Method : setShowRoomEquipmentStatus
|
|
|
+ * @Description :
|
|
|
+ * @Params : [id,status]
|
|
|
+ * @Return : com.huimv.common.utils.Result
|
|
|
+ * @Author : ZhuoNing
|
|
|
+ * @Date : 2022/10/27
|
|
|
+ * @Time : 19:01
|
|
|
*/
|
|
|
@PostMapping("/setShowRoomEquipmentStatus")
|
|
|
- public com.huimv.common.utils.Result setShowRoomEquipmentStatus(@RequestBody Map<String,String> paramsMap){
|
|
|
+ public com.huimv.common.utils.Result setShowRoomEquipmentStatus(@RequestBody Map<String, String> paramsMap) {
|
|
|
return envDeviceEquipmentService.setShowRoomEquipmentStatus(paramsMap);
|
|
|
}
|
|
|
}
|