修改redis配置参数,新增获取账号爬取次数接口
This commit is contained in:
@@ -15,7 +15,7 @@ import org.springframework.transaction.annotation.EnableTransactionManagement;
|
||||
* @from <a href="https://yupi.icu">编程导航知识星球</a>
|
||||
*/
|
||||
// todo 如需开启 Redis,须移除 exclude 中的内容
|
||||
@SpringBootApplication(exclude = {RedisAutoConfiguration.class})
|
||||
@SpringBootApplication()
|
||||
@MapperScan("com.yupi.springbootinit.mapper")
|
||||
@EnableScheduling
|
||||
@EnableTransactionManagement
|
||||
|
||||
@@ -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<String, String> redisTemplate(RedisConnectionFactory factory) {
|
||||
RedisTemplate<String, String> template = new RedisTemplate<>();
|
||||
RedisSerializer<String> 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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -2,13 +2,12 @@ package com.yupi.springbootinit.controller;
|
||||
|
||||
import com.yupi.springbootinit.common.BaseResponse;
|
||||
import com.yupi.springbootinit.common.ResultUtils;
|
||||
import com.yupi.springbootinit.model.vo.common.AccountCrawlCount;
|
||||
import com.yupi.springbootinit.model.vo.country.CountryInfoVO;
|
||||
import com.yupi.springbootinit.service.CommonService;
|
||||
import com.yupi.springbootinit.service.CountryInfoService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.web.bind.annotation.CrossOrigin;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
@@ -26,9 +25,18 @@ public class CommonController {
|
||||
@Resource
|
||||
private CountryInfoService countryInfoService;
|
||||
|
||||
@Resource
|
||||
private CommonService commonService;
|
||||
|
||||
@PostMapping("country_info")
|
||||
public BaseResponse<List<CountryInfoVO>> countryInfo() {
|
||||
|
||||
return ResultUtils.success(countryInfoService.getCountryList());
|
||||
}
|
||||
|
||||
@GetMapping("accountCount")
|
||||
public BaseResponse<AccountCrawlCount> getAccountCount(@RequestParam String accountName){
|
||||
return ResultUtils.success(commonService.getAccountCrawlCount(accountName));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.yupi.springbootinit.model.vo.common;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import lombok.Data;
|
||||
|
||||
/*
|
||||
* @author: ziin
|
||||
* @date: 2025/6/16 14:10
|
||||
*/
|
||||
@ApiModel(description = "账号爬取统计")
|
||||
@Data
|
||||
public class AccountCrawlCount {
|
||||
private String accountName;
|
||||
|
||||
private Integer count;
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package com.yupi.springbootinit.service;
|
||||
|
||||
import com.yupi.springbootinit.model.vo.common.AccountCrawlCount;
|
||||
|
||||
/*
|
||||
* @author: ziin
|
||||
* @date: 2025/6/16 14:07
|
||||
*/
|
||||
public interface CommonService {
|
||||
AccountCrawlCount getAccountCrawlCount(String accountName);
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package com.yupi.springbootinit.service.impl;
|
||||
|
||||
import com.yupi.springbootinit.common.ErrorCode;
|
||||
import com.yupi.springbootinit.exception.BusinessException;
|
||||
import com.yupi.springbootinit.model.vo.common.AccountCrawlCount;
|
||||
import com.yupi.springbootinit.service.CommonService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
/*
|
||||
* @author: ziin
|
||||
* @date: 2025/6/16 14:08
|
||||
*/
|
||||
@Service
|
||||
public class CommonServiceImpl implements CommonService {
|
||||
|
||||
@Resource
|
||||
private RedisTemplate redisTemplate;
|
||||
|
||||
@Override
|
||||
public AccountCrawlCount getAccountCrawlCount(String accountName) {
|
||||
AccountCrawlCount accountCrawlCount = new AccountCrawlCount();
|
||||
accountCrawlCount.setAccountName(accountName);
|
||||
Object o = redisTemplate.opsForValue().get("tkaccount:" + accountName);
|
||||
if (o != null) {
|
||||
accountCrawlCount.setCount(Integer.valueOf(o.toString()));
|
||||
return accountCrawlCount;
|
||||
}else{
|
||||
throw new BusinessException(ErrorCode.NOT_FOUND_ERROR);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -14,17 +14,10 @@ spring:
|
||||
# Redis 配置
|
||||
# todo 需替换配置
|
||||
redis:
|
||||
database: 1
|
||||
database: 0
|
||||
host: localhost
|
||||
port: 6379
|
||||
timeout: 5000
|
||||
password: 123456
|
||||
# Elasticsearch 配置
|
||||
# todo 需替换配置
|
||||
elasticsearch:
|
||||
uris: http://localhost:9200
|
||||
username: root
|
||||
password: 123456
|
||||
rabbitmq:
|
||||
host: localhost
|
||||
port: 5672
|
||||
|
||||
Reference in New Issue
Block a user