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 95dfa326b..c675ce312 100755 --- a/mallinkAdmin/src/main/java/com/iformall/controller/invest/InvestCustomerController.java +++ b/mallinkAdmin/src/main/java/com/iformall/controller/invest/InvestCustomerController.java @@ -95,7 +95,7 @@ public class InvestCustomerController extends InvestBaseController{ @ApiOperation("导出客户信息模板") @GetMapping("/exportCustomerTemplate") - @SystemControllerLog(description = "招商管理-导出客户信息模板") + @SystemControllerLog(description = "导出客户信息模板") public void exportCustomerTemplate(HttpServletResponse response) { exportData(null, response, (p, u) -> investBizService.exportCustomerTemplate(u)); } @@ -107,4 +107,10 @@ public class InvestCustomerController extends InvestBaseController{ return importData(file, p -> investBizService.importCustomer(p)); } + @GetMapping("/queryTemplateCount") + @SystemControllerLog(description = "查询导入数据") + public InvestResultData queryTemplateCount() { + return execute(null, p -> investBizService.queryCustomerImportCount()); + } + } diff --git a/mallinkAdmin/src/main/resources/db/migration/V201910231900__W_INVEST_CREATE.sql b/mallinkAdmin/src/main/resources/db/migration/V201910231900__W_INVEST_CREATE.sql index cb62ca87d..2ad38c8a0 100644 --- a/mallinkAdmin/src/main/resources/db/migration/V201910231900__W_INVEST_CREATE.sql +++ b/mallinkAdmin/src/main/resources/db/migration/V201910231900__W_INVEST_CREATE.sql @@ -56,6 +56,9 @@ CREATE TABLE `invest_remind` ( `minute` BIGINT(6) NOT NULL COMMENT '提醒时间', `begin_date` DATETIME NOT NULL COMMENT '开始时间', `end_date` DATETIME NOT NULL COMMENT '结束时间', + `customer_id` BIGINT(20) NOT NULL DEFAULT '0' COMMENT '客户ID', + `negotiation_type` TINYINT(6) NOT NULL DEFAULT '0' COMMENT '拜访方式:0-拜访;1-来访;2-电话;3-短信、微信或其它', + `status` TINYINT(6) NOT NULL DEFAULT '0' COMMENT '是否提醒:0-未提醒;1-已提醒', `create_date` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', `update_date` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间', PRIMARY KEY (`id`), diff --git a/mallinkSchedule/src/main/java/com/iformall/schedule/InvestSchedule.java b/mallinkSchedule/src/main/java/com/iformall/schedule/InvestSchedule.java index e43508093..82ad1d301 100644 --- a/mallinkSchedule/src/main/java/com/iformall/schedule/InvestSchedule.java +++ b/mallinkSchedule/src/main/java/com/iformall/schedule/InvestSchedule.java @@ -3,9 +3,15 @@ package com.iformall.schedule; import com.alibaba.fastjson.JSONArray; import com.google.common.collect.ImmutableListMultimap; import com.google.common.collect.Multimaps; +import com.iformall.domain.po.MallUserInfo; +import com.iformall.domain.po.WxMall; import com.iformall.domain.po.invest.*; +import com.iformall.domain.po.msg.WxMsgRecord; import com.iformall.domain.vo.invest.InvestCustomerVo; import com.iformall.enums.*; +import com.iformall.mapper.WxMallMapper; +import com.iformall.mq.MqBaseProducer; +import com.iformall.service.MallUserInfoService; import com.iformall.service.invest.*; import com.iformall.utils.DateUtils; import lombok.extern.slf4j.Slf4j; @@ -16,6 +22,7 @@ import org.springframework.core.env.Environment; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Component; +import javax.annotation.Resource; import java.util.*; @@ -36,22 +43,85 @@ public class InvestSchedule { InvestCustomerService customerService; @Autowired InvestFollowRecordService followRecordService; + @Autowired + InvestRemindService remindService; + @Resource + WxMallMapper mallMapper; + @Autowired + MallUserInfoService userInfoService; + @Autowired + private MqBaseProducer mqBaseProducer; @Autowired Environment environment; - private static final String PREFIX = "招商定时任务"; + private static final String TAG_MESSAGE = "招商定时任务-消息"; + private static final String TAG_REMIND = "招商定时任务-提醒"; //@Scheduled(cron = "0 0 14 * * ?") // 每天下午两点执行定时任务 - @Scheduled(cron = "0 */30 * * * *?") // 测试,每5分钟执行 + @Scheduled(cron = "0 */30 * * * *?") // 测试,每30分钟执行 public void messageSchedule() { - log.info("{}: 开始", PREFIX); + log.info("{}: 开始", TAG_MESSAGE); //一个月内未完成提醒 taskMonthMessage(); //一周内未跟踪提醒 demandWeekMessage(); - log.info("{}: 结束", PREFIX); + log.info("{}: 结束", TAG_MESSAGE); + } + + @Scheduled(cron = "0 */5 * * * *?") + public void remindSchedule() { + log.info("{}: 开始", TAG_REMIND); + // 提醒新 + List reminds = remindService.findUnRemindList(); + log.info("{}:提醒数 :{}", TAG_REMIND, reminds.size()); + if (CollectionUtils.isEmpty(reminds)) { + return; + } + + // mall 信息 + List mallList = mallMapper.findList(new WxMall()); + if (mallList.size() == 0) { + log.info("{}: No Mall info found", TAG_REMIND); + return; + } + Map mallMap = InvestHelper.getMap(mallList, WxMall::getTenantId); + // 用户信息 + List userList = userInfoService.findList(new MallUserInfo()); + if (userList.size() == 0) { + log.info("{}: No user info found", TAG_REMIND); + return; + } + Map userMap = InvestHelper.getMap(userList, MallUserInfo::getId); + + Collection customs = customerService.listByIds(InvestHelper.getIds(reminds, InvestRemindEntity::getCustomerId)); + Map customerMap = InvestHelper.getMap(customs, InvestCustomerEntity::getId); + + Calendar now = Calendar.getInstance(); + for (InvestRemindEntity remind : reminds) { + if (Objects.equals(remind.getMinute(), 0L)) { + log.warn("{}:remindID:{} 不提醒, 跳过", TAG_REMIND, remind.getId()); + continue; + } + + Calendar begin = Calendar.getInstance(); + begin.setTime(remind.getBeginDate()); + if (getRemindMinute(now, begin) > remind.getMinute()) { + boolean sended = sendSMS(userMap.get(remind.getOwner()), mallMap.get(remind.getTenantId()), remind, customerMap.get(remind.getCustomerId())); + if (sended) { + remind.setStatus(EnumInvestRemindStatus.REMINDED); + remindService.updateById(remind); + } + } + } + log.info("{}: 结束", TAG_REMIND); + } + + private long getRemindMinute(Calendar c1, Calendar c2) { + long beginTime = c1.getTime().getTime(); + long endTime = c2.getTime().getTime(); + return (endTime - beginTime) / (1000 * 60); } private void taskMonthMessage() { @@ -69,14 +139,14 @@ public class InvestSchedule { } //查询满足条件 List tasks = taskService.listByStatusAndTime(Arrays.asList(EnumTaskStatus.INTENTION, EnumTaskStatus.NEGOTIATING), start.getTime(), end.getTime()); - log.info("{}:{} - {} 的任务数 :{}", PREFIX, start, end, tasks.size()); + log.info("{}:{} - {} 的任务数 :{}", TAG_MESSAGE, start, end, tasks.size()); if (tasks.isEmpty()) { return; } for (InvestTaskEntity task : tasks) { String owner = task.getOwner(); if (StringUtils.isEmpty(owner)) { - log.warn("{}:taskID:{} owner不存在:{}, 跳过", PREFIX, task.getId(), task.getOwner()); + log.warn("{}:taskID:{} owner不存在:{}, 跳过", TAG_MESSAGE, task.getId(), task.getOwner()); continue; } List ownerArray = JSONArray.parseArray(owner, Long.class); @@ -85,7 +155,7 @@ public class InvestSchedule { if (CollectionUtils.isNotEmpty(messageList)) { for (InvestMessageEntity messageEntity : messageList) { if (messageEntity.getTid().equals(task.getId())) { - log.info("{}:taskID:{} 提醒已存在:{}, 跳过", PREFIX, task.getId(), messageEntity.getId()); + log.info("{}:taskID:{} 提醒已存在:{}, 跳过", TAG_MESSAGE, task.getId(), messageEntity.getId()); continue; } addTaskMessage(task, ownerArray); @@ -100,7 +170,7 @@ public class InvestSchedule { private void addTaskMessage(InvestTaskEntity task, List ownerArray) { String message = String.format(EnumInvestMessageType.TASK_REMIND.getInfo(), task.getId(), DateUtils.format(task.getLastTime())); messageService.saveBatchMessage(ownerArray, message, EnumInvestMessageTag.TASK_MONTH, EnumFollowType.TASK, task.getId(),task.getTenantId()); - log.info("{}:taskID:{} 为用户{}创建消息提醒", PREFIX, task.getId(), task.getOwner()); + log.info("{}:taskID:{} 为用户{}创建消息提醒", TAG_MESSAGE, task.getId(), task.getOwner()); } private void demandWeekMessage() { @@ -111,9 +181,9 @@ public class InvestSchedule { //初始化时间条件 Calendar start = Calendar.getInstance(); if (environment.acceptsProfiles(ENV_STR)) { - start.add(Calendar.DAY_OF_YEAR, 1); //测试 + start.add(Calendar.DAY_OF_YEAR, -1); //测试 } else { - start.add(Calendar.DAY_OF_YEAR, 7); + start.add(Calendar.DAY_OF_YEAR, -7); } //查询跟踪列表 @@ -122,14 +192,12 @@ public class InvestSchedule { List demands = customerService.listByIds(InvestHelper.getIds(follows, InvestFollowRecordEntity::getFollowId), Arrays.asList(EnumCustomerType.INTENTIONAL, EnumCustomerType.POTENTIAL)); - /** - * 已经已经提醒过的用户 - */ + // 已经提醒过的用户 List userDemandFlag = new ArrayList<>(); for (InvestCustomerVo customerVo : demands) { Long owner = customerVo.getDemandOwner(); if (Objects.isNull(owner)) { - log.warn("{}:customerID:{} owner不存在:{}, 跳过", PREFIX, customerVo.getId(), customerVo.getDemandOwner()); + log.warn("{}:customerID:{} owner不存在:{}, 跳过", TAG_MESSAGE, customerVo.getId(), customerVo.getDemandOwner()); continue; } List messageList = demandMessageUserIdMap.get(owner); @@ -138,13 +206,13 @@ public class InvestSchedule { } for (InvestMessageEntity messageEntity : messageList) { if (messageEntity.getTid().equals(messageEntity.getId())) { - log.info("{}:taskID:{} 提醒已存在:{}, 跳过", PREFIX, customerVo.getId(), messageEntity.getId()); + log.info("{}:taskID:{} 提醒已存在:{}, 跳过", TAG_MESSAGE, customerVo.getId(), messageEntity.getId()); continue; } String userDemandFlagItem = StringUtils.join(messageEntity.getOwner(), messageEntity.getId()); //已经提醒过的用户不在提醒 if (userDemandFlag.contains(userDemandFlagItem)) { - log.info("{}:taskID:{} 提醒已存在:{}, 跳过", PREFIX, customerVo.getId(), userDemandFlagItem); + log.info("{}:taskID:{} 提醒已存在:{}, 跳过", TAG_MESSAGE, customerVo.getId(), userDemandFlagItem); continue; } addCustomerMessage(customerVo, owner); @@ -155,7 +223,42 @@ public class InvestSchedule { private void addCustomerMessage(InvestCustomerVo customerVo, Long owner) { String message = String.format(EnumInvestMessageType.COSTOMER_REMIND.getInfo(), customerVo.getId()); - messageService.saveBatchMessage(Arrays.asList(owner), message, EnumInvestMessageTag.CUSTOMER_WEEK, EnumFollowType.DEMAND, customerVo.getId(),customerVo.getTenantId()); - log.info("{}:customerID:{} 为用户{}创建消息提醒", PREFIX, customerVo.getId(), customerVo.getDemandOwner()); + messageService.saveBatchMessage(Collections.singletonList(owner), message, EnumInvestMessageTag.CUSTOMER_WEEK, EnumFollowType.DEMAND, customerVo.getId(), customerVo.getTenantId()); + log.info("{}:customerID:{} 为用户{}创建消息提醒", TAG_MESSAGE, customerVo.getId(), customerVo.getDemandOwner()); + } + + private boolean sendSMS(MallUserInfo userInfo, WxMall mall, InvestRemindEntity remind, InvestCustomerEntity customer) { + if (Objects.isNull(userInfo) || Objects.isNull(mall) || Objects.isNull(customer)) { + log.warn("{}: 参数为空 : userInfo: {}, mall: {} ,customer:{}", TAG_REMIND, userInfo, mall, customer); + return false; + } + WxMsgRecord wxMsgRecord = new WxMsgRecord(); + wxMsgRecord.setMsgType(EnumMsgRecordType.SMS.getCode()); + wxMsgRecord.setReceiver(userInfo.getPhone()); + wxMsgRecord.setTenantId(mall.getTenantId()); + Map dynamicContentMap = new HashMap<>(); + wxMsgRecord.setModelType(EnumMsgModel.INVEST_REMIND.getCode()); + dynamicContentMap.put("mallName", mall.getName()); + dynamicContentMap.put("beginDate", DateUtils.formatDateTime(remind.getBeginDate())); + dynamicContentMap.put("negotiationType", convet(remind.getNegotiationType())); + dynamicContentMap.put("customerName", customer.getName()); + wxMsgRecord.setDynamicContentMap(dynamicContentMap); + mqBaseProducer.sendMessage(wxMsgRecord, EnumMsgMqTopic.DEFAULT.getCode(), EnumMsgMqTag.DEFAULT.getCode(), EnumMsgMqKey.DEFAULT.getCode()); + return true; + } + + private String convet(EnumNegotiationType type) { + String message = ""; + if (Objects.equals(type, EnumNegotiationType.TO_VISIT)) { + message = "预约拜访"; + } else if (Objects.equals(type, EnumNegotiationType.COME_VISIT)) { + message = "需接待来访"; + } else if (Objects.equals(type, EnumNegotiationType.TELEPHONE)) { + message = "需电话联系"; + } else if (Objects.equals(type, EnumNegotiationType.MESSAGE)) { + message = "需短信、微信或其他方式联系"; + } + + return message; } } \ No newline at end of file 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 4954c2b65..76c828ec0 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,8 +1,6 @@ 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; @@ -11,7 +9,6 @@ import com.fasterxml.jackson.annotation.JsonProperty; import com.iformall.common.LogColumn; import com.iformall.enums.EnumCustomerRatingType; import com.iformall.enums.EnumCustomerType; -import com.iformall.enums.EnumInvestChannel; import lombok.Data; import lombok.EqualsAndHashCode; diff --git a/mallinkService/src/main/java/com/iformall/domain/po/invest/InvestRemindEntity.java b/mallinkService/src/main/java/com/iformall/domain/po/invest/InvestRemindEntity.java index ca8462c27..c62b0a8aa 100755 --- a/mallinkService/src/main/java/com/iformall/domain/po/invest/InvestRemindEntity.java +++ b/mallinkService/src/main/java/com/iformall/domain/po/invest/InvestRemindEntity.java @@ -1,10 +1,13 @@ package com.iformall.domain.po.invest; +import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableName; import java.util.Date; -import com.fasterxml.jackson.annotation.JsonFormat; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.iformall.enums.EnumInvestRemindStatus; +import com.iformall.enums.EnumNegotiationType; import lombok.Data; import lombok.EqualsAndHashCode; @@ -57,4 +60,21 @@ public class InvestRemindEntity extends InvestBaseEntity { */ @io.swagger.annotations.ApiModelProperty(value = "结束时间", name = "endDate" ,example = "2018-10-01") private Date endDate; + + /** + * 是否提醒:0-未提醒;1-已提醒 + */ + //@io.swagger.annotations.ApiModelProperty(value = "结束时间", name = "status") + @JsonIgnore + @TableField(value = "`status`") + private EnumInvestRemindStatus status; + + /** + * 提醒用户InvestRemindEntity + */ + @io.swagger.annotations.ApiModelProperty(value = "customerId", name = "customerId") + private Long customerId; + + @io.swagger.annotations.ApiModelProperty(value = "拜访方式:0-拜访;1-来访;2-电话;3-短信、微信或其它", name = "negotiationType") + private EnumNegotiationType negotiationType; } diff --git a/mallinkService/src/main/java/com/iformall/domain/vo/invest/InvestDemandQuery.java b/mallinkService/src/main/java/com/iformall/domain/vo/invest/InvestDemandQuery.java index 6951906b7..3d8629a58 100644 --- a/mallinkService/src/main/java/com/iformall/domain/vo/invest/InvestDemandQuery.java +++ b/mallinkService/src/main/java/com/iformall/domain/vo/invest/InvestDemandQuery.java @@ -9,10 +9,10 @@ import lombok.EqualsAndHashCode; public class InvestDemandQuery extends InvestPageQuery { /** - * 客户编号 + * 客户手机号 */ - @io.swagger.annotations.ApiModelProperty(value = "客户编号", name = "customerNo") - private String customerNo; + @io.swagger.annotations.ApiModelProperty(value = "客户手机号", name = "phone") + private String phone; /** * 客户分类:0-潜在客户;1-意向客户;2-合作客户;3-谈判失败 diff --git a/mallinkService/src/main/java/com/iformall/domain/vo/invest/InvestRemindVo.java b/mallinkService/src/main/java/com/iformall/domain/vo/invest/InvestRemindVo.java index 6f0bc8bc0..441243b15 100644 --- a/mallinkService/src/main/java/com/iformall/domain/vo/invest/InvestRemindVo.java +++ b/mallinkService/src/main/java/com/iformall/domain/vo/invest/InvestRemindVo.java @@ -15,18 +15,10 @@ public class InvestRemindVo extends InvestRemindEntity { @io.swagger.annotations.ApiModelProperty(value = "ownerInfo", name = "ownerInfo") private MallUserInfo ownerInfo; - /** - * 提醒用户InvestRemindEntity - */ - @io.swagger.annotations.ApiModelProperty(value = "customerId", name = "customerId") - private Long customerId; @io.swagger.annotations.ApiModelProperty(value = "customer", name = "customer") private InvestCustomerEntity customer; @io.swagger.annotations.ApiModelProperty(value = "brand", name = "brand") private WxBrand brand; - - @io.swagger.annotations.ApiModelProperty(value = "拜访方式:0-拜访;1-来访;2-电话;3-短信、微信或其它", name = "negotiationType") - private EnumNegotiationType negotiationType; } diff --git a/mallinkService/src/main/java/com/iformall/enums/EnumInvestRemindStatus.java b/mallinkService/src/main/java/com/iformall/enums/EnumInvestRemindStatus.java new file mode 100644 index 000000000..bf883bd3b --- /dev/null +++ b/mallinkService/src/main/java/com/iformall/enums/EnumInvestRemindStatus.java @@ -0,0 +1,40 @@ +package com.iformall.enums; + +import com.baomidou.mybatisplus.annotation.EnumValue; +import com.fasterxml.jackson.annotation.JsonValue; + +/** + * 是否提醒:0-未提醒;1-已提醒 + */ +public enum EnumInvestRemindStatus { + UN_REMINDED(0, "未提醒"), + REMINDED(1, "已提醒"), + ; + + public static EnumInvestRemindStatus getEnum(Integer code) { + for (EnumInvestRemindStatus value : values()) { + if (value.getCode().equals(code)) { + return value; + } + } + return null; + } + + @EnumValue + private final Integer code; + private final String info; + + EnumInvestRemindStatus(Integer code, String info) { + this.code = code; + this.info = info; + } + + @JsonValue + public Integer getCode() { + return code; + } + + public String getInfo() { + return info; + } +} diff --git a/mallinkService/src/main/java/com/iformall/enums/EnumMsgModel.java b/mallinkService/src/main/java/com/iformall/enums/EnumMsgModel.java index 6c6906fc6..441099b22 100644 --- a/mallinkService/src/main/java/com/iformall/enums/EnumMsgModel.java +++ b/mallinkService/src/main/java/com/iformall/enums/EnumMsgModel.java @@ -36,6 +36,8 @@ public enum EnumMsgModel { COUPON_BIRTHDAY_OPENED_NO(29, "会员生日券倍率未开启"), COUPON_CARD_SEND(30, "系统发卡"), + + INVEST_REMIND(31, "招商预约提醒"), ; public static EnumMsgModel getEnum(Integer code) { diff --git a/mallinkService/src/main/java/com/iformall/enums/EnumMsgModelReplace.java b/mallinkService/src/main/java/com/iformall/enums/EnumMsgModelReplace.java index b17b78026..94649a5ca 100644 --- a/mallinkService/src/main/java/com/iformall/enums/EnumMsgModelReplace.java +++ b/mallinkService/src/main/java/com/iformall/enums/EnumMsgModelReplace.java @@ -22,6 +22,10 @@ public enum EnumMsgModelReplace { R14("{page}", "【管理端】"), R15("{bustype}", "【任务类型】"), R16("{contract}", "【合同编号】"), + R17("{mallName}", "【商户名称】"), + R18("{beginDate}", "【开始时间】"), + R19("{negotiationType}", "【洽谈方式】"), + R20("{customerName}", "【客户负责人】"), ; public static EnumMsgModelReplace getEnum(Integer code) { diff --git a/mallinkService/src/main/java/com/iformall/enums/EnumNegotiationType.java b/mallinkService/src/main/java/com/iformall/enums/EnumNegotiationType.java index 3373848fb..5335e59d5 100644 --- a/mallinkService/src/main/java/com/iformall/enums/EnumNegotiationType.java +++ b/mallinkService/src/main/java/com/iformall/enums/EnumNegotiationType.java @@ -22,8 +22,8 @@ public enum EnumNegotiationType { return null; } - private final Integer code; @EnumValue + private final Integer code; private final String info; EnumNegotiationType(Integer code, String info) { diff --git a/mallinkService/src/main/java/com/iformall/service/impl/WxBillAllServiceImpl.java b/mallinkService/src/main/java/com/iformall/service/impl/WxBillAllServiceImpl.java index ed19532d9..b2aa9490b 100644 --- a/mallinkService/src/main/java/com/iformall/service/impl/WxBillAllServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/impl/WxBillAllServiceImpl.java @@ -1292,15 +1292,15 @@ public class WxBillAllServiceImpl implements WxBillAllService { JSONArray priceDetals = new JSONArray(); JSONObject priceDetal = new JSONObject(); priceDetal.put("key", "price"); - priceDetal.put("value", 0); + priceDetal.put("value", 1); priceDetals.add(priceDetal); priceDetal = new JSONObject(); priceDetal.put("key", "way"); - priceDetal.put("value", 0); + priceDetal.put("value", 1); priceDetals.add(priceDetal); priceDetal = new JSONObject(); priceDetal.put("key", "unit"); - priceDetal.put("value", 0); + priceDetal.put("value", 1); priceDetals.add(priceDetal); daily.setPriceDetail(JSONArray.toJSONString(priceDetals)); wxBillDailyMapper.insert(daily); 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 ef15c5708..482822591 100644 --- a/mallinkService/src/main/java/com/iformall/service/invest/InvestBizService.java +++ b/mallinkService/src/main/java/com/iformall/service/invest/InvestBizService.java @@ -23,6 +23,8 @@ public interface InvestBizService { void importCustomer(@RequestParam("file") MultipartFile mFile); + Map queryCustomerImportCount() ; + List queryCustomer(); InvestPageResult queryPageTask(InvestTaskQuery params); @@ -61,4 +63,6 @@ public interface InvestBizService { InvestFollowRecordVo findFollowRecordById(Long id) ; + Map statistics(); + } diff --git a/mallinkService/src/main/java/com/iformall/service/invest/InvestRemindService.java b/mallinkService/src/main/java/com/iformall/service/invest/InvestRemindService.java index e25a8ece7..d332c5afb 100755 --- a/mallinkService/src/main/java/com/iformall/service/invest/InvestRemindService.java +++ b/mallinkService/src/main/java/com/iformall/service/invest/InvestRemindService.java @@ -2,8 +2,8 @@ package com.iformall.service.invest; import com.baomidou.mybatisplus.extension.service.IService; import com.iformall.domain.po.invest.InvestRemindEntity; -import com.iformall.domain.vo.invest.InvestPageQuery; -import com.iformall.domain.vo.invest.InvestPageResult; + +import java.util.List; /** * 招商提醒 @@ -17,5 +17,7 @@ public interface InvestRemindService extends IService,Invest //InvestPageResult queryPage(InvestPageQuery params); boolean removeAll() ; + + List findUnRemindList(); } 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 6a2cfc027..4a50976ac 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 @@ -38,7 +38,6 @@ import org.springframework.web.multipart.MultipartFile; import javax.servlet.http.HttpServletResponse; import java.io.*; -import java.time.temporal.TemporalAmount; import java.util.*; import java.util.concurrent.TimeUnit; import java.util.function.Function; @@ -90,7 +89,7 @@ public class InvestBizServiceImpl implements InvestBizService { } List demandList = demandService.list(new LambdaQueryWrapper<>(demandParams)); LambdaQueryWrapper queryWrapperCustomer = new LambdaQueryWrapper<>(customerParams); - queryWrapperCustomer.like(StringUtils.isNotBlank(params.getCustomerNo()), InvestCustomerEntity::getCustomerNo, params.getCustomerNo()); + queryWrapperCustomer.like(StringUtils.isNotBlank(params.getPhone()), InvestCustomerEntity::getPhone, params.getPhone()); if (Objects.isNull(InvestUserContext.getDataUser())) { if (CollectionUtils.isEmpty(demandList) && Objects.nonNull(params.getDemandOwner())) { @@ -227,10 +226,44 @@ public class InvestBizServiceImpl implements InvestBizService { } } - doImport(lFile, tenantId, importKey); + doImport(lFile, importKey); } - private void doImport(File file, String tenantId, String importKey) { + @Override + public Map queryCustomerImportCount() { + String importKey = Constant.importInvestCustomerPrev + InvestUserContext.getUserId(); + Map entries = stringRedisTemplate.opsForHash().entries(importKey); + log.info(JSONArray.toJSONString(entries) + ">>>>>>>>>>>>>>>>>>>>>1"); + if (entries.size() < 4) { + entries.clear(); + return entries; + } + String allCount = entries.get("allCount").toString(); + String allSuccessCount = entries.get("allSuccessCount").toString(); + String processCount = entries.get("processCount").toString(); + String failCount = entries.get("failCount").toString(); + + if (StringUtils.isNotBlank(failCount) && allCount.equals(failCount)) {//stringRedisTemplate.expire(userId,1,TimeUnit.SECONDS); + log.info(JSONArray.toJSONString(entries) + ">>>>>>>>>>>>>>>>>>>>>2"); + //完全失败 + stringRedisTemplate.opsForHash().delete(importKey, "allCount"); + stringRedisTemplate.opsForHash().delete(importKey, "allSuccessCount"); + stringRedisTemplate.opsForHash().delete(importKey, "processCount"); + stringRedisTemplate.opsForHash().delete(importKey, "failCount"); + throw new MallinkException(ErrorCode.MEM_IMPORT_ERR); + } + //导入完成 + if (StringUtils.isNotBlank(allSuccessCount) && allSuccessCount.equals(processCount)) { + stringRedisTemplate.opsForHash().delete(importKey, "allCount"); + stringRedisTemplate.opsForHash().delete(importKey, "allSuccessCount"); + stringRedisTemplate.opsForHash().delete(importKey, "processCount"); + stringRedisTemplate.opsForHash().delete(importKey, "failCount"); + return entries; + } + return entries; + } + + private void doImport(File file, String importKey) { ImportParams params = new ImportParams(); // 需要验证 params.setImportFields(new String[]{"品牌*", "品牌负责人*", "负责人电话*", "经营业态*", "意向铺位*", "意向租凭面积", "预计开业时间"}); @@ -335,7 +368,7 @@ public class InvestBizServiceImpl implements InvestBizService { log.error("经营业态为空", customer.toString()); return; } - InvestDemandDto toImportCustomer = convetCustomer(customer, brandMap, businesseMap, shopMap, customerMap.get(customer.getPhone()), demandMap); + InvestDemandDto toImportCustomer = convetCustomer(importKey, customer, brandMap, businesseMap, shopMap, customerMap.get(customer.getPhone()), demandMap); if (toImportCustomer == null) { stringRedisTemplate.opsForHash().increment(importKey, "processCount", 1); log.error("customerBase null"); @@ -347,13 +380,14 @@ public class InvestBizServiceImpl implements InvestBizService { toImportCustomer.getCustomer().setId(customerMap.get(customer.getPhone()).getId()); updateCustomerAndDemand(toImportCustomer); } + //记数 + stringRedisTemplate.opsForHash().increment(importKey,"processCount",1); + stringRedisTemplate.expire(importKey,10, TimeUnit.SECONDS); }); } catch (Exception e) { setRedisValue(importKey, "1", "0", "0", "1", true); log.error("导入模板失败", e); throw new MallinkException(ErrorCode.MEM_IMPORT_ERR.getCode(), "导入模板失败"); - } finally { - stringRedisTemplate.expire(importKey, 3, TimeUnit.SECONDS); } } @@ -367,7 +401,7 @@ public class InvestBizServiceImpl implements InvestBizService { return getMap(brands, WxBrand::getName); } - private InvestDemandDto convetCustomer(InvestCustomerVo importCustomerVo, Map brandMap, Map businesseMap, Map shopMap, InvestCustomerEntity dbCustomer, Map demandMap) { + private InvestDemandDto convetCustomer(String importKey, InvestCustomerVo importCustomerVo, Map brandMap, Map businesseMap, Map shopMap, InvestCustomerEntity dbCustomer, Map demandMap) { InvestCustomerEntity customerEntity = null; InvestDemandEntity demandEntity = null; if (Objects.isNull(dbCustomer)) { @@ -380,16 +414,19 @@ public class InvestBizServiceImpl implements InvestBizService { demandEntity = new InvestDemandEntity(); } if (Objects.isNull(brandMap.get(importCustomerVo.getBrandName()))) { + log.warn("品牌:{} 不存在", importCustomerVo.getBrandName()); return null; } customerEntity.setBrandId(brandMap.get(importCustomerVo.getBrandName()).getId()); if (Objects.isNull(businesseMap.get(importCustomerVo.getBusiness()))) { + log.warn("业态:{} 不存在", importCustomerVo.getBusiness()); return null; } customerEntity.setBusinessId(businesseMap.get(importCustomerVo.getBusiness()).getId()); if (Objects.isNull(shopMap.get(importCustomerVo.getShopNumber()))) { + log.warn("意向铺位:{} 不存在", importCustomerVo.getShopNumber()); return null; } customerEntity.setName(importCustomerVo.getName()); @@ -620,7 +657,7 @@ public class InvestBizServiceImpl implements InvestBizService { LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); queryWrapper.eq(InvestRemindEntity::getTenantId,InvestUserContext.getUser().getTenantId()); queryWrapper.apply(Objects.nonNull(params.getRemindDate()), - "date_format(begin_date,'%Y-%m-%d') >= {0} AND date_format(end_date,'%Y-%m-%d') <= {1}" + "date_format(begin_date,'%Y-%m-%d') >= {0} AND date_format(end_date,'%Y-%m-%d') < {1}" , getDayStart(params.getRemindDate()) , getDayEnd(params.getRemindDate())); queryWrapper.orderByDesc(InvestRemindEntity::getCreateDate); @@ -888,6 +925,10 @@ public class InvestBizServiceImpl implements InvestBizService { List businesses = businessService.listAsPage(null, 1, Integer.MAX_VALUE).getList(); Map businesseMap = getMap(businesses, WxBusiness::getId); + //业态信息 + List shopList = shopService.listAsPage(null, 1, Integer.MAX_VALUE).getList(); + Map shopMap = getMap(shopList, WxShop::getId); + List resultList = new ArrayList<>(); for (InvestOperateRecordEntity recordEntity : recordList) { InvestOperateRecordVo itemVo = new InvestOperateRecordVo(); @@ -926,6 +967,15 @@ public class InvestBizServiceImpl implements InvestBizService { if (Objects.nonNull(userAfter)) { tableTriple.setAfter(userAfter.getName()); } + } else if (Objects.equals(column, "targetId")) { + WxShop shopBefore = shopMap.get(tableTriple.getBefore()); + WxShop shopAfter = shopMap.get(tableTriple.getAfter()); + if (Objects.nonNull(shopBefore)) { + tableTriple.setBefore(shopBefore.getShopNumber()); + } + if (Objects.nonNull(shopAfter)) { + tableTriple.setAfter(shopAfter.getShopNumber()); + } } return tableTriple; })); @@ -962,19 +1012,52 @@ public class InvestBizServiceImpl implements InvestBizService { return buildFollowRecordItem(usersMap, followRecordEntity, customerEntity, brand); } + @Override + public Map statistics() { + Map result = new HashMap<>(); + if (Objects.isNull(InvestUserContext.getDataUser())) { + result.put("taskTotal", taskService.count(new LambdaQueryWrapper() + .ge(InvestTaskEntity::getStatus, EnumTaskStatus.CREATED) + .eq(InvestTaskEntity::getTenantId, InvestUserContext.getUser().getTenantId()))); + result.put("customerTotal", customerService.count(new LambdaQueryWrapper() + .ge(InvestCustomerEntity::getTenantId, InvestUserContext.getUser().getTenantId()))); + result.put("taskToday", customerService.count(new LambdaQueryWrapper() + .apply("date_format(create_date,'%Y-%m-%d') = {0}", DateUtils.format(new Date())) + .eq(InvestCustomerEntity::getTenantId, InvestUserContext.getUser().getTenantId()))); + result.put("customerImport", customerService.count(new LambdaQueryWrapper() + .eq(InvestCustomerEntity::getType, EnumCustomerType.INTENTIONAL) + .eq(InvestCustomerEntity::getTenantId, InvestUserContext.getUser().getTenantId()))); + result.put("remindCount", remindService.count(new LambdaQueryWrapper() + .ge(InvestRemindEntity::getTenantId, InvestUserContext.getUser().getTenantId()))); + result.put("taskCreate", taskService.count(new LambdaQueryWrapper() + .eq(InvestTaskEntity::getStatus, EnumTaskStatus.CREATED) + .eq(InvestTaskEntity::getTenantId, InvestUserContext.getUser().getTenantId()))); + //result.put("customerCreate", customerService.count(new LambdaQueryWrapper() + // .eq(InvestCustomerEntity::getStatus, EnumTaskStatus.CREATED))); + } else { + result.put("taskTotal", taskService.count(new LambdaQueryWrapper() + .ge(InvestTaskEntity::getStatus, EnumTaskStatus.CREATED) + .apply("`owner` REGEXP {0}", InvestUserContext.getUserId()))); + result.put("customerTotal", demandService.count(new LambdaQueryWrapper() + .ge(InvestDemandEntity::getOwner, InvestUserContext.getUser().getTenantId()))); + } + return result; + } + private void syncTargetStatus(InvestTaskEntity investTaskEntity) { //if (!Objects.equals(investTaskEntity.getTargetType(), EnumInvestType.RENT)) { // return; //} - if (StringUtils.isNotBlank(investTaskEntity.getOwner())) { - investTaskEntity.setStatus(EnumTaskStatus.NEGOTIATING); + if (StringUtils.isBlank(investTaskEntity.getOwner())) { + investTaskEntity.setStatus(EnumTaskStatus.CREATED); } else { WxShop shop = shopService.getById(investTaskEntity.getTargetId()); Map shopContractMap = getWxRentContractMap(shop); WxRentContract contract = shopContractMap.get(shop.getId()); if (Objects.nonNull(contract)) { InvestHelper.addContractId(investTaskEntity.getContent(), contract.getId(), null); + investTaskEntity.setStatus(EnumTaskStatus.FINISH); } else { WxRentContract contractQuery = new WxRentContract(); contractQuery.setTenantId(InvestUserContext.getUser().getTenantId()); @@ -984,6 +1067,8 @@ public class InvestBizServiceImpl implements InvestBizService { int count = rentContractService.selectContractCountByShopId(contractQuery); if (count > 0) { investTaskEntity.setStatus(EnumTaskStatus.INTENTION); + } else { + investTaskEntity.setStatus(EnumTaskStatus.NEGOTIATING); } } } @@ -1115,10 +1200,14 @@ public class InvestBizServiceImpl implements InvestBizService { Map bussinessMap = getMap(businessService.getByIds(getIds(customers, InvestCustomerEntity::getBusinessId)), WxBusiness::getId); List resultList = new ArrayList<>(); for (InvestCustomerEntity costomerItem : customers) { - Optional demandItem = Optional.ofNullable(demindsMap.get(costomerItem.getId())); - WxShop shop = shopsMap.get(demandItem.orElse(null)); - WxBrand brand = brandMap.get(costomerItem.getBrandId()); - resultList.add(buildCustomerItem(demandItem.orElse(null), costomerItem, brand, shop, bussinessMap.get(costomerItem.getBusinessId()))); + InvestDemandEntity demandItem = demindsMap.get(costomerItem.getId()); + WxShop shop = null; + WxBrand brand = null ; + if (Objects.nonNull(demandItem)) { + shop = shopsMap.get(demandItem.getTargetId()); + brand = brandMap.get(costomerItem.getBrandId()); + } + resultList.add(buildCustomerItem(demandItem, costomerItem, brand, shop, bussinessMap.get(costomerItem.getBusinessId()))); } return resultList; } @@ -1137,10 +1226,14 @@ public class InvestBizServiceImpl implements InvestBizService { List resultList = new ArrayList<>(); for (InvestCustomerEntity costomerItem : customers) { - Optional demandItem = Optional.ofNullable(demindsMap.get(costomerItem.getId())); - WxShop shop = shopsMap.get(demandItem.orElse(null)); - WxBrand brand = brandMap.get(costomerItem.getBrandId()); - resultList.add(buildDemindItem(demandItem.orElse(null), costomerItem, brand, shop, usersMap)); + InvestDemandEntity demandItem = demindsMap.get(costomerItem.getId()); + WxShop shop = null; + WxBrand brand = null ; + if (Objects.nonNull(demandItem)) { + shop = shopsMap.get(demandItem.getTargetId()); + brand = brandMap.get(costomerItem.getBrandId()); + } + resultList.add(buildDemindItem(demandItem, costomerItem, brand, shop, usersMap)); } return resultList; } 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 c9f03c884..4a5f15dc8 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 @@ -44,6 +44,7 @@ public class InvestCustomerServiceImpl extends InvestBaseServiceImpl listByTime(EnumFollowType followType, Date start) { LambdaUpdateWrapper query = new LambdaUpdateWrapper<>() ; query.eq(InvestFollowRecordEntity::getType,followType) ; - query.ge(InvestFollowRecordEntity::getCreateDate, start); + query.le(InvestFollowRecordEntity::getCreateDate, start); return list(query); } diff --git a/mallinkService/src/main/java/com/iformall/service/invest/impl/InvestMessageServiceImpl.java b/mallinkService/src/main/java/com/iformall/service/invest/impl/InvestMessageServiceImpl.java index 50ce6d2c1..06664d12c 100755 --- a/mallinkService/src/main/java/com/iformall/service/invest/impl/InvestMessageServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/invest/impl/InvestMessageServiceImpl.java @@ -66,7 +66,7 @@ public class InvestMessageServiceImpl extends InvestBaseServiceImpl listByTypeAndTag(EnumFollowType type, EnumInvestMessageTag tag) { LambdaQueryWrapper messageQueryWrapper = new LambdaQueryWrapper<>(); messageQueryWrapper.eq(InvestMessageEntity::getType, type); - messageQueryWrapper.ge(InvestMessageEntity::getTag, tag); + messageQueryWrapper.eq(InvestMessageEntity::getTag, tag); return list(messageQueryWrapper); } } diff --git a/mallinkService/src/main/java/com/iformall/service/invest/impl/InvestRemindServiceImpl.java b/mallinkService/src/main/java/com/iformall/service/invest/impl/InvestRemindServiceImpl.java index 5312e9808..5d7236348 100755 --- a/mallinkService/src/main/java/com/iformall/service/invest/impl/InvestRemindServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/invest/impl/InvestRemindServiceImpl.java @@ -1,13 +1,21 @@ package com.iformall.service.invest.impl; +import com.alibaba.fastjson.JSON; import com.baomidou.mybatisplus.core.conditions.Wrapper; import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; import com.iformall.domain.po.invest.InvestRemindEntity; import com.iformall.domain.vo.invest.InvestUserContext; +import com.iformall.enums.EnumInvestRemindStatus; +import com.iformall.enums.EnumNegotiationType; import com.iformall.mapper.InvestRemindMapper; import com.iformall.service.invest.InvestRemindService; +import com.iformall.utils.DateUtils; +import org.apache.commons.collections.MapUtils; import org.springframework.stereotype.Service; +import java.util.Date; +import java.util.List; +import java.util.Map; import java.util.Objects; @@ -42,10 +50,25 @@ public class InvestRemindServiceImpl extends InvestBaseServiceImpl findUnRemindList() { + LambdaUpdateWrapper wrapper = new LambdaUpdateWrapper<>(); + wrapper.eq(InvestRemindEntity::getStatus, EnumInvestRemindStatus.UN_REMINDED); + wrapper.gt(InvestRemindEntity::getBeginDate, DateUtils.formatDateTime(new Date())); + return this.list(wrapper); + } + private void checkBeforeSaveOrUpdate(InvestRemindEntity input) { input.setOwner(InvestUserContext.getUserId()); if (Objects.nonNull(input.getContent())) { input.setContent(stringToJson(input.getContent())); } + Map contentMap = JSON.parseObject(input.getContent(), Map.class); + if (MapUtils.isNotEmpty(contentMap)) { + Object customerId = contentMap.get(InvestRemindEntity.KEY_CUSTOMER); + input.setCustomerId(Objects.isNull(customerId) ? null : Long.parseLong((String) customerId)); + Object negotiationType = contentMap.get(InvestRemindEntity.KEY_NEGOTIATIONTYPE); + input.setNegotiationType(EnumNegotiationType.getEnum(Integer.valueOf((String) negotiationType))); + } } } diff --git a/mallinkService/src/main/resources/mapper/InvestCustomerMapper.xml b/mallinkService/src/main/resources/mapper/InvestCustomerMapper.xml index e968a5624..7930e51af 100644 --- a/mallinkService/src/main/resources/mapper/InvestCustomerMapper.xml +++ b/mallinkService/src/main/resources/mapper/InvestCustomerMapper.xml @@ -20,10 +20,9 @@