Commit a0b61a94 by 墨竹

feat:通讯录同步插入wxopenid

parent 6043b5bd
......@@ -12,7 +12,10 @@ import com.gic.haoban.manage.api.enums.AppPageType;
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.*;
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.*;
......@@ -43,12 +46,9 @@ import java.util.stream.Collectors;
@Service("messageApiService")
public class MessageApiServiceImpl implements MessageApiService {
private static final Logger log = LogManager.getLogger(MessageApiServiceImpl.class);
private final String CONTACT_APP = "contactSuiteId";
@Autowired
private DepartmentService departmentService;
@Autowired
private DepartmentApiService departmentApiService;
@Autowired
private WxEnterpriseService enterpriseService;
@Autowired
private StaffService staffService;
......
......@@ -24,18 +24,15 @@ import com.gic.haoban.manage.api.dto.*;
import com.gic.haoban.manage.api.enums.SecretTypeEnum;
import com.gic.haoban.manage.api.service.DepartmentApiService;
import com.gic.haoban.manage.api.service.StaffApiService;
import com.gic.haoban.manage.service.config.Config;
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.TabHaobanStaffDepartmentRelated;
import com.gic.haoban.manage.service.entity.TabHaobanSyncErrorLog;
import com.gic.haoban.manage.service.entity.*;
import com.gic.haoban.manage.service.service.*;
import com.gic.haoban.manage.service.util.EmojiFilterUtil;
import com.gic.redis.data.util.RedisUtil;
import com.gic.thirdparty.api.dto.PicUploadResDTO;
import com.gic.thirdparty.api.service.QQCloudPicService;
import com.gic.wechat.api.dto.qywx.QywxNewUseridDTO;
import com.gic.wechat.api.dto.qywx.UserDTO;
import com.gic.wechat.api.service.qywx.QywxUserApiService;
import com.github.pagehelper.PageHelper;
......@@ -101,7 +98,7 @@ public class StaffApiServiceImpl implements StaffApiService {
@Autowired
private StaffPrivacyUseLogService staffPrivacyUseLogService;
@Autowired
private Config config;
private WxApplicationService wxApplicationService;
@Override
public StaffDTO selectById(String staffId) {
......@@ -296,14 +293,12 @@ public class StaffApiServiceImpl implements StaffApiService {
WxEnterpriseDTO enterpriseDTO = wxEnterpriseService.selectById(staff.getWxEnterpriseId());
if (enterpriseDTO != null) {
ServiceResponse delQywxStaff = delQywxStaff(staff, enterpriseDTO);
// JSONResponse jp = qywxUserApiService.deleteSelfWorkWxUser(enterpriseDTO.getCorpid(), enterpriseDTO.getContactSecret(), staff.getWxUserId());
logger.info("【删除成员】{} ,jp={}", staffDepartmentStaffRelatedId, JSON.toJSONString(delQywxStaff));
if (delQywxStaff.getCode() != 1) {
throw new RuntimeException("企业微信删除失败");
}
}
staffDepartmentRelatedService.del(related);
// staffService.delByuserid(relatedList.get(0).getStaffId());
TabHaobanStaffDepartmentRelated staffRelated = relatedList.get(0);
if (StringUtils.isNotBlank(staffRelated.getClerkCode())) {
......@@ -369,7 +364,7 @@ public class StaffApiServiceImpl implements StaffApiService {
res.setCode(2);
return res;
}
String corpid = enterpriseDTO.getCorpid();
SecretSettingDTO secretSetting = secretSettingService.getSecretSetting(enterpriseDTO.getWxEnterpriseId(), SecretTypeEnum.HAOBAN_HELP.getVal());
if (null == secretSetting || secretSetting.getCheckFlag() == 0) {
logger.info("没有配置secret:{}", JSONObject.toJSONString(enterpriseDTO));
......@@ -377,7 +372,7 @@ public class StaffApiServiceImpl implements StaffApiService {
res.setCode(4);
return res;
}
UserDTO user = qywxUserApiService.getSelfWorkWxUser(enterpriseDTO.getCorpid(), secretSetting.getSecretVal(), userId);
UserDTO user = qywxUserApiService.getSelfWorkWxUser(corpid, secretSetting.getSecretVal(), userId);
if (null == user) {
logger.info("企业微信用户不存在:{}:{}", wxEnterpriseId, userId);
res.setMessage("企业微信用户不存在");
......@@ -418,6 +413,10 @@ public class StaffApiServiceImpl implements StaffApiService {
if (StringUtils.isNotBlank(qr_code)) {
staff.setQrCode(qr_code);
}
String openUserid = getOpenUserid(userId, corpid);
if (StringUtils.isNotBlank(openUserid)) {
staff.setWxOpenUseId(openUserid);
}
//成员更改或更新
if (StringUtils.isBlank(staff.getStaffId())) {
logger.info("新增成员");
......@@ -434,6 +433,21 @@ public class StaffApiServiceImpl implements StaffApiService {
return res;
}
/**
* 获取wxopenid
* @param userId
* @param corpid
* @return
*/
private String getOpenUserid(String userId, String corpid) {
TabHaobanWxApplication tabHaobanWxApplication = wxApplicationService.selectByCorpId(corpid);
List<QywxNewUseridDTO> qywxNewUseridDTOS = qywxUserApiService.useridToOpenuserid(corpid, tabHaobanWxApplication.getSiteId(), Collections.singletonList(userId));
if (CollectionUtils.isEmpty(qywxNewUseridDTOS)) {
return "";
}
return qywxNewUseridDTOS.get(0).getOpen_userid();
}
private String[] getNationCodeAndPhoneNumber(String phoneNumber) {
String[] arr = new String[2];
if (StringUtils.isBlank(phoneNumber)) {
......@@ -467,7 +481,6 @@ public class StaffApiServiceImpl implements StaffApiService {
}
private void staffDepartChange(TabHaobanStaff staff, String wxEnterpriseId, UserDTO user) {
//更新部门
Integer[] departmentIds = user.getDepartment();
List<String> wxDepartIds = new ArrayList<>();
......@@ -545,119 +558,6 @@ public class StaffApiServiceImpl implements StaffApiService {
logger.info("信息:{}", JSONObject.toJSONString(wxSaveNew));
}
@Deprecated
public void wxGetAddOld(String userId, String wxEnterpriseId) {
//获取微信用户信息
TabHaobanStaff staff = staffService.selectByUserIdAndEnterpriseId(userId, wxEnterpriseId);
if (staff == null) {
WxEnterpriseDTO enterpriseDTO = wxEnterpriseService.selectById(wxEnterpriseId);
if (enterpriseDTO != null) {
Date now = new Date();
SecretSettingDTO secretSetting = secretSettingService.getSecretSetting(wxEnterpriseId, SecretTypeEnum.HAOBAN_HELP.getVal());
if (null == secretSetting || secretSetting.getCheckFlag() == 0) {
logger.info("没有配置secret");
return;
}
UserDTO user = qywxUserApiService.getSelfWorkWxUser(enterpriseDTO.getCorpid(), secretSetting.getSecretVal(), userId);
if (user == null) {
return;
}
logger.info("【新增用户】user={}", JSON.toJSONString(user));
TabHaobanStaff tab = new TabHaobanStaff();
tab.setWxUserId(userId);
tab.setCreateTime(now);
tab.setUpdateTime(now);
tab.setStatusFlag(1);
tab.setWxEnterpriseId(wxEnterpriseId);
if (StringUtils.isNotBlank(user.getAvatar())) {
tab.setHeadImg(changeHeaderImageUrl(user.getAvatar()));
}
tab.setPhoneNumber(user.getMobile());
if (StringUtils.isNotBlank(user.getName())) {
user.setName(EmojiFilterUtil.removeAllEmoji(user.getName()));
tab.setStaffName((user.getName()));
}
if (StringUtils.isNotBlank(user.getAlias())) {
user.setAlias(EmojiFilterUtil.removeAllEmoji(user.getAlias()));
tab.setNickName((user.getAlias()));
}
// tab.setNickName(user.getAlias());
tab.setNationCode("86");
tab.setSex(user.getGender() == null ? 1 : Integer.parseInt(user.getGender()));
tab.setActiveFlag(1);
tab.setPostion(user.getPosition());
tab.setExtendPostion(user.getExternal_position());
if (user.getStatus() != null && user.getStatus() == 1) {
tab.setActiveFlag(1);
} else {
tab.setActiveFlag(0);
}
String staffId = staffService.add(tab);
Integer[] departmentId = user.getDepartment();
for (Integer integer : departmentId) {
TabHaobanDepartment tabDepartment = departmentService.getByWxId(integer.toString(), wxEnterpriseId);
if (tabDepartment != null) {
TabHaobanStaffDepartmentRelated tabStaff = staffDepartmentRelatedService.getDepartmentIdAndStaffId(tabDepartment.getDepartmentId(), tab.getStaffId());
if (tabStaff == null) {
StaffDepartmentRelatedDTO dto = new StaffDepartmentRelatedDTO();
dto.setPhoneNumber(user.getMobile());
dto.setWxUserId(userId);
dto.setStaffId(staffId);
dto.setStaffName(user.getName());
dto.setWxEnterpriseId(wxEnterpriseId);
dto.setStatusFlag(1);
dto.setDepartmentId(tabDepartment.getDepartmentId());
dto.setNationCode("86");
dto.setStaffName(user.getName());
staffDepartmentRelatedService.add(dto);
}
}
}
}
} else {
WxEnterpriseDTO enterpriseDTO = wxEnterpriseService.selectById(wxEnterpriseId);
if (enterpriseDTO != null) {
SecretSettingDTO secretSetting = secretSettingService.getSecretSetting(enterpriseDTO.getWxEnterpriseId(), SecretTypeEnum.CONTACT_SECRET.getVal());
if (null == secretSetting || secretSetting.getCheckFlag() == 0) {
logger.info("没有设置通讯录secret");
return;
}
UserDTO user = qywxUserApiService.getSelfWorkWxUser(enterpriseDTO.getCorpid(), secretSetting.getSecretVal(), userId);
logger.info("【修改用户】user={}", JSON.toJSONString(user));
Integer[] departmentId = user.getDepartment();
String departmentIds = "";
for (Integer integer : departmentId) {
TabHaobanDepartment tabDepartment = departmentService.getByWxId(integer.toString(), wxEnterpriseId);
if (tabDepartment != null) {
departmentIds += tabDepartment.getDepartmentId() + ",";
}
}
if (StringUtils.isNotBlank(departmentIds)) {
departmentIds = departmentIds.substring(0, departmentIds.length() - 1);
}
StaffDTO staffDTO = EntityUtil.changeEntityByJSON(StaffDTO.class, staff);
staffDTO.setWeixinPush(true);
if (StringUtils.isBlank(staffDTO.getPhoneNumber())) {
staffDTO.setPhoneNumber(user.getMobile());
staffDTO.setSex(StringUtils.isBlank(user.getGender()) ? null : Integer.parseInt(user.getGender()));
staffDTO.setHeadImg(user.getAvatar());
staffDTO.setPostion(user.getPosition());
staffDTO.setNickName(user.getAlias());
staffDTO.setExtendPostion(user.getExternal_position());
Integer status = user.getStatus();
if (status != null && status == 2) {
staffDTO.setActiveFlag(1);
}
}
this.staffEdit(staffDTO, departmentIds);
//String staffId = staffService.add(tab);
}
}
}
@Override
public void wxFristAdd(String userJson, String wxEnterpriseId) {
if (StringUtils.isBlank(userJson)) {
......@@ -671,7 +571,6 @@ public class StaffApiServiceImpl implements StaffApiService {
WxEnterpriseDTO enterpriseDTO = wxEnterpriseService.selectById(wxEnterpriseId);
if (enterpriseDTO != null) {
Date now = new Date();
//UserDTO user = qywxUserApiService.getSelfWorkWxUser(enterpriseDTO.getCorpid(), enterpriseDTO.getContactSecret(), userId);
logger.info("【新增用户】user={}", JSON.toJSONString(user));
TabHaobanStaff tab = new TabHaobanStaff();
tab.setWxUserId(userId);
......@@ -691,7 +590,6 @@ public class StaffApiServiceImpl implements StaffApiService {
user.setAlias(EmojiFilterUtil.removeAllEmoji(user.getAlias()));
tab.setNickName((user.getAlias()));
}
// tab.setNickName(user.getAlias());
tab.setNationCode("86");
tab.setSex(user.getGender() == null ? 1 : Integer.parseInt(user.getGender()));
tab.setActiveFlag(1);
......@@ -702,7 +600,7 @@ public class StaffApiServiceImpl implements StaffApiService {
} else {
tab.setActiveFlag(0);
}
String staffId = staffService.add(tab);
staffService.add(tab);
}
} else {
WxEnterpriseDTO enterpriseDTO = wxEnterpriseService.selectById(wxEnterpriseId);
......@@ -783,7 +681,8 @@ public class StaffApiServiceImpl implements StaffApiService {
}
Boolean weixinPush = staffDTO.getWeixinPush();
if (weixinPush == null || !weixinPush) {
updateWxMessage(oldStaff, staffDTO, departmentIds);
//不需要推送到企微
//updateWxMessage(oldStaff, staffDTO, departmentIds);
}
}
......
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