支持批量支付

20240115-ljl-multiPay
ljl 10 months ago
parent 9e59593d2b
commit 647622edc1

@ -478,29 +478,34 @@ public class DistributionOrderServiceImpl implements DistributionOrderService {
@Override
public void batchPay(BatchPayParam param, BatchPayData data) {
if (param.getParams().size() != 1) {
throw new RuntimeException("每次只能请求1个采购单");
List<String> purOrderIds = new ArrayList<>();
for (BatchPayParam.Param payParam: param.getParams()) {
purOrderIds.add(payParam.getPurOrderId());
}
String purOrderId = param.getParams().get(0).getPurOrderId();
PlatformPurchaseOrder platformPurchaseOrder = platformPurchaseOrderMapper.selectByPrimaryKey(param.getParams().get(0).getPurOrderId());
if (platformPurchaseOrder == null) {
List<PlatformPurchaseOrder> platformPurchaseOrders = platformPurchaseOrderMapper.getListByPurOrderIds(purOrderIds);
if (platformPurchaseOrders.isEmpty()) {
throw new RuntimeException("采购单不存在");
}
PurchaseOrder purchaseOrder = purchaseOrderMapper.getByPurOrderId(purOrderId);
List<PurchaseOrder> purchaseOrders = purchaseOrderMapper.getListByPurOrderIds(purOrderIds);
List<String> sourceOrderIds = new ArrayList<>();
for (PurchaseOrder purchaseOrder: purchaseOrders) {
sourceOrderIds.add(purchaseOrder.getPurchaseOrderSn());
}
Long shopId = param.getParams().get(0).getShopId();
GetPurchaseOrderPayUrlResponseDTO response1 = dsApiService.getPurchaseOrderPayUrl(shopId, sourceOrderIds, "PC");
GetPurchaseOrderPayUrlResponseDTO response2 = dsApiService.getPurchaseOrderPayUrl(shopId, sourceOrderIds, "WIRELESS");
if (!response1.isSuccess()) {
throw new RuntimeException(response1.getReason());
}
if (!response2.isSuccess()) {
throw new RuntimeException(response2.getReason());
}
List<PaymentResult> paymentResults = new ArrayList<>();
for (BatchPayParam.Param p: param.getParams()) {
List<String> sourceOrderIds = Collections.singletonList(purchaseOrder.getPurchaseOrderSn());
GetPurchaseOrderPayUrlResponseDTO response1 = dsApiService.getPurchaseOrderPayUrl(p.getShopId(), sourceOrderIds, "PC");
GetPurchaseOrderPayUrlResponseDTO response2 = dsApiService.getPurchaseOrderPayUrl(p.getShopId(), sourceOrderIds, "WIRELESS");
if (!response1.isSuccess()) {
throw new RuntimeException(response1.getReason());
}
if (!response2.isSuccess()) {
throw new RuntimeException(response2.getReason());
}
PaymentResult paymentResult = new PaymentResult();
PaymentResult.PayUrl payUrl = new PaymentResult.PayUrl();
@ -510,11 +515,8 @@ public class DistributionOrderServiceImpl implements DistributionOrderService {
paymentResult.setPayUrl(payUrl);
paymentResult.setPurOrderId(p.getPurOrderId());
paymentResults.add(paymentResult);
platformPurchaseOrder.setPayPcUrl(response1.getPayUrl());
platformPurchaseOrder.setPayH5Url(response2.getPayUrl());
platformPurchaseOrderMapper.updateByPrimaryKeySelective(platformPurchaseOrder);
}
platformPurchaseOrderMapper.updatePayUrlByPurOrderIds(response1.getPayUrl(), response2.getPayUrl(), purOrderIds);
data.setPaymentResults(paymentResults);
}

@ -27,4 +27,6 @@ public interface PlatformPurchaseOrderMapper {
int updateByPrimaryKey(PlatformPurchaseOrder record);
List<PlatformPurchaseOrder> getListByPurOrderIds(@Param("purOrderIds") List<String> purOrderIds);
int updatePayUrlByPurOrderIds(@Param("payPcUrl") String payPcUrl, @Param("payH5Url") String payH5Url, @Param("purOrderIds") List<String> purOrderIds);
}

@ -32,4 +32,6 @@ public interface PurchaseOrderMapper {
PurchaseOrder getByPurchaseOrderSn(@Param("purchaseOrderSn") String purchaseOrderSn);
PurchaseOrder getByPurOrderId(@Param("purOrderId") String purOrderId);
List<PurchaseOrder> getListByPurOrderIds(@Param("purOrderIds") List<String> purOrderIds);
}

@ -234,4 +234,23 @@
gmt_modified = #{gmtModified,jdbcType=TIMESTAMP}
where pur_order_id = #{purOrderId,jdbcType=VARCHAR}
</update>
<update id="updatePayUrlByPurOrderIds">
update platform_purchase_order
set
pay_h5_url = #{payH5Url,jdbcType=VARCHAR},
pay_pc_url = #{payPcUrl,jdbcType=VARCHAR},
gmt_modified = #{gmtModified,jdbcType=TIMESTAMP}
where 1=1
<choose>
<when test="purOrderIds!=null and purOrderIds.size>0">
and pur_order_id in
<foreach collection="purOrderIds" index="index" item="item" open="(" separator="," close=")">
#{item}
</foreach>
</when>
<otherwise>
AND 1=0
</otherwise>
</choose>
</update>
</mapper>

@ -56,6 +56,23 @@
from purchase_order
where pur_order_id = #{purOrderId,jdbcType=VARCHAR}
</select>
<select id="getListByPurOrderIds" resultType="com.ms.dal.entity.PurchaseOrder">
select
<include refid="Base_Column_List" />
from purchase_order
where 1=1
<choose>
<when test="purOrderIds!=null and purOrderIds.size>0">
and pur_order_id in
<foreach collection="purOrderIds" index="index" item="item" open="(" separator="," close=")">
#{item}
</foreach>
</when>
<otherwise>
AND 1=0
</otherwise>
</choose>
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Long">
delete from purchase_order

Loading…
Cancel
Save