parent
1feaa1c977
commit
3e47748c5a
@ -0,0 +1,14 @@
|
||||
package com.mashibing.api.client;
|
||||
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
|
||||
/**
|
||||
* @author zjw
|
||||
* @description
|
||||
*/
|
||||
@FeignClient(value = "beacon-cache")
|
||||
public interface BeaconCacheClient {
|
||||
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
package com.mashibing.test;
|
||||
|
||||
import org.mybatis.spring.annotation.MapperScan;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
|
||||
import org.springframework.cloud.openfeign.EnableFeignClients;
|
||||
|
||||
/**
|
||||
* @author zjw
|
||||
* @description
|
||||
*/
|
||||
@SpringBootApplication
|
||||
@EnableDiscoveryClient
|
||||
@EnableFeignClients
|
||||
@MapperScan(basePackages = "com.mashibing.test.mapper")
|
||||
public class TestStarterApp {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(TestStarterApp.class,args);
|
||||
}
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
package com.mashibing.test.client;
|
||||
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @author zjw
|
||||
* @description
|
||||
*/
|
||||
@FeignClient(value = "beacon-cache")
|
||||
public interface CacheClient {
|
||||
|
||||
@PostMapping(value = "/cache/hmset/{key}")
|
||||
void hmset(@PathVariable(value = "key")String key, @RequestBody Map<String,Object> map);
|
||||
|
||||
@PostMapping(value = "/cache/set/{key}")
|
||||
void set(@PathVariable(value = "key")String key, @RequestParam(value = "value")Object value);
|
||||
|
||||
@PostMapping(value = "/cache/sadd/{key}")
|
||||
void sadd(@PathVariable(value = "key")String key, @RequestBody Map<String,Object>... maps);
|
||||
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
package com.mashibing.test.mapper;
|
||||
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
|
||||
/**
|
||||
* @author zjw
|
||||
* @description
|
||||
*/
|
||||
public interface ClientBalanceMapper {
|
||||
|
||||
@Select("select balance from client_balance where client_id = #{clientId}")
|
||||
Long findByClientId(@Param("clientId")Long clientId);
|
||||
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
package com.mashibing.test.mapper;
|
||||
|
||||
import com.mashibing.test.entity.ClientBusiness;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
|
||||
/**
|
||||
* @author zjw
|
||||
* @description
|
||||
*/
|
||||
public interface ClientBusinessMapper {
|
||||
|
||||
@Select("select * from client_business where id = #{id}")
|
||||
ClientBusiness findById(@Param("id") Long id);
|
||||
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
package com.mashibing.test.mapper;
|
||||
|
||||
import com.mashibing.test.entity.ClientSign;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author zjw
|
||||
* @description
|
||||
*/
|
||||
public interface ClientSignMapper {
|
||||
|
||||
@Select("select * from client_sign where client_id = #{clientId}")
|
||||
List<ClientSign> findByClientId(@Param("clientId")Long clientId);
|
||||
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
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 zjw
|
||||
* @description
|
||||
*/
|
||||
public interface ClientTemplateMapper {
|
||||
|
||||
@Select("select * from client_template where sign_id = #{signId}")
|
||||
List<ClientTemplate> findBySignId(@Param("signId") Long signId);
|
||||
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
# 服务名
|
||||
spring:
|
||||
application:
|
||||
name: beacon-test
|
||||
# nacos地址
|
||||
cloud:
|
||||
nacos:
|
||||
discovery:
|
||||
server-addr: 114.116.226.76:8848
|
||||
# datasource
|
||||
datasource:
|
||||
driver-class-name: org.gjt.mm.mysql.Driver
|
||||
url: jdbc:mysql://114.116.226.76:3306/beacon_cloud?characterEncoding=utf-8
|
||||
username: root
|
||||
password: ZhengJinWei123!
|
||||
# 端口号
|
||||
server:
|
||||
port: 20000
|
||||
|
||||
# mybatis
|
||||
mybatis:
|
||||
configuration:
|
||||
map-underscore-to-camel-case: true
|
@ -0,0 +1,29 @@
|
||||
package com.mashibing.test.mapper;
|
||||
|
||||
import com.mashibing.test.client.CacheClient;
|
||||
import org.junit.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.Assert.*;
|
||||
|
||||
@SpringBootTest
|
||||
@RunWith(SpringRunner.class)
|
||||
public class ClientBalanceMapperTest {
|
||||
|
||||
@Autowired
|
||||
private ClientBalanceMapper mapper;
|
||||
|
||||
@Autowired
|
||||
private CacheClient cacheClient;
|
||||
|
||||
@Test
|
||||
public void findByClientId() {
|
||||
Long balance = mapper.findByClientId(1L);
|
||||
System.out.println(balance);
|
||||
|
||||
cacheClient.set("client_balance:1",balance);
|
||||
}
|
||||
}
|
@ -0,0 +1,48 @@
|
||||
package com.mashibing.test.mapper;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.mashibing.test.client.CacheClient;
|
||||
import com.mashibing.test.entity.ClientSign;
|
||||
import org.junit.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.Assert.*;
|
||||
|
||||
@SpringBootTest
|
||||
@RunWith(SpringRunner.class)
|
||||
public class ClientSignMapperTest {
|
||||
|
||||
@Autowired
|
||||
private ClientSignMapper mapper;
|
||||
|
||||
@Autowired
|
||||
private CacheClient cacheClient;
|
||||
|
||||
@Test
|
||||
public void findByClientId() {
|
||||
List<ClientSign> list = mapper.findByClientId(1L);
|
||||
for (ClientSign clientSign : list) {
|
||||
System.out.println(clientSign);
|
||||
}
|
||||
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
List<Map> value = list.stream().map(cs -> {
|
||||
try {
|
||||
return objectMapper.readValue(objectMapper.writeValueAsString(cs), Map.class);
|
||||
} catch (JsonProcessingException e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}).collect(Collectors.toList());
|
||||
|
||||
cacheClient.sadd("client_sign:1",value.toArray(new Map[]{}));
|
||||
}
|
||||
}
|
@ -0,0 +1,53 @@
|
||||
package com.mashibing.test.mapper;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.mashibing.test.client.CacheClient;
|
||||
import com.mashibing.test.entity.ClientTemplate;
|
||||
import org.junit.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.SpringJUnit4ClassRunner;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
@SpringBootTest
|
||||
@RunWith(SpringRunner.class)
|
||||
public class ClientTemplateMapperTest {
|
||||
|
||||
@Autowired
|
||||
private ClientTemplateMapper mapper;
|
||||
|
||||
@Autowired
|
||||
private CacheClient cacheClient;
|
||||
|
||||
@Test
|
||||
public void findBySignId() {
|
||||
List<ClientTemplate> ct1 = mapper.findBySignId(15L);
|
||||
List<ClientTemplate> ct2 = mapper.findBySignId(24L);
|
||||
for (ClientTemplate clientTemplate : ct1) {
|
||||
System.out.println(clientTemplate);
|
||||
}
|
||||
// ct2在现有的库中没有数据
|
||||
System.out.println(ct2);
|
||||
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
List<Map> value = ct1.stream().map(ct -> {
|
||||
try {
|
||||
return objectMapper.readValue(objectMapper.writeValueAsString(ct), Map.class);
|
||||
} catch (JsonProcessingException e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}).collect(Collectors.toList());
|
||||
|
||||
|
||||
cacheClient.sadd("client_template:15",value.toArray(new Map[]{}));
|
||||
}
|
||||
}
|
Loading…
Reference in new issue