Authored by gemingdan

增加提现mq到erp的手动接口

... ... @@ -80,6 +80,7 @@
<value>/UnionShareRest/getShareInfoByUid</value>
<value>/UnionShareRest/checkSettlement</value>
<value>/UnionShareRest/addSettlement</value>
<value>/UnionShareRest/sendSettlementMqToErp</value>
<value>/UnionShareRest/queryUnionShareOrder</value>
<value>/UnionShareRest/queryUnionTypeByUid</value>
<value>/UnionShareRest/queryShareTotal</value>
... ...
... ... @@ -56,6 +56,7 @@ public interface UnionShareOrdersMapper {
List<UnionShareOrders> selectListByCondition(@Param("promoteUid")int promoteUid, @Param("status")String status,@Param("updateTime")int updateTime, @Param("offset") int offset, @Param("rows") int rows);
List<String> selectOrderCodesByCondition(@Param("settlementCode")String settlementCode, @Param("offset") int offset, @Param("rows") int rows);
int selectOrderNumByCondition(@Param("settlementCode")String settlementCode);
List<UnionShareOrders> selectOrderByCondition(@Param("settlementCode")String settlementCode, @Param("offset") int offset, @Param("rows") int rows);
List<Integer> selectIdForActivity(@Param("settlementCode")String settlementCode);
... ...
... ... @@ -98,6 +98,11 @@
where settlement_code = #{settlementCode,jdbcType=VARCHAR} and order_code is not null
limit #{offset}, #{rows}
</select>
<select id="selectOrderNumByCondition" resultType="java.lang.Integer">
select count(1)
from union_share_orders
where settlement_code = #{settlementCode,jdbcType=VARCHAR} and order_code is not null
</select>
<select id="selectOrderByCondition" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
... ...
... ... @@ -87,6 +87,16 @@ public class UnionShareRest {
BigDecimal result = unionShareService.addSettlement(uid);
return new UnionResponse(200, "addSettlement success", result);
}
/**
* 提现mq重新发送给erp
* */
@RequestMapping("/sendSettlementMqToErp")
@ResponseBody
public UnionResponse sendSettlementMqToErp(String settlementCode,int uid){
log.info("addSettlement,uid is {}",uid);
int result = unionShareService.sendSettlementMqToErp(settlementCode,uid);
return new UnionResponse(200, "sendSettlementMqToErp success", result);
}
@RequestMapping("/queryUnionShareOrders")
@ResponseBody
... ...
... ... @@ -52,6 +52,11 @@ public interface IUnionShareService {
*/
BigDecimal addSettlement(Integer uid);
/***
* 提现mq重发给erp
* */
int sendSettlementMqToErp(String settlementCode, int uid);
/**
* 获取用户可提现金额、已提现金额、是否可以提现
* */
... ...
... ... @@ -695,7 +695,7 @@ public class UnionShareServiceImpl implements IUnionShareService,IBusinessExport
logger.info("joinInviteActivity end.newUids error.uids is {}.",uids);
return;
}
// Set<Integer> newUids = uids;//TODO 测试环境绕过
// Set<Integer> newUids = uids;// 测试环境绕过
//过滤udid有过记录的用户
Set<String> udids=appYohoCpsNewUids.stream().map(u->u.getUdid()).collect(Collectors.toSet());
Set<String> existUdids=unionShareYohoNewUidMapper.selectByUdids(udids);
... ... @@ -3504,6 +3504,69 @@ public class UnionShareServiceImpl implements IUnionShareService,IBusinessExport
return totalAmount;
}
@Override
public int sendSettlementMqToErp(String settlementCode,int uid) {
mqLog.info("sendSettlementMqToErp start,send mq {} to erp,uid is {},settlementCode is {}", SETTLEMENT_TOPIC, uid, settlementCode);
UnionShareSettlement unionShareSettlement=unionShareSettlementMapper.selectByCode(settlementCode);
if (unionShareSettlement == null||unionShareSettlement.getPromoteUid()!=uid) {
return 0;
}
int count = unionShareOrdersMapper.selectOrderNumByCondition(settlementCode);
if (count < 1) {
return -1;
}
Set<String> orderCodes = new HashSet<>();
List<UnionShareOrdersBo> orderList = new ArrayList<>();//该提现对应的订单
int size = 1000;
int page = count % size > 0 ? (count / size) + 1 : count / size;
for (int i = 0; i < page; i++) {
int offset = i * size ;
List<UnionShareOrders> periodOrders = unionShareOrdersMapper.selectOrderByCondition(settlementCode, offset, size);
if (CollectionUtils.isEmpty(periodOrders) || periodOrders.get(0) == null) {
break;
}
periodOrders.forEach(o->{
UnionShareOrdersBo b = new UnionShareOrdersBo();
BeanUtils.copyProperties(o,b);
if (b.getActivityId()>0) {
b.setActivityType(2);
}
orderList.add(b);
orderCodes.add(b.getOrderCode());
});
}
//查询活动额外返的返利单
List<Integer> ids = unionShareOrdersMapper.selectIdForActivity(settlementCode);
List<UnionShareOrdersActivityBo> activityBos = new ArrayList<>();
if(CollectionUtils.isNotEmpty(ids)){
List<UnionShareOrdersActivityLogs> activities = unionShareOrdersActivityLogsMapper.selectByOrderIds(ids);
activities.forEach(a->{
UnionShareOrdersActivityBo bo = new UnionShareOrdersActivityBo();
BeanUtils.copyProperties(a,bo);
bo.setId(a.getOrderId());
activityBos.add(bo);
});
}
if (CollectionUtils.isEmpty(orderList)&&CollectionUtils.isEmpty(activityBos)) {
//不该查不到订单
settlementLog.warn("sendSettlementMqToErp end,uid is {},settlementCode is {},totalAmount is {},can not find orders and activity.",uid,settlementCode,unionShareSettlement.getSettlementAmount());
throw new ServiceException(ServiceError.UNION_SETTLEMENT_CANNOT_FIND_ORDER_ERROR);
}
//清缓存
clearShareOrderRedis(uid);
// 发送取现mq给erp SETTLEMENT_TOPIC
ShareSettlementBo bo = new ShareSettlementBo();
BeanUtils.copyProperties(unionShareSettlement,bo);
bo.setOrderCodes(orderCodes);
bo.setOrderList(orderList);
bo.setActivities(activityBos);
mqLog.info("sendSettlementMqToErp,send mq {} to erp,uid is {},settlementCode is {},bo is {}", SETTLEMENT_TOPIC, uid, settlementCode, JsonUtil.objectToJSON(bo));
yhProducer.send(SETTLEMENT_TOPIC, bo);
settlementLog.info("sendSettlementMqToErp,send mq {} to erp success,uid is {},settlementCode is {},bo is {}", SETTLEMENT_TOPIC, uid, settlementCode, bo);
return count;
}
//扣税金额计算,保留两位小数,多余位舍弃
private BigDecimal getTaxAmount(BigDecimal amount) {
// 假设佣金为X
... ...