|
|
|
@@ -184,8 +184,8 @@ public class InvestBizServiceImpl implements InvestBizService { |
|
|
|
targetFile.mkdirs(); |
|
|
|
} |
|
|
|
String fileName = "invest_1.xlsx"; |
|
|
|
//int dot = mFile.getOriginalFilename().lastIndexOf('.'); |
|
|
|
//fileName = fileName + mFile.getOriginalFilename().substring(dot); |
|
|
|
int dot = mFile.getOriginalFilename().lastIndexOf('.'); |
|
|
|
fileName = fileName + mFile.getOriginalFilename().substring(dot); |
|
|
|
|
|
|
|
File lFile = new File(fpath + File.separator + fileName); |
|
|
|
|
|
|
|
@@ -256,7 +256,7 @@ public class InvestBizServiceImpl implements InvestBizService { |
|
|
|
log.error(e.getMessage()); |
|
|
|
// 删除缓存文件 |
|
|
|
file.delete(); |
|
|
|
return; |
|
|
|
throw new MallinkException(ErrorCode.MEM_IMPORT_ERR.getCode(), "导入模板失败: 模板数据解析失败"); |
|
|
|
} |
|
|
|
// 删除缓存文件 |
|
|
|
file.delete(); |
|
|
|
@@ -264,7 +264,7 @@ public class InvestBizServiceImpl implements InvestBizService { |
|
|
|
if (datalist == null) { |
|
|
|
log.error("导入模板失败: 模板数据解析失败"); |
|
|
|
setRedisValue(importKey, "1", "0", "0", "1", true); |
|
|
|
return; |
|
|
|
throw new MallinkException(ErrorCode.MEM_IMPORT_ERR.getCode(), "导入模板失败: 模板数据解析失败"); |
|
|
|
} |
|
|
|
|
|
|
|
List<InvestCustomerVo> successList = datalist.getList(); |
|
|
|
@@ -280,6 +280,7 @@ public class InvestBizServiceImpl implements InvestBizService { |
|
|
|
//添加到redis里 |
|
|
|
setRedisValue(importKey, "" + total, "" + all_success, "0", "" + all_fail, total == all_fail); |
|
|
|
if (CollectionUtils.isEmpty(successList)) { |
|
|
|
stringRedisTemplate.expire(importKey, 3, TimeUnit.SECONDS); |
|
|
|
return; |
|
|
|
} |
|
|
|
//品牌信息 |
|
|
|
@@ -300,8 +301,15 @@ public class InvestBizServiceImpl implements InvestBizService { |
|
|
|
List<InvestCustomerEntity> customers = customerService.list(customerQuery); |
|
|
|
Map<String, InvestCustomerEntity> customerMap = getMap(customers, InvestCustomerEntity::getPhone); |
|
|
|
|
|
|
|
//商铺信息 |
|
|
|
LambdaQueryWrapper<InvestDemandEntity> demandQuery = new LambdaQueryWrapper<>(); |
|
|
|
Collection<Long> customerIds = getIds(customers, InvestCustomerEntity::getId); |
|
|
|
demandQuery.in(CollectionUtils.isNotEmpty(customerIds), InvestDemandEntity::getCustomerId, customerIds); |
|
|
|
List<InvestDemandEntity> demandList = demandService.list(demandQuery); |
|
|
|
Map<Long, InvestDemandEntity> demandMap = getMap(demandList, InvestDemandEntity::getCustomerId); |
|
|
|
|
|
|
|
try { |
|
|
|
successList.parallelStream().forEach(customer -> { |
|
|
|
successList.forEach(customer -> { |
|
|
|
if (StringUtils.isBlank(customer.getPhone())) { |
|
|
|
stringRedisTemplate.opsForHash().increment(importKey, "processCount", 1); |
|
|
|
log.error("负责人电话为空", customer.toString()); |
|
|
|
@@ -327,17 +335,25 @@ public class InvestBizServiceImpl implements InvestBizService { |
|
|
|
log.error("经营业态为空", customer.toString()); |
|
|
|
return; |
|
|
|
} |
|
|
|
InvestDemandDto customerBase = convetCustomer(customer, brandMap, businesseMap, shopMap, customerMap); |
|
|
|
if (customerBase == null) { |
|
|
|
InvestDemandDto toImportCustomer = convetCustomer(customer, brandMap, businesseMap, shopMap, customerMap.get(customer.getPhone()), demandMap); |
|
|
|
if (toImportCustomer == null) { |
|
|
|
stringRedisTemplate.opsForHash().increment(importKey, "processCount", 1); |
|
|
|
log.error("customerBase null"); |
|
|
|
return; |
|
|
|
} |
|
|
|
if (Objects.isNull(customerMap.get(customer.getPhone()))) { |
|
|
|
saveCustomerAndDemand(toImportCustomer); |
|
|
|
} else { |
|
|
|
toImportCustomer.getCustomer().setId(customerMap.get(customer.getPhone()).getId()); |
|
|
|
updateCustomerAndDemand(toImportCustomer); |
|
|
|
} |
|
|
|
saveCustomerAndDemand(customerBase) ; |
|
|
|
}); |
|
|
|
} catch (Exception e) { |
|
|
|
setRedisValue(importKey, "1", "0", "0", "1", true); |
|
|
|
e.printStackTrace(); |
|
|
|
log.error("导入模板失败:" + e.getMessage()); |
|
|
|
log.error("导入模板失败", e); |
|
|
|
throw new MallinkException(ErrorCode.MEM_IMPORT_ERR.getCode(), "导入模板失败"); |
|
|
|
} finally { |
|
|
|
stringRedisTemplate.expire(importKey, 3, TimeUnit.SECONDS); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@@ -351,30 +367,42 @@ public class InvestBizServiceImpl implements InvestBizService { |
|
|
|
return getMap(brands, WxBrand::getName); |
|
|
|
} |
|
|
|
|
|
|
|
private InvestDemandDto convetCustomer(InvestCustomerVo customerVoT, Map<String, WxBrand> brandMap, Map<String, WxBusiness> businesseMap, Map<String, WxShop> shopMap, Map<String, InvestCustomerEntity> customerMap) { |
|
|
|
InvestCustomerEntity customerEntity = new InvestCustomerEntity(); |
|
|
|
if (Objects.isNull(brandMap.get(customerVoT.getBrandName()))) { |
|
|
|
private InvestDemandDto convetCustomer(InvestCustomerVo importCustomerVo, Map<String, WxBrand> brandMap, Map<String, WxBusiness> businesseMap, Map<String, WxShop> shopMap, InvestCustomerEntity dbCustomer, Map<Long, InvestDemandEntity> demandMap) { |
|
|
|
InvestCustomerEntity customerEntity = null; |
|
|
|
InvestDemandEntity demandEntity = null; |
|
|
|
if (Objects.isNull(dbCustomer)) { |
|
|
|
customerEntity = new InvestCustomerEntity(); |
|
|
|
} else { |
|
|
|
customerEntity = dbCustomer; |
|
|
|
demandEntity = demandMap.get(dbCustomer.getId()); |
|
|
|
} |
|
|
|
if (Objects.isNull(demandEntity)) { |
|
|
|
demandEntity = new InvestDemandEntity(); |
|
|
|
} |
|
|
|
if (Objects.isNull(brandMap.get(importCustomerVo.getBrandName()))) { |
|
|
|
return null; |
|
|
|
} |
|
|
|
customerEntity.setBrandId(brandMap.get(customerVoT.getBrandName()).getId()); |
|
|
|
customerEntity.setBrandId(brandMap.get(importCustomerVo.getBrandName()).getId()); |
|
|
|
|
|
|
|
if (Objects.isNull(businesseMap.get(customerVoT.getBusiness()))) { |
|
|
|
if (Objects.isNull(businesseMap.get(importCustomerVo.getBusiness()))) { |
|
|
|
return null; |
|
|
|
} |
|
|
|
customerEntity.setBusinessId(businesseMap.get(customerVoT.getBusiness()).getId()); |
|
|
|
customerEntity.setBusinessId(businesseMap.get(importCustomerVo.getBusiness()).getId()); |
|
|
|
|
|
|
|
InvestDemandEntity demandEntity = new InvestDemandEntity(); |
|
|
|
if (Objects.isNull(shopMap.get(customerVoT.getShopNumber()))) { |
|
|
|
if (Objects.isNull(shopMap.get(importCustomerVo.getShopNumber()))) { |
|
|
|
return null; |
|
|
|
} |
|
|
|
demandEntity.setTargetId(shopMap.get(customerVoT.getShopNumber()).getId()); |
|
|
|
customerEntity.setName(importCustomerVo.getName()); |
|
|
|
customerEntity.setPhone(importCustomerVo.getPhone()); |
|
|
|
customerEntity.setType(importCustomerVo.getType()); |
|
|
|
demandEntity.setTargetId(shopMap.get(importCustomerVo.getShopNumber()).getId()); |
|
|
|
demandEntity.setTargetType(EnumInvestType.RENT); |
|
|
|
Map<String, Object> intent = new HashMap<>(); |
|
|
|
if (Objects.nonNull(customerVoT.getRentArea())) { |
|
|
|
intent.put(InvestDemandEntity.KEY_RENT_AREA, customerVoT.getRentArea()); |
|
|
|
if (Objects.nonNull(importCustomerVo.getRentArea())) { |
|
|
|
intent.put(InvestDemandEntity.KEY_RENT_AREA, importCustomerVo.getRentArea()); |
|
|
|
} |
|
|
|
if (Objects.nonNull(customerVoT.getOpeningTime())) { |
|
|
|
intent.put(InvestDemandEntity.KEY_OPENING_TIME, customerVoT.getOpeningTime()); |
|
|
|
if (Objects.nonNull(importCustomerVo.getOpeningTime())) { |
|
|
|
intent.put(InvestDemandEntity.KEY_OPENING_TIME, importCustomerVo.getOpeningTime()); |
|
|
|
} |
|
|
|
|
|
|
|
if (!intent.isEmpty()) { |
|
|
|
@@ -384,12 +412,6 @@ public class InvestBizServiceImpl implements InvestBizService { |
|
|
|
InvestDemandDto demandDto = new InvestDemandDto(); |
|
|
|
demandDto.setCustomer(customerEntity); |
|
|
|
demandDto.setDemand(demandEntity); |
|
|
|
if (Objects.isNull(customerMap.get(customerVoT.getPhone()))) { |
|
|
|
//TODO insert |
|
|
|
} else { |
|
|
|
//TODO update |
|
|
|
} |
|
|
|
|
|
|
|
return demandDto; |
|
|
|
} |
|
|
|
|
|
|
|
@@ -399,7 +421,7 @@ public class InvestBizServiceImpl implements InvestBizService { |
|
|
|
stringRedisTemplate.opsForHash().put(importKey, "processCount", processCount); |
|
|
|
stringRedisTemplate.opsForHash().put(importKey, "failCount", failCount); |
|
|
|
if (fail) { |
|
|
|
stringRedisTemplate.expire(importKey, 10, TimeUnit.SECONDS); |
|
|
|
stringRedisTemplate.expire(importKey, 3, TimeUnit.SECONDS); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@@ -719,7 +741,12 @@ public class InvestBizServiceImpl implements InvestBizService { |
|
|
|
if (Objects.isNull(demandEntity.getCustomerId())) { |
|
|
|
demandEntity.setCustomerId(customerId); |
|
|
|
} |
|
|
|
demandService.updateById(demandEntity); |
|
|
|
InvestDemandEntity dbDemand = demandService.getByCustomerId(customerId); |
|
|
|
if (Objects.isNull(dbDemand)) { |
|
|
|
demandService.save(demandEntity); |
|
|
|
} else { |
|
|
|
demandService.updateById(demandEntity); |
|
|
|
} |
|
|
|
saveMessage(demandEntity, demandDto.getCustomer()); |
|
|
|
return true; |
|
|
|
} |
|
|
|
@@ -730,7 +757,7 @@ public class InvestBizServiceImpl implements InvestBizService { |
|
|
|
} |
|
|
|
Long owner = demandEntity.getOwner(); |
|
|
|
if (Objects.nonNull(owner) && !Objects.equals(owner, 0L)) { |
|
|
|
List<Long> ownerArray = Arrays.asList(owner); |
|
|
|
List<Long> ownerArray = Collections.singletonList(owner); |
|
|
|
demandService.saveBatchMessage(ownerArray, EnumInvestMessageType.CUSTOMER_CREATE.getInfo(), EnumInvestMessageTag.CUSTOMER_CREATE, EnumFollowType.DEMAND, customerEntity.getId()); |
|
|
|
} |
|
|
|
} |
|
|
|
@@ -1124,6 +1151,9 @@ public class InvestBizServiceImpl implements InvestBizService { |
|
|
|
} |
|
|
|
|
|
|
|
private <T, R> Collection<R> getIds(Collection<T> dataList, Function<? super T, R> mapper) { |
|
|
|
if (CollectionUtils.isEmpty(dataList)) { |
|
|
|
return Collections.emptyList(); |
|
|
|
} |
|
|
|
return InvestHelper.getIds(dataList, mapper); |
|
|
|
} |
|
|
|
} |