|
|
@@ -1,18 +1,24 @@
|
|
|
package com.inspur.netty.controller;
|
|
|
|
|
|
+import cn.dev33.satoken.annotation.SaCheckPermission;
|
|
|
+import com.inspur.device.domain.bo.SmsbOtaRecordBo;
|
|
|
import com.inspur.device.domain.vo.SmsbDeviceVo;
|
|
|
-import com.inspur.device.mapper.SmsbDeviceMapper;
|
|
|
import com.inspur.device.service.ISmsbDeviceService;
|
|
|
-import com.inspur.netty.message.push.PushMessage;
|
|
|
+import com.inspur.device.service.ISmsbOtaRecordService;
|
|
|
import com.inspur.netty.message.push.PushMessageType;
|
|
|
import com.inspur.netty.util.NettyConstants;
|
|
|
import com.inspur.netty.util.PushMsgUtil;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
import org.dromara.common.core.domain.R;
|
|
|
+import org.dromara.common.core.validate.AddGroup;
|
|
|
+import org.dromara.common.idempotent.annotation.RepeatSubmit;
|
|
|
+import org.dromara.common.log.annotation.Log;
|
|
|
+import org.dromara.common.log.enums.BusinessType;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.web.bind.annotation.GetMapping;
|
|
|
-import org.springframework.web.bind.annotation.PathVariable;
|
|
|
-import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
-import org.springframework.web.bind.annotation.RestController;
|
|
|
+import org.springframework.validation.annotation.Validated;
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
+
|
|
|
+import java.util.List;
|
|
|
|
|
|
/**
|
|
|
* netty device controller
|
|
|
@@ -21,11 +27,15 @@ import org.springframework.web.bind.annotation.RestController;
|
|
|
*/
|
|
|
@RestController()
|
|
|
@RequestMapping("/netty/device")
|
|
|
+@Slf4j
|
|
|
public class DeviceController {
|
|
|
|
|
|
@Autowired
|
|
|
private ISmsbDeviceService smsbDeviceService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private ISmsbOtaRecordService smsbOtaRecordService;
|
|
|
+
|
|
|
/**
|
|
|
* 重启设备
|
|
|
*
|
|
|
@@ -102,4 +112,28 @@ public class DeviceController {
|
|
|
return isSend ? R.ok() : R.fail("发送失败,设备长连接已断开");
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 新增发布升级
|
|
|
+ */
|
|
|
+ @SaCheckPermission("device:otaRecord:add")
|
|
|
+ @Log(title = "发布升级", businessType = BusinessType.INSERT)
|
|
|
+ @RepeatSubmit()
|
|
|
+ @PostMapping()
|
|
|
+ public R<Void> add(@Validated(AddGroup.class) @RequestBody SmsbOtaRecordBo bo) {
|
|
|
+ R<Void> addResult = smsbOtaRecordService.insertByBo(bo);
|
|
|
+ if (addResult.getCode() == 200) {
|
|
|
+ // 发送升级指令
|
|
|
+ List<Long> deviceIds = bo.getDeviceIds();
|
|
|
+ for (Long deviceId : deviceIds) {
|
|
|
+ SmsbDeviceVo deviceVo = smsbDeviceService.getDeviceCacheById(deviceId);
|
|
|
+ if (deviceVo != null) {
|
|
|
+ String upgradeCmd = deviceVo.getIdentifier() + PushMessageType.DEVICE_CHECK_OTA.getValue() + NettyConstants.DATA_PACK_SEPARATOR;
|
|
|
+ boolean isSend = PushMsgUtil.sendV2(deviceVo.getIdentifier(), upgradeCmd);
|
|
|
+ log.info("发送设备 :{} 升级指令 : {}", deviceId, isSend);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return addResult;
|
|
|
+ }
|
|
|
+
|
|
|
}
|