master:档口会员更新到ES中;
parent
79c92e652c
commit
b71cf2192f
|
|
@ -764,6 +764,52 @@ public class XktTask {
|
|||
redisCache.setCacheObject(CacheConstants.CATE_TOP_50_SALE_PROD, cateSaleTop50ProdList);
|
||||
}
|
||||
|
||||
/**
|
||||
* 凌晨3:00更新档口权重到redis
|
||||
*/
|
||||
public void updateStoreWeightToES() throws IOException {
|
||||
// 找到昨天开通会员的所有档口
|
||||
List<StoreMember> memberList = this.storeMemberMapper.selectList(new LambdaQueryWrapper<StoreMember>()
|
||||
.eq(StoreMember::getDelFlag, Constants.UNDELETED)
|
||||
.eq(StoreMember::getLevel, StoreMemberLevel.STRENGTH_CONSTRUCT.getValue())
|
||||
.eq(StoreMember::getVoucherDate, java.sql.Date.valueOf(LocalDate.now().minusDays(1))));
|
||||
if (CollectionUtils.isEmpty(memberList)) {
|
||||
return;
|
||||
}
|
||||
final List<Long> storeIdList = memberList.stream().map(StoreMember::getStoreId).collect(Collectors.toList());
|
||||
List<Store> storeList = this.storeMapper.selectList(new LambdaQueryWrapper<Store>()
|
||||
.eq(Store::getDelFlag, Constants.UNDELETED).in(Store::getId, storeIdList));
|
||||
List<StoreProduct> storeProdList = this.storeProdMapper.selectList(new LambdaQueryWrapper<StoreProduct>()
|
||||
.eq(StoreProduct::getDelFlag, Constants.UNDELETED).in(StoreProduct::getStoreId, storeIdList));
|
||||
if (CollectionUtils.isEmpty(storeProdList)) {
|
||||
return;
|
||||
}
|
||||
// 档口权重map
|
||||
Map<Long, Integer> storeWeightMap = storeList.stream().collect(Collectors
|
||||
.toMap(Store::getId, x -> ObjectUtils.defaultIfNull(x.getStoreWeight(), 0)));
|
||||
// 构建一个批量数据集合
|
||||
List<BulkOperation> list = new ArrayList<>();
|
||||
storeProdList.forEach(storeProd -> {
|
||||
// 构建部分文档更新请求
|
||||
list.add(new BulkOperation.Builder().update(u -> u
|
||||
.action(a -> a.doc(new HashMap<String, Object>() {{
|
||||
put("storeWeight", ObjectUtils.defaultIfNull(storeWeightMap.get(storeProd.getStoreId()), Constants.STORE_WEIGHT_DEFAULT_ZERO));
|
||||
}}))
|
||||
.id(String.valueOf(storeProd.getId()))
|
||||
.index(Constants.ES_IDX_PRODUCT_INFO))
|
||||
.build());
|
||||
});
|
||||
try {
|
||||
// 调用bulk方法执行批量更新操作
|
||||
BulkResponse bulkResponse = esClientWrapper.getEsClient().bulk(e -> e.index(Constants.ES_IDX_PRODUCT_INFO).operations(list));
|
||||
log.info("bulkResponse.result() = {}", bulkResponse.items());
|
||||
} catch (IOException | RuntimeException e) {
|
||||
// 记录日志并抛出或处理异常
|
||||
log.error("向ES更新档口权重失败,商品ID: {}, 错误信息: {}", storeProdList.stream().map(StoreProduct::getId).collect(Collectors.toList()), e.getMessage());
|
||||
throw e; // 或者做其他补偿处理,比如异步重试
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 每晚22:00:10 更新广告位竞价状态 将biddingTempStatus赋值给biddingStatus
|
||||
|
|
|
|||
|
|
@ -40,5 +40,9 @@ public class StoreMember extends XktBaseEntity {
|
|||
* 截止日期 yyyy-MM-dd
|
||||
*/
|
||||
private Date endTime;
|
||||
/**
|
||||
* 单据日期
|
||||
*/
|
||||
private Date voucherDate;
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,19 +1,26 @@
|
|||
package com.ruoyi.xkt.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.ruoyi.common.constant.CacheConstants;
|
||||
import com.ruoyi.common.constant.Constants;
|
||||
import com.ruoyi.common.constant.HttpStatus;
|
||||
import com.ruoyi.common.core.redis.RedisCache;
|
||||
import com.ruoyi.common.exception.ServiceException;
|
||||
import com.ruoyi.common.utils.SecurityUtils;
|
||||
import com.ruoyi.xkt.domain.Store;
|
||||
import com.ruoyi.xkt.domain.StoreMember;
|
||||
import com.ruoyi.xkt.dto.storeMember.StoreMemberCreateDTO;
|
||||
import com.ruoyi.xkt.enums.NoticeOwnerType;
|
||||
import com.ruoyi.xkt.enums.NoticeType;
|
||||
import com.ruoyi.xkt.enums.StoreMemberLevel;
|
||||
import com.ruoyi.xkt.enums.UserNoticeType;
|
||||
import com.ruoyi.xkt.mapper.StoreMapper;
|
||||
import com.ruoyi.xkt.mapper.StoreMemberMapper;
|
||||
import com.ruoyi.xkt.service.IAssetService;
|
||||
import com.ruoyi.xkt.service.INoticeService;
|
||||
import com.ruoyi.xkt.service.IStoreMemberService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.apache.commons.lang3.ObjectUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
|
|
@ -34,6 +41,7 @@ public class StoreMemberServiceImpl implements IStoreMemberService {
|
|||
final RedisCache redisCache;
|
||||
final IAssetService assetService;
|
||||
final INoticeService noticeService;
|
||||
final StoreMapper storeMapper;
|
||||
|
||||
/**
|
||||
* 档口购买会员
|
||||
|
|
@ -53,8 +61,15 @@ public class StoreMemberServiceImpl implements IStoreMemberService {
|
|||
storeMember.setStartTime(java.sql.Date.valueOf(LocalDate.now()));
|
||||
// 过期时间设置为1年后
|
||||
storeMember.setEndTime(java.sql.Date.valueOf(LocalDate.now().plusYears(1)));
|
||||
storeMember.setVoucherDate(java.sql.Date.valueOf(LocalDate.now()));
|
||||
storeMember.setCreateBy(SecurityUtils.getUsername());
|
||||
int count = this.storeMemberMapper.insert(storeMember);
|
||||
// 将档口权重增加1
|
||||
Store store = Optional.ofNullable(this.storeMapper.selectOne(new LambdaQueryWrapper<Store>()
|
||||
.eq(Store::getId, createDTO.getStoreId()).eq(Store::getDelFlag, Constants.UNDELETED)))
|
||||
.orElseThrow(() -> new ServiceException("档口不存在!", HttpStatus.ERROR));
|
||||
store.setStoreWeight(ObjectUtils.defaultIfNull(store.getStoreWeight(), 0) + 1);
|
||||
this.storeMapper.updateById(store);
|
||||
// 将档口会员信息添加到 redis 中
|
||||
redisCache.setCacheObject(CacheConstants.STORE_MEMBER + createDTO.getStoreId(), StoreMemberLevel.STRENGTH_CONSTRUCT.getValue());
|
||||
// 新增订购成功的消息通知
|
||||
|
|
|
|||
|
|
@ -1269,9 +1269,15 @@ public class StoreProductServiceImpl implements IStoreProductService {
|
|||
.index(Constants.ES_IDX_PRODUCT_INFO))
|
||||
.build());
|
||||
});
|
||||
// 调用bulk方法执行批量更新操作
|
||||
BulkResponse bulkResponse = esClientWrapper.getEsClient().bulk(e -> e.index(Constants.ES_IDX_PRODUCT_INFO).operations(list));
|
||||
System.out.println("bulkResponse.items() = " + bulkResponse.items());
|
||||
try {
|
||||
// 调用bulk方法执行批量更新操作
|
||||
BulkResponse bulkResponse = esClientWrapper.getEsClient().bulk(e -> e.index(Constants.ES_IDX_PRODUCT_INFO).operations(list));
|
||||
log.info("bulkResponse.result() = {}", bulkResponse.items());
|
||||
} catch (IOException | RuntimeException e) {
|
||||
// 记录日志并抛出或处理异常
|
||||
log.error("向ES更新商品状态失败,商品ID: {}, 错误信息: {}", statusDTO.getStoreProdIdList(), e.getMessage());
|
||||
throw e; // 或者做其他补偿处理,比如异步重试
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Reference in New Issue