| | |
| | | import java.time.temporal.TemporalAdjusters;
|
| | | import java.util.ArrayList;
|
| | | import java.util.Arrays;
|
| | | import java.util.Calendar;
|
| | | import java.util.Collections;
|
| | | import java.util.Comparator;
|
| | | import java.util.Date;
|
| | |
| | | public Map<String, List<Object>> getCompareReport(Map<String, Object> parameters) throws Exception {
|
| | | Map<String, List<Object>> resultMap = new HashMap<String, List<Object>>();
|
| | | List<Map<String, Object>> list = JSON.parseObject((String)parameters.remove("items"), new TypeReference<List<Map<String, Object>>>() {});
|
| | | Map<String, Object> timeType = JSON.parseObject((String)parameters.remove("timeType"), new TypeReference<Map<String, Object>>() {});
|
| | | parameters.putAll(timeType);
|
| | | parameters.put("type", parameters.remove("value"));
|
| | |
|
| | | ExecutorService threadPool = Executors.newCachedThreadPool();
|
| | | CompletionService<Map<String, List<Object>>> cs = new ExecutorCompletionService<Map<String, List<Object>>>(threadPool);
|
| | |
|
| | | String type = (String) parameters.get("type");
|
| | | parameters.putAll(getElementByType(type));
|
| | | Integer timeLength = Integer.valueOf(parameters.remove("timeLength").toString());
|
| | | if ("month".equals(type)) {
|
| | | for (Map<String, Object> map : list) {
|
| | | int timeLength = Integer.valueOf(parameters.get("timeLength").toString());
|
| | | String[] formatTime = map.get("formatTime").toString().split("-");
|
| | | LocalDate localDate = LocalDate.of(Integer.valueOf(formatTime[0]), Integer.valueOf(formatTime[1]), 1);
|
| | | int lengthOfMonth = localDate.lengthOfMonth();
|
| | | if (lengthOfMonth > timeLength) {
|
| | | parameters.put("timeLength", lengthOfMonth);
|
| | | timeLength = lengthOfMonth;
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | | List<Object> timeList = new ArrayList<Object>();
|
| | | for (int i = 0; i <Integer.valueOf(parameters.get("timeLength").toString()); i++) {
|
| | | for (int i = 0; i < timeLength; i++) {
|
| | | timeList.add(i, String.format("%02d", "day".equals(type) || "hour".equals(type) ? i : i + 1));
|
| | | }
|
| | | parameters.put("timeList", timeList);
|
| | |
|
| | | ExecutorService threadPool = Executors.newCachedThreadPool();
|
| | | CompletionService<Map<String, List<Object>>> cs = new ExecutorCompletionService<Map<String, List<Object>>>(threadPool);
|
| | | for (int i = 0; i < list.size(); i++) {
|
| | | Map<String, Object> map = list.get(i);
|
| | | map.put("part", i);
|
| | |
| | | List<Map<String, Object>> resultList ;
|
| | |
|
| | | String type = (String) parameters.get("type");
|
| | | if (!parameters.containsKey("field")) {
|
| | | parameters.putAll(getElementByType(type));
|
| | | }
|
| | | String time = (String) parameters.get("time");
|
| | | String format = (String) parameters.get("format");
|
| | | Integer field = Integer.valueOf(parameters.get("field").toString());
|
| | | Date start = DateUtils.parseDate(time, format), end = null ;
|
| | | if (parameters.containsKey("timeb")) {
|
| | | end = DateUtils.parseDate((String)parameters.get("timeb"), format);
|
| | | } else {
|
| | | switch (type) {
|
| | | case "year":
|
| | | end = DateUtils.addYears(start, 1);
|
| | | break;
|
| | | case "month":
|
| | | end = DateUtils.addMonths(start, 1);
|
| | | break;
|
| | | case "day":
|
| | | end = DateUtils.addDays(start, 1);
|
| | | break;
|
| | | case "hour":
|
| | | end = DateUtils.addHours(start, 1);
|
| | | break;
|
| | | }
|
| | | |
| | | Calendar instance = Calendar.getInstance();
|
| | | instance.setTime(start);
|
| | | instance.add(field, 1);
|
| | | end = instance.getTime();
|
| | | }
|
| | | parameters.put("start", start);
|
| | | parameters.put("end", end);
|
| | |
| | | }
|
| | |
|
| | | /**
|
| | | * 根据线性表单的条件规则,获取一条线性表单数据
|
| | | * 根据线性表单的条件规则,获取一条线性表单数据,包含 所有检测项目
|
| | | * @param sensorKeys
|
| | | * @param timePeriod
|
| | | * @param dataCondition
|
| | |
| | | // list to map
|
| | | int finalN = n;
|
| | | sensorKeys.forEach(sensorKey -> {
|
| | | Double sensorValue = rowData.get(sensorKey)!= null?new Double(rowData.get(sensorKey).toString()):null;
|
| | | lineChartDatasWithEmpty.get(sensorKey).set(finalN,sensorValue);
|
| | | Object value = rowData.get(sensorKey);
|
| | | List<Double> lineChartDatasWithEmptyTemp = lineChartDatasWithEmpty.get(sensorKey);
|
| | | if(finalN < lineChartDatasWithEmptyTemp.size()){
|
| | | Double sensorValue = value!= null?new Double(value.toString()):null;
|
| | | lineChartDatasWithEmptyTemp.set(finalN,sensorValue);
|
| | | }
|
| | | });
|
| | | // 置为 -1,防止越界
|
| | | m = m<dataLength ? m+1 : -1;
|
| | |
| | | }
|
| | | return lineChartDatasWithEmpty;
|
| | | }
|
| | | |
| | | private Map<String, Object> getElementByType(Object type){
|
| | | Map<String, Object> resultMap = new HashMap<String, Object>();
|
| | | switch (type.toString()) {
|
| | | case "year":
|
| | | resultMap.put("format", "yyyy");
|
| | | resultMap.put("typeFormat", "%Y-%m");
|
| | | resultMap.put("timeLength", 12);
|
| | | resultMap.put("field", Calendar.YEAR);
|
| | | break;
|
| | | case "month":
|
| | | resultMap.put("format", "yyyy-MM");
|
| | | resultMap.put("typeFormat", "%Y-%m-%d");
|
| | | resultMap.put("timeLength", 28);
|
| | | resultMap.put("field", Calendar.MONTH);
|
| | | break;
|
| | | case "day":
|
| | | resultMap.put("format", "yyyy-MM-dd");
|
| | | resultMap.put("typeFormat", "%Y-%m-%d %H");
|
| | | resultMap.put("timeLength", 24);
|
| | | resultMap.put("field", Calendar.DATE);
|
| | | break;
|
| | | case "hour":
|
| | | resultMap.put("format", "yyyy-MM-dd HH");
|
| | | resultMap.put("typeFormat", "%Y-%m-%d %H:%i");
|
| | | resultMap.put("timeLength", 60);
|
| | | resultMap.put("field", Calendar.HOUR);
|
| | | break;
|
| | | }
|
| | | return resultMap;
|
| | | }
|
| | | }
|