feat(mcp): properties 流带出所属销售 sale_id / sale_name
所属销售不在物业表上,而在代理商表:property.agent_id → Agent.saleId(注释即"销售id")/ Agent.saleName。supervisorId 实测全空,不能作归属。 - PropertiesSyncEntity 注入 AgentMapper,按页批量富化(一次 selectBatchIds,无 N+1) - PropertyChange 增加 sale_id / sale_name 下游:CRM 用 sale_id(SaaS 用户 id)经 user 映射解析为客户负责人。
This commit is contained in:
@@ -27,10 +27,13 @@ public class PropertiesSyncEntity extends AbstractSyncEntity implements SyncEnti
|
||||
|
||||
final ProperytMapper properytMapper;
|
||||
final PermissionService permissionService;
|
||||
final me.iiv.agent.mapper.m0.AgentMapper agentMapper;
|
||||
|
||||
public PropertiesSyncEntity(ProperytMapper properytMapper, PermissionService permissionService) {
|
||||
public PropertiesSyncEntity(ProperytMapper properytMapper, PermissionService permissionService,
|
||||
me.iiv.agent.mapper.m0.AgentMapper agentMapper) {
|
||||
this.properytMapper = properytMapper;
|
||||
this.permissionService = permissionService;
|
||||
this.agentMapper = agentMapper;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -47,21 +50,37 @@ public class PropertiesSyncEntity extends AbstractSyncEntity implements SyncEnti
|
||||
}
|
||||
applyWindow(wrapper, fromTs, cutoffTs, cursorMt, cursorId);
|
||||
applyOrderAndLimit(wrapper, limit);
|
||||
List<Properyt> list = properytMapper.selectList(wrapper);
|
||||
// 物业的"所属销售"在代理商表上(Agent.saleId/saleName),这里按页批量富化,避免 N+1。
|
||||
java.util.Set<Long> agentIds = new java.util.HashSet<>();
|
||||
for (Properyt row : list) {
|
||||
if (row.getAgentId() != null) {
|
||||
agentIds.add(row.getAgentId());
|
||||
}
|
||||
}
|
||||
Map<Long, me.iiv.agent.entity.m0.Agent> agents = new java.util.HashMap<>();
|
||||
if (!agentIds.isEmpty()) {
|
||||
for (me.iiv.agent.entity.m0.Agent agent : agentMapper.selectBatchIds(agentIds)) {
|
||||
agents.put(agent.getId(), agent);
|
||||
}
|
||||
}
|
||||
List<SyncRow> rows = new ArrayList<>();
|
||||
for (Properyt row : properytMapper.selectList(wrapper)) {
|
||||
for (Properyt row : list) {
|
||||
long mt = ChangesEngine.effectiveTs(row.getModifyTime(), row.getCreateTime());
|
||||
rows.add(new SyncRow(toItem(row, mt), mt, row.getId()));
|
||||
rows.add(new SyncRow(toItem(row, mt, agents.get(row.getAgentId())), mt, row.getId()));
|
||||
}
|
||||
return rows;
|
||||
}
|
||||
|
||||
private Map<String, Object> toItem(Properyt row, long mt) {
|
||||
private Map<String, Object> toItem(Properyt row, long mt, me.iiv.agent.entity.m0.Agent agent) {
|
||||
boolean deleted = row.getSoftDelete() != null && row.getSoftDelete() == 1;
|
||||
Date effective = row.getModifyTime() != null ? row.getModifyTime() : row.getCreateTime();
|
||||
return SyncChangeSchemas.toMap(new SyncChangeSchemas.PropertyChange(
|
||||
stableId(row.getId()), row.getCustomerId(), row.getName(), row.getJinideName(),
|
||||
row.getIdentificationNumber(), row.getSerialnumber(),
|
||||
stableId(row.getSupervisorId()), stableId(row.getAgentId()),
|
||||
agent == null ? null : stableId(agent.getSaleId()),
|
||||
agent == null ? null : agent.getSaleName(),
|
||||
deleted ? "INACTIVE" : "ACTIVE",
|
||||
ChangesEngine.iso(effective), mt, deleted ? ChangesEngine.iso(effective) : null));
|
||||
}
|
||||
|
||||
@@ -49,6 +49,8 @@ final class SyncChangeSchemas {
|
||||
@JsonProperty("external_customer_no") String externalCustomerNo,
|
||||
@JsonProperty("supervisor_id") String supervisorId,
|
||||
@JsonProperty("agent_id") String agentId,
|
||||
@JsonProperty("sale_id") String saleId,
|
||||
@JsonProperty("sale_name") String saleName,
|
||||
String status,
|
||||
@JsonProperty("updated_at") String updatedAt,
|
||||
long version,
|
||||
|
||||
Reference in New Issue
Block a user