Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/feature/pg' into test
Browse files Browse the repository at this point in the history
# Conflicts:
#	framework/src/main/java/cn/lili/modules/order/order/serviceimpl/TradeServiceImpl.java
  • Loading branch information
chopper711 committed Jan 11, 2022
2 parents 05818ba + 1c28e0b commit 6280494
Show file tree
Hide file tree
Showing 20 changed files with 223 additions and 98 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ public void onMessage(MessageExt messageExt) {
case GOODS_AUDIT:
Goods goods = JSONUtil.toBean(new String(messageExt.getBody()), Goods.class);
updateGoodsNum(goods);
updateGoodsIndex(goods);
break;
//删除商品
case GOODS_DELETE:
Expand Down Expand Up @@ -390,7 +391,7 @@ private void settingUpGoodsIndexOtherParam(EsGoodsIndex goodsIndex) {

if (goodsIndex.getPromotionMap() == null || goodsIndex.getPromotionMap().isEmpty()) {
Map<String, Object> goodsCurrentPromotionMap = promotionService.getGoodsPromotionMap(goodsIndex);
goodsIndex.setPromotionMap(goodsCurrentPromotionMap);
goodsIndex.setPromotionMapJson(JSONUtil.toJsonStr(goodsCurrentPromotionMap));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import cn.lili.modules.store.entity.dto.StoreSettlementDay;
import cn.lili.modules.store.mapper.StoreDetailMapper;
import cn.lili.modules.store.service.BillService;
import cn.lili.modules.store.service.StoreDetailService;
import cn.lili.timetask.handler.EveryDayExecute;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;

/**
Expand All @@ -29,8 +28,8 @@ public class BillExecute implements EveryDayExecute {
/**
* 店铺详情
*/
@Resource
private StoreDetailMapper storeDetailMapper;
@Autowired
private StoreDetailService storeDetailService;

/**
* 1.查询今日待结算的商家
Expand All @@ -44,18 +43,18 @@ public void execute() {
int day = DateUtil.date().dayOfMonth();

//获取待结算商家列表
List<StoreSettlementDay> storeList = storeDetailMapper.getSettlementStore(day);
List<StoreSettlementDay> storeList = storeDetailService.getSettlementStore(day);

//获取当前时间
DateTime endTime =DateUtil.date();
DateTime endTime = DateUtil.date();
//批量商家结算
for (StoreSettlementDay storeSettlementDay : storeList) {

//生成结算单
billService.createBill(storeSettlementDay.getStoreId(), storeSettlementDay.getSettlementDay(),endTime);
billService.createBill(storeSettlementDay.getStoreId(), storeSettlementDay.getSettlementDay(), endTime);

//修改店铺结算时间
storeDetailMapper.updateSettlementDay(storeSettlementDay.getStoreId(), endTime);
storeDetailService.updateSettlementDay(storeSettlementDay.getStoreId(), endTime);
}
}
}
61 changes: 61 additions & 0 deletions consumer/src/test/java/cn/lili/buyer/test/bill/BillTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package cn.lili.buyer.test.bill;

import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import cn.lili.modules.store.entity.dto.StoreSettlementDay;
import cn.lili.modules.store.service.BillService;
import cn.lili.modules.store.service.StoreDetailService;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit.jupiter.SpringExtension;

import java.util.List;

/**
* @author paulG
* @since 2022/1/10
**/
@ExtendWith(SpringExtension.class)
@SpringBootTest
public class BillTest {


/**
* 结算单
*/
@Autowired
private BillService billService;

/**
* 店铺详情
*/
@Autowired
private StoreDetailService storeDetailService;

@Test
void createBillTest() {
//获取当前天数
int day = DateUtil.date().dayOfMonth();

//获取待结算商家列表
List<StoreSettlementDay> storeList = storeDetailService.getSettlementStore(day);

//获取当前时间
DateTime endTime = DateUtil.date();
//批量商家结算
for (StoreSettlementDay storeSettlementDay : storeList) {

//生成结算单
billService.createBill(storeSettlementDay.getStoreId(), storeSettlementDay.getSettlementDay(), endTime);

//修改店铺结算时间
storeDetailService.updateSettlementDay(storeSettlementDay.getStoreId(), endTime);
}
Assertions.assertTrue(true);
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ public CacheManager cacheManager(RedisConnectionFactory connectionFactory) {
可参考 https://blog.csdn.net/u012240455/article/details/80538540
*/
ParserConfig.getGlobalInstance().addAccept("cn.lili.");
ParserConfig.getGlobalInstance().addAccept("cn.hutool.json.");

return cacheManager;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public enum PromotionTypeEnum {
/**
* 有促销库存的活动类型
*/
static PromotionTypeEnum[] haveStockPromotion = new PromotionTypeEnum[]{PINTUAN, SECKILL, KANJIA, POINTS_GOODS};
static final PromotionTypeEnum[] haveStockPromotion = new PromotionTypeEnum[]{PINTUAN, SECKILL, KANJIA, POINTS_GOODS};

private final String description;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import cn.hutool.http.HtmlUtil;
import cn.hutool.json.JSONUtil;
import lombok.extern.slf4j.Slf4j;
import org.owasp.html.HtmlPolicyBuilder;
import org.owasp.html.PolicyFactory;
import org.owasp.html.Sanitizers;

import javax.servlet.ReadListener;
Expand Down Expand Up @@ -57,6 +59,24 @@ public class XssHttpServletRequestWrapper extends HttpServletRequestWrapper {
"wechatpay",
};

//允许的标签
private static final String[] allowedTags = {"h1", "h2", "h3", "h4", "h5", "h6",
"span", "strong",
"img", "video", "source", "iframe", "code",
"blockquote", "p", "div",
"ul", "ol", "li",
"table", "thead", "caption", "tbody", "tr", "th", "td", "br",
"a"
};

//需要转化的标签
private static final String[] needTransformTags = {"article", "aside", "command", "datalist", "details", "figcaption", "figure",
"footer", "header", "hgroup", "section", "summary"};

//带有超链接的标签
private static final String[] linkTags = {"img", "video", "source", "a", "iframe"};


public XssHttpServletRequestWrapper(HttpServletRequest request) {
super(request);
}
Expand Down Expand Up @@ -257,13 +277,25 @@ public int read() {

private String cleanXSS(String value) {
if (value != null) {
// 自定义策略
PolicyFactory policy = new HtmlPolicyBuilder()
.allowStandardUrlProtocols()
//所有允许的标签
.allowElements(allowedTags)
//内容标签转化为div
.allowElements((elementName, attributes) -> "div", needTransformTags)
.allowAttributes("src", "href", "target", "width", "height").onElements(linkTags)
//校验链接中的是否为http
// .allowUrlProtocols("https")
.toFactory();
// basic prepackaged policies for links, tables, integers, images, styles, blocks
value = Sanitizers.FORMATTING
.and(Sanitizers.STYLES)
.and(Sanitizers.IMAGES)
.and(Sanitizers.LINKS)
.and(Sanitizers.BLOCKS)
.and(Sanitizers.TABLES)
.and(policy)
.sanitize(value);
}
return HtmlUtil.unescape(value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,9 @@ public void createMapping(String index) throws Exception {
" }\n" +
" }\n" +
" },\n" +
" \"promotionMapJson\": {\n" +
" \"type\": \"text\"\n" +
" },\n" +
" \"thumbnail\": {\n" +
" \"type\": \"text\",\n" +
" \"fields\": {\n" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,7 @@
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.*;

/**
* 商品业务层实现
Expand Down Expand Up @@ -197,6 +194,9 @@ public void editGoods(GoodsOperationDTO goodsOperationDTO, String goodsId) {
if (goodsOperationDTO.getGoodsGalleryList() != null && !goodsOperationDTO.getGoodsGalleryList().isEmpty()) {
this.goodsGalleryService.add(goodsOperationDTO.getGoodsGalleryList(), goods.getId());
}
if (GoodsAuthEnum.TOBEAUDITED.name().equals(goods.getAuthFlag())) {
this.deleteEsGoods(Collections.singletonList(goodsId));
}
cache.remove(CachePrefix.GOODS.getPrefix() + goodsId);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import cn.hutool.core.map.MapUtil;
import cn.hutool.core.text.CharSequenceUtil;
import cn.hutool.core.util.NumberUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import cn.lili.cache.Cache;
Expand Down Expand Up @@ -51,6 +50,8 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.event.TransactionPhase;
import org.springframework.transaction.event.TransactionalEventListener;

import java.util.*;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -171,7 +172,7 @@ public void update(List<Map<String, Object>> skuList, Goods goods, Boolean regen
this.updateBatchById(newSkuList);
}
this.updateStock(newSkuList);
if (!newSkuList.isEmpty()) {
if (GoodsAuthEnum.PASS.name().equals(goods.getAuthFlag()) && !newSkuList.isEmpty()) {
generateEs(goods);
}
}
Expand Down Expand Up @@ -564,6 +565,7 @@ public List<String> getSkuIdsByGoodsId(String goodsId) {
* @param goods 商品信息
*/
@Override
@TransactionalEventListener(phase = TransactionPhase.AFTER_COMMIT)
public void generateEs(Goods goods) {
// 不生成没有审核通过且没有上架的商品
if (!GoodsStatusEnum.UPPER.name().equals(goods.getMarketEnable()) || !GoodsAuthEnum.PASS.name().equals(goods.getAuthFlag())) {
Expand All @@ -572,16 +574,6 @@ public void generateEs(Goods goods) {
String destination = rocketmqCustomProperties.getGoodsTopic() + ":" + GoodsTagsEnum.GENERATOR_GOODS_INDEX.name();
//发送mq消息
rocketMQTemplate.asyncSend(destination, goods.getId(), RocketmqSendCallbackBuilder.commonCallback());
// ThreadUtil.execAsync(() -> {
// try {
// // 延时执行,防止商品未保存完成就去生成商品索引导致生成索引时找不到商品问题
// Thread.sleep(2000);
//
// } catch (InterruptedException e) {
// log.error("发送商品索引信息失败!", e);
// Thread.currentThread().interrupt();
// }
// });
}

/**
Expand Down Expand Up @@ -716,7 +708,7 @@ private void skuInfo(GoodsSku sku, Goods goods, Map<String, Object> map, EsGoods
}
//设置规格商品缩略图
//如果规格没有图片,则用商品图片复盖。有则增加规格图片,放在商品图片集合之前
if (spec.getValue() != null && StrUtil.isNotEmpty(spec.getValue().toString())) {
if (CharSequenceUtil.isNotEmpty(spec.getValue().toString())) {
thumbnail = goodsGalleryService.getGoodsGallery(images.get(0).get("url")).getThumbnail();
small = goodsGalleryService.getGoodsGallery(images.get(0).get("url")).getSmall();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import cn.hutool.core.text.CharSequenceUtil;
import cn.lili.common.enums.PromotionTypeEnum;
import cn.lili.common.security.context.UserContext;
import cn.lili.common.utils.CurrencyUtil;
import cn.lili.common.utils.StringUtils;
import cn.lili.modules.order.cart.entity.dto.MemberCouponDTO;
Expand All @@ -13,11 +12,8 @@
import cn.lili.modules.order.cart.render.util.PromotionPriceUtil;
import cn.lili.modules.order.order.entity.dto.PriceDetailDTO;
import cn.lili.modules.promotion.entity.dos.MemberCoupon;
import cn.lili.modules.promotion.entity.dto.search.MemberCouponSearchParams;
import cn.lili.modules.promotion.entity.enums.CouponTypeEnum;
import cn.lili.modules.promotion.entity.enums.MemberCouponStatusEnum;
import cn.lili.modules.promotion.entity.enums.PromotionsScopeTypeEnum;
import cn.lili.modules.promotion.entity.enums.PromotionsStatusEnum;
import cn.lili.modules.promotion.entity.vos.MemberCouponVO;
import cn.lili.modules.promotion.service.MemberCouponService;
import org.springframework.beans.factory.annotation.Autowired;
Expand Down Expand Up @@ -64,11 +60,7 @@ public void render(TradeDTO tradeDTO) {
* @param tradeDTO 交易dto
*/
private void renderCouponRule(TradeDTO tradeDTO) {
MemberCouponSearchParams searchParams = new MemberCouponSearchParams();
searchParams.setMemberId(UserContext.getCurrentUser().getId());
searchParams.setMemberCouponStatus(MemberCouponStatusEnum.NEW.name());
searchParams.setPromotionStatus(PromotionsStatusEnum.START.name());
List<MemberCoupon> memberCouponList = memberCouponService.getMemberCoupons(searchParams);
List<MemberCoupon> memberCouponList = memberCouponService.getMemberCoupons(tradeDTO.getMemberId());

if (!memberCouponList.isEmpty()) {
this.checkMemberExistCoupon(tradeDTO, memberCouponList);
Expand Down
Loading

0 comments on commit 6280494

Please sign in to comment.