Authored by tanling

Merge branch 'test6.9.0' of http://git.yoho.cn/ufo/yohoufo-fore into test6.9.0

... ... @@ -17,6 +17,8 @@ public class InviteSettlement {
private Integer uid;
private Integer settleCode;
private BigDecimal settleAmount;
private Integer settleTime;
... ...
... ... @@ -4,6 +4,7 @@
<resultMap id="BaseResultMap" type="com.yohoufo.dal.order.model.InviteSettlement" >
<id column="id" property="id" jdbcType="INTEGER" />
<result column="uid" property="uid" jdbcType="INTEGER" />
<result column="settle_code" property="settleCode" jdbcType="INTEGER" />
<result column="settle_amount" property="settleAmount" jdbcType="DECIMAL" />
<result column="settle_time" property="settleTime" jdbcType="INTEGER" />
<result column="paid_time" property="paidTime" jdbcType="INTEGER" />
... ... @@ -11,18 +12,21 @@
<result column="create_time" property="createTime" jdbcType="INTEGER" />
</resultMap>
<sql id="Base_Column_List" >
id, uid, settle_amount, settle_time,paid_time, status, create_time
id, uid, settle_code, settle_amount, settle_time,paid_time, status, create_time
</sql>
<insert id="insert" parameterType="com.yohoufo.dal.order.model.InviteSettlement" useGeneratedKeys="true" keyProperty="id">
insert into invite_settlement (id, uid, settle_amount, settle_time, status, create_time)
values (#{id,jdbcType=INTEGER}, #{uid,jdbcType=INTEGER}, #{settleAmount,jdbcType=DECIMAL},
insert into invite_settlement (id, uid, settle_code, settle_amount, settle_time, status, create_time)
values (#{id,jdbcType=INTEGER}, #{uid,jdbcType=INTEGER}, #{settleCode,jdbcType=DECIMAL}, #{settleAmount,jdbcType=DECIMAL},
#{settleTime,jdbcType=INTEGER}, #{status,jdbcType=INTEGER}, #{createTime,jdbcType=INTEGER})
</insert>
<update id="updateByUidAndId" parameterType="com.yohoufo.dal.order.model.InviteSettlement" >
update invite_settlement
<set >
<if test="settleCode != null" >
settle_code = #{settleCode,jdbcType=INTEGER},
</if>
<if test="settleAmount != null" >
settle_amount = #{settleAmount,jdbcType=DECIMAL},
</if>
... ...
... ... @@ -6,6 +6,7 @@ import com.yohoufo.dal.order.model.InviteSettlement;
import com.yohoufo.dal.order.model.Inviter;
import com.yohoufo.order.model.InviteSettlementListVO;
import com.yohoufo.order.service.IInviteSettlementService;
import com.yohoufo.order.utils.IdUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
... ... @@ -47,11 +48,10 @@ public class InviteSettlementServiceImpl implements IInviteSettlementService {
ZoneOffset zoneOffset = ZoneOffset.of("+8");
List<InviteSettlementListVO.InviteSettlementVO> items = inviteSettlementList.stream()
.map(inviteSettlement -> {
LocalDateTime createTime = LocalDateTime.ofEpochSecond(inviteSettlement.getCreateTime().longValue(), 0, zoneOffset);
LocalDateTime settleTime = LocalDateTime.ofEpochSecond(inviteSettlement.getSettleTime().longValue(), 0, zoneOffset);
LocalDateTime paidTime = LocalDateTime.ofEpochSecond(inviteSettlement.getPaidTime().longValue(), 0, zoneOffset);
InviteSettlementListVO.InviteSettlementVO item = new InviteSettlementListVO.InviteSettlementVO();
item.setSettleCode(String.format("%s%010d", createTime.format(DateTimeFormatter.ofPattern("yyyyMMdd")), inviteSettlement.getId()));
item.setSettleCode(String.format("%010d", inviteSettlement.getSettleCode()));
item.setSettleAmount("+" + inviteSettlement.getSettleAmount().setScale(1, RoundingMode.FLOOR));
item.setSettleTime(settleTime.format(DateTimeFormatter.ofPattern("yyyy.MM.dd HH:mm:ss")));
item.setPaidTime(paidTime.format(DateTimeFormatter.ofPattern("yyyy.MM.dd HH:mm:ss")));
... ...
... ... @@ -9,6 +9,7 @@ import com.yohoufo.dal.order.InviteSettlementItemMapper;
import com.yohoufo.dal.order.InviteSettlementMapper;
import com.yohoufo.dal.order.model.InviteSettlement;
import com.yohoufo.dal.order.model.InviteSettlementItem;
import com.yohoufo.order.utils.IdUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
... ... @@ -46,6 +47,7 @@ public class InviterSettleService {
InviteSettlement settlement = new InviteSettlement();
settlement.setUid(uid);
settlement.setCreateTime(now);
settlement.setSettleCode(0);
settlement.setSettleAmount(BigDecimal.ZERO);
settlement.setSettleTime(0);
settlement.setStatus(InviteSettlement.STATUS_WAIT_SETTLE);
... ... @@ -77,6 +79,7 @@ public class InviterSettleService {
log.info("settle for {} calculate settle amount for settlement {}, the amount of type2 is {}.",
uid, settlementId, settleAmountOfType2);
// 更新结算金额
settlement.setSettleCode(IdUtils.derangement(settlementId));
settlement.setSettleAmount(settleAmountOfType1.add(settleAmountOfType2));
settlement.setSettleTime(DateUtil.getCurrentTimeSecond());
settlement.setStatus(InviteSettlement.STATUS_WAIT_PAY);
... ...
package com.yohoufo.order.utils;
/**
* @author LUOXC
* @date 2019/4/3 17:58
*/
public class IdUtils {
private static final int SEQUENCE_BITS = 31; //31位序列位: 1 ~ 31
private static final long MAX_SEQUENCE = -1L ^ -1L << SEQUENCE_BITS;
private static final int REVERSE_KEY = 0x1111EEEE;
private static final int SEQUENCE_UP_LIMIT = (int) MAX_SEQUENCE;
/**
* 错位排列,尽量不能计算出每天的数量
* (注意,序列号只有31位有效位,而非32位)
*
* @param sequence
* @return
*/
public static int derangement(int sequence) {
if (sequence >= SEQUENCE_UP_LIMIT) {
throw new RuntimeException("sequence overflow");
}
//31位有效位,丢弃反转前的符号位
return bitReverse((sequence ^ REVERSE_KEY)) >>> 1;
}
private static int bitReverse(int sequence) {
int result = 0;
for (int i = Integer.SIZE; i > 0; i--) {
result = ((sequence & 1) << (i - 1)) | result;
sequence = sequence >>> 1;
}
return result;
}
}
... ...