Authored by gemingdan

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

@@ -80,6 +80,7 @@ @@ -80,6 +80,7 @@
80 <value>/UnionShareRest/getShareInfoByUid</value> 80 <value>/UnionShareRest/getShareInfoByUid</value>
81 <value>/UnionShareRest/checkSettlement</value> 81 <value>/UnionShareRest/checkSettlement</value>
82 <value>/UnionShareRest/addSettlement</value> 82 <value>/UnionShareRest/addSettlement</value>
  83 + <value>/UnionShareRest/sendSettlementMqToErp</value>
83 <value>/UnionShareRest/queryUnionShareOrder</value> 84 <value>/UnionShareRest/queryUnionShareOrder</value>
84 <value>/UnionShareRest/queryUnionTypeByUid</value> 85 <value>/UnionShareRest/queryUnionTypeByUid</value>
85 <value>/UnionShareRest/queryShareTotal</value> 86 <value>/UnionShareRest/queryShareTotal</value>
@@ -56,6 +56,7 @@ public interface UnionShareOrdersMapper { @@ -56,6 +56,7 @@ public interface UnionShareOrdersMapper {
56 List<UnionShareOrders> selectListByCondition(@Param("promoteUid")int promoteUid, @Param("status")String status,@Param("updateTime")int updateTime, @Param("offset") int offset, @Param("rows") int rows); 56 List<UnionShareOrders> selectListByCondition(@Param("promoteUid")int promoteUid, @Param("status")String status,@Param("updateTime")int updateTime, @Param("offset") int offset, @Param("rows") int rows);
57 57
58 List<String> selectOrderCodesByCondition(@Param("settlementCode")String settlementCode, @Param("offset") int offset, @Param("rows") int rows); 58 List<String> selectOrderCodesByCondition(@Param("settlementCode")String settlementCode, @Param("offset") int offset, @Param("rows") int rows);
  59 + int selectOrderNumByCondition(@Param("settlementCode")String settlementCode);
59 List<UnionShareOrders> selectOrderByCondition(@Param("settlementCode")String settlementCode, @Param("offset") int offset, @Param("rows") int rows); 60 List<UnionShareOrders> selectOrderByCondition(@Param("settlementCode")String settlementCode, @Param("offset") int offset, @Param("rows") int rows);
60 List<Integer> selectIdForActivity(@Param("settlementCode")String settlementCode); 61 List<Integer> selectIdForActivity(@Param("settlementCode")String settlementCode);
61 62
@@ -98,6 +98,11 @@ @@ -98,6 +98,11 @@
98 where settlement_code = #{settlementCode,jdbcType=VARCHAR} and order_code is not null 98 where settlement_code = #{settlementCode,jdbcType=VARCHAR} and order_code is not null
99 limit #{offset}, #{rows} 99 limit #{offset}, #{rows}
100 </select> 100 </select>
  101 + <select id="selectOrderNumByCondition" resultType="java.lang.Integer">
  102 + select count(1)
  103 + from union_share_orders
  104 + where settlement_code = #{settlementCode,jdbcType=VARCHAR} and order_code is not null
  105 + </select>
101 <select id="selectOrderByCondition" resultMap="BaseResultMap"> 106 <select id="selectOrderByCondition" resultMap="BaseResultMap">
102 select 107 select
103 <include refid="Base_Column_List" /> 108 <include refid="Base_Column_List" />
@@ -87,6 +87,16 @@ public class UnionShareRest { @@ -87,6 +87,16 @@ public class UnionShareRest {
87 BigDecimal result = unionShareService.addSettlement(uid); 87 BigDecimal result = unionShareService.addSettlement(uid);
88 return new UnionResponse(200, "addSettlement success", result); 88 return new UnionResponse(200, "addSettlement success", result);
89 } 89 }
  90 + /**
  91 + * 提现mq重新发送给erp
  92 + * */
  93 + @RequestMapping("/sendSettlementMqToErp")
  94 + @ResponseBody
  95 + public UnionResponse sendSettlementMqToErp(String settlementCode,int uid){
  96 + log.info("addSettlement,uid is {}",uid);
  97 + int result = unionShareService.sendSettlementMqToErp(settlementCode,uid);
  98 + return new UnionResponse(200, "sendSettlementMqToErp success", result);
  99 + }
90 100
91 @RequestMapping("/queryUnionShareOrders") 101 @RequestMapping("/queryUnionShareOrders")
92 @ResponseBody 102 @ResponseBody
@@ -52,6 +52,11 @@ public interface IUnionShareService { @@ -52,6 +52,11 @@ public interface IUnionShareService {
52 */ 52 */
53 BigDecimal addSettlement(Integer uid); 53 BigDecimal addSettlement(Integer uid);
54 54
  55 + /***
  56 + * 提现mq重发给erp
  57 + * */
  58 + int sendSettlementMqToErp(String settlementCode, int uid);
  59 +
55 /** 60 /**
56 * 获取用户可提现金额、已提现金额、是否可以提现 61 * 获取用户可提现金额、已提现金额、是否可以提现
57 * */ 62 * */
@@ -695,7 +695,7 @@ public class UnionShareServiceImpl implements IUnionShareService,IBusinessExport @@ -695,7 +695,7 @@ public class UnionShareServiceImpl implements IUnionShareService,IBusinessExport
695 logger.info("joinInviteActivity end.newUids error.uids is {}.",uids); 695 logger.info("joinInviteActivity end.newUids error.uids is {}.",uids);
696 return; 696 return;
697 } 697 }
698 -// Set<Integer> newUids = uids;//TODO 测试环境绕过 698 +// Set<Integer> newUids = uids;// 测试环境绕过
699 //过滤udid有过记录的用户 699 //过滤udid有过记录的用户
700 Set<String> udids=appYohoCpsNewUids.stream().map(u->u.getUdid()).collect(Collectors.toSet()); 700 Set<String> udids=appYohoCpsNewUids.stream().map(u->u.getUdid()).collect(Collectors.toSet());
701 Set<String> existUdids=unionShareYohoNewUidMapper.selectByUdids(udids); 701 Set<String> existUdids=unionShareYohoNewUidMapper.selectByUdids(udids);
@@ -3504,6 +3504,69 @@ public class UnionShareServiceImpl implements IUnionShareService,IBusinessExport @@ -3504,6 +3504,69 @@ public class UnionShareServiceImpl implements IUnionShareService,IBusinessExport
3504 return totalAmount; 3504 return totalAmount;
3505 } 3505 }
3506 3506
  3507 + @Override
  3508 + public int sendSettlementMqToErp(String settlementCode,int uid) {
  3509 + mqLog.info("sendSettlementMqToErp start,send mq {} to erp,uid is {},settlementCode is {}", SETTLEMENT_TOPIC, uid, settlementCode);
  3510 + UnionShareSettlement unionShareSettlement=unionShareSettlementMapper.selectByCode(settlementCode);
  3511 + if (unionShareSettlement == null||unionShareSettlement.getPromoteUid()!=uid) {
  3512 + return 0;
  3513 + }
  3514 + int count = unionShareOrdersMapper.selectOrderNumByCondition(settlementCode);
  3515 + if (count < 1) {
  3516 + return -1;
  3517 + }
  3518 + Set<String> orderCodes = new HashSet<>();
  3519 + List<UnionShareOrdersBo> orderList = new ArrayList<>();//该提现对应的订单
  3520 + int size = 1000;
  3521 + int page = count % size > 0 ? (count / size) + 1 : count / size;
  3522 + for (int i = 0; i < page; i++) {
  3523 + int offset = i * size ;
  3524 + List<UnionShareOrders> periodOrders = unionShareOrdersMapper.selectOrderByCondition(settlementCode, offset, size);
  3525 + if (CollectionUtils.isEmpty(periodOrders) || periodOrders.get(0) == null) {
  3526 + break;
  3527 + }
  3528 + periodOrders.forEach(o->{
  3529 + UnionShareOrdersBo b = new UnionShareOrdersBo();
  3530 + BeanUtils.copyProperties(o,b);
  3531 + if (b.getActivityId()>0) {
  3532 + b.setActivityType(2);
  3533 + }
  3534 + orderList.add(b);
  3535 + orderCodes.add(b.getOrderCode());
  3536 + });
  3537 + }
  3538 + //查询活动额外返的返利单
  3539 + List<Integer> ids = unionShareOrdersMapper.selectIdForActivity(settlementCode);
  3540 + List<UnionShareOrdersActivityBo> activityBos = new ArrayList<>();
  3541 + if(CollectionUtils.isNotEmpty(ids)){
  3542 + List<UnionShareOrdersActivityLogs> activities = unionShareOrdersActivityLogsMapper.selectByOrderIds(ids);
  3543 + activities.forEach(a->{
  3544 + UnionShareOrdersActivityBo bo = new UnionShareOrdersActivityBo();
  3545 + BeanUtils.copyProperties(a,bo);
  3546 + bo.setId(a.getOrderId());
  3547 + activityBos.add(bo);
  3548 + });
  3549 + }
  3550 + if (CollectionUtils.isEmpty(orderList)&&CollectionUtils.isEmpty(activityBos)) {
  3551 + //不该查不到订单
  3552 + settlementLog.warn("sendSettlementMqToErp end,uid is {},settlementCode is {},totalAmount is {},can not find orders and activity.",uid,settlementCode,unionShareSettlement.getSettlementAmount());
  3553 + throw new ServiceException(ServiceError.UNION_SETTLEMENT_CANNOT_FIND_ORDER_ERROR);
  3554 + }
  3555 + //清缓存
  3556 + clearShareOrderRedis(uid);
  3557 +
  3558 + // 发送取现mq给erp SETTLEMENT_TOPIC
  3559 + ShareSettlementBo bo = new ShareSettlementBo();
  3560 + BeanUtils.copyProperties(unionShareSettlement,bo);
  3561 + bo.setOrderCodes(orderCodes);
  3562 + bo.setOrderList(orderList);
  3563 + bo.setActivities(activityBos);
  3564 + mqLog.info("sendSettlementMqToErp,send mq {} to erp,uid is {},settlementCode is {},bo is {}", SETTLEMENT_TOPIC, uid, settlementCode, JsonUtil.objectToJSON(bo));
  3565 + yhProducer.send(SETTLEMENT_TOPIC, bo);
  3566 + settlementLog.info("sendSettlementMqToErp,send mq {} to erp success,uid is {},settlementCode is {},bo is {}", SETTLEMENT_TOPIC, uid, settlementCode, bo);
  3567 + return count;
  3568 + }
  3569 +
3507 //扣税金额计算,保留两位小数,多余位舍弃 3570 //扣税金额计算,保留两位小数,多余位舍弃
3508 private BigDecimal getTaxAmount(BigDecimal amount) { 3571 private BigDecimal getTaxAmount(BigDecimal amount) {
3509 // 假设佣金为X 3572 // 假设佣金为X