|
@@ -6,6 +6,7 @@ import cn.afterturn.easypoi.excel.ExcelImportUtil;
|
|
|
import cn.afterturn.easypoi.excel.entity.ExportParams;
|
|
|
import cn.afterturn.easypoi.excel.entity.ImportParams;
|
|
|
import cn.hutool.core.collection.CollectionUtil;
|
|
|
+import cn.hutool.core.date.DateTime;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
@@ -28,6 +29,9 @@ import com.usky.common.core.exception.BusinessException;
|
|
|
import com.usky.common.core.util.BeanMapperUtils;
|
|
|
import com.usky.common.core.util.UUIDUtils;
|
|
|
import com.usky.common.mybatis.core.AbstractCrudService;
|
|
|
+import com.usky.demo.RemoteTsdbProxyService;
|
|
|
+import com.usky.demo.domain.LastInnerQueryVO;
|
|
|
+import com.usky.demo.domain.LastInnerResultVO;
|
|
|
import com.usky.iot.domain.*;
|
|
|
import com.usky.common.security.utils.SecurityUtils;
|
|
|
import com.usky.iot.mapper.DmpDeviceInfoMapper;
|
|
@@ -39,6 +43,7 @@ import com.usky.iot.service.DmpProductAttributeService;
|
|
|
import com.usky.iot.service.enums.TopicInfo;
|
|
|
import com.usky.iot.service.vo.*;
|
|
|
import com.usky.transfer.RemoteTransferService;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.poi.ss.usermodel.Workbook;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
@@ -50,7 +55,9 @@ import javax.servlet.ServletOutputStream;
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
import java.io.IOException;
|
|
|
import java.text.DecimalFormat;
|
|
|
+import java.time.Instant;
|
|
|
import java.time.LocalDateTime;
|
|
|
+import java.time.ZoneOffset;
|
|
|
import java.time.format.DateTimeFormatter;
|
|
|
import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
@@ -63,6 +70,7 @@ import java.util.stream.Collectors;
|
|
|
* @author ya
|
|
|
* @since 2022-10-08
|
|
|
*/
|
|
|
+@Slf4j
|
|
|
@Service
|
|
|
public class DmpDeviceInfoServiceImpl extends AbstractCrudService<DmpDeviceInfoMapper, DmpDeviceInfo> implements DmpDeviceInfoService {
|
|
|
@Autowired
|
|
@@ -84,10 +92,14 @@ public class DmpDeviceInfoServiceImpl extends AbstractCrudService<DmpDeviceInfoM
|
|
|
private RemoteTransferService remoteTransferService;
|
|
|
|
|
|
@Autowired
|
|
|
+ private RemoteTsdbProxyService remoteTsdbProxyService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
private DmpProductAttributeMapper dmpProductAttributeMapper;
|
|
|
|
|
|
private static final String ALARM_HTTP_URL = "/service-alarm/baseAlarm/alarmInfo";
|
|
|
|
|
|
+
|
|
|
@Override
|
|
|
public Map<String, Object> control(String productCode, String deviceUuid, String commandCode, String commandValue, String domain, Long userId, String userName) {
|
|
|
Integer tenantId;
|
|
@@ -364,6 +376,7 @@ public class DmpDeviceInfoServiceImpl extends AbstractCrudService<DmpDeviceInfoM
|
|
|
dmpDeviceStatus.setDeviceStatus(2);
|
|
|
dmpDeviceStatus.setLastOfflineTime(LocalDateTime.now());
|
|
|
dmpDeviceStatus.setProductCode(dmpDeviceInfo.getProductCode());
|
|
|
+ dmpDeviceStatus.setDeviceUuid(dmpDeviceInfo.getDeviceUuid());
|
|
|
dmpDeviceStatusService.save(dmpDeviceStatus);
|
|
|
} else {
|
|
|
throw new BusinessException("新增设备信息'" + dmpDeviceInfo.getDeviceId() + "'失败,无对应产品信息");
|
|
@@ -407,6 +420,84 @@ public class DmpDeviceInfoServiceImpl extends AbstractCrudService<DmpDeviceInfoM
|
|
|
return null != one && !Objects.equals(one.getId(), id);
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public void deviceStatus(){
|
|
|
+ log.info("定时同步设备状态数据 start");
|
|
|
+ LastInnerQueryVO queryVO = new LastInnerQueryVO();
|
|
|
+ List<String> deviceuuidList = new ArrayList<>();
|
|
|
+ LambdaQueryWrapper<DmpDeviceInfo> queryWrapper = Wrappers.lambdaQuery();
|
|
|
+ queryWrapper.select(DmpDeviceInfo::getDeviceUuid)
|
|
|
+ .eq(DmpDeviceInfo::getDeleteFlag,0)
|
|
|
+ .ne(DmpDeviceInfo::getServiceStatus,3)
|
|
|
+ .orderByDesc(DmpDeviceInfo::getId);
|
|
|
+ List<DmpDeviceInfo> devList = this.list(queryWrapper);
|
|
|
+ if(CollectionUtils.isNotEmpty(devList)){
|
|
|
+ int count = devList.size();
|
|
|
+ for (int i = 0; i < devList.size(); i++) {
|
|
|
+ deviceuuidList.add(devList.get(i).getDeviceUuid());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ queryVO.setDeviceuuid(deviceuuidList);
|
|
|
+
|
|
|
+ List<LastInnerResultVO> list = remoteTsdbProxyService.last(queryVO);
|
|
|
+ if(CollectionUtils.isNotEmpty(list)){
|
|
|
+ for(int i=0;i<list.size();i++){
|
|
|
+ if(Objects.nonNull(list.get(i).getMetrics())){
|
|
|
+ String deviceuuid = list.get(i).getDeviceuuid();
|
|
|
+ LocalDateTime lTime = Instant.ofEpochMilli(Long.valueOf(list.get(i).getMetrics().get("time").toString())).atZone(ZoneOffset.ofHours(8)).toLocalDateTime();
|
|
|
+ String date = lTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
|
|
|
+ String currentDate = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
|
|
|
+ LambdaUpdateWrapper<DmpDeviceStatus> updateWrapper = Wrappers.lambdaUpdate();
|
|
|
+ if(date.equals(currentDate)){
|
|
|
+ updateWrapper.set(DmpDeviceStatus::getDeviceStatus,1) //设备在线
|
|
|
+ .set(DmpDeviceStatus::getLastOnlineTime,lTime)
|
|
|
+ .eq(DmpDeviceStatus::getDeviceUuid,deviceuuid);
|
|
|
+
|
|
|
+ }else{
|
|
|
+ updateWrapper.set(DmpDeviceStatus::getDeviceStatus,2) //设备离线
|
|
|
+ .set(DmpDeviceStatus::getLastOnlineTime,lTime)
|
|
|
+ .eq(DmpDeviceStatus::getDeviceUuid,deviceuuid);
|
|
|
+
|
|
|
+ }
|
|
|
+ dmpDeviceStatusService.update(updateWrapper);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ log.info("定时同步设备状态数据 end");
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void updateDeviceStatus(LastInnerQueryVO queryVO){
|
|
|
+ List<LastInnerResultVO> list = remoteTsdbProxyService.last(queryVO);
|
|
|
+ if(CollectionUtils.isNotEmpty(list)){
|
|
|
+ for(int i=0;i<list.size();i++){
|
|
|
+ if(Objects.nonNull(list.get(i).getMetrics())){
|
|
|
+ String deviceuuid = list.get(i).getDeviceuuid();
|
|
|
+ LocalDateTime lTime = Instant.ofEpochMilli(Long.valueOf(list.get(i).getMetrics().get("time").toString())).atZone(ZoneOffset.ofHours(8)).toLocalDateTime();
|
|
|
+ String date = lTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
|
|
|
+ String currentDate = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
|
|
|
+ LambdaUpdateWrapper<DmpDeviceStatus> updateWrapper = Wrappers.lambdaUpdate();
|
|
|
+ if(date.equals(currentDate)){
|
|
|
+ updateWrapper.set(DmpDeviceStatus::getDeviceStatus,1) //设备在线
|
|
|
+ .set(DmpDeviceStatus::getLastOnlineTime,lTime)
|
|
|
+ .eq(DmpDeviceStatus::getDeviceUuid,deviceuuid);
|
|
|
+
|
|
|
+ }else{
|
|
|
+ updateWrapper.set(DmpDeviceStatus::getDeviceStatus,2) //设备离线
|
|
|
+ .set(DmpDeviceStatus::getLastOnlineTime,lTime)
|
|
|
+ .eq(DmpDeviceStatus::getDeviceUuid,deviceuuid);
|
|
|
+
|
|
|
+ }
|
|
|
+ dmpDeviceStatusService.update(updateWrapper);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public CommonPage<DmpDeviceInfo> page(DmpDeviceInfoRequest diRequest) {
|
|
|
List<DmpDeviceInfo> list = new ArrayList<>();
|
|
@@ -868,6 +959,7 @@ public class DmpDeviceInfoServiceImpl extends AbstractCrudService<DmpDeviceInfoM
|
|
|
dmpDeviceStatus.setDeviceStatus(2);
|
|
|
dmpDeviceStatus.setLastOfflineTime(LocalDateTime.now());
|
|
|
dmpDeviceStatus.setProductCode(devList.get(i).getProductCode());
|
|
|
+ dmpDeviceStatus.setDeviceUuid(devList.get(i).getDeviceUuid());
|
|
|
dmpDeviceStatusList.add(dmpDeviceStatus);
|
|
|
} else {
|
|
|
throw new BusinessException("新增设备信息'" + devList.get(i).getDeviceId() + "'失败,无对应产品信息");
|