|
@@ -0,0 +1,104 @@
|
|
|
+package com.malk.aosk.event;
|
|
|
+
|
|
|
+import cn.hutool.core.io.FileUtil;
|
|
|
+import cn.hutool.core.util.URLUtil;
|
|
|
+import cn.hutool.http.HttpUtil;
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.malk.delegate.DDEvent;
|
|
|
+import com.malk.server.dingtalk.DDConf;
|
|
|
+import com.malk.server.dingtalk.DDR_New;
|
|
|
+import com.malk.service.dingtalk.DDClient;
|
|
|
+import com.malk.service.dingtalk.DDClient_Workflow;
|
|
|
+import com.malk.utils.UtilMap;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
+import org.springframework.context.annotation.Primary;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import java.time.LocalDate;
|
|
|
+import java.time.format.DateTimeFormatter;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+@Slf4j
|
|
|
+@Primary
|
|
|
+@Service
|
|
|
+public class DDaskEventImpl implements DDEvent {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private DDClient_Workflow ddClientWorkflow;
|
|
|
+ @Autowired
|
|
|
+ private DDClient ddClient;
|
|
|
+ @Value("${aosk.oa.path}")
|
|
|
+ private String PATH;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void executeEvent_Task_Finish(String processInstanceId, String processCode, boolean isAgree, String remark) {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void executeEvent_Task_Start(String processInstanceId, String processCode) {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void executeEvent_Task_Comment(String processInstanceId, String processCode) {
|
|
|
+ // 评论回调 1.查询审批实例 2.获取评论附件 3.保存附件
|
|
|
+ Map form = ddClientWorkflow.getForms(ddClient.getAccessToken(),processCode);
|
|
|
+ Map map = ddClientWorkflow.getProcessInstanceId(ddClient.getAccessToken(), processInstanceId);
|
|
|
+ String createTime=UtilMap.getString(map,"createTime");
|
|
|
+ String yearMonth = createTime.substring(0,7).replace("-","");
|
|
|
+ String filePath = PATH+"/"+yearMonth+"/"+UtilMap.getString(form,"name")+"/"+UtilMap.getString(map,"businessId")+"/";
|
|
|
+ List<Map> list = UtilMap.getList(map, "operationRecords");
|
|
|
+ for (Map record : list) {
|
|
|
+ if("ADD_REMARK".equals(UtilMap.getString(record,"type"))){
|
|
|
+ if((record.containsKey("attachments")&& UtilMap.getList(record,"attachments").size()>0)){
|
|
|
+ saveFile(filePath, JSONArray.parseArray(UtilMap.getString(record,"attachments")),processInstanceId);
|
|
|
+ }
|
|
|
+ if((record.containsKey("images")&& UtilMap.getList(record,"images").size()>0)){
|
|
|
+ saveImg(filePath, UtilMap.getList(record,"images"));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void saveImg(String filePath, List<String> attachments){
|
|
|
+ for(String attachment : attachments){
|
|
|
+ // 1. 获取URL的路径部分(自动解码%20等字符)
|
|
|
+ String path = URLUtil.getPath(attachment);
|
|
|
+ // 2. 从路径中提取文件名
|
|
|
+ String fileName = FileUtil.getName(path);
|
|
|
+ HttpUtil.downloadFile(attachment,filePath+fileName);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void saveFile(String filePath,JSONArray fileIds,String pid){
|
|
|
+ for(int i=0;i<fileIds.size();i++){
|
|
|
+ JSONObject fileInfo=fileIds.getJSONObject(i);
|
|
|
+ String fileId=fileInfo.getString("fileId");
|
|
|
+ String fileName=fileInfo.getString("fileName");
|
|
|
+ String url=ddClientWorkflow.getFileUrl(ddClient.getAccessToken(),pid,fileId,true);
|
|
|
+ HttpUtil.downloadFile(url,filePath+fileName);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void executeEvent_Task_Redirect(String processInstanceId, String processCode) {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void executeEvent_Instance_Finish(String processInstanceId, String processCode, boolean isAgree, boolean isTerminate, String staffId) {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void executeEvent_Instance_Start(String processInstanceId, String processCode) {
|
|
|
+
|
|
|
+ }
|
|
|
+}
|