Authored by tanling

Merge branch 'hotfix-invite-activity-2' of http://git.yoho.cn/ufo/yohoufo-fore i…

…nto hotfix-invite-activity-2
... ... @@ -4,17 +4,13 @@ package com.yohoufo.dal.order;
import com.yohoufo.dal.order.model.InviteActivity;
public interface InviteActivityMapper {
int deleteByPrimaryKey(Integer id);
int insert(InviteActivity record);
int insertSelective(InviteActivity record);
InviteActivity selectByPrimaryKey(Integer id);
InviteActivity selectLastActivtiy();
int updateByPrimaryKeySelective(InviteActivity record);
int updateByPrimaryKey(InviteActivity record);
}
\ No newline at end of file
... ...
package com.yohoufo.dal.order.model;
import lombok.Data;
@Data
public class InviteActivity {
private Integer id;
private String name;
... ... @@ -11,53 +15,10 @@ public class InviteActivity {
private Integer rewardDays;
private Integer createTime;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name == null ? null : name.trim();
}
private String productSortLimit;
public Integer getStartTime() {
return startTime;
}
private String orderAttributesLimit;
public void setStartTime(Integer startTime) {
this.startTime = startTime;
}
public Integer getEndTime() {
return endTime;
}
public void setEndTime(Integer endTime) {
this.endTime = endTime;
}
public Integer getRewardDays() {
return rewardDays;
}
public void setRewardDays(Integer rewardDays) {
this.rewardDays = rewardDays;
}
public Integer getCreateTime() {
return createTime;
}
private Integer createTime;
public void setCreateTime(Integer createTime) {
this.createTime = createTime;
}
}
\ No newline at end of file
... ...
... ... @@ -7,10 +7,12 @@
<result column="start_time" property="startTime" jdbcType="INTEGER" />
<result column="end_time" property="endTime" jdbcType="INTEGER" />
<result column="reward_days" property="rewardDays" jdbcType="INTEGER" />
<result column="product_sort_limit" property="productSortLimit" jdbcType="VARCHAR" />
<result column="order_attributes_limit" property="orderAttributesLimit" jdbcType="VARCHAR" />
<result column="create_time" property="createTime" jdbcType="INTEGER" />
</resultMap>
<sql id="Base_Column_List" >
id, name, start_time, end_time, reward_days, create_time
id, name, start_time, end_time, reward_days,product_sort_limit,order_attributes_limit, create_time
</sql>
... ... @@ -29,63 +31,29 @@
where id = #{id,jdbcType=INTEGER}
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Integer" >
delete from invite_activity
where id = #{id,jdbcType=INTEGER}
</delete>
<insert id="insert" parameterType="com.yohoufo.dal.order.model.InviteActivity" >
insert into invite_activity (id, name, start_time,
end_time, reward_days, create_time
)
values (#{id,jdbcType=INTEGER}, #{name,jdbcType=VARCHAR}, #{startTime,jdbcType=INTEGER},
#{endTime,jdbcType=INTEGER}, #{rewardDays,jdbcType=INTEGER}, #{createTime,jdbcType=INTEGER}
)
</insert>
<insert id="insertSelective" parameterType="com.yohoufo.dal.order.model.InviteActivity" >
insert into invite_activity
<trim prefix="(" suffix=")" suffixOverrides="," >
<if test="id != null" >
insert into invite_activity (
id,
</if>
<if test="name != null" >
name,
</if>
<if test="startTime != null" >
start_time,
</if>
<if test="endTime != null" >
end_time,
</if>
<if test="rewardDays != null" >
reward_days,
</if>
<if test="createTime != null" >
create_time,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides="," >
<if test="id != null" >
product_sort_limit,
order_attributes_limit,
create_time
)
values (
#{id,jdbcType=INTEGER},
</if>
<if test="name != null" >
#{name,jdbcType=VARCHAR},
</if>
<if test="startTime != null" >
#{startTime,jdbcType=INTEGER},
</if>
<if test="endTime != null" >
#{endTime,jdbcType=INTEGER},
</if>
<if test="rewardDays != null" >
#{rewardDays,jdbcType=INTEGER},
</if>
<if test="createTime != null" >
#{createTime,jdbcType=INTEGER},
</if>
</trim>
#{productSortLimit,jdbcType=VARCHAR},
#{orderAttributesLimit,jdbcType=VARCHAR},
#{createTime,jdbcType=INTEGER}
)
</insert>
<update id="updateByPrimaryKeySelective" parameterType="com.yohoufo.dal.order.model.InviteActivity" >
update invite_activity
<set >
... ... @@ -107,13 +75,5 @@
</set>
where id = #{id,jdbcType=INTEGER}
</update>
<update id="updateByPrimaryKey" parameterType="com.yohoufo.dal.order.model.InviteActivity" >
update invite_activity
set name = #{name,jdbcType=VARCHAR},
start_time = #{startTime,jdbcType=INTEGER},
end_time = #{endTime,jdbcType=INTEGER},
reward_days = #{rewardDays,jdbcType=INTEGER},
create_time = #{createTime,jdbcType=INTEGER}
where id = #{id,jdbcType=INTEGER}
</update>
</mapper>
\ No newline at end of file
... ...
... ... @@ -19,6 +19,8 @@ public class InviteSettlementItemCreateRequest {
private Integer orderCreateTime;
private Integer orderAttributes;
private Integer sellerUid;
private Integer sellerOrderPayment;
... ...
... ... @@ -16,7 +16,6 @@ import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.tuple.Pair;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import java.util.List;
... ... @@ -59,9 +58,6 @@ public class InviteSettlementItemCreator {
@Autowired
private ProductMapper productMapper;
@Value("${ufo.invite.productSortLimit}")
private String productSortLimit;
public void createInviteSettlementItem(Long buyerOrderCode, Integer status) {
if (status == OrderStatus.WAITING_RECEIVE.getCode() || status == OrderStatus.DONE.getCode()) {
BuyerOrder buyerOrder = buyerOrderMapper.selectByOrderCode(buyerOrderCode);
... ... @@ -72,6 +68,7 @@ public class InviteSettlementItemCreator {
request.setBuyerOrderCode(buyerOrder.getOrderCode());
request.setSellerUid(buyerOrder.getSellerUid());
request.setOrderAmount(buyerOrder.getAmount());
request.setOrderAttributes(buyerOrder.getAttributes());
request.setSkup(buyerOrderGoods.getSkup());
// 卖家商家单子上架时间
request.setOrderCreateTime(sellerOrder.getCreateTime());
... ... @@ -93,7 +90,7 @@ public class InviteSettlementItemCreator {
}
int inviterUid = invitee.getInviterUid();
int orderCreateTime = request.getOrderCreateTime();
Inviter inviter = inviterMapper.selectByPrimaryKey(invitee.getInviterId());
if (Objects.isNull(inviter)) {
log.warn("{} fail, can not find inviter", tag);
... ... @@ -104,7 +101,7 @@ public class InviteSettlementItemCreator {
return;
}
if (!checkWithInviteActivity(tag, orderCreateTime, invitee, inviter)) {
if (!checkActivity(tag, request, invitee, inviter)) {
return;
}
... ... @@ -170,10 +167,6 @@ public class InviteSettlementItemCreator {
// 受邀人非入驻商家
else if (nonStoredSellerOfInvitee(request)) {
return Pair.of(InviteSettlementItem.STATUS_DISABLE, "NON_STORED_SELLER");
}
// 品类无效
else if (!hitProductSortLimit(request.getSkup())) {
return Pair.of(InviteSettlementItem.STATUS_DISABLE, "PRODUCT_SORT_LIMIT");
} else {
return Pair.of(InviteSettlementItem.STATUS_ENABLE, "OK");
}
... ... @@ -183,27 +176,36 @@ public class InviteSettlementItemCreator {
return request.getSellerOrderPayment() != Payment.WALLET.getCode();
}
private boolean checkWithInviteActivity(String tag, int orderCreateTime, InviteRecord invitee, Inviter inviter) {
int inviterType = inviter.getType();
int inviteTime = invitee.getCreateTime();
private boolean checkActivity(String tag, InviteSettlementItemCreateRequest request, InviteRecord invitee, Inviter inviter) {
// 入驻商家
if (inviterType == INVITER_TYPE_STORED_SELLER) {
if (inviter.getType() == INVITER_TYPE_STORED_SELLER) {
InviteActivity activity = inviteActivityMapper.selectByPrimaryKey(invitee.getInviteActivityId());
if (Objects.isNull(activity)) {
log.warn("{} fail, can not find inviter ", tag);
return false;
}
// 验证品类是否满足条件
if (!checkActivityProductSortLimit(request.getSkup(), activity.getProductSortLimit())) {
log.warn("{} fail, can not hit product sort limit is {}", tag, activity.getProductSortLimit());
return false;
}
// 验证订单属性是否满足条件
if (!checkActivityOrderAttributesLimit(request.getOrderAttributes(), activity.getOrderAttributesLimit())) {
log.warn("{} fail, can not hit order attributes limit is {}", tag, activity.getOrderAttributesLimit());
return false;
}
// 验证是否过了奖励时间
int days = activity.getRewardDays() * 24 * 60 * 60;
if (inviteTime + days < orderCreateTime) {
if (!checkActivityRewardDays(request, invitee, activity.getRewardDays())) {
log.warn("{} fail, reward end.", tag);
return false;
}
}
return true;
}
private boolean hitProductSortLimit(Integer skup) {
private boolean checkActivityProductSortLimit(Integer skup, String productSortLimit) {
if (StringUtils.isBlank(productSortLimit)) {
return true;
}
... ... @@ -214,5 +216,20 @@ public class InviteSettlementItemCreator {
return productSortLimitList.contains(maxSortId);
}
private boolean checkActivityOrderAttributesLimit(Integer orderAttributes, String orderAttributesLimit) {
if (StringUtils.isBlank(orderAttributesLimit)) {
return true;
}
List<String> orderAttributesLimitList = Splitter.on(",").splitToList(orderAttributesLimit);
return orderAttributesLimitList.contains(orderAttributes.toString());
}
private boolean checkActivityRewardDays(InviteSettlementItemCreateRequest request, InviteRecord invitee, int rewardDays) {
int orderCreateTime = request.getOrderCreateTime();
int inviteTime = invitee.getCreateTime();
int rewardTime = inviteTime + (rewardDays * 24 * 60 * 60);
return rewardTime >= orderCreateTime;
}
}
... ...
... ... @@ -118,5 +118,3 @@ offline.store.seller=${offline.store.seller}
ip.port.uic.server = ${ip.port.uic.server}
ufo.nfc.syncBlockChain.url=${ufo.nfc.syncBlockChain.url}
\ No newline at end of file
ufo.invite.productSortLimit=16,20,40
\ No newline at end of file
... ...