diff --git a/src/main/java/com/lz/common/utils/DingTalkUtil.java b/src/main/java/com/lz/common/utils/DingTalkUtil.java new file mode 100644 index 00000000..ff666b78 --- /dev/null +++ b/src/main/java/com/lz/common/utils/DingTalkUtil.java @@ -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 getDepartmentDetails(String accessToken, String departmentIds) { + try { + //下面获取所有部门的i就按单信息 + List 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 getDepartmentStaffDetails(String accessToken, String departmentId) { + try { + List 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(); + } + + + +} diff --git a/src/main/java/com/lz/modules/app/dao/DepartmentsStaffRelateDao.java b/src/main/java/com/lz/modules/app/dao/DepartmentsStaffRelateDao.java index 7535fca9..20d0b7f1 100644 --- a/src/main/java/com/lz/modules/app/dao/DepartmentsStaffRelateDao.java +++ b/src/main/java/com/lz/modules/app/dao/DepartmentsStaffRelateDao.java @@ -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 { List selectByName(@Param("name") String name); List selectByIds(@Param("staffIds") List staffIds); + + int addStaff(StaffEntity staff); } diff --git a/src/main/java/com/lz/modules/app/entity/DepartmentsStaffRelateEntity.java b/src/main/java/com/lz/modules/app/entity/DepartmentsStaffRelateEntity.java index a21a313f..edc90a6d 100644 --- a/src/main/java/com/lz/modules/app/entity/DepartmentsStaffRelateEntity.java +++ b/src/main/java/com/lz/modules/app/entity/DepartmentsStaffRelateEntity.java @@ -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{" + diff --git a/src/main/java/com/lz/modules/app/entity/StaffEntity.java b/src/main/java/com/lz/modules/app/entity/StaffEntity.java index 69c26ecb..2615ad59 100644 --- a/src/main/java/com/lz/modules/app/entity/StaffEntity.java +++ b/src/main/java/com/lz/modules/app/entity/StaffEntity.java @@ -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; } diff --git a/src/main/java/com/lz/modules/app/service/DepartmentsStaffRelateService.java b/src/main/java/com/lz/modules/app/service/DepartmentsStaffRelateService.java index 5ebaab75..f6830fc5 100644 --- a/src/main/java/com/lz/modules/app/service/DepartmentsStaffRelateService.java +++ b/src/main/java/com/lz/modules/app/service/DepartmentsStaffRelateService.java @@ -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 staffIds); + void addRelateInfos(String departmentId, List staffIds); void deleteAllRelates(); diff --git a/src/main/java/com/lz/modules/app/service/StaffService.java b/src/main/java/com/lz/modules/app/service/StaffService.java index b67191d7..d47bae2a 100644 --- a/src/main/java/com/lz/modules/app/service/StaffService.java +++ b/src/main/java/com/lz/modules/app/service/StaffService.java @@ -23,7 +23,7 @@ public interface StaffService extends IService { PageUtils queryPage(Map params); - List updateStaffsInfo(List staffs); + List updateStaffsInfo(List staffs); StaffEntity getStaffInfoByOpenId(String openId); diff --git a/src/main/java/com/lz/modules/app/service/impl/DepartmentsStaffRelateServiceImpl.java b/src/main/java/com/lz/modules/app/service/impl/DepartmentsStaffRelateServiceImpl.java index 7e133c05..bf13d743 100644 --- a/src/main/java/com/lz/modules/app/service/impl/DepartmentsStaffRelateServiceImpl.java +++ b/src/main/java/com/lz/modules/app/service/impl/DepartmentsStaffRelateServiceImpl.java @@ -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 staffIds) { + public void addRelateInfos(String departmentId, List staffIds) { List 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); diff --git a/src/main/java/com/lz/modules/app/service/impl/StaffServiceImpl.java b/src/main/java/com/lz/modules/app/service/impl/StaffServiceImpl.java index e2004424..d2d1a023 100644 --- a/src/main/java/com/lz/modules/app/service/impl/StaffServiceImpl.java +++ b/src/main/java/com/lz/modules/app/service/impl/StaffServiceImpl.java @@ -56,27 +56,22 @@ public class StaffServiceImpl extends ServiceImpl impleme } @Override - public List updateStaffsInfo(List staffs) { + public List updateStaffsInfo(List staffs) { try { - List staffIds = Lists.newArrayList(); List 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 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; } diff --git a/src/main/java/com/lz/modules/job/business/DingtalkBusiness.java b/src/main/java/com/lz/modules/job/business/DingtalkBusiness.java index 3ac68039..abf74379 100644 --- a/src/main/java/com/lz/modules/job/business/DingtalkBusiness.java +++ b/src/main/java/com/lz/modules/job/business/DingtalkBusiness.java @@ -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 departmentInfosBos = dingTalkUtil.getDepartmentDetails(token, "1"); + //更新数据库中的部门相关信息 + departmentsService.updateDepartmentInfos(departmentInfosBos); + //删除原有的对应关系下面在更新 + departmentsStaffRelateService.deleteAllRelates(); + //未在飞书组织架构里的成员,置为离职(全部置为离职,再把在职的恢复) + staffOccupationService.updateAllOccupation(); + //获取飞书部门对应的用户详情 + for (DepartmentInfosBo departmentInfo : departmentInfosBos) { + //获取部门用户详情 + List staffs = dingTalkUtil.getDepartmentStaffDetails(token, departmentInfo.getId()); + logger.info("=============================" + departmentInfo.getName() + "================================"); + if(staffs.size() > 0){ + //循环录入到员工信息表中 + List staffIds = staffService.updateStaffsInfo(staffs); + + //加入到部门和员工关系表,同时更新leader关系 + departmentsStaffRelateService.addRelateInfos(departmentInfo.getId(), staffIds); + //录入员工职业信息表 + enterStaffOccupationInfos(staffs); + } + - //获取通讯录授权范围:获取最高级架构的department_id - List 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 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 departmentInfosBos = feishuUtil.getDepartmentDetails(token, topDepartmentIds); - //更新数据库中的部门相关信息 - departmentsService.updateDepartmentInfos(departmentInfosBos); - departmentsStaffRelateService.deleteAllRelates(); - //未在飞书组织架构里的成员,置为离职(全部置为离职,再把在职的恢复) - staffOccupationService.updateAllOccupation(); - //获取飞书部门对应的用户详情 - for (DepartmentInfosBo departmentInfo : departmentInfosBos) { - //获取部门用户详情 - List staffs = feishuUtil.getDepartmentStaffDetails(token, departmentInfo.getId()); - logger.info("=============================" + departmentInfo.getName() + "================================"); -// for (DepartmentStaffBo staff : staffs) -// logger.info(staff.getName()); - //循环录入到员工信息表中 - List staffIds = staffService.updateStaffsInfo(staffs); - - //加入到部门和员工关系表 - departmentsStaffRelateService.addRelateInfos(departmentInfo.getId(), staffIds); - //录入员工职业信息表 - enterStaffOccupationInfos(staffs); - - } } diff --git a/src/main/java/com/lz/modules/job/business/FeishuBusiness.java b/src/main/java/com/lz/modules/job/business/FeishuBusiness.java index 55c7e1f1..33c7a2fb 100644 --- a/src/main/java/com/lz/modules/job/business/FeishuBusiness.java +++ b/src/main/java/com/lz/modules/job/business/FeishuBusiness.java @@ -85,7 +85,7 @@ public class FeishuBusiness { // for (DepartmentStaffBo staff : staffs) // logger.info(staff.getName()); //循环录入到员工信息表中 - List staffIds = staffService.updateStaffsInfo(staffs); + List staffIds = staffService.updateStaffsInfo(staffs); //加入到部门和员工关系表 departmentsStaffRelateService.addRelateInfos(departmentInfo.getId(), staffIds); diff --git a/src/main/java/com/lz/modules/job/model/responseBo/DepartmentInfosBo.java b/src/main/java/com/lz/modules/job/model/responseBo/DepartmentInfosBo.java index 3800d039..3d8521b6 100644 --- a/src/main/java/com/lz/modules/job/model/responseBo/DepartmentInfosBo.java +++ b/src/main/java/com/lz/modules/job/model/responseBo/DepartmentInfosBo.java @@ -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; } diff --git a/src/main/java/com/lz/modules/job/model/responseBo/DepartmentStaffBo.java b/src/main/java/com/lz/modules/job/model/responseBo/DepartmentStaffBo.java index 75a29444..e308cf1e 100644 --- a/src/main/java/com/lz/modules/job/model/responseBo/DepartmentStaffBo.java +++ b/src/main/java/com/lz/modules/job/model/responseBo/DepartmentStaffBo.java @@ -65,6 +65,18 @@ public class DepartmentStaffBo implements Serializable { * 用户所在部门,用户可能同时存在于多个部门 */ private List departments; + /*** + * 头像 + */ + private String avatar; + /*** + * 职称 + */ + private String position; + /*** + * 是否为领导 + */ + private Integer isLeader; diff --git a/src/main/java/com/lz/modules/job/task/DingtalkSynDataJob.java b/src/main/java/com/lz/modules/job/task/DingtalkSynDataJob.java index c92bd1c3..d1cb73bb 100644 --- a/src/main/java/com/lz/modules/job/task/DingtalkSynDataJob.java +++ b/src/main/java/com/lz/modules/job/task/DingtalkSynDataJob.java @@ -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()); } diff --git a/src/main/java/com/lz/modules/third/controller/ThirdAppConfigController.java b/src/main/java/com/lz/modules/third/controller/ThirdAppConfigController.java new file mode 100644 index 00000000..dd97ae7d --- /dev/null +++ b/src/main/java/com/lz/modules/third/controller/ThirdAppConfigController.java @@ -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 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(); + } +} diff --git a/src/main/java/com/lz/modules/third/dao/ThirdAppConfigMapper.java b/src/main/java/com/lz/modules/third/dao/ThirdAppConfigMapper.java new file mode 100644 index 00000000..ccea0910 --- /dev/null +++ b/src/main/java/com/lz/modules/third/dao/ThirdAppConfigMapper.java @@ -0,0 +1,34 @@ +package com.lz.modules.third.dao; +/** +*

+* 第三方应用配置表 服务类 +*

+* +* @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 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); +} \ No newline at end of file diff --git a/src/main/java/com/lz/modules/third/entity/ThirdAppConfig.java b/src/main/java/com/lz/modules/third/entity/ThirdAppConfig.java new file mode 100644 index 00000000..73eae622 --- /dev/null +++ b/src/main/java/com/lz/modules/third/entity/ThirdAppConfig.java @@ -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; +/** +*

+* 菜单权限表 +*

*第三方应用配置表 +* @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 + + "}"; + } +} \ No newline at end of file diff --git a/src/main/java/com/lz/modules/third/entity/ThirdAppConfigReq.java b/src/main/java/com/lz/modules/third/entity/ThirdAppConfigReq.java new file mode 100644 index 00000000..f0ae0831 --- /dev/null +++ b/src/main/java/com/lz/modules/third/entity/ThirdAppConfigReq.java @@ -0,0 +1,223 @@ +package com.lz.modules.third.entity; +import lombok.Data; +import java.util.Date; +/** +*

+* 菜单权限表 +*

*第三方应用配置表 +* @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 + + "}"; + } +} \ No newline at end of file diff --git a/src/main/java/com/lz/modules/third/service/ThirdAppConfigService.java b/src/main/java/com/lz/modules/third/service/ThirdAppConfigService.java new file mode 100644 index 00000000..957760b7 --- /dev/null +++ b/src/main/java/com/lz/modules/third/service/ThirdAppConfigService.java @@ -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; + +/** +*

+* 第三方应用配置表 服务类 +*

+* +* @author quyixiao +* @since 2020-08-17 +*/ +public interface ThirdAppConfigService extends IService { + + + + ThirdAppConfig selectThirdAppConfigById(Long id); + + + Long insertThirdAppConfig(ThirdAppConfig thirdAppConfig); + + + int updateThirdAppConfigById(ThirdAppConfig thirdAppConfig); + + + int updateCoverThirdAppConfigById(ThirdAppConfig thirdAppConfig); + + + int deleteThirdAppConfigById(Long id); + + + PageUtils queryPage(Map params); + + ThirdAppConfig getByAppId(String appid); +} \ No newline at end of file diff --git a/src/main/java/com/lz/modules/third/service/impl/ThirdAppConfigServiceImpl.java b/src/main/java/com/lz/modules/third/service/impl/ThirdAppConfigServiceImpl.java new file mode 100644 index 00000000..304b54f0 --- /dev/null +++ b/src/main/java/com/lz/modules/third/service/impl/ThirdAppConfigServiceImpl.java @@ -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; + +/** +*

+* 第三方应用配置表 服务类 +*

+* +* @author quyixiao +* @since 2020-08-17 +*/ + +@Service +public class ThirdAppConfigServiceImpl extends ServiceImpl 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 params){ + String roleName = (String)params.get("app_name"); + Long createUserId = (Long)params.get("app_key"); + + IPage page = this.page( + new Query().getPage(params), + new QueryWrapper() + .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); + } + +} diff --git a/src/main/resources/mapper/generator/DepartmentsStaffRelateDao.xml b/src/main/resources/mapper/generator/DepartmentsStaffRelateDao.xml index 92ac5d7a..66caff3f 100644 --- a/src/main/resources/mapper/generator/DepartmentsStaffRelateDao.xml +++ b/src/main/resources/mapper/generator/DepartmentsStaffRelateDao.xml @@ -12,6 +12,7 @@ + @@ -38,7 +39,7 @@ - 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} @@ -80,15 +82,17 @@ union_id = #{unionId,jdbcType=VARCHAR}, + avatar = #{avatar}, + job_number = #{jobNumber} WHERE is_delete = 0 AND open_id = #{openId ,jdbcType=BIGINT} - 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 - (#{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}) @@ -280,5 +284,11 @@ + + 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}) + + diff --git a/src/main/resources/mapper/third/ThirdAppConfigMapper.xml b/src/main/resources/mapper/third/ThirdAppConfigMapper.xml new file mode 100644 index 00000000..eae4b9fd --- /dev/null +++ b/src/main/resources/mapper/third/ThirdAppConfigMapper.xml @@ -0,0 +1,107 @@ + + + + + + + + + + + + + + + + + + + + + + + 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 + + + + + + + + + + insert into third_app_config( + app_id, + app_key, + app_secret, + app_name, + app_type, + third_app_name, + app_url, + is_delete, + gmt_create, + gmt_modified + )values( + #{ appId}, + #{ appKey}, + #{ appSecret}, + #{ appName}, + #{ appType}, + #{ thirdAppName}, + #{ appUrl}, + 0, + now(), + now() + ) + + + + + update + third_app_config + + 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 + 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 third_app_config set is_delete = 1 where id=#{id} limit 1 + + + + + + diff --git a/src/test/java/com/lz/mysql/MysqlMain.java b/src/test/java/com/lz/mysql/MysqlMain.java index a45a5aa3..ce1783ae 100644 --- a/src/test/java/com/lz/mysql/MysqlMain.java +++ b/src/test/java/com/lz/mysql/MysqlMain.java @@ -60,7 +60,7 @@ public class MysqlMain { file.mkdirs(); } List list = new ArrayList(); - list.add(new TablesBean("lz_result_detail")); + list.add(new TablesBean("third_app_config")); List list2 = new ArrayList(); Map map = MysqlUtil2ShowCreateTable.getComments();