|
|
@@ -1,15 +1,26 @@
|
|
|
package com.yunfeiyun.agmp.iotm.device.scd.controller;
|
|
|
|
|
|
+import com.alibaba.fastjson2.JSONObject;
|
|
|
import com.yunfeiyun.agmp.common.constant.ErrorCode;
|
|
|
import com.yunfeiyun.agmp.common.core.domain.AjaxResult;
|
|
|
import com.yunfeiyun.agmp.common.core.page.TableDataInfo;
|
|
|
+import com.yunfeiyun.agmp.common.log.LogCore;
|
|
|
+import com.yunfeiyun.agmp.common.utils.DateUtils;
|
|
|
+import com.yunfeiyun.agmp.common.utils.StringUtils;
|
|
|
+import com.yunfeiyun.agmp.iot.common.constant.IotErrorCode;
|
|
|
import com.yunfeiyun.agmp.iot.common.constant.devicetype.IotDeviceDictConst;
|
|
|
+import com.yunfeiyun.agmp.iot.common.domain.IotDevice;
|
|
|
+import com.yunfeiyun.agmp.iot.common.enums.IotDeviceStatusTypeEnum;
|
|
|
+import com.yunfeiyun.agmp.iot.common.exception.IotBizException;
|
|
|
import com.yunfeiyun.agmp.iotm.common.controller.BaseController;
|
|
|
import com.yunfeiyun.agmp.iotm.device.common.domin.IotDeviceBaseFunReqVo;
|
|
|
import com.yunfeiyun.agmp.iotm.device.common.domin.IotDeviceDataListReqVo;
|
|
|
import com.yunfeiyun.agmp.iotm.device.common.domin.IotDeviceExportReqVo;
|
|
|
import com.yunfeiyun.agmp.iotm.device.common.service.IotDeviceCommonService;
|
|
|
import com.yunfeiyun.agmp.iotm.device.common.service.IotDeviceRefreshService;
|
|
|
+import com.yunfeiyun.agmp.iotm.device.scd.domain.IotScdClearPestDto;
|
|
|
+import com.yunfeiyun.agmp.iotm.device.scd.domain.IotScdConfig;
|
|
|
+import com.yunfeiyun.agmp.iotm.device.scd.domain.IotScdConfigEditReqVo;
|
|
|
import com.yunfeiyun.agmp.iotm.web.domain.reqvo.IotDeviceListReqVo;
|
|
|
import com.yunfeiyun.agmp.iotm.web.domain.resvo.IotDeviceListResVo;
|
|
|
import com.yunfeiyun.agmp.iotm.web.service.IIotDeviceService;
|
|
|
@@ -21,7 +32,9 @@ import javax.annotation.Resource;
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
import java.util.Arrays;
|
|
|
+import java.util.Date;
|
|
|
import java.util.List;
|
|
|
+import java.util.Objects;
|
|
|
|
|
|
/**
|
|
|
* 杀虫灯设备控制器
|
|
|
@@ -132,4 +145,90 @@ public class IotDeviceScdController extends BaseController {
|
|
|
iotDeviceCommonService.func(iotDeviceBaseFunReqVo);
|
|
|
}
|
|
|
|
|
|
+ @GetMapping("/config/info/{devBid}")
|
|
|
+ public AjaxResult configInfo(@PathVariable("devBid") String devBid){
|
|
|
+ IotDeviceDataListReqVo reqVo = new IotDeviceDataListReqVo();
|
|
|
+ reqVo.setDevBid(devBid);
|
|
|
+
|
|
|
+ IotDeviceBaseFunReqVo iotDeviceBaseFunReqVo = new IotDeviceBaseFunReqVo();
|
|
|
+ iotDeviceBaseFunReqVo.setDevBid(reqVo.getDevBid());
|
|
|
+ iotDeviceBaseFunReqVo.setMethodName("configInfo");
|
|
|
+ iotDeviceBaseFunReqVo.setParam(reqVo);
|
|
|
+ JSONObject jsonObject = iotDeviceCommonService.func(iotDeviceBaseFunReqVo);
|
|
|
+ return AjaxResult.success(jsonObject);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 下发杀虫灯配置指令
|
|
|
+ *
|
|
|
+ * @return
|
|
|
+ * @throws Exception
|
|
|
+ */
|
|
|
+ @PostMapping("/config/edit")
|
|
|
+ public AjaxResult sendConfigCmd(@RequestBody IotScdConfigEditReqVo reqVo) {
|
|
|
+ log.info("【{}】【杀虫灯】【下发指令配置】客户id {}", LogCore.getSeq(), getCustomerId());
|
|
|
+ String devBid = reqVo.getDevBid();
|
|
|
+ IotScdConfig iotScdConfig = reqVo.getIotScdConfig();
|
|
|
+ if(StringUtils.isEmpty(devBid) || iotScdConfig == null){
|
|
|
+ throw new IotBizException(IotErrorCode.PARAM_INVALID.getCode(),"参数不能为空");
|
|
|
+ }
|
|
|
+ IotDevice iotDevice = iIotDeviceService.selectIotDeviceByDevBid(devBid);
|
|
|
+ if(iotDevice == null){
|
|
|
+ throw new IotBizException(ErrorCode.INVALID_PARAMETER.getCode(),"设备不存在");
|
|
|
+ }
|
|
|
+ String devStatus = iotDevice.getDevStatus();
|
|
|
+ String devCreateddate = iotDevice.getDevCreateddate();
|
|
|
+ Date createdDate = DateUtils.dateTime(DateUtils.YYYY_MM_DD_HH_MM_SS, devCreateddate);
|
|
|
+ Date nowDate = DateUtils.getNowDate();
|
|
|
+ long diffTime = nowDate.getTime() - createdDate.getTime();
|
|
|
+ if(diffTime > 10 * 1000){
|
|
|
+ if (!Objects.equals(devStatus, IotDeviceStatusTypeEnum.ONLINE.getCode()) && !Objects.equals(devStatus, IotDeviceStatusTypeEnum.WAIT_ACTIVATE.getCode())) {
|
|
|
+ throw new IotBizException(IotErrorCode.FAILURE.getCode(), "设备离线无法操作");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ reqVo.setIotDevice(iotDevice);
|
|
|
+
|
|
|
+ IotDeviceBaseFunReqVo iotDeviceBaseFunReqVo = new IotDeviceBaseFunReqVo();
|
|
|
+ iotDeviceBaseFunReqVo.setDevBid(reqVo.getDevBid());
|
|
|
+ iotDeviceBaseFunReqVo.setMethodName("sendConfigCmd");
|
|
|
+ iotDeviceBaseFunReqVo.setParam(reqVo);
|
|
|
+ String taskId = iotDeviceCommonService.func(iotDeviceBaseFunReqVo);
|
|
|
+
|
|
|
+ return new AjaxResult(ErrorCode.SUCCESS.getCode(), "下发成功,等待设备响应结果", taskId);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 一键清虫
|
|
|
+ * @param devBid
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @GetMapping("/clear/{devBid}")
|
|
|
+ public AjaxResult clearPest(@PathVariable("devBid") String devBid) {
|
|
|
+ IotDevice iotDevice = iIotDeviceService.selectIotDeviceByDevBid(devBid);
|
|
|
+ if(iotDevice == null){
|
|
|
+ throw new IotBizException(ErrorCode.INVALID_PARAMETER.getCode(),"设备不存在");
|
|
|
+ }
|
|
|
+ String devStatus = iotDevice.getDevStatus();
|
|
|
+ String devCreateddate = iotDevice.getDevCreateddate();
|
|
|
+ Date createdDate = DateUtils.dateTime(DateUtils.YYYY_MM_DD_HH_MM_SS, devCreateddate);
|
|
|
+ Date nowDate = DateUtils.getNowDate();
|
|
|
+ long diffTime = nowDate.getTime() - createdDate.getTime();
|
|
|
+ if(diffTime > 10 * 1000){
|
|
|
+ if (!Objects.equals(devStatus, IotDeviceStatusTypeEnum.ONLINE.getCode()) && !Objects.equals(devStatus, IotDeviceStatusTypeEnum.WAIT_ACTIVATE.getCode())) {
|
|
|
+ throw new IotBizException(IotErrorCode.FAILURE.getCode(), "设备离线无法操作");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ IotScdClearPestDto iotScdClearPestDto = new IotScdClearPestDto();
|
|
|
+ iotScdClearPestDto.setIotDevice(iotDevice);
|
|
|
+
|
|
|
+ IotDeviceBaseFunReqVo iotDeviceBaseFunReqVo = new IotDeviceBaseFunReqVo();
|
|
|
+ iotDeviceBaseFunReqVo.setDevBid(devBid);
|
|
|
+ iotDeviceBaseFunReqVo.setMethodName("clearPest");
|
|
|
+
|
|
|
+ iotDeviceBaseFunReqVo.setParam(iotScdClearPestDto);
|
|
|
+ String taskId = iotDeviceCommonService.func(iotDeviceBaseFunReqVo);
|
|
|
+
|
|
|
+ return new AjaxResult(ErrorCode.SUCCESS.getCode(), "下发成功,等待设备响应结果", taskId);
|
|
|
+ }
|
|
|
}
|