|
@@ -0,0 +1,668 @@
|
|
|
+package com.muzhi.zhizhong.APITest;
|
|
|
+
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.aliyun.dingtalkstorage_1_0.models.CommitFileResponse;
|
|
|
+import com.aliyun.dingtalkstorage_1_0.models.GetFileUploadInfoResponse;
|
|
|
+import com.aliyun.dingtalkworkflow_1_0.models.GetProcessInstanceResponse;
|
|
|
+import com.aliyun.dingtalkworkflow_1_0.models.ListProcessInstanceIdsResponse;
|
|
|
+import com.aliyun.dingtalkworkflow_1_0.models.StartProcessInstanceResponse;
|
|
|
+import com.aliyun.tea.TeaException;
|
|
|
+import com.aliyun.teautil.models.RuntimeOptions;
|
|
|
+import com.dingtalk.api.DefaultDingTalkClient;
|
|
|
+import com.dingtalk.api.DingTalkClient;
|
|
|
+import com.dingtalk.api.request.OapiCspaceAddRequest;
|
|
|
+import com.dingtalk.api.request.OapiProcessinstanceCreateRequest;
|
|
|
+import com.dingtalk.api.request.OapiProcessinstanceCspaceInfoRequest;
|
|
|
+import com.dingtalk.api.request.OapiV2UserGetRequest;
|
|
|
+import com.dingtalk.api.response.OapiCspaceAddResponse;
|
|
|
+import com.dingtalk.api.response.OapiProcessinstanceCreateResponse;
|
|
|
+import com.dingtalk.api.response.OapiProcessinstanceCspaceInfoResponse;
|
|
|
+import com.dingtalk.api.response.OapiV2UserGetResponse;
|
|
|
+import com.muzhi.zhizhong.service.AccessTokenService;
|
|
|
+import com.taobao.api.ApiException;
|
|
|
+import org.junit.jupiter.api.Test;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.boot.test.context.SpringBootTest;
|
|
|
+
|
|
|
+import java.io.*;
|
|
|
+import java.net.HttpURLConnection;
|
|
|
+import java.net.MalformedURLException;
|
|
|
+import java.net.URL;
|
|
|
+import java.net.URLConnection;
|
|
|
+import java.text.DateFormat;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
+import java.util.*;
|
|
|
+
|
|
|
+@SpringBootTest
|
|
|
+public class Test1 {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private AccessTokenService accessTokenService;
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void panduan(){
|
|
|
+ //判断日期是否为周六周日
|
|
|
+ String date = "2022-10-08 00:00:00";
|
|
|
+ DateFormat format = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
+ Date date1 = null;
|
|
|
+ try {
|
|
|
+ date1 = format.parse(date);
|
|
|
+ System.out.println("date1:" + date1);
|
|
|
+ }catch (Exception e){
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ Calendar calendar = Calendar.getInstance();
|
|
|
+ calendar.setTime(date1);
|
|
|
+
|
|
|
+ if (calendar.get(Calendar.DAY_OF_WEEK)==Calendar.SATURDAY||calendar.get(Calendar.DAY_OF_WEEK)==Calendar.SUNDAY){
|
|
|
+ System.out.println("当前日期为周六周日!");
|
|
|
+ }else {
|
|
|
+ System.out.println("当前日期为工作日");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void date(){
|
|
|
+ //获取当天前一天的零点零分零秒
|
|
|
+ Date Date = new Date(System.currentTimeMillis());
|
|
|
+ System.out.println("当前时间:" + Date);
|
|
|
+ Calendar calendar = Calendar.getInstance();
|
|
|
+ calendar.setTime(Date);
|
|
|
+ //前一天
|
|
|
+ calendar.add(Calendar.DAY_OF_MONTH,-1);
|
|
|
+ calendar.set(Calendar.HOUR_OF_DAY,0);
|
|
|
+ calendar.set(Calendar.MINUTE,0);
|
|
|
+ calendar.set(Calendar.SECOND,0);
|
|
|
+ calendar.set(Calendar.MILLISECOND,0);
|
|
|
+ String time = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(calendar.getTime());
|
|
|
+ System.out.println("前一天零点:" + time);
|
|
|
+
|
|
|
+ Calendar calendar111 = Calendar.getInstance();
|
|
|
+ calendar111.setTime(Date);
|
|
|
+ //前一个月第一天
|
|
|
+ calendar111.add(Calendar.MONTH,-1);
|
|
|
+ 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);
|
|
|
+ String 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.set(Calendar.MONTH,month222-1);
|
|
|
+ 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);
|
|
|
+ String TOtime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(calendar222.getTime());
|
|
|
+ System.out.println("前一个月最后一天零点:" + TOtime);
|
|
|
+ }
|
|
|
+
|
|
|
+ //新版创建OA审批
|
|
|
+ public static com.aliyun.dingtalkworkflow_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.dingtalkworkflow_1_0.Client(config);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void creatOAnew() throws Exception{
|
|
|
+
|
|
|
+ JSONObject jsonObject = null;
|
|
|
+ com.aliyun.dingtalkworkflow_1_0.Client client = createClient();
|
|
|
+ com.aliyun.dingtalkworkflow_1_0.models.StartProcessInstanceHeaders startProcessInstanceHeaders = new com.aliyun.dingtalkworkflow_1_0.models.StartProcessInstanceHeaders();
|
|
|
+ startProcessInstanceHeaders.xAcsDingtalkAccessToken = accessTokenService.getAccessToken();
|
|
|
+ com.aliyun.dingtalkworkflow_1_0.models.StartProcessInstanceRequest.StartProcessInstanceRequestFormComponentValues formComponentValues0 = new com.aliyun.dingtalkworkflow_1_0.models.StartProcessInstanceRequest.StartProcessInstanceRequestFormComponentValues()
|
|
|
+ .setName("供应商名称")
|
|
|
+ .setComponentType("TextField")
|
|
|
+ .setId("TextField_18SNO8NGT59FK")
|
|
|
+ .setValue("随便是什么222333");
|
|
|
+ com.aliyun.dingtalkworkflow_1_0.models.StartProcessInstanceRequest.StartProcessInstanceRequestApprovers approvers0 = new com.aliyun.dingtalkworkflow_1_0.models.StartProcessInstanceRequest.StartProcessInstanceRequestApprovers()
|
|
|
+ .setActionType("NONE")
|
|
|
+ .setUserIds(java.util.Arrays.asList(
|
|
|
+ "3956393642753968"
|
|
|
+ ));
|
|
|
+ com.aliyun.dingtalkworkflow_1_0.models.StartProcessInstanceRequest startProcessInstanceRequest = new com.aliyun.dingtalkworkflow_1_0.models.StartProcessInstanceRequest()
|
|
|
+ .setApprovers(java.util.Arrays.asList(
|
|
|
+ approvers0
|
|
|
+ ))
|
|
|
+ .setOriginatorUserId("3956393642753968")
|
|
|
+ .setProcessCode("PROC-C897D925-5856-4200-BB0E-2AC03A1CBD60")
|
|
|
+ .setFormComponentValues(java.util.Arrays.asList(
|
|
|
+ formComponentValues0
|
|
|
+ ));
|
|
|
+ try {
|
|
|
+ StartProcessInstanceResponse startProcessInstanceResponse = client.startProcessInstanceWithOptions(startProcessInstanceRequest, startProcessInstanceHeaders, new RuntimeOptions());
|
|
|
+ System.out.println("*************" + JSON.toJSONString(startProcessInstanceResponse.getBody()));
|
|
|
+ String s = JSON.toJSONString(startProcessInstanceResponse.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 属性,可帮助开发定位问题
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ System.out.println("创建审批实例接口object对象:" + jsonObject);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void creatOA() throws Exception{
|
|
|
+
|
|
|
+ DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/processinstance/create");
|
|
|
+ OapiProcessinstanceCreateRequest req = new OapiProcessinstanceCreateRequest();
|
|
|
+ req.setAgentId(2121466878L);
|
|
|
+ req.setProcessCode("PROC-C897D925-5856-4200-BB0E-2AC03A1CBD60");
|
|
|
+ req.setOriginatorUserId("3956393642753968");
|
|
|
+ req.setDeptId(-1L);
|
|
|
+// req.setCcList("4525xxxxxxxx77041");
|
|
|
+// req.setCcPosition("FINISH");
|
|
|
+
|
|
|
+ //单行输入框
|
|
|
+ List<OapiProcessinstanceCreateRequest.FormComponentValueVo> formComponentValueVoList = new ArrayList<>();
|
|
|
+ OapiProcessinstanceCreateRequest.FormComponentValueVo formComponentValueVo = new OapiProcessinstanceCreateRequest.FormComponentValueVo();
|
|
|
+ formComponentValueVoList.add(formComponentValueVo);
|
|
|
+ formComponentValueVo.setName("供应商名称");
|
|
|
+ formComponentValueVo.setValue("这是一个测试供应商");
|
|
|
+
|
|
|
+// //多行输入框
|
|
|
+// OapiProcessinstanceCreateRequest.FormComponentValueVo formComponentValueVo1 = new OapiProcessinstanceCreateRequest.FormComponentValueVo();
|
|
|
+// formComponentValueVoList.add(formComponentValueVo1);
|
|
|
+// formComponentValueVo1.setName("多行输入框");
|
|
|
+// formComponentValueVo1.setValue("测试多行输入框");
|
|
|
+//
|
|
|
+// //金额输入框
|
|
|
+// OapiProcessinstanceCreateRequest.FormComponentValueVo formComponentValueVo2 = new OapiProcessinstanceCreateRequest.FormComponentValueVo();
|
|
|
+// formComponentValueVoList.add(formComponentValueVo2);
|
|
|
+// formComponentValueVo2.setName("金额(元)大写");
|
|
|
+// formComponentValueVo2.setValue("1");
|
|
|
+//
|
|
|
+// //数字输入框
|
|
|
+// OapiProcessinstanceCreateRequest.FormComponentValueVo formComponentValueVo3 = new OapiProcessinstanceCreateRequest.FormComponentValueVo();
|
|
|
+// formComponentValueVoList.add(formComponentValueVo3);
|
|
|
+// formComponentValueVo3.setName("数字输入框");
|
|
|
+// formComponentValueVo3.setValue("100");
|
|
|
+//
|
|
|
+// //单选框组件
|
|
|
+// OapiProcessinstanceCreateRequest.FormComponentValueVo formComponentValueVo5 = new OapiProcessinstanceCreateRequest.FormComponentValueVo();
|
|
|
+// formComponentValueVoList.add(formComponentValueVo5);
|
|
|
+// formComponentValueVo5.setName("单选框");
|
|
|
+// formComponentValueVo5.setValue("a");
|
|
|
+//
|
|
|
+// //多选框组件
|
|
|
+// OapiProcessinstanceCreateRequest.FormComponentValueVo formComponentValueVo6 = new OapiProcessinstanceCreateRequest.FormComponentValueVo();
|
|
|
+// formComponentValueVoList.add(formComponentValueVo6);
|
|
|
+// formComponentValueVo6.setName("多选框");
|
|
|
+// formComponentValueVo6.setValue("[\"a\",\"b\"]");
|
|
|
+//
|
|
|
+// //日期组件
|
|
|
+// OapiProcessinstanceCreateRequest.FormComponentValueVo formComponentValueVo7 = new OapiProcessinstanceCreateRequest.FormComponentValueVo();
|
|
|
+// formComponentValueVoList.add(formComponentValueVo7);
|
|
|
+// formComponentValueVo7.setName("日期");
|
|
|
+// formComponentValueVo7.setValue("2021-08-17");
|
|
|
+//
|
|
|
+// //日期区间组件
|
|
|
+// OapiProcessinstanceCreateRequest.FormComponentValueVo formComponentValueVo8 = new OapiProcessinstanceCreateRequest.FormComponentValueVo();
|
|
|
+// formComponentValueVoList.add(formComponentValueVo8);
|
|
|
+// formComponentValueVo8.setName("[\"开始时间\",\"结束时间\"]");
|
|
|
+// formComponentValueVo8.setValue("[\"2019-02-19\",\"2019-02-25\"]");
|
|
|
+//
|
|
|
+// //上传图片
|
|
|
+// OapiProcessinstanceCreateRequest.FormComponentValueVo formComponentValueVo9 = new OapiProcessinstanceCreateRequest.FormComponentValueVo();
|
|
|
+// formComponentValueVoList.add(formComponentValueVo9);
|
|
|
+// formComponentValueVo9.setName("图片");
|
|
|
+// formComponentValueVo9.setValue(JSON.toJSONString(new String[]{"https://xxxxxxxx", "https://xxxxxxxxx"}));
|
|
|
+//
|
|
|
+// //上传审批附件
|
|
|
+// OapiProcessinstanceCreateRequest.FormComponentValueVo formComponentValueVo10 = new OapiProcessinstanceCreateRequest.FormComponentValueVo();
|
|
|
+// formComponentValueVoList.add(formComponentValueVo10);
|
|
|
+// JSONObject jsonObject = new JSONObject();
|
|
|
+// jsonObject.put("spaceId", "163xxxx658");
|
|
|
+// jsonObject.put("fileName", "IMG_2322.PNG");
|
|
|
+// jsonObject.put("fileSize", "276297");
|
|
|
+// jsonObject.put("fileType", "png");
|
|
|
+// jsonObject.put("fileId", "405xxxxx777");
|
|
|
+// Object o[] = new Object[]{jsonObject};
|
|
|
+// String s = JSON.toJSONString(o);
|
|
|
+// formComponentValueVo10.setName("附件");
|
|
|
+// formComponentValueVo10.setValue(s);
|
|
|
+//
|
|
|
+// //联系人
|
|
|
+// OapiProcessinstanceCreateRequest.FormComponentValueVo formComponentValueVo11 = new OapiProcessinstanceCreateRequest.FormComponentValueVo();
|
|
|
+// formComponentValueVoList.add(formComponentValueVo11);
|
|
|
+// formComponentValueVo11.setName("联系人");
|
|
|
+// formComponentValueVo11.setValue("[\"4525xxxxxxxx77041\"]");
|
|
|
+//
|
|
|
+// //明细
|
|
|
+// OapiProcessinstanceCreateRequest.FormComponentValueVo formComponentValueVo12 = new OapiProcessinstanceCreateRequest.FormComponentValueVo();
|
|
|
+// OapiProcessinstanceCreateRequest.FormComponentValueVo Item1 = new OapiProcessinstanceCreateRequest.FormComponentValueVo();
|
|
|
+// Item1.setName("单行输入框");
|
|
|
+// Item1.setValue("明细单行输入框");
|
|
|
+// OapiProcessinstanceCreateRequest.FormComponentValueVo Item2 = new OapiProcessinstanceCreateRequest.FormComponentValueVo();
|
|
|
+// Item2.setName("数字输入框");
|
|
|
+// Item2.setValue("100");
|
|
|
+// formComponentValueVo12.setName("明细");
|
|
|
+// formComponentValueVo12.setValue(JSON.toJSONString(Arrays.asList(Arrays.asList(Item1, Item2))));
|
|
|
+// formComponentValueVoList.add(formComponentValueVo12);
|
|
|
+//
|
|
|
+// //关联审批单
|
|
|
+// OapiProcessinstanceCreateRequest.FormComponentValueVo formComponentValueVo13 = new OapiProcessinstanceCreateRequest.FormComponentValueVo();
|
|
|
+// formComponentValueVoList.add(formComponentValueVo13);
|
|
|
+// formComponentValueVo13.setName("关联审批单");
|
|
|
+// formComponentValueVo13.setValue(JSON.toJSONString(Arrays.asList("fa2aa864-xxxx-xxxx-xxxx-75572c0e2cdf")));
|
|
|
+//
|
|
|
+// //设置审批人,会签、或签设置的审批人必须大于等于2个人
|
|
|
+// List<OapiProcessinstanceCreateRequest.ProcessInstanceApproverVo> processInstanceApproverVoList = new ArrayList<OapiProcessinstanceCreateRequest.ProcessInstanceApproverVo>();
|
|
|
+// OapiProcessinstanceCreateRequest.ProcessInstanceApproverVo processInstanceApproverVo = new OapiProcessinstanceCreateRequest.ProcessInstanceApproverVo();
|
|
|
+// processInstanceApproverVoList.add(processInstanceApproverVo);
|
|
|
+// processInstanceApproverVo.setTaskActionType("AND");
|
|
|
+// processInstanceApproverVo.setUserIds(Arrays.asList("4525xxxxxxxx77041","2643xxxxxxx69379"));
|
|
|
+// OapiProcessinstanceCreateRequest.ProcessInstanceApproverVo processInstanceApproverVo1 = new OapiProcessinstanceCreateRequest.ProcessInstanceApproverVo();
|
|
|
+// processInstanceApproverVoList.add(processInstanceApproverVo1);
|
|
|
+// processInstanceApproverVo1.setTaskActionType("OR");
|
|
|
+// processInstanceApproverVo1.setUserIds(Arrays.asList("4525xxxxxxxx77041","2643xxxxxxx69379"));
|
|
|
+// req.setApproversV2(processInstanceApproverVoList);
|
|
|
+
|
|
|
+ req.setFormComponentValues(formComponentValueVoList);
|
|
|
+ OapiProcessinstanceCreateResponse rsp = client.execute(req, accessTokenService.getAccessToken());
|
|
|
+ System.out.println(JSON.toJSONString(rsp));
|
|
|
+ }
|
|
|
+
|
|
|
+ //审批附件id
|
|
|
+ public static String fileId = null;
|
|
|
+ //审批附件名称
|
|
|
+ public static String fileName = null;
|
|
|
+ //审批附件长度
|
|
|
+ public static Long fileSize = 0L;
|
|
|
+ //审批附件类型
|
|
|
+ public static String fileType = null;
|
|
|
+ //审批钉盘空间id
|
|
|
+ public static String spaceId = null;
|
|
|
+
|
|
|
+ //文件下载保存方法
|
|
|
+ @SuppressWarnings("finally")
|
|
|
+ public static File downloadFile(String urlPath, String downloadDir) {
|
|
|
+ File file = null;
|
|
|
+ try {
|
|
|
+
|
|
|
+ URL url = new URL(urlPath);
|
|
|
+
|
|
|
+ URLConnection urlConnection = url.openConnection();
|
|
|
+
|
|
|
+ HttpURLConnection httpURLConnection = (HttpURLConnection) urlConnection;// http的连接类
|
|
|
+
|
|
|
+ //String contentType = httpURLConnection.getContentType();//请求类型,可用来过滤请求,
|
|
|
+
|
|
|
+ httpURLConnection.setConnectTimeout(1000*5);//设置超时
|
|
|
+
|
|
|
+ httpURLConnection.setRequestMethod("GET");//设置请求方式,默认是GET
|
|
|
+
|
|
|
+ httpURLConnection.setRequestProperty("Charset", "UTF-8");// 设置字符编码
|
|
|
+
|
|
|
+
|
|
|
+ httpURLConnection.connect();// 打开连接
|
|
|
+
|
|
|
+ BufferedInputStream bin = new BufferedInputStream(httpURLConnection.getInputStream());
|
|
|
+
|
|
|
+ //TODO 修改成动态文件名称:当前审批单的文件名称
|
|
|
+// String fileName = "ceshi.pdf";// 指定文件名称
|
|
|
+
|
|
|
+ String path = downloadDir + File.separatorChar + fileName;// 指定存放位置,此处使用的是全局变量的文件名称
|
|
|
+ file = new File(path);
|
|
|
+ // 校验文件夹目录是否存在,不存在就创建一个目录
|
|
|
+ if (!file.getParentFile().exists()) {
|
|
|
+ file.getParentFile().mkdirs();
|
|
|
+ }
|
|
|
+
|
|
|
+ OutputStream out = new FileOutputStream(file);
|
|
|
+ int size = 0;
|
|
|
+
|
|
|
+ byte[] b = new byte[2048];
|
|
|
+ //把输入流的文件读取到字节数据b中,然后输出到指定目录的文件
|
|
|
+ while ((size = bin.read(b)) != -1) {
|
|
|
+ out.write(b, 0, size);
|
|
|
+ }
|
|
|
+ // 关闭资源
|
|
|
+ bin.close();
|
|
|
+ out.close();
|
|
|
+ System.out.println("文件下载成功!");
|
|
|
+ } catch (MalformedURLException e) {
|
|
|
+ // TODO Auto-generated catch block
|
|
|
+ e.printStackTrace();
|
|
|
+ } catch (IOException e) {
|
|
|
+ // TODO Auto-generated catch block
|
|
|
+ e.printStackTrace();
|
|
|
+ System.out.println("文件下载失败!");
|
|
|
+ } finally {
|
|
|
+ return file;
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ public static com.aliyun.dingtalkstorage_1_0.Client createClient1() throws Exception {
|
|
|
+ com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config();
|
|
|
+ config.protocol = "https";
|
|
|
+ config.regionId = "central";
|
|
|
+ return new com.aliyun.dingtalkstorage_1_0.Client(config);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void getSpaceId(){
|
|
|
+
|
|
|
+ //文件下载地址
|
|
|
+ String download_url = "https://mc.cloudpure.cn/portal/aliwork/love.pdf";
|
|
|
+
|
|
|
+ //获取当前日期,用于创建文件保存目录中增加当前日期的文件夹作区分
|
|
|
+ SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");//设置日期格式 yyyy-MM-dd HH:mm:ss
|
|
|
+ String format = df.format(new Date());
|
|
|
+ System.out.println(format);// new Date()为获取当前系统时间
|
|
|
+
|
|
|
+ //参数1:文件下载地址;
|
|
|
+ //参数2:文件下载后保存地址;
|
|
|
+ //【windows端下载文件保存路径】
|
|
|
+ File file = downloadFile(download_url, "D:\\pdf\\" + format);
|
|
|
+ System.out.println("&&&&&&&&&&&&&&&&&" + file);
|
|
|
+ if (file != null){
|
|
|
+ fileSize = file.length();
|
|
|
+ System.out.println("文件长度:" + fileSize);
|
|
|
+ fileName = file.getName();
|
|
|
+ System.out.println("文件名称:" + fileName);
|
|
|
+ //截取文件全名最后一个小数点后面的文件后缀(文件类型)
|
|
|
+ fileType = fileName.substring(fileName.lastIndexOf(".") + 1,fileName.length());
|
|
|
+ System.out.println("文件类型:" + fileType);
|
|
|
+ }else {
|
|
|
+ System.out.println("文件下载地址有误!");
|
|
|
+ }
|
|
|
+ //【Linux端下载文件保存路径】
|
|
|
+ //downloadFile(download_uri,format);
|
|
|
+
|
|
|
+ //【Linux下面的路径】
|
|
|
+ //原始文件路径
|
|
|
+ String strFile = format + File.separator + fileName;
|
|
|
+
|
|
|
+ //【windows下面的路径】
|
|
|
+ //原始文件路径
|
|
|
+ String a = "D:\\pdf\\" + format + "\\" + fileName;
|
|
|
+
|
|
|
+ System.out.println("#################" + a);
|
|
|
+
|
|
|
+ //***获取审批钉盘空间信息(企业审批附件钉盘空间,需通过获取审批钉盘空间信息接口进行【授权】)***
|
|
|
+ String space_XX = null;
|
|
|
+
|
|
|
+ try {
|
|
|
+ DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/processinstance/cspace/info");
|
|
|
+ OapiProcessinstanceCspaceInfoRequest req = new OapiProcessinstanceCspaceInfoRequest();
|
|
|
+ //用户id
|
|
|
+ req.setUserId("3956393642753968");
|
|
|
+ //企业应用标识,此处可以不传
|
|
|
+// req.setAgentId(2121466878L);
|
|
|
+ OapiProcessinstanceCspaceInfoResponse rsp = client.execute(req, accessTokenService.getAccessToken());
|
|
|
+ space_XX = rsp.getBody();
|
|
|
+ System.out.println(rsp.getBody());
|
|
|
+ } catch (ApiException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+
|
|
|
+ JSONObject jsonObject_space = JSON.parseObject(space_XX);
|
|
|
+ JSONObject result_space = jsonObject_space.getJSONObject("result");
|
|
|
+ spaceId = result_space.getString("space_id");
|
|
|
+ System.out.println("审批钉盘空间id:" + spaceId);
|
|
|
+
|
|
|
+ //获取当前人员的unionid
|
|
|
+ String unionid = null;
|
|
|
+ try {
|
|
|
+ DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/v2/user/get");
|
|
|
+ OapiV2UserGetRequest req = new OapiV2UserGetRequest();
|
|
|
+ //待查询的人员userid
|
|
|
+ req.setUserid("3956393642753968");
|
|
|
+ OapiV2UserGetResponse rsp = client.execute(req, accessTokenService.getAccessToken());
|
|
|
+ String result = rsp.getBody();
|
|
|
+ System.out.println(result);
|
|
|
+ unionid = JSON.parseObject(result).getJSONObject("result").getString("unionid");
|
|
|
+ System.out.println("获取的人员unionid:" + unionid);
|
|
|
+ } catch (ApiException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+
|
|
|
+ //获取文件上传信息
|
|
|
+ JSONObject jsonObject = null;
|
|
|
+ try {
|
|
|
+ com.aliyun.dingtalkstorage_1_0.Client client = createClient1();
|
|
|
+ com.aliyun.dingtalkstorage_1_0.models.GetFileUploadInfoHeaders getFileUploadInfoHeaders = new com.aliyun.dingtalkstorage_1_0.models.GetFileUploadInfoHeaders();
|
|
|
+ getFileUploadInfoHeaders.xAcsDingtalkAccessToken = accessTokenService.getAccessToken();
|
|
|
+
|
|
|
+ com.aliyun.dingtalkstorage_1_0.models.GetFileUploadInfoRequest getFileUploadInfoRequest = new com.aliyun.dingtalkstorage_1_0.models.GetFileUploadInfoRequest()
|
|
|
+ .setUnionId(unionid)
|
|
|
+ .setProtocol("HEADER_SIGNATURE")
|
|
|
+ .setMultipart(false);
|
|
|
+
|
|
|
+ GetFileUploadInfoResponse fileUploadInfoWithOptions = client.getFileUploadInfoWithOptions(spaceId, getFileUploadInfoRequest, getFileUploadInfoHeaders, new RuntimeOptions());
|
|
|
+ System.out.println("*************" + JSON.toJSONString(fileUploadInfoWithOptions.getBody()));
|
|
|
+ String s = JSON.toJSONString(fileUploadInfoWithOptions.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 属性,可帮助开发定位问题
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ JSONObject headerSignatureInfo = jsonObject.getJSONObject("headerSignatureInfo");
|
|
|
+
|
|
|
+ //uploadKey
|
|
|
+ String uploadKey = jsonObject.getString("uploadKey");
|
|
|
+ System.out.println("uploadKey:" + uploadKey);
|
|
|
+
|
|
|
+ //headers
|
|
|
+ JSONObject headersA = headerSignatureInfo.getJSONObject("headers");
|
|
|
+ String authorization = headersA.getString("Authorization");
|
|
|
+ String xossdate = headersA.getString("x-oss-date");
|
|
|
+ Map map = new HashMap();
|
|
|
+ map.put("Authorization",authorization);
|
|
|
+ map.put("x-oss-date",xossdate);
|
|
|
+ System.out.println("headers:" + map);
|
|
|
+
|
|
|
+ //resourceUrl
|
|
|
+ JSONArray resourceUrls = headerSignatureInfo.getJSONArray("resourceUrls");
|
|
|
+ String resourceUrlsString = resourceUrls.getString(0);
|
|
|
+ System.out.println("resourceUrl:" + resourceUrlsString);
|
|
|
+
|
|
|
+ // 从接口返回信息中拿到url
|
|
|
+ String resourceUrl = resourceUrlsString;
|
|
|
+ // 从接口返回信息中拿到headers
|
|
|
+ Map<String, String> headers = map;
|
|
|
+ try {
|
|
|
+ URL url = new URL(resourceUrl);
|
|
|
+ HttpURLConnection connection = (HttpURLConnection)url.openConnection();
|
|
|
+ if (headers != null) {
|
|
|
+ for (Map.Entry<String, String> entry : headers.entrySet()) {
|
|
|
+ connection.setRequestProperty(entry.getKey(), entry.getValue());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ connection.setDoOutput(true);
|
|
|
+ connection.setRequestMethod("PUT");
|
|
|
+ connection.setUseCaches(false);
|
|
|
+ connection.setReadTimeout(10000);
|
|
|
+ connection.setConnectTimeout(10000);
|
|
|
+ connection.connect();
|
|
|
+ OutputStream out = connection.getOutputStream();
|
|
|
+
|
|
|
+ //本地上传文件路径
|
|
|
+ InputStream is = new FileInputStream(new File(a));
|
|
|
+
|
|
|
+ byte[] b =new byte[1024];
|
|
|
+ int temp;
|
|
|
+ while ((temp=is.read(b))!=-1){
|
|
|
+ out.write(b,0,temp);
|
|
|
+ }
|
|
|
+ out.flush();
|
|
|
+ out.close();
|
|
|
+ int responseCode = connection.getResponseCode();
|
|
|
+ connection.disconnect();
|
|
|
+ if (responseCode == 200) {
|
|
|
+ System.out.println("上传成功");
|
|
|
+ } else {
|
|
|
+ System.out.println("上传失败");
|
|
|
+ }
|
|
|
+ }catch (Exception e){
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ public static com.aliyun.dingtalkstorage_1_0.Client createClientFile() throws Exception {
|
|
|
+ com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config();
|
|
|
+ config.protocol = "https";
|
|
|
+ config.regionId = "central";
|
|
|
+ return new com.aliyun.dingtalkstorage_1_0.Client(config);
|
|
|
+ }
|
|
|
+
|
|
|
+ //提交文件
|
|
|
+ @Test
|
|
|
+ public void commit(){
|
|
|
+
|
|
|
+ /*提交文件,并获取文件id*/
|
|
|
+ JSONObject jsonObjectTJ = null;
|
|
|
+ try {
|
|
|
+ com.aliyun.dingtalkstorage_1_0.Client client = createClientFile();
|
|
|
+ com.aliyun.dingtalkstorage_1_0.models.CommitFileHeaders commitFileHeaders = new com.aliyun.dingtalkstorage_1_0.models.CommitFileHeaders();
|
|
|
+ commitFileHeaders.xAcsDingtalkAccessToken = accessTokenService.getAccessToken();
|
|
|
+ com.aliyun.dingtalkstorage_1_0.models.CommitFileRequest.CommitFileRequestOptionAppProperties optionAppProperties0 = new com.aliyun.dingtalkstorage_1_0.models.CommitFileRequest.CommitFileRequestOptionAppProperties()
|
|
|
+ //属性名。
|
|
|
+ .setName("123.pdf")
|
|
|
+ //属性可见性。
|
|
|
+ //PUBLIC:所有应用都可见
|
|
|
+ //PRIVATE:仅限当前应用可见
|
|
|
+ .setVisibility("PUBLIC")
|
|
|
+ //属性值。
|
|
|
+ .setValue("合同附件");
|
|
|
+ com.aliyun.dingtalkstorage_1_0.models.CommitFileRequest.CommitFileRequestOption option = new com.aliyun.dingtalkstorage_1_0.models.CommitFileRequest.CommitFileRequestOption()
|
|
|
+ .setAppProperties(java.util.Arrays.asList(
|
|
|
+ optionAppProperties0
|
|
|
+ ));
|
|
|
+ com.aliyun.dingtalkstorage_1_0.models.CommitFileRequest commitFileRequest = new com.aliyun.dingtalkstorage_1_0.models.CommitFileRequest()
|
|
|
+ .setUnionId("WdWZ8N96r257fu4N33YJcgiEiE")
|
|
|
+ //文件的名称,带后缀。
|
|
|
+ .setName("123.pdf")
|
|
|
+ //添加文件唯一标识。
|
|
|
+ .setUploadKey("hgHOI6ZojQLPAAAAFUPLNPUDAQShNwXaADkjaUFFSEFxUm1hV3hsQTZoNWRXNWthWE5yTUFUT0lVYWl5UVhOQnBnR3pJb0h6bU9PRm1vSXpRSjEGqERJTkdUQUxL")
|
|
|
+ //父目录Id。根目录时,该参数是0
|
|
|
+ .setParentId("0")
|
|
|
+ .setOption(option);
|
|
|
+
|
|
|
+ CommitFileResponse commitFileResponse = client.commitFileWithOptions("598108301", commitFileRequest, commitFileHeaders, new RuntimeOptions());
|
|
|
+ System.out.println("*************" + JSON.toJSONString(commitFileResponse.getBody()));
|
|
|
+ String s = JSON.toJSONString(commitFileResponse.getBody());
|
|
|
+ jsonObjectTJ = JSON.parseObject(s);
|
|
|
+ System.out.println("提交文件接口object对象:" + jsonObjectTJ);
|
|
|
+ } 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 属性,可帮助开发定位问题
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ try {
|
|
|
+ JSONObject dentry = jsonObjectTJ.getJSONObject("dentry");
|
|
|
+ fileId = dentry.getString("id");
|
|
|
+ }catch (Exception e){
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ System.out.println("获取的文件id:" + fileId);
|
|
|
+ /*提交文件,并获取文件id*/
|
|
|
+ }
|
|
|
+
|
|
|
+ //获取审批实例ID列表
|
|
|
+ @Test
|
|
|
+ public void getShenpiID(){
|
|
|
+
|
|
|
+ JSONObject jsonObject = null;
|
|
|
+ try {
|
|
|
+ com.aliyun.dingtalkworkflow_1_0.Client client = createClient();
|
|
|
+ com.aliyun.dingtalkworkflow_1_0.models.ListProcessInstanceIdsHeaders listProcessInstanceIdsHeaders = new com.aliyun.dingtalkworkflow_1_0.models.ListProcessInstanceIdsHeaders();
|
|
|
+ listProcessInstanceIdsHeaders.xAcsDingtalkAccessToken = accessTokenService.getAccessToken();
|
|
|
+ com.aliyun.dingtalkworkflow_1_0.models.ListProcessInstanceIdsRequest listProcessInstanceIdsRequest = new com.aliyun.dingtalkworkflow_1_0.models.ListProcessInstanceIdsRequest()
|
|
|
+ .setStartTime(1671087622000L)
|
|
|
+ .setEndTime(1671091222000L)
|
|
|
+ .setProcessCode("PROC-67912B9E-E328-469E-BF1A-0578297B49B1")
|
|
|
+ .setNextToken(0L)
|
|
|
+ .setMaxResults(20L);
|
|
|
+
|
|
|
+ ListProcessInstanceIdsResponse listProcessInstanceIdsResponse = client.listProcessInstanceIdsWithOptions(listProcessInstanceIdsRequest, listProcessInstanceIdsHeaders, new RuntimeOptions());
|
|
|
+ System.out.println("*************" + JSON.toJSONString(listProcessInstanceIdsResponse.getBody()));
|
|
|
+ String s = JSON.toJSONString(listProcessInstanceIdsResponse.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 属性,可帮助开发定位问题
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ JSONObject jsonObject1 = null;
|
|
|
+ try {
|
|
|
+ com.aliyun.dingtalkworkflow_1_0.Client client = createClient();
|
|
|
+ com.aliyun.dingtalkworkflow_1_0.models.GetProcessInstanceHeaders getProcessInstanceHeaders = new com.aliyun.dingtalkworkflow_1_0.models.GetProcessInstanceHeaders();
|
|
|
+ getProcessInstanceHeaders.xAcsDingtalkAccessToken = accessTokenService.getAccessToken();
|
|
|
+ com.aliyun.dingtalkworkflow_1_0.models.GetProcessInstanceRequest getProcessInstanceRequest = new com.aliyun.dingtalkworkflow_1_0.models.GetProcessInstanceRequest()
|
|
|
+ .setProcessInstanceId("pTA0ccsyS_O0L-g5Hym27w05291671089519");
|
|
|
+
|
|
|
+ GetProcessInstanceResponse processInstanceWithOptions = client.getProcessInstanceWithOptions(getProcessInstanceRequest, getProcessInstanceHeaders, new RuntimeOptions());
|
|
|
+ System.out.println("*************" + JSON.toJSONString(processInstanceWithOptions.getBody()));
|
|
|
+ String s = JSON.toJSONString(processInstanceWithOptions.getBody());
|
|
|
+ jsonObject1 = JSON.parseObject(s);
|
|
|
+ System.out.println("提交文件接口object对象:" + jsonObject1);
|
|
|
+ } 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 属性,可帮助开发定位问题
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //测试U8C回传状态接口
|
|
|
+ @Test
|
|
|
+ public void setState(){
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+}
|