Commit d1a57666 by 墨竹

feat:转换userid

parent 174a1699
...@@ -304,7 +304,6 @@ public interface MemberUnionidRelatedApiService { ...@@ -304,7 +304,6 @@ public interface MemberUnionidRelatedApiService {
MemberUnionidRelatedDTO getById(String memberUnionidRelatedId); MemberUnionidRelatedDTO getById(String memberUnionidRelatedId);
/** /**
* 更新对外联系人id * 更新对外联系人id
* *
...@@ -328,10 +327,13 @@ public interface MemberUnionidRelatedApiService { ...@@ -328,10 +327,13 @@ public interface MemberUnionidRelatedApiService {
/** /**
* 更新新userid corpid mq * 更新新userid corpid mq
* "routerName": "updateNewUseridCorpidMq"
* *
* @param params 参数个数 * @param params 参数个数
* @author mozhu * @author mozhu
* @date 2022-06-30 13:56:27 * @date 2022-06-30 13:56:27
*/ */
void updateNewUseridCorpidMq(String params); void updateNewUseridCorpidMq(String params);
} }
...@@ -626,7 +626,11 @@ public class EnterpriseController extends WebBaseController { ...@@ -626,7 +626,11 @@ public class EnterpriseController extends WebBaseController {
return resultResponse(HaoBanErrCode.ERR_1, bindInfo); return resultResponse(HaoBanErrCode.ERR_1, bindInfo);
} }
/**
* 转换corpid、userid、external_userid
* @param wxEnterpriseId
* @return
*/
@RequestMapping("/updateNewUseridCorpid") @RequestMapping("/updateNewUseridCorpid")
public HaobanResponse updateNewUseridCorpid(String wxEnterpriseId) { public HaobanResponse updateNewUseridCorpid(String wxEnterpriseId) {
ServiceResponse serviceResponse = memberUnionidRelatedApiService.updateNewUseridCorpid(wxEnterpriseId); ServiceResponse serviceResponse = memberUnionidRelatedApiService.updateNewUseridCorpid(wxEnterpriseId);
......
...@@ -92,4 +92,24 @@ public interface MemberUnionidRelatedMapper { ...@@ -92,4 +92,24 @@ public interface MemberUnionidRelatedMapper {
int updateSelfExternalUserIdByOldSelfExternalUserId(@Param("newExternalUserId") String new_external_userid, int updateSelfExternalUserIdByOldSelfExternalUserId(@Param("newExternalUserId") String new_external_userid,
@Param("oldExternalUserId") String external_userid, @Param("oldExternalUserId") String external_userid,
@Param("wxEnterpriseId") String wxEnterpriseId); @Param("wxEnterpriseId") String wxEnterpriseId);
/**
* wx企业id查询数据
*
* @param wxEnterpriseId wx企业标识
* @return {@link List }<{@link MemberUnionidRelated }>
* @author mozhu
* @date 2022-06-30 17:35:50
*/
List<MemberUnionidRelated> listByWxEnterpriseId(@Param("wxEnterpriseId") String wxEnterpriseId);
/**
* 更新外部userid wx企业id
*
* @param wxEnterpriseId wx企业标识
* @return int
* @author mozhu
* @date 2022-06-30 19:36:00
*/
int updateExternalUseridByWxEnterpriseId(String wxEnterpriseId);
} }
\ No newline at end of file
...@@ -29,4 +29,15 @@ public interface WxApplicationMapper { ...@@ -29,4 +29,15 @@ public interface WxApplicationMapper {
* @date 2021-12-21 22:00:54 * @date 2021-12-21 22:00:54
*/ */
TabHaobanWxApplication selectByCorpId(@Param("corpid") String corpid,@Param("applicationType") Integer applicationType); TabHaobanWxApplication selectByCorpId(@Param("corpid") String corpid,@Param("applicationType") Integer applicationType);
/**
* 更新corpid通过id
*
* @param wxApplicationId 天气应用程序id
* @param corpid corpid
* @return int
* @author mozhu
* @date 2022-06-30 19:19:19
*/
int updateCorpidById(@Param("wxApplicationId") String wxApplicationId, @Param("corpid") String corpid);
} }
\ No newline at end of file
...@@ -57,4 +57,19 @@ public interface WxEnterpriseMapper { ...@@ -57,4 +57,19 @@ public interface WxEnterpriseMapper {
* @date 2021-12-30 20:40:59 * @date 2021-12-30 20:40:59
*/ */
int updateExternalFlagById(@Param("externalFlag") Integer externalFlag, @Param("wxEnterpriseId") String wxEnterpriseId); int updateExternalFlagById(@Param("externalFlag") Integer externalFlag, @Param("wxEnterpriseId") String wxEnterpriseId);
/**
* 更新是否转化userid
*
* @param useridFlag userid国旗
* @param corpid corpid
* @param wxEnterpriseId wx企业标识
* @return int
* @author mozhu
* @date 2022-06-30 18:46:44
*/
int updateUseridFlagById(@Param("useridFlag") Integer useridFlag,
@Param("corpid") String corpid,
@Param("wxEnterpriseId") String wxEnterpriseId);
} }
\ No newline at end of file
package com.gic.haoban.manage.service.service; package com.gic.haoban.manage.service.service;
import com.gic.api.base.commons.Page;
import com.gic.haoban.base.api.common.BasePageInfo;
import com.gic.haoban.manage.api.dto.MemberUnionidRelatedDTO; import com.gic.haoban.manage.api.dto.MemberUnionidRelatedDTO;
import com.gic.haoban.manage.service.entity.MemberUnionidRelated; import com.gic.haoban.manage.service.entity.MemberUnionidRelated;
import com.github.pagehelper.PageInfo;
import java.util.List; import java.util.List;
...@@ -78,4 +81,27 @@ public interface MemberUnionRelatedService { ...@@ -78,4 +81,27 @@ public interface MemberUnionRelatedService {
* @date 2022-06-30 16:32:21 * @date 2022-06-30 16:32:21
*/ */
int updateUserIdByWxEnterpriseId(String wxEnterpriseId); int updateUserIdByWxEnterpriseId(String wxEnterpriseId);
/**
* 更新外部userid wx企业id
*
* @param wxEnterpriseId wx企业标识
* @return int
* @author mozhu
* @date 2022-06-30 19:34:27
*/
int updateExternalUseridByWxEnterpriseId(String wxEnterpriseId);
/**
* 分页查询外部联系人id
*
* @param wxEnterpriseId wx企业标识
* @param basePageInfo 基本信息页
* @return {@link Page }<{@link MemberUnionidRelatedDTO }>
* @author mozhu
* @date 2022-06-30 17:34:06
*/
PageInfo<MemberUnionidRelated> listByWxEnterpriseId(String wxEnterpriseId, BasePageInfo basePageInfo);
} }
...@@ -53,4 +53,16 @@ public interface WxEnterpriseService { ...@@ -53,4 +53,16 @@ public interface WxEnterpriseService {
* @return * @return
*/ */
List<TabHaobanWxEnterprise> listAll(); List<TabHaobanWxEnterprise> listAll();
/**
* 更新userid
*
* @param useridFlag userid国旗
* @param corpid corpid
* @param wxEnterpriseId wx企业标识
* @return int
* @author mozhu
* @date 2022-06-30 18:49:31
*/
int updateUseridFlagById(Integer useridFlag, String corpid, String wxEnterpriseId);
} }
package com.gic.haoban.manage.service.service.impl; package com.gic.haoban.manage.service.service.impl;
import com.gic.commons.util.EntityUtil; import com.gic.commons.util.EntityUtil;
import com.gic.haoban.base.api.common.BasePageInfo;
import com.gic.haoban.common.utils.StringUtil; import com.gic.haoban.common.utils.StringUtil;
import com.gic.haoban.manage.api.dto.MemberUnionidRelatedDTO; import com.gic.haoban.manage.api.dto.MemberUnionidRelatedDTO;
import com.gic.haoban.manage.service.dao.mapper.MemberUnionidRelatedMapper; import com.gic.haoban.manage.service.dao.mapper.MemberUnionidRelatedMapper;
import com.gic.haoban.manage.service.entity.MemberUnionidRelated; import com.gic.haoban.manage.service.entity.MemberUnionidRelated;
import com.gic.haoban.manage.service.service.MemberUnionRelatedService; import com.gic.haoban.manage.service.service.MemberUnionRelatedService;
import com.github.pagehelper.Page; import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
...@@ -104,4 +107,16 @@ public class MemberUnionRelatedServiceImpl implements MemberUnionRelatedService ...@@ -104,4 +107,16 @@ public class MemberUnionRelatedServiceImpl implements MemberUnionRelatedService
public int updateUserIdByWxEnterpriseId(String wxEnterpriseId) { public int updateUserIdByWxEnterpriseId(String wxEnterpriseId) {
return mapper.updateUserIdByWxEnterpriseId(wxEnterpriseId); return mapper.updateUserIdByWxEnterpriseId(wxEnterpriseId);
} }
@Override
public int updateExternalUseridByWxEnterpriseId(String wxEnterpriseId) {
return mapper.updateExternalUseridByWxEnterpriseId(wxEnterpriseId);
}
@Override
public PageInfo<MemberUnionidRelated> listByWxEnterpriseId(String wxEnterpriseId, BasePageInfo basePageInfo) {
PageHelper.startPage(basePageInfo);
List<MemberUnionidRelated> memberUnionidRelateds = mapper.listByWxEnterpriseId(wxEnterpriseId);
return new PageInfo<>(memberUnionidRelateds);
}
} }
...@@ -94,4 +94,9 @@ public class WxEnterpriseServiceImpl implements WxEnterpriseService { ...@@ -94,4 +94,9 @@ public class WxEnterpriseServiceImpl implements WxEnterpriseService {
public List<TabHaobanWxEnterprise> listAll() { public List<TabHaobanWxEnterprise> listAll() {
return mapper.listAll(); return mapper.listAll();
} }
@Override
public int updateUseridFlagById(Integer useridFlag, String corpid, String wxEnterpriseId) {
return mapper.updateUseridFlagById(useridFlag, corpid, wxEnterpriseId);
}
} }
...@@ -28,6 +28,7 @@ import com.gic.haoban.app.customer.enums.QywxSyncTaskTypeEnum; ...@@ -28,6 +28,7 @@ import com.gic.haoban.app.customer.enums.QywxSyncTaskTypeEnum;
import com.gic.haoban.app.customer.service.api.service.CustomerApiService; import com.gic.haoban.app.customer.service.api.service.CustomerApiService;
import com.gic.haoban.base.api.common.BasePageInfo; import com.gic.haoban.base.api.common.BasePageInfo;
import com.gic.haoban.base.api.common.ServiceResponse; import com.gic.haoban.base.api.common.ServiceResponse;
import com.gic.haoban.base.api.common.errCode.HaoBanErrCodeCommon;
import com.gic.haoban.common.utils.PageUtil; import com.gic.haoban.common.utils.PageUtil;
import com.gic.haoban.manage.api.constants.Manage3Constants; import com.gic.haoban.manage.api.constants.Manage3Constants;
import com.gic.haoban.manage.api.dto.*; import com.gic.haoban.manage.api.dto.*;
...@@ -1979,24 +1980,65 @@ public class MemberUnionidRelatedApiServiceImpl implements MemberUnionidRelatedA ...@@ -1979,24 +1980,65 @@ public class MemberUnionidRelatedApiServiceImpl implements MemberUnionidRelatedA
return EntityUtil.changeEntityNew(MemberUnionidRelatedDTO.class, memberUnionidRelated); return EntityUtil.changeEntityNew(MemberUnionidRelatedDTO.class, memberUnionidRelated);
} }
@Override @Override
public ServiceResponse updateNewUseridCorpid(String wxEnterpriseId) { public ServiceResponse updateNewUseridCorpid(String wxEnterpriseId) {
String lockKey = "updateNewUseridCorpid_" + wxEnterpriseId;
WxEnterpriseDTO wxEnterpriseDTO = wxEnterpriseService.selectById(wxEnterpriseId); WxEnterpriseDTO wxEnterpriseDTO = wxEnterpriseService.selectById(wxEnterpriseId);
ServiceResponse serviceResponse = new ServiceResponse(); ServiceResponse serviceResponse = new ServiceResponse();
if (wxEnterpriseDTO == null) { if (wxEnterpriseDTO == null) {
serviceResponse.setCode(-1); serviceResponse.setCode(HaoBanErrCodeCommon.ERR_0.getCode());
serviceResponse.setMessage("企微不存在"); serviceResponse.setMessage("企微不存在");
return serviceResponse; return serviceResponse;
} }
if (RedisUtil.isLocked(lockKey)) {
log.info("redis锁,lockKey:{}", lockKey);
String corpName = wxEnterpriseDTO.getCorpName();
serviceResponse.setCode(HaoBanErrCodeCommon.ERR_0.getCode());
serviceResponse.setMessage(corpName + "已经在转换中,请勿重复操作!");
return serviceResponse;
}
SecretSettingDTO secretSetting = secretSettingService.getSecretSetting(wxEnterpriseId, SecretTypeEnum.CUSTOMIZED_APP.getVal()); SecretSettingDTO secretSetting = secretSettingService.getSecretSetting(wxEnterpriseId, SecretTypeEnum.CUSTOMIZED_APP.getVal());
if (secretSetting == null) { if (secretSetting == null) {
serviceResponse.setCode(-1); serviceResponse.setCode(HaoBanErrCodeCommon.ERR_0.getCode());
serviceResponse.setMessage("代开发密钥不存在"); serviceResponse.setMessage("代开发密钥不存在");
return serviceResponse; return serviceResponse;
} }
String corpid = wxEnterpriseDTO.getCorpid(); String corpid = wxEnterpriseDTO.getCorpid();
RedisUtil.lock(lockKey, 2L, TimeUnit.HOURS, 0L);
wxEnterpriseService.updateUseridFlagById(2, null, wxEnterpriseId);
JSONObject jsonObject = new JSONObject();
jsonObject.put("corpid",corpid);
jsonObject.put("wxEnterpriseId",wxEnterpriseId);
jsonObject.put("secret",secretSetting.getSecretVal());
GicMQClient clientInstance = GICMQClientUtil.getClientInstance();
try {
clientInstance.sendMessage("updateNewUseridCorpidMq", jsonObject.toJSONString());
} catch (Exception e) {
log.info("企微转换id发送消息队列异常:{}", e.getMessage(), e);
}
serviceResponse.setCode(HaoBanErrCodeCommon.ERR_1.getCode());
return serviceResponse;
}
@Override
public void updateNewUseridCorpidMq(String params) {
if (StringUtils.isBlank(params)) {
log.error("传入为空");
return;
}
log.info("转换corpid、userid start params:{}",params);
JSONObject jsonObject = JSON.parseObject(params);
String wxEnterpriseId = jsonObject.getString("wxEnterpriseId");
String corpid = jsonObject.getString("corpid");
String secret = jsonObject.getString("secret");
// 限流器 // 限流器
RRateLimiter rateLimiter = RedisUtil.getRedisClient().getRateLimiter("haoban:manage3:updateNewUseridCorpid:limit"); RRateLimiter rateLimiter = RedisUtil.getRedisClient().getRateLimiter("haoban:manage3:updateNewUseridCorpid:limit");
// 每1秒产生5个令牌 // 每1秒产生5个令牌
...@@ -2012,20 +2054,22 @@ public class MemberUnionidRelatedApiServiceImpl implements MemberUnionidRelatedA ...@@ -2012,20 +2054,22 @@ public class MemberUnionidRelatedApiServiceImpl implements MemberUnionidRelatedA
if (CollectionUtil.isEmpty(staffDTOList)) { if (CollectionUtil.isEmpty(staffDTOList)) {
break; break;
} }
pageNum ++;
List<String> stringList = staffDTOList.stream().map(StaffDTO::getWxUserId).distinct().collect(Collectors.toList()); List<String> stringList = staffDTOList.stream().map(StaffDTO::getWxUserId).distinct().collect(Collectors.toList());
List<QywxNewUseridDTO> qywxNewUseridDTOList = qywxUserApiService.getSelfUseridToOpenuserid(corpid, secretSetting.getSecretVal(), stringList); List<QywxNewUseridDTO> qywxNewUseridDTOList = qywxUserApiService.getSelfUseridToOpenuserid(corpid, secret, stringList);
if (CollectionUtils.isEmpty(qywxNewUseridDTOList)) { if (CollectionUtils.isEmpty(qywxNewUseridDTOList)) {
log.error("调用企微无权限"); log.error("调用企微无权限");
continue; continue;
} }
for (QywxNewUseridDTO qywxNewUseridDTO : qywxNewUseridDTOList) { for (QywxNewUseridDTO qywxNewUseridDTO : qywxNewUseridDTOList) {
String userid = qywxNewUseridDTO.getUserid(); String userid = qywxNewUseridDTO.getUserid();
String openUserid = qywxNewUseridDTO.getOpen_userid(); String openUserid = qywxNewUseridDTO.getOpen_userid();
log.info("转换新的userid,userid:{},openUserid:{}",userid,openUserid); log.info("转换新的userid,userid:{},openUserid:{}",userid,openUserid);
staffService.updateUserIdByUserId(wxEnterpriseId,openUserid,userid); staffService.updateUserIdByUserId(wxEnterpriseId,openUserid,userid);
} }
pageNum ++;
} }
//更新导购员工关联关系表 //更新导购员工关联关系表
staffClerkRelationService.updateUserIdByWxEnterpriseId(wxEnterpriseId); staffClerkRelationService.updateUserIdByWxEnterpriseId(wxEnterpriseId);
//更新员工部门关联关系表 //更新员工部门关联关系表
...@@ -2034,16 +2078,40 @@ public class MemberUnionidRelatedApiServiceImpl implements MemberUnionidRelatedA ...@@ -2034,16 +2078,40 @@ public class MemberUnionidRelatedApiServiceImpl implements MemberUnionidRelatedA
memberUnionRelatedService.updateUserIdByWxEnterpriseId(wxEnterpriseId); memberUnionRelatedService.updateUserIdByWxEnterpriseId(wxEnterpriseId);
//更新会员好友关系表 //更新会员好友关系表
externalClerkRelatedService.updateUserIdByWxEnterpriseId(wxEnterpriseId); externalClerkRelatedService.updateUserIdByWxEnterpriseId(wxEnterpriseId);
//更新自建外部联系人id
serviceResponse.setCode(0); memberUnionRelatedService.updateExternalUseridByWxEnterpriseId(wxEnterpriseId);
return serviceResponse; log.info("转换corpid、userid end params:{}",params);
//迁移完成
updateUseridFlagById(wxEnterpriseId,corpid);
} }
@Override /**
public void updateNewUseridCorpidMq(String params) { * 迁移完成
* @param wxEnterpriseId
* @param corpid
*/
private void updateUseridFlagById(String wxEnterpriseId, String corpid) {
String serviceCorpid = config.getCorpid();
String openCorpid = qywxUserApiService.toOpenCorpid(corpid, serviceCorpid);
TabHaobanWxApplication tabHaobanWxApplication = wxApplicationMapper.selectByCorpId(corpid, 3);
if (tabHaobanWxApplication == null) {
log.info("代开发应用不存在:{}",corpid);
return;
}
wxApplicationMapper.updateCorpidById(tabHaobanWxApplication.getWxApplicationId(),openCorpid);
String[] openidType = {"1","3"};
//调用完成接口
boolean flag = qywxUserApiService.finishOpenidMigration(corpid, serviceCorpid, tabHaobanWxApplication.getAgentId(), openidType);
if (flag) {
wxEnterpriseService.updateUseridFlagById(1, openCorpid, wxEnterpriseId);
}else {
wxEnterpriseService.updateUseridFlagById(3, openCorpid, wxEnterpriseId);
}
String lockKey = "updateNewUseridCorpid_" + wxEnterpriseId;
RedisUtil.unlock(lockKey);
} }
/** /**
* 获取客户详情列表 * 获取客户详情列表
* *
......
...@@ -269,4 +269,20 @@ ...@@ -269,4 +269,20 @@
where self_external_userid = #{oldExternalUserId} where self_external_userid = #{oldExternalUserId}
and wx_enterprise_id = #{wxEnterpriseId} and wx_enterprise_id = #{wxEnterpriseId}
</update> </update>
<select id="listByWxEnterpriseId" resultMap="BaseResultMap">
select
<include refid="Base_Column_List"/>
from tab_haoban_member_unionid_related
where wx_enterprise_id = #{wxEnterpriseId}
and status_flag = 1
</select>
<update id="updateExternalUseridByWxEnterpriseId">
UPDATE
tab_haoban_member_unionid_related
SET self_external_userid = external_userid,
update_time = now()
where wx_enterprise_id = #{wxEnterpriseId}
</update>
</mapper> </mapper>
\ No newline at end of file
...@@ -202,4 +202,13 @@ ...@@ -202,4 +202,13 @@
</if> </if>
limit 1 limit 1
</select> </select>
<update id="updateCorpidById">
update tab_haoban_wx_application
set corpid = #{corpId},
update_time = now()
where wx_application_id = #{wxApplicationId}
and status_flag = 1
</update>
</mapper> </mapper>
\ No newline at end of file
...@@ -472,9 +472,18 @@ ...@@ -472,9 +472,18 @@
<update id="updateExternalFlagById"> <update id="updateExternalFlagById">
update tab_haoban_wx_enterprise update tab_haoban_wx_enterprise
set external_flag = #{externalFlag}, set external_flag = #{externalFlag},
update_time = now() update_time = now()
where wx_enterprise_id = #{wxEnterpriseId} where wx_enterprise_id = #{wxEnterpriseId}
</update> </update>
<update id="updateUseridFlagById">
update tab_haoban_wx_enterprise
set userid_flag = #{externalFlag},
<if test="corpid != null">
corpid = #{corpid},
</if>
update_time = now()
where wx_enterprise_id = #{wxEnterpriseId}
</update>
</mapper> </mapper>
\ No newline at end of file
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