Browse Source

集成时间和天气预告。

tanlie 2 tuần trước cách đây
mục cha
commit
fb91dac86f
15 tập tin đã thay đổi với 250 bổ sung7 xóa
  1. 3 0
      wishing-platform/platform-entity/platform-entity-wishing/src/main/java/cn/qinys/platform/entity/wishing/WishingTreeExtension.java
  2. BIN
      wishing-platform/platform-entity/platform-entity-wishing/target/classes/cn/qinys/platform/entity/wishing/WishingTreeExtension.class
  3. BIN
      wishing-platform/platform-entity/platform-entity-wishing/target/platform-entity-wishing-1.0.0-SNAPSHOT.jar
  4. 16 0
      wishing-platform/platform-service/platform-service-admin/src/main/java/cn/qinys/platform/admin/mapper/WishingTreeExtensionMapper.java
  5. 15 0
      wishing-platform/platform-service/platform-service-admin/src/main/java/cn/qinys/platform/admin/service/GaoDeService.java
  6. 46 0
      wishing-platform/platform-service/platform-service-admin/src/main/java/cn/qinys/platform/admin/service/impl/GaoDeServiceImpl.java
  7. 63 0
      wishing-platform/platform-service/platform-service-admin/src/test/java/cn/qinys/platform/admin/service/GaoDeServiceTest.java
  8. 2 1
      wishing-platform/platform-service/platform-service-mobile/src/main/java/cn/qinys/platform/mobile/service/impl/ChatServiceImpl.java
  9. 3 0
      wishing-platform/platform-service/platform-service-mobile/src/main/java/cn/qinys/platform/mobile/tool/DateTimeTools.java
  10. 45 0
      wishing-platform/platform-service/platform-service-mobile/src/main/java/cn/qinys/platform/mobile/tool/WeatherTools.java
  11. 23 0
      wishing-platform/platform-service/platform-service-mobile/src/test/java/cn/qinys/platform/mobile/tool/WeatherToolsTest.java
  12. 7 1
      wishing-platform/platform-service/platform-service-upms/src/main/java/cn/qinys/platform/upms/api/controller/GaoDeKeyController.java
  13. 6 0
      wishing-platform/platform-service/platform-service-upms/src/main/java/cn/qinys/platform/upms/api/service/IGaoDeKeyService.java
  14. 5 5
      wishing-platform/platform-service/platform-service-upms/src/main/java/cn/qinys/platform/upms/api/service/impl/GaoDeKeyServiceImpl.java
  15. 16 0
      wishing-platform/platform-service/platform-service-upms/src/test/java/cn/qinys/platform/upms/api/service/IGaoDeKeyServiceTest.java

+ 3 - 0
wishing-platform/platform-entity/platform-entity-wishing/src/main/java/cn/qinys/platform/entity/wishing/WishingTreeExtension.java

@@ -35,5 +35,8 @@ public class WishingTreeExtension implements Serializable {
     @TableField(fill = FieldFill.INSERT_UPDATE)
     private LocalDateTime updatedAt;
 
+    private Integer adcode;
+
+    private String regeocode;
 
 }

BIN
wishing-platform/platform-entity/platform-entity-wishing/target/classes/cn/qinys/platform/entity/wishing/WishingTreeExtension.class


BIN
wishing-platform/platform-entity/platform-entity-wishing/target/platform-entity-wishing-1.0.0-SNAPSHOT.jar


+ 16 - 0
wishing-platform/platform-service/platform-service-admin/src/main/java/cn/qinys/platform/admin/mapper/WishingTreeExtensionMapper.java

@@ -0,0 +1,16 @@
+package cn.qinys.platform.admin.mapper;
+
+import cn.qinys.platform.entity.wishing.WishingTreeExtension;
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import org.apache.ibatis.annotations.Mapper;
+
+/**
+ * @author lie tan
+ * @description
+ * @date 2026-06-07 14:53
+ **/
+@Mapper
+public interface WishingTreeExtensionMapper extends BaseMapper<WishingTreeExtension> {
+
+
+}

+ 15 - 0
wishing-platform/platform-service/platform-service-admin/src/main/java/cn/qinys/platform/admin/service/GaoDeService.java

@@ -0,0 +1,15 @@
+package cn.qinys.platform.admin.service;
+
+import com.alibaba.fastjson2.JSONObject;
+
+import java.math.BigDecimal;
+
+/**
+ * @author lie tan
+ * @description
+ * @date 2026-06-13 11:14
+ **/
+public interface GaoDeService {
+
+    JSONObject getGaoDeResult(BigDecimal lon, BigDecimal lat, Integer index);
+}

+ 46 - 0
wishing-platform/platform-service/platform-service-admin/src/main/java/cn/qinys/platform/admin/service/impl/GaoDeServiceImpl.java

@@ -0,0 +1,46 @@
+package cn.qinys.platform.admin.service.impl;
+
+import cn.qinys.platform.admin.service.GaoDeService;
+import cn.qinys.platform.base.exceptions.BizException;
+import com.alibaba.fastjson2.JSONObject;
+import jakarta.annotation.Resource;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.stereotype.Service;
+import org.springframework.web.client.RestTemplate;
+
+import java.math.BigDecimal;
+
+/**
+ * @author lie tan
+ * @description
+ * @date 2026-06-13 11:15
+ **/
+@Slf4j
+@Service
+public class GaoDeServiceImpl implements GaoDeService {
+
+    @Resource
+    RestTemplate restTemplate;
+
+    String key = "88a0c82c3f60a748c6c638ef9db16bca";
+
+    @Override
+    public JSONObject getGaoDeResult(BigDecimal lon, BigDecimal lat, Integer index) {
+        if (index >= 100) {
+            return null;
+        }
+        index++;
+        String url = "https://restapi.amap.com/v3/geocode/regeo?key={0}&location={1},{2}";
+        JSONObject res = restTemplate.getForObject(url, JSONObject.class, key, lon, lat);
+        if (res == null) {
+            throw new BizException("逆地理解释出现错误");
+        }
+        if ("1".equals(res.getString("status"))) {
+            log.info("获取逆地理解析信息成功{}", res);
+            return res.getJSONObject("regeocode");
+        } else {
+            return this.getGaoDeResult(lon, lat, index);
+        }
+    }
+
+}

+ 63 - 0
wishing-platform/platform-service/platform-service-admin/src/test/java/cn/qinys/platform/admin/service/GaoDeServiceTest.java

@@ -0,0 +1,63 @@
+package cn.qinys.platform.admin.service;
+
+import cn.qinys.platform.admin.mapper.WishingTreeExtensionMapper;
+import cn.qinys.platform.admin.mapper.WishingTreeMapper;
+import cn.qinys.platform.entity.wishing.WishingTree;
+import cn.qinys.platform.entity.wishing.WishingTreeExtension;
+import com.alibaba.fastjson2.JSON;
+import com.alibaba.fastjson2.JSONObject;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
+import jakarta.annotation.Resource;
+import org.junit.jupiter.api.Test;
+import org.springframework.boot.test.context.SpringBootTest;
+
+import java.util.List;
+
+import static org.junit.jupiter.api.Assertions.*;
+
+/**
+ * @author lie tan
+ * @description
+ * @date 2026-06-13 11:26
+ **/
+
+@SpringBootTest
+class GaoDeServiceTest {
+
+    @Resource
+    private GaoDeService gaoDeService;
+    @Resource
+    WishingTreeMapper treeMapper;
+    @Resource
+    WishingTreeExtensionMapper treeExtensionMapper;
+
+    @Test
+    void getGaoDeResult() {
+        QueryWrapper<WishingTree> queryWrapper = new QueryWrapper<>();
+        queryWrapper.ge("id", 0);
+        List<WishingTree> trees = treeMapper.selectList(queryWrapper);
+        trees.forEach(tree -> {
+            JSONObject gaoDeResult = gaoDeService.getGaoDeResult(tree.getLongitude(), tree.getLatitude(), 5);
+            JSONObject addressComponent = gaoDeResult.getJSONObject("addressComponent");
+            Integer adcode = addressComponent.getInteger("adcode");
+            UpdateWrapper<WishingTreeExtension> updateWrapper = new UpdateWrapper<>();
+            updateWrapper.eq("tree_id", tree.getId());
+            updateWrapper.set("adcode", adcode);
+            updateWrapper.set("regeocode", JSON.toJSONString(gaoDeResult));
+            int update = treeExtensionMapper.update(updateWrapper);
+            if(update == 0){
+                WishingTreeExtension extension = new WishingTreeExtension();
+                extension.setTreeId(tree.getId());
+                extension.setTotalCount(0);
+                extension.setPublicCount(0);
+                extension.setPrivateCount(0);
+                extension.setAdcode(adcode);
+                extension.setRegeocode(JSON.toJSONString(gaoDeResult));
+                treeExtensionMapper.insert(extension);
+            }
+
+        });
+
+    }
+}

+ 2 - 1
wishing-platform/platform-service/platform-service-mobile/src/main/java/cn/qinys/platform/mobile/service/impl/ChatServiceImpl.java

@@ -6,6 +6,7 @@ import cn.qinys.platform.mobile.mapper.ChatMessageMapper;
 import cn.qinys.platform.mobile.resp.ChatHistoryResp;
 import cn.qinys.platform.mobile.service.ChatService;
 import cn.qinys.platform.mobile.tool.DateTimeTools;
+import cn.qinys.platform.mobile.tool.WeatherTools;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import jakarta.annotation.Resource;
 import lombok.extern.slf4j.Slf4j;
@@ -36,7 +37,7 @@ public class ChatServiceImpl implements ChatService {
         try {
             reply = chatClient.prompt()
                     .user(message)
-                    .tools(new DateTimeTools())
+                    .tools(new DateTimeTools(), new WeatherTools(treeId))
                     .call()
                     .content();
         } catch (Exception e) {

+ 3 - 0
wishing-platform/platform-service/platform-service-mobile/src/main/java/cn/qinys/platform/mobile/tool/DateTimeTools.java

@@ -18,4 +18,7 @@ public class DateTimeTools {
         return LocalDateTime.now().atZone(LocaleContextHolder.getTimeZone().toZoneId()).toString();
     }
 
+
+
+
 }

+ 45 - 0
wishing-platform/platform-service/platform-service-mobile/src/main/java/cn/qinys/platform/mobile/tool/WeatherTools.java

@@ -0,0 +1,45 @@
+package cn.qinys.platform.mobile.tool;
+
+import cn.qinys.platform.base.utils.SpringUtil;
+import cn.qinys.platform.entity.wishing.WishingTreeExtension;
+import cn.qinys.platform.mobile.mapper.WishingTreeExtensionMapper;
+import org.springframework.ai.tool.annotation.Tool;
+import org.springframework.web.client.RestTemplate;
+
+/**
+ * @author lie tan
+ * @description
+ * @date 2026-06-13 10:47
+ **/
+
+public class WeatherTools {
+
+    String key = "88a0c82c3f60a748c6c638ef9db16bca";
+
+    private Integer treeId;
+
+    public WeatherTools() {
+    }
+
+    public WeatherTools(Integer treeId) {
+        this.treeId = treeId;
+    }
+
+
+    @Tool(description = """
+            get the weather forecast for the special wishing tree
+            along with the current date and time in the user's timezone
+            """)
+    public String getWeather() {
+        WishingTreeExtensionMapper extensionMapper = SpringUtil.getBean(WishingTreeExtensionMapper.class);
+        WishingTreeExtension extension = extensionMapper.selectByTreeId(treeId);
+        if (extension == null || extension.getAdcode() == null) {
+            return null;
+        }
+        RestTemplate restTemplate = SpringUtil.getBean(RestTemplate.class);
+        String url = "https://restapi.amap.com/v3/weather/weatherInfo?city={0}&key={1}";
+        return restTemplate.getForObject(url, String.class, extension.getAdcode(), key);
+    }
+
+
+}

+ 23 - 0
wishing-platform/platform-service/platform-service-mobile/src/test/java/cn/qinys/platform/mobile/tool/WeatherToolsTest.java

@@ -0,0 +1,23 @@
+package cn.qinys.platform.mobile.tool;
+
+import org.junit.jupiter.api.Test;
+import org.springframework.boot.test.context.SpringBootTest;
+/**
+* @author lie tan
+* @description 
+* @date 2026-06-13 11:58
+**/
+
+@SpringBootTest
+class WeatherToolsTest {
+
+
+    @Test
+    void getWeather() {
+        WeatherTools weatherTools = new WeatherTools(3);
+        String weather = weatherTools.getWeather();
+        System.out.println(weather);
+    }
+
+
+}

+ 7 - 1
wishing-platform/platform-service/platform-service-upms/src/main/java/cn/qinys/platform/upms/api/controller/GaoDeKeyController.java

@@ -5,6 +5,7 @@ import cn.qinys.platform.base.security.annotation.HasPermission;
 import cn.qinys.platform.base.utils.excel.ExcelElement;
 import cn.qinys.platform.base.utils.excel.ExcelUtils;
 import cn.qinys.platform.upms.api.req.GaoDeGetAddressReq;
+import com.alibaba.fastjson2.JSONObject;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import cn.qinys.platform.upms.api.req.GaoDeKeyPageReq;
 import cn.qinys.platform.upms.api.resp.GaoDeKeyPageResp;
@@ -70,7 +71,7 @@ public class GaoDeKeyController extends DevBaseController {
 
 
     /**
-     * 网关日志分页
+     * 根据经纬度获取地址
      *
      * @return
      */
@@ -80,5 +81,10 @@ public class GaoDeKeyController extends DevBaseController {
         return new Result<>(address);
     }
 
+    @PostMapping("/info")
+    public JSONObject getInfo(@RequestBody @Valid GaoDeGetAddressReq req) {
+        return gaoDeKeyService.getGaoDeResult("", req.getLongitude(), req.getLatitude(), 10);
+    }
+
 
 }

+ 6 - 0
wishing-platform/platform-service/platform-service-upms/src/main/java/cn/qinys/platform/upms/api/service/IGaoDeKeyService.java

@@ -1,10 +1,13 @@
 package cn.qinys.platform.upms.api.service;
 
 import cn.qinys.platform.upms.api.req.GaoDeGetAddressReq;
+import com.alibaba.fastjson2.JSONObject;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import cn.qinys.platform.upms.api.req.GaoDeKeyPageReq;
 import cn.qinys.platform.upms.api.resp.GaoDeKeyPageResp;
 
+import java.math.BigDecimal;
+
 /**
  * 网关日志
  *
@@ -27,4 +30,7 @@ public interface IGaoDeKeyService {
      * @return
      */
     String getAddress(GaoDeGetAddressReq req);
+
+
+    JSONObject getGaoDeResult(String key, BigDecimal lon, BigDecimal lat, Integer index);
 }

+ 5 - 5
wishing-platform/platform-service/platform-service-upms/src/main/java/cn/qinys/platform/upms/api/service/impl/GaoDeKeyServiceImpl.java

@@ -57,11 +57,12 @@ public class GaoDeKeyServiceImpl implements IGaoDeKeyService {
 
     @Override
     public String getAddress(GaoDeGetAddressReq req) {
-        return this.getGaoDeResult("", req.getLongitude(), req.getLatitude(), 0);
+        JSONObject res = this.getGaoDeResult("", req.getLongitude(), req.getLatitude(), 0);
+        return res == null ? "" : res.getString("formatted_address");
     }
 
-
-    private String getGaoDeResult(String key, BigDecimal lon, BigDecimal lat, Integer index) {
+    @Override
+    public JSONObject getGaoDeResult(String key, BigDecimal lon, BigDecimal lat, Integer index) {
         if (index >= 100) {
             return null;
         }
@@ -76,9 +77,8 @@ public class GaoDeKeyServiceImpl implements IGaoDeKeyService {
         if ("1".equals(res.getString("status"))) {
             log.info("获取逆地理解析信息成功{}", res);
             JSONObject regeocode = res.getJSONObject("regeocode");
-            String address = regeocode.getString("formatted_address");
             this.countKeyUsage(geoKey.getGeoKey());
-            return address;
+            return regeocode;
         } else {
             return this.getGaoDeResult(geoKey.getGeoKey(), lon, lat, index);
         }

+ 16 - 0
wishing-platform/platform-service/platform-service-upms/src/test/java/cn/qinys/platform/upms/api/service/IGaoDeKeyServiceTest.java

@@ -0,0 +1,16 @@
+package cn.qinys.platform.upms.api.service;
+
+import org.springframework.boot.test.context.SpringBootTest;
+
+/**
+ * @author lie tan
+ * @description
+ * @date 2026-06-13 11:06
+ **/
+@SpringBootTest
+class IGaoDeKeyServiceTest {
+
+
+    
+
+}