ZhuDongming
2019-08-29 ef3a45a366ea8451f2581547fa6a3894bd1d672f
src/main/java/com/moral/service/impl/HistoryServiceImpl.java
@@ -33,11 +33,13 @@
import com.moral.entity.Sensor;
import com.moral.mapper.DeviceMapper;
import com.moral.mapper.HistoryMapper;
import com.moral.mapper.OrganizationRelationMapper;
import com.moral.mapper.SensorMapper;
import com.moral.mapper.SensorUnitMapper;
import com.moral.service.AccountService;
import com.moral.service.HistoryService;
import com.moral.service.ProfessionService;
import com.moral.util.AQICalculation;
@Service
public class HistoryServiceImpl implements HistoryService {
@@ -56,6 +58,9 @@
    @Resource
    private ProfessionService professionService;
    @Resource
    private OrganizationRelationMapper organizationRelationMapper;
   @Override
   public Map<String, Object> getAllSensorAverageByDevice(Map<String, Object> parameters) throws Exception {
@@ -286,7 +291,7 @@
         if (sensorUnits.containsKey(sensorKey)) {
            Map<String, Object> sensorUnit  = (Map<String, Object>) sensorUnits.get(sensorKey);
            String rules = sensorUnit.get("rules").toString();
            rules = rules.replace("d", "").replace("{0}", "sensorKeyValue");
            rules = rules.replace("d", "").replace("{0}", "value");
            Expression expression = AviatorEvaluator.compile(rules);
            Map<String, Object> env = new HashMap<String, Object>();
            env.put("value", Double.valueOf(sensorKeyValue.toString()));
@@ -359,6 +364,54 @@
         startTime = localDate+" "+startHour+":00:00";
      }
      Map<String, Object> map = historyMapper.getAVGValueByMacAndTimeslot(mac, startTime, endTime);
      return map;
      System.out.println(map);
      Map<String, Object> returnMap = new HashMap<>();
      if (map.isEmpty()) {
         returnMap.put("AQI", "N/V");
      } else {
         Map<String, Double> AQIMap = new HashMap<>();
         for (Map.Entry<String, Object> entry : map.entrySet()) {
            String key = entry.getKey();
            Double value = Double.parseDouble(entry.getValue().toString());
            AQIMap.put(key, value);
           }
         returnMap = AQICalculation.hourlyAQI(AQIMap);
      }
      return returnMap;
   }
   @Override
   public Map<String, Object> getMointorPointRankByOrganizationId(Map<String, Object> parameters) {
      //获取组织id
      String organizationId = parameters.get("organization_id").toString();
      //声明一个集合存放要查询站点数据的组织id
      List<Object> organizationIdList = new ArrayList<>();
      organizationIdList.add(organizationId);
      //声明一个集合存放父组织id
      List<Object> parentIdList = new ArrayList<>();
      parentIdList.add(organizationId);
      //进行循环
      for(int i=0;i<10;i++) {
         if(!parentIdList.isEmpty()) {
            //或去该组织下的子组织
            System.out.println("parentIdList:"+parentIdList);
            List<Map<String, Object>> childIdList = organizationRelationMapper.getChildIdByParentId(parentIdList);
            //清空父组织id集合
            parentIdList.clear();
            System.out.println("childIdList:"+childIdList);
            //将子组织id放入到集合中
            for (Map<String, Object> map : childIdList) {
               organizationIdList.add(map.get("child_id"));
               parentIdList.add(map.get("child_id"));
            }
         }else {
            break;
         }
      }
      System.out.println(organizationIdList);
      return null;
   }
}