fix: protect business fields during wecom sync
This commit is contained in:
@@ -234,6 +234,12 @@ public class ChannelAccountService {
|
||||
person = personMapper.selectById(identity.getPersonId());
|
||||
person.setPersonName(contact.getName());
|
||||
person.setPhone(contact.getMobile());
|
||||
Person existing = personMapper.selectById(person.getId());
|
||||
if (existing != null) {
|
||||
person.setInstitutionId(existing.getInstitutionId());
|
||||
person.setSupplierId(existing.getSupplierId());
|
||||
person.setPersonType(existing.getPersonType());
|
||||
}
|
||||
personMapper.updateById(person);
|
||||
|
||||
identity.setChannelUserName(contact.getName());
|
||||
@@ -273,6 +279,13 @@ public class ChannelAccountService {
|
||||
conversation.setConversationName(conv.getChatName());
|
||||
conversation.setOwnerAccountId(account.getId());
|
||||
conversation.setSubjectId(subjectId);
|
||||
Conversation existing = conversationMapper.selectById(conversation.getId());
|
||||
if (existing != null) {
|
||||
conversation.setInstitutionId(existing.getInstitutionId());
|
||||
conversation.setSupplierId(existing.getSupplierId());
|
||||
conversation.setContractId(existing.getContractId());
|
||||
conversation.setChannelCode(existing.getChannelCode());
|
||||
}
|
||||
conversationMapper.updateById(conversation);
|
||||
return conversation;
|
||||
}
|
||||
|
||||
@@ -179,6 +179,84 @@ class WeComSyncTest {
|
||||
assertThat(receiveMaster).isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldPreservePersonBusinessFieldsDuringContactSync() throws Exception {
|
||||
String authToken = createTenantAndLogin(mockMvc, TENANT_CODE, "企微同步租户");
|
||||
ChannelAccount account = createWeComAccount();
|
||||
|
||||
Person person = new Person();
|
||||
person.setTenantCode(TENANT_CODE);
|
||||
person.setPersonCode("user001");
|
||||
person.setPersonName("原始姓名");
|
||||
person.setPhone("13800138001");
|
||||
person.setPersonType(1);
|
||||
person.setInstitutionId(100L);
|
||||
person.setSupplierId(200L);
|
||||
person.setStatus(1);
|
||||
personMapper.insert(person);
|
||||
|
||||
ChannelIdentity identity = new ChannelIdentity();
|
||||
identity.setTenantCode(TENANT_CODE);
|
||||
identity.setPersonId(person.getId());
|
||||
identity.setChannelType(CHANNEL_TYPE);
|
||||
identity.setChannelUserId("user001");
|
||||
identity.setChannelUserName("原始姓名");
|
||||
identity.setSubjectId(account.getSubjectId());
|
||||
identity.setStatus(1);
|
||||
channelIdentityMapper.insert(identity);
|
||||
|
||||
mockMvc.perform(post("/msg-platform/api/v1/channel-account/{account_id}/sync-contacts", account.getId())
|
||||
.contextPath("/msg-platform")
|
||||
.header("Authorization", authToken)
|
||||
.header("X-Tenant-Code", TENANT_CODE)
|
||||
.contentType(MediaType.APPLICATION_JSON))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$.code").value(0));
|
||||
|
||||
Person updated = personMapper.selectById(person.getId());
|
||||
assertThat(updated.getPersonName()).isEqualTo("张三");
|
||||
assertThat(updated.getInstitutionId()).isEqualTo(100L);
|
||||
assertThat(updated.getSupplierId()).isEqualTo(200L);
|
||||
assertThat(updated.getPersonType()).isEqualTo(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldPreserveConversationBusinessFieldsDuringConversationSync() throws Exception {
|
||||
String authToken = createTenantAndLogin(mockMvc, TENANT_CODE, "企微同步租户");
|
||||
ChannelAccount account = createWeComAccount();
|
||||
|
||||
Conversation conversation = new Conversation();
|
||||
conversation.setTenantCode(TENANT_CODE);
|
||||
conversation.setConversationType(2);
|
||||
conversation.setChannelType(CHANNEL_TYPE);
|
||||
conversation.setChannelConversationId("chat001");
|
||||
conversation.setOwnerAccountId(account.getId());
|
||||
conversation.setSubjectId(account.getSubjectId());
|
||||
conversation.setConversationName("原始群名");
|
||||
conversation.setInstitutionId(100L);
|
||||
conversation.setSupplierId(200L);
|
||||
conversation.setContractId(300L);
|
||||
conversation.setChannelCode("ORIGINAL");
|
||||
conversation.setCreateSource(1);
|
||||
conversation.setStatus(1);
|
||||
conversationMapper.insert(conversation);
|
||||
|
||||
mockMvc.perform(post("/msg-platform/api/v1/channel-account/{account_id}/sync-conversations", account.getId())
|
||||
.contextPath("/msg-platform")
|
||||
.header("Authorization", authToken)
|
||||
.header("X-Tenant-Code", TENANT_CODE)
|
||||
.contentType(MediaType.APPLICATION_JSON))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$.code").value(0));
|
||||
|
||||
Conversation updated = conversationMapper.selectById(conversation.getId());
|
||||
assertThat(updated.getConversationName()).isEqualTo("测试客户群");
|
||||
assertThat(updated.getInstitutionId()).isEqualTo(100L);
|
||||
assertThat(updated.getSupplierId()).isEqualTo(200L);
|
||||
assertThat(updated.getContractId()).isEqualTo(300L);
|
||||
assertThat(updated.getChannelCode()).isEqualTo("ORIGINAL");
|
||||
}
|
||||
|
||||
private ChannelAccount createWeComAccount() {
|
||||
ChannelSubject subject = new ChannelSubject();
|
||||
subject.setTenantCode(TENANT_CODE);
|
||||
|
||||
Reference in New Issue
Block a user