Commit 4c735ce0 by 陶光胜

联合商户门店授权日志

parent 27a4767f
......@@ -17,6 +17,8 @@ public interface StoreAuthorizationApiService {
ServiceResponse<Void> authorizationSingleStore(String params);
ServiceResponse<Void> saveStore(StoreDTO storeDTO, Integer logId);
ServiceResponse<Void> saveStore(StoreDTO storeDTO);
ServiceResponse<Void> cancelStore(Integer storeInfoId, Integer enterpriseId);
......
package com.gic.store.service;
public interface AuthStoreLogService {
int saveAuthStoreLog(Integer storeInfoId, Integer fromEnterpriseId, Integer toEnterpriseId, String key);
int updateStatus(Integer id, int status);
int getCount(String key, int status);
}
package com.gic.store.service.impl;
import com.gic.store.dao.mapper.TabAuthStoreLogMapper;
import com.gic.store.entity.TabAuthStoreLog;
import com.gic.store.service.AuthStoreLogService;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
@Service("authStoreLogService")
public class AuthStoreLogServiceImpl implements AuthStoreLogService {
@Autowired
private TabAuthStoreLogMapper tabAuthStoreLogMapper;
@Override
public int saveAuthStoreLog(Integer storeInfoId, Integer fromEnterpriseId, Integer toEnterpriseId, String key) {
TabAuthStoreLog log = new TabAuthStoreLog();
log.setStoreInfoId(storeInfoId);
log.setFromEnterpriseId(fromEnterpriseId);
log.setKey(key);
log.setToEnterpriseId(toEnterpriseId);
log.setStatus(1);
this.tabAuthStoreLogMapper.insertSelective(log);
return log.getId();
}
@Override
public int updateStatus(Integer id, int status) {
TabAuthStoreLog log = new TabAuthStoreLog();
log.setId(id);
log.setStatus(status);
return this.tabAuthStoreLogMapper.updateByPrimaryKeySelective(log);
}
@Override
public int getCount(String key, int status) {
List<TabAuthStoreLog> list = this.tabAuthStoreLogMapper.listLogByKey(key, status);
if(CollectionUtils.isNotEmpty(list)){
return list.size();
}
return 0;
}
}
......@@ -8,6 +8,7 @@ import com.gic.auth.constant.AuthModeEnum;
import com.gic.auth.constant.AuthorizationStatusEnum;
import com.gic.auth.service.UnionEnterpriseApiService;
import com.gic.commons.util.GICMQClientUtil;
import com.gic.commons.util.ToolUtil;
import com.gic.mq.sdk.GicMQClient;
import com.gic.store.constant.StoreGroupConstant;
import com.gic.store.constant.StoreOwnTypeEnum;
......@@ -45,6 +46,8 @@ public class StoreAuthorizationApiServiceImpl implements StoreAuthorizationApiSe
private StoreRegionApiService storeRegionApiService;
@Autowired
private StoreDictApiService storeDictApiService;
@Autowired
private AuthStoreLogService authStoreLogService;
@Override
public ServiceResponse<Void> authStore(Integer storeResourceId, Integer toEnterpriseId, Integer enterpriseId) {
......@@ -81,17 +84,25 @@ public class StoreAuthorizationApiServiceImpl implements StoreAuthorizationApiSe
Integer toEnterpriseId = json.getInteger("toEnterpriseId");
Integer fromEnterpriseId = json.getInteger("enterpriseId");
Integer isEnd = json.getInteger("isEnd");
int total = json.getInteger("total");
String key = json.getString("key");
storeDTO.setEnterpriseId(toEnterpriseId);
storeDTO.setFromEnterpriseId(fromEnterpriseId);
this.saveStore(storeDTO);
int logId = this.authStoreLogService.saveAuthStoreLog(storeDTO.getStoreInfoId(), fromEnterpriseId, toEnterpriseId, key);
this.saveStore(storeDTO, logId);
if(isEnd == 1){
int count = this.authStoreLogService.getCount(key, 2);
if(count > 0){
this.unionEnterpriseApiService.updateStoreAuthorizationStatus
(AuthorizationStatusEnum.PARTSUCCESS.getCode(), storeDTO.getEnterpriseId(), "成功授权"+(total-count)+"条数据,失败"+count+"条");
}
this.unionEnterpriseApiService.updateStoreAuthorizationStatus(AuthorizationStatusEnum.SUCCESS.getCode(), storeDTO.getEnterpriseId());
}
return null;
}
@Override
public ServiceResponse<Void> saveStore(StoreDTO storeDTO){
public ServiceResponse<Void> saveStore(StoreDTO storeDTO, Integer logId){
String groupId = storeStrategyService.isHitStrategy(storeDTO, StoreGroupConstant.STORE_GROUP_STRATEGY_TYPE);
if (StringUtils.isBlank(groupId)) {
TabStoreGroup group = storeGroupService.selectUnGroupedStore(storeDTO.getEnterpriseId());
......@@ -104,10 +115,18 @@ public class StoreAuthorizationApiServiceImpl implements StoreAuthorizationApiSe
storeDTO.setOwnType(StoreOwnTypeEnum.OTHER.getCode());
int i = this.storeService.authAddStore(storeDTO);
log.info("{},门店授权结果:{}", storeDTO.getStoreInfoId(), i);
if(i == 0 && logId != 0){
this.authStoreLogService.updateStatus(logId, 2);
}
return ServiceResponse.success();
}
@Override
public ServiceResponse<Void> saveStore(StoreDTO storeDTO) {
return this.saveStore(storeDTO, 0);
}
@Override
public ServiceResponse<Void> cancelStore(Integer storeId, Integer enterpriseId){
List<Integer> list = new ArrayList<>();
list.add(storeId);
......@@ -116,12 +135,14 @@ public class StoreAuthorizationApiServiceImpl implements StoreAuthorizationApiSe
}
private void queryStoreByPage(Long count, StoreSearchDTO storeSearchDTO, Integer toEnterpriseId, Integer enterpriseId){
String key = ToolUtil.randomUUID();
int pages = count/pageSize + count%pageSize>0 ? 1 : 0;
Set<Integer> regionSet = new HashSet<>();
Set<String> storeTypeSet = new HashSet<>();
Set<String> storeStatusSet = new HashSet<>();
List<Integer> existStoreInfoIdList = this.storeService.listStoreIdByFromEnterpriseId(enterpriseId);
Set<Integer> storeInfoIdSet = new HashSet<>(existStoreInfoIdList);
int total = 0;
for(int page = 1; page <= pages; page++){
ServiceResponse<Page<StoreDTO>> pageServiceResponse = this.storeApiService.listStore(storeSearchDTO, page, pageSize);
if(pageServiceResponse.isSuccess()){
......@@ -137,7 +158,8 @@ public class StoreAuthorizationApiServiceImpl implements StoreAuthorizationApiSe
if(page == pages && k == list.size()-1) {
isEnd = 1;
}
this.sendDataToMq(storeDTO, toEnterpriseId, isEnd);
total++;
this.sendDataToMq(storeDTO, toEnterpriseId, isEnd, key, total);
if(storeInfoIdSet.contains(storeDTO.getStoreInfoId())){
storeInfoIdSet.remove(storeDTO.getStoreInfoId());
}
......@@ -148,12 +170,14 @@ public class StoreAuthorizationApiServiceImpl implements StoreAuthorizationApiSe
this.authRegionStatusStoreType(regionSet, storeStatusSet, storeTypeSet, storeInfoIdSet, enterpriseId, toEnterpriseId);
}
private void sendDataToMq(StoreDTO storeDTO, Integer toEnterpriseId, int isEnd){
private void sendDataToMq(StoreDTO storeDTO, Integer toEnterpriseId, int isEnd, String key, int total){
Map<String, Object> params = new HashMap<>();
params.put("enterpriseId", storeDTO.getEnterpriseId());
params.put("store", storeDTO);
params.put("toEnterpriseId", toEnterpriseId);
params.put("isEnd", isEnd);
params.put("key", key);
params.put("total", total);
GicMQClient client = GICMQClientUtil.getClientInstance();
try {
client.sendMessage("storeAuthorizationMq", JSON.toJSONString(params));
......
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