feat(mcp): 新增合同查询工具 contract.list/detail.query (REQ-20260911-0002)

This commit is contained in:
xiaoqu
2026-09-11 10:21:18 +08:00
parent d5bb8646e1
commit 52bb9faa27
12 changed files with 1248 additions and 1 deletions
@@ -0,0 +1,71 @@
package me.iiv.agent.entity.m2;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import java.io.Serializable;
import java.util.Date;
/**
* <p>
* 合同附件
* </p>
*
* @author codegen
* @since 2026-09-11
*/
@Getter
@Setter
@ToString
@TableName("contract_file")
public class ContractFile implements Serializable {
private static final long serialVersionUID = 1L;
@TableId(value = "id", type = IdType.AUTO)
private Long id;
/**
* 创建id
*/
private Long createId;
/**
* 创建时间
*/
private Date createTime;
/**
* 修改id
*/
private Long modifyId;
/**
* 修改时间
*/
private Date modifyTime;
/**
* 数据状态0:正常;1:删除
*/
private Integer softDelete;
/**
* 合同ID(0=上传后未提交的孤儿附件,定时清理)
*/
private Long contractId;
/**
* 原始文件名
*/
private String fileName;
/**
* 文件访问地址
*/
private String fileUrl;
}
@@ -0,0 +1,162 @@
package me.iiv.agent.entity.m2;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;
/**
* <p>
* 合同主表
* </p>
*
* @author codegen
* @since 2026-09-11
*/
@Getter
@Setter
@ToString
@TableName("contract_new")
public class ContractNew implements Serializable {
private static final long serialVersionUID = 1L;
@TableId(value = "id", type = IdType.AUTO)
private Long id;
/**
* 创建id
*/
private Long createId;
/**
* 创建时间
*/
private Date createTime;
/**
* 修改id
*/
private Long modifyId;
/**
* 修改时间
*/
private Date modifyTime;
/**
* 数据状态0:正常;1:删除
*/
private Integer softDelete;
/**
* 合同编号(properyt.serialnumber + "C" + 三位流水,如452542C001)
*/
private String contractNo;
/**
* 合同名称
*/
private String contractName;
/**
* 合同所属公司(=物业所属销售所属公司,审批流按此公司匹配)
*/
private Long contractAgentId;
/**
* 客户所属公司(=创建人提交时选择的所属公司)
*/
private Long customerAgentId;
/**
* 所属物业ID(关联权限库properyt)
*/
private Long propertyId;
/**
* 物业名称(冗余快照)
*/
private String propertyName;
/**
* 客户编号快照(=properyt.serialnumber,编号流水/按客户归集用)
*/
private String customerNo;
/**
* 客户名称快照(=properyt.jinide_name 金蝶客户名称)
*/
private String customerName;
/**
* 合同金额(元)
*/
private BigDecimal amount;
/**
* 联系人
*/
private String contact;
/**
* 合同开始日期
*/
private Date startDate;
/**
* 合同结束日期
*/
private Date endDate;
/**
* 到期提醒开关0:关;1:开
*/
private Integer expireRemind;
/**
* 到期提醒天数
*/
private Integer remindDays;
/**
* 到期提醒时间(=end_date-remind_days 当天09:30:00)
*/
private Date remindTime;
/**
* 到期提醒是否已发送0:未发送;1:已发送
*/
private Integer reminded;
/**
* 所属销售ID(=物业所属销售)
*/
private Long saleId;
/**
* 所属销售姓名(冗余快照)
*/
private String saleName;
/**
* 合同状态0:待审;1:驳回;2:正常;3:过期;4:终止
*/
private Integer contractStatus;
/**
* 终止原因分类(cancel_reason.content快照,type=6)
*/
private String stopReasonType;
/**
* 终止详细原因
*/
private String stopReason;
}
@@ -0,0 +1,106 @@
package me.iiv.agent.entity.m2;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import java.io.Serializable;
import java.util.Date;
/**
* <p>
* 合同流程/待办/操作记录表
* </p>
*
* @author codegen
* @since 2026-09-11
*/
@Getter
@Setter
@ToString
@TableName("contract_process")
public class ContractProcess implements Serializable {
private static final long serialVersionUID = 1L;
@TableId(value = "id", type = IdType.AUTO)
private Long id;
/**
* 创建id
*/
private Long createId;
/**
* 创建时间
*/
private Date createTime;
/**
* 修改id
*/
private Long modifyId;
/**
* 修改时间
*/
private Date modifyTime;
/**
* 数据状态0:正常;1:删除
*/
private Integer softDelete;
/**
* 合同ID
*/
private Long contractId;
/**
* 合同编号(冗余)
*/
private String contractNo;
/**
* 节点类型0:创建;1:部门内审核;2:层级审核;3:终止;4:抄送
*/
private Integer nodeType;
/**
* 审核层级(层级审核为第几级,其余0)
*/
private Integer auditLevel;
/**
* 操作类型0:创建;1:审核通过;2:审核驳回;3:终止;4:修改再提交;5:抄送
*/
private Integer operationType;
/**
* 待办人/操作人ID
*/
private Long userId;
/**
* 待办人/操作人姓名
*/
private String userName;
/**
* 待办状态0:无需待办;1:待办;2:已办
*/
private Integer scheduleState;
/**
* 备注/驳回原因/终止原因/抄送文案
*/
private String remark;
/**
* 办理时间(待办未办为NULL)
*/
private Date operateTime;
}
@@ -0,0 +1,16 @@
package me.iiv.agent.mapper.m2;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import me.iiv.agent.entity.m2.ContractFile;
/**
* <p>
* 合同附件 Mapper 接口
* </p>
*
* @author codegen
* @since 2026-09-11
*/
public interface ContractFileMapper extends BaseMapper<ContractFile> {
}
@@ -0,0 +1,16 @@
package me.iiv.agent.mapper.m2;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import me.iiv.agent.entity.m2.ContractNew;
/**
* <p>
* 合同主表 Mapper 接口
* </p>
*
* @author codegen
* @since 2026-09-11
*/
public interface ContractNewMapper extends BaseMapper<ContractNew> {
}
@@ -0,0 +1,16 @@
package me.iiv.agent.mapper.m2;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import me.iiv.agent.entity.m2.ContractProcess;
/**
* <p>
* 合同流程/待办/操作记录 Mapper 接口
* </p>
*
* @author codegen
* @since 2026-09-11
*/
public interface ContractProcessMapper extends BaseMapper<ContractProcess> {
}
@@ -0,0 +1,321 @@
package me.iiv.agent.mcp.tool;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import me.iiv.agent.entity.m0.Agent;
import me.iiv.agent.entity.m0.User;
import me.iiv.agent.entity.m2.ContractFile;
import me.iiv.agent.entity.m2.ContractNew;
import me.iiv.agent.entity.m2.ContractProcess;
import me.iiv.agent.mapper.m0.AgentMapper;
import me.iiv.agent.mapper.m0.UserMapper;
import me.iiv.agent.mapper.m2.ContractFileMapper;
import me.iiv.agent.mapper.m2.ContractNewMapper;
import me.iiv.agent.mapper.m2.ContractProcessMapper;
import me.iiv.agent.mcp.ToolObject;
import me.iiv.agent.mcp.XqTool;
import me.iiv.agent.permission.PermissionService;
import me.iiv.agent.security.AuthContextHolder;
import org.springframework.ai.tool.annotation.Tool;
import org.springframework.ai.tool.annotation.ToolParam;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors;
import java.util.stream.Stream;
/**
* 合同域工具:contract.list.query / contract.detail.query(对应老系统 /contract/listByPage
* 合同列表页 web_id=394,数据在 m2 库 contract_new/contract_file/contract_process,
* 行权限走 PermissionService.applyContractRowFilter)。
*/
@Component
public class ContractTools implements ToolObject {
private static final int DEFAULT_ROWS = 20;
private static final int MAX_ROWS = 100;
private static final Map<Integer, String> CONTRACT_STATUS_TEXT = Map.of(
0, "待审", 1, "驳回", 2, "正常", 3, "过期", 4, "终止");
private static final Map<Integer, String> NODE_TYPE_TEXT = Map.of(
0, "创建", 1, "部门内审核", 2, "层级审核", 3, "终止", 4, "抄送");
private static final Map<Integer, String> OPERATION_TYPE_TEXT = Map.of(
0, "创建", 1, "审核通过", 2, "审核驳回", 3, "终止", 4, "修改再提交", 5, "抄送");
private static final Map<Integer, String> SCHEDULE_STATE_TEXT = Map.of(
0, "无需待办", 1, "待办", 2, "已办");
final ContractNewMapper contractNewMapper;
final ContractFileMapper contractFileMapper;
final ContractProcessMapper contractProcessMapper;
final AgentMapper agentMapper;
final UserMapper userMapper;
final PermissionService permissionService;
public ContractTools(ContractNewMapper contractNewMapper, ContractFileMapper contractFileMapper,
ContractProcessMapper contractProcessMapper, AgentMapper agentMapper,
UserMapper userMapper, PermissionService permissionService) {
this.contractNewMapper = contractNewMapper;
this.contractFileMapper = contractFileMapper;
this.contractProcessMapper = contractProcessMapper;
this.agentMapper = agentMapper;
this.userMapper = userMapper;
this.permissionService = permissionService;
}
@XqTool(category = "customer", kind = "read")
@Tool(name = "contract.list.query", description = "查询合同列表(分页),对应老系统 /contract/listByPage 合同列表页,"
+ "数据来源 m2 库 contract_new 表。"
+ "行级权限:代理商身份(权限组 isagent=1)只能看到 自己+直属下级代理+被授权代管代理 作为合同所属公司的合同,"
+ "以及被授权代管物业名下的合同;销售部门非负责人只能看到 自己创建的物业 及 被授权代管代理名下物业 的合同;"
+ "总部身份(isagent=0)可看全部。"
+ "分页:page 从 1 开始,rows 默认 20、上限 100,超出自动截断为 100 并在返回的 notice 字段提示。"
+ "contractStatus 含义:0=待审 1=驳回 2=正常 3=过期 4=终止;expireRemind 含义:0=关 1=开。"
+ "返回 total(符合条件的总数)、records(本页记录,按 id 倒序,含 contractStatusText 状态文案)。")
public Map<String, Object> contractListQuery(
@ToolParam(required = false, description = "合同编号,模糊匹配") String contractNo,
@ToolParam(required = false, description = "合同名称,模糊匹配") String contractName,
@ToolParam(required = false, description = "物业名称,模糊匹配") String propertyName,
@ToolParam(required = false, description = "客户名称(金蝶客户名称快照),模糊匹配") String customerName,
@ToolParam(required = false, description = "客户编号(=物业 serialnumber),精确匹配") String customerNo,
@ToolParam(required = false, description = "合同所属公司 id,精确匹配") Long contractAgentId,
@ToolParam(required = false, description = "客户所属公司 id,精确匹配") Long customerAgentId,
@ToolParam(required = false, description = "所属物业 id,精确匹配") Long propertyId,
@ToolParam(required = false, description = "合同状态:0=待审 1=驳回 2=正常 3=过期 4=终止") Integer contractStatus,
@ToolParam(required = false, description = "到期提醒开关:0=关 1=开") Integer expireRemind,
@ToolParam(required = false, description = "合同结束日期起,格式 yyyy-MM-dd(查即将到期合同用)") String endDateFrom,
@ToolParam(required = false, description = "合同结束日期止,格式 yyyy-MM-dd(含当天)") String endDateTo,
@ToolParam(required = false, description = "页码,从 1 开始,默认 1") Integer page,
@ToolParam(required = false, description = "每页条数,默认 20,上限 100(超出截断为 100)") Integer rows) {
User user = AuthContextHolder.get().getUser();
int pageNo = page == null || page < 1 ? 1 : page;
boolean truncated = rows != null && rows > MAX_ROWS;
int pageSize = rows == null || rows < 1 ? DEFAULT_ROWS : Math.min(rows, MAX_ROWS);
LambdaQueryWrapper<ContractNew> wrapper = new LambdaQueryWrapper<ContractNew>()
.eq(ContractNew::getSoftDelete, 0);
if (StringUtils.hasText(contractNo)) {
wrapper.like(ContractNew::getContractNo, contractNo);
}
if (StringUtils.hasText(contractName)) {
wrapper.like(ContractNew::getContractName, contractName);
}
if (StringUtils.hasText(propertyName)) {
wrapper.like(ContractNew::getPropertyName, propertyName);
}
if (StringUtils.hasText(customerName)) {
wrapper.like(ContractNew::getCustomerName, customerName);
}
if (StringUtils.hasText(customerNo)) {
wrapper.eq(ContractNew::getCustomerNo, customerNo);
}
if (contractAgentId != null) {
wrapper.eq(ContractNew::getContractAgentId, contractAgentId);
}
if (customerAgentId != null) {
wrapper.eq(ContractNew::getCustomerAgentId, customerAgentId);
}
if (propertyId != null) {
wrapper.eq(ContractNew::getPropertyId, propertyId);
}
if (contractStatus != null) {
wrapper.eq(ContractNew::getContractStatus, contractStatus);
}
if (expireRemind != null) {
wrapper.eq(ContractNew::getExpireRemind, expireRemind);
}
if (StringUtils.hasText(endDateFrom)) {
wrapper.ge(ContractNew::getEndDate, endDateFrom);
}
if (StringUtils.hasText(endDateTo)) {
wrapper.le(ContractNew::getEndDate, endDateTo);
}
// 行级权限(getByIsAgent propertyFlag 变体,统一走 PermissionService)
permissionService.applyContractRowFilter(wrapper, user);
Long total = contractNewMapper.selectCount(wrapper);
wrapper.orderByDesc(ContractNew::getId)
.last("LIMIT " + (long) (pageNo - 1) * pageSize + "," + pageSize);
List<ContractNew> contracts = contractNewMapper.selectList(wrapper);
// 合同所属公司 / 客户所属公司 / 创建人 名称批量富化(一次 IN 查询,消除 N+1)
List<Long> agentIds = contracts.stream()
.flatMap(c -> Stream.of(c.getContractAgentId(), c.getCustomerAgentId()))
.filter(Objects::nonNull).distinct().collect(Collectors.toList());
Map<Long, String> agentNames = agentIds.isEmpty()
? Map.of()
: agentMapper.selectBatchIds(agentIds).stream()
.collect(Collectors.toMap(Agent::getId, Agent::getName, (a, b) -> a));
List<Long> creatorIds = contracts.stream().map(ContractNew::getCreateId)
.filter(Objects::nonNull).distinct().collect(Collectors.toList());
Map<Long, String> creatorNames = creatorIds.isEmpty()
? Map.of()
: userMapper.selectBatchIds(creatorIds).stream()
.collect(Collectors.toMap(User::getId, User::getName, (a, b) -> a));
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
List<Map<String, Object>> records = new ArrayList<>();
for (ContractNew contract : contracts) {
records.add(toRecord(contract, agentNames, creatorNames, sdf, df));
}
Map<String, Object> result = new LinkedHashMap<>();
result.put("total", total);
result.put("page", pageNo);
result.put("rows", pageSize);
if (truncated) {
result.put("notice", "rows 超过上限 100,已截断为 100");
}
result.put("records", records);
return result;
}
/**
* 合同详情:行权限与 contract.list.query 一致 + 精确 id/contractNo 叠加。
* files 来自 m2.contract_file,processes 来自 m2.contract_process(按 id 正序)。
*/
@XqTool(category = "customer", kind = "read")
@Tool(name = "contract.detail.query", description = "按 id 或 contractNo 查询合同详情(二选一必填),数据来源 m2 库 contract_new 表。"
+ "行级权限与 contract.list.query 一致;合同不存在或当前身份无权查看时 record 为 null 并在 notice 字段说明(两者不区分)。"
+ "返回 record(合同全字段,含终止原因和状态文案 contractStatusText)、"
+ "files(合同附件列表,含 fileName/fileUrl)、"
+ "processes(审批流程/待办/操作记录,按 id 正序;nodeType 含义:0=创建 1=部门内审核 2=层级审核 3=终止 4=抄送;"
+ "operationType 含义:0=创建 1=审核通过 2=审核驳回 3=终止 4=修改再提交 5=抄送;"
+ "scheduleState 含义:0=无需待办 1=待办 2=已办,均附对应文案字段)。")
public Map<String, Object> contractDetailQuery(
@ToolParam(required = false, description = "合同 id;与 contractNo 二选一必填") Long id,
@ToolParam(required = false, description = "合同编号,精确匹配;与 id 二选一必填") String contractNo) {
User user = AuthContextHolder.get().getUser();
Map<String, Object> result = new LinkedHashMap<>();
if (id == null && !StringUtils.hasText(contractNo)) {
result.put("record", null);
result.put("files", List.of());
result.put("processes", List.of());
result.put("notice", "id 和 contractNo 必须传一个");
return result;
}
LambdaQueryWrapper<ContractNew> wrapper = new LambdaQueryWrapper<ContractNew>()
.eq(ContractNew::getSoftDelete, 0);
if (id != null) {
wrapper.eq(ContractNew::getId, id);
} else {
wrapper.eq(ContractNew::getContractNo, contractNo);
}
permissionService.applyContractRowFilter(wrapper, user);
ContractNew contract = contractNewMapper.selectOne(wrapper);
if (contract == null) {
result.put("record", null);
result.put("files", List.of());
result.put("processes", List.of());
result.put("notice", (id != null ? "id=" + id : "contractNo=" + contractNo) + " 不存在或当前身份无权查看");
return result;
}
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
Map<Long, String> agentNames = agentNamesOf(contract);
String createName = null;
if (contract.getCreateId() != null) {
User creator = userMapper.selectById(contract.getCreateId());
createName = creator == null ? null : creator.getName();
}
result.put("record", toRecord(contract, agentNames,
Map.of(contract.getCreateId() == null ? 0L : contract.getCreateId(),
createName == null ? "未查询到" : createName),
sdf, df));
List<ContractFile> files = contractFileMapper.selectList(new LambdaQueryWrapper<ContractFile>()
.eq(ContractFile::getSoftDelete, 0)
.eq(ContractFile::getContractId, contract.getId())
.orderByAsc(ContractFile::getId));
List<Map<String, Object>> fileList = new ArrayList<>();
for (ContractFile file : files) {
Map<String, Object> item = new LinkedHashMap<>();
item.put("id", file.getId());
item.put("fileName", file.getFileName());
item.put("fileUrl", file.getFileUrl());
item.put("createTime", file.getCreateTime() == null ? null : sdf.format(file.getCreateTime()));
fileList.add(item);
}
result.put("files", fileList);
List<ContractProcess> processes = contractProcessMapper.selectList(new LambdaQueryWrapper<ContractProcess>()
.eq(ContractProcess::getSoftDelete, 0)
.eq(ContractProcess::getContractId, contract.getId())
.orderByAsc(ContractProcess::getId));
List<Map<String, Object>> processList = new ArrayList<>();
for (ContractProcess process : processes) {
Map<String, Object> item = new LinkedHashMap<>();
item.put("id", process.getId());
item.put("nodeType", process.getNodeType());
item.put("nodeTypeText", NODE_TYPE_TEXT.getOrDefault(process.getNodeType(), "未知"));
item.put("auditLevel", process.getAuditLevel());
item.put("operationType", process.getOperationType());
item.put("operationTypeText", OPERATION_TYPE_TEXT.getOrDefault(process.getOperationType(), "未知"));
item.put("userId", process.getUserId());
item.put("userName", process.getUserName());
item.put("scheduleState", process.getScheduleState());
item.put("scheduleStateText", SCHEDULE_STATE_TEXT.getOrDefault(process.getScheduleState(), "未知"));
item.put("remark", process.getRemark());
item.put("operateTime", process.getOperateTime() == null ? null : sdf.format(process.getOperateTime()));
processList.add(item);
}
result.put("processes", processList);
return result;
}
private Map<String, Object> toRecord(ContractNew contract, Map<Long, String> agentNames,
Map<Long, String> creatorNames,
SimpleDateFormat sdf, SimpleDateFormat df) {
Map<String, Object> record = new LinkedHashMap<>();
record.put("id", contract.getId());
record.put("contractNo", contract.getContractNo());
record.put("contractName", contract.getContractName());
record.put("contractAgentId", contract.getContractAgentId());
record.put("contractAgentName", contract.getContractAgentId() == null
? "未查询到" : agentNames.getOrDefault(contract.getContractAgentId(), "未查询到"));
record.put("customerAgentId", contract.getCustomerAgentId());
record.put("customerAgentName", contract.getCustomerAgentId() == null
? "未查询到" : agentNames.getOrDefault(contract.getCustomerAgentId(), "未查询到"));
record.put("propertyId", contract.getPropertyId());
record.put("propertyName", contract.getPropertyName());
record.put("customerNo", contract.getCustomerNo());
record.put("customerName", contract.getCustomerName());
record.put("amount", contract.getAmount());
record.put("contact", contract.getContact());
record.put("startDate", contract.getStartDate() == null ? null : df.format(contract.getStartDate()));
record.put("endDate", contract.getEndDate() == null ? null : df.format(contract.getEndDate()));
record.put("expireRemind", contract.getExpireRemind());
record.put("remindDays", contract.getRemindDays());
record.put("remindTime", contract.getRemindTime() == null ? null : sdf.format(contract.getRemindTime()));
record.put("reminded", contract.getReminded());
record.put("saleId", contract.getSaleId());
record.put("saleName", contract.getSaleName());
record.put("contractStatus", contract.getContractStatus());
record.put("contractStatusText", CONTRACT_STATUS_TEXT.getOrDefault(contract.getContractStatus(), "未知"));
record.put("stopReasonType", contract.getStopReasonType());
record.put("stopReason", contract.getStopReason());
record.put("createId", contract.getCreateId());
record.put("createName", contract.getCreateId() == null
? "未查询到" : creatorNames.getOrDefault(contract.getCreateId(), "未查询到"));
record.put("createTime", contract.getCreateTime() == null ? null : sdf.format(contract.getCreateTime()));
return record;
}
private Map<Long, String> agentNamesOf(ContractNew contract) {
List<Long> agentIds = Stream.of(contract.getContractAgentId(), contract.getCustomerAgentId())
.filter(Objects::nonNull).distinct().collect(Collectors.toList());
if (agentIds.isEmpty()) {
return Map.of();
}
return agentMapper.selectBatchIds(agentIds).stream()
.collect(Collectors.toMap(Agent::getId, Agent::getName, (a, b) -> a));
}
}
@@ -9,6 +9,7 @@ import me.iiv.agent.entity.m0.HardwareView;
import me.iiv.agent.entity.m0.Properyt;
import me.iiv.agent.entity.m0.User;
import me.iiv.agent.entity.m1.MallGoodsOrder;
import me.iiv.agent.entity.m2.ContractNew;
import me.iiv.agent.entity.m2.WarehouseAgentAuth;
import me.iiv.agent.mapper.m0.AgentManageDistrictAuthMapper;
import me.iiv.agent.mapper.m0.AgentMapper;
@@ -400,4 +401,28 @@ public class PermissionService {
wrapper.in(HardwareView::getAgentId, scope.ids);
}
}
/**
* 合同(m2 contract_new)行权限:与站点/出纸机同一 getByIsAgent 变体
* (propertyFlag=true),agent 维度落到 contract_agent_id(合同所属公司,
* =物业所属销售所属公司),property 维度落到 property_id。
* 老系统 /contract/listByPage 源码不在本工作区,按合同表字段语义对齐
* district/hardware 的过滤组合(2026-09-11 决策)。
*/
public void applyContractRowFilter(LambdaQueryWrapper<ContractNew> wrapper, User user) {
RowScope scope = resolveRowScope(user);
if (scope.headquarters) {
return;
}
if (scope.salesPropertyIds != null) {
wrapper.in(ContractNew::getPropertyId, scope.salesPropertyIds);
return;
}
if (!scope.managedPropertyIds.isEmpty()) {
wrapper.and(w -> w.in(ContractNew::getContractAgentId, scope.ids)
.or().in(ContractNew::getPropertyId, scope.managedPropertyIds));
} else {
wrapper.in(ContractNew::getContractAgentId, scope.ids);
}
}
}