/** * ***************************** 获取故障信息,将被":"隔开字符串转换成map集合 * * @param dparamMapDatas * @return */ private Map<Integer, DparamMapValue> stringTransformMap(int dparamIsMap, String dparamMapDatas) { Map<Integer, DparamMapValue> map = new HashMap<Integer, DparamMapValue>(); if (dparamIsMap != 0) { try { String[] warns = dparamMapDatas.split(","); for (String s : warns) { String[] elements = s.split(":"); int key = Integer.parseInt(elements[0]); DparamMapValue dmv = new DparamMapValue(); dmv.setKey(Integer.parseInt(elements[0])); try { dmv.setValue(elements[1]); } catch (ArrayIndexOutOfBoundsException e) { dmv.setValue("110"); map.put(key, dmv); } if (elements.length > 2) { dmv.setSwitchStatus(Integer.parseInt(elements[2])); dmv.setSwitchColor(Integer.parseInt(elements[3])); } map.put(key, dmv); } } catch (java.lang.NumberFormatException e) { } catch (Exception e) { e.printStackTrace(); } } return map; }
private void begin(String vin, List<MyDParam> myDParams) throws Exception { Processing processing = new Processing(); Date endTime = startDate; processing.setEndTime(endTime); processing.setVin(vin); List<Data> car_list = dataService.getAllDatas(vin, startDate); Data data; StringBuilder key = new StringBuilder(" ("); key.append( "SN,VIN,Time,LocateIsValid,LocateTime,LocateLongitude,LocateLatitude,LocateSpeed,LocateDirection,"); int sign = 0; // 批量插入数据的标志,等于0时需要获取key StringBuilder values = new StringBuilder(); MyDParam myDParam; int size = myDParams.size(); if (size == 0) { System.out.println(vin + " has not param to analys"); if (Processer.vintime_map.get(vin) == null) { processingService.add(processing); } else { processingService.update(processing); } Processer.vintime_map.put(vin, endTime); return; } if (car_list.size() == 0) { System.out.println(vin + " has not data to analys"); if (Processer.vintime_map.get(vin) == null) { processingService.add(processing); } else { processingService.update(processing); } Processer.vintime_map.put(vin, endTime); return; } // 获取表的字段 // Map<String , String> single = new HashMap<String, // String>();////防止重复的参数放入key for (int i = 0; i < size; i++) { myDParam = myDParams.get(i); String namePinYin = myDParam.getdParam().getNamePinYin(); if (namePinYin != null && !namePinYin.equals("")) { // //if (single.get(namePinYin) != null ) { // //System.out.println("double key :"+namePinYin+" the name is :" // +myDParam.getdParam().getDparamName()); // //continue; // //} else { // //single.put(namePinYin, ""); key.append(namePinYin + ","); // } } else { key.append(pinyin(myDParam.getdParam().getDparamName()) + ","); // 获取表的字段名 } } key = key.delete(key.length() - 1, key.length()); key.append(") "); // 获取分析后的数据,并插入表中 for (Iterator<Data> iterator = car_list.iterator(); iterator.hasNext(); ) { data = iterator.next(); byte[] bDatas = null; StringBuilder value = new StringBuilder(" ("); value.append( data.getSn() + ",'" + data.getVin() + "','" + data.getTime() + "'," + data.getLocateIsValid() + ",'" + data.getLocateTime() + "'," + data.getLocateLongitude() + "," + data.getLocateLatitude() + "," + data.getLocateSpeed() + "," + data.getLocateDirection() + ","); for (int i = 0; i < size; i++) { // 逐个分析参数 myDParam = myDParams.get(i); bDatas = data.getDatas(); endTime = data.getTime(); processing.setEndTime(endTime); float param = getParam(bDatas, myDParam); // 解析数据 if (myDParam.getdParam().getDparamIsMap() == 1) { int paramInt = (int) param; DparamMapValue dmv = myDParam.getDmv().get(paramInt); if (dmv == null) { value.append("'" + paramInt + "',"); } else { value.append("'" + dmv.getValue() + "',"); } } else { value.append(param + ","); } } value = value.delete(value.length() - 1, value.length()); value.append(") "); values.append(value + ","); sign++; if (sign >= 100) { values = values.delete(values.length() - 1, values.length()); // 插入参数 dParamService.insertDParams(vin, key.toString(), values.toString()); values.delete(0, values.length()); sign = 1; } } if (values.length() == 0) { System.out.println(vin + " has no data at that time"); } else { values = values.delete(values.length() - 1, values.length()); // 插入参数 dParamService.insertDParams(vin, key.toString(), values.toString()); values.delete(0, values.length()); } if (Processer.vintime_map.get(vin) == null) { processingService.add(processing); } else { processingService.update(processing); } Processer.vintime_map.put(vin, endTime); }