Kaynağa Gözat

[招商][客户信息]导入

release_toaliyun_real
Burce 6 yıl önce
ebeveyn
işleme
5cfc21814e
6 değiştirilmiş dosya ile 87 ekleme ve 46 silme
  1. +7
    -4
      mallinkAdmin/src/main/java/com/iformall/controller/invest/InvestBaseController.java
  2. +8
    -8
      mallinkAdmin/src/main/java/com/iformall/controller/invest/InvestCustomerController.java
  3. +3
    -0
      mallinkAdmin/src/main/java/com/iformall/log/TableOperateAspect.java
  4. +0
    -1
      mallinkService/src/main/java/com/iformall/domain/vo/invest/InvestCustomerVo.java
  5. +62
    -32
      mallinkService/src/main/java/com/iformall/service/invest/impl/InvestBizServiceImpl.java
  6. +7
    -1
      mallinkService/src/main/java/com/iformall/service/invest/impl/InvestCustomerServiceImpl.java

+ 7
- 4
mallinkAdmin/src/main/java/com/iformall/controller/invest/InvestBaseController.java Dosyayı Görüntüle

@@ -43,9 +43,6 @@ public class InvestBaseController extends BaseController {
return new InvestResultData(r); return new InvestResultData(r);
} catch (MallinkException e) { } catch (MallinkException e) {
log.error("execute error", e); log.error("execute error", e);
if (Objects.equals(Result.SUCCESS, e.getErrorCode())) {
return new InvestResultData();
}
return new InvestResultData(e.getErrorCode(), e.getMessage()); return new InvestResultData(e.getErrorCode(), e.getMessage());
} catch (NullPointerException e) { } catch (NullPointerException e) {
ErrorCode errorCode = ErrorCode.SYS_NULLPOINTER_ERROR ; ErrorCode errorCode = ErrorCode.SYS_NULLPOINTER_ERROR ;
@@ -66,11 +63,17 @@ public class InvestBaseController extends BaseController {
} }
} }


public <T> void importData(T t, Consumer<T> action) {
public <T> InvestResultData importData(T t, Consumer<T> action) {
try { try {
log.debug("[" + getIpAddr() + "] request , params : {}", JSON.toJSONString(t)); log.debug("[" + getIpAddr() + "] request , params : {}", JSON.toJSONString(t));
InvestUserContext.setUser(getUser()); InvestUserContext.setUser(getUser());
action.accept(t); action.accept(t);
return new InvestResultData();
} catch (MallinkException e) {
if (Objects.equals(Result.SUCCESS, e.getErrorCode())) {
return new InvestResultData(Result.SUCCESS, e.getMessage());
}
throw e;
} finally { } finally {
InvestUserContext.remove(); InvestUserContext.remove();
} }


+ 8
- 8
mallinkAdmin/src/main/java/com/iformall/controller/invest/InvestCustomerController.java Dosyayı Görüntüle

@@ -86,12 +86,12 @@ public class InvestCustomerController extends InvestBaseController{
return execute(customerDto, p -> investBizService.updateCustomerAndDemand(p)); return execute(customerDto, p -> investBizService.updateCustomerAndDemand(p));
} }


@ApiOperation("导出客户信息")
@GetMapping("/exportCustomer")
@SystemControllerLog(description = "招商管理-导出客户信息")
public void exportCustomer(InvestDemandQuery params, HttpServletResponse response) {
exportData(params, response, (p, u) -> investBizService.exportCustomer(p, u));
}
//@ApiOperation("导出客户信息")
//@GetMapping("/exportCustomer")
//@SystemControllerLog(description = "招商管理-导出客户信息")
//public void exportCustomer(InvestDemandQuery params, HttpServletResponse response) {
// exportData(params, response, (p, u) -> investBizService.exportCustomer(p, u));
//}


@ApiOperation("导出客户信息模板") @ApiOperation("导出客户信息模板")
@GetMapping("/exportCustomerTemplate") @GetMapping("/exportCustomerTemplate")
@@ -103,8 +103,8 @@ public class InvestCustomerController extends InvestBaseController{
@ApiOperation("导入客户信息" ) @ApiOperation("导入客户信息" )
@PostMapping(value = "/importCustomer", consumes = "multipart/*", headers = "content-type=multipart/form-data") @PostMapping(value = "/importCustomer", consumes = "multipart/*", headers = "content-type=multipart/form-data")
@SystemControllerLog(description = "招商管理-导入客户信息") @SystemControllerLog(description = "招商管理-导入客户信息")
public void importCustomer(@RequestParam("file") MultipartFile file) {
importData(file, p -> investBizService.importCustomer(p));
public InvestResultData importCustomer(@RequestParam("file") MultipartFile file) {
return importData(file, p -> investBizService.importCustomer(p));
} }


} }

+ 3
- 0
mallinkAdmin/src/main/java/com/iformall/log/TableOperateAspect.java Dosyayı Görüntüle

@@ -143,6 +143,9 @@ public class TableOperateAspect {
for (Field field : fields) { for (Field field : fields) {
String annotationVal = field.getAnnotation(LogColumn.class).value(); String annotationVal = field.getAnnotation(LogColumn.class).value();
Object value = FieldUtils.readDeclaredField(entity, field.getName(), true); Object value = FieldUtils.readDeclaredField(entity, field.getName(), true);
if(Objects.isNull(value)) {
continue;
}
if (field.getType().isEnum()) { if (field.getType().isEnum()) {
value = InvestHelper.getEnumVal(InvestHelper.valueOf(value.getClass(), ((Enum) value).name())); value = InvestHelper.getEnumVal(InvestHelper.valueOf(value.getClass(), ((Enum) value).name()));
} }


+ 0
- 1
mallinkService/src/main/java/com/iformall/domain/vo/invest/InvestCustomerVo.java Dosyayı Görüntüle

@@ -5,7 +5,6 @@ import com.iformall.domain.po.invest.InvestCustomerEntity;
import lombok.Data; import lombok.Data;
import lombok.EqualsAndHashCode; import lombok.EqualsAndHashCode;


import java.util.Date;


@Data @Data
@EqualsAndHashCode(callSuper = true) @EqualsAndHashCode(callSuper = true)


+ 62
- 32
mallinkService/src/main/java/com/iformall/service/invest/impl/InvestBizServiceImpl.java Dosyayı Görüntüle

@@ -184,8 +184,8 @@ public class InvestBizServiceImpl implements InvestBizService {
targetFile.mkdirs(); targetFile.mkdirs();
} }
String fileName = "invest_1.xlsx"; 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); File lFile = new File(fpath + File.separator + fileName);


@@ -256,7 +256,7 @@ public class InvestBizServiceImpl implements InvestBizService {
log.error(e.getMessage()); log.error(e.getMessage());
// 删除缓存文件 // 删除缓存文件
file.delete(); file.delete();
return;
throw new MallinkException(ErrorCode.MEM_IMPORT_ERR.getCode(), "导入模板失败: 模板数据解析失败");
} }
// 删除缓存文件 // 删除缓存文件
file.delete(); file.delete();
@@ -264,7 +264,7 @@ public class InvestBizServiceImpl implements InvestBizService {
if (datalist == null) { if (datalist == null) {
log.error("导入模板失败: 模板数据解析失败"); log.error("导入模板失败: 模板数据解析失败");
setRedisValue(importKey, "1", "0", "0", "1", true); setRedisValue(importKey, "1", "0", "0", "1", true);
return;
throw new MallinkException(ErrorCode.MEM_IMPORT_ERR.getCode(), "导入模板失败: 模板数据解析失败");
} }


List<InvestCustomerVo> successList = datalist.getList(); List<InvestCustomerVo> successList = datalist.getList();
@@ -280,6 +280,7 @@ public class InvestBizServiceImpl implements InvestBizService {
//添加到redis里 //添加到redis里
setRedisValue(importKey, "" + total, "" + all_success, "0", "" + all_fail, total == all_fail); setRedisValue(importKey, "" + total, "" + all_success, "0", "" + all_fail, total == all_fail);
if (CollectionUtils.isEmpty(successList)) { if (CollectionUtils.isEmpty(successList)) {
stringRedisTemplate.expire(importKey, 3, TimeUnit.SECONDS);
return; return;
} }
//品牌信息 //品牌信息
@@ -300,8 +301,15 @@ public class InvestBizServiceImpl implements InvestBizService {
List<InvestCustomerEntity> customers = customerService.list(customerQuery); List<InvestCustomerEntity> customers = customerService.list(customerQuery);
Map<String, InvestCustomerEntity> customerMap = getMap(customers, InvestCustomerEntity::getPhone); 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 { try {
successList.parallelStream().forEach(customer -> {
successList.forEach(customer -> {
if (StringUtils.isBlank(customer.getPhone())) { if (StringUtils.isBlank(customer.getPhone())) {
stringRedisTemplate.opsForHash().increment(importKey, "processCount", 1); stringRedisTemplate.opsForHash().increment(importKey, "processCount", 1);
log.error("负责人电话为空", customer.toString()); log.error("负责人电话为空", customer.toString());
@@ -327,17 +335,25 @@ public class InvestBizServiceImpl implements InvestBizService {
log.error("经营业态为空", customer.toString()); log.error("经营业态为空", customer.toString());
return; 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); stringRedisTemplate.opsForHash().increment(importKey, "processCount", 1);
log.error("customerBase null"); 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) { } catch (Exception e) {
setRedisValue(importKey, "1", "0", "0", "1", true); 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); 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; 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; 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; 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); demandEntity.setTargetType(EnumInvestType.RENT);
Map<String, Object> intent = new HashMap<>(); 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()) { if (!intent.isEmpty()) {
@@ -384,12 +412,6 @@ public class InvestBizServiceImpl implements InvestBizService {
InvestDemandDto demandDto = new InvestDemandDto(); InvestDemandDto demandDto = new InvestDemandDto();
demandDto.setCustomer(customerEntity); demandDto.setCustomer(customerEntity);
demandDto.setDemand(demandEntity); demandDto.setDemand(demandEntity);
if (Objects.isNull(customerMap.get(customerVoT.getPhone()))) {
//TODO insert
} else {
//TODO update
}

return demandDto; return demandDto;
} }


@@ -399,7 +421,7 @@ public class InvestBizServiceImpl implements InvestBizService {
stringRedisTemplate.opsForHash().put(importKey, "processCount", processCount); stringRedisTemplate.opsForHash().put(importKey, "processCount", processCount);
stringRedisTemplate.opsForHash().put(importKey, "failCount", failCount); stringRedisTemplate.opsForHash().put(importKey, "failCount", failCount);
if (fail) { 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())) { if (Objects.isNull(demandEntity.getCustomerId())) {
demandEntity.setCustomerId(customerId); 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()); saveMessage(demandEntity, demandDto.getCustomer());
return true; return true;
} }
@@ -730,7 +757,7 @@ public class InvestBizServiceImpl implements InvestBizService {
} }
Long owner = demandEntity.getOwner(); Long owner = demandEntity.getOwner();
if (Objects.nonNull(owner) && !Objects.equals(owner, 0L)) { 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()); 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) { 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); return InvestHelper.getIds(dataList, mapper);
} }
} }

+ 7
- 1
mallinkService/src/main/java/com/iformall/service/invest/impl/InvestCustomerServiceImpl.java Dosyayı Görüntüle

@@ -6,10 +6,12 @@ import com.iformall.common.TableLog;
import com.iformall.domain.po.invest.InvestCustomerEntity; import com.iformall.domain.po.invest.InvestCustomerEntity;
import com.iformall.domain.vo.invest.InvestCustomerVo; import com.iformall.domain.vo.invest.InvestCustomerVo;
import com.iformall.enums.EnumCustomerType; import com.iformall.enums.EnumCustomerType;
import com.iformall.enums.EnumInvestChannel;
import com.iformall.mapper.InvestCustomerMapper; import com.iformall.mapper.InvestCustomerMapper;
import com.iformall.service.WxBrandService; import com.iformall.service.WxBrandService;
import com.iformall.service.WxBusinessService; import com.iformall.service.WxBusinessService;
import com.iformall.service.invest.InvestCustomerService; import com.iformall.service.invest.InvestCustomerService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;


@@ -33,6 +35,7 @@ public class InvestCustomerServiceImpl extends InvestBaseServiceImpl<InvestCusto
return super.saveAction(entity, this::checkBeforeSaveOrUpdate); return super.saveAction(entity, this::checkBeforeSaveOrUpdate);
} }


@TableLog
@Override @Override
public boolean update(InvestCustomerEntity entity, Wrapper<InvestCustomerEntity> updateWrapper) { public boolean update(InvestCustomerEntity entity, Wrapper<InvestCustomerEntity> updateWrapper) {
return super.updateActon(entity, updateWrapper, this::checkBeforeSaveOrUpdate); return super.updateActon(entity, updateWrapper, this::checkBeforeSaveOrUpdate);
@@ -48,10 +51,13 @@ public class InvestCustomerServiceImpl extends InvestBaseServiceImpl<InvestCusto
private void checkBeforeSaveOrUpdate(InvestCustomerEntity entity) { private void checkBeforeSaveOrUpdate(InvestCustomerEntity entity) {
checkBusiness(businessService, entity.getBusinessId()); checkBusiness(businessService, entity.getBusinessId());
checkBrand(brandService, entity.getBrandId()); checkBrand(brandService, entity.getBrandId());
checkType(entity);
//checkType(entity);
if (Objects.isNull(entity.getBrandId())) { if (Objects.isNull(entity.getBrandId())) {
entity.setBrandId(0L); entity.setBrandId(0L);
} }
if (StringUtils.isBlank(entity.getInvestChannel())) {
entity.setInvestChannel(EnumInvestChannel.NONE.getInfo());
}
} }


/** /**


Yükleniyor…
İptal
Kaydet