| | |
| | | package com.moral.service.impl; |
| | | |
| | | import com.moral.common.bean.PageBean; |
| | | import com.moral.common.util.MyBatisBaseMapUtil; |
| | | import com.moral.entity.Sensor; |
| | | import com.moral.mapper.SensorMapper; |
| | | import com.moral.service.SensorService; |
| | | import org.springframework.stereotype.Service; |
| | | import tk.mybatis.mapper.entity.Example; |
| | | import java.util.ArrayList; |
| | | import java.util.Arrays; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.util.Arrays; |
| | | import java.util.List; |
| | | |
| | | import org.apache.commons.collections.CollectionUtils; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import com.moral.common.bean.PageBean; |
| | | import com.moral.common.util.MyBatisBaseMapUtil; |
| | | import com.moral.entity.Device; |
| | | import com.moral.entity.MonitorPoint; |
| | | import com.moral.entity.Sensor; |
| | | import com.moral.mapper.SensorMapper; |
| | | import com.moral.service.MonitorPointService; |
| | | import com.moral.service.SensorService; |
| | | |
| | | import tk.mybatis.mapper.entity.Example; |
| | | |
| | | @Service |
| | | public class SensorServiceImpl implements SensorService{ |
| | | public class SensorServiceImpl implements SensorService { |
| | | @Resource |
| | | SensorMapper sensorMapper; |
| | | |
| | | @Resource |
| | | MonitorPointService monitorPointService; |
| | | |
| | | private static Class ENTITY_CLASS = Sensor.class; |
| | | |
| | | /** |
| | | * 查询所有的传感器类型 |
| | | * |
| | | * @return |
| | | */ |
| | | @Override |
| | | public List<Sensor> queryAll(){ |
| | | public List<Sensor> queryAll() { |
| | | return sensorMapper.selectByExample(null); |
| | | } |
| | | public PageBean queryByPageBean(PageBean pageBean){ |
| | | return MyBatisBaseMapUtil.queryPage(sensorMapper,pageBean,ENTITY_CLASS); |
| | | |
| | | public PageBean<Sensor> queryByPageBean(PageBean pageBean) { |
| | | return MyBatisBaseMapUtil.queryPage(sensorMapper, pageBean, ENTITY_CLASS); |
| | | } |
| | | |
| | | @Override |
| | | public PageBean queryByVersionId(Integer deviceVersionId){ |
| | | public PageBean queryByVersionId(Integer deviceVersionId) { |
| | | List<Sensor> sensorList = sensorMapper.selectByVersionId(deviceVersionId); |
| | | return new PageBean(sensorList); |
| | | return new PageBean(sensorList); |
| | | } |
| | | public void addOrModify(Sensor sensor){ |
| | | try{ |
| | | if(sensor.getId()==null){ |
| | | |
| | | @Override |
| | | public List<Sensor> queryListByVersionId(Integer deviceVersionId) { |
| | | return sensorMapper.selectByVersionId(deviceVersionId); |
| | | } |
| | | |
| | | @Override |
| | | public List<Sensor> queryListByVersionNo(Integer versionNo) { |
| | | return sensorMapper.selectByVersionNo(versionNo); |
| | | } |
| | | |
| | | public void addOrModify(Sensor sensor) { |
| | | try { |
| | | if (sensor.getId() == null) { |
| | | sensorMapper.insertSelective(sensor); |
| | | }else{ |
| | | } else { |
| | | sensorMapper.updateByPrimaryKeySelective(sensor); |
| | | } |
| | | } |
| | | catch (Exception ex){ |
| | | throw ex; |
| | | } catch (Exception ex) { |
| | | throw ex; |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void deleteByIds(Integer... ids) { |
| | | if(ids!=null&&ids.length>0){ |
| | | if(ids.length==1){ |
| | | if (ids != null && ids.length > 0) { |
| | | if (ids.length == 1) { |
| | | sensorMapper.deleteByPrimaryKey(ids[0]); |
| | | }else{ |
| | | } else { |
| | | Example example = new Example(ENTITY_CLASS); |
| | | example.or().andIn("id", Arrays.asList(ids)); |
| | | sensorMapper.deleteByExample(example); |
| | |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 获取当前组织下所有传感器并集 |
| | | * |
| | | * @param organizationId |
| | | * @return |
| | | */ |
| | | @Override |
| | | public List<Sensor> getAllSensors() { |
| | | return sensorMapper.selectAll(); |
| | | } |
| | | public List<Sensor> queryByOrgId(Integer organizationId) { |
| | | return sensorMapper.selectByOrgId(organizationId); |
| | | } |
| | | |
| | | @Override |
| | | public List<Sensor> getAllSensors() { |
| | | return sensorMapper.selectAll(); |
| | | } |
| | | |
| | | @Override |
| | | public Map<String, Object> getSensorBySensorKey(String sensorKey) { |
| | | Map<String, Object> map = sensorMapper.getSensorBySensorKey(sensorKey); |
| | | return map; |
| | | } |
| | | |
| | | @Override |
| | | public List<Map<String, Object>> getSensorByDeviceId(String id) { |
| | | List<Map<String, Object>> list = sensorMapper.getSensorByDeviceId(id); |
| | | return list; |
| | | } |
| | | |
| | | @Override |
| | | public List<Map<String, Object>> getSensorByMonitorPointId(String monitor_point_id) { |
| | | List<Map<String, Object>> list = sensorMapper.getSensorByMonitorPointId(monitor_point_id); |
| | | return list; |
| | | } |
| | | |
| | | @Override |
| | | public Map<String, String> getSensorsMap(Map<String, Object> parameters) { |
| | | List<Sensor> sensors = sensorMapper.getSensorsByMac(parameters); |
| | | Map<String, String> sensorMap = new HashMap<>(); |
| | | for (Sensor sensor : sensors) { |
| | | sensorMap.put(sensor.getSensorKey(), sensor.getDescription()); |
| | | } |
| | | return sensorMap; |
| | | } |
| | | |
| | | @Override |
| | | public List<Map<String, String>> getSensorsMaps(String mac) { |
| | | List<Sensor> sensors = sensorMapper.getSensorsInfoByMac(mac); |
| | | Map<String, String> sensorsDescriptionMap = new HashMap<>(); |
| | | for (Sensor sensor : sensors) { |
| | | sensorsDescriptionMap.put(sensor.getSensorKey(), sensor.getDescription()); |
| | | } |
| | | Map<String, String> sensorsUnitMap = new HashMap<>(); |
| | | for (Sensor sensor : sensors) { |
| | | sensorsUnitMap.put(sensor.getSensorKey(), sensor.getUnit()); |
| | | } |
| | | List<Map<String, String>> sensorsMapList = new ArrayList<>(); |
| | | sensorsMapList.add(sensorsDescriptionMap); |
| | | sensorsMapList.add(sensorsUnitMap); |
| | | return sensorsMapList; |
| | | } |
| | | |
| | | @Override |
| | | public List<Sensor> selectSenosrsByOrgId(Map<String, Object> parameters) { |
| | | List<String> macList = new ArrayList<>(); |
| | | List<MonitorPoint> monitorPoints = monitorPointService.getMonitorPointsAndDevicesByRegion(parameters); |
| | | for (MonitorPoint m : monitorPoints) { |
| | | for (Device d : m.getDevices()) { |
| | | macList.add(d.getMac()); |
| | | } |
| | | } |
| | | parameters.put("macs", macList); |
| | | List<Sensor> sensors = new ArrayList<>(); |
| | | if (!CollectionUtils.isEmpty(macList)) { |
| | | sensors = sensorMapper.selectSenosrsByOrgId(parameters); |
| | | } else { |
| | | sensors = sensorMapper.selectAll(); |
| | | } |
| | | return sensors; |
| | | } |
| | | |
| | | } |