Commit 9c506311 by 陶光胜

init

parent f8f68720
package com.gic.message.service.impl;
import com.alibaba.fastjson.JSONObject;
import com.gic.redis.data.util.RedisUtil;
import com.gic.store.service.StoreApiService;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -22,7 +23,10 @@ public class StoreIndexRefreshHandler {
String key = "enterprise:refresh:"+storeId;
Object cache = RedisUtil.getCache(key);
if(cache == null){
this.storeApiService.addStoreToIndex(enterpriseId, storeId);
JSONObject json = new JSONObject();
json.put("enterpriseId", enterpriseId);
json.put("storeId", storeId);
this.storeApiService.addStoreToIndexMq(json.toJSONString());
RedisUtil.setCache(key, storeId, 1L, TimeUnit.SECONDS);
}
}
......
......@@ -3,11 +3,16 @@ 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.ResourceDTO;
import com.gic.auth.dto.UnionEnterpriseResourceDTO;
import com.gic.auth.service.ResourceApiService;
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.enterprise.dto.union.UnionEnterpriseAuthDTO;
import com.gic.enterprise.dto.union.UnionEnterpriseAuthListDTO;
import com.gic.enterprise.service.UnionEnterpriseAuthApiService;
import com.gic.message.service.MessageHandler;
import com.gic.message.utils.ListToMapUtil;
import com.gic.store.constant.StoreOwnTypeEnum;
......@@ -17,8 +22,11 @@ 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 com.gic.store.service.UnionStoreChangeApiService;
import org.apache.commons.collections.CollectionUtils;
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.stereotype.Component;
......@@ -41,6 +49,8 @@ public class StoreMessageHandler implements MessageHandler {
private static final String OLD_DELETE_FLAG = "old_delete_flag";
private static final String NEW_DELETE_FALG = "new_delete_flag";
private static final Logger logger = LogManager.getLogger(StoreMessageHandler.class);
@Autowired
private StoreApiService storeApiService;
@Autowired
......@@ -51,6 +61,12 @@ public class StoreMessageHandler implements MessageHandler {
private UnionEnterpriseApiService unionEnterpriseApiService;
@Autowired
private StoreAuthorizationApiService storeAuthorizationApiService;
@Autowired
private UnionEnterpriseAuthApiService unionEnterpriseAuthApiService;
@Autowired
private ResourceApiService resourceApiService;
@Autowired
private UnionStoreChangeApiService unionStoreChangeApiService;
@Override
public void handler(ConsumerRecord<String, GicRecord> consumerRecord){
......@@ -63,9 +79,7 @@ public class StoreMessageHandler implements MessageHandler {
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());
}
this.dealStoreChange(enterpriseId, storeId, storeInfoId, GicRecordType.INSERT.value());
}
if(GicRecordType.UPDATE.value() == value.getRecordType().value()) {
enterpriseId = Integer.valueOf(fieldMap.get("new_enterprise_id").getValue());
......@@ -74,7 +88,6 @@ public class StoreMessageHandler implements MessageHandler {
if (Integer.valueOf(fieldMap.get(OLD_DELETE_FLAG).getValue()) == 0 && Integer.valueOf(fieldMap.get(NEW_DELETE_FALG).getValue()) == 1) { //删除
this.storeApiService.deleteStoreFromEs(enterpriseId, storeId);
}else {
//todo 刷新es改为同步
this.storeIndexRefreshHandler.refreshStoreIndex(enterpriseId, storeId);
}
this.dealStoreChange(enterpriseId, storeId, storeInfoId, GicRecordType.UPDATE.value());
......@@ -85,9 +98,7 @@ public class StoreMessageHandler implements MessageHandler {
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());
}
this.dealStoreChange(enterpriseId, storeId, storeInfoId, GicRecordType.DELETE.value());
}
}
......@@ -96,48 +107,43 @@ public class StoreMessageHandler implements MessageHandler {
* 1 判断当前门店是否在联合商户资源组中 存在 判断联合商户中是否存在 不存在需要进行同步
* 2 判断当前门店是否在联合商户资源组中 不存在 判断联合商户中是否存在 存在需要进行取消同步
* ****/
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;
/**查询商户下的所有联合商户授权资源组**/
List<UnionEnterpriseAuthDTO> list = this.unionEnterpriseAuthApiService.listUnionEnterpriseAuth(enterpriseId).getResult();
if(CollectionUtils.isEmpty(list)){
return;
}
for(UnionEnterpriseAuthDTO dto : list){
/***通过联合商户**/
ResourceDTO resourceDTO = this.resourceApiService.getResource(dto.getResourceGroupId()).getResult();
if(resourceDTO == null){
return;
}
StoreWidgetDTO storeWidgetDTO = this.storeWidgetApiService.getStoreWidget(resourceDTO.getStoreResource().intValue()).getResult();
if(storeWidgetDTO == null){
return;
}
if(AuthModeEnum.YES.getCode().equals(storeWidgetDTO.getAuthMode())){
StoreSearchDTO storeSearchDTO = new StoreSearchDTO();
storeSearchDTO.setStoreIds(String.valueOf(storeId));
storeSearchDTO.setSearchJson(storeWidgetDTO.getSearchParam());
storeSearchDTO.setEnterpriseId(enterpriseId);
Long count = this.storeApiService.queryStoreCountFromEs(storeSearchDTO).getResult();
boolean ownExist = count > 0 ? true : false;
Integer unionEnterpriseId = 1;
storeSearchDTO.setEnterpriseId(unionEnterpriseId);
count = this.storeApiService.queryStoreCountFromEs(storeSearchDTO).getResult();
boolean unionExist = count > 0 ? true : false;
if(ownExist && !unionExist){
StoreDTO storeDTO = new StoreDTO();
storeDTO.setStoreInfoId(storeInfoId);
storeDTO.setEnterpriseId(enterpriseId);
storeDTO.setFromEnterpriseId(dto.getUnionEnterpriseId());
this.storeAuthorizationApiService.saveStore(storeDTO);
this.unionStoreChangeApiService.save(dto.getOwnEnterpriseId(), dto.getUnionEnterpriseId());
}
StoreWidgetDTO storeWidgetDTO = storeWidget.getResult();
if(storeWidgetDTO != null){
if(AuthModeEnum.YES.getCode().equals(storeWidgetDTO.getAuthMode())){
StoreSearchDTO storeSearchDTO = new StoreSearchDTO();
storeSearchDTO.setStoreIds(String.valueOf(storeId));
storeSearchDTO.setSearchJson(storeWidgetDTO.getSearchParam());
storeSearchDTO.setEnterpriseId(enterpriseId);
Long count = this.storeApiService.queryStoreCountFromEs(storeSearchDTO).getResult();
boolean ownExist = count > 0 ? true : false;
Integer unionEnterpriseId = 1;
storeSearchDTO.setEnterpriseId(unionEnterpriseId);
count = this.storeApiService.queryStoreCountFromEs(storeSearchDTO).getResult();
boolean unionExist = count > 0 ? true : false;
if(ownExist && !unionExist){
//todo 进行联合同步 记录表更日志
}
if(!ownExist && unionExist){
//// TODO: 2021/2/9 取消授权 记录表更日志
}
if(count > 0){
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());
}
}
if(!ownExist && unionExist){
this.storeAuthorizationApiService.cancelStore(storeInfoId, dto.getUnionEnterpriseId());
this.unionStoreChangeApiService.save(dto.getOwnEnterpriseId(), dto.getUnionEnterpriseId());
}
}
}
......
......@@ -23,5 +23,7 @@
<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" />
<dubbo:reference interface="com.gic.enterprise.service.UnionEnterpriseAuthApiService" id="unionEnterpriseAuthApiService" timeout="6000" />
<dubbo:reference interface="com.gic.auth.service.ResourceApiService" id="resourceApiService" timeout="6000" />
<dubbo:reference interface="com.gic.store.service.UnionStoreChangeApiService" id="unionStoreChangeApiService" timeout="6000" />
</beans>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment