From 5cfc21814e5ce2b7f22819f73f7be834a460ea1a Mon Sep 17 00:00:00 2001 From: Burce Date: Fri, 25 Oct 2019 17:59:35 +0800 Subject: [PATCH] =?UTF-8?q?[=E6=8B=9B=E5=95=86][=E5=AE=A2=E6=88=B7?= =?UTF-8?q?=E4=BF=A1=E6=81=AF]=E5=AF=BC=E5=85=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../invest/InvestBaseController.java | 11 ++- .../invest/InvestCustomerController.java | 16 ++-- .../com/iformall/log/TableOperateAspect.java | 3 + .../domain/vo/invest/InvestCustomerVo.java | 1 - .../invest/impl/InvestBizServiceImpl.java | 94 ++++++++++++------- .../impl/InvestCustomerServiceImpl.java | 8 +- 6 files changed, 87 insertions(+), 46 deletions(-) diff --git a/mallinkAdmin/src/main/java/com/iformall/controller/invest/InvestBaseController.java b/mallinkAdmin/src/main/java/com/iformall/controller/invest/InvestBaseController.java index d3abfb8de..5a069ca28 100644 --- a/mallinkAdmin/src/main/java/com/iformall/controller/invest/InvestBaseController.java +++ b/mallinkAdmin/src/main/java/com/iformall/controller/invest/InvestBaseController.java @@ -43,9 +43,6 @@ public class InvestBaseController extends BaseController { return new InvestResultData(r); } catch (MallinkException e) { log.error("execute error", e); - if (Objects.equals(Result.SUCCESS, e.getErrorCode())) { - return new InvestResultData(); - } return new InvestResultData(e.getErrorCode(), e.getMessage()); } catch (NullPointerException e) { ErrorCode errorCode = ErrorCode.SYS_NULLPOINTER_ERROR ; @@ -66,11 +63,17 @@ public class InvestBaseController extends BaseController { } } - public void importData(T t, Consumer action) { + public InvestResultData importData(T t, Consumer action) { try { log.debug("[" + getIpAddr() + "] request , params : {}", JSON.toJSONString(t)); InvestUserContext.setUser(getUser()); 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 { InvestUserContext.remove(); } diff --git a/mallinkAdmin/src/main/java/com/iformall/controller/invest/InvestCustomerController.java b/mallinkAdmin/src/main/java/com/iformall/controller/invest/InvestCustomerController.java index da6316136..95dfa326b 100755 --- a/mallinkAdmin/src/main/java/com/iformall/controller/invest/InvestCustomerController.java +++ b/mallinkAdmin/src/main/java/com/iformall/controller/invest/InvestCustomerController.java @@ -86,12 +86,12 @@ public class InvestCustomerController extends InvestBaseController{ 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("导出客户信息模板") @GetMapping("/exportCustomerTemplate") @@ -103,8 +103,8 @@ public class InvestCustomerController extends InvestBaseController{ @ApiOperation("导入客户信息" ) @PostMapping(value = "/importCustomer", consumes = "multipart/*", headers = "content-type=multipart/form-data") @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)); } } diff --git a/mallinkAdmin/src/main/java/com/iformall/log/TableOperateAspect.java b/mallinkAdmin/src/main/java/com/iformall/log/TableOperateAspect.java index 2f46ac4ed..d65be0d47 100644 --- a/mallinkAdmin/src/main/java/com/iformall/log/TableOperateAspect.java +++ b/mallinkAdmin/src/main/java/com/iformall/log/TableOperateAspect.java @@ -143,6 +143,9 @@ public class TableOperateAspect { for (Field field : fields) { String annotationVal = field.getAnnotation(LogColumn.class).value(); Object value = FieldUtils.readDeclaredField(entity, field.getName(), true); + if(Objects.isNull(value)) { + continue; + } if (field.getType().isEnum()) { value = InvestHelper.getEnumVal(InvestHelper.valueOf(value.getClass(), ((Enum) value).name())); } diff --git a/mallinkService/src/main/java/com/iformall/domain/vo/invest/InvestCustomerVo.java b/mallinkService/src/main/java/com/iformall/domain/vo/invest/InvestCustomerVo.java index 3ca1197b0..fbe0d01bb 100644 --- a/mallinkService/src/main/java/com/iformall/domain/vo/invest/InvestCustomerVo.java +++ b/mallinkService/src/main/java/com/iformall/domain/vo/invest/InvestCustomerVo.java @@ -5,7 +5,6 @@ import com.iformall.domain.po.invest.InvestCustomerEntity; import lombok.Data; import lombok.EqualsAndHashCode; -import java.util.Date; @Data @EqualsAndHashCode(callSuper = true) diff --git a/mallinkService/src/main/java/com/iformall/service/invest/impl/InvestBizServiceImpl.java b/mallinkService/src/main/java/com/iformall/service/invest/impl/InvestBizServiceImpl.java index a07f85d16..2063e943a 100644 --- a/mallinkService/src/main/java/com/iformall/service/invest/impl/InvestBizServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/invest/impl/InvestBizServiceImpl.java @@ -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 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 customers = customerService.list(customerQuery); Map customerMap = getMap(customers, InvestCustomerEntity::getPhone); + //商铺信息 + LambdaQueryWrapper demandQuery = new LambdaQueryWrapper<>(); + Collection customerIds = getIds(customers, InvestCustomerEntity::getId); + demandQuery.in(CollectionUtils.isNotEmpty(customerIds), InvestDemandEntity::getCustomerId, customerIds); + List demandList = demandService.list(demandQuery); + Map 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 brandMap, Map businesseMap, Map shopMap, Map customerMap) { - InvestCustomerEntity customerEntity = new InvestCustomerEntity(); - if (Objects.isNull(brandMap.get(customerVoT.getBrandName()))) { + private InvestDemandDto convetCustomer(InvestCustomerVo importCustomerVo, Map brandMap, Map businesseMap, Map shopMap, InvestCustomerEntity dbCustomer, Map 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 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 ownerArray = Arrays.asList(owner); + List 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 Collection getIds(Collection dataList, Function mapper) { + if (CollectionUtils.isEmpty(dataList)) { + return Collections.emptyList(); + } return InvestHelper.getIds(dataList, mapper); } } diff --git a/mallinkService/src/main/java/com/iformall/service/invest/impl/InvestCustomerServiceImpl.java b/mallinkService/src/main/java/com/iformall/service/invest/impl/InvestCustomerServiceImpl.java index 14f871102..c9f03c884 100755 --- a/mallinkService/src/main/java/com/iformall/service/invest/impl/InvestCustomerServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/invest/impl/InvestCustomerServiceImpl.java @@ -6,10 +6,12 @@ import com.iformall.common.TableLog; import com.iformall.domain.po.invest.InvestCustomerEntity; import com.iformall.domain.vo.invest.InvestCustomerVo; import com.iformall.enums.EnumCustomerType; +import com.iformall.enums.EnumInvestChannel; import com.iformall.mapper.InvestCustomerMapper; import com.iformall.service.WxBrandService; import com.iformall.service.WxBusinessService; import com.iformall.service.invest.InvestCustomerService; +import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -33,6 +35,7 @@ public class InvestCustomerServiceImpl extends InvestBaseServiceImpl updateWrapper) { return super.updateActon(entity, updateWrapper, this::checkBeforeSaveOrUpdate); @@ -48,10 +51,13 @@ public class InvestCustomerServiceImpl extends InvestBaseServiceImpl