From 1d44c20eabc99e9970fb58d4dbd3a94d77e83e39 Mon Sep 17 00:00:00 2001
From: 无关风月 <443237572@qq.com>
Date: 星期五, 07 三月 2025 18:35:50 +0800
Subject: [PATCH] 冥想

---
 xinquan-modules/xinquan-user/src/main/java/com/xinquan/user/controller/client/ClientAppUserTreeController.java |  230 ++++++++++++++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 219 insertions(+), 11 deletions(-)

diff --git a/xinquan-modules/xinquan-user/src/main/java/com/xinquan/user/controller/client/ClientAppUserTreeController.java b/xinquan-modules/xinquan-user/src/main/java/com/xinquan/user/controller/client/ClientAppUserTreeController.java
index 6f2f983..0e3f8bd 100644
--- a/xinquan-modules/xinquan-user/src/main/java/com/xinquan/user/controller/client/ClientAppUserTreeController.java
+++ b/xinquan-modules/xinquan-user/src/main/java/com/xinquan/user/controller/client/ClientAppUserTreeController.java
@@ -32,6 +32,7 @@
 import org.springframework.web.bind.annotation.*;
 
 import javax.annotation.Resource;
+import java.time.LocalDate;
 import java.time.LocalDateTime;
 import java.time.LocalTime;
 import java.time.temporal.ChronoUnit;
@@ -151,7 +152,7 @@
                 } else {
                     appUserTree.setIsSign(2);
                 }
-                if (temp >= 120) {
+                if (temp >= 3600) {
                     if (appUserTree.getTaskOne() == 2) {
                         AppUserEnergyRecord appUserEnergyRecord = new AppUserEnergyRecord();
                         appUserEnergyRecord.setAppUserId(userId);
@@ -160,6 +161,8 @@
                         appUserEnergyRecord.setReason("完成【每日疗愈30分钟】任务");
                         appUserEnergyRecordService.save(appUserEnergyRecord);
                         byId.setTotalEnergyValue(byId.getTotalEnergyValue() + 10);
+                        byId.setEnergyValue(byId.getEnergyValue() + 10);
+
                     }
                     if (appUserTree.getTaskTwo() == 2) {
                         AppUserEnergyRecord appUserEnergyRecord = new AppUserEnergyRecord();
@@ -169,11 +172,12 @@
                         appUserEnergyRecord.setReason("完成【每日疗愈60分钟】任务");
                         appUserEnergyRecordService.save(appUserEnergyRecord);
                         byId.setTotalEnergyValue(byId.getTotalEnergyValue() + 20);
+                        byId.setEnergyValue(byId.getEnergyValue() + 20);
 
                     }
                     appUserTree.setTaskOne(1);
                     appUserTree.setTaskTwo(1);
-                } else if (temp >= 60) {
+                } else if (temp >= 1800) {
                     if (appUserTree.getTaskOne() == 2) {
                         AppUserEnergyRecord appUserEnergyRecord = new AppUserEnergyRecord();
                         appUserEnergyRecord.setAppUserId(userId);
@@ -182,9 +186,10 @@
                         appUserEnergyRecord.setReason("完成【每日疗愈30分钟】任务");
                         appUserEnergyRecordService.save(appUserEnergyRecord);
                         byId.setTotalEnergyValue(byId.getTotalEnergyValue() + 10);
+                        byId.setEnergyValue(byId.getEnergyValue() + 10);
                     }
-                    appUserTree.setTaskOne(1);
-                    appUserTree.setTaskTwo(2);
+                    appUserTree.setTaskOne(2);
+                    appUserTree.setTaskTwo(1);
                 } else {
                     appUserTree.setTaskOne(2);
                     appUserTree.setTaskTwo(2);
@@ -195,7 +200,7 @@
                 appUserTree.setTotalEnergyValue(byId.getTotalEnergyValue());
                 return R.ok(appUserTree);
             } else {
-                if (temp >= 120) {
+                if (temp >= 3600) {
                     if (one.getTaskOne() == 2) {
                         AppUserEnergyRecord appUserEnergyRecord = new AppUserEnergyRecord();
                         appUserEnergyRecord.setAppUserId(userId);
@@ -204,6 +209,9 @@
                         appUserEnergyRecord.setReason("完成【每日疗愈30分钟】任务");
                         appUserEnergyRecordService.save(appUserEnergyRecord);
                         byId.setTotalEnergyValue(byId.getTotalEnergyValue() + 10);
+                        one.setTaskOne(1);
+                        byId.setEnergyValue(byId.getEnergyValue() + 10);
+
                     }
                     if (one.getTaskTwo() == 2) {
                         AppUserEnergyRecord appUserEnergyRecord = new AppUserEnergyRecord();
@@ -213,11 +221,12 @@
                         appUserEnergyRecord.setReason("完成【每日疗愈60分钟】任务");
                         appUserEnergyRecordService.save(appUserEnergyRecord);
                         byId.setTotalEnergyValue(byId.getTotalEnergyValue() + 20);
+                        one.setTaskTwo(1);
+                        byId.setEnergyValue(byId.getEnergyValue() + 20);
 
                     }
-                    one.setTaskOne(1);
-                    one.setTaskTwo(1);
-                } else if (temp >= 60) {
+
+                } else if (temp >= 1800) {
                     if (one.getTaskOne() == 2) {
                         AppUserEnergyRecord appUserEnergyRecord = new AppUserEnergyRecord();
                         appUserEnergyRecord.setAppUserId(userId);
@@ -226,9 +235,9 @@
                         appUserEnergyRecord.setReason("完成【每日疗愈30分钟】任务");
                         appUserEnergyRecordService.save(appUserEnergyRecord);
                         byId.setTotalEnergyValue(byId.getTotalEnergyValue() + 10);
+                        one.setTaskOne(1);
+                        byId.setEnergyValue(byId.getEnergyValue() + 10);
                     }
-                    one.setTaskOne(1);
-                    one.setTaskTwo(2);
                 } else {
                     one.setTaskOne(2);
                     one.setTaskTwo(2);
@@ -281,6 +290,7 @@
                 one.setEnergyValue(byId.getEnergyValue());
                 appUserTreeService.updateById(one);
                 one.setTotalEnergyValue(byId.getTotalEnergyValue());
+                appUserService.updateById(byId);
                 return R.ok(one);
             }
         }else{
@@ -304,6 +314,190 @@
             appUserTree.setTotalEnergyValue(0);
             return R.ok(appUserTree);
         }
+    }
+
+    /**
+     * 刷新用户观看和任务完成记录
+     * @return
+     */
+    @PostMapping("/getUserEnergy/{id}")
+    public R getUserEnergy(@PathVariable("id")Long id) {
+            AppUser byId = appUserService.getById(id);
+            byId.setIsFirst(2);
+            appUserService.updateById(byId);
+            // 查询用户今日观看疗愈多少秒
+            LocalDateTime now = LocalDateTime.now();
+            LocalDateTime startOfDay = now.toLocalDate().atStartOfDay();
+            LocalDateTime endOfDay = now.toLocalDate().atTime(LocalTime.MAX);
+            List<AppUserViewingHistory> list = appUserViewingHistoryService
+                    .lambdaQuery().eq(AppUserViewingHistory::getAppUserId, id)
+                    .eq(AppUserViewingHistory::getViewingType, 1)
+                    .eq(BaseModel::getDelFlag, 0)
+                    .between(AppUserViewingHistory::getCreateTime, startOfDay, endOfDay).list();
+            int temp = 0;
+            for (AppUserViewingHistory appUserViewingHistory : list) {
+                if (appUserViewingHistory.getTimeLook()!=null){
+                    temp += appUserViewingHistory.getTimeLook();
+
+                }
+            }
+            AppUserTree one = appUserTreeService.lambdaQuery().eq(AppUserTree::getAppUserId, id)
+                    .eq(AppUserTree::getSowAgain, 2).one();
+            if (one == null) {
+                AppUserTree appUserTree = new AppUserTree();
+                appUserTree.setTime(LocalDateTime.now());
+                appUserTree.setAppUserId(id);
+                appUserTree.setTreeLevelType(1);
+                appUserTree.setGrowthValue(0);
+                appUserTree.setSowAgain(2);
+                appUserTree.setCreateTime(LocalDateTime.now());
+                // 如果用户的签到时间是今天 那么修改为已签到
+                if (byId.getSignTime() != null && byId.getSignTime().toLocalDate().equals(LocalDateTime.now().toLocalDate())) {
+                    appUserTree.setIsSign(1);
+                } else {
+                    appUserTree.setIsSign(2);
+                }
+                if (temp >= 3600) {
+                    if (appUserTree.getTaskOne() == 2) {
+                        AppUserEnergyRecord appUserEnergyRecord = new AppUserEnergyRecord();
+                        appUserEnergyRecord.setAppUserId(id);
+                        appUserEnergyRecord.setChangeType(1);
+                        appUserEnergyRecord.setEnergyValue(10);
+                        appUserEnergyRecord.setReason("完成【每日疗愈30分钟】任务");
+                        appUserEnergyRecordService.save(appUserEnergyRecord);
+                        byId.setTotalEnergyValue(byId.getTotalEnergyValue() + 10);
+                        byId.setEnergyValue(byId.getEnergyValue() + 10);
+
+                    }
+                    if (appUserTree.getTaskTwo() == 2) {
+                        AppUserEnergyRecord appUserEnergyRecord = new AppUserEnergyRecord();
+                        appUserEnergyRecord.setAppUserId(id);
+                        appUserEnergyRecord.setChangeType(1);
+                        appUserEnergyRecord.setEnergyValue(20);
+                        appUserEnergyRecord.setReason("完成【每日疗愈60分钟】任务");
+                        appUserEnergyRecordService.save(appUserEnergyRecord);
+                        byId.setTotalEnergyValue(byId.getTotalEnergyValue() + 20);
+                        byId.setEnergyValue(byId.getEnergyValue() + 20);
+
+                    }
+                    appUserTree.setTaskOne(1);
+                    appUserTree.setTaskTwo(1);
+                } else if (temp >= 1800) {
+                    if (appUserTree.getTaskOne() == 2) {
+                        AppUserEnergyRecord appUserEnergyRecord = new AppUserEnergyRecord();
+                        appUserEnergyRecord.setAppUserId(id);
+                        appUserEnergyRecord.setChangeType(1);
+                        appUserEnergyRecord.setEnergyValue(10);
+                        appUserEnergyRecord.setReason("完成【每日疗愈30分钟】任务");
+                        appUserEnergyRecordService.save(appUserEnergyRecord);
+                        byId.setTotalEnergyValue(byId.getTotalEnergyValue() + 10);
+                        byId.setEnergyValue(byId.getEnergyValue() + 10);
+                    }
+                    appUserTree.setTaskOne(2);
+                    appUserTree.setTaskTwo(1);
+                } else {
+                    appUserTree.setTaskOne(2);
+                    appUserTree.setTaskTwo(2);
+                }
+                appUserTree.setEnergyValue(byId.getEnergyValue());
+                appUserTree.setNextLevel(1000);
+                appUserTreeService.save(appUserTree);
+                appUserTree.setTotalEnergyValue(byId.getTotalEnergyValue());
+                return R.ok();
+            } else {
+                if (temp >= 3600) {
+                    if (one.getTaskOne() == 2) {
+                        AppUserEnergyRecord appUserEnergyRecord = new AppUserEnergyRecord();
+                        appUserEnergyRecord.setAppUserId(id);
+                        appUserEnergyRecord.setChangeType(1);
+                        appUserEnergyRecord.setEnergyValue(10);
+                        appUserEnergyRecord.setReason("完成【每日疗愈30分钟】任务");
+                        appUserEnergyRecordService.save(appUserEnergyRecord);
+                        byId.setTotalEnergyValue(byId.getTotalEnergyValue() + 10);
+                        one.setTaskOne(1);
+                        byId.setEnergyValue(byId.getEnergyValue() + 10);
+
+                    }
+                    if (one.getTaskTwo() == 2) {
+                        AppUserEnergyRecord appUserEnergyRecord = new AppUserEnergyRecord();
+                        appUserEnergyRecord.setAppUserId(id);
+                        appUserEnergyRecord.setChangeType(1);
+                        appUserEnergyRecord.setEnergyValue(20);
+                        appUserEnergyRecord.setReason("完成【每日疗愈60分钟】任务");
+                        appUserEnergyRecordService.save(appUserEnergyRecord);
+                        byId.setTotalEnergyValue(byId.getTotalEnergyValue() + 20);
+                        one.setTaskTwo(1);
+                        byId.setEnergyValue(byId.getEnergyValue() + 20);
+
+                    }
+
+                } else if (temp >= 1800) {
+                    if (one.getTaskOne() == 2) {
+                        AppUserEnergyRecord appUserEnergyRecord = new AppUserEnergyRecord();
+                        appUserEnergyRecord.setAppUserId(id);
+                        appUserEnergyRecord.setChangeType(1);
+                        appUserEnergyRecord.setEnergyValue(10);
+                        appUserEnergyRecord.setReason("完成【每日疗愈30分钟】任务");
+                        appUserEnergyRecordService.save(appUserEnergyRecord);
+                        byId.setTotalEnergyValue(byId.getTotalEnergyValue() + 10);
+                        one.setTaskOne(1);
+                        byId.setEnergyValue(byId.getEnergyValue() + 10);
+                    }
+                } else {
+                    one.setTaskOne(2);
+                    one.setTaskTwo(2);
+                }
+                // 如果用户的签到时间是今天 那么修改为已签到
+                if (byId.getSignTime() != null && byId.getSignTime().toLocalDate().equals(LocalDateTime.now().toLocalDate())) {
+                    one.setIsSign(1);
+                } else {
+                    one.setIsSign(2);
+                }
+                List<TreeLevelSetting> data = sysUserClient.getTreeGroup().getData();
+
+                Integer total1 = one.getTotal();
+                // 根据总能量值 确定他在哪一等级
+                int x = 1;
+                int tem = 0;
+                for (TreeLevelSetting datum : data) {
+                    if (total1 == 0) {
+                        Integer growthValue = data.get(1).getGrowthValue();
+                        tem = growthValue;
+                        break;
+                    } else if (total1 >= datum.getGrowthValue()) {
+                        x = datum.getTreeLevelType();
+                    }
+                }
+                if (x == 10) {
+                    // 如果等级为10那么成长阈值是10级减去9级
+                    int ten = 0;
+                    int nine = 0;
+                    for (TreeLevelSetting datum : data) {
+                        if (datum.getTreeLevelType() == 10) {
+                            ten = datum.getGrowthValue();
+                        }
+                        if (datum.getTreeLevelType() == 9) {
+                            nine = datum.getGrowthValue();
+                        }
+                    }
+                    tem = ten - nine;
+                    total1 = tem;
+                } else {
+                    // 根据当前所在等级查询成长值
+                    int a = data.get(x).getGrowthValue() - data.get(x - 1).getGrowthValue();
+                    tem = a;
+                    total1 = Math.abs(total1 - data.get(x - 1).getGrowthValue());
+                }
+                one.setNextLevel(tem);
+                one.setTreeLevelType(x);
+                // 将当前成长值更新
+                one.setGrowthValue(total1);
+                one.setEnergyValue(byId.getEnergyValue());
+                appUserTreeService.updateById(one);
+                one.setTotalEnergyValue(byId.getTotalEnergyValue());
+                appUserService.updateById(byId);
+                return R.ok();
+            }
     }
     @Autowired
     private TokenService tokenService;
@@ -346,12 +540,14 @@
         AppUser byId = appUserService.getById(userId);
         if (byId.getEnergyValue() == 0){
             return R.energyValueError("能量值不足");
-
         }
         WateringVO wateringVO = new WateringVO();
 
         AppUserTree one = appUserTreeService.lambdaQuery().eq(AppUserTree::getAppUserId, userId)
                 .eq(AppUserTree::getSowAgain,2).one();
+        if (one.getTreeLevelType() == 10){
+            return R.fail("成长值已满,请重新播种");
+        }
         one.setStatus(2);
         one.setTotal(one.getTotal()+byId.getEnergyValue());
         one.setTime(LocalDateTime.now());
@@ -399,9 +595,17 @@
         one.setGrowthValue(total1);
         one.setEnergyValue(byId.getEnergyValue());
         appUserTreeService.updateById(one);
+        if (one.getTotal()>=data.get(9).getGrowthValue()){
+            // 本次浇水量
+            byId.setEnergyValue(one.getTotal()-data.get(9).getGrowthValue());
+            appUserService.updateById(byId);
+            one.setTotal(data.get(9).getGrowthValue());
+            appUserTreeService.updateById(one);
+        }
         wateringVO.setNextLevel(tem);
         wateringVO.setTreeLevelType(x);
         wateringVO.setGrowthValue(total1);
+        wateringVO.setEnergyValue(byId.getEnergyValue());
         if (x>y){
             wateringVO.setIsNext(true);
             NoticeRecord noticeRecord = new NoticeRecord();
@@ -424,6 +628,10 @@
         Long userId = loginUser.getUserid();
         // 给用户加10能量
         AppUser byId = appUserService.getById(userId);
+        if (byId.getSignTime()!=null
+                && byId.getSignTime().toLocalDate().equals(LocalDate.now())){
+        return R.fail("您今日已签到");
+        }
         byId.setEnergyValue(byId.getEnergyValue()+10);
         byId.setSignTime(LocalDateTime.now());
         byId.setTotalEnergyValue(byId.getTotalEnergyValue()+10);

--
Gitblit v1.7.1