64 lines
2.2 KiB
Java
64 lines
2.2 KiB
Java
package run.webup.platform;
|
|
|
|
import java.util.*;
|
|
import org.springframework.jdbc.core.JdbcTemplate;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
@Service
|
|
public class SiteModerationService {
|
|
private final JdbcTemplate db;
|
|
private final RuntimeOperationService operations;
|
|
|
|
public SiteModerationService(JdbcTemplate db, RuntimeOperationService operations) {
|
|
this.db = db;
|
|
this.operations = operations;
|
|
}
|
|
|
|
@Transactional
|
|
public Object review(UUID project, UUID actor, String status, String reason, String ip) {
|
|
var p = db.queryForList("SELECT id FROM projects WHERE id=? FOR UPDATE", project);
|
|
if (p.isEmpty()) throw new ApiError.Failure(404, "网站项目不存在");
|
|
var old = db.queryForList("SELECT status FROM project_moderation WHERE project_id=?", project);
|
|
String before = old.isEmpty() ? "PENDING" : old.getFirst().get("status").toString();
|
|
if (old.isEmpty())
|
|
db.update(
|
|
"INSERT INTO project_moderation(project_id,status,reason,reviewer_id,reviewed_at) VALUES"
|
|
+ " (?,?,?,?,CURRENT_TIMESTAMP)",
|
|
project,
|
|
status,
|
|
reason,
|
|
actor);
|
|
else
|
|
db.update(
|
|
"UPDATE project_moderation SET"
|
|
+ " status=?,reason=?,reviewer_id=?,reviewed_at=CURRENT_TIMESTAMP,updated_at=CURRENT_TIMESTAMP"
|
|
+ " WHERE project_id=?",
|
|
status,
|
|
reason,
|
|
actor,
|
|
project);
|
|
UUID op = null;
|
|
if (Set.of("BANNED", "REJECTED").contains(status))
|
|
op =
|
|
operations.enqueue(
|
|
project, actor, "SUSPEND", "网站审核:" + reason, "moderation:" + UUID.randomUUID());
|
|
db.update(
|
|
"INSERT INTO admin_operation_logs(id,actor_id,action,target,ip,details) VALUES"
|
|
+ " (?,?,?,?,?,?)",
|
|
UUID.randomUUID(),
|
|
actor,
|
|
"SITE_MODERATION",
|
|
project.toString(),
|
|
ip,
|
|
before + " → " + status + "; " + reason);
|
|
return Map.of(
|
|
"message",
|
|
op == null ? "审核状态已更新" : "已限制发布与恢复,运行暂停已排队执行",
|
|
"status",
|
|
status,
|
|
"operationId",
|
|
op == null ? "" : op.toString());
|
|
}
|
|
}
|