烽火云长椿街3.20 1:35

master
DanielDeng 8 months ago
parent 60ee08880c
commit b198ad115c

@ -10,6 +10,8 @@
<sourceOutputDir name="target/generated-sources/annotations" />
<sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
<outputRelativeToContentRoot value="true" />
<module name="beacon-cache" />
<module name="beacon-test" />
<module name="beacon-api" />
<module name="beacon-common" />
</profile>
@ -18,7 +20,9 @@
<component name="JavacSettings">
<option name="ADDITIONAL_OPTIONS_OVERRIDE">
<module name="beacon-api" options="-parameters" />
<module name="beacon-cache" options="-parameters" />
<module name="beacon-common" options="-parameters" />
<module name="beacon-test" options="-parameters" />
</option>
</component>
</project>

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="DataSourceManagerImpl" format="xml" multifile-model="true">
<data-source source="LOCAL" name="beacon_cloud@localhost" uuid="702b1f07-0ea8-4a1f-b42e-119c036b73d5">
<driver-ref>mysql.8</driver-ref>
<synchronize>true</synchronize>
<jdbc-driver>com.mysql.cj.jdbc.Driver</jdbc-driver>
<jdbc-url>jdbc:mysql://localhost:3306/beacon_cloud</jdbc-url>
<working-dir>$ProjectFileDir$</working-dir>
</data-source>
</component>
</project>

@ -60,6 +60,12 @@
<version>1.0-SNAPSHOT</version>
</dependency>
<!-- 为了访问缓存模块需要配置OpenFeign-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>
</dependencies>
</project>

@ -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) {

@ -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 {
}

@ -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;*/
}
}

@ -0,0 +1,52 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.mashibing</groupId>
<artifactId>beacon-cloud</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<artifactId>beacon-cache</artifactId>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<!-- web项目-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- nacos注册中心-->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
</dependency>
<!-- nacos的配置中心-->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
</dependency>
<!-- data系列的redis依赖-->
<!--
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
-->
<dependency>
<groupId>com.msb.cloud</groupId>
<artifactId>horse-framework-starter-redis</artifactId>
<version>1.0.0</version>
</dependency>
</dependencies>
</project>

@ -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);
}
}

@ -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 <T> RedisTemplate<String,T> redisTemplate(RedisConnectionFactory factory,RedisSerializer<Object> redisSerializer){
//1. 构建RedisTemplate对象
RedisTemplate<String,T> 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<Object> 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;
}
}*/

@ -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<String,Object> 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<String,Object>... value){
log.info("【缓存模块】 sadd方法存储key = {}存储value = {}", key, value);
redisClient.sAdd(key,value);
}
}

@ -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<String,Object> 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<Object, Object> result = redisTemplate.opsForHash().entries(key);
Map<String, Object> result = redisClient.hGetAll(key);
return result;
}
}

@ -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

@ -93,6 +93,17 @@ public class StandardSubmit {
*/
private int reportState;
// 后续再做封装~~~~
/**
IP
*/
private String realIP;
/** 请求携带的apiKey封装*/
private String apikey;
/**
0- 1- 3-
*/
private Integer state;
}

@ -0,0 +1,58 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.mashibing</groupId>
<artifactId>beacon-cloud</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<artifactId>beacon-test</artifactId>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-test</artifactId>
</dependency>
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>2.2.2</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.49</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>

@ -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);
}
}

@ -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<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,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 + '\'' +
'}';
}
}

@ -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 + '\'' +
'}';
}
}

@ -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 + '\'' +
'}';
}
}

@ -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 + '\'' +
'}';
}
}

@ -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);
}

@ -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);
}

@ -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<ClientSign> findByClientId(@Param("clientId")Long clientId);
}

@ -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<ClientTemplate> findBySignId(@Param("signId") Long signId);
}

@ -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

@ -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);
}
}

@ -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);
}
}

@ -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<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,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<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[]{}));
}
}

@ -17,11 +17,14 @@
<module>beacon-api</module>
<module>beacon-common</module>
<module>beacon-cache</module>
<module>beacon-test</module>
</modules>
<properties>
<spring.cloud-version>Hoxton.SR12</spring.cloud-version>
<spring.cloud.alibaba-version>2.2.6.RELEASE</spring.cloud.alibaba-version>
<horse-version>1.0.0</horse-version>
</properties>
<dependencyManagement>
<dependencies>
@ -39,6 +42,13 @@
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>com.msb.cloud</groupId>
<artifactId>horse-framework-starters</artifactId>
<version>${horse-version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

Loading…
Cancel
Save