feat(mcp): properties 流导出物业所属销售 sale_user_id / sale_user_name
物业表的所属销售列是 userId / userName(实体未映射),此前一直取不到。 - ProperytMapper.selectPropertyOwners:显式 SQL 按 id 批量取 userId/userName - PropertiesSyncEntity 批量富化,**独立查询 + try/catch 容错**:列名或数据异常 只丢归属,不影响 properties 变更流 - 流字段:sale_user_id / sale_user_name(缺失时回落到 create_id) 依据:PermissionService.resolveRowScope 用 properyt.create_id=user.id 判定销售可见物业, 说明物业归属销售;本次直接取物业表的 userId 列,命中即为该物业的所属销售。
This commit is contained in:
@@ -1,16 +1,32 @@
|
||||
package me.iiv.agent.mapper.m0;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import me.iiv.agent.entity.m0.Properyt;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 物业表 Mapper 接口
|
||||
* </p>
|
||||
*
|
||||
* @author codegen
|
||||
* @since 2026-09-08
|
||||
*/
|
||||
public interface ProperytMapper extends BaseMapper<Properyt> {
|
||||
|
||||
}
|
||||
package me.iiv.agent.mapper.m0;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import me.iiv.agent.entity.m0.Properyt;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 物业表 Mapper 接口
|
||||
* </p>
|
||||
*
|
||||
* @author codegen
|
||||
* @since 2026-09-08
|
||||
*/
|
||||
public interface ProperytMapper extends BaseMapper<Properyt> {
|
||||
|
||||
/**
|
||||
* 按 id 批量取物业的"所属销售"。
|
||||
*
|
||||
* <p>来源是物业表的 userId / userName 两列(实体未映射,故用显式 SQL)。
|
||||
* 独立查询 + 调用方容错:列名或数据异常只丢归属,不影响 properties 变更流。</p>
|
||||
*/
|
||||
@Select("<script>SELECT id AS property_id, userId AS user_id, userName AS user_name"
|
||||
+ " FROM properyt WHERE id IN"
|
||||
+ " <foreach collection='ids' item='id' open='(' separator=',' close=')'>#{id}</foreach>"
|
||||
+ "</script>")
|
||||
List<Map<String, Object>> selectPropertyOwners(@Param("ids") List<Long> ids);
|
||||
}
|
||||
|
||||
@@ -64,22 +64,57 @@ public class PropertiesSyncEntity extends AbstractSyncEntity implements SyncEnti
|
||||
agents.put(agent.getId(), agent);
|
||||
}
|
||||
}
|
||||
// 物业"所属销售":优先物业表 userId/userName(实体未映射,独立查询 + 容错)。
|
||||
Map<Long, String> ownerIds = new java.util.HashMap<>();
|
||||
Map<Long, String> ownerNames = new java.util.HashMap<>();
|
||||
try {
|
||||
List<Long> ids = new java.util.ArrayList<>();
|
||||
for (Properyt row : list) {
|
||||
if (row.getId() != null) {
|
||||
ids.add(row.getId());
|
||||
}
|
||||
}
|
||||
if (!ids.isEmpty()) {
|
||||
for (Map<String, Object> owner : properytMapper.selectPropertyOwners(ids)) {
|
||||
Object pid = owner.get("property_id");
|
||||
if (pid == null) {
|
||||
continue;
|
||||
}
|
||||
Long propertyId = Long.valueOf(String.valueOf(pid));
|
||||
Object uid = owner.get("user_id");
|
||||
Object uname = owner.get("user_name");
|
||||
if (uid != null) {
|
||||
ownerIds.put(propertyId, String.valueOf(uid));
|
||||
}
|
||||
if (uname != null) {
|
||||
ownerNames.put(propertyId, String.valueOf(uname));
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception enrichmentError) {
|
||||
// 列名/权限异常时只丢归属,不能让整条 properties 流失败。
|
||||
org.slf4j.LoggerFactory.getLogger(PropertiesSyncEntity.class)
|
||||
.warn("物业所属销售富化失败,跳过归属: {}", enrichmentError.getMessage());
|
||||
}
|
||||
List<SyncRow> rows = new ArrayList<>();
|
||||
for (Properyt row : list) {
|
||||
long mt = ChangesEngine.effectiveTs(row.getModifyTime(), row.getCreateTime());
|
||||
rows.add(new SyncRow(toItem(row, mt, agents.get(row.getAgentId())), mt, row.getId()));
|
||||
rows.add(new SyncRow(toItem(row, mt, agents.get(row.getAgentId()),
|
||||
ownerIds.get(row.getId()), ownerNames.get(row.getId())), mt, row.getId()));
|
||||
}
|
||||
return rows;
|
||||
}
|
||||
|
||||
private Map<String, Object> toItem(Properyt row, long mt, me.iiv.agent.entity.m0.Agent agent) {
|
||||
private Map<String, Object> toItem(Properyt row, long mt, me.iiv.agent.entity.m0.Agent agent,
|
||||
String ownerUserId, String ownerUserName) {
|
||||
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()),
|
||||
stableId(row.getCreateId()),
|
||||
ownerUserId == null ? stableId(row.getCreateId()) : ownerUserId,
|
||||
ownerUserName,
|
||||
agent == null ? null : stableId(agent.getSaleId()),
|
||||
agent == null ? null : agent.getSaleName(),
|
||||
deleted ? "INACTIVE" : "ACTIVE",
|
||||
|
||||
@@ -49,7 +49,8 @@ final class SyncChangeSchemas {
|
||||
@JsonProperty("external_customer_no") String externalCustomerNo,
|
||||
@JsonProperty("supervisor_id") String supervisorId,
|
||||
@JsonProperty("agent_id") String agentId,
|
||||
@JsonProperty("create_id") String createId,
|
||||
@JsonProperty("sale_user_id") String saleUserId,
|
||||
@JsonProperty("sale_user_name") String saleUserName,
|
||||
@JsonProperty("sale_id") String saleId,
|
||||
@JsonProperty("sale_name") String saleName,
|
||||
String status,
|
||||
|
||||
Reference in New Issue
Block a user