安防门状态改成实时数据

This commit is contained in:
wyw 2024-08-16 15:33:41 +08:00
parent 87d2232fcd
commit d0d7f46fc8
2 changed files with 66 additions and 98 deletions

View File

@ -18,6 +18,8 @@ import com.fastbee.iot.haiwei.service.HaiWeiService;
import com.fastbee.iot.mapper.DeviceMapper;
import com.fastbee.iot.model.anfang.UploadedPhotos;
import com.fastbee.iot.model.haiwei.CmdHaiWeiVo;
import com.fastbee.iot.model.haiwei.HaiWeiDeviceInfoVo;
import com.fastbee.iot.model.haiwei.HaiWeiPropertyVo;
import com.fastbee.iot.model.haiwei.dto.CmdHaiWeiDto;
import com.fastbee.iot.service.IDeviceLogService;
import com.fastbee.iot.service.IDeviceService;
@ -178,20 +180,36 @@ public class DeviceDetailServiceImpl implements IDeviceDetailService {
if (StringUtils.isNotEmpty(anfangIds)) {
Device anfangDevice = iDeviceService.selectDeviceByDeviceId(Long.parseLong(anfangIds));
//获取当前安防告警状态
CommonResult<HaiWeiDeviceInfoVo> cache = haiWeiService.getCache(anfangDevice.getDeviceId());
HaiWeiDeviceInfoVo checkedData = cache.getCheckedData();
List<HaiWeiPropertyVo> propertyList = checkedData.getPropertyList();
for (HaiWeiPropertyVo haiWeiPropertyVo : propertyList) {
if (haiWeiPropertyVo.getNameEn().equals("三菱FX2N_1_open")) {
// HashMap<Object, Object> hashMap1 = new HashMap<Object, Object>() {{
// put("upType", 0);
// put("identifier", "xiangmen");
// put("unit", "");
// put("value", haiWeiPropertyVo.getValue());
// put("name", haiWeiPropertyVo.getNameCn());
// }};
anfangInfoVo.setDoorStatus(Integer.parseInt(haiWeiPropertyVo.getValue().toString()));
}
}
UploadedPhotos uploadedPhotos = new UploadedPhotos();
uploadedPhotos.setSn(anfangDevice.getSerialNumber());
List<UploadedPhotos> uploadedPhotos1 = uploadedPhotosService.selectUploadedPhotosList(uploadedPhotos);
int doorStatus = 0;//0=正常1=箱门振动2=箱门打开
if (uploadedPhotos1.size() > 0) {
UploadedPhotos temp = uploadedPhotos1.get(0);
if (new Date().getTime() - temp.getUploadTime().getTime() < 36000000) {
if (temp.getShakeState().equals("1")) {
doorStatus = 1;
}
if (temp.getDoorState().equals("1")) {
doorStatus = 2;
}
}
// if (new Date().getTime() - temp.getUploadTime().getTime() < 36000000) {
// if (temp.getShakeState().equals("1")) {
// doorStatus = 1;
// }
// if (temp.getDoorState().equals("1")) {
// doorStatus = 2;
// }
// }
}
if (uploadedPhotos1.size() > 5) {
uploadedPhotos1 = uploadedPhotos1.subList(0, 5);

View File

@ -6,6 +6,7 @@ import cn.hutool.core.util.NumberUtil;
import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import com.fastbee.common.core.domain.CommonResult;
import com.fastbee.common.core.page.TableDataInfo;
import com.fastbee.common.model.vo.TreeItemVo;
import com.fastbee.common.model.vo.iot.GisDeviceListVo;
@ -18,8 +19,11 @@ import com.fastbee.iot.domain.Device;
import com.fastbee.iot.domain.DeviceLog;
import com.fastbee.iot.domain.Product;
import com.fastbee.iot.domain.ThingsModel;
import com.fastbee.iot.haiwei.service.HaiWeiService;
import com.fastbee.iot.mapper.DeviceMapper;
import com.fastbee.iot.mapper.ProductMapper;
import com.fastbee.iot.model.haiwei.HaiWeiDeviceInfoVo;
import com.fastbee.iot.model.haiwei.HaiWeiPropertyVo;
import com.fastbee.iot.service.*;
import com.fastbee.waterele.domain.MaWatereleRecord;
import com.fastbee.waterele.service.IMaWatereleRecordService;
@ -55,6 +59,8 @@ public class GisDeviceServiceImpl implements IGisDeviceService {
@Autowired
private IMaWatereleRecordService watereleRecordService;
@Resource
HaiWeiService haiWeiService;
public GisDeviceServiceImpl(@Qualifier("deviceMapper") DeviceMapper deviceMapper, @Qualifier("productMapper") ProductMapper productMapper) {
this.deviceMapper = deviceMapper;
@ -202,70 +208,22 @@ public class GisDeviceServiceImpl implements IGisDeviceService {
}
//箱门信息
String guimenIds = devParams.get("guimenIds").toString();
ThingsModel thingsModel3 = new ThingsModel();
thingsModel3.setProductId(140L);
List<ThingsModel> guimenModels = thingsModelService.selectThingsModelList(thingsModel3);
if (StringUtils.isNotEmpty(taiyangnengIds)) {
Device guimenDevice = deviceMapper.selectDeviceByDeviceId(Long.parseLong(guimenIds));
List<DeviceLog> deviceLogs = logService.selectDeviceLogList(new DeviceLog() {{
setSerialNumber(guimenDevice.getSerialNumber());
setBeginTime(DateUtil.beginOfDay(DateUtil.offsetDay(dateTime, -1)).toString());
setEndTime(DateUtil.endOfDay(dateTime).toString());
}});
Map<String, List<DeviceLog>> guimenCollect = deviceLogs.stream().sorted(Comparator
.comparing(DeviceLog::getCreateTime, Comparator
.nullsFirst(Comparator.naturalOrder())).reversed()).collect(Collectors.groupingBy(t -> t.getIdentity()));
for (ThingsModel thingsModel : guimenModels) {
if (StringUtils.isNotEmpty(guimenIds)) {
CommonResult<HaiWeiDeviceInfoVo> cache = haiWeiService.getCache(Long.valueOf(guimenIds));
HaiWeiDeviceInfoVo checkedData = cache.getCheckedData();
List<HaiWeiPropertyVo> propertyList = checkedData.getPropertyList();
for (HaiWeiPropertyVo haiWeiPropertyVo : propertyList) {
if (haiWeiPropertyVo.getNameEn().equals("三菱FX2N_1_open")) {
HashMap<Object, Object> hashMap1 = new HashMap<Object, Object>() {{
put("upType", 0);
put("identifier", thingsModel.getIdentifier().equals("三菱FX2N_1_open")?"xiangmen":thingsModel.getIdentifier());
put("identifier", "xiangmen");
put("unit", "");
put("value", 0);
put("name", thingsModel.getModelName());
put("value", haiWeiPropertyVo.getValue());
put("name", haiWeiPropertyVo.getNameCn());
}};
if (StringUtils.isNotEmpty(thingsModel.getSpecs())) {
String specs = thingsModel.getSpecs();
JSONObject parse = (JSONObject) JSON.parse(specs);
if (parse.containsKey("unit")) {
hashMap1.put("unit", parse.get("unit"));
rMap.put("xiangmen", hashMap1);
}
}
if (hashMap1.size() > 1) {
List<DeviceLog> deviceLogs1 = guimenCollect.get(thingsModel.getIdentifier());
if (deviceLogs1 != null) {
if(deviceLogs1.size() > 0){
if (StringUtils.isNotEmpty(deviceLogs1.get(0).getLogValue())) {
if(deviceLogs1.size() > 1){
if (Float.parseFloat(deviceLogs1.get(0).getLogValue()) == Float.parseFloat(deviceLogs1.get(1).getLogValue())) {
hashMap1.put("upType", 1);
} else if (Float.parseFloat(deviceLogs1.get(0).getLogValue()) < Float.parseFloat(deviceLogs1.get(1).getLogValue())) {
hashMap1.put("upType", -1);
}
}else{
hashMap1.put("upType", 0);
}
hashMap1.put("value", deviceLogs1.get(0).getLogValue());
} else {
hashMap1.put("value", "--");
hashMap1.put("upType", 0);
}
}else{
hashMap1.put("value", "--");
hashMap1.put("upType", 0);
}
}
} else if (hashMap1.size() > 0) {
List<DeviceLog> deviceLogs3 = guimenCollect.get(thingsModel.getIdentifier());
if (deviceLogs3 != null) {
hashMap1.put("value", deviceLogs3.get(0).getLogValue());
}
}
rMap.put(thingsModel.getIdentifier().equals("三菱FX2N_1_open")?"xiangmen":thingsModel.getIdentifier(), hashMap1);
}
} else {
for (ThingsModel thingsModel : taiyangnengModels) {
HashMap<Object, Object> hashMap1 = new HashMap<Object, Object>() {{
@ -278,14 +236,6 @@ public class GisDeviceServiceImpl implements IGisDeviceService {
rMap.put(thingsModel.getIdentifier().equals("三菱FX2N_1_open") ? "xiangmen" : thingsModel.getIdentifier(), hashMap1);
}
}
// HashMap<Object, Object> hashMap = new HashMap<Object, Object>() {{
// put("upType", 0);
// put("identifier", "xiangmen");
// put("unit", "");
// put("value", 0);//0=正常1=箱门振动2=箱门打开
// put("name", "箱门状态");
// }};
// rMap.put("xiangmen", hashMap);
String liuliangIds = devParams.get("liuliangIds").toString();
ThingsModel thingsModel2 = new ThingsModel();
thingsModel2.setProductId(139L);