feat:feature-REQ/2129 重新修改清洗ouId的逻辑,注册cmp账号时过滤掉ouId = 0的情况

This commit is contained in:
lilong 2024-04-03 17:14:11 +08:00
parent afd0f29c01
commit 1fc56cd565
7 changed files with 51 additions and 22 deletions

View File

@ -112,6 +112,11 @@
<groupId>cn.axzo.im.center</groupId> <groupId>cn.axzo.im.center</groupId>
<artifactId>im-center-api</artifactId> <artifactId>im-center-api</artifactId>
</dependency> </dependency>
<dependency>
<groupId>cn.axzo.tyr</groupId>
<artifactId>tyr-api</artifactId>
</dependency>
</dependencies> </dependencies>
<build> <build>

View File

@ -55,8 +55,8 @@ public class PrivateController {
} }
@PostMapping("/private/im-account/ou-id/update") @PostMapping("/private/im-account/ou-id/update")
public Object updateImAccountOuId(@RequestParam("param") String param) throws Exception { public Object updateImAccountOuId(@RequestBody UpdateImAccountOuIdJob.UpdateImAccountOuIdParam param) throws Exception {
return updateImAccountOuIdJob.execute(param); return updateImAccountOuIdJob.execute(JSONObject.toJSONString(param));
} }
@PostMapping("/private/account-register/page") @PostMapping("/private/account-register/page")

View File

@ -189,6 +189,12 @@ public class MessageTask {
if (StringUtils.isNotBlank(this.getImAccount())) { if (StringUtils.isNotBlank(this.getImAccount())) {
return this.getImAccount(); return this.getImAccount();
} }
// 因为模板消息发给工人端的时候会带ouId
if (appType == AppTypeEnum.CM) {
return this.getPersonId() + "_" + this.getAppType().getCode();
}
return this.getPersonId() + "_" + this.getAppType().getCode() + "_" + this.getOuId(); return this.getPersonId() + "_" + this.getAppType().getCode() + "_" + this.getOuId();
} }
} }

View File

@ -4,9 +4,10 @@ import cn.axzo.im.center.common.enums.AccountTypeEnum;
import cn.axzo.im.center.common.enums.AppTypeEnum; import cn.axzo.im.center.common.enums.AppTypeEnum;
import cn.axzo.im.entity.AccountRegister; import cn.axzo.im.entity.AccountRegister;
import cn.axzo.im.service.AccountRegisterService; import cn.axzo.im.service.AccountRegisterService;
import cn.axzo.maokai.api.client.OrganizationalNodeUserApi; import cn.axzo.tyr.client.feign.TyrSaasRoleUserApi;
import cn.axzo.maokai.api.vo.request.OrganizationalNodeUserBasicQueryVO; import cn.axzo.tyr.client.model.roleuser.dto.SaasRoleUserDTO;
import cn.axzo.maokai.api.vo.response.OrganizationalNodeUserBasicVO; import cn.axzo.tyr.client.model.roleuser.req.RoleUserParam;
import cn.hutool.core.lang.Pair;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xxl.job.core.biz.model.ReturnT; import com.xxl.job.core.biz.model.ReturnT;
@ -30,7 +31,6 @@ import java.util.Map;
import java.util.Objects; import java.util.Objects;
import java.util.Optional; import java.util.Optional;
import java.util.Set; import java.util.Set;
import java.util.function.Function;
import java.util.stream.Collectors; import java.util.stream.Collectors;
/** /**
@ -45,7 +45,7 @@ public class UpdateImAccountOuIdJob extends IJobHandler {
@Autowired @Autowired
private AccountRegisterService accountRegisterService; private AccountRegisterService accountRegisterService;
@Autowired @Autowired
private OrganizationalNodeUserApi organizationalNodeUserApi; private TyrSaasRoleUserApi tyrSaasRoleUserApi;
private static final Integer DEFAULT_PAGE_SIZE = 500; private static final Integer DEFAULT_PAGE_SIZE = 500;
@ -63,13 +63,15 @@ public class UpdateImAccountOuIdJob extends IJobHandler {
.ids(updateImAccountOuIdParam.getIds()) .ids(updateImAccountOuIdParam.getIds())
.appType(AppTypeEnum.CMP.getCode()) .appType(AppTypeEnum.CMP.getCode())
.accountType(AccountTypeEnum.USER.getCode()) .accountType(AccountTypeEnum.USER.getCode())
.accountWrapperEW("cmp")
.page(pageNumber++) .page(pageNumber++)
.pageSize(DEFAULT_PAGE_SIZE) .pageSize(DEFAULT_PAGE_SIZE)
.build(); .build();
Page<AccountRegisterService.AccountRegisterDTO> page = accountRegisterService.page(req); Page<AccountRegisterService.AccountRegisterDTO> page = accountRegisterService.page(req);
if (CollectionUtils.isNotEmpty(page.getRecords())) { if (CollectionUtils.isNotEmpty(page.getRecords())) {
Map<String, OrganizationalNodeUserBasicVO> nodeUsers = listNodeUsers(page.getRecords());
Map<String, Long> nodeUsers = listNodeUsers(page.getRecords());
updateAccountRegister(page.getRecords(), nodeUsers); updateAccountRegister(page.getRecords(), nodeUsers);
} }
@ -82,17 +84,22 @@ public class UpdateImAccountOuIdJob extends IJobHandler {
return ReturnT.SUCCESS; return ReturnT.SUCCESS;
} }
private void updateAccountRegister(List<AccountRegisterService.AccountRegisterDTO> accountRegisters, Map<String, OrganizationalNodeUserBasicVO> nodeUsers) { private void updateAccountRegister(List<AccountRegisterService.AccountRegisterDTO> accountRegisters, Map<String, Long> nodeUsers) {
List<AccountRegister> update = accountRegisters.stream() List<AccountRegister> update = accountRegisters.stream()
.filter(accountRegister -> nodeUsers.get(accountRegister.getAccountId()) != null) .filter(accountRegister -> nodeUsers.get(accountRegister.getAccountId()) != null)
.map(accountRegister -> { .map(accountRegister -> {
OrganizationalNodeUserBasicVO nodeUser = nodeUsers.get(accountRegister.getAccountId()); Long ouId = nodeUsers.get(accountRegister.getAccountId());
if (ouId == null) {
return null;
}
AccountRegister result = new AccountRegister(); AccountRegister result = new AccountRegister();
result.setId(accountRegister.getId()); result.setId(accountRegister.getId());
result.setOuId(nodeUser.getOrganizationalUnitId()); result.setOuId(ouId);
result.setUpdateAt(new Date()); result.setUpdateAt(new Date());
return result; return result;
}) })
.filter(Objects::nonNull)
.collect(Collectors.toList()); .collect(Collectors.toList());
if (CollectionUtils.isEmpty(accountRegisters)) { if (CollectionUtils.isEmpty(accountRegisters)) {
log.info("updateImAccountOuIdJob: no data update"); log.info("updateImAccountOuIdJob: no data update");
@ -102,7 +109,7 @@ public class UpdateImAccountOuIdJob extends IJobHandler {
accountRegisterService.updateBatchById(update); accountRegisterService.updateBatchById(update);
} }
private Map<String, OrganizationalNodeUserBasicVO> listNodeUsers(List<AccountRegisterService.AccountRegisterDTO> accountRegisters) { private Map<String, Long> listNodeUsers(List<AccountRegisterService.AccountRegisterDTO> accountRegisters) {
if (CollectionUtils.isEmpty(accountRegisters)) { if (CollectionUtils.isEmpty(accountRegisters)) {
return Collections.EMPTY_MAP; return Collections.EMPTY_MAP;
} }
@ -115,19 +122,21 @@ public class UpdateImAccountOuIdJob extends IJobHandler {
if (CollectionUtils.isEmpty(accountIds)) { if (CollectionUtils.isEmpty(accountIds)) {
return Collections.EMPTY_MAP; return Collections.EMPTY_MAP;
} }
OrganizationalNodeUserBasicQueryVO queryVO = new OrganizationalNodeUserBasicQueryVO();
queryVO.setPersonIds(accountIds);
List<OrganizationalNodeUserBasicVO> nodeUsers = organizationalNodeUserApi.queryUserBasic(queryVO).getData();
return nodeUsers.stream() return accountIds.stream()
.collect(Collectors.toMap(e -> e.getPersonId().toString(), Function.identity(), (f, s) -> s)); .map(e -> {
Optional<SaasRoleUserDTO> user = tyrSaasRoleUserApi.roleUserList(RoleUserParam.builder().personId(e).build()).getData().stream().findFirst();
return Pair.of(e.toString(), user.map(SaasRoleUserDTO::getOuId).orElse(null));
})
.filter(e -> e.getValue() != null)
.collect(Collectors.toMap(Pair::getKey, Pair::getValue));
} }
@Data @Data
@Builder @Builder
@NoArgsConstructor @NoArgsConstructor
@AllArgsConstructor @AllArgsConstructor
static class UpdateImAccountOuIdParam { public static class UpdateImAccountOuIdParam {
private List<Long> ids; private List<Long> ids;
} }
} }

View File

@ -68,6 +68,9 @@ public interface AccountRegisterService extends IService<AccountRegister> {
@CriteriaField(field = "accountType", operator = Operator.EQ) @CriteriaField(field = "accountType", operator = Operator.EQ)
private String accountType; private String accountType;
@CriteriaField(field = "accountWrapper", operator = Operator.EW)
private String accountWrapperEW;
@CriteriaField(ignore = true) @CriteriaField(ignore = true)
private boolean needOuInfo; private boolean needOuInfo;

View File

@ -341,7 +341,7 @@ public class AccountService {
.appType(appTypeEnum.getCode()) .appType(appTypeEnum.getCode())
.accountId(accountAbsentQuery.getPersonId()) .accountId(accountAbsentQuery.getPersonId())
.build(); .build();
if (appTypeEnum == AppTypeEnum.CMP) { if (appTypeEnum == AppTypeEnum.CMP && accountAbsentQuery.getOuId() != 0) {
listAccountRegisterParam.setOuId(accountAbsentQuery.getOuId()); listAccountRegisterParam.setOuId(accountAbsentQuery.getOuId());
} }
List<AccountRegisterService.AccountRegisterDTO> accountRegisters = accountRegisterService.list(listAccountRegisterParam); List<AccountRegisterService.AccountRegisterDTO> accountRegisters = accountRegisterService.list(listAccountRegisterParam);
@ -368,7 +368,7 @@ public class AccountService {
userAccountReq.setUserId(accountAbsentQuery.getPersonId()); userAccountReq.setUserId(accountAbsentQuery.getPersonId());
userAccountReq.setNickName(DEFAULT_NICK_NAME + accountAbsentQuery.getPersonId()); userAccountReq.setNickName(DEFAULT_NICK_NAME + accountAbsentQuery.getPersonId());
// 管理版需要根据ou注册IM账号做数据隔离 // 管理版需要根据ou注册IM账号做数据隔离
if (appTypeEnum == AppTypeEnum.CMP) { if (appTypeEnum == AppTypeEnum.CMP && accountAbsentQuery.getOuId() != 0) {
userAccountReq.setOrganizationalUnitId(accountAbsentQuery.getOuId()); userAccountReq.setOrganizationalUnitId(accountAbsentQuery.getOuId());
} }
UserAccountResp accountResp = generateAccount(userAccountReq, iNotifyService); UserAccountResp accountResp = generateAccount(userAccountReq, iNotifyService);

View File

@ -267,8 +267,14 @@ public class MessageTaskServiceImpl extends ServiceImpl<MessageTaskMapper, Messa
.accountIds(personIds) .accountIds(personIds)
.build()) .build())
.stream() .stream()
.collect(Collectors.toMap(accountRegister -> accountRegister.getAccountId() + .collect(Collectors.toMap(accountRegister -> {
"_" + accountRegister.getAppType() + "_" + accountRegister.getOuId(), AccountRegister::getImAccount, (f, s) -> f)); if (Objects.equals(accountRegister.getAppType(), AppTypeEnum.CM.getCode())) {
return accountRegister.getAccountId() +
"_" + accountRegister.getAppType();
}
return accountRegister.getAccountId() +
"_" + accountRegister.getAppType() + "_" + accountRegister.getOuId();
}, AccountRegister::getImAccount, (f, s) -> f));
} }
private Map<String, AccountRegisterService.AccountRegisterDTO> listImAccount(List<MessageTask.ReceivePerson> receivePersons) { private Map<String, AccountRegisterService.AccountRegisterDTO> listImAccount(List<MessageTask.ReceivePerson> receivePersons) {