From dba54bf8c8f9299d61c05bf3a941708ea399c998 Mon Sep 17 00:00:00 2001
From: ZhuDongming <773644075@qq.com>
Date: Sun, 26 Apr 2020 15:20:22 +0800
Subject: [PATCH] update excel多个工作表导出

---
 src/main/java/com/moral/service/impl/SensorServiceImpl.java |  145 ++++++++++++++++++++++++++++++++++++++----------
 1 files changed, 115 insertions(+), 30 deletions(-)

diff --git a/src/main/java/com/moral/service/impl/SensorServiceImpl.java b/src/main/java/com/moral/service/impl/SensorServiceImpl.java
index c088849..7d0c013 100644
--- a/src/main/java/com/moral/service/impl/SensorServiceImpl.java
+++ b/src/main/java/com/moral/service/impl/SensorServiceImpl.java
@@ -1,67 +1,85 @@
 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<Sensor> 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);
     }
+
     @Override
-    public List<Sensor> queryListByVersionId(Integer deviceVersionId){
+    public List<Sensor> queryListByVersionId(Integer deviceVersionId) {
         return sensorMapper.selectByVersionId(deviceVersionId);
     }
+
     @Override
-    public List<Sensor> queryListByVersionNo(Integer versionNo){
+    public List<Sensor> queryListByVersionNo(Integer versionNo) {
         return sensorMapper.selectByVersionNo(versionNo);
     }
-    public void addOrModify(Sensor sensor){
-        try{
-            if(sensor.getId()==null){
+
+    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);
@@ -72,6 +90,7 @@
 
     /**
      * ������������������������������������������
+     *
      * @param organizationId
      * @return
      */
@@ -79,8 +98,74 @@
     public List<Sensor> queryByOrgId(Integer organizationId) {
         return sensorMapper.selectByOrgId(organizationId);
     }
+
     @Override
-	public List<Sensor> getAllSensors() {
-		return sensorMapper.selectAll();
-	}
+    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;
+    }
+
 }

--
Gitblit v1.8.0