예제 #1
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;
 }
예제 #2
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;
  }