[fix] 工单工具审查修复:销售负责人前缀碰撞/装机人员/撤机凭证/送货权限范围 (#22)
This commit is contained in:
@@ -230,7 +230,6 @@ public class InstallOrderTools implements ToolObject {
|
||||
List<InstallOrderUser> users = userMapper.selectList(new LambdaQueryWrapper<InstallOrderUser>()
|
||||
.eq(InstallOrderUser::getSoftDelete, 0)
|
||||
.eq(InstallOrderUser::getInstallOrderNo, no)
|
||||
.eq(InstallOrderUser::getType, 0)
|
||||
.orderByAsc(InstallOrderUser::getId));
|
||||
Long processTotal = include ? processMapper.selectCount(processBase(no)) : 0L;
|
||||
List<InstallOrderProcess> processes = include ? processMapper.selectList(processBase(no)
|
||||
|
||||
@@ -3,13 +3,17 @@ package me.iiv.agent.mcp.tool;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.support.SFunction;
|
||||
import me.iiv.agent.entity.m0.User;
|
||||
import me.iiv.agent.entity.m1.MallLogisticsPic;
|
||||
import me.iiv.agent.entity.m2.InstallOrderUser;
|
||||
import me.iiv.agent.entity.m2.OrderProcess;
|
||||
import me.iiv.agent.entity.m2.PickupOrderProcess;
|
||||
import me.iiv.agent.entity.m2.WarehouseInOutPic;
|
||||
import me.iiv.agent.entity.m2.WithdrawOrder;
|
||||
import me.iiv.agent.entity.m2.WithdrawOrderDetails;
|
||||
import me.iiv.agent.mapper.m1.MallLogisticsPicMapper;
|
||||
import me.iiv.agent.mapper.m2.InstallOrderUserMapper;
|
||||
import me.iiv.agent.mapper.m2.OrderProcessMapper;
|
||||
import me.iiv.agent.mapper.m2.PickupOrderProcessMapper;
|
||||
import me.iiv.agent.mapper.m2.WarehouseInOutPicMapper;
|
||||
import me.iiv.agent.mapper.m2.WithdrawOrderDetailsMapper;
|
||||
import me.iiv.agent.mapper.m2.WithdrawOrderMapper;
|
||||
@@ -29,6 +33,7 @@ import java.time.ZoneId;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.time.format.DateTimeParseException;
|
||||
import java.time.format.ResolverStyle;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
@@ -73,6 +78,8 @@ public class WithdrawOrderTools implements ToolObject {
|
||||
final OrderProcessMapper processMapper;
|
||||
final InstallOrderUserMapper userMapper;
|
||||
final WarehouseInOutPicMapper picMapper;
|
||||
final PickupOrderProcessMapper pickupProcessMapper;
|
||||
final MallLogisticsPicMapper mallPicMapper;
|
||||
final PermissionService permissionService;
|
||||
|
||||
public WithdrawOrderTools(WithdrawOrderMapper orderMapper,
|
||||
@@ -80,12 +87,16 @@ public class WithdrawOrderTools implements ToolObject {
|
||||
OrderProcessMapper processMapper,
|
||||
InstallOrderUserMapper userMapper,
|
||||
WarehouseInOutPicMapper picMapper,
|
||||
PickupOrderProcessMapper pickupProcessMapper,
|
||||
MallLogisticsPicMapper mallPicMapper,
|
||||
PermissionService permissionService) {
|
||||
this.orderMapper = orderMapper;
|
||||
this.detailsMapper = detailsMapper;
|
||||
this.processMapper = processMapper;
|
||||
this.userMapper = userMapper;
|
||||
this.picMapper = picMapper;
|
||||
this.pickupProcessMapper = pickupProcessMapper;
|
||||
this.mallPicMapper = mallPicMapper;
|
||||
this.permissionService = permissionService;
|
||||
}
|
||||
|
||||
@@ -179,7 +190,9 @@ public class WithdrawOrderTools implements ToolObject {
|
||||
@Tool(name = "withdraw.order.detail.query", description = "按 id 或撤机工单号查询详情。"
|
||||
+ "两者至少传一个,同时传入时必须匹配同一条记录;行级权限与列表一致。"
|
||||
+ "不存在或无权查看统一返回 NOT_FOUND_OR_FORBIDDEN。返回主单、撤机物品明细(in_count>0)、"
|
||||
+ "运维/协同人员、已办流程(共享 order_process,order_type=1,排除抄送)与凭证附件;附件仅返回 bucket/objectKey/fileName。")
|
||||
+ "运维/协同人员、已办流程(共享 order_process,order_type=1,排除抄送)与凭证附件;"
|
||||
+ "凭证附件含取货/入库签收凭证(source=pickup_process)与发货附件(source=logistics),"
|
||||
+ "仅返回 bucket/objectKey/fileName。")
|
||||
public Map<String, Object> withdrawOrderDetailQuery(
|
||||
@ToolParam(required = false, description = "撤机工单主键 id,与 withdrawOrderNo 至少传一个") Long id,
|
||||
@ToolParam(required = false, description = "撤机工单号,与 id 至少传一个") String withdrawOrderNo) {
|
||||
@@ -224,7 +237,6 @@ public class WithdrawOrderTools implements ToolObject {
|
||||
.orderByAsc(OrderProcess::getOperationTime)
|
||||
.orderByAsc(OrderProcess::getId));
|
||||
Map<Long, List<InstallOrderUser>> processUsers = processUsers(processes);
|
||||
List<WarehouseInOutPic> certificates = certificates(processes);
|
||||
|
||||
Map<String, Object> result = new LinkedHashMap<>();
|
||||
result.put("record", orderRecord(order));
|
||||
@@ -233,8 +245,7 @@ public class WithdrawOrderTools implements ToolObject {
|
||||
result.put("cooperateUsers", personnel(users, 1));
|
||||
result.put("processes", processes.stream().map(process -> processRecord(process,
|
||||
processUsers.getOrDefault(process.getId(), List.of()))).collect(Collectors.toList()));
|
||||
result.put("certificates", certificates.stream().map(this::fileRecord)
|
||||
.collect(Collectors.toList()));
|
||||
result.put("certificates", certificates(order.getPickupOrderNo()));
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -250,14 +261,50 @@ public class WithdrawOrderTools implements ToolObject {
|
||||
LinkedHashMap::new, Collectors.toList()));
|
||||
}
|
||||
|
||||
private List<WarehouseInOutPic> certificates(List<OrderProcess> processes) {
|
||||
if (processes.isEmpty()) return List.of();
|
||||
List<Long> ids = processes.stream().map(OrderProcess::getId).collect(Collectors.toList());
|
||||
return picMapper.selectList(new LambdaQueryWrapper<WarehouseInOutPic>()
|
||||
.eq(WarehouseInOutPic::getSoftDelete, 0)
|
||||
.in(WarehouseInOutPic::getAggregateId, ids)
|
||||
.eq(WarehouseInOutPic::getInOutAllocationType, PICKUP_AGGREGATE_TYPE)
|
||||
.orderByAsc(WarehouseInOutPic::getId));
|
||||
/**
|
||||
* 凭证附件,1:1 对齐老系统 lookDetails:取货/入库签收凭证挂在派生取货工单的
|
||||
* pickup_order_process(operation_theme 1=取货、2=入库确认,aggregate_id 指向其 id,
|
||||
* 与共享 order_process 是两套自增 id,不能混查),结单节点的发货附件来自
|
||||
* mall_logistics_pic(order_no = 取货单号)。无取货单号时返回空。
|
||||
*/
|
||||
private List<Map<String, Object>> certificates(String pickupOrderNo) {
|
||||
if (!StringUtils.hasText(pickupOrderNo)) {
|
||||
return List.of();
|
||||
}
|
||||
List<Map<String, Object>> records = new ArrayList<>();
|
||||
List<PickupOrderProcess> pickupProcesses = pickupProcessMapper.selectList(
|
||||
new LambdaQueryWrapper<PickupOrderProcess>()
|
||||
.eq(PickupOrderProcess::getSoftDelete, 0)
|
||||
.eq(PickupOrderProcess::getPickupOrderNo, pickupOrderNo)
|
||||
.in(PickupOrderProcess::getOperationTheme, 1, 2));
|
||||
if (!pickupProcesses.isEmpty()) {
|
||||
List<Long> processIds = pickupProcesses.stream().map(PickupOrderProcess::getId)
|
||||
.collect(Collectors.toList());
|
||||
picMapper.selectList(new LambdaQueryWrapper<WarehouseInOutPic>()
|
||||
.eq(WarehouseInOutPic::getSoftDelete, 0)
|
||||
.in(WarehouseInOutPic::getAggregateId, processIds)
|
||||
.eq(WarehouseInOutPic::getInOutAllocationType, PICKUP_AGGREGATE_TYPE)
|
||||
.orderByAsc(WarehouseInOutPic::getId))
|
||||
.forEach(pic -> {
|
||||
Map<String, Object> record = fileRecord(pic);
|
||||
record.put("source", "pickup_process");
|
||||
records.add(record);
|
||||
});
|
||||
}
|
||||
mallPicMapper.selectList(new LambdaQueryWrapper<MallLogisticsPic>()
|
||||
.eq(MallLogisticsPic::getSoftDelete, 0)
|
||||
.eq(MallLogisticsPic::getOrderNo, pickupOrderNo)
|
||||
.orderByAsc(MallLogisticsPic::getId))
|
||||
.forEach(pic -> {
|
||||
Map<String, Object> record = new LinkedHashMap<>();
|
||||
record.put("id", pic.getId());
|
||||
record.put("fileName", pic.getFileName());
|
||||
record.put("bucket", pic.getOssbucketname());
|
||||
record.put("objectKey", nullToEmpty(pic.getOssfolder()) + nullToEmpty(pic.getFileName()));
|
||||
record.put("source", "logistics");
|
||||
records.add(record);
|
||||
});
|
||||
return records;
|
||||
}
|
||||
|
||||
private Map<String, Object> orderRecord(WithdrawOrder order) {
|
||||
|
||||
@@ -198,28 +198,52 @@ public class PermissionService {
|
||||
}
|
||||
|
||||
/**
|
||||
* 送货工单权限:总部看全部;销售非负责人按自己创建/代管物业;其余代理身份
|
||||
* 可看申请代理、所属代理、代管物业范围,以及本人参与过流程的工单。
|
||||
* 送货工单权限:1:1 复刻老系统 getWorkOrderAuth(type=1)。总部看全部;其余代理身份
|
||||
* 可看申请代理、所属代理(本代理+授权代管,不含直属下级)、授权代管物业范围,
|
||||
* 以及本人出现在 delivery_order_process 的工单;销售非负责人只看自己创建及
|
||||
* 代管代理名下物业,空集塞 0。
|
||||
* 列表和详情必须复用本方法,避免详情绕过行权限。
|
||||
*/
|
||||
public void applyDeliveryOrderRowFilter(LambdaQueryWrapper<DeliveryOrder> wrapper, User user) {
|
||||
RowScope scope = resolveRowScope(user);
|
||||
if (scope.headquarters) {
|
||||
if (!isAgentAuthority(user.getAuthorityId())) {
|
||||
return;
|
||||
}
|
||||
if (user.getAgentId() == null) {
|
||||
throw new IllegalStateException("代理商用户未关联代理商,拒绝访问业务数据");
|
||||
}
|
||||
List<WarehouseAgentAuth> auths = managedAuths(user.getId());
|
||||
List<Long> agentIds = new ArrayList<>();
|
||||
agentIds.add(user.getAgentId());
|
||||
agentIds.addAll(auths.stream().map(WarehouseAgentAuth::getManagerAgentId)
|
||||
.collect(Collectors.toList()));
|
||||
if (isSalesNonLeader(user)) {
|
||||
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());
|
||||
List<Long> managedAgentIds = auths.stream().map(WarehouseAgentAuth::getManagerAgentId)
|
||||
.collect(Collectors.toList());
|
||||
if (!managedAgentIds.isEmpty()) {
|
||||
propertyIds.addAll(properytMapper.selectList(new LambdaQueryWrapper<Properyt>()
|
||||
.eq(Properyt::getSoftDelete, 0)
|
||||
.in(Properyt::getAgentId, managedAgentIds)
|
||||
.select(Properyt::getId))
|
||||
.stream().map(Properyt::getId).collect(Collectors.toList()));
|
||||
}
|
||||
wrapper.in(DeliveryOrder::getPropertyId,
|
||||
propertyIds.isEmpty() ? List.of(0L) : new LinkedHashSet<>(propertyIds));
|
||||
return;
|
||||
}
|
||||
String participantExists = "EXISTS (SELECT 1 FROM delivery_order_process dop "
|
||||
+ "WHERE dop.delivery_order_no = delivery_order.delivery_order_no "
|
||||
+ "AND dop.soft_delete = 0 AND dop.user_id = {0})";
|
||||
if (scope.salesPropertyIds != null) {
|
||||
wrapper.and(w -> w.in(DeliveryOrder::getPropertyId, scope.salesPropertyIds)
|
||||
.or().apply(participantExists, user.getId()));
|
||||
return;
|
||||
}
|
||||
List<Long> managedPropertyIds = managedPropertyIds(agentIds);
|
||||
wrapper.and(w -> {
|
||||
w.in(DeliveryOrder::getApplyAgentId, scope.ids)
|
||||
.or().in(DeliveryOrder::getAgentId, scope.ids);
|
||||
if (!scope.managedPropertyIds.isEmpty()) {
|
||||
w.or().in(DeliveryOrder::getPropertyId, scope.managedPropertyIds);
|
||||
w.in(DeliveryOrder::getApplyAgentId, agentIds)
|
||||
.or().in(DeliveryOrder::getAgentId, agentIds);
|
||||
if (!managedPropertyIds.isEmpty()) {
|
||||
w.or().in(DeliveryOrder::getPropertyId, managedPropertyIds);
|
||||
}
|
||||
w.or().apply(participantExists, user.getId());
|
||||
});
|
||||
@@ -494,7 +518,7 @@ public class PermissionService {
|
||||
|
||||
/**
|
||||
* 销售部门非负责人判定(老系统 getByIsAgent 内 saleFlag 逻辑,:703-710):
|
||||
* Redis db5 Dictionary hash 的 authDeptId 命中 ",deptId," 且 authDeptPostId 不命中 "postId,"。
|
||||
* Redis db5 Dictionary hash 的 authDeptId 命中 ",deptId," 且 authDeptPostId 不命中 ",postId,"。
|
||||
* 字典缺失时拒绝访问,避免权限配置异常导致数据范围放宽。
|
||||
*/
|
||||
public boolean isSalesNonLeader(User user) {
|
||||
@@ -508,7 +532,7 @@ public class PermissionService {
|
||||
throw new IllegalStateException("销售数据权限配置不可用,拒绝访问业务数据");
|
||||
}
|
||||
return authDeptId.toString().contains("," + user.getDeptId() + ",")
|
||||
&& !authDeptPostId.toString().contains(user.getPostId() + ",");
|
||||
&& !authDeptPostId.toString().contains("," + user.getPostId() + ",");
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user