property.list.query 销售非负责人规则改为 1:1 复刻老代码 saleFlag 分支(id IN 自建∪代管物业,互斥 return);新增销售视角种子 ak,dev 实测 total=14 与老语义 SQL 逐 id 一致
This commit is contained in:
@@ -51,7 +51,7 @@ public class PropertyTools implements ToolObject {
|
||||
@Tool(name = "property.list.query", description = "查询物业(客户)列表(分页),数据来源 m0 库 properyt 表。"
|
||||
+ "行级权限:代理商身份的用户(权限组 isagent=1)只能看到 自己+直属下级代理+被授权代管代理 名下的物业,"
|
||||
+ "以及被授权代管的物业(agent_manage_district_auth);总部身份(isagent=0)可看全部;"
|
||||
+ "销售部门非负责人只能看自己创建的物业。"
|
||||
+ "销售部门非负责人只能看到 自己创建的物业 及 被授权代管代理名下的物业(与其余规则互斥)。"
|
||||
+ "分页:page 从 1 开始,rows 默认 20、上限 100,超出自动截断为 100 并在返回的 notice 字段提示。"
|
||||
+ "返回 total(符合条件的总数)、records(本页记录)。")
|
||||
public Map<String, Object> propertyListQuery(
|
||||
|
||||
@@ -10,6 +10,7 @@ import me.iiv.agent.entity.m2.WarehouseAgentAuth;
|
||||
import me.iiv.agent.mapper.m0.AgentManageDistrictAuthMapper;
|
||||
import me.iiv.agent.mapper.m0.AgentMapper;
|
||||
import me.iiv.agent.mapper.m0.AuthorityMapper;
|
||||
import me.iiv.agent.mapper.m0.ProperytMapper;
|
||||
import me.iiv.agent.mapper.m2.WarehouseAgentAuthMapper;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@@ -41,16 +42,18 @@ public class PermissionService {
|
||||
final AgentMapper agentMapper;
|
||||
final WarehouseAgentAuthMapper warehouseAgentAuthMapper;
|
||||
final AgentManageDistrictAuthMapper agentManageDistrictAuthMapper;
|
||||
final ProperytMapper properytMapper;
|
||||
final StringRedisTemplate redisTemplate;
|
||||
|
||||
public PermissionService(AuthorityMapper authorityMapper, AgentMapper agentMapper,
|
||||
WarehouseAgentAuthMapper warehouseAgentAuthMapper,
|
||||
AgentManageDistrictAuthMapper agentManageDistrictAuthMapper,
|
||||
StringRedisTemplate redisTemplate) {
|
||||
ProperytMapper properytMapper, StringRedisTemplate redisTemplate) {
|
||||
this.authorityMapper = authorityMapper;
|
||||
this.agentMapper = agentMapper;
|
||||
this.warehouseAgentAuthMapper = warehouseAgentAuthMapper;
|
||||
this.agentManageDistrictAuthMapper = agentManageDistrictAuthMapper;
|
||||
this.properytMapper = properytMapper;
|
||||
this.redisTemplate = redisTemplate;
|
||||
}
|
||||
|
||||
@@ -73,6 +76,15 @@ public class PermissionService {
|
||||
return null;
|
||||
}
|
||||
Set<Long> ids = new LinkedHashSet<>();
|
||||
ids.addAll(subordinateAndSelfIds(user));
|
||||
ids.addAll(managedAuths(user.getId()).stream()
|
||||
.map(WarehouseAgentAuth::getManagerAgentId).collect(Collectors.toList()));
|
||||
return new ArrayList<>(ids);
|
||||
}
|
||||
|
||||
/** 直属下级代理 id + 自己 agentId(老 :682-695,supervisor_id=自己,只取一层) */
|
||||
private List<Long> subordinateAndSelfIds(User user) {
|
||||
List<Long> ids = new ArrayList<>();
|
||||
if (user.getAgentId() != null) {
|
||||
List<Agent> subordinates = agentMapper.selectList(new LambdaQueryWrapper<Agent>()
|
||||
.eq(Agent::getSoftDelete, 0)
|
||||
@@ -80,15 +92,18 @@ public class PermissionService {
|
||||
ids.addAll(subordinates.stream().map(Agent::getId).collect(Collectors.toList()));
|
||||
ids.add(user.getAgentId());
|
||||
}
|
||||
List<WarehouseAgentAuth> auths = warehouseAgentAuthMapper.selectList(new LambdaQueryWrapper<WarehouseAgentAuth>()
|
||||
return ids;
|
||||
}
|
||||
|
||||
/** m2 warehouse_agent_auth 代管授权(user_id, soft_delete=0),老 :696-702 */
|
||||
private List<WarehouseAgentAuth> managedAuths(Long userId) {
|
||||
return warehouseAgentAuthMapper.selectList(new LambdaQueryWrapper<WarehouseAgentAuth>()
|
||||
.eq(WarehouseAgentAuth::getSoftDelete, 0)
|
||||
.eq(WarehouseAgentAuth::getUserId, user.getId()));
|
||||
ids.addAll(auths.stream().map(WarehouseAgentAuth::getManagerAgentId).collect(Collectors.toList()));
|
||||
return new ArrayList<>(ids);
|
||||
.eq(WarehouseAgentAuth::getUserId, userId));
|
||||
}
|
||||
|
||||
/**
|
||||
* 销售部门非负责人判定(老系统 getByIsAgent 内 saleFlag 逻辑):
|
||||
* 销售部门非负责人判定(老系统 getByIsAgent 内 saleFlag 逻辑,:703-710):
|
||||
* Redis db5 Dictionary hash 的 authDeptId 命中 ",deptId," 且 authDeptPostId 不命中 "postId,"。
|
||||
* 字典缺失时按"不限制"处理并告警(与老系统 NPE 直接报错的行为不同,属于有意收敛)。
|
||||
*/
|
||||
@@ -133,31 +148,61 @@ public class PermissionService {
|
||||
}
|
||||
|
||||
/**
|
||||
* 物业(properyt 表)行级过滤组合,语义对应老系统 PropertyController.listByPage 使用的
|
||||
* getByIsAgent(agentFlag, agentId, wrapper, user, propertyFlag=true, className="id", redisTemplate):
|
||||
* 物业(properyt 表)行级过滤组合,1:1 复刻老系统 PropertyController.listByPage 使用的
|
||||
* getByIsAgent(agentFlag, agentId, wrapper, user, propertyFlag=true, className="id", redisTemplate)
|
||||
* (WrapperUtils.java:679-765):
|
||||
* <ol>
|
||||
* <li>isagent=1:agent_id IN (自己+下级+warehouse_agent_auth 代管),
|
||||
* 若存在代管物业则 OR id IN (agent_manage_district_auth 代管物业 id 集合);</li>
|
||||
* <li>isagent!=1(总部):不加 agent/id 过滤;</li>
|
||||
* <li>销售部门非负责人:再 AND create_id = 自己
|
||||
* (注:老代码 saleFlag 分支是 id IN (自建 ∪ 代管 agent 的物业),
|
||||
* 此处按设计文档 §3.3"只看 create_id=自己"收窄)。</li>
|
||||
* <li>isagent!=1(总部):不加任何过滤(老 :680 if(agentFlag) 外层);</li>
|
||||
* <li>销售非负责人(saleFlag=true,:716-735,互斥 return,不进第 3 条):
|
||||
* id IN (create_id=自己 的物业 ∪ [代管授权非空时] agent_id IN (下级+代管,移除自己) 的物业),
|
||||
* 集合为空时 id IN (0);</li>
|
||||
* <li>其余 isagent=1:agent_id IN (自己+下级+代管),
|
||||
* 若存在 agent_manage_district_auth 代管物业则 AND (agent_id IN ids OR id IN 代管物业ids),
|
||||
* 否则 agent_id IN ids(:747-760 else 分支,className="id")。</li>
|
||||
* </ol>
|
||||
* 不含 enterprise_type=2(物业用户)限制:物业用户不查此列表,与老接口语义一致
|
||||
* (2026-09-03 用户决策;§3.3 通用规则保留于 {@link #isPropertyUser})。
|
||||
* 不含 enterprise_type=2(物业用户)限制:物业用户不查此列表,与老接口语义一致(2026-09-03 用户决策)。
|
||||
* 销售非负责人规则 2026-09-03 用户决策:1:1 复刻老代码(不再按 §3.3 收窄为 AND create_id=自己)。
|
||||
*/
|
||||
public void applyPropertyRowFilter(LambdaQueryWrapper<Properyt> wrapper, User user) {
|
||||
List<Long> agentIds = visibleAgentIds(user);
|
||||
if (agentIds != null) {
|
||||
List<Long> propertyIds = managedPropertyIds(agentIds);
|
||||
if (!propertyIds.isEmpty()) {
|
||||
wrapper.and(w -> w.in(Properyt::getAgentId, agentIds).or().in(Properyt::getId, propertyIds));
|
||||
} else {
|
||||
wrapper.in(Properyt::getAgentId, agentIds);
|
||||
}
|
||||
if (!isAgentAuthority(user.getAuthorityId())) {
|
||||
return;
|
||||
}
|
||||
// ids 组装:下级 + 自己 + 代管(老 :682-702)
|
||||
List<Long> ids = new ArrayList<>(subordinateAndSelfIds(user));
|
||||
List<WarehouseAgentAuth> agentlist = managedAuths(user.getId());
|
||||
ids.addAll(agentlist.stream().map(WarehouseAgentAuth::getManagerAgentId).collect(Collectors.toList()));
|
||||
|
||||
// 老 :716-735 saleFlag 分支(互斥,直接 return)
|
||||
if (isSalesNonLeader(user)) {
|
||||
wrapper.eq(Properyt::getCreateId, user.getId());
|
||||
List<Long> propertyIds = properytMapper.selectList(new LambdaQueryWrapper<Properyt>()
|
||||
.eq(Properyt::getSoftDelete, 0)
|
||||
.eq(Properyt::getCreateId, user.getId())
|
||||
.select(Properyt::getId))
|
||||
.stream().map(Properyt::getId).collect(Collectors.toList());
|
||||
if (!agentlist.isEmpty()) {
|
||||
ids.remove(user.getAgentId());
|
||||
if (!ids.isEmpty()) {
|
||||
propertyIds.addAll(properytMapper.selectList(new LambdaQueryWrapper<Properyt>()
|
||||
.eq(Properyt::getSoftDelete, 0)
|
||||
.in(Properyt::getAgentId, ids)
|
||||
.select(Properyt::getId))
|
||||
.stream().map(Properyt::getId).collect(Collectors.toList()));
|
||||
}
|
||||
}
|
||||
if (propertyIds.isEmpty()) {
|
||||
wrapper.in(Properyt::getId, 0);
|
||||
} else {
|
||||
wrapper.in(Properyt::getId, propertyIds);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// 老 :747-760 else 分支(className="id")
|
||||
List<Long> managedPropertyIds = managedPropertyIds(ids);
|
||||
if (!managedPropertyIds.isEmpty()) {
|
||||
wrapper.and(w -> w.in(Properyt::getAgentId, ids).or().in(Properyt::getId, managedPropertyIds));
|
||||
} else {
|
||||
wrapper.in(Properyt::getAgentId, ids);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user