| | |
| | | package com.moral.service.impl; |
| | | |
| | | import com.moral.entity.SensorUnit; |
| | | import com.moral.mapper.SensorUnitMapper; |
| | | import com.moral.service.SensorService; |
| | | import com.moral.service.SensorUnitService; |
| | | import org.apache.log4j.Logger; |
| | | import org.springframework.data.annotation.Transient; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.util.Date; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | import javax.annotation.Resource; |
| | | |
| | | import org.apache.log4j.Logger; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import com.moral.entity.SensorUnit; |
| | | import com.moral.mapper.SensorUnitMapper; |
| | | import com.moral.service.SensorService; |
| | | import com.moral.service.SensorUnitService; |
| | | |
| | | @Service |
| | | public class SensorUnitServiceImpl implements SensorUnitService{ |
| | | public class SensorUnitServiceImpl implements SensorUnitService { |
| | | private static Logger log = Logger.getLogger(SensorService.class); |
| | | @Resource |
| | | private SensorUnitMapper sensorUnitMapper; |
| | | |
| | | @Override |
| | | public boolean addOrModify(SensorUnit sensorUnit) { |
| | | try { |
| | | if(sensorUnit.getId()!=null) { |
| | | if (sensorUnit.getId() != null) { |
| | | sensorUnit.setUpdateTime(new Date()); |
| | | sensorUnitMapper.updateByPrimaryKeySelective(sensorUnit); |
| | | }else{ |
| | | } else { |
| | | sensorUnit.setIsDelete(false); |
| | | sensorUnit.setCreateTime(new Date()); |
| | | sensorUnitMapper.insertSelective(sensorUnit); |
| | |
| | | |
| | | @Override |
| | | public List<SensorUnit> queryListBySensorId(int sensorId) { |
| | | return queryListBySensorId(sensorId,false); |
| | | return queryListBySensorId(sensorId, false); |
| | | } |
| | | |
| | | /** |
| | | * 根据传感器id 获取 所属传感器数组 |
| | | * |
| | | * @param sensorId |
| | | * @return |
| | | */ |
| | |
| | | SensorUnit sensorUnitQuery = new SensorUnit(); |
| | | sensorUnitQuery.setSensorId(sensorId); |
| | | sensorUnitQuery.setIsDelete(isDelete); |
| | | return sensorUnitMapper.select(sensorUnitQuery); |
| | | return sensorUnitMapper.select(sensorUnitQuery); |
| | | } |
| | | |
| | | /** |
| | | * 根据传感器单位实体id 删除 |
| | | * |
| | | * @param id |
| | | */ |
| | | @Override |
| | | public void remove(Integer id) { |
| | | SensorUnit sensorUnit = new SensorUnit(); |
| | | sensorUnit.setId(id); |
| | | sensorUnit.setIsDelete(true); |
| | | sensorUnit.setUpdateTime(new Date()); |
| | | sensorUnitMapper.updateByPrimaryKeySelective(sensorUnit); |
| | | SensorUnit sensorUnit = new SensorUnit(); |
| | | sensorUnit.setId(id); |
| | | sensorUnit.setIsDelete(true); |
| | | sensorUnit.setUpdateTime(new Date()); |
| | | sensorUnitMapper.updateByPrimaryKeySelective(sensorUnit); |
| | | } |
| | | |
| | | /** |
| | | * 获取传感器单位数组分组 |
| | | * |
| | | * @param sensorIds |
| | | * @return |
| | | */ |
| | | @Override |
| | | public Map<Integer,List<SensorUnit>> queryGroupSensorBySids(List<Integer> sensorIds){ |
| | | public Map<Integer, List<SensorUnit>> queryGroupSensorBySids(List<Integer> sensorIds) { |
| | | SensorUnit sensorUnitQuery = new SensorUnit(); |
| | | Map<Integer,List<SensorUnit>> resultListMap = new HashMap<>(); |
| | | for(Integer sensorId: sensorIds) { |
| | | Map<Integer, List<SensorUnit>> resultListMap = new HashMap<>(); |
| | | for (Integer sensorId : sensorIds) { |
| | | sensorUnitQuery.setSensorId(sensorId); |
| | | sensorUnitQuery.setIsDelete(false); |
| | | List<SensorUnit> sensorUnitList = sensorUnitMapper.select(sensorUnitQuery); |
| | | if(sensorUnitList!=null&&sensorUnitList.size()>0){ |
| | | resultListMap.put(sensorId,sensorUnitList); |
| | | if (sensorUnitList != null && sensorUnitList.size() > 0) { |
| | | resultListMap.put(sensorId, sensorUnitList); |
| | | } |
| | | } |
| | | return resultListMap; |
| | | return resultListMap; |
| | | } |
| | | |
| | | @Override |
| | | public Map<String, Object> getSensorByMac(String mac) { |
| | | List<Map<String, Object>> list = sensorUnitMapper.getSensorsByDeviceMac(mac); |
| | | if (list!=null && !list.isEmpty()) { |
| | | Map<String, Object> sensorUnitMap = new HashMap<>(); |
| | | for(Map<String, Object> sensorMap : list) { |
| | | String sensor_key = (String) sensorMap.get("sensor_key"); |
| | | String name = (String) sensorMap.get("name"); |
| | | sensorUnitMap.put(sensor_key, name); |
| | | } |
| | | System.out.println(sensorUnitMap); |
| | | return sensorUnitMap; |
| | | } else { |
| | | Map<String, Object> sensorUnitMap = null; |
| | | return sensorUnitMap; |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public Map<String, Map<String, Object>> getSensorsByMonitPointId(String id) { |
| | | List<Map<String, Object>> list = sensorUnitMapper.getSensorsByMonitPointId(id); |
| | | if (list!=null && !list.isEmpty()) { |
| | | Map<String, Object> innerMap = new HashMap<>(); |
| | | Map<String, Map<String, Object>> sensorUnitMap = new HashMap<>(); |
| | | for(Map<String, Object> sensorMap : list) { |
| | | innerMap.put("unit", sensorMap.get("unit")); |
| | | innerMap.put("name", sensorMap.get("name")); |
| | | innerMap.put("rules", sensorMap.get("rules")); |
| | | String sensor_key = (String) sensorMap.get("sensor_key"); |
| | | String name = (String) sensorMap.get("name"); |
| | | sensorUnitMap.put(sensor_key, innerMap); |
| | | } |
| | | System.out.println(sensorUnitMap); |
| | | return sensorUnitMap; |
| | | } else { |
| | | Map<String, Map<String, Object>> sensorUnitMap = null; |
| | | return sensorUnitMap; |
| | | } |
| | | } |
| | | @Override |
| | | public Map<String, Object> getSensorByMac(String mac) { |
| | | List<Map<String, Object>> list = sensorUnitMapper.getSensorsByDeviceMac(mac); |
| | | if (list != null && !list.isEmpty()) { |
| | | Map<String, Object> sensorUnitMap = new HashMap<>(); |
| | | for (Map<String, Object> sensorMap : list) { |
| | | String sensor_key = (String) sensorMap.get("sensor_key"); |
| | | String name = (String) sensorMap.get("name"); |
| | | sensorUnitMap.put(sensor_key, name); |
| | | } |
| | | return sensorUnitMap; |
| | | } else { |
| | | Map<String, Object> sensorUnitMap = null; |
| | | return sensorUnitMap; |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public List<Map<String, Object>> getSensorsByMonitPointId2(String id) { |
| | | List<Map<String, Object>> list = sensorUnitMapper.getSensorsByMonitPointId(id); |
| | | /*if (list!=null && !list.isEmpty()) { |
| | | Map<String, Object> innerMap = new HashMap<>(); |
| | | Map<String, Map<String, Object>> sensorUnitMap = new HashMap<>(); |
| | | for(Map<String, Object> sensorMap : list) { |
| | | innerMap.put("unit", sensorMap.get("unit")); |
| | | innerMap.put("name", sensorMap.get("name")); |
| | | innerMap.put("rules", sensorMap.get("rules")); |
| | | String sensor_key = (String) sensorMap.get("sensor_key"); |
| | | String name = (String) sensorMap.get("name"); |
| | | sensorUnitMap.put(sensor_key, innerMap); |
| | | } |
| | | System.out.println(sensorUnitMap); |
| | | return sensorUnitMap; |
| | | } else { |
| | | Map<String, Map<String, Object>> sensorUnitMap = null; |
| | | return sensorUnitMap; |
| | | }*/ |
| | | return list; |
| | | } |
| | | @Override |
| | | public Map<String, Map<String, Object>> getSensorsByMonitPointId(String id) { |
| | | List<Map<String, Object>> list = sensorUnitMapper.getSensorsByMonitPointId(id); |
| | | if (list != null && !list.isEmpty()) { |
| | | Map<String, Map<String, Object>> sensorUnitMap = new HashMap<>(); |
| | | for (Map<String, Object> sensorMap : list) { |
| | | Map<String, Object> innerMap = new HashMap<>(); |
| | | innerMap.put("unit", sensorMap.get("unit")); |
| | | innerMap.put("name", sensorMap.get("name")); |
| | | innerMap.put("rules", sensorMap.get("rules")); |
| | | String sensor_key = (String) sensorMap.get("sensor_key"); |
| | | sensorUnitMap.put(sensor_key, innerMap); |
| | | } |
| | | //System.out.println(sensorUnitMap); |
| | | return sensorUnitMap; |
| | | } else { |
| | | Map<String, Map<String, Object>> sensorUnitMap = null; |
| | | return sensorUnitMap; |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public List<Map<String, Object>> getSensorsByMonitPointId2(String id) { |
| | | List<Map<String, Object>> list = sensorUnitMapper.getSensorsByMonitPointId(id); |
| | | return list; |
| | | } |
| | | } |