xufenglei
2018-02-05 48bfa4e57cd2195b86bd8c0debe2e241db0ba80d
报表
4 files modified
131 ■■■■ changed files
src/main/java/com/moral/controller/ReportController.java 2 ●●● patch | view | raw | blame | history
src/main/java/com/moral/controller/ScreenController.java 21 ●●●●● patch | view | raw | blame | history
src/main/java/com/moral/service/HistoryMinutelyService.java 2 ●●● patch | view | raw | blame | history
src/main/java/com/moral/service/impl/HistoryMinutelyServiceImpl.java 106 ●●●●● patch | view | raw | blame | history
src/main/java/com/moral/controller/ReportController.java
@@ -38,7 +38,7 @@
    @GetMapping("excel")
    public ResultBean<Boolean> getExcelReport(HttpServletRequest request,HttpServletResponse response) throws Exception {
        Map<String, Object> parameters = getParametersStartingWith(request, null);
        List<Map<String, Object>> list = historyMinutelyService.getMonitorPointOrDeviceAvgData4Excel(parameters);
        List<Map<String, Object>> list = historyMinutelyService.getMonitorPointOrDeviceAvgData(parameters);
        String[][] exportColumn =  new String[2][];
        exportColumn[0] = new String[] { "时间", "20", "time" };
        if (parameters.containsKey("sensors")) {
src/main/java/com/moral/controller/ScreenController.java
@@ -5,7 +5,11 @@
import static com.moral.common.util.ResourceUtil.getValue;
import static com.moral.common.util.WebUtils.getParametersStartingWith;
import java.io.*;
import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
@@ -13,27 +17,31 @@
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import com.moral.common.xml.Version;
import org.apache.commons.net.ftp.FTPClient;
import org.dom4j.Document;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.xml.sax.InputSource;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONReader;
import com.alibaba.fastjson.TypeReference;
import com.moral.common.bean.ResultBean;
import com.moral.common.util.ValidateUtil;
import com.moral.common.xml.Version;
import com.moral.service.AccountService;
import com.moral.service.HistoryMinutelyService;
import com.moral.service.DeviceService;
import com.moral.service.HistoryMinutelyService;
import com.moral.service.HistoryService;
import com.moral.service.MachineActivateService;
import org.xml.sax.InputSource;
/**
 * The Class ScreenController.大屏接口
@@ -101,7 +109,6 @@
     * @return the equipment states
     */
    @GetMapping("/equipment-state")
    @PreAuthorize("hasAnyRole('USER', 'ADMIN')")
    public Map<String, Object> getDeviceStatesByAccount(HttpServletRequest request) {
        Map<String, Object> parameters = getParametersStartingWith(request, null);
        return deviceService.getDeviceStatesByAccount(parameters);
src/main/java/com/moral/service/HistoryMinutelyService.java
@@ -9,7 +9,7 @@
    
    Map<String, List<Object>> getCompareReport(Map<String, Object> parameters) throws Exception;
    List<Map<String, Object>> getMonitorPointOrDeviceAvgData4Excel(Map<String, Object> parameters) throws Exception;
    List<Map<String, Object>> getMonitorPointOrDeviceAvgData(Map<String, Object> parameters) throws Exception;
}
src/main/java/com/moral/service/impl/HistoryMinutelyServiceImpl.java
@@ -4,6 +4,8 @@
import static org.apache.commons.lang3.time.DateUtils.truncate;
import static org.springframework.util.ObjectUtils.isEmpty;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collections;
@@ -116,107 +118,13 @@
        return resultMap;
    }
    public Map<String, List<Object>> getMonitorPointOrDeviceAvgData(Map<String, Object> parameters) throws Exception {
    public Map<String, List<Object>> getMonitorPointOrDeviceAvgData4Compare(Map<String, Object> parameters) throws Exception {
        Map<String, List<Object>> resultMap = new HashMap<String, List<Object>>();
        if (ObjectUtils.isEmpty(parameters)) {
            resultMap.put("c", null);
            return resultMap;
        }
        List<Map<String, Object>> resultList = getMonitorPointOrDeviceAvgData4Excel(parameters);
//        String type = (String) parameters.get("type");
//        String time = (String) parameters.get("time");
//        String format = (String) parameters.get("format");
//        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;
//            }
//
//        }
//        parameters.put("start", start);
//        parameters.put("end", end);
//
//        String sensorKey = (String) parameters.get("sensorKey");
//        String sensorKeyColumn = "AVG(json -> '$." + sensorKey + "[0]') " + sensorKey;
//        parameters.put("sensorKeyColumn", sensorKeyColumn);
//        List<Object> timeList = new ArrayList<Object>();
//        List<Object> dataList = new ArrayList<Object>();
//
//        if (!parameters.containsKey("mac")) {
//            Integer monitorPointId = Integer.valueOf((String) parameters.get("monitorPoint"));
//            List<Map<String, Object>> deviceVersions = deviceMapper.getDeviceVersionIdByMonitorPoint(monitorPointId);
//            ExecutorService threadPool = Executors.newCachedThreadPool();
//            CompletionService<List<Map<String, Object>>> cs = new ExecutorCompletionService<List<Map<String, Object>>>(threadPool);
//            //List<Future<Long>> list = new ArrayList<Future<Long>>();
//            List<Map<String, Object>> list = new ArrayList<Map<String,Object>>();
//            for (Map<String, Object> map : deviceVersions) {
//                cs.submit(new Callable<List<Map<String, Object>>>() {
//                    @Override
//                    public List<Map<String, Object>> call() throws Exception {
//                        Integer deviceVersionId = (Integer) map.get("deviceVersionId");
//                        List<String> macs = deviceMapper.getDeviceMacByMonitorPointAndDeviceVersion(monitorPointId, deviceVersionId);
//                        parameters.put("macs", macs);
//                        return historyMinutelyMapper.getMonitorPointOrDeviceAvgData(parameters);
//                    }
//                });
//            }
//            //Future<List<Map<String, Object>>> take = cs.take();
//            for (Map<String, Object> map : deviceVersions) {
//                list.addAll(cs.take().get());
//            }
//            Map<String, Map<String, Number>> result = new LinkedHashMap<String, Map<String, Number>>();
//            for (Map<String, Object> map : list) {
//                time = (String) map.get("time");
//                if (map.containsKey(sensorKey)) {
//                    Double data = (Double) map.get(sensorKey);
//                    Map<String, Number> number;
//                    Double sum;
//                    Integer count;
//                    if (result.containsKey(time)) {
//                        number = result.get(time);
//                        count = 1 + (Integer) number.get("count");
//                        sum = data + (Double) number.get("sum");
//                    } else {
//                        number = new HashMap<String, Number>();
//                        count = 1;
//                        sum = data;
//                    }
//                    number.put("count", count);
//                    number.put("sum", sum);
//                    number.put("avg", sum / count);
//                    result.put(time, number);
//                }
//            }
//            Iterator<Entry<String, Map<String, Number>>> iterator= result.entrySet().iterator();
//            while(iterator.hasNext()){
//                Entry<String, Map<String, Number>> entry = iterator.next();
//                String key = entry.getKey();
//                timeList.add(key.substring(key.length() - 2));
//                dataList.add(entry.getValue().get("avg"));
//            }
//
//        } else {
//            List<Map<String, Object>> demo1 = historyMinutelyMapper.getMonitorPointOrDeviceAvgData(parameters);
//            for (Map<String, Object> map : demo1) {
//                time = map.get("time").toString();
//                time =time.substring(time.length() - 2);
//                timeList.add(time);
//                dataList.add(map.get(sensorKey));
//            }
//        }
        List<Map<String, Object>> resultList = getMonitorPointOrDeviceAvgData(parameters);
        
        List<Object> timeList = new ArrayList<Object>();
        List<Object> dataList = new ArrayList<Object>();
@@ -262,7 +170,7 @@
            cs.submit(new Callable<Map<String, List<Object>>>() {
                @Override
                public Map<String, List<Object>> call() throws Exception {
                    return getMonitorPointOrDeviceAvgData(map);
                    return getMonitorPointOrDeviceAvgData4Compare(map);
                }
            });
            
@@ -315,7 +223,7 @@
    
    @Override
    public List<Map<String, Object>> getMonitorPointOrDeviceAvgData4Excel(Map<String, Object> parameters) throws Exception {
    public List<Map<String, Object>> getMonitorPointOrDeviceAvgData(Map<String, Object> parameters) throws Exception {
        List<Map<String, Object>> resul ;
        String type = (String) parameters.get("type");
@@ -402,7 +310,7 @@
                    } 
                    doubles[0] = sum;
                    doubles[1] = count;
                    doubles[2] = (sum / count);
                    doubles[2] = new BigDecimal(sum / count).setScale(3, RoundingMode.HALF_UP).doubleValue();
                    times.put(sensorKey, doubles);
                }
                result.put(time, times);