Authored by mali

Merge branch 'test6.9.0' into test6.9.1

... ... @@ -256,12 +256,13 @@ public class RedisGwCacheClient implements CacheClient {
lastResult.put(cacheKeyAndStringMap.get(entry.getKey()), entry.getValue());
}
Map<K, T> apply = nullCacheFun.apply(nullCachekeys); // 执行回调函数去数据库查询未缓存的键值集合
setBulk(apply, timeOut, cacheKeyPre, clazz); // 将不在缓存的键值对批量放入缓存
for(Map.Entry<K, T> item : apply.entrySet()) {
lastResult.put(item.getKey(), item.getValue());
if (CollectionUtils.isNotEmpty(nullCachekeys)) {
Map<K, T> apply = nullCacheFun.apply(nullCachekeys); // 执行回调函数去数据库查询未缓存的键值集合
setBulk(apply, timeOut, cacheKeyPre, clazz); // 将不在缓存的键值对批量放入缓存
for(Map.Entry<K, T> item : apply.entrySet()) {
lastResult.put(item.getKey(), item.getValue());
}
}
return lastResult;
} catch (Exception e) {
LOGGER.warn("getBulk from redis failed!!", e);
... ...
... ... @@ -6,7 +6,6 @@ import com.yohoufo.dal.order.model.InviteSettlementItemStats;
import org.apache.ibatis.annotations.Param;
import java.util.List;
import java.math.BigDecimal;
public interface InviteSettlementItemMapper {
... ... @@ -20,7 +19,8 @@ public interface InviteSettlementItemMapper {
InviteSettlementItem selectByUidAndBuyerOrderCode(@Param("uid") Integer uid, @Param("buyerOrderCode") Long buyerOrderCode);
InviteSettlementItem selectOneByUidAndStatus(@Param("uid") Integer uid, @Param("status") Integer status);
InviteSettlementItem selectOneByUidAndStatus(@Param("uid") Integer uid,
@Param("status") Integer status);
int selectCountByUidTypeAndInviteSettlementId(@Param("uid") Integer uid,
@Param("type") Integer type,
... ... @@ -29,9 +29,15 @@ public interface InviteSettlementItemMapper {
List<InviteSettlementItem> selectOrderNumByInviterUid(@Param("inviterUid") Integer inviterUid);
int updateByPrimaryKeySelective(InviteSettlementItem record);
BigDecimal selectTotalOrderAmountByUidTypeAndInviteSettlementId(@Param("uid") Integer uid,
@Param("type") Integer type,
@Param("inviteSettlementId") Integer inviteSettlementId);
List<InviteSettlementItemStats> selectStatsByUidTypeAndInviteSettlementIdGroupBySellerUid(@Param("uid") Integer uid,
@Param("type") Integer type,
@Param("inviteSettlementId") Integer inviteSettlementId);
List<InviteSettlementItem> selectByUidTypeInviteSettlementIdAndSellerUid(@Param("uid") Integer uid,
@Param("type") Integer type,
@Param("inviteSettlementId") Integer inviteSettlementId,
@Param("sellerUid") Integer sellerUid);
InviteSettlementItemStats selectStats(@Param("uid") Integer uid,
... ...
... ... @@ -11,6 +11,8 @@ import java.math.BigDecimal;
@Data
public class InviteSettlementItemStats {
Integer sellerUid;
Integer totalElements;
BigDecimal totalOrderAmount;
... ...
... ... @@ -52,9 +52,11 @@
<update id="updateToSettled">
update invite_settlement_item
set status = #{tagStatus,jdbcType=INTEGER},
set status = #{tagStatus,jdbcType=INTEGER},
invite_settlement_id = #{inviteSettlementId,jdbcType=INTEGER}
where uid = #{uid,jdbcType=INTEGER} and type = #{type,jdbcType=INTEGER} and status = #{srcStatus,jdbcType=INTEGER}
where uid = #{uid,jdbcType=INTEGER}
and type = #{type,jdbcType=INTEGER}
and status = #{srcStatus,jdbcType=INTEGER}
</update>
<select id="selectByUidAndBuyerOrderCode" resultMap="BaseResultMap" >
... ... @@ -68,7 +70,8 @@
select
<include refid="Base_Column_List" />
from invite_settlement_item
where uid = #{uid,jdbcType=INTEGER} and status = #{status,jdbcType=INTEGER}
where uid = #{uid,jdbcType=INTEGER}
and status = #{status,jdbcType=INTEGER}
limit 1
</select>
... ... @@ -87,17 +90,32 @@
where uid = #{uid,jdbcType=INTEGER} and type = #{type,jdbcType=INTEGER} and invite_settlement_id = #{inviteSettlementId,jdbcType=INTEGER}
</select>
<select id="selectTotalOrderAmountByUidTypeAndInviteSettlementId" resultType="java.math.BigDecimal" >
<select id="selectStatsByUidTypeAndInviteSettlementIdGroupBySellerUid" resultType="com.yohoufo.dal.order.model.InviteSettlementItemStats" >
select
sum(order_amount)
seller_uid as 'sellerUid',
count(1) as 'totalElements',
sum(order_amount) as 'totalOrderAmount',
sum(settle_amount) as 'totalSettleAmount'
from invite_settlement_item
where uid = #{uid,jdbcType=INTEGER} and type = #{type,jdbcType=INTEGER} and invite_settlement_id = #{inviteSettlementId,jdbcType=INTEGER}
group by seller_uid
</select>
<select id="selectByUidTypeInviteSettlementIdAndSellerUid" resultMap="BaseResultMap" >
select
<include refid="Base_Column_List" />
from invite_settlement_item
where uid = #{uid,jdbcType=INTEGER} and type = #{type,jdbcType=INTEGER} and invite_settlement_id = #{inviteSettlementId,jdbcType=INTEGER}
and seller_uid = #{sellerUid,jdbcType=INTEGER}
</select>
<select id="selectStats" resultType="com.yohoufo.dal.order.model.InviteSettlementItemStats" >
select
count(1) as 'totalElements',
sum(order_amount) as 'totalOrderAmount'
sum(order_amount) as 'totalOrderAmount',
sum(settle_amount) as 'totalSettleAmount'
from invite_settlement_item
where uid = #{uid,jdbcType=INTEGER}
and type = #{type,jdbcType=INTEGER}
... ...
... ... @@ -23,6 +23,7 @@ import java.util.Objects;
import static com.yohoufo.order.constants.InviteConstant.INVITER_TYPE_AGENT;
import static com.yohoufo.order.constants.InviteConstant.INVITER_TYPE_STORED_SELLER;
import static com.yohoufo.order.utils.InviteSettlementUtils.calculateSettleAmountOfType1;
/**
* @author LUOXC
... ... @@ -130,6 +131,9 @@ public class InviteSettlementItemCreator {
// 结算方式选择
Integer inviteSettlementItemType = buildInviteSettlementItemType(inviter);
inviteSettlementItem.setType(inviteSettlementItemType);
if (inviteSettlementItemType == 1) {
inviteSettlementItem.setSettleAmount(calculateSettleAmountOfType1(1));
}
// 待结算订单状态
Pair<Integer, String> status = buildInviteSettlementItemStatus(request, invitee, inviter);
... ...
... ... @@ -13,6 +13,7 @@ import com.yohoufo.dal.order.model.Inviter;
import com.yohoufo.order.model.InviteSettlementItemListVO;
import com.yohoufo.order.model.InviteSettlementListVO;
import com.yohoufo.order.service.IInviteSettlementService;
import com.yohoufo.order.service.proxy.UserProxyService;
import com.yohoufo.order.utils.InviteSettlementUtils;
import lombok.extern.slf4j.Slf4j;
import lombok.val;
... ... @@ -56,6 +57,9 @@ public class InviteSettlementServiceImpl implements IInviteSettlementService {
@Autowired
private InviteSettlementItemCreator inviteSettlementItemCreator;
@Autowired
UserProxyService userProxyService;
@Override
public InviteSettlementListVO getInviteSettlementList(Integer uid) {
... ... @@ -101,12 +105,17 @@ public class InviteSettlementServiceImpl implements IInviteSettlementService {
int start = (page - 1) * limit;
List<InviteSettlementItem> list = inviteSettlementItemMapper.select(uid, settlementType, time.getLeft(), time.getRight(), start, limit);
Map<Integer, Integer> settlementStatusMap = buildInviteSettlementIdStatusMap(uid, list);
Map<Integer, String> sellerUidNickNameMap = userProxyService.getNickNameByUids(list.stream()
.map(InviteSettlementItem::getSellerUid)
.filter(Objects::nonNull)
.distinct()
.collect(Collectors.toList()));
return builder
.list(list.stream().map(item -> {
Integer settlementStatus = settlementStatusMap.getOrDefault(item.getInviteSettlementId(), InviteSettlement.STATUS_WAIT_SETTLE);
InviteSettlementItemListVO.InviteSettlementItemVO vo = new InviteSettlementItemListVO.InviteSettlementItemVO();
vo.setBuyerOrderCode(item.getBuyerOrderCode().toString());
vo.setSellerName(item.getSellerUid().toString());
vo.setSellerName(sellerUidNickNameMap.get(item.getSellerUid()));
vo.setOrderAmount(InviteSettlementUtils.format(item.getOrderAmount()));
vo.setOrderCreateTime(DateUtil.formatYYMMddHHmmssPoint(item.getOrderCreateTime()));
vo.setSettleAmount(InviteSettlementUtils.format(item.getSettleAmount()));
... ...
... ... @@ -5,21 +5,30 @@ import com.github.rholder.retry.RetryerBuilder;
import com.github.rholder.retry.StopStrategies;
import com.github.rholder.retry.WaitStrategies;
import com.yohoufo.common.utils.DateUtil;
import com.yohoufo.dal.order.InviteRecordMapper;
import com.yohoufo.dal.order.InviteSettlementItemMapper;
import com.yohoufo.dal.order.InviteSettlementMapper;
import com.yohoufo.dal.order.model.InviteRecord;
import com.yohoufo.dal.order.model.InviteSettlement;
import com.yohoufo.dal.order.model.InviteSettlementItem;
import com.yohoufo.dal.order.model.InviteSettlementItemStats;
import com.yohoufo.order.model.bo.BankCard;
import com.yohoufo.order.service.proxy.BankCardService;
import com.yohoufo.order.utils.IdUtils;
import com.yohoufo.order.utils.InviteSettlementUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.math.BigDecimal;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
import static com.yohoufo.order.utils.InviteSettlementUtils.newLocalDateTimeOfEpochSecond;
/**
* @author LUOXC
... ... @@ -38,6 +47,9 @@ public class InviterSettleService {
@Autowired
private BankCardService bankCardService;
@Autowired
private InviteRecordMapper inviteRecordMapper;
public void settle(int uid) {
log.info("settle for {}", uid);
int now = DateUtil.getCurrentTimeSecond();
... ... @@ -116,19 +128,37 @@ public class InviterSettleService {
InviteSettlementItem.STATUS_ENABLE,
InviteSettlementItem.STATUS_SETTLED,
settlementId);
int storedSellerCount = inviteSettlementItemMapper.selectCountByUidTypeAndInviteSettlementId(uid, type, settlementId);
return BigDecimal.TEN.multiply(BigDecimal.valueOf(storedSellerCount));
int totalElements = inviteSettlementItemMapper.selectCountByUidTypeAndInviteSettlementId(uid, type, settlementId);
return InviteSettlementUtils.calculateSettleAmountOfType1(totalElements);
}
/**
* TODO 计算type2方式结算金额
* 计算type2方式结算金额
*
* @param uid
* @param settlementId
* @return
*/
private BigDecimal calculateSettleAmountOfType2(int uid, int settlementId) {
return BigDecimal.ZERO;
int type = 2;
inviteSettlementItemMapper.updateToSettled(
uid,
type,
InviteSettlementItem.STATUS_ENABLE,
InviteSettlementItem.STATUS_SETTLED,
settlementId);
// 待结算用户统计
List<InviteSettlementItemStats> statsList = inviteSettlementItemMapper.selectStatsByUidTypeAndInviteSettlementIdGroupBySellerUid(uid, type, settlementId);
// 被邀请时间
Map<Integer, Integer> invitees = inviteRecordMapper.selectByInviterUid(uid).stream()
.collect(Collectors.toMap(InviteRecord::getInviteeUid, InviteRecord::getCreateTime));
return statsList.stream()
.map(stats -> InviteSettlementUtils.calculateSettleAmountOfType2(
newLocalDateTimeOfEpochSecond(invitees.getOrDefault(stats.getSellerUid(), 0)),
inviteSettlementItemMapper.selectByUidTypeInviteSettlementIdAndSellerUid(uid, type, settlementId, stats.getSellerUid())
))
.reduce(BigDecimal.ZERO, BigDecimal::add);
}
}
... ...
... ... @@ -14,6 +14,7 @@ import com.yohoufo.common.ApiResponse;
import com.yohoufo.order.convert.AddressInfoConvertor;
import com.yohobuy.ufo.model.order.vo.AddressInfo;
import com.yohoufo.order.service.IStoredSellerService;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
... ... @@ -163,6 +164,9 @@ public class UserProxyService {
* @return
*/
public Map<Integer, String> getNickNameByUids(List<Integer> uids){
if(CollectionUtils.isEmpty(uids)){
return Maps.newHashMap();
}
String url = uicUrl + NICK_NAME_API;
Map<String,Object> params = Maps.newHashMap();
params.put("uids", uids.stream().map(String::valueOf).collect(Collectors.joining(",")));
... ...
package com.yohoufo.order.utils;
import com.yohoufo.dal.order.model.InviteSettlementItem;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.util.List;
import java.util.Objects;
import java.util.function.BiPredicate;
/**
* @author LUOXC
... ... @@ -22,4 +28,79 @@ public class InviteSettlementUtils {
}
}
/**
* type1 计算结算金额
*
* @param totalElements 待结算订单数量
* @return
*/
public static BigDecimal calculateSettleAmountOfType1(int totalElements) {
return BigDecimal.TEN.multiply(BigDecimal.valueOf(totalElements));
}
/**
* type2 计算结算金额
*
* @param inviteTime 被邀请时间
* @param items 待结算订单
* @return
*/
public static BigDecimal calculateSettleAmountOfType2(LocalDateTime inviteTime, List<InviteSettlementItem> items) {
// 一个月内
BigDecimal inOneMonthTotalSettleAmount = items.stream()
.filter(item -> newLocalDateTimeOfEpochSecond(item.getCreateTime()).isBefore(inviteTime.plusMonths(1)))
.map(InviteSettlementItem::getOrderAmount)
.reduce(BigDecimal.ZERO, BigDecimal::add)
.multiply(BigDecimal.valueOf(0.02));
BiPredicate<InviteSettlementItem, Integer> iaAfterOrEqual = (item, months) -> {
LocalDateTime createTime = newLocalDateTimeOfEpochSecond(item.getCreateTime());
LocalDateTime afterInviteMonth = inviteTime.plusMonths(months);
return createTime.isAfter(afterInviteMonth) || createTime.isEqual(afterInviteMonth);
};
// 五个月内
BigDecimal inFiveMonthTotalSettleAmount;
BigDecimal inFiveMonthTotalOrderAmount = items.stream()
.filter(item -> iaAfterOrEqual.test(item, 1))
.filter(item -> newLocalDateTimeOfEpochSecond(item.getCreateTime()).isBefore(inviteTime.plusMonths(5)))
.map(InviteSettlementItem::getOrderAmount)
.reduce(BigDecimal.ZERO, BigDecimal::add);
if (inFiveMonthTotalOrderAmount.compareTo(BigDecimal.valueOf(100_0000)) < 0) {
inFiveMonthTotalSettleAmount = inFiveMonthTotalOrderAmount.multiply(BigDecimal.ZERO);
} else if (inFiveMonthTotalOrderAmount.compareTo(BigDecimal.valueOf(180_0000)) <= 0) {
inFiveMonthTotalSettleAmount = inFiveMonthTotalOrderAmount.multiply(BigDecimal.valueOf(0.008));
} else if (inFiveMonthTotalOrderAmount.compareTo(BigDecimal.valueOf(300_0000)) <= 0) {
inFiveMonthTotalSettleAmount = inFiveMonthTotalOrderAmount.multiply(BigDecimal.valueOf(0.015));
} else {
inFiveMonthTotalSettleAmount = inFiveMonthTotalOrderAmount.multiply(BigDecimal.valueOf(0.020));
}
// 五个月以后
BigDecimal outFiveMonthTotalSettleAmount;
BigDecimal outFiveMonthTotalOrderAmount = items.stream()
.filter(item -> iaAfterOrEqual.test(item, 5))
.map(InviteSettlementItem::getOrderAmount)
.reduce(BigDecimal.ZERO, BigDecimal::add);
if (outFiveMonthTotalOrderAmount.compareTo(BigDecimal.valueOf(180_0000)) < 0) {
outFiveMonthTotalSettleAmount = outFiveMonthTotalOrderAmount.multiply(BigDecimal.ZERO);
} else if (outFiveMonthTotalOrderAmount.compareTo(BigDecimal.valueOf(300_0000)) <= 0) {
outFiveMonthTotalSettleAmount = outFiveMonthTotalOrderAmount.multiply(BigDecimal.valueOf(0.010));
} else if (outFiveMonthTotalOrderAmount.compareTo(BigDecimal.valueOf(500_0000)) <= 0) {
outFiveMonthTotalSettleAmount = outFiveMonthTotalOrderAmount.multiply(BigDecimal.valueOf(0.012));
} else {
outFiveMonthTotalSettleAmount = outFiveMonthTotalOrderAmount.multiply(BigDecimal.valueOf(0.018));
}
return inOneMonthTotalSettleAmount.add(inFiveMonthTotalSettleAmount).add(outFiveMonthTotalSettleAmount);
}
public static ZoneOffset zoneOffset() {
return ZoneOffset.of("+8");
}
public static LocalDateTime newLocalDateTimeOfEpochSecond(int epochSecond) {
return LocalDateTime.ofEpochSecond(epochSecond, 0, ZoneOffset.of("+8"));
}
}
... ...