丽知:新增钉钉审批实例
This commit is contained in:
parent
f0d76ddf6d
commit
6d246b79ae
|
@ -1,16 +1,17 @@
|
|||
package com.hzya.frame.plugin.lets.dingtalk.push.serivce.impl;
|
||||
|
||||
import cn.hutool.core.lang.Assert;
|
||||
import cn.hutool.json.JSONObject;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import com.aliyun.dingtalkoauth2_1_0.models.GetAccessTokenResponseBody;
|
||||
import com.aliyun.dingtalkworkflow_1_0.models.StartProcessInstanceRequest;
|
||||
import com.aliyun.dingtalkworkflow_1_0.models.StartProcessInstanceResponse;
|
||||
import com.dingtalk.api.response.OapiV2UserGetResponse;
|
||||
import com.dingtalk.api.response.OapiV2UserGetbymobileResponse;
|
||||
import com.hzya.frame.plugin.lets.dingtalk.push.serivce.PushU8CService;
|
||||
import com.hzya.frame.plugin.lets.dingtalk.utils.DingTalkUtils;
|
||||
import com.hzya.frame.plugin.lets.dingtalk.utils.FileUtil;
|
||||
import com.hzya.frame.plugin.lets.dingtalk.vo.DjFileVO;
|
||||
import com.hzya.frame.plugin.lets.dingtalk.vo.DjzbVO;
|
||||
import com.hzya.frame.plugin.lets.dingtalk.vo.FileModuleVO;
|
||||
import com.hzya.frame.plugin.lets.dingtalk.vo.SysFileVO;
|
||||
import com.hzya.frame.plugin.lets.dingtalk.vo.*;
|
||||
import com.hzya.frame.plugin.lets.plugin.adjust.AdjustInPluginInitializer;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
@ -35,6 +36,8 @@ import java.util.List;
|
|||
@Service("PushU8CService")
|
||||
public class PushU8CServiceImpl implements PushU8CService {
|
||||
|
||||
@Value("${DING.U8C_TEST_AGENTID}")
|
||||
private String U8C_TEST_AGENTID;
|
||||
@Value("${DING.CorpId}")
|
||||
private String CorpId;
|
||||
@Value("${DING.APIToken}")
|
||||
|
@ -49,18 +52,18 @@ public class PushU8CServiceImpl implements PushU8CService {
|
|||
|
||||
@Value("${DING.APPROVE_CODE.SPECIAL_SERVICE_PROCESSING}")
|
||||
private String SPECIAL_SERVICE_PROCESSING;
|
||||
@Value("${DING.APPROVE_FILE_SPACE.SPECIAL_SERVICE_PROCESSING}")
|
||||
private String SPECIAL_SERVICE_PROCESSING_SPACE;
|
||||
@Value("${DING.APPROVE_FOLDER_SPACE.SPECIAL_SERVICE_PROCESSING}")
|
||||
private String SPECIAL_SERVICE_PROCESSING_FOLDER;
|
||||
|
||||
@Value("${DING.APPROVE_CODE.PURCHASE_PAYMENT_REQUEST_NEW}")
|
||||
private String PURCHASE_PAYMENT_REQUEST_NEW;
|
||||
@Value("${DING.APPROVE_FILE_SPACE.PURCHASE_PAYMENT_REQUEST_NEW}")
|
||||
private String PURCHASE_PAYMENT_REQUEST_NEW_SPACE;
|
||||
@Value("${DING.APPROVE_FOLDER_SPACE.PURCHASE_PAYMENT_REQUEST_NEW}")
|
||||
private String PURCHASE_PAYMENT_REQUEST_NEW_FOLDER;
|
||||
|
||||
@Value("${DING.APPROVE_CODE.PURCHASE_PAYMENT_REQUEST_SHOP}")
|
||||
private String PURCHASE_PAYMENT_REQUEST_SHOP;
|
||||
@Value("${DING.APPROVE_FILE_SPACE.PURCHASE_PAYMENT_REQUEST_SHOP}")
|
||||
private String PURCHASE_PAYMENT_REQUEST_SHOP_SPACE;
|
||||
@Value("${DING.APPROVE_FOLDER_SPACE.PURCHASE_PAYMENT_REQUEST_SHOP}")
|
||||
private String PURCHASE_PAYMENT_REQUEST_SHOP_FOLDER;
|
||||
|
||||
|
||||
Logger logger = LoggerFactory.getLogger(PushU8CServiceImpl.class);
|
||||
|
@ -83,9 +86,14 @@ public class PushU8CServiceImpl implements PushU8CService {
|
|||
|
||||
|
||||
//base转文件流-上传钉盘-拿到钉盘信息。可能是List集合
|
||||
List<FileModuleVO> fileModuleVOList = baseTransformFile2uploadDing(djFileVO.getSysFileVOS(),tokenBody.getAccessToken(),unionid,SPECIAL_SERVICE_PROCESSING_SPACE,SPECIAL_SERVICE_PROCESSING_SPACE);
|
||||
List<FileModuleVO> fileModuleVOList = baseTransformFile2uploadDing(djFileVO.getSysFileVOS(),tokenBody.getAccessToken(),unionid,SPACEID,SPECIAL_SERVICE_PROCESSING_FOLDER);
|
||||
System.out.println(fileModuleVOList);
|
||||
|
||||
//推送钉钉--》发起审批实例
|
||||
excuteDingTalkOutSource(tokenBody.getAccessToken(),SPECIAL_SERVICE_PROCESSING,djFileVO.getDjzbVO(),fileModuleVOList);
|
||||
|
||||
|
||||
|
||||
|
||||
}catch (Exception e){
|
||||
e.printStackTrace();
|
||||
|
@ -126,9 +134,9 @@ public class PushU8CServiceImpl implements PushU8CService {
|
|||
* @Param token token
|
||||
* @Param unionid unionid
|
||||
* @Param spaceId 空间信息
|
||||
* @Param parentSpaceId 父级空间id
|
||||
* @Param dingFileUrlID 钉盘审批实例中附件地址
|
||||
*/
|
||||
public List<FileModuleVO> baseTransformFile2uploadDing(List<SysFileVO> fileVOS,String token,String unionid,String spaceId,String parentSpaceId) throws IOException {
|
||||
public List<FileModuleVO> baseTransformFile2uploadDing(List<SysFileVO> fileVOS,String token,String unionid,String spaceId,String dingFileUrlID) throws IOException {
|
||||
List<FileModuleVO> fileModuleVOList=new ArrayList<>();
|
||||
for (SysFileVO fileVO : fileVOS) {
|
||||
// 指定输出文件路径
|
||||
|
@ -151,11 +159,97 @@ public class PushU8CServiceImpl implements PushU8CService {
|
|||
// 3. 打印ByteArrayOutputStream的内容(可选)
|
||||
byte[] fileContent = byteArrayOutputStream.toByteArray();
|
||||
// 4. 文件流上传钉盘
|
||||
FileModuleVO dingDileModuleVO = FileUtil.get4DingDileModuleVO(token, unionid, spaceId, fileVO, byteArrayOutputStream, parentSpaceId);
|
||||
FileModuleVO dingDileModuleVO = FileUtil.get4DingDileModuleVO(token, unionid, spaceId, fileVO, byteArrayOutputStream, dingFileUrlID);
|
||||
|
||||
fileModuleVOList.add(dingDileModuleVO);
|
||||
}
|
||||
return fileModuleVOList;
|
||||
}
|
||||
|
||||
/**\
|
||||
* 委外采购(付款单)->采购付款申请(新):推送钉钉审批实例
|
||||
* @param accessToken token
|
||||
* @param processCode 钉钉模板Code
|
||||
* @param djzbVO U8C单据VO
|
||||
* @param fileModuleVOList 钉钉文件信息,用于上传审批实例使用
|
||||
*/
|
||||
public void excuteDingTalkOutSource(String accessToken,String processCode,DjzbVO djzbVO,List<FileModuleVO> fileModuleVOList) throws Exception {
|
||||
try {
|
||||
DjzbVO.Arap_djzb parentvo = djzbVO.getParentvo();
|
||||
List<DjzbVO.Arap_djfb> childrens = djzbVO.getChildren();
|
||||
|
||||
//公司
|
||||
//部门
|
||||
//发起人
|
||||
|
||||
|
||||
//formComponentValues-->表单数据内容,控件列表,最大列表长度:150。
|
||||
List<StartProcessInstanceRequest.StartProcessInstanceRequestFormComponentValues> form = new ArrayList<>();
|
||||
|
||||
// form.add(new StartProcessInstanceRequest.StartProcessInstanceRequestFormComponentValues().setName("费用归属公司").setValue(parentvo.getExternal_org_name()));
|
||||
// form.add(new StartProcessInstanceRequest.StartProcessInstanceRequestFormComponentValues().setName("费用归属部门(选择至末级部门)").setValue(parentvo.getExternal_org_name()));
|
||||
// form.add(new StartProcessInstanceRequest.StartProcessInstanceRequestFormComponentValues().setName("品牌").setValue(parentvo.getExternal_org_name()));
|
||||
// form.add(new StartProcessInstanceRequest.StartProcessInstanceRequestFormComponentValues().setName("费用所属类目").setValue(parentvo.getExternal_org_name()));
|
||||
// form.add(new StartProcessInstanceRequest.StartProcessInstanceRequestFormComponentValues().setName("付款类型").setValue(parentvo.getExternal_org_name()));
|
||||
// form.add(new StartProcessInstanceRequest.StartProcessInstanceRequestFormComponentValues().setName("付款比例").setValue(parentvo.getExternal_org_name()));
|
||||
// form.add(new StartProcessInstanceRequest.StartProcessInstanceRequestFormComponentValues().setName("类目所属(供应链)").setValue(parentvo.getExternal_org_name()));
|
||||
// form.add(new StartProcessInstanceRequest.StartProcessInstanceRequestFormComponentValues().setName("项目编号").setValue(parentvo.getExternal_org_name()));
|
||||
// form.add(new StartProcessInstanceRequest.StartProcessInstanceRequestFormComponentValues().setName("项目名称").setValue(parentvo.getExternal_org_name()));
|
||||
// form.add(new StartProcessInstanceRequest.StartProcessInstanceRequestFormComponentValues().setName("类型").setValue(parentvo.getExternal_org_name()));
|
||||
//列表
|
||||
List<List<DingTableVO>> dingTableVOSMaterialList = new ArrayList<>();
|
||||
for (DjzbVO.Arap_djfb children : childrens) {
|
||||
List<DingTableVO> dingTableVOS = new ArrayList<>();
|
||||
// dingTableVOS.add(new DingTableVO("存货分类", children.getDate_property_name()));
|
||||
// dingTableVOS.add(new DingTableVO("产品名称", children.getDate_property_name()));
|
||||
// dingTableVOS.add(new DingTableVO("产品数量", children.getDate_property_name()));
|
||||
// dingTableVOS.add(new DingTableVO("付款金额(元)", children.getDate_property_name()));
|
||||
// dingTableVOS.add(new DingTableVO("税率", children.getDate_property_name()));
|
||||
}
|
||||
// form.add(new StartProcessInstanceRequest.StartProcessInstanceRequestFormComponentValues().setName("开票抬头").setValue(parentvo.getExternal_org_name()));
|
||||
// form.add(new StartProcessInstanceRequest.StartProcessInstanceRequestFormComponentValues().setName("开票方").setValue(parentvo.getExternal_org_name()));
|
||||
// form.add(new StartProcessInstanceRequest.StartProcessInstanceRequestFormComponentValues().setName("对方类型").setValue(parentvo.getExternal_org_name()));
|
||||
// form.add(new StartProcessInstanceRequest.StartProcessInstanceRequestFormComponentValues().setName("支付方式-银行").setValue(parentvo.getExternal_org_name()));
|
||||
// form.add(new StartProcessInstanceRequest.StartProcessInstanceRequestFormComponentValues().setName("银行支行名称").setValue(parentvo.getExternal_org_name()));
|
||||
// form.add(new StartProcessInstanceRequest.StartProcessInstanceRequestFormComponentValues().setName("申请支付日期").setValue(parentvo.getExternal_org_name()));
|
||||
// form.add(new StartProcessInstanceRequest.StartProcessInstanceRequestFormComponentValues().setName("备注").setValue(parentvo.getExternal_org_name()));
|
||||
//附件
|
||||
form.add(new StartProcessInstanceRequest.StartProcessInstanceRequestFormComponentValues().setName("附件").setValue(JSONUtil.toJsonStr(fileModuleVOList)));
|
||||
|
||||
|
||||
/**
|
||||
* 推送钉钉--》发起审批实例
|
||||
* accessToken-->
|
||||
* originatorUserId-->审批发起人的userId。
|
||||
* processCode-->审批流的唯一码。
|
||||
* deptId-->审批发起人所在的部门ID。
|
||||
* microappAgentId-->应用标识AgentId,
|
||||
* approvers-->不使用审批流模板时,直接指定的审批人列表,最大列表长度:20。
|
||||
* formComponentValues-->表单数据内容,控件列表,最大列表长度:150。
|
||||
*/
|
||||
StartProcessInstanceResponse startProcessInstanceResponse = DingTalkUtils.InitiateApprovalInstance(accessToken, "6715600736721738", processCode, 1L, Long.valueOf(U8C_TEST_AGENTID), null, form);
|
||||
JSONObject jsonObject = JSONUtil.parseObj(startProcessInstanceResponse);
|
||||
String statusCode = jsonObject.get("statusCode").toString();
|
||||
if (!statusCode.equals("200")) {
|
||||
Assert.state(false, "问题记录:推送钉钉审批实例失败。失败原因:{}", JSONUtil.toJsonStr(jsonObject.get("body")));
|
||||
}
|
||||
logger.info("推送钉钉-->发起审批实例-->执行成功");
|
||||
|
||||
//审批实例id
|
||||
String instanceId = JSONUtil.parseObj(jsonObject.get("body")).get("instanceId").toString();
|
||||
System.out.println(instanceId);
|
||||
|
||||
//记录成功记录
|
||||
|
||||
|
||||
|
||||
}catch (Exception e){
|
||||
logger.error(e.getMessage());
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -31,27 +31,27 @@ public class FileUtil {
|
|||
* 审批文件上传钉盘
|
||||
* @param accessToken 应用Token
|
||||
* @param unionid 钉钉用户unionid
|
||||
* @param dingFileUrlID 钉盘审批实例中附件地址
|
||||
* @param spaceId 钉盘审批实例中附件地址
|
||||
* @param fileVO 的文件信息
|
||||
* @param stream 文件读取的字节流
|
||||
* @param parentSpaceId 父空间id
|
||||
* @param dingFileUrlID 钉盘审批实例中附件地址
|
||||
* @return
|
||||
*/
|
||||
public static FileModuleVO get4DingDileModuleVO(String accessToken, String unionid, String dingFileUrlID, SysFileVO fileVO, ByteArrayOutputStream stream,String parentSpaceId){
|
||||
public static FileModuleVO get4DingDileModuleVO(String accessToken, String unionid, String spaceId, SysFileVO fileVO, ByteArrayOutputStream stream,String dingFileUrlID){
|
||||
FileModuleVO fileModuleVO = new FileModuleVO();
|
||||
try {
|
||||
//钉钉--上传附件
|
||||
//1.调用服务端API-获取审批钉盘空间信息接口,获取审批空间spaceId。
|
||||
System.out.println(dingFileUrlID);
|
||||
System.out.println(spaceId);
|
||||
//2.调用服务端API-获取文件上传信息接口,获取审批空间文件上传信息并执行上传。
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////此处很容易调权限,钉钉问题。添加权限
|
||||
AddPermissionResponse addPermissionResponse = DingTalkUtils.addFileStorageByUnionId(accessToken, parentSpaceId, unionid);
|
||||
AddPermissionResponse addPermissionResponse = DingTalkUtils.addFileStorageByUnionId(accessToken, spaceId, unionid);
|
||||
if(addPermissionResponse.getBody().getSuccess()!=true){
|
||||
Assert.state(false,"钉钉添加审批实例附件到钉盘权限失败");
|
||||
}
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////此处很容易调权限,钉钉问题。添加权限
|
||||
//2.1调用本接口,获取上传文件需要的resourceUrls和headers参数值。
|
||||
GetFileUploadInfoResponse headerSignature = DingTalkUtils.getFileUploadInfo(accessToken, parentSpaceId, unionid, "HEADER_SIGNATURE", false);
|
||||
GetFileUploadInfoResponse headerSignature = DingTalkUtils.getFileUploadInfo(accessToken, spaceId, unionid, "HEADER_SIGNATURE", false);
|
||||
String uploadKey = headerSignature.getBody().getUploadKey();
|
||||
List<String> resourceUrls = headerSignature.getBody().getHeaderSignatureInfo().getResourceUrls();
|
||||
if (resourceUrls.size() > 1) {
|
||||
|
@ -91,13 +91,13 @@ public class FileUtil {
|
|||
commitFileRequestOptionAppProperties.setVisibility("PUBLIC");//属性可见性。 - PUBLIC:所有应用都可见 - PRIVATE:仅限当前应用可见
|
||||
|
||||
//3.提交文件
|
||||
CommitFileResponse commitFileResponse = DingTalkUtils.submitFile(accessToken, parentSpaceId, unionid, uploadKey, fileVO.getFileName(), parentSpaceId, commitFileRequestOptionAppProperties);
|
||||
CommitFileResponse commitFileResponse = DingTalkUtils.submitFile(accessToken, spaceId, unionid, uploadKey, fileVO.getFileName(), dingFileUrlID, commitFileRequestOptionAppProperties);
|
||||
|
||||
//钉盘文件唯一id
|
||||
String dingFileUniqueId = commitFileResponse.getBody().getDentry().getId();
|
||||
|
||||
//4.组装钉钉文件控件-->"[{\"spaceId\": \"163xxxx658\", \"fileName\": \"2644.JPG\", \"fileSize\": \"333\", \"fileType\": \"jpg\", \"fileId\": \"643xxxx140\"}]"
|
||||
fileModuleVO.setSpaceId(parentSpaceId);
|
||||
fileModuleVO.setSpaceId(spaceId);
|
||||
fileModuleVO.setFileName(fileVO.getFileName());
|
||||
fileModuleVO.setFileSize(String.valueOf(fileVO.getFileSize()));
|
||||
String s = StringUtils.substringAfter(fileVO.getFileName(), ".");
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
package com.hzya.frame.plugin.lets.dingtalk.vo;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class DingTableVO {
|
||||
private String id;
|
||||
private String name;
|
||||
private String value;
|
||||
public DingTableVO(String name, String value) {
|
||||
this.name = name;
|
||||
this.value = value;
|
||||
}
|
||||
}
|
|
@ -53,6 +53,7 @@ letsofs:
|
|||
|
||||
#钉钉
|
||||
DING:
|
||||
U8C_TEST_AGENTID: 3281181231
|
||||
CorpId: dingc5b16c82b7f25e64acaaa37764f94726
|
||||
APIToken: c5530fb4faed387593ee17f4e6bb748d
|
||||
#钉钉回调
|
||||
|
@ -73,10 +74,10 @@ DING:
|
|||
#采购付款申请(店群专用)
|
||||
PURCHASE_PAYMENT_REQUEST_SHOP: PROC-285CCF2B-524F-4055-BE62-FC31F490C654
|
||||
#审批表单空间
|
||||
APPROVE_FILE_SPACE:
|
||||
APPROVE_FOLDER_SPACE:
|
||||
#特殊业务处理(新)
|
||||
SPECIAL_SERVICE_PROCESSING: 25354825296
|
||||
SPECIAL_SERVICE_PROCESSING: 157791788097
|
||||
#采购付款申请(新)
|
||||
PURCHASE_PAYMENT_REQUEST_NEW: 25354984089
|
||||
PURCHASE_PAYMENT_REQUEST_NEW: 157828688115
|
||||
#采购付款申请(店群专用)
|
||||
PURCHASE_PAYMENT_REQUEST_SHOP: 25354973072
|
||||
PURCHASE_PAYMENT_REQUEST_SHOP: 157828627012
|
|
@ -45,6 +45,7 @@ letsofs:
|
|||
|
||||
#钉钉
|
||||
DING:
|
||||
U8C_TEST_AGENTID: 3281181231
|
||||
CorpId: dingc5b16c82b7f25e64acaaa37764f94726
|
||||
APIToken: c5530fb4faed387593ee17f4e6bb748d
|
||||
#钉钉回调
|
||||
|
@ -65,10 +66,10 @@ DING:
|
|||
#采购付款申请(店群专用)
|
||||
PURCHASE_PAYMENT_REQUEST_SHOP: PROC-285CCF2B-524F-4055-BE62-FC31F490C654
|
||||
#审批表单空间
|
||||
APPROVE_FILE_SPACE:
|
||||
APPROVE_FOLDER_SPACE:
|
||||
#特殊业务处理(新)
|
||||
SPECIAL_SERVICE_PROCESSING: 25354825296
|
||||
SPECIAL_SERVICE_PROCESSING: 157791788097
|
||||
#采购付款申请(新)
|
||||
PURCHASE_PAYMENT_REQUEST_NEW: 25354984089
|
||||
PURCHASE_PAYMENT_REQUEST_NEW: 157828688115
|
||||
#采购付款申请(店群专用)
|
||||
PURCHASE_PAYMENT_REQUEST_SHOP: 25354973072
|
||||
PURCHASE_PAYMENT_REQUEST_SHOP: 157828627012
|
Loading…
Reference in New Issue