Authored by LUOXC

add limit

@@ -4,17 +4,13 @@ package com.yohoufo.dal.order; @@ -4,17 +4,13 @@ package com.yohoufo.dal.order;
4 import com.yohoufo.dal.order.model.InviteActivity; 4 import com.yohoufo.dal.order.model.InviteActivity;
5 5
6 public interface InviteActivityMapper { 6 public interface InviteActivityMapper {
7 - int deleteByPrimaryKey(Integer id);  
8 7
9 int insert(InviteActivity record); 8 int insert(InviteActivity record);
10 9
11 - int insertSelective(InviteActivity record);  
12 -  
13 InviteActivity selectByPrimaryKey(Integer id); 10 InviteActivity selectByPrimaryKey(Integer id);
14 11
15 InviteActivity selectLastActivtiy(); 12 InviteActivity selectLastActivtiy();
16 13
17 int updateByPrimaryKeySelective(InviteActivity record); 14 int updateByPrimaryKeySelective(InviteActivity record);
18 15
19 - int updateByPrimaryKey(InviteActivity record);  
20 } 16 }
1 package com.yohoufo.dal.order.model; 1 package com.yohoufo.dal.order.model;
2 2
  3 +import lombok.Data;
  4 +
  5 +@Data
3 public class InviteActivity { 6 public class InviteActivity {
  7 +
4 private Integer id; 8 private Integer id;
5 9
6 private String name; 10 private String name;
@@ -11,53 +15,10 @@ public class InviteActivity { @@ -11,53 +15,10 @@ public class InviteActivity {
11 15
12 private Integer rewardDays; 16 private Integer rewardDays;
13 17
14 - private Integer createTime;  
15 -  
16 - public Integer getId() {  
17 - return id;  
18 - }  
19 -  
20 - public void setId(Integer id) {  
21 - this.id = id;  
22 - }  
23 -  
24 - public String getName() {  
25 - return name;  
26 - }  
27 -  
28 - public void setName(String name) {  
29 - this.name = name == null ? null : name.trim();  
30 - } 18 + private String productSortLimit;
31 19
32 - public Integer getStartTime() {  
33 - return startTime;  
34 - } 20 + private String orderAttributesLimit;
35 21
36 - public void setStartTime(Integer startTime) {  
37 - this.startTime = startTime;  
38 - }  
39 -  
40 - public Integer getEndTime() {  
41 - return endTime;  
42 - }  
43 -  
44 - public void setEndTime(Integer endTime) {  
45 - this.endTime = endTime;  
46 - }  
47 -  
48 - public Integer getRewardDays() {  
49 - return rewardDays;  
50 - }  
51 -  
52 - public void setRewardDays(Integer rewardDays) {  
53 - this.rewardDays = rewardDays;  
54 - }  
55 -  
56 - public Integer getCreateTime() {  
57 - return createTime;  
58 - } 22 + private Integer createTime;
59 23
60 - public void setCreateTime(Integer createTime) {  
61 - this.createTime = createTime;  
62 - }  
63 } 24 }
@@ -7,10 +7,12 @@ @@ -7,10 +7,12 @@
7 <result column="start_time" property="startTime" jdbcType="INTEGER" /> 7 <result column="start_time" property="startTime" jdbcType="INTEGER" />
8 <result column="end_time" property="endTime" jdbcType="INTEGER" /> 8 <result column="end_time" property="endTime" jdbcType="INTEGER" />
9 <result column="reward_days" property="rewardDays" jdbcType="INTEGER" /> 9 <result column="reward_days" property="rewardDays" jdbcType="INTEGER" />
  10 + <result column="product_sort_limit" property="productSortLimit" jdbcType="VARCHAR" />
  11 + <result column="order_attributes_limit" property="orderAttributesLimit" jdbcType="VARCHAR" />
10 <result column="create_time" property="createTime" jdbcType="INTEGER" /> 12 <result column="create_time" property="createTime" jdbcType="INTEGER" />
11 </resultMap> 13 </resultMap>
12 <sql id="Base_Column_List" > 14 <sql id="Base_Column_List" >
13 - id, name, start_time, end_time, reward_days, create_time 15 + id, name, start_time, end_time, reward_days,product_sort_limit,order_attributes_limit, create_time
14 </sql> 16 </sql>
15 17
16 18
@@ -29,63 +31,29 @@ @@ -29,63 +31,29 @@
29 where id = #{id,jdbcType=INTEGER} 31 where id = #{id,jdbcType=INTEGER}
30 </select> 32 </select>
31 33
32 -  
33 -  
34 - <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer" >  
35 - delete from invite_activity  
36 - where id = #{id,jdbcType=INTEGER}  
37 - </delete>  
38 <insert id="insert" parameterType="com.yohoufo.dal.order.model.InviteActivity" > 34 <insert id="insert" parameterType="com.yohoufo.dal.order.model.InviteActivity" >
39 - insert into invite_activity (id, name, start_time,  
40 - end_time, reward_days, create_time  
41 - )  
42 - values (#{id,jdbcType=INTEGER}, #{name,jdbcType=VARCHAR}, #{startTime,jdbcType=INTEGER},  
43 - #{endTime,jdbcType=INTEGER}, #{rewardDays,jdbcType=INTEGER}, #{createTime,jdbcType=INTEGER}  
44 - )  
45 - </insert>  
46 - <insert id="insertSelective" parameterType="com.yohoufo.dal.order.model.InviteActivity" >  
47 - insert into invite_activity  
48 - <trim prefix="(" suffix=")" suffixOverrides="," >  
49 - <if test="id != null" >  
50 - id,  
51 - </if>  
52 - <if test="name != null" >  
53 - name,  
54 - </if>  
55 - <if test="startTime != null" >  
56 - start_time,  
57 - </if>  
58 - <if test="endTime != null" >  
59 - end_time,  
60 - </if>  
61 - <if test="rewardDays != null" >  
62 - reward_days,  
63 - </if>  
64 - <if test="createTime != null" >  
65 - create_time,  
66 - </if>  
67 - </trim>  
68 - <trim prefix="values (" suffix=")" suffixOverrides="," >  
69 - <if test="id != null" >  
70 - #{id,jdbcType=INTEGER},  
71 - </if>  
72 - <if test="name != null" >  
73 - #{name,jdbcType=VARCHAR},  
74 - </if>  
75 - <if test="startTime != null" >  
76 - #{startTime,jdbcType=INTEGER},  
77 - </if>  
78 - <if test="endTime != null" >  
79 - #{endTime,jdbcType=INTEGER},  
80 - </if>  
81 - <if test="rewardDays != null" >  
82 - #{rewardDays,jdbcType=INTEGER},  
83 - </if>  
84 - <if test="createTime != null" >  
85 - #{createTime,jdbcType=INTEGER},  
86 - </if>  
87 - </trim> 35 + insert into invite_activity (
  36 + id,
  37 + name,
  38 + start_time,
  39 + end_time,
  40 + reward_days,
  41 + product_sort_limit,
  42 + order_attributes_limit,
  43 + create_time
  44 + )
  45 + values (
  46 + #{id,jdbcType=INTEGER},
  47 + #{name,jdbcType=VARCHAR},
  48 + #{startTime,jdbcType=INTEGER},
  49 + #{endTime,jdbcType=INTEGER},
  50 + #{rewardDays,jdbcType=INTEGER},
  51 + #{productSortLimit,jdbcType=VARCHAR},
  52 + #{orderAttributesLimit,jdbcType=VARCHAR},
  53 + #{createTime,jdbcType=INTEGER}
  54 + )
88 </insert> 55 </insert>
  56 +
89 <update id="updateByPrimaryKeySelective" parameterType="com.yohoufo.dal.order.model.InviteActivity" > 57 <update id="updateByPrimaryKeySelective" parameterType="com.yohoufo.dal.order.model.InviteActivity" >
90 update invite_activity 58 update invite_activity
91 <set > 59 <set >
@@ -107,13 +75,5 @@ @@ -107,13 +75,5 @@
107 </set> 75 </set>
108 where id = #{id,jdbcType=INTEGER} 76 where id = #{id,jdbcType=INTEGER}
109 </update> 77 </update>
110 - <update id="updateByPrimaryKey" parameterType="com.yohoufo.dal.order.model.InviteActivity" >  
111 - update invite_activity  
112 - set name = #{name,jdbcType=VARCHAR},  
113 - start_time = #{startTime,jdbcType=INTEGER},  
114 - end_time = #{endTime,jdbcType=INTEGER},  
115 - reward_days = #{rewardDays,jdbcType=INTEGER},  
116 - create_time = #{createTime,jdbcType=INTEGER}  
117 - where id = #{id,jdbcType=INTEGER}  
118 - </update> 78 +
119 </mapper> 79 </mapper>
@@ -19,6 +19,8 @@ public class InviteSettlementItemCreateRequest { @@ -19,6 +19,8 @@ public class InviteSettlementItemCreateRequest {
19 19
20 private Integer orderCreateTime; 20 private Integer orderCreateTime;
21 21
  22 + private Integer orderAttributes;
  23 +
22 private Integer sellerUid; 24 private Integer sellerUid;
23 25
24 private Integer sellerOrderPayment; 26 private Integer sellerOrderPayment;
@@ -16,7 +16,6 @@ import lombok.extern.slf4j.Slf4j; @@ -16,7 +16,6 @@ import lombok.extern.slf4j.Slf4j;
16 import org.apache.commons.lang3.StringUtils; 16 import org.apache.commons.lang3.StringUtils;
17 import org.apache.commons.lang3.tuple.Pair; 17 import org.apache.commons.lang3.tuple.Pair;
18 import org.springframework.beans.factory.annotation.Autowired; 18 import org.springframework.beans.factory.annotation.Autowired;
19 -import org.springframework.beans.factory.annotation.Value;  
20 import org.springframework.stereotype.Component; 19 import org.springframework.stereotype.Component;
21 20
22 import java.util.List; 21 import java.util.List;
@@ -59,9 +58,6 @@ public class InviteSettlementItemCreator { @@ -59,9 +58,6 @@ public class InviteSettlementItemCreator {
59 @Autowired 58 @Autowired
60 private ProductMapper productMapper; 59 private ProductMapper productMapper;
61 60
62 - @Value("${ufo.invite.productSortLimit}")  
63 - private String productSortLimit;  
64 -  
65 public void createInviteSettlementItem(Long buyerOrderCode, Integer status) { 61 public void createInviteSettlementItem(Long buyerOrderCode, Integer status) {
66 if (status == OrderStatus.WAITING_RECEIVE.getCode() || status == OrderStatus.DONE.getCode()) { 62 if (status == OrderStatus.WAITING_RECEIVE.getCode() || status == OrderStatus.DONE.getCode()) {
67 BuyerOrder buyerOrder = buyerOrderMapper.selectByOrderCode(buyerOrderCode); 63 BuyerOrder buyerOrder = buyerOrderMapper.selectByOrderCode(buyerOrderCode);
@@ -72,6 +68,7 @@ public class InviteSettlementItemCreator { @@ -72,6 +68,7 @@ public class InviteSettlementItemCreator {
72 request.setBuyerOrderCode(buyerOrder.getOrderCode()); 68 request.setBuyerOrderCode(buyerOrder.getOrderCode());
73 request.setSellerUid(buyerOrder.getSellerUid()); 69 request.setSellerUid(buyerOrder.getSellerUid());
74 request.setOrderAmount(buyerOrder.getAmount()); 70 request.setOrderAmount(buyerOrder.getAmount());
  71 + request.setOrderAttributes(buyerOrder.getAttributes());
75 request.setSkup(buyerOrderGoods.getSkup()); 72 request.setSkup(buyerOrderGoods.getSkup());
76 // 卖家商家单子上架时间 73 // 卖家商家单子上架时间
77 request.setOrderCreateTime(sellerOrder.getCreateTime()); 74 request.setOrderCreateTime(sellerOrder.getCreateTime());
@@ -93,7 +90,7 @@ public class InviteSettlementItemCreator { @@ -93,7 +90,7 @@ public class InviteSettlementItemCreator {
93 } 90 }
94 int inviterUid = invitee.getInviterUid(); 91 int inviterUid = invitee.getInviterUid();
95 92
96 - int orderCreateTime = request.getOrderCreateTime(); 93 +
97 Inviter inviter = inviterMapper.selectByPrimaryKey(invitee.getInviterId()); 94 Inviter inviter = inviterMapper.selectByPrimaryKey(invitee.getInviterId());
98 if (Objects.isNull(inviter)) { 95 if (Objects.isNull(inviter)) {
99 log.warn("{} fail, can not find inviter", tag); 96 log.warn("{} fail, can not find inviter", tag);
@@ -104,7 +101,7 @@ public class InviteSettlementItemCreator { @@ -104,7 +101,7 @@ public class InviteSettlementItemCreator {
104 return; 101 return;
105 } 102 }
106 103
107 - if (!checkWithInviteActivity(tag, orderCreateTime, invitee, inviter)) { 104 + if (!checkActivity(tag, request, invitee, inviter)) {
108 return; 105 return;
109 } 106 }
110 107
@@ -170,10 +167,6 @@ public class InviteSettlementItemCreator { @@ -170,10 +167,6 @@ public class InviteSettlementItemCreator {
170 // 受邀人非入驻商家 167 // 受邀人非入驻商家
171 else if (nonStoredSellerOfInvitee(request)) { 168 else if (nonStoredSellerOfInvitee(request)) {
172 return Pair.of(InviteSettlementItem.STATUS_DISABLE, "NON_STORED_SELLER"); 169 return Pair.of(InviteSettlementItem.STATUS_DISABLE, "NON_STORED_SELLER");
173 - }  
174 - // 品类无效  
175 - else if (!hitProductSortLimit(request.getSkup())) {  
176 - return Pair.of(InviteSettlementItem.STATUS_DISABLE, "PRODUCT_SORT_LIMIT");  
177 } else { 170 } else {
178 return Pair.of(InviteSettlementItem.STATUS_ENABLE, "OK"); 171 return Pair.of(InviteSettlementItem.STATUS_ENABLE, "OK");
179 } 172 }
@@ -183,27 +176,36 @@ public class InviteSettlementItemCreator { @@ -183,27 +176,36 @@ public class InviteSettlementItemCreator {
183 return request.getSellerOrderPayment() != Payment.WALLET.getCode(); 176 return request.getSellerOrderPayment() != Payment.WALLET.getCode();
184 } 177 }
185 178
186 - private boolean checkWithInviteActivity(String tag, int orderCreateTime, InviteRecord invitee, Inviter inviter) {  
187 - int inviterType = inviter.getType();  
188 - int inviteTime = invitee.getCreateTime(); 179 + private boolean checkActivity(String tag, InviteSettlementItemCreateRequest request, InviteRecord invitee, Inviter inviter) {
  180 +
189 // 入驻商家 181 // 入驻商家
190 - if (inviterType == INVITER_TYPE_STORED_SELLER) { 182 + if (inviter.getType() == INVITER_TYPE_STORED_SELLER) {
191 InviteActivity activity = inviteActivityMapper.selectByPrimaryKey(invitee.getInviteActivityId()); 183 InviteActivity activity = inviteActivityMapper.selectByPrimaryKey(invitee.getInviteActivityId());
192 if (Objects.isNull(activity)) { 184 if (Objects.isNull(activity)) {
193 log.warn("{} fail, can not find inviter ", tag); 185 log.warn("{} fail, can not find inviter ", tag);
194 return false; 186 return false;
195 } 187 }
  188 + // 验证品类是否满足条件
  189 + if (!checkActivityProductSortLimit(request.getSkup(), activity.getProductSortLimit())) {
  190 + log.warn("{} fail, can not hit product sort limit is {}", tag, activity.getProductSortLimit());
  191 + return false;
  192 + }
  193 + // 验证订单属性是否满足条件
  194 + if (!checkActivityOrderAttributesLimit(request.getOrderAttributes(), activity.getOrderAttributesLimit())) {
  195 + log.warn("{} fail, can not hit order attributes limit is {}", tag, activity.getOrderAttributesLimit());
  196 + return false;
  197 + }
196 // 验证是否过了奖励时间 198 // 验证是否过了奖励时间
197 - int days = activity.getRewardDays() * 24 * 60 * 60;  
198 - if (inviteTime + days < orderCreateTime) { 199 + if (!checkActivityRewardDays(request, invitee, activity.getRewardDays())) {
199 log.warn("{} fail, reward end.", tag); 200 log.warn("{} fail, reward end.", tag);
200 return false; 201 return false;
201 } 202 }
202 } 203 }
  204 +
203 return true; 205 return true;
204 } 206 }
205 207
206 - private boolean hitProductSortLimit(Integer skup) { 208 + private boolean checkActivityProductSortLimit(Integer skup, String productSortLimit) {
207 if (StringUtils.isBlank(productSortLimit)) { 209 if (StringUtils.isBlank(productSortLimit)) {
208 return true; 210 return true;
209 } 211 }
@@ -214,5 +216,20 @@ public class InviteSettlementItemCreator { @@ -214,5 +216,20 @@ public class InviteSettlementItemCreator {
214 return productSortLimitList.contains(maxSortId); 216 return productSortLimitList.contains(maxSortId);
215 } 217 }
216 218
  219 + private boolean checkActivityOrderAttributesLimit(Integer orderAttributes, String orderAttributesLimit) {
  220 + if (StringUtils.isBlank(orderAttributesLimit)) {
  221 + return true;
  222 + }
  223 + List<String> orderAttributesLimitList = Splitter.on(",").splitToList(orderAttributesLimit);
  224 + return orderAttributesLimitList.contains(orderAttributes.toString());
  225 + }
  226 +
  227 + private boolean checkActivityRewardDays(InviteSettlementItemCreateRequest request, InviteRecord invitee, int rewardDays) {
  228 + int orderCreateTime = request.getOrderCreateTime();
  229 + int inviteTime = invitee.getCreateTime();
  230 + int rewardTime = inviteTime + (rewardDays * 24 * 60 * 60);
  231 + return rewardTime >= orderCreateTime;
  232 + }
  233 +
217 234
218 } 235 }
@@ -117,6 +117,4 @@ offline.store.seller=${offline.store.seller} @@ -117,6 +117,4 @@ offline.store.seller=${offline.store.seller}
117 117
118 ip.port.uic.server = ${ip.port.uic.server} 118 ip.port.uic.server = ${ip.port.uic.server}
119 119
120 -ufo.nfc.syncBlockChain.url=${ufo.nfc.syncBlockChain.url}  
121 -  
122 -ufo.invite.productSortLimit=16,20,40  
  120 +ufo.nfc.syncBlockChain.url=${ufo.nfc.syncBlockChain.url}