补偿提现定时器
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.JSONObject;
|
||||
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.payment.domain.DrawCashRecord;
|
||||
import com.ghy.payment.mapper.DrawCashRecordMapper;
|
||||
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 lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
|
@ -17,6 +21,7 @@ import org.springframework.transaction.annotation.Transactional;
|
|||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
|
|
@ -32,10 +37,46 @@ public class AdapaySyncTimer {
|
|||
@Resource
|
||||
private AdapayService adapayService;
|
||||
@Resource
|
||||
private WorkerBankService workerBankService;
|
||||
@Resource
|
||||
private OrderDetailService orderDetailService;
|
||||
@Resource
|
||||
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)
|
||||
public void syncDrawCash() {
|
||||
List<DrawCashRecord> records = drawCashRecordMapper.selectByStatus("pending");
|
||||
|
|
|
|||
|
|
@ -32,4 +32,6 @@ public interface WorkerBankMapper {
|
|||
List<WorkerBank> getByWorkerIds(@Param("ids") String ids);
|
||||
|
||||
WorkerBank getByMemberId(String memberId);
|
||||
|
||||
List<WorkerBank> select(WorkerBank workerBank);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,4 +32,5 @@ public interface WorkerBankService {
|
|||
*/
|
||||
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) {
|
||||
return workerBankMapper.getByWorkerIds(ids);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<WorkerBank> select(WorkerBank workerBank) {
|
||||
return workerBankMapper.select(workerBank);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,22 +3,22 @@
|
|||
<mapper namespace="com.ghy.worker.mapper.WorkerBankMapper">
|
||||
|
||||
<resultMap id="WorkerBankResult" type="com.ghy.worker.domain.WorkerBank">
|
||||
<result property="workerBankId" column="worker_bank_id"/>
|
||||
<result property="settleAccountId" column="settle_account_id"/>
|
||||
<result property="workerId" column="worker_id"/>
|
||||
<result property="name" column="name"/>
|
||||
<result property="certId" column="cert_id"/>
|
||||
<result property="bankName" column="bank_name"/>
|
||||
<result property="bankNum" column="bank_num"/>
|
||||
<result property="phone" column="phone"/>
|
||||
<result property="deptId" column="dept_id"/>
|
||||
<result property="adapayMemberId" column="adapay_member_id"/>
|
||||
<result property="settleAccount" column="settle_account"/>
|
||||
<result property="createBy" column="create_by"/>
|
||||
<result property="createTime" column="create_time"/>
|
||||
<result property="updateBy" column="update_by"/>
|
||||
<result property="updateTime" column="update_time"/>
|
||||
<result property="remark" column="remark"/>
|
||||
<result property="workerBankId" column="worker_bank_id"/>
|
||||
<result property="settleAccountId" column="settle_account_id"/>
|
||||
<result property="workerId" column="worker_id"/>
|
||||
<result property="name" column="name"/>
|
||||
<result property="certId" column="cert_id"/>
|
||||
<result property="bankName" column="bank_name"/>
|
||||
<result property="bankNum" column="bank_num"/>
|
||||
<result property="phone" column="phone"/>
|
||||
<result property="deptId" column="dept_id"/>
|
||||
<result property="adapayMemberId" column="adapay_member_id"/>
|
||||
<result property="settleAccount" column="settle_account"/>
|
||||
<result property="createBy" column="create_by"/>
|
||||
<result property="createTime" column="create_time"/>
|
||||
<result property="updateBy" column="update_by"/>
|
||||
<result property="updateTime" column="update_time"/>
|
||||
<result property="remark" column="remark"/>
|
||||
</resultMap>
|
||||
|
||||
<insert id="insertWorkerBank" parameterType="com.ghy.worker.domain.WorkerBank" useGeneratedKeys="true"
|
||||
|
|
@ -56,8 +56,8 @@
|
|||
UPDATE worker_bank
|
||||
<set>
|
||||
<if test="phone != null and phone != ''">phone = #{phone},</if>
|
||||
<if test="bankNum != null and bankNum != ''">bank_num = #{bankNum},</if>
|
||||
<if test="settleAccountId != null and settleAccountId != ''">settle_account_id = #{settleAccountId},</if>
|
||||
<if test="bankNum != null and bankNum != ''">bank_num = #{bankNum},</if>
|
||||
<if test="settleAccountId != null and settleAccountId != ''">settle_account_id = #{settleAccountId},</if>
|
||||
update_time = NOW()
|
||||
</set>
|
||||
WHERE adapay_member_id = #{adapayMemberId}
|
||||
|
|
@ -80,24 +80,14 @@
|
|||
</select>
|
||||
|
||||
<select id="getByWorkerIds" resultMap="WorkerBankResult">
|
||||
SELECT * FROM worker_bank
|
||||
WHERE worker_id in ( #{ids} )
|
||||
SELECT *
|
||||
FROM worker_bank
|
||||
WHERE worker_id in (#{ids})
|
||||
</select>
|
||||
|
||||
<!-- <select id="getWorkerTeamList" resultMap="WorkerTeamResult">-->
|
||||
<!-- <include refid="selectWorkerTeam"/>-->
|
||||
<!-- <where>-->
|
||||
<!-- <if test="leaderId != null and leaderId != ''">-->
|
||||
<!-- 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>-->
|
||||
<select id="select" resultMap="WorkerBankResult">
|
||||
SELECT *
|
||||
FROM worker_bank
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
|
|
|
|||
Loading…
Reference in New Issue