| | |
| | | import java.util.concurrent.ExecutorCompletionService;
|
| | | import java.util.concurrent.ExecutorService;
|
| | | import java.util.concurrent.Executors;
|
| | | import java.util.stream.Collectors;
|
| | |
|
| | | import javax.annotation.Resource;
|
| | |
|
| | |
| | | * @return
|
| | | */
|
| | | @Override
|
| | | public Map<String, List<List<PairData>>> queryLineChartDateByCrieria(LineChartCriteria lineChartCriteria){
|
| | | Map<String,List<List<PairData>>> listMap = new HashMap<>();
|
| | | for(String sensorKey:lineChartCriteria.getSensorKeys()){
|
| | | TimePeriod timePeriod = lineChartCriteria.getTimePeriod();
|
| | | List<DataCondition> dataConditionList = lineChartCriteria.getDataConditions();
|
| | | List<List<PairData>> list = new ArrayList<>();
|
| | | dataConditionList.forEach(item -> {
|
| | | List<PairData> pairDataList = queryOneLineChartDateByCrieria(sensorKey,timePeriod,item);
|
| | | list.add(pairDataList);
|
| | | });
|
| | | listMap.put(sensorKey,list);
|
| | | }
|
| | |
|
| | | public Map<String, List<List<Double>>> queryLineChartDateByCrieria(LineChartCriteria lineChartCriteria){
|
| | | Map<String,List<List<Double>>> listMap = new HashMap<>();
|
| | | List<String> sensorKeys = lineChartCriteria.getSensorKeys();
|
| | | List<DataCondition> dataConditionList = lineChartCriteria.getDataConditions();
|
| | | TimePeriod timePeriod = lineChartCriteria.getTimePeriod();
|
| | | sensorKeys.forEach(sensorKey -> {
|
| | | listMap.put(sensorKey,new ArrayList<List<Double>>(dataConditionList.size()));
|
| | | });
|
| | | dataConditionList.forEach(dataCondition -> {
|
| | | Map<String,List<Double>> dataMap = queryOneLineChartDateByCrieria(sensorKeys,timePeriod,dataCondition);
|
| | | // 数据装载
|
| | | listMap.forEach( (sensorKey,list) -> {
|
| | | List<Double> rowData = dataMap.get(sensorKey);
|
| | | list.add(rowData);
|
| | | });
|
| | | });
|
| | | return listMap;
|
| | | }
|
| | |
|
| | | /**
|
| | | * 根据线性表单的条件规则,获取一条线性表单数据
|
| | | * @param sensorKey
|
| | | * 根据线性表单的条件规则,获取一条线性表单数据,包含 所有检测项目
|
| | | * @param sensorKeys
|
| | | * @param timePeriod
|
| | | * @param dataCondition
|
| | | * @return
|
| | | */
|
| | | public List<PairData> queryOneLineChartDateByCrieria(String sensorKey, TimePeriod timePeriod, DataCondition dataCondition){
|
| | | public Map<String,List<Double>> queryOneLineChartDateByCrieria(List<String> sensorKeys, TimePeriod timePeriod, DataCondition dataCondition){
|
| | | List<String> timeList = ReportTimeFormat.makeTimeList(timePeriod);
|
| | | List<PairData> lineChartDatas = historyMinutelyMapper.selectLineChartDateByCrieria(sensorKey,timePeriod,dataCondition);
|
| | | List<PairData> lineChartDatasWithEmpty = new ArrayList<>();
|
| | | List<Map<String,Object>> lineChartDatas = historyMinutelyMapper.selectLineChartDateByCrieria(sensorKeys,timePeriod,dataCondition);
|
| | | Map<String,List<Double>> lineChartDatasWithEmpty = new HashMap<>();
|
| | | // lineChartDatasWithEmpty 初始化
|
| | | sensorKeys.forEach(sensorKey -> {
|
| | | lineChartDatasWithEmpty.put(sensorKey,timeList.stream().map(time -> {
|
| | | Double data = null;
|
| | | return data;
|
| | | }).collect(Collectors.toList()));
|
| | | });
|
| | | // m 为查询data的index,此处要防止m越界
|
| | | int m = 0;
|
| | | int dataLength = lineChartDatas.size()-1;
|
| | | m = dataLength>-1?0:-1;
|
| | | if(m>-1){
|
| | | if(m >-1){
|
| | | for(int n =0;n<timeList.size();n++){
|
| | | String time = timeList.get(n);
|
| | | if(m>-1){
|
| | | PairData pairData = lineChartDatas.get(m);
|
| | | String keyTime = pairData.getCategory();
|
| | | if(time.equals(keyTime)){
|
| | | lineChartDatasWithEmpty.add(pairData);
|
| | | m = m<dataLength ? m+1 : -1;
|
| | | }else{
|
| | | lineChartDatasWithEmpty.add(generateEmptyData(time));
|
| | | }
|
| | | }else {
|
| | | lineChartDatasWithEmpty.add(generateEmptyData(time));
|
| | | }
|
| | |
|
| | | if(m>-1) {
|
| | | String time = timeList.get(n);
|
| | | Map<String,Object> rowData = lineChartDatas.get(m);
|
| | | String keyTime = rowData.get("format_time").toString();
|
| | | if(time.equals(keyTime)){
|
| | | // list to map
|
| | | int finalN = n;
|
| | | sensorKeys.forEach(sensorKey -> {
|
| | | 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;
|
| | | }
|
| | | }
|
| | | }
|
| | | }else{
|
| | | fillEmptyDataToList(timeList,lineChartDatasWithEmpty);
|
| | | }
|
| | | return lineChartDatasWithEmpty;
|
| | | }
|
| | | private PairData generateEmptyData(String time) {
|
| | | PairData pairData = new PairData();
|
| | | pairData.setCategory(time);
|
| | | pairData.setValue(null);
|
| | | return pairData;
|
| | | }
|
| | | private void fillEmptyDataToList(List<String> timeList,List<PairData> lineChartDatasWithEmpty){
|
| | | timeList.forEach( time ->{
|
| | | PairData pairData = generateEmptyData(time);
|
| | | lineChartDatasWithEmpty.add(pairData);
|
| | | });
|
| | | }
|
| | | }
|