Browse Source

测试持续返利

wujiefeng 9 months ago
parent
commit
cba43c2de1

+ 30 - 6
RewardServer/src/main/java/com/zhongshu/reward/server/core/controller/TestController.java

@@ -9,15 +9,13 @@ import com.zhongshu.reward.server.core.domain.WalletReceipts;
 import com.zhongshu.reward.server.core.service.Impl.InviteRecordFeignServiceImpl;
 import com.zhongshu.reward.server.core.service.WalletReceiptsService;
 import com.zhongshu.reward.server.core.util.DateUtils;
-import com.zhongshu.vip.client.model.param.VipUserParam;
-import com.zswl.cloud.bdb.client.vo.InviteReceiptsRoleVo;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import lombok.extern.slf4j.Slf4j;
-import org.apache.commons.lang3.ObjectUtils;
-import org.springframework.beans.BeanUtils;
+
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
+import redis.clients.jedis.Jedis;
 
 import java.time.LocalDate;
 import java.util.Calendar;
@@ -126,8 +124,34 @@ public class TestController {
 
     @ApiOperation("生成持续订购返利")
     @PostMapping("autoReceipts")
-    public Object autoReceipts(){
-        walletReceiptsService.autoReceipts();
+    public Object autoReceipts(@RequestParam("month") Integer month){
+
+        walletReceiptsService.testAutoReceipts(month);
         return ResultContent.buildSuccess();
     }
+
+
+
+
+//    @PostMapping("testLock")
+//    public void testLock(){
+//        boolean lock = jedisUtil.lock("user_1001", 1000);
+////        RedisDistributedLock lock = new RedisDistributedLock(jedis, "user_1001", 1000);
+//
+//        try {
+//            if (lock) {
+//                // 执行业务逻辑
+//                System.out.println("执行业务逻辑...");
+//                // 模拟耗时操作
+//                Thread.sleep(2000);
+//            } else {
+//                System.out.println("未获取到锁,其他实例可能正在操作...");
+//            }
+//        } catch (InterruptedException e) {
+//            e.printStackTrace();
+//        } finally {
+//            jedisUtil.unlock("user_1001");
+////            jedisUtil.del()
+//        }
+//    }
 }

+ 36 - 0
RewardServer/src/main/java/com/zhongshu/reward/server/core/service/WalletReceiptsService.java

@@ -176,6 +176,42 @@ public class WalletReceiptsService {
 //        walletReceiptsDao.saveAll(receipts);
 
     }
+    public void testAutoReceipts(Integer month){
+        //获取设置持续订购返利的套餐规则
+        com.zswl.cloud.bdb.client.ret.ResultContent<List<InviteReceiptsRoleVo>> rulerResult = inviteReceiptsRoleFeignService.listKeep();
+        if (rulerResult.getState().equals(com.zswl.cloud.bdb.client.ret.ResultState.Success)){
+            List<InviteReceiptsRoleVo> rulerList = rulerResult.getContent();
+            if (rulerList.isEmpty()){
+                return;
+            }
+            List<String> setMealCodeList = rulerList.stream().map(InviteReceiptsRoleVo::getSetMealCode).collect(Collectors.toList());
+
+            //获取上月所有入帐单(待结算和已结算的)
+            Long startTime = DateUtils.getMonthStartTime(2024, month);
+            Long endTime = DateUtils.getMonthEndTime(2024, month);
+            List<WalletReceipts> walletReceiptsList = walletReceiptsDao.listMonthBySetMealCode(startTime, endTime, setMealCodeList);
+            if (walletReceiptsList.isEmpty()){
+                return;
+            }
+
+            rulerList.forEach(ruler->{
+                walletReceiptsList.forEach(walletReceipts -> {
+                    //匹配规则
+                    if (walletReceipts.getOutTradeNo().equals(ruler.getSetMealCode())){
+                        //上月最新消息
+                        VipUserRecord topOne = vipUserRecordDao.findTopOneByOperateTime(walletReceipts.getUserId(), startTime, endTime);
+                        if (Objects.isNull(topOne)){
+                            //上月无消息,生成入账
+                            insertReceipts(ruler, walletReceipts);
+                        }else if (topOne.getSuc().equals(1) || topOne.getSuc().equals(4)){
+                            //上月最后消息为订购,生成入账
+                            insertReceipts(ruler, walletReceipts);
+                        }
+                    }
+                });
+            });
+        }
+    }
 
     public void autoReceipts(){
         //获取设置持续订购返利的套餐规则