提交修改

This commit is contained in:
quyixiao 2020-08-18 18:31:37 +08:00
commit aabb29d943
10 changed files with 106 additions and 75 deletions

View File

@ -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");
}

View File

@ -68,5 +68,9 @@ public interface StaffDao extends BaseMapper<StaffEntity> {
int addStaff(StaffEntity staff);
List<StaffEntity> selectByRang(@Param("id") String id);
StaffEntity selectByPhone(@Param("phone") String phone);
}

View File

@ -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<StaffOccupationEntity> {
void updateAllOccupation();
void updateStatusByStaff(Long staffId, DepartmentStaffBo departmentStaffBo);
}

View File

@ -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<StaffOccupationEntity>
StaffOccupationInfoDto getOccupationByStaffId(Long id);
void updateAllOccupation();
void updateStatusByStaff(Long staffId, DepartmentStaffBo departmentStaffBo);
}

View File

@ -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<StaffOccupationDao,
public void updateAllOccupation() {
staffOccupationDao.updateAllOccupation();
}
@Override
public void updateStatusByStaff(Long staffId, DepartmentStaffBo departmentStaffBo){
staffOccupationDao.updateStatusByStaff(staffId, departmentStaffBo);
}
}

View File

@ -7,6 +7,7 @@ import com.dingtalk.api.response.OapiGettokenResponse;
import com.google.common.collect.Lists;
import com.lz.common.utils.DateUtils;
import com.lz.common.utils.DingTalkUtil;
import com.lz.modules.app.dao.StaffDao;
import com.lz.modules.app.entity.StaffEntity;
import com.lz.modules.app.entity.StaffOccupationEntity;
import com.lz.modules.app.service.DepartmentsService;
@ -15,6 +16,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.mchange.lang.IntegerUtils;
import com.taobao.api.ApiException;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
@ -26,7 +28,7 @@ import java.util.List;
/**
* @author fumeiai
* @date 2019-05-29 17:06
* @Description 钉钉业务
* @Description 钉钉同步业务
* @注意 本内容仅限于杭州霖梓网络科技有限公司内部传阅禁止外泄以及用于其他的商业目的
*/
@Component(value = "dingtalkBusiness")
@ -48,45 +50,71 @@ public class DingtalkBusiness {
@Resource
StaffOccupationService staffOccupationService;
@Resource
StaffDao staffDao;
/**
* 获取组织架构信息并录入到数据库
*/
// @DataSource(name = DataSourceNames.FOUR)
public void getDingTalkepartmentsIntoData() {
public void getDingTalkepartmentsIntoData(String appid) {
/*List<StaffEntity> staffEntityList = staffDao.selectByRang("535");//飞书数据更新为钉钉数据
for (StaffEntity staff:staffEntityList
) {
List<StaffEntity> 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<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);
if(departmentInfosBos.size() > 0){
//更新数据库中的部门相关信息
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);
//加入到部门和员工关系表同时更新leader关系
departmentsStaffRelateService.addRelateInfos(departmentInfo.getId(), staffIds);
//录入员工职业信息表
enterStaffOccupationInfos(staffs);
}
}
}else{
logger.info("部门信息为空");
}
}
}
public void enterStaffOccupationInfos(List<DepartmentStaffBo> 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);
}
}
}

View File

@ -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());
}

View File

@ -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();
}

View File

@ -182,7 +182,7 @@
gender = #{gender,jdbcType=INTEGER},
</if>
<if test="birthday != null and birthday != '' ">
birthday = #{birthday,jdbcType=VARCHAR},
birthday = #{birthday,jdbcType=DATETIME},
</if>
<if test="maritalStatus != null">
marital_status = #{maritalStatus,jdbcType=INTEGER},
@ -220,10 +220,18 @@
<if test="unionId != null and unionId != '' ">
union_id = #{unionId,jdbcType=VARCHAR},
</if>
avatar = #{avatar},
job_number = #{jobNumber}
<if test="openId != null and openId != '' ">
open_id = #{openId,jdbcType=VARCHAR},
</if>
<if test="jobNumber != null and jobNumber != '' ">
job_number = #{jobNumber,jdbcType=VARCHAR},
</if>
<if test="avatar != null and avatar != '' ">
avatar = #{avatar,jdbcType=VARCHAR}
</if>
</set>
WHERE is_delete = 0 AND open_id = #{openId ,jdbcType=BIGINT}
WHERE is_delete = 0 AND id = #{id ,jdbcType=BIGINT}
</update>
<insert id="addStaffBatch">
@ -422,13 +430,16 @@
</foreach>
</select>
<insert id="addStaff" useGeneratedKeys="true" keyProperty="id">
<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>
<select id="selectByRang" resultType="com.lz.modules.app.entity.StaffEntity">
select * from lz_staff where is_delete=0 and id > #{id}
</select>
<select id="selectByPhone" resultType="com.lz.modules.app.entity.StaffEntity">
select * from lz_staff where is_delete = 0 and ( mobile = #{phone} or mobile = concat('+86',#{phone},'')) limit 1
</select>

View File

@ -55,4 +55,8 @@
</foreach>
</insert>
<update id="updateStatusByStaff">
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}
</update>
</mapper>