Commit 2f4550d9 by 徐高华

通讯录

parent c37b3f5f
......@@ -34,28 +34,10 @@ public interface StaffService {
*/
TabHaobanStaff selectByUserIdAndEnterpriseId(String userId, String wxEnterpriseId);
/**
* 选择电话号码和企业标识
*
* @param phoneNumber 电话号码
* @param wxEnterpriseId wx企业标识
* @return {@link TabHaobanStaff }
* @author mozhu
* @date 2022-01-12 17:19:28
*/
TabHaobanStaff selectByPhoneNumberAndEnterpriseId(String phoneNumber, String wxEnterpriseId);
/**
* 选择userId跟手机号查询数据 userid优先级高
*
* @param phoneNumber 电话号码
* @param wxEnterpriseId wx企业标识
* @return {@link TabHaobanStaff }
* @author mozhu
* @date 2022-01-12 17:19:28
*/
TabHaobanStaff selectByPhoneNumberOrUserIdAndEnterpriseId(String phoneNumber, String userId, String wxEnterpriseId);
TabHaobanStaff selectByUserIdAndEnterpriseId(String wxuserId, String wxOpenUserId , String wxEnterpriseId);
List<StaffDTO> listByUserIdsAndWxEnterpriseId(List<String> userIds, String wxEnterpriseId);
......
package com.gic.haoban.manage.service.service.impl;
import java.util.Date;
import java.util.List;
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.gic.commons.util.EntityUtil;
import com.gic.haoban.base.api.common.BasePageInfo;
......@@ -9,23 +16,10 @@ import com.gic.haoban.manage.api.dto.StaffDTO;
import com.gic.haoban.manage.service.dao.mapper.StaffMapper;
import com.gic.haoban.manage.service.entity.TabHaobanStaff;
import com.gic.haoban.manage.service.service.MemberUnionRelatedService;
import com.gic.haoban.manage.service.service.StaffClerkRelationService;
import com.gic.haoban.manage.service.service.StaffService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
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.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
@Service
public class StaffServiceImpl implements StaffService {
......@@ -35,10 +29,6 @@ public class StaffServiceImpl implements StaffService {
private StaffMapper mapper;
@Autowired
private MemberUnionRelatedService memberUnionRelatedService;
@Autowired
private StaffClerkRelationService staffClerkRelationService;
@Override
public TabHaobanStaff selectById(String id) {
if (StringUtils.isBlank(id)) {
......@@ -80,39 +70,16 @@ public class StaffServiceImpl implements StaffService {
}
@Override
public TabHaobanStaff selectByPhoneNumberAndEnterpriseId(String phoneNumber, String wxEnterpriseId) {
if (StringUtils.isBlank(phoneNumber)) {
public TabHaobanStaff selectByUserIdAndEnterpriseId(String wxUserId, String wxOpenUserId , String wxEnterpriseId) {
if (StringUtils.isBlank(wxUserId)) {
log.info("wxUserId is null");
return null;
}
return mapper.selectByPhoneNumberAndEnterpriseId(phoneNumber, wxEnterpriseId);
}
@Override
public TabHaobanStaff selectByPhoneNumberOrUserIdAndEnterpriseId(String phoneNumber, String userId, String wxEnterpriseId) {
if (StringUtils.isBlank(userId)) {
return null;
}
//存在多条
List<String> userIds=new ArrayList<>();
userIds.add(userId);
List<TabHaobanStaff> staffs = mapper.listByUserIdsAndWxEnterpriseId(userIds, wxEnterpriseId);
if (CollectionUtils.isEmpty(staffs)) {
return this.selectByPhoneNumberAndEnterpriseId(phoneNumber, wxEnterpriseId);
}
if (staffs.size()==1) {
return staffs.get(0);
//需要去除多余的
}else if (staffs.size()>1) {
Map<String, TabHaobanStaff> staffMap = staffs.stream().collect(Collectors.toMap(dto -> dto.getStaffId(), dto -> dto,(o,n)->n));
List<String> relationStaffIds = staffClerkRelationService.listRelationsStaffId(staffMap.keySet());
if (CollectionUtils.isNotEmpty(relationStaffIds)) {
return staffMap.get(relationStaffIds.get(0));
}else{
return staffs.get(0);
}
TabHaobanStaff staff = this.mapper.selectByUserIdAndEnterpriseId(wxUserId, wxEnterpriseId) ;
if (null == staff && null != wxOpenUserId && !wxUserId.equals(wxOpenUserId)) {
return this.mapper.selectByUserIdAndEnterpriseId(wxOpenUserId, wxEnterpriseId) ;
}
return null;
}
@Override
......
......@@ -55,7 +55,6 @@ 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.TabHaobanDepartment;
import com.gic.haoban.manage.service.entity.TabHaobanStaff;
import com.gic.haoban.manage.service.entity.TabHaobanStaffClerkRelation;
import com.gic.haoban.manage.service.entity.TabHaobanStaffDepartmentRelated;
import com.gic.haoban.manage.service.entity.TabHaobanSyncErrorLog;
import com.gic.haoban.manage.service.entity.TabHaobanWxApplication;
......@@ -190,11 +189,11 @@ public class StaffApiServiceImpl implements StaffApiService {
}
@Override
public ServiceResponse getWxSaveNew(String userId, String wxEnterpriseId) {
public ServiceResponse getWxSaveNew(String wxUserId, String wxEnterpriseId) {
ServiceResponse res = new ServiceResponse();
WxEnterpriseQwDTO qwDTO = this.wxEnterpriseService.getQwInfo(wxEnterpriseId) ;
if (null == qwDTO) {
logger.info("企业不存在:{}:{}", wxEnterpriseId, userId);
logger.info("企业不存在:{}:{}", wxEnterpriseId, wxUserId);
res.setMessage("企业不存在");
res.setCode(2);
return res;
......@@ -209,7 +208,7 @@ public class StaffApiServiceImpl implements StaffApiService {
}
UserDTO user = null;
if(qwDTO.getWxSecurityType()==4) {
user = qywxUserApiService.getWorkWxUser(corpid, config.getWxSuiteid(), userId);
user = qywxUserApiService.getWorkWxUser(corpid, config.getWxSuiteid(), wxUserId);
logger.info("成员详情(第三方)={}",JSON.toJSONString(user)) ;
UserDTO userSelf = qywxUserApiService.getSelfWorkWxUser(qwDTO.getDkCorpid(), secretSetting.getSecretVal(), user.getOpen_userid());
logger.info("成员详情(代开)={}",JSON.toJSONString(user)) ;
......@@ -218,11 +217,11 @@ public class StaffApiServiceImpl implements StaffApiService {
user.setPosition(userSelf.getPosition());
}
} else {
user = qywxUserApiService.getSelfWorkWxUser(corpid, secretSetting.getSecretVal(), userId);
user = qywxUserApiService.getSelfWorkWxUser(corpid, secretSetting.getSecretVal(), wxUserId);
logger.info("成员详情(代开)={}",JSON.toJSONString(user)) ;
}
if (null == user) {
logger.info("企业微信用户不存在:{}:{}", wxEnterpriseId, userId);
logger.info("企业微信用户不存在:{}:{}", wxEnterpriseId, wxUserId);
res.setMessage("企业微信用户不存在");
res.setCode(3);
return res;
......@@ -236,13 +235,13 @@ public class StaffApiServiceImpl implements StaffApiService {
nationCode = arr[0];
phoneNumber = arr[1];
}
TabHaobanStaff staff = staffService.selectByPhoneNumberOrUserIdAndEnterpriseId(phoneNumber, userId, wxEnterpriseId);
String openUserid = getOpenUserid(wxUserId, corpid , qwDTO);
TabHaobanStaff staff = staffService.selectByUserIdAndEnterpriseId(wxUserId, openUserid, wxEnterpriseId);
if (staff != null) {
staffService.delOtherStaffByWxUserId(staff.getWxUserId(), staff.getStaffId(), wxEnterpriseId);
}
staff = (staff == null ? new TabHaobanStaff() : staff);
staff.setWxUserId(userId);
String openUserid = getOpenUserid(userId, corpid , qwDTO);
staff.setWxUserId(wxUserId);
if (StringUtils.isNotBlank(openUserid)) {
staff.setWxOpenUseId(openUserid);
}
......@@ -559,23 +558,6 @@ public class StaffApiServiceImpl implements StaffApiService {
@Override
public StaffDTO getByUserIdAndReflushWhenNoPhone(String userId, String wxEnterpriseId) {
StaffDTO staffDTO = EntityUtil.changeEntityByJSON(StaffDTO.class, staffService.selectByUserIdAndEnterpriseId(userId, wxEnterpriseId));
if (staffDTO == null) {
return null;
}
//存在多条
List<String> userIds = new ArrayList<>();
userIds.add(userId);
List<TabHaobanStaff> staffs = staffMapper.listByUserIdsAndWxEnterpriseId(userIds, wxEnterpriseId);
//需要去除多余的
if (CollectionUtils.isNotEmpty(staffs) && staffs.size() > 1) {
Map<String, TabHaobanStaff> staffMap = staffs.stream().collect(Collectors.toMap(dto -> dto.getStaffId(), dto -> dto, (o, n) -> n));
List<String> relationStaffIds = staffClerkRelationService.listRelationsStaffId(staffMap.keySet());
if (CollectionUtils.isNotEmpty(relationStaffIds)) {
TabHaobanStaff staff = staffMap.get(relationStaffIds.get(0));
staffService.delOtherStaffByWxUserId(staff.getWxUserId(), staff.getStaffId(), wxEnterpriseId);
}
staffDTO = EntityUtil.changeEntityByJSON(StaffDTO.class, staffService.selectByUserIdAndEnterpriseId(userId, wxEnterpriseId));
}
return staffDTO;
}
......
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