From 68d7e59a34edf1966f80e8cf5530a4ceb7077da9 Mon Sep 17 00:00:00 2001 From: heqijun Date: Fri, 6 Jun 2025 15:11:16 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BC=93=E5=AD=98=E6=8E=A5=E5=8F=A3+beacon-tes?= =?UTF-8?q?t=E6=A8=A1=E5=9D=97=E7=94=A8=E4=BA=8E=E6=B5=8B=E8=AF=95?= =?UTF-8?q?=E7=BC=93=E5=AD=98=E6=8E=A5=E5=8F=A3=E4=BB=A5=E5=8F=8A=E5=90=91?= =?UTF-8?q?redis=E5=86=99=E5=85=A5=E6=B5=8B=E8=AF=95=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/feignClient/BeaconCacheClient.java | 34 +++++++++++++++ .../mashibing/test/entity/ClientTemplate.java | 2 + .../test/mapper/ClientBalanceMapper.java | 18 ++++++++ .../test/mapper/ClientTemplateMapper.java | 20 +++++++++ .../test/mapper/ClientBalanceMapperTest.java | 29 +++++++++++++ .../test/mapper/ClientBusinessMapperTest.java | 1 - .../test/mapper/ClientTemplateMapperTest.java | 41 +++++++++++++++++++ 7 files changed, 144 insertions(+), 1 deletion(-) create mode 100644 beacon-api/src/main/java/com/mashibing/api/feignClient/BeaconCacheClient.java create mode 100644 beacon-test/src/main/java/com/mashibing/test/mapper/ClientBalanceMapper.java create mode 100644 beacon-test/src/main/java/com/mashibing/test/mapper/ClientTemplateMapper.java create mode 100644 beacon-test/src/test/java/com/mashibing/test/mapper/ClientBalanceMapperTest.java create mode 100644 beacon-test/src/test/java/com/mashibing/test/mapper/ClientTemplateMapperTest.java diff --git a/beacon-api/src/main/java/com/mashibing/api/feignClient/BeaconCacheClient.java b/beacon-api/src/main/java/com/mashibing/api/feignClient/BeaconCacheClient.java new file mode 100644 index 0000000..1e3b528 --- /dev/null +++ b/beacon-api/src/main/java/com/mashibing/api/feignClient/BeaconCacheClient.java @@ -0,0 +1,34 @@ +package com.mashibing.api.feignClient; + +import org.springframework.cloud.openfeign.FeignClient; +import org.springframework.web.bind.annotation.*; + +import java.util.Map; + +/** + * @author heqijun + * @ClassName: BeaconCacheClient + * @Description: TODO(这里用一句话描述这个类的作用) + * @date 2025/6/5 20:13 + */ + +@FeignClient("beacon-cache") +@RequestMapping("cache") +public interface BeaconCacheClient { + @GetMapping("get/{key}") + public String get(@PathVariable String key); + + @GetMapping("set/{key}/{value}") + public void set(@PathVariable String key, @PathVariable String value); + + @GetMapping("hget/{key}") + public Map hget(@PathVariable String key); + + @PostMapping("hset/{key}") + public void hset(@PathVariable String key, @RequestBody Map hash); + + @PostMapping("/sadd/{key}") + public void sadd(@PathVariable(value = "key") String key, @RequestBody Map... maps); + + +} diff --git a/beacon-test/src/main/java/com/mashibing/test/entity/ClientTemplate.java b/beacon-test/src/main/java/com/mashibing/test/entity/ClientTemplate.java index 5beca9d..c1bcfd9 100644 --- a/beacon-test/src/main/java/com/mashibing/test/entity/ClientTemplate.java +++ b/beacon-test/src/main/java/com/mashibing/test/entity/ClientTemplate.java @@ -1,6 +1,8 @@ package com.mashibing.test.entity; +import lombok.ToString; +@ToString public class ClientTemplate { private long id; diff --git a/beacon-test/src/main/java/com/mashibing/test/mapper/ClientBalanceMapper.java b/beacon-test/src/main/java/com/mashibing/test/mapper/ClientBalanceMapper.java new file mode 100644 index 0000000..69749bd --- /dev/null +++ b/beacon-test/src/main/java/com/mashibing/test/mapper/ClientBalanceMapper.java @@ -0,0 +1,18 @@ +package com.mashibing.test.mapper; + +import org.apache.ibatis.annotations.Param; +import org.apache.ibatis.annotations.Select; + +/** + * @author heqijun + * @ClassName: ClientBalanceMapper + * @Description: TODO(这里用一句话描述这个类的作用) + * @date 2025/6/6 15:00 + */ + +public interface ClientBalanceMapper { + + @Select("select balance from client_balance where client_id = #{clientId}") + Long getBalanceByClientId(@Param("clientId") Long clientId); + +} diff --git a/beacon-test/src/main/java/com/mashibing/test/mapper/ClientTemplateMapper.java b/beacon-test/src/main/java/com/mashibing/test/mapper/ClientTemplateMapper.java new file mode 100644 index 0000000..b37c39e --- /dev/null +++ b/beacon-test/src/main/java/com/mashibing/test/mapper/ClientTemplateMapper.java @@ -0,0 +1,20 @@ +package com.mashibing.test.mapper; + +import com.mashibing.test.entity.ClientTemplate; +import org.apache.ibatis.annotations.Param; +import org.apache.ibatis.annotations.Select; + +import java.util.List; + +/** + * @author heqijun + * @ClassName: ClientTemplateMapper + * @Description: TODO(这里用一句话描述这个类的作用) + * @date 2025/6/6 14:26 + */ + +public interface ClientTemplateMapper { + + @Select("select * from client_template where sign_id = #{signId}") + List findByClientId(@Param("signId") Integer signId); +} diff --git a/beacon-test/src/test/java/com/mashibing/test/mapper/ClientBalanceMapperTest.java b/beacon-test/src/test/java/com/mashibing/test/mapper/ClientBalanceMapperTest.java new file mode 100644 index 0000000..e38805b --- /dev/null +++ b/beacon-test/src/test/java/com/mashibing/test/mapper/ClientBalanceMapperTest.java @@ -0,0 +1,29 @@ +package com.mashibing.test.mapper; + +import com.mashibing.test.feignClient.BeaconCacheClient; +import org.junit.jupiter.api.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; + +import static org.junit.jupiter.api.Assertions.*; + +@SpringBootTest +@RunWith(SpringRunner.class) +class ClientBalanceMapperTest { + + @Autowired + BeaconCacheClient beaconCacheClient; + + @Autowired + ClientBalanceMapper clientBalanceMapper; + + @Test + void getBalanceByClientId() { + Long balance = clientBalanceMapper.getBalanceByClientId(1L); + System.out.println("balance = " + balance); + + beaconCacheClient.set("client_balance:1", balance.toString()); + } +} \ No newline at end of file diff --git a/beacon-test/src/test/java/com/mashibing/test/mapper/ClientBusinessMapperTest.java b/beacon-test/src/test/java/com/mashibing/test/mapper/ClientBusinessMapperTest.java index d1cb6b3..23963b7 100644 --- a/beacon-test/src/test/java/com/mashibing/test/mapper/ClientBusinessMapperTest.java +++ b/beacon-test/src/test/java/com/mashibing/test/mapper/ClientBusinessMapperTest.java @@ -8,7 +8,6 @@ import org.junit.jupiter.api.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.cloud.openfeign.EnableFeignClients; import org.springframework.test.context.junit4.SpringRunner; import java.util.Map; diff --git a/beacon-test/src/test/java/com/mashibing/test/mapper/ClientTemplateMapperTest.java b/beacon-test/src/test/java/com/mashibing/test/mapper/ClientTemplateMapperTest.java new file mode 100644 index 0000000..253b37b --- /dev/null +++ b/beacon-test/src/test/java/com/mashibing/test/mapper/ClientTemplateMapperTest.java @@ -0,0 +1,41 @@ +package com.mashibing.test.mapper; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.mashibing.test.entity.ClientTemplate; +import com.mashibing.test.feignClient.BeaconCacheClient; +import org.junit.jupiter.api.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; + +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +import static org.junit.jupiter.api.Assertions.*; + +@SpringBootTest +@RunWith(SpringRunner.class) +class ClientTemplateMapperTest { + + @Autowired + BeaconCacheClient beaconCacheClient; + + @Autowired + ClientTemplateMapper clientTemplateMapper; + + @Test + void findByClientId() { + List clientTemplate1 = clientTemplateMapper.findByClientId(15); + List clientTemplate2 = clientTemplateMapper.findByClientId(24); + clientTemplate1.forEach(System.out::println); + clientTemplate2.forEach(System.out::println); + ObjectMapper mapper = new ObjectMapper(); + List maps = clientTemplate1 + .stream() + .map(clientTemplate -> mapper.convertValue(clientTemplate, Map.class)) + .collect(Collectors.toList()); + beaconCacheClient.sadd("client_template:15", maps.toArray(new Map[]{})); + } +} \ No newline at end of file