diff --git a/src/main/java/com/ai/da/common/security/filter/AuthenticationFilter.java b/src/main/java/com/ai/da/common/security/filter/AuthenticationFilter.java index bd1052be..894a2231 100644 --- a/src/main/java/com/ai/da/common/security/filter/AuthenticationFilter.java +++ b/src/main/java/com/ai/da/common/security/filter/AuthenticationFilter.java @@ -46,7 +46,7 @@ public class AuthenticationFilter extends OncePerRequestFilter { "/webjars/", "/swagger-resources", "/v2/api-docs", "api/account/resetPwd", "/api/python/saveGeneratePicture", "/api/python/getLibraryByUserId", "/api/third/party/addUser","/api/third/party/addTrialUser", "/api/third/party/editUser", "/api/element/initDefaultSysFile", - "/api/third/party/addNoLoginRequiredNew","/api/third/party/deleteNoLoginRequiredNew", + "/api/third/party/addNoLoginRequiredNew","/api/third/party/deleteNoLoginRequiredNew","/api/third/party/updateNoLoginRequiredNew", "/api/third/party/existNoLoginRequired","/api/third/party/getRedirectUrl", "/api/python/flush","/api/account/healthy","/api/ali-pay/trade/notify","/api/paypal/ipn/back","/api/alipay-hk/trade/notify", "/api/portfolio/page", "/api/portfolio/detail", "/api/portfolio/commentPage", "/api/portfolio/viewsIncrease", diff --git a/src/main/java/com/ai/da/common/task/MoveDataScheduler.java b/src/main/java/com/ai/da/common/task/MoveDataScheduler.java new file mode 100644 index 00000000..759a9067 --- /dev/null +++ b/src/main/java/com/ai/da/common/task/MoveDataScheduler.java @@ -0,0 +1,216 @@ +//package com.ai.da.common.task; +// +//import com.ai.da.common.utils.CopyUtil; +//import com.ai.da.common.utils.ExcelReader; +//import com.ai.da.common.utils.MinioUtil; +//import com.ai.da.common.utils.SendEmailUtil; +//import com.ai.da.mapper.primary.*; +//import com.ai.da.mapper.primary.entity.*; +//import com.ai.da.mapper.secondary.AttributeRetrievalMapper; +//import com.ai.da.mapper.third.*; +//import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +//import org.apache.commons.lang3.StringUtils; +//import org.apache.poi.ss.usermodel.Row; +//import org.apache.poi.ss.usermodel.Sheet; +//import org.apache.poi.ss.usermodel.Workbook; +//import org.apache.poi.xssf.usermodel.XSSFWorkbook; +//import org.springframework.stereotype.Component; +//import org.springframework.util.CollectionUtils; +// +//import javax.annotation.PostConstruct; +//import javax.annotation.Resource; +//import java.io.FileOutputStream; +//import java.io.IOException; +//import java.nio.file.Files; +//import java.nio.file.Paths; +//import java.time.LocalDate; +//import java.time.format.DateTimeFormatter; +//import java.util.List; +//import java.util.concurrent.ExecutorService; +//import java.util.concurrent.Executors; +//import java.util.concurrent.TimeUnit; +//import java.util.stream.Collectors; +// +//@Component +//public class MoveDataScheduler { +// +// @PostConstruct +// public void test() { +// moveData(); +// } +// +// @Resource +// private UserLikeGroupMapper userLikeGroupMapper; +// @Resource +// private UserLikeGroupZSMapper userLikeGroupZSMapper; +// @Resource +// private UserLikeMapper userLikeMapper; +// @Resource +// private UserLikeZSMapper userLikeZSMapper; +// @Resource +// private CollectionElementMapper collectionElementMapper; +// @Resource +// private CollectionElementZSMapper collectionElementZSMapper; +// +// @Resource +// private CollectionMapper collectionMapper; +// +// @Resource +// private CollectionZSMapper collectionZSMapper; +// +// @Resource +// private DesignMapper designMapper; +// +// @Resource +// private DesignZSMapper designZSMapper; +// +// @Resource +// private DesignItemMapper designItemMapper; +// +// @Resource +// private DesignItemZSMapper designItemZSMapper; +// +// @Resource +// private TDesignPythonOutfitMapper designPythonOutfitMapper; +// +// @Resource +// private TDesignPythonOutfitZSMapper designPythonOutfitZSMapper; +// +// @Resource +// private TDesignPythonOutfitDetailMapper designPythonOutfitDetailMapper; +// +// @Resource +// private TDesignPythonOutfitDetailZSMapper designPythonOutfitDetailZSMapper; +// +// @Resource +// private DesignItemDetailMapper designItemDetailMapper; +// @Resource +// private DesignItemZSDetailMapper designItemDetailZSMapper; +// +// @Resource +// private DesignItemDetailPrintMapper designItemDetailPrintMapper; +// +// @Resource +// private DesignItemDetailPrintZSMapper designItemDetailPrintZSMapper; +// +// +// private void moveData() { +// // 查询用户所有history记录 +// QueryWrapper userLikeGroupQueryWrapper = new QueryWrapper<>(); +// userLikeGroupQueryWrapper.lambda().eq(UserLikeGroup::getAccountId, 11411); +// List userLikeGroupList = userLikeGroupMapper.selectList(userLikeGroupQueryWrapper); +// +// for (UserLikeGroup userLikeGroup : userLikeGroupList) { +// +// com.ai.da.mapper.third.entity.UserLikeGroup userLikeGroupZS = CopyUtil.copyObject(userLikeGroup, com.ai.da.mapper.third.entity.UserLikeGroup.class); +// userLikeGroupZS.setAccountId(11420L); +// userLikeGroupZS.setId(null); +// Collection collection = collectionMapper.selectById(userLikeGroup.getCollectionId()); +// com.ai.da.mapper.third.entity.Collection collectionZS = CopyUtil.copyObject(collection, com.ai.da.mapper.third.entity.Collection.class); +// collectionZS.setAccountId(11420L); +// collectionZS.setId(null); +// +// if (collection.getMoodTemplateId() != null) { +// CollectionElement element = collectionElementMapper.selectById(collection.getMoodTemplateId()); +// com.ai.da.mapper.third.entity.CollectionElement collectionElementZS = CopyUtil.copyObject(element, com.ai.da.mapper.third.entity.CollectionElement.class); +// collectionElementZS.setAccountId(11420L); +// collectionElementZS.setId(null); +// collectionElementZSMapper.insert(collectionElementZS); +// collectionZS.setMoodTemplateId(String.valueOf(collectionElementZS.getId())); +// } +// collectionZSMapper.insert(collectionZS); +// userLikeGroupZS.setCollectionId(collectionZS.getId()); +// userLikeGroupZSMapper.insert(userLikeGroupZS); +// +// // 生成元素 +// QueryWrapper collectionElementQueryWrapper = new QueryWrapper<>(); +// collectionElementQueryWrapper.lambda().eq(CollectionElement::getCollectionId, userLikeGroup.getCollectionId()); +// List collectionElements = collectionElementMapper.selectList(collectionElementQueryWrapper); +// +// for (CollectionElement collectionElement : collectionElements) { +// com.ai.da.mapper.third.entity.CollectionElement collectionElementZS = CopyUtil.copyObject(collectionElement, com.ai.da.mapper.third.entity.CollectionElement.class); +// collectionElementZS.setId(null); +// collectionElementZS.setAccountId(11420L); +// collectionElementZS.setCollectionId(collectionZS.getId()); +// collectionElementZSMapper.insert(collectionElementZS); +// } +// +// // 查询记录关联 +// QueryWrapper userLikeQueryWrapper = new QueryWrapper<>(); +// userLikeQueryWrapper.lambda().eq(UserLike::getUserLikeGroupId, userLikeGroup.getId()); +// List userLikes = userLikeMapper.selectList(userLikeQueryWrapper); +// for (UserLike userLike : userLikes) { +// Design design = designMapper.selectById(userLike.getDesignId()); +// com.ai.da.mapper.third.entity.Design designZS = CopyUtil.copyObject(design, com.ai.da.mapper.third.entity.Design.class); +// designZS.setId(null); +// designZS.setAccountId(11420L); +// designZS.setCollectionId(collectionZS.getId()); +// designZSMapper.insert(designZS); +// +// com.ai.da.mapper.third.entity.UserLike userLikeZS = CopyUtil.copyObject(userLike, com.ai.da.mapper.third.entity.UserLike.class); +//// Design design = designMapper.selectById(userLike.getDesignId()); +// userLikeZS.setId(null); +// DesignItem designItem = designItemMapper.selectById(userLike.getDesignItemId()); +// com.ai.da.mapper.third.entity.DesignItem designItemZS = CopyUtil.copyObject(designItem, com.ai.da.mapper.third.entity.DesignItem.class); +// designItemZS.setId(null); +// designItemZS.setAccountId(11420L); +// designItemZS.setDesignId(designZS.getId()); +// designItemZSMapper.insert(designItemZS); +// +// QueryWrapper designItemDetailQueryWrapper = new QueryWrapper<>(); +// designItemDetailQueryWrapper.lambda().eq(DesignItemDetail::getDesignItemId, designItem.getId()); +// List designItemDetails = designItemDetailMapper.selectList(designItemDetailQueryWrapper); +// for (DesignItemDetail designItemDetail : designItemDetails) { +// com.ai.da.mapper.third.entity.DesignItemDetail designItemDetailZS = CopyUtil.copyObject(designItemDetail, com.ai.da.mapper.third.entity.DesignItemDetail.class); +// designItemDetailZS.setId(null); +// designItemDetailZS.setDesignItemId(designItemZS.getId()); +// designItemDetailZS.setAccountId(11420L); +// designItemDetailZS.setDesignId(designZS.getId()); +// designItemDetailZSMapper.insert(designItemDetailZS); +// +// QueryWrapper designItemDetailPrintQueryWrapper = new QueryWrapper<>(); +// designItemDetailPrintQueryWrapper.lambda().eq(DesignItemDetailPrint::getDesignItemDetailId, designItemDetail.getId()); +// List designItemDetailPrintList = designItemDetailPrintMapper.selectList(designItemDetailPrintQueryWrapper); +// if (!CollectionUtils.isEmpty(designItemDetailPrintList)) { +// for (DesignItemDetailPrint designItemDetailPrint : designItemDetailPrintList) { +// com.ai.da.mapper.third.entity.DesignItemDetailPrint designItemDetailPrintZS = CopyUtil.copyObject(designItemDetailPrint, com.ai.da.mapper.third.entity.DesignItemDetailPrint.class); +// designItemDetailPrintZS.setId(null); +// designItemDetailPrintZS.setDesignItemDetailId(designItemDetailZS.getId()); +// designItemDetailPrintZSMapper.insert(designItemDetailPrintZS); +// } +// } +// } +// +// userLikeZS.setDesignItemId(designItemZS.getId()); +// TDesignPythonOutfit tDesignPythonOutfit = designPythonOutfitMapper.selectById(userLike.getDesignOutfitId()); +// com.ai.da.mapper.third.entity.TDesignPythonOutfit tDesignPythonOutfitZS = CopyUtil.copyObject(tDesignPythonOutfit, com.ai.da.mapper.third.entity.TDesignPythonOutfit.class); +// tDesignPythonOutfitZS.setId(null); +// tDesignPythonOutfitZS.setDesignItemId(designItemZS.getId()); +// tDesignPythonOutfitZS.setCollectionId(collectionZS.getId()); +// tDesignPythonOutfitZS.setUserId(11420L); +// tDesignPythonOutfitZS.setDesignId(designZS.getId()); +// designPythonOutfitZSMapper.insert(tDesignPythonOutfitZS); +// +// userLikeZS.setUserLikeGroupId(userLikeGroupZS.getId()); +// userLikeZS.setDesignId(designZS.getId()); +// userLikeZS.setDesignOutfitId(tDesignPythonOutfitZS.getId()); +// userLikeZSMapper.insert(userLikeZS); +// +// QueryWrapper designPythonOutfitDetailQueryWrapper = new QueryWrapper<>(); +// designPythonOutfitDetailQueryWrapper.lambda().eq(TDesignPythonOutfitDetail::getDesignPythonOutfitId, tDesignPythonOutfit.getId()); +// List tDesignPythonOutfitDetails = designPythonOutfitDetailMapper.selectList(designPythonOutfitDetailQueryWrapper); +// for (TDesignPythonOutfitDetail tDesignPythonOutfitDetail : tDesignPythonOutfitDetails) { +// com.ai.da.mapper.third.entity.TDesignPythonOutfitDetail tDesignPythonOutfitDetailZS = CopyUtil.copyObject(tDesignPythonOutfitDetail, com.ai.da.mapper.third.entity.TDesignPythonOutfitDetail.class); +// tDesignPythonOutfitDetailZS.setDesignPythonOutfitId(tDesignPythonOutfitZS.getId()); +// tDesignPythonOutfitDetailZS.setId(null); +// tDesignPythonOutfitDetailZS.setDesignId(designZS.getId()); +// designPythonOutfitDetailZSMapper.insert(tDesignPythonOutfitDetailZS); +// } +// } +// } +// +// +// } +// +// +//} diff --git a/src/main/java/com/ai/da/service/AccountService.java b/src/main/java/com/ai/da/service/AccountService.java index 24ec1248..8aca8e2a 100644 --- a/src/main/java/com/ai/da/service/AccountService.java +++ b/src/main/java/com/ai/da/service/AccountService.java @@ -168,8 +168,6 @@ public interface AccountService extends IService { void registerUserToVisitor(); - String updateNoLoginRequiredNew(NoLoginRequiredDTO noLoginRequiredDTO, HttpServletRequest request); - Map getNicknameModifyTimes(); void editUserName(String newUserName); @@ -179,4 +177,6 @@ public interface AccountService extends IService { void changeUserEmail(String newMailbox); void activateNewEmail(String token); + + String updateNoLoginRequiredNew(NoLoginRequiredDTO noLoginRequiredDTO, HttpServletRequest request); } diff --git a/src/main/java/com/ai/da/service/impl/AccountServiceImpl.java b/src/main/java/com/ai/da/service/impl/AccountServiceImpl.java index 905ab175..45306d4d 100644 --- a/src/main/java/com/ai/da/service/impl/AccountServiceImpl.java +++ b/src/main/java/com/ai/da/service/impl/AccountServiceImpl.java @@ -572,7 +572,7 @@ public class AccountServiceImpl extends ServiceImpl impl account.setSystemUser(3); account.setValidStartTime(System.currentTimeMillis()); if (link) { - account.setValidEndTime(toDayEnd(Instant.now().plus(14, ChronoUnit.DAYS).toEpochMilli())); + account.setValidEndTime(toDayEnd(Instant.now().plus(5, ChronoUnit.DAYS).toEpochMilli())); } else { account.setValidEndTime(toDayEnd(Instant.now().plus(5, ChronoUnit.DAYS).toEpochMilli())); } @@ -584,7 +584,7 @@ public class AccountServiceImpl extends ServiceImpl impl account.setLanguage(Language.ENGLISH.name()); account.setValidStartTime(System.currentTimeMillis()); if (link) { - account.setValidEndTime(toDayEnd(Instant.now().plus(14, ChronoUnit.DAYS).toEpochMilli())); + account.setValidEndTime(toDayEnd(Instant.now().plus(5, ChronoUnit.DAYS).toEpochMilli())); } else { account.setValidEndTime(toDayEnd(Instant.now().plus(5, ChronoUnit.DAYS).toEpochMilli())); } diff --git a/src/main/java/com/ai/da/service/impl/CollectionElementServiceImpl.java b/src/main/java/com/ai/da/service/impl/CollectionElementServiceImpl.java index 6c33eb2a..a6bcedc6 100644 --- a/src/main/java/com/ai/da/service/impl/CollectionElementServiceImpl.java +++ b/src/main/java/com/ai/da/service/impl/CollectionElementServiceImpl.java @@ -81,6 +81,9 @@ public class CollectionElementServiceImpl extends ServiceImpl sketchBoards) { if (CollectionUtil.isNotEmpty(sketchBoards)) { - sketchBoards.forEach(sketchBoard -> { + List collect = sketchBoards.stream().filter(o -> o.getDesignType().equals(DesignTypeEnum.COLLECTION.getRealName())).collect(Collectors.toList()); + collect.forEach(sketchBoard -> { CollectionElement collectionElement = CopyUtil.copyObject(sketchBoard, CollectionElement.class); collectionElement.setHasPin(sketchBoard.getIsPin()); collectionElement.setId(sketchBoard.getSketchBoardId()); collectionElementMapper.updateById(collectionElement); }); - List sketchBoardIds = sketchBoards.stream().map(CollectionSketchDTO::getSketchBoardId).collect(Collectors.toList()); - List sketchBoardElements = collectionElementMapper.selectBatchIds(sketchBoardIds); - elementVO.setSketchBoardElements(sketchBoardElements); + List sketchBoardIds = collect.stream().map(CollectionSketchDTO::getSketchBoardId).collect(Collectors.toList()); + if (!CollectionUtils.isEmpty(sketchBoardIds)) { + List sketchBoardElements = collectionElementMapper.selectBatchIds(sketchBoardIds); + elementVO.setSketchBoardElements(sketchBoardElements); + }else { + elementVO.setSketchBoardElements(new ArrayList<>()); + } } } @Override public void editPrintBoardsElement(ValidateElementVO elementVO, List printBoards) { if (CollectionUtil.isNotEmpty(printBoards)) { - printBoards.forEach(printBoard -> { + List collect = printBoards.stream().filter(o -> o.getDesignType().equals(DesignTypeEnum.COLLECTION.getRealName())).collect(Collectors.toList()); + collect.forEach(printBoard -> { CollectionElement collectionElement = CopyUtil.copyObject(printBoard, CollectionElement.class); collectionElement.setHasPin(Objects.isNull(printBoard.getIsPin()) ? 0 : printBoard.getIsPin()); collectionElement.setId(printBoard.getId()); collectionElementMapper.updateById(collectionElement); }); - List printBoardIds = printBoards.stream().map(DesignCollectionPrintElementDTO::getId).collect(Collectors.toList()); - List printBoardElements = collectionElementMapper.selectBatchIds(printBoardIds); - elementVO.setPrintBoardElements(printBoardElements); + List printBoardIds = collect.stream().map(DesignCollectionPrintElementDTO::getId).collect(Collectors.toList()); + if (!CollectionUtils.isEmpty(printBoardIds)) { + List printBoardElements = collectionElementMapper.selectBatchIds(printBoardIds); + elementVO.setPrintBoardElements(printBoardElements); + }else { + elementVO.setPrintBoardElements(new ArrayList<>()); + } } } diff --git a/src/main/java/com/ai/da/service/impl/PortfolioServiceImpl.java b/src/main/java/com/ai/da/service/impl/PortfolioServiceImpl.java index b59a7479..7524c2e4 100644 --- a/src/main/java/com/ai/da/service/impl/PortfolioServiceImpl.java +++ b/src/main/java/com/ai/da/service/impl/PortfolioServiceImpl.java @@ -426,11 +426,15 @@ public class PortfolioServiceImpl extends ServiceImpl page(QueryPortfolioPageDTO query) { AuthPrincipalVo userHolder = UserContext.getUserHolder(); QueryWrapper qw = new QueryWrapper<>(); + + // 查询用户的作品集 if (query.getGetMyPortfolio() == 1) { qw.lambda().eq(Portfolio::getAccountId, userHolder.getId()); } else if (!Objects.isNull(query.getAccountId())) { qw.lambda().eq(Portfolio::getAccountId, query.getAccountId()); } + + // 查询用户喜欢的作品集 if (query.getGetLikePortfolio() == 1) { List likedPortfolioIdList = redisUtil.getLikedPortfolios(userHolder.getId()); if (!CollectionUtils.isEmpty(likedPortfolioIdList)) { @@ -439,31 +443,54 @@ public class PortfolioServiceImpl extends ServiceImpl()); } } - List topThree = new ArrayList<>(); - if (query.getPage() == 1 && - (query.getGetMyPortfolio() != 1 || query.getGetLikePortfolio() != 1)) { + List topThree = new ArrayList<>(); + List excludeIds = new ArrayList<>(); // 存放需要排除的 ID 列表 + + // 获取前三点赞和前三浏览的作品集,并将其排除在分页查询之外 + if (query.getPage() == 1 && (query.getGetMyPortfolio() != 1 || query.getGetLikePortfolio() != 1)) { + // 获取前三点赞的作品集 ID List topThreeLike = getTopThreeLikeFromRedis(RedisUtil.PORTFOLIO_LIKE_KEY); - log.info("top three like 的作品集的id : {}", topThreeLike); - List topThreeView = getTopThreeViewFromRedis(RedisUtil.PORTFOLIO_VIEW_KEY); - log.info("top three view 的作品集的id : {}", topThreeView); - QueryWrapper queryLike = new QueryWrapper<>(); - queryLike.in("id", topThreeLike); - QueryWrapper queryView = new QueryWrapper<>(); - queryView.in("id", topThreeView); - List topThreeLikePortfolio = baseMapper.selectList(queryLike); - List topThreeViewPortfolio = baseMapper.selectList(queryView); - topThree.addAll(topThreeLikePortfolio); - topThree.addAll(topThreeViewPortfolio); + List topThreeView = getTopThreeViewFromRedis(RedisUtil.PORTFOLIO_VIEW_KEY, topThreeLike); + + // 获取前三点赞的作品集 + if (!CollectionUtils.isEmpty(topThreeLike)) { + QueryWrapper queryLike = new QueryWrapper<>(); + queryLike.in("id", topThreeLike); + List topThreeLikePortfolio = baseMapper.selectList(queryLike); + topThree.addAll(topThreeLikePortfolio); + excludeIds.addAll(topThreeLike); // 添加到排除 ID 列表 + } + + // 获取前三浏览的作品集 + if (!CollectionUtils.isEmpty(topThreeView)) { + QueryWrapper queryView = new QueryWrapper<>(); + queryView.in("id", topThreeView); + List topThreeViewPortfolio = baseMapper.selectList(queryView); + topThree.addAll(topThreeViewPortfolio); + excludeIds.addAll(topThreeView); // 添加到排除 ID 列表 + } } + // 在正常分页查询中排除前三点赞和前三浏览的作品集 + if (!CollectionUtils.isEmpty(excludeIds)) { + qw.lambda().notIn(Portfolio::getId, excludeIds); + } + + // 按更新时间排序 qw.lambda().orderByDesc(Portfolio::getUpdateDate); + + // 执行分页查询 IPage page = portfolioMapper.selectPage(new Page<>(query.getPage(), query.getSize()), qw); + + // 如果前三点赞和浏览不为空,将它们添加到分页查询的结果最前面 if (!topThree.isEmpty()) { List records = page.getRecords(); - records.addAll(0, topThree); + records.addAll(0, topThree); // 添加到查询结果的开头 page.setRecords(records); } + + // 将 Portfolio 转换为 PortfolioVO 并进行相关处理 IPage convert = page.convert((Function) portfolio -> { if (portfolio != null) { PortfolioVO vo = CopyUtil.copyObject(portfolio, PortfolioVO.class); @@ -480,9 +507,11 @@ public class PortfolioServiceImpl extends ServiceImpl getTopThreeViewFromRedis(String prefix) { + private List getTopThreeViewFromRedis(String prefix, List excludeIds) { // Step 1: Get all keys with the specific prefix Set keys = redisUtil.getKeysFromString(prefix + "*"); -// Step 2: Create a map to store portfolioId and its corresponding value + + // Step 2: Create a map to store portfolioId and its corresponding value Map portfolioViews = new HashMap<>(); if (keys != null) { for (String key : keys) { @@ -1027,11 +1057,15 @@ public class PortfolioServiceImpl extends ServiceImpl top3PortfolioIds = portfolioViews.entrySet().stream() .sorted(Map.Entry.comparingByValue().reversed()) @@ -1039,7 +1073,7 @@ public class PortfolioServiceImpl extends ServiceImpl