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