代理租赁实现

This commit is contained in:
lu7213 committed 2026-10-22 19:58:57 -04:00
1 parent 1c0544afe0
commit 2a9f1c4c7c
38 files changed
+5824 -6

No files matched your search

@@ -0,0 +1,106 @@
package com.ruoyi.system.rental;
import static com.ruoyi.system.rental.RentalValues.*;
import org.springframework.stereotype.Service;
import java.util.*;
/** 查询层显式沿关联关系确定用户归属,绝不对没有user_id的表直接拼用户过滤。 */
@Service
public class RentalQueries {
private final RentalStore store;
public RentalQueries(RentalStore store) {
this.store = store;
}
public List<Map<String, Object>> list(String type, Long user, int page) {
String table = store.table(type);
String where = "1=1";
List<Object> args = new ArrayList<>();
if (user != null) {
switch (type) {
case "app":
case "node":
case "account":
where = "r.user_id=?";
break;
case "package":
where = "r.status='ACTIVE'";
break;
case "wallet":
where =
"EXISTS(SELECT 1 FROM rent_node n WHERE n.id=r.node_id AND"
+ " n.user_id=?)";
break;
case "order":
where =
"EXISTS(SELECT 1 FROM rent_app a WHERE a.id=r.app_id AND a.user_id=?)"
+ " OR r.supplier_user_id=?";
break;
case "task":
where =
"EXISTS(SELECT 1 FROM rent_node n WHERE n.id=r.node_id AND"
+ " n.user_id=?)";
break;
case "ledger":
case "settlement":
where =
"EXISTS(SELECT 1 FROM rent_account a WHERE a.id=r.account_id AND"
+ " a.user_id=?)";
break;
case "refund":
where =
"EXISTS(SELECT 1 FROM rent_order o JOIN rent_app a ON a.id=o.app_id"
+ " WHERE o.id=r.order_id AND a.user_id=?)";
break;
case "credential":
where =
"(r.owner_type='APP' AND EXISTS(SELECT 1 FROM rent_app a WHERE"
+ " a.id=r.owner_id AND a.user_id=?)) OR (r.owner_type='NODE' AND"
+ " EXISTS(SELECT 1 FROM rent_node n WHERE n.id=r.owner_id AND"
+ " n.user_id=?))";
break;
default:
throw new IllegalArgumentException("该资源仅限运营查询");
}
if (!"package".equals(type)) {
args.add(user);
}
if ("order".equals(type) || "credential".equals(type)) {
args.add(user);
}
}
require(page > 0 && page <= 10000, "页码不合法");
args.add((page - 1) * 50);
List<Map<String, Object>> rows =
store.rows(
"SELECT r.* FROM "
+ table
+ " r WHERE ("
+ where
+ ") ORDER BY r.id DESC LIMIT 50 OFFSET ?",
args.toArray());
for (Map<String, Object> row : rows) {
row.remove("api_secret");
row.remove("ownership_signature");
row.remove("ownership_challenge");
row.remove("ownership_message");
row.remove("signature");
row.remove("nonce");
if (user != null && "order".equals(type)) {
for (String field :
Arrays.asList(
"package_snapshot",
"supplier_amount",
"supplier_fee_percent",
"supplier_fee_amount",
"supplier_net_amount")) {
row.remove(field);
}
}
}
return rows;
}
}