diff --git a/.idea/compiler.xml b/.idea/compiler.xml index 7c01407..1d89b37 100644 --- a/.idea/compiler.xml +++ b/.idea/compiler.xml @@ -10,9 +10,10 @@ - - + + + @@ -21,6 +22,7 @@ + \ 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 9fdddf8..497e668 100644 Binary files a/beacon-api/target/classes/com/mashibing/api/controller/SmsController.class and b/beacon-api/target/classes/com/mashibing/api/controller/SmsController.class differ diff --git a/beacon-cache/pom.xml b/beacon-cache/pom.xml index 2f8f85e..f9b5d33 100644 --- a/beacon-cache/pom.xml +++ b/beacon-cache/pom.xml @@ -2,15 +2,21 @@ + 4.0.0 - beacon-cloud com.mashibing + beacon-cloud 1.0-SNAPSHOT - 4.0.0 beacon-cache + + 8 + 8 + UTF-8 + + @@ -28,10 +34,19 @@ 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 index a647be4..b129831 100644 --- a/beacon-cache/src/main/java/com/mashibing/cache/CacheStarterApp.java +++ b/beacon-cache/src/main/java/com/mashibing/cache/CacheStarterApp.java @@ -6,7 +6,7 @@ import org.springframework.cloud.client.discovery.EnableDiscoveryClient; /** * @author dch - * @create 2024-03-19 14:34 + * @create 2024-03-19 20:00 */ @SpringBootApplication @EnableDiscoveryClient @@ -16,4 +16,4 @@ public class CacheStarterApp { 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 index 91436e3..80a136c 100644 --- a/beacon-cache/src/main/java/com/mashibing/cache/config/RedisConfig.java +++ b/beacon-cache/src/main/java/com/mashibing/cache/config/RedisConfig.java @@ -19,15 +19,17 @@ import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; /** - * 设置RedisTemplate的序列化方式 - * @author dch - * @create 2024-03-19 11:31 + * 设置RedisTemplate的序列化方式 + * @author zjw + * @description */ +/* + @Configuration public class RedisConfig { @Bean - public RedisTemplate redisTemplate(RedisConnectionFactory factory, RedisSerializer redisSerializer){ + public RedisTemplate redisTemplate(RedisConnectionFactory factory,RedisSerializer redisSerializer){ //1. 构建RedisTemplate对象 RedisTemplate redisTemplate = new RedisTemplate<>(); @@ -75,4 +77,4 @@ public class RedisConfig { } -} +}*/ 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 index 560613c..b1bad06 100644 --- a/beacon-cache/src/main/java/com/mashibing/cache/controller/TestController.java +++ b/beacon-cache/src/main/java/com/mashibing/cache/controller/TestController.java @@ -1,5 +1,6 @@ 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.*; @@ -8,24 +9,27 @@ import java.util.Map; /** * @author dch - * @create 2024-03-19 14:37 + * @create 2024-03-19 19:59 */ @RestController public class TestController { @Autowired - private RedisTemplate redisTemplate; +// 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); +// 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 = 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 index 9fee06a..4b85102 100644 --- a/beacon-cache/src/main/resources/bootstrap.yml +++ b/beacon-cache/src/main/resources/bootstrap.yml @@ -9,10 +9,9 @@ spring: cloud: nacos: discovery: - server-addr: 192.168.1.113:8848 + server-addr: 192.168.43.132:8848 # nacos配置中心地址: config: - server-addr: 192.168.1.113:8848 + 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 335f19d..0cbec28 100644 --- a/pom.xml +++ b/pom.xml @@ -18,11 +18,13 @@ beacon-api beacon-common beacon-cache + beacon-test Hoxton.SR12 2.2.6.RELEASE + 1.0.0 @@ -40,6 +42,13 @@ pom import + + com.msb.cloud + horse-framework-starters + ${horse-version} + pom + import +