|
@@ -2,16 +2,36 @@ package com.muzhi.shennongshi.APITest;
|
|
|
|
|
|
|
|
import cn.hutool.core.date.DateTime;
|
|
import cn.hutool.core.date.DateTime;
|
|
|
import cn.hutool.core.date.DateUtil;
|
|
import cn.hutool.core.date.DateUtil;
|
|
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
|
|
+import com.aliyun.dingtalkhrm_1_0.models.QueryHrmEmployeeDismissionInfoResponse;
|
|
|
|
|
+import com.aliyun.dingtalkyida_1_0.models.CreateOrUpdateFormDataResponse;
|
|
|
|
|
+import com.aliyun.dingtalkyida_1_0.models.SearchFormDatasResponse;
|
|
|
|
|
+import com.aliyun.tea.TeaException;
|
|
|
|
|
+import com.aliyun.teautil.models.RuntimeOptions;
|
|
|
|
|
+import com.auth0.jwt.JWT;
|
|
|
|
|
+import com.auth0.jwt.algorithms.Algorithm;
|
|
|
|
|
+import com.dingtalk.api.DefaultDingTalkClient;
|
|
|
|
|
+import com.dingtalk.api.DingTalkClient;
|
|
|
|
|
+import com.dingtalk.api.request.OapiAttendanceGetcolumnvalRequest;
|
|
|
|
|
+import com.dingtalk.api.response.OapiAttendanceGetcolumnvalResponse;
|
|
|
import com.muzhi.shennongshi.service.AccessTokenService;
|
|
import com.muzhi.shennongshi.service.AccessTokenService;
|
|
|
|
|
+import com.taobao.api.ApiException;
|
|
|
|
|
+import com.taobao.api.internal.util.StringUtils;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
+import okhttp3.*;
|
|
|
import org.junit.jupiter.api.Test;
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
|
+import org.slf4j.Logger;
|
|
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.boot.test.context.SpringBootTest;
|
|
import org.springframework.boot.test.context.SpringBootTest;
|
|
|
|
|
|
|
|
|
|
+import javax.crypto.Mac;
|
|
|
|
|
+import java.io.IOException;
|
|
|
import java.text.DateFormat;
|
|
import java.text.DateFormat;
|
|
|
import java.text.SimpleDateFormat;
|
|
import java.text.SimpleDateFormat;
|
|
|
-import java.util.Calendar;
|
|
|
|
|
-import java.util.Date;
|
|
|
|
|
|
|
+import java.util.*;
|
|
|
|
|
|
|
|
@SpringBootTest
|
|
@SpringBootTest
|
|
|
@Slf4j
|
|
@Slf4j
|
|
@@ -214,4 +234,835 @@ public class Test1 {
|
|
|
// //4364bbbc-3480-4cf2-a6c6-2e5a42635892
|
|
// //4364bbbc-3480-4cf2-a6c6-2e5a42635892
|
|
|
// //1672913268514
|
|
// //1672913268514
|
|
|
// }
|
|
// }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ //宜搭接口调用
|
|
|
|
|
+ public static com.aliyun.dingtalkyida_1_0.Client createClient2() throws Exception {
|
|
|
|
|
+ com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config();
|
|
|
|
|
+ config.protocol = "https";
|
|
|
|
|
+ config.regionId = "central";
|
|
|
|
|
+ return new com.aliyun.dingtalkyida_1_0.Client(config);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ //钉钉接口调用
|
|
|
|
|
+ public static com.aliyun.dingtalkhrm_1_0.Client createClient() throws Exception {
|
|
|
|
|
+ com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config();
|
|
|
|
|
+ config.protocol = "https";
|
|
|
|
|
+ config.regionId = "central";
|
|
|
|
|
+ return new com.aliyun.dingtalkhrm_1_0.Client(config);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ //获取宜搭表单数据【人员信息底表】
|
|
|
|
|
+ @Test
|
|
|
|
|
+ public void getYidaRenyuanxinxidibiao(){
|
|
|
|
|
+
|
|
|
|
|
+ JSONObject jsonObject = null;
|
|
|
|
|
+
|
|
|
|
|
+ int size = 100;
|
|
|
|
|
+ int page = 1;
|
|
|
|
|
+
|
|
|
|
|
+ List listAll = new ArrayList();
|
|
|
|
|
+
|
|
|
|
|
+ do {
|
|
|
|
|
+
|
|
|
|
|
+ //【神农氏架构】
|
|
|
|
|
+ try {
|
|
|
|
|
+ com.aliyun.dingtalkyida_1_0.Client client = createClient2();
|
|
|
|
|
+ com.aliyun.dingtalkyida_1_0.models.SearchFormDatasHeaders searchFormDatasHeaders = new com.aliyun.dingtalkyida_1_0.models.SearchFormDatasHeaders();
|
|
|
|
|
+ searchFormDatasHeaders.xAcsDingtalkAccessToken = accessTokenService.getAccessToken();
|
|
|
|
|
+ com.aliyun.dingtalkyida_1_0.models.SearchFormDatasRequest searchFormDatasRequest = new com.aliyun.dingtalkyida_1_0.models.SearchFormDatasRequest()
|
|
|
|
|
+ .setSystemToken("LO966L91E3JG3VA0BAE2Z6F75BYV2RBPPRQPL5")
|
|
|
|
|
+// .setSearchFieldJson(mapAllStr)
|
|
|
|
|
+ .setCurrentPage(page)
|
|
|
|
|
+ .setPageSize(size)
|
|
|
|
|
+ .setFormUuid("FORM-06C1245BFC21473690EF3528C7111F64V1YO")
|
|
|
|
|
+ .setUserId("yida_pub_account")
|
|
|
|
|
+ .setAppType("APP_KLB0U4PB8MELVV1R5LSX");
|
|
|
|
|
+
|
|
|
|
|
+ SearchFormDatasResponse searchFormDatasResponse = client.searchFormDatasWithOptions(searchFormDatasRequest, searchFormDatasHeaders, new RuntimeOptions());
|
|
|
|
|
+// System.out.println(JSON.toJSONString(searchFormDatasResponse.getBody()));
|
|
|
|
|
+ String s = JSON.toJSONString(searchFormDatasResponse.getBody());
|
|
|
|
|
+ jsonObject = JSON.parseObject(s);
|
|
|
|
|
+// System.out.println("宜搭数据高级条件查询【人员信息底表】接口object对象:" + jsonObject);
|
|
|
|
|
+ } catch (TeaException err) {
|
|
|
|
|
+ if (!com.aliyun.teautil.Common.empty(err.code) && !com.aliyun.teautil.Common.empty(err.message)) {
|
|
|
|
|
+ // err 中含有 code 和 message 属性,可帮助开发定位问题
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ } catch (Exception _err) {
|
|
|
|
|
+ TeaException err = new TeaException(_err.getMessage(), _err);
|
|
|
|
|
+ if (!com.aliyun.teautil.Common.empty(err.code) && !com.aliyun.teautil.Common.empty(err.message)) {
|
|
|
|
|
+ // err 中含有 code 和 message 属性,可帮助开发定位问题
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ JSONArray data = jsonObject.getJSONArray("data");
|
|
|
|
|
+// System.out.println("返回的宜搭data:" + data);
|
|
|
|
|
+
|
|
|
|
|
+ if (data.isEmpty()) {
|
|
|
|
|
+ System.out.println("查询【人员信息底表】返回数据为空!");
|
|
|
|
|
+ } else {
|
|
|
|
|
+ for (int i = 0; i < data.size(); i++) {
|
|
|
|
|
+ JSONObject formData = data.getJSONObject(i).getJSONObject("formData");
|
|
|
|
|
+ Map map = new HashMap<>();
|
|
|
|
|
+
|
|
|
|
|
+ //实例ID
|
|
|
|
|
+ String shiliID = data.getJSONObject(i).getString("formInstanceId");
|
|
|
|
|
+ System.out.println("实例ID===>" + shiliID);
|
|
|
|
|
+
|
|
|
|
|
+ //钉钉userid
|
|
|
|
|
+ String userid = formData.getString("textField_lkkg5ay7");
|
|
|
|
|
+ System.out.println("钉钉userid===>" + userid);
|
|
|
|
|
+ //人员姓名
|
|
|
|
|
+ String username = formData.getString("textField_lkkdkp5m");
|
|
|
|
|
+ System.out.println("人员姓名===>" + username);
|
|
|
|
|
+ //主部门
|
|
|
|
|
+ String zhubumen = formData.getString("textField_lm64k9gb");
|
|
|
|
|
+ System.out.println("主部门===>" + zhubumen);
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ map.put("shiliID",shiliID);
|
|
|
|
|
+
|
|
|
|
|
+ map.put("userid",userid);
|
|
|
|
|
+ map.put("username",username);
|
|
|
|
|
+ map.put("zhubumen",zhubumen);
|
|
|
|
|
+
|
|
|
|
|
+ listAll.add(map);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (jsonObject.getFloat("totalCount") / 100 > jsonObject.getInteger("currentPage")){
|
|
|
|
|
+ page = page + 1;
|
|
|
|
|
+ System.out.println("下一次待查询分页:" + page);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ }while (jsonObject.getFloat("totalCount") / 100 > jsonObject.getInteger("currentPage"));
|
|
|
|
|
+
|
|
|
|
|
+ JSONArray jsonArray = JSON.parseArray(JSON.toJSONString(listAll));
|
|
|
|
|
+ System.out.println("封装【人员信息底表】明细jsonArray:" + jsonArray);
|
|
|
|
|
+
|
|
|
|
|
+// return jsonArray;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ @Test
|
|
|
|
|
+ public void time(){
|
|
|
|
|
+
|
|
|
|
|
+ //获取当前时间
|
|
|
|
|
+ Date Date = new Date(System.currentTimeMillis());
|
|
|
|
|
+ System.out.println("当前时间:" + Date);
|
|
|
|
|
+
|
|
|
|
|
+ String lastMonthNow = null;
|
|
|
|
|
+ //本月
|
|
|
|
|
+ //截取当天本月的年月
|
|
|
|
|
+ Calendar calendar123 = Calendar.getInstance();
|
|
|
|
|
+ calendar123.setTime(Date);
|
|
|
|
|
+ calendar123.add(Calendar.MONTH,0);
|
|
|
|
|
+ lastMonthNow = new SimpleDateFormat("yyyy-MM").format(calendar123.getTime());
|
|
|
|
|
+ System.out.println("当天本月的日期,文本格式(月)" + lastMonthNow);
|
|
|
|
|
+
|
|
|
|
|
+ //将当前月份转换成毫秒级时间戳
|
|
|
|
|
+ long lastMonthNowTime = 0;
|
|
|
|
|
+ try {
|
|
|
|
|
+ lastMonthNowTime = new SimpleDateFormat("yyyy-MM").parse(lastMonthNow).getTime();
|
|
|
|
|
+ }catch (Exception e){
|
|
|
|
|
+ e.printStackTrace();
|
|
|
|
|
+ }
|
|
|
|
|
+ System.out.println("当前月份时间戳:" + lastMonthNowTime);
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ //获取考勤
|
|
|
|
|
+ @Test
|
|
|
|
|
+ public void getKaoqin(){
|
|
|
|
|
+
|
|
|
|
|
+ String userId = "206703181036284980";
|
|
|
|
|
+
|
|
|
|
|
+ /*计算规则*/
|
|
|
|
|
+ String FORMtime = null;
|
|
|
|
|
+ String TOtime = null;
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ //获取当前时间
|
|
|
|
|
+ Date Date = new Date(System.currentTimeMillis());
|
|
|
|
|
+ System.out.println("当前时间:" + Date);
|
|
|
|
|
+ /*
|
|
|
|
|
+ * 获取本月的第一天和最后一天的时间
|
|
|
|
|
+ * */
|
|
|
|
|
+ Calendar calendar111 = Calendar.getInstance();
|
|
|
|
|
+ calendar111.setTime(Date);
|
|
|
|
|
+ //本月第一天
|
|
|
|
|
+ calendar111.add(Calendar.MONTH,0);
|
|
|
|
|
+ calendar111.set(Calendar.DAY_OF_MONTH,1);
|
|
|
|
|
+ calendar111.set(Calendar.HOUR_OF_DAY,0);
|
|
|
|
|
+ calendar111.set(Calendar.MINUTE,0);
|
|
|
|
|
+ calendar111.set(Calendar.SECOND,0);
|
|
|
|
|
+ calendar111.set(Calendar.MILLISECOND,0);
|
|
|
|
|
+ FORMtime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(calendar111.getTime());
|
|
|
|
|
+ System.out.println("本月第一天零点:" + FORMtime);
|
|
|
|
|
+
|
|
|
|
|
+ Calendar calendar222 = Calendar.getInstance();
|
|
|
|
|
+// int month222 = calendar222.get(Calendar.MONTH);
|
|
|
|
|
+ //本月最后一天
|
|
|
|
|
+ calendar222.add(Calendar.MONTH,0);
|
|
|
|
|
+ calendar222.set(Calendar.DAY_OF_MONTH,calendar222.getActualMaximum(Calendar.DAY_OF_MONTH));
|
|
|
|
|
+ calendar222.set(Calendar.HOUR_OF_DAY,0);
|
|
|
|
|
+ calendar222.set(Calendar.MINUTE,0);
|
|
|
|
|
+ calendar222.set(Calendar.SECOND,0);
|
|
|
|
|
+ calendar222.set(Calendar.MILLISECOND,0);
|
|
|
|
|
+ TOtime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(calendar222.getTime());
|
|
|
|
|
+ System.out.println("本月最后一天零点:" + TOtime);
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ FORMtime = "2024-03-01 00:00:00";
|
|
|
|
|
+ TOtime = "2024-03-31 00:00:00";
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ float chuqintianshu = 0;
|
|
|
|
|
+ float yingchuqintianshu = 0;
|
|
|
|
|
+
|
|
|
|
|
+ //查询上月出勤数据,统计上月应出勤天数
|
|
|
|
|
+ try {
|
|
|
|
|
+ DingTalkClient client11 = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/attendance/getcolumnval");
|
|
|
|
|
+ OapiAttendanceGetcolumnvalRequest req = new OapiAttendanceGetcolumnvalRequest();
|
|
|
|
|
+ //TODO 待查询人员的userid
|
|
|
|
|
+ req.setUserid(userId);
|
|
|
|
|
+ //考勤报表列定义查出来的工作时长的列id(固定)
|
|
|
|
|
+ req.setColumnIdList("140064190,140064193");
|
|
|
|
|
+ //TODO 查询开始时间
|
|
|
|
|
+ req.setFromDate(StringUtils.parseDateTime(FORMtime));
|
|
|
|
|
+ //TODO 查询结束时间
|
|
|
|
|
+ req.setToDate(StringUtils.parseDateTime(TOtime));
|
|
|
|
|
+ OapiAttendanceGetcolumnvalResponse rsp = client11.execute(req, accessTokenService.getAccessToken());
|
|
|
|
|
+ System.out.println("钉钉月度考勤报表接口返回信息:" + rsp.getBody());
|
|
|
|
|
+ String string = rsp.getBody();
|
|
|
|
|
+ JSONObject jsonObjectKaoqin = JSON.parseObject(string);
|
|
|
|
|
+
|
|
|
|
|
+ int errcode = jsonObjectKaoqin.getInteger("errcode");
|
|
|
|
|
+ System.out.println("考勤时间周期查询结果状态码:" + errcode);
|
|
|
|
|
+ String errmsg = jsonObjectKaoqin.getString("errmsg");
|
|
|
|
|
+ System.out.println("考勤时间周期查询结果状态信息:" + errmsg);
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ if (errcode != 0){
|
|
|
|
|
+ log.info("考勤时间周期查询结果反馈异常,异常状态码:" + errcode + "【"+ errmsg +"】");
|
|
|
|
|
+
|
|
|
|
|
+ }else {
|
|
|
|
|
+ //应出勤天数
|
|
|
|
|
+ JSONArray jsonArray1 = jsonObjectKaoqin.getJSONObject("result").
|
|
|
|
|
+ getJSONArray("column_vals").
|
|
|
|
|
+ getJSONObject(0).
|
|
|
|
|
+ getJSONArray("column_vals");
|
|
|
|
|
+ for (int x = 0; x<jsonArray1.size(); x++){
|
|
|
|
|
+ //应出勤天数
|
|
|
|
|
+ String value = jsonArray1.getJSONObject(x).getString("value");
|
|
|
|
|
+ System.out.println("【钉钉月度报表返回】应出勤天数:" + value);
|
|
|
|
|
+ float v = Float.parseFloat(value);
|
|
|
|
|
+ if (v > 0) {
|
|
|
|
|
+ System.out.println("应出勤天数,进行循环统计!");
|
|
|
|
|
+ yingchuqintianshu = yingchuqintianshu + 1;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ //出勤天数
|
|
|
|
|
+ JSONArray jsonArray = jsonObjectKaoqin.getJSONObject("result").
|
|
|
|
|
+ getJSONArray("column_vals").
|
|
|
|
|
+ getJSONObject(1).
|
|
|
|
|
+ getJSONArray("column_vals");
|
|
|
|
|
+ for (int x = 0; x<jsonArray.size(); x++){
|
|
|
|
|
+ //出勤天数
|
|
|
|
|
+ String value = jsonArray.getJSONObject(x).getString("value");
|
|
|
|
|
+ System.out.println("【钉钉月度报表返回】出勤天数:" + value);
|
|
|
|
|
+ float v = Float.parseFloat(value);
|
|
|
|
|
+ if (v > 0) {
|
|
|
|
|
+ System.out.println("出勤天数,进行循环统计!");
|
|
|
|
|
+ chuqintianshu = chuqintianshu + 1;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ } catch (ApiException e) {
|
|
|
|
|
+ e.printStackTrace();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ System.out.println("本月当前应出勤天数:" + yingchuqintianshu);
|
|
|
|
|
+ System.out.println("本月当前实际出勤天数:" + chuqintianshu);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ //获取节假日假期表
|
|
|
|
|
+ @Test
|
|
|
|
|
+ public void getJiaqi(){
|
|
|
|
|
+
|
|
|
|
|
+// //获取当前时间
|
|
|
|
|
+// Date Date = new Date(System.currentTimeMillis());
|
|
|
|
|
+// System.out.println("当前时间:" + Date);
|
|
|
|
|
+// //截取当天本月的年月
|
|
|
|
|
+// Calendar calendar123 = Calendar.getInstance();
|
|
|
|
|
+// calendar123.setTime(Date);
|
|
|
|
|
+// calendar123.add(Calendar.MONTH,0);
|
|
|
|
|
+// String lastYearNow = new SimpleDateFormat("yyyy").format(calendar123.getTime());
|
|
|
|
|
+// System.out.println("当天本月的日期,文本格式(月)" + lastYearNow);
|
|
|
|
|
+//
|
|
|
|
|
+// //封装根据当前年份作为查询条件
|
|
|
|
|
+// Map mapAll = new HashMap();
|
|
|
|
|
+// //查询实际统计月份
|
|
|
|
|
+// mapAll.put("textField_lfw815u7",lastYearNow);
|
|
|
|
|
+//
|
|
|
|
|
+// String mapAllStr = JSON.toJSONString(mapAll);
|
|
|
|
|
+// System.out.println("封装修改的字段参数:" + mapAllStr);
|
|
|
|
|
+
|
|
|
|
|
+ JSONObject jsonObject = null;
|
|
|
|
|
+
|
|
|
|
|
+ int size = 100;
|
|
|
|
|
+ int page = 1;
|
|
|
|
|
+
|
|
|
|
|
+ List listAll = new ArrayList();
|
|
|
|
|
+
|
|
|
|
|
+ do {
|
|
|
|
|
+
|
|
|
|
|
+ //【神农氏架构】
|
|
|
|
|
+ try {
|
|
|
|
|
+ com.aliyun.dingtalkyida_1_0.Client client = createClient2();
|
|
|
|
|
+ com.aliyun.dingtalkyida_1_0.models.SearchFormDatasHeaders searchFormDatasHeaders = new com.aliyun.dingtalkyida_1_0.models.SearchFormDatasHeaders();
|
|
|
|
|
+ searchFormDatasHeaders.xAcsDingtalkAccessToken = accessTokenService.getAccessToken();
|
|
|
|
|
+ com.aliyun.dingtalkyida_1_0.models.SearchFormDatasRequest searchFormDatasRequest = new com.aliyun.dingtalkyida_1_0.models.SearchFormDatasRequest()
|
|
|
|
|
+ .setSystemToken("LO966L91E3JG3VA0BAE2Z6F75BYV2RBPPRQPL5")
|
|
|
|
|
+// .setSearchFieldJson(mapAllStr)
|
|
|
|
|
+ .setCurrentPage(page)
|
|
|
|
|
+ .setPageSize(size)
|
|
|
|
|
+ .setFormUuid("FORM-4226FF0F9E164EA7A85E143CBE57172BP63G")
|
|
|
|
|
+ .setUserId("yida_pub_account")
|
|
|
|
|
+ .setAppType("APP_KLB0U4PB8MELVV1R5LSX");
|
|
|
|
|
+
|
|
|
|
|
+ SearchFormDatasResponse searchFormDatasResponse = client.searchFormDatasWithOptions(searchFormDatasRequest, searchFormDatasHeaders, new RuntimeOptions());
|
|
|
|
|
+// System.out.println(JSON.toJSONString(searchFormDatasResponse.getBody()));
|
|
|
|
|
+ String s = JSON.toJSONString(searchFormDatasResponse.getBody());
|
|
|
|
|
+ jsonObject = JSON.parseObject(s);
|
|
|
|
|
+// System.out.println("钉钉宜搭数据高级条件查询【节假日假期表】接口object对象:" + jsonObject);
|
|
|
|
|
+ } catch (TeaException err) {
|
|
|
|
|
+ if (!com.aliyun.teautil.Common.empty(err.code) && !com.aliyun.teautil.Common.empty(err.message)) {
|
|
|
|
|
+ // err 中含有 code 和 message 属性,可帮助开发定位问题
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ } catch (Exception _err) {
|
|
|
|
|
+ TeaException err = new TeaException(_err.getMessage(), _err);
|
|
|
|
|
+ if (!com.aliyun.teautil.Common.empty(err.code) && !com.aliyun.teautil.Common.empty(err.message)) {
|
|
|
|
|
+ // err 中含有 code 和 message 属性,可帮助开发定位问题
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ JSONArray data = jsonObject.getJSONArray("data");
|
|
|
|
|
+// System.out.println("返回的宜搭data:" + data);
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ if (data.isEmpty()) {
|
|
|
|
|
+ System.out.println("查询【节假日假期表】返回数据为空!");
|
|
|
|
|
+ } else {
|
|
|
|
|
+ for (int i = 0; i < data.size(); i++) {
|
|
|
|
|
+ JSONObject formData = data.getJSONObject(i).getJSONObject("formData");
|
|
|
|
|
+// System.out.println("循环返回的宜搭formData:" + formData);
|
|
|
|
|
+ Map map = new HashMap<>();
|
|
|
|
|
+
|
|
|
|
|
+ //实例ID
|
|
|
|
|
+ String shiliID = data.getJSONObject(i).getString("formInstanceId");
|
|
|
|
|
+ System.out.println("实例ID===>" + shiliID);
|
|
|
|
|
+
|
|
|
|
|
+ //年份
|
|
|
|
|
+ String year = formData.getString("dateField_lqaqhdcq");
|
|
|
|
|
+ System.out.println("年份===>" + year);
|
|
|
|
|
+ //假期名称
|
|
|
|
|
+ String name = formData.getString("textField_lprq5uv7");
|
|
|
|
|
+ System.out.println("假期名称===>" + name);
|
|
|
|
|
+ //假期日期
|
|
|
|
|
+ String time = formData.getString("dateField_lprq5uv8");
|
|
|
|
|
+ System.out.println("假期日期===>" + time);
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ map.put("shiliID",shiliID);
|
|
|
|
|
+
|
|
|
|
|
+ map.put("year",year);
|
|
|
|
|
+ map.put("name",name);
|
|
|
|
|
+ map.put("time",time);
|
|
|
|
|
+
|
|
|
|
|
+ System.out.println("每次封装节假日假期信息的map:" + map);
|
|
|
|
|
+
|
|
|
|
|
+ listAll.add(map);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (jsonObject.getFloat("totalCount") / 100 > jsonObject.getInteger("currentPage")){
|
|
|
|
|
+ page = page + 1;
|
|
|
|
|
+ System.out.println("下一次待查询分页:" + page);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ }while (jsonObject.getFloat("totalCount") / 100 > jsonObject.getInteger("currentPage"));
|
|
|
|
|
+
|
|
|
|
|
+ JSONArray jsonArray = JSON.parseArray(JSON.toJSONString(listAll));
|
|
|
|
|
+ System.out.println("封装【节假日假期表】明细jsonArray:" + jsonArray);
|
|
|
|
|
+
|
|
|
|
|
+ String jiabanshijian = "2024-05-04 15:39";
|
|
|
|
|
+ String substring = jiabanshijian.substring(0, 10);
|
|
|
|
|
+ System.out.println("截取后的加班时间:" + substring);
|
|
|
|
|
+
|
|
|
|
|
+ //调用封装方法,获取【节假日假期】
|
|
|
|
|
+// JSONArray jiaqi = getJiaqi();
|
|
|
|
|
+ for (int k = 0; k < jsonArray.size(); k++) {
|
|
|
|
|
+ JSONObject jsonObject1 = jsonArray.getJSONObject(k);
|
|
|
|
|
+ String name = jsonObject1.getString("name");
|
|
|
|
|
+ System.out.println("循环获取的节假日假期名称:" + name);
|
|
|
|
|
+ long time = jsonObject1.getLong("time");
|
|
|
|
|
+ System.out.println("循环获取的节假日假期[long型]:" + time);
|
|
|
|
|
+
|
|
|
|
|
+ //转换成时间格式
|
|
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); // 设置要输出的日期时间格式
|
|
|
|
|
+ String formattedDateTime = sdf.format(new Date(time)); // 进行格式化操作
|
|
|
|
|
+ System.out.println("转换成时间格式:" + formattedDateTime);
|
|
|
|
|
+
|
|
|
|
|
+ if (formattedDateTime.equals(substring)){
|
|
|
|
|
+ log.info("请假日期和当前循环到的假期匹配!!!");
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+// return jsonArray;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ //获取假期规则配置【请假规则】
|
|
|
|
|
+ @Test
|
|
|
|
|
+ public void getQingjiaGuize(){
|
|
|
|
|
+
|
|
|
|
|
+ String ygjqlx = "兼职";
|
|
|
|
|
+
|
|
|
|
|
+ //封装根据当前年份作为查询条件
|
|
|
|
|
+ Map mapAll = new HashMap();
|
|
|
|
|
+ //查询实际统计月份
|
|
|
|
|
+ mapAll.put("checkboxField_lqaxex6p",ygjqlx);
|
|
|
|
|
+
|
|
|
|
|
+ String mapAllStr = JSON.toJSONString(mapAll);
|
|
|
|
|
+ System.out.println("封装修改的字段参数:" + mapAllStr);
|
|
|
|
|
+
|
|
|
|
|
+ JSONObject jsonObject = null;
|
|
|
|
|
+
|
|
|
|
|
+ int size = 100;
|
|
|
|
|
+ int page = 1;
|
|
|
|
|
+
|
|
|
|
|
+ List listAll = new ArrayList();
|
|
|
|
|
+
|
|
|
|
|
+ do {
|
|
|
|
|
+
|
|
|
|
|
+ //【神农氏架构】
|
|
|
|
|
+ try {
|
|
|
|
|
+ com.aliyun.dingtalkyida_1_0.Client client = createClient2();
|
|
|
|
|
+ com.aliyun.dingtalkyida_1_0.models.SearchFormDatasHeaders searchFormDatasHeaders = new com.aliyun.dingtalkyida_1_0.models.SearchFormDatasHeaders();
|
|
|
|
|
+ searchFormDatasHeaders.xAcsDingtalkAccessToken = accessTokenService.getAccessToken();
|
|
|
|
|
+ com.aliyun.dingtalkyida_1_0.models.SearchFormDatasRequest searchFormDatasRequest = new com.aliyun.dingtalkyida_1_0.models.SearchFormDatasRequest()
|
|
|
|
|
+ .setSystemToken("LO966L91E3JG3VA0BAE2Z6F75BYV2RBPPRQPL5")
|
|
|
|
|
+ .setSearchFieldJson(mapAllStr)
|
|
|
|
|
+ .setCurrentPage(page)
|
|
|
|
|
+ .setPageSize(size)
|
|
|
|
|
+ .setFormUuid("FORM-A0DCD4AE4645437BB4614A6B2B033BFDT9T1")
|
|
|
|
|
+ .setUserId("yida_pub_account")
|
|
|
|
|
+ .setAppType("APP_KLB0U4PB8MELVV1R5LSX");
|
|
|
|
|
+
|
|
|
|
|
+ SearchFormDatasResponse searchFormDatasResponse = client.searchFormDatasWithOptions(searchFormDatasRequest, searchFormDatasHeaders, new RuntimeOptions());
|
|
|
|
|
+// System.out.println(JSON.toJSONString(searchFormDatasResponse.getBody()));
|
|
|
|
|
+ String s = JSON.toJSONString(searchFormDatasResponse.getBody());
|
|
|
|
|
+ jsonObject = JSON.parseObject(s);
|
|
|
|
|
+// System.out.println("钉钉宜搭数据高级条件查询【请假规则表】接口object对象:" + jsonObject);
|
|
|
|
|
+ } catch (TeaException err) {
|
|
|
|
|
+ if (!com.aliyun.teautil.Common.empty(err.code) && !com.aliyun.teautil.Common.empty(err.message)) {
|
|
|
|
|
+ // err 中含有 code 和 message 属性,可帮助开发定位问题
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ } catch (Exception _err) {
|
|
|
|
|
+ TeaException err = new TeaException(_err.getMessage(), _err);
|
|
|
|
|
+ if (!com.aliyun.teautil.Common.empty(err.code) && !com.aliyun.teautil.Common.empty(err.message)) {
|
|
|
|
|
+ // err 中含有 code 和 message 属性,可帮助开发定位问题
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ JSONArray data = jsonObject.getJSONArray("data");
|
|
|
|
|
+// System.out.println("返回的宜搭data:" + data);
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ if (data.isEmpty()) {
|
|
|
|
|
+ System.out.println("查询【请假规则表】返回数据为空!");
|
|
|
|
|
+ } else {
|
|
|
|
|
+ for (int i = 0; i < data.size(); i++) {
|
|
|
|
|
+ JSONObject formData = data.getJSONObject(i).getJSONObject("formData");
|
|
|
|
|
+// System.out.println("循环返回的宜搭formData:" + formData);
|
|
|
|
|
+ Map map = new HashMap<>();
|
|
|
|
|
+
|
|
|
|
|
+ //实例ID
|
|
|
|
|
+ String shiliID = data.getJSONObject(i).getString("formInstanceId");
|
|
|
|
|
+ System.out.println("实例ID===>" + shiliID);
|
|
|
|
|
+
|
|
|
|
|
+ //员工假期类型
|
|
|
|
|
+ String yuangongjiaqileixing = formData.getString("checkboxField_lqaxex6p");
|
|
|
|
|
+ System.out.println("员工假期类型===>" + yuangongjiaqileixing);
|
|
|
|
|
+ //假期类型
|
|
|
|
|
+ String jiaqileixing = formData.getString("checkboxField_lqaxex6s");
|
|
|
|
|
+ System.out.println("假期类型===>" + jiaqileixing);
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ map.put("shiliID",shiliID);
|
|
|
|
|
+
|
|
|
|
|
+ map.put("yuangongjiaqileixing",yuangongjiaqileixing);
|
|
|
|
|
+ map.put("jiaqileixing",jiaqileixing);
|
|
|
|
|
+
|
|
|
|
|
+ System.out.println("每次封装请假规则信息的map:" + map);
|
|
|
|
|
+
|
|
|
|
|
+ listAll.add(map);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (jsonObject.getFloat("totalCount") / 100 > jsonObject.getInteger("currentPage")){
|
|
|
|
|
+ page = page + 1;
|
|
|
|
|
+ System.out.println("下一次待查询分页:" + page);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ }while (jsonObject.getFloat("totalCount") / 100 > jsonObject.getInteger("currentPage"));
|
|
|
|
|
+
|
|
|
|
|
+ JSONArray jsonArray = JSON.parseArray(JSON.toJSONString(listAll));
|
|
|
|
|
+ System.out.println("封装【请假规则表】明细jsonArray:" + jsonArray);
|
|
|
|
|
+
|
|
|
|
|
+ for (int i = 0; i < jsonArray.size(); i++) {
|
|
|
|
|
+ JSONObject jsonObject1 = jsonArray.getJSONObject(i);
|
|
|
|
|
+ String jiaqileixing = jsonObject1.getString("jiaqileixing");
|
|
|
|
|
+ JSONArray jiaqileixingArray = JSON.parseArray(jiaqileixing);
|
|
|
|
|
+ System.out.println("该类型员工可请假类型:" + jiaqileixingArray);
|
|
|
|
|
+ for (int j = 0; j < jiaqileixingArray.size(); j++) {
|
|
|
|
|
+ String string = jiaqileixingArray.getString(j);
|
|
|
|
|
+ System.out.println("循环获取请假类型:" + string);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+// return jsonArray;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ //批量获取离职人员信息
|
|
|
|
|
+ @Test
|
|
|
|
|
+ public void getLizhiRenyuan(){
|
|
|
|
|
+
|
|
|
|
|
+ String userId = "10412065201994340688";
|
|
|
|
|
+
|
|
|
|
|
+ JSONObject jsonObject = null;
|
|
|
|
|
+ try {
|
|
|
|
|
+ com.aliyun.dingtalkhrm_1_0.Client client = createClient();
|
|
|
|
|
+ com.aliyun.dingtalkhrm_1_0.models.QueryHrmEmployeeDismissionInfoHeaders queryHrmEmployeeDismissionInfoHeaders = new com.aliyun.dingtalkhrm_1_0.models.QueryHrmEmployeeDismissionInfoHeaders();
|
|
|
|
|
+ queryHrmEmployeeDismissionInfoHeaders.xAcsDingtalkAccessToken = accessTokenService.getAccessToken();
|
|
|
|
|
+ com.aliyun.dingtalkhrm_1_0.models.QueryHrmEmployeeDismissionInfoRequest queryHrmEmployeeDismissionInfoRequest = new com.aliyun.dingtalkhrm_1_0.models.QueryHrmEmployeeDismissionInfoRequest()
|
|
|
|
|
+ .setUserIdList(java.util.Arrays.asList(userId));
|
|
|
|
|
+
|
|
|
|
|
+ QueryHrmEmployeeDismissionInfoResponse queryHrmEmployeeDismissionInfoResponse = client.queryHrmEmployeeDismissionInfoWithOptions(queryHrmEmployeeDismissionInfoRequest, queryHrmEmployeeDismissionInfoHeaders, new RuntimeOptions());
|
|
|
|
|
+ String s = JSON.toJSONString(queryHrmEmployeeDismissionInfoResponse.getBody());
|
|
|
|
|
+ jsonObject = JSON.parseObject(s);
|
|
|
|
|
+ System.out.println("批量获取离职人员信息:" + jsonObject);
|
|
|
|
|
+ } catch (TeaException err) {
|
|
|
|
|
+ if (!com.aliyun.teautil.Common.empty(err.code) && !com.aliyun.teautil.Common.empty(err.message)) {
|
|
|
|
|
+ // err 中含有 code 和 message 属性,可帮助开发定位问题
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ } catch (Exception _err) {
|
|
|
|
|
+ TeaException err = new TeaException(_err.getMessage(), _err);
|
|
|
|
|
+ if (!com.aliyun.teautil.Common.empty(err.code) && !com.aliyun.teautil.Common.empty(err.message)) {
|
|
|
|
|
+ // err 中含有 code 和 message 属性,可帮助开发定位问题
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ String status = "0";
|
|
|
|
|
+ //员工状态:1:待离职。2:已离职。3:非待离职或非已离职。4:已提交离职审批单,审批单暂未通过。
|
|
|
|
|
+ JSONArray jsonArray = jsonObject.getJSONArray("result");
|
|
|
|
|
+ if (!jsonArray.isEmpty()){
|
|
|
|
|
+ status = jsonArray.getJSONObject(0).getString("status");
|
|
|
|
|
+ }
|
|
|
|
|
+ System.out.println("员工状态【1:待离职。2:已离职。3:非待离职或非已离职。4:已提交离职审批单,审批单暂未通过。】:" + status);
|
|
|
|
|
+
|
|
|
|
|
+// if (!status.equals("2")){
|
|
|
|
|
+// System.out.println("该员工未离职,【更新】当前宜搭应出勤天数!");
|
|
|
|
|
+// }else {
|
|
|
|
|
+// System.out.println("该员工已离职,宜搭应出勤天数【不作更新】!");
|
|
|
|
|
+// }
|
|
|
|
|
+
|
|
|
|
|
+ //判断宜搭人员信息表是否有当前人员userid
|
|
|
|
|
+ /*同步至宜搭*/
|
|
|
|
|
+ Map map = new HashMap();
|
|
|
|
|
+ //员工
|
|
|
|
|
+ map.put("employeeField_ljm75t23", userId);
|
|
|
|
|
+ //状态
|
|
|
|
|
+ if (status.equals("2")) {
|
|
|
|
|
+ log.info("该员工已离职,记录【已离职】状态!");
|
|
|
|
|
+ map.put("selectField_lrecgsfy","已离职");
|
|
|
|
|
+ }else {
|
|
|
|
|
+ log.info("该员工未离职,记录【在职】状态!");
|
|
|
|
|
+ map.put("selectField_lrecgsfy","在职");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ //钉钉userid
|
|
|
|
|
+ map.put("textField_lkkg5ay7", userId);
|
|
|
|
|
+// //姓名
|
|
|
|
|
+// map.put("textField_lkkdkp5m", "");
|
|
|
|
|
+// //主部门
|
|
|
|
|
+// map.put("textField_lm64k9gb", "");
|
|
|
|
|
+
|
|
|
|
|
+ String mapJson = JSON.toJSONString(map);
|
|
|
|
|
+ System.out.println("mapJson:" + mapJson);
|
|
|
|
|
+
|
|
|
|
|
+ //宜搭表单判断查询条件
|
|
|
|
|
+ Map map1 = new HashMap();
|
|
|
|
|
+ //字段编号
|
|
|
|
|
+ map1.put("key", "textField_lkkg5ay7");
|
|
|
|
|
+ //同步类型
|
|
|
|
|
+ map1.put("value", userId);
|
|
|
|
|
+ //控件类型
|
|
|
|
|
+ map1.put("type", "TEXT");
|
|
|
|
|
+ //逻辑判断符
|
|
|
|
|
+ map1.put("operator", "eq");
|
|
|
|
|
+ //控件名称
|
|
|
|
|
+ map1.put("componentName", "TextField");
|
|
|
|
|
+
|
|
|
|
|
+ List list11 = new ArrayList();
|
|
|
|
|
+ list11.add(map1);
|
|
|
|
|
+
|
|
|
|
|
+ String listJson = JSON.toJSONString(list11);
|
|
|
|
|
+ System.out.println("查询条件listJson:" + listJson);
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ //新增或更新表单实例【宜搭】
|
|
|
|
|
+ try {
|
|
|
|
|
+ com.aliyun.dingtalkyida_1_0.Client client11 = createClient2();
|
|
|
|
|
+ com.aliyun.dingtalkyida_1_0.models.CreateOrUpdateFormDataHeaders createOrUpdateFormDataHeaders = new com.aliyun.dingtalkyida_1_0.models.CreateOrUpdateFormDataHeaders();
|
|
|
|
|
+ createOrUpdateFormDataHeaders.xAcsDingtalkAccessToken = accessTokenService.getAccessToken();
|
|
|
|
|
+ com.aliyun.dingtalkyida_1_0.models.CreateOrUpdateFormDataRequest createOrUpdateFormDataRequest = new com.aliyun.dingtalkyida_1_0.models.CreateOrUpdateFormDataRequest()
|
|
|
|
|
+ //应用秘钥
|
|
|
|
|
+ .setSystemToken("LO966L91E3JG3VA0BAE2Z6F75BYV2RBPPRQPL5")
|
|
|
|
|
+ //表单编码
|
|
|
|
|
+ .setFormUuid("FORM-06C1245BFC21473690EF3528C7111F64V1YO")
|
|
|
|
|
+ .setUserId("yida_pub_account")
|
|
|
|
|
+ .setSearchCondition(listJson)
|
|
|
|
|
+ //应用编码
|
|
|
|
|
+ .setAppType("APP_KLB0U4PB8MELVV1R5LSX")
|
|
|
|
|
+ .setFormDataJson(mapJson);
|
|
|
|
|
+
|
|
|
|
|
+ CreateOrUpdateFormDataResponse orUpdateFormDataWithOptions = client11.createOrUpdateFormDataWithOptions(createOrUpdateFormDataRequest, createOrUpdateFormDataHeaders, new RuntimeOptions());
|
|
|
|
|
+ String s = JSON.toJSONString(orUpdateFormDataWithOptions.getBody());
|
|
|
|
|
+ jsonObject = JSON.parseObject(s);
|
|
|
|
|
+ System.out.println("【创建或更新】表单object对象:" + jsonObject);
|
|
|
|
|
+ } catch (TeaException err) {
|
|
|
|
|
+ if (!com.aliyun.teautil.Common.empty(err.code) && !com.aliyun.teautil.Common.empty(err.message)) {
|
|
|
|
|
+ // err 中含有 code 和 message 属性,可帮助开发定位问题
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ } catch (Exception _err) {
|
|
|
|
|
+ TeaException err = new TeaException(_err.getMessage(), _err);
|
|
|
|
|
+ if (!com.aliyun.teautil.Common.empty(err.code) && !com.aliyun.teautil.Common.empty(err.message)) {
|
|
|
|
|
+ // err 中含有 code 和 message 属性,可帮助开发定位问题
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ //用友NC的应用appKey
|
|
|
|
|
+ private String appKey = "d30d5088b7634543b79fbe839e0236f1";
|
|
|
|
|
+ //用友NC的应用密钥
|
|
|
|
|
+ private String appSecret = "0cbc3734343a1957d1d2161ff628babb3dfebf06";
|
|
|
|
|
+ //用友NC的接口访问主地址
|
|
|
|
|
+ private String openApiUrl = "https://c2.yonyoucloud.com/iuap-api-auth";
|
|
|
|
|
+
|
|
|
|
|
+ //获取NC接口的授权token
|
|
|
|
|
+ @Test
|
|
|
|
|
+ public void getNCtoken() throws Exception{
|
|
|
|
|
+
|
|
|
|
|
+// Map<String, String> params = new HashMap<>();
|
|
|
|
|
+// // 除签名外的其他参数
|
|
|
|
|
+// params.put("appKey", appKey);
|
|
|
|
|
+// params.put("timestamp", String.valueOf(System.currentTimeMillis()));
|
|
|
|
|
+// System.out.println("{}," + params);
|
|
|
|
|
+// // 计算签名SignHelper
|
|
|
|
|
+// String signature = SignHelper.sign(params, appSecret);
|
|
|
|
|
+// params.put("signature", signature);
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+// //当前系统时间的毫秒级时间戳
|
|
|
|
|
+// String timestamp = String.valueOf(System.currentTimeMillis());
|
|
|
|
|
+// System.out.println("当前系统时间的毫秒级时间戳:" + timestamp);
|
|
|
|
|
+//
|
|
|
|
|
+// //待加密字符串拼接
|
|
|
|
|
+// String params = "appKey" + appKey + "×tamp=" + timestamp;
|
|
|
|
|
+//
|
|
|
|
|
+// Mac mac = Mac.getInstance("HmacSHA256");
|
|
|
|
|
+// mac.init(new SecretKeySpec(suiteSecret.getBytes(StandardCharsets.UTF_8), "HmacSHA256"));
|
|
|
|
|
+// byte[] signData = mac.doFinal(stringBuilder.toString().getBytes(StandardCharsets.UTF_8));
|
|
|
|
|
+// String base64String = Base64.getEncoder().encodeToString(signData);
|
|
|
|
|
+// return URLEncoder.encode(base64String, "UTF-8");
|
|
|
|
|
+//
|
|
|
|
|
+//
|
|
|
|
|
+// // 请求
|
|
|
|
|
+// // 示例:https://c2.yonyoucloud.com/iuap-api-auth/open-auth/selfAppAuth/getAccessToken?appKey=xxx×tamp=xxx&signature=xxx
|
|
|
|
|
+// String requestUrl = openApiUrl + "/open-auth/selfAppAuth/getAccessToken?" + "appKey=" + appKey + "×tamp=" + timestamp + "&signature=" + signature;
|
|
|
|
|
+// GenericResponse<AccessTokenResponse> response = RequestTool.doGet(requestUrl, params, new TypeReference<GenericResponse<AccessTokenResponse>>() {});
|
|
|
|
|
+//
|
|
|
|
|
+// if (response.isSuccess()) {
|
|
|
|
|
+// return response.getData();
|
|
|
|
|
+// }
|
|
|
|
|
+//
|
|
|
|
|
+// LOGGER.error("请求开放平台接口失败,code: {}, message: {}", response.getCode(), response.getMessage());
|
|
|
|
|
+// throw new RuntimeException("请求开放平台接口失败, code: " + response.getCode() + ", message: " + response.getMessage());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ //测试鸿欢排班接口
|
|
|
|
|
+// @Test
|
|
|
|
|
+ public String getHonghuanToken(){
|
|
|
|
|
+
|
|
|
|
|
+ String corpId = "dinge1f03b6df74842ea";
|
|
|
|
|
+ String AppId = "10005";
|
|
|
|
|
+ String AppSecret = "dIqPwYoLdUuqRsdnKPRLljIFxesmqvcA";
|
|
|
|
|
+ Map map = new HashMap();
|
|
|
|
|
+ map.put("corpId",corpId);
|
|
|
|
|
+ map.put("AppId",AppId);
|
|
|
|
|
+ map.put("AppSecret",AppSecret);
|
|
|
|
|
+ String mapStr = JSON.toJSONString(map);
|
|
|
|
|
+ System.out.println("封装的密钥传参mapStr:" + mapStr);
|
|
|
|
|
+
|
|
|
|
|
+ int status = 0;
|
|
|
|
|
+ JSONObject data = null;
|
|
|
|
|
+ try {
|
|
|
|
|
+ OkHttpClient client = new OkHttpClient().newBuilder()
|
|
|
|
|
+ .build();
|
|
|
|
|
+ MediaType mediaType = MediaType.parse("application/json");
|
|
|
|
|
+ RequestBody body = RequestBody.create(mediaType, mapStr);
|
|
|
|
|
+ Request request = new Request.Builder()
|
|
|
|
|
+ .url("https://app67443.eapps.dingtalkcloud.com/topapi/open/login/get_token")
|
|
|
|
|
+ .method("POST", body)
|
|
|
|
|
+ .addHeader("Content-Type", "application/json")
|
|
|
|
|
+ .build();
|
|
|
|
|
+ Response response = client.newCall(request).execute();
|
|
|
|
|
+
|
|
|
|
|
+ String bodyStr = response.body().string();
|
|
|
|
|
+ JSONObject jsonObject = JSON.parseObject(bodyStr);
|
|
|
|
|
+ System.out.println("返回体body:" + jsonObject);
|
|
|
|
|
+
|
|
|
|
|
+ status = jsonObject.getInteger("status");
|
|
|
|
|
+ System.out.println("获取鸿欢授权接口返回状态码:" + status);
|
|
|
|
|
+ data = jsonObject.getJSONObject("data");
|
|
|
|
|
+ System.out.println("获取鸿欢授权接口返回data:" + data);
|
|
|
|
|
+ }catch (IOException e){
|
|
|
|
|
+ e.printStackTrace();
|
|
|
|
|
+ }
|
|
|
|
|
+ String access_token = data.getString("access_token");
|
|
|
|
|
+ System.out.println("获取鸿欢授权接口返回的【token】:" + access_token);
|
|
|
|
|
+
|
|
|
|
|
+ return access_token;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ //获取鸿欢排班信息
|
|
|
|
|
+ @Test
|
|
|
|
|
+ public void getHonghuanPaiban(){
|
|
|
|
|
+
|
|
|
|
|
+ List list = new ArrayList();
|
|
|
|
|
+ list.add("012725692727917145");
|
|
|
|
|
+
|
|
|
|
|
+ Map map = new HashMap();
|
|
|
|
|
+ //待查询人员userid
|
|
|
|
|
+ map.put("userIds", list);
|
|
|
|
|
+ //查询人userid
|
|
|
|
|
+ map.put("op_userid", "0319462021758313");//TODO 待查询人员userid,暂时以固定人员【封渊】
|
|
|
|
|
+ //查询开始日期
|
|
|
|
|
+ map.put("startDate", "2024-06-01");
|
|
|
|
|
+ //查询结束日期
|
|
|
|
|
+ map.put("endDate", "2024-06-30");
|
|
|
|
|
+ String mapStr = JSON.toJSONString(map);
|
|
|
|
|
+ System.out.println("封装排班查询参数:" + mapStr);
|
|
|
|
|
+
|
|
|
|
|
+ int status = 0;
|
|
|
|
|
+ JSONArray data = null;
|
|
|
|
|
+ try {
|
|
|
|
|
+ OkHttpClient client = new OkHttpClient().newBuilder()
|
|
|
|
|
+ .build();
|
|
|
|
|
+ MediaType mediaType = MediaType.parse("application/json");
|
|
|
|
|
+ RequestBody body = RequestBody.create(mediaType, mapStr);
|
|
|
|
|
+ Request request = new Request.Builder()
|
|
|
|
|
+ .url("https://app67443.eapps.dingtalkcloud.com/topapi/open/schedule/batch/user/query")
|
|
|
|
|
+ .method("POST", body)
|
|
|
|
|
+ .addHeader("Content-Type", "application/json")
|
|
|
|
|
+ .addHeader("Authorization", "Bearer " + getHonghuanToken())
|
|
|
|
|
+ .build();
|
|
|
|
|
+ Response response = client.newCall(request).execute();
|
|
|
|
|
+
|
|
|
|
|
+ String bodyStr = response.body().string();
|
|
|
|
|
+ JSONObject jsonObject = JSON.parseObject(bodyStr);
|
|
|
|
|
+ System.out.println("返回体body:" + jsonObject);
|
|
|
|
|
+
|
|
|
|
|
+ status = jsonObject.getInteger("status");
|
|
|
|
|
+ System.out.println("获取鸿欢排班接口返回状态码:" + status);
|
|
|
|
|
+ data = jsonObject.getJSONArray("data");
|
|
|
|
|
+ System.out.println("获取鸿欢排班接口返回data[]:" + data);
|
|
|
|
|
+ }catch (IOException e){
|
|
|
|
|
+ e.printStackTrace();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ //应出勤天数(排班天数)
|
|
|
|
|
+ int ycqts = 0;
|
|
|
|
|
+ if (data == null || data.isEmpty()){
|
|
|
|
|
+ System.out.println("【未获取到】排班信息。。。");
|
|
|
|
|
+ }else {
|
|
|
|
|
+ System.out.println("【获取到】排班信息。。。开始循环统计排班天数。。。");
|
|
|
|
|
+
|
|
|
|
|
+ for (int i = 0; i < data.size(); i++) {
|
|
|
|
|
+ String isRest = data.getJSONObject(i).getString("isRest");
|
|
|
|
|
+ if (isRest.equals("false")){
|
|
|
|
|
+ ycqts = ycqts + 1;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ System.out.println("应出勤天数(排班天数):" + ycqts);
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Test
|
|
|
|
|
+ public void getTime(){
|
|
|
|
|
+
|
|
|
|
|
+ //获取当前时间
|
|
|
|
|
+ Date Date = new Date(System.currentTimeMillis());
|
|
|
|
|
+ System.out.println("当前时间:" + Date);
|
|
|
|
|
+
|
|
|
|
|
+ /*计算规则*/
|
|
|
|
|
+ String FORMtime = null;
|
|
|
|
|
+ String TOtime = null;
|
|
|
|
|
+
|
|
|
|
|
+ /*
|
|
|
|
|
+ * 获取本月的第一天和最后一天的时间
|
|
|
|
|
+ * */
|
|
|
|
|
+ Calendar calendar111 = Calendar.getInstance();
|
|
|
|
|
+ calendar111.setTime(Date);
|
|
|
|
|
+ //本月第一天
|
|
|
|
|
+ calendar111.add(Calendar.MONTH,0);
|
|
|
|
|
+ calendar111.set(Calendar.DAY_OF_MONTH,1);
|
|
|
|
|
+ calendar111.set(Calendar.HOUR_OF_DAY,0);
|
|
|
|
|
+ calendar111.set(Calendar.MINUTE,0);
|
|
|
|
|
+ calendar111.set(Calendar.SECOND,0);
|
|
|
|
|
+ calendar111.set(Calendar.MILLISECOND,0);
|
|
|
|
|
+// FORMtime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(calendar111.getTime());
|
|
|
|
|
+ FORMtime = new SimpleDateFormat("yyyy-MM-dd").format(calendar111.getTime());
|
|
|
|
|
+ System.out.println("本月第一天零点:" + FORMtime);
|
|
|
|
|
+
|
|
|
|
|
+ Calendar calendar222 = Calendar.getInstance();
|
|
|
|
|
+// int month222 = calendar222.get(Calendar.MONTH);
|
|
|
|
|
+ //本月最后一天
|
|
|
|
|
+ calendar222.add(Calendar.MONTH,0);
|
|
|
|
|
+ calendar222.set(Calendar.DAY_OF_MONTH,calendar222.getActualMaximum(Calendar.DAY_OF_MONTH));
|
|
|
|
|
+ calendar222.set(Calendar.HOUR_OF_DAY,0);
|
|
|
|
|
+ calendar222.set(Calendar.MINUTE,0);
|
|
|
|
|
+ calendar222.set(Calendar.SECOND,0);
|
|
|
|
|
+ calendar222.set(Calendar.MILLISECOND,0);
|
|
|
|
|
+// TOtime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(calendar222.getTime());
|
|
|
|
|
+ TOtime = new SimpleDateFormat("yyyy-MM-dd").format(calendar222.getTime());
|
|
|
|
|
+ System.out.println("本月最后一天零点:" + TOtime);
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|