添加cgy留言板数据时间修改接口
This commit is contained in:
parent
cf9481b89e
commit
081edb0534
@ -55,6 +55,7 @@ public class WebConfig implements WebMvcConfigurer {
|
||||
whiteList.add("/api/learn/cgy/{messageId}/comment");
|
||||
whiteList.add("/api/learn/{postId}/message/pagedQuery/postId");
|
||||
whiteList.add("/api/learn/{messageId}/comment");
|
||||
whiteList.add("/api/learn/cgy/updateMessageTime");
|
||||
registry.addInterceptor(authenticateInterceptor).excludePathPatterns(whiteList);
|
||||
}
|
||||
|
||||
|
@ -202,15 +202,21 @@ public class LearnController {
|
||||
|
||||
//----------------------------------------- 改数据 -----------------------------------------
|
||||
@ApiOperation(value = "管理员修改留言数据")
|
||||
@DeleteMapping(path = "/admin/update/message")
|
||||
@PutMapping(path = "/admin/update/message")
|
||||
public void adminUpdateMessage(LearnMessageUpdateVO messageUpdateVO) {
|
||||
iLearnService.adminUpdateMessage(messageUpdateVO);
|
||||
}
|
||||
|
||||
@ApiOperation(value = "管理员修改评论数据")
|
||||
@DeleteMapping(path = "/admin/update/comment")
|
||||
@PutMapping(path = "/admin/update/comment")
|
||||
public void adminUpdateComment(LearnCommentUpdateVO commentUpdateVO) {
|
||||
iLearnService.adminUpdateComment(commentUpdateVO);
|
||||
}
|
||||
|
||||
@ApiOperation(value = "成工院留言时间打散")
|
||||
@PutMapping(path = "/cgy/updateMessageTime")
|
||||
public void cgyUpdateMessageTime() {
|
||||
iLearnService.cgyUpdateMessageTime();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -146,6 +146,11 @@ public interface ILearnService {
|
||||
*/
|
||||
void adminUpdateComment(LearnCommentUpdateVO commitUpdateVO);
|
||||
|
||||
/**
|
||||
* 成工院留言时间打散
|
||||
*/
|
||||
void cgyUpdateMessageTime();
|
||||
|
||||
// /**
|
||||
// * 点赞留言
|
||||
// */
|
||||
|
@ -32,9 +32,8 @@ import org.springframework.util.StringUtils;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.*;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Slf4j
|
||||
@ -381,6 +380,68 @@ public class LearnService implements ILearnService {
|
||||
learnCommentDAO.updateByPrimaryKey(commentEntity);
|
||||
}
|
||||
|
||||
// @Transactional
|
||||
// @Override
|
||||
// public void cgyUpdateMessageTime() {
|
||||
// LearnMessageExample example = new LearnMessageExample();
|
||||
// example.createCriteria().andPostIdEqualTo(27L);
|
||||
// List<LearnMessage> list = learnMessageDAO.selectByExample(example);
|
||||
// int send = 365 * 3 * 24 * 60 * 60;
|
||||
// Random random = new Random();
|
||||
// List<Integer> secondsOffsetList = new ArrayList<>();
|
||||
// for (LearnMessage ignored : list) {
|
||||
// secondsOffsetList.add(random.nextInt(send));
|
||||
// }
|
||||
// secondsOffsetList.sort((i1, i2) -> i2 - i1);
|
||||
// LocalDateTime now = LocalDateTime.now();
|
||||
// for (int i = 0; i < list.size(); i++) {
|
||||
// LearnMessage message = list.get(i);
|
||||
// message.setCreateTime(now.minusSeconds(secondsOffsetList.get(i)));
|
||||
// learnMessageDAO.updateByPrimaryKey(message);
|
||||
// }
|
||||
// }
|
||||
|
||||
@Transactional
|
||||
@Override
|
||||
public void cgyUpdateMessageTime() {
|
||||
LearnMessageExample example = new LearnMessageExample();
|
||||
example.createCriteria().andPostIdEqualTo(27L);
|
||||
List<LearnMessage> allMessage = learnMessageDAO.selectByExample(example);
|
||||
//删重复数据
|
||||
List<LearnMessage> list = allMessage.stream().collect(Collectors.toMap(LearnMessage::getContent, Function.identity(), (old, newValue) -> old))
|
||||
.values().stream().sorted(Comparator.comparingLong(LearnMessage::getId)).collect(Collectors.toList());
|
||||
HashSet<LearnMessage> distinctSet = new HashSet<>(list);
|
||||
List<Long> deleteIds = allMessage.stream().filter(message -> !distinctSet.contains(message)).map(LearnMessage::getId).collect(Collectors.toList());
|
||||
example.clear();
|
||||
example.createCriteria().andIdIn(deleteIds);
|
||||
learnMessageDAO.deleteByExample(example);
|
||||
//修改时间
|
||||
int day = 365 * 3;
|
||||
Random random = new Random();
|
||||
List<Integer> dayOffsetList = new ArrayList<>();
|
||||
for (LearnMessage ignored : list) {
|
||||
dayOffsetList.add(random.nextInt(day));
|
||||
}
|
||||
dayOffsetList.sort((i1, i2) -> i2 - i1);
|
||||
Map<Integer, Long> dayCountMap = dayOffsetList.stream().collect(Collectors.groupingBy(Function.identity(), LinkedHashMap::new, Collectors.counting()));
|
||||
int startIndex = 0;
|
||||
LocalDateTime now = LocalDateTime.now().withHour(0).withMinute(0).withSecond(0);
|
||||
for (Integer dayOffset : dayCountMap.keySet()) {
|
||||
List<Integer> secondsOffsetList = new ArrayList<>();
|
||||
Long dayCount = dayCountMap.get(dayOffset);
|
||||
for (int i = 0; i < dayCount; i++) {
|
||||
secondsOffsetList.add(random.nextInt(24 * 3600 - 8 * 3600) + 8 * 3600);
|
||||
secondsOffsetList.sort(Integer::compareTo);
|
||||
}
|
||||
for (int i = startIndex; i < startIndex + dayCount; i++) {
|
||||
LearnMessage message = list.get(i);
|
||||
message.setCreateTime(now.minusDays(dayOffset).plusSeconds(secondsOffsetList.get(i - startIndex)));
|
||||
learnMessageDAO.updateByPrimaryKey(message);
|
||||
}
|
||||
startIndex += dayCount;
|
||||
}
|
||||
}
|
||||
|
||||
// @Override
|
||||
// public Integer likeMessage(Long messageId) {
|
||||
// LearnMessageWithBLOBs message = getMessage(messageId);
|
||||
|
Loading…
Reference in New Issue
Block a user