Advertisement
psi_mmobile

Untitled

Jul 26th, 2021
1,251
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 9.59 KB | None | 0 0
  1.   public String calculatePoiTraffic(){
  2.     if(null == ContextBean.getCurrent().getSelectedPoi()){
  3.       BuildixxUtils.addInfoMessage(JSFUtils.resolveExpressionAsString("#{res.misc_pls_sel_poi_first}"));      
  4.       return "";
  5.     }
  6.    
  7.     personDataIdx = new HashMap();
  8.     vehicleDataIdx = new HashMap();
  9.     personData = new ArrayList<HashMap>();
  10.     vehicleData = new ArrayList<HashMap>();
  11.     poiData = new HashMap();
  12.    
  13.     AppModuleImpl am = (AppModuleImpl)ADFUtils.getApplicationModuleForDataControl("AppModuleDataControl");
  14.     //Get POI history
  15.     try{
  16.       SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
  17.       SimpleDateFormat filterDateFormat = new SimpleDateFormat("dd/MM/yyyy HH:mm");
  18.       Date from = new Date(dateDay.getValue().getTime());
  19.       Date to = new Date(dateDay.getValue().getTime());
  20.       String fromString = dateFormat.format(from)+" 00:00";
  21.       String toString = dateFormat.format(to)+" 23:59";
  22.       oracle.jbo.domain.Date fromDate = new oracle.jbo.domain.Date(new java.sql.Timestamp(filterDateFormat.parse(fromString).getTime()));
  23.       oracle.jbo.domain.Date toDate = new oracle.jbo.domain.Date(new java.sql.Timestamp(filterDateFormat.parse(toString).getTime()));
  24.       filterPoiHistory(fromDate, toDate);
  25.      
  26.       ArrayList<Integer> personIds = new ArrayList<Integer>();
  27.       for(HashMap pdata : personData){
  28.         int personId = (Integer)pdata.get("PersonId");
  29.         System.out.println(personId+" - "+pdata.toString());
  30.         personIds.add(personId);
  31.       }
  32.      
  33.       ArrayList<Integer> vehicleIds = new ArrayList<Integer>();
  34.       for(HashMap vdata : vehicleData){
  35.         int vehicleId = (Integer)vdata.get("VehicleId");
  36.         System.out.println(vehicleId+" - "+vdata.toString());
  37.         vehicleIds.add(vehicleId);
  38.       }
  39.      
  40.       ArrayList<Integer> poiIds = new ArrayList<Integer>();
  41.       poiIds.add(ContextBean.getCurrent().getSelectedPoi().getPoiId());
  42.       if(personIds.size()>0){
  43.        
  44.         //get homePOI info - filter persons
  45.         System.out.println("Get home poi for personIds : "+personIds.toString());
  46.        // ViewObject personHomeVo = am.getPersonViewEx1();
  47.       //  personHomeVo.executeQuery();
  48.       //  RowSetIterator prowIter = personHomeVo.createRowSetIterator(null);
  49. //        while (prowIter.hasNext()) {
  50. //          Row row = prowIter.next();
  51. //          int personId = (Integer)row.getAttribute("PersonId");
  52. //          int homePoiId = (Integer)row.getAttribute("HomePoiId");
  53. //          if(null != personDataIdx.get(personId)) {
  54. //            HashMap pdata = personData.get((Integer)personDataIdx.get(personId));
  55. //            pdata.put("HomePoiId",homePoiId);
  56. //            pdata.put("GraphicalSymbol",row.getAttribute("GraphicalSymbol"));
  57. //            poiIds.add(homePoiId);
  58. //          }
  59. //        }
  60. //        prowIter.closeRowSetIterator();
  61. //        
  62.         ViewObject poiVo = am.getZonePoiView1();
  63.         poiVo.setWhereClause("POI_ID in("+poiIds.toString().replace("[", "").replace("]", "")+")");
  64.         poiVo.executeQuery();
  65.         RowSetIterator poiIter = poiVo.createRowSetIterator(null);
  66.         while (poiIter.hasNext()) {
  67.           Row row = poiIter.next();
  68.           HashMap poi = new HashMap();
  69.           int poiId = (Integer)row.getAttribute("PoiId");
  70.           PoiResult poiRes = new PoiResult(row);
  71.           poi.put("json",LocationTools.genMarker(poiRes, true));
  72.           poi.put("lat",row.getAttribute("Wgs84Latitude").toString());
  73.           poi.put("lng",row.getAttribute("Wgs84Longitude").toString());
  74.           poiData.put(poiId, poi);
  75.         }
  76. //        prowIter.closeRowSetIterator();
  77.        
  78.         //get pdday info
  79.         ViewObject pddayVo = am.getVFmxPdDayView2();
  80.         pddayVo.setWhereClause("PERSON_ID in("+personIds.toString().replace("[", "").replace("]", "")+") and DATE_DAY=to_date('"+dateFormat.format(from)+"','dd/MM/yyyy')");
  81.         pddayVo.executeQuery();
  82.         RowSetIterator rowIter = pddayVo.createRowSetIterator(null);
  83.         while (rowIter.hasNext()) {
  84.           Row row = rowIter.next();
  85.           int personId = (Integer)row.getAttribute("PersonId");
  86.           System.out.println("Found PD_DAY for person "+(personData.get((Integer)personDataIdx.get(personId))).get("PersonName"));  
  87.           BigDecimal hpDriverAloneKm = (BigDecimal)row.getAttribute("HpDriverAloneKm");
  88.           BigDecimal hpDriverWithPKm = (BigDecimal)row.getAttribute("HpDriverWithPKm");
  89.           BigDecimal hpPassengerKm = (BigDecimal)row.getAttribute("HpPassengerKm");
  90.           BigDecimal hpPrivateKm = (BigDecimal)row.getAttribute("HpPrivateKm");
  91.           BigDecimal totHpCalculated = (BigDecimal)row.getAttribute("TotHpCalculated");
  92.            
  93.           BigDecimal phDriverAloneKm = (BigDecimal)row.getAttribute("PhDriverAloneKm");
  94.           BigDecimal phDriverWithPKm = (BigDecimal)row.getAttribute("PhDriverWithPKm");
  95.           BigDecimal phPassengerKm = (BigDecimal)row.getAttribute("PhPassengerKm");
  96.           BigDecimal phPrivateKm = (BigDecimal)row.getAttribute("PhPrivateKm");
  97.           BigDecimal totPhCalculated = (BigDecimal)row.getAttribute("TotPhCalculated");
  98.          
  99.           System.out.println("hpKm : "+totHpCalculated+", phKm : "+totPhCalculated);
  100.           HashMap pdata = personData.get((Integer)personDataIdx.get(personId));
  101.           pdata.put("TotHpCalculated",totHpCalculated);
  102.           pdata.put("TotPhCalculated",totPhCalculated);
  103.           pdata.put("HpPrivateKm",row.getAttribute("HpPrivateKm"));
  104.           pdata.put("PhPrivateKm",row.getAttribute("PhPrivateKm"));
  105.         }
  106.         rowIter.closeRowSetIterator();  
  107.       }
  108.      
  109.       if(vehicleIds.size()>0){
  110.        
  111.         //get vehicledata
  112.         System.out.println("Get data for vehicleIds : "+vehicleIds.toString());
  113.         ViewObject vehVo = am.getVehicleViewEx1();
  114.         vehVo.executeQuery();
  115.         RowSetIterator vrowIter = vehVo.createRowSetIterator(null);
  116.         while (vrowIter.hasNext()) {
  117.           Row row = vrowIter.next();
  118.           int vehicleId = (Integer)row.getAttribute("VehicleId");
  119.           if(null != vehicleDataIdx.get(vehicleId)) {
  120.             HashMap vdata = vehicleData.get((Integer)vehicleDataIdx.get(vehicleId));
  121.             vdata.put("Brand",row.getAttribute("Brand"));
  122.             vdata.put("Model",row.getAttribute("Model"));
  123.             vdata.put("GraphicalSymbol",row.getAttribute("GraphicalSymbol"));
  124.           }
  125.         }
  126.         vrowIter.closeRowSetIterator();
  127.        
  128.         //sort person data on vehicle id
  129.         Comparator<Map> comp = new Comparator<Map>() {
  130.             @Override
  131.             public int compare(Map o1, Map o2) {
  132.                 int vehId = (Integer)o1.get("VehicleId");
  133.                 int vehId2 = (Integer)o2.get("VehicleId");
  134.                 return vehId<vehId2 ? -1 : vehId>vehId2 ? 1 : 0;
  135.             }
  136.         };
  137.         Collections.sort(personData, comp);
  138.         Collections.sort(vehicleData, comp);
  139.        
  140.         //remove filtered vehicle/persons
  141.         personDataIdx.clear();
  142.         vehicleDataIdx.clear();
  143.         vehicleIds = new ArrayList<Integer>();
  144.         personIds = new ArrayList<Integer>();
  145.         for (Iterator<HashMap> viterator = vehicleData.iterator(); viterator.hasNext(); ) {
  146.           HashMap vdata = viterator.next();
  147.             if(null != vdata.get("Brand")){
  148.               int vehicleId = (Integer)vdata.get("VehicleId");
  149.               vehicleIds.add(vehicleId);
  150.               vehicleDataIdx.put(vehicleId, vehicleIds.size()-1);  
  151.             }
  152.             else{
  153.               viterator.remove();
  154.             }
  155.         }
  156.        
  157.         ArrayList<Integer> filteredVehicleIds = new ArrayList<Integer>();
  158.         for (Iterator<HashMap> piterator = personData.iterator(); piterator.hasNext(); ) {
  159.           HashMap pdata = piterator.next();
  160.           if(!vehicleIds.contains(pdata.get("VehicleId")) || null == pdata.get("HomePoiId"))
  161.             piterator.remove();
  162.           else{
  163.             int personId = (Integer)pdata.get("PersonId");
  164.             int vehicleId = (Integer)pdata.get("VehicleId");
  165.             personIds.add(personId);
  166.             filteredVehicleIds.add(vehicleId);
  167.             personDataIdx.put(personId, personIds.size()-1);  
  168.           }
  169.         }
  170.        
  171.         int vehIdx = 0;
  172.         for (Iterator<HashMap> viterator = vehicleData.iterator(); viterator.hasNext(); ) {
  173.           HashMap vdata = viterator.next();
  174.           int vehicleId = (Integer)vdata.get("VehicleId");
  175.           if(!filteredVehicleIds.contains(vehicleId))
  176.             viterator.remove();
  177.           else{
  178.             vehicleDataIdx.put(vehicleId, vehIdx);
  179.             vehIdx++;
  180.           }
  181.         }
  182.        
  183.         //get vehicle history info
  184.         ViewObject vhistVo = am.getVVehicleTrackingView2();
  185.         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')");
  186.         vhistVo.setOrderByClause("GPS_FULL_DATE, EVENT_ID");
  187.         vhistVo.executeQuery();
  188.         RowSetIterator rowIter = vhistVo.createRowSetIterator(null);
  189.         genTrips(rowIter);
  190.         rowIter.closeRowSetIterator();  
  191.       }
  192.       JSONObject jsonFeed = genTripsJSON(tripType);
  193.       String jsonData = "callBackResult(" + jsonFeed.toString() + ")";
  194.       ADFContext.getCurrent().getSessionScope().put(mapSubtype, jsonData);
  195.     }catch(Exception e){
  196.       e.printStackTrace();
  197.       log.error(e.getMessage(), e);  
  198.     }
  199.    
  200.    
  201.     return "poiTraffic";
  202.   }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement