Authored by tanling

1.没有银行卡信息照样结算 2结算增加事限制

... ... @@ -2191,4 +2191,12 @@ public class DateUtil {
return (int) (cal.getTimeInMillis() / 1000);
}
public static Integer getTimestampOfDateTime(LocalDateTime localDateTime) {
ZoneId zone = ZoneId.systemDefault();
Instant instant = localDateTime.atZone(zone).toInstant();
return (int)instant.toEpochMilli()/1000;
}
}
... ...
... ... @@ -15,7 +15,8 @@ public interface InviteSettlementItemMapper {
@Param("type") Integer type,
@Param("srcStatus") Integer srcStatus,
@Param("tagStatus") Integer tagStatus,
@Param("inviteSettlementId") Integer inviteSettlementId);
@Param("inviteSettlementId") Integer inviteSettlementId,
@Param("settlementTime") Integer settlementTime);
int updateToSettledRollback(@Param("uid") Integer uid,
@Param("type") Integer type,
... ... @@ -35,13 +36,15 @@ public interface InviteSettlementItemMapper {
int selectCountByUidTypeAndInviteSettlementId(@Param("uid") Integer uid,
@Param("type") Integer type,
@Param("inviteSettlementId") Integer inviteSettlementId);
@Param("inviteSettlementId") Integer inviteSettlementId,
@Param("settlementTime") Integer settlementTime);
int updateByPrimaryKeySelective(InviteSettlementItem record);
List<InviteSettlementItemStats> selectStatsByUidTypeAndInviteSettlementIdGroupBySellerUid(@Param("uid") Integer uid,
@Param("type") Integer type,
@Param("inviteSettlementId") Integer inviteSettlementId);
@Param("inviteSettlementId") Integer inviteSettlementId,
@Param("settlementTime") Integer settlementTime);
List<InviteSettlementItem> selectByUidTypeInviteSettlementIdAndSellerUid(@Param("uid") Integer uid,
@Param("type") Integer type,
... ...
... ... @@ -57,6 +57,7 @@
where uid = #{uid,jdbcType=INTEGER}
and type = #{type,jdbcType=INTEGER}
and status = #{srcStatus,jdbcType=INTEGER}
and <![CDATA[ create_time <= #{settlementTime,jdbcType=INTEGER}]]>
</update>
<update id="updateToSettledRollback">
... ... @@ -101,6 +102,7 @@
count(1)
from invite_settlement_item
where uid = #{uid,jdbcType=INTEGER} and type = #{type,jdbcType=INTEGER} and invite_settlement_id = #{inviteSettlementId,jdbcType=INTEGER}
and <![CDATA[ create_time <= #{settlementTime,jdbcType=INTEGER}]]>
</select>
<select id="selectStatsByUidTypeAndInviteSettlementIdGroupBySellerUid" resultType="com.yohoufo.dal.order.model.InviteSettlementItemStats" >
... ... @@ -113,6 +115,7 @@
where uid = #{uid,jdbcType=INTEGER}
and type = #{type,jdbcType=INTEGER}
and invite_settlement_id = #{inviteSettlementId,jdbcType=INTEGER}
and <![CDATA[ create_time <= #{settlementTime,jdbcType=INTEGER}]]>
group by seller_uid
</select>
... ...
... ... @@ -77,10 +77,10 @@ public class InviterSettleService {
return;
}
BankCard bankCard = bankCardService.getBankCard(uid);
if (Objects.isNull(bankCard)) {
log.warn("settle for {} end bank card is null.", uid);
return;
}
// if (Objects.isNull(bankCard)) {
// log.warn("settle for {} end bank card is null.", uid);
// return;
// }
// 新建结算单
log.info("settle for {} create a new settlement.", uid);
InviteSettlement settlement = new InviteSettlement();
... ... @@ -90,11 +90,15 @@ public class InviterSettleService {
settlement.setSettleCode(0);
settlement.setSettleAmount(BigDecimal.ZERO);
settlement.setSettleTime(0);
if (Objects.nonNull(bankCard)){
settlement.setName(bankCard.getName());
settlement.setIdCardNo(bankCard.getIdCardNo());
settlement.setBankName(bankCard.getBankName());
settlement.setBankBranch(bankCard.getBankBranch());
settlement.setBankCardNo(bankCard.getBankCardNo());
}
settlement.setStatus(InviteSettlement.STATUS_WAIT_SETTLE);
inviteSettlementMapper.insert(settlement);
// 计算结算金额
... ... @@ -118,7 +122,7 @@ public class InviterSettleService {
BigDecimal settleAmount;
if (settleType == InviteSettlement.SETTLE_TYPE_STORED) {
// type1方式结算金额
settleAmount = calculateSettleAmountOfType1(uid, settlementId);
settleAmount = calculateSettleAmountOfType1(uid, settlementId, settleTime);
log.info("settle for {} calculate settle amount for settlement {}, the amount of type1 is {}.",
uid, settlementId, settleAmount);
} else {
... ... @@ -142,15 +146,15 @@ public class InviterSettleService {
* @param settlementId
* @return
*/
private BigDecimal calculateSettleAmountOfType1(int uid, int settlementId) {
private BigDecimal calculateSettleAmountOfType1(int uid, int settlementId, LocalDateTime settleTime) {
int type = 1;
inviteSettlementItemMapper.updateToSettled(
uid,
type,
InviteSettlementItem.STATUS_ENABLE,
InviteSettlementItem.STATUS_SETTLED,
settlementId);
int totalElements = inviteSettlementItemMapper.selectCountByUidTypeAndInviteSettlementId(uid, type, settlementId);
settlementId, DateUtil.getTimestampOfDateTime(settleTime));
int totalElements = inviteSettlementItemMapper.selectCountByUidTypeAndInviteSettlementId(uid, type, settlementId, DateUtil.getTimestampOfDateTime(settleTime));
log.info("settle for calculateSettleAmountOfType1 totalElements is {}, uid is {}, uid is {}, settlementId is {}", totalElements, uid, type, settlementId);
return InviteSettlementUtils.calculateSettleAmountOfType1(totalElements);
}
... ... @@ -169,9 +173,10 @@ public class InviterSettleService {
type,
InviteSettlementItem.STATUS_ENABLE,
InviteSettlementItem.STATUS_SETTLED,
settlementId);
settlementId, DateUtil.getTimestampOfDateTime(settleTime));
// 待结算用户统计
List<InviteSettlementItemStats> statsList = inviteSettlementItemMapper.selectStatsByUidTypeAndInviteSettlementIdGroupBySellerUid(uid, type, settlementId);
List<InviteSettlementItemStats> statsList = inviteSettlementItemMapper.selectStatsByUidTypeAndInviteSettlementIdGroupBySellerUid(uid, type,
settlementId,DateUtil.getTimestampOfDateTime(settleTime));
// 被邀请时间
Map<Integer, Integer> invitees = inviteRecordMapper.selectByInviterUid(uid).stream()
.collect(Collectors.toMap(InviteRecord::getInviteeUid, InviteRecord::getCreateTime));
... ...