完善项目,增加用户字段

This commit is contained in:
jinqiming 2020-11-12 17:29:22 +08:00
parent debe6d9191
commit 1131ecc5a0
12 changed files with 208 additions and 83 deletions

View File

@ -13,7 +13,9 @@ public enum DingTalkListenerType {
DEPARTMENT_DELETED(3,2,"部门删除"),
USER_CREATED(5,2,"用户创建"),
USER_CREATED(5,1,"用户创建"),
USER_DELETE(6,1,"用户删除"),
CALL_BACK_REGISTER(20,10, "回调注册"),

View File

@ -12,6 +12,10 @@ public class BaseConstantUrl {
* 创建用户
*/
public static final String USER_CREATE= "https://oapi.dingtalk.com/topapi/v2/user/create";
/**
* 删除用户
*/
public static final String USER_DELETE= "https://oapi.dingtalk.com/topapi/v2/user/delete";
/**
* 获取token url
*/

View File

@ -1,35 +0,0 @@
package com.snow.dingtalk.listener;
import com.alibaba.fastjson.JSON;
import com.snow.common.utils.spring.SpringUtils;
import com.snow.dingtalk.model.DepartmentCreateRequest;
import com.snow.dingtalk.service.impl.DepartmentServiceImpl;
import com.snow.system.domain.SysDept;
import com.snow.system.event.SyncEvent;
import lombok.extern.slf4j.Slf4j;
/**
* @author qimingjin
* @Title: 创建部门数据同步
* @Description:
* @date 2020/9/28 9:33
*/
@Slf4j
public class DepartmentCreateEventService implements ISyncDingTalkInfo {
private DepartmentServiceImpl departmentService=SpringUtils.getBean("departmentServiceImpl");
@Override
public void syncDingTalkInfoEvent(SyncEvent syncEvent) {
log.info("调用创建钉钉组织架构传入的原始参数:{}"+JSON.toJSONString(syncEvent));
SysDept sysDept=(SysDept)syncEvent.getT();
DepartmentCreateRequest departmentDTO = DepartmentCreateRequest.builder()
.name(sysDept.getDeptName())
.order(sysDept.getOrderNum())
.parentid(sysDept.getParentName())
.build();
departmentService.createDepartment(departmentDTO);
}
}

View File

@ -0,0 +1,44 @@
package com.snow.dingtalk.listener;
import com.alibaba.fastjson.JSON;
import com.snow.common.enums.DingTalkListenerType;
import com.snow.common.utils.spring.SpringUtils;
import com.snow.dingtalk.model.DepartmentCreateRequest;
import com.snow.dingtalk.service.impl.DepartmentServiceImpl;
import com.snow.system.domain.SysDept;
import com.snow.system.event.SyncEvent;
import lombok.extern.slf4j.Slf4j;
/**
* @author qimingjin
* @Title: 创建部门数据同步
* @Description:
* @date 2020/9/28 9:33
*/
@Slf4j
public class DepartmentEventService implements ISyncDingTalkInfo {
private DepartmentServiceImpl departmentService=SpringUtils.getBean("departmentServiceImpl");
@Override
public void syncDingTalkInfoEvent(SyncEvent syncEvent) {
log.info("调用创建钉钉部门传入的原始参数:{}"+JSON.toJSONString(syncEvent));
DingTalkListenerType eventType =(DingTalkListenerType) syncEvent.getT();
Integer code = eventType.getCode();
if(code.equals(DingTalkListenerType.DEPARTMENT_CREATE.getCode())){
SysDept sysDept=(SysDept)syncEvent.getSource();
DepartmentCreateRequest departmentDTO = DepartmentCreateRequest.builder()
.name(sysDept.getDeptName())
.order(sysDept.getOrderNum())
.parentid(sysDept.getParentName())
.build();
departmentService.createDepartment(departmentDTO);
}
else if( code.equals(DingTalkListenerType.DEPARTMENT_DELETED.getCode())){
}
}
}

View File

@ -20,10 +20,10 @@ public class SyncDingTalkInfoFactory {
DingTalkListenerType dingTalkEnum = (DingTalkListenerType) syncEvent.getT();
Integer type = dingTalkEnum.getType();
if(type.equals(DingTalkListenerType.DEPARTMENT_CREATE.getType())){
return new DepartmentCreateEventService();
return new DepartmentEventService();
}
else if(type.equals(DingTalkListenerType.USER_CREATED.getType())){
return new UserCreateEventService();
return new UserEventService();
}
else if(type.equals(DingTalkListenerType.CALL_BACK_REGISTER.getType())){
return new CallBackService();

View File

@ -1,16 +0,0 @@
package com.snow.dingtalk.listener;
import com.snow.system.event.SyncEvent;
/**
* @author qimingjin
* @Title: 创建用户
* @Description:
* @date 2020/9/28 9:34
*/
public class UserCreateEventService implements ISyncDingTalkInfo {
@Override
public void syncDingTalkInfoEvent(SyncEvent syncEvent) {
}
}

View File

@ -0,0 +1,36 @@
package com.snow.dingtalk.listener;
import com.alibaba.fastjson.JSON;
import com.snow.common.enums.DingTalkListenerType;
import com.snow.common.utils.spring.SpringUtils;
import com.snow.dingtalk.service.impl.UserServiceImpl;
import com.snow.system.domain.SysUser;
import com.snow.system.event.SyncEvent;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
/**
* @author qimingjin
* @Title: 创建用户
* @Description:
* @date 2020/9/28 9:34
*/
@Component
@Slf4j
public class UserEventService implements ISyncDingTalkInfo {
private UserServiceImpl userService=SpringUtils.getBean("userServiceImpl");
@Override
public void syncDingTalkInfoEvent(SyncEvent syncEvent) {
log.info("调用钉钉用户回调传入的原始参数:{}"+JSON.toJSONString(syncEvent));
DingTalkListenerType eventType =(DingTalkListenerType) syncEvent.getT();
Integer code = eventType.getCode();
if(code.equals(DingTalkListenerType.USER_CREATED.getCode())){
userService.createUser((SysUser) syncEvent.getSource());
}
else if( code.equals(DingTalkListenerType.USER_DELETE.getCode())){
userService.deleteUser((String) syncEvent.getSource());
}
}
}

View File

@ -1,5 +1,6 @@
package com.snow.dingtalk.service;
import com.dingtalk.api.response.OapiV2UserCreateResponse;
import com.snow.system.domain.SysUser;
/**
@ -17,6 +18,12 @@ public interface UserService {
* @param
* @return
*/
String create(SysUser sysUser);
OapiV2UserCreateResponse.UserCreateResponse createUser(SysUser sysUser);
/**
* 删除用户
* @param ids
*/
void deleteUser(String ids);
}

View File

@ -1,14 +1,23 @@
package com.snow.dingtalk.service.impl;
import com.alibaba.fastjson.JSON;
import com.dingtalk.api.DefaultDingTalkClient;
import com.dingtalk.api.DingTalkClient;
import com.dingtalk.api.request.OapiV2UserCreateRequest;
import com.dingtalk.api.request.OapiV2UserDeleteRequest;
import com.dingtalk.api.response.OapiV2UserCreateResponse;
import com.dingtalk.api.response.OapiV2UserDeleteResponse;
import com.snow.common.utils.StringUtils;
import com.snow.common.utils.spring.SpringUtils;
import com.snow.dingtalk.common.BaseConstantUrl;
import com.snow.dingtalk.common.BaseService;
import com.snow.dingtalk.service.UserService;
import com.snow.system.domain.SysPost;
import com.snow.system.domain.SysUser;
import com.snow.system.service.impl.SysDeptServiceImpl;
import com.snow.system.service.impl.SysPostServiceImpl;
import com.taobao.api.ApiException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
@ -21,46 +30,80 @@ import java.util.List;
* @date 2020/11/9 10:51
*/
@Service
@Slf4j
public class UserServiceImpl extends BaseService implements UserService {
private SysPostServiceImpl sysPostService=SpringUtils.getBean("sysPostServiceImpl");
@Override
public String create(SysUser sysUser) {
public OapiV2UserCreateResponse.UserCreateResponse createUser(SysUser sysUser) {
DingTalkClient client = new DefaultDingTalkClient(BaseConstantUrl.USER_CREATE);
OapiV2UserCreateRequest req = new OapiV2UserCreateRequest();
req.setUserid(String.valueOf(sysUser.getUserId()));
req.setName(sysUser.getUserName());
req.setMobile(sysUser.getPhonenumber());
req.setHideMobile(false);
//req.setTelephone(sysUser.getPhonenumber());
req.setTelephone(sysUser.getPhonenumber());
req.setJobNumber(sysUser.getJobnumber());
req.setTitle("技术总监");
req.setEmail("test@xxx.com");
req.setOrgEmail("test@xxx.com");
req.setWorkPlace("未来park");
req.setRemark("备注备注");
req.setDeptIdList("\"2,3,4\"");
req.setTitle(sysUser.getPosition());
req.setEmail(sysUser.getEmail());
req.setOrgEmail(sysUser.getOrgEmail());
req.setWorkPlace(sysUser.getWorkPlace());
req.setRemark(sysUser.getRemark());
//部门list
req.setDeptIdList(JSON.toJSONString(sysUser.getDept().getDeptId()));
List<OapiV2UserCreateRequest.DeptOrder> list2 = new ArrayList<>();
OapiV2UserCreateRequest.DeptOrder obj3 = new OapiV2UserCreateRequest.DeptOrder();
list2.add(obj3);
obj3.setDeptId(2L);
obj3.setOrder(1L);
req.setDeptOrderList(list2);
List<OapiV2UserCreateRequest.DeptTitle> list5 = new ArrayList<>();
OapiV2UserCreateRequest.DeptTitle obj6 = new OapiV2UserCreateRequest.DeptTitle();
list5.add(obj6);
obj6.setDeptId(2L);
obj6.setTitle("资深产品经理");
req.setDeptTitleList(list5);
req.setExtension("{\"爱好\":\"旅游\",\"年龄\":\"24\"}");
//员工在对应的部门中的职位
List<OapiV2UserCreateRequest.DeptTitle> deptTitleList = new ArrayList<>();
Long[] postIds = sysUser.getPostIds();
if(StringUtils.isNotNull(postIds)){
for(Long postId:postIds){
SysPost sysPost = sysPostService.selectPostById(postId);
OapiV2UserCreateRequest.DeptTitle deptTitle = new OapiV2UserCreateRequest.DeptTitle();
deptTitle.setDeptId(sysUser.getDeptId());
deptTitle.setTitle(sysPost.getPostName());
deptTitleList.add(deptTitle);
}
}
//req.setExtension("{\"爱好\":\"旅游\",\"年龄\":\"24\"}");
req.setSeniorMode(false);
req.setHiredDate(1597573616828L);
OapiV2UserCreateResponse rsp = null;
req.setHiredDate(sysUser.getHiredDate());
OapiV2UserCreateResponse response = null;
try {
rsp = client.execute(req, getDingTalkToken());
response = client.execute(req, getDingTalkToken());
if(response.getErrcode()==0){
syncDingTalkErrorOperLog(BaseConstantUrl.USER_CREATE,response.getMessage(),"createUser",JSON.toJSONString(req));
OapiV2UserCreateResponse.UserCreateResponse result = response.getResult();
return result;
}else {
syncDingTalkErrorOperLog(BaseConstantUrl.USER_CREATE,response.getErrmsg(),"createUser",JSON.toJSONString(req));
}
} catch (ApiException e) {
syncDingTalkErrorOperLog(BaseConstantUrl.USER_CREATE,e.getMessage(),"createUser",JSON.toJSONString(req));
e.printStackTrace();
}
System.out.println(rsp.getBody());
return null;
}
@Override
public void deleteUser(String ids) {
DingTalkClient client = new DefaultDingTalkClient(BaseConstantUrl.USER_DELETE);
OapiV2UserDeleteRequest req = new OapiV2UserDeleteRequest();
req.setUserid(ids);
OapiV2UserDeleteResponse response = null;
try {
response = client.execute(req, getDingTalkToken());
if(response.getErrcode()==0){
syncDingTalkErrorOperLog(BaseConstantUrl.USER_DELETE,response.getMessage(),"deleteUser",JSON.toJSONString(req));
String requestId = response.getRequestId();
log.info("dingTalk删除用户返回{}",requestId);
}else {
syncDingTalkErrorOperLog(BaseConstantUrl.USER_DELETE,response.getErrmsg(),"deleteUser",JSON.toJSONString(req));
}
} catch (ApiException e) {
syncDingTalkErrorOperLog(BaseConstantUrl.USER_DELETE,e.getMessage(),"deleteUser",JSON.toJSONString(req));
e.printStackTrace();
}
}
}

View File

@ -129,7 +129,11 @@ public class SysUser extends BaseEntity
/**
* 入职时间时间戳
*/
private Number hiredDate;
private Long hiredDate;
/**
* 组织邮箱
*/
private String orgEmail;
public SysUser()
{
@ -419,14 +423,22 @@ public class SysUser extends BaseEntity
this.position = position;
}
public Number getHiredDate() {
public Long getHiredDate() {
return hiredDate;
}
public void setHiredDate(Number hiredDate) {
public void setHiredDate(Long hiredDate) {
this.hiredDate = hiredDate;
}
public String getOrgEmail() {
return orgEmail;
}
public void setOrgEmail(String orgEmail) {
this.orgEmail = orgEmail;
}
@Override
public String toString() {
return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)

View File

@ -190,6 +190,9 @@ public class SysUserServiceImpl implements ISysUserService
{
checkUserAllowed(new SysUser(userId));
}
//同步用户数据
SyncEvent syncEvent = new SyncEvent(ids, DingTalkListenerType.USER_DELETE);
applicationContext.publishEvent(syncEvent);
return userMapper.deleteUserByIds(userIds);
}

View File

@ -25,10 +25,16 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<result property="updateBy" column="update_by" />
<result property="updateTime" column="update_time" />
<result property="remark" column="remark" />
<result property="isSenior" column="is_senior" />
<result property="jobnumber" column="job_number" />
<result property="workPlace" column="work_place" />
<result property="tel" column="tel" />
<result property="hiredDate" column="hired_date" />
<result property="orgEmail" column="org_email" />
<association property="dept" column="dept_id" javaType="SysDept" resultMap="deptResult" />
<collection property="roles" javaType="java.util.List" resultMap="RoleResult" />
</resultMap>
<resultMap id="deptResult" type="SysDept">
<id property="deptId" column="dept_id" />
<result property="parentId" column="parent_id" />
@ -179,6 +185,13 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="loginDate != null">login_date = #{loginDate},</if>
<if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>
<if test="remark != null">remark = #{remark},</if>
<if test="isSenior != null">is_senior = #{isSenior},</if>
<if test="jobnumber != null">job_number = #{jobnumber},</if>
<if test="workPlace != null">work_place = #{workPlace},</if>
<if test="tel != null">tel = #{tel},</if>
<if test="hiredDate != null">hired_date = #{hiredDate},</if>
<if test="orgEmail != null">org_email = #{orgEmail},</if>
update_time = sysdate()
</set>
where user_id = #{userId}
@ -200,6 +213,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="status != null and status != ''">status,</if>
<if test="createBy != null and createBy != ''">create_by,</if>
<if test="remark != null and remark != ''">remark,</if>
<if test="isSenior != null">is_senior,</if>
<if test="jobnumber != null">job_number,</if>
<if test="workPlace != null">work_place ,</if>
<if test="tel != null">tel ,</if>
<if test="hiredDate != null">hired_date,</if>
<if test="orgEmail != null">org_email,</if>
create_time
)values(
<if test="userId != null and userId != ''">#{userId},</if>
@ -216,6 +235,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="status != null and status != ''">#{status},</if>
<if test="createBy != null and createBy != ''">#{createBy},</if>
<if test="remark != null and remark != ''">#{remark},</if>
<if test="isSenior != null ">#{isSenior},</if>
<if test="jobnumber != null and jobnumber !=''"> #{jobnumber},</if>
<if test="workPlace != null and workPlace !=''">#{workPlace},</if>
<if test="tel != null and tel!=''">#{tel},</if>
<if test="hiredDate != null and hiredDate !='' ">#{hiredDate},</if>
<if test="orgEmail != null and orgEmail !=''"> #{orgEmail},</if>
sysdate()
)
</insert>