Commit a158089f by 程裕兵

feat:listBoundEmbeddedXcx

parent c6c26678
......@@ -15,6 +15,7 @@
package com.jiejing.fitness.finance.repository.service;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.jiejing.fitness.enums.finance.EmbededXcxEnum;
import com.jiejing.fitness.finance.repository.entity.StudioEmbeddedXcxApply;
import com.jiejing.fitness.finance.repository.mapper.StudioEmbeddedXcxApplyMapper;
import com.jiejing.mbp.MapperRepoService;
......@@ -69,4 +70,12 @@ public class StudioEmbeddedXcxApplyRpService extends
wrapper.in(StudioEmbeddedXcxApply.AUTHORIZER_APP_ID, appIds);
return Optional.ofNullable(this.baseMapper.selectList(wrapper)).orElse(new ArrayList<>(1));
}
public List<StudioEmbeddedXcxApply> listAllInit(String componentAppId, String embeddedAppId) {
QueryWrapper<StudioEmbeddedXcxApply> wrapper = new QueryWrapper<>();
wrapper.eq(StudioEmbeddedXcxApply.COMPONENT_APP_ID, componentAppId);
wrapper.eq(StudioEmbeddedXcxApply.EMBEDDED_APP_ID, embeddedAppId);
wrapper.eq(StudioEmbeddedXcxApply.STATE, EmbededXcxEnum.INIT.getCode());
return Optional.ofNullable(this.baseMapper.selectList(wrapper)).orElse(new ArrayList<>(1));
}
}
......@@ -347,67 +347,23 @@ public class StudioMerchantServiceImpl implements StudioMerchantService {
@Override
public void syncEmbeddedXcx() {
List<AuthXcxInfo> list = this.listBoundAppIds();
if (CollectionUtil.isEmpty(list)) {
return;
}
List<StudioEmbeddedXcxApply> applies = studioEmbeddedXcxApplyRpService.listByAppIds(wxComponentAppId,
embeddedAppId, list.stream().map(AuthXcxInfo::getAppId).collect(Collectors.toList()));
List<StudioEmbeddedXcxApply> applies = studioEmbeddedXcxApplyRpService.listAllInit(wxComponentAppId,
embeddedAppId);
if (CollectionUtil.isEmpty(applies)) {
return;
}
Map<EmbededXcxEnum, List<AuthXcxInfo>> map = list.stream()
.collect(Collectors.groupingBy(e -> EmbededXcxEnum.getByWxCode(Integer.parseInt(e.getStatus()))));
map.keySet().forEach(status -> {
List<AuthXcxInfo> authXcxInfos = map.getOrDefault(status, Lists.newArrayList());
if (CollectionUtil.isEmpty(authXcxInfos)) {
return;
}
List<String> appIds = authXcxInfos.stream().map(AuthXcxInfo::getAppId)
.collect(Collectors.toList());
switch (status) {
case SUCCESS:
List<Long> toSuccessList = StudioEmbeddedXcxConvert.filterAppIds(applies, appIds);
if (CollectionUtil.isEmpty(toSuccessList)) {
break;
}
studioEmbeddedXcxApplyRpService.updateByIds(StudioEmbeddedXcxConvert.toSuccess(null),
toSuccessList);
break;
case CANCEL:
case REFUSE:
case TIMEOUT:
case REVOKE:
List<StudioEmbeddedXcxApply> toFailList = StudioEmbeddedXcxConvert.toFailList(status, applies,
authXcxInfos);
if (CollectionUtil.isEmpty(toFailList)) {
break;
}
studioEmbeddedXcxApplyRpService.updateBatchById(toFailList);
default:
break;
applies.forEach(apply -> {
log.info("start sync embedded xcx {}, {}", apply.getId(), apply.getAuthorizerAppId());
try {
this.doComplete(apply.getId(), apply.getAuthorizerAppId());
} catch (Exception e) {
log.info("fail sync embedded xcx {}, {}", apply.getId(), apply.getAuthorizerAppId(), e);
}
log.info("complete sync embedded xcx {}, {}", apply.getId(), apply.getAuthorizerAppId());
});
}
private List<AuthXcxInfo> listBoundAppIds() {
List<AuthXcxInfo> result = new ArrayList<>();
int num = 100;
for (int start = 0; start < 10; start++) {
HalfScreenXcxAuthVO vo = weXcxService.listEmbeddedXcx(wxComponentAppId, embeddedAppId, start, num);
if (CollectionUtil.isEmpty(vo.getWxaEmbeddedList())) {
break;
}
result.addAll(vo.getWxaEmbeddedList());
}
return result;
}
@Override
public StudioMerchantApplyVO getApply(Long id) {
StudioMerchantApply apply = studioMerchantApplyRpService.getById(id)
......
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