Commit e6f99e63 by 墨竹

Merge branch 'fixbug_0720' into developer

# Conflicts:
#	haoban-manage3-service/src/main/java/com/gic/haoban/manage/service/config/Config.java
parents 8e43079d c013095c
...@@ -26,9 +26,11 @@ public class Config { ...@@ -26,9 +26,11 @@ public class Config {
private String historyMbrMassOperWhiteList; private String historyMbrMassOperWhiteList;
@Value("${qywx_member_suite}") @Value("${qywx_member_suite}")
private String qywxMemberSuite; private String qywxMemberSuite;
@Value("${staff_third_wx_enterpriseId}")
private String staffThirdWxEnterpriseId;
@Value("${hm_link_url}") @Value("${hm_link_url}")
private String hmLinkUrl; private String hmLinkUrl;
public String getHmLinkUrl() { public String getHmLinkUrl() {
return hmLinkUrl; return hmLinkUrl;
} }
...@@ -100,4 +102,12 @@ public class Config { ...@@ -100,4 +102,12 @@ public class Config {
public void setQywxMemberSuite(String qywxMemberSuite) { public void setQywxMemberSuite(String qywxMemberSuite) {
this.qywxMemberSuite = qywxMemberSuite; this.qywxMemberSuite = qywxMemberSuite;
} }
public String getStaffThirdWxEnterpriseId() {
return staffThirdWxEnterpriseId;
}
public void setStaffThirdWxEnterpriseId(String staffThirdWxEnterpriseId) {
this.staffThirdWxEnterpriseId = staffThirdWxEnterpriseId;
}
} }
...@@ -131,6 +131,15 @@ public class MessageApiServiceImpl implements MessageApiService { ...@@ -131,6 +131,15 @@ public class MessageApiServiceImpl implements MessageApiService {
QywxCallBackDTO dto = JSON.parseObject(param, QywxCallBackDTO.class); QywxCallBackDTO dto = JSON.parseObject(param, QywxCallBackDTO.class);
log.info("【成员部门同步回调处理】dto={}", JSON.toJSONString(param)); log.info("【成员部门同步回调处理】dto={}", JSON.toJSONString(param));
String suiteId = dto.getSuiteId(); String suiteId = dto.getSuiteId();
String staffThirdWxEnterpriseId = config.getStaffThirdWxEnterpriseId();
if (staffThirdWxEnterpriseId.contains(suiteId)) {
//处理部门
dealQywxThirdDepartment(dto);
//处理成员
dealQywxThirdUser(dto);
return;
}
if (!SELF_APP.equals(suiteId)) { if (!SELF_APP.equals(suiteId)) {
log.info("通讯录只处理自建应用回调 dto={}", JSON.toJSONString(param)); log.info("通讯录只处理自建应用回调 dto={}", JSON.toJSONString(param));
return; return;
...@@ -602,4 +611,217 @@ public class MessageApiServiceImpl implements MessageApiService { ...@@ -602,4 +611,217 @@ public class MessageApiServiceImpl implements MessageApiService {
return corpid.length() > 20 ? tabHaobanStaff.getWxOpenUseId() : tabHaobanStaff.getWxUserId(); return corpid.length() > 20 ? tabHaobanStaff.getWxOpenUseId() : tabHaobanStaff.getWxUserId();
} }
/**
* 处理企业通讯录成员
*
* @param qywxCallBackDTO
*/
private void dealQywxThirdUser(QywxCallBackDTO qywxCallBackDTO) {
String userid = qywxCallBackDTO.getUserid();
log.info("成员同步开始:userid:{}", userid);
if (StringUtils.isBlank(userid)) {
log.info("成员为空");
return;
}
String corpId = qywxCallBackDTO.getAuthCorpId();
TabHaobanWxApplication wxApplication = wxApplicationService.selectByCorpId(corpId);
if (Objects.isNull(wxApplication)) {
log.info("授权企业不存在,{}", corpId);
return;
}
String wxEnterpriseId = wxApplication.getWxEnterpriseId();
String changeType = qywxCallBackDTO.getChangeType();
if (changeType.equals(WxEditType.ADD_USER.getCode())) {
log.info("成员同步新增,userid:{}", userid);
//新增
this.staffApiService.wxGetAdd(userid, wxEnterpriseId);
} else if (changeType.equals(WxEditType.UPDATE_USER.getCode())) {
log.info("成员同步修改,userid:{}", userid);
//修改
TabHaobanStaff oldStaff = this.staffService.selectByUserIdAndEnterpriseId(userid, wxEnterpriseId);
if (oldStaff == null) {
log.error("成员同步更新失败,无历史员工数据:userid:{},wxEnterpriseId:{}", userid, wxEnterpriseId);
return;
}
TabHaobanStaff staff = new TabHaobanStaff();
staff.setStaffId(oldStaff.getStaffId());
staff.setPhoneNumber(qywxCallBackDTO.getMobile());
staff.setNickName(qywxCallBackDTO.getAlias());
staff.setSex(qywxCallBackDTO.getGender());
staff.setStaffName(qywxCallBackDTO.getUserName());
staff.setWxUserId(userid);
staff.setPostion(qywxCallBackDTO.getPosition());
if (StringUtils.isNotBlank(qywxCallBackDTO.getAvatar())) {
staff.setHeadImg(changeHeaderImageUrl(qywxCallBackDTO.getAvatar()));
}
staff.setNationCode("86");
//激活状态
if (qywxCallBackDTO.getStatus() != null && qywxCallBackDTO.getStatus() == 1) {
staff.setActiveFlag(1);
}
String[] departArr = qywxCallBackDTO.getDepartment();
StringBuilder departmentIds = new StringBuilder();
//部门修改了
if (departArr != null) {
for (String s : departArr) {
TabHaobanDepartment department = this.departmentService.getByWxId(s, wxEnterpriseId);
if (department == null) {
log.info("成员同步,部门不存在");
continue;
}
departmentIds.append(department.getDepartmentId()).append(",");
}
departmentIds = new StringBuilder(departmentIds.substring(0, departmentIds.length() - 1));
} else {
//部门没有修改
List<TabHaobanStaffDepartmentRelated> list = staffDepartmentRelatedService.listStaffDepartmentByStaffId(staff.getStaffId());
for (TabHaobanStaffDepartmentRelated tabHaobanStaffDepartmentRelated : list) {
departmentIds.append(tabHaobanStaffDepartmentRelated.getDepartmentId()).append(",");
}
departmentIds = new StringBuilder(departmentIds.substring(0, departmentIds.length() - 1));
}
StaffDTO staffDTO = EntityUtil.changeEntityByJSON(StaffDTO.class, staff);
staffApiService.staffEdit(staffDTO, departmentIds.toString());
} else if (changeType.equals(WxEditType.DELETE_USER.getCode())) {
log.info("成员同步删除,userid:{}", userid);
SecretSettingDTO secretSetting = secretSettingService.getSecretSetting(wxEnterpriseId, SecretTypeEnum.HAOBAN_HELP.getVal());
if (null == secretSetting || secretSetting.getCheckFlag() == 0) {
log.info("没有配置secret,wxEnterpriseId:{}", wxEnterpriseId);
return;
}
UserDTO user = qywxUserApiService.getSelfWorkWxUser(corpId, secretSetting.getSecretVal(), userid);
if (null != user) {
Integer status = user.getStatus();
// 1=已激活,2=已禁用,4=未激活,5=退出企业。
log.info("企业微信用户状态:{}",status);
if (status == 1) {
log.info("企业微信用户存在,并且已激活无需删除:{}:{}", wxEnterpriseId, userid);
return;
}
}
//删除
TabHaobanStaff oldStaff = this.staffService.selectByUserIdAndEnterpriseId(userid, wxEnterpriseId);
if (oldStaff == null) {
log.info("微信成员同步删除的门店不存在,{}", userid);
return;
}
String staffId = oldStaff.getStaffId();
//销毁卡券
innerApiService.delCardByStaffId(staffId);
//删除导购好友关联关系表
this.staffDepartmentRelatedService.delByUserid(userid);
//删除员工表
this.staffService.delByStaffId(staffId);
//员工解绑
List<StaffClerkRelationDTO> staffClerkRelationDTOS = staffClerkRelationApiService.listByStaffId(wxEnterpriseId, staffId);
if (CollectionUtils.isNotEmpty(staffClerkRelationDTOS)) {
for (StaffClerkRelationDTO staffClerkRelationDTO : staffClerkRelationDTOS) {
staffClerkRelationApiService.unbindByStaffAndClerkId(staffId,staffClerkRelationDTO.getClerkId());
}
}
}
log.error("成员同步结束");
}
/**
* 处理部门
*
* @param qywxCallBackDTO
*/
private void dealQywxThirdDepartment(QywxCallBackDTO qywxCallBackDTO) {
log.info("处理部门start:{}", JSON.toJSONString(qywxCallBackDTO));
Integer wxDeptId = qywxCallBackDTO.getId();
if (wxDeptId == null) {
log.info("部门为空");
return;
}
String authCorpId = qywxCallBackDTO.getAuthCorpId();
DepartmentDTO departmentDTO = new DepartmentDTO();
departmentDTO.setIsStore(0);
TabHaobanWxApplication wxApplication = wxApplicationService.selectByCorpId(authCorpId);
if (Objects.isNull(wxApplication)) {
log.info("授权企业不存在,{}", qywxCallBackDTO.getAuthCorpId());
return;
}
String wxEnterpriseId = wxApplication.getWxEnterpriseId();
SecretSettingDTO secretSetting = secretSettingService.getSecretSetting(wxEnterpriseId, SecretTypeEnum.HAOBAN_HELP.getVal());
if (null == secretSetting || secretSetting.getCheckFlag() == 0) {
log.info("没有配置secret:{}", wxEnterpriseId);
return;
}
String secret = secretSetting.getSecretVal();
TabHaobanDepartment parentDepartment = new TabHaobanDepartment();
if (qywxCallBackDTO.getParentId() != null) {
parentDepartment = this.departmentService.getByWxId(qywxCallBackDTO.getParentId() + "", wxEnterpriseId);
} else {
TabHaobanDepartment oldDepartment = this.departmentService.getByWxId(wxDeptId + "", wxEnterpriseId);
if (oldDepartment != null) {
parentDepartment = departmentService.selectById(oldDepartment.getParentDepartmentId());
}
}
String changeType = qywxCallBackDTO.getChangeType();
if (!changeType.equals(WxEditType.DELETE_DEPART.getCode())) {
if (parentDepartment == null) {
log.info("企微同步父部门不存在");
return;
}
com.gic.wechat.api.dto.qywx.DepartmentDTO deptDetail = qywxDepartmentApiService.getSelfDepartmentById(authCorpId, secret, wxDeptId);
departmentDTO.setDepartmentName(deptDetail.getName());
departmentDTO.setParentDepartmentId(parentDepartment.getDepartmentId());
departmentDTO.setChainId(parentDepartment.getChainId() + Constant.ID_SEPARATOR + parentDepartment.getDepartmentId());
departmentDTO.setChainName(parentDepartment.getChainName() + parentDepartment.getChainName());
departmentDTO.setLevel(parentDepartment.getLevel() + 1);
}
departmentDTO.setWxEnterpriseId(wxEnterpriseId);
departmentDTO.setWxDepartmentId(wxDeptId + "");
if (qywxCallBackDTO.getParentId() != null) {
List<com.gic.wechat.api.dto.qywx.DepartmentDTO> list = this.qywxDepartmentApiService.listSelfDepartment(authCorpId, secret, qywxCallBackDTO.getParentId());
if (CollectionUtils.isNotEmpty(list)) {
for (com.gic.wechat.api.dto.qywx.DepartmentDTO wxDepartmentDTO : list) {
if (Convert.toStr(wxDepartmentDTO.getId()).equals(departmentDTO.getDepartmentId())) {
departmentDTO.setSort(qywxCallBackDTO.getOrder());
} else {
TabHaobanDepartment tab = this.departmentService.getByWxId(wxDepartmentDTO.getId() + "", wxEnterpriseId);
if (tab != null) {
tab.setSort(wxDepartmentDTO.getOrder());
this.departmentService.edit(EntityUtil.changeEntityByJSON(DepartmentDTO.class, tab));
}
}
}
}
}
if (changeType.equals(WxEditType.ADD_DEPART.getCode())) {
log.info("企微新增部门同步");
this.departmentService.add(departmentDTO);
} else if (changeType.equals(WxEditType.UPDATE_DEPART.getCode())) {
log.info("企微修改部门同步");
TabHaobanDepartment department = this.departmentService.getByWxId(wxDeptId + "", wxEnterpriseId);
if (department == null) {
String response = this.departmentService.add(departmentDTO);
log.info("企微同步新增部门:{}", JSON.toJSONString(response));
} else {
departmentDTO.setIsStore(department.getIsStore());
departmentDTO.setDepartmentId(department.getDepartmentId());
this.departmentService.edit(departmentDTO);
log.info("企微修改部门同步完成");
}
} else if (changeType.equals(WxEditType.DELETE_DEPART.getCode())) {
log.info("企微删除部门同步");
TabHaobanDepartment department = this.departmentService.getByWxId(wxDeptId + "", wxEnterpriseId);
if (department == null) {
log.info("企微同步删除部门不存在");
} else {
this.departmentService.del(department.getDepartmentId());
log.info("企微删除部门同步完成");
}
}
RedisUtil.delLocalCache("department-list-cache-" + wxEnterpriseId);
log.info("处理部门end:{}", JSON.toJSONString(qywxCallBackDTO));
}
} }
...@@ -29,6 +29,7 @@ import com.gic.haoban.common.utils.UuidUtil; ...@@ -29,6 +29,7 @@ import com.gic.haoban.common.utils.UuidUtil;
import com.gic.haoban.manage.api.dto.*; import com.gic.haoban.manage.api.dto.*;
import com.gic.haoban.manage.api.enums.SecretTypeEnum; import com.gic.haoban.manage.api.enums.SecretTypeEnum;
import com.gic.haoban.manage.api.service.StaffApiService; 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.StaffDepartmentRelatedMapper;
import com.gic.haoban.manage.service.dao.mapper.StaffMapper; import com.gic.haoban.manage.service.dao.mapper.StaffMapper;
import com.gic.haoban.manage.service.entity.*; import com.gic.haoban.manage.service.entity.*;
...@@ -102,6 +103,8 @@ public class StaffApiServiceImpl implements StaffApiService { ...@@ -102,6 +103,8 @@ public class StaffApiServiceImpl implements StaffApiService {
private StoreRangeService storeRangeService; private StoreRangeService storeRangeService;
@Autowired @Autowired
private EnterpriseService enterpriseService; private EnterpriseService enterpriseService;
@Autowired
private Config config;
@Override @Override
public StaffDTO selectById(String staffId) { public StaffDTO selectById(String staffId) {
...@@ -314,18 +317,26 @@ public class StaffApiServiceImpl implements StaffApiService { ...@@ -314,18 +317,26 @@ public class StaffApiServiceImpl implements StaffApiService {
res.setCode(4); res.setCode(4);
return res; return res;
} }
UserDTO user = qywxUserApiService.getSelfWorkWxUser(corpid, secretSetting.getSecretVal(), userId);
String staffThirdWxEnterpriseId = config.getStaffThirdWxEnterpriseId();
UserDTO user = null;
if (staffThirdWxEnterpriseId.contains(corpid)) {
user = qywxUserApiService.getWorkWxUser(corpid, config.getWxSuiteid(), userId);
} else {
user = qywxUserApiService.getSelfWorkWxUser(corpid, secretSetting.getSecretVal(), userId);
}
if (null == user) { if (null == user) {
logger.info("企业微信用户不存在:{}:{}", wxEnterpriseId, userId); logger.info("企业微信用户不存在:{}:{}", wxEnterpriseId, userId);
res.setMessage("企业微信用户不存在"); res.setMessage("企业微信用户不存在");
res.setCode(3); res.setCode(3);
return res; return res;
} }
String nationCode = null ; String nationCode = null;
String phoneNumber = null; String phoneNumber = null;
String imageUrl = changeHeaderImageUrl(user.getAvatar()); String imageUrl = changeHeaderImageUrl(user.getAvatar());
String mobile = user.getMobile(); String mobile = user.getMobile();
if(StringUtils.isNotBlank(mobile)) { if (StringUtils.isNotBlank(mobile)) {
String[] arr = getNationCodeAndPhoneNumber(mobile); String[] arr = getNationCodeAndPhoneNumber(mobile);
nationCode = arr[0]; nationCode = arr[0];
phoneNumber = arr[1]; phoneNumber = arr[1];
...@@ -899,7 +910,7 @@ public class StaffApiServiceImpl implements StaffApiService { ...@@ -899,7 +910,7 @@ public class StaffApiServiceImpl implements StaffApiService {
return Collections.emptyList(); return Collections.emptyList();
} }
List<String> unBindList = clerkList.stream().filter(clerkId -> !clerkIds.contains(clerkId)).collect(Collectors.toList()); List<String> unBindList = clerkList.stream().filter(clerkId -> !clerkIds.contains(clerkId)).collect(Collectors.toList());
logger.info("未绑定导购id:{}",JSON.toJSONString(unBindList)); logger.info("未绑定导购id:{}", JSON.toJSONString(unBindList));
return unBindList; return unBindList;
} }
...@@ -1330,7 +1341,7 @@ public class StaffApiServiceImpl implements StaffApiService { ...@@ -1330,7 +1341,7 @@ public class StaffApiServiceImpl implements StaffApiService {
Object cache = RedisUtil.getCache(cacheKey); Object cache = RedisUtil.getCache(cacheKey);
if (cache != null) { if (cache != null) {
List<String> storeList = (List<String>) cache; List<String> storeList = (List<String>) cache;
logger.info("从缓存中获取通道={},数量:{}", cacheKey,storeList.size()); logger.info("从缓存中获取通道={},数量:{}", cacheKey, storeList.size());
return storeList; return storeList;
} }
ClerkDTO clerkDTO = clerkService.getClerkByClerkId(clerkId); ClerkDTO clerkDTO = clerkService.getClerkByClerkId(clerkId);
...@@ -1376,7 +1387,7 @@ public class StaffApiServiceImpl implements StaffApiService { ...@@ -1376,7 +1387,7 @@ public class StaffApiServiceImpl implements StaffApiService {
} }
@Override @Override
public List<String> getHaoBanStoreRolesByStoreWidgetId(String storeWidgetId,String wxEnterpriseId, String enterpriseId) { public List<String> getHaoBanStoreRolesByStoreWidgetId(String storeWidgetId, String wxEnterpriseId, String enterpriseId) {
return getStoreWidgetIdStoreIds(storeWidgetId, enterpriseId); return getStoreWidgetIdStoreIds(storeWidgetId, enterpriseId);
} }
......
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