1.应用详情页面时间显示不对,显0-0-0 0:0:0 2.提供应用删除功能,删除前需要判断应用下面没有任何关联订单和凭证等信息
This commit is contained in:
1 parent
101140f3c2
commit
6321cde4c0
8 files changed
+117
-12
No files matched your search
@@ -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<Map<String, Object>> 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<String, Object> 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(
|
||||
|
||||
@@ -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<String, Object> 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<String, Object> request, long actor) {
|
||||
Map<String, Object> row;
|
||||
|
||||
@@ -31,6 +31,9 @@ public class RentAppServiceImpl extends ServiceImpl<RentAppMapper, RentAppPlus>
|
||||
@Autowired
|
||||
private JdbcTemplate jdbcTemplate;
|
||||
|
||||
@Autowired
|
||||
private com.ruoyi.system.rental.RentalProvisioning rentalProvisioning;
|
||||
|
||||
@Override
|
||||
public List<RentAppPlus> getByIds(List<Long> ids ,boolean isUser, SFunction<RentAppPlus, ?>... columns) {
|
||||
LambdaQueryWrapper<RentAppPlus> lambdaQueryWrapper = new LambdaQueryWrapper<RentAppPlus>()
|
||||
@@ -243,13 +246,22 @@ public class RentAppServiceImpl extends ServiceImpl<RentAppMapper, RentAppPlus>
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
@org.springframework.transaction.annotation.Transactional(rollbackFor = Exception.class)
|
||||
public int deleteRentAppByIds(Long[] ids,boolean isUser)
|
||||
{
|
||||
if(isUser){
|
||||
List<RentAppPlus> 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<RentAppMapper, RentAppPlus>
|
||||
@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);
|
||||
}
|
||||
}
|
||||
@@ -57,6 +57,9 @@ public class RentalBusinessTest {
|
||||
RentalController controller = new RentalController(
|
||||
store, null, identity, orders, funds, reviews, tasks, null, null);
|
||||
Map<String, Object> result = (Map<String, Object>) controller.appDetail(app).get("data");
|
||||
Map<String, Object> appDetail = (Map<String, Object>) result.get("app");
|
||||
assertEquals(time(store.get("app", app, false).get("created_at")).toEpochMilli(),
|
||||
((Number) appDetail.get("created_at")).longValue());
|
||||
List<Map<String, Object>> credentials =
|
||||
(List<Map<String, Object>>) 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<String, Object> 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();
|
||||
|
||||
Reference in new issue
Block a user