From c63f6cc9414b8a47a63e856153ee3a973e9a80ac Mon Sep 17 00:00:00 2001 From: wulin Date: Tue, 18 Aug 2020 17:44:48 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=B5=8B=E8=AF=95=E4=B8=AD?= =?UTF-8?q?=E5=8F=91=E7=8E=B0=E7=9A=84=E9=92=89=E9=92=89=E5=90=8C=E6=AD=A5?= =?UTF-8?q?bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/lz/common/utils/DingTalkUtil.java | 41 ++------- .../java/com/lz/modules/app/dao/StaffDao.java | 2 + .../modules/app/dao/StaffOccupationDao.java | 2 + .../app/service/StaffOccupationService.java | 3 + .../impl/StaffOccupationServiceImpl.java | 5 ++ .../job/business/DingtalkBusiness.java | 88 ++++++++++++------- .../modules/job/task/DingtalkSynDataJob.java | 4 +- .../controller/ThirdAppConfigController.java | 9 +- .../resources/mapper/generator/StaffDao.xml | 22 +++-- .../mapper/generator/StaffOccupationDao.xml | 4 + 10 files changed, 105 insertions(+), 75 deletions(-) diff --git a/src/main/java/com/lz/common/utils/DingTalkUtil.java b/src/main/java/com/lz/common/utils/DingTalkUtil.java index ff666b78..8892ac5f 100644 --- a/src/main/java/com/lz/common/utils/DingTalkUtil.java +++ b/src/main/java/com/lz/common/utils/DingTalkUtil.java @@ -56,41 +56,13 @@ public class DingTalkUtil { @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值 @@ -98,7 +70,7 @@ public class DingTalkUtil { * @return * @throws IOException */ - public String getAccessToken() { + public String getAccessToken(String appid) { try { ThirdAppConfig thirdAppConfig = thirdAppConfigService.getByAppId(appid); @@ -160,6 +132,8 @@ public class DingTalkUtil { list.add(departmentInfosBo); } + }else{ + logger.info("获取部门详情异常{}", rsp.getBody()); } return list; } catch (ApiException e) { @@ -204,6 +178,7 @@ public class DingTalkUtil { departmentStaffBo.setMobile(json.getString("mobile"));//手机,需要单独授权手机权限 departmentStaffBo.setEmail(json.getString("email"));//邮箱,钉钉的企业邮箱才可以,需要单独授权手机权限 departmentStaffBo.setAvatar(json.getString("avatar"));//头像 + departmentStaffBo.setPosition(json.getString("position")); if(json.getBoolean("active")){ //在职已激活 departmentStaffBo.setStatus(0); @@ -221,6 +196,8 @@ public class DingTalkUtil { } + }else{ + logger.info("获取部门详情异常{}", rsp.getBody()); } } @@ -240,7 +217,7 @@ public class DingTalkUtil { */ public String getImageKey(File file, String tenant_access_token) throws IOException { // File file = new File(imgUrl); - String result = SendImageByApacheHttpClient(file, tenant_access_token); + String result = "";//SendImageByApacheHttpClient(file, tenant_access_token); JSONObject dataObj = JSON.parseObject(result); String image_key = dataObj.getJSONObject("data").getString("image_key"); return image_key; @@ -264,7 +241,7 @@ public class DingTalkUtil { public static void main(String[] args) { DingTalkUtil dingTalkUtil = new DingTalkUtil(); - String token = dingTalkUtil.getAccessToken(); + String token = dingTalkUtil.getAccessToken("855818566"); } diff --git a/src/main/java/com/lz/modules/app/dao/StaffDao.java b/src/main/java/com/lz/modules/app/dao/StaffDao.java index 54e5d84c..210ec6ca 100644 --- a/src/main/java/com/lz/modules/app/dao/StaffDao.java +++ b/src/main/java/com/lz/modules/app/dao/StaffDao.java @@ -50,4 +50,6 @@ public interface StaffDao extends BaseMapper { List selectByIds(@Param("staffIds") List staffIds); int addStaff(StaffEntity staff); + + List selectByRang(@Param("id") String id); } diff --git a/src/main/java/com/lz/modules/app/dao/StaffOccupationDao.java b/src/main/java/com/lz/modules/app/dao/StaffOccupationDao.java index 7dc52fa5..34f217a3 100644 --- a/src/main/java/com/lz/modules/app/dao/StaffOccupationDao.java +++ b/src/main/java/com/lz/modules/app/dao/StaffOccupationDao.java @@ -3,6 +3,7 @@ package com.lz.modules.app.dao; import com.lz.modules.app.dto.StaffOccupationInfoDto; import com.lz.modules.app.entity.StaffOccupationEntity; import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.lz.modules.job.model.responseBo.DepartmentStaffBo; import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Param; @@ -29,4 +30,5 @@ public interface StaffOccupationDao extends BaseMapper { void updateAllOccupation(); + void updateStatusByStaff(Long staffId, DepartmentStaffBo departmentStaffBo); } diff --git a/src/main/java/com/lz/modules/app/service/StaffOccupationService.java b/src/main/java/com/lz/modules/app/service/StaffOccupationService.java index 55a3761e..b1a63333 100644 --- a/src/main/java/com/lz/modules/app/service/StaffOccupationService.java +++ b/src/main/java/com/lz/modules/app/service/StaffOccupationService.java @@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.extension.service.IService; import com.lz.common.utils.PageUtils; import com.lz.modules.app.dto.StaffOccupationInfoDto; import com.lz.modules.app.entity.StaffOccupationEntity; +import com.lz.modules.job.model.responseBo.DepartmentStaffBo; import java.util.List; import java.util.Map; @@ -28,5 +29,7 @@ public interface StaffOccupationService extends IService StaffOccupationInfoDto getOccupationByStaffId(Long id); void updateAllOccupation(); + + void updateStatusByStaff(Long staffId, DepartmentStaffBo departmentStaffBo); } diff --git a/src/main/java/com/lz/modules/app/service/impl/StaffOccupationServiceImpl.java b/src/main/java/com/lz/modules/app/service/impl/StaffOccupationServiceImpl.java index bea236fd..112f331b 100644 --- a/src/main/java/com/lz/modules/app/service/impl/StaffOccupationServiceImpl.java +++ b/src/main/java/com/lz/modules/app/service/impl/StaffOccupationServiceImpl.java @@ -9,6 +9,7 @@ import com.lz.modules.app.dto.StaffOccupationInfoDto; import com.lz.modules.app.dao.StaffOccupationDao; import com.lz.modules.app.entity.StaffOccupationEntity; import com.lz.modules.app.service.StaffOccupationService; +import com.lz.modules.job.model.responseBo.DepartmentStaffBo; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -56,5 +57,9 @@ public class StaffOccupationServiceImpl extends ServiceImpl staffEntityList = staffDao.selectByRang("535");//飞书数据更新为钉钉数据 + for (StaffEntity staff:staffEntityList + ) { + List list = staffDao.selectByName(staff.getName()); + if(list.size() > 0){ + StaffEntity staff1 = list.get(0); + if(staff.getId().intValue() != staff1.getId().intValue()){ + staff1.setJobNumber(staff.getJobNumber()); + staff1.setAvatar(staff.getAvatar()); + staff1.setEmployeeId(staff.getEmployeeId()); + staff1.setOpenId(staff.getOpenId()); + staff1.setUnionId(staff.getUnionId()); + + + staffDao.deleteById(staff.getId()); + staffDao.updateStaff(staff1); + } + + } + + + } + return;*/ //获取Token - String token = dingTalkUtil.getAccessToken(); + String token = dingTalkUtil.getAccessToken(appid); 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); + if(departmentInfosBos.size() > 0){ + //更新数据库中的部门相关信息 + 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); + //加入到部门和员工关系表,同时更新leader关系 + departmentsStaffRelateService.addRelateInfos(departmentInfo.getId(), staffIds); + //录入员工职业信息表 + enterStaffOccupationInfos(staffs); + } } - - - - + }else{ + logger.info("部门信息为空"); } } - - } public void enterStaffOccupationInfos(List staffs) { @@ -98,19 +126,19 @@ public class DingtalkBusiness { if (staffOccupationEntity == null) { StaffOccupationEntity staffOccupation = new StaffOccupationEntity(); staffOccupation.setStaffId(staffId); + staffOccupation.setPosition(departmentStaffBo.getPosition());//职位信息 staffOccupation.setEmployeeNo(departmentStaffBo.getEmployeeNo()); + staffOccupation.setStaffNo(departmentStaffBo.getEmployeeNo());//钉钉的员工工号 staffOccupation.setStaffType(departmentStaffBo.getEmployeeType()); staffOccupation.setStaffStatus(departmentStaffBo.getStatus()); staffOccupation.setEntryTime(DateUtils.getCurrentDate()); StaffOccupations.add(staffOccupation); } else { - staffOccupationService.updateStatusByStaffId(staffId, departmentStaffBo.getStatus()); + staffOccupationService.updateStatusByStaff(staffId, departmentStaffBo);//更新职位信息,工号信息 } } if (StaffOccupations.size() > 0) { staffOccupationService.saveBatch(StaffOccupations); } } - - } 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 d1cb73bb..2b8a7291 100644 --- a/src/main/java/com/lz/modules/job/task/DingtalkSynDataJob.java +++ b/src/main/java/com/lz/modules/job/task/DingtalkSynDataJob.java @@ -29,12 +29,12 @@ public class DingtalkSynDataJob implements ITask { @Autowired DingtalkBusiness dingtalkBusiness; - + static String appid = "855818566"; @Override public void run(String params) { logger.info("dingtalkSynDataJob start date == {}", DateUtils.getCurrentDate()); - dingtalkBusiness.getDingTalkepartmentsIntoData(); + dingtalkBusiness.getDingTalkepartmentsIntoData(appid); 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 index dd97ae7d..02ee792c 100644 --- a/src/main/java/com/lz/modules/third/controller/ThirdAppConfigController.java +++ b/src/main/java/com/lz/modules/third/controller/ThirdAppConfigController.java @@ -8,10 +8,7 @@ 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 org.springframework.web.bind.annotation.*; import com.lz.modules.third.service.ThirdAppConfigService; import java.util.HashMap; import java.util.Map; @@ -39,8 +36,8 @@ public class ThirdAppConfigController { } @GetMapping("/syn") - public R syn() { - dingtalkBusiness.getDingTalkepartmentsIntoData(); + public R syn(@RequestParam String appid) { + dingtalkBusiness.getDingTalkepartmentsIntoData(appid); return R.ok(); } diff --git a/src/main/resources/mapper/generator/StaffDao.xml b/src/main/resources/mapper/generator/StaffDao.xml index fa76f05f..9765330c 100644 --- a/src/main/resources/mapper/generator/StaffDao.xml +++ b/src/main/resources/mapper/generator/StaffDao.xml @@ -44,7 +44,7 @@ gender = #{gender,jdbcType=INTEGER}, - birthday = #{birthday,jdbcType=VARCHAR}, + birthday = #{birthday,jdbcType=DATETIME}, marital_status = #{maritalStatus,jdbcType=INTEGER}, @@ -82,10 +82,18 @@ union_id = #{unionId,jdbcType=VARCHAR}, - avatar = #{avatar}, - job_number = #{jobNumber} + + open_id = #{openId,jdbcType=VARCHAR}, + + + job_number = #{jobNumber,jdbcType=VARCHAR}, + + + avatar = #{avatar,jdbcType=VARCHAR} + + - WHERE is_delete = 0 AND open_id = #{openId ,jdbcType=BIGINT} + WHERE is_delete = 0 AND id = #{id ,jdbcType=BIGINT} @@ -284,11 +292,15 @@ - + 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/generator/StaffOccupationDao.xml b/src/main/resources/mapper/generator/StaffOccupationDao.xml index 7ffd0ce0..3a10f499 100644 --- a/src/main/resources/mapper/generator/StaffOccupationDao.xml +++ b/src/main/resources/mapper/generator/StaffOccupationDao.xml @@ -55,4 +55,8 @@ + + update lz_staff_occupation set staff_status=1,resignation_time=null, position=#{departmentStaffBo.position}, staff_no=#{departmentStaffBo.employeeNo} where is_delete=0 and staff_id = #{staffId} + +