Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
S
shop
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
曲欣亮
shop
Commits
8abd95d0
Commit
8abd95d0
authored
Oct 13, 2018
by
Quxl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修改搜索引擎代码,修改Redis配置
parent
90d5f431
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
95 additions
and
18 deletions
+95
-18
RedisConfig.java
src/main/java/com/egolm/shop/config/RedisConfig.java
+3
-1
SolrConfig.java
src/main/java/com/egolm/shop/config/SolrConfig.java
+21
-0
SolrGoodsController.java
...n/java/com/egolm/shop/controller/SolrGoodsController.java
+63
-10
SolrGoodsService.java
src/main/java/com/egolm/shop/service/SolrGoodsService.java
+0
-2
SolrGoodsServiceImpl.java
...ava/com/egolm/shop/service/impl/SolrGoodsServiceImpl.java
+6
-5
application-dev.properties
src/main/resources/application-dev.properties
+2
-0
No files found.
src/main/java/com/egolm/shop/config/RedisConfig.java
View file @
8abd95d0
package
com
.
egolm
.
shop
.
config
;
import
org.springframework.beans.factory.annotation.Qualifier
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.data.redis.connection.RedisConnectionFactory
;
...
...
@@ -15,7 +16,8 @@ import com.fasterxml.jackson.databind.ObjectMapper;
public
class
RedisConfig
{
@Bean
public
RedisTemplate
<
String
,
?>
getRedisTemplate
(
RedisConnectionFactory
connectionFactory
)
{
@Qualifier
(
"redisTemplate"
)
public
RedisTemplate
<
String
,
?>
redisTemplate
(
RedisConnectionFactory
connectionFactory
)
{
RedisTemplate
<
String
,
?>
template
=
new
RedisTemplate
<>();
template
.
setConnectionFactory
(
connectionFactory
);
Jackson2JsonRedisSerializer
<?>
valueSerializer
=
new
Jackson2JsonRedisSerializer
<
Object
>(
Object
.
class
);
...
...
src/main/java/com/egolm/shop/config/SolrConfig.java
0 → 100644
View file @
8abd95d0
package
com
.
egolm
.
shop
.
config
;
import
org.apache.solr.client.solrj.impl.HttpSolrClient
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
@Configuration
public
class
SolrConfig
{
@Value
(
"solr.baseURL"
)
private
String
baseURL
;
@Bean
public
HttpSolrClient
httpSolrClient
()
{
return
new
HttpSolrClient
(
baseURL
);
}
}
src/main/java/com/egolm/shop/controller/SolrGoodsController.java
View file @
8abd95d0
package
com
.
egolm
.
shop
.
controller
;
import
java.util.UUID
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Qualifier
;
import
org.springframework.dao.DataAccessException
;
import
org.springframework.data.redis.connection.RedisConnection
;
import
org.springframework.data.redis.core.RedisCallback
;
import
org.springframework.data.redis.core.RedisTemplate
;
import
org.springframework.scheduling.annotation.Scheduled
;
import
org.springframework.stereotype.Controller
;
import
org.springframework.web.bind.annotation.PostMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.ResponseBody
;
...
...
@@ -13,6 +22,7 @@ import io.swagger.annotations.Api;
import
io.swagger.annotations.ApiImplicitParam
;
import
io.swagger.annotations.ApiImplicitParams
;
import
io.swagger.annotations.ApiOperation
;
import
redis.clients.jedis.JedisCommands
;
@Api
@Controller
...
...
@@ -21,9 +31,13 @@ public class SolrGoodsController {
@Autowired
private
SolrGoodsService
service
;
@Autowired
@Qualifier
(
"redisTemplate"
)
private
RedisTemplate
<
String
,
?>
redisTemplate
;
@ResponseBody
@
Reque
stMapping
(
"query"
)
@
Po
stMapping
(
"query"
)
@ApiOperation
(
"搜索引擎商品搜索"
)
@ApiImplicitParams
({
@ApiImplicitParam
(
dataType
=
"long"
,
allowMultiple
=
false
,
name
=
"index"
,
value
=
"分页编号"
),
...
...
@@ -40,15 +54,7 @@ public class SolrGoodsController {
}
@ResponseBody
@RequestMapping
(
"update"
)
@ApiOperation
(
"搜索引擎更新全部商品索引"
)
public
Object
update
()
{
service
.
update
();
return
Rjx
.
jsonOk
();
}
@ResponseBody
@RequestMapping
(
"updateByDistrictID"
)
@PostMapping
(
"updateByDistrictID"
)
@ApiOperation
(
"搜索引擎按区域编号更新商品索引"
)
@ApiImplicitParams
({
@ApiImplicitParam
(
dataType
=
"string"
,
name
=
"sDistrictID"
,
value
=
"区域编号"
),
...
...
@@ -58,4 +64,51 @@ public class SolrGoodsController {
return
Rjx
.
jsonOk
();
}
@ResponseBody
@PostMapping
(
"update"
)
@Scheduled
(
cron
=
"0 0 4 * * ?"
)
@ApiOperation
(
"搜索引擎更新全部商品索引"
)
public
Object
update
()
{
if
(
this
.
getLock
().
getCode
()
==
200
)
{
try
{
service
.
update
(
null
);
}
finally
{
this
.
releaseLock
();
}
}
else
{
return
Rjx
.
jsonErr
().
setMessage
(
"该任务正在运行,请不要重复执行"
);
}
return
Rjx
.
jsonOk
();
}
private
static
final
String
SCHEDULE_LOCK_KEY
=
"SCHEDULE_LOCK_KEY"
;
private
static
final
long
SCHEDULE_LOCK_EXPIRE
=
1000
*
60
;
@ResponseBody
@PostMapping
(
"getLock"
)
@ApiOperation
(
"设置搜索引擎更新索引定时任务分布式互斥锁"
)
public
Rjx
getLock
()
{
String
result
=
redisTemplate
.
execute
(
new
RedisCallback
<
String
>()
{
@Override
public
String
doInRedis
(
RedisConnection
connection
)
throws
DataAccessException
{
JedisCommands
commands
=
(
JedisCommands
)
connection
.
getNativeConnection
();
String
uuid
=
UUID
.
randomUUID
().
toString
();
return
commands
.
set
(
SCHEDULE_LOCK_KEY
,
uuid
,
"NX"
,
"PX"
,
SCHEDULE_LOCK_EXPIRE
);
}
});
if
(
result
!=
null
&&
result
.
equals
(
"OK"
))
{
return
Rjx
.
jsonOk
();
}
else
{
return
Rjx
.
jsonErr
();
}
}
@ResponseBody
@PostMapping
(
"releaseLock"
)
@ApiOperation
(
"删除搜索引擎更新索引定时任务分布式互斥锁"
)
public
Rjx
releaseLock
()
{
redisTemplate
.
delete
(
SCHEDULE_LOCK_KEY
);
return
Rjx
.
jsonOk
();
}
}
src/main/java/com/egolm/shop/service/SolrGoodsService.java
View file @
8abd95d0
...
...
@@ -7,8 +7,6 @@ public interface SolrGoodsService {
public
Rjx
query
(
Page
page
,
String
queryKey
,
String
[]
keywords
,
String
[]
facetFields
,
String
[]
facetPivotFields
);
public
void
update
();
public
void
update
(
String
sDistrictID
);
public
void
deleteByQuery
(
String
queryKey
);
...
...
src/main/java/com/egolm/shop/service/impl/SolrGoodsServiceImpl.java
View file @
8abd95d0
...
...
@@ -23,7 +23,9 @@ import org.apache.solr.common.SolrDocument;
import
org.apache.solr.common.SolrDocumentList
;
import
org.apache.solr.common.SolrInputDocument
;
import
org.apache.solr.common.util.NamedList
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.scheduling.annotation.Async
;
import
org.springframework.stereotype.Service
;
import
com.egolm.common.DateUtil
;
import
com.egolm.common.StringUtil
;
...
...
@@ -34,11 +36,15 @@ import com.egolm.common.jdbc.Page;
import
com.egolm.shop.config.XException
;
import
com.egolm.shop.service.SolrGoodsService
;
@Service
public
class
SolrGoodsServiceImpl
implements
SolrGoodsService
{
private
static
final
Logger
logger
=
Logger
.
getLogger
(
SolrGoodsService
.
class
);
@Autowired
private
JdbcTemplate
jdbcTemplate
;
@Autowired
private
HttpSolrClient
solrClient
;
@Override
...
...
@@ -160,11 +166,6 @@ public class SolrGoodsServiceImpl implements SolrGoodsService {
}
}
@Async
public
void
update
()
{
this
.
update
(
null
);
}
@Async
public
void
update
(
String
sDistrictID
)
{
List
<
String
>
strs
=
new
ArrayList
<
String
>();
...
...
src/main/resources/application-dev.properties
View file @
8abd95d0
...
...
@@ -32,6 +32,8 @@ spring.redis.pool.max-wait=2000
spring.redis.pool.max-idle
=
5
spring.redis.pool.min-idle
=
0
solr.baseURL
=
http://10.10.0.84:8983/solr/goods
### 游客 用户生成用户的前缀
redis.guest.key
=
B2B_Guest
#### 用户验证码存储的前缀
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment