|
@@ -1,14 +1,26 @@
|
|
|
package com.izouma.nineth.service;
|
|
package com.izouma.nineth.service;
|
|
|
|
|
|
|
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
|
|
+import com.aliyuncs.CommonRequest;
|
|
|
|
|
+import com.aliyuncs.CommonResponse;
|
|
|
|
|
+import com.aliyuncs.DefaultAcsClient;
|
|
|
|
|
+import com.aliyuncs.IAcsClient;
|
|
|
|
|
+import com.aliyuncs.http.MethodType;
|
|
|
|
|
+import com.aliyuncs.profile.DefaultProfile;
|
|
|
import com.izouma.nineth.annotations.RedisLock;
|
|
import com.izouma.nineth.annotations.RedisLock;
|
|
|
import com.izouma.nineth.config.GeneralProperties;
|
|
import com.izouma.nineth.config.GeneralProperties;
|
|
|
|
|
+import com.izouma.nineth.enums.WithdrawStatus;
|
|
|
|
|
+import com.izouma.nineth.repo.WithdrawApplyRepo;
|
|
|
import com.izouma.nineth.utils.DateTimeUtils;
|
|
import com.izouma.nineth.utils.DateTimeUtils;
|
|
|
import lombok.AllArgsConstructor;
|
|
import lombok.AllArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
|
|
|
|
+import org.springframework.core.env.Environment;
|
|
|
import org.springframework.scheduling.annotation.Scheduled;
|
|
import org.springframework.scheduling.annotation.Scheduled;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
|
|
+import java.math.BigDecimal;
|
|
|
import java.time.LocalDate;
|
|
import java.time.LocalDate;
|
|
|
import java.util.concurrent.ExecutionException;
|
|
import java.util.concurrent.ExecutionException;
|
|
|
import java.util.concurrent.TimeUnit;
|
|
import java.util.concurrent.TimeUnit;
|
|
@@ -22,6 +34,9 @@ public class WithdrawApplyScheduleService {
|
|
|
private SysConfigService sysConfigService;
|
|
private SysConfigService sysConfigService;
|
|
|
private WithdrawApplyService withdrawApplyService;
|
|
private WithdrawApplyService withdrawApplyService;
|
|
|
private GeneralProperties generalProperties;
|
|
private GeneralProperties generalProperties;
|
|
|
|
|
+ private SandPayService sandPayService;
|
|
|
|
|
+ private WithdrawApplyRepo withdrawApplyRepo;
|
|
|
|
|
+ private Environment env;
|
|
|
|
|
|
|
|
|
|
|
|
|
@Scheduled(cron = "0 0 8 * * ?")
|
|
@Scheduled(cron = "0 0 8 * * ?")
|
|
@@ -43,4 +58,46 @@ public class WithdrawApplyScheduleService {
|
|
|
withdrawApplyService.approveAll();
|
|
withdrawApplyService.approveAll();
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ @Scheduled(cron = "0 0 10 * * ?")
|
|
|
|
|
+ @RedisLock(value = "'scheduleCheckBalance'", expire = 1, unit = TimeUnit.HOURS)
|
|
|
|
|
+ public void scheduleCheckBalance() throws ExecutionException, InterruptedException {
|
|
|
|
|
+ if (DateTimeUtils.isWorkDay(LocalDate.now())) {
|
|
|
|
|
+ String phone = sysConfigService.getString("finance_phone");
|
|
|
|
|
+ withdrawApplyService.approveAll();
|
|
|
|
|
+ BigDecimal balance = sandPayService.balance();
|
|
|
|
|
+ BigDecimal total = withdrawApplyRepo.findByCreatedAtBeforeAndStatus(LocalDate.now().atStartOfDay(),
|
|
|
|
|
+ WithdrawStatus.PENDING).stream().reduce(BigDecimal.ZERO, (a, b) -> a.add(b.getAmount()), BigDecimal::add);
|
|
|
|
|
+ if (balance.compareTo(total) < 0) {
|
|
|
|
|
+ log.error("余额不足,余额:{},待提现:{}", balance, total);
|
|
|
|
|
+ DefaultProfile profile = DefaultProfile.getProfile("cn-shenzhen", env.getProperty("aliyun.access-key-id"), env.getProperty("aliyun.access-key-secret"));
|
|
|
|
|
+ IAcsClient client = new DefaultAcsClient(profile);
|
|
|
|
|
+
|
|
|
|
|
+ CommonRequest request = new CommonRequest();
|
|
|
|
|
+ request.setMethod(MethodType.POST);
|
|
|
|
|
+ request.setDomain("dysmsapi.aliyuncs.com");
|
|
|
|
|
+ request.setVersion("2017-05-25");
|
|
|
|
|
+ request.setAction("SendSms");
|
|
|
|
|
+ request.putQueryParameter("PhoneNumbers", phone);
|
|
|
|
|
+ request.putQueryParameter("SignName", "RAEX绿洲宇宙");
|
|
|
|
|
+ request.putQueryParameter("TemplateCode", "SMS_268505729");
|
|
|
|
|
+ request.putQueryParameter("TemplateParam", "{\"total\":\"" + total + "\",\"balance\":\"" + balance + "\"}");
|
|
|
|
|
+ try {
|
|
|
|
|
+ CommonResponse response = client.getCommonResponse(request);
|
|
|
|
|
+ if (response.getHttpStatus() != 200) {
|
|
|
|
|
+ log.error("发送失败," + response.getHttpStatus() + "," + response.getData());
|
|
|
|
|
+ }
|
|
|
|
|
+ log.info("send sms response {}", response.getData());
|
|
|
|
|
+ JSONObject jsonObject = JSON.parseObject(response.getData());
|
|
|
|
|
+ if (!"ok".equalsIgnoreCase(jsonObject.getString("Code"))) {
|
|
|
|
|
+ log.error("发送失败," + jsonObject.getString("Message"));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ e.printStackTrace();
|
|
|
|
|
+ log.error("发送失败," + e.getMessage());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|