refactor: site_change_log 重命名为 site_changes,更准确表达待审核+已变更
This commit is contained in:
@@ -266,7 +266,7 @@ public class AdminController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/sites/pending")
|
@GetMapping("/sites/pending")
|
||||||
public ApiResponse<List<com.par.core.dto.SiteChangeLogDTO>> listPendingChanges(HttpServletRequest request) {
|
public ApiResponse<List<com.par.core.dto.SiteChangeDTO>> listPendingChanges(HttpServletRequest request) {
|
||||||
checkAdmin(request);
|
checkAdmin(request);
|
||||||
return ApiResponse.success(siteService.listPendingChanges());
|
return ApiResponse.success(siteService.listPendingChanges());
|
||||||
}
|
}
|
||||||
@@ -290,10 +290,10 @@ public class AdminController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/sites/{siteId}/changes")
|
@GetMapping("/sites/{siteId}/changes")
|
||||||
public ApiResponse<List<com.par.core.dto.SiteChangeLogDTO>> listSiteChanges(
|
public ApiResponse<List<com.par.core.dto.SiteChangeDTO>> listSiteChanges(
|
||||||
@PathVariable("siteId") String siteId, HttpServletRequest request) {
|
@PathVariable("siteId") String siteId, HttpServletRequest request) {
|
||||||
checkAdmin(request);
|
checkAdmin(request);
|
||||||
return ApiResponse.success(siteService.listChangeLogBySite(siteId));
|
return ApiResponse.success(siteService.listChangesBySite(siteId));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void checkAdmin(HttpServletRequest request) {
|
private void checkAdmin(HttpServletRequest request) {
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import java.time.LocalDateTime;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
public class SiteChangeLogDTO {
|
public class SiteChangeDTO {
|
||||||
private Long id;
|
private Long id;
|
||||||
private String siteId;
|
private String siteId;
|
||||||
private Long submitterId;
|
private Long submitterId;
|
||||||
@@ -6,8 +6,8 @@ import lombok.Data;
|
|||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
@TableName("site_change_log")
|
@TableName("site_changes")
|
||||||
public class SiteChangeLog {
|
public class SiteChange {
|
||||||
|
|
||||||
@TableId(type = IdType.AUTO)
|
@TableId(type = IdType.AUTO)
|
||||||
private Long id;
|
private Long id;
|
||||||
@@ -1,19 +0,0 @@
|
|||||||
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);
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
package com.par.core.mapper;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import com.par.core.entity.SiteChange;
|
||||||
|
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 SiteChangeMapper extends BaseMapper<SiteChange> {
|
||||||
|
|
||||||
|
@Select("SELECT * FROM site_changes WHERE status = #{status} ORDER BY created_at DESC")
|
||||||
|
List<SiteChange> selectByStatus(@Param("status") String status);
|
||||||
|
|
||||||
|
@Select("SELECT * FROM site_changes WHERE site_id = #{siteId} ORDER BY created_at DESC")
|
||||||
|
List<SiteChange> selectBySiteId(@Param("siteId") String siteId);
|
||||||
|
}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
package com.par.core.service;
|
package com.par.core.service;
|
||||||
|
|
||||||
import com.par.core.dto.SiteChangeLogDTO;
|
import com.par.core.dto.SiteChangeDTO;
|
||||||
import com.par.core.dto.SiteDTO;
|
import com.par.core.dto.SiteDTO;
|
||||||
import com.par.core.entity.Site;
|
import com.par.core.entity.Site;
|
||||||
|
|
||||||
@@ -48,7 +48,7 @@ public interface SiteService {
|
|||||||
List<Site> listAllSites();
|
List<Site> listAllSites();
|
||||||
|
|
||||||
/** 待审核变更列表 */
|
/** 待审核变更列表 */
|
||||||
List<SiteChangeLogDTO> listPendingChanges();
|
List<SiteChangeDTO> listPendingChanges();
|
||||||
|
|
||||||
/** 审核通过 → 写入 sites 表 */
|
/** 审核通过 → 写入 sites 表 */
|
||||||
Site approveChange(Long changeId, Long reviewerId);
|
Site approveChange(Long changeId, Long reviewerId);
|
||||||
@@ -57,5 +57,5 @@ public interface SiteService {
|
|||||||
void rejectChange(Long changeId, Long reviewerId);
|
void rejectChange(Long changeId, Long reviewerId);
|
||||||
|
|
||||||
/** 查看站点的变更记录 */
|
/** 查看站点的变更记录 */
|
||||||
List<SiteChangeLogDTO> listChangeLogBySite(String siteId);
|
List<SiteChangeDTO> listChangesBySite(String siteId);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,13 +3,13 @@ package com.par.core.service.impl;
|
|||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
import com.fasterxml.jackson.core.type.TypeReference;
|
import com.fasterxml.jackson.core.type.TypeReference;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import com.par.core.dto.SiteChangeLogDTO;
|
import com.par.core.dto.SiteChangeDTO;
|
||||||
import com.par.core.dto.SiteDTO;
|
import com.par.core.dto.SiteDTO;
|
||||||
import com.par.core.entity.Site;
|
import com.par.core.entity.Site;
|
||||||
import com.par.core.entity.SiteChangeLog;
|
import com.par.core.entity.SiteChange;
|
||||||
import com.par.core.enums.SiteStatus;
|
import com.par.core.enums.SiteStatus;
|
||||||
import com.par.core.enums.SiteType;
|
import com.par.core.enums.SiteType;
|
||||||
import com.par.core.mapper.SiteChangeLogMapper;
|
import com.par.core.mapper.SiteChangeMapper;
|
||||||
import com.par.core.mapper.SiteMapper;
|
import com.par.core.mapper.SiteMapper;
|
||||||
import com.par.core.service.SiteService;
|
import com.par.core.service.SiteService;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
@@ -28,7 +28,7 @@ import java.util.stream.Collectors;
|
|||||||
public class SiteServiceImpl implements SiteService {
|
public class SiteServiceImpl implements SiteService {
|
||||||
|
|
||||||
private final SiteMapper siteMapper;
|
private final SiteMapper siteMapper;
|
||||||
private final SiteChangeLogMapper changeLogMapper;
|
private final SiteChangeMapper changeMapper;
|
||||||
private static final ObjectMapper objectMapper = new ObjectMapper();
|
private static final ObjectMapper objectMapper = new ObjectMapper();
|
||||||
|
|
||||||
// ==================== 工具方法 ====================
|
// ==================== 工具方法 ====================
|
||||||
@@ -132,7 +132,7 @@ public class SiteServiceImpl implements SiteService {
|
|||||||
raw.put("notes", notes != null ? notes : "");
|
raw.put("notes", notes != null ? notes : "");
|
||||||
raw.put("siteStatus", status != null ? status : "正常");
|
raw.put("siteStatus", status != null ? status : "正常");
|
||||||
|
|
||||||
SiteChangeLog entry = new SiteChangeLog();
|
SiteChange entry = new SiteChange();
|
||||||
entry.setSiteId(siteId);
|
entry.setSiteId(siteId);
|
||||||
entry.setSubmitterId(submitterId);
|
entry.setSubmitterId(submitterId);
|
||||||
entry.setStatus("pending");
|
entry.setStatus("pending");
|
||||||
@@ -141,8 +141,8 @@ public class SiteServiceImpl implements SiteService {
|
|||||||
} catch (JsonProcessingException e) {
|
} catch (JsonProcessingException e) {
|
||||||
throw new RuntimeException("序列化变更数据失败", e);
|
throw new RuntimeException("序列化变更数据失败", e);
|
||||||
}
|
}
|
||||||
changeLogMapper.insert(entry);
|
changeMapper.insert(entry);
|
||||||
log.info("站点变更提交: siteId={} changeLogId={}", siteId, entry.getId());
|
log.info("站点变更提交: siteId={} changeId={}", siteId, entry.getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -181,14 +181,14 @@ public class SiteServiceImpl implements SiteService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<SiteChangeLogDTO> listPendingChanges() {
|
public List<SiteChangeDTO> listPendingChanges() {
|
||||||
return changeLogMapper.selectByStatus("pending").stream()
|
return changeMapper.selectByStatus("pending").stream()
|
||||||
.map(this::toChangeLogDTO).collect(Collectors.toList());
|
.map(this::toChangeDTO).collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Site approveChange(Long changeId, Long reviewerId) {
|
public Site approveChange(Long changeId, Long reviewerId) {
|
||||||
SiteChangeLog entry = changeLogMapper.selectById(changeId);
|
SiteChange entry = changeMapper.selectById(changeId);
|
||||||
if (entry == null) throw new IllegalArgumentException("变更记录不存在");
|
if (entry == null) throw new IllegalArgumentException("变更记录不存在");
|
||||||
if (!"pending".equals(entry.getStatus())) throw new IllegalArgumentException("该变更已处理");
|
if (!"pending".equals(entry.getStatus())) throw new IllegalArgumentException("该变更已处理");
|
||||||
|
|
||||||
@@ -231,31 +231,31 @@ public class SiteServiceImpl implements SiteService {
|
|||||||
entry.setReviewerId(reviewerId);
|
entry.setReviewerId(reviewerId);
|
||||||
entry.setReviewedAt(java.time.LocalDateTime.now());
|
entry.setReviewedAt(java.time.LocalDateTime.now());
|
||||||
entry.setSiteRecordId(site.getId());
|
entry.setSiteRecordId(site.getId());
|
||||||
changeLogMapper.updateById(entry);
|
changeMapper.updateById(entry);
|
||||||
log.info("站点变更通过: siteId={} changeLogId={}", entry.getSiteId(), changeId);
|
log.info("站点变更通过: siteId={} changeId={}", entry.getSiteId(), changeId);
|
||||||
return site;
|
return site;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void rejectChange(Long changeId, Long reviewerId) {
|
public void rejectChange(Long changeId, Long reviewerId) {
|
||||||
SiteChangeLog entry = changeLogMapper.selectById(changeId);
|
SiteChange entry = changeMapper.selectById(changeId);
|
||||||
if (entry == null) throw new IllegalArgumentException("变更记录不存在");
|
if (entry == null) throw new IllegalArgumentException("变更记录不存在");
|
||||||
if (!"pending".equals(entry.getStatus())) throw new IllegalArgumentException("该变更已处理");
|
if (!"pending".equals(entry.getStatus())) throw new IllegalArgumentException("该变更已处理");
|
||||||
entry.setStatus("rejected");
|
entry.setStatus("rejected");
|
||||||
entry.setReviewerId(reviewerId);
|
entry.setReviewerId(reviewerId);
|
||||||
entry.setReviewedAt(java.time.LocalDateTime.now());
|
entry.setReviewedAt(java.time.LocalDateTime.now());
|
||||||
changeLogMapper.updateById(entry);
|
changeMapper.updateById(entry);
|
||||||
log.info("站点变更拒绝: siteId={} changeLogId={}", entry.getSiteId(), changeId);
|
log.info("站点变更拒绝: siteId={} changeId={}", entry.getSiteId(), changeId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<SiteChangeLogDTO> listChangeLogBySite(String siteId) {
|
public List<SiteChangeDTO> listChangesBySite(String siteId) {
|
||||||
return changeLogMapper.selectBySiteId(siteId).stream()
|
return changeMapper.selectBySiteId(siteId).stream()
|
||||||
.map(this::toChangeLogDTO).collect(Collectors.toList());
|
.map(this::toChangeDTO).collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
private SiteChangeLogDTO toChangeLogDTO(SiteChangeLog entry) {
|
private SiteChangeDTO toChangeDTO(SiteChange entry) {
|
||||||
SiteChangeLogDTO dto = new SiteChangeLogDTO();
|
SiteChangeDTO dto = new SiteChangeDTO();
|
||||||
dto.setId(entry.getId());
|
dto.setId(entry.getId());
|
||||||
dto.setSiteId(entry.getSiteId());
|
dto.setSiteId(entry.getSiteId());
|
||||||
dto.setSubmitterId(entry.getSubmitterId());
|
dto.setSubmitterId(entry.getSubmitterId());
|
||||||
|
|||||||
@@ -1,16 +0,0 @@
|
|||||||
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',
|
|
||||||
raw_data JSON NOT NULL COMMENT '原始提交数据 {names,urls,notes,site_status}',
|
|
||||||
status VARCHAR(20) NOT NULL DEFAULT 'pending' COMMENT '审核状态: pending/approved/rejected',
|
|
||||||
reviewer_id BIGINT UNSIGNED COMMENT '审核人ID',
|
|
||||||
review_comment VARCHAR(500) COMMENT '审核备注',
|
|
||||||
reviewed_at DATETIME COMMENT '审核时间',
|
|
||||||
site_record_id BIGINT UNSIGNED COMMENT '审核通过后关联的 sites.id',
|
|
||||||
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
||||||
PRIMARY KEY (id),
|
|
||||||
KEY idx_site_id (site_id),
|
|
||||||
KEY idx_status (status),
|
|
||||||
KEY idx_submitter (submitter_id)
|
|
||||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='站点提交审核表';
|
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
CREATE TABLE site_changes (
|
||||||
|
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '涓婚敭',
|
||||||
|
site_id VARCHAR(64) NOT NULL COMMENT '绔欑偣鏍囪瘑',
|
||||||
|
submitter_id BIGINT UNSIGNED COMMENT '鎻愪氦鑰呰处鎴稩D',
|
||||||
|
raw_data JSON NOT NULL COMMENT '鍘熷鎻愪氦鏁版嵁 {names,urls,notes,site_status}',
|
||||||
|
status VARCHAR(20) NOT NULL DEFAULT 'pending' COMMENT '瀹℃牳鐘舵€? pending/approved/rejected',
|
||||||
|
reviewer_id BIGINT UNSIGNED COMMENT '瀹℃牳浜篒D',
|
||||||
|
review_comment VARCHAR(500) COMMENT '瀹℃牳澶囨敞',
|
||||||
|
reviewed_at DATETIME COMMENT '瀹℃牳鏃堕棿',
|
||||||
|
site_record_id BIGINT UNSIGNED COMMENT '瀹℃牳閫氳繃鍚庡叧鑱旂殑 sites.id',
|
||||||
|
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
PRIMARY KEY (id),
|
||||||
|
KEY idx_site_id (site_id),
|
||||||
|
KEY idx_status (status),
|
||||||
|
KEY idx_submitter (submitter_id)
|
||||||
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='绔欑偣鎻愪氦瀹℃牳琛?;
|
||||||
Reference in New Issue
Block a user