From 6321cde4c0738f14bd1ce6aea8852fc928e8bff8 Mon Sep 17 00:00:00 2001 From: luqingjie <544309509@qq.com> Date: Sun, 25 Oct 2026 10:06:33 -0400 Subject: [PATCH] =?UTF-8?q?1.=E5=BA=94=E7=94=A8=E8=AF=A6=E6=83=85=E9=A1=B5?= =?UTF-8?q?=E9=9D=A2=E6=97=B6=E9=97=B4=E6=98=BE=E7=A4=BA=E4=B8=8D=E5=AF=B9?= =?UTF-8?q?=EF=BC=8C=E6=98=BE0-0-0=200:0:0=20=202.=E6=8F=90=E4=BE=9B?= =?UTF-8?q?=E5=BA=94=E7=94=A8=E5=88=A0=E9=99=A4=E5=8A=9F=E8=83=BD=EF=BC=8C?= =?UTF-8?q?=E5=88=A0=E9=99=A4=E5=89=8D=E9=9C=80=E8=A6=81=E5=88=A4=E6=96=AD?= =?UTF-8?q?=E5=BA=94=E7=94=A8=E4=B8=8B=E9=9D=A2=E6=B2=A1=E6=9C=89=E4=BB=BB?= =?UTF-8?q?=E4=BD=95=E5=85=B3=E8=81=94=E8=AE=A2=E5=8D=95=E5=92=8C=E5=87=AD?= =?UTF-8?q?=E8=AF=81=E7=AD=89=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/rental/app-workbench.md | 12 ++++++- .../src/main/resources/application-rental.yml | 2 +- .../ruoyi/system/rental/RentalController.java | 21 ++++++++++++ .../system/rental/RentalProvisioning.java | 20 +++++++++++ .../service/impl/RentAppServiceImpl.java | 26 +++++++++----- .../system/rental/RentalBusinessTest.java | 34 +++++++++++++++++++ sql/rent_app_remove_permission.sql | 11 ++++++ sql/rent_role_permissions.sql | 3 +- 8 files changed, 117 insertions(+), 12 deletions(-) create mode 100644 sql/rent_app_remove_permission.sql diff --git a/docs/rental/app-workbench.md b/docs/rental/app-workbench.md index 8597d8b..c665e6a 100644 --- a/docs/rental/app-workbench.md +++ b/docs/rental/app-workbench.md @@ -19,7 +19,17 @@ | GET /rental/app/{id} | rent:portal:view | 按当前用户校验应用归属,凭证显式选列,不返回 Secret | | POST /rental/credential/issue | rent:credential:issue | owner_type 固定 APP,owner_id 为当前应用;后端再次校验归属 | -现有 sql/rent_role_permissions.sql 已授予 PROXY_ACCOUNT 上述业务权限,无新增表结构及权限编码。若部署环境未执行该角色权限脚本,需要先完成授权并重新登录。 +现有 sql/rent_role_permissions.sql 授予 PROXY_ACCOUNT 创建、查看、签发及删除权限,无新增表结构。已部署环境执行 sql/rent_app_remove_permission.sql 增量授权删除权限,执行后重新登录。 + +## 删除与时间显示(2026-10-25) + +- 应用详情时间统一返回 UTC 毫秒时间戳,页面按浏览器本地时区显示。前端兼容 ISO 与旧 UTC 日期文本;无效值显示 `—`,不会再显示全零时间。 +- 详情底部提供删除按钮和二次确认。DELETE /rental/app/{id} 需要 rent:app:remove(兼容旧 rent:portal:register)。 +- 删除只允许本人应用;任何状态订单及任何状态 APP 凭证(包括已过期、已吊销及 VERIFY_ONLY)均阻止删除,不自动清理关联。 +- 订单下的任务、退款、流水、回调等通过禁止删除有订单应用而受到保护。审计日志独立保留,并记录删除操作,不作为业务依赖阻止空应用删除。 +- 删除、下单、凭证签发共享应用行锁,先检查后删除在同一事务完成。旧生成器单个及批量删除入口同步复用此规则,整批失败回滚。 + +本轮验证:JDK8 Rental*Test 56项通过;ESLint、Vue模板编译、`node tests/rental-app-time.mjs` 时间回归通过。未执行数据库授权SQL及真实浏览器联调。 验收:空列表引导、创建失败保留输入、创建后打开详情、取消轮换不签发、重复点击防重、一次性密钥确认、跨用户详情拒绝、窄屏布局。构建及隔离测试不替代真实登录浏览器联调。 diff --git a/ruoyi-admin/src/main/resources/application-rental.yml b/ruoyi-admin/src/main/resources/application-rental.yml index def5ea1..364cfe6 100644 --- a/ruoyi-admin/src/main/resources/application-rental.yml +++ b/ruoyi-admin/src/main/resources/application-rental.yml @@ -8,7 +8,7 @@ rental: rpc: nile: ${RENT_NILE_RPC:https://nile.trongrid.io} mainnet: ${RENT_MAINNET_RPC:https://api.trongrid.io} - api-key: ${RENT_RPC_KEY:719b2ba2-dedd-48ad-99a6-df1caa6f08ae} + api-key: ${RENT_RPC_KEY:719b2ba2-dedd-48ad-99a6-df1caa6f08ae}notify history: # 内置历史采集与云端同进程;先执行sql/rent_history_init.sql。默认关闭,不自动启用主网。 embedded-enabled: ${RENT_HISTORY_EMBEDDED_ENABLED:true} diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/rental/RentalController.java b/ruoyi-system/src/main/java/com/ruoyi/system/rental/RentalController.java index 95d3702..4d6e608 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/rental/RentalController.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/rental/RentalController.java @@ -76,12 +76,33 @@ public class RentalController { "SELECT id,name,status,notify_url,created_at,updated_at FROM rent_app WHERE id=? AND user_id=?", id, user()); require(app != null, "应用不存在或无权访问"); + // DATETIME(3) 约定存 UTC;统一输出毫秒,避免驱动返回 Timestamp/LocalDateTime 的差异。 + for (String field : Arrays.asList("created_at", "updated_at")) { + if (app.get(field) != null) { + app.put(field, time(app.get(field)).toEpochMilli()); + } + } List> credentials = store.rows( "SELECT id,api_key,status,expires_at,created_at FROM rent_credential" + " WHERE owner_type='APP' AND owner_id=? ORDER BY id DESC", id); + for (Map credential : credentials) { + for (String field : Arrays.asList("created_at", "expires_at")) { + if (credential.get(field) != null) { + credential.put(field, time(credential.get(field)).toEpochMilli()); + } + } + } return AjaxResult.success(map("app", app, "credentials", credentials)); } + /** 仅允许删除本人未产生业务关联的空应用。 */ + @DeleteMapping("/app/{id}") + @PreAuthorize("@ss.hasPermi('rent:portal:register') or @ss.hasPermi('rent:app:remove')") + public AjaxResult removeApp(@PathVariable long id) { + provisioning.deleteApp(id, user()); + return AjaxResult.success(); + } + @GetMapping("/manage/{resource}") @PreAuthorize("@ss.hasPermi('rent:manage:list')") public AjaxResult manage( diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/rental/RentalProvisioning.java b/ruoyi-system/src/main/java/com/ruoyi/system/rental/RentalProvisioning.java index 0caaed6..b8635c3 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/rental/RentalProvisioning.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/rental/RentalProvisioning.java @@ -25,6 +25,26 @@ public class RentalProvisioning { this.orders = orders; } + /** + * 删除未使用的应用。actor 为 null 仅供已有运营权限校验的内部入口使用。 + * 与下单和凭证签发使用相同父行锁,保证检查与删除之间不会插入新关联。 + * 子记录采用锁定读,避免 MySQL REPEATABLE READ 下读取到旧快照。 + * 所有历史订单、所有状态凭证均阻止删除;不级联清理任何业务或审计记录。 + */ + @Transactional(rollbackFor = Exception.class) + public int deleteApp(long appId, Long actor) { + Map app = store.get("app", appId, true); + require(actor == null || number(app, "user_id") == actor, "应用不存在或无权访问"); + require(store.one("SELECT id FROM rent_order WHERE app_id=? LIMIT 1 FOR UPDATE", appId) == null, + "应用存在关联订单(包括历史订单),不能删除"); + require(store.one("SELECT id FROM rent_credential WHERE owner_type='APP' AND owner_id=? LIMIT 1 FOR UPDATE", appId) == null, + "应用存在关联凭证(包括历史或已吊销凭证),不能删除"); + require(store.execute("DELETE FROM rent_app WHERE id=?", appId) == 1, "应用删除失败"); + // 审计不是活动业务依赖,独立留存创建和删除记录,禁止级联清理。 + store.event("APP", appId, "DELETE", actor == null ? 0 : actor, "删除无订单及凭证关联的空应用"); + return 1; + } + @Transactional(rollbackFor = Exception.class) public long create(String type, Map request, long actor) { Map row; diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/RentAppServiceImpl.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/RentAppServiceImpl.java index e6bc852..ae7c3bb 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/RentAppServiceImpl.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/RentAppServiceImpl.java @@ -31,6 +31,9 @@ public class RentAppServiceImpl extends ServiceImpl @Autowired private JdbcTemplate jdbcTemplate; + @Autowired + private com.ruoyi.system.rental.RentalProvisioning rentalProvisioning; + @Override public List getByIds(List ids ,boolean isUser, SFunction... columns) { LambdaQueryWrapper lambdaQueryWrapper = new LambdaQueryWrapper() @@ -243,13 +246,22 @@ public class RentAppServiceImpl extends ServiceImpl * @return 结果 */ @Override + @org.springframework.transaction.annotation.Transactional(rollbackFor = Exception.class) public int deleteRentAppByIds(Long[] ids,boolean isUser) { - if(isUser){ - List list= getByIds(Arrays.asList(ids),false,RentAppPlus::getUserId,RentAppPlus::getId); - checkUserPlus(list); + if (ids == null || ids.length == 0) { + return 0; } - return rentAppMapper.deleteRentAppByIds(ids); + // 旧生成器入口同样执行业务关联校验;稳定锁顺序,任一应用失败则整批回滚。 + Long actor = isUser ? SecurityUtils.getUserId() : null; + if (isUser && actor == null) { + throw new IllegalArgumentException("请先登录"); + } + int count = 0; + for (Long id : new TreeSet<>(Arrays.asList(ids))) { + count += rentalProvisioning.deleteApp(id, actor); + } + return count; } /** @@ -261,10 +273,6 @@ public class RentAppServiceImpl extends ServiceImpl @Override public int deleteRentAppById(Long id,boolean isUser) { - if(isUser){ - RentAppPlus vo = getById(id,RentAppPlus::getUserId,RentAppPlus::getId); - checkUser(vo); - } - return rentAppMapper.deleteRentAppById(id); + return deleteRentAppByIds(new Long[] {id}, isUser); } } diff --git a/ruoyi-system/src/test/java/com/ruoyi/system/rental/RentalBusinessTest.java b/ruoyi-system/src/test/java/com/ruoyi/system/rental/RentalBusinessTest.java index 2d13d0e..497e5a6 100644 --- a/ruoyi-system/src/test/java/com/ruoyi/system/rental/RentalBusinessTest.java +++ b/ruoyi-system/src/test/java/com/ruoyi/system/rental/RentalBusinessTest.java @@ -57,6 +57,9 @@ public class RentalBusinessTest { RentalController controller = new RentalController( store, null, identity, orders, funds, reviews, tasks, null, null); Map result = (Map) controller.appDetail(app).get("data"); + Map appDetail = (Map) result.get("app"); + assertEquals(time(store.get("app", app, false).get("created_at")).toEpochMilli(), + ((Number) appDetail.get("created_at")).longValue()); List> credentials = (List>) result.get("credentials"); assertEquals(1, credentials.size()); @@ -70,6 +73,37 @@ public class RentalBusinessTest { } } + /** 订单或任意历史凭证均阻止物理删除,无依赖空应用可删除且写审计。 */ + @Test + public void appDeletionRejectsEveryOrderAndCredentialState() { + try { + long empty = store.insert("app", map("user_id", 10, "name", "empty", "status", "ACTIVE")); + tx.execute(status -> { rentalDeletion().deleteApp(empty, 10L); return null; }); + assertNull(store.one("SELECT id FROM rent_app WHERE id=?", empty)); + assertEquals(1, store.rows("SELECT id FROM rent_event WHERE object_type='APP' AND object_id=? AND action='DELETE'", empty).size()); + + long withCredential = store.insert("app", map("user_id", 10, "name", "credential", "status", "ACTIVE")); + tx.execute(status -> identity.issue("APP", withCredential, 10)); + for (String credentialStatus : Arrays.asList("ACTIVE", "VERIFY_ONLY", "REVOKED")) { + store.execute("UPDATE rent_credential SET status=? WHERE owner_type='APP' AND owner_id=?", credentialStatus, withCredential); + expectFailure(() -> tx.execute(status -> { rentalDeletion().deleteApp(withCredential, 10L); return null; })); + } + + long withOrder = store.insert("app", map("user_id", 10, "name", "order", "status", "ACTIVE")); + Map order = tx.execute(status -> orders.create(withOrder, 10, + map("package_id", product, "merchant_order_no", "delete-test", "receiver_address", ADDRESS))); + tx.execute(status -> { orders.cancel(number(order, "id"), 10); return null; }); + expectFailure(() -> tx.execute(status -> { rentalDeletion().deleteApp(withOrder, 10L); return null; })); + + long foreign = store.insert("app", map("user_id", 20, "name", "foreign", "status", "ACTIVE")); + expectFailure(() -> tx.execute(status -> { rentalDeletion().deleteApp(foreign, 10L); return null; })); + } catch (Exception ex) { + throw new AssertionError(ex); + } + } + + private RentalProvisioning rentalDeletion() { return new RentalProvisioning(store, orders); } + @Before public void setup() throws Exception { JdbcDataSource source = new JdbcDataSource(); diff --git a/sql/rent_app_remove_permission.sql b/sql/rent_app_remove_permission.sql new file mode 100644 index 0000000..c3ee783 --- /dev/null +++ b/sql/rent_app_remove_permission.sql @@ -0,0 +1,11 @@ +-- 已部署环境增量授权;只授予删除本人空应用,不删除任何业务数据。 +START TRANSACTION; +SET @rent_parent=(SELECT menu_id FROM sys_menu WHERE parent_id=0 AND path='proxyRent' LIMIT 1); +INSERT INTO sys_menu(menu_name,parent_id,order_num,path,is_frame,is_cache,menu_type,visible,status,perms,icon,create_by,create_time) +SELECT '删除本人空应用',@rent_parent,99,'#',1,0,'F','0','0','rent:app:remove','#','admin',NOW() +WHERE @rent_parent IS NOT NULL AND NOT EXISTS(SELECT 1 FROM sys_menu WHERE perms='rent:app:remove'); +INSERT INTO sys_role_menu(role_id,menu_id) +SELECT r.role_id,m.menu_id FROM sys_role r JOIN sys_menu m ON m.perms='rent:app:remove' +WHERE r.role_key='PROXY_ACCOUNT' AND r.del_flag='0' +AND NOT EXISTS(SELECT 1 FROM sys_role_menu rm WHERE rm.role_id=r.role_id AND rm.menu_id=m.menu_id); +COMMIT; diff --git a/sql/rent_role_permissions.sql b/sql/rent_role_permissions.sql index 71024cd..ed3feae 100644 --- a/sql/rent_role_permissions.sql +++ b/sql/rent_role_permissions.sql @@ -18,6 +18,7 @@ INSERT INTO sys_menu(menu_name,parent_id,order_num,path,is_frame,is_cache,menu_t SELECT p.label,@rent_parent,99,'#',1,0,'F','0','0',p.perm,'#','admin',NOW() FROM ( SELECT '创建本人商户应用' label,'rent:app:create' perm + UNION ALL SELECT '删除本人空应用','rent:app:remove' UNION ALL SELECT '注册本人供应节点','rent:node:create' UNION ALL SELECT '绑定本人供应钱包','rent:wallet:create' UNION ALL SELECT '开通本人网络账户','rent:account:open' @@ -31,7 +32,7 @@ SELECT r.role_id,m.menu_id FROM sys_role r JOIN sys_menu m ON (r.role_key='PROXY_SUPPLIER' AND m.perms IN ('rent:supplier:home','rent:portal:view','rent:node:create','rent:wallet:create','rent:credential:issue','rent:wallet:bind','rent:account:open')) OR (r.role_key='PROXY_ACCOUNT' AND m.perms IN - ('rent:account:home','rent:portal:view','rent:app:create','rent:account:open','rent:credential:issue','rent:order:create'))) + ('rent:account:home','rent:portal:view','rent:app:create','rent:app:remove','rent:account:open','rent:credential:issue','rent:order:create'))) WHERE r.role_key IN ('PROXY_SUPPLIER','PROXY_ACCOUNT') AND r.del_flag='0' AND NOT EXISTS(SELECT 1 FROM sys_role_menu rm WHERE rm.role_id=r.role_id AND rm.menu_id=m.menu_id); COMMIT;