Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
qq_46911822
mall
提交
d1e687da
M
mall
项目概览
qq_46911822
/
mall
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
M
mall
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
d1e687da
编写于
6月 19, 2018
作者:
Z
zhh
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
添加商品导入es功能
上级
f960972e
变更
12
隐藏空白更改
内联
并排
Showing
12 changed file
with
402 addition
and
2 deletion
+402
-2
mall-search/pom.xml
mall-search/pom.xml
+17
-1
mall-search/src/main/java/com/macro/mall/search/MallSearchApplication.java
...ain/java/com/macro/mall/search/MallSearchApplication.java
+2
-0
mall-search/src/main/java/com/macro/mall/search/config/Swagger2Config.java
...ain/java/com/macro/mall/search/config/Swagger2Config.java
+38
-0
mall-search/src/main/java/com/macro/mall/search/controller/EsProductController.java
...com/macro/mall/search/controller/EsProductController.java
+28
-0
mall-search/src/main/java/com/macro/mall/search/dao/EsProductDao.java
...src/main/java/com/macro/mall/search/dao/EsProductDao.java
+13
-0
mall-search/src/main/java/com/macro/mall/search/domain/EsProduct.java
...src/main/java/com/macro/mall/search/domain/EsProduct.java
+190
-0
mall-search/src/main/java/com/macro/mall/search/repository/EsProductRepository.java
...com/macro/mall/search/repository/EsProductRepository.java
+11
-0
mall-search/src/main/java/com/macro/mall/search/service/EsProductService.java
.../java/com/macro/mall/search/service/EsProductService.java
+12
-0
mall-search/src/main/java/com/macro/mall/search/service/impl/EsProductServiceImpl.java
.../macro/mall/search/service/impl/EsProductServiceImpl.java
+28
-0
mall-search/src/main/resources/application.properties
mall-search/src/main/resources/application.properties
+18
-0
mall-search/src/main/resources/dao/EsProductDao.xml
mall-search/src/main/resources/dao/EsProductDao.xml
+33
-0
mall-search/src/test/java/com/macro/mall/search/MallSearchApplicationTests.java
...ava/com/macro/mall/search/MallSearchApplicationTests.java
+12
-1
未找到文件。
mall-search/pom.xml
浏览文件 @
d1e687da
...
...
@@ -38,12 +38,28 @@
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-web
</artifactId>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-test
</artifactId>
<scope>
test
</scope>
</dependency>
<!--MyBatis分页插件-->
<dependency>
<groupId>
com.github.pagehelper
</groupId>
<artifactId>
pagehelper-spring-boot-starter
</artifactId>
<version>
1.2.3
</version>
</dependency>
<!--Swagger-UI API文档生产工具-->
<dependency>
<groupId>
io.springfox
</groupId>
<artifactId>
springfox-swagger2
</artifactId>
<version>
2.6.1
</version>
</dependency>
<dependency>
<groupId>
io.springfox
</groupId>
<artifactId>
springfox-swagger-ui
</artifactId>
<version>
2.6.1
</version>
</dependency>
</dependencies>
<build>
...
...
mall-search/src/main/java/com/macro/mall/search/MallSearchApplication.java
浏览文件 @
d1e687da
package
com.macro.mall.search
;
import
org.mybatis.spring.annotation.MapperScan
;
import
org.springframework.boot.SpringApplication
;
import
org.springframework.boot.autoconfigure.SpringBootApplication
;
@SpringBootApplication
@MapperScan
({
"com.macro.mall.mapper"
,
"com.macro.mall.search.dao"
})
public
class
MallSearchApplication
{
public
static
void
main
(
String
[]
args
)
{
...
...
mall-search/src/main/java/com/macro/mall/search/config/Swagger2Config.java
0 → 100644
浏览文件 @
d1e687da
package
com.macro.mall.search.config
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
springfox.documentation.builders.ApiInfoBuilder
;
import
springfox.documentation.builders.PathSelectors
;
import
springfox.documentation.builders.RequestHandlerSelectors
;
import
springfox.documentation.service.ApiInfo
;
import
springfox.documentation.spi.DocumentationType
;
import
springfox.documentation.spring.web.plugins.Docket
;
import
springfox.documentation.swagger2.annotations.EnableSwagger2
;
/**
* Swagger2API文档的配置
* Created by macro on 2018/4/26.
*/
@Configuration
@EnableSwagger2
public
class
Swagger2Config
{
@Bean
public
Docket
createRestApi
(){
return
new
Docket
(
DocumentationType
.
SWAGGER_2
)
.
apiInfo
(
apiInfo
())
.
select
()
.
apis
(
RequestHandlerSelectors
.
basePackage
(
"com.macro.mall.search.controller"
))
.
paths
(
PathSelectors
.
any
())
.
build
();
}
private
ApiInfo
apiInfo
()
{
return
new
ApiInfoBuilder
()
.
title
(
"mall搜索系统"
)
.
description
(
"mall搜索模块"
)
.
contact
(
"macro"
)
.
version
(
"1.0"
)
.
build
();
}
}
mall-search/src/main/java/com/macro/mall/search/controller/EsProductController.java
0 → 100644
浏览文件 @
d1e687da
package
com.macro.mall.search.controller
;
import
com.macro.mall.search.service.EsProductService
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiOperation
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Controller
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestMethod
;
import
org.springframework.web.bind.annotation.ResponseBody
;
/**
* 搜索商品管理Controller
* Created by macro on 2018/6/19.
*/
@Controller
@Api
(
tags
=
"EsProductController"
,
description
=
"搜索商品管理"
)
@RequestMapping
(
"/search/product"
)
public
class
EsProductController
{
@Autowired
private
EsProductService
esProductService
;
@ApiOperation
(
value
=
"导入所有数据库中商品到ES"
)
@RequestMapping
(
value
=
"/importAll"
,
method
=
RequestMethod
.
POST
)
@ResponseBody
public
Object
importAllList
()
{
return
esProductService
.
importAll
();
}
}
mall-search/src/main/java/com/macro/mall/search/dao/EsProductDao.java
0 → 100644
浏览文件 @
d1e687da
package
com.macro.mall.search.dao
;
import
com.macro.mall.search.domain.EsProduct
;
import
java.util.List
;
/**
* 搜索系统中的商品管理自定义Dao
* Created by macro on 2018/6/19.
*/
public
interface
EsProductDao
{
List
<
EsProduct
>
getAllEsProductList
();
}
mall-search/src/main/java/com/macro/mall/search/domain/EsProduct.java
0 → 100644
浏览文件 @
d1e687da
package
com.macro.mall.search.domain
;
import
org.springframework.data.elasticsearch.annotations.Document
;
import
java.io.Serializable
;
import
java.math.BigDecimal
;
import
java.util.List
;
/**
* 搜索中的商品信息
* Created by macro on 2018/6/19.
*/
@Document
(
indexName
=
"pms"
,
type
=
"product"
)
public
class
EsProduct
implements
Serializable
{
private
static
final
long
serialVersionUID
=
-
1L
;
private
Long
id
;
private
String
productSn
;
private
Long
brandId
;
private
String
brandName
;
private
Long
productCategoryId
;
private
String
productCategoryName
;
private
String
pic
;
private
String
name
;
private
String
subTitle
;
private
BigDecimal
price
;
private
Integer
sale
;
private
Integer
newStatus
;
private
Integer
recommandStatus
;
private
Integer
stock
;
private
Integer
promotionType
;
private
Integer
sort
;
private
List
<
EsProductAttrValue
>
attrValueList
;
public
Long
getId
()
{
return
id
;
}
public
void
setId
(
Long
id
)
{
this
.
id
=
id
;
}
public
String
getProductSn
()
{
return
productSn
;
}
public
void
setProductSn
(
String
productSn
)
{
this
.
productSn
=
productSn
;
}
public
Long
getBrandId
()
{
return
brandId
;
}
public
void
setBrandId
(
Long
brandId
)
{
this
.
brandId
=
brandId
;
}
public
String
getBrandName
()
{
return
brandName
;
}
public
void
setBrandName
(
String
brandName
)
{
this
.
brandName
=
brandName
;
}
public
Long
getProductCategoryId
()
{
return
productCategoryId
;
}
public
void
setProductCategoryId
(
Long
productCategoryId
)
{
this
.
productCategoryId
=
productCategoryId
;
}
public
String
getProductCategoryName
()
{
return
productCategoryName
;
}
public
void
setProductCategoryName
(
String
productCategoryName
)
{
this
.
productCategoryName
=
productCategoryName
;
}
public
String
getPic
()
{
return
pic
;
}
public
void
setPic
(
String
pic
)
{
this
.
pic
=
pic
;
}
public
String
getName
()
{
return
name
;
}
public
void
setName
(
String
name
)
{
this
.
name
=
name
;
}
public
String
getSubTitle
()
{
return
subTitle
;
}
public
void
setSubTitle
(
String
subTitle
)
{
this
.
subTitle
=
subTitle
;
}
public
BigDecimal
getPrice
()
{
return
price
;
}
public
void
setPrice
(
BigDecimal
price
)
{
this
.
price
=
price
;
}
public
Integer
getSale
()
{
return
sale
;
}
public
void
setSale
(
Integer
sale
)
{
this
.
sale
=
sale
;
}
public
Integer
getNewStatus
()
{
return
newStatus
;
}
public
void
setNewStatus
(
Integer
newStatus
)
{
this
.
newStatus
=
newStatus
;
}
public
Integer
getRecommandStatus
()
{
return
recommandStatus
;
}
public
void
setRecommandStatus
(
Integer
recommandStatus
)
{
this
.
recommandStatus
=
recommandStatus
;
}
public
Integer
getStock
()
{
return
stock
;
}
public
void
setStock
(
Integer
stock
)
{
this
.
stock
=
stock
;
}
public
Integer
getPromotionType
()
{
return
promotionType
;
}
public
void
setPromotionType
(
Integer
promotionType
)
{
this
.
promotionType
=
promotionType
;
}
public
Integer
getSort
()
{
return
sort
;
}
public
void
setSort
(
Integer
sort
)
{
this
.
sort
=
sort
;
}
public
List
<
EsProductAttrValue
>
getAttrValueList
()
{
return
attrValueList
;
}
public
void
setAttrValueList
(
List
<
EsProductAttrValue
>
attrValueList
)
{
this
.
attrValueList
=
attrValueList
;
}
static
class
EsProductAttrValue
{
private
Long
id
;
private
String
value
;
public
String
getValue
()
{
return
value
;
}
public
void
setValue
(
String
value
)
{
this
.
value
=
value
;
}
public
Long
getId
()
{
return
id
;
}
public
void
setId
(
Long
id
)
{
this
.
id
=
id
;
}
}
}
mall-search/src/main/java/com/macro/mall/search/repository/EsProductRepository.java
0 → 100644
浏览文件 @
d1e687da
package
com.macro.mall.search.repository
;
import
com.macro.mall.search.domain.EsProduct
;
import
org.springframework.data.elasticsearch.repository.ElasticsearchCrudRepository
;
/**
* 商品ES操作类
* Created by macro on 2018/6/19.
*/
public
interface
EsProductRepository
extends
ElasticsearchCrudRepository
<
EsProduct
,
Long
>
{
}
mall-search/src/main/java/com/macro/mall/search/service/EsProductService.java
0 → 100644
浏览文件 @
d1e687da
package
com.macro.mall.search.service
;
/**
* 商品搜索管理Service
* Created by macro on 2018/6/19.
*/
public
interface
EsProductService
{
/**
* 从数据库中导入所有商品到ES
*/
Object
importAll
();
}
mall-search/src/main/java/com/macro/mall/search/service/impl/EsProductServiceImpl.java
0 → 100644
浏览文件 @
d1e687da
package
com.macro.mall.search.service.impl
;
import
com.macro.mall.search.dao.EsProductDao
;
import
com.macro.mall.search.domain.EsProduct
;
import
com.macro.mall.search.repository.EsProductRepository
;
import
com.macro.mall.search.service.EsProductService
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
java.util.List
;
/**
* 商品搜索管理Service实现类
* Created by macro on 2018/6/19.
*/
@Service
public
class
EsProductServiceImpl
implements
EsProductService
{
@Autowired
private
EsProductDao
productDao
;
@Autowired
private
EsProductRepository
productRepository
;
@Override
public
Object
importAll
()
{
List
<
EsProduct
>
esProductList
=
productDao
.
getAllEsProductList
();
Iterable
<
EsProduct
>
esProductIterable
=
productRepository
.
save
(
esProductList
);
return
esProductIterable
;
}
}
mall-search/src/main/resources/application.properties
浏览文件 @
d1e687da
#===server start===
server.port
=
8081
#===server end===
#===datasource start===
spring.datasource.url
=
jdbc:mysql://localhost:3306/mall
spring.datasource.username
=
root
spring.datasource.password
=
root
#===datasource end===
#===mybatis start===
mybatis.mapper-locations
=
classpath:dao/*.xml,classpath*:com/**/mapper/*.xml
#===mybatis end===
#===es start===
spring.data.elasticsearch.repositories.enabled
=
true
spring.data.elasticsearch.cluster-nodes
=
127.0.0.1:9300
#===es
end
=
==
\ No newline at end of file
mall-search/src/main/resources/dao/EsProductDao.xml
0 → 100644
浏览文件 @
d1e687da
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper
namespace=
"com.macro.mall.search.dao.EsProductDao"
>
<resultMap
id=
"esProductListMap"
type=
"com.macro.mall.search.domain.EsProduct"
autoMapping=
"true"
>
<id
column=
"id"
jdbcType=
"BIGINT"
property=
"id"
/>
<collection
property=
"attrValueList"
columnPrefix=
"attr_"
resultMap=
"com.macro.mall.mapper.PmsProductAttributeValueMapper.BaseResultMap"
>
</collection>
</resultMap>
<select
id=
"getAllEsProductList"
resultMap=
"esProductListMap"
>
select
p.id id,
p.product_sn productSn,
p.brand_id brandId,
p.brand_name brandName,
p.product_category_id productCategoryId,
p.product_category_name productCategoryName,
p.pic pic,
p.name name,
p.sub_title subTitle,
p.price price,
p.sale sale,
p.new_status newStatus,
p.recommand_status recommandStatus,
p.stock stock,
p.promotion_type promotionType,
p.sort sort,
a.id attr_id,
a.value attr_value
from pms_product p
left join pms_product_attribute_value a on p.id = a.product_id
where delete_status = 0 and publish_status = 1
</select>
</mapper>
\ No newline at end of file
mall-search/src/test/java/com/macro/mall/search/MallSearchApplicationTests.java
浏览文件 @
d1e687da
package
com.macro.mall.search
;
import
com.macro.mall.search.dao.EsProductDao
;
import
com.macro.mall.search.domain.EsProduct
;
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
;
@RunWith
(
SpringRunner
.
class
)
@SpringBootTest
public
class
MallSearchApplicationTests
{
@Autowired
private
EsProductDao
productDao
;
@Test
public
void
contextLoads
()
{
}
@Test
public
void
testGetAllEsProductList
(){
List
<
EsProduct
>
esProductList
=
productDao
.
getAllEsProductList
();
System
.
out
.
print
(
esProductList
);
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录