REQ-3282: 删除无用job

This commit is contained in:
yanglin 2024-12-23 15:12:30 +08:00
parent cf49ffb856
commit 25b1226d87
3 changed files with 5 additions and 167 deletions

View File

@ -21,6 +21,11 @@
</properties> </properties>
<dependencies> <dependencies>
<dependency>
<groupId>cn.axzo.org</groupId>
<artifactId>org-api</artifactId>
<version>1.0.0-SNAPSHOT</version>
</dependency>
<dependency> <dependency>
<groupId>com.alibaba</groupId> <groupId>com.alibaba</groupId>
<artifactId>druid</artifactId> <artifactId>druid</artifactId>

View File

@ -8,7 +8,6 @@ import cn.axzo.im.channel.netease.dto.RevokeMessageRequest;
import cn.axzo.im.job.CreateMessageHistoryJob; import cn.axzo.im.job.CreateMessageHistoryJob;
import cn.axzo.im.job.ExpungeImTaskJob; import cn.axzo.im.job.ExpungeImTaskJob;
import cn.axzo.im.job.RevokeAllMessagesJob; import cn.axzo.im.job.RevokeAllMessagesJob;
import cn.axzo.im.job.UpdateImAccountOuIdJob;
import cn.axzo.im.service.AccountRegisterService; import cn.axzo.im.service.AccountRegisterService;
import cn.azxo.framework.common.model.CommonResponse; import cn.azxo.framework.common.model.CommonResponse;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
@ -29,7 +28,6 @@ public class PrivateController {
private final NimClient nimClient; private final NimClient nimClient;
private final RevokeAllMessagesJob revokeAllMessagesJob; private final RevokeAllMessagesJob revokeAllMessagesJob;
private final UpdateImAccountOuIdJob updateImAccountOuIdJob;
private final AccountRegisterService accountRegisterService; private final AccountRegisterService accountRegisterService;
private final CreateMessageHistoryJob createMessageHistoryJob; private final CreateMessageHistoryJob createMessageHistoryJob;
private final MessageController messageController; private final MessageController messageController;
@ -55,11 +53,6 @@ public class PrivateController {
return revokeAllMessagesJob.execute(param); return revokeAllMessagesJob.execute(param);
} }
@PostMapping("/private/im-account/ou-id/update")
public Object updateImAccountOuId(@RequestBody UpdateImAccountOuIdJob.UpdateImAccountOuIdParam param) throws Exception {
return updateImAccountOuIdJob.execute(JSONObject.toJSONString(param));
}
@PostMapping("/private/account-register/page") @PostMapping("/private/account-register/page")
public Object pageAccountRegister(@RequestBody AccountRegisterService.PageAccountRegisterParam param) throws Exception { public Object pageAccountRegister(@RequestBody AccountRegisterService.PageAccountRegisterParam param) throws Exception {
return accountRegisterService.page(param); return accountRegisterService.page(param);

View File

@ -1,160 +0,0 @@
package cn.axzo.im.job;
import cn.axzo.basics.common.constant.enums.OrganizationalUnitTypeEnum;
import cn.axzo.im.center.common.enums.AccountTypeEnum;
import cn.axzo.im.center.common.enums.AppTypeEnum;
import cn.axzo.im.entity.AccountRegister;
import cn.axzo.im.service.AccountRegisterService;
import cn.axzo.maokai.api.client.OrganizationalUnitApi;
import cn.axzo.maokai.api.vo.request.OrganizationalUnitQuery;
import cn.axzo.maokai.api.vo.response.OrganizationalUnitVO;
import cn.axzo.tyr.client.feign.TyrSaasRoleUserApi;
import cn.axzo.tyr.client.model.roleuser.dto.SaasRoleUserDTO;
import cn.axzo.tyr.client.model.roleuser.req.RoleUserParam;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.google.common.collect.Lists;
import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.handler.IJobHandler;
import com.xxl.job.core.handler.annotation.XxlJob;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;
/**
* 把appType = CMPaccountType = 'user'的账号的ouId更新成用户最后加入的企业id
* 因为用户在管理版的IM云信消息要按照企业隔离历史的账号是跟企业没绑定要保持数据不丢失
*/
@Slf4j
@Component
@RequiredArgsConstructor
public class UpdateImAccountOuIdJob extends IJobHandler {
@Autowired
private AccountRegisterService accountRegisterService;
@Autowired
private TyrSaasRoleUserApi tyrSaasRoleUserApi;
@Autowired
private OrganizationalUnitApi organizationalUnitApi;
private static final Integer DEFAULT_PAGE_SIZE = 500;
@Override
@XxlJob("updateImAccountOuIdJob")
public ReturnT<String> execute(String s) throws Exception {
log.info("start updateImAccountOuIdJob,s:{}", s);
UpdateImAccountOuIdParam updateImAccountOuIdParam = Optional.ofNullable(s)
.map(e -> JSONObject.parseObject(e, UpdateImAccountOuIdParam.class))
.orElseGet(() -> UpdateImAccountOuIdParam.builder().build());
Integer pageNumber = 1;
while (true) {
AccountRegisterService.PageAccountRegisterParam req = AccountRegisterService.PageAccountRegisterParam.builder()
.ids(updateImAccountOuIdParam.getIds())
.appType(AppTypeEnum.CMP.getCode())
.accountType(AccountTypeEnum.USER.getCode())
.accountWrapperEW("cmp")
.page(pageNumber++)
.pageSize(DEFAULT_PAGE_SIZE)
.build();
Page<AccountRegisterService.AccountRegisterDTO> page = accountRegisterService.page(req);
if (CollectionUtils.isNotEmpty(page.getRecords())) {
Map<String, Long> nodeUsers = listNodeUsers(page.getRecords());
updateAccountRegister(page.getRecords(), nodeUsers);
}
if (!page.hasNext()) {
break;
}
}
log.info("end updateImAccountOuIdJob");
return ReturnT.SUCCESS;
}
private void updateAccountRegister(List<AccountRegisterService.AccountRegisterDTO> accountRegisters, Map<String, Long> nodeUsers) {
List<AccountRegister> update = accountRegisters.stream()
.filter(accountRegister -> nodeUsers.get(accountRegister.getAccountId()) != null)
.map(accountRegister -> {
Long ouId = nodeUsers.get(accountRegister.getAccountId());
if (ouId == null) {
return null;
}
AccountRegister result = new AccountRegister();
result.setId(accountRegister.getId());
result.setOuId(ouId);
result.setUpdateAt(new Date());
return result;
})
.filter(Objects::nonNull)
.collect(Collectors.toList());
if (CollectionUtils.isEmpty(accountRegisters)) {
log.info("updateImAccountOuIdJob: no data update");
return;
}
accountRegisterService.updateBatchById(update);
}
private Map<String, Long> listNodeUsers(List<AccountRegisterService.AccountRegisterDTO> accountRegisters) {
if (CollectionUtils.isEmpty(accountRegisters)) {
return Collections.EMPTY_MAP;
}
Set<Long> accountIds = accountRegisters.stream()
.map(AccountRegister::getAccountId)
.filter(Objects::nonNull)
.filter(StringUtils::isNumeric)
.map(Long::valueOf)
.collect(Collectors.toSet());
if (CollectionUtils.isEmpty(accountIds)) {
return Collections.EMPTY_MAP;
}
List<SaasRoleUserDTO> saasRoleUsers = accountIds.stream()
.flatMap(e -> tyrSaasRoleUserApi.roleUserList(RoleUserParam.builder().personId(e).build()).getData().stream())
.collect(Collectors.toList());
List<Long> ouIds = Lists.transform(saasRoleUsers, SaasRoleUserDTO::getOuId);
if (CollectionUtils.isEmpty(ouIds)) {
return Collections.EMPTY_MAP;
}
Set<Long> effectOuIds = organizationalUnitApi.list(OrganizationalUnitQuery.builder().unitIds(ouIds).build()).getData()
.stream()
.filter(e -> !Objects.equals(e.getType(), OrganizationalUnitTypeEnum.PROJECT_OUT_TEAM.getValue()))
.map(OrganizationalUnitVO::getId)
.collect(Collectors.toSet());
return saasRoleUsers.stream()
.filter(e -> effectOuIds.contains(e.getOuId()))
.collect(Collectors.toMap(e -> e.getNaturalPersonId().toString(), SaasRoleUserDTO::getOuId, (f, s) -> f));
}
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public static class UpdateImAccountOuIdParam {
private List<Long> ids;
}
}