xiongzhu 2 лет назад
Родитель
Сommit
cc1cc14649

+ 6 - 0
pom.xml

@@ -368,6 +368,12 @@
             <artifactId>telegrambots</artifactId>
             <version>6.5.0</version>
         </dependency>
+
+        <dependency>
+            <groupId>org.telegram</groupId>
+            <artifactId>telegrambots-abilities</artifactId>
+            <version>6.5.0</version>
+        </dependency>
     </dependencies>
 
 </project>

+ 6 - 1
src/main/java/com/izouma/awesomeAdmin/repo/OrderRepo.java

@@ -85,5 +85,10 @@ public interface OrderRepo extends JpaRepository<Order, Long>, JpaSpecificationE
 
     long countUserIdByCreatedAtBetweenAndStatusNotIn(LocalDateTime start, LocalDateTime end, Collection<OrderStatus> statuses);
 
-    long countByCreatedAtBetweenAndStatusNotIn(LocalDateTime start, LocalDateTime end, Collection<OrderStatus> statuses);
+    @Query("select o.userId from order_info o where o.createdAt >=?1 and o.createdAt <= ?2 " +
+            "and o.status <> com.izouma.awesomeAdmin.enums.OrderStatus.NOT_PAID " +
+            "and o.status <> com.izouma.awesomeAdmin.enums.OrderStatus.CANCELED " +
+            "and o.createProduct = false")
+    List<Long> findUserIdByCreatedAtBetweenAndStatusNotIn(LocalDateTime start, LocalDateTime end);
+
 }

+ 4 - 1
src/main/java/com/izouma/awesomeAdmin/service/StatService.java

@@ -87,10 +87,13 @@ public class StatService {
     }
 
     public Map<String, Object> dailyPaidAndRegister(LocalDate date) {
-        long paid = orderRepo.countByCreatedAtBetweenAndStatusNotIn(date.atStartOfDay(), date.atTime(LocalTime.MAX), Arrays.asList(OrderStatus.CANCELED, OrderStatus.NOT_PAID));
+        List<Long> userIds = orderRepo.findUserIdByCreatedAtBetweenAndStatusNotIn(date.atStartOfDay(), date.atTime(LocalTime.MAX));
+        long paid = userIds.size();
+        long unique = userIds.stream().distinct().count();
         long register = userRepo.countByCreatedAtBetween(date.atStartOfDay(), date.atTime(LocalTime.MAX));
         Map<String, Object> map = new HashMap<>();
         map.put("paid", paid);
+        map.put("unique", unique);
         map.put("register", register);
         return map;
     }

+ 1 - 0
src/main/java/com/izouma/awesomeAdmin/service/TelegramBotConfig.java

@@ -8,5 +8,6 @@ import org.springframework.boot.context.properties.ConfigurationProperties;
 public class TelegramBotConfig {
     private String username;
     private String token;
+    private long creatorId;
     private boolean enabled = false;
 }

+ 27 - 31
src/main/java/com/izouma/awesomeAdmin/web/TelegramBot.java

@@ -4,53 +4,49 @@ import com.izouma.awesomeAdmin.service.TelegramBotConfig;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.boot.context.properties.EnableConfigurationProperties;
 import org.springframework.stereotype.Service;
-import org.telegram.telegrambots.bots.TelegramLongPollingBot;
-import org.telegram.telegrambots.meta.api.methods.send.SendMessage;
-import org.telegram.telegrambots.meta.api.objects.Chat;
-import org.telegram.telegrambots.meta.api.objects.MessageEntity;
+import org.telegram.abilitybots.api.bot.AbilityBot;
+import org.telegram.abilitybots.api.objects.Ability;
+import org.telegram.abilitybots.api.objects.Locality;
+import org.telegram.abilitybots.api.objects.Privacy;
 import org.telegram.telegrambots.meta.api.objects.Update;
-import org.telegram.telegrambots.meta.exceptions.TelegramApiException;
+
+import java.util.List;
 
 @EnableConfigurationProperties(TelegramBotConfig.class)
 @Service
 @Slf4j
-public class TelegramBot extends TelegramLongPollingBot {
+public class TelegramBot extends AbilityBot {
 
     private final TelegramBotConfig config;
 
     public TelegramBot(TelegramBotConfig config) {
-        super(config.getToken());
+        super(config.getToken(), config.getUsername());
         this.config = config;
     }
 
     @Override
-    public void onUpdateReceived(Update update) {
-        if (update.hasMessage() && update.getMessage().hasText()) {
-            String text = update.getMessage().getText();
-            log.info("Received message: {}", text);
-            Chat chat = update.getMessage().getChat();
-            log.info("Chat: id={} type={} title={}", chat.getId(), chat.getType(), chat.getTitle());
-            if (update.getMessage().getEntities() != null) {
-                for (MessageEntity entity : update.getMessage().getEntities()) {
-                    log.info("Entity: type={} text={}", entity.getType(), entity.getText());
-                }
-            }
-
-            SendMessage message = new SendMessage(); // Create a SendMessage object with mandatory fields
-            message.setChatId(update.getMessage().getChatId().toString());
-            message.setText("hello");
-
-            try {
-                execute(message); // Call method to send the message
-            } catch (TelegramApiException e) {
-                e.printStackTrace();
-            }
-        }
+    public long creatorId() {
+        return config.getCreatorId();
     }
 
     @Override
-    public String getBotUsername() {
-        return config.getUsername();
+    public void onUpdatesReceived(List<Update> updates) {
+        super.onUpdatesReceived(updates);
     }
 
+    @Override
+    public void onClosing() {
+        super.onClosing();
+    }
+
+    public Ability sayHelloWorld() {
+        return Ability
+                .builder()
+                .name("hello")
+                .info("says hello world!")
+                .locality(Locality.ALL)
+                .privacy(Privacy.PUBLIC)
+                .action(ctx -> silent.send("Hello world!", ctx.chatId()))
+                .build();
+    }
 }

+ 1 - 0
src/main/resources/application.yaml

@@ -125,6 +125,7 @@ cloudpay:
 tg-bot:
   token: 6127741905:AAHD3FjbRQ5iJxKLs5pIemHUc5DTvqh_G9s
   username: firstcashtestbot
+  creator-id: 846881110
   enabled: true
 ---
 

+ 1 - 1
src/main/vue/src/views/Dashboard.vue

@@ -65,7 +65,7 @@
             <el-col :md="12" :lg="6">
                 <legend-widget
                     label="今日付费"
-                    :value="`${dailyPaidAndRegister.paid}`"
+                    :value="`${dailyPaidAndRegister.paid}笔 / ${dailyPaidAndRegister.unique}人`"
                     icon="fa-solid fa-money-bill"
                 ></legend-widget>
             </el-col>