From b198ad115ca28e53b66586af6dac94f6945047d4 Mon Sep 17 00:00:00 2001 From: DanielDeng Date: Wed, 20 Mar 2024 01:36:42 +0800 Subject: [PATCH] =?UTF-8?q?=E7=83=BD=E7=81=AB=E4=BA=91=E9=95=BF=E6=A4=BF?= =?UTF-8?q?=E8=A1=973.20=201:35?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .idea/compiler.xml | 4 + .idea/dataSources.xml | 12 + beacon-api/pom.xml | 6 + .../java/com/mashibing/ApiStarterApp.java | 2 + .../api/client/BeaconCacheClient.java | 12 + .../api/controller/SmsController.java | 141 +++++++++++- .../api/controller/SmsController.class | Bin 2233 -> 3816 bytes beacon-cache/pom.xml | 52 +++++ .../com/mashibing/cache/CacheStarterApp.java | 19 ++ .../mashibing/cache/config/RedisConfig.java | 80 +++++++ .../cache/controller/CacheController.java | 39 ++++ .../cache/controller/TestController.java | 35 +++ beacon-cache/src/main/resources/bootstrap.yml | 17 ++ .../common/model/StandardSubmit.java | 13 +- beacon-test/pom.xml | 58 +++++ .../com/mashibing/test/TestStarterApp.java | 22 ++ .../mashibing/test/client/CacheClient.java | 27 +++ .../mashibing/test/entity/ClientBalance.java | 144 ++++++++++++ .../mashibing/test/entity/ClientBusiness.java | 210 ++++++++++++++++++ .../com/mashibing/test/entity/ClientSign.java | 199 +++++++++++++++++ .../mashibing/test/entity/ClientTemplate.java | 188 ++++++++++++++++ .../test/mapper/ClientBalanceMapper.java | 14 ++ .../test/mapper/ClientBusinessMapper.java | 16 ++ .../test/mapper/ClientSignMapper.java | 16 ++ .../test/mapper/ClientTemplateMapper.java | 17 ++ .../src/main/resources/application.yml | 23 ++ .../test/mapper/ClientBalanceMapperTest.java | 33 +++ .../test/mapper/ClientBusinessMapperTest.java | 40 ++++ .../test/mapper/ClientSignMapperTest.java | 53 +++++ .../test/mapper/ClientTemplateMapperTest.java | 56 +++++ pom.xml | 10 + 31 files changed, 1553 insertions(+), 5 deletions(-) create mode 100644 .idea/dataSources.xml create mode 100644 beacon-api/src/main/java/com/mashibing/api/client/BeaconCacheClient.java create mode 100644 beacon-cache/pom.xml create mode 100644 beacon-cache/src/main/java/com/mashibing/cache/CacheStarterApp.java create mode 100644 beacon-cache/src/main/java/com/mashibing/cache/config/RedisConfig.java create mode 100644 beacon-cache/src/main/java/com/mashibing/cache/controller/CacheController.java create mode 100644 beacon-cache/src/main/java/com/mashibing/cache/controller/TestController.java create mode 100644 beacon-cache/src/main/resources/bootstrap.yml create mode 100644 beacon-test/pom.xml create mode 100644 beacon-test/src/main/java/com/mashibing/test/TestStarterApp.java create mode 100644 beacon-test/src/main/java/com/mashibing/test/client/CacheClient.java create mode 100644 beacon-test/src/main/java/com/mashibing/test/entity/ClientBalance.java create mode 100644 beacon-test/src/main/java/com/mashibing/test/entity/ClientBusiness.java create mode 100644 beacon-test/src/main/java/com/mashibing/test/entity/ClientSign.java create mode 100644 beacon-test/src/main/java/com/mashibing/test/entity/ClientTemplate.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/ClientBusinessMapper.java create mode 100644 beacon-test/src/main/java/com/mashibing/test/mapper/ClientSignMapper.java create mode 100644 beacon-test/src/main/java/com/mashibing/test/mapper/ClientTemplateMapper.java create mode 100644 beacon-test/src/main/resources/application.yml 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/ClientBusinessMapperTest.java create mode 100644 beacon-test/src/test/java/com/mashibing/test/mapper/ClientSignMapperTest.java create mode 100644 beacon-test/src/test/java/com/mashibing/test/mapper/ClientTemplateMapperTest.java diff --git a/.idea/compiler.xml b/.idea/compiler.xml index b2ec7c1..1d89b37 100644 --- a/.idea/compiler.xml +++ b/.idea/compiler.xml @@ -10,6 +10,8 @@ + + @@ -18,7 +20,9 @@ \ No newline at end of file diff --git a/.idea/dataSources.xml b/.idea/dataSources.xml new file mode 100644 index 0000000..cd8ba92 --- /dev/null +++ b/.idea/dataSources.xml @@ -0,0 +1,12 @@ + + + + + mysql.8 + true + com.mysql.cj.jdbc.Driver + jdbc:mysql://localhost:3306/beacon_cloud + $ProjectFileDir$ + + + \ No newline at end of file diff --git a/beacon-api/pom.xml b/beacon-api/pom.xml index f28c790..b4ebb81 100644 --- a/beacon-api/pom.xml +++ b/beacon-api/pom.xml @@ -60,6 +60,12 @@ 1.0-SNAPSHOT + + + org.springframework.cloud + spring-cloud-starter-openfeign + + \ No newline at end of file diff --git a/beacon-api/src/main/java/com/mashibing/ApiStarterApp.java b/beacon-api/src/main/java/com/mashibing/ApiStarterApp.java index 6f4263a..0af7d4e 100644 --- a/beacon-api/src/main/java/com/mashibing/ApiStarterApp.java +++ b/beacon-api/src/main/java/com/mashibing/ApiStarterApp.java @@ -3,6 +3,7 @@ package com.mashibing; 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 dch @@ -10,6 +11,7 @@ import org.springframework.cloud.client.discovery.EnableDiscoveryClient; */ @SpringBootApplication @EnableDiscoveryClient +@EnableFeignClients public class ApiStarterApp { public static void main(String[] args) { diff --git a/beacon-api/src/main/java/com/mashibing/api/client/BeaconCacheClient.java b/beacon-api/src/main/java/com/mashibing/api/client/BeaconCacheClient.java new file mode 100644 index 0000000..9d4a1be --- /dev/null +++ b/beacon-api/src/main/java/com/mashibing/api/client/BeaconCacheClient.java @@ -0,0 +1,12 @@ +package com.mashibing.api.client; + +import org.springframework.cloud.openfeign.FeignClient; + +/** + * @author dch + * @create 2024-03-19 23:56 + */ +@FeignClient(value="beacon-cache") +public class BeaconCacheClient { + +} diff --git a/beacon-api/src/main/java/com/mashibing/api/controller/SmsController.java b/beacon-api/src/main/java/com/mashibing/api/controller/SmsController.java index 3574e5f..19a4381 100644 --- a/beacon-api/src/main/java/com/mashibing/api/controller/SmsController.java +++ b/beacon-api/src/main/java/com/mashibing/api/controller/SmsController.java @@ -1,10 +1,14 @@ package com.mashibing.api.controller; +import com.alibaba.cloud.commons.lang.StringUtils; import com.mashibing.api.enums.SmsCodeEnum; import com.mashibing.api.form.SingleSendForm; import com.mashibing.api.util.R; import com.mashibing.api.vo.ResultVO; +import com.mashibing.common.model.StandardSubmit; import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.cloud.context.config.annotation.RefreshScope; import org.springframework.validation.BindingResult; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.PostMapping; @@ -12,24 +16,153 @@ import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; +import javax.servlet.http.HttpServletRequest; + /** * @author dch * @create 2024-03-18 23:40 */ @RestController @RequestMapping("/sms") +@RefreshScope @Slf4j public class SmsController { + /** + * 客户端IP地址的请求头信息,多个用','隔开。 + */ + @Value("${headers}") + private String headers; + + /** + * 基于请求头获取信息时,可能获取到的未知信息 + */ + private final String UNKNOW = "unknow"; + + /** + * 如果是当前请求头获取IP地址,需要截取到第一个','未知 + */ + private final String X_FORWARDED_FOR = "x-forwarded-for"; + + private final String HEADERHOST = "host"; + - @PostMapping(value = "/single_send",produces = "application/json;charset=utf-8") - public ResultVO singleSend(@RequestBody @Validated SingleSendForm singleSendForm, BindingResult bindingResult){ + @PostMapping(value = "/single_send", produces = "application/json;charset=utf-8") + public ResultVO singleSend(@RequestBody @Validated SingleSendForm singleSendForm, BindingResult bindingResult, HttpServletRequest req) { //1. 校验参数 if (bindingResult.hasErrors()){ String msg = bindingResult.getFieldError().getDefaultMessage(); log.info("【接口模块-单条短信Controller】 参数不合法 msg = {}",msg); return R.error(SmsCodeEnum.PARAMETER_ERROR.getCode(),msg); } - //封装校验,构建submitcommon;发给mq,交给策略模块处理 - return R.ok(); } + //=========================获取真实的IP地址========================================= + String ip = this.getRealIP(req); + + //=========================构建StandardSubmit,各种封装校验========================================= + StandardSubmit submit = new StandardSubmit(); + submit.setRealIP(ip); + submit.setApikey(singleSendForm.getApikey()); + submit.setMobile(singleSendForm.getMobile()); + submit.setText(singleSendForm.getText()); + submit.setState(singleSendForm.getState()); + submit.setUid(singleSendForm.getUid()); + + //=========================发送到MQ,交给策略模块处理========================================= + return R.ok(); + } + + /** + * 获取客户端真实的IP地址 + * + * @param req + * @return + */ + private String getRealIP(HttpServletRequest req) { + + //1. 声明返回的ip地址 + String ip; + + //2. 遍历请求头,并且通过req获取ip地址 + for (String header : headers.split(",")) { + // 健壮性校验 + if (!StringUtils.isEmpty(header)) { + // 基于req获取ip地址 + ip = req.getHeader(header); + // 如果获取到的ip不为null,不为空串,并且不为unknow,就可以返回 + if (!StringUtils.isEmpty(ip) && !UNKNOW.equalsIgnoreCase(ip)) { + + // 判断请求头是否是host + if (HEADERHOST.equalsIgnoreCase(header)) { + ip = ip.contains(":") ? ip.substring(0, ip.indexOf(":")) : ip; + } + + + // 判断请求头是否是x-forwarded-for + if (X_FORWARDED_FOR.equalsIgnoreCase(header) && ip.indexOf(",") > 0) { + ip = ip.substring(0,ip.indexOf(",")); + } + // 返回IP地址 + return ip; + } + } + } + + //3. 如果请求头都没有获取到IP地址,直接基于传统的方式获取一个IP + return req.getRemoteAddr(); + + + + + + /* + //0. 声明真实IP地址 + String ip; + + //虚拟机取host + ip = req.getHeader("host"); + if (StringUtils.isNotEmpty(ip)) + return ip.contains(":") ? ip.substring(0, ip.indexOf(":")) : ip; + + + //1. 基于x-forwarded-for请求头获取IP地址 + String ips = req.getHeader("x-forwarded-for"); + // 直接基于第一个,的位置,截取需要的IP地址 + if (StringUtils.isNotEmpty(ips)) { + if (ips.contains(",")) { + return ips.substring(0, ips.indexOf(",")); + } else { + return ips; + } + } + + // 2. 基于请求头获取IP地址,基于request请求头获取信息时,除了null和空串外,还有可能拿到unknow, + ip = req.getHeader("x-real-ip"); + if (StringUtils.isEmpty(ip) || "unknow".equalsIgnoreCase(ip)) { + // x-real-ip没拿到,考虑一下其他的代理服务器 + //3. Apache的服务器,请求头中携带真实IP的名称是 proxy-client-ip + ip = req.getHeader("proxy-client-ip"); + } + + //4. 如果real没有拿到,判断apache是否拿到了。 + if (StringUtils.isEmpty(ip) || "unknow".equalsIgnoreCase(ip)) { + // 5. 如果Apache服务器没拿到,考虑一手WebLogic, wl-proxy-client-ip + ip = req.getHeader("wl-proxy-client-ip"); + } + + //6. 判断WebLogic有木有拿到IP + if (StringUtils.isEmpty(ip) || "unknow".equalsIgnoreCase(ip)) { + //7. 基于其他的代理服务器的方式获取请求头的IP地址 + ip = req.getHeader("http_client_ip"); + } + //8. 如果上诉方式都获取不到, + if (StringUtils.isEmpty(ip) || "unknow".equalsIgnoreCase(ip)) { + // 9. 基于传统方式获取IP + ip = req.getRemoteAddr(); + } + //10. 返回 + return ip;*/ + + + } + } \ No newline at end of file diff --git a/beacon-api/target/classes/com/mashibing/api/controller/SmsController.class b/beacon-api/target/classes/com/mashibing/api/controller/SmsController.class index 510420a284df477b5a7bf4fbab853a1ce486c8af..497e6682d77a3774236e94f7afa057e831b0913d 100644 GIT binary patch literal 3816 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 diff --git a/beacon-cache/pom.xml b/beacon-cache/pom.xml new file mode 100644 index 0000000..f9b5d33 --- /dev/null +++ b/beacon-cache/pom.xml @@ -0,0 +1,52 @@ + + + 4.0.0 + + com.mashibing + beacon-cloud + 1.0-SNAPSHOT + + + beacon-cache + + + 8 + 8 + UTF-8 + + + + + + org.springframework.boot + spring-boot-starter-web + + + + com.alibaba.cloud + spring-cloud-starter-alibaba-nacos-discovery + + + + com.alibaba.cloud + spring-cloud-starter-alibaba-nacos-config + + + + + + com.msb.cloud + horse-framework-starter-redis + 1.0.0 + + + + + \ No newline at end of file diff --git a/beacon-cache/src/main/java/com/mashibing/cache/CacheStarterApp.java b/beacon-cache/src/main/java/com/mashibing/cache/CacheStarterApp.java new file mode 100644 index 0000000..b129831 --- /dev/null +++ b/beacon-cache/src/main/java/com/mashibing/cache/CacheStarterApp.java @@ -0,0 +1,19 @@ +package com.mashibing.cache; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.cloud.client.discovery.EnableDiscoveryClient; + +/** + * @author dch + * @create 2024-03-19 20:00 + */ +@SpringBootApplication +@EnableDiscoveryClient +public class CacheStarterApp { + + public static void main(String[] args) { + SpringApplication.run(CacheStarterApp.class,args); + } + +} \ No newline at end of file diff --git a/beacon-cache/src/main/java/com/mashibing/cache/config/RedisConfig.java b/beacon-cache/src/main/java/com/mashibing/cache/config/RedisConfig.java new file mode 100644 index 0000000..80a136c --- /dev/null +++ b/beacon-cache/src/main/java/com/mashibing/cache/config/RedisConfig.java @@ -0,0 +1,80 @@ +package com.mashibing.cache.config; + +import com.fasterxml.jackson.databind.Module; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; +import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateDeserializer; +import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer; +import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateSerializer; +import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.data.redis.connection.RedisConnectionFactory; +import org.springframework.data.redis.core.RedisTemplate; +import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer; +import org.springframework.data.redis.serializer.RedisSerializer; + +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; + +/** + * 设置RedisTemplate的序列化方式 + * @author zjw + * @description + */ +/* + +@Configuration +public class RedisConfig { + + @Bean + public RedisTemplate redisTemplate(RedisConnectionFactory factory,RedisSerializer redisSerializer){ + //1. 构建RedisTemplate对象 + RedisTemplate redisTemplate = new RedisTemplate<>(); + + //2. 设置RedisConnectionFactory到RedisTemplate + redisTemplate.setConnectionFactory(factory); + + //3. 设置Redis的key的序列化方式 + redisTemplate.setKeySerializer(RedisSerializer.string()); + redisTemplate.setHashKeySerializer(RedisSerializer.string()); + + //4. 设置Redis的value的序列化方式 Date + redisTemplate.setValueSerializer(redisSerializer); + redisTemplate.setHashValueSerializer(redisSerializer); + + //5. 保证生效 + redisTemplate.afterPropertiesSet(); + + //6. 返回RedisTemplate + return redisTemplate; + } + + @Bean + public RedisSerializer redisSerializer(){ + //1. 构建Jackson的ObjectMapper + ObjectMapper objectMapper = new ObjectMapper(); + + //2. 设置JDK8日期格式的支持 + DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); + DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); + Module timeModule = new JavaTimeModule() + .addDeserializer(LocalDate.class,new LocalDateDeserializer(dateFormatter)) + .addDeserializer(LocalDateTime.class,new LocalDateTimeDeserializer(dateTimeFormatter)) + .addSerializer(LocalDate.class,new LocalDateSerializer(dateFormatter)) + .addSerializer(LocalDateTime.class,new LocalDateTimeSerializer(dateTimeFormatter)); + objectMapper.registerModule(timeModule); + + //3. 构建Jackson2JsonRedisSerializer + Jackson2JsonRedisSerializer jackson2JsonRedisSerializer = new Jackson2JsonRedisSerializer(Object.class); + + //4. 设置好对JDK8日期的支持 + jackson2JsonRedisSerializer.setObjectMapper(objectMapper); + + //5. 返回设置好的Jackson2JsonRedisSerializer + return jackson2JsonRedisSerializer; + } + + +}*/ diff --git a/beacon-cache/src/main/java/com/mashibing/cache/controller/CacheController.java b/beacon-cache/src/main/java/com/mashibing/cache/controller/CacheController.java new file mode 100644 index 0000000..801a9d6 --- /dev/null +++ b/beacon-cache/src/main/java/com/mashibing/cache/controller/CacheController.java @@ -0,0 +1,39 @@ +package com.mashibing.cache.controller; + +import com.msb.framework.redis.RedisClient; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +import java.util.Map; + +/** + * @author dch + * @create 2024-03-20 0:52 + */ +@RestController +@Slf4j +public class CacheController { + @Autowired + private RedisClient redisClient; + + @PostMapping(value = "/cache/hmset/{key}") + public void hmset(@PathVariable(value = "key")String key, @RequestBody Map map){ + log.info("【缓存模块】 hmset方法,存储key = {},存储value = {}",key,map); + redisClient.hSet(key,map); + } + + @PostMapping(value = "/cache/set/{key}") + public void set(@PathVariable(value = "key")String key, @RequestParam(value = "value")Object value){ + log.info("【缓存模块】 set方法,存储key = {},存储value = {}",key,value); + redisClient.set(key,value); + } + + @PostMapping(value = "/cache/sadd/{key}") + public void sadd(@PathVariable(value = "key")String key, @RequestBody Map... value){ + log.info("【缓存模块】 sadd方法,存储key = {},存储value = {}", key, value); + redisClient.sAdd(key,value); + } + + +} diff --git a/beacon-cache/src/main/java/com/mashibing/cache/controller/TestController.java b/beacon-cache/src/main/java/com/mashibing/cache/controller/TestController.java new file mode 100644 index 0000000..b1bad06 --- /dev/null +++ b/beacon-cache/src/main/java/com/mashibing/cache/controller/TestController.java @@ -0,0 +1,35 @@ +package com.mashibing.cache.controller; + +import com.msb.framework.redis.RedisClient; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.redis.core.RedisTemplate; +import org.springframework.web.bind.annotation.*; + +import java.util.Map; + +/** + * @author dch + * @create 2024-03-19 19:59 + */ +@RestController +public class TestController { + + @Autowired +// private RedisTemplate redisTemplate; + private RedisClient redisClient; + + // 写测试 hash结构 + @PostMapping("/test/set/{key}") + public String set(@PathVariable String key, @RequestBody Map map){ +// redisTemplate.opsForHash().putAll(key,map); + redisClient.hSet(key,map); + return "ok"; + } + // 读测试 + @GetMapping("/test/get/{key}") + public Map get(@PathVariable String key){ +// Map result = redisTemplate.opsForHash().entries(key); + Map result = redisClient.hGetAll(key); + return result; + } +} \ No newline at end of file diff --git a/beacon-cache/src/main/resources/bootstrap.yml b/beacon-cache/src/main/resources/bootstrap.yml new file mode 100644 index 0000000..4b85102 --- /dev/null +++ b/beacon-cache/src/main/resources/bootstrap.yml @@ -0,0 +1,17 @@ +# 服务名称 +spring: + application: + name: beacon-cache + # 多环境 + profiles: + active: dev + # nacos注册中心地址 + cloud: + nacos: + discovery: + server-addr: 192.168.43.132:8848 + # nacos配置中心地址: + config: + server-addr: 192.168.43.132:8848 + file-extension: yml + # beacon-cache-dev.yml diff --git a/beacon-common/src/main/java/com/mashibing/common/model/StandardSubmit.java b/beacon-common/src/main/java/com/mashibing/common/model/StandardSubmit.java index c359111..7fa2555 100644 --- a/beacon-common/src/main/java/com/mashibing/common/model/StandardSubmit.java +++ b/beacon-common/src/main/java/com/mashibing/common/model/StandardSubmit.java @@ -93,6 +93,17 @@ public class StandardSubmit { */ private int reportState; - // 后续再做封装~~~~ +/** + 真实的IP地址 +*/ + private String realIP; + +/** 请求携带的apiKey封装*/ + private String apikey; + +/** + 短信的类型 0-验证码短信 1-通知类 3-营销类 +*/ + private Integer state; } \ No newline at end of file diff --git a/beacon-test/pom.xml b/beacon-test/pom.xml new file mode 100644 index 0000000..6318388 --- /dev/null +++ b/beacon-test/pom.xml @@ -0,0 +1,58 @@ + + + 4.0.0 + + com.mashibing + beacon-cloud + 1.0-SNAPSHOT + + + beacon-test + + + 8 + 8 + UTF-8 + + + + + org.springframework.boot + spring-boot-starter-web + + + org.springframework.boot + spring-boot-test + + + com.alibaba.cloud + spring-cloud-starter-alibaba-nacos-discovery + + + org.springframework.cloud + spring-cloud-starter-openfeign + + + org.mybatis.spring.boot + mybatis-spring-boot-starter + 2.2.2 + + + mysql + mysql-connector-java + 5.1.49 + + + junit + junit + test + + + org.springframework + spring-test + test + + + \ No newline at end of file diff --git a/beacon-test/src/main/java/com/mashibing/test/TestStarterApp.java b/beacon-test/src/main/java/com/mashibing/test/TestStarterApp.java new file mode 100644 index 0000000..35b7224 --- /dev/null +++ b/beacon-test/src/main/java/com/mashibing/test/TestStarterApp.java @@ -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 dch + * @create 2024-03-20 0:15 + */ +@SpringBootApplication +@EnableDiscoveryClient +@EnableFeignClients +@MapperScan(basePackages = "com.mashibing.test.mapper") +public class TestStarterApp { + + public static void main(String[] args) { + SpringApplication.run(TestStarterApp.class,args); + } +} diff --git a/beacon-test/src/main/java/com/mashibing/test/client/CacheClient.java b/beacon-test/src/main/java/com/mashibing/test/client/CacheClient.java new file mode 100644 index 0000000..c0f7280 --- /dev/null +++ b/beacon-test/src/main/java/com/mashibing/test/client/CacheClient.java @@ -0,0 +1,27 @@ +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; + +/** + * @author dch + * @create 2024-03-20 0:50 + */ +@FeignClient(value = "beacon-cache") +public interface CacheClient { + + @PostMapping(value = "/cache/hmset/{key}") + void hmset(@PathVariable(value = "key")String key, @RequestBody Map 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... maps); + +} diff --git a/beacon-test/src/main/java/com/mashibing/test/entity/ClientBalance.java b/beacon-test/src/main/java/com/mashibing/test/entity/ClientBalance.java new file mode 100644 index 0000000..ae0e7ce --- /dev/null +++ b/beacon-test/src/main/java/com/mashibing/test/entity/ClientBalance.java @@ -0,0 +1,144 @@ +package com.mashibing.test.entity; + + +public class ClientBalance { + + private long id; + private long clientId; + private long balance; + private java.sql.Timestamp created; + private long createId; + private java.sql.Timestamp updated; + private long updateId; + private long isDelete; + private String extend1; + private String extend2; + private String extend3; + private String extend4; + + + public long getId() { + return id; + } + + public void setId(long id) { + this.id = id; + } + + + public long getClientId() { + return clientId; + } + + public void setClientId(long clientId) { + this.clientId = clientId; + } + + + public long getBalance() { + return balance; + } + + public void setBalance(long balance) { + this.balance = balance; + } + + + public java.sql.Timestamp getCreated() { + return created; + } + + public void setCreated(java.sql.Timestamp created) { + this.created = created; + } + + + public long getCreateId() { + return createId; + } + + public void setCreateId(long createId) { + this.createId = createId; + } + + + public java.sql.Timestamp getUpdated() { + return updated; + } + + public void setUpdated(java.sql.Timestamp updated) { + this.updated = updated; + } + + + public long getUpdateId() { + return updateId; + } + + public void setUpdateId(long updateId) { + this.updateId = updateId; + } + + + public long getIsDelete() { + return isDelete; + } + + public void setIsDelete(long isDelete) { + this.isDelete = isDelete; + } + + + public String getExtend1() { + return extend1; + } + + public void setExtend1(String extend1) { + this.extend1 = extend1; + } + + + public String getExtend2() { + return extend2; + } + + public void setExtend2(String extend2) { + this.extend2 = extend2; + } + + + public String getExtend3() { + return extend3; + } + + public void setExtend3(String extend3) { + this.extend3 = extend3; + } + + + public String getExtend4() { + return extend4; + } + + public void setExtend4(String extend4) { + this.extend4 = extend4; + } + + @Override + public String toString() { + return "ClientBalance{" + + "id=" + id + + ", clientId=" + clientId + + ", balance=" + balance + + ", created=" + created + + ", createId=" + createId + + ", updated=" + updated + + ", updateId=" + updateId + + ", isDelete=" + isDelete + + ", extend1='" + extend1 + '\'' + + ", extend2='" + extend2 + '\'' + + ", extend3='" + extend3 + '\'' + + ", extend4='" + extend4 + '\'' + + '}'; + } +} diff --git a/beacon-test/src/main/java/com/mashibing/test/entity/ClientBusiness.java b/beacon-test/src/main/java/com/mashibing/test/entity/ClientBusiness.java new file mode 100644 index 0000000..e2c223c --- /dev/null +++ b/beacon-test/src/main/java/com/mashibing/test/entity/ClientBusiness.java @@ -0,0 +1,210 @@ +package com.mashibing.test.entity; + + +public class ClientBusiness { + + private long id; + private String corpname; + private String apikey; + private String ipAddress; + private long isCallback; + private String callbackUrl; + private String clientLinkname; + private String clientPhone; + private String clientFilters; + private java.sql.Timestamp created; + private long createId; + private java.sql.Timestamp updated; + private long updateId; + private long isDelete; + private String extend1; + private String extend2; + private String extend3; + private String extend4; + + + public long getId() { + return id; + } + + public void setId(long id) { + this.id = id; + } + + + public String getCorpname() { + return corpname; + } + + public void setCorpname(String corpname) { + this.corpname = corpname; + } + + + public String getApikey() { + return apikey; + } + + public void setApikey(String apikey) { + this.apikey = apikey; + } + + + public String getIpAddress() { + return ipAddress; + } + + public void setIpAddress(String ipAddress) { + this.ipAddress = ipAddress; + } + + + public long getIsCallback() { + return isCallback; + } + + public void setIsCallback(long isCallback) { + this.isCallback = isCallback; + } + + + public String getCallbackUrl() { + return callbackUrl; + } + + public void setCallbackUrl(String callbackUrl) { + this.callbackUrl = callbackUrl; + } + + + public String getClientLinkname() { + return clientLinkname; + } + + public void setClientLinkname(String clientLinkname) { + this.clientLinkname = clientLinkname; + } + + + public String getClientPhone() { + return clientPhone; + } + + public void setClientPhone(String clientPhone) { + this.clientPhone = clientPhone; + } + + + public String getClientFilters() { + return clientFilters; + } + + public void setClientFilters(String clientFilters) { + this.clientFilters = clientFilters; + } + + + public java.sql.Timestamp getCreated() { + return created; + } + + public void setCreated(java.sql.Timestamp created) { + this.created = created; + } + + + public long getCreateId() { + return createId; + } + + public void setCreateId(long createId) { + this.createId = createId; + } + + + public java.sql.Timestamp getUpdated() { + return updated; + } + + public void setUpdated(java.sql.Timestamp updated) { + this.updated = updated; + } + + + public long getUpdateId() { + return updateId; + } + + public void setUpdateId(long updateId) { + this.updateId = updateId; + } + + + public long getIsDelete() { + return isDelete; + } + + public void setIsDelete(long isDelete) { + this.isDelete = isDelete; + } + + + public String getExtend1() { + return extend1; + } + + public void setExtend1(String extend1) { + this.extend1 = extend1; + } + + + public String getExtend2() { + return extend2; + } + + public void setExtend2(String extend2) { + this.extend2 = extend2; + } + + + public String getExtend3() { + return extend3; + } + + public void setExtend3(String extend3) { + this.extend3 = extend3; + } + + + public String getExtend4() { + return extend4; + } + + public void setExtend4(String extend4) { + this.extend4 = extend4; + } + + @Override + public String toString() { + return "ClientBusiness{" + + "id=" + id + + ", corpname='" + corpname + '\'' + + ", apikey='" + apikey + '\'' + + ", ipAddress='" + ipAddress + '\'' + + ", isCallback=" + isCallback + + ", callbackUrl='" + callbackUrl + '\'' + + ", clientLinkname='" + clientLinkname + '\'' + + ", clientPhone='" + clientPhone + '\'' + + ", clientFilters='" + clientFilters + '\'' + + ", created=" + created + + ", createId=" + createId + + ", updated=" + updated + + ", updateId=" + updateId + + ", isDelete=" + isDelete + + ", extend1='" + extend1 + '\'' + + ", extend2='" + extend2 + '\'' + + ", extend3='" + extend3 + '\'' + + ", extend4='" + extend4 + '\'' + + '}'; + } +} diff --git a/beacon-test/src/main/java/com/mashibing/test/entity/ClientSign.java b/beacon-test/src/main/java/com/mashibing/test/entity/ClientSign.java new file mode 100644 index 0000000..9788467 --- /dev/null +++ b/beacon-test/src/main/java/com/mashibing/test/entity/ClientSign.java @@ -0,0 +1,199 @@ +package com.mashibing.test.entity; + + +public class ClientSign { + + private long id; + private long clientId; + private String signInfo; + private long signState; + private long signType; + private String businessWeb; + private String proveDescr; + private String proveFile; + private java.sql.Timestamp created; + private long createId; + private java.sql.Timestamp updated; + private long updateId; + private long isDelete; + private String extend1; + private String extend2; + private String extend3; + private String extend4; + + + public long getId() { + return id; + } + + public void setId(long id) { + this.id = id; + } + + + public long getClientId() { + return clientId; + } + + public void setClientId(long clientId) { + this.clientId = clientId; + } + + + public String getSignInfo() { + return signInfo; + } + + public void setSignInfo(String signInfo) { + this.signInfo = signInfo; + } + + + public long getSignState() { + return signState; + } + + public void setSignState(long signState) { + this.signState = signState; + } + + + public long getSignType() { + return signType; + } + + public void setSignType(long signType) { + this.signType = signType; + } + + + public String getBusinessWeb() { + return businessWeb; + } + + public void setBusinessWeb(String businessWeb) { + this.businessWeb = businessWeb; + } + + + public String getProveDescr() { + return proveDescr; + } + + public void setProveDescr(String proveDescr) { + this.proveDescr = proveDescr; + } + + + public String getProveFile() { + return proveFile; + } + + public void setProveFile(String proveFile) { + this.proveFile = proveFile; + } + + + public java.sql.Timestamp getCreated() { + return created; + } + + public void setCreated(java.sql.Timestamp created) { + this.created = created; + } + + + public long getCreateId() { + return createId; + } + + public void setCreateId(long createId) { + this.createId = createId; + } + + + public java.sql.Timestamp getUpdated() { + return updated; + } + + public void setUpdated(java.sql.Timestamp updated) { + this.updated = updated; + } + + + public long getUpdateId() { + return updateId; + } + + public void setUpdateId(long updateId) { + this.updateId = updateId; + } + + + public long getIsDelete() { + return isDelete; + } + + public void setIsDelete(long isDelete) { + this.isDelete = isDelete; + } + + + public String getExtend1() { + return extend1; + } + + public void setExtend1(String extend1) { + this.extend1 = extend1; + } + + + public String getExtend2() { + return extend2; + } + + public void setExtend2(String extend2) { + this.extend2 = extend2; + } + + + public String getExtend3() { + return extend3; + } + + public void setExtend3(String extend3) { + this.extend3 = extend3; + } + + + public String getExtend4() { + return extend4; + } + + public void setExtend4(String extend4) { + this.extend4 = extend4; + } + + @Override + public String toString() { + return "ClientSign{" + + "id=" + id + + ", clientId=" + clientId + + ", signInfo='" + signInfo + '\'' + + ", signState=" + signState + + ", signType=" + signType + + ", businessWeb='" + businessWeb + '\'' + + ", proveDescr='" + proveDescr + '\'' + + ", proveFile='" + proveFile + '\'' + + ", created=" + created + + ", createId=" + createId + + ", updated=" + updated + + ", updateId=" + updateId + + ", isDelete=" + isDelete + + ", extend1='" + extend1 + '\'' + + ", extend2='" + extend2 + '\'' + + ", extend3='" + extend3 + '\'' + + ", extend4='" + extend4 + '\'' + + '}'; + } +} 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 new file mode 100644 index 0000000..34d0176 --- /dev/null +++ b/beacon-test/src/main/java/com/mashibing/test/entity/ClientTemplate.java @@ -0,0 +1,188 @@ +package com.mashibing.test.entity; + + +public class ClientTemplate { + + private long id; + private long signId; + private String templateText; + private long templateType; + private long templateState; + private long useId; + private String useWeb; + private java.sql.Timestamp created; + private long createId; + private java.sql.Timestamp updated; + private long updateId; + private long isDelete; + private String extend1; + private String extend2; + private String extend3; + private String extend4; + + + public long getId() { + return id; + } + + public void setId(long id) { + this.id = id; + } + + + public long getSignId() { + return signId; + } + + public void setSignId(long signId) { + this.signId = signId; + } + + + public String getTemplateText() { + return templateText; + } + + public void setTemplateText(String templateText) { + this.templateText = templateText; + } + + + public long getTemplateType() { + return templateType; + } + + public void setTemplateType(long templateType) { + this.templateType = templateType; + } + + + public long getTemplateState() { + return templateState; + } + + public void setTemplateState(long templateState) { + this.templateState = templateState; + } + + + public long getUseId() { + return useId; + } + + public void setUseId(long useId) { + this.useId = useId; + } + + + public String getUseWeb() { + return useWeb; + } + + public void setUseWeb(String useWeb) { + this.useWeb = useWeb; + } + + + public java.sql.Timestamp getCreated() { + return created; + } + + public void setCreated(java.sql.Timestamp created) { + this.created = created; + } + + + public long getCreateId() { + return createId; + } + + public void setCreateId(long createId) { + this.createId = createId; + } + + + public java.sql.Timestamp getUpdated() { + return updated; + } + + public void setUpdated(java.sql.Timestamp updated) { + this.updated = updated; + } + + + public long getUpdateId() { + return updateId; + } + + public void setUpdateId(long updateId) { + this.updateId = updateId; + } + + + public long getIsDelete() { + return isDelete; + } + + public void setIsDelete(long isDelete) { + this.isDelete = isDelete; + } + + + public String getExtend1() { + return extend1; + } + + public void setExtend1(String extend1) { + this.extend1 = extend1; + } + + + public String getExtend2() { + return extend2; + } + + public void setExtend2(String extend2) { + this.extend2 = extend2; + } + + + public String getExtend3() { + return extend3; + } + + public void setExtend3(String extend3) { + this.extend3 = extend3; + } + + + public String getExtend4() { + return extend4; + } + + public void setExtend4(String extend4) { + this.extend4 = extend4; + } + + @Override + public String toString() { + return "ClientTemplate{" + + "id=" + id + + ", signId=" + signId + + ", templateText='" + templateText + '\'' + + ", templateType=" + templateType + + ", templateState=" + templateState + + ", useId=" + useId + + ", useWeb='" + useWeb + '\'' + + ", created=" + created + + ", createId=" + createId + + ", updated=" + updated + + ", updateId=" + updateId + + ", isDelete=" + isDelete + + ", extend1='" + extend1 + '\'' + + ", extend2='" + extend2 + '\'' + + ", extend3='" + extend3 + '\'' + + ", extend4='" + extend4 + '\'' + + '}'; + } +} 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..1ed344c --- /dev/null +++ b/beacon-test/src/main/java/com/mashibing/test/mapper/ClientBalanceMapper.java @@ -0,0 +1,14 @@ +package com.mashibing.test.mapper; + +import org.apache.ibatis.annotations.Param; +import org.apache.ibatis.annotations.Select; + +/** + * @author dch + * @create 2024-03-20 1:28 + */ +public interface ClientBalanceMapper { + @Select("select balance from client_balance where client_id = #{clientId}") + Long findByClientId(@Param("clientId")Long clientId); + +} diff --git a/beacon-test/src/main/java/com/mashibing/test/mapper/ClientBusinessMapper.java b/beacon-test/src/main/java/com/mashibing/test/mapper/ClientBusinessMapper.java new file mode 100644 index 0000000..7b304c0 --- /dev/null +++ b/beacon-test/src/main/java/com/mashibing/test/mapper/ClientBusinessMapper.java @@ -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 dch + * @create 2024-03-20 0:19 + */ +public interface ClientBusinessMapper { + + @Select("select * from client_business where id = #{id}") + ClientBusiness findById(@Param("id") Long id); + +} diff --git a/beacon-test/src/main/java/com/mashibing/test/mapper/ClientSignMapper.java b/beacon-test/src/main/java/com/mashibing/test/mapper/ClientSignMapper.java new file mode 100644 index 0000000..c5469d8 --- /dev/null +++ b/beacon-test/src/main/java/com/mashibing/test/mapper/ClientSignMapper.java @@ -0,0 +1,16 @@ +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 dch + * @create 2024-03-20 1:06 + */ +public interface ClientSignMapper { + @Select("select * from client_sign where client_id = #{clientId}") + List findByClientId(@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..b3dbcd3 --- /dev/null +++ b/beacon-test/src/main/java/com/mashibing/test/mapper/ClientTemplateMapper.java @@ -0,0 +1,17 @@ +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 dch + * @create 2024-03-20 1:24 + */ +public interface ClientTemplateMapper { + @Select("select * from client_template where sign_id = #{signId}") + List findBySignId(@Param("signId") Long signId); + +} diff --git a/beacon-test/src/main/resources/application.yml b/beacon-test/src/main/resources/application.yml new file mode 100644 index 0000000..7a16174 --- /dev/null +++ b/beacon-test/src/main/resources/application.yml @@ -0,0 +1,23 @@ +# 服务名 +spring: + application: + name: beacon-test + # nacos地址 + cloud: + nacos: + discovery: + server-addr: 192.168.43.132:8848 + # datasource + datasource: + driver-class-name: org.gjt.mm.mysql.Driver + url: jdbc:mysql://localhost:3306/beacon_cloud?characterEncoding=utf-8&useSSL=false + username: root + password: 1234 +# 端口号 +server: + port: 20000 + +# mybatis +mybatis: + configuration: + map-underscore-to-camel-case: true \ No newline at end of file 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..96606e7 --- /dev/null +++ b/beacon-test/src/test/java/com/mashibing/test/mapper/ClientBalanceMapperTest.java @@ -0,0 +1,33 @@ +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.*; + +/** + * @author dch + * @create 2024-03-20 1:29 + */ +@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); + } +} \ 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 new file mode 100644 index 0000000..eceba25 --- /dev/null +++ b/beacon-test/src/test/java/com/mashibing/test/mapper/ClientBusinessMapperTest.java @@ -0,0 +1,40 @@ +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.ClientBusiness; +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.Map; + +import static org.junit.Assert.*; + +/** + * @author dch + * @create 2024-03-20 0:36 + */ +@SpringBootTest +@RunWith(SpringRunner.class) +public class ClientBusinessMapperTest { + + @Autowired + private ClientBusinessMapper mapper; + + @Autowired + private CacheClient cacheClient; + + @Test + public void findById() throws JsonProcessingException { + ClientBusiness cb = mapper.findById(1L); + ObjectMapper objectMapper = new ObjectMapper(); + Map map = objectMapper.readValue(objectMapper.writeValueAsString(cb), Map.class); + cacheClient.hmset("client_business:"+cb.getApikey(),map); + } + + +} \ No newline at end of file diff --git a/beacon-test/src/test/java/com/mashibing/test/mapper/ClientSignMapperTest.java b/beacon-test/src/test/java/com/mashibing/test/mapper/ClientSignMapperTest.java new file mode 100644 index 0000000..b684ab5 --- /dev/null +++ b/beacon-test/src/test/java/com/mashibing/test/mapper/ClientSignMapperTest.java @@ -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.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.*; + +/** + * @author dch + * @create 2024-03-20 1:08 + */ +@SpringBootTest +@RunWith(SpringRunner.class) +public class ClientSignMapperTest { + + + @Autowired + private CacheClient cacheClient; + + @Autowired + private ClientSignMapper mapper; + + @Test + public void findByClientId() { + List list = mapper.findByClientId(1L); + for (ClientSign clientSign : list) { + System.out.println(clientSign); + } + + ObjectMapper objectMapper = new ObjectMapper(); + List 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[]{})); + } +} \ No newline at end of file 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..1b3aecd --- /dev/null +++ b/beacon-test/src/test/java/com/mashibing/test/mapper/ClientTemplateMapperTest.java @@ -0,0 +1,56 @@ +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.SpringRunner; + +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +import static org.junit.Assert.*; + +/** + * @author dch + * @create 2024-03-20 1:25 + */ +@SpringBootTest +@RunWith(SpringRunner.class) +public class ClientTemplateMapperTest { + + @Autowired + private ClientTemplateMapper mapper; + + @Autowired + private CacheClient cacheClient; + + @Test + public void findBySignId() { + List ct1 = mapper.findBySignId(15L); + List ct2 = mapper.findBySignId(24L); + for (ClientTemplate clientTemplate : ct1) { + System.out.println(clientTemplate); + } + // ct2在现有的库中没有数据 + System.out.println(ct2); + + ObjectMapper objectMapper = new ObjectMapper(); + List 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[]{})); + } +} \ No newline at end of file diff --git a/pom.xml b/pom.xml index b02576f..0cbec28 100644 --- a/pom.xml +++ b/pom.xml @@ -17,11 +17,14 @@ beacon-api beacon-common + beacon-cache + beacon-test Hoxton.SR12 2.2.6.RELEASE + 1.0.0 @@ -39,6 +42,13 @@ pom import + + com.msb.cloud + horse-framework-starters + ${horse-version} + pom + import +