From 4d97ca09b204a503cda71cd294051741775e9e3d Mon Sep 17 00:00:00 2001 From: Burce Date: Wed, 23 Oct 2019 18:00:21 +0800 Subject: [PATCH] =?UTF-8?q?[=E6=8B=9B=E5=95=86]adjust?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../invest/InvestBaseController.java | 3 - .../invest/InvestCustomerController.java | 7 + .../po/invest/InvestCustomerEntity.java | 8 +- .../domain/po/invest/InvestDemandEntity.java | 3 + .../domain/po/invest/InvestTaskEntity.java | 3 +- .../com/iformall/domain/vo/RentEventInfo.java | 4 + .../domain/vo/invest/InvestCustomerVo.java | 10 +- .../service/invest/InvestBizService.java | 2 + .../iformall/service/invest/InvestHelper.java | 17 +- .../service/invest/event/InvestListener.java | 2 +- .../invest/impl/InvestBizServiceImpl.java | 295 +++++++++++++++++- .../java/com/iformall/utils/Constant.java | 1 + .../java/com/iformall/utils/EventUtil.java | 2 +- 13 files changed, 339 insertions(+), 18 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 5fe1c56f7..d5212b078 100644 --- a/mallinkAdmin/src/main/java/com/iformall/controller/invest/InvestBaseController.java +++ b/mallinkAdmin/src/main/java/com/iformall/controller/invest/InvestBaseController.java @@ -46,9 +46,6 @@ public class InvestBaseController extends BaseController { ErrorCode errorCode = ErrorCode.SYS_NULLPOINTER_ERROR ; log.error("execute error {}", errorCode.getMessage()); return new InvestResultData(errorCode); - } catch (Exception e) { - log.error("execute error", e); - return new InvestResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(),e.getMessage()); } 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 0f36c74f6..a746e8d91 100755 --- a/mallinkAdmin/src/main/java/com/iformall/controller/invest/InvestCustomerController.java +++ b/mallinkAdmin/src/main/java/com/iformall/controller/invest/InvestCustomerController.java @@ -94,6 +94,13 @@ public class InvestCustomerController extends InvestBaseController{ exportData(params, response, (p, u) -> investBizService.exportCustomer(p, u)); } + @ApiOperation("导出客户信息模板") + @GetMapping("/exportCustomerTemplate") + @SystemControllerLog(description = "招商管理-导出客户信息模板") + public void exportCustomerTemplate(HttpServletResponse response) { + exportData(null, response, (p, u) -> investBizService.exportCustomerTemplate(u)); + } + @ApiOperation("导入客户信息") @GetMapping("/importCustomer") @SystemControllerLog(description = "招商管理-导入客户信息") diff --git a/mallinkService/src/main/java/com/iformall/domain/po/invest/InvestCustomerEntity.java b/mallinkService/src/main/java/com/iformall/domain/po/invest/InvestCustomerEntity.java index acfd0cc43..0a011e4ef 100755 --- a/mallinkService/src/main/java/com/iformall/domain/po/invest/InvestCustomerEntity.java +++ b/mallinkService/src/main/java/com/iformall/domain/po/invest/InvestCustomerEntity.java @@ -1,6 +1,8 @@ package com.iformall.domain.po.invest; import cn.afterturn.easypoi.excel.annotation.Excel; +import com.baomidou.mybatisplus.annotation.FieldStrategy; +import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableName; @@ -32,14 +34,14 @@ public class InvestCustomerEntity extends InvestBaseEntity { */ @LogColumn @io.swagger.annotations.ApiModelProperty(value = "品牌负责人", name = "name") - @Excel(name = "品牌负责人", width = 20, orderNum = "2") + @Excel(name = "品牌负责人*", width = 20, orderNum = "2") private String name; /** * 电话 */ @LogColumn @io.swagger.annotations.ApiModelProperty(value = "电话", name = "phone") - @Excel(name = "负责人电话", width = 20, orderNum = "3") + @Excel(name = "负责人电话*", width = 20, orderNum = "3") private String phone; /** * 经营业态 @@ -58,12 +60,14 @@ public class InvestCustomerEntity extends InvestBaseEntity { */ @io.swagger.annotations.ApiModelProperty(value = "客户分类:0-潜在客户;1-意向客户;2-合作客户;3-谈判失败", name = "type") @LogColumn + @TableField(strategy = FieldStrategy.IGNORED) private EnumCustomerType type; /** * 客户预评级:0-无;1-主力店;2-次主力店;3-甲;4-乙;5-丙 */ @io.swagger.annotations.ApiModelProperty(value = "客户预评级:0-无;1-主力店;2-次主力店;3-甲;4-乙;5-丙", name = "rating") @LogColumn + @TableField(strategy = FieldStrategy.IGNORED) private EnumCustomerRatingType rating; /** diff --git a/mallinkService/src/main/java/com/iformall/domain/po/invest/InvestDemandEntity.java b/mallinkService/src/main/java/com/iformall/domain/po/invest/InvestDemandEntity.java index cda0ec9f3..2d2fbf390 100755 --- a/mallinkService/src/main/java/com/iformall/domain/po/invest/InvestDemandEntity.java +++ b/mallinkService/src/main/java/com/iformall/domain/po/invest/InvestDemandEntity.java @@ -1,5 +1,7 @@ package com.iformall.domain.po.invest; +import com.baomidou.mybatisplus.annotation.FieldStrategy; +import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableName; @@ -32,6 +34,7 @@ public class InvestDemandEntity extends InvestBaseEntity { */ @io.swagger.annotations.ApiModelProperty(value = "负责人", name = "owner") @LogColumn + @TableField(strategy = FieldStrategy.IGNORED) private Long owner; /** * 客户ID diff --git a/mallinkService/src/main/java/com/iformall/domain/po/invest/InvestTaskEntity.java b/mallinkService/src/main/java/com/iformall/domain/po/invest/InvestTaskEntity.java index 489ea781f..0c360ebbc 100755 --- a/mallinkService/src/main/java/com/iformall/domain/po/invest/InvestTaskEntity.java +++ b/mallinkService/src/main/java/com/iformall/domain/po/invest/InvestTaskEntity.java @@ -23,7 +23,8 @@ import java.util.Date; @EqualsAndHashCode(callSuper = true) public class InvestTaskEntity extends InvestBaseEntity { - public static final String KEY_CONTRACTID = "contractId" ; + public static final String KEY_CONTRACT_ID = "contractId" ; + public static final String KEY_CONTRACT_TYPE = "ContractType" ; /** * 负责人 diff --git a/mallinkService/src/main/java/com/iformall/domain/vo/RentEventInfo.java b/mallinkService/src/main/java/com/iformall/domain/vo/RentEventInfo.java index c252a63d7..ba60f5790 100644 --- a/mallinkService/src/main/java/com/iformall/domain/vo/RentEventInfo.java +++ b/mallinkService/src/main/java/com/iformall/domain/vo/RentEventInfo.java @@ -15,4 +15,8 @@ public class RentEventInfo { private final Long rentId ; private final List targetIds ; private final EnumRentContractStatus type ; + /** + * 合同类型 + */ + private final Integer ContractType ; } 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 2f8136d0b..7f8176d9a 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,6 +5,8 @@ import com.iformall.domain.po.invest.InvestCustomerEntity; import lombok.Data; import lombok.EqualsAndHashCode; +import java.util.Date; + @Data @EqualsAndHashCode(callSuper = true) public class InvestCustomerVo extends InvestCustomerEntity { @@ -18,17 +20,17 @@ public class InvestCustomerVo extends InvestCustomerEntity { @io.swagger.annotations.ApiModelProperty(value = "客户需求负责人", name = "demandOwner") private Long demandOwner; - @Excel(name = "品牌", width = 30, orderNum = "1") + @Excel(name = "品牌*", width = 30, orderNum = "1") private String brandName; - @Excel(name = "经营业态", width = 20, orderNum = "3") + @Excel(name = "经营业态*", width = 20, orderNum = "3") private String business; @Excel(name = "意向租赁面积", width = 20, orderNum = "5") - private String rentArea; + private Integer rentArea; @Excel(name = "预计开业时间", width = 20, orderNum = "6") private String openingTime; - @Excel(name = "意向铺位", width = 20, orderNum = "4") + @Excel(name = "意向铺位*", width = 20, orderNum = "4") private String shopNumber; } diff --git a/mallinkService/src/main/java/com/iformall/service/invest/InvestBizService.java b/mallinkService/src/main/java/com/iformall/service/invest/InvestBizService.java index 95633606b..7961b5fe2 100644 --- a/mallinkService/src/main/java/com/iformall/service/invest/InvestBizService.java +++ b/mallinkService/src/main/java/com/iformall/service/invest/InvestBizService.java @@ -18,6 +18,8 @@ public interface InvestBizService { void exportCustomer(InvestDemandQuery params, HttpServletResponse response); + void exportCustomerTemplate(HttpServletResponse response); + void importCustomer(@RequestParam("file") MultipartFile mFile); List queryCustomer(); diff --git a/mallinkService/src/main/java/com/iformall/service/invest/InvestHelper.java b/mallinkService/src/main/java/com/iformall/service/invest/InvestHelper.java index 3b3f90943..95d37c38d 100644 --- a/mallinkService/src/main/java/com/iformall/service/invest/InvestHelper.java +++ b/mallinkService/src/main/java/com/iformall/service/invest/InvestHelper.java @@ -10,11 +10,14 @@ import com.iformall.domain.po.invest.InvestTaskEntity; import com.iformall.domain.vo.invest.InvestPageQuery; import com.iformall.exception.MallinkException; import com.iformall.utils.JsonUtil; +import org.apache.commons.lang3.ObjectUtils; import org.apache.commons.lang3.StringUtils; import org.checkerframework.checker.nullness.qual.Nullable; import java.lang.reflect.Method; import java.text.MessageFormat; +import java.text.ParseException; +import java.text.SimpleDateFormat; import java.util.*; import java.util.function.Function; import java.util.function.Predicate; @@ -176,9 +179,19 @@ public class InvestHelper { return dataList.parallelStream().filter(predicate).map(mapper).collect(Collectors.toList()); } - public static String addContractId(String content,Long rentId) { + public static String addContractId(String content,Long rentId,Integer ContractType) { Map contentMap = JSON.parseObject(content, Map.class); - contentMap.put(InvestTaskEntity.KEY_CONTRACTID, rentId); + if(Objects.nonNull(rentId)) { + contentMap.put(InvestTaskEntity.KEY_CONTRACT_ID, rentId); + } + if(Objects.nonNull(ContractType)) { + contentMap.put(InvestTaskEntity.KEY_CONTRACT_TYPE, ContractType); + } return JsonUtil.obj2Json(contentMap); } + + public static Date parseDate(String dateStr) throws ParseException { + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); + return sdf.parse(dateStr); + } } diff --git a/mallinkService/src/main/java/com/iformall/service/invest/event/InvestListener.java b/mallinkService/src/main/java/com/iformall/service/invest/event/InvestListener.java index de38b6aa4..af47da419 100644 --- a/mallinkService/src/main/java/com/iformall/service/invest/event/InvestListener.java +++ b/mallinkService/src/main/java/com/iformall/service/invest/event/InvestListener.java @@ -56,7 +56,7 @@ public class InvestListener implements ApplicationListener { if (status == EnumTaskStatus.FINISH) { for (InvestTaskEntity task : tasks) { task.setStatus(status); - task.setContent(InvestHelper.addContractId(task.getContent(),rentEventInfo.getRentId())); + task.setContent(InvestHelper.addContractId(task.getContent(),rentEventInfo.getRentId(),rentEventInfo.getContractType())); } taskService.updateBatchById(tasks); } 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 2e5a15560..9ee54ca31 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 @@ -1,9 +1,16 @@ package com.iformall.service.invest.impl; +import cn.afterturn.easypoi.excel.ExcelImportUtil; +import cn.afterturn.easypoi.excel.entity.ImportParams; +import cn.afterturn.easypoi.excel.entity.result.ExcelImportResult; +import cn.afterturn.easypoi.handler.impl.ExcelDataHandlerDefaultImpl; +import cn.afterturn.easypoi.handler.inter.IExcelDataHandler; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.iformall.common.ErrorCode; +import com.iformall.common.Result; import com.iformall.domain.dto.InvestDemandDto; import com.iformall.domain.dto.InvestTaskDto; import com.iformall.domain.po.*; @@ -11,9 +18,12 @@ import com.iformall.domain.po.invest.*; import com.iformall.domain.vo.WxShopVo; import com.iformall.domain.vo.invest.*; import com.iformall.enums.*; +import com.iformall.exception.MallinkException; import com.iformall.service.*; import com.iformall.service.invest.*; +import com.iformall.utils.Constant; import com.iformall.utils.DateUtils; +import lombok.extern.slf4j.Slf4j; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.MapUtils; import org.apache.commons.compress.utils.Lists; @@ -21,15 +31,22 @@ import org.apache.commons.lang3.ObjectUtils; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.redis.core.StringRedisTemplate; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.web.multipart.MultipartFile; import javax.servlet.http.HttpServletResponse; +import java.io.BufferedInputStream; +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.text.SimpleDateFormat; import java.util.*; +import java.util.concurrent.TimeUnit; import java.util.function.Function; -import java.util.stream.Collectors; +@Slf4j @Service public class InvestBizServiceImpl implements InvestBizService { @@ -59,6 +76,10 @@ public class InvestBizServiceImpl implements InvestBizService { private WxRentContractService rentContractService; @Autowired private ExcelService excelService; + @Autowired + StringRedisTemplate stringRedisTemplate; + @Autowired + private String fmUploadDir; @Override public InvestPageResult queryPageDemand(InvestDemandQuery params) { @@ -123,9 +144,262 @@ public class InvestBizServiceImpl implements InvestBizService { } } + @Override + public void exportCustomerTemplate(HttpServletResponse response) { + List resultList = new ArrayList<>(); + InvestCustomerVo item = new InvestCustomerVo(); + item.setBusiness("超市"); + item.setRentArea(100); + item.setShopNumber("A10092"); + item.setBrandName("肯德基"); + item.setName("张三"); + item.setPhone("1358888888"); + item.setOpeningTime("2019-01-01"); + resultList.add(item); + excelService.exportExcel(resultList, null, "客户信息模板", InvestCustomerVo.class, "客户信息模板.xlsx", response, true); + } + @Override public void importCustomer(MultipartFile mFile) { + if (mFile.isEmpty()) { + throw new MallinkException(Result.ERROR, "上传文件不能为空"); + } + + String importKey = Constant.importInvestCustomerPrev + InvestUserContext.getUserId(); + final String tenantId = InvestUserContext.getUser().getTenantId(); + + //查询当前用户得到的值是否为空,为空继续,不为空,返回模板正在导入 + Boolean allCount = stringRedisTemplate.opsForHash().hasKey(importKey, "allCount"); + if (allCount) { + throw new MallinkException(Result.SUCCESS, "模板正在导入"); + } + setRedisValueIfAbsent(importKey); + + String fpath = fmUploadDir; + File targetFile = new File(fpath); + if (!targetFile.exists()) { + targetFile.mkdirs(); + } + String fileName = "invest_1.xlsx"; + int dot = mFile.getOriginalFilename().lastIndexOf('.'); + fileName = fileName + mFile.getOriginalFilename().substring(dot); + + File lFile = new File(fpath + File.separator + fileName); + + FileOutputStream fos = null; + BufferedInputStream fs = null; + try { + fos = new FileOutputStream(lFile); + fs = (BufferedInputStream) mFile.getInputStream(); + byte[] buffer = new byte[1024]; + int len = 0; + while ((len = fs.read(buffer)) != -1) { + fos.write(buffer, 0, len); + } + fos.close(); + fs.close(); + } catch (Exception e) { + setRedisValueIfError(importKey, "1", "1", e); + throw new MallinkException(ErrorCode.MEM_IMPORT_ERR.getCode(), "模板上传失败"); + } finally { + if (fos != null) { + try { + fos.close(); + } catch (IOException e) { + setRedisValueIfError(importKey, "1", "1", e); + throw new MallinkException(ErrorCode.MEM_IMPORT_ERR.getCode(), "模板上传失败"); + } + } + if (fs != null) { + try { + fs.close(); + } catch (IOException e) { + setRedisValueIfError(importKey, "1", "1", e); + throw new MallinkException(ErrorCode.MEM_IMPORT_ERR.getCode(), "模板上传失败"); + } + } + } + doImport(lFile, tenantId, importKey); + throw new MallinkException(Result.SUCCESS, "模板正在导入"); + } + + private void doImport(File file, String tenantId, String importKey) { + ImportParams params = new ImportParams(); + // 需要验证 + params.setImportFields(new String[]{"品牌*", "品牌负责人*", "负责人电话*", "经营业态*", "意向铺位*", "意向租凭面积", "预计开业时间"}); + IExcelDataHandler handler = new ExcelDataHandlerDefaultImpl() { + @Override + public Object importHandler(InvestCustomerVoT obj, String name, Object value) { + if (value == null) { + value = ""; + } + System.out.println(name + " + " + value.toString()); + return super.importHandler(obj, name, value); + } + }; + handler.setNeedHandlerFields(new String[]{"品牌*", "品牌负责人*", "负责人电话*", "经营业态*", "意向铺位*"}); + params.setNeedVerify(true); + + ExcelImportResult datalist = null; + + try { + datalist = ExcelImportUtil.importExcelMore(file, InvestCustomerVoT.class, params); + } catch (Exception e) { + setRedisValue(importKey, "1", "0", "0", "1", true); + log.error(e.getMessage()); + // 删除缓存文件 + file.delete(); + return; + } + // 删除缓存文件 + file.delete(); + + if (datalist == null) { + log.error("导入模板失败: 模板数据解析失败"); + setRedisValue(importKey, "1", "0", "0", "1", true); + return; + } + + List successList = datalist.getList(); + List failList = datalist.getFailList(); + + log.info("验证通过的数量: " + successList.size()); + log.info("验证未通过的数量: " + failList.size()); + + int total = successList.size() + failList.size(); + int all_success = successList.size(); + int all_fail = failList.size(); + + //添加到redis里 + setRedisValue(importKey, "" + total, "" + all_success, "0", "" + all_fail, total == all_fail); + if (CollectionUtils.isEmpty(successList)) { + return; + } + //品牌信息 + List brands = brandService.listAsPage(null, 1, Integer.MAX_VALUE).getList(); + Map brandMap = getMap(brands, WxBrand::getName); + + //业态信息 + List businesses = businessService.listAsPage(null, 1, Integer.MAX_VALUE).getList(); + Map businesseMap = getMap(businesses, WxBusiness::getTitle); + + //商铺信息 + List shops = shopService.listAsPage(null, 1, Integer.MAX_VALUE).getList(); + Map shopMap = getMap(shops, WxShop::getShopNumber); + + //商铺信息 + LambdaQueryWrapper customerQuery = new LambdaQueryWrapper<>(); + customerQuery.in(InvestCustomerEntity::getPhone, getIds(successList, InvestCustomerVoT::getPhone)); + List customers = customerService.list(customerQuery); + Map customerMap = getMap(customers, InvestCustomerEntity::getPhone); + + try { + successList.parallelStream().forEach(customer -> { + if (StringUtils.isBlank(customer.getPhone())) { + stringRedisTemplate.opsForHash().increment(importKey, "processCount", 1); + log.error("负责人电话为空", customer.toString()); + return; + } + if (StringUtils.isBlank(customer.getShopNumber())) { + stringRedisTemplate.opsForHash().increment(importKey, "processCount", 1); + log.error("意向铺位为空", customer.toString()); + return; + } + if (StringUtils.isBlank(customer.getBrandName())) { + stringRedisTemplate.opsForHash().increment(importKey, "processCount", 1); + log.error("品牌为空", customer.toString()); + return; + } + if (StringUtils.isBlank(customer.getName())) { + stringRedisTemplate.opsForHash().increment(importKey, "processCount", 1); + log.error("品牌负责人为空", customer.toString()); + return; + } + if (StringUtils.isBlank(customer.getBusiness())) { + stringRedisTemplate.opsForHash().increment(importKey, "processCount", 1); + log.error("经营业态为空", customer.toString()); + return; + } + InvestDemandDto customerBase = convetCustomer(customer, brandMap, businesseMap, shopMap, customerMap); + if (customerBase == null) { + stringRedisTemplate.opsForHash().increment(importKey, "processCount", 1); + log.error("userBasenull"); + } + saveCustomerAndDemand(customerBase) ; + }); + } catch (Exception e) { + setRedisValue(importKey, "1", "0", "0", "1", true); + e.printStackTrace(); + log.error("导入模板失败:" + e.getMessage()); + } + } + + private InvestDemandDto convetCustomer(InvestCustomerVoT customerVoT, Map brandMap, Map businesseMap, Map shopMap, Map customerMap) { + InvestCustomerEntity customerEntity = new InvestCustomerEntity(); + if (Objects.isNull(brandMap.get(customerVoT.getBrandName()))) { + return null; + } + customerEntity.setBrandId(brandMap.get(customerVoT.getBrandName()).getId()); + + if (Objects.isNull(businesseMap.get(customerVoT.getBusiness()))) { + return null; + } + customerEntity.setBusinessId(businesseMap.get(customerVoT.getBusiness()).getId()); + + InvestDemandEntity demandEntity = new InvestDemandEntity(); + if (Objects.isNull(shopMap.get(customerVoT.getShopNumber()))) { + return null; + } + demandEntity.setTargetId(shopMap.get(customerVoT.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(customerVoT.getOpeningTime())) { + intent.put(InvestDemandEntity.KEY_OPENING_TIME, customerVoT.getOpeningTime()); + } + + if (!intent.isEmpty()) { + demandEntity.setIntent(JSON.toJSONString(intent)); + } + + InvestDemandDto demandDto = new InvestDemandDto(); + demandDto.setCustomer(customerEntity); + demandDto.setDemand(demandEntity); + if (Objects.isNull(customerMap.get(customerVoT.getPhone()))) { + //TODO insert + } else { + //TODO update + } + + return demandDto; + } + + private void setRedisValue(String importKey, String allCount, String allSuccessCount, String processCount, String failCount, boolean fail) { + stringRedisTemplate.opsForHash().put(importKey, "allCount", allCount); + stringRedisTemplate.opsForHash().put(importKey, "allSuccessCount", allSuccessCount); + stringRedisTemplate.opsForHash().put(importKey, "processCount", processCount); + stringRedisTemplate.opsForHash().put(importKey, "failCount", failCount); + if (fail) { + stringRedisTemplate.expire(importKey, 10, TimeUnit.SECONDS); + } + } + + private void setRedisValueIfAbsent(String importKey) { + stringRedisTemplate.opsForHash().putIfAbsent(importKey, "allCount", 0 + ""); + stringRedisTemplate.expire(importKey, 30, TimeUnit.MINUTES); + stringRedisTemplate.opsForHash().putIfAbsent(importKey, "allSuccessCount", 0 + ""); + stringRedisTemplate.opsForHash().putIfAbsent(importKey, "processCount", ""); + stringRedisTemplate.opsForHash().putIfAbsent(importKey, "failCount", ""); + } + + private void setRedisValueIfError(String importKey, String allCount, String failCount, Exception e) { + stringRedisTemplate.expire(importKey, 3, TimeUnit.SECONDS); + stringRedisTemplate.opsForHash().putIfAbsent(importKey, "allCount", allCount); + stringRedisTemplate.opsForHash().putIfAbsent(importKey, "failCount", failCount); + log.error(e.getMessage()); } @Override @@ -499,6 +773,12 @@ public class InvestBizServiceImpl implements InvestBizService { return buildTaskItem(taskEntity, shopVo, usersMap); } + /** + * 获取商铺对应的正式合同信息 + * + * @param shop + * @return + */ private Map getWxRentContractMap(WxShop shop) { InvestHelper.notNull(shop, "商铺不存在"); return rentContractService.selectRentContractByShopIds(Arrays.asList(shop.getId()), StringUtils.join(shop.getId(), ""), @@ -588,12 +868,13 @@ public class InvestBizServiceImpl implements InvestBizService { Map shopContractMap = getWxRentContractMap(shop); WxRentContract contract = shopContractMap.get(shop.getId()); if (Objects.nonNull(contract)) { - InvestHelper.addContractId(investTaskEntity.getContent(), contract.getId()); + InvestHelper.addContractId(investTaskEntity.getContent(), contract.getId(), null); } else { WxRentContract contractQuery = new WxRentContract(); contractQuery.setTenantId(InvestUserContext.getUser().getTenantId()); contractQuery.setShopId(investTaskEntity.getTargetId()); contractQuery.setStatus(EnumRentContractStatus.INTENTION.getCode()); + //获取意向合同 int count = rentContractService.selectContractCountByShopId(contractQuery); if (count > 0) { investTaskEntity.setStatus(EnumTaskStatus.INTENTION); @@ -652,8 +933,14 @@ public class InvestBizServiceImpl implements InvestBizService { resultItemVo.setDemandOwner(item.getOwner()); if (StringUtils.isNotBlank(item.getIntent())) { Map intentMap = JSON.parseObject(item.getIntent(), Map.class); - resultItemVo.setRentArea(String.valueOf(intentMap.get(InvestDemandEntity.KEY_RENT_AREA))); - resultItemVo.setOpeningTime(String.valueOf(intentMap.get(InvestDemandEntity.KEY_OPENING_TIME))); + Object rentArea = intentMap.get(InvestDemandEntity.KEY_RENT_AREA); + Object openingTime = intentMap.get(InvestDemandEntity.KEY_OPENING_TIME); + if (Objects.nonNull(rentArea)) { + resultItemVo.setRentArea(Integer.valueOf(String.valueOf(rentArea))); + } + if (Objects.nonNull(openingTime)) { + resultItemVo.setOpeningTime(String.valueOf(openingTime)); + } } } //resultItemVo.setBusiness(usersMap.get(item.getOwner())); diff --git a/mallinkService/src/main/java/com/iformall/utils/Constant.java b/mallinkService/src/main/java/com/iformall/utils/Constant.java index f04c6be2b..00307865d 100644 --- a/mallinkService/src/main/java/com/iformall/utils/Constant.java +++ b/mallinkService/src/main/java/com/iformall/utils/Constant.java @@ -32,6 +32,7 @@ public class Constant { public static final String UNDEFINED = "undefined"; public static final String importMemPrev = "importmem:"; + public static final String importInvestCustomerPrev = "importinvestcustomer:"; public static final String adminPage = "https://admin.malls.iformall.com"; diff --git a/mallinkService/src/main/java/com/iformall/utils/EventUtil.java b/mallinkService/src/main/java/com/iformall/utils/EventUtil.java index 5b703f9ff..16dd8e277 100644 --- a/mallinkService/src/main/java/com/iformall/utils/EventUtil.java +++ b/mallinkService/src/main/java/com/iformall/utils/EventUtil.java @@ -14,7 +14,7 @@ public class EventUtil { public static void publistRentEvent(WxRentContractService rentContractService, WxRentContract rentContract) { try { RentEventInfo rentEventInfo = RentEventInfo - .of(rentContract.getId(), rentContractService.getShopIds(rentContract), EnumRentContractStatus.getEnum(rentContract.getStatus())); + .of(rentContract.getId(), rentContractService.getShopIds(rentContract), EnumRentContractStatus.getEnum(rentContract.getStatus()),null); InvestEvent event = new InvestEvent(rentEventInfo); SpringContextUtils.pulish(event); } catch (Exception e) {