fix(channel): address Task 1 spec review issues for business-field preservation

- Strengthen WeComSyncTest personType assertion by seeding a value (3)
  that differs from what resolvePersonType(user001/INTERNAL) would assign (1),
  so the test actually detects an overwrite.
- Remove redundant personMapper/conversationMapper selectById calls in
  upsertContact and upsertConversation; preserve original business fields
  by reading them from the already-loaded entity before mutation.
- Delete the manual regression shell script; the unit tests are the primary
  verification and the script required manual DB edits and only covered
  conversation fields.
This commit is contained in:
2026-07-08 15:33:10 +08:00
parent 7ec77732e0
commit d7c996de0e
3 changed files with 17 additions and 155 deletions

View File

@@ -232,14 +232,14 @@ public class ChannelAccountService {
Person person;
if (identity != null) {
person = personMapper.selectById(identity.getPersonId());
Long originalInstitutionId = person.getInstitutionId();
Long originalSupplierId = person.getSupplierId();
Integer originalPersonType = person.getPersonType();
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());
}
person.setInstitutionId(originalInstitutionId);
person.setSupplierId(originalSupplierId);
person.setPersonType(originalPersonType);
personMapper.updateById(person);
identity.setChannelUserName(contact.getName());
@@ -276,16 +276,17 @@ public class ChannelAccountService {
.eq(Conversation::getChannelConversationId, conv.getChatId()));
if (conversation != null) {
Long originalInstitutionId = conversation.getInstitutionId();
Long originalSupplierId = conversation.getSupplierId();
Long originalContractId = conversation.getContractId();
String originalChannelCode = conversation.getChannelCode();
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());
}
conversation.setInstitutionId(originalInstitutionId);
conversation.setSupplierId(originalSupplierId);
conversation.setContractId(originalContractId);
conversation.setChannelCode(originalChannelCode);
conversationMapper.updateById(conversation);
return conversation;
}

View File

@@ -189,7 +189,8 @@ class WeComSyncTest {
person.setPersonCode("user001");
person.setPersonName("原始姓名");
person.setPhone("13800138001");
person.setPersonType(1);
// Seed with a personType that differs from what resolvePersonType(user001/INTERNAL) would assign (1).
person.setPersonType(3);
person.setInstitutionId(100L);
person.setSupplierId(200L);
person.setStatus(1);
@@ -217,7 +218,7 @@ class WeComSyncTest {
assertThat(updated.getPersonName()).isEqualTo("张三");
assertThat(updated.getInstitutionId()).isEqualTo(100L);
assertThat(updated.getSupplierId()).isEqualTo(200L);
assertThat(updated.getPersonType()).isEqualTo(1);
assertThat(updated.getPersonType()).isEqualTo(3);
}
@Test