Exemplo n.º 1
0
 /**
  * CONTEXT公式
  *
  * @param cf
  * @return
  */
 public String eval_CONTEXT(String cf) {
   String regex = "(@CONTEXT\\([a-zA-Z0-9\"-\\/_ 年月日:,]+\\))"; // 匹配@VALUE公式
   Pattern p = Pattern.compile(regex);
   Matcher mt = p.matcher(cf);
   while (mt.find()) {
     String group = mt.group();
     String tmpArray[] = group.split("\"");
     String varName = tmpArray[1].toUpperCase();
     Object value = this.context.getVar(varName);
     if (value == null) {
       value = "";
     } else {
       if (value instanceof Date) {
         String fm = "yyyy-MM-dd";
         if (tmpArray.length > 3) {
           fm = tmpArray[3];
         }
         value = DateUtils.formatDate((Date) value, fm);
       }
     }
     cf = mt.replaceFirst("\"" + value + "\"");
     mt = p.matcher(cf);
   }
   return cf;
 }
Exemplo n.º 2
0
 /**
  * 计算@SYSDT公式
  *
  * @param cf
  * @return
  */
 public String eval_SYSDT(String cf) {
   String regex = "@SYSDT\\(\"[yMdhmsiH年月日时分秒: -]*\"\\)"; // 匹配@VALUE公式
   Pattern p = Pattern.compile(regex);
   Matcher mt = p.matcher(cf);
   while (mt.find()) {
     String group = mt.group();
     String fm = group.substring(group.indexOf("\"") + 1, group.lastIndexOf("\""));
     String dt = DateUtils.getDate(fm);
     cf = mt.replaceFirst("\"" + dt + "\"");
     mt = p.matcher(cf);
   }
   return cf;
 }
Exemplo n.º 3
0
 /** 描述:判断日期是否合法 时间:2010-5-6 作者:童贝 参数: 返回值: 抛出异常: */
 public boolean isDateLawful(String keyList, String flflag) {
   boolean result = true;
   Map<String, String> keyMap = new HashMap<String, String>();
   String[] keys = keyList.split("!");
   for (String key : keys) {
     String[] nameAndValue = key.split(",");
     if (nameAndValue.length == 2) {
       String name = nameAndValue[0];
       String value = nameAndValue[1];
       keyMap.put(name, value);
     }
   }
   String startNian = keyMap.get(TjInterFace.SNIAN);
   String startYue = keyMap.get(TjInterFace.SYUE);
   String startRi = keyMap.get(TjInterFace.SRI);
   String endNian = keyMap.get(TjInterFace.ENIAN);
   String endYue = keyMap.get(TjInterFace.EYUE);
   String endRi = keyMap.get(TjInterFace.ERI);
   if ("1".equals(flflag)) {
     long res =
         this.compareStringTime(
             endNian
                 + "-"
                 + (endYue.length() == 1 ? "0" + endYue : endYue)
                 + "-"
                 + (endRi.length() == 1 ? "0" + endRi : endRi),
             startNian
                 + "-"
                 + (startYue.length() == 1 ? "0" + startYue : startYue)
                 + "-"
                 + (startRi.length() == 1 ? "0" + startRi : startRi),
             "yyyy-MM-dd");
     if (res < 0) {
       result = false;
     } else {
       // 限定日期在两个月之间(包括2个月)
       String startDate =
           startNian
               + "-"
               + (startYue.length() == 1 ? "0" + startYue : startYue)
               + "-"
               + (startRi.length() == 1 ? "0" + startRi : startRi);
       String twoMonth =
           DateUtils.getNextDate(DateUtils.StrToDate(startDate, "yyyy-MM-dd"), 2, "yyyy-MM-dd");
       long ps =
           this.compareStringTime(
               twoMonth,
               endNian
                   + "-"
                   + (endYue.length() == 1 ? "0" + endYue : endYue)
                   + "-"
                   + (endRi.length() == 1 ? "0" + endRi : endRi),
               "yyyy-MM-dd");
       if (ps < 0) {
         result = false;
       }
     }
   } else if ("2".equals(flflag)) {
     long res =
         this.compareStringTime(
             endNian + "-" + endYue + "-1", startNian + "-" + startYue + "-1", "yyyy-MM-dd");
     if (res < 0) {
       result = false;
     }
   } else if ("3".equals(flflag)) {
     Integer sNian = Integer.parseInt(startNian);
     Integer eNian = Integer.parseInt(endNian);
     if (sNian > eNian) {
       result = false;
     }
   }
   return result;
 }
Exemplo n.º 4
0
  /** 描述:初始化起始时间到终止时间之间的每天的值 时间:2010-5-5 作者:童贝 参数:keyMap 查询条件集合,flflag 分类标识,item 选择的字段 返回值: 抛出异常: */
  public List<Map<String, String>> initQssjToZzsjData(
      Map<String, String> keyMap, String flflag, String item) {
    List<Map<String, String>> result = new ArrayList<Map<String, String>>();
    String startNian = keyMap.get(TjInterFace.SNIAN);
    String startYue = keyMap.get(TjInterFace.SYUE);
    String startRi = keyMap.get(TjInterFace.SRI);
    String endNian = keyMap.get(TjInterFace.ENIAN);
    String endYue = keyMap.get(TjInterFace.EYUE);
    String endRi = keyMap.get(TjInterFace.ERI);

    if ("1".equals(flflag)) {
      while (true) {
        if (startNian.equals(endNian) && startYue.equals(endYue)) {
          int start = new Integer(startRi);
          int end = new Integer(endRi);
          for (int i = start; i <= end; i++) {
            Map<String, String> map = new HashMap<String, String>();
            map.put(TjInterFace.NIAN, startNian);
            map.put(TjInterFace.YUE, startYue);
            map.put(TjInterFace.RI, i + "");
            map.put(item, "0");
            result.add(map);
          }
          break;
        } else {
          int start = new Integer(startRi);
          // 本月的最后一天
          String lastDate = DateUtils.getLastDate(startNian + "-" + startYue + "-1");
          String endDate = DateUtils.getDate(DateUtils.StrToDate(lastDate, ""), "dd");
          endDate = (endDate.charAt(0) == '0' ? endDate.substring(1) : endDate);
          int end = new Integer(endDate);
          for (int i = start; i <= end; i++) {
            Map<String, String> map = new HashMap<String, String>();
            map.put(TjInterFace.NIAN, startNian);
            map.put(TjInterFace.YUE, startYue);
            map.put(TjInterFace.RI, i + "");
            map.put(item, "0");
            result.add(map);
          }
          // 把日期往后推一个月
          Date curDate =
              DateUtils.StrToDate(startNian + "-" + startYue + "-" + startRi, "yyyy-MM-dd");
          String nextDate = DateUtils.getNextDate(curDate, 1, "yyyy-MM-dd");
          startNian = DateUtils.getDate(DateUtils.StrToDate(nextDate, ""), "yyyy");
          startYue = DateUtils.getDate(DateUtils.StrToDate(nextDate, ""), "MM");
          startYue = (startYue.charAt(0) == '0' ? startYue.substring(1) : startYue);
          startRi = "1";
        }
      }
    } else if ("2".equals(flflag)) {
      while (true) {
        if (startNian.equals(endNian)) {
          int start = new Integer(startYue);
          int end = new Integer(endYue);
          for (int i = start; i <= end; i++) {
            Map<String, String> map = new HashMap<String, String>();
            map.put(TjInterFace.NIAN, startNian);
            map.put(TjInterFace.YUE, i + "");
            map.put(item, "0");
            result.add(map);
          }
          break;
        } else {
          int start = new Integer(startYue);
          int end = 12;
          for (int i = start; i <= end; i++) {
            Map<String, String> map = new HashMap<String, String>();
            map.put(TjInterFace.NIAN, startNian);
            map.put(TjInterFace.YUE, i + "");
            map.put(item, "0");
            result.add(map);
          }
          // 直接是下一年
          startNian = new Integer(new Integer(startNian) + 1).toString();
          // 下一年的第一个月
          startYue = "1";
        }
      }
    } else if ("3".equals(flflag)) {
      int start = new Integer(startNian);
      int end = new Integer(endNian);
      for (int i = start; i <= end; i++) {
        Map<String, String> map = new HashMap<String, String>();
        map.put(TjInterFace.NIAN, i + "");
        map.put(item, "0");
        result.add(map);
      }
    }
    return result;
  }