Commit ee13d8d2 by 徐高华

Merge remote-tracking branch 'origin/master_xgh_pendingid' into

developer

Conflicts:
	haoban-manage3-service/src/main/java/com/gic/haoban/manage/service/service/out/impl/StaffApiServiceImpl.java
parents cda95f4e 35e25ce4
package com.gic.haoban.manage.service.service;
import com.gic.haoban.manage.api.dto.StaffDepartmentRelatedDTO;
import com.gic.haoban.manage.service.entity.TabHaobanStaff;
import com.gic.haoban.manage.service.entity.TabHaobanStaffDepartmentRelated;
import java.util.List;
......@@ -32,5 +33,9 @@ public interface StaffDepartmentRelatedService {
public int cleanStaffDepartment(String wxEnterpriseId,List<String> staffIds);
public int update(TabHaobanStaffDepartmentRelated tab);
public void repairStaffDepart(String staffId) ;
public void staffDepartChange(TabHaobanStaff staff, String wxEnterpriseId, Integer[] departmentIds) ;
}
package com.gic.haoban.manage.service.service.impl;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
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.commons.util.EntityUtil;
import com.gic.haoban.common.utils.StringUtil;
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.service.dao.mapper.StaffDepartmentRelatedMapper;
import com.gic.haoban.manage.service.dao.mapper.StaffMapper;
import com.gic.haoban.manage.service.entity.TabHaobanStaff;
import com.gic.haoban.manage.service.entity.TabHaobanStaffDepartmentRelated;
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 org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Date;
import java.util.List;
import com.gic.haoban.manage.service.service.WxEnterpriseService;
import com.gic.haoban.manage.service.service.out.impl.MessageApiServiceImpl;
import com.gic.haoban.manage.service.service.out.impl.StaffApiServiceImpl;
import com.gic.wechat.api.dto.qywx.UserDTO;
import com.gic.wechat.api.service.qywx.QywxUserApiService;
import com.google.common.collect.Sets;
@Service
public class StaffDepartmentRelatedServiceImpl implements StaffDepartmentRelatedService {
private static final Logger logger = LogManager.getLogger(StaffDepartmentRelatedService.class);
@Autowired
private StaffDepartmentRelatedMapper mapper;
@Autowired
private StaffMapper staffMapper ;
@Autowired
private SecretSettingService secretSettingService ;
@Autowired
private WxEnterpriseService wxEnterpriseService ;
@Autowired
private QywxUserApiService qywxUserApiService ;
@Autowired
private DepartmentService departmentService ;
@Override
public List<TabHaobanStaffDepartmentRelated> listByDepartmentId(String departmentId) {
......@@ -78,5 +115,90 @@ public class StaffDepartmentRelatedServiceImpl implements StaffDepartmentRelated
public int update(TabHaobanStaffDepartmentRelated tab) {
return mapper.updateByPrimaryKeySelective(tab);
}
@Override
public void repairStaffDepart(String staffId) {
TabHaobanStaff staff = this.staffMapper.selectByPrimaryKey(staffId) ;
String wxEnterpriseId = staff.getWxEnterpriseId() ;
WxEnterpriseQwDTO qwDTO = this.wxEnterpriseService.getQwInfo(wxEnterpriseId) ;
String wxUserId = staff.getWxUserId() ;
if(qwDTO.needOpenUserIdDk()) {
wxUserId = staff.getWxOpenUseId() ;
}
SecretSettingDTO secretSetting = secretSettingService.getSecretSetting(qwDTO.getWxEnterpriseId(), SecretTypeEnum.CUSTOMIZED_APP.getVal());
if (null != secretSetting && StringUtils.isNotBlank(secretSetting.getSecretVal())) {
UserDTO user = qywxUserApiService.getSelfWorkWxUser(qwDTO.getDkCorpid(), secretSetting.getSecretVal(), wxUserId);
logger.info("成员详情(代开)={}",JSON.toJSONString(user)) ;
if(null != user.getDepartment()) {
this.staffDepartChange(staff, wxEnterpriseId, user.getDepartment()); ;
}
}
}
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));
}
//新增操作
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);
}
}
}
}
}
package com.gic.haoban.manage.service.service.out.impl;
import cn.hutool.core.collection.CollectionUtil;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
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.api.base.commons.Page;
......@@ -52,17 +68,6 @@ import com.gic.wechat.api.dto.qywx.UserDTO;
import com.gic.wechat.api.service.qywx.QywxUserApiService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.google.common.collect.Sets;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
@Service
public class StaffApiServiceImpl implements StaffApiService {
......@@ -132,21 +137,7 @@ public class StaffApiServiceImpl implements StaffApiService {
List<TabHaobanStaffDepartmentRelated> list = staffDepartmentRelatedService.listStaffDepartmentByStaffId(staffId);
// 如果成员部门为空,修复部门数据
if(CollectionUtils.isEmpty(list)) {
TabHaobanStaff staff = this.staffMapper.selectByPrimaryKey(staffId) ;
String wxEnterpriseId = staff.getWxEnterpriseId() ;
WxEnterpriseQwDTO qwDTO = this.wxEnterpriseService.getQwInfo(wxEnterpriseId) ;
String wxUserId = staff.getWxUserId() ;
if(qwDTO.needOpenUserIdDk()) {
wxUserId = staff.getWxOpenUseId() ;
}
SecretSettingDTO secretSetting = secretSettingService.getSecretSetting(qwDTO.getWxEnterpriseId(), SecretTypeEnum.CUSTOMIZED_APP.getVal());
if (null != secretSetting && StringUtils.isNotBlank(secretSetting.getSecretVal())) {
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.staffDepartmentRelatedService.repairStaffDepart(staffId);
}
return EntityUtil.changeEntityListByJSON(StaffDepartmentRelatedDTO.class, list);
}
......@@ -275,7 +266,7 @@ public class StaffApiServiceImpl implements StaffApiService {
staffService.updateByPrimaryKey(staff);
}
logger.info("staff变更保存:{}", JSONObject.toJSONString(user));
staffDepartChange(staff, wxEnterpriseId, user.getDepartment());
this.staffDepartmentRelatedService.staffDepartChange(staff, wxEnterpriseId, user.getDepartment());
// 返回结果带上员工姓名
res.setResult(staff.getStaffName());
return res;
......@@ -345,72 +336,6 @@ public class StaffApiServiceImpl implements StaffApiService {
return arr;
}
private 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 = staffDepartmentRelatedService.listStaffDepartmentByStaffId(staff.getStaffId());
Map<String, TabHaobanStaffDepartmentRelated> hasRelationMap = new HashMap<>();
if (CollectionUtils.isNotEmpty(hasRelation)) {
hasRelationMap = hasRelation.stream().collect(Collectors.toMap(TabHaobanStaffDepartmentRelated::getDepartmentId, tab -> tab));
}
//新增操作
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());
staffDepartmentRelatedService.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());
staffDepartmentRelatedService.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());
staffDepartmentRelatedService.update(departmentRelated);
}
}
}
}
@Override
public ServiceResponse wxGetAdd(String userId, String wxEnterpriseId) {
RedisUtil.lock("haoban_add_user" + wxEnterpriseId + userId, 2L);
......
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