Commit dff24ee6 by 徐高华

好办延时调用

parent cfcce7c1
......@@ -8,7 +8,7 @@ public class CommonMQDTO implements Serializable {
* @Fields serialVersionUID : TODO(用一句话描述这个变量表示什么)
*/
private static final long serialVersionUID = -5681421708810402425L;
// 1删除日报定时 2无部门成员修复
private int type;
private Object params;
......
......@@ -13,6 +13,8 @@ import com.gic.haoban.manage.api.dto.CommonMQDTO;
public interface HaobanCommonMQApiService {
public void putCommonMessage(CommonMQDTO dto);
public void putCommonDelayMessage(CommonMQDTO dto , int delay);
public void commonHandler(String message);
......
......@@ -44,6 +44,6 @@ public interface StaffDepartmentRelatedService {
*/
public void repairAllStaffDepart(String params) ;
public void repairStaffDepart(String staffId) ;
public void staffDepartChange(TabHaobanStaff staff, String wxEnterpriseId, Integer[] departmentIds) ;
public void staffDepartChange(TabHaobanStaff staff, String wxEnterpriseId, Integer[] departmentIds, boolean retryFlag) ;
}
......@@ -21,11 +21,13 @@ import com.gic.commons.util.DateUtil;
import com.gic.commons.util.EntityUtil;
import com.gic.haoban.common.utils.DingUtils;
import com.gic.haoban.common.utils.StringUtil;
import com.gic.haoban.manage.api.dto.CommonMQDTO;
import com.gic.haoban.manage.api.dto.DepartmentDTO;
import com.gic.haoban.manage.api.dto.SecretSettingDTO;
import com.gic.haoban.manage.api.dto.StaffDepartmentRelatedDTO;
import com.gic.haoban.manage.api.dto.WxEnterpriseQwDTO;
import com.gic.haoban.manage.api.enums.SecretTypeEnum;
import com.gic.haoban.manage.api.service.HaobanCommonMQApiService;
import com.gic.haoban.manage.service.dao.mapper.StaffDepartmentRelatedMapper;
import com.gic.haoban.manage.service.dao.mapper.StaffMapper;
import com.gic.haoban.manage.service.entity.TabHaobanStaff;
......@@ -54,6 +56,8 @@ public class StaffDepartmentRelatedServiceImpl implements StaffDepartmentRelated
private QywxUserApiService qywxUserApiService ;
@Autowired
private DepartmentService departmentService ;
@Autowired
private HaobanCommonMQApiService haobanCommonMQApiService ;
@Override
public List<TabHaobanStaffDepartmentRelated> listByDepartmentId(String departmentId) {
......@@ -156,75 +160,84 @@ public class StaffDepartmentRelatedServiceImpl implements StaffDepartmentRelated
UserDTO user = qywxUserApiService.getSelfWorkWxUser(qwDTO.getDkCorpid(), secretSetting.getSecretVal(), wxUserId);
logger.info("成员详情(代开)={}",JSON.toJSONString(user)) ;
if(null != user.getDepartment()) {
this.staffDepartChange(staff, wxEnterpriseId, user.getDepartment()); ;
this.staffDepartChange(staff, wxEnterpriseId, user.getDepartment(),false); ;
}
}
}
public void staffDepartChange(TabHaobanStaff staff, String wxEnterpriseId, Integer[] departmentIds) {
//更新部门
List<String> wxDepartIds = new ArrayList<>();
for (Integer wDId : departmentIds) {
wxDepartIds.add(wDId.toString());
}
//关联部门
List<DepartmentDTO> departmentDTOList = departmentService.listDepartmentByWxDepartIds(wxEnterpriseId, wxDepartIds);
if (CollectionUtils.isEmpty(departmentDTOList)) {
logger.info("部门没有更新或同步:{}", wxEnterpriseId);
return;
}
//已存在部门
List<TabHaobanStaffDepartmentRelated> hasRelation = this.listStaffDepartmentByStaffId(staff.getStaffId());
Map<String, TabHaobanStaffDepartmentRelated> hasRelationMap = new HashMap<>();
if (CollectionUtils.isNotEmpty(hasRelation)) {
hasRelationMap = hasRelation.stream().collect(Collectors.toMap(TabHaobanStaffDepartmentRelated::getDepartmentId, tab -> tab));
}
public void staffDepartChange(TabHaobanStaff staff, String wxEnterpriseId, Integer[] departmentIds , boolean retryFlag) {
//更新部门
List<String> wxDepartIds = new ArrayList<>();
for (Integer wDId : departmentIds) {
wxDepartIds.add(wDId.toString());
}
if(CollectionUtils.isEmpty(wxDepartIds)) {
return ;
}
//关联部门
List<DepartmentDTO> departmentDTOList = departmentService.listDepartmentByWxDepartIds(wxEnterpriseId, wxDepartIds);
if (CollectionUtils.isEmpty(departmentDTOList)) {
logger.info("部门没有更新或同步:{}", wxEnterpriseId);
if(retryFlag) {
Map<String,Object> map = new HashMap<>() ;
map.put("staffId", staff.getStaffId()) ;
CommonMQDTO dto = new CommonMQDTO();
dto.setType(2);
dto.setParams(map);
this.haobanCommonMQApiService.putCommonDelayMessage(dto, 60);
}
return;
}
//新增操作
for (DepartmentDTO departmentDTO : departmentDTOList) {
if (!hasRelationMap.containsKey(departmentDTO.getDepartmentId())) {
StaffDepartmentRelatedDTO dto = new StaffDepartmentRelatedDTO();
dto.setPhoneNumber(staff.getPhoneNumber());
dto.setStaffId(staff.getStaffId());
dto.setStaffName(staff.getStaffName());
dto.setWxEnterpriseId(wxEnterpriseId);
dto.setStatusFlag(1);
dto.setDepartmentId(departmentDTO.getDepartmentId());
dto.setNationCode(staff.getNationCode());
this.add(dto);
}
}
//删除操作
Set<String> newDepartIds = departmentDTOList.stream().map(DepartmentDTO::getDepartmentId).collect(Collectors.toSet());
Set<String> hasDepartIds = hasRelationMap.keySet();
Sets.SetView<String> delDepartIds = Sets.difference(hasDepartIds, newDepartIds);
Sets.SetView<String> updateDepartIds = Sets.intersection(newDepartIds, hasDepartIds);//交集
logger.info("删除部门:{}", JSONObject.toJSONString(delDepartIds));
if (CollectionUtils.isNotEmpty(delDepartIds)) {
for (String delDepartId : delDepartIds) {
TabHaobanStaffDepartmentRelated departmentRelated = hasRelationMap.get(delDepartId);
if (null != departmentRelated) {
StaffDepartmentRelatedDTO relatedDTO = new StaffDepartmentRelatedDTO();
relatedDTO.setStaffDepartmentRelatedId(departmentRelated.getStaffDepartmentRelatedId());
this.del(relatedDTO);
}
}
}
//已存在部门
List<TabHaobanStaffDepartmentRelated> hasRelation = this.listStaffDepartmentByStaffId(staff.getStaffId());
Map<String, TabHaobanStaffDepartmentRelated> hasRelationMap = new HashMap<>();
if (CollectionUtils.isNotEmpty(hasRelation)) {
hasRelationMap = hasRelation.stream().collect(Collectors.toMap(TabHaobanStaffDepartmentRelated::getDepartmentId, tab -> tab));
}
if (CollectionUtils.isNotEmpty(updateDepartIds)) {
for (String updateDeId : updateDepartIds) {
TabHaobanStaffDepartmentRelated departmentRelated = hasRelationMap.get(updateDeId);
if (null != departmentRelated) {
departmentRelated.setPhoneNumber(staff.getPhoneNumber());
departmentRelated.setStaffName(staff.getStaffName());
departmentRelated.setNationCode(staff.getNationCode());
departmentRelated.setUpdateTime(new Date());
this.update(departmentRelated);
}
}
}
}
//新增操作
for (DepartmentDTO departmentDTO : departmentDTOList) {
if (!hasRelationMap.containsKey(departmentDTO.getDepartmentId())) {
StaffDepartmentRelatedDTO dto = new StaffDepartmentRelatedDTO();
dto.setPhoneNumber(staff.getPhoneNumber());
dto.setStaffId(staff.getStaffId());
dto.setStaffName(staff.getStaffName());
dto.setWxEnterpriseId(wxEnterpriseId);
dto.setStatusFlag(1);
dto.setDepartmentId(departmentDTO.getDepartmentId());
dto.setNationCode(staff.getNationCode());
this.add(dto);
}
}
//删除操作
Set<String> newDepartIds = departmentDTOList.stream().map(DepartmentDTO::getDepartmentId).collect(Collectors.toSet());
Set<String> hasDepartIds = hasRelationMap.keySet();
Sets.SetView<String> delDepartIds = Sets.difference(hasDepartIds, newDepartIds);
Sets.SetView<String> updateDepartIds = Sets.intersection(newDepartIds, hasDepartIds);//交集
logger.info("删除部门:{}", JSONObject.toJSONString(delDepartIds));
if (CollectionUtils.isNotEmpty(delDepartIds)) {
for (String delDepartId : delDepartIds) {
TabHaobanStaffDepartmentRelated departmentRelated = hasRelationMap.get(delDepartId);
if (null != departmentRelated) {
StaffDepartmentRelatedDTO relatedDTO = new StaffDepartmentRelatedDTO();
relatedDTO.setStaffDepartmentRelatedId(departmentRelated.getStaffDepartmentRelatedId());
this.del(relatedDTO);
}
}
}
if (CollectionUtils.isNotEmpty(updateDepartIds)) {
for (String updateDeId : updateDepartIds) {
TabHaobanStaffDepartmentRelated departmentRelated = hasRelationMap.get(updateDeId);
if (null != departmentRelated) {
departmentRelated.setPhoneNumber(staff.getPhoneNumber());
departmentRelated.setStaffName(staff.getStaffName());
departmentRelated.setNationCode(staff.getNationCode());
departmentRelated.setUpdateTime(new Date());
this.update(departmentRelated);
}
}
}
}
}
......@@ -13,6 +13,7 @@ import com.alibaba.fastjson.JSONObject;
import com.gic.commons.util.GICMQClientUtil;
import com.gic.haoban.manage.api.dto.CommonMQDTO;
import com.gic.haoban.manage.api.service.HaobanCommonMQApiService;
import com.gic.haoban.manage.service.service.StaffDepartmentRelatedService;
import com.gic.mq.sdk.GicMQClient;
import com.gic.quartz.api.dto.QuartzTaskDTO;
import com.gic.quartz.api.service.QuartzService;
......@@ -26,6 +27,8 @@ public class HaobanCommonMQApiServiceImpl implements HaobanCommonMQApiService {
@Autowired
private QuartzService quartzService ;
@Autowired
private StaffDepartmentRelatedService staffDepartmentRelatedService ;
@Override
public void putCommonMessage(CommonMQDTO dto) {
......@@ -39,16 +42,37 @@ public class HaobanCommonMQApiServiceImpl implements HaobanCommonMQApiService {
e.printStackTrace();
}
}
@Override
public void putCommonDelayMessage(CommonMQDTO dto , int delay) {
String message = JSONObject.toJSONString(dto);
log.info("加入好办延时通用队列params={}",message);
try {
mqClient.sendMessage("haobanDelayMQ", message, delay);
} catch (Exception e) {
log.error("发送MQ异常");
e.printStackTrace();
}
}
@Override
public void commonHandler(String message) {
log.info("接收好办通用队列params={}",message);
CommonMQDTO dto = JSON.parseObject(message, CommonMQDTO.class);
// 好办停用,删除定时
if(dto.getType()==1) {
Map<String,String> map = (Map<String, String>) dto.getParams() ;
Map<String,String> map = (Map<String, String>) dto.getParams() ;
switch (dto.getType()) {
case 1:
String enterpriseId = map.get("enterpriseId") ;
this.deleteQuartz(enterpriseId);
break;
case 2:
String staffId = map.get("staffId") ;
if(StringUtils.isNotBlank(staffId)) {
this.staffDepartmentRelatedService.repairStaffDepart(staffId);
}
default:
break;
}
}
......
package com.gic.haoban.manage.service.service.out.impl;
import cn.hutool.core.convert.Convert;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.function.Function;
import java.util.stream.Collectors;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.gic.clerk.api.dto.ClerkQwDTO;
import com.gic.clerk.api.service.ClerkService;
import com.gic.commons.util.*;
import com.gic.commons.util.EntityUtil;
import com.gic.commons.util.GICMQClientUtil;
import com.gic.commons.util.GlobalInfo;
import com.gic.commons.util.GlobalVar;
import com.gic.commons.util.ImageUtil;
import com.gic.haoban.app.customer.service.api.service.InnerApiService;
import com.gic.haoban.base.api.common.Constant;
import com.gic.haoban.base.api.common.ServiceResponse;
import com.gic.haoban.manage.api.dto.*;
import com.gic.haoban.manage.api.enums.*;
import com.gic.haoban.manage.api.dto.CommonMQDTO;
import com.gic.haoban.manage.api.dto.DepartmentDTO;
import com.gic.haoban.manage.api.dto.QywxCallBackDTO;
import com.gic.haoban.manage.api.dto.SecretSettingDTO;
import com.gic.haoban.manage.api.dto.StaffClerkRelationDTO;
import com.gic.haoban.manage.api.dto.StaffDTO;
import com.gic.haoban.manage.api.dto.WxEnterpriseDTO;
import com.gic.haoban.manage.api.dto.WxEnterpriseQwDTO;
import com.gic.haoban.manage.api.enums.AppPageType;
import com.gic.haoban.manage.api.enums.ChannelCodeEnum;
import com.gic.haoban.manage.api.enums.NoticeMessageTypeEnum;
import com.gic.haoban.manage.api.enums.SecretTypeEnum;
import com.gic.haoban.manage.api.enums.WxEditType;
import com.gic.haoban.manage.api.service.HaobanCommonMQApiService;
import com.gic.haoban.manage.api.service.MessageApiService;
import com.gic.haoban.manage.api.service.StaffApiService;
import com.gic.haoban.manage.api.service.StaffClerkRelationApiService;
import com.gic.haoban.manage.api.service.StaffDepartmentRelatedApiService;
import com.gic.haoban.manage.api.util.notify.NoticeMessageUtil;
import com.gic.haoban.manage.service.config.Config;
import com.gic.haoban.manage.service.entity.*;
import com.gic.haoban.manage.service.service.*;
import com.gic.haoban.manage.service.entity.TabHaobanDepartment;
import com.gic.haoban.manage.service.entity.TabHaobanStaff;
import com.gic.haoban.manage.service.entity.TabHaobanStaffDepartmentRelated;
import com.gic.haoban.manage.service.entity.TabHaobanWxApplication;
import com.gic.haoban.manage.service.entity.TabHaobanWxEnterpriseRelated;
import com.gic.haoban.manage.service.service.DepartmentService;
import com.gic.haoban.manage.service.service.SecretSettingService;
import com.gic.haoban.manage.service.service.StaffDepartmentRelatedService;
import com.gic.haoban.manage.service.service.StaffService;
import com.gic.haoban.manage.service.service.WxApplicationService;
import com.gic.haoban.manage.service.service.WxEnterpriseRelatedService;
import com.gic.haoban.manage.service.service.WxEnterpriseService;
import com.gic.mq.sdk.GicMQClient;
import com.gic.redis.data.util.RedisUtil;
import com.gic.thirdparty.api.dto.PicUploadResDTO;
......@@ -30,16 +71,8 @@ import com.gic.wechat.api.service.qywx.QywxDepartmentApiService;
import com.gic.wechat.api.service.qywx.QywxSuiteApiService;
import com.gic.wechat.api.service.qywx.QywxUserApiService;
import com.google.common.collect.Sets;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;
import cn.hutool.core.convert.Convert;
/**
* 接收企业微信或者gic推送消息进行处理
......@@ -86,6 +119,8 @@ public class MessageApiServiceImpl implements MessageApiService {
private WxApplicationService wxApplicationService;
@Autowired
private QywxUserApiService qywxUserApiService;
@Autowired
private HaobanCommonMQApiService haobanCommonMQApiService ;
@Override
public void wxMessageReceive(QywxCallBackDTO qywxCallBackDTO) {
......@@ -244,6 +279,12 @@ public class MessageApiServiceImpl implements MessageApiService {
TabHaobanDepartment department = this.departmentService.getByWxId(s, wxEnterpriseId);
if (department == null) {
log.info("成员同步,部门不存在");
Map<String,Object> map = new HashMap<>() ;
map.put("staffId", staff.getStaffId()) ;
CommonMQDTO dto = new CommonMQDTO();
dto.setType(2);
dto.setParams(map);
this.haobanCommonMQApiService.putCommonDelayMessage(dto, 60);
continue;
}
departmentIds.append(department.getDepartmentId()).append(",");
......
......@@ -266,7 +266,7 @@ public class StaffApiServiceImpl implements StaffApiService {
staffService.updateByPrimaryKey(staff);
}
logger.info("staff变更保存:{}", JSONObject.toJSONString(user));
this.staffDepartmentRelatedService.staffDepartChange(staff, wxEnterpriseId, user.getDepartment());
this.staffDepartmentRelatedService.staffDepartChange(staff, wxEnterpriseId, user.getDepartment(),true);
// 返回结果带上员工姓名
res.setResult(staff.getStaffName());
return res;
......
......@@ -52,13 +52,6 @@ public class QywxStaffSyncOperation implements BaseSyncOperation {
private StaffApiService staffApiService;
@Autowired
private DealSyncOperationApiService dealSyncOperationApiService;
@Autowired
private QywxUserApiService qywxUserApiService;
@Autowired
private WxEnterpriseApiService wxEnterpriseApiService;
@Autowired
private Config config;
@Override
public void dealSingleByMq(DealParamMqDTO dealParamMqDTO, TabHaobanPreDealLog dataPre) {
logger.info("企微通讯录成员同步处理:{}", JSONObject.toJSONString(dealParamMqDTO));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment