增加监听器

This commit is contained in:
jinqiming 2020-09-18 17:03:54 +08:00
parent 0d723be4ba
commit 51170f41a8
7 changed files with 280 additions and 9 deletions

View File

@ -99,10 +99,13 @@ public class Constants
/**
* 钉钉企业内部APPkey
*/
public static final String ENTERPRICE_APP_KEY="enterpriceAppKey";
public static final String ENTERPRICE_APP_KEY="enterprice.app.key";
/**
* 钉钉企业内部ENTERPRICE_APP_SECRET
*/
public static final String ENTERPRICE_APP_SECRET="enterpriceAppSecret";
public static final String ENTERPRICE_APP_SECRET="enterprice.app.secret";
/**
* 钉钉企业内部 AGENT_ID
*/
public static final String AGENT_ID="agent.id";
}

View File

@ -15,4 +15,10 @@ public class BaseConstantUrl {
* 创建部门
*/
public static final String DEPARTMENT_CREATE="https://oapi.dingtalk.com/department/create";
/**
* 创建流程
*
*/
public static final String FLOW_CREATE="https://oapi.dingtalk.com/topapi/processinstance/create";
}

View File

@ -2,7 +2,7 @@ package com.snow.dingtalk.listener;
import com.alibaba.fastjson.JSON;
import com.snow.common.enums.DingTalkListenerType;
import com.snow.dingtalk.model.DepartmentDTO;
import com.snow.dingtalk.model.DepartmentCreateRequest;
import com.snow.dingtalk.service.DepartmentService;
import com.snow.system.domain.SysDept;
import com.snow.system.event.SyncEvent;
@ -30,7 +30,7 @@ public class SyncEventListener implements ApplicationListener<SyncEvent> {
Integer eventType = syncEvent.getEventType();
if(eventType==DingTalkListenerType.DEPARTMENT_CREATE.getCode()){
SysDept sysDept=(SysDept)syncEvent.getT();
DepartmentDTO departmentDTO = DepartmentDTO.builder().name(sysDept.getDeptName()).order(sysDept.getOrderNum())
DepartmentCreateRequest departmentDTO = DepartmentCreateRequest.builder().name(sysDept.getDeptName()).order(sysDept.getOrderNum())
.parentid(sysDept.getParentName()).build();
departmentService.createDepartment(departmentDTO);
}

View File

@ -15,7 +15,7 @@ import lombok.NoArgsConstructor;
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class DepartmentDTO {
public class DepartmentCreateRequest {
/**
* 部门名称长度限制为1~64个字符不允许包含字符-以及,
*/

View File

@ -0,0 +1,205 @@
package com.snow.dingtalk.model;
import com.dingtalk.api.request.OapiProcessinstanceCreateRequest;
import com.taobao.api.internal.mapping.ApiField;
import com.taobao.api.internal.mapping.ApiListField;
import com.taobao.api.internal.util.json.JSONWriter;
import lombok.NonNull;
import java.util.List;
/**
* @author qimingjin
* @Title:
* @Description:
* @date 2020/9/18 15:26
*/
public class ProcessinstanceCreateRequest {
/**
*
* 审批人userid列表最大列表长度20
*
* 多个审批人用逗号分隔按传入的顺序依次审批
*/
private String approvers;
/**
* 审批人列表
*
* 支持会签/或签优先级高于approvers变量
*/
private String approversV2;
/**
*抄送人userid列表最大列表长度20多个抄送人用逗号分隔
*
* 该参数需要与cc_position参数一起传抄送人才会生效
*
* 该参数需要与approvers或approvers_v2参数一起传抄送人才会生效
*/
private String ccList;
/**
* 抄送时间分为START, FINISH, START_FINISH,默认是START
*/
private String ccPosition;
/**
* 发起人所在的部门
*
* 如果发起人属于根部门-1
*/
@NonNull
private Long deptId;
private String formComponentValues;
/**
* 审批实例发起人的userid
*/
private String originatorUserId;
/**
* 审批流的唯一码process_code就在审批流编辑的页面URL中
*/
private String processCode;
public ProcessinstanceCreateRequest() {
}
public void setApprovers(String approvers) {
this.approvers = approvers;
}
public String getApprovers() {
return this.approvers;
}
public void setApproversV2(String approversV2) {
this.approversV2 = approversV2;
}
public void setApproversV2(List<OapiProcessinstanceCreateRequest.ProcessInstanceApproverVo> approversV2) {
this.approversV2 = (new JSONWriter(false, false, true)).write(approversV2);
}
public String getApproversV2() {
return this.approversV2;
}
public void setCcList(String ccList) {
this.ccList = ccList;
}
public String getCcList() {
return this.ccList;
}
public void setCcPosition(String ccPosition) {
this.ccPosition = ccPosition;
}
public String getCcPosition() {
return this.ccPosition;
}
public void setDeptId(Long deptId) {
this.deptId = deptId;
}
public Long getDeptId() {
return this.deptId;
}
public void setFormComponentValues(String formComponentValues) {
this.formComponentValues = formComponentValues;
}
public void setFormComponentValues(List<OapiProcessinstanceCreateRequest.FormComponentValueVo> formComponentValues) {
this.formComponentValues = (new JSONWriter(false, false, true)).write(formComponentValues);
}
public String getFormComponentValues() {
return this.formComponentValues;
}
public void setOriginatorUserId(String originatorUserId) {
this.originatorUserId = originatorUserId;
}
public String getOriginatorUserId() {
return this.originatorUserId;
}
public void setProcessCode(String processCode) {
this.processCode = processCode;
}
public String getProcessCode() {
return this.processCode;
}
public static class ProcessInstanceApproverVo {
private static final long serialVersionUID = 7264365528946378186L;
@ApiField("task_action_type")
private String taskActionType;
@ApiListField("user_ids")
@ApiField("string")
private List<String> userIds;
public ProcessInstanceApproverVo() {
}
public String getTaskActionType() {
return this.taskActionType;
}
public void setTaskActionType(String taskActionType) {
this.taskActionType = taskActionType;
}
public List<String> getUserIds() {
return this.userIds;
}
public void setUserIds(List<String> userIds) {
this.userIds = userIds;
}
}
public static class FormComponentValueVo {
private static final long serialVersionUID = 4315945541956941229L;
@ApiField("ext_value")
private String extValue;
@ApiField("name")
private String name;
@ApiField("value")
private String value;
public FormComponentValueVo() {
}
public String getExtValue() {
return this.extValue;
}
public void setExtValue(String extValue) {
this.extValue = extValue;
}
public String getName() {
return this.name;
}
public void setName(String name) {
this.name = name;
}
public String getValue() {
return this.value;
}
public void setValue(String value) {
this.value = value;
}
}
}

View File

@ -7,10 +7,9 @@ import com.dingtalk.api.request.OapiDepartmentCreateRequest;
import com.dingtalk.api.response.OapiDepartmentCreateResponse;
import com.snow.dingtalk.common.BaseConstantUrl;
import com.snow.dingtalk.common.BaseService;
import com.snow.dingtalk.model.DepartmentDTO;
import com.snow.dingtalk.model.DepartmentCreateRequest;
import com.taobao.api.ApiException;
import com.taobao.api.Constants;
import org.slf4j.Logger;
import org.springframework.stereotype.Service;
/**
@ -26,7 +25,7 @@ public class DepartmentService extends BaseService {
* @param departmentDTO
* @return
*/
public Long createDepartment(DepartmentDTO departmentDTO){
public Long createDepartment(DepartmentCreateRequest departmentDTO){
DingTalkClient client = new DefaultDingTalkClient(BaseConstantUrl.DEPARTMENT_CREATE);
OapiDepartmentCreateRequest request = new OapiDepartmentCreateRequest();
request.setParentid(departmentDTO.getParentid());

View File

@ -0,0 +1,58 @@
package com.snow.dingtalk.service;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.dingtalk.api.DefaultDingTalkClient;
import com.dingtalk.api.request.OapiProcessinstanceCreateRequest;
import com.dingtalk.api.response.OapiProcessinstanceCreateResponse;
import com.snow.common.constant.Constants;
import com.snow.dingtalk.common.BaseConstantUrl;
import com.snow.dingtalk.common.BaseService;
import com.snow.dingtalk.model.ProcessinstanceCreateRequest;
import com.snow.system.service.ISysConfigService;
import com.snow.system.service.ISysOperLogService;
import com.taobao.api.ApiException;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
/**
* @author qimingjin
* @Title:
* @Description:
* @date 2020/9/18 14:32
*/
@Service
public class ProcessInstanceService extends BaseService {
@Autowired
private ISysConfigService isysConfigService;
/**
* 创建流程
* @param processinstanceCreateRequest
*/
public String create(ProcessinstanceCreateRequest processinstanceCreateRequest){
DefaultDingTalkClient client = new DefaultDingTalkClient(BaseConstantUrl.FLOW_CREATE);
OapiProcessinstanceCreateRequest request = new OapiProcessinstanceCreateRequest();
request.setAgentId(Long.parseLong(isysConfigService.selectConfigByKey(Constants.AGENT_ID)));
BeanUtils.copyProperties(processinstanceCreateRequest,request);
try {
OapiProcessinstanceCreateResponse response = client.execute(request,getDingTalkToken());
if(response.getErrcode()==0){
syncDingTalkErrorOperLog(BaseConstantUrl.FLOW_CREATE,response.getMessage(),"ProcessInstanceCreateRequest",JSON.toJSONString(request));
return response.getProcessInstanceId();
}else {
syncDingTalkErrorOperLog(BaseConstantUrl.FLOW_CREATE,response.getErrmsg(),"ProcessInstanceCreateRequest",JSON.toJSONString(request));
}
} catch (ApiException e) {
syncDingTalkErrorOperLog(BaseConstantUrl.FLOW_CREATE,e.getMessage(),"ProcessInstanceCreateRequest",JSON.toJSONString(request));
e.printStackTrace();
}
return null;
}
}