koul 1 жил өмнө
parent
commit
3e1c75f58b

+ 58 - 6
dingtalk-sdk/src/main/java/com/usoftchina/dingtalk/sdk/OaSdk.java

@@ -229,10 +229,10 @@ public class OaSdk extends BaseSdk {
      * @param startTime  查询起始工作日。格式为“yyyy-MM-dd HH:mm:ss”,HH:mm:ss可以使用00:00:00,将返回此日期从0点到24点的结果
      * @param endTime    查询结束工作日。格式为“yyyy-MM-dd HH:mm:ss”,HH:mm:ss可以使用00:00:00,将返回此日期从0点到24点的结果。注意,起始与结束工作日最多相隔7天
      * @param offset     表示获取考勤数据的起始点,第一次传1,如果还有多余数据,下次获取传的offset值为之前的offset+limit 1、2...依次递增
-     * @param limit      表示获取考勤数据的条数,最大不能超过50条
+     * @param size      表示获取考勤数据的条数,最大不能超过50条
      * @return
      */
-    public List<OapiAlitripBtripApplySearchResponse.OpenApplyRs> getAlitripList(String agentCode, String startTime, String endTime, long offset, long limit) {
+    public List<OapiAlitripBtripApplySearchResponse.OpenApplyRs> getAlitripList(String agentCode, String startTime, String endTime, long offset, long size) {
         DingTalkClient client = new DefaultDingTalkClient(getProperties().getApi() + "/topapi/alitrip/btrip/apply/search");
         OapiAlitripBtripApplySearchRequest req = new OapiAlitripBtripApplySearchRequest();
         OapiAlitripBtripApplySearchRequest.OpenSearchRq rq = new OapiAlitripBtripApplySearchRequest.OpenSearchRq();
@@ -240,16 +240,15 @@ public class OaSdk extends BaseSdk {
         rq.setStartTime(StringUtils.parseDateTime(startTime));
         rq.setEndTime(StringUtils.parseDateTime(endTime));
         rq.setPage(offset);
-        rq.setPageSize(limit);
+        rq.setPageSize(size);
         req.setRq(rq);
         OapiAlitripBtripApplySearchResponse resp = cached(() -> client.execute(req, getAccessToken(agentCode)));
         assertOK(resp);
         return resp.getModule();
     }
-     public List<OapiAlitripBtripApplySearchResponse.OpenApplyRs> getAllAlitrip(String agentCode, String startTime, String endTime, long offset, long limit){
+     public List<OapiAlitripBtripApplySearchResponse.OpenApplyRs> getAllAlitrip(String agentCode, String startTime, String endTime){
         List<OapiAlitripBtripApplySearchResponse.OpenApplyRs> dataList = new ArrayList<>();
-        long size = 50;
-        long i = 1;
+        long i=1,size=50;
         while (true) {
             List<OapiAlitripBtripApplySearchResponse.OpenApplyRs> alitripList = getAlitripList(agentCode, startTime, endTime, i++, size);
             if (null != alitripList) {
@@ -263,4 +262,57 @@ public class OaSdk extends BaseSdk {
         }
         return dataList;
      }
+
+    /**
+     * 员工离职列表
+     * @param agentCode
+     * @param offset
+     * @param size
+     */
+     public OapiSmartworkHrmEmployeeQuerydimissionResponse.Paginator getEmpLeaveRecords(String agentCode, long offset, long size){
+         DingTalkClient client = new DefaultDingTalkClient(getProperties().getApi() + "/topapi/smartwork/hrm/employee/querydimission");
+         OapiSmartworkHrmEmployeeQuerydimissionRequest req = new OapiSmartworkHrmEmployeeQuerydimissionRequest();
+         req.setOffset(offset);
+         req.setSize(size);
+         OapiSmartworkHrmEmployeeQuerydimissionResponse resp= cached(() -> client.execute(req, getAccessToken(agentCode)));
+         assertOK(resp);
+         return resp.getResult();
+     }
+
+    /**
+     * 员工离职列表
+     * @param agentCode
+     */
+    public List<OapiSmartworkHrmEmployeeListdimissionResponse.EmpDimissionInfoVo> getAllEmpLeaveRecords(String agentCode){
+        List<OapiSmartworkHrmEmployeeListdimissionResponse.EmpDimissionInfoVo> list = new ArrayList<>();
+        long i=1,size=50;
+        while (true) {
+            OapiSmartworkHrmEmployeeQuerydimissionResponse.Paginator empLeaveRecords = getEmpLeaveRecords(agentCode, i++, size);
+            if (null != empLeaveRecords) {
+                Long nextCursor = empLeaveRecords.getNextCursor()==null?0:empLeaveRecords.getNextCursor();
+                list.addAll(getEmpLeave(agentCode, empLeaveRecords.getDataList()));
+                if (nextCursor<=0) {
+                    break;
+                }
+            } else {
+                break;
+            }
+        }
+        return list;
+    }
+
+    /**
+     * 员工离职信息
+     *
+     * @param agentCode
+     * @param userIdList
+     */
+    public List<OapiSmartworkHrmEmployeeListdimissionResponse.EmpDimissionInfoVo> getEmpLeave(String agentCode, List<String> userIdList){
+            DingTalkClient client = new DefaultDingTalkClient(getProperties().getApi() + "/topapi/smartwork/hrm/employee/listdimission");
+            OapiSmartworkHrmEmployeeListdimissionRequest req = new OapiSmartworkHrmEmployeeListdimissionRequest();
+            req.setUseridList(String.join(",", userIdList));
+            OapiSmartworkHrmEmployeeListdimissionResponse resp= cached(() -> client.execute(req, getAccessToken(agentCode)));
+            assertOK(resp);
+            return resp.getResult();
+    }
 }

+ 2 - 2
dingtalk-sdk/src/test/java/com/usoftchina/dingtalk/sdk/test/BaseTest.java

@@ -17,7 +17,7 @@ public class BaseTest {
         properties = new DingTalkProperties();
 //        properties.setCorpId("ding0fb1b0cd2510faf7ffe93478753d9884");
 //        properties.setAgents(Arrays.asList(new Agent("Uas", 508343055L, "dingibz8hztjohd4epzp", "Kwkf2aq4k35Crjw2smSAGH9diTj5q--c0Qg4TsyoFxfurOkiIoKzmOd-VCLJ1kEc")));
-        properties.setCorpId("dingf484d054c7fcbf4435c2f4657eb6378f");
-        properties.setAgents(Arrays.asList(new Agent("Uas", 587373913L, "dingk8oe4y0efafgwe4m", "n_xcuKNsqcID8GvXPVtXlFEWnw4WJLIXqSc4zR67Y8MrLHUYCw20yF_Gifu9ctRi")));
+        properties.setCorpId("dingcc2251af7d9b14e735c2f4657eb6378f");
+        properties.setAgents(Arrays.asList(new Agent("Uas", 587373913L, "dingxfuwm5g76h4q5a4q", "vGizhqKZOqcKb4-iJmZR6_LPUaK1OafMe4GuZ-LX6pSdXr6x15y6PgLdBGSYcq3d")));
     }
 }

+ 44 - 0
dingtalk-sdk/src/test/java/com/usoftchina/dingtalk/sdk/test/OaSdkTest.java

@@ -0,0 +1,44 @@
+package com.usoftchina.dingtalk.sdk.test;
+
+import com.dingtalk.api.response.OapiAlitripBtripApplySearchResponse;
+import com.dingtalk.api.response.OapiSmartworkHrmEmployeeListdimissionResponse;
+import com.dingtalk.api.response.OapiSmartworkHrmEmployeeQuerydimissionResponse;
+import com.usoftchina.dingtalk.sdk.OaSdk;
+import org.junit.Test;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.util.CollectionUtils;
+
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.List;
+
+/**
+ * @author yingp
+ * @date 2020/3/6
+ */
+public class OaSdkTest extends BaseTest {
+
+    private static OaSdk sdk;
+
+    static {
+        sdk = new OaSdk(properties);
+    }
+
+    @Test
+    public void getAlitripList() {
+        List<OapiAlitripBtripApplySearchResponse.OpenApplyRs> alitripList = sdk.getAlitripList("Uas", "2024-04-23 00:00:00", "2024-04-26 18:00:00", 1, 10);
+        if (!CollectionUtils.isEmpty(alitripList)) {
+            for (OapiAlitripBtripApplySearchResponse.OpenApplyRs openApplyRs:alitripList) {
+                System.out.println(openApplyRs);
+            }
+        }
+    }
+
+    @Test
+    public void getEmpLeaveRecords() {
+        List<OapiSmartworkHrmEmployeeListdimissionResponse.EmpDimissionInfoVo> empLeave = sdk.getAllEmpLeaveRecords("Uas");
+        if (!CollectionUtils.isEmpty(empLeave)) {
+            System.err.println(empLeave);
+        }
+    }
+}

+ 125 - 0
uas-office-dingtalk/src/main/java/com/usoftchina/uas/office/dingtalk/core/Constant.java

@@ -0,0 +1,125 @@
+package com.usoftchina.uas.office.dingtalk.core;
+
+/**
+ * 系统常量
+ * 
+ * @author yingp
+ * 
+ */
+public class Constant {
+
+	// 日期格式
+
+	public final static String YM = "yyyy-MM";
+
+	public final static String ym = "yyyyMM";
+
+	public final static String YMD = "yyyy-MM-dd";
+
+	public final static String YMD_HM = "yyyy-MM-dd HH:mm";
+
+	public final static String YMD_HMS = "yyyy-MM-dd HH:mm:ss";
+
+	public final static String ORACLE_YMD = "yyyy-MM-dd";
+
+	public final static String ORACLE_YMD_HMS = "yyyy-MM-dd HH24:mi:ss";
+
+	public static final String REGEXP_MOBILE = "^[1|8][3-9]\\d{9}$|^([6|9])\\d{7}$|^[0][9]\\d{8}$|^[6]([8|6])\\d{5}$|^(886|0)[9]\\d{8}$";
+
+	public static final String REGEXP_EMAIL = "^([\\w-])+(\\.\\w+)*@([\\w-])+((\\.\\w{2,3}){1,3})$";
+
+	/**
+	 * 求和
+	 * */
+	public final static String SUMMARY_SUM = "sum";
+
+	/**
+	 * 最大值
+	 * */
+	public final static String SUMMARY_MAX = "max";
+	/**
+	 * 最小值
+	 * */
+	public final static String SUMMARY_MIN = "min";
+	/**
+	 * 平均值
+	 * */
+	public final static String SUMMARY_AVERAGE = "average";
+	/**
+	 *  公式合计
+	 * */
+	public final static String SUMMARY_FORMULA = "formula";
+	/**
+	 * 是
+	 */
+	public static final short YES = 1;
+	/**
+	 * 是
+	 */
+	public static final short yes = -1;
+	/**
+	 * 是
+	 */
+	public static final String TRUE = "T";
+	/**
+	 * 否
+	 */
+	public static final short NO = 0;
+	/**
+	 * 否
+	 */
+	public static final String FALSE = "F";
+
+	public static final int ORACLE_MAX_TABLE_SIZE = 999;
+
+	/**
+	 * 优软云
+	 * */
+	public static final String UAS_CLOUD = "CLOUD";
+
+	/**
+	 * 类型--"是否"字段
+	 */
+	public static final String TYPE_YN = "yn";
+
+	/**
+	 * 类型--"下拉框"
+	 */
+	public static final String TYPE_COMBO = "combo";
+
+	/**
+	 * 正则表达式:数字
+	 */
+	public static final String REG_NUM = "^-?[0-9]+(.[0-9]+)?";
+
+	/**
+	 * 正则表达式:日期
+	 */
+	public static final String REG_DATE = "\\d{2,4}-\\d{1,2}-\\d{1,2}";
+
+	/**
+	 * 正则表达式:时间
+	 */
+	public static final String REG_DATETIME = "\\d{2,4}-\\d{1,2}-\\d{1,2} \\d{1,2}:\\d{1,2}:\\d{1,2}";
+
+	/**
+	 * excel导出阈值
+	 */
+	public static final int EXCEL_LG_SIZE = 5000;
+
+	/**
+	 * excel导出最大条数
+	 */
+	public static final int EXCEL_MAX_SIZE = 100000;
+
+	/**
+	 * 正则表达式:ipv4
+	 */
+	public static final String REG_IPV4 = "((?:(?:25[0-5]|2[0-4]\\d|((1\\d{2})|([1-9]?\\d)))\\.){3}(?:25[0-5]|2[0-4]\\d|((1\\d{2})|([1-9]?\\d))))";
+	
+	/**
+	 * 临时表名称
+	 */
+	public static final String TEMP_TABLE_NAME = "TEMP_TABLE";
+
+}

+ 647 - 0
uas-office-dingtalk/src/main/java/com/usoftchina/uas/office/dingtalk/core/DateUtil.java

@@ -0,0 +1,647 @@
+package com.usoftchina.uas.office.dingtalk.core;
+
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.*;
+
+public class DateUtil {
+	static final SimpleDateFormat ym = new SimpleDateFormat("yyyyMM");
+	static final SimpleDateFormat YM = new SimpleDateFormat("yyyy-MM");
+	static final SimpleDateFormat YMD = new SimpleDateFormat("yyyy-MM-dd");
+	static final SimpleDateFormat YMD_HMS = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+
+	public static String format(Date date, String f) {
+		if (date == null) {
+			date = new Date();
+		}
+		if (f == null) {
+			return YMD.format(date);
+		}
+		SimpleDateFormat sdf = new SimpleDateFormat(f);
+		return sdf.format(date);
+	}
+
+	public static String format(java.sql.Date date, String f) {
+		if (date == null) {
+			return currentDateString(f);
+		} else {
+			if (f == null) {
+				return YMD.format(date);
+			}
+			SimpleDateFormat sdf = new SimpleDateFormat(f);
+			return sdf.format(date);
+		}
+	}
+
+	public static Date parse(String date, String f) {
+		if (date == null) {
+			return new Date();
+		}
+		if (f == null) {
+			try {
+				return date.contains(" ") ? YMD_HMS.parse(date) : YMD.parse(date);
+			} catch (ParseException e) {
+				return new Date();
+			}
+		}
+		SimpleDateFormat sdf = new SimpleDateFormat(f);
+		try {
+			return sdf.parse(date);
+		} catch (ParseException e) {
+			return new Date();
+		}
+	}
+
+	/**
+	 * 获取日期年份
+	 * 
+	 * @param date
+	 * @return
+	 * @throws ParseException
+	 */
+	public static int getYear(String date) throws ParseException {
+		date = date == null ? format(null, null) : date;
+		Calendar calendar = Calendar.getInstance();
+		calendar.setTime(YMD.parse(date));
+		return calendar.get(Calendar.YEAR);
+	}
+
+	/**
+	 * 获取日期年份
+	 * 
+	 * @param date
+	 * @return
+	 * @throws ParseException
+	 */
+	public static int getYear(Date date) throws ParseException {
+		date = date == null ? parse(null, null) : date;
+		Calendar calendar = Calendar.getInstance();
+		calendar.setTime(date);
+		return calendar.get(Calendar.YEAR);
+	}
+
+	/**
+	 * 获取日期月份
+	 * 
+	 * @param date
+	 * @return
+	 * @throws ParseException
+	 */
+	public static int getMonth(String date) throws ParseException {
+		date = date == null ? format(null, null) : date;
+		Calendar calendar = Calendar.getInstance();
+		calendar.setTime(YMD.parse(date));
+		return (calendar.get(Calendar.MONTH) + 1);
+	}
+
+	/**
+	 * 获取日期月份
+	 * 
+	 * @param date
+	 * @return
+	 * @throws ParseException
+	 */
+	public static int getMonth(Date date) throws ParseException {
+		date = date == null ? parse(null, null) : date;
+		Calendar calendar = Calendar.getInstance();
+		calendar.setTime(date);
+		return (calendar.get(Calendar.MONTH) + 1);
+	}
+
+	/**
+	 * 获取日期号
+	 * 
+	 * @param date
+	 * @return
+	 * @throws ParseException
+	 */
+	public static int getDay(String date) throws ParseException {
+		date = date == null ? format(null, null) : date;
+		Calendar calendar = Calendar.getInstance();
+		calendar.setTime(YMD.parse(date));
+		return calendar.get(Calendar.DAY_OF_MONTH);
+	}
+
+	/**
+	 * 获取日期号
+	 * 
+	 * @param date
+	 * @return
+	 * @throws ParseException
+	 */
+	public static int getDay(Date date) throws ParseException {
+		date = date == null ? parse(null, null) : date;
+		Calendar calendar = Calendar.getInstance();
+		calendar.setTime(date);
+		return calendar.get(Calendar.DAY_OF_MONTH);
+	}
+
+	/**
+	 * 获取日期前一年日期
+	 * 
+	 * @param date
+	 * @return
+	 * @throws ParseException
+	 */
+	public static String getLastYearDay(String date) throws ParseException {
+		date = date == null ? format(null, null) : date;
+		Calendar calendar = Calendar.getInstance();
+		try {
+			calendar.setTime(YMD.parse(date));
+		} catch (ParseException e) {
+			calendar.setTime(new Date());
+		}
+		calendar.set(Calendar.YEAR, calendar.get(Calendar.YEAR) - 1);
+		return YMD.format(calendar.getTime());
+
+	}
+
+	/**
+	 * 获取月份起始日期
+	 * 
+	 * @param date
+	 * @return
+	 * @throws ParseException
+	 */
+	public static String getMinMonthDate(String date) {
+		date = date == null ? format(null, null) : date;
+		Calendar calendar = Calendar.getInstance();
+		try {
+			calendar.setTime(YMD.parse(date));
+		} catch (ParseException e) {
+			calendar.setTime(new Date());
+		}
+		calendar.set(Calendar.DAY_OF_MONTH, calendar.getActualMinimum(Calendar.DAY_OF_MONTH));
+		return YMD.format(calendar.getTime());
+	}
+
+	/**
+	 * 获取月份起始日期
+	 * 
+	 * @param date
+	 * @return
+	 * @throws ParseException
+	 */
+	public static String getMinMonthDate(Date date) {
+		date = date == null ? parse(null, null) : date;
+		Calendar calendar = Calendar.getInstance();
+		calendar.setTime(date);
+		calendar.set(Calendar.DAY_OF_MONTH, calendar.getActualMinimum(Calendar.DAY_OF_MONTH));
+		return YMD.format(calendar.getTime());
+	}
+
+	/**
+	 * 获取月份最后日期
+	 * 
+	 * @param date
+	 * @return
+	 * @throws ParseException
+	 */
+	public static String getMaxMonthDate(String date) {
+		date = date == null ? format(null, null) : date;
+		Calendar calendar = Calendar.getInstance();
+		try {
+			calendar.setTime(YMD.parse(date));
+		} catch (ParseException e) {
+			calendar.setTime(new Date());
+		}
+		calendar.set(Calendar.DAY_OF_MONTH, calendar.getActualMaximum(Calendar.DAY_OF_MONTH));
+		return YMD.format(calendar.getTime());
+	}
+
+	/**
+	 * 获取月份最后日期
+	 * 
+	 * @param date
+	 * @return
+	 * @throws ParseException
+	 */
+	public static String getMaxMonthDate(Date date) {
+		date = date == null ? parse(null, null) : date;
+		Calendar calendar = Calendar.getInstance();
+		calendar.setTime(date);
+		calendar.set(Calendar.DAY_OF_MONTH, calendar.getActualMaximum(Calendar.DAY_OF_MONTH));
+		return YMD.format(calendar.getTime());
+	}
+
+	/**
+	 * 当前时间
+	 * 
+	 * @return <h3>String</h3>
+	 */
+	public static String getCurrentDate() {
+		return format(new Date(), null);
+	}
+
+	/**
+	 * 截取指定日期的年月
+	 * 
+	 * @param date
+	 * @return
+	 */
+	public static Integer getYearmonth(Date date) {
+		if (date == null) {
+			date = new Date();
+		}
+		return Integer.parseInt(ym.format(date));
+	}
+
+	/**
+	 * 截取指定日期的年月
+	 * 
+	 * @param date
+	 * @return
+	 */
+	public static Integer getYearmonth(String date) {
+		return Integer.parseInt(ym.format(parse(date, null)));
+	}
+
+	/**
+	 * 获取当前年月
+	 * 
+	 * @return
+	 */
+	public static Integer getYearmonth() {
+		return Integer.parseInt(ym.format(new Date()));
+	}
+
+	public static int compare(String date1, String date2) {
+		try {
+			Date dt1 = YMD.parse(date1);
+			Date dt2 = YMD.parse(date2);
+			if (dt1.getTime() > dt2.getTime()) {
+				return 1;
+			} else if (dt1.getTime() < dt2.getTime()) {
+				return -1;
+			} else {
+				return 0;
+			}
+		} catch (Exception exception) {
+			exception.printStackTrace();
+		}
+		return 0;
+	}
+
+	/**
+	 * 获取特定日期是星期几
+	 * 
+	 * @return
+	 */
+	public static String getWeekDay(String DateStr) {
+		SimpleDateFormat formatYMD = new SimpleDateFormat("yyyy-MM-dd");// formatYMD表示的是yyyy-MM-dd格式
+		SimpleDateFormat formatD = new SimpleDateFormat("E");// "E"表示"day in week"
+		Date d = null;
+		String weekDay = "";
+		try {
+			d = formatYMD.parse(DateStr);// 将String 转换为符合格式的日期
+			weekDay = formatD.format(d);
+		} catch (Exception e) {
+			e.printStackTrace();
+		}
+		// System.out.println("日期:"+DateStr+" : "+weekDay);
+		return weekDay;
+	}
+
+	public static int getWeekDay1(String DateStr) {// 返回日期对应数字
+		SimpleDateFormat formatYMD = new SimpleDateFormat("yyyy-MM-dd");// formatYMD表示的是yyyy-MM-dd格式
+		Date d = null;
+		int weekDay = 0;
+		try {
+			d = formatYMD.parse(DateStr);// 将String 转换为符合格式的日期
+			Calendar calendar = Calendar.getInstance();
+			calendar.setTime(d);
+			weekDay = calendar.get(Calendar.DAY_OF_WEEK) - 1;
+		} catch (Exception e) {
+			e.printStackTrace();
+		}
+		return weekDay;
+	}
+
+	/**
+	 * 获取特定时间段内有哪几日
+	 * 
+	 * @return
+	 */
+	public static List<Object> findDates(String start_time, String end_time) throws ParseException {
+		SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
+		Date date1 = df.parse(start_time);
+		Date date2 = df.parse(end_time);
+		int s = (int) ((date2.getTime() - date1.getTime()) / (24 * 60 * 60 * 1000));
+		List<Object> objects = new ArrayList<Object>();
+		String value = "";
+		if (s + 1 > 0) {
+			for (int i = 0; i <= s; i++) {
+				long todayDate = date1.getTime() + (long) i * 24 * 60 * 60 * 1000;
+				Date tmDate = new Date(todayDate);
+				value = new SimpleDateFormat("yyyy-MM-dd").format(tmDate);
+				objects.add(value);
+			}
+		}
+		return objects;
+	}
+
+	/**
+	 * 获取特定时间段内有多少天
+	 * 
+	 * @return
+	 */
+	public static int countDates(String start_time, String end_time) throws ParseException {
+		SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
+		Date date1 = df.parse(start_time);
+		Date date2 = df.parse(end_time);
+		int s = (int) ((date2.getTime() - date1.getTime()) / (24 * 60 * 60 * 1000));
+		return s;
+	}
+
+	/**
+	 * 日期转化成oracle格式to_date('2012-12-12', 'yyyy-MM-dd')
+	 * 
+	 * @param format
+	 *            format type,for example: 'yyyy-MM-dd', 'yyyy-MM-dd HH:mm:ss'
+	 * @param date
+	 *            date{type=java.util.Date}
+	 */
+	public static String parseDateToOracleString(String format, Date date) {
+		if (format == null) {
+			format = Constant.YMD;
+		}
+		SimpleDateFormat sdf = new SimpleDateFormat(format);
+		if (date == null) {
+			date = new Date();
+		}
+		if (Constant.YMD_HMS.toUpperCase().equals(format.toUpperCase())) {
+			format = Constant.ORACLE_YMD_HMS;
+		} else {
+			format = Constant.ORACLE_YMD;
+		}
+		return "to_date('" + sdf.format(date) + "','" + format + "')";
+	}
+
+	/**
+	 * 日期转化成oracle格式to_date('2012-12-12', 'yyyy-MM-dd')
+	 * 
+	 * @param format
+	 *            format type,for example: 'yyyy-MM-dd', 'yyyy-MM-dd HH:mm:ss'
+	 * @param dateString
+	 *            date{type=string}
+	 */
+	public static String parseDateToOracleString(String format, String dateString) {
+		if (format == null) {
+			format = Constant.YMD;
+		}
+		if (dateString == null || "".equals(dateString) || "null".equals(dateString)) {
+			SimpleDateFormat sdf = new SimpleDateFormat(format);
+			dateString = sdf.format(new Date());
+		}
+		if (Constant.YMD_HMS.toUpperCase().equals(format.toUpperCase())) {
+			format = Constant.ORACLE_YMD_HMS;
+		} else {
+			format = Constant.ORACLE_YMD;
+		}
+		return "to_date('" + dateString + "','" + format + "')";
+	}
+
+	/**
+	 * Date转化成字符串格式
+	 * 
+	 * @param f
+	 *            format格式;若为空,则默认为yyyy-MM-dd
+	 */
+	public static String parseDateToString(Date date, String f) {
+		if (f == null) {
+			f = Constant.YMD;
+		}
+		SimpleDateFormat sdf = new SimpleDateFormat(f);
+		if (date == null) {
+			date = new Date();
+		}
+		return sdf.format(date);
+	}
+
+	/**
+	 * 形如{2012-12-21}或{2012-12-21 12:12:12}字符串格式的日期转化成java.util.Date类型
+	 * 
+	 * @param date
+	 *            string日期;若为空或格式错误,则返回当前时间
+	 * @param f
+	 *            format格式;若为空,则默认为yyyy-MM-dd
+	 * @return java.util.Date类型日期
+	 */
+	public static Date parseStringToDate(String date, String f) {
+		if (f == null) {
+			f = Constant.YMD;
+		}
+		SimpleDateFormat sdf = new SimpleDateFormat(f);
+		if (date == null) {
+			return new Date();
+		}
+		try {
+			return sdf.parse(date);
+		} catch (ParseException e) {
+			return new Date();
+		}
+	}
+
+	/**
+	 * 当前时间的字符串格式
+	 * 
+	 * @param f
+	 *            format格式;若为空,则默认为yyyy-MM-dd
+	 */
+	public static String currentDateString(String f) {
+		if (f == null) {
+			f = Constant.YMD;
+		}
+		SimpleDateFormat sdf = new SimpleDateFormat(f);
+		return sdf.format(new Date());
+	}
+
+	/**
+	 * 借贷合同月份处理
+	 */
+	public static int getMonthSpace(Date date1, Date date2) throws ParseException {
+		int iMonth = 0;
+		int flag = 0;
+		try {
+			Calendar objCalendarDate1 = Calendar.getInstance();
+			objCalendarDate1.setTime(date1);
+
+			Calendar objCalendarDate2 = Calendar.getInstance();
+			objCalendarDate2.setTime(date2);
+
+			if (objCalendarDate2.equals(objCalendarDate1))
+				return 0;
+			if (objCalendarDate1.after(objCalendarDate2)) {
+				Calendar temp = objCalendarDate1;
+				objCalendarDate1 = objCalendarDate2;
+				objCalendarDate2 = temp;
+			}
+			if (objCalendarDate2.get(Calendar.DAY_OF_MONTH) > objCalendarDate1.get(Calendar.DAY_OF_MONTH))
+				flag = 1;
+
+			if (objCalendarDate2.get(Calendar.YEAR) > objCalendarDate1.get(Calendar.YEAR)) {
+				iMonth = ((objCalendarDate2.get(Calendar.YEAR) - objCalendarDate1.get(Calendar.YEAR)) * 12
+						+ objCalendarDate2.get(Calendar.MONTH) + flag)
+						- objCalendarDate1.get(Calendar.MONTH);
+			} else {
+				iMonth = objCalendarDate2.get(Calendar.MONTH) + flag - objCalendarDate1.get(Calendar.MONTH);
+			}
+
+		} catch (Exception e) {
+			e.printStackTrace();
+		}
+		return iMonth;
+	}
+
+	/**
+	 * 月份往前或往后n天
+	 */
+	public static Date overDate(Date date, int num) {
+		date = date == null ? new Date() : date;
+		Calendar calendar = new GregorianCalendar();
+		calendar.setTime(date);
+		calendar.add(Calendar.DATE, num);
+		date = calendar.getTime();
+		return date;
+	}
+
+	/**
+	 * 月份加减
+	 * 
+	 * @param date
+	 * @param increase
+	 * @return
+	 */
+	public static Integer addMonth(Date date, int increase) {
+		if (date == null)
+			date = new Date();
+		Calendar calendar = new GregorianCalendar();
+		calendar.setTime(date);
+		calendar.add(Calendar.MONTH, increase);
+		return getYearmonth(calendar.getTime());
+	}
+
+	/**
+	 * 月份加减
+	 * 
+	 * @param month
+	 * @param increase
+	 * @return
+	 */
+	public static Integer addMonth(Integer month, int increase) {
+		Calendar calendar = new GregorianCalendar();
+		try {
+			calendar.setTime(ym.parse(String.valueOf(month)));
+		} catch (ParseException e) {
+			e.printStackTrace();
+		}
+		calendar.add(Calendar.MONTH, increase);
+		return getYearmonth(calendar.getTime());
+	}
+
+	/**
+	 * 时间添加小时数
+	 * */
+	public static Date addHours(Date date, float hours) {
+		Calendar ca = Calendar.getInstance();
+		ca.setTime(date);
+		ca.add(Calendar.MINUTE, (int) (hours * 60));
+		return ca.getTime();
+	}
+
+	/**
+	 * 判断日期是否合法
+	 */
+	public static boolean isValidDate(String dateString, String f) {
+		SimpleDateFormat sdf = new SimpleDateFormat(f);
+		sdf.setLenient(false);
+		try {
+			sdf.parse(dateString);
+		} catch (ParseException e) {
+			e.printStackTrace();
+			return false;
+		}
+		return true;
+	}
+	
+	/**
+     * 获取起止日期
+     * @param sdf 需要显示的日期格式
+     * @param date 需要参照的日期
+     * @param n 最近n周
+     * @param option 0 开始日期;1 结束日期
+     * @param k 0 包含本周 1 不包含本周
+     * @return
+     * @author uas wb
+     */
+    public static String getFromToDate(SimpleDateFormat sdf, Date date, int n, int option, int k) {
+        Calendar calendar = Calendar.getInstance();
+        calendar.setTime(date);
+        int dayOfWeek = calendar.get(Calendar.DAY_OF_WEEK) - 1;
+        int offset = 0 == option ? 1 - dayOfWeek : 7 - dayOfWeek;
+        int amount = 0 == option ? offset - (n - 1  + k) * 7 : offset - k * 7;
+        calendar.add(Calendar.DATE, amount);
+        return sdf.format(calendar.getTime());
+    }
+ 
+    /**
+     * 根据当前日期获得最近n周的日期区间(包含本周)
+     * @param n
+     * @param sdf
+     * @return
+     */
+    public static String getNWeekTimeInterval(int n, SimpleDateFormat sdf) {
+        String beginDate = getFromToDate(sdf, new Date(), n, 0, 0);
+        String endDate = getFromToDate(sdf, new Date(), n, 1, 0);
+        return beginDate + "," + endDate;
+    }
+ 
+    /**
+     * 根据当前日期获得最近n周的日期区间(不包含本周)
+     * @param n
+     * @param sdf
+     * @return
+     */
+    public static String getNWeekTimeIntervalTwo(int n, SimpleDateFormat sdf) {
+        String beginDate = getFromToDate(sdf, new Date(), n, 0, 1);
+        String endDate = getFromToDate(sdf, new Date(), n, 1, 1);
+        return beginDate + "," + endDate;
+    }
+ 
+    /**
+     * 根据当前日期获得本周的日期区间(本周周一和周日日期)
+     * @param sdf
+     * @return
+     */
+    public static String getThisWeekTimeInterval(SimpleDateFormat sdf) {
+        return getNWeekTimeInterval(1, sdf);
+    }
+ 
+    /**
+     * 根据当前日期获得上周的日期区间(上周周一和周日日期)
+     * @param sdf
+     * @return
+     * @author uas wb
+     */
+    public static String getLastWeekTimeInterval(SimpleDateFormat sdf) {
+        return getNWeekTimeIntervalTwo(1, sdf);
+    }
+    
+    /**
+     * 根据当前日期获得本月的日期区间(本月第一天日期和本月最后一天日期)
+     * @param sdf
+     * @return
+     * @author uas wb
+     */
+    public static String getThisMonthFirstDayAndLastDayTime(SimpleDateFormat sdf) {
+   	 Calendar c = Calendar.getInstance();    
+   	 c.add(Calendar.MONTH, 0);
+   	 c.set(Calendar.DAY_OF_MONTH,1);//设置为1号,当前日期既为本月第一天 
+   	 String firstDay = sdf.format(c.getTime());
+   	 
+   	 Calendar ca = Calendar.getInstance();    
+   	 ca.set(Calendar.DAY_OF_MONTH, ca.getActualMaximum(Calendar.DAY_OF_MONTH));  
+   	 String lastDay = sdf.format(ca.getTime());
+   	 return firstDay + "," +lastDay;
+   }
+}

+ 270 - 0
uas-office-dingtalk/src/main/java/com/usoftchina/uas/office/dingtalk/core/NumberUtil.java

@@ -0,0 +1,270 @@
+package com.usoftchina.uas.office.dingtalk.core;
+
+import java.math.BigDecimal;
+import java.text.DecimalFormat;
+
+/**
+ * 数值处理工具
+ * 
+ * @author yingp
+ * 
+ */
+public class NumberUtil {
+
+	/**
+	 * 是否为空、0
+	 * 
+	 * @param numberObj
+	 * @return
+	 */
+	public static boolean isEmpty(Object numberObj) {
+		try {
+			return numberObj == null || "0".equals(String.valueOf(numberObj)) || Integer.parseInt(numberObj.toString()) == 0;
+		} catch (Exception e) {
+			return false;
+		}
+	}
+
+	/**
+	 * format double类型
+	 * 
+	 * @param number
+	 *            需要format的数据
+	 * @param f
+	 *            保留f位的小数
+	 * @return format之后的double类型的数据
+	 */
+	public static double formatDouble(double number, int f) {
+		if (f > 0) {
+			BigDecimal b = new BigDecimal(Double.toString(number));
+			BigDecimal one = new BigDecimal("1");
+			return b.divide(one, f, BigDecimal.ROUND_HALF_UP).doubleValue();
+		} else {
+			return Math.floor(number);
+		}
+	}
+
+	/**
+	 * format double类型
+	 * 
+	 * @param number
+	 *            需要format的数据
+	 * @param f
+	 *            保留f位的小数
+	 * @return format之后的double类型的数据
+	 */
+	public static double formatDouble(String number, int f) {
+		double n = Double.parseDouble(number);
+		if (f > 0) {
+			BigDecimal b = new BigDecimal(number);
+			BigDecimal one = new BigDecimal("1");
+			return b.divide(one, f, BigDecimal.ROUND_HALF_UP).doubleValue();
+		} else {
+			return Math.floor(n);
+		}
+	}
+
+	/**
+	 * 浮点型转成BigDecimal
+	 * 
+	 * @param number
+	 * @return
+	 */
+	public static String parseBigDecimal(double number) {
+		int scale = BigDecimal.valueOf(number).scale();
+		if (scale == -1) {
+			scale = 0;
+		}
+		return String.valueOf(BigDecimal.valueOf(number).setScale(scale, BigDecimal.ROUND_HALF_UP));
+	}
+
+	/**
+	 * 数字格式化
+	 * 
+	 * @param number
+	 * @param f
+	 * @return
+	 */
+	public static String formatNumber(Object number, int f) {
+		if ("0".equals(String.valueOf(number)))
+			return "0";
+		if (number instanceof String)
+			number = Double.parseDouble(number.toString());
+		DecimalFormat df = (DecimalFormat) DecimalFormat.getInstance();
+		df.setGroupingSize(3);
+		int len = number.toString().length();
+		if (number.toString().indexOf(".") > 0)
+			len = number.toString().indexOf(".");
+		String pattern = len > 3 ? "0,000" : "0";
+		for (int i = 0; i < f; i++) {
+			if (i == 0)
+				pattern += ".";
+			pattern += "0";
+		}
+		df.applyPattern(pattern);
+		try {
+			return df.format(number);
+		} catch (Exception e) {
+			return null;
+		}
+	}
+
+	/**
+	 * 设置小数点保留位数
+	 * */
+	public static float subFloat(float f, int length) {
+		String fStr = String.valueOf(f);
+		int i = fStr.indexOf(".");
+		String returnStr = null;
+		if (fStr.length() > i + 1 + length) {
+			returnStr = fStr.substring(0, i + 1 + length);
+		} else
+			returnStr = fStr;
+		float returnf = (Float.valueOf(returnStr)).floatValue();
+		return returnf;
+	}
+
+	/**
+	 * int数组转化成Integer数组
+	 */
+	public static Integer[] toIntegerArray(int[] arr) {
+		int n = arr.length;
+		Integer[] iarr = new Integer[n];
+		for (int i = 0; i < n; i++) {
+			iarr[i] = new Integer(arr[i]);
+		}
+		return iarr;
+	}
+
+	public static Number nvl(Number number, Number ifNullNumber) {
+		return number == null ? ifNullNumber : number;
+	}
+
+	public static int compare(Double paramDouble1, Double paramDouble2) {
+		if (paramDouble1 == null)
+			paramDouble1 = 0.0;
+		if (paramDouble2 == null)
+			paramDouble2 = 0.0;
+		return Double.compare(paramDouble1, paramDouble2);
+	}
+
+	/**
+	 * Double型加法运算
+	 * 
+	 * @param d1
+	 *            第一个加数
+	 * @param ds
+	 *            若干个加数
+	 * @return 相加的结果
+	 * @author suntg
+	 */
+	public static double add(Double d1, Double... ds) {
+		BigDecimal bd = new BigDecimal(Double.toString(d1));
+		for (Double d : ds) {
+			bd = bd.add(new BigDecimal(Double.toString(d)));
+		}
+		return bd.doubleValue();
+	}
+
+	/**
+	 * Double型加法运算
+	 * 
+	 * @param d1
+	 *            第一个加数
+	 * @param ds
+	 *            若干个加数
+	 * @return 相加的结果
+	 * @author suntg
+	 */
+	public static double add(String ds1, String... dss) {
+		BigDecimal bd = new BigDecimal(ds1);
+		for (String ds : dss) {
+			bd = bd.add(new BigDecimal(ds));
+		}
+		return bd.doubleValue();
+	}
+
+	/**
+	 * Double型减法运算
+	 * 
+	 * @param d1
+	 *            被减数
+	 * @param d2
+	 *            减数
+	 * @return 运算结果
+	 * @author suntg
+	 */
+	public static double sub(Double d1, Double d2) {
+		BigDecimal b1 = new BigDecimal(Double.toString(d1));
+		BigDecimal b2 = new BigDecimal(Double.toString(d2));
+		return b1.subtract(b2).doubleValue();
+	}
+
+	/**
+	 * Double 型乘法运算
+	 * 
+	 * @param d1
+	 *            第一个乘数
+	 * @param d2
+	 *            第二个乘数
+	 * @return 运算结果
+	 * @author suntg
+	 */
+	public static double mul(Double d1, Double d2) {
+		BigDecimal b1 = new BigDecimal(Double.toString(d1));
+		BigDecimal b2 = new BigDecimal(Double.toString(d2));
+		return b1.multiply(b2).doubleValue();
+	}
+
+	/**
+	 * Double 型除法运算
+	 * 
+	 * @param d1
+	 *            被除数
+	 * @param d2
+	 *            除数
+	 * @param scale
+	 *            小数点四舍五入精度
+	 * @return 运算结果
+	 * @author suntg
+	 */
+	public static double div(Double d1, Double d2, int scale) {
+		if (scale < 0) {
+			throw new IllegalArgumentException("四舍五入精度必须大于0");
+		}
+		if (d2.doubleValue() == 0) {
+			throw new IllegalArgumentException("被除数不能为0");
+		}
+		BigDecimal b1 = new BigDecimal(Double.toString(d1));
+		BigDecimal b2 = new BigDecimal(Double.toString(d2));
+		return b1.divide(b2, scale, BigDecimal.ROUND_HALF_UP).doubleValue();
+	}
+
+	/**
+	 * 默认小数点四舍五入精度为6的Double型除法运算
+	 * 
+	 * @param d1
+	 *            被除数
+	 * @param d2
+	 *            除数
+	 * @return 运算结果
+	 * @author suntg
+	 */
+	public static double div(Double d1, Double d2) {
+		return div(d1, d2, 6);
+	}
+
+	/**
+	 * 比较浮点型数值
+	 * 
+	 * @param paramDouble1
+	 * @param paramDouble2
+	 * @param paramInt
+	 *            精度
+	 * @return
+	 */
+	public static int compare(double paramDouble1, double paramDouble2, int paramInt) {
+		return Double.compare(formatDouble(paramDouble1, paramInt), formatDouble(paramDouble2, paramInt));
+	}
+
+}

+ 2 - 1
uas-office-dingtalk/src/main/java/com/usoftchina/uas/office/dingtalk/listener/UasOaListener.java

@@ -25,6 +25,7 @@ public class UasOaListener {
             return;
         }
         int id = Integer.parseInt(event.getKey().toString());
-        uasOaService.saveOa(id);
+        uasOaService.saveOa("Uas",id);
+        logger.info("OaDingTalklog结束");
     }
 }

+ 53 - 95
uas-office-dingtalk/src/main/java/com/usoftchina/uas/office/dingtalk/service/UasOaService.java

@@ -1,144 +1,102 @@
 package com.usoftchina.uas.office.dingtalk.service;
 
 import com.dingtalk.api.response.OapiAlitripBtripApplySearchResponse;
+import com.dingtalk.api.response.OapiSmartworkHrmEmployeeListdimissionResponse;
 import com.usoftchina.dingtalk.sdk.OaSdk;
+import com.usoftchina.uas.office.dingtalk.util.BaseDao;
+import com.usoftchina.uas.office.dingtalk.util.SqlRowList;
 import com.usoftchina.uas.office.service.AbstractService;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.dao.DataAccessException;
-import org.springframework.jdbc.core.CallableStatementCallback;
-import org.springframework.jdbc.core.CallableStatementCreator;
-import org.springframework.jdbc.core.JdbcTemplate;
-import org.springframework.jdbc.support.rowset.SqlRowSet;
 import org.springframework.stereotype.Service;
 import org.springframework.util.CollectionUtils;
 
-import java.sql.CallableStatement;
-import java.sql.Connection;
-import java.sql.SQLException;
 import java.text.SimpleDateFormat;
 import java.util.List;
 
 @Service
 public class UasOaService extends AbstractService {
-    //创建序列
-    static final String CREATE_SEQ = "CREATE SEQUENCE ? MINVALUE 1 MAXVALUE 99999999999 INCREMENT BY 1 START WITH 3000 CACHE 20 NOORDER NOCYCLE ";
-    @Autowired
-    protected JdbcTemplate jdbcTemplate;
 
     @Autowired
     private OaSdk oaSdk;
+    @Autowired
+    private BaseDao baseDao;
 
-    public void saveOa(int id){
-        SqlRowSet rs = jdbcTemplate.queryForRowSet("select od_id,od_kind,to_char(od_startdate,'yyyy-MM-dd hh24:mi:ss') startdate,to_char(od_enddate,'yyyy-MM-dd hh24:mi:ss') enddate from OaDingTalklog where od_id=" + id);
+    public void saveOa(String agentCode,int id){
+        SqlRowList rs = baseDao.queryForRowSet("select od_id,od_kind,to_char(od_startdate,'yyyy-MM-dd hh24:mi:ss') startdate,to_char(od_enddate,'yyyy-MM-dd hh24:mi:ss') enddate from OaDingTalklog where od_id=" + id);
         while (rs.next()){
             String odKind = rs.getString("od_kind");
             String startdate = rs.getString("startdate");
             String enddate = rs.getString("enddate");
+            //离职、补卡、请假、出差、加班
             if ("出差申请单".equals(odKind)){
-                saveAlitripList("Uas", startdate, enddate, 1, 50);
-            } else if ("".equals(odKind)) {
+                saveAlitripList(agentCode, startdate, enddate);
+            } else if ("请假申请单".equals(odKind)) {
+
+            } else if ("加班申请单".equals(odKind)) {
 
+            }else if ("补卡申请单".equals(odKind)) {
+
+            }else if ("离职申请单".equals(odKind)) {
+                saveEmpLeaveRecords(agentCode);
             }
         }
     }
     /**
      * 保存出差申请
      */
-    public void saveAlitripList(String agentCode, String startTime, String endTime, long offset, long limit) {
-        List<OapiAlitripBtripApplySearchResponse.OpenApplyRs> alitripList = oaSdk.getAllAlitrip(agentCode,startTime,endTime,offset,limit);
+    public void saveAlitripList(String agentCode, String startTime, String endTime) {
+        List<OapiAlitripBtripApplySearchResponse.OpenApplyRs> alitripList = oaSdk.getAllAlitrip(agentCode,startTime,endTime);
         if (!CollectionUtils.isEmpty(alitripList)) {
+            SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
             for (OapiAlitripBtripApplySearchResponse.OpenApplyRs openApplyRs:alitripList) {
-                int id = getSeqId("FEEPLEASE_SEQ");
-                String code = callProcedure("Sp_GetMaxNumber", new Object[]{"FeePlease!CCSQ!new", 2});
-                SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                 String inDate = format.format(openApplyRs.getGmtCreate());
                 List<OapiAlitripBtripApplySearchResponse.OpenItineraryInfo> itineraryList = openApplyRs.getItineraryList();
-                String startDate = format.format(itineraryList.get(0).getDepDate());
-                String endDate = format.format(itineraryList.get(0).getArrDate());
+                OapiAlitripBtripApplySearchResponse.OpenItineraryInfo openItineraryInfo = itineraryList.get(0);
+                String startDate = format.format(openItineraryInfo.getDepDate());
+                String endDate = format.format(openItineraryInfo.getArrDate());
                 Long rsId = openApplyRs.getId();
-                SqlRowSet rowSet = jdbcTemplate.queryForRowSet("select * from FeePlease where dp_ddid=" + rsId);
-                if (!rowSet.next()) {
-                    jdbcTemplate.execute("insert into FeePlease (fp_id,fp_code,fp_v9,FP_PEOPLE2,fp_recordman,fp_recorddate,fp_statuscode,fp_status,fp_v3,fp_prestartdate,fp_preenddate,fp_n6,) " +
-                            "values (" + id + ",'" + code + "','" + openApplyRs.getDeptName() + "','" + openApplyRs.getUserName() + "','" + openApplyRs.getUserName() + "',to_date('" + inDate + "','yyyy-MM-dd HH:mi:ss'),'AUDITED','已审核','" + openApplyRs.getTripCause() + "',to_date('" + startDate + "','yyyy-MM-dd HH:mi:ss'),to_date('" + endDate + "','yyyy-MM-dd HH:mi:ss')," + openApplyRs.getTripDay() + ")");
+                String projectTitle = openItineraryInfo.getProjectTitle();
+                String projectCode = openItineraryInfo.getProjectCode();
+                String statusDesc = openApplyRs.getStatusDesc()==null?"":openApplyRs.getStatusDesc();
+                int count = baseDao.getCountByCondition("FeePlease", "dp_ddid=" + rsId);
+                if (count<=0&&"已同意".equals(statusDesc)) {
+                    int id = baseDao.getSeqId("FEEPLEASE_SEQ");
+                    String code = baseDao.callProcedure("Sp_GetMaxNumber", new Object[]{"FeePlease!CCSQ!new", 2});
+                    baseDao.execute("insert into FeePlease (fp_id,fp_code,fp_kind,fp_v9,FP_PEOPLE2,fp_recordman,fp_recorddate,fp_statuscode,fp_status,fp_v3,fp_prestartdate,fp_preenddate,fp_n6,dp_ddid,fp_remark,fp_prjcode,fp_prjname) " +
+                            "values (" + id + ",'" + code + "','出差申请单','" + openApplyRs.getDeptName() + "','" + openApplyRs.getUserName() + "','" + openApplyRs.getUserName() + "',to_date('" + inDate + "','yyyy-MM-dd HH24:mi:ss'),'AUDITED','已审核','" + openApplyRs.getTripCause() + "',to_date('" + startDate + "','yyyy-MM-dd HH24:mi:ss'),to_date('" + endDate + "','yyyy-MM-dd HH24:mi:ss')," + openApplyRs.getTripDay() + ","+rsId+",'"+statusDesc+"','"+projectCode+"','"+projectTitle+"')");
+                    /*jdbcTemplate.execute("insert into FeePleaseDetail(fpd_id,fpd_fpid,fpd_code,fpd_class,fpd_detno,fpd_d5,fpd_d6,fpd_date1,fpd_date2) " +
+                            "values(FeePleaseDetail_seq.nextval,"+id+",'"+code+"','出差申请单',1,'"+projectCode+"','"+projectTitle+"',to_date('" + startDate + "','yyyy-MM-dd HH24:mi:ss'),to_date('" + endDate + "','yyyy-MM-dd HH24:mi:ss'))");*/
                 }
             }
         }
     }
 
     /**
-     * 获取序列号
-     *
-     * @param seq
-     *            指定的序列名
+     * 保存离职申请
      */
-    private int getSeqId(String seq) {
-        try {
-            String sql = "select " + seq + ".nextval from dual";
-            SqlRowSet rs = jdbcTemplate.queryForRowSet(sql);
-            if (rs.next()) {
-                return rs.getInt(1);
-            } else {// 如果不存在就创建序列
-                SqlRowSet rowSet = jdbcTemplate.queryForRowSet("select * from user_sequences where Sequence_Name='" + seq.toUpperCase() + "'");
-                if (!rowSet.next()) {
-                    jdbcTemplate.execute(CREATE_SEQ.replace("?", seq));
+    public void saveEmpLeaveRecords(String agentCode) {
+        List<OapiSmartworkHrmEmployeeListdimissionResponse.EmpDimissionInfoVo> empLeave = oaSdk.getAllEmpLeaveRecords(agentCode);
+        if (!CollectionUtils.isEmpty(empLeave)){
+            SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+            for (int i = 0; i < empLeave.size(); i++) {
+                OapiSmartworkHrmEmployeeListdimissionResponse.EmpDimissionInfoVo empDimissionInfoVo = empLeave.get(i);
+                String deptName = empDimissionInfoVo.getMainDeptName();
+                String reasonMemo = empDimissionInfoVo.getReasonMemo();
+                Long lastWorkDay = empDimissionInfoVo.getLastWorkDay();
+                String leaves = format.format(lastWorkDay);
+                String userid = empDimissionInfoVo.getUserid();
+                int count = baseDao.getCountByCondition("Turnover", "to_dingtalkid='" + userid + "'");
+                int count1 = baseDao.getCountByCondition("employee", "em_ding='" + userid + "'");
+                if (count<=0&&count1>0){
+                    int id = baseDao.getSeqId("TURNOVER_SEQ");
+                    String code = baseDao.callProcedure("Sp_GetMaxNumber", new Object[]{"Turnover", 2});
+                    baseDao.execute("insert into Turnover (to_id,to_code,to_applymancode,to_applyman,to_leavedate,to_recordor,to_date,to_statuscode,to_status,to_otherreason,to_dingtalkid) " +
+                            "select " + id + ",'" + code + "',em_code,em_name,to_date('" + leaves + "','yyyy-MM-dd HH24:mi:ss'),em_name,sysdate,'AUDITED','已审核','" + reasonMemo + "','"+userid+"' employee where em_ding='" + userid + "'");
                 }
-                return getSeqId(seq);
-            }
-        } catch (Exception e) {
-            SqlRowSet rowSet = jdbcTemplate.queryForRowSet("select * from user_sequences where Sequence_Name='" + seq.toUpperCase() + "'");
-            if (!rowSet.next()) {
-                jdbcTemplate.execute(CREATE_SEQ.replace("?", seq));
             }
-            return getSeqId(seq);
         }
     }
 
-     /**
-     * 调用存储过程
-     *
-     * @param procedureName
-     *            存储过程名称
-     * @param args
-     *            参数
-     * @return varchar类型结果
-     */
-     private String callProcedure(final String procedureName, final Object... args) {
-        try {
-            return jdbcTemplate.execute(new CallableStatementCreator() {
-                @Override
-                public CallableStatement createCallableStatement(Connection conn) throws SQLException {
-                    StringBuffer storedProcName = new StringBuffer("{call ");
-                    int i = 0;
-                    storedProcName.append(procedureName + "(");
-                    for (i = 0; i < args.length; i++) {
-                        if (storedProcName.toString().contains("?")) {
-                            storedProcName.append(",");
-                        }
-                        storedProcName.append("?");
-                    }
-                    if (storedProcName.toString().contains("?")) {
-                        storedProcName.append(",");
-                    }
-                    storedProcName.append("?");
-                    storedProcName.append(")}");
-                    CallableStatement cs = conn.prepareCall(storedProcName.toString());
-                    for (i = 0; i < args.length; i++) {
-                        cs.setObject(i + 1, args[i]);
-                    }
-                    cs.registerOutParameter(args.length + 1, java.sql.Types.VARCHAR);
-                    return cs;
-                }
-            }, new CallableStatementCallback<String>() {
-                @Override
-                public String doInCallableStatement(CallableStatement cs) throws SQLException, DataAccessException {
-                    cs.execute();
-                    return cs.getString(args.length + 1);
-                }
 
-            });
-        } catch (Exception e) {
-            e.getMessage();
-        }
-        return null;
-    }
+
 }

+ 226 - 0
uas-office-dingtalk/src/main/java/com/usoftchina/uas/office/dingtalk/util/BaseDao.java

@@ -0,0 +1,226 @@
+package com.usoftchina.uas.office.dingtalk.util;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.dao.DataAccessException;
+import org.springframework.jdbc.core.CallableStatementCallback;
+import org.springframework.jdbc.core.CallableStatementCreator;
+import org.springframework.jdbc.core.JdbcTemplate;
+import org.springframework.jdbc.core.support.JdbcDaoSupport;
+import org.springframework.jdbc.support.rowset.SqlRowSet;
+import org.springframework.stereotype.Repository;
+
+import java.sql.CallableStatement;
+import java.sql.Connection;
+import java.sql.SQLException;
+import java.util.List;
+
+@Repository("baseDao")
+public class BaseDao extends JdbcDaoSupport {
+    //创建序列
+    static final String CREATE_SEQ = "CREATE SEQUENCE ? MINVALUE 1 MAXVALUE 99999999999 INCREMENT BY 1 START WITH 3000 CACHE 20 NOORDER NOCYCLE ";
+    @Autowired
+    protected JdbcTemplate jdbcTemplate;
+
+
+    /**
+     * 获取序列号
+     *
+     * @param seq
+     *            指定的序列名
+     */
+    public int getSeqId(String seq) {
+        try {
+            String sql = "select " + seq + ".nextval from dual";
+            SqlRowSet rs = jdbcTemplate.queryForRowSet(sql);
+            if (rs.next()) {
+                return rs.getInt(1);
+            } else {// 如果不存在就创建序列
+                SqlRowSet rowSet = jdbcTemplate.queryForRowSet("select * from user_sequences where Sequence_Name='" + seq.toUpperCase() + "'");
+                if (!rowSet.next()) {
+                    jdbcTemplate.execute(CREATE_SEQ.replace("?", seq));
+                }
+                return getSeqId(seq);
+            }
+        } catch (Exception e) {
+            SqlRowSet rowSet = jdbcTemplate.queryForRowSet("select * from user_sequences where Sequence_Name='" + seq.toUpperCase() + "'");
+            if (!rowSet.next()) {
+                jdbcTemplate.execute(CREATE_SEQ.replace("?", seq));
+            }
+            return getSeqId(seq);
+        }
+    }
+
+    /**
+     * 调用存储过程
+     *
+     * @param procedureName
+     *            存储过程名称
+     * @param args
+     *            参数
+     * @return varchar类型结果
+     */
+    public String callProcedure(final String procedureName, final Object... args) {
+        try {
+            return jdbcTemplate.execute(new CallableStatementCreator() {
+                @Override
+                public CallableStatement createCallableStatement(Connection conn) throws SQLException {
+                    StringBuffer storedProcName = new StringBuffer("{call ");
+                    int i = 0;
+                    storedProcName.append(procedureName + "(");
+                    for (i = 0; i < args.length; i++) {
+                        if (storedProcName.toString().contains("?")) {
+                            storedProcName.append(",");
+                        }
+                        storedProcName.append("?");
+                    }
+                    if (storedProcName.toString().contains("?")) {
+                        storedProcName.append(",");
+                    }
+                    storedProcName.append("?");
+                    storedProcName.append(")}");
+                    CallableStatement cs = conn.prepareCall(storedProcName.toString());
+                    for (i = 0; i < args.length; i++) {
+                        cs.setObject(i + 1, args[i]);
+                    }
+                    cs.registerOutParameter(args.length + 1, java.sql.Types.VARCHAR);
+                    return cs;
+                }
+            }, new CallableStatementCallback<String>() {
+                @Override
+                public String doInCallableStatement(CallableStatement cs) throws SQLException, DataAccessException {
+                    cs.execute();
+                    return cs.getString(args.length + 1);
+                }
+
+            });
+        } catch (Exception e) {
+            e.getMessage();
+        }
+        return null;
+    }
+
+    /**
+     * @param tableName
+     *            对应要查询的表
+     * @param condition
+     *            查询条件
+     * @return Count
+     */
+    public int getCountByCondition(String tableName, String condition) {
+        StringBuffer sql = new StringBuffer("SELECT count(1) FROM ");
+        sql.append(tableName);
+        sql.append(" WHERE ");
+        sql.append(condition);
+        SqlRowList srs = queryForRowSet(sql.toString());
+        if (srs.next()) {
+            return srs.getInt(1);
+        } else {
+            try {
+                throw new Exception("Condition:" + condition + " is wrong!");
+            } catch (Exception e) {
+                return -1;
+            }
+        }
+    }
+
+    /**
+     * 查询结果集
+     *
+     * @param sql
+     *            查询语句
+     */
+    public SqlRowList queryForRowSet(String sql) {
+        SqlRowList rs = new SqlRowList();
+        rs.setResultList(jdbcTemplate.queryForList(sql));
+        return rs;
+    }
+
+    public void execute(String sql) {
+        jdbcTemplate.execute(sql);
+    }
+
+    public synchronized boolean execute(String sql, Object... objs) {
+        try {
+            jdbcTemplate.update(sql, objs);
+            return true;
+        } catch (Exception e) {
+            return false;
+        }
+    }
+
+    public void execute(List<String> sqls) {
+        if (sqls.size() > 0) {
+            StringBuffer sb = new StringBuffer("begin ");
+            for (String sql : sqls) {
+                sb.append("execute immediate '").append(sql.replace("'", "''")).append("';");
+            }
+            sb.append("end;");
+            jdbcTemplate.execute(sb.toString());
+        }
+    }
+
+    /**
+     * @param execSqls
+     *            先执行的sql
+     * @param updateSqls
+     *            校验通过之后的更新语句
+     * @param checkSqls
+     *            校验语句,出错会回滚并返回异常信息
+     * @return
+     */
+    public String executeWithCheck(List<String> execSqls, List<String> updateSqls, String... checkSqls) {
+        if (execSqls.size() > 0) {
+            StringBuffer sb = new StringBuffer("declare v_r varchar2(200);begin ");
+            for (String sql : execSqls) {
+                sb.append("execute immediate '").append(sql.replace("'", "''")).append("';");
+            }
+            for (String checkSql : checkSqls) {
+                sb.append("BEGIN execute immediate '")
+                        .append(checkSql.replace("'", "''"))
+                        .append("' into v_r;if nvl(v_r,' ')<>' ' then rollback;RAISE_APPLICATION_ERROR(-20001,'ERROR_BEGIN'||v_r||'ERROR_END'); end if;exception when no_data_found then v_r := null;END;");
+            }
+            if (updateSqls != null) {
+                for (String sql : updateSqls) {
+                    sb.append("execute immediate '").append(sql.replace("'", "''")).append("';");
+                }
+            }
+            sb.append("end;");
+            try {
+                jdbcTemplate.execute(sb.toString());
+            } catch (Exception e) {
+                if (e.getCause() instanceof java.sql.SQLException) {
+                    String errMsg = e.getCause().getMessage();
+                    if (errMsg.contains("ERROR_BEGIN"))
+                        return errMsg.substring(errMsg.indexOf("ERROR_BEGIN") + 11, errMsg.lastIndexOf("ERROR_END"));
+                }
+                return e.getMessage();
+            }
+        }
+        return null;
+    }
+
+    public void execute(String[] sqls) {
+        if (sqls.length > 0) {
+            StringBuffer sb = new StringBuffer("begin ");
+            for (String sql : sqls) {
+                sb.append("execute immediate '").append(sql.replace("'", "''")).append("';");
+            }
+            sb.append("end;");
+            jdbcTemplate.execute(sb.toString());
+        }
+    }
+
+    public void deleteById(String tablename, String keyField, long id) {
+        deleteByCondition(tablename, keyField + "=" + id);
+    }
+
+    public void deleteByCondition(String tablename, String condition, Object... params) {
+        StringBuffer sb = new StringBuffer();
+        sb.append("DELETE FROM ");
+        sb.append(tablename);
+        sb.append(" WHERE ");
+        sb.append(condition);
+        execute(sb.toString(), params);
+    }
+
+}

+ 36 - 0
uas-office-dingtalk/src/main/java/com/usoftchina/uas/office/dingtalk/util/RowConvert.java

@@ -0,0 +1,36 @@
+package com.usoftchina.uas.office.dingtalk.util;
+
+import org.springframework.util.NumberUtils;
+
+public class RowConvert<T>{
+
+	private Class<T> requiredType;
+
+	public RowConvert(Class<T> requiredType) {
+		this.requiredType = requiredType;
+	}
+
+	@SuppressWarnings("unchecked")
+	protected Object convertValueToRequiredType(Object value, @SuppressWarnings("rawtypes") Class requiredType) {
+		if (String.class.equals(requiredType)) {
+			return value.toString();
+		}
+		if (Number.class.isAssignableFrom(requiredType)) {
+			if (value instanceof Number) {
+				return NumberUtils.convertNumberToTargetClass((Number) value, requiredType);
+			}
+			return NumberUtils.parseNumber(value.toString(), requiredType);
+		}
+		throw new IllegalArgumentException(
+				"Value [" + value + "] is of type [" + value.getClass().getName() +
+						"] and cannot be converted to required type [" + requiredType.getName() + "]");
+	}
+
+	@SuppressWarnings("unchecked")
+	public T convert(Object value) {
+		if (value != null && this.requiredType != null && !this.requiredType.isInstance(value)) {
+			return (T) convertValueToRequiredType(value, this.requiredType);
+		}
+		return (T) value;
+	}
+}

+ 431 - 0
uas-office-dingtalk/src/main/java/com/usoftchina/uas/office/dingtalk/util/SqlRowList.java

@@ -0,0 +1,431 @@
+package com.usoftchina.uas.office.dingtalk.util;
+
+import com.alibaba.fastjson.JSONObject;
+import com.usoftchina.uas.office.dingtalk.core.Constant;
+import com.usoftchina.uas.office.dingtalk.core.DateUtil;
+import com.usoftchina.uas.office.dingtalk.core.NumberUtil;
+
+import java.math.BigDecimal;
+import java.sql.Timestamp;
+import java.util.*;
+
+/**
+ * org.springframework.jdbc.support.rowset.SqlRowSet有jdk版本问题
+ * 
+ * @author yingp 2013-1-10 11:50:08
+ */
+public class SqlRowList {
+
+	private List<Map<String, Object>> resultList;// 结果集
+	private Iterator<Map<String, Object>> iterator;
+	private Map<String, Object> currentMap;// 当前Map
+	private int currentIndex = -1;// 当前index,从0开始
+	private List<String> keys;// 字段名集
+
+	public SqlRowList() {
+		this.resultList = new ArrayList<Map<String, Object>>();
+	}
+
+	public List<Map<String, Object>> getResultList() {
+		return resultList;
+	}
+
+	public int size() {
+		return getResultList().size();
+	}
+
+	public void setResultList(List<Map<String, Object>> resultList) {
+		this.resultList = resultList;
+	}
+
+	public Map<String, Object> getCurrentMap() {
+		return currentMap;
+	}
+
+	public void setCurrentMap(Map<String, Object> currentMap) {
+		this.currentMap = currentMap;
+	}
+
+	public int getCurrentIndex() {
+		return currentIndex;
+	}
+
+	public void setCurrentIndex(int currentIndex) {
+		this.currentIndex = currentIndex;
+	}
+
+	public List<String> getKeys() {
+		if (this.keys == null) {
+			this.keys = new ArrayList<String>();
+			if (this.resultList != null) {
+				Iterator<Map<String, Object>> iterator = resultList.iterator();
+				if (iterator.hasNext()) {
+					Map<String, Object> map = iterator.next();
+					Iterator<String> fields = map.keySet().iterator();
+					while (fields.hasNext()) {
+						this.keys.add(fields.next());
+					}
+				}
+			}
+		}
+		return keys;
+	}
+
+	public void setKeys(List<String> keys) {
+		this.keys = keys;
+	}
+
+	/**
+	 * 取ResultSet的第index条Map
+	 * 
+	 * @param index
+	 * @return
+	 */
+	public Map<String, Object> getAt(int index) {
+		if (this.resultList != null) {
+			Iterator<Map<String, Object>> iterator = resultList.iterator();
+			Map<String, Object> map = null;
+			int idx = 0;
+			while (iterator.hasNext() && (map = iterator.next()) != null) {
+				if (index == idx)
+					return map;
+				idx++;
+			}
+		}
+		return null;
+	}
+
+	public <T> List<T> queryForList(String field, Class<T> requiredType) {
+		if (this.resultList != null) {
+			Iterator<Map<String, Object>> iterator = resultList.iterator();
+			Map<String, Object> map = null;
+			List<T> list = new ArrayList<T>();
+			RowConvert<T> convert = new RowConvert<T>(requiredType);
+			field = field.toUpperCase();
+			while (iterator.hasNext() && (map = iterator.next()) != null) {
+				Object result = map.get(field);
+				if (result != null) {
+					list.add(convert.convert(result));
+				}
+			}
+			return list;
+		}
+		return null;
+	}
+
+	public <T> Set<T> queryForSet(String field, Class<T> requiredType) {
+		if (this.resultList != null) {
+			Iterator<Map<String, Object>> iterator = resultList.iterator();
+			Map<String, Object> map = null;
+			Set<T> set = new java.util.HashSet<T>();
+			RowConvert<T> convert = new RowConvert<T>(requiredType);
+			field = field.toUpperCase();
+			while (iterator.hasNext() && (map = iterator.next()) != null) {
+				Object result = map.get(field);
+				if (result != null) {
+					set.add(convert.convert(result));
+				}
+			}
+			return set;
+		}
+		return null;
+	}
+
+	public boolean hasNext() {
+		if (this.resultList != null) {
+			if (this.iterator == null) {
+				this.iterator = resultList.iterator();
+			}
+			if (this.iterator.hasNext()) {
+				return true;
+			}
+		}
+		return false;
+	}
+
+	public boolean next(int count) {
+		for (int i = 0; i < count; i++) {
+			if (!next())
+				return false;
+		}
+		return true;
+	}
+
+	public boolean next() {
+		if (this.resultList != null) {
+			if (this.iterator == null) {
+				this.iterator = resultList.iterator();
+				this.currentIndex = -1;
+			}
+			if (this.iterator.hasNext()) {
+				this.currentMap = iterator.next();
+				this.currentIndex += 1;
+				if (this.keys == null) {
+					this.keys = new ArrayList<String>();
+					Iterator<String> fields = currentMap.keySet().iterator();
+					while (fields.hasNext()) {
+						this.keys.add(fields.next());
+					}
+				}
+				return true;
+			}
+		}
+		return false;
+	}
+
+	public int getInt(int index) {
+		Object obj = getObject(index);
+		return obj == null ? -1 : Integer.parseInt(obj.toString());
+	}
+
+	public int getInt(String field) {
+		Object obj = getObject(field);
+		return obj == null ? -1 : Integer.parseInt(obj.toString());
+	}
+
+	public int getGeneralInt(int index) {
+		Object obj = getObject(index);
+		return obj == null ? 0 : Integer.parseInt(obj.toString());
+	}
+
+	public int getGeneralInt(String field) {
+		Object obj = getObject(field);
+		return obj == null ? 0 : Integer.parseInt(obj.toString());
+	}
+
+	public float getFloat(int index) {
+		Object obj = getObject(index);
+		return obj == null ? -1 : Float.parseFloat(obj.toString());
+	}
+
+	public float getFloat(String field) {
+		Object obj = getObject(field);
+		return obj == null ? -1 : Float.parseFloat(obj.toString());
+	}
+
+	public float getGeneralFloat(int index) {
+		Object obj = getObject(index);
+		return obj == null ? 0 : Float.parseFloat(obj.toString());
+	}
+
+	public float getGeneralFloat(String field) {
+		Object obj = getObject(field);
+		return obj == null ? 0 : Float.parseFloat(obj.toString());
+	}
+
+	public double getDouble(int index) {
+		Object obj = getObject(index);
+		return obj == null ? -1 : Double.parseDouble(obj.toString());
+	}
+
+	public double getDouble(String field) {
+		Object obj = getObject(field);
+		return obj == null ? -1 : Double.parseDouble(obj.toString());
+	}
+
+	public BigDecimal getBigDecimal(int index) {
+		Object obj = getObject(index);
+		return obj == null ? null : BigDecimal.valueOf(Double.parseDouble(obj.toString()));
+	}
+
+	public BigDecimal getBigDecimal(String field) {
+		Object obj = getObject(field);
+		return obj == null ? null : BigDecimal.valueOf(Double.parseDouble(obj.toString()));
+	}
+
+	public double getGeneralDouble(int index) {
+		Object obj = getObject(index);
+		return obj == null ? 0 : Double.parseDouble(obj.toString());
+	}
+
+	/**
+	 * @param index
+	 * @param sub
+	 *            保留小数位数
+	 * @return
+	 */
+	public double getGeneralDouble(int index, int sub) {
+		return NumberUtil.formatDouble(getGeneralDouble(index), sub);
+	}
+
+	public double getGeneralDouble(String field) {
+		Object obj = getObject(field);
+		return obj == null || String.valueOf(obj).trim().equals("") ? 0 : Double.parseDouble(String.valueOf(obj).trim());
+	}
+
+	/**
+	 * @param field
+	 * @param sub
+	 *            保留小数位数
+	 * @return
+	 */
+	public double getGeneralDouble(String field, int sub) {
+		return NumberUtil.formatDouble(getGeneralDouble(field), sub);
+	}
+
+	public BigDecimal getGeneralBigDecimal(int index) {
+		Object obj = getObject(index);
+		return obj == null ? new BigDecimal(0) : BigDecimal.valueOf(Double.parseDouble(obj.toString()));
+	}
+
+	public BigDecimal getGeneralBigDecimal(String field) {
+		Object obj = getObject(field);
+		return obj == null ? new BigDecimal(0) : BigDecimal.valueOf(Double.parseDouble(obj.toString()));
+	}
+
+	public long getLong(int index) {
+		Object obj = getObject(index);
+		return obj == null ? -1 : Long.parseLong(obj.toString());
+	}
+
+	public long getLong(String field) {
+		Object obj = getObject(field);
+		return obj == null ? -1 : Long.parseLong(obj.toString());
+	}
+
+	public long getGeneralLong(int index) {
+		Object obj = getObject(index);
+		return obj == null ? 0 : Long.parseLong(obj.toString());
+	}
+
+	public long getGeneralLong(String field) {
+		Object obj = getObject(field);
+		return obj == null ? 0 : Long.parseLong(obj.toString());
+	}
+
+	public String getString(int index) {
+		Object obj = getObject(index);
+		return obj == null ? null : obj.toString();
+	}
+
+	public String getString(String field) {
+		Object obj = getObject(field);
+		return obj == null ? null : obj.toString();
+	}
+
+	public String getGeneralString(int index) {
+		Object obj = getObject(index);
+		return obj == null ? "" : obj.toString();
+	}
+
+	public String getGeneralString(String field) {
+		Object obj = getObject(field);
+		return obj == null ? "" : obj.toString();
+	}
+
+	public Object getObject(int index) {
+		if (this.iterator == null || this.currentMap == null || this.keys == null || index <= 0 || index > this.keys.size()) {
+			return null;
+		}
+		return this.currentMap.get(this.keys.get(index - 1));
+	}
+
+	public Object getObject(String field) {
+		if (this.iterator == null || this.currentMap == null) {
+			return null;
+		}
+		return this.currentMap.get(field.toUpperCase());
+	}
+
+	/**
+	 * currentMap的JSON格式
+	 */
+	public JSONObject getJSONObject() {
+		if (this.iterator == null || this.currentMap == null) {
+			return null;
+		}
+		JSONObject json = new JSONObject();
+		Object value = null;
+		for (String k : this.keys) {
+			value = parseValue(this.getObject(k));
+			json.put(k, value);
+		}
+		return json;
+	}
+
+	public static Object parseValue(Object value) {
+		if (value != null) {
+			// 以字符串格式表示时间
+			if ("TIMESTAMP".equals(value.getClass().getSimpleName().toUpperCase())) {
+				Timestamp time = (Timestamp) value;
+				value = DateUtil.parseDateToString(new Date(time.getTime()), Constant.YMD_HMS);
+			}
+			// 科学计数法改为js处理
+		}
+		return value;
+	}
+
+	/**
+	 * currentMap的JSONString格式
+	 */
+	public String getJSON() {
+		if (this.iterator == null || this.currentMap == null) {
+			return null;
+		}
+		return getJSONObject().toString();
+	}
+
+	public Date getDate(int index) {
+		Object obj = getObject(index);
+		return obj == null ? null : (Date) obj;
+	}
+
+	public Date getDate(String field) {
+		Object obj = getObject(field);
+		return obj == null ? null : (Date) obj;
+	}
+
+	public Timestamp getTimestamp(int index) {
+		Object obj = getObject(index);
+		return obj == null ? null : (Timestamp) obj;
+	}
+
+	public Timestamp getTimestamp(String field) {
+		Object obj = getObject(field);
+		return obj == null ? null : (Timestamp) obj;
+	}
+
+	public String getGeneralTimestamp(int index, String format) {
+		Timestamp time = getTimestamp(index);
+		if (time != null)
+			return DateUtil.parseDateToString(new Date(time.getTime()), format);
+		return "";
+	}
+
+	public String getGeneralTimestamp(int index) {
+		return getGeneralTimestamp(index, Constant.YMD_HMS);
+	}
+
+	public String getGeneralTimestamp(String field, String format) {
+		Timestamp time = getTimestamp(field);
+		if (time != null)
+			return DateUtil.parseDateToString(new Date(time.getTime()), format);
+		return "";
+	}
+
+	public String getGeneralTimestamp(String field) {
+		return getGeneralTimestamp(field, Constant.YMD_HMS);
+	}
+
+	public double getSummary(String field) {
+		if (hasNext()) {
+			Iterator<Map<String, Object>> iterator = resultList.iterator();
+			Map<String, Object> map = null;
+			double sum = 0;
+			Object obj = null;
+			while ((map = iterator.next()) != null) {
+				obj = map.get(field.toUpperCase());
+				sum += obj == null ? 0 : Double.parseDouble(obj.toString());
+			}
+			return sum;
+		}
+		return 0;
+	}
+
+	public double getSummary(int index) {
+		if (index <= 0 || index > this.getKeys().size()) {
+			return 0;
+		}
+		return getSummary(this.keys.get(index - 1));
+	}
+}