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 060e9a0..1f406bb 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,15 +1,20 @@ package com.mashibing.api.controller; import com.mashibing.api.pojo.SingleSendRequest; +import com.mashibing.api.service.SmsService; import com.mashibing.api.service.sendCheck.SendCheckContext; import com.mashibing.common.pojo.JsonResult; +import com.mashibing.common.pojo.StandardSubmit; import com.mashibing.common.utils.JsonResultUtil; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; 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.*; +import javax.servlet.http.HttpServletRequest; import javax.validation.Valid; /** @@ -19,6 +24,7 @@ import javax.validation.Valid; * @date 2025/6/4 18:58 */ +@Slf4j @RestController @RequestMapping("sms") @RefreshScope @@ -27,14 +33,27 @@ public class SMSController { @Autowired SendCheckContext sendCheckContext; + @Autowired + SmsService smsService; + @PostMapping("singleSend") - public JsonResult singleSend(@RequestBody @Validated SingleSendRequest request) { + public JsonResult singleSend(@RequestBody @Validated SingleSendRequest request, + HttpServletRequest httpServletRequest) { sendCheckContext.check(request); - //TODO 构建StandardSubmit,各种业务处理 + //获取真实ip + String realIp = smsService.getRealIP(httpServletRequest); + + log.info("real ip: {}", realIp); + //TODO 构建StandardSubmit,各种业务处理 + StandardSubmit standardSubmit = new StandardSubmit(); + standardSubmit.setRealIp(realIp); + BeanUtils.copyProperties(request, standardSubmit); //TODO 发送到MQ return JsonResultUtil.ok(); } + + } diff --git a/beacon-api/src/main/java/com/mashibing/api/pojo/SingleSendRequest.java b/beacon-api/src/main/java/com/mashibing/api/pojo/SingleSendRequest.java index b0c1cb5..640a7f3 100644 --- a/beacon-api/src/main/java/com/mashibing/api/pojo/SingleSendRequest.java +++ b/beacon-api/src/main/java/com/mashibing/api/pojo/SingleSendRequest.java @@ -46,7 +46,7 @@ public class SingleSendRequest { @NotNull(message = "短信类型state不能为空") @Min(value = 0, message = "短信类型state必须在0-2之间") @Max(value = 2, message = "短信类型state必须在0-2之间") - private String state; + private Integer state; } diff --git a/beacon-api/src/main/java/com/mashibing/api/service/SmsService.java b/beacon-api/src/main/java/com/mashibing/api/service/SmsService.java new file mode 100644 index 0000000..c0a4d5c --- /dev/null +++ b/beacon-api/src/main/java/com/mashibing/api/service/SmsService.java @@ -0,0 +1,15 @@ +package com.mashibing.api.service; + +import javax.servlet.http.HttpServletRequest; + +/** + * @author heqijun + * @ClassName: SmsService + * @Description: TODO(这里用一句话描述这个类的作用) + * @date 2025/6/5 16:56 + */ + +public interface SmsService { + + String getRealIP(HttpServletRequest request); +} diff --git a/beacon-api/src/main/java/com/mashibing/api/service/impl/SmsServiceImpl.java b/beacon-api/src/main/java/com/mashibing/api/service/impl/SmsServiceImpl.java new file mode 100644 index 0000000..7d408e9 --- /dev/null +++ b/beacon-api/src/main/java/com/mashibing/api/service/impl/SmsServiceImpl.java @@ -0,0 +1,42 @@ +package com.mashibing.api.service.impl; + +import com.mashibing.api.service.SmsService; +import com.mashibing.common.constant.SMSConstant; +import org.apache.commons.lang.StringUtils; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.cloud.context.config.annotation.RefreshScope; +import org.springframework.stereotype.Service; + +import javax.servlet.http.HttpServletRequest; + +/** + * @author heqijun + * @ClassName: SmsServiceImpl + * @Description: TODO(这里用一句话描述这个类的作用) + * @date 2025/6/5 16:57 + */ + +@Service +@RefreshScope +public class SmsServiceImpl implements SmsService { + + @Value("${headers}") + private String[] headers; + + @Override + public String getRealIP(HttpServletRequest request) { + + String ip; + for (String header : headers) { + if (StringUtils.isNotBlank(header)) { + ip = request.getHeader(header); + if (StringUtils.isNotBlank(ip) && !SMSConstant.UNKNOWN.equalsIgnoreCase(ip)) { + ip = (SMSConstant.X_FORWARDED_FOR.equalsIgnoreCase(header) && ip.indexOf(",") > 0) ? ip.split(",")[0] : ip; + return ip; + } + } + } + ip = request.getRemoteAddr(); + return ip; + } +} diff --git a/beacon-api/src/main/resources/bootstrap.yml b/beacon-api/src/main/resources/bootstrap.yml index fd3e373..f9a0ab8 100644 --- a/beacon-api/src/main/resources/bootstrap.yml +++ b/beacon-api/src/main/resources/bootstrap.yml @@ -9,9 +9,9 @@ spring: cloud: nacos: discovery: - server-addr: 192.168.1.13:8848 + server-addr: 192.168.1.10:8848 # nacos配置中心地址: config: - server-addr: 192.168.1.13:8848 + server-addr: 192.168.1.10:8848 file-extension: yml # beacon-api-dev.yml \ No newline at end of file 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 index 4f5b59b..fd39d54 100644 --- a/beacon-cache/src/main/java/com/mashibing/cache/controller/CacheController.java +++ b/beacon-cache/src/main/java/com/mashibing/cache/controller/CacheController.java @@ -1,6 +1,7 @@ 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.data.redis.core.RedisTemplate; import org.springframework.web.bind.annotation.*; @@ -14,6 +15,7 @@ import java.util.Map; * @date 2025/6/5 13:46 */ +@Slf4j @RestController @RequestMapping("cache") public class CacheController { @@ -21,25 +23,34 @@ public class CacheController { @Autowired private RedisClient redisClient; - @GetMapping("getString/{key}") - public String getString(@PathVariable String key) { + @GetMapping("get/{key}") + public String get(@PathVariable String key) { + log.info("【缓存模块】getString:{}", key); return redisClient.get(key); } - @GetMapping("setString/{key}/{value}") - public String setString(@PathVariable String key, @PathVariable String value) { + @GetMapping("set/{key}/{value}") + public void set(@PathVariable String key, @PathVariable String value) { + log.info("【缓存模块】setString: key = {},\nvalue = {}", key, value); redisClient.set(key, value); - return "保存成功"; } - @GetMapping("getHash/{key}") - public Map getHash(@PathVariable String key) { + @GetMapping("hget/{key}") + public Map hget(@PathVariable String key) { + log.info("【缓存模块】getHash:{}", key); return redisClient.hGetAll(key); } - @PostMapping("setHash/{key}") - public String setHash(@PathVariable String key, @RequestBody Map hash) { + @PostMapping("hset/{key}") + public void hset(@PathVariable String key, @RequestBody Map hash) { + log.info("【缓存模块】setHash: key = {},\nvalue = {}", key, hash.toString()); redisClient.hSet(key, hash); - return "保存成功"; } + + @PostMapping("/sadd/{key}") + public void sadd(@PathVariable(value = "key") String key, @RequestBody Map... value) { + log.info("【缓存模块】sadd: key = {},\nvalue = {}", key, value); + redisClient.sAdd(key, value); + } + } diff --git a/beacon-cache/src/main/resources/bootstrap.yml b/beacon-cache/src/main/resources/bootstrap.yml index 1b2ddd6..feb718b 100644 --- a/beacon-cache/src/main/resources/bootstrap.yml +++ b/beacon-cache/src/main/resources/bootstrap.yml @@ -9,10 +9,10 @@ spring: cloud: nacos: discovery: - server-addr: 192.168.1.13:8848 + server-addr: 192.168.1.10:8848 # nacos配置中心地址: config: - server-addr: 192.168.1.13:8848 + server-addr: 192.168.1.10:8848 file-extension: yml # beacon-cache-dev.yml \ No newline at end of file diff --git a/beacon-common/pom.xml b/beacon-common/pom.xml index 8676e7a..68a9389 100644 --- a/beacon-common/pom.xml +++ b/beacon-common/pom.xml @@ -19,6 +19,11 @@ org.projectlombok lombok + + + org.springframework.cloud + spring-cloud-starter-openfeign + \ No newline at end of file diff --git a/beacon-common/src/main/java/com/mashibing/common/constant/SMSConstant.java b/beacon-common/src/main/java/com/mashibing/common/constant/SMSConstant.java new file mode 100644 index 0000000..9950d4f --- /dev/null +++ b/beacon-common/src/main/java/com/mashibing/common/constant/SMSConstant.java @@ -0,0 +1,18 @@ +package com.mashibing.common.constant; + +/** + * @author heqijun + * @ClassName: Constant + * @Description: TODO(这里用一句话描述这个类的作用) + * @date 2025/6/5 17:10 + */ + +public class SMSConstant { + + public static final double EARTH_RADIUS = 6378.137; + + public static final String UNKNOWN = "unknown"; + + public static final String X_FORWARDED_FOR = "x-forwarded-for"; + +} diff --git a/beacon-common/src/main/java/com/mashibing/common/pojo/StandardSubmit.java b/beacon-common/src/main/java/com/mashibing/common/pojo/StandardSubmit.java index 63b2548..0b632d4 100644 --- a/beacon-common/src/main/java/com/mashibing/common/pojo/StandardSubmit.java +++ b/beacon-common/src/main/java/com/mashibing/common/pojo/StandardSubmit.java @@ -64,4 +64,13 @@ public class StandardSubmit { @Description("短信的发送状态, 0-等待ing,1-成功,2-失败") private int reportState; + @Description("apikey") + private String apikey; + + @Description("realIP获取到的真实ip地址") + private String realIp; + + @Description("state短信类型 0-验证码短信 1-通知类短信 2-营销类短信") + private Integer state; + } diff --git a/beacon-test/pom.xml b/beacon-test/pom.xml new file mode 100644 index 0000000..55cc2e4 --- /dev/null +++ b/beacon-test/pom.xml @@ -0,0 +1,57 @@ + + + 4.0.0 + + com.mashibing + beacon-cloud + 1.0-SNAPSHOT + + + beacon-test + + + + + + org.springframework.boot + spring-boot-starter-web + + + + com.alibaba.cloud + spring-cloud-starter-alibaba-nacos-discovery + + + org.springframework.boot + spring-boot-starter-test + + + + org.springframework.cloud + spring-cloud-starter-openfeign + + + + org.projectlombok + lombok + + + org.mybatis.spring.boot + mybatis-spring-boot-starter + 2.2.2 + + + mysql + mysql-connector-java + 5.1.49 + + + com.mashibing + beacon-common + 1.0-SNAPSHOT + + + + \ No newline at end of file diff --git a/beacon-test/src/main/java/com/mashibing/test/TestApplication.java b/beacon-test/src/main/java/com/mashibing/test/TestApplication.java new file mode 100644 index 0000000..45cadb6 --- /dev/null +++ b/beacon-test/src/main/java/com/mashibing/test/TestApplication.java @@ -0,0 +1,24 @@ +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 heqijun + * @ClassName: TestApplication + * @Description: TestApplication启动类 + * @date 2025/6/5 18:42 + */ + +@SpringBootApplication +@EnableDiscoveryClient +@EnableFeignClients +@MapperScan(basePackages = "com.mashibing.test.mapper") +public class TestApplication { + public static void main(String[] args) { + SpringApplication.run(TestApplication.class, args); + } +} 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..edd4a42 --- /dev/null +++ b/beacon-test/src/main/java/com/mashibing/test/entity/ClientBalance.java @@ -0,0 +1,127 @@ +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; + } + +} 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..9fca380 --- /dev/null +++ b/beacon-test/src/main/java/com/mashibing/test/entity/ClientBusiness.java @@ -0,0 +1,189 @@ +package com.mashibing.test.entity; + +import lombok.Data; +import lombok.ToString; + +@ToString +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; + } + +} 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..676c6bf --- /dev/null +++ b/beacon-test/src/main/java/com/mashibing/test/entity/ClientSign.java @@ -0,0 +1,178 @@ +package com.mashibing.test.entity; + +import lombok.ToString; + +@ToString +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; + } + +} 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..5beca9d --- /dev/null +++ b/beacon-test/src/main/java/com/mashibing/test/entity/ClientTemplate.java @@ -0,0 +1,167 @@ +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; + } + +} diff --git a/beacon-test/src/main/java/com/mashibing/test/feignClient/BeaconCacheClient.java b/beacon-test/src/main/java/com/mashibing/test/feignClient/BeaconCacheClient.java new file mode 100644 index 0000000..6697b2e --- /dev/null +++ b/beacon-test/src/main/java/com/mashibing/test/feignClient/BeaconCacheClient.java @@ -0,0 +1,34 @@ +package com.mashibing.test.feignClient; + +import org.springframework.cloud.openfeign.FeignClient; +import org.springframework.web.bind.annotation.*; + +import java.util.Map; + +/** + * @author heqijun + * @ClassName: BeaconCacheClient + * @Description: TODO(这里用一句话描述这个类的作用) + * @date 2025/6/5 20:13 + */ + +@FeignClient("beacon-cache") +@RequestMapping("cache") +public interface BeaconCacheClient { + @GetMapping("get/{key}") + public String get(@PathVariable String key); + + @GetMapping("set/{key}/{value}") + public void set(@PathVariable String key, @PathVariable String value); + + @GetMapping("hget/{key}") + public Map hget(@PathVariable String key); + + @PostMapping("hset/{key}") + public void hset(@PathVariable String key, @RequestBody Map hash); + + @PostMapping("/sadd/{key}") + public void sadd(@PathVariable(value = "key") String key, @RequestBody Map... maps); + + +} 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..9d65396 --- /dev/null +++ b/beacon-test/src/main/java/com/mashibing/test/mapper/ClientBusinessMapper.java @@ -0,0 +1,19 @@ +package com.mashibing.test.mapper; + +import com.mashibing.test.entity.ClientBusiness; +import org.apache.ibatis.annotations.Param; +import org.apache.ibatis.annotations.Select; + +/** + * @author heqijun + * @ClassName: ClientBalanceMapper + * @Description: TODO(这里用一句话描述这个类的作用) + * @date 2025/6/5 18:58 + */ + +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..8b520be --- /dev/null +++ b/beacon-test/src/main/java/com/mashibing/test/mapper/ClientSignMapper.java @@ -0,0 +1,22 @@ +package com.mashibing.test.mapper; + +import com.mashibing.test.entity.ClientBusiness; +import com.mashibing.test.entity.ClientSign; +import org.apache.ibatis.annotations.Param; +import org.apache.ibatis.annotations.Select; + +import java.util.List; + +/** + * @author heqijun + * @ClassName: ClientSignMapper + * @Description: TODO(这里用一句话描述这个类的作用) + * @date 2025/6/5 20:51 + */ + +public interface ClientSignMapper { + + @Select("select * from client_sign where client_id = #{clientId}") + List findAllByClientId(@Param("clientId") Long clientId); + +} diff --git a/beacon-test/src/main/resources/application.yml b/beacon-test/src/main/resources/application.yml new file mode 100644 index 0000000..1d412d1 --- /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.1.10:8848 + # datasource + datasource: + driver-class-name: org.gjt.mm.mysql.Driver + url: jdbc:mysql://192.168.1.10:3306/beacon_cloud?characterEncoding=utf-8&useSSL=false + username: root + password: root +# 端口号 +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/ClientBusinessMapperTest.java b/beacon-test/src/test/java/com/mashibing/test/mapper/ClientBusinessMapperTest.java new file mode 100644 index 0000000..d1cb6b3 --- /dev/null +++ b/beacon-test/src/test/java/com/mashibing/test/mapper/ClientBusinessMapperTest.java @@ -0,0 +1,33 @@ +package com.mashibing.test.mapper; + +import com.fasterxml.jackson.databind.ObjectMapper; + +import com.mashibing.test.entity.ClientBusiness; +import com.mashibing.test.feignClient.BeaconCacheClient; +import org.junit.jupiter.api.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.cloud.openfeign.EnableFeignClients; +import org.springframework.test.context.junit4.SpringRunner; + +import java.util.Map; + +@SpringBootTest +@RunWith(SpringRunner.class) +public class ClientBusinessMapperTest { + + @Autowired + private ClientBusinessMapper mapper; + + @Autowired + BeaconCacheClient beaconCacheClient; + + @Test + public void findById() { + ClientBusiness cb = mapper.findById(1L); + System.out.println(cb); + ObjectMapper mapper = new ObjectMapper(); + beaconCacheClient.hset("client_business:" + cb.getApikey(), mapper.convertValue(cb, Map.class)); + } +} \ 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..3d814ec --- /dev/null +++ b/beacon-test/src/test/java/com/mashibing/test/mapper/ClientSignMapperTest.java @@ -0,0 +1,41 @@ +package com.mashibing.test.mapper; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.mashibing.test.entity.ClientSign; +import com.mashibing.test.feignClient.BeaconCacheClient; +import org.junit.jupiter.api.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; + +import java.util.Arrays; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +import static org.junit.jupiter.api.Assertions.*; + +@SpringBootTest +@RunWith(SpringRunner.class) +class ClientSignMapperTest { + + @Autowired + private ClientSignMapper mapper; + + @Autowired + BeaconCacheClient beaconCacheClient; + + @Test + void findAllByClientId() { + List clientSignList = mapper.findAllByClientId(1L); + clientSignList.forEach(System.out::println); + ObjectMapper mapper = new ObjectMapper(); + List maps = clientSignList + .stream() + .map(clientSign -> mapper.convertValue(clientSign, Map.class)) + .collect(Collectors.toList()); + + beaconCacheClient.sadd("client_sign:1", maps.toArray(new Map[]{})); + } +} \ No newline at end of file diff --git a/pom.xml b/pom.xml index 8932c53..b314567 100644 --- a/pom.xml +++ b/pom.xml @@ -12,6 +12,7 @@ beacon-api beacon-common beacon-cache + beacon-test