diff --git a/pom.xml b/pom.xml index 4901caf..1afa5b6 100644 --- a/pom.xml +++ b/pom.xml @@ -8,7 +8,7 @@ org.springframework.boot spring-boot-starter-parent - 2.7.2 + 2.6.11 com.yupi @@ -51,11 +51,12 @@ org.springframework.boot spring-boot-starter-data-redis + 2.7.18 - - org.springframework.session - spring-session-data-redis - + + + + com.github.xiaoymin diff --git a/src/main/java/com/yupi/springbootinit/MainApplication.java b/src/main/java/com/yupi/springbootinit/MainApplication.java index 712c0b0..0438b56 100644 --- a/src/main/java/com/yupi/springbootinit/MainApplication.java +++ b/src/main/java/com/yupi/springbootinit/MainApplication.java @@ -14,7 +14,7 @@ import org.springframework.scheduling.annotation.EnableScheduling; * @from 编程导航知识星球 */ // todo 如需开启 Redis,须移除 exclude 中的内容 -@SpringBootApplication(exclude = {RedisAutoConfiguration.class}) +@SpringBootApplication() @MapperScan("com.yupi.springbootinit.mapper") @EnableScheduling @EnableAspectJAutoProxy(proxyTargetClass = true, exposeProxy = true) diff --git a/src/main/java/com/yupi/springbootinit/config/RedisConfig.java b/src/main/java/com/yupi/springbootinit/config/RedisConfig.java new file mode 100644 index 0000000..287c1d5 --- /dev/null +++ b/src/main/java/com/yupi/springbootinit/config/RedisConfig.java @@ -0,0 +1,37 @@ +package com.yupi.springbootinit.config; + + + +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.RedisSerializer; +import org.springframework.data.redis.serializer.StringRedisSerializer; + +@Configuration +public class RedisConfig { + + + @Bean(name="redisTemplate") + public RedisTemplate redisTemplate(RedisConnectionFactory factory) { + RedisTemplate template = new RedisTemplate<>(); + RedisSerializer redisSerializer = new StringRedisSerializer(); + template.setConnectionFactory(factory); + //key序列化方式 + template.setKeySerializer(redisSerializer); + //value序列化 + template.setValueSerializer(redisSerializer); + //value hashmap序列化 + template.setHashValueSerializer(redisSerializer); + //key haspmap序列化 + template.setHashKeySerializer(redisSerializer); + // + return template; + } + + + + + +} diff --git a/src/main/java/com/yupi/springbootinit/controller/HostInfoController.java b/src/main/java/com/yupi/springbootinit/controller/HostInfoController.java index 9d7d532..456c403 100644 --- a/src/main/java/com/yupi/springbootinit/controller/HostInfoController.java +++ b/src/main/java/com/yupi/springbootinit/controller/HostInfoController.java @@ -3,6 +3,7 @@ package com.yupi.springbootinit.controller; import com.yupi.springbootinit.common.BaseResponse; import com.yupi.springbootinit.common.ResultUtils; import com.yupi.springbootinit.model.dto.host.HostInfoDTO; +import com.yupi.springbootinit.model.dto.host.QueryCountDTO; import com.yupi.springbootinit.model.entity.NewHosts; import com.yupi.springbootinit.model.vo.country.CountryInfoVO; import com.yupi.springbootinit.model.vo.hosts.NewHostsVO; @@ -37,11 +38,14 @@ public class HostInfoController { return ResultUtils.success(true); } - @GetMapping("host_info") - public BaseResponse> getCountryInfo(@Param("countryName") String countryName){ + @GetMapping("country_info") + public BaseResponse> getCountryInfo(@RequestParam(name = "countryName") String countryName){ return ResultUtils.success(hostInfoService.getCountryInfo(countryName)); } - + @PostMapping("query_count") + public void count_query(@RequestBody QueryCountDTO queryCountDTO){ + hostInfoService.queryCount(queryCountDTO); + } } diff --git a/src/main/java/com/yupi/springbootinit/model/dto/host/QueryCountDTO.java b/src/main/java/com/yupi/springbootinit/model/dto/host/QueryCountDTO.java new file mode 100644 index 0000000..08521fe --- /dev/null +++ b/src/main/java/com/yupi/springbootinit/model/dto/host/QueryCountDTO.java @@ -0,0 +1,12 @@ +package com.yupi.springbootinit.model.dto.host; + +import lombok.Data; + +/* + * @author: ziin + * @date: 2025/6/13 15:35 + */ +@Data +public class QueryCountDTO { + public String tkAccount; +} diff --git a/src/main/java/com/yupi/springbootinit/service/HostInfoService.java b/src/main/java/com/yupi/springbootinit/service/HostInfoService.java index e75afb6..3e108a1 100644 --- a/src/main/java/com/yupi/springbootinit/service/HostInfoService.java +++ b/src/main/java/com/yupi/springbootinit/service/HostInfoService.java @@ -3,6 +3,7 @@ package com.yupi.springbootinit.service; import com.baomidou.mybatisplus.extension.service.IService; import com.yupi.springbootinit.model.dto.host.HostInfoDTO; +import com.yupi.springbootinit.model.dto.host.QueryCountDTO; import com.yupi.springbootinit.model.entity.NewHosts; import com.yupi.springbootinit.model.vo.country.CountryInfoVO; import com.yupi.springbootinit.model.vo.hosts.NewHostsVO; @@ -22,4 +23,6 @@ public interface HostInfoService extends IService { List getCountryInfo(String countryName); + + void queryCount(QueryCountDTO queryCountDTO); } diff --git a/src/main/java/com/yupi/springbootinit/service/impl/HostInfoServiceImpl.java b/src/main/java/com/yupi/springbootinit/service/impl/HostInfoServiceImpl.java index 45862a8..df38ad7 100644 --- a/src/main/java/com/yupi/springbootinit/service/impl/HostInfoServiceImpl.java +++ b/src/main/java/com/yupi/springbootinit/service/impl/HostInfoServiceImpl.java @@ -4,12 +4,14 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.google.common.collect.Lists; import com.yupi.springbootinit.mapper.CountryInfoMapper; import com.yupi.springbootinit.mapper.NewHostsMapper; -import com.yupi.springbootinit.model.dto.host.HostInfoDTO; +import com.yupi.springbootinit.model.dto.host.QueryCountDTO; import com.yupi.springbootinit.model.entity.NewHosts; import com.yupi.springbootinit.model.vo.country.CountryInfoVO; -import com.yupi.springbootinit.model.vo.hosts.NewHostsVO; import com.yupi.springbootinit.service.HostInfoService; import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.redis.core.RedisTemplate; +import org.springframework.data.redis.core.StringRedisTemplate; import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -32,6 +34,19 @@ public class HostInfoServiceImpl extends ServiceImpl i @Resource private CountryInfoMapper countryInfoMapper; + + @Resource + private RedisTemplate redisTemplate; + + +// +// private final RedisTemplate redisTemplate; +// +// public HostInfoServiceImpl(RedisTemplate redisTemplate) { +// this.redisTemplate = redisTemplate; +// } + + @Override @Async("taskExecutor") public CompletableFuture saveHostInfo(List newHosts) { @@ -86,8 +101,13 @@ public class HostInfoServiceImpl extends ServiceImpl i @Override public List getCountryInfo(String countryName) { - countryInfoMapper.selectCountryGroupCountryByCountryName(countryName); - return List.of(); + return countryInfoMapper.selectCountryGroupCountryByCountryName(countryName); + } + + @Override + public void queryCount(QueryCountDTO queryCountDTO) { + + redisTemplate.opsForValue().increment(queryCountDTO.getTkAccount(),1); } diff --git a/src/main/resources/application-dev.yml b/src/main/resources/application-dev.yml index 2ea8743..ad65298 100644 --- a/src/main/resources/application-dev.yml +++ b/src/main/resources/application-dev.yml @@ -14,11 +14,10 @@ spring: # Redis 配置 # todo 需替换配置 redis: - database: 1 + database: 0 host: localhost port: 6379 timeout: 5000 - password: 123456 rabbitmq: host: localhost port: 5672 diff --git a/src/main/resources/application-prod.yml b/src/main/resources/application-prod.yml index cd818a7..b045995 100644 --- a/src/main/resources/application-prod.yml +++ b/src/main/resources/application-prod.yml @@ -14,11 +14,10 @@ spring: # Redis 配置 # todo 需替换配置 redis: - database: 1 + database: 0 host: localhost port: 6379 timeout: 5000 - password: 123456 rabbitmq: host: localhost port: 5672 diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 2f599a2..171f0e9 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -50,35 +50,8 @@ mybatis-plus: logic-delete-field: isDelete # 全局逻辑删除的实体字段名 logic-delete-value: 1 # 逻辑已删除值(默认为 1) logic-not-delete-value: 0 # 逻辑未删除值(默认为 0) -# 微信相关 -wx: - # 微信公众平台 - # todo 需替换配置 - mp: - token: xxx - aesKey: xxx - appId: xxx - secret: xxx - config-storage: - http-client-type: HttpClient - key-prefix: wx - redis: - host: 127.0.0.1 - port: 6379 - type: Memory - # 微信开放平台 - # todo 需替换配置 - open: - appId: xxx - appSecret: xxx -# 对象存储 -# todo 需替换配置 -cos: - client: - accessKey: xxx - secretKey: xxx - region: xxx - bucket: xxx + + # 接口文档配置 knife4j: enable: true diff --git a/src/main/resources/mapper/CountryInfoMapper.xml b/src/main/resources/mapper/CountryInfoMapper.xml index 9781db5..6e44ad8 100644 --- a/src/main/resources/mapper/CountryInfoMapper.xml +++ b/src/main/resources/mapper/CountryInfoMapper.xml @@ -166,7 +166,7 @@