Authored by LUOXC

Merge branch 'hotfix-20200305' into test6.9.22

package com.yohoufo.dal.order.model;
import lombok.Data;
import lombok.Getter;
import lombok.Setter;
import java.math.BigDecimal;
import java.util.Objects;
/**
* 交易流水表
*/
@Data
@Getter
@Setter
public class TradeBills {
/**
... ... @@ -66,10 +69,23 @@ public class TradeBills {
//支付阶段,0:普通,1:定金
private int payLevel = 0;
/**
* suggest use new enum, define class as blow
* {@link com.yohoufo.order.common.BillTradeStatus}
*/
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
TradeBills that = (TradeBills) o;
return Objects.equals(uid, that.uid) &&
Objects.equals(orderCode, that.orderCode) &&
Objects.equals(userType, that.userType) &&
Objects.equals(tradeType, that.tradeType) &&
Objects.equals(incomeOutcome, that.incomeOutcome);
}
@Override
public int hashCode() {
return Objects.hash(uid, orderCode, userType, tradeType, incomeOutcome);
}
@Deprecated
public enum Status {
... ... @@ -78,10 +94,14 @@ public class TradeBills {
Status(int code) {
this.code = code;
}
private int code;
public int getCode() {
return code;
}
}
}
... ...
... ... @@ -2,10 +2,14 @@ package com.yohoufo.order.repository;
import com.yohoufo.dal.order.model.TradeBills;
import java.util.List;
public interface TradeBillsRepository {
int save(TradeBills record);
List<TradeBills> findByOrderCode(Long orderCode);
int lock(Integer id);
int unlock(Integer id);
... ...
package com.yohoufo.order.repository;
import com.google.common.collect.Lists;
import com.yohoufo.common.alarm.EventBusPublisher;
import com.yohoufo.dal.order.TradeBillsMapper;
import com.yohoufo.dal.order.model.TradeBills;
... ... @@ -7,6 +8,7 @@ import com.yohoufo.order.event.TradeBillsChangeEvent;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import java.util.List;
import java.util.Objects;
@Repository
... ... @@ -27,6 +29,11 @@ public class TradeBillsRepositoryImpl implements TradeBillsRepository {
}
@Override
public List<TradeBills> findByOrderCode(Long orderCode) {
return tradeBillsMapper.selectByOrderCodeList(Lists.newArrayList(orderCode));
}
@Override
public int lock(Integer id) {
return tradeBillsMapper.updateLock(id);
}
... ...
... ... @@ -28,6 +28,7 @@ import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
... ... @@ -84,9 +85,12 @@ public class TransferManager {
@Transactional(propagation = Propagation.REQUIRES_NEW)
@Database(ForceMaster = true, DataSource = "ufo_order")
public ServiceException save(TransferBill transferBill) {
if (Objects.isNull(transferBill.getTradeBills().getId())) {
TradeBills tradeBills = transferBill.getTradeBills();
if (Objects.isNull(tradeBills.getId())) {
ServiceException serviceException = transferBill.resetTradeStatus();
tradeBillsRepository.save(transferBill.getTradeBills());
List<TradeBills> histories = tradeBillsRepository.findByOrderCode(tradeBills.getOrderCode());
throwServiceExceptionIf(histories.contains(tradeBills), 500, "转账单已存在");
tradeBillsRepository.save(tradeBills);
ordersPayTransferMapper.insert(transferBill.getTransfer());
publishEvent(transferBill);
return serviceException;
... ...