优化快照功能 更新sql文件
This commit is contained in:
7581
sql/yshop-pro.sql
7581
sql/yshop-pro.sql
File diff suppressed because one or more lines are too long
8644
sql/yshop_pro.sql
Normal file
8644
sql/yshop_pro.sql
Normal file
File diff suppressed because one or more lines are too long
@ -163,6 +163,7 @@ public interface ErrorCodeConstants {
|
||||
// ========== 站内信发送 1002028000 ==========
|
||||
ErrorCode NOTIFY_SEND_TEMPLATE_PARAM_MISS = new ErrorCode(1002025000, "模板参数({})缺失");
|
||||
|
||||
ErrorCode BACKUP_NO_BACKUP = new ErrorCode(100202711, "请先备份数据再还原备份!");
|
||||
ErrorCode BACKUP_MANY = new ErrorCode(100202701, "备份太频繁,距离上一次备份未超过5分钟!");
|
||||
|
||||
}
|
||||
|
@ -26,6 +26,7 @@ import java.util.stream.Collectors;
|
||||
|
||||
import static co.yixiang.yshop.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||
import static co.yixiang.yshop.module.system.enums.ErrorCodeConstants.BACKUP_MANY;
|
||||
import static co.yixiang.yshop.module.system.enums.ErrorCodeConstants.BACKUP_NO_BACKUP;
|
||||
|
||||
/**
|
||||
* 品牌 Service 实现类
|
||||
@ -34,7 +35,7 @@ import static co.yixiang.yshop.module.system.enums.ErrorCodeConstants.BACKUP_MAN
|
||||
*/
|
||||
@Service
|
||||
@Validated
|
||||
public class BackupRecordServiceImpl extends ServiceImpl<BackupRecordMapper, BackupRecordDO> implements BackupRecordService {
|
||||
public class BackupRecordServiceImpl extends ServiceImpl<BackupRecordMapper, BackupRecordDO> implements BackupRecordService {
|
||||
|
||||
@Resource
|
||||
private BackupRecordMapper backupRecordMapper;
|
||||
@ -46,33 +47,33 @@ public class BackupRecordServiceImpl extends ServiceImpl<BackupRecordMapper, Ba
|
||||
private AdminUserService adminUserService;
|
||||
|
||||
|
||||
|
||||
private static final String orderCountKey = "yshop_order_count_cache:*";
|
||||
|
||||
private static final String orderAdminCountKey = "yshop_admin_order_count_cache:*";
|
||||
|
||||
@Override
|
||||
public PageResult<BackupRecordRespVO> backupPageList(BackupPageReqVO pageVO){
|
||||
PageResult<BackupRecordDO> pageResult = this.baseMapper.selectPage(pageVO);
|
||||
if(pageResult.getTotal()>0){
|
||||
public PageResult<BackupRecordRespVO> backupPageList(BackupPageReqVO pageVO) {
|
||||
PageResult<BackupRecordDO> pageResult = this.baseMapper.selectPage(pageVO);
|
||||
if (pageResult.getTotal() > 0) {
|
||||
List<Long> ids = new ArrayList<>();
|
||||
pageResult.getList().forEach( record -> {
|
||||
ids.add(Long.parseLong(record.getCreator()));
|
||||
if(!StringUtils.isEmpty(record.getUpdater())){
|
||||
ids.add(Long.parseLong(record.getUpdater()));
|
||||
}
|
||||
}
|
||||
);
|
||||
Map<Long,String> nameMap = adminUserService.getUserList(ids).stream()
|
||||
.collect(Collectors.toMap(AdminUserDO::getId,AdminUserDO::getUsername));
|
||||
PageResult<BackupRecordRespVO> page= BackupRecordConvert.INSTANCE.convertPage(pageResult);
|
||||
page.getList().forEach(resp->{
|
||||
pageResult.getList().forEach(record -> {
|
||||
ids.add(Long.parseLong(record.getCreator()));
|
||||
if (!StringUtils.isEmpty(record.getUpdater())) {
|
||||
ids.add(Long.parseLong(record.getUpdater()));
|
||||
}
|
||||
}
|
||||
);
|
||||
Map<Long, String> nameMap = adminUserService.getUserList(ids).stream()
|
||||
.collect(Collectors.toMap(AdminUserDO::getId, AdminUserDO::getUsername));
|
||||
PageResult<BackupRecordRespVO> page = BackupRecordConvert.INSTANCE.convertPage(pageResult);
|
||||
page.getList().forEach(resp -> {
|
||||
resp.setCreatorName(nameMap.get(Long.parseLong(resp.getCreator())));
|
||||
if(!StringUtils.isEmpty(resp.getUpdater())){
|
||||
if (!StringUtils.isEmpty(resp.getUpdater())) {
|
||||
resp.setUpdaterName(nameMap.get(Long.parseLong(resp.getUpdater())));
|
||||
}
|
||||
});
|
||||
return page;
|
||||
}else{
|
||||
} else {
|
||||
return PageResult.empty();
|
||||
}
|
||||
|
||||
@ -80,11 +81,11 @@ public class BackupRecordServiceImpl extends ServiceImpl<BackupRecordMapper, Ba
|
||||
|
||||
@Transactional
|
||||
@Override
|
||||
public void backup(){
|
||||
public void backup() {
|
||||
BackupRecordDO last = backupRecordMapper.selectOne(new LambdaQueryWrapper<BackupRecordDO>().orderByDesc(
|
||||
BackupRecordDO::getId
|
||||
).last("limit 1"));
|
||||
if(last!= null) {
|
||||
if (last != null) {
|
||||
if (last.getCreateTime().plusMinutes(5).isAfter(LocalDateTime.now())) {
|
||||
throw exception(BACKUP_MANY);
|
||||
}
|
||||
@ -97,17 +98,18 @@ public class BackupRecordServiceImpl extends ServiceImpl<BackupRecordMapper, Ba
|
||||
|
||||
@Transactional
|
||||
@Override
|
||||
public void revertBackup(){
|
||||
public void revertBackup() {
|
||||
BackupRecordDO backupRecordDO = backupRecordMapper.selectOne(new LambdaQueryWrapper<BackupRecordDO>().orderByDesc(
|
||||
BackupRecordDO::getId
|
||||
).last("limit 1"));
|
||||
if(backupRecordDO!=null) {
|
||||
if (backupRecordDO.getUpdateTime().plusMinutes(5).isAfter(LocalDateTime.now()) &&
|
||||
!backupRecordDO.getCreateTime().isEqual(backupRecordDO.getUpdateTime())) {
|
||||
throw exception(BACKUP_MANY);
|
||||
}
|
||||
|
||||
Long count = backupRecordMapper.selectCount();
|
||||
if (backupRecordDO == null) throw exception(BACKUP_NO_BACKUP);
|
||||
if (backupRecordDO.getUpdateTime().plusMinutes(5).isAfter(LocalDateTime.now()) && count > 1) {
|
||||
throw exception(BACKUP_MANY);
|
||||
}
|
||||
this.baseMapper.revertBackup();
|
||||
backupRecordDO.setUpdateTime(LocalDateTime.now());
|
||||
this.baseMapper.updateById(backupRecordDO);
|
||||
//清除redis信息
|
||||
Set<String> orderCountKeys = stringRedisTemplate.keys(orderCountKey);
|
||||
|
Reference in New Issue
Block a user