Commit 428a9f2d by 墨竹

fix:改为分批

parent 0682cfd8
...@@ -138,12 +138,12 @@ public class QywxClerkSyncOperation implements BaseSyncOperation { ...@@ -138,12 +138,12 @@ public class QywxClerkSyncOperation implements BaseSyncOperation {
// 每1秒产生5个令牌 // 每1秒产生5个令牌
rateLimiter.trySetRate(RateType.OVERALL, 5, 1, RateIntervalUnit.SECONDS); rateLimiter.trySetRate(RateType.OVERALL, 5, 1, RateIntervalUnit.SECONDS);
int pageNum = 1; int pageNum = 1;
while (true){ while (true) {
// 获取令牌 // 获取令牌
rateLimiter.acquire(); rateLimiter.acquire();
//企微转换最多支持1000个 //企微转换最多支持1000个
//批量处理wx_user_id to wx_open_user_id //批量处理wx_user_id to wx_open_user_id
Page<StaffDTO> staffDTOPageInfo = pageStaffListByWxEnterpriseId(wxEnterpriseId,pageNum,1000); Page<StaffDTO> staffDTOPageInfo = staffApiService.listUserIdByWxEnterpriseId(wxEnterpriseId, pageNum, 1000);
List<StaffDTO> staffDTOS = staffDTOPageInfo.getResult(); List<StaffDTO> staffDTOS = staffDTOPageInfo.getResult();
if (CollectionUtils.isEmpty(staffDTOS)) { if (CollectionUtils.isEmpty(staffDTOS)) {
logger.info("转换完成,为最后一个"); logger.info("转换完成,为最后一个");
...@@ -166,7 +166,7 @@ public class QywxClerkSyncOperation implements BaseSyncOperation { ...@@ -166,7 +166,7 @@ public class QywxClerkSyncOperation implements BaseSyncOperation {
private Page<StaffDTO> pageStaffListByWxEnterpriseId(String wxEnterpriseId, Integer pageNum, Integer pageSize) { private Page<StaffDTO> pageStaffListByWxEnterpriseId(String wxEnterpriseId, Integer pageNum, Integer pageSize) {
return staffApiService.listUserIdByWxEnterpriseId(wxEnterpriseId,pageNum,pageSize); return staffApiService.listUserIdByWxEnterpriseId(wxEnterpriseId, pageNum, pageSize);
} }
......
...@@ -17,6 +17,9 @@ import com.gic.wechat.api.service.qywx.QywxSuiteApiService; ...@@ -17,6 +17,9 @@ import com.gic.wechat.api.service.qywx.QywxSuiteApiService;
import com.gic.wechat.api.service.qywx.QywxUserApiService; import com.gic.wechat.api.service.qywx.QywxUserApiService;
import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.redisson.api.RRateLimiter;
import org.redisson.api.RateIntervalUnit;
import org.redisson.api.RateType;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
...@@ -219,7 +222,7 @@ public class TestController extends WebBaseController { ...@@ -219,7 +222,7 @@ public class TestController extends WebBaseController {
if (wxEnterpriseDTO == null) { if (wxEnterpriseDTO == null) {
return resultResponse(HaoBanErrCode.ERR_10012); return resultResponse(HaoBanErrCode.ERR_10012);
} }
wxEnterpriseApiService.agreeExternalUseridFlag(wxEnterpriseDTO.getWxEnterpriseId(),1); wxEnterpriseApiService.agreeExternalUseridFlag(wxEnterpriseDTO.getWxEnterpriseId(), 1);
return resultResponse(HaoBanErrCode.ERR_1); return resultResponse(HaoBanErrCode.ERR_1);
} else { } else {
return resultResponse(HaoBanErrCode.ERR_0); return resultResponse(HaoBanErrCode.ERR_0);
...@@ -249,15 +252,27 @@ public class TestController extends WebBaseController { ...@@ -249,15 +252,27 @@ public class TestController extends WebBaseController {
*/ */
@RequestMapping("/useridToOpenuserid") @RequestMapping("/useridToOpenuserid")
public HaobanResponse useridToOpenuserid(String corpid, String suiteId, String wxEnterpriseId) { public HaobanResponse useridToOpenuserid(String corpid, String suiteId, String wxEnterpriseId) {
//批量处理wx_user_id to wx_open_user_id // 限流器
List<StaffDTO> staffDTOS = staffApiService.listUserIdByWxEnterpriseId(wxEnterpriseId); RRateLimiter rateLimiter = RedisUtil.getRedisClient().getRateLimiter("haoban:manage3:updateWxOpenUserId:limit");
logger.info("useridToOpenuserid请求:corpid:{}", corpid); // 每1秒产生5个令牌
List<QywxNewUseridDTO> qywxNewUseridDTOS = qywxUserApiService.useridToOpenuserid(corpid, suiteId, staffDTOS.stream().map(StaffDTO::getWxUserId).collect(Collectors.toList())); rateLimiter.trySetRate(RateType.OVERALL, 5, 1, RateIntervalUnit.SECONDS);
if (CollectionUtils.isNotEmpty(qywxNewUseridDTOS)) { int pageNum = 1;
for (QywxNewUseridDTO qywxNewUseridDTO : qywxNewUseridDTOS) { while (true) {
staffApiService.updateOpenUserIdsByUserId(wxEnterpriseId, qywxNewUseridDTO.getUserid(), qywxNewUseridDTO.getOpen_userid()); rateLimiter.acquire();
//批量处理wx_user_id to wx_open_user_id
Page<StaffDTO> staffDTOPageInfo = staffApiService.listUserIdByWxEnterpriseId(wxEnterpriseId, pageNum, 1000);
List<StaffDTO> staffDTOS = staffDTOPageInfo.getResult();
if (CollectionUtils.isEmpty(staffDTOS)) {
break;
}
logger.info("useridToOpenuserid请求:corpid:{}", corpid);
List<QywxNewUseridDTO> qywxNewUseridDTOS = qywxUserApiService.useridToOpenuserid(corpid, suiteId, staffDTOS.stream().map(StaffDTO::getWxUserId).collect(Collectors.toList()));
if (CollectionUtils.isNotEmpty(qywxNewUseridDTOS)) {
for (QywxNewUseridDTO qywxNewUseridDTO : qywxNewUseridDTOS) {
staffApiService.updateOpenUserIdsByUserId(wxEnterpriseId, qywxNewUseridDTO.getUserid(), qywxNewUseridDTO.getOpen_userid());
}
} }
} }
return resultResponse(HaoBanErrCode.ERR_1, qywxNewUseridDTOS); return resultResponse(HaoBanErrCode.ERR_1);
} }
} }
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