Commit 35e25ce4 by 徐高华

修复部门

parent 13330710
package com.gic.haoban.manage.service.service; package com.gic.haoban.manage.service.service;
import com.gic.haoban.manage.api.dto.StaffDepartmentRelatedDTO; 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 com.gic.haoban.manage.service.entity.TabHaobanStaffDepartmentRelated;
import java.util.List; import java.util.List;
...@@ -32,5 +33,9 @@ public interface StaffDepartmentRelatedService { ...@@ -32,5 +33,9 @@ public interface StaffDepartmentRelatedService {
public int cleanStaffDepartment(String wxEnterpriseId,List<String> staffIds); public int cleanStaffDepartment(String wxEnterpriseId,List<String> staffIds);
public int update(TabHaobanStaffDepartmentRelated tab); 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; 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.commons.util.EntityUtil;
import com.gic.haoban.common.utils.StringUtil; 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.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.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.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 com.gic.haoban.manage.service.service.StaffDepartmentRelatedService;
import org.springframework.beans.factory.annotation.Autowired; import com.gic.haoban.manage.service.service.WxEnterpriseService;
import org.springframework.stereotype.Service; import com.gic.haoban.manage.service.service.out.impl.MessageApiServiceImpl;
import com.gic.haoban.manage.service.service.out.impl.StaffApiServiceImpl;
import java.util.Date; import com.gic.wechat.api.dto.qywx.UserDTO;
import java.util.List; import com.gic.wechat.api.service.qywx.QywxUserApiService;
import com.google.common.collect.Sets;
@Service @Service
public class StaffDepartmentRelatedServiceImpl implements StaffDepartmentRelatedService { public class StaffDepartmentRelatedServiceImpl implements StaffDepartmentRelatedService {
private static final Logger logger = LogManager.getLogger(StaffDepartmentRelatedService.class);
@Autowired @Autowired
private StaffDepartmentRelatedMapper mapper; private StaffDepartmentRelatedMapper mapper;
@Autowired
private StaffMapper staffMapper ;
@Autowired
private SecretSettingService secretSettingService ;
@Autowired
private WxEnterpriseService wxEnterpriseService ;
@Autowired
private QywxUserApiService qywxUserApiService ;
@Autowired
private DepartmentService departmentService ;
@Override @Override
public List<TabHaobanStaffDepartmentRelated> listByDepartmentId(String departmentId) { public List<TabHaobanStaffDepartmentRelated> listByDepartmentId(String departmentId) {
...@@ -78,5 +115,90 @@ public class StaffDepartmentRelatedServiceImpl implements StaffDepartmentRelated ...@@ -78,5 +115,90 @@ public class StaffDepartmentRelatedServiceImpl implements StaffDepartmentRelated
public int update(TabHaobanStaffDepartmentRelated tab) { public int update(TabHaobanStaffDepartmentRelated tab) {
return mapper.updateByPrimaryKeySelective(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);
}
}
}
}
} }
...@@ -3,7 +3,6 @@ package com.gic.haoban.manage.service.service.out.impl; ...@@ -3,7 +3,6 @@ package com.gic.haoban.manage.service.service.out.impl;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.Date; import java.util.Date;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
...@@ -76,7 +75,6 @@ import com.gic.wechat.api.dto.qywx.UserDTO; ...@@ -76,7 +75,6 @@ import com.gic.wechat.api.dto.qywx.UserDTO;
import com.gic.wechat.api.service.qywx.QywxUserApiService; import com.gic.wechat.api.service.qywx.QywxUserApiService;
import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo; import com.github.pagehelper.PageInfo;
import com.google.common.collect.Sets;
import cn.hutool.core.collection.CollectionUtil; import cn.hutool.core.collection.CollectionUtil;
...@@ -148,21 +146,7 @@ public class StaffApiServiceImpl implements StaffApiService { ...@@ -148,21 +146,7 @@ public class StaffApiServiceImpl implements StaffApiService {
List<TabHaobanStaffDepartmentRelated> list = staffDepartmentRelatedService.listStaffDepartmentByStaffId(staffId); List<TabHaobanStaffDepartmentRelated> list = staffDepartmentRelatedService.listStaffDepartmentByStaffId(staffId);
// 如果成员部门为空,修复部门数据 // 如果成员部门为空,修复部门数据
if(CollectionUtils.isEmpty(list)) { if(CollectionUtils.isEmpty(list)) {
TabHaobanStaff staff = this.staffMapper.selectByPrimaryKey(staffId) ; this.staffDepartmentRelatedService.repairStaffDepart(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()); ;
}
}
} }
return EntityUtil.changeEntityListByJSON(StaffDepartmentRelatedDTO.class, list); return EntityUtil.changeEntityListByJSON(StaffDepartmentRelatedDTO.class, list);
} }
...@@ -291,7 +275,7 @@ public class StaffApiServiceImpl implements StaffApiService { ...@@ -291,7 +275,7 @@ public class StaffApiServiceImpl implements StaffApiService {
staffService.updateByPrimaryKey(staff); staffService.updateByPrimaryKey(staff);
} }
logger.info("staff变更保存:{}", JSONObject.toJSONString(user)); logger.info("staff变更保存:{}", JSONObject.toJSONString(user));
staffDepartChange(staff, wxEnterpriseId, user.getDepartment()); this.staffDepartmentRelatedService.staffDepartChange(staff, wxEnterpriseId, user.getDepartment());
// 返回结果带上员工姓名 // 返回结果带上员工姓名
res.setResult(staff.getStaffName()); res.setResult(staff.getStaffName());
return res; return res;
...@@ -361,72 +345,6 @@ public class StaffApiServiceImpl implements StaffApiService { ...@@ -361,72 +345,6 @@ public class StaffApiServiceImpl implements StaffApiService {
return arr; 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 @Override
public ServiceResponse wxGetAdd(String userId, String wxEnterpriseId) { public ServiceResponse wxGetAdd(String userId, String wxEnterpriseId) {
RedisUtil.lock("haoban_add_user" + wxEnterpriseId + userId, 2L); 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