Commit 851b47dd by zhouhaibao

feat(sop): 完善SOP策略配置和消息执行功能

- 添加coverurl配置项并设置默认值
- 修改marketingPageUrl默认值为百度链接
- 移除快照中的冗余客户信息变量
- 更新动作确认类型枚举说明
- 添加pageDesc字段映射到数据库查询结果
- 修正groupId字段名映射
- 扩展确认状态类型定义
- 调整策略触发服务中的确认逻辑
- 在策略创建和更新DTO中更新确认类型描述
- 实现媒体资源处理逻辑
- 更新测试用例中的相关数据和配置
- 完善微信链接消息发送功能,增加页面描述和封面URL支持
1 parent da5661d1
...@@ -40,7 +40,7 @@ public class SopStrategyCreateReqDTO implements Serializable { ...@@ -40,7 +40,7 @@ public class SopStrategyCreateReqDTO implements Serializable {
@ApiModelProperty(value = "触发分钟") @ApiModelProperty(value = "触发分钟")
private Integer triggerMinute; private Integer triggerMinute;
@ApiModelProperty(value = "动作确认类型:1-自动执行 2-需确认") @ApiModelProperty(value = "确认类型(0自动执行/1人工确认)")
private Integer actionConfirmType; private Integer actionConfirmType;
@ApiModelProperty(value = "门店ID列表") @ApiModelProperty(value = "门店ID列表")
......
...@@ -43,7 +43,7 @@ public class SopStrategyUpdateReqDTO implements Serializable { ...@@ -43,7 +43,7 @@ public class SopStrategyUpdateReqDTO implements Serializable {
@ApiModelProperty(value = "触发分钟") @ApiModelProperty(value = "触发分钟")
private Integer triggerMinute; private Integer triggerMinute;
@ApiModelProperty(value = "动作确认类型:1-自动执行 2-需确认") @ApiModelProperty(value = "确认类型(0自动执行/1人工确认)")
private Integer actionConfirmType; private Integer actionConfirmType;
@ApiModelProperty(value = "门店ID列表") @ApiModelProperty(value = "门店ID列表")
......
...@@ -92,7 +92,7 @@ public class SopStrategy implements Serializable { ...@@ -92,7 +92,7 @@ public class SopStrategy implements Serializable {
private Integer triggerMinute; private Integer triggerMinute;
/** /**
* 动作确认类型:-1 自动执行 0 需确认 * 动作确认类型: 0 自动执行 1 需确认
*/ */
@Column(name = "action_confirm_type", nullable = false) @Column(name = "action_confirm_type", nullable = false)
private Integer actionConfirmType; private Integer actionConfirmType;
......
...@@ -56,7 +56,7 @@ public class SopStrategyTask implements Serializable { ...@@ -56,7 +56,7 @@ public class SopStrategyTask implements Serializable {
private Integer executeStatus; private Integer executeStatus;
/** /**
* 确认状态:0-待确认 1-已确认 2-已拒绝 * 确认状态:-1 无需确认,系统执行 0-待确认 1-已确认 2-已拒绝
*/ */
@Column(name = "confirm_status", nullable = false) @Column(name = "confirm_status", nullable = false)
private Integer confirmStatus; private Integer confirmStatus;
......
...@@ -16,6 +16,8 @@ public class ImHubConfig { ...@@ -16,6 +16,8 @@ public class ImHubConfig {
@Value("${imhub.channel:yjy_ww}") @Value("${imhub.channel:yjy_ww}")
private String channel; private String channel;
@Value("${imhub.coverurl:https://jinrong-huidan-test.oss-cn-shenzhen.aliyuncs.com/jpg/1758857680085_8172/微信图片_20220321210132.jpg}")
private String coverurl;
@Value("${imhub.allow-retry:1}") @Value("${imhub.allow-retry:1}")
private String allowRetry; private String allowRetry;
...@@ -23,6 +25,6 @@ public class ImHubConfig { ...@@ -23,6 +25,6 @@ public class ImHubConfig {
@Value("${imhub.allow-realloc:1}") @Value("${imhub.allow-realloc:1}")
private String allowRealloc; private String allowRealloc;
@Value("${sop.marketing-page.url:}") @Value("${sop.marketing-page.url:https://www.baidu.com}")
private String marketingPageUrl; private String marketingPageUrl;
} }
\ No newline at end of file \ No newline at end of file
...@@ -159,19 +159,6 @@ public class SopCustomerSnapshotService { ...@@ -159,19 +159,6 @@ public class SopCustomerSnapshotService {
variables.put("carSeriesLevel", snapshot.getCarSeriesLevel()); variables.put("carSeriesLevel", snapshot.getCarSeriesLevel());
variables.put("groupId", snapshot.getGroupId()); variables.put("groupId", snapshot.getGroupId());
variables.put("group_id", snapshot.getGroupId()); variables.put("group_id", snapshot.getGroupId());
variables.put("客户称呼", snapshot.getCustomerName());
variables.put("客户交付车系", snapshot.getCarSeries());
variables.put("客户手机号", snapshot.getCustomerPhone());
variables.put("所属门店", snapshot.getStoreName());
variables.put("门店名称", snapshot.getStoreName());
variables.put("车辆品牌", snapshot.getCarBrand());
variables.put("车辆车系", snapshot.getCarSeries());
variables.put("车系级别", snapshot.getCarSeriesLevel());
variables.put("客户类别", snapshot.getCustomerCategory());
variables.put("员工姓名", snapshot.getStaffName());
variables.put("大定日期", snapshot.getDepositDate());
variables.put("交付日期", snapshot.getDeliveryDate());
log.info("从快照构建上下文变量完成, taskId:{}, variableCount:{}", taskId, variables.size()); log.info("从快照构建上下文变量完成, taskId:{}, variableCount:{}", taskId, variables.size());
return variables; return variables;
......
...@@ -198,7 +198,7 @@ public class SopStrategyTriggerService { ...@@ -198,7 +198,7 @@ public class SopStrategyTriggerService {
task.setTriggerTime(triggerTime); task.setTriggerTime(triggerTime);
task.setExecuteStatus(0); task.setExecuteStatus(0);
task.setConfirmStatus( task.setConfirmStatus(
strategy.getActionConfirmType() != null && strategy.getActionConfirmType() == 2 ? 0 : -1); strategy.getActionConfirmType() != null && strategy.getActionConfirmType() == 0 ? -1 : 0);
task.setSnapshotInfo(snapshotInfo); task.setSnapshotInfo(snapshotInfo);
task.setDeletedFlag("N"); task.setDeletedFlag("N");
task.setCreatedDate(new Date()); task.setCreatedDate(new Date());
......
...@@ -19,8 +19,10 @@ import cn.hutool.core.collection.CollUtil; ...@@ -19,8 +19,10 @@ import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.lang.UUID; import cn.hutool.core.lang.UUID;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import java.util.stream.Collectors;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
...@@ -273,6 +275,11 @@ public class StrategySopService { ...@@ -273,6 +275,11 @@ public class StrategySopService {
} }
for (SopActionReqDTO actionReq : actions) { for (SopActionReqDTO actionReq : actions) {
SopStrategyAction action = BeanUtil.copyProperties(actionReq, SopStrategyAction.class); SopStrategyAction action = BeanUtil.copyProperties(actionReq, SopStrategyAction.class);
List<SopActionMediaReqDTO> medias = actionReq.getMedias();
if (CollectionUtils.isNotEmpty(medias)){
action.setMediaIds(medias.stream().map(SopActionMediaReqDTO::getMediaUrl).collect(
Collectors.joining(",")));
}
action.setStrategyId(strategyId); action.setStrategyId(strategyId);
action.setBranchId(branchId); action.setBranchId(branchId);
action.setDeletedFlag(DeleteFlagEnum.N.getValue()); action.setDeletedFlag(DeleteFlagEnum.N.getValue());
......
...@@ -51,6 +51,7 @@ public class WechatMessageActionExecutor implements SopActionExecutor { ...@@ -51,6 +51,7 @@ public class WechatMessageActionExecutor implements SopActionExecutor {
String content = action.getContent(); String content = action.getContent();
String mediaIds = action.getMediaIds(); String mediaIds = action.getMediaIds();
String jumpUrl = action.getJumpUrl(); String jumpUrl = action.getJumpUrl();
String pageDesc = action.getPageDesc();
if (contextVariables != null) { if (contextVariables != null) {
content = replaceVariables(content, contextVariables); content = replaceVariables(content, contextVariables);
...@@ -110,7 +111,7 @@ public class WechatMessageActionExecutor implements SopActionExecutor { ...@@ -110,7 +111,7 @@ public class WechatMessageActionExecutor implements SopActionExecutor {
if (StrUtil.isNotBlank(finalUrl)) { if (StrUtil.isNotBlank(finalUrl)) {
String finalContent = content; String finalContent = content;
retryTemplate.execute(() -> { retryTemplate.execute(() -> {
sendLinkMessage(groupId, finalContent, finalUrl); sendLinkMessage(groupId, finalContent, finalUrl, pageDesc);
return null; return null;
}, 3, idempotentKey + "_link"); }, 3, idempotentKey + "_link");
} else { } else {
...@@ -265,12 +266,14 @@ public class WechatMessageActionExecutor implements SopActionExecutor { ...@@ -265,12 +266,14 @@ public class WechatMessageActionExecutor implements SopActionExecutor {
sendImHubMessage(TASK_TYPE_VIDEO, groupId, payload); sendImHubMessage(TASK_TYPE_VIDEO, groupId, payload);
} }
private void sendLinkMessage(String groupId, String title, String link) { private void sendLinkMessage(String groupId, String title, String link, String pageDesc) {
log.info("发送链接消息, groupId:{}, title:{}, link:{}", groupId, title, link); log.info("发送链接消息, groupId:{}, title:{}, link:{}", groupId, title, link);
JSONObject payload = new JSONObject(); JSONObject payload = new JSONObject();
payload.put("title", title); payload.put("title", title);
payload.put("link", link); payload.put("link", link);
payload.put("desc", pageDesc);
payload.put("cover_url", imHubConfig.getCoverurl());
sendImHubMessage(TASK_TYPE_LINK, groupId, payload); sendImHubMessage(TASK_TYPE_LINK, groupId, payload);
} }
......
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
<result column="updated_by" property="updatedBy"/> <result column="updated_by" property="updatedBy"/>
<result column="updated_date" property="updatedDate"/> <result column="updated_date" property="updatedDate"/>
<result column="deleted_flag" property="deletedFlag"/> <result column="deleted_flag" property="deletedFlag"/>
<result column="page_desc" property="pageDesc"/>
</resultMap> </resultMap>
<select id="selectByBranchId" resultMap="BaseResultMap"> <select id="selectByBranchId" resultMap="BaseResultMap">
......
...@@ -22,7 +22,7 @@ ...@@ -22,7 +22,7 @@
<result column="car_series_level" property="carSeriesLevel"/> <result column="car_series_level" property="carSeriesLevel"/>
<result column="snapshot_data" property="snapshotData"/> <result column="snapshot_data" property="snapshotData"/>
<result column="snapshot_time" property="snapshotTime"/> <result column="snapshot_time" property="snapshotTime"/>
<result column="groupId" property="groupId"/> <result column="group_id" property="groupId"/>
<result column="deleted_flag" property="deletedFlag"/> <result column="deleted_flag" property="deletedFlag"/>
<result column="created_by" property="createdBy"/> <result column="created_by" property="createdBy"/>
<result column="created_date" property="createdDate"/> <result column="created_date" property="createdDate"/>
......
package cn.com.glsx.dj.strategy.service; package cn.com.glsx.dj.strategy.service;
import cn.com.glsx.dj.strategy.dto.MerchantInfo; import cn.com.glsx.dj.strategy.dto.MerchantInfo;
import cn.com.glsx.dj.strategy.dto.sop.SopActionMediaReqDTO;
import cn.com.glsx.dj.strategy.dto.sop.SopActionReqDTO; import cn.com.glsx.dj.strategy.dto.sop.SopActionReqDTO;
import cn.com.glsx.dj.strategy.dto.sop.SopBranchReqDTO; import cn.com.glsx.dj.strategy.dto.sop.SopBranchReqDTO;
import cn.com.glsx.dj.strategy.dto.sop.SopConditionGroupReqDTO; import cn.com.glsx.dj.strategy.dto.sop.SopConditionGroupReqDTO;
...@@ -13,6 +14,7 @@ import cn.com.glsx.dj.strategy.mapper.sop.*; ...@@ -13,6 +14,7 @@ import cn.com.glsx.dj.strategy.mapper.sop.*;
import cn.com.glsx.dj.strategy.model.sop.SopStrategy; import cn.com.glsx.dj.strategy.model.sop.SopStrategy;
import cn.com.glsx.dj.strategy.model.sop.SopStrategyTask; import cn.com.glsx.dj.strategy.model.sop.SopStrategyTask;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
...@@ -75,9 +77,9 @@ public class StrategySopServiceTest { ...@@ -75,9 +77,9 @@ public class StrategySopServiceTest {
@Test @Test
public void testCreateSopStrategy_Success() { public void testCreateSopStrategy_Success() {
SopStrategyCreateReqDTO request = new SopStrategyCreateReqDTO(); SopStrategyCreateReqDTO request = new SopStrategyCreateReqDTO();
request.setStrategyName("测试策略"); request.setStrategyName("测试策略图片发送");
request.setBizType(1); request.setBizType(1);
request.setStoreScopeType(2); request.setStoreScopeType(1);
request.setMarketingStage("AFTER_DELIVERY"); request.setMarketingStage("AFTER_DELIVERY");
request.setTriggerType("DATE_TIME"); request.setTriggerType("DATE_TIME");
request.setDateVariableType("DEPOSIT_DATE"); request.setDateVariableType("DEPOSIT_DATE");
...@@ -87,7 +89,7 @@ public class StrategySopServiceTest { ...@@ -87,7 +89,7 @@ public class StrategySopServiceTest {
request.setTriggerMinute(20); request.setTriggerMinute(20);
request.setActionConfirmType(1); request.setActionConfirmType(1);
MerchantInfo merchantInfo = new MerchantInfo(); MerchantInfo merchantInfo = new MerchantInfo();
merchantInfo.setMerchantId(1); merchantInfo.setMerchantId(44211227);
request.setStoreIds(Collections.singletonList(merchantInfo)); request.setStoreIds(Collections.singletonList(merchantInfo));
request.setCreatedBy("admin"); request.setCreatedBy("admin");
...@@ -141,7 +143,7 @@ public class StrategySopServiceTest { ...@@ -141,7 +143,7 @@ public class StrategySopServiceTest {
condition1.setVariableCode("carBrand"); condition1.setVariableCode("carBrand");
condition1.setOperator(1); condition1.setOperator(1);
condition1.setValueType(4); condition1.setValueType(4);
condition1.setEnumValue("岚图"); condition1.setEnumValue("奥迪");
condition1.setValueSource(0); condition1.setValueSource(0);
SopConditionGroupReqDTO group = new SopConditionGroupReqDTO(); SopConditionGroupReqDTO group = new SopConditionGroupReqDTO();
...@@ -157,8 +159,31 @@ public class StrategySopServiceTest { ...@@ -157,8 +159,31 @@ public class StrategySopServiceTest {
action.setActionNo(1); action.setActionNo(1);
action.setActionType(1); action.setActionType(1);
action.setTargetGroupType(1); action.setTargetGroupType(1);
action.setMessageType(1); action.setMessageType(4);
action.setContent("尊敬的{{customerName}},您的新车{{carSeries}}即将交付!"); action.setPageTitle("专属服务推荐");
action.setPageDesc("欢迎查看专属服务");
action.setBgColor("#f5f5f5");
action.setMaterialJson("[{\"type\":\"image\",\"url\":\"https://example.com/image1.jpg\"},{\"type\":\"text\",\"content\":\"欢迎查看专属服务\"}]");
action.setIntervalPx(10);
/* SopActionReqDTO action = new SopActionReqDTO();
action.setActionNo(1);
action.setActionType(1);
action.setTargetGroupType(1);
action.setMessageType(2);
List<SopActionMediaReqDTO> medias= new ArrayList<>();
SopActionMediaReqDTO media = new SopActionMediaReqDTO();
media.setMediaType(1);
media.setMediaName("图片1");
media.setMediaUrl("https://jinrong-huidan-test.oss-cn-shenzhen.aliyuncs.com/jpg/1758857680085_8172/微信图片_20220321210132.jpg");
media.setSortNo(1);
medias.add(media);
SopActionMediaReqDTO media1 = new SopActionMediaReqDTO();
media1.setMediaType(1);
media1.setMediaName("图片2");
media1.setMediaUrl("http://qcimg01.glsx.com.cn:7060/group1/M00/0F/B4/wKgD3mi2ocOAInrGAABJXOEUbL4222.jpg");
media1.setSortNo(2);
medias.add(media1);
action.setMedias(medias);*/
return Arrays.asList(action); return Arrays.asList(action);
} }
...@@ -406,21 +431,12 @@ public class StrategySopServiceTest { ...@@ -406,21 +431,12 @@ public class StrategySopServiceTest {
@Test @Test
public void testConfirmSopStrategyTask_TaskAlreadyConfirmed() { public void testConfirmSopStrategyTask_TaskAlreadyConfirmed() {
SopStrategyConfirmReqDTO request = new SopStrategyConfirmReqDTO(); SopStrategyConfirmReqDTO request = new SopStrategyConfirmReqDTO();
request.setTaskId(1); request.setTaskId(39);
request.setConfirmStatus(1); request.setConfirmStatus(1);
SopStrategyTask task = new SopStrategyTask();
task.setId(1);
task.setConfirmStatus(1);
task.setDeletedFlag("N");
when(sopStrategyTaskMapper.selectByPrimaryKey(1)).thenReturn(task);
Boolean result = strategySopService.confirmSopStrategyTask(request); Boolean result = strategySopService.confirmSopStrategyTask(request);
assertTrue(result); assertTrue(result);
verify(sopStrategyTaskMapper, never()).updateByPrimaryKeySelective(any(SopStrategyTask.class));
verify(sopStrategyExecutionService, never()).executeTask(anyInt());
} }
@Test @Test
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!