| | |
| | | import java.util.ArrayList; |
| | | import java.util.Arrays; |
| | | import java.util.HashMap; |
| | | import java.util.LinkedHashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | |
| | | import org.apache.commons.collections.CollectionUtils; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.moral.common.bean.PageBean; |
| | | import com.moral.common.util.MyBatisBaseMapUtil; |
| | | import com.moral.entity.Device; |
| | |
| | | return sensors; |
| | | } |
| | | |
| | | @Override |
| | | public List<List<String>> listSensorInfos(String[] sensorsResult) { |
| | | List<String> sensorKeys = new ArrayList<>(); |
| | | List<String> sensorKeysNames = new ArrayList<>(); |
| | | List<String> sensorKeysUnits = new ArrayList<>(); |
| | | List<List<String>> sensorInfos = new ArrayList<>(); |
| | | for (int index = 0; index < sensorsResult.length; index++) { |
| | | String[] split = sensorsResult[index].split("-"); |
| | | String key = split[0].replace("\"", ""); |
| | | String name = split[1].replace("\"", ""); |
| | | String Unit = split[2].replace("\"", ""); |
| | | sensorKeys.add(key); |
| | | sensorKeysNames.add(name); |
| | | sensorKeysUnits.add(Unit); |
| | | } |
| | | sensorInfos.add(sensorKeys); |
| | | sensorInfos.add(sensorKeysNames); |
| | | sensorInfos.add(sensorKeysUnits); |
| | | return sensorInfos; |
| | | } |
| | | |
| | | @Override |
| | | public List<List<Map<String, Object>>> listExcelDatas(List<List<String>> sensorInfos, List<Map<String, Object>> list) { |
| | | List<List<Map<String, Object>>> sheets = new ArrayList<>(); |
| | | for (int i = 0; i < sensorInfos.get(0).size(); i++) { |
| | | List<Map<String, Object>> sheet = new ArrayList<>(); |
| | | for (int j = 0; j < list.size(); j++) { |
| | | Map<String, Object> data = new LinkedHashMap<>(); |
| | | for (Map.Entry<String, Object> kv : list.get(j).entrySet()) { |
| | | if ("monitorPointName".equals(kv.getKey())) { |
| | | data.put("站点名称(单位:" + sensorInfos.get(2).get(i) + ")", kv.getValue()); |
| | | } else if ("name".equals(kv.getKey())) { |
| | | data.put("设备名称", kv.getValue()); |
| | | } else { |
| | | String sensorsValue = kv.getValue().toString(); |
| | | JSONObject jsonObject = JSONObject.parseObject(sensorsValue); |
| | | if (jsonObject != null) { |
| | | List<Object> sensorsValueList = (List<Object>) jsonObject.get(sensorInfos.get(0).get(i)); |
| | | if (sensorsValueList != null) { |
| | | data.put(kv.getKey(), sensorsValueList.get(0)); |
| | | } else { |
| | | data.put(kv.getKey(), ""); |
| | | } |
| | | } else { |
| | | data.put(kv.getKey(), ""); |
| | | } |
| | | } |
| | | } |
| | | sheet.add(data); |
| | | } |
| | | sheets.add(sheet); |
| | | } |
| | | return sheets; |
| | | } |
| | | |
| | | } |