增加钉钉同步通讯录功能

This commit is contained in:
wulin 2020-08-18 09:23:00 +08:00
parent 1dcf374478
commit 6c95752f4b
24 changed files with 1186 additions and 74 deletions

View File

@ -0,0 +1,272 @@
package com.lz.common.utils;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.dingtalk.api.DefaultDingTalkClient;
import com.dingtalk.api.DingTalkClient;
import com.dingtalk.api.request.*;
import com.dingtalk.api.response.*;
import com.lz.modules.job.model.responseBo.DepartmentInfosBo;
import com.lz.modules.job.model.responseBo.DepartmentStaffBo;
import com.lz.modules.third.entity.ThirdAppConfig;
import com.lz.modules.third.service.ThirdAppConfigService;
import com.lz.modules.third.service.impl.ThirdAppConfigServiceImpl;
import com.taobao.api.ApiException;
import org.apache.http.HttpEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.config.Registry;
import org.apache.http.config.RegistryBuilder;
import org.apache.http.conn.socket.ConnectionSocketFactory;
import org.apache.http.conn.socket.PlainConnectionSocketFactory;
import org.apache.http.conn.ssl.NoopHostnameVerifier;
import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
import org.apache.http.conn.ssl.TrustSelfSignedStrategy;
import org.apache.http.entity.mime.MultipartEntityBuilder;
import org.apache.http.entity.mime.content.FileBody;
import org.apache.http.impl.client.BasicCookieStore;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
import org.apache.http.ssl.SSLContextBuilder;
import org.apache.http.util.EntityUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.io.File;
import java.io.IOException;
import java.security.KeyManagementException;
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Component("dingtalkRobotUtil")
public class DingTalkUtil {
protected static Logger logger = LoggerFactory.getLogger(DingTalkUtil.class);
@Autowired
RedisUtils redisUtils;
@Autowired
ThirdAppConfigService thirdAppConfigService;
static String appid = "855818566";//"856016278";
CloseableHttpClient getHttpClient(){
return null;
}
public String SendImageByApacheHttpClient(File file, String authorization) throws IOException {
CloseableHttpClient client = getHttpClient();
HttpPost post = new HttpPost("https://open.feishu.cn/open-apis/image/v4/put/");
final MultipartEntityBuilder builder = MultipartEntityBuilder.create();
FileBody bin = new FileBody(file);
builder.addPart("image", bin);
builder.addTextBody("image_type", "message");
HttpEntity multiPartEntity = builder.build();
post.setEntity(multiPartEntity);
post.setHeader("Authorization", "Bearer " + authorization);
CloseableHttpResponse response = client.execute(post);
logger.info("http response code:" + response.getStatusLine().getStatusCode());
// for (Header header: response.getAllHeaders()) {
// System.out.println(header.toString());
// }
if (StringUtil.equals(response.getStatusLine().getStatusCode() + "", "99991663")) {
authorization = this.getAccessToken();
redisUtils.set(Constant.FEI_SHU_ROBOT_TOKEN, authorization);
SendImageByApacheHttpClient(file, authorization);
}
HttpEntity resEntity = response.getEntity();
if (resEntity == null) {
logger.info("never here?");
return "";
}
logger.info("Response content length: " + resEntity.getContentLength());
return EntityUtils.toString(resEntity);
}
/**
* 获取机器人的有效token值
*
* @return
* @throws IOException
*/
public String getAccessToken() {
try {
ThirdAppConfig thirdAppConfig = thirdAppConfigService.getByAppId(appid);
DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/gettoken");
OapiGettokenRequest req = new OapiGettokenRequest();
req.setAppkey(thirdAppConfig.getAppKey());
req.setAppsecret(thirdAppConfig.getAppSecret());
req.setHttpMethod("GET");
OapiGettokenResponse rsp = client.execute(req);
String resultStr = rsp.getBody();
JSONObject dataObj = JSON.parseObject(resultStr);
String tenant_access_token = dataObj.getString("access_token");
return tenant_access_token;
} catch (ApiException e) {
e.printStackTrace();
}
return null;
}
/**
* 批量获取部门详情
*
* @param accessToken
* @return
*/
public List<DepartmentInfosBo> getDepartmentDetails(String accessToken, String departmentIds) {
try {
//下面获取所有部门的i就按单信息
List<DepartmentInfosBo> list = new ArrayList<>();
DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/department/list");
OapiDepartmentListRequest req = new OapiDepartmentListRequest();
req.setFetchChild(true);
req.setId("1");
req.setHttpMethod("GET");
OapiDepartmentListResponse rsp = client.execute(req, accessToken);
JSONObject json = JSONObject.parseObject(rsp.getBody());
if(json.getInteger("errcode") == 0){
JSONArray array = json.getJSONArray("department");
for (int i = 0; i < array.size(); i++){
json = array.getJSONObject(i);
DepartmentInfosBo departmentInfosBo = new DepartmentInfosBo();
departmentInfosBo.setName(json.getString("name"));
departmentInfosBo.setId(json.getString("id"));//自身ID
departmentInfosBo.setParentId(json.getString("parentid"));//父级ID
//下面获取详细信息
client = new DefaultDingTalkClient("https://oapi.dingtalk.com/department/get");
OapiDepartmentGetRequest deReq = new OapiDepartmentGetRequest();
deReq.setId(departmentInfosBo.getId());
deReq.setHttpMethod("GET");
OapiDepartmentGetResponse deRsp = client.execute(deReq, accessToken);
json = JSONObject.parseObject(deRsp.getBody());
departmentInfosBo.setChatId(json.getString("deptGroupChatId"));
departmentInfosBo.setLeaderEmployeeId(json.getString("deptManagerUseridList"));//部门主管,多个主管以|隔开
departmentInfosBo.setStatus(1);
departmentInfosBo.setOrder(json.getInteger("order"));
list.add(departmentInfosBo);
}
}
return list;
} catch (ApiException e) {
logger.info("获取部门详情异常{}", e);
}
return null;
}
/**
* 获取部门用户详情
*
* @param accessToken
* @return
*/
public List<DepartmentStaffBo> getDepartmentStaffDetails(String accessToken, String departmentId) {
try {
List<DepartmentStaffBo> list =new ArrayList<>();
DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/user/listbypage");
OapiUserListbypageRequest req = new OapiUserListbypageRequest();
req.setDepartmentId(Long.parseLong(departmentId));
req.setSize(100L);
req.setHttpMethod("GET");
boolean isNext = true;
for(long page = 0; isNext; page++){
req.setOffset(page);
OapiUserListbypageResponse rsp = client.execute(req, accessToken);
JSONObject json = JSONObject.parseObject(rsp.getBody());
if(json.getInteger("errcode") == 0){
JSONArray array = json.getJSONArray("userlist");
isNext = json.getBoolean("hasMore");//获取是否由更多数据
for (int i = 0; i < array.size(); i++) {
json = array.getJSONObject(i);
DepartmentStaffBo departmentStaffBo = new DepartmentStaffBo();
departmentStaffBo.setEmployeeId(json.getString("userid"));//用户在企业内部的唯一编号创建时可指定可代表一定的含义
departmentStaffBo.setName(json.getString("name"));
departmentStaffBo.setEmployeeNo(json.getString("jobnumber"));//工号
departmentStaffBo.setUnionId(json.getString("unionid"));//企业内部id,唯一
departmentStaffBo.setOpenId(json.getString("openId"));//和上面的值目前是一样的未找到说明
departmentStaffBo.setMobile(json.getString("mobile"));//手机需要单独授权手机权限
departmentStaffBo.setEmail(json.getString("email"));//邮箱钉钉的企业邮箱才可以需要单独授权手机权限
departmentStaffBo.setAvatar(json.getString("avatar"));//头像
if(json.getBoolean("active")){
//在职已激活
departmentStaffBo.setStatus(0);
}else{
//在职未激活
departmentStaffBo.setStatus(4);
}
if(json.getBoolean("isLeader")){
departmentStaffBo.setIsLeader(1);
}else{
departmentStaffBo.setIsLeader(0);
}
list.add(departmentStaffBo);
}
}
}
return list;
} catch (ApiException e) {
e.printStackTrace();
}
return null;
}
/**
* 获取图片image_key
*
* @return
* @throws IOException
*/
public String getImageKey(File file, String tenant_access_token) throws IOException {
// File file = new File(imgUrl);
String result = SendImageByApacheHttpClient(file, tenant_access_token);
JSONObject dataObj = JSON.parseObject(result);
String image_key = dataObj.getJSONObject("data").getString("image_key");
return image_key;
}
/**
* 获取飞书用户唯一标识
*
* @param mobile
* @param accessToken
* @return
*/
public static String getUserId(String mobile, String accessToken) {
String urlStr = "https://open.feishu.cn/open-apis/user/v1/batch_get_id?mobiles=" + mobile;
String result = HttpUtil.feishuGet(urlStr, accessToken);
JSONObject dataObj = JSON.parseObject(result);
String userId = dataObj.getJSONObject("data").getJSONObject("mobile_users").getJSONArray(mobile).getJSONObject(0).getString("user_id");
return userId;
}
public static void main(String[] args) {
DingTalkUtil dingTalkUtil = new DingTalkUtil();
String token = dingTalkUtil.getAccessToken();
}
}

View File

@ -2,6 +2,7 @@ package com.lz.modules.app.dao;
import com.lz.modules.app.entity.DepartmentsStaffRelateEntity;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.lz.modules.app.entity.StaffEntity;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
@ -37,7 +38,7 @@ public interface DepartmentsStaffRelateDao extends BaseMapper<DepartmentsStaffRe
* @param staffId
* @return
*/
int updateByStaffId(@Param("departmentId") String departmentId, @Param("staffId") Long staffId);
int updateByStaffId(@Param("departmentId") String departmentId, @Param("staffId") StaffEntity staffId);
void deleteAllRelates();

View File

@ -48,4 +48,6 @@ public interface StaffDao extends BaseMapper<StaffEntity> {
List<StaffEntity> selectByName(@Param("name") String name);
List<StaffEntity> selectByIds(@Param("staffIds") List<Long> staffIds);
int addStaff(StaffEntity staff);
}

View File

@ -35,6 +35,10 @@ public class DepartmentsStaffRelateEntity implements Serializable {
private Long staffId;
//第几级部门
private Integer level;
/***
* 是否为部门领导
*/
private Integer isLeader;
/**
* 自增主键
* @return
@ -140,6 +144,18 @@ public class DepartmentsStaffRelateEntity implements Serializable {
this.level = level;
}
public static long getSerialVersionUID() {
return serialVersionUID;
}
public Integer getIsLeader() {
return isLeader;
}
public void setIsLeader(Integer isLeader) {
this.isLeader = isLeader;
}
@Override
public String toString() {
return "DepartmentsStaffRelate{" +

View File

@ -100,5 +100,17 @@ public class StaffEntity implements Serializable {
* 飞书用户的union_id
*/
private String unionId;
/***
* 是否为部门领导 0不是 1是
*/
private Integer isLeader;
/**
* 头像url
*/
private String avatar;
/**
* 工号
*/
private String jobNumber;
}

View File

@ -3,6 +3,7 @@ package com.lz.modules.app.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.lz.common.utils.PageUtils;
import com.lz.modules.app.entity.DepartmentsStaffRelateEntity;
import com.lz.modules.app.entity.StaffEntity;
import java.util.List;
import java.util.Map;
@ -21,7 +22,7 @@ public interface DepartmentsStaffRelateService extends IService<DepartmentsStaff
/**
* 根据部门ID和员工Ids创建部门和员工关系表
*/
void addRelateInfos(String departmentId, List<Long> staffIds);
void addRelateInfos(String departmentId, List<StaffEntity> staffIds);
void deleteAllRelates();

View File

@ -23,7 +23,7 @@ public interface StaffService extends IService<StaffEntity> {
PageUtils queryPage(Map<String, Object> params);
List<Long> updateStaffsInfo(List<DepartmentStaffBo> staffs);
List<StaffEntity> updateStaffsInfo(List<DepartmentStaffBo> staffs);
StaffEntity getStaffInfoByOpenId(String openId);

View File

@ -2,6 +2,7 @@ package com.lz.modules.app.service.impl;
import com.google.common.collect.Lists;
import com.lz.common.utils.StringUtil;
import com.lz.modules.app.entity.StaffEntity;
import org.springframework.stereotype.Service;
import java.util.List;
@ -36,14 +37,15 @@ public class DepartmentsStaffRelateServiceImpl extends ServiceImpl<DepartmentsSt
}
@Override
public void addRelateInfos(String departmentId, List<Long> staffIds) {
public void addRelateInfos(String departmentId, List<StaffEntity> staffIds) {
List<DepartmentsStaffRelateEntity> departStaffRelateList = Lists.newArrayList();
for (Long staffId : staffIds) {
String departId = departmentsStaffRelateDao.getRelateByStaffIdAndDepartmentId(staffId, departmentId);
for (StaffEntity staffId : staffIds) {
String departId = departmentsStaffRelateDao.getRelateByStaffIdAndDepartmentId(staffId.getId(), departmentId);
if (StringUtil.isEmpty(departId)) {
DepartmentsStaffRelateEntity departmentsStaffRelateBo = new DepartmentsStaffRelateEntity();
departmentsStaffRelateBo.setDepartmentId(departmentId);
departmentsStaffRelateBo.setStaffId(staffId);
departmentsStaffRelateBo.setStaffId(staffId.getId());
departmentsStaffRelateBo.setIsLeader(staffId.getIsLeader());
departStaffRelateList.add(departmentsStaffRelateBo);
} else if (!StringUtil.equals(departmentId, departId)) {
departmentsStaffRelateDao.updateByStaffId(departmentId, staffId);

View File

@ -56,27 +56,22 @@ public class StaffServiceImpl extends ServiceImpl<StaffDao, StaffEntity> impleme
}
@Override
public List<Long> updateStaffsInfo(List<DepartmentStaffBo> staffs) {
public List<StaffEntity> updateStaffsInfo(List<DepartmentStaffBo> staffs) {
try {
List<Long> staffIds = Lists.newArrayList();
List<StaffEntity> staffEntitys = Lists.newArrayList();
for (DepartmentStaffBo staffBo : staffs) {
StaffEntity staffEntity = staffDao.getStaffInfoByOpenId(staffBo.getOpenId());
StaffEntity staff = convertStaffEntity(staffBo);
if (staffEntity != null) {
staff.setId(staffEntity.getId());
staffDao.updateStaff(staff);
staffIds.add(staffEntity.getId());
} else {
staffEntitys.add(staff);
staffDao.addStaff(staff);
}
staffEntitys.add(staff);
}
if (staffEntitys.size() > 0) {
saveBatch(staffEntitys);//staffDao.addStaffBatch(staffEntitys);
}
for (StaffEntity staffEntity : staffEntitys) {
staffIds.add(staffEntity.getId());
}
return staffIds;
return staffEntitys;
} catch (Exception e) {
logger.info("updateDepartmentInfos error : " + e);
return null;
@ -303,6 +298,9 @@ public class StaffServiceImpl extends ServiceImpl<StaffDao, StaffEntity> impleme
staffEntity.setOpenId(staffBo.getOpenId());
staffEntity.setEmployeeId(staffBo.getEmployeeId());
staffEntity.setUnionId(staffBo.getUnionId());
staffEntity.setIsLeader(staffBo.getIsLeader());
staffEntity.setAvatar(staffBo.getAvatar());
staffEntity.setJobNumber(staffBo.getEmployeeNo());
return staffEntity;
}

View File

@ -1,8 +1,12 @@
package com.lz.modules.job.business;
import com.dingtalk.api.DefaultDingTalkClient;
import com.dingtalk.api.DingTalkClient;
import com.dingtalk.api.request.OapiGettokenRequest;
import com.dingtalk.api.response.OapiGettokenResponse;
import com.google.common.collect.Lists;
import com.lz.common.utils.DateUtils;
import com.lz.common.utils.FeishuUtil;
import com.lz.common.utils.DingTalkUtil;
import com.lz.modules.app.entity.StaffEntity;
import com.lz.modules.app.entity.StaffOccupationEntity;
import com.lz.modules.app.service.DepartmentsService;
@ -11,6 +15,7 @@ import com.lz.modules.app.service.StaffOccupationService;
import com.lz.modules.app.service.StaffService;
import com.lz.modules.job.model.responseBo.DepartmentInfosBo;
import com.lz.modules.job.model.responseBo.DepartmentStaffBo;
import com.taobao.api.ApiException;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@ -29,7 +34,7 @@ public class DingtalkBusiness {
protected final static org.slf4j.Logger logger = LoggerFactory.getLogger(DingtalkBusiness.class);
@Autowired
FeishuUtil feishuUtil;
DingTalkUtil dingTalkUtil;
@Resource
DepartmentsService departmentsService;
@ -47,52 +52,40 @@ public class DingtalkBusiness {
* 获取组织架构信息并录入到数据库
*/
// @DataSource(name = DataSourceNames.FOUR)
public void getFeishuDepartmentsIntoData() {
public void getDingTalkepartmentsIntoData() {
//获取Token
String token = feishuUtil.getAccessToken();
String token = dingTalkUtil.getAccessToken();
if(token != null && token.length() > 0){
//获取所有的部门详情
List<DepartmentInfosBo> departmentInfosBos = dingTalkUtil.getDepartmentDetails(token, "1");
//更新数据库中的部门相关信息
departmentsService.updateDepartmentInfos(departmentInfosBos);
//删除原有的对应关系下面在更新
departmentsStaffRelateService.deleteAllRelates();
//未在飞书组织架构里的成员置为离职(全部置为离职再把在职的恢复)
staffOccupationService.updateAllOccupation();
//获取飞书部门对应的用户详情
for (DepartmentInfosBo departmentInfo : departmentInfosBos) {
//获取部门用户详情
List<DepartmentStaffBo> staffs = dingTalkUtil.getDepartmentStaffDetails(token, departmentInfo.getId());
logger.info("=============================" + departmentInfo.getName() + "================================");
if(staffs.size() > 0){
//循环录入到员工信息表中
List<StaffEntity> staffIds = staffService.updateStaffsInfo(staffs);
//加入到部门和员工关系表同时更新leader关系
departmentsStaffRelateService.addRelateInfos(departmentInfo.getId(), staffIds);
//录入员工职业信息表
enterStaffOccupationInfos(staffs);
}
//获取通讯录授权范围获取最高级架构的department_id
List<String> departmentIds = feishuUtil.getDepartmentIds(token);
if (departmentIds == null || departmentIds.size() == 0) {
return;
}
//批量获取部门详情根据详情填充部门信息
StringBuffer departmentIdSbs = new StringBuffer();
for (String departmentId : departmentIds) {
//获取子孙部门id列表
departmentIdSbs.append("department_ids=" + departmentId + "&");
List<String> childDepartmentIds = feishuUtil.getChildDepartmentIds(token, departmentId);
for (String childDepartmentId : childDepartmentIds) {
departmentIdSbs.append("department_ids=" + childDepartmentId + "&");
}
}
String topDepartmentIds = departmentIdSbs.toString().substring(0, departmentIdSbs.toString().length() - 1);
//获取所有的部门详情
List<DepartmentInfosBo> departmentInfosBos = feishuUtil.getDepartmentDetails(token, topDepartmentIds);
//更新数据库中的部门相关信息
departmentsService.updateDepartmentInfos(departmentInfosBos);
departmentsStaffRelateService.deleteAllRelates();
//未在飞书组织架构里的成员置为离职(全部置为离职再把在职的恢复)
staffOccupationService.updateAllOccupation();
//获取飞书部门对应的用户详情
for (DepartmentInfosBo departmentInfo : departmentInfosBos) {
//获取部门用户详情
List<DepartmentStaffBo> staffs = feishuUtil.getDepartmentStaffDetails(token, departmentInfo.getId());
logger.info("=============================" + departmentInfo.getName() + "================================");
// for (DepartmentStaffBo staff : staffs)
// logger.info(staff.getName());
//循环录入到员工信息表中
List<Long> staffIds = staffService.updateStaffsInfo(staffs);
//加入到部门和员工关系表
departmentsStaffRelateService.addRelateInfos(departmentInfo.getId(), staffIds);
//录入员工职业信息表
enterStaffOccupationInfos(staffs);
}
}

View File

@ -85,7 +85,7 @@ public class FeishuBusiness {
// for (DepartmentStaffBo staff : staffs)
// logger.info(staff.getName());
//循环录入到员工信息表中
List<Long> staffIds = staffService.updateStaffsInfo(staffs);
List<StaffEntity> staffIds = staffService.updateStaffsInfo(staffs);
//加入到部门和员工关系表
departmentsStaffRelateService.addRelateInfos(departmentInfo.getId(), staffIds);

View File

@ -5,7 +5,7 @@ import lombok.Data;
import java.io.Serializable;
/**
* 飞书返回部门详情信息类
* 返回部门详情信息类
*
* @author fumeiai
* @email fumeiai@linzikg.com
@ -16,42 +16,42 @@ public class DepartmentInfosBo implements Serializable {
private static final long serialVersionUID = 1L;
/**
* 飞书部门群id
* 部门群id
*/
private String chatId;
/**
* 飞书部门id
* 部门id
*/
private String id;
/**
* 飞书部门负责人Id
* 部门负责人Id
*/
private String leaderEmployeeId;
/**
* 飞书部门负责人的openId
* 部门负责人的openId
*/
private String leaderOpenId;
/**
* 飞书部门负责人UnionId
* 部门负责人UnionId
*/
private String leaderUnionId;
/**
* 飞书部门人数
* 部门人数
*/
private Integer memberCount;
/**
* 飞书部门名称
* 部门名称
*/
private String name;
/**
* 飞书部门负责人Id
* 上级部门Id
*/
private String parentId;
@ -59,6 +59,10 @@ public class DepartmentInfosBo implements Serializable {
* 部门状态0 无效1 有效
*/
private Integer status;
/**
* 在父部门中的排序越小越靠前 钉钉才有
* */
private Integer order;
}

View File

@ -65,6 +65,18 @@ public class DepartmentStaffBo implements Serializable {
* 用户所在部门用户可能同时存在于多个部门
*/
private List departments;
/***
* 头像
*/
private String avatar;
/***
* 职称
*/
private String position;
/***
* 是否为领导
*/
private Integer isLeader;

View File

@ -34,7 +34,7 @@ public class DingtalkSynDataJob implements ITask {
public void run(String params) {
logger.info("dingtalkSynDataJob start date == {}", DateUtils.getCurrentDate());
dingtalkBusiness.getFeishuDepartmentsIntoData();
dingtalkBusiness.getDingTalkepartmentsIntoData();
logger.info("dingtalkSynDataJob end date == {}", DateUtils.getCurrentDate());
}

View File

@ -0,0 +1,74 @@
package com.lz.modules.third.controller;
import com.alibaba.fastjson.JSONObject;
import com.lz.common.utils.PageUtils;
import com.lz.common.utils.R;
import com.lz.common.utils.StringUtil;
import com.lz.modules.job.business.DingtalkBusiness;
import com.lz.modules.third.entity.ThirdAppConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.lz.modules.third.service.ThirdAppConfigService;
import java.util.HashMap;
import java.util.Map;
@RestController
@RequestMapping("/thirdAppConfig")
public class ThirdAppConfigController {
@Autowired
private ThirdAppConfigService thirdAppConfigservice;
@Autowired
private DingtalkBusiness dingtalkBusiness;
@RequestMapping("/list")
public R list(@RequestBody String body) {
Map<String,Object> params = new HashMap<>();
if(StringUtil.isNotBlank(body)){
params = JSONObject.parseObject(body,Map.class);
}
PageUtils page = thirdAppConfigservice.queryPage(params);
return R.ok().put("page", page);
}
@GetMapping("/syn")
public R syn() {
dingtalkBusiness.getDingTalkepartmentsIntoData();
return R.ok();
}
@RequestMapping("/getById")
public R getById(@RequestBody ThirdAppConfig thirdAppConfig) {
thirdAppConfig = thirdAppConfigservice.selectThirdAppConfigById(thirdAppConfig.getId());
return R.ok().put("thirdAppConfig",thirdAppConfig);
}
@RequestMapping("/update")
public R update(@RequestBody ThirdAppConfig thirdAppConfig) {
thirdAppConfigservice.updateThirdAppConfigById(thirdAppConfig);
return R.ok();
}
@RequestMapping("/save")
public R save(@RequestBody ThirdAppConfig thirdAppConfig) {
thirdAppConfigservice.insertThirdAppConfig(thirdAppConfig);
return R.ok();
}
@RequestMapping("/delete")
public R list(@RequestBody Long id) {
thirdAppConfigservice.deleteThirdAppConfigById(id);
return R.ok();
}
}

View File

@ -0,0 +1,34 @@
package com.lz.modules.third.dao;
/**
* <p>
* 第三方应用配置表 服务类
* </p>
*
* @author quyixiao
* @since 2020-08-17
*/
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.lz.modules.third.entity.ThirdAppConfig;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
@Mapper
public interface ThirdAppConfigMapper extends BaseMapper<ThirdAppConfig> {
ThirdAppConfig selectThirdAppConfigById(@Param("id")Long id);
Long insertThirdAppConfig(ThirdAppConfig thirdAppConfig);
int updateThirdAppConfigById(ThirdAppConfig thirdAppConfig);
int updateCoverThirdAppConfigById(ThirdAppConfig thirdAppConfig);
int deleteThirdAppConfigById(@Param("id")Long id);
ThirdAppConfig getByAppId(@Param("appid") String appid);
}

View File

@ -0,0 +1,222 @@
package com.lz.modules.third.entity;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import java.util.Date;
/**
* <p>
* 菜单权限表
* </p>*第三方应用配置表
* @author quyixiao
* @since 2020-08-17
*/
@Data
@TableName("third_app_config")
public class ThirdAppConfig implements java.io.Serializable {
//
@TableId(value = "id", type = IdType.AUTO)
private Long id;
//
private Integer isDelete;
//
private Date gmtCreate;
//
private Date gmtModified;
//AppId
private Long appId;
//AppKey
private String appKey;
//AppSecret
private String appSecret;
//在第三方中的应用名称
private String appName;
//第三方App类型0表示h5 1表示小程序
private Integer appType;
//第三方app名称钉钉微信
private String thirdAppName;
//程序入口如果有
private String appUrl;
/**
*
* @return
*/
public Long getId() {
return id;
}
/**
*
* @param id
*/
public void setId(Long id) {
this.id = id;
}
/**
*
* @return
*/
public Integer getIsDelete() {
return isDelete;
}
/**
*
* @param isDelete
*/
public void setIsDelete(Integer isDelete) {
this.isDelete = isDelete;
}
/**
*
* @return
*/
public Date getGmtCreate() {
return gmtCreate;
}
/**
*
* @param gmtCreate
*/
public void setGmtCreate(Date gmtCreate) {
this.gmtCreate = gmtCreate;
}
/**
*
* @return
*/
public Date getGmtModified() {
return gmtModified;
}
/**
*
* @param gmtModified
*/
public void setGmtModified(Date gmtModified) {
this.gmtModified = gmtModified;
}
/**
* AppId
* @return
*/
public Long getAppId() {
return appId;
}
/**
* AppId
* @param appId
*/
public void setAppId(Long appId) {
this.appId = appId;
}
/**
* AppKey
* @return
*/
public String getAppKey() {
return appKey;
}
/**
* AppKey
* @param appKey
*/
public void setAppKey(String appKey) {
this.appKey = appKey;
}
/**
* AppSecret
* @return
*/
public String getAppSecret() {
return appSecret;
}
/**
* AppSecret
* @param appSecret
*/
public void setAppSecret(String appSecret) {
this.appSecret = appSecret;
}
/**
* 在第三方中的应用名称
* @return
*/
public String getAppName() {
return appName;
}
/**
* 在第三方中的应用名称
* @param appName
*/
public void setAppName(String appName) {
this.appName = appName;
}
/**
* 第三方App类型0表示h5 1表示小程序
* @return
*/
public Integer getAppType() {
return appType;
}
/**
* 第三方App类型0表示h5 1表示小程序
* @param appType
*/
public void setAppType(Integer appType) {
this.appType = appType;
}
/**
* 第三方app名称钉钉微信
* @return
*/
public String getThirdAppName() {
return thirdAppName;
}
/**
* 第三方app名称钉钉微信
* @param thirdAppName
*/
public void setThirdAppName(String thirdAppName) {
this.thirdAppName = thirdAppName;
}
/**
* 程序入口如果有
* @return
*/
public String getAppUrl() {
return appUrl;
}
/**
* 程序入口如果有
* @param appUrl
*/
public void setAppUrl(String appUrl) {
this.appUrl = appUrl;
}
@Override
public String toString() {
return "ThirdAppConfig{" +
",id=" + id +
",isDelete=" + isDelete +
",gmtCreate=" + gmtCreate +
",gmtModified=" + gmtModified +
",appId=" + appId +
",appKey=" + appKey +
",appSecret=" + appSecret +
",appName=" + appName +
",appType=" + appType +
",thirdAppName=" + thirdAppName +
",appUrl=" + appUrl +
"}";
}
}

View File

@ -0,0 +1,223 @@
package com.lz.modules.third.entity;
import lombok.Data;
import java.util.Date;
/**
* <p>
* 菜单权限表
* </p>*第三方应用配置表
* @author quyixiao
* @since 2020-08-17
*/
@Data
public class ThirdAppConfigReq implements java.io.Serializable {
private int page = 1;
private int rows = 10;
private String sort;
private String order;
//
private Long id;
//
private Integer isDelete;
//
private Date gmtCreate;
//
private Date gmtModified;
//AppId
private Long appId;
//AppKey
private String appKey;
//AppSecret
private String appSecret;
//在第三方中的应用名称
private String appName;
//第三方App类型0表示h5 1表示小程序
private Integer appType;
//第三方app名称钉钉微信
private String thirdAppName;
//程序入口如果有
private String appUrl;
/**
*
* @return
*/
public Long getId() {
return id;
}
/**
*
* @param id
*/
public void setId(Long id) {
this.id = id;
}
/**
*
* @return
*/
public Integer getIsDelete() {
return isDelete;
}
/**
*
* @param isDelete
*/
public void setIsDelete(Integer isDelete) {
this.isDelete = isDelete;
}
/**
*
* @return
*/
public Date getGmtCreate() {
return gmtCreate;
}
/**
*
* @param gmtCreate
*/
public void setGmtCreate(Date gmtCreate) {
this.gmtCreate = gmtCreate;
}
/**
*
* @return
*/
public Date getGmtModified() {
return gmtModified;
}
/**
*
* @param gmtModified
*/
public void setGmtModified(Date gmtModified) {
this.gmtModified = gmtModified;
}
/**
* AppId
* @return
*/
public Long getAppId() {
return appId;
}
/**
* AppId
* @param appId
*/
public void setAppId(Long appId) {
this.appId = appId;
}
/**
* AppKey
* @return
*/
public String getAppKey() {
return appKey;
}
/**
* AppKey
* @param appKey
*/
public void setAppKey(String appKey) {
this.appKey = appKey;
}
/**
* AppSecret
* @return
*/
public String getAppSecret() {
return appSecret;
}
/**
* AppSecret
* @param appSecret
*/
public void setAppSecret(String appSecret) {
this.appSecret = appSecret;
}
/**
* 在第三方中的应用名称
* @return
*/
public String getAppName() {
return appName;
}
/**
* 在第三方中的应用名称
* @param appName
*/
public void setAppName(String appName) {
this.appName = appName;
}
/**
* 第三方App类型0表示h5 1表示小程序
* @return
*/
public Integer getAppType() {
return appType;
}
/**
* 第三方App类型0表示h5 1表示小程序
* @param appType
*/
public void setAppType(Integer appType) {
this.appType = appType;
}
/**
* 第三方app名称钉钉微信
* @return
*/
public String getThirdAppName() {
return thirdAppName;
}
/**
* 第三方app名称钉钉微信
* @param thirdAppName
*/
public void setThirdAppName(String thirdAppName) {
this.thirdAppName = thirdAppName;
}
/**
* 程序入口如果有
* @return
*/
public String getAppUrl() {
return appUrl;
}
/**
* 程序入口如果有
* @param appUrl
*/
public void setAppUrl(String appUrl) {
this.appUrl = appUrl;
}
@Override
public String toString() {
return "ThirdAppConfig{" +
",id=" + id +
",isDelete=" + isDelete +
",gmtCreate=" + gmtCreate +
",gmtModified=" + gmtModified +
",appId=" + appId +
",appKey=" + appKey +
",appSecret=" + appSecret +
",appName=" + appName +
",appType=" + appType +
",thirdAppName=" + thirdAppName +
",appUrl=" + appUrl +
"}";
}
}

View File

@ -0,0 +1,39 @@
package com.lz.modules.third.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.lz.common.utils.PageUtils;
import com.lz.modules.third.entity.ThirdAppConfig;
import java.util.Map;
/**
* <p>
* 第三方应用配置表 服务类
* </p>
*
* @author quyixiao
* @since 2020-08-17
*/
public interface ThirdAppConfigService extends IService<ThirdAppConfig> {
ThirdAppConfig selectThirdAppConfigById(Long id);
Long insertThirdAppConfig(ThirdAppConfig thirdAppConfig);
int updateThirdAppConfigById(ThirdAppConfig thirdAppConfig);
int updateCoverThirdAppConfigById(ThirdAppConfig thirdAppConfig);
int deleteThirdAppConfigById(Long id);
PageUtils queryPage(Map<String, Object> params);
ThirdAppConfig getByAppId(String appid);
}

View File

@ -0,0 +1,89 @@
package com.lz.modules.third.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lz.common.utils.PageUtils;
import com.lz.common.utils.Query;
import com.lz.modules.sys.entity.SysRoleEntity;
import com.lz.modules.third.dao.ThirdAppConfigMapper;
import com.lz.modules.third.entity.ThirdAppConfig;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Map;
/**
* <p>
* 第三方应用配置表 服务类
* </p>
*
* @author quyixiao
* @since 2020-08-17
*/
@Service
public class ThirdAppConfigServiceImpl extends ServiceImpl<ThirdAppConfigMapper, ThirdAppConfig> implements com.lz.modules.third.service.ThirdAppConfigService {
@Autowired
private ThirdAppConfigMapper thirdAppConfigMapper;
@Override
public ThirdAppConfig selectThirdAppConfigById(Long id){
return thirdAppConfigMapper.selectThirdAppConfigById(id);
}
@Override
public Long insertThirdAppConfig(ThirdAppConfig thirdAppConfig){
return thirdAppConfigMapper.insertThirdAppConfig(thirdAppConfig);
}
@Override
public int updateThirdAppConfigById(ThirdAppConfig thirdAppConfig){
return thirdAppConfigMapper.updateThirdAppConfigById(thirdAppConfig);
}
@Override
public int updateCoverThirdAppConfigById(ThirdAppConfig thirdAppConfig){
return thirdAppConfigMapper.updateCoverThirdAppConfigById(thirdAppConfig);
}
@Override
public int deleteThirdAppConfigById(Long id){
return thirdAppConfigMapper.deleteThirdAppConfigById(id);
}
@Override
public PageUtils queryPage(Map<String, Object> params){
String roleName = (String)params.get("app_name");
Long createUserId = (Long)params.get("app_key");
IPage<ThirdAppConfig> page = this.page(
new Query<ThirdAppConfig>().getPage(params),
new QueryWrapper<ThirdAppConfig>()
.like(StringUtils.isNotBlank(roleName),"app_name", roleName)
.eq(createUserId != null,"app_key", createUserId)
);
return new PageUtils(page);
}
@Override
public ThirdAppConfig getByAppId(String appid){
return thirdAppConfigMapper.getByAppId(appid);
}
}

View File

@ -12,6 +12,7 @@
<result property="departmentId" column="department_id"/>
<result property="staffId" column="staff_id"/>
<result column="level" property="level"/>
<result column="is_leader" property="isLeader"/>
</resultMap>
@ -38,7 +39,7 @@
<update id="updateByStaffId">
update lz_departments_staff_relate set is_delete=0 and update_time=now(), department_id=#{departmentId} where is_delete=0 and staff_id = #{staffId}
update lz_departments_staff_relate set is_delete=0, update_time=now(), department_id=#{departmentId}, is_leader=#{staffId.isLeader} where is_delete=0 and staff_id = #{staffId.id}
</update>
<select id="selectByDepartmentIds" resultType="com.lz.modules.app.entity.DepartmentsStaffRelateEntity">

View File

@ -25,6 +25,8 @@
<result property="openId" column="open_id"/>
<result property="employeeId" column="employee_id"/>
<result property="unionId" column="union_id"/>
<result property="avatar" column="avatar"/>
<result property="jobNumber" column="job_number"/>
</resultMap>
<select id="getStaffInfoByOpenId" resultType="com.lz.modules.app.entity.StaffEntity">
@ -80,15 +82,17 @@
<if test="unionId != null and unionId != '' ">
union_id = #{unionId,jdbcType=VARCHAR},
</if>
avatar = #{avatar},
job_number = #{jobNumber}
</set>
WHERE is_delete = 0 AND open_id = #{openId ,jdbcType=BIGINT}
</update>
<insert id="addStaffBatch">
INSERT INTO lz_staff(name,gender,mobile,email,open_id,employee_id,union_id)
INSERT INTO lz_staff(name,gender,mobile,email,open_id,employee_id,union_id,avatar,job_number)
VALUES
<foreach collection="staffs" item="staff" separator=",">
(#{staff.name},#{staff.gender},#{staff.mobile},#{staff.email},#{staff.openId},#{staff.employeeId},#{staff.unionId})
(#{staff.name},#{staff.gender},#{staff.mobile},#{staff.email},#{staff.openId},#{staff.employeeId},#{staff.unionId},#{staff.avatar},#{staff.jobNumber})
</foreach>
</insert>
@ -280,5 +284,11 @@
</foreach>
</select>
<insert id="addStaff">
INSERT INTO lz_staff(name,gender,mobile,email,open_id,employee_id,union_id,avatar,job_number)
VALUES
(#{name},#{gender},#{mobile},#{email},#{openId},#{employeeId},#{unionId},#{avatar},#{jobNumber})
</insert>
</mapper>

View File

@ -0,0 +1,107 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.lz.modules.third.dao.ThirdAppConfigMapper">
<!-- 通用查询映射结果 -->
<resultMap id="BaseResultMap" type="com.lz.modules.third.entity.ThirdAppConfig">
<id column="id" property="id"/>
<result column="is_delete" property="isDelete"/>
<result column="gmt_create" property="gmtCreate"/>
<result column="gmt_modified" property="gmtModified"/>
<result column="app_id" property="appId"/>
<result column="app_key" property="appKey"/>
<result column="app_secret" property="appSecret"/>
<result column="app_name" property="appName"/>
<result column="app_type" property="appType"/>
<result column="third_app_name" property="thirdAppName"/>
<result column="app_url" property="appUrl"/>
</resultMap>
<!-- 通用查询结果列 -->
<sql id="Base_Column_List">
id AS id, is_delete AS isDelete, gmt_create AS gmtCreate, gmt_modified AS gmtModified, app_id AS appId, app_key AS appKey, app_secret AS appSecret, app_name AS appName, app_type AS appType, third_app_name AS thirdAppName, app_url AS appUrl
</sql>
<select id="selectThirdAppConfigById" resultType="com.lz.modules.third.entity.ThirdAppConfig" >
select * from third_app_config where id=#{id} and is_delete = 0 limit 1
</select>
<insert id="insertThirdAppConfig" parameterType="com.lz.modules.third.entity.ThirdAppConfig" useGeneratedKeys="true" keyProperty="id" >
insert into third_app_config(
<if test="appId != null">app_id, </if>
<if test="appKey != null">app_key, </if>
<if test="appSecret != null">app_secret, </if>
<if test="appName != null">app_name, </if>
<if test="appType != null">app_type, </if>
<if test="thirdAppName != null">third_app_name, </if>
<if test="appUrl != null">app_url, </if>
is_delete,
gmt_create,
gmt_modified
)values(
<if test="appId != null">#{ appId}, </if>
<if test="appKey != null">#{ appKey}, </if>
<if test="appSecret != null">#{ appSecret}, </if>
<if test="appName != null">#{ appName}, </if>
<if test="appType != null">#{ appType}, </if>
<if test="thirdAppName != null">#{ thirdAppName}, </if>
<if test="appUrl != null">#{ appUrl}, </if>
0,
now(),
now()
)
</insert>
<update id="updateThirdAppConfigById" parameterType="com.lz.modules.third.entity.ThirdAppConfig" >
update
third_app_config
<trim prefix="set" suffixOverrides=",">
<if test="isDelete != null">is_delete = #{isDelete},</if>
<if test="gmtCreate != null">gmt_create = #{gmtCreate},</if>
<if test="appId != null">app_id = #{appId},</if>
<if test="appKey != null">app_key = #{appKey},</if>
<if test="appSecret != null">app_secret = #{appSecret},</if>
<if test="appName != null">app_name = #{appName},</if>
<if test="appType != null">app_type = #{appType},</if>
<if test="thirdAppName != null">third_app_name = #{thirdAppName},</if>
<if test="appUrl != null">app_url = #{appUrl}</if>
</trim>
,gmt_modified = now()
where id = #{id}
</update>
<update id="updateCoverThirdAppConfigById" parameterType="com.lz.modules.third.entity.ThirdAppConfig" >
update
third_app_config
set
is_delete = #{isDelete},
gmt_create = #{gmtCreate},
app_id = #{appId},
app_key = #{appKey},
app_secret = #{appSecret},
app_name = #{appName},
app_type = #{appType},
third_app_name = #{thirdAppName},
app_url = #{appUrl}
,gmt_modified = now()
where id = #{id}
</update>
<update id="deleteThirdAppConfigById" parameterType="java.lang.Long">
update third_app_config set is_delete = 1 where id=#{id} limit 1
</update>
<select id="getByAppId" resultType="com.lz.modules.third.entity.ThirdAppConfig" >
select * from third_app_config where app_id=#{appid} and is_delete = 0 limit 1
</select>
</mapper>

View File

@ -60,7 +60,7 @@ public class MysqlMain {
file.mkdirs();
}
List<TablesBean> list = new ArrayList<TablesBean>();
list.add(new TablesBean("lz_result_detail"));
list.add(new TablesBean("third_app_config"));
List<TablesBean> list2 = new ArrayList<TablesBean>();
Map<String, String> map = MysqlUtil2ShowCreateTable.getComments();