Authored by tanling

增加允许类型

... ... @@ -41,6 +41,16 @@ public class Coupon {
private String skupForbidType;
private String skupAllowType;
public String getSkupAllowType() {
return skupAllowType;
}
public void setSkupAllowType(String skupAllowType) {
this.skupAllowType = skupAllowType;
}
public String getSkupForbidType() {
return skupForbidType;
}
... ...
... ... @@ -21,11 +21,12 @@
<result column="pid" jdbcType="INTEGER" property="pid" />
<result column="remark" jdbcType="VARCHAR" property="remark" />
<result column="skup_forbid_type" jdbcType="VARCHAR" property="skupForbidType" />
<result column="skup_allow_type" jdbcType="VARCHAR" property="skupAllowType" />
</resultMap>
<sql id="Base_Column_List">
id, coupon_token, coupon_name, coupon_amount, coupon_type, coupon_num, use_num, send_num,
use_limit_type, use_limit_value, product_limit_type, product_limit_value, start_time,
end_time, status, create_time, pid, remark,skup_forbid_type
use_limit_type, use_limit_value, product_limit_type, product_limit_value, start_time,
end_time, status, create_time, pid, remark,skup_forbid_type,skup_allow_type
</sql>
<select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
select
... ...
package com.yohoufo.order.charge;
import com.google.common.collect.Lists;
import com.yohobuy.ufo.model.order.constants.OrderConstant;
import com.yohobuy.ufo.model.order.constants.RegionEnum;
import com.yohobuy.ufo.model.promotion.UserCouponsBo;
import com.yohobuy.ufo.model.promotion.constant.CouponProductLimitTypeEnum;
... ... @@ -9,7 +10,9 @@ import com.yohobuy.ufo.model.promotion.constant.CouponUseLimitTypeEnum;
import com.yohoufo.order.charge.model.ChargeGoods;
import com.yohoufo.order.charge.model.CouponMatchResult;
import com.yohoufo.order.utils.LoggerUtils;
import com.yohoufo.order.utils.SellerGoodsHelper;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.springframework.stereotype.Component;
... ... @@ -17,6 +20,7 @@ import java.math.BigDecimal;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
import java.util.stream.Collectors;
/**
* Created by jiexiang.wu on 2018/11/19.
... ... @@ -37,7 +41,7 @@ public class CouponRuleMatcher {
RULE_MATCHERS.add(new UseLimitRuleMatcher());
// skup类型匹配
RULE_MATCHERS.add(new SkupForbidRuleMatcher());
// RULE_MATCHERS.add(new SkupForbidRuleMatcher());
// 按商品区域匹配
RULE_MATCHERS.add(new SkupRegionRuleMatcher());
... ... @@ -150,24 +154,63 @@ public class CouponRuleMatcher {
}
}
private static class SkupForbidRuleMatcher implements IRuleMatcher {
// 6.9.10之后 从[禁用] 改成 [可用]
// private static class SkupForbidRuleMatcher implements IRuleMatcher {
// @Override
// public String ruleName() {
// return "SkupForbid";
// }
//
// @Override
// public boolean match(ChargeGoods chargeGoods, UserCouponsBo couponsBo) {
//
// if (couponsBo.getSkupForbidType() == null){
// return true;
// }
//
// if (Arrays.asList(couponsBo.getSkupForbidType().split(",")).contains(String.valueOf(chargeGoods.getAttributes()))){
// return false;
// }
//
// return true;
// }
// }
private static class SkupAllowRuleMatcher implements IRuleMatcher{
@Override
public String ruleName() {
return "SkupForbid";
return "SkupAllow";
}
@Override
public boolean match(ChargeGoods chargeGoods, UserCouponsBo couponsBo) {
if (couponsBo.getSkupForbidType() == null){
if (StringUtils.isEmpty(couponsBo.getSkupAllowType())){
return true;
}
if (Arrays.asList(couponsBo.getSkupForbidType().split(",")).contains(String.valueOf(chargeGoods.getAttributes()))){
return false;
// 该优惠券允许的skup属性
if (Arrays.asList(couponsBo.getSkupAllowType().split(",")).contains(String.valueOf(chargeGoods.getAttributes()))){
return true;
}
return true;
// 特殊处理
// 现货: 现货发货1-N & 现货寄存1-Y
// 闪购: 闪购发货3-N & 闪购寄存3-Y
String depositRequirement = chargeGoods.isDepositRequirement()? OrderConstant.Y_STR: OrderConstant.N_STR;
List<String> specialAttributeList = Arrays.stream(couponsBo.getSkupAllowType().split(",")).filter(x->x.contains(OrderConstant.SPLIT_STR)).collect(Collectors.toList());
for (String specialAttribute : specialAttributeList){
String[] items = specialAttribute.split(OrderConstant.SPLIT_STR);
if (items[0].equalsIgnoreCase(String.valueOf(chargeGoods.getAttributes())) && depositRequirement.equalsIgnoreCase(items[1])){
return true;
}
}
return false;
}
}
... ...
package com.yohoufo.order;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import com.yohoufo.common.utils.RandomUtil;
import com.yohoufo.common.utils.StringSimilarity;
import org.apache.commons.io.FileUtils;
import java.io.IOException;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.stream.Collectors;
public class ForbidToAllowTest {
final static String SQL_CONTANT = "update ufo_promotion.coupon set skup_allow_type='$skup_allow_type' where skup_forbid_type='$skup_forbid_type';";
public static void main(String[] args) throws IOException {
// String str1 = "望京东园523号楼融科望京中心写字楼A座1208-";
// String str = "望京东园$$523号楼融科望&&京中心写字楼A座1208-15010019250";
// System.out.println(StringSimilarity.getSimilarityRatio(str1, str));
List<String> orderAttributes = Lists.newArrayList();
orderAttributes.add("1");
orderAttributes.add("2");
orderAttributes.add("3");
orderAttributes.add("4");
orderAttributes.add("5");
orderAttributes.add("6");
orderAttributes.add("7");
orderAttributes.add("17");
List<String> forbidAttrs = FileUtils.readLines(new java.io.File("/Users/tanling/tempnodes/attribute.txt"));
List<String> sql = Lists.newArrayList();
for (String forbidAttr : forbidAttrs){
String[] forbidAttrItem = forbidAttr.split(",");
List<String> allowAttribute = Lists.newCopyOnWriteArrayList(orderAttributes);
allowAttribute.removeAll(Arrays.stream(forbidAttrItem).collect(Collectors.toList()));
if (allowAttribute.contains("1")){
allowAttribute.remove("1");
allowAttribute.add("1-N");
allowAttribute.add("1-Y");
}
if (allowAttribute.contains("3")){
allowAttribute.remove("3");
allowAttribute.add("3-N");
allowAttribute.add("3-Y");
}
// System.out.println(forbidAttr + " " + allowAttribute);
sql.add(SQL_CONTANT.replace("$skup_allow_type", allowAttribute.stream().collect(Collectors.joining(","))).replace("$skup_forbid_type", forbidAttr));
}
sql.stream().forEach(x-> System.out.println(x));
}
}
... ...
package com.yohoufo.order;
import com.google.common.collect.Sets;
import com.yohoufo.common.utils.RandomUtil;
import com.yohoufo.common.utils.StringSimilarity;
import java.util.HashSet;
public class TestRandom {
public static void main(String[] args){
String str1 = "望京东园523号楼融科望京中心写字楼A座1208-";
String str = "望京东园$$523号楼融科望&&京中心写字楼A座1208-15010019250";
System.out.println(StringSimilarity.getSimilarityRatio(str1, str));
}
}
... ... @@ -44,6 +44,7 @@ public class CouponConvert {
couponBo.setStatus(userCoupon.getStatus());
couponBo.setSkupForbidType(coupon.getSkupForbidType());
couponBo.setSkupAllowType(coupon.getSkupAllowType());
// use_limit_type use_limit_value 满多少元可用
if (coupon.getUseLimitType()!=null && CouponUseLimitTypeEnum.AMOUNT_LIMIT.getLimitType().equals(String.valueOf(coupon.getUseLimitType()))){
... ...