refactor: site_submissions 重命名为 site_change_log,更通用的变更记录表

This commit is contained in:
mediabot-pt
2026-06-30 09:02:09 +08:00
parent a6bfc69000
commit 39af3dc034
10 changed files with 105 additions and 108 deletions

View File

@@ -6,7 +6,7 @@ import java.time.LocalDateTime;
import java.util.List;
@Data
public class SiteSubmissionDTO {
public class SiteChangeLogDTO {
private Long id;
private String siteId;
private Long submitterId;

View File

@@ -6,8 +6,8 @@ import lombok.Data;
import java.time.LocalDateTime;
@Data
@TableName("site_submissions")
public class SiteSubmission {
@TableName("site_change_log")
public class SiteChangeLog {
@TableId(type = IdType.AUTO)
private Long id;

View File

@@ -0,0 +1,19 @@
package com.par.core.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.par.core.entity.SiteChangeLog;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import java.util.List;
@Mapper
public interface SiteChangeLogMapper extends BaseMapper<SiteChangeLog> {
@Select("SELECT * FROM site_change_log WHERE status = #{status} ORDER BY created_at DESC")
List<SiteChangeLog> selectByStatus(@Param("status") String status);
@Select("SELECT * FROM site_change_log WHERE site_id = #{siteId} ORDER BY created_at DESC")
List<SiteChangeLog> selectBySiteId(@Param("siteId") String siteId);
}

View File

@@ -1,19 +0,0 @@
package com.par.core.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.par.core.entity.SiteSubmission;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import java.util.List;
@Mapper
public interface SiteSubmissionMapper extends BaseMapper<SiteSubmission> {
@Select("SELECT * FROM site_submissions WHERE status = #{status} ORDER BY created_at DESC")
List<SiteSubmission> selectByStatus(@Param("status") String status);
@Select("SELECT * FROM site_submissions WHERE site_id = #{siteId} ORDER BY created_at DESC")
List<SiteSubmission> selectBySiteId(@Param("siteId") String siteId);
}

View File

@@ -1,7 +1,7 @@
package com.par.core.service;
import com.par.core.dto.SiteChangeLogDTO;
import com.par.core.dto.SiteDTO;
import com.par.core.dto.SiteSubmissionDTO;
import com.par.core.entity.Site;
import java.util.List;
@@ -47,15 +47,15 @@ public interface SiteService {
/** 所有站点列表(管理员用) */
List<Site> listAllSites();
/** 待审核提交列表 */
List<SiteSubmissionDTO> listPendingSubmissions();
/** 待审核变更列表 */
List<SiteChangeLogDTO> listPendingChanges();
/** 审核通过 → 写入 sites 表 */
Site approveSubmission(Long submissionId, Long reviewerId);
Site approveChange(Long changeId, Long reviewerId);
/** 拒绝提交 */
void rejectSubmission(Long submissionId, Long reviewerId);
/** 拒绝变更 */
void rejectChange(Long changeId, Long reviewerId);
/** 查看站点的变更(审核)记录 */
List<SiteSubmissionDTO> listSubmissionsBySite(String siteId);
/** 查看站点的变更记录 */
List<SiteChangeLogDTO> listChangeLogBySite(String siteId);
}

View File

@@ -3,14 +3,14 @@ package com.par.core.service.impl;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.par.core.dto.SiteChangeLogDTO;
import com.par.core.dto.SiteDTO;
import com.par.core.dto.SiteSubmissionDTO;
import com.par.core.entity.Site;
import com.par.core.entity.SiteSubmission;
import com.par.core.entity.SiteChangeLog;
import com.par.core.enums.SiteStatus;
import com.par.core.enums.SiteType;
import com.par.core.mapper.SiteChangeLogMapper;
import com.par.core.mapper.SiteMapper;
import com.par.core.mapper.SiteSubmissionMapper;
import com.par.core.service.SiteService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
@@ -28,7 +28,7 @@ import java.util.stream.Collectors;
public class SiteServiceImpl implements SiteService {
private final SiteMapper siteMapper;
private final SiteSubmissionMapper submissionMapper;
private final SiteChangeLogMapper changeLogMapper;
private static final ObjectMapper objectMapper = new ObjectMapper();
// ==================== 工具方法 ====================
@@ -132,17 +132,17 @@ public class SiteServiceImpl implements SiteService {
raw.put("notes", notes != null ? notes : "");
raw.put("siteStatus", status != null ? status : "正常");
SiteSubmission sub = new SiteSubmission();
sub.setSiteId(siteId);
sub.setSubmitterId(submitterId);
sub.setStatus("pending");
SiteChangeLog entry = new SiteChangeLog();
entry.setSiteId(siteId);
entry.setSubmitterId(submitterId);
entry.setStatus("pending");
try {
sub.setRawData(objectMapper.writeValueAsString(raw));
entry.setRawData(objectMapper.writeValueAsString(raw));
} catch (JsonProcessingException e) {
throw new RuntimeException("序列化提交数据失败", e);
throw new RuntimeException("序列化变更数据失败", e);
}
submissionMapper.insert(sub);
log.info("站点信息提交审核: siteId={} submissionId={}", siteId, sub.getId());
changeLogMapper.insert(entry);
log.info("站点变更提交: siteId={} changeLogId={}", siteId, entry.getId());
}
@Override
@@ -181,23 +181,22 @@ public class SiteServiceImpl implements SiteService {
}
@Override
public List<SiteSubmissionDTO> listPendingSubmissions() {
return submissionMapper.selectByStatus("pending").stream()
.map(this::toSubmissionDTO).collect(Collectors.toList());
public List<SiteChangeLogDTO> listPendingChanges() {
return changeLogMapper.selectByStatus("pending").stream()
.map(this::toChangeLogDTO).collect(Collectors.toList());
}
@Override
public Site approveSubmission(Long submissionId, Long reviewerId) {
SiteSubmission sub = submissionMapper.selectById(submissionId);
if (sub == null) throw new IllegalArgumentException("提交记录不存在");
if (!"pending".equals(sub.getStatus())) throw new IllegalArgumentException("该提交已处理");
public Site approveChange(Long changeId, Long reviewerId) {
SiteChangeLog entry = changeLogMapper.selectById(changeId);
if (entry == null) throw new IllegalArgumentException("变更记录不存在");
if (!"pending".equals(entry.getStatus())) throw new IllegalArgumentException("该变更已处理");
// 解析提交数据
Map<String, Object> raw;
try {
raw = objectMapper.readValue(sub.getRawData(), new TypeReference<Map<String, Object>>() {});
raw = objectMapper.readValue(entry.getRawData(), new TypeReference<Map<String, Object>>() {});
} catch (Exception e) {
throw new RuntimeException("解析提交数据失败", e);
throw new RuntimeException("解析变更数据失败", e);
}
@SuppressWarnings("unchecked")
@@ -206,8 +205,7 @@ public class SiteServiceImpl implements SiteService {
List<String> urls = (List<String>) raw.getOrDefault("urls", List.of());
String notes = (String) raw.getOrDefault("notes", "");
// 写入 sites 表
Site existing = siteMapper.selectBySiteId(sub.getSiteId());
Site existing = siteMapper.selectBySiteId(entry.getSiteId());
Site site;
if (existing != null) {
existing.setNamesJson(toJsonArray(names));
@@ -218,58 +216,57 @@ public class SiteServiceImpl implements SiteService {
site = existing;
} else {
site = new Site();
site.setSiteId(sub.getSiteId());
site.setSiteId(entry.getSiteId());
site.setNamesJson(toJsonArray(names));
site.setUrlsJson(toJsonArray(urls));
site.setNotes(notes);
site.setSiteType(SiteType.UNKNOWN);
site.setSchemaVersion("1.0.0");
site.setStatus(SiteStatus.ACTIVE);
site.setSubmitterId(sub.getSubmitterId());
site.setSubmitterId(entry.getSubmitterId());
siteMapper.insert(site);
}
// 更新提交状态
sub.setStatus("approved");
sub.setReviewerId(reviewerId);
sub.setReviewedAt(java.time.LocalDateTime.now());
sub.setSiteRecordId(site.getId());
submissionMapper.updateById(sub);
log.info("站点审核通过: siteId={} submissionId={}", sub.getSiteId(), submissionId);
entry.setStatus("approved");
entry.setReviewerId(reviewerId);
entry.setReviewedAt(java.time.LocalDateTime.now());
entry.setSiteRecordId(site.getId());
changeLogMapper.updateById(entry);
log.info("站点变更通过: siteId={} changeLogId={}", entry.getSiteId(), changeId);
return site;
}
@Override
public void rejectSubmission(Long submissionId, Long reviewerId) {
SiteSubmission sub = submissionMapper.selectById(submissionId);
if (sub == null) throw new IllegalArgumentException("提交记录不存在");
if (!"pending".equals(sub.getStatus())) throw new IllegalArgumentException("该提交已处理");
sub.setStatus("rejected");
sub.setReviewerId(reviewerId);
sub.setReviewedAt(java.time.LocalDateTime.now());
submissionMapper.updateById(sub);
log.info("站点审核拒绝: siteId={} submissionId={}", sub.getSiteId(), submissionId);
public void rejectChange(Long changeId, Long reviewerId) {
SiteChangeLog entry = changeLogMapper.selectById(changeId);
if (entry == null) throw new IllegalArgumentException("变更记录不存在");
if (!"pending".equals(entry.getStatus())) throw new IllegalArgumentException("该变更已处理");
entry.setStatus("rejected");
entry.setReviewerId(reviewerId);
entry.setReviewedAt(java.time.LocalDateTime.now());
changeLogMapper.updateById(entry);
log.info("站点变更拒绝: siteId={} changeLogId={}", entry.getSiteId(), changeId);
}
@Override
public List<SiteSubmissionDTO> listSubmissionsBySite(String siteId) {
return submissionMapper.selectBySiteId(siteId).stream()
.map(this::toSubmissionDTO).collect(Collectors.toList());
public List<SiteChangeLogDTO> listChangeLogBySite(String siteId) {
return changeLogMapper.selectBySiteId(siteId).stream()
.map(this::toChangeLogDTO).collect(Collectors.toList());
}
private SiteSubmissionDTO toSubmissionDTO(SiteSubmission sub) {
SiteSubmissionDTO dto = new SiteSubmissionDTO();
dto.setId(sub.getId());
dto.setSiteId(sub.getSiteId());
dto.setSubmitterId(sub.getSubmitterId());
dto.setStatus(sub.getStatus());
dto.setReviewerId(sub.getReviewerId());
dto.setReviewComment(sub.getReviewComment());
dto.setReviewedAt(sub.getReviewedAt());
dto.setCreatedAt(sub.getCreatedAt());
private SiteChangeLogDTO toChangeLogDTO(SiteChangeLog entry) {
SiteChangeLogDTO dto = new SiteChangeLogDTO();
dto.setId(entry.getId());
dto.setSiteId(entry.getSiteId());
dto.setSubmitterId(entry.getSubmitterId());
dto.setStatus(entry.getStatus());
dto.setReviewerId(entry.getReviewerId());
dto.setReviewComment(entry.getReviewComment());
dto.setReviewedAt(entry.getReviewedAt());
dto.setCreatedAt(entry.getCreatedAt());
try {
Map<String, Object> raw = objectMapper.readValue(sub.getRawData(), new TypeReference<Map<String, Object>>() {});
Map<String, Object> raw = objectMapper.readValue(entry.getRawData(), new TypeReference<Map<String, Object>>() {});
@SuppressWarnings("unchecked")
List<String> names = (List<String>) raw.getOrDefault("names", List.of());
@SuppressWarnings("unchecked")

View File

@@ -1,4 +1,4 @@
CREATE TABLE site_submissions (
CREATE TABLE site_change_log (
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '主键',
site_id VARCHAR(64) NOT NULL COMMENT '站点标识',
submitter_id BIGINT UNSIGNED COMMENT '提交者账户ID',