Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public String calculatePoiTraffic(){
- if(null == ContextBean.getCurrent().getSelectedPoi()){
- BuildixxUtils.addInfoMessage(JSFUtils.resolveExpressionAsString("#{res.misc_pls_sel_poi_first}"));
- return "";
- }
- personDataIdx = new HashMap();
- vehicleDataIdx = new HashMap();
- personData = new ArrayList<HashMap>();
- vehicleData = new ArrayList<HashMap>();
- poiData = new HashMap();
- AppModuleImpl am = (AppModuleImpl)ADFUtils.getApplicationModuleForDataControl("AppModuleDataControl");
- //Get POI history
- try{
- SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
- SimpleDateFormat filterDateFormat = new SimpleDateFormat("dd/MM/yyyy HH:mm");
- Date from = new Date(dateDay.getValue().getTime());
- Date to = new Date(dateDay.getValue().getTime());
- String fromString = dateFormat.format(from)+" 00:00";
- String toString = dateFormat.format(to)+" 23:59";
- oracle.jbo.domain.Date fromDate = new oracle.jbo.domain.Date(new java.sql.Timestamp(filterDateFormat.parse(fromString).getTime()));
- oracle.jbo.domain.Date toDate = new oracle.jbo.domain.Date(new java.sql.Timestamp(filterDateFormat.parse(toString).getTime()));
- filterPoiHistory(fromDate, toDate);
- ArrayList<Integer> personIds = new ArrayList<Integer>();
- for(HashMap pdata : personData){
- int personId = (Integer)pdata.get("PersonId");
- System.out.println(personId+" - "+pdata.toString());
- personIds.add(personId);
- }
- ArrayList<Integer> vehicleIds = new ArrayList<Integer>();
- for(HashMap vdata : vehicleData){
- int vehicleId = (Integer)vdata.get("VehicleId");
- System.out.println(vehicleId+" - "+vdata.toString());
- vehicleIds.add(vehicleId);
- }
- ArrayList<Integer> poiIds = new ArrayList<Integer>();
- poiIds.add(ContextBean.getCurrent().getSelectedPoi().getPoiId());
- if(personIds.size()>0){
- //get homePOI info - filter persons
- System.out.println("Get home poi for personIds : "+personIds.toString());
- // ViewObject personHomeVo = am.getPersonViewEx1();
- // personHomeVo.executeQuery();
- // RowSetIterator prowIter = personHomeVo.createRowSetIterator(null);
- // while (prowIter.hasNext()) {
- // Row row = prowIter.next();
- // int personId = (Integer)row.getAttribute("PersonId");
- // int homePoiId = (Integer)row.getAttribute("HomePoiId");
- // if(null != personDataIdx.get(personId)) {
- // HashMap pdata = personData.get((Integer)personDataIdx.get(personId));
- // pdata.put("HomePoiId",homePoiId);
- // pdata.put("GraphicalSymbol",row.getAttribute("GraphicalSymbol"));
- // poiIds.add(homePoiId);
- // }
- // }
- // prowIter.closeRowSetIterator();
- //
- ViewObject poiVo = am.getZonePoiView1();
- poiVo.setWhereClause("POI_ID in("+poiIds.toString().replace("[", "").replace("]", "")+")");
- poiVo.executeQuery();
- RowSetIterator poiIter = poiVo.createRowSetIterator(null);
- while (poiIter.hasNext()) {
- Row row = poiIter.next();
- HashMap poi = new HashMap();
- int poiId = (Integer)row.getAttribute("PoiId");
- PoiResult poiRes = new PoiResult(row);
- poi.put("json",LocationTools.genMarker(poiRes, true));
- poi.put("lat",row.getAttribute("Wgs84Latitude").toString());
- poi.put("lng",row.getAttribute("Wgs84Longitude").toString());
- poiData.put(poiId, poi);
- }
- // prowIter.closeRowSetIterator();
- //get pdday info
- ViewObject pddayVo = am.getVFmxPdDayView2();
- pddayVo.setWhereClause("PERSON_ID in("+personIds.toString().replace("[", "").replace("]", "")+") and DATE_DAY=to_date('"+dateFormat.format(from)+"','dd/MM/yyyy')");
- pddayVo.executeQuery();
- RowSetIterator rowIter = pddayVo.createRowSetIterator(null);
- while (rowIter.hasNext()) {
- Row row = rowIter.next();
- int personId = (Integer)row.getAttribute("PersonId");
- System.out.println("Found PD_DAY for person "+(personData.get((Integer)personDataIdx.get(personId))).get("PersonName"));
- BigDecimal hpDriverAloneKm = (BigDecimal)row.getAttribute("HpDriverAloneKm");
- BigDecimal hpDriverWithPKm = (BigDecimal)row.getAttribute("HpDriverWithPKm");
- BigDecimal hpPassengerKm = (BigDecimal)row.getAttribute("HpPassengerKm");
- BigDecimal hpPrivateKm = (BigDecimal)row.getAttribute("HpPrivateKm");
- BigDecimal totHpCalculated = (BigDecimal)row.getAttribute("TotHpCalculated");
- BigDecimal phDriverAloneKm = (BigDecimal)row.getAttribute("PhDriverAloneKm");
- BigDecimal phDriverWithPKm = (BigDecimal)row.getAttribute("PhDriverWithPKm");
- BigDecimal phPassengerKm = (BigDecimal)row.getAttribute("PhPassengerKm");
- BigDecimal phPrivateKm = (BigDecimal)row.getAttribute("PhPrivateKm");
- BigDecimal totPhCalculated = (BigDecimal)row.getAttribute("TotPhCalculated");
- System.out.println("hpKm : "+totHpCalculated+", phKm : "+totPhCalculated);
- HashMap pdata = personData.get((Integer)personDataIdx.get(personId));
- pdata.put("TotHpCalculated",totHpCalculated);
- pdata.put("TotPhCalculated",totPhCalculated);
- pdata.put("HpPrivateKm",row.getAttribute("HpPrivateKm"));
- pdata.put("PhPrivateKm",row.getAttribute("PhPrivateKm"));
- }
- rowIter.closeRowSetIterator();
- }
- if(vehicleIds.size()>0){
- //get vehicledata
- System.out.println("Get data for vehicleIds : "+vehicleIds.toString());
- ViewObject vehVo = am.getVehicleViewEx1();
- vehVo.executeQuery();
- RowSetIterator vrowIter = vehVo.createRowSetIterator(null);
- while (vrowIter.hasNext()) {
- Row row = vrowIter.next();
- int vehicleId = (Integer)row.getAttribute("VehicleId");
- if(null != vehicleDataIdx.get(vehicleId)) {
- HashMap vdata = vehicleData.get((Integer)vehicleDataIdx.get(vehicleId));
- vdata.put("Brand",row.getAttribute("Brand"));
- vdata.put("Model",row.getAttribute("Model"));
- vdata.put("GraphicalSymbol",row.getAttribute("GraphicalSymbol"));
- }
- }
- vrowIter.closeRowSetIterator();
- //sort person data on vehicle id
- Comparator<Map> comp = new Comparator<Map>() {
- @Override
- public int compare(Map o1, Map o2) {
- int vehId = (Integer)o1.get("VehicleId");
- int vehId2 = (Integer)o2.get("VehicleId");
- return vehId<vehId2 ? -1 : vehId>vehId2 ? 1 : 0;
- }
- };
- Collections.sort(personData, comp);
- Collections.sort(vehicleData, comp);
- //remove filtered vehicle/persons
- personDataIdx.clear();
- vehicleDataIdx.clear();
- vehicleIds = new ArrayList<Integer>();
- personIds = new ArrayList<Integer>();
- for (Iterator<HashMap> viterator = vehicleData.iterator(); viterator.hasNext(); ) {
- HashMap vdata = viterator.next();
- if(null != vdata.get("Brand")){
- int vehicleId = (Integer)vdata.get("VehicleId");
- vehicleIds.add(vehicleId);
- vehicleDataIdx.put(vehicleId, vehicleIds.size()-1);
- }
- else{
- viterator.remove();
- }
- }
- ArrayList<Integer> filteredVehicleIds = new ArrayList<Integer>();
- for (Iterator<HashMap> piterator = personData.iterator(); piterator.hasNext(); ) {
- HashMap pdata = piterator.next();
- if(!vehicleIds.contains(pdata.get("VehicleId")) || null == pdata.get("HomePoiId"))
- piterator.remove();
- else{
- int personId = (Integer)pdata.get("PersonId");
- int vehicleId = (Integer)pdata.get("VehicleId");
- personIds.add(personId);
- filteredVehicleIds.add(vehicleId);
- personDataIdx.put(personId, personIds.size()-1);
- }
- }
- int vehIdx = 0;
- for (Iterator<HashMap> viterator = vehicleData.iterator(); viterator.hasNext(); ) {
- HashMap vdata = viterator.next();
- int vehicleId = (Integer)vdata.get("VehicleId");
- if(!filteredVehicleIds.contains(vehicleId))
- viterator.remove();
- else{
- vehicleDataIdx.put(vehicleId, vehIdx);
- vehIdx++;
- }
- }
- //get vehicle history info
- ViewObject vhistVo = am.getVVehicleTrackingView2();
- vhistVo.setWhereClause("GUI_USER_ID="+UserBean.getCurrent().getUserId()+" and VEHICLE_ID in("+filteredVehicleIds.toString().replace("[", "").replace("]", "")+") and GPS_FULL_DATE between to_date('"+fromString+"','dd/MM/yyyy hh24:mi') and to_date('"+toString+"','dd/MM/yyyy hh24:mi')");
- vhistVo.setOrderByClause("GPS_FULL_DATE, EVENT_ID");
- vhistVo.executeQuery();
- RowSetIterator rowIter = vhistVo.createRowSetIterator(null);
- genTrips(rowIter);
- rowIter.closeRowSetIterator();
- }
- JSONObject jsonFeed = genTripsJSON(tripType);
- String jsonData = "callBackResult(" + jsonFeed.toString() + ")";
- ADFContext.getCurrent().getSessionScope().put(mapSubtype, jsonData);
- }catch(Exception e){
- e.printStackTrace();
- log.error(e.getMessage(), e);
- }
- return "poiTraffic";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement