补偿提现定时器
This commit is contained in:
parent
2e5ff5096c
commit
d9e2a782ac
|
|
@ -3,10 +3,14 @@ package com.ghy.web.timer;
|
||||||
import com.alibaba.fastjson.JSONArray;
|
import com.alibaba.fastjson.JSONArray;
|
||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
import com.ghy.common.adapay.model.AdapayStatusEnum;
|
import com.ghy.common.adapay.model.AdapayStatusEnum;
|
||||||
|
import com.ghy.common.enums.AdapayOrderType;
|
||||||
|
import com.ghy.common.utils.AdapayUtils;
|
||||||
import com.ghy.order.service.OrderDetailService;
|
import com.ghy.order.service.OrderDetailService;
|
||||||
import com.ghy.payment.domain.DrawCashRecord;
|
import com.ghy.payment.domain.DrawCashRecord;
|
||||||
import com.ghy.payment.mapper.DrawCashRecordMapper;
|
import com.ghy.payment.mapper.DrawCashRecordMapper;
|
||||||
import com.ghy.payment.service.AdapayService;
|
import com.ghy.payment.service.AdapayService;
|
||||||
|
import com.ghy.worker.domain.WorkerBank;
|
||||||
|
import com.ghy.worker.service.WorkerBankService;
|
||||||
import com.huifu.adapay.core.exception.BaseAdaPayException;
|
import com.huifu.adapay.core.exception.BaseAdaPayException;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
@ -17,6 +21,7 @@ import org.springframework.transaction.annotation.Transactional;
|
||||||
import org.springframework.util.CollectionUtils;
|
import org.springframework.util.CollectionUtils;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
|
import java.math.BigDecimal;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
|
@ -32,10 +37,46 @@ public class AdapaySyncTimer {
|
||||||
@Resource
|
@Resource
|
||||||
private AdapayService adapayService;
|
private AdapayService adapayService;
|
||||||
@Resource
|
@Resource
|
||||||
|
private WorkerBankService workerBankService;
|
||||||
|
@Resource
|
||||||
private OrderDetailService orderDetailService;
|
private OrderDetailService orderDetailService;
|
||||||
@Resource
|
@Resource
|
||||||
private DrawCashRecordMapper drawCashRecordMapper;
|
private DrawCashRecordMapper drawCashRecordMapper;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 补偿提现定时器
|
||||||
|
* 某些订单分账成功,但是提现失败,需要在这里为它重新发起提现
|
||||||
|
*/
|
||||||
|
@Scheduled(fixedRate = 5 * 60 * 1000L)
|
||||||
|
public void autoDrawCash() {
|
||||||
|
List<WorkerBank> workerBanks = workerBankService.select(new WorkerBank());
|
||||||
|
for (WorkerBank workerBank : workerBanks) {
|
||||||
|
Long deptId = workerBank.getDeptId();
|
||||||
|
String memberId = workerBank.getAdapayMemberId();
|
||||||
|
String settleAccountId = workerBank.getSettleAccountId();
|
||||||
|
if (deptId == null || StringUtils.isBlank(memberId) || StringUtils.isBlank(settleAccountId)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
JSONObject accountBalance = adapayService.queryAccountBalance(deptId, memberId, settleAccountId, "01");
|
||||||
|
if (AdapayStatusEnum.succeeded.code.equals(accountBalance.getString("status"))) {
|
||||||
|
// 可提现金额
|
||||||
|
String avlBalance = accountBalance.getString("avl_balance");
|
||||||
|
if (BigDecimal.ZERO.compareTo(new BigDecimal(avlBalance)) > -1) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
// 提现
|
||||||
|
log.info("Worker[{},{}]开始提现: avlBalance={}", workerBank.getWorkerId(), workerBank.getName(), avlBalance);
|
||||||
|
String orderNo = AdapayUtils.createOrderNo(AdapayOrderType.DRAW_CASH);
|
||||||
|
JSONObject drawCash = adapayService.drawCash(deptId, orderNo, "T1", avlBalance, memberId, "提现", null);
|
||||||
|
log.info("Worker[{},{}]提现结果: {}", workerBank.getWorkerId(), workerBank.getName(), drawCash.toJSONString());
|
||||||
|
}
|
||||||
|
} catch (BaseAdaPayException e) {
|
||||||
|
log.error(e.getMessage(), e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Scheduled(fixedRate = 5 * 60 * 1000L)
|
@Scheduled(fixedRate = 5 * 60 * 1000L)
|
||||||
public void syncDrawCash() {
|
public void syncDrawCash() {
|
||||||
List<DrawCashRecord> records = drawCashRecordMapper.selectByStatus("pending");
|
List<DrawCashRecord> records = drawCashRecordMapper.selectByStatus("pending");
|
||||||
|
|
|
||||||
|
|
@ -32,4 +32,6 @@ public interface WorkerBankMapper {
|
||||||
List<WorkerBank> getByWorkerIds(@Param("ids") String ids);
|
List<WorkerBank> getByWorkerIds(@Param("ids") String ids);
|
||||||
|
|
||||||
WorkerBank getByMemberId(String memberId);
|
WorkerBank getByMemberId(String memberId);
|
||||||
|
|
||||||
|
List<WorkerBank> select(WorkerBank workerBank);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -32,4 +32,5 @@ public interface WorkerBankService {
|
||||||
*/
|
*/
|
||||||
List<WorkerBank> getByWorkerIds(String ids);
|
List<WorkerBank> getByWorkerIds(String ids);
|
||||||
|
|
||||||
|
List<WorkerBank> select(WorkerBank workerBank);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -40,4 +40,9 @@ public class WorkerBankServiceImpl implements WorkerBankService {
|
||||||
public List<WorkerBank> getByWorkerIds(String ids) {
|
public List<WorkerBank> getByWorkerIds(String ids) {
|
||||||
return workerBankMapper.getByWorkerIds(ids);
|
return workerBankMapper.getByWorkerIds(ids);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<WorkerBank> select(WorkerBank workerBank) {
|
||||||
|
return workerBankMapper.select(workerBank);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -80,24 +80,14 @@
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
<select id="getByWorkerIds" resultMap="WorkerBankResult">
|
<select id="getByWorkerIds" resultMap="WorkerBankResult">
|
||||||
SELECT * FROM worker_bank
|
SELECT *
|
||||||
|
FROM worker_bank
|
||||||
WHERE worker_id in (#{ids})
|
WHERE worker_id in (#{ids})
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
<!-- <select id="getWorkerTeamList" resultMap="WorkerTeamResult">-->
|
<select id="select" resultMap="WorkerBankResult">
|
||||||
<!-- <include refid="selectWorkerTeam"/>-->
|
SELECT *
|
||||||
<!-- <where>-->
|
FROM worker_bank
|
||||||
<!-- <if test="leaderId != null and leaderId != ''">-->
|
</select>
|
||||||
<!-- AND leader_id = #{leaderId}-->
|
|
||||||
<!-- </if>-->
|
|
||||||
<!-- </where>-->
|
|
||||||
<!-- </select>-->
|
|
||||||
|
|
||||||
<!-- <delete id="deleteWorkerTeamByIds" parameterType="Long">-->
|
|
||||||
<!-- DELETE FROM worker_team WHERE worker_team_id IN-->
|
|
||||||
<!-- <foreach collection="array" item="workerTeamId" open="(" separator="," close=")">-->
|
|
||||||
<!-- #{workerTeamId}-->
|
|
||||||
<!-- </foreach>-->
|
|
||||||
<!-- </delete>-->
|
|
||||||
|
|
||||||
</mapper>
|
</mapper>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue