feat(search): search模块基本搭建

This commit is contained in:
bunny 2024-04-04 15:52:54 +08:00
parent e7eb08ca3b
commit 0f06295fc5
16 changed files with 218 additions and 59 deletions

View File

@ -44,5 +44,18 @@
</jdbc-additional-properties>
<working-dir>$ProjectFileDir$</working-dir>
</data-source>
<data-source source="LOCAL" name="0@47.120.65.66" uuid="80c74a8a-8467-45dc-ad24-8422085124e9">
<driver-ref>redis</driver-ref>
<synchronize>true</synchronize>
<imported>true</imported>
<jdbc-driver>jdbc.RedisDriver</jdbc-driver>
<jdbc-url>jdbc:redis://47.120.65.66:6379/0</jdbc-url>
<jdbc-additional-properties>
<property name="com.intellij.clouds.kubernetes.db.host.port" />
<property name="com.intellij.clouds.kubernetes.db.enabled" value="false" />
<property name="com.intellij.clouds.kubernetes.db.container.port" />
</jdbc-additional-properties>
<working-dir>$ProjectFileDir$</working-dir>
</data-source>
</component>
</project>

View File

@ -1,4 +1,4 @@
package com.atguigu.ssyx;
package com.atguigu.ssyx.common;
import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.generator.AutoGenerator;

View File

@ -14,12 +14,6 @@ bunny:
discovery:
namespace: ssyx
redis:
host: 47.120.65.66
port: 6379
database: 2
password: "02120212"
minio:
endpointUrl: "http://129.211.31.58:9000"
bucket-name: ssyx

View File

@ -0,0 +1,27 @@
package com.atguigu.ssyx.product.controller;
import com.atguigu.ssyx.common.result.Result;
import com.atguigu.ssyx.product.service.FileUploadService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
@Api(tags = "文件上传接口")
@RestController
@RequestMapping("admin/product")
public class FileUploadController {
@Autowired
private FileUploadService fileUploadService;
@ApiOperation(value = "文件上传")
@PostMapping("fileUpload")
public Result<String> fileUpload(@RequestBody MultipartFile file) {
String filename = fileUploadService.uploadFile(file);
return Result.success(filename);
}
}

View File

@ -0,0 +1,13 @@
package com.atguigu.ssyx.product.service;
import org.springframework.web.multipart.MultipartFile;
public interface FileUploadService {
/**
* 文件上传
*
* @param file 上传的文件
* @return 文件路径
*/
String uploadFile(MultipartFile file);
}

View File

@ -0,0 +1,58 @@
package com.atguigu.ssyx.product.service.impl;
import cn.hutool.core.date.DateUtil;
import com.atguigu.ssyx.common.properties.MinioProperties;
import com.atguigu.ssyx.product.service.FileUploadService;
import io.minio.BucketExistsArgs;
import io.minio.MakeBucketArgs;
import io.minio.MinioClient;
import io.minio.PutObjectArgs;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
import java.util.Date;
import java.util.UUID;
@Service
@Slf4j
public class FileUploadServiceImpl implements FileUploadService {
@Autowired
private MinioProperties properties;
@Autowired
private MinioClient minioClient;
/**
* 文件上传
*
* @param file 上传的文件
* @return 文件路径
*/
@Override
public String uploadFile(MultipartFile file) {
String bucketName = properties.getBucketName();
String dir = DateUtil.format(new Date(), "yyyy-MM-dd");
String uuid = UUID.randomUUID().toString();
String filename = dir + "/" + uuid + "-" + file.getOriginalFilename();
try {
boolean bucketExists = minioClient.bucketExists(BucketExistsArgs.builder().bucket(bucketName).build());
if (!bucketExists) {
log.warn("minio桶不存在{}", bucketName);
minioClient.makeBucket(MakeBucketArgs.builder().bucket(bucketName).build());
}
// 存入图片
minioClient.putObject(PutObjectArgs.builder()
.bucket(bucketName)
.object(filename)
.stream(file.getInputStream(), file.getSize(), -1).build());
return properties.getEndpointUrl() + "/" + properties.getBucketName() + "/" + filename;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}

View File

@ -14,12 +14,6 @@ bunny:
discovery:
namespace: ssyx
redis:
host: 47.120.65.66
port: 6379
database: 2
password: "02120212"
minio:
endpointUrl: "http://129.211.31.58:9000"
bucket-name: ssyx

View File

@ -22,7 +22,11 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-elasticsearch</artifactId>
</dependency>
<!-- redis的起步依赖 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
<!-- <dependency> -->
<!-- <groupId>com.atguigu</groupId> -->
<!-- <artifactId>service-product-client</artifactId> -->

View File

@ -0,0 +1,19 @@
package com.atguigu.ssyx.search;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.transaction.annotation.EnableTransactionManagement;
@SpringBootApplication(exclude = DataSourceAutoConfiguration.class)
@ComponentScan(basePackages = {"com.atguigu.ssyx"})
@EnableDiscoveryClient
@EnableFeignClients
public class ServiceSearchApplication {
public static void main(String[] args) {
SpringApplication.run(ServiceSearchApplication.class, args);
}
}

View File

@ -0,0 +1,9 @@
package com.atguigu.ssyx.search.controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/api/search/sku")
public class SkuApiController {
}

View File

@ -0,0 +1,7 @@
package com.atguigu.ssyx.search.repository;
import com.atguigu.ssyx.model.search.SkuEs;
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
public interface SkuRepository extends ElasticsearchRepository<SkuEs,Long> {
}

View File

@ -0,0 +1,4 @@
package com.atguigu.ssyx.search.service;
public interface SkuService {
}

View File

@ -0,0 +1,8 @@
package com.atguigu.ssyx.search.service.impl;
import com.atguigu.ssyx.search.service.SkuService;
import org.springframework.stereotype.Service;
@Service
public class SkuServiceImpl implements SkuService {
}

View File

@ -1,14 +1,16 @@
server:
port: 8203
port: 8208
bunny:
datasource:
host: 106.15.251.123
port: 3305
sqlData: shequ-product
username: root
rabbitmq:
host: 116.196.101.14
port: 5672
username: bunny
password: "02120212"
elasticsearch:
uris: http://192.168.1.4:9200
nacos:
server-addr: z-bunny.cn:8848
discovery:
@ -17,7 +19,7 @@ bunny:
redis:
host: 47.120.65.66
port: 6379
database: 2
database: 3
password: "02120212"
minio:

View File

@ -1,17 +1,39 @@
server:
port: 8203
port: 8208
spring:
application:
name: service-product
name: service-search
profiles:
active: dev
datasource:
type: com.zaxxer.hikari.HikariDataSource
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://${bunny.datasource.host}:${bunny.datasource.port}/${bunny.datasource.sqlData}?serverTimezone=GMT%2B8&useSSL=false&characterEncoding=utf-8&allowPublicKeyRetrieval=true
username: ${bunny.datasource.username}
password: ${bunny.datasource.password}
redis:
host: ${bunny.redis.host}
port: ${bunny.redis.port}
database: ${bunny.redis.database}
password: ${bunny.redis.password}
lettuce:
pool:
max-active: 20 #最大连接数
max-wait: -1 #最大阻塞等待时间(负数表示没限制)
max-idle: 5 #最大空闲
min-idle: 0 #最小空闲
elasticsearch:
rest:
uris: ${bunny.elasticsearch.uris}
rabbitmq:
host: ${bunny.rabbitmq.host}
port: ${bunny.rabbitmq.port}
username: ${bunny.rabbitmq.username}
password: ${bunny.rabbitmq.password}
publisher-confirm-type: CORRELATED
publisher-returns: true
listener:
simple:
prefetch: 1
concurrency: 3
acknowledge-mode: manual
cloud:
sentinel:
@ -26,23 +48,21 @@ spring:
date-format: yyyy-MM-dd HH:mm:ss
time-zone: GMT+8
bunny:
minio:
endpointUrl: ${bunny.minio.endpointUrl}
accessKey: ${bunny.minio.accessKey}
secretKey: ${bunny.minio.secretKey}
bucket-name: ${bunny.minio.bucket-name}
mybatis-plus:
type-aliases-package: com.atguigu.model # 配置每个包前缀
mapper-locations: classpath:mapper/*.xml
configuration:
map-underscore-to-camel-case: true
auto-mapping-behavior: full
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl # 查看日志
global-config:
db-config:
# 设置表名前缀不用在每个tableName添加前缀
# table-prefix: t_
# 全局配置主键值方式
id-type: assign_id
logic-not-delete-value: 0 # 未删除默认为0
logic-delete-value: 1 # 删除
logic-delete-field: deleted # 全局配置逻辑删除
feign:
sentinel:
enabled: true
client:
config:
default: #配置全局的feign的调用超时时间 如果 有指定的服务配置 默认的配置不会生效
connectTimeout: 30000 # 指定的是 消费者 连接服务提供者的连接超时时间 是否能连接 单位是毫秒
readTimeout: 50000 # 指定的是调用服务提供者的 服务 的超时时间() 单位是毫秒
logging:
level:
@ -52,11 +72,4 @@ logging:
pattern:
dateformat: HH:mm:ss:SSS
file:
path: "logs/${spring.application.name}"
bunny:
minio:
endpointUrl: ${bunny.minio.endpointUrl}
accessKey: ${bunny.minio.accessKey}
secretKey: ${bunny.minio.secretKey}
bucket-name: ${bunny.minio.bucket-name}
path: "logs/${spring.application.name}"

View File

@ -14,12 +14,6 @@ bunny:
discovery:
namespace: ssyx
redis:
host: 47.120.65.66
port: 6379
database: 2
password: "02120212"
minio:
endpointUrl: "http://129.211.31.58:9000"
bucket-name: ssyx