|
|
|
|
@@ -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")
|
|
|
|
|
|