|
|
@@ -3,13 +3,16 @@ package com.xunmei.iot.service.impl;
|
|
|
import cn.hutool.core.date.DateUtil;
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
import com.alibaba.fastjson2.JSON;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.xunmei.common.core.constant.SecurityConstants;
|
|
|
import com.xunmei.common.core.domain.iot.domain.IotSensor;
|
|
|
+import com.xunmei.common.core.domain.mediator.domain.MediatorCategory;
|
|
|
import com.xunmei.common.core.web.page.TableDataInfo;
|
|
|
import com.xunmei.iot.dto.sensor.SensorPageDto;
|
|
|
import com.xunmei.iot.mapper.IotCommonSensorMapper;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.xunmei.iot.mapper.MediatorCategoryMapper;
|
|
|
import com.xunmei.iot.service.IIotCommonSensorService;
|
|
|
import com.xunmei.iot.vo.sensor.SensorPageVo;
|
|
|
import com.xunmei.system.api.RemoteOrgService;
|
|
|
@@ -21,6 +24,7 @@ import javax.annotation.Resource;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
+import java.util.Optional;
|
|
|
|
|
|
/**
|
|
|
* <p>
|
|
|
@@ -39,34 +43,23 @@ public class IotCommonSensorServiceImpl extends ServiceImpl<IotCommonSensorMappe
|
|
|
@Resource
|
|
|
private IotCommonSensorMapper sensorMapper;
|
|
|
|
|
|
+ @Resource
|
|
|
+ private MediatorCategoryMapper categoryMapper;
|
|
|
+
|
|
|
@Override
|
|
|
public TableDataInfo<SensorPageVo> selectSensorDataPage(SensorPageDto request) {
|
|
|
dealPageParam(request);
|
|
|
|
|
|
Page<SensorPageVo> page = sensorMapper.selectPageData(request.getPageRequest(), request);
|
|
|
+ final List<MediatorCategory> categoryList = categoryMapper.selectList(new LambdaQueryWrapper<>());
|
|
|
for (SensorPageVo record : page.getRecords()) {
|
|
|
final String info = record.getInfo();
|
|
|
record.setInfo(dealInfoData(info));
|
|
|
+ dealCategoryName(record, categoryList);
|
|
|
}
|
|
|
return TableDataInfo.build(page);
|
|
|
}
|
|
|
|
|
|
- private String dealInfoData(String info) {
|
|
|
- if (ObjectUtil.isEmpty(info)){
|
|
|
- return StringUtil.EMPTY_STRING;
|
|
|
- }
|
|
|
- final List<Map> list = JSON.parseArray(info, Map.class);
|
|
|
- List<String> dataList = new ArrayList<>();
|
|
|
- for (Map map : list) {
|
|
|
- final String name = (String) map.get("name");
|
|
|
- final String res = (String) map.get("res");
|
|
|
- if (ObjectUtil.hasEmpty(name, res)) {
|
|
|
- continue;
|
|
|
- }
|
|
|
- dataList.add(name + ":" + res);
|
|
|
- }
|
|
|
- return String.join(";", dataList);
|
|
|
- }
|
|
|
|
|
|
@Override
|
|
|
public TableDataInfo<SensorPageVo> selectSensorLogDataPage(SensorPageDto request) {
|
|
|
@@ -95,4 +88,40 @@ public class IotCommonSensorServiceImpl extends ServiceImpl<IotCommonSensorMappe
|
|
|
request.setEndTime(DateUtil.endOfDay(request.getDateRange()[1]));
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ private String dealInfoData(String info) {
|
|
|
+ if (ObjectUtil.isEmpty(info)) {
|
|
|
+ return StringUtil.EMPTY_STRING;
|
|
|
+ }
|
|
|
+ final List<Map> list = JSON.parseArray(info, Map.class);
|
|
|
+ List<String> dataList = new ArrayList<>();
|
|
|
+ for (Map map : list) {
|
|
|
+ final String name = (String) map.get("name");
|
|
|
+ final String res = (String) map.get("res");
|
|
|
+ if (ObjectUtil.hasEmpty(name, res)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ dataList.add(name + ":" + res);
|
|
|
+ }
|
|
|
+ return String.join(";", dataList);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void dealCategoryName(SensorPageVo record, List<MediatorCategory> categoryList) {
|
|
|
+ if (ObjectUtil.isEmpty(record.getCategoryId())) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ final Optional<MediatorCategory> optional = categoryList.stream().filter(c -> ObjectUtil.equal(c.getId(), record.getCategoryId())).findFirst();
|
|
|
+ if (!optional.isPresent()) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ final MediatorCategory category = optional.get();
|
|
|
+ record.setCategoryType(category.getName());
|
|
|
+ final Optional<MediatorCategory> parentCategoryOptional = categoryList.stream().filter(c -> ObjectUtil.equal(c.getId(), category.getParentId())).findFirst();
|
|
|
+ if (!parentCategoryOptional.isPresent()) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ final MediatorCategory parentCategory = parentCategoryOptional.get();
|
|
|
+ record.setAssetsType(parentCategory.getName());
|
|
|
+
|
|
|
+ }
|
|
|
}
|