...
|
...
|
@@ -50,6 +50,9 @@ import java.util.concurrent.atomic.AtomicInteger; |
|
|
@Service
|
|
|
public class UnionShareServiceImpl implements IUnionShareService,IBusinessExportService {
|
|
|
private Logger logger = LoggerFactory.getLogger(UnionShareServiceImpl.class);
|
|
|
private Logger mqLog = LoggerFactory.getLogger("cps_mq");
|
|
|
private Logger settlementLog = LoggerFactory.getLogger("cps_settlement");
|
|
|
// private Logger mqLog = LoggerFactory.getLogger("cps_mq");
|
|
|
|
|
|
@Autowired
|
|
|
private UnionShareOrdersMapper unionShareOrdersMapper;
|
...
|
...
|
@@ -516,7 +519,7 @@ public class UnionShareServiceImpl implements IUnionShareService,IBusinessExport |
|
|
*/
|
|
|
@Override
|
|
|
public BigDecimal addSettlement(Integer uid) {
|
|
|
logger.info("addSettlement enter,uid is {}",uid);
|
|
|
settlementLog.info("addSettlement enter,uid is {}",uid);
|
|
|
if (uid == null ) {
|
|
|
throw new ServiceException(ServiceError.USER_ID_ERROR);
|
|
|
}
|
...
|
...
|
@@ -524,13 +527,13 @@ public class UnionShareServiceImpl implements IUnionShareService,IBusinessExport |
|
|
int count = unionShareUserMapper.selectCountByUid(uid);
|
|
|
if (count == 0) {
|
|
|
//不是特邀用户
|
|
|
logger.info("addSettlement end,can not find unionType,uid is {}",uid);
|
|
|
settlementLog.info("addSettlement end,can not find unionType,uid is {}",uid);
|
|
|
throw new ServiceException(ServiceError.USER_ID_ERROR);
|
|
|
}
|
|
|
//查询是否有处理中的提现
|
|
|
if (hasSettlement(uid)) {
|
|
|
//有处理中的提现单,不可提现
|
|
|
logger.info("addSettlement end,hasSettlement,uid is {}",uid);
|
|
|
settlementLog.info("addSettlement end,hasSettlement,uid is {}",uid);
|
|
|
throw new ServiceException(ServiceError.UNION_HASSETTLEMENT_ERROR);
|
|
|
}
|
|
|
|
...
|
...
|
@@ -538,12 +541,12 @@ public class UnionShareServiceImpl implements IUnionShareService,IBusinessExport |
|
|
int orderCount = unionShareOrdersMapper.selectCountByCondition(uid,ShareOrdersStatusEnum.CAN_SETTLE.getCode());
|
|
|
if (orderCount == 0 ) {
|
|
|
//没有可以提现的订单
|
|
|
logger.info("addSettlement end,has not remaining settlement,uid is {}",uid);
|
|
|
settlementLog.info("addSettlement end,has not remaining settlement,uid is {}",uid);
|
|
|
throw new ServiceException(ServiceError.UNION_HASNOT_REMAINING_SETTLEMENT);
|
|
|
}
|
|
|
// 生成取现单,绑定订单
|
|
|
BigDecimal amount = relateSettlementAndOrder(uid);
|
|
|
logger.info("addSettlement end,remaining settlement is {},uid is {}",amount,uid);
|
|
|
settlementLog.info("addSettlement end,remaining settlement is {},uid is {}",amount,uid);
|
|
|
return amount;
|
|
|
}
|
|
|
|
...
|
...
|
@@ -632,22 +635,22 @@ public class UnionShareServiceImpl implements IUnionShareService,IBusinessExport |
|
|
* */
|
|
|
public BigDecimal relateSettlementAndOrder(int uid) {
|
|
|
|
|
|
logger.info("relateSettlementAndOrder enter,uid is {}",uid);
|
|
|
settlementLog.info("relateSettlementAndOrder enter,uid is {}",uid);
|
|
|
|
|
|
//生成提现编号
|
|
|
String settlementCode = createSettlementCode();
|
|
|
logger.info("relateSettlementAndOrder,uid is {},settlementCode is {}",uid,settlementCode);
|
|
|
settlementLog.info("relateSettlementAndOrder,uid is {},settlementCode is {}",uid,settlementCode);
|
|
|
|
|
|
//更新订单状态,由可结算变为打款中
|
|
|
int updateTime = DateUtil.getCurrentTimeSecond();
|
|
|
int count=unionShareOrdersMapper.updateStatusByUid(uid,settlementCode, ShareOrdersStatusEnum.CAN_SETTLE.getCode(), ShareOrdersStatusEnum.SETTLE.getCode(), updateTime);
|
|
|
if (count == 0) {
|
|
|
logger.info("relateSettlementAndOrder end,uid is {},settlementCode is {},There are no available orders.",uid,settlementCode);
|
|
|
settlementLog.info("relateSettlementAndOrder end,uid is {},settlementCode is {},There are no available orders.",uid,settlementCode);
|
|
|
throw new ServiceException(ServiceError.UNION_SETTLEMENT_UNAVAILABLE_ORDER_ERROR);
|
|
|
}
|
|
|
//计算提现金额
|
|
|
BigDecimal totalAmount=unionShareOrdersMapper.selectAmountBySettleCode(uid, settlementCode);
|
|
|
logger.info("relateSettlementAndOrder,uid is {},settlementCode is {},totalAmount is {}",uid,settlementCode,totalAmount);
|
|
|
settlementLog.info("relateSettlementAndOrder,uid is {},settlementCode is {},totalAmount is {}",uid,settlementCode,totalAmount);
|
|
|
|
|
|
//生成提现单
|
|
|
UnionShareSettlement insertReq = new UnionShareSettlement();
|
...
|
...
|
@@ -660,7 +663,7 @@ public class UnionShareServiceImpl implements IUnionShareService,IBusinessExport |
|
|
int num=unionShareSettlementMapper.insertSelective(insertReq);
|
|
|
if (num < 1) {
|
|
|
//插入失败 todo 日志记录
|
|
|
logger.warn("relateSettlementAndOrder end,uid is {},settlementCode is {},totalAmount is {},insert nothing.",uid,settlementCode,totalAmount);
|
|
|
settlementLog.warn("relateSettlementAndOrder end,uid is {},settlementCode is {},totalAmount is {},insert nothing.",uid,settlementCode,totalAmount);
|
|
|
}
|
|
|
|
|
|
Set<String> orderCodes = new HashSet<>();
|
...
|
...
|
@@ -676,7 +679,7 @@ public class UnionShareServiceImpl implements IUnionShareService,IBusinessExport |
|
|
}
|
|
|
if (orderCodes.size() == 0) {
|
|
|
//不该查不到订单
|
|
|
logger.warn("relateSettlementAndOrder end,uid is {},settlementCode is {},totalAmount is {},can not find orders.",uid,settlementCode,totalAmount);
|
|
|
settlementLog.warn("relateSettlementAndOrder end,uid is {},settlementCode is {},totalAmount is {},can not find orders.",uid,settlementCode,totalAmount);
|
|
|
throw new ServiceException(ServiceError.UNION_SETTLEMENT_CANNOT_FIND_ORDER_ERROR);
|
|
|
}
|
|
|
|
...
|
...
|
@@ -688,8 +691,9 @@ public class UnionShareServiceImpl implements IUnionShareService,IBusinessExport |
|
|
ShareSettlementBo bo = new ShareSettlementBo();
|
|
|
BeanUtils.copyProperties(insertReq,bo);
|
|
|
bo.setOrderCodes(orderCodes);
|
|
|
logger.info("relateSettlementAndOrder,send mq {} to erp,uid is {},settlementCode is {},bo is {}", SETTLEMENT_TOPIC, uid, settlementCode, bo);
|
|
|
mqLog.info("relateSettlementAndOrder,send mq {} to erp,uid is {},settlementCode is {},bo is {}", SETTLEMENT_TOPIC, uid, settlementCode, bo);
|
|
|
yhProducer.send(SETTLEMENT_TOPIC, bo);
|
|
|
settlementLog.info("relateSettlementAndOrder,send mq {} to erp success,uid is {},settlementCode is {},bo is {}", SETTLEMENT_TOPIC, uid, settlementCode, bo);
|
|
|
return totalAmount;
|
|
|
}
|
|
|
|
...
|
...
|
|