Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gic-platform-message
Overview
Overview
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
base_platform_enterprise
gic-platform-message
Commits
2046261c
Commit
2046261c
authored
Apr 14, 2020
by
陶光胜
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'developer' into 'master'
Developer See merge request
!1
parents
310d9b92
92ce5df5
Hide whitespace changes
Inline
Side-by-side
Showing
14 changed files
with
495 additions
and
186 deletions
+495
-186
pom.xml
pom.xml
+5
-0
Constants.java
src/main/java/com/gic/message/constant/Constants.java
+6
-0
TabCityMapper.java
src/main/java/com/gic/message/dao/mapper/TabCityMapper.java
+0
-63
TestMapper.java
src/main/java/com/gic/message/dao/mapper/TestMapper.java
+4
-0
MessageHandler.java
src/main/java/com/gic/message/service/MessageHandler.java
+8
-0
KafkaMessageServiceImpl.java
...com/gic/message/service/impl/KafkaMessageServiceImpl.java
+10
-2
MessageHandlerInit.java
...java/com/gic/message/service/impl/MessageHandlerInit.java
+36
-0
StoreCustomMessageHandler.java
...m/gic/message/service/impl/StoreCustomMessageHandler.java
+117
-0
StoreIndexRefreshHandler.java
...om/gic/message/service/impl/StoreIndexRefreshHandler.java
+23
-0
StoreInfoMessageHandler.java
...com/gic/message/service/impl/StoreInfoMessageHandler.java
+127
-0
StoreMessageHandler.java
...ava/com/gic/message/service/impl/StoreMessageHandler.java
+119
-0
ListToMapUtil.java
src/main/java/com/gic/message/utils/ListToMapUtil.java
+34
-0
dubbo-gic-platform-message.xml
src/main/resources/dubbo-gic-platform-message.xml
+6
-0
TabCityMapper.xml
src/main/resources/mapper/TabCityMapper.xml
+0
-121
No files found.
pom.xml
View file @
2046261c
...
...
@@ -139,6 +139,11 @@
<artifactId>
gic-binlog-base
</artifactId>
<version>
1.0-SNAPSHOT
</version>
</dependency>
<dependency>
<groupId>
com.gic
</groupId>
<artifactId>
gic-platform-auth-api
</artifactId>
<version>
${gic-platform-auth-api}
</version>
</dependency>
</dependencies>
<build>
...
...
src/main/java/com/gic/message/constant/Constants.java
0 → 100644
View file @
2046261c
package
com
.
gic
.
message
.
constant
;
public
class
Constants
{
public
static
final
String
INSERT
=
"INSERT"
;
public
static
final
String
UPDATE
=
"UPDATE"
;
}
src/main/java/com/gic/message/dao/mapper/TabCityMapper.java
deleted
100644 → 0
View file @
310d9b92
package
com
.
gic
.
message
.
dao
.
mapper
;
import
com.gic.store.entity.TabCity
;
import
java.util.List
;
public
interface
TabCityMapper
{
/**
* 根据主键删除
*
* @param cityId 主键
* @return 更新条目数
*/
int
deleteByPrimaryKey
(
String
cityId
);
/**
* 插入一条记录
*
* @param record 实体对象
* @return 更新条目数
*/
int
insert
(
TabCity
record
);
/**
* 动态插入一条记录
*
* @param record 实体对象
* @return 更新条目数
*/
int
insertSelective
(
TabCity
record
);
/**
* 根据主键查询
*
* @param cityId 主键
* @return 实体对象
*/
TabCity
selectByPrimaryKey
(
String
cityId
);
/**
* 根据主键动态更新记录
*
* @param record 实体对象
* @return 更新条目数
*/
int
updateByPrimaryKeySelective
(
TabCity
record
);
/**
* 根据主键更新记录
*
* @param record 实体对象
* @return 更新条目数
*/
int
updateByPrimaryKey
(
TabCity
record
);
/**
* 查询所有城市
* @return
*/
List
<
TabCity
>
selectAllCity
();
}
\ No newline at end of file
src/main/java/com/gic/message/dao/mapper/TestMapper.java
0 → 100644
View file @
2046261c
package
com
.
gic
.
message
.
dao
.
mapper
;
public
class
TestMapper
{
}
src/main/java/com/gic/message/service/MessageHandler.java
0 → 100644
View file @
2046261c
package
com
.
gic
.
message
.
service
;
import
com.gic.binlog.base.entity.GicRecord
;
import
org.apache.kafka.clients.consumer.ConsumerRecord
;
public
interface
MessageHandler
{
void
handler
(
ConsumerRecord
<
String
,
GicRecord
>
consumerRecord
);
}
src/main/java/com/gic/message/service/impl/KafkaMessageServiceImpl.java
View file @
2046261c
...
...
@@ -2,16 +2,24 @@ package com.gic.message.service.impl;
import
com.alibaba.fastjson.JSON
;
import
com.gic.binlog.base.entity.GicRecord
;
import
com.gic.message.service.MessageHandler
;
import
org.apache.kafka.clients.consumer.ConsumerRecord
;
import
org.apache.logging.log4j.LogManager
;
import
org.apache.logging.log4j.Logger
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.kafka.listener.MessageListener
;
public
class
KafkaMessageServiceImpl
implements
MessageListener
<
String
,
GicRecord
>
{
private
static
final
Logger
log
=
LogManager
.
getLogger
(
KafkaMessageServiceImpl
.
class
);
@Autowired
private
MessageHandlerInit
messageHandlerInit
;
@Override
public
void
onMessage
(
ConsumerRecord
<
String
,
GicRecord
>
stringGicRecordConsumerRecord
)
{
log
.
info
(
"接收kafka消息,内容为:{}"
,
JSON
.
toJSONString
(
stringGicRecordConsumerRecord
));
public
void
onMessage
(
ConsumerRecord
<
String
,
GicRecord
>
consumerRecord
)
{
log
.
info
(
"接收kafka消息,内容为111:"
+
consumerRecord
.
value
());
MessageHandler
handler
=
this
.
messageHandlerInit
.
getHandler
().
get
(
consumerRecord
.
value
().
getTableName
());
if
(
handler
!=
null
){
handler
.
handler
(
consumerRecord
);
}
}
}
src/main/java/com/gic/message/service/impl/MessageHandlerInit.java
0 → 100644
View file @
2046261c
package
com
.
gic
.
message
.
service
.
impl
;
import
com.gic.message.service.MessageHandler
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Component
;
import
javax.annotation.PostConstruct
;
import
java.util.HashMap
;
import
java.util.Map
;
@Component
public
class
MessageHandlerInit
{
@Autowired
private
StoreMessageHandler
storeMessageHandler
;
@Autowired
private
StoreInfoMessageHandler
storeInfoMessageHandler
;
@Autowired
private
StoreCustomMessageHandler
storeCustomMessageHandler
;
private
Map
<
String
,
MessageHandler
>
handler
=
new
HashMap
<>();
@PostConstruct
public
void
init
(){
handler
.
put
(
"tab_store"
,
this
.
storeMessageHandler
);
handler
.
put
(
"tab_store_info"
,
this
.
storeInfoMessageHandler
);
handler
.
put
(
"tab_store_extend"
,
this
.
storeCustomMessageHandler
);
}
public
Map
<
String
,
MessageHandler
>
getHandler
()
{
return
handler
;
}
public
void
setHandler
(
Map
<
String
,
MessageHandler
>
handler
)
{
this
.
handler
=
handler
;
}
}
src/main/java/com/gic/message/service/impl/StoreCustomMessageHandler.java
0 → 100644
View file @
2046261c
package
com
.
gic
.
message
.
service
.
impl
;
import
com.gic.api.base.commons.Page
;
import
com.gic.api.base.commons.ServiceResponse
;
import
com.gic.auth.constant.AuthModeEnum
;
import
com.gic.auth.dto.UnionEnterpriseResourceDTO
;
import
com.gic.auth.service.UnionEnterpriseApiService
;
import
com.gic.binlog.base.entity.GicField
;
import
com.gic.binlog.base.entity.GicRecord
;
import
com.gic.binlog.base.entity.enums.GicRecordType
;
import
com.gic.message.service.MessageHandler
;
import
com.gic.message.utils.ListToMapUtil
;
import
com.gic.redis.data.util.RedisUtil
;
import
com.gic.store.constant.StoreOwnTypeEnum
;
import
com.gic.store.dto.StoreDTO
;
import
com.gic.store.dto.StoreSearchDTO
;
import
com.gic.store.dto.StoreWidgetDTO
;
import
com.gic.store.service.StoreApiService
;
import
com.gic.store.service.StoreAuthorizationApiService
;
import
com.gic.store.service.StoreWidgetApiService
;
import
org.apache.commons.collections.CollectionUtils
;
import
org.apache.kafka.clients.consumer.ConsumerRecord
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Component
;
import
java.util.List
;
import
java.util.Map
;
@Component
public
class
StoreCustomMessageHandler
implements
MessageHandler
{
@Autowired
private
StoreApiService
storeApiService
;
@Autowired
private
StoreIndexRefreshHandler
storeIndexRefreshHandler
;
@Autowired
private
StoreAuthorizationApiService
storeAuthorizationApiService
;
@Autowired
private
UnionEnterpriseApiService
unionEnterpriseApiService
;
@Autowired
private
StoreWidgetApiService
storeWidgetApiService
;
@Override
public
void
handler
(
ConsumerRecord
<
String
,
GicRecord
>
consumerRecord
)
{
GicRecord
value
=
consumerRecord
.
value
();
Map
<
String
,
GicField
>
fieldMap
=
ListToMapUtil
.
listToMap
(
consumerRecord
);
Integer
enterpriseId
=
0
,
storeInfoId
=
0
,
storeFieldId
=
0
;
if
(
GicRecordType
.
INSERT
.
value
()
==
value
.
getRecordType
().
value
()
||
GicRecordType
.
DELETE
.
value
()
==
value
.
getRecordType
().
value
()){
enterpriseId
=
Integer
.
valueOf
(
fieldMap
.
get
(
"enterprise_id"
).
getValue
());
storeFieldId
=
Integer
.
valueOf
(
fieldMap
.
get
(
"store_field_id"
).
getValue
());
storeInfoId
=
Integer
.
valueOf
(
fieldMap
.
get
(
"store_info_id"
).
getValue
());
this
.
dealCustomChange
(
enterpriseId
,
storeFieldId
,
storeInfoId
,
fieldMap
);
}
if
(
GicRecordType
.
UPDATE
.
value
()
==
value
.
getRecordType
().
value
()){
enterpriseId
=
Integer
.
valueOf
(
fieldMap
.
get
(
"new_enterprise_id"
).
getValue
());
storeFieldId
=
Integer
.
valueOf
(
fieldMap
.
get
(
"new_store_field_id"
).
getValue
());
storeInfoId
=
Integer
.
valueOf
(
fieldMap
.
get
(
"new_store_info_id"
).
getValue
());
if
(!
fieldMap
.
get
(
"old_value"
).
getValue
().
equals
(
fieldMap
.
get
(
"new_value"
).
getValue
())){
this
.
dealCustomChange
(
enterpriseId
,
storeFieldId
,
storeInfoId
,
fieldMap
);
}
}
}
private
void
dealCustomChange
(
Integer
enterpriseId
,
Integer
storeFieldId
,
Integer
storeInfoId
,
Map
<
String
,
GicField
>
fieldMap
){
String
key
=
"enterprise:store:storeField:"
+
enterpriseId
+
":"
+
storeFieldId
;
Object
existObj
=
RedisUtil
.
getCache
(
key
);
if
(
existObj
!=
null
){
ServiceResponse
<
List
<
StoreDTO
>>
listStoreResponse
=
this
.
storeApiService
.
listStoreByStoreInfoId
(
storeInfoId
);
List
<
StoreDTO
>
listStore
=
listStoreResponse
.
getResult
();
for
(
StoreDTO
storeDTO
:
listStore
){
if
(
StoreOwnTypeEnum
.
OWNER
.
getCode
()
==
storeDTO
.
getOwnType
()){
this
.
storeIndexRefreshHandler
.
refreshStoreIndex
(
storeDTO
.
getEnterpriseId
(),
storeDTO
.
getStoreId
());
}
}
this
.
dealStoreInfoChange
(
enterpriseId
,
storeInfoId
,
fieldMap
);
ServiceResponse
<
List
<
StoreDTO
>>
listStoreResponse1
=
this
.
storeApiService
.
listStoreByStoreInfoId
(
storeInfoId
);
List
<
StoreDTO
>
listStore1
=
listStoreResponse1
.
getResult
();
for
(
StoreDTO
storeDTO
:
listStore1
){
this
.
storeIndexRefreshHandler
.
refreshStoreIndex
(
storeDTO
.
getEnterpriseId
(),
storeDTO
.
getStoreId
());
}
}
}
private
void
dealStoreInfoChange
(
Integer
enterpriseId
,
Integer
storeInfoId
,
Map
<
String
,
GicField
>
fieldMap
){
ServiceResponse
<
List
<
UnionEnterpriseResourceDTO
>>
resourceResponse
=
this
.
unionEnterpriseApiService
.
listStoreResourceByEnterpriseId
(
enterpriseId
);
if
(
CollectionUtils
.
isNotEmpty
(
resourceResponse
.
getResult
())){
for
(
UnionEnterpriseResourceDTO
dto
:
resourceResponse
.
getResult
()){
ServiceResponse
<
StoreWidgetDTO
>
storeWidget
=
this
.
storeWidgetApiService
.
getStoreWidget
(
dto
.
getResource
().
intValue
());
if
(!
storeWidget
.
isSuccess
()){
continue
;
}
StoreWidgetDTO
storeWidgetDTO
=
storeWidget
.
getResult
();
if
(
storeWidgetDTO
!=
null
){
if
(
AuthModeEnum
.
YES
.
getCode
()
==
storeWidgetDTO
.
getAuthMode
()){
StoreSearchDTO
storeSearchDTO
=
new
StoreSearchDTO
();
storeSearchDTO
.
setStoreInfoIds
(
String
.
valueOf
(
storeInfoId
));
storeSearchDTO
.
setSearchJson
(
storeWidgetDTO
.
getSearchParam
());
storeSearchDTO
.
setEnterpriseId
(
enterpriseId
);
ServiceResponse
<
Page
<
StoreDTO
>>
response
=
this
.
storeApiService
.
listStore
(
storeSearchDTO
,
1
,
1
);
if
(!
response
.
isSuccess
()){
continue
;
}
if
(
CollectionUtils
.
isNotEmpty
(
response
.
getResult
().
getResult
())){
StoreDTO
storeDTO
=
new
StoreDTO
();
storeDTO
.
setStoreInfoId
(
storeInfoId
);
storeDTO
.
setEnterpriseId
(
enterpriseId
);
storeDTO
.
setFromEnterpriseId
(
dto
.
getUnionEnterpriseId
());
this
.
storeAuthorizationApiService
.
saveStore
(
storeDTO
);
}
else
{
this
.
storeAuthorizationApiService
.
cancelStore
(
storeInfoId
,
dto
.
getUnionEnterpriseId
());
}
}
}
}
}
}
}
src/main/java/com/gic/message/service/impl/StoreIndexRefreshHandler.java
0 → 100644
View file @
2046261c
package
com
.
gic
.
message
.
service
.
impl
;
import
com.gic.redis.data.util.RedisUtil
;
import
com.gic.store.service.StoreApiService
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Component
;
import
java.util.concurrent.TimeUnit
;
@Component
public
class
StoreIndexRefreshHandler
{
@Autowired
private
StoreApiService
storeApiService
;
public
void
refreshStoreIndex
(
Integer
enterpriseId
,
Integer
storeId
){
String
key
=
"enterprise:refresh:"
+
storeId
;
Object
cache
=
RedisUtil
.
getCache
(
key
);
if
(
cache
==
null
){
this
.
storeApiService
.
addStoreToIndex
(
enterpriseId
,
storeId
);
RedisUtil
.
setCache
(
key
,
storeId
,
1
l
,
TimeUnit
.
SECONDS
);
}
}
}
src/main/java/com/gic/message/service/impl/StoreInfoMessageHandler.java
0 → 100644
View file @
2046261c
package
com
.
gic
.
message
.
service
.
impl
;
import
com.gic.api.base.commons.Page
;
import
com.gic.api.base.commons.ServiceResponse
;
import
com.gic.auth.constant.AuthModeEnum
;
import
com.gic.auth.dto.UnionEnterpriseResourceDTO
;
import
com.gic.auth.service.UnionEnterpriseApiService
;
import
com.gic.binlog.base.entity.GicField
;
import
com.gic.binlog.base.entity.GicRecord
;
import
com.gic.binlog.base.entity.enums.GicRecordType
;
import
com.gic.message.service.MessageHandler
;
import
com.gic.message.utils.ListToMapUtil
;
import
com.gic.store.constant.StoreOwnTypeEnum
;
import
com.gic.store.dto.StoreDTO
;
import
com.gic.store.dto.StoreSearchDTO
;
import
com.gic.store.dto.StoreWidgetDTO
;
import
com.gic.store.service.StoreApiService
;
import
com.gic.store.service.StoreAuthorizationApiService
;
import
com.gic.store.service.StoreRegionApiService
;
import
com.gic.store.service.StoreWidgetApiService
;
import
org.apache.commons.collections.CollectionUtils
;
import
org.apache.kafka.clients.consumer.ConsumerRecord
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Component
;
import
java.util.List
;
import
java.util.Map
;
@Component
public
class
StoreInfoMessageHandler
implements
MessageHandler
{
@Autowired
private
StoreIndexRefreshHandler
storeIndexRefreshHandler
;
@Autowired
private
StoreApiService
storeApiService
;
@Autowired
private
StoreWidgetApiService
storeWidgetApiService
;
@Autowired
private
UnionEnterpriseApiService
unionEnterpriseApiService
;
@Autowired
private
StoreAuthorizationApiService
storeAuthorizationApiService
;
@Autowired
private
StoreRegionApiService
storeRegionApiService
;
@Override
public
void
handler
(
ConsumerRecord
<
String
,
GicRecord
>
consumerRecord
)
{
GicRecord
value
=
consumerRecord
.
value
();
Map
<
String
,
GicField
>
fieldMap
=
ListToMapUtil
.
listToMap
(
consumerRecord
);
Integer
enterpriseId
=
0
,
storeInfoId
=
0
,
storeId
=
0
;
if
(
GicRecordType
.
INSERT
.
value
()
==
value
.
getRecordType
().
value
()){
}
if
(
GicRecordType
.
UPDATE
.
value
()
==
value
.
getRecordType
().
value
()){
enterpriseId
=
Integer
.
valueOf
(
fieldMap
.
get
(
"new_enterprise_id"
).
getValue
());
storeInfoId
=
Integer
.
valueOf
(
fieldMap
.
get
(
"new_store_info_id"
).
getValue
());
ServiceResponse
<
List
<
StoreDTO
>>
listStoreResponse
=
this
.
storeApiService
.
listStoreByStoreInfoId
(
storeInfoId
);
List
<
StoreDTO
>
listStore
=
listStoreResponse
.
getResult
();
for
(
StoreDTO
storeDTO
:
listStore
){
if
(
storeDTO
.
getOwnType
()
==
StoreOwnTypeEnum
.
OWNER
.
getCode
()){
if
(
Integer
.
valueOf
(
fieldMap
.
get
(
"old_status"
).
getValue
())
==
1
&&
Integer
.
valueOf
(
fieldMap
.
get
(
"new_status"
).
getValue
())
==
0
){
this
.
storeApiService
.
deleteStoreFromES
(
storeDTO
.
getEnterpriseId
(),
storeDTO
.
getStoreId
());
}
else
{
this
.
storeIndexRefreshHandler
.
refreshStoreIndex
(
storeDTO
.
getEnterpriseId
(),
storeDTO
.
getStoreId
());
}
}
}
this
.
dealStoreInfoChange
(
enterpriseId
,
storeInfoId
,
fieldMap
);
ServiceResponse
<
List
<
StoreDTO
>>
listStoreResponse1
=
this
.
storeApiService
.
listStoreByStoreInfoId
(
storeInfoId
);
List
<
StoreDTO
>
listStore1
=
listStoreResponse1
.
getResult
();
for
(
StoreDTO
storeDTO
:
listStore1
){
this
.
storeIndexRefreshHandler
.
refreshStoreIndex
(
storeDTO
.
getEnterpriseId
(),
storeDTO
.
getStoreId
());
}
}
if
(
GicRecordType
.
DELETE
.
value
()
==
value
.
getRecordType
().
value
()){
storeInfoId
=
Integer
.
valueOf
(
fieldMap
.
get
(
"store_info_id"
).
getValue
());
ServiceResponse
<
List
<
StoreDTO
>>
listStoreResponse
=
this
.
storeApiService
.
listStoreByStoreInfoId
(
storeInfoId
);
List
<
StoreDTO
>
listStore
=
listStoreResponse
.
getResult
();
for
(
StoreDTO
storeDTO
:
listStore
){
this
.
storeApiService
.
deleteStoreFromES
(
storeDTO
.
getEnterpriseId
(),
storeDTO
.
getStoreId
());
}
}
}
private
void
dealStoreInfoChange
(
Integer
enterpriseId
,
Integer
storeInfoId
,
Map
<
String
,
GicField
>
fieldMap
){
ServiceResponse
<
List
<
UnionEnterpriseResourceDTO
>>
resourceResponse
=
this
.
unionEnterpriseApiService
.
listStoreResourceByEnterpriseId
(
enterpriseId
);
if
(
CollectionUtils
.
isNotEmpty
(
resourceResponse
.
getResult
())){
for
(
UnionEnterpriseResourceDTO
dto
:
resourceResponse
.
getResult
()){
ServiceResponse
<
StoreWidgetDTO
>
storeWidget
=
this
.
storeWidgetApiService
.
getStoreWidget
(
dto
.
getResource
().
intValue
());
if
(!
storeWidget
.
isSuccess
()){
continue
;
}
StoreWidgetDTO
storeWidgetDTO
=
storeWidget
.
getResult
();
if
(
storeWidgetDTO
!=
null
){
if
(
AuthModeEnum
.
YES
.
getCode
()
==
storeWidgetDTO
.
getAuthMode
()){
StoreSearchDTO
storeSearchDTO
=
new
StoreSearchDTO
();
storeSearchDTO
.
setStoreInfoIds
(
String
.
valueOf
(
storeInfoId
));
storeSearchDTO
.
setSearchJson
(
storeWidgetDTO
.
getSearchParam
());
storeSearchDTO
.
setEnterpriseId
(
enterpriseId
);
ServiceResponse
<
Page
<
StoreDTO
>>
response
=
this
.
storeApiService
.
listStore
(
storeSearchDTO
,
1
,
1
);
if
(!
response
.
isSuccess
()){
continue
;
}
if
(
CollectionUtils
.
isNotEmpty
(
response
.
getResult
().
getResult
())){
StoreDTO
storeDTO
=
new
StoreDTO
();
storeDTO
.
setStoreInfoId
(
storeInfoId
);
storeDTO
.
setEnterpriseId
(
enterpriseId
);
storeDTO
.
setFromEnterpriseId
(
dto
.
getUnionEnterpriseId
());
this
.
storeAuthorizationApiService
.
saveStore
(
storeDTO
);
}
else
{
this
.
storeAuthorizationApiService
.
cancelStore
(
storeInfoId
,
dto
.
getUnionEnterpriseId
());
}
if
(
Integer
.
valueOf
(
fieldMap
.
get
(
"old_region_id"
).
getValue
())
!=
Integer
.
valueOf
(
fieldMap
.
get
(
"new_region_id"
).
getValue
())){
StoreSearchDTO
storeSearchDTO1
=
new
StoreSearchDTO
();
storeSearchDTO1
.
setRegionId
(
Integer
.
valueOf
(
fieldMap
.
get
(
"old_region_id"
).
getValue
()));
storeSearchDTO1
.
setSearchJson
(
storeWidgetDTO
.
getSearchParam
());
storeSearchDTO1
.
setEnterpriseId
(
enterpriseId
);
ServiceResponse
<
Page
<
StoreDTO
>>
response1
=
this
.
storeApiService
.
listStore
(
storeSearchDTO
,
1
,
1
);
if
(
CollectionUtils
.
isEmpty
(
response1
.
getResult
().
getResult
())){
this
.
storeRegionApiService
.
unAuthorizeRegion
(
dto
.
getUnionEnterpriseId
(),
Integer
.
valueOf
(
fieldMap
.
get
(
"old_region_id"
).
getValue
()));
}
}
}
}
}
}
}
}
src/main/java/com/gic/message/service/impl/StoreMessageHandler.java
0 → 100644
View file @
2046261c
package
com
.
gic
.
message
.
service
.
impl
;
import
com.gic.api.base.commons.Page
;
import
com.gic.api.base.commons.ServiceResponse
;
import
com.gic.auth.constant.AuthModeEnum
;
import
com.gic.auth.dto.UnionEnterpriseDTO
;
import
com.gic.auth.dto.UnionEnterpriseResourceDTO
;
import
com.gic.auth.service.UnionEnterpriseApiService
;
import
com.gic.binlog.base.entity.GicField
;
import
com.gic.binlog.base.entity.GicRecord
;
import
com.gic.binlog.base.entity.enums.GicRecordType
;
import
com.gic.message.service.MessageHandler
;
import
com.gic.message.utils.ListToMapUtil
;
import
com.gic.store.constant.StoreOwnTypeEnum
;
import
com.gic.store.dto.StoreDTO
;
import
com.gic.store.dto.StoreSearchDTO
;
import
com.gic.store.dto.StoreWidgetDTO
;
import
com.gic.store.service.StoreApiService
;
import
com.gic.store.service.StoreAuthorizationApiService
;
import
com.gic.store.service.StoreWidgetApiService
;
import
org.apache.commons.collections.CollectionUtils
;
import
org.apache.kafka.clients.consumer.ConsumerRecord
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Component
;
import
java.util.List
;
import
java.util.Map
;
@Component
public
class
StoreMessageHandler
implements
MessageHandler
{
@Autowired
private
StoreApiService
storeApiService
;
@Autowired
private
StoreIndexRefreshHandler
storeIndexRefreshHandler
;
@Autowired
private
StoreWidgetApiService
storeWidgetApiService
;
@Autowired
private
UnionEnterpriseApiService
unionEnterpriseApiService
;
@Autowired
private
StoreAuthorizationApiService
storeAuthorizationApiService
;
@Override
public
void
handler
(
ConsumerRecord
<
String
,
GicRecord
>
consumerRecord
){
GicRecord
value
=
consumerRecord
.
value
();
Map
<
String
,
GicField
>
fieldMap
=
ListToMapUtil
.
listToMap
(
consumerRecord
);
Integer
enterpriseId
=
0
,
storeId
=
0
,
storeInfoId
;
if
(
GicRecordType
.
INSERT
.
value
()
==
value
.
getRecordType
().
value
()){
enterpriseId
=
Integer
.
valueOf
(
fieldMap
.
get
(
"enterprise_id"
).
getValue
());
storeId
=
Integer
.
valueOf
(
fieldMap
.
get
(
"store_id"
).
getValue
());
storeInfoId
=
Integer
.
valueOf
(
fieldMap
.
get
(
"store_info_id"
).
getValue
());
this
.
storeIndexRefreshHandler
.
refreshStoreIndex
(
enterpriseId
,
storeId
);
Integer
ownType
=
Integer
.
valueOf
(
fieldMap
.
get
(
"own_type"
).
getValue
());
if
(
ownType
==
StoreOwnTypeEnum
.
OWNER
.
getCode
()){
this
.
dealStoreChange
(
enterpriseId
,
storeId
,
storeInfoId
,
GicRecordType
.
INSERT
.
value
());
}
}
if
(
GicRecordType
.
UPDATE
.
value
()
==
value
.
getRecordType
().
value
())
{
enterpriseId
=
Integer
.
valueOf
(
fieldMap
.
get
(
"new_enterprise_id"
).
getValue
());
storeId
=
Integer
.
valueOf
(
fieldMap
.
get
(
"new_store_id"
).
getValue
());
storeInfoId
=
Integer
.
valueOf
(
fieldMap
.
get
(
"new_store_info_id"
).
getValue
());
if
(
Integer
.
valueOf
(
fieldMap
.
get
(
"old_status"
).
getValue
())
==
1
&&
Integer
.
valueOf
(
fieldMap
.
get
(
"new_status"
).
getValue
())
==
0
)
{
this
.
storeApiService
.
deleteStoreFromES
(
enterpriseId
,
storeId
);
}
else
{
this
.
storeIndexRefreshHandler
.
refreshStoreIndex
(
enterpriseId
,
storeId
);
}
if
(
StoreOwnTypeEnum
.
OWNER
.
getCode
()
==
Integer
.
valueOf
(
fieldMap
.
get
(
"new_own_type"
).
getValue
()))
{
this
.
dealStoreChange
(
enterpriseId
,
storeId
,
storeInfoId
,
GicRecordType
.
UPDATE
.
value
());
}
}
if
(
GicRecordType
.
DELETE
.
value
()
==
value
.
getRecordType
().
value
()){
enterpriseId
=
Integer
.
valueOf
(
fieldMap
.
get
(
"enterprise_id"
).
getValue
());
storeId
=
Integer
.
valueOf
(
fieldMap
.
get
(
"store_id"
).
getValue
());
storeInfoId
=
Integer
.
valueOf
(
fieldMap
.
get
(
"store_info_id"
).
getValue
());
this
.
storeApiService
.
deleteStoreFromES
(
enterpriseId
,
storeId
);
Integer
ownType
=
Integer
.
valueOf
(
fieldMap
.
get
(
"own_type"
).
getValue
());
if
(
ownType
==
StoreOwnTypeEnum
.
OWNER
.
getCode
()){
this
.
dealStoreChange
(
enterpriseId
,
storeId
,
storeInfoId
,
GicRecordType
.
DELETE
.
value
());
}
}
}
private
void
dealStoreChange
(
Integer
enterpriseId
,
Integer
storeId
,
Integer
storeInfoId
,
int
recordType
){
ServiceResponse
<
List
<
UnionEnterpriseResourceDTO
>>
resourceResponse
=
this
.
unionEnterpriseApiService
.
listStoreResourceByEnterpriseId
(
enterpriseId
);
if
(
CollectionUtils
.
isNotEmpty
(
resourceResponse
.
getResult
())){
for
(
UnionEnterpriseResourceDTO
dto
:
resourceResponse
.
getResult
()){
ServiceResponse
<
StoreWidgetDTO
>
storeWidget
=
this
.
storeWidgetApiService
.
getStoreWidget
(
dto
.
getResource
().
intValue
());
if
(!
storeWidget
.
isSuccess
()){
continue
;
}
StoreWidgetDTO
storeWidgetDTO
=
storeWidget
.
getResult
();
if
(
storeWidgetDTO
!=
null
){
if
(
AuthModeEnum
.
YES
.
getCode
()
==
storeWidgetDTO
.
getAuthMode
()){
StoreSearchDTO
storeSearchDTO
=
new
StoreSearchDTO
();
storeSearchDTO
.
setStoreIds
(
String
.
valueOf
(
storeId
));
storeSearchDTO
.
setSearchJson
(
storeWidgetDTO
.
getSearchParam
());
storeSearchDTO
.
setEnterpriseId
(
enterpriseId
);
ServiceResponse
<
Page
<
StoreDTO
>>
response
=
this
.
storeApiService
.
listStore
(
storeSearchDTO
,
1
,
1
);
if
(!
response
.
isSuccess
()){
continue
;
}
if
(
CollectionUtils
.
isNotEmpty
(
response
.
getResult
().
getResult
())){
if
(
GicRecordType
.
DELETE
.
value
()
==
recordType
){
this
.
storeAuthorizationApiService
.
cancelStore
(
storeInfoId
,
dto
.
getUnionEnterpriseId
());
}
else
{
StoreDTO
storeDTO
=
new
StoreDTO
();
storeDTO
.
setStoreInfoId
(
storeInfoId
);
storeDTO
.
setEnterpriseId
(
enterpriseId
);
storeDTO
.
setFromEnterpriseId
(
dto
.
getUnionEnterpriseId
());
this
.
storeAuthorizationApiService
.
saveStore
(
storeDTO
);
}
}
else
{
this
.
storeAuthorizationApiService
.
cancelStore
(
storeInfoId
,
dto
.
getUnionEnterpriseId
());
}
}
}
}
}
}
}
src/main/java/com/gic/message/utils/ListToMapUtil.java
0 → 100644
View file @
2046261c
package
com
.
gic
.
message
.
utils
;
import
com.gic.binlog.base.entity.GicField
;
import
com.gic.binlog.base.entity.GicRecord
;
import
com.gic.binlog.base.entity.enums.GicRecordType
;
import
org.apache.kafka.clients.consumer.ConsumerRecord
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
public
class
ListToMapUtil
{
public
static
Map
<
String
,
GicField
>
listToMap
(
ConsumerRecord
<
String
,
GicRecord
>
consumerRecord
){
GicRecord
value
=
consumerRecord
.
value
();
List
<
GicField
>
list
=
value
.
getFieldList
();
Map
<
String
,
GicField
>
result
=
new
HashMap
<>();
if
(
value
.
getRecordType
().
value
()
==
GicRecordType
.
INSERT
.
value
()
||
value
.
getRecordType
().
value
()
==
GicRecordType
.
DELETE
.
value
()){
for
(
int
i
=
0
;
i
<
list
.
size
();
i
++){
GicField
gicField
=
list
.
get
(
i
);
result
.
put
(
gicField
.
getName
(),
gicField
);
}
}
if
(
value
.
getRecordType
().
value
()
==
GicRecordType
.
UPDATE
.
value
()){
for
(
int
i
=
0
;
i
<
list
.
size
();){
GicField
oldField
=
list
.
get
(
i
);
GicField
newFiled
=
list
.
get
(
i
+
1
);
result
.
put
(
"old_"
+
oldField
.
getName
(),
oldField
);
result
.
put
(
"new_"
+
newFiled
.
getName
(),
newFiled
);
i
=
i
+
2
;
}
}
return
result
;
}
}
src/main/resources/dubbo-gic-platform-message.xml
View file @
2046261c
...
...
@@ -19,4 +19,10 @@
<dubbo:reference
interface=
"com.gic.log.api.service.LogApiService"
id=
"logApiService"
timeout=
"6000"
/>
<dubbo:reference
interface=
"com.gic.search.business.api.service.EsBusinessOperaApiService"
id=
"esBusinessOperaApiService"
timeout=
"6000"
/>
<dubbo:reference
interface=
"com.gic.enterprise.service.PlatformBrandApiService"
id=
"platformBrandApiService"
timeout=
"6000"
/>
<dubbo:reference
interface=
"com.gic.store.service.StoreApiService"
id=
"storeApiService"
timeout=
"6000"
/>
<dubbo:reference
interface=
"com.gic.auth.service.UnionEnterpriseApiService"
id=
"unionEnterpriseApiService"
timeout=
"6000"
/>
<dubbo:reference
interface=
"com.gic.store.service.StoreWidgetApiService"
id=
"storeWidgetApiService"
timeout=
"6000"
/>
<dubbo:reference
interface=
"com.gic.store.service.StoreAuthorizationApiService"
id=
"storeAuthorizationApiService"
timeout=
"6000"
/>
<dubbo:reference
interface=
"com.gic.store.service.StoreRegionApiService"
id=
"storeRegionApiService"
timeout=
"6000"
/>
</beans>
src/main/resources/mapper/TabCityMapper.xml
deleted
100644 → 0
View file @
310d9b92
<?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.gic.store.dao.mapper.TabCityMapper"
>
<resultMap
id=
"BaseResultMap"
type=
"com.gic.store.entity.TabCity"
>
<id
column=
"city_id"
jdbcType=
"VARCHAR"
property=
"cityId"
/>
<result
column=
"city_name"
jdbcType=
"VARCHAR"
property=
"cityName"
/>
<result
column=
"province_id"
jdbcType=
"VARCHAR"
property=
"provinceId"
/>
<result
column=
"city_py"
jdbcType=
"VARCHAR"
property=
"cityPy"
/>
<result
column=
"create_time"
jdbcType=
"TIMESTAMP"
property=
"createTime"
/>
<result
column=
"update_time"
jdbcType=
"TIMESTAMP"
property=
"updateTime"
/>
</resultMap>
<sql
id=
"Base_Column_List"
>
city_id, city_name, province_id, city_py, create_time, update_time
</sql>
<select
id=
"selectByPrimaryKey"
parameterType=
"java.lang.String"
resultMap=
"BaseResultMap"
>
select
<include
refid=
"Base_Column_List"
/>
from tab_city
where city_id = #{cityId,jdbcType=VARCHAR}
</select>
<delete
id=
"deleteByPrimaryKey"
parameterType=
"java.lang.String"
>
delete from tab_city
where city_id = #{cityId,jdbcType=VARCHAR}
</delete>
<insert
id=
"insert"
parameterType=
"com.gic.store.entity.TabCity"
>
insert into tab_city (city_id, city_name, province_id,
city_py, create_time, update_time
)
values (#{cityId,jdbcType=VARCHAR}, #{cityName,jdbcType=VARCHAR}, #{provinceId,jdbcType=VARCHAR},
#{cityPy,jdbcType=VARCHAR}, #{createTime,jdbcType=TIMESTAMP}, #{updateTime,jdbcType=TIMESTAMP}
)
</insert>
<insert
id=
"insertSelective"
parameterType=
"com.gic.store.entity.TabCity"
>
insert into tab_city
<trim
prefix=
"("
suffix=
")"
suffixOverrides=
","
>
<if
test=
"cityId != null"
>
city_id,
</if>
<if
test=
"cityName != null"
>
city_name,
</if>
<if
test=
"provinceId != null"
>
province_id,
</if>
<if
test=
"cityPy != null"
>
city_py,
</if>
<if
test=
"createTime != null"
>
create_time,
</if>
<if
test=
"updateTime != null"
>
update_time,
</if>
</trim>
<trim
prefix=
"values ("
suffix=
")"
suffixOverrides=
","
>
<if
test=
"cityId != null"
>
#{cityId,jdbcType=VARCHAR},
</if>
<if
test=
"cityName != null"
>
#{cityName,jdbcType=VARCHAR},
</if>
<if
test=
"provinceId != null"
>
#{provinceId,jdbcType=VARCHAR},
</if>
<if
test=
"cityPy != null"
>
#{cityPy,jdbcType=VARCHAR},
</if>
<if
test=
"createTime != null"
>
#{createTime,jdbcType=TIMESTAMP},
</if>
<if
test=
"updateTime != null"
>
#{updateTime,jdbcType=TIMESTAMP},
</if>
</trim>
</insert>
<update
id=
"updateByPrimaryKeySelective"
parameterType=
"com.gic.store.entity.TabCity"
>
update tab_city
<set>
<if
test=
"cityName != null"
>
city_name = #{cityName,jdbcType=VARCHAR},
</if>
<if
test=
"provinceId != null"
>
province_id = #{provinceId,jdbcType=VARCHAR},
</if>
<if
test=
"cityPy != null"
>
city_py = #{cityPy,jdbcType=VARCHAR},
</if>
<if
test=
"createTime != null"
>
create_time = #{createTime,jdbcType=TIMESTAMP},
</if>
<if
test=
"updateTime != null"
>
update_time = #{updateTime,jdbcType=TIMESTAMP},
</if>
</set>
where city_id = #{cityId,jdbcType=VARCHAR}
</update>
<update
id=
"updateByPrimaryKey"
parameterType=
"com.gic.store.entity.TabCity"
>
update tab_city
set city_name = #{cityName,jdbcType=VARCHAR},
province_id = #{provinceId,jdbcType=VARCHAR},
city_py = #{cityPy,jdbcType=VARCHAR},
create_time = #{createTime,jdbcType=TIMESTAMP},
update_time = #{updateTime,jdbcType=TIMESTAMP}
where city_id = #{cityId,jdbcType=VARCHAR}
</update>
<select
id=
"selectAllCity"
resultMap=
"BaseResultMap"
>
select
<include
refid=
"Base_Column_List"
/>
from tab_city
</select>
<select
id=
"queryCity"
resultMap=
"BaseResultMap"
>
select
<include
refid=
"Base_Column_List"
/>
from tab_city where 1=1
<if
test=
"search != null and search != ''"
>
and city_name like concat('%',#{search}, '%')
</if>
</select>
</mapper>
\ No newline at end of file
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