From 6a940a0bb0d25b531e23d70ae93a44627486090a Mon Sep 17 00:00:00 2001
From: jinqiming <45981669@qq.com>
Date: Thu, 17 Sep 2020 18:04:40 +0800
Subject: [PATCH 01/82] =?UTF-8?q?=E4=BF=AE=E6=94=B9readme?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
snow-common/pom.xml | 1 +
.../com/snow/common/constant/Constants.java | 14 +++
.../com/snow/common/enums/BusinessType.java | 8 ++
snow-dingtalk/pom.xml | 6 ++
.../com/snow/dingtalk/SyncEventListener.java | 32 +++++++
.../snow/dingtalk/common/BaseConstantUrl.java | 8 +-
.../com/snow/dingtalk/common/BaseService.java | 44 ++++++++--
.../snow/dingtalk/model/DepartmentDTO.java | 86 +++++++++++++++++++
.../dingtalk/service/DepartmentService.java | 50 +++++++++++
.../src/main/java/com/snow/dingtalk/test.java | 10 ---
.../java/com/snow/system/event/SyncEvent.java | 38 ++++++++
.../service/impl/SysDeptServiceImpl.java | 9 ++
12 files changed, 290 insertions(+), 16 deletions(-)
create mode 100644 snow-dingtalk/src/main/java/com/snow/dingtalk/SyncEventListener.java
create mode 100644 snow-dingtalk/src/main/java/com/snow/dingtalk/model/DepartmentDTO.java
create mode 100644 snow-dingtalk/src/main/java/com/snow/dingtalk/service/DepartmentService.java
delete mode 100644 snow-dingtalk/src/main/java/com/snow/dingtalk/test.java
create mode 100644 snow-system/src/main/java/com/snow/system/event/SyncEvent.java
diff --git a/snow-common/pom.xml b/snow-common/pom.xml
index 4520fe1..2fe1641 100644
--- a/snow-common/pom.xml
+++ b/snow-common/pom.xml
@@ -100,6 +100,7 @@
hutool-all
5.4.2
+
\ No newline at end of file
diff --git a/snow-common/src/main/java/com/snow/common/constant/Constants.java b/snow-common/src/main/java/com/snow/common/constant/Constants.java
index 6e3fdfd..036f1f8 100644
--- a/snow-common/src/main/java/com/snow/common/constant/Constants.java
+++ b/snow-common/src/main/java/com/snow/common/constant/Constants.java
@@ -91,4 +91,18 @@ public class Constants
* 资源映射路径 前缀
*/
public static final String RESOURCE_PREFIX = "/profile";
+
+
+ public static final String POST="POST";
+
+ public static final String GET="GET";
+ /**
+ * 钉钉企业内部APPkey
+ */
+ public static final String ENTERPRICE_APP_KEY="enterpriceAppKey";
+ /**
+ * 钉钉企业内部ENTERPRICE_APP_SECRET
+ */
+ public static final String ENTERPRICE_APP_SECRET="enterpriceAppSecret";
+
}
diff --git a/snow-common/src/main/java/com/snow/common/enums/BusinessType.java b/snow-common/src/main/java/com/snow/common/enums/BusinessType.java
index 996b8ea..5d423ea 100644
--- a/snow-common/src/main/java/com/snow/common/enums/BusinessType.java
+++ b/snow-common/src/main/java/com/snow/common/enums/BusinessType.java
@@ -56,4 +56,12 @@ public enum BusinessType
* 清空
*/
CLEAN,
+ /**
+ * 钉钉
+ */
+ DING_TALK,
+ /**
+ * 同步
+ */
+ SYNCHRONIZATION
}
diff --git a/snow-dingtalk/pom.xml b/snow-dingtalk/pom.xml
index ca84560..b072cb6 100644
--- a/snow-dingtalk/pom.xml
+++ b/snow-dingtalk/pom.xml
@@ -24,5 +24,11 @@
alibaba-dingtalk-service-sdk
1.0.1
+
+
+ org.projectlombok
+ lombok
+ 1.18.10
+
\ No newline at end of file
diff --git a/snow-dingtalk/src/main/java/com/snow/dingtalk/SyncEventListener.java b/snow-dingtalk/src/main/java/com/snow/dingtalk/SyncEventListener.java
new file mode 100644
index 0000000..da4d184
--- /dev/null
+++ b/snow-dingtalk/src/main/java/com/snow/dingtalk/SyncEventListener.java
@@ -0,0 +1,32 @@
+package com.snow.dingtalk;
+
+import com.alibaba.fastjson.JSON;
+import com.snow.dingtalk.model.DepartmentDTO;
+import com.snow.dingtalk.service.DepartmentService;
+import com.snow.system.domain.SysDept;
+import com.snow.system.event.SyncEvent;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.ApplicationListener;
+import org.springframework.stereotype.Component;
+
+/**
+ * @author qimingjin
+ * @Title:
+ * @Description:
+ * @date 2020/9/17 17:40
+ */
+@Component
+public class SyncEventListener implements ApplicationListener {
+
+ @Autowired
+ private DepartmentService departmentService;
+ @Override
+ public void onApplicationEvent(SyncEvent syncEvent) {
+ Integer eventType = syncEvent.getEventType();
+ SysDept sysDept=(SysDept)syncEvent.getT();
+ DepartmentDTO departmentDTO = DepartmentDTO.builder().name(sysDept.getDeptName()).order(sysDept.getOrderNum())
+ .parentid(sysDept.getParentName()).build();
+ departmentService.createDepartment(departmentDTO);
+ System.out.println("监听到的事件类型:"+eventType+JSON.toJSONString(syncEvent));
+ }
+}
diff --git a/snow-dingtalk/src/main/java/com/snow/dingtalk/common/BaseConstantUrl.java b/snow-dingtalk/src/main/java/com/snow/dingtalk/common/BaseConstantUrl.java
index 7aa6724..77590b9 100644
--- a/snow-dingtalk/src/main/java/com/snow/dingtalk/common/BaseConstantUrl.java
+++ b/snow-dingtalk/src/main/java/com/snow/dingtalk/common/BaseConstantUrl.java
@@ -7,6 +7,12 @@ package com.snow.dingtalk.common;
* @date 2020/9/16 11:02
*/
public class BaseConstantUrl {
-
+ /**
+ * 获取token url
+ */
public static final String GET_TOKEN_URL="https://oapi.dingtalk.com/gettoken";
+ /**
+ * 创建部门
+ */
+ public static final String DEPARTMENT_CREATE="https://oapi.dingtalk.com/department/create";
}
diff --git a/snow-dingtalk/src/main/java/com/snow/dingtalk/common/BaseService.java b/snow-dingtalk/src/main/java/com/snow/dingtalk/common/BaseService.java
index 4d28ee6..57cc262 100644
--- a/snow-dingtalk/src/main/java/com/snow/dingtalk/common/BaseService.java
+++ b/snow-dingtalk/src/main/java/com/snow/dingtalk/common/BaseService.java
@@ -5,31 +5,45 @@ import cn.hutool.cache.impl.TimedCache;
import com.dingtalk.api.DefaultDingTalkClient;
import com.dingtalk.api.request.OapiGettokenRequest;
import com.dingtalk.api.response.OapiGettokenResponse;
+import com.snow.common.constant.Constants;
+import com.snow.common.enums.BusinessType;
import com.snow.common.utils.StringUtils;
+import com.snow.system.domain.SysOperLog;
+import com.snow.system.service.ISysConfigService;
+import com.snow.system.service.ISysOperLogService;
import com.taobao.api.ApiException;
+import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
+import java.util.Date;
+
/**
* @author qimingjin
* @Title:
* @Description:
* @date 2020/9/16 10:46
*/
-@Service
public class BaseService {
- public final String TOKEN="token";
+
+ public static final String TOKEN="token";
+ @Autowired
+ private ISysConfigService isysConfigService;
+ @Autowired
+ private ISysOperLogService iSysOperLogService;
+
/**
* 获取token
* @return
*/
public String getDingTalkToken(){
+ //创建缓存,缓存默认是7100S
TimedCache timedCache = CacheUtil.newTimedCache(7100);
if(StringUtils.isEmpty(timedCache.get(TOKEN))){
DefaultDingTalkClient client = new DefaultDingTalkClient(BaseConstantUrl.GET_TOKEN_URL);
OapiGettokenRequest request = new OapiGettokenRequest();
- request.setAppkey("dingjidrzgnmznpofira");
- request.setAppsecret("IuKf2e8Z0stvf8LPMfHy_Im6sTi3G1mh0Jn0k4xuEnOhOyiLfKogwYympDVcRGK4");
- request.setHttpMethod("GET");
+ request.setAppkey(isysConfigService.selectConfigByKey(Constants.ENTERPRICE_APP_KEY));
+ request.setAppsecret(isysConfigService.selectConfigByKey(Constants.ENTERPRICE_APP_SECRET));
+ request.setHttpMethod(Constants.GET);
try {
OapiGettokenResponse response = client.execute(request);
if(response.getErrcode()==0){
@@ -37,9 +51,11 @@ public class BaseService {
return response.getAccessToken();
}else {
//记录获取token失败日志
+ syncDingTalkErrorOperLog(BaseConstantUrl.GET_TOKEN_URL,response.getErrmsg(),"getDingTalkToken()");
return null;
}
} catch (ApiException e) {
+ syncDingTalkErrorOperLog(BaseConstantUrl.GET_TOKEN_URL,e.getMessage(),"getDingTalkToken()");
e.printStackTrace();
}
return null;
@@ -49,4 +65,22 @@ public class BaseService {
}
+ /**
+ * 记录钉钉异常信息
+ * @param url
+ * @param errorMessage
+ * @param method
+ */
+ public void syncDingTalkErrorOperLog(String url,String errorMessage,String method){
+ SysOperLog sysOperLog=new SysOperLog();
+ sysOperLog.setOperTime(new Date());
+ sysOperLog.setErrorMsg(errorMessage);
+ sysOperLog.setBusinessType(BusinessType.SYNCHRONIZATION.ordinal());
+ sysOperLog.setOperName("系统自动记录");
+ sysOperLog.setOperUrl(url);
+ sysOperLog.setMethod(method);
+ sysOperLog.setTitle("系统调用钉钉异常");
+ iSysOperLogService.insertOperlog(sysOperLog);
+ }
+
}
diff --git a/snow-dingtalk/src/main/java/com/snow/dingtalk/model/DepartmentDTO.java b/snow-dingtalk/src/main/java/com/snow/dingtalk/model/DepartmentDTO.java
new file mode 100644
index 0000000..0ec6b1c
--- /dev/null
+++ b/snow-dingtalk/src/main/java/com/snow/dingtalk/model/DepartmentDTO.java
@@ -0,0 +1,86 @@
+package com.snow.dingtalk.model;
+
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+/**
+ * @author qimingjin
+ * @Title:
+ * @Description:
+ * @date 2020/9/17 17:10
+ */
+@Data
+@Builder
+@AllArgsConstructor
+@NoArgsConstructor
+public class DepartmentDTO {
+ /**
+ * 部门名称,长度限制为1~64个字符,不允许包含字符‘-’‘,’以及‘,’
+ */
+ private String name;
+
+
+ /**
+ * 父部门id,根部门id为1
+ */
+ private String parentid;
+
+
+ /**
+ * 在父部门中的排序值,order值小的排序靠前
+ */
+ private String order;
+
+
+ /**
+ * 是否创建一个关联此部门的企业群,默认为false
+ */
+ private Boolean createDeptGroup;
+
+
+ /**
+ *
+ 是否隐藏部门,
+
+ true表示隐藏
+
+ false表示显示
+ */
+ private Boolean deptHiding;
+
+
+ /**
+ * 可以查看指定隐藏部门的其他部门列表,如果部门隐藏,则此值生效,
+ * 取值为其他的部门id组成的字符串,使用“\|”符号进行分割。总数不能超过200
+ */
+
+ private String deptPermits;
+
+
+ /**
+ * 可以查看指定隐藏部门的其他人员列表,如果部门隐藏,则此值生效,
+ * 取值为其他的人员userid组成的字符串,使用“\|”符号进行分割。总数不能超过200
+ */
+ private String userPermits;
+
+
+ /**
+ * 限制本部门成员查看通讯录,限制开启后,本部门成员只能看到限定范围内的通讯录。true表示限制开启
+ */
+ private Boolean outerDept;
+
+
+ /**
+ * 部门标识字段,开发者可用该字段来唯一标识一个部门,并与钉钉外部通讯录里的部门做映射
+ */
+ private String sourceIdentifier;
+
+
+ /**
+ * 部门自定义字段,格式为文本类型的Json格式
+ */
+ private String ext;
+
+}
diff --git a/snow-dingtalk/src/main/java/com/snow/dingtalk/service/DepartmentService.java b/snow-dingtalk/src/main/java/com/snow/dingtalk/service/DepartmentService.java
new file mode 100644
index 0000000..94d018b
--- /dev/null
+++ b/snow-dingtalk/src/main/java/com/snow/dingtalk/service/DepartmentService.java
@@ -0,0 +1,50 @@
+package com.snow.dingtalk.service;
+
+import com.dingtalk.api.DefaultDingTalkClient;
+import com.dingtalk.api.DingTalkClient;
+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.taobao.api.ApiException;
+import com.taobao.api.Constants;
+import org.slf4j.Logger;
+import org.springframework.stereotype.Service;
+
+/**
+ * @author qimingjin
+ * @Title:
+ * @Description:
+ * @date 2020/9/17 17:02
+ */
+@Service
+public class DepartmentService extends BaseService {
+ /**
+ * 创建部门
+ * @param departmentDTO
+ * @return
+ */
+ public Long createDepartment(DepartmentDTO departmentDTO){
+ DingTalkClient client = new DefaultDingTalkClient(BaseConstantUrl.DEPARTMENT_CREATE);
+ OapiDepartmentCreateRequest request = new OapiDepartmentCreateRequest();
+ request.setParentid(departmentDTO.getParentid());
+ request.setCreateDeptGroup(departmentDTO.getCreateDeptGroup());
+ request.setOrder(departmentDTO.getOrder());
+ request.setName(departmentDTO.getName());
+ request.setHttpMethod(Constants.METHOD_POST);
+ request.setSourceIdentifier(departmentDTO.getSourceIdentifier());
+ try {
+ OapiDepartmentCreateResponse response = client.execute(request,getDingTalkToken());
+ if(response.getErrcode()==0){
+ return response.getId();
+ }else {
+ syncDingTalkErrorOperLog(BaseConstantUrl.DEPARTMENT_CREATE,response.getErrmsg(),"createDepartment");
+ }
+ } catch (ApiException e) {
+ syncDingTalkErrorOperLog(BaseConstantUrl.DEPARTMENT_CREATE,e.getMessage(),"createDepartment");
+ e.printStackTrace();
+ }
+ return null;
+ }
+}
diff --git a/snow-dingtalk/src/main/java/com/snow/dingtalk/test.java b/snow-dingtalk/src/main/java/com/snow/dingtalk/test.java
deleted file mode 100644
index 124f019..0000000
--- a/snow-dingtalk/src/main/java/com/snow/dingtalk/test.java
+++ /dev/null
@@ -1,10 +0,0 @@
-package com.snow.dingtalk;
-
-/**
- * @author qimingjin
- * @Title:
- * @Description:
- * @date 2020/9/16 10:45
- */
-public class test {
-}
diff --git a/snow-system/src/main/java/com/snow/system/event/SyncEvent.java b/snow-system/src/main/java/com/snow/system/event/SyncEvent.java
new file mode 100644
index 0000000..a8317c1
--- /dev/null
+++ b/snow-system/src/main/java/com/snow/system/event/SyncEvent.java
@@ -0,0 +1,38 @@
+package com.snow.system.event;
+
+import org.springframework.context.ApplicationEvent;
+
+/**
+ * @author qimingjin
+ * @Title: 同步事件监听器
+ * @Description:
+ * @date 2020/9/17 17:34
+ */
+public class SyncEvent extends ApplicationEvent {
+
+ private Integer eventType;
+
+ private T t;
+
+ public SyncEvent(Object source,Integer eventType,T t) {
+ super(source);
+ this.eventType = eventType;
+ this.t=t;
+ }
+
+ public T getT() {
+ return t;
+ }
+
+ public void setT(T t) {
+ this.t = t;
+ }
+
+ public Integer getEventType() {
+ return eventType;
+ }
+
+ public void setEventType(Integer eventType) {
+ this.eventType = eventType;
+ }
+}
diff --git a/snow-system/src/main/java/com/snow/system/service/impl/SysDeptServiceImpl.java b/snow-system/src/main/java/com/snow/system/service/impl/SysDeptServiceImpl.java
index 6a73579..2892004 100644
--- a/snow-system/src/main/java/com/snow/system/service/impl/SysDeptServiceImpl.java
+++ b/snow-system/src/main/java/com/snow/system/service/impl/SysDeptServiceImpl.java
@@ -5,8 +5,10 @@ import java.util.Iterator;
import java.util.List;
import com.snow.system.domain.SysDept;
+import com.snow.system.event.SyncEvent;
import org.apache.commons.lang3.ArrayUtils;
import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.snow.common.annotation.DataScope;
@@ -18,6 +20,8 @@ import com.snow.system.domain.SysRole;
import com.snow.system.mapper.SysDeptMapper;
import com.snow.system.service.ISysDeptService;
+import javax.annotation.Resource;
+
/**
* 部门管理 服务实现
*
@@ -29,6 +33,9 @@ public class SysDeptServiceImpl implements ISysDeptService
@Autowired
private SysDeptMapper deptMapper;
+ @Resource
+ private ApplicationContext applicationContext;
+
/**
* 查询部门管理数据
*
@@ -204,6 +211,8 @@ public class SysDeptServiceImpl implements ISysDeptService
throw new BusinessException("部门停用,不允许新增");
}
dept.setAncestors(info.getAncestors() + "," + dept.getParentId());
+ SyncEvent syncEvent = new SyncEvent(dept, 1, dept);
+ applicationContext.publishEvent(syncEvent);
return deptMapper.insertDept(dept);
}
From 0d723be4ba6e7b1b276566bdc6398c5f2cdf39cb Mon Sep 17 00:00:00 2001
From: jinqiming <45981669@qq.com>
Date: Fri, 18 Sep 2020 10:49:04 +0800
Subject: [PATCH 02/82] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E7=9B=91=E5=90=AC?=
=?UTF-8?q?=E5=99=A8?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
snow-admin/pom.xml | 6 ++++
.../common/enums/DingTalkListenerType.java | 32 ++++++++++++++++++
.../com/snow/dingtalk/common/BaseService.java | 33 ++++++++++++++++---
.../{ => listener}/SyncEventListener.java | 22 +++++++++----
.../dingtalk/service/DepartmentService.java | 6 ++--
5 files changed, 86 insertions(+), 13 deletions(-)
create mode 100644 snow-common/src/main/java/com/snow/common/enums/DingTalkListenerType.java
rename snow-dingtalk/src/main/java/com/snow/dingtalk/{ => listener}/SyncEventListener.java (52%)
diff --git a/snow-admin/pom.xml b/snow-admin/pom.xml
index dd770d6..9c64e39 100644
--- a/snow-admin/pom.xml
+++ b/snow-admin/pom.xml
@@ -81,6 +81,12 @@
4.3.1
+
+ com.snow
+ snow-dingtalk
+ 4.3.1
+
+
diff --git a/snow-common/src/main/java/com/snow/common/enums/DingTalkListenerType.java b/snow-common/src/main/java/com/snow/common/enums/DingTalkListenerType.java
new file mode 100644
index 0000000..82d2948
--- /dev/null
+++ b/snow-common/src/main/java/com/snow/common/enums/DingTalkListenerType.java
@@ -0,0 +1,32 @@
+package com.snow.common.enums;
+
+/**
+ * @author qimingjin
+ * @Title:
+ * @Description:
+ * @date 2020/9/18 10:18
+ */
+public enum DingTalkListenerType {
+ DEPARTMENT_CREATE(1, "部门创建"),
+ DEPARTMENT_UPDATE(2, "部门更新"),
+ DEPARTMENT_DELETED(3, "部门删除");
+
+ private final Integer code;
+ private final String info;
+
+ DingTalkListenerType(Integer code, String info)
+ {
+ this.code = code;
+ this.info = info;
+ }
+
+ public Integer getCode()
+ {
+ return code;
+ }
+
+ public String getInfo()
+ {
+ return info;
+ }
+}
diff --git a/snow-dingtalk/src/main/java/com/snow/dingtalk/common/BaseService.java b/snow-dingtalk/src/main/java/com/snow/dingtalk/common/BaseService.java
index 57cc262..bcc8662 100644
--- a/snow-dingtalk/src/main/java/com/snow/dingtalk/common/BaseService.java
+++ b/snow-dingtalk/src/main/java/com/snow/dingtalk/common/BaseService.java
@@ -7,6 +7,7 @@ import com.dingtalk.api.request.OapiGettokenRequest;
import com.dingtalk.api.response.OapiGettokenResponse;
import com.snow.common.constant.Constants;
import com.snow.common.enums.BusinessType;
+import com.snow.common.json.JSON;
import com.snow.common.utils.StringUtils;
import com.snow.system.domain.SysOperLog;
import com.snow.system.service.ISysConfigService;
@@ -47,15 +48,16 @@ public class BaseService {
try {
OapiGettokenResponse response = client.execute(request);
if(response.getErrcode()==0){
- timedCache.put( TOKEN,response.getAccessToken());
+ timedCache.put(TOKEN,response.getAccessToken());
+ syncDingTalkErrorOperLog(BaseConstantUrl.GET_TOKEN_URL,response.getMessage(),"getDingTalkToken()", com.alibaba.fastjson.JSON.toJSONString(request));
return response.getAccessToken();
}else {
//记录获取token失败日志
- syncDingTalkErrorOperLog(BaseConstantUrl.GET_TOKEN_URL,response.getErrmsg(),"getDingTalkToken()");
+ syncDingTalkErrorOperLog(BaseConstantUrl.GET_TOKEN_URL,response.getErrmsg(),"getDingTalkToken()", com.alibaba.fastjson.JSON.toJSONString(request));
return null;
}
} catch (ApiException e) {
- syncDingTalkErrorOperLog(BaseConstantUrl.GET_TOKEN_URL,e.getMessage(),"getDingTalkToken()");
+ syncDingTalkErrorOperLog(BaseConstantUrl.GET_TOKEN_URL,e.getMessage(),"getDingTalkToken()",com.alibaba.fastjson.JSON.toJSONString(request));
e.printStackTrace();
}
return null;
@@ -71,7 +73,7 @@ public class BaseService {
* @param errorMessage
* @param method
*/
- public void syncDingTalkErrorOperLog(String url,String errorMessage,String method){
+ public void syncDingTalkErrorOperLog(String url,String errorMessage,String method,String operParam){
SysOperLog sysOperLog=new SysOperLog();
sysOperLog.setOperTime(new Date());
sysOperLog.setErrorMsg(errorMessage);
@@ -79,7 +81,30 @@ public class BaseService {
sysOperLog.setOperName("系统自动记录");
sysOperLog.setOperUrl(url);
sysOperLog.setMethod(method);
+ sysOperLog.setOperParam(operParam);
sysOperLog.setTitle("系统调用钉钉异常");
+ sysOperLog.setStatus(1);
+ iSysOperLogService.insertOperlog(sysOperLog);
+ }
+
+ /**
+ * 成功
+ * @param url
+ * @param successMessage
+ * @param method
+ * @param operParam
+ */
+ public void syncDingTalkSuccessOperLog(String url,String successMessage,String method,String operParam){
+ SysOperLog sysOperLog=new SysOperLog();
+ sysOperLog.setOperTime(new Date());
+ sysOperLog.setBusinessType(BusinessType.SYNCHRONIZATION.ordinal());
+ sysOperLog.setJsonResult(successMessage);
+ sysOperLog.setOperName("系统自动记录");
+ sysOperLog.setOperUrl(url);
+ sysOperLog.setMethod(method);
+ sysOperLog.setOperParam(operParam);
+ sysOperLog.setTitle("调用钉钉成功");
+ sysOperLog.setStatus(0);
iSysOperLogService.insertOperlog(sysOperLog);
}
diff --git a/snow-dingtalk/src/main/java/com/snow/dingtalk/SyncEventListener.java b/snow-dingtalk/src/main/java/com/snow/dingtalk/listener/SyncEventListener.java
similarity index 52%
rename from snow-dingtalk/src/main/java/com/snow/dingtalk/SyncEventListener.java
rename to snow-dingtalk/src/main/java/com/snow/dingtalk/listener/SyncEventListener.java
index da4d184..7d883e5 100644
--- a/snow-dingtalk/src/main/java/com/snow/dingtalk/SyncEventListener.java
+++ b/snow-dingtalk/src/main/java/com/snow/dingtalk/listener/SyncEventListener.java
@@ -1,32 +1,40 @@
-package com.snow.dingtalk;
+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.service.DepartmentService;
import com.snow.system.domain.SysDept;
import com.snow.system.event.SyncEvent;
+import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationListener;
import org.springframework.stereotype.Component;
/**
* @author qimingjin
- * @Title:
+ * @Title: 同步事件监听器
* @Description:
* @date 2020/9/17 17:40
*/
@Component
+@Slf4j
public class SyncEventListener implements ApplicationListener {
@Autowired
private DepartmentService departmentService;
+
@Override
public void onApplicationEvent(SyncEvent syncEvent) {
+ log.info("进入监听器.....");
Integer eventType = syncEvent.getEventType();
- SysDept sysDept=(SysDept)syncEvent.getT();
- DepartmentDTO departmentDTO = DepartmentDTO.builder().name(sysDept.getDeptName()).order(sysDept.getOrderNum())
- .parentid(sysDept.getParentName()).build();
- departmentService.createDepartment(departmentDTO);
- System.out.println("监听到的事件类型:"+eventType+JSON.toJSONString(syncEvent));
+ if(eventType==DingTalkListenerType.DEPARTMENT_CREATE.getCode()){
+ SysDept sysDept=(SysDept)syncEvent.getT();
+ DepartmentDTO departmentDTO = DepartmentDTO.builder().name(sysDept.getDeptName()).order(sysDept.getOrderNum())
+ .parentid(sysDept.getParentName()).build();
+ departmentService.createDepartment(departmentDTO);
+ }
+
+ log.info("监听到的事件类型:"+eventType+JSON.toJSONString(syncEvent));
}
}
diff --git a/snow-dingtalk/src/main/java/com/snow/dingtalk/service/DepartmentService.java b/snow-dingtalk/src/main/java/com/snow/dingtalk/service/DepartmentService.java
index 94d018b..9cd3441 100644
--- a/snow-dingtalk/src/main/java/com/snow/dingtalk/service/DepartmentService.java
+++ b/snow-dingtalk/src/main/java/com/snow/dingtalk/service/DepartmentService.java
@@ -1,5 +1,6 @@
package com.snow.dingtalk.service;
+import com.alibaba.fastjson.JSON;
import com.dingtalk.api.DefaultDingTalkClient;
import com.dingtalk.api.DingTalkClient;
import com.dingtalk.api.request.OapiDepartmentCreateRequest;
@@ -37,12 +38,13 @@ public class DepartmentService extends BaseService {
try {
OapiDepartmentCreateResponse response = client.execute(request,getDingTalkToken());
if(response.getErrcode()==0){
+ syncDingTalkErrorOperLog(BaseConstantUrl.DEPARTMENT_CREATE,response.getMessage(),"createDepartment",JSON.toJSONString(request));
return response.getId();
}else {
- syncDingTalkErrorOperLog(BaseConstantUrl.DEPARTMENT_CREATE,response.getErrmsg(),"createDepartment");
+ syncDingTalkErrorOperLog(BaseConstantUrl.DEPARTMENT_CREATE,response.getErrmsg(),"createDepartment",JSON.toJSONString(request));
}
} catch (ApiException e) {
- syncDingTalkErrorOperLog(BaseConstantUrl.DEPARTMENT_CREATE,e.getMessage(),"createDepartment");
+ syncDingTalkErrorOperLog(BaseConstantUrl.DEPARTMENT_CREATE,e.getMessage(),"createDepartment",JSON.toJSONString(request));
e.printStackTrace();
}
return null;
From 51170f41a85f76948f151d77a4948bb38c327d91 Mon Sep 17 00:00:00 2001
From: jinqiming <45981669@qq.com>
Date: Fri, 18 Sep 2020 17:03:54 +0800
Subject: [PATCH 03/82] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E7=9B=91=E5=90=AC?=
=?UTF-8?q?=E5=99=A8?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../com/snow/common/constant/Constants.java | 9 +-
.../snow/dingtalk/common/BaseConstantUrl.java | 6 +
.../dingtalk/listener/SyncEventListener.java | 4 +-
...tDTO.java => DepartmentCreateRequest.java} | 2 +-
.../model/ProcessinstanceCreateRequest.java | 205 ++++++++++++++++++
.../dingtalk/service/DepartmentService.java | 5 +-
.../service/ProcessInstanceService.java | 58 +++++
7 files changed, 280 insertions(+), 9 deletions(-)
rename snow-dingtalk/src/main/java/com/snow/dingtalk/model/{DepartmentDTO.java => DepartmentCreateRequest.java} (98%)
create mode 100644 snow-dingtalk/src/main/java/com/snow/dingtalk/model/ProcessinstanceCreateRequest.java
create mode 100644 snow-dingtalk/src/main/java/com/snow/dingtalk/service/ProcessInstanceService.java
diff --git a/snow-common/src/main/java/com/snow/common/constant/Constants.java b/snow-common/src/main/java/com/snow/common/constant/Constants.java
index 036f1f8..3715ad5 100644
--- a/snow-common/src/main/java/com/snow/common/constant/Constants.java
+++ b/snow-common/src/main/java/com/snow/common/constant/Constants.java
@@ -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";
}
diff --git a/snow-dingtalk/src/main/java/com/snow/dingtalk/common/BaseConstantUrl.java b/snow-dingtalk/src/main/java/com/snow/dingtalk/common/BaseConstantUrl.java
index 77590b9..428a69f 100644
--- a/snow-dingtalk/src/main/java/com/snow/dingtalk/common/BaseConstantUrl.java
+++ b/snow-dingtalk/src/main/java/com/snow/dingtalk/common/BaseConstantUrl.java
@@ -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";
}
diff --git a/snow-dingtalk/src/main/java/com/snow/dingtalk/listener/SyncEventListener.java b/snow-dingtalk/src/main/java/com/snow/dingtalk/listener/SyncEventListener.java
index 7d883e5..a52eb0c 100644
--- a/snow-dingtalk/src/main/java/com/snow/dingtalk/listener/SyncEventListener.java
+++ b/snow-dingtalk/src/main/java/com/snow/dingtalk/listener/SyncEventListener.java
@@ -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 {
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);
}
diff --git a/snow-dingtalk/src/main/java/com/snow/dingtalk/model/DepartmentDTO.java b/snow-dingtalk/src/main/java/com/snow/dingtalk/model/DepartmentCreateRequest.java
similarity index 98%
rename from snow-dingtalk/src/main/java/com/snow/dingtalk/model/DepartmentDTO.java
rename to snow-dingtalk/src/main/java/com/snow/dingtalk/model/DepartmentCreateRequest.java
index 0ec6b1c..7f7679e 100644
--- a/snow-dingtalk/src/main/java/com/snow/dingtalk/model/DepartmentDTO.java
+++ b/snow-dingtalk/src/main/java/com/snow/dingtalk/model/DepartmentCreateRequest.java
@@ -15,7 +15,7 @@ import lombok.NoArgsConstructor;
@Builder
@AllArgsConstructor
@NoArgsConstructor
-public class DepartmentDTO {
+public class DepartmentCreateRequest {
/**
* 部门名称,长度限制为1~64个字符,不允许包含字符‘-’‘,’以及‘,’
*/
diff --git a/snow-dingtalk/src/main/java/com/snow/dingtalk/model/ProcessinstanceCreateRequest.java b/snow-dingtalk/src/main/java/com/snow/dingtalk/model/ProcessinstanceCreateRequest.java
new file mode 100644
index 0000000..8f52890
--- /dev/null
+++ b/snow-dingtalk/src/main/java/com/snow/dingtalk/model/ProcessinstanceCreateRequest.java
@@ -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 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 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 userIds;
+
+ public ProcessInstanceApproverVo() {
+ }
+
+ public String getTaskActionType() {
+ return this.taskActionType;
+ }
+
+ public void setTaskActionType(String taskActionType) {
+ this.taskActionType = taskActionType;
+ }
+
+ public List getUserIds() {
+ return this.userIds;
+ }
+
+ public void setUserIds(List 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;
+ }
+ }
+}
diff --git a/snow-dingtalk/src/main/java/com/snow/dingtalk/service/DepartmentService.java b/snow-dingtalk/src/main/java/com/snow/dingtalk/service/DepartmentService.java
index 9cd3441..8bd484d 100644
--- a/snow-dingtalk/src/main/java/com/snow/dingtalk/service/DepartmentService.java
+++ b/snow-dingtalk/src/main/java/com/snow/dingtalk/service/DepartmentService.java
@@ -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());
diff --git a/snow-dingtalk/src/main/java/com/snow/dingtalk/service/ProcessInstanceService.java b/snow-dingtalk/src/main/java/com/snow/dingtalk/service/ProcessInstanceService.java
new file mode 100644
index 0000000..1322380
--- /dev/null
+++ b/snow-dingtalk/src/main/java/com/snow/dingtalk/service/ProcessInstanceService.java
@@ -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;
+ }
+}
From 5b52ffdcdcb9a1efece7b27c61df4eff53fd58f4 Mon Sep 17 00:00:00 2001
From: jinqiming <45981669@qq.com>
Date: Tue, 22 Sep 2020 17:08:49 +0800
Subject: [PATCH 04/82] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=AF=B9=E6=8E=A5?=
=?UTF-8?q?=E9=92=89=E9=92=89=E6=8E=A5=E5=8F=A3?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../src/main/resources/templates/main.html | 13 +
.../common/enums/DingTalkListenerType.java | 4 +-
.../snow/common/enums/WorkRecordStatus.java | 30 ++
.../snow/dingtalk/common/BaseConstantUrl.java | 20 ++
.../dingtalk/listener/SyncEventListener.java | 3 +
...java => ProcessInstanceCreateRequest.java} | 10 +-
.../dingtalk/model/UserCreateRequest.java | 263 ++++++++++++++++++
.../dingtalk/model/WorkrecordAddRequest.java | 174 ++++++++++++
.../model/WorkrecordGetbyuseridRequest.java | 17 ++
.../service/ProcessInstanceService.java | 11 +-
.../snow/dingtalk/service/UserService.java | 54 ++++
.../dingtalk/service/WorkRecodeService.java | 111 ++++++++
.../java/com/snow/system/event/SyncEvent.java | 4 +
.../service/impl/SysUserServiceImpl.java | 8 +
14 files changed, 707 insertions(+), 15 deletions(-)
create mode 100644 snow-common/src/main/java/com/snow/common/enums/WorkRecordStatus.java
rename snow-dingtalk/src/main/java/com/snow/dingtalk/model/{ProcessinstanceCreateRequest.java => ProcessInstanceCreateRequest.java} (92%)
create mode 100644 snow-dingtalk/src/main/java/com/snow/dingtalk/model/UserCreateRequest.java
create mode 100644 snow-dingtalk/src/main/java/com/snow/dingtalk/model/WorkrecordAddRequest.java
create mode 100644 snow-dingtalk/src/main/java/com/snow/dingtalk/model/WorkrecordGetbyuseridRequest.java
create mode 100644 snow-dingtalk/src/main/java/com/snow/dingtalk/service/UserService.java
create mode 100644 snow-dingtalk/src/main/java/com/snow/dingtalk/service/WorkRecodeService.java
diff --git a/snow-admin/src/main/resources/templates/main.html b/snow-admin/src/main/resources/templates/main.html
index d622df2..29d4b53 100644
--- a/snow-admin/src/main/resources/templates/main.html
+++ b/snow-admin/src/main/resources/templates/main.html
@@ -1015,7 +1015,9 @@
+