|
|
@@ -0,0 +1,97 @@
|
|
|
+package com.nb.aliyun.controller;
|
|
|
+
|
|
|
+
|
|
|
+import cn.dev33.satoken.annotation.SaIgnore;
|
|
|
+import cn.hutool.core.util.ObjectUtil;
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
+import cn.hutool.json.JSONUtil;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.IdWorker;
|
|
|
+import com.nb.core.exception.CustomException;
|
|
|
+import com.nb.core.result.R;
|
|
|
+import com.nb.core.utils.ExceptionUtil;
|
|
|
+import com.nb.web.api.entity.BusDeviceEntity;
|
|
|
+import com.nb.web.api.entity.BusHospitalLogEntity;
|
|
|
+import com.nb.web.api.entity.common.BusDeviceRunningEntity;
|
|
|
+import com.nb.web.api.enums.DeviceStatusEnum2;
|
|
|
+import com.nb.web.api.enums.HospitalLogEnum;
|
|
|
+import com.nb.web.api.feign.IDeviceClient;
|
|
|
+import com.nb.web.api.feign.IHospitalLogClient;
|
|
|
+import com.nb.web.api.feign.IIotMsgHandler;
|
|
|
+import io.netty.channel.DefaultEventLoopGroup;
|
|
|
+import io.swagger.annotations.Api;
|
|
|
+import lombok.AllArgsConstructor;
|
|
|
+import org.springframework.validation.annotation.Validated;
|
|
|
+import org.springframework.web.bind.annotation.PostMapping;
|
|
|
+import org.springframework.web.bind.annotation.RequestBody;
|
|
|
+import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
+import org.springframework.web.bind.annotation.RestController;
|
|
|
+
|
|
|
+import java.util.concurrent.ExecutorService;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @ClassName : IotController
|
|
|
+ * @Description :
|
|
|
+ * @Author : LF
|
|
|
+ * @Date: 2023年10月17日
|
|
|
+ */
|
|
|
+@RestController
|
|
|
+@RequestMapping("/iot")
|
|
|
+@Api(description="iot数据处理")
|
|
|
+@AllArgsConstructor
|
|
|
+public class IotController {
|
|
|
+
|
|
|
+ private final IIotMsgHandler iotMsgHandler;
|
|
|
+ private final IHospitalLogClient hospitalLogService;
|
|
|
+ private final IDeviceClient deviceService;
|
|
|
+ private final ExecutorService executorService=new DefaultEventLoopGroup();
|
|
|
+ /**
|
|
|
+ * 数据保存
|
|
|
+ */
|
|
|
+ @PostMapping("/data/save")
|
|
|
+ @SaIgnore
|
|
|
+ public R assignMenu(@RequestBody BusDeviceRunningEntity source) {
|
|
|
+ if(StrUtil.isBlank(source.getDeviceId())){
|
|
|
+ throw new CustomException("[deviceId]设备id不能为空");
|
|
|
+ }
|
|
|
+ if(StrUtil.isBlank(source.getClassification())){
|
|
|
+ throw new CustomException("[classification]分类标识号不能为空");
|
|
|
+ }
|
|
|
+ if(ObjectUtil.isNull(source.getDataNumber())){
|
|
|
+ throw new CustomException("[dataNumber]数据编号不能为空");
|
|
|
+ }
|
|
|
+ if(ObjectUtil.isNull(source.getType())){
|
|
|
+ throw new CustomException("[type]设备类型不能为空");
|
|
|
+ }
|
|
|
+ if(ObjectUtil.isNull(source.getRunState())){
|
|
|
+ throw new CustomException("[runState]设备运行状态不能为空");
|
|
|
+ }
|
|
|
+ source.setTest(false);
|
|
|
+ executorService.execute(()->{
|
|
|
+ BusDeviceEntity device = new BusDeviceEntity();
|
|
|
+ device.setStatus(DeviceStatusEnum2.ONLINE);
|
|
|
+ device.setDeviceId(source.getDeviceId());
|
|
|
+ device.setStatus(DeviceStatusEnum2.ONLINE);
|
|
|
+ device.setEnable(true);
|
|
|
+ deviceService.saveDevice(device);
|
|
|
+ BusHospitalLogEntity hospitalLog = new BusHospitalLogEntity();
|
|
|
+ hospitalLog.setIdentityCode(source.getDeviceId());
|
|
|
+ hospitalLog.setInput(JSONUtil.toJsonStr(source));
|
|
|
+ hospitalLog.setType(HospitalLogEnum.IOT_INTERFACE);
|
|
|
+ hospitalLog.setTenantId(device.getTenantId());
|
|
|
+ long startTime = System.currentTimeMillis();
|
|
|
+ try {
|
|
|
+ BusDeviceRunningEntity sync = iotMsgHandler.sync(source, source.getDeviceId());
|
|
|
+ hospitalLog.setResult(JSONUtil.toJsonStr(sync));
|
|
|
+ hospitalLog.setSuccess(true);
|
|
|
+ }catch (Exception e) {
|
|
|
+ hospitalLog.setSuccess(false);
|
|
|
+ hospitalLog.setMessage(ExceptionUtil.getExceptionMsg(e));
|
|
|
+ }
|
|
|
+ long entTime = System.currentTimeMillis();
|
|
|
+ hospitalLog.setUseTime(entTime - startTime);
|
|
|
+ hospitalLog.setId(IdWorker.getIdStr());
|
|
|
+ hospitalLogService.save(hospitalLog);
|
|
|
+ });
|
|
|
+ return R.success();
|
|
|
+ }
|
|
|
+}
|