Prechádzať zdrojové kódy

Merge branch 'dev' of http://git.izouma.com/xiongzhu/raex_back into dev

wangqifan 3 rokov pred
rodič
commit
525115b8bf

+ 8 - 0
src/main/java/com/izouma/nineth/service/SysConfigService.java

@@ -267,6 +267,14 @@ public class SysConfigService {
                     .value("5")
                     .build());
         }
+        if (list.stream().noneMatch(i -> i.getName().equals("finance_phone"))) {
+            sysConfigRepo.save(SysConfig.builder()
+                    .name("finance_phone")
+                    .desc("财务通知手机号")
+                    .type(SysConfig.ValueType.STRING)
+                    .value("15077886171")
+                    .build());
+        }
         SearchMode searchMode = SearchMode.valueOf(sysConfigRepo.findByName("default_search_mode").get().getValue());
         JpaUtils.setDefaultSearchMode(searchMode);
 

+ 57 - 0
src/main/java/com/izouma/nineth/service/WithdrawApplyScheduleService.java

@@ -1,14 +1,26 @@
 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.config.GeneralProperties;
+import com.izouma.nineth.enums.WithdrawStatus;
+import com.izouma.nineth.repo.WithdrawApplyRepo;
 import com.izouma.nineth.utils.DateTimeUtils;
 import lombok.AllArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
+import org.springframework.core.env.Environment;
 import org.springframework.scheduling.annotation.Scheduled;
 import org.springframework.stereotype.Service;
 
+import java.math.BigDecimal;
 import java.time.LocalDate;
 import java.util.concurrent.ExecutionException;
 import java.util.concurrent.TimeUnit;
@@ -22,6 +34,9 @@ public class WithdrawApplyScheduleService {
     private SysConfigService     sysConfigService;
     private WithdrawApplyService withdrawApplyService;
     private GeneralProperties    generalProperties;
+    private SandPayService       sandPayService;
+    private WithdrawApplyRepo    withdrawApplyRepo;
+    private Environment          env;
 
 
     @Scheduled(cron = "0 0 8 * * ?")
@@ -43,4 +58,46 @@ public class WithdrawApplyScheduleService {
             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());
+                }
+            }
+        }
+    }
 }