Пример #1
0
 public static String getQuery(Map params) {
   if (params.containsKey("param1")) {
     params = (Map) params.get("param1");
   }
   Boolean disaggregated =
       StringHelper.isBlank(params, "disaggregated")
           ? false
           : Boolean.parseBoolean(StringHelper.getValue(params, "disaggregated"));
   return (disaggregated)
       ? getDisaggregatedSelect() + getPredicates(params) + getDisAggregatedGroupBy()
       : getAggregateSelect() + getPredicates(params) + getAggregateGroupBy();
 }
Пример #2
0
  private static String getPredicates(Map params) {
    String predicate = " WHERE r.status in ('APPROVED','RELEASED') ";
    String facilityTypeId =
        StringHelper.isBlank(params, "facilityType")
            ? null
            : ((String[]) params.get("facilityType"))[0];
    String facilityName =
        StringHelper.isBlank(params, "facilityName")
            ? null
            : ((String[]) params.get("facilityName"))[0];
    String period =
        StringHelper.isBlank(params, "period") ? null : ((String[]) params.get("period"))[0];
    String productCategory = StringHelper.getValue(params, "productCategory");
    String program =
        StringHelper.isBlank(params, "program") ? null : ((String[]) params.get("program"))[0];
    String product =
        StringHelper.isBlank(params, "product") ? null : ((String[]) params.get("product"))[0];
    String zone = StringHelper.isBlank(params, "zone") ? null : ((String[]) params.get("zone"))[0];
    String schedule =
        StringHelper.isBlank(params, "schedule") ? null : ((String[]) params.get("schedule"))[0];
    String facilityId =
        StringHelper.isBlank(params, "facility") ? null : ((String[]) params.get("facility"))[0];

    predicate += " and r.periodId = " + period;
    predicate += " and r.programId = " + program;

    if (productCategory != null
        && !productCategory.equals("undefined")
        && !productCategory.isEmpty()
        && !productCategory.equals("0")
        && !productCategory.equals("-1")) {
      predicate += "and pps.productCategoryId = " + productCategory;
    }

    if (product != null
        && !product.equals("undefined")
        && !product.isEmpty()
        && !product.equals("0")
        && !product.equals("-1")) {
      predicate += " and products.id = " + product;
    }

    if (schedule != null
        && !schedule.equals("undefined")
        && !schedule.isEmpty()
        && !schedule.equals("0")
        && !schedule.equals("-1")) {
      predicate += " and processing_schedules.id = " + schedule;
    }

    if (zone != null && !zone.equals("0") && !zone.isEmpty() && !zone.endsWith("undefined")) {
      predicate +=
          (" and (gz.district_id = "
              + zone
              + " or gz.zone_id = "
              + zone
              + " or gz.region_id = "
              + zone
              + " or gz.parent = "
              + zone
              + " )");
    }

    if (facilityTypeId != null
        && !facilityTypeId.equals("undefined")
        && !facilityTypeId.isEmpty()
        && !facilityTypeId.equals("0")
        && !facilityTypeId.equals("-1")) {
      predicate += " and facilities.typeid = " + facilityTypeId;
    }

    if (facilityName != null && !facilityName.equals("undefined") && !facilityName.isEmpty()) {
      predicate += " and facilities.name = '" + facilityName + "'";
    }

    if (facilityId != null
        && !facilityId.equals("")
        && !facilityId.equals("undefined")
        && !facilityId.equals("0")) {
      predicate += " and facilities.id = " + facilityId + "";
    }
    return predicate;
  }