diff --git a/flossom-common/flossom-common-core/src/main/java/com/flossom/common/core/enums/IsScriptTemplateEnum.java b/flossom-common/flossom-common-core/src/main/java/com/flossom/common/core/enums/IsScriptTemplateEnum.java new file mode 100644 index 0000000..00f40a1 --- /dev/null +++ b/flossom-common/flossom-common-core/src/main/java/com/flossom/common/core/enums/IsScriptTemplateEnum.java @@ -0,0 +1,27 @@ +package com.flossom.common.core.enums; + +/** + * 是否自定话术 + * + * @author flossom + */ +public enum IsScriptTemplateEnum { + SCRIPT_TEMPLATE(0, "话术模板"), CUSTOM_SCRIPT(1, "自定义话术"); + + private final Integer code; + private final String info; + + IsScriptTemplateEnum(Integer code, String info) { + this.code = code; + this.info = info; + } + + public Integer getCode() { + return code; + } + + public String getInfo() { + return info; + } + +} diff --git a/flossom-modules/flossom-system/src/main/java/com/flossom/system/service/impl/WxUserScriptLogServiceImpl.java b/flossom-modules/flossom-system/src/main/java/com/flossom/system/service/impl/WxUserScriptLogServiceImpl.java index 0204b35..3d3153c 100644 --- a/flossom-modules/flossom-system/src/main/java/com/flossom/system/service/impl/WxUserScriptLogServiceImpl.java +++ b/flossom-modules/flossom-system/src/main/java/com/flossom/system/service/impl/WxUserScriptLogServiceImpl.java @@ -8,6 +8,8 @@ import com.flossom.common.core.domain.entity.SysTag; import com.flossom.common.core.domain.entity.WxScriptTemplate; import com.flossom.common.core.domain.entity.WxUserScriptLog; import com.flossom.common.core.domain.req.WxUserScriptReq; +import com.flossom.common.core.enums.IsScriptTemplateEnum; +import com.flossom.common.core.enums.Status; import com.flossom.common.core.enums.WxUserIntegralMessageTypeEnum; import com.flossom.common.core.mapper.*; import com.flossom.common.core.utils.DateUtils; @@ -116,25 +118,32 @@ public class WxUserScriptLogServiceImpl implements IWxUserScriptLogService { @Transactional public void sendScript(WxUserScriptReq wxUserScriptReq) { List userIdList = wxUserScriptReq.getUserIdList(); - // 保存消息 - for (Long wxUserId : userIdList) { - WxUserScriptLog wxUserScriptLog = new WxUserScriptLog(); - BeanUtils.copyProperties(wxUserScriptReq, wxUserScriptLog); - if (wxUserScriptReq.getTagIds() != null && wxUserScriptReq.getTagIds().size() > 0) { - wxUserScriptLog.setTagIds(wxUserScriptReq.getTagIds().stream().collect(Collectors.joining(","))); - } - wxUserScriptLog.setMessageType(WxUserIntegralMessageTypeEnum.MEMBER_MANAGEMENT.getCode()); - wxUserScriptLog.setWxUserId(wxUserId); - wxUserScriptLog.setCreateBy(SecurityUtils.getUsername()); - wxUserScriptLog.setCreateTime(DateUtils.getNowDate()); - wxUserScriptLogMapper.insertWxUserScriptLog(wxUserScriptLog); - } - - // 保存标签关联 - if (wxUserScriptReq.getIsCustom() == 0) { - // 模板话术 + // 1、话术模板 + if (IsScriptTemplateEnum.SCRIPT_TEMPLATE.getCode() == wxUserScriptReq.getIsCustom()) { + // 1.1、保存消息 + // 获取话术模板 Integer scriptTemplateId = wxUserScriptReq.getScriptTemplateId(); WxScriptTemplate wxScriptTemplate = wxScriptTemplateMapper.selectWxScriptTemplateById(scriptTemplateId.longValue()); + for (Long wxUserId : userIdList) { + WxUserScriptLog wxUserScriptLog = new WxUserScriptLog(); + BeanUtils.copyProperties(wxScriptTemplate, wxUserScriptLog); + + wxUserScriptLog.setId(null); + wxUserScriptLog.setWxUserId(wxUserId); + wxUserScriptLog.setMessageType(WxUserIntegralMessageTypeEnum.MEMBER_MANAGEMENT.getCode()); + wxUserScriptLog.setIsCustom(IsScriptTemplateEnum.SCRIPT_TEMPLATE.getCode()); + wxUserScriptLog.setScriptTemplateId(scriptTemplateId); + + wxUserScriptLog.setStatus(Status.OK.getCode()); + wxUserScriptLog.setCreateBy(SecurityUtils.getUsername()); + wxUserScriptLog.setCreateTime(DateUtils.getNowDate()); + wxUserScriptLog.setUpdateBy(null); + wxUserScriptLog.setUpdateTime(null); + wxUserScriptLog.setRemark(null); + wxUserScriptLogMapper.insertWxUserScriptLog(wxUserScriptLog); + } + + //1.2、 会员添加小程序标签 if (StringUtils.isNotBlank(wxScriptTemplate.getTagIds())) { List list = Arrays.asList(wxScriptTemplate.getTagIds().split(",")); List tagList = list.stream().map(Integer::parseInt).collect(Collectors.toList()); @@ -142,8 +151,23 @@ public class WxUserScriptLogServiceImpl implements IWxUserScriptLogService { wxUserMemberService.batchAddMiniProgramTag(tagList, collect); } } - if (wxUserScriptReq.getIsCustom() == 1) { - // 自定义话术 + + // 2、自定义话术 + if (IsScriptTemplateEnum.CUSTOM_SCRIPT.getCode() == wxUserScriptReq.getIsCustom()) { + //2、1 保存消息 + for (Long wxUserId : userIdList) { + WxUserScriptLog wxUserScriptLog = new WxUserScriptLog(); + BeanUtils.copyProperties(wxUserScriptReq, wxUserScriptLog); + if (wxUserScriptReq.getTagIds() != null && wxUserScriptReq.getTagIds().size() > 0) { + wxUserScriptLog.setTagIds(wxUserScriptReq.getTagIds().stream().collect(Collectors.joining(","))); + } + wxUserScriptLog.setMessageType(WxUserIntegralMessageTypeEnum.MEMBER_MANAGEMENT.getCode()); + wxUserScriptLog.setWxUserId(wxUserId); + wxUserScriptLog.setCreateBy(SecurityUtils.getUsername()); + wxUserScriptLog.setCreateTime(DateUtils.getNowDate()); + wxUserScriptLogMapper.insertWxUserScriptLog(wxUserScriptLog); + } + //2、2 会员添加小程序标签 if (wxUserScriptReq.getTagIds() != null && wxUserScriptReq.getTagIds().size() > 0) { List tagList = wxUserScriptReq.getTagIds().stream().map(Integer::parseInt).collect(Collectors.toList()); List collect = userIdList.stream().map(Long::intValue).collect(Collectors.toList());