parent
b66a9974df
commit
68d7e59a34
@ -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<String, Object>... maps);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -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);
|
||||||
|
|
||||||
|
}
|
@ -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<ClientTemplate> findByClientId(@Param("signId") Integer signId);
|
||||||
|
}
|
@ -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());
|
||||||
|
}
|
||||||
|
}
|
@ -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<ClientTemplate> clientTemplate1 = clientTemplateMapper.findByClientId(15);
|
||||||
|
List<ClientTemplate> clientTemplate2 = clientTemplateMapper.findByClientId(24);
|
||||||
|
clientTemplate1.forEach(System.out::println);
|
||||||
|
clientTemplate2.forEach(System.out::println);
|
||||||
|
ObjectMapper mapper = new ObjectMapper();
|
||||||
|
List<Map> maps = clientTemplate1
|
||||||
|
.stream()
|
||||||
|
.map(clientTemplate -> mapper.convertValue(clientTemplate, Map.class))
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
beaconCacheClient.sadd("client_template:15", maps.toArray(new Map[]{}));
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in new issue