Просмотр исходного кода

提现失败自动补偿一次

wujiefeng 9 месяцев назад
Родитель
Сommit
e05edcab97

+ 5 - 2
RewardServer/src/main/java/com/zhongshu/reward/server/core/controller/TestController.java

@@ -16,6 +16,9 @@ import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 
+import java.time.LocalDate;
+import java.util.Calendar;
+
 /**
  * @author wjf
  * @date 2024/8/16
@@ -44,8 +47,8 @@ public class TestController {
 
     @ApiOperation("结算奖励")
     @PostMapping("settle")
-    public Object settle(){
-        walletReceiptsService.settle();
+    public Object settle(Integer day){
+        walletReceiptsService.settle(day);
         return ResultContent.buildSuccess();
     }
 

+ 3 - 1
RewardServer/src/main/java/com/zhongshu/reward/server/core/dao/Impl/WalletReceiptsDaoImpl.java

@@ -44,7 +44,7 @@ public class WalletReceiptsDaoImpl implements WalletReceiptsDaoExtend {
     }
 
     @Override
-    public List<WalletReceipts> listMonth(Long startTime, Long endTime) {
+    public List<WalletReceipts> listMonth(Long startTime, Long endTime, List<String> setMealCodeList) {
         Criteria criteria = new Criteria();
         criteria.andOperator(Criteria.where("createTime").gte(startTime),Criteria.where("createTime").lte(endTime));
 
@@ -54,6 +54,7 @@ public class WalletReceiptsDaoImpl implements WalletReceiptsDaoExtend {
 
         criteria.and("receiptsType").is(ReceiptsType.COMMISSION);
         criteria.and("status").is(ReceiptsStatus.WAIT);
+        criteria.and("outTradeNo").in(setMealCodeList);
         Query query = Query.query(criteria);
         query.with(Sort.by(Sort.Order.desc("createTime")));
 
@@ -65,6 +66,7 @@ public class WalletReceiptsDaoImpl implements WalletReceiptsDaoExtend {
         Criteria criteria = new Criteria();
         criteria.and("inviteUserId").is(userId);
         criteria.and("status").in(List.of(ReceiptsStatus.WAIT, ReceiptsStatus.RECEIPTS));
+        criteria.and("receiptsType").is(ReceiptsType.COMMISSION);
 
         Aggregation aggregation = Aggregation.newAggregation(
                 Aggregation.match(criteria),

+ 1 - 1
RewardServer/src/main/java/com/zhongshu/reward/server/core/dao/extend/WalletReceiptsDaoExtend.java

@@ -13,7 +13,7 @@ public interface WalletReceiptsDaoExtend {
 
     List<WalletReceipts> inviteDetail(String inviteUserId, Long startTime, Long endTime);
 
-    List<WalletReceipts> listMonth(Long startTime, Long endTime);
+    List<WalletReceipts> listMonth(Long startTime, Long endTime, List<String> setMealCodeList);
 
     List<InviteSuccessModel> myInvite(String userId);
 

+ 8 - 3
RewardServer/src/main/java/com/zhongshu/reward/server/core/service/WalletReceiptsService.java

@@ -126,13 +126,18 @@ public class WalletReceiptsService {
     /**
      * 结算
      */
-    public void settle(){
+    public void settle(Integer day){
 
-//        inviteReceiptsRoleFeignService.li()
+        com.zswl.cloud.bdb.client.ret.ResultContent<List<InviteReceiptsRoleVo>> listResultContent = inviteReceiptsRoleFeignService.listByDay(day);
+        if (listResultContent.getState().equals(com.zswl.cloud.bdb.client.ret.ResultState.Fail)){
+            return;
+        }
+        List<InviteReceiptsRoleVo> rulerList = listResultContent.getContent();
+        List<String> setMealCodeList = rulerList.stream().map(InviteReceiptsRoleVo::getSetMealCode).collect(Collectors.toList());
 
         Long startTime = DateUtils.lastMonthStartTime();
         Long endTime = DateUtils.lastMonthEndTime();
-        List<WalletReceipts> list = walletReceiptsDao.listMonth(startTime, endTime);
+        List<WalletReceipts> list = walletReceiptsDao.listMonth(startTime, endTime, setMealCodeList);
 
         List<WalletReceipts> receipts = new ArrayList<>();
         List<Wallet> wallets = new ArrayList<>();

+ 12 - 3
RewardServer/src/main/java/com/zhongshu/reward/server/core/timer/WalletTimer.java

@@ -7,11 +7,13 @@ import com.zhongshu.reward.server.core.dao.WxTransferBatchDao;
 import com.zhongshu.reward.server.core.domain.WxTransferBatch;
 import com.zhongshu.reward.server.core.service.WalletReceiptsService;
 import com.zhongshu.reward.server.core.service.WxTransferService;
+import com.zhongshu.reward.server.core.util.DateUtils;
 import lombok.extern.log4j.Log4j2;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.scheduling.annotation.Scheduled;
 import org.springframework.stereotype.Component;
 
+import java.time.LocalDate;
 import java.util.List;
 
 /**
@@ -58,10 +60,17 @@ public class WalletTimer {
         }
     }
 
-    @Scheduled(cron = "0 0 0 25 * ?")
+    @Scheduled(cron = "0 0 1 * * ?")
     public void settle(){
         try {
-            walletReceiptsService.settle();
+            LocalDate now = LocalDate.now();
+
+            if (DateUtils.checkLastDayOfMonth() &&  now.getMonthValue() == 2){
+                for (int i = now.getDayOfMonth(); i <= 31; i++) {
+                    walletReceiptsService.settle(i);
+                }
+            }
+            walletReceiptsService.settle(now.getDayOfMonth());
         }catch (Exception e){
             e.printStackTrace();
         }
@@ -70,7 +79,7 @@ public class WalletTimer {
     @Scheduled(cron = "0 0 0 1 * ?")
     public void autoReceipts(){
         try {
-            walletReceiptsService.settle();
+            walletReceiptsService.autoReceipts();
         }catch (Exception e){
             e.printStackTrace();
         }

+ 12 - 0
RewardServer/src/main/java/com/zhongshu/reward/server/core/util/DateUtils.java

@@ -34,6 +34,18 @@ public class DateUtils {
         }
         return null;
     }
+    /**
+     * 判断当日是否当月最后一天
+     */
+    public static boolean checkLastDayOfMonth(){
+        Calendar calendar = Calendar.getInstance();
+        int today = calendar.get(Calendar.DATE);
+        calendar.set(Calendar.DATE, 1);
+        calendar.add(Calendar.MONTH, 1);
+        calendar.set(Calendar.DATE, 1);
+        int lastDay = calendar.get(Calendar.DATE);
+        return today == lastDay;
+    }
 
 
     /**