Commit cdd1cc8d by zhouhaibao

feat(sop): 更新SOP策略DTO和添加消息变量解析服务

- 为CandidateCustomerDTO添加客户实例ID、客户手机号、客户姓名等字段的@ApiModel注解
- 重构SopActionDTO将actionId改为id,textContent改为content,添加pageTitle、bgColor等网页相关字段
- 简化SopActionMediaDTO和SopActionMediaReqDTO,移除mediaId、fileSize、fileExt字段,统一使用mediaName和mediaUrl
- 更新SopConditionDTO字段定义,将conditionId改为Integer类型,conditionNo改为conditionSeq,添加variableName等新字段
- 修改SopBranchDTO添加branchLogic字段定义分支逻辑,并移除step字段
- 更新SopConditionVariableDTO添加sopConditionVariableDTOList字段支持变量列表
- 添加SopMessageVariableResolverService实现消息变量解析功能,支持从快照和SQL两种数据源获取变量值
- 新增SopConditionEngineTest单元测试类验证条件引擎的各种逻辑场景
1 parent a8c3dc79
Showing 41 changed files with 1238 additions and 211 deletions
package cn.com.glsx.dj.strategy.dto.sop;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.math.BigDecimal;
......@@ -8,41 +9,60 @@ import java.util.Date;
@Data
public class CandidateCustomerDTO {
@ApiModelProperty(notes = "客户实例ID")
private Long customerInstanceId;
@ApiModelProperty(notes = "客户手机号")
private String customerPhone;
@ApiModelProperty(notes = "客户姓名")
private String customerName;
@ApiModelProperty(notes = "门店ID")
private Long storeId;
@ApiModelProperty(notes = "门店编码")
private String storeCode;
@ApiModelProperty(notes = "门店名称")
private String storeName;
@ApiModelProperty(notes = "大定日期")
private Date depositDate;
@ApiModelProperty(notes = "交付日期")
private Date deliveryDate;
@ApiModelProperty(notes = "大定到交付天数")
private BigDecimal depositToDeliveryDays;
@ApiModelProperty(notes = "交付剩余天数")
private BigDecimal deliveryRemainingDays;
@ApiModelProperty(notes = "员工UUID")
private String staffUuid;
@ApiModelProperty(notes = "员工姓名")
private String staffName;
@ApiModelProperty(notes = "客户分类")
private String customerCategory;
@ApiModelProperty(notes = "新车品牌")
private String carBrand;
@ApiModelProperty(notes = "新车车系")
private String carSeries;
@ApiModelProperty(notes = "新车车系等级")
private String carSeriesLevel;
@ApiModelProperty(notes = "未成交产品分类")
private String unfinishedProductCategory;
@ApiModelProperty(notes = "已成交产品分类")
private String finishedProductCategory;
@ApiModelProperty(notes = "分组ID")
private String groupId;
}
\ No newline at end of file
......@@ -8,30 +8,36 @@ import java.util.List;
@Data
public class SopActionDTO {
@ApiModelProperty(value = "动作ID")
private Integer actionId;
@ApiModelProperty(notes = "动作ID")
private Integer id;
@ApiModelProperty(value = "动作编号")
@ApiModelProperty(notes= "动作编号")
private Integer actionNo;
@ApiModelProperty(value = "动作类型:1-企微消息 2-短信 3-邮件 4-小程序推送")
@ApiModelProperty(notes= "动作类型:1-发送群消息")
private Integer actionType;
@ApiModelProperty(value = "目标人群类型")
@ApiModelProperty(notes= "目标人群类型1.客户所在群")
private Integer targetGroupType;
@ApiModelProperty(value = "目标企微群ID")
private String targetWecomGroupId;
@ApiModelProperty(value = "消息类型")
@ApiModelProperty(notes= "消息类型:1-文本 2-图片 3-视频 4-网页链接")
private Integer messageType;
@ApiModelProperty(value = "文本内容")
private String textContent;
@ApiModelProperty(notes= "文本内容")
private String content;
@ApiModelProperty(notes= "网页标题(消息类型为4时使用)")
private String pageTitle;
@ApiModelProperty(notes= "网页背景色(消息类型为4时使用)")
private String bgColor;
@ApiModelProperty(notes= "素材配置JSON(消息类型为4时使用)")
private String materialJson;
@ApiModelProperty(value = "网页ID")
private Long webpageId;
@ApiModelProperty(notes= "素材间隔(像素)(消息类型为4时使用)")
private Integer intervalPx;
@ApiModelProperty(value = "素材列表")
@ApiModelProperty(notes= "素材列表")
private List<SopActionMediaDTO> medias;
}
\ No newline at end of file
......@@ -5,24 +5,14 @@ import lombok.Data;
@Data
public class SopActionMediaDTO {
@ApiModelProperty(value = "素材ID")
private Long mediaId;
@ApiModelProperty(value = "素材类型:1-图片 2-视频 3-文件")
private Integer mediaType;
@ApiModelProperty(value = "文件名")
private String fileName;
private String mediaName;
@ApiModelProperty(value = "文件URL")
private String fileUrl;
@ApiModelProperty(value = "文件大小")
private Long fileSize;
@ApiModelProperty(value = "文件扩展名")
private String fileExt;
private String mediaUrl;
@ApiModelProperty(value = "排序号")
private Integer sortNo;
......
......@@ -10,16 +10,10 @@ public class SopActionMediaReqDTO {
private Integer mediaType;
@ApiModelProperty(value = "文件名")
private String fileName;
private String mediaName;
@ApiModelProperty(value = "文件URL")
private String fileUrl;
@ApiModelProperty(value = "文件大小")
private Long fileSize;
@ApiModelProperty(value = "文件扩展名")
private String fileExt;
private String mediaUrl;
@ApiModelProperty(value = "排序号")
private Integer sortNo;
......
......@@ -8,36 +8,33 @@ import java.util.List;
@Data
public class SopActionReqDTO {
@ApiModelProperty(value = "动作编号")
@ApiModelProperty(notes= "动作编号")
private Integer actionNo;
@ApiModelProperty(value = "动作类型:1-企微消息")
@ApiModelProperty(notes= "动作类型:1-发送群消息")
private Integer actionType;
@ApiModelProperty(value = "目标人群类型")
@ApiModelProperty(notes= "目标人群类型1.客户所在群")
private Integer targetGroupType;
@ApiModelProperty(value = "目标企微群ID")
private String targetWecomGroupId;
@ApiModelProperty(value = "消息类型:1-文本 2-图片 3-视频 4-网页链接")
@ApiModelProperty(notes= "消息类型:1-文本 2-图片 3-视频 4-网页链接")
private Integer messageType;
@ApiModelProperty(value = "文本内容")
private String textContent;
@ApiModelProperty(notes= "文本内容")
private String content;
@ApiModelProperty(value = "网页标题(消息类型为4时使用)")
@ApiModelProperty(notes= "网页标题(消息类型为4时使用)")
private String pageTitle;
@ApiModelProperty(value = "网页背景色(消息类型为4时使用)")
@ApiModelProperty(notes= "网页背景色(消息类型为4时使用)")
private String bgColor;
@ApiModelProperty(value = "素材配置JSON(消息类型为4时使用)")
@ApiModelProperty(notes= "素材配置JSON(消息类型为4时使用)")
private String materialJson;
@ApiModelProperty(value = "素材间隔(像素)(消息类型为4时使用)")
@ApiModelProperty(notes= "素材间隔(像素)(消息类型为4时使用)")
private Integer intervalPx;
@ApiModelProperty(value = "素材列表")
@ApiModelProperty(notes= "素材列表")
private List<SopActionMediaReqDTO> medias;
}
\ No newline at end of file
......@@ -8,21 +8,24 @@ import java.util.List;
@Data
public class SopBranchDTO {
@ApiModelProperty(value = "分支ID")
private Integer branchId;
@ApiModelProperty(notes = "分支ID")
private Integer id;
@ApiModelProperty(value = "分支编号")
@ApiModelProperty(notes = "分支编号")
private Integer branchNo;
@ApiModelProperty(value = "分支名称")
@ApiModelProperty(notes = "分支名称")
private String branchName;
@ApiModelProperty(value = "分支排序")
@ApiModelProperty(notes = "分支排序")
private Integer branchOrder;
@ApiModelProperty(value = "条件组合列表")
@ApiModelProperty(notes = "分支逻辑:1-并集(满足任一条件组) 0-交集(需满足所有条件组)")
private Boolean branchLogic;
@ApiModelProperty(notes = "条件组合列表")
private List<SopConditionGroupDTO> conditionGroups;
@ApiModelProperty(value = "动作列表")
@ApiModelProperty(notes = "动作列表")
private List<SopActionDTO> actions;
}
\ No newline at end of file
......@@ -17,9 +17,6 @@ public class SopBranchReqDTO {
@ApiModelProperty(value = "分支排序")
private Integer branchOrder;
@ApiModelProperty(value = "步骤:2-第二步(规则条件) 3-第三步(动作条件)")
private Integer step;
@ApiModelProperty(value = "条件组合列表")
private List<SopConditionGroupReqDTO> conditionGroups;
......
......@@ -6,39 +6,39 @@ import lombok.Data;
@Data
public class SopConditionDTO {
@ApiModelProperty(value = "条件ID")
private Long conditionId;
@ApiModelProperty(notes = "条件ID")
private Integer id;
@ApiModelProperty(value = "条件编号")
private Integer conditionNo;
@ApiModelProperty(notes = "条件编号")
private Integer conditionSeq;
@ApiModelProperty(value = "变量编码")
@ApiModelProperty(notes = "变量编码")
private String variableCode;
@ApiModelProperty(value = "变量类型")
private Integer variableType;
@ApiModelProperty(notes = "变量名称")
private String variableName;
@ApiModelProperty(value = "操作符类型")
private Integer operatorType;
@ApiModelProperty(notes = "值类型:1-文本 2-数值 3-日期 4-枚举")
private Integer valueType;
@ApiModelProperty(value = "值来源类型")
private Integer valueSourceType;
@ApiModelProperty(notes = "操作符类型")
private Integer operator;
@ApiModelProperty(value = "文本值")
private String valueText;
@ApiModelProperty(notes = "值来源:0-固定值 1-变量引用")
private Integer valueSource;
@ApiModelProperty(value = "数值")
private java.math.BigDecimal valueNumber;
@ApiModelProperty(notes = "文本值")
private String textValue;
@ApiModelProperty(value = "日期值")
private java.sql.Date valueDate;
@ApiModelProperty(notes = "数值")
private String numberValue;
@ApiModelProperty(value = "日期时间值")
private java.sql.Timestamp valueDatetime;
@ApiModelProperty(notes = "日期值")
private String dateValue;
@ApiModelProperty(value = "枚举值编码")
private String valueEnumCode;
@ApiModelProperty(notes = "枚举值")
private String enumValue;
@ApiModelProperty(value = "JSON值")
private String valueJson;
}
\ No newline at end of file
@ApiModelProperty(notes = "引用的变量编码")
private String variableRefCode;
}
......@@ -8,15 +8,18 @@ import java.util.List;
@Data
public class SopConditionGroupDTO {
@ApiModelProperty(value = "组合ID")
private Integer groupId;
@ApiModelProperty(notes = "组合ID")
private Integer id;
@ApiModelProperty(value = "组合编号")
private Integer groupNo;
@ApiModelProperty(notes = "组合名称")
private String groupName;
@ApiModelProperty(value = "组合逻辑:1-AND(所有条件都满足) 2-OR(任一条件满足)")
@ApiModelProperty(notes = "组合编号")
private Integer groupSeq;
@ApiModelProperty(notes = "组合逻辑:1-AND(所有条件都满足) 2-OR(任一条件满足)")
private Integer groupLogic;
@ApiModelProperty(value = "条件列表")
@ApiModelProperty(notes = "条件列表")
private List<SopConditionDTO> conditions;
}
\ No newline at end of file
package cn.com.glsx.dj.strategy.dto.sop;
import io.swagger.annotations.ApiModelProperty;
import java.math.BigDecimal;
import java.util.Date;
import lombok.Data;
@Data
......@@ -12,30 +14,30 @@ public class SopConditionReqDTO {
@ApiModelProperty(value = "变量编码")
private String variableCode;
@ApiModelProperty(value = "变量类型")
private Integer variableType;
@ApiModelProperty(value = "变量名称")
private Integer variableName;
@ApiModelProperty(value = "操作符类型")
private Integer operatorType;
private Integer operator;
@ApiModelProperty(value = "值来源类型")
private Integer valueSourceType;
@ApiModelProperty(value = "值类型:1-文本 2-数值 3-日期 4-枚举")
private Integer valueType;
@ApiModelProperty(value = "文本值")
private String valueText;
private String textValue;
@ApiModelProperty(value = "数值")
private java.math.BigDecimal valueNumber;
private BigDecimal numberValue;
@ApiModelProperty(value = "日期值")
private java.sql.Date valueDate;
private Date dateValue;
@ApiModelProperty(value = "日期时间值")
private java.sql.Timestamp valueDatetime;
@ApiModelProperty(value = "枚举值(值类型为4时使用,多个值用逗号分隔)")
private String enumValue;
@ApiModelProperty(value = "枚举值编码")
private String valueEnumCode;
@ApiModelProperty(value = "值来源:0-固定值 1-变量引用")
private Integer valueSource;
@ApiModelProperty(value = "JSON值")
private String valueJson;
@ApiModelProperty(value = "引用的变量编码")
private String variableRefCode;
}
\ No newline at end of file
......@@ -11,36 +11,39 @@ import java.util.List;
@Data
public class SopConditionVariableDTO {
@ApiModelProperty(value = "变量编码")
@ApiModelProperty(notes = "变量编码")
private String variableCode;
@ApiModelProperty(value = "变量名称")
@ApiModelProperty(notes = "变量名称")
private String variableName;
@ApiModelProperty(value = "变量类型:1-日期 2-数值 3-文本 4-枚举")
@ApiModelProperty(notes = "变量类型:1-文本 2-数值 3-日期 4-枚举")
private Integer variableType;
@ApiModelProperty(value = "第二步是否可用:1-可用 0-不可用")
@ApiModelProperty(notes = "第二步是否可用:1-可用 0-不可用")
private Integer step2Available;
@ApiModelProperty(value = "第三步是否可用:1-可用 0-不可用")
@ApiModelProperty(notes = "第三步是否可用:1-可用 0-不可用")
private Integer step3Available;
@ApiModelProperty(value = "取值逻辑描述")
@ApiModelProperty(notes = "取值逻辑描述")
private String valueLogic;
@ApiModelProperty(value = "SQL片段")
@ApiModelProperty(notes = "SQL片段")
private String sqlFragment;
@ApiModelProperty(value = "枚举数据来源")
@ApiModelProperty(notes = "枚举数据来源")
private String enumDataSource;
@ApiModelProperty(value = "排序号")
@ApiModelProperty(notes = "排序号")
private Integer sortOrder;
@ApiModelProperty(value = "枚举值列表")
@ApiModelProperty(notes = "枚举值列表")
private List<SopEnumValueDTO> enumValues;
@ApiModelProperty(value = "可用操作符列表")
@ApiModelProperty(notes = "可用操作符列表")
private List<SopStrategyMetaDTO.SopMetaItemDTO> operators;
@ApiModelProperty(notes = "可选的变量列表")
private List<SopConditionVariableDTO> sopConditionVariableDTOList;
}
\ No newline at end of file
......@@ -9,15 +9,15 @@ import lombok.Data;
@Data
public class SopEnumValueDTO {
@ApiModelProperty(value = "枚举编码")
@ApiModelProperty(notes = "枚举编码")
private String enumCode;
@ApiModelProperty(value = "枚举名称")
@ApiModelProperty(notes = "枚举名称")
private String enumName;
@ApiModelProperty(value = "枚举值")
@ApiModelProperty(notes = "枚举值")
private String enumValue;
@ApiModelProperty(value = "排序号")
@ApiModelProperty(notes = "排序号")
private Integer sortOrder;
}
\ No newline at end of file
package cn.com.glsx.dj.strategy.dto.sop;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
@Data
public class SopStageDTO {
@ApiModelProperty(notes = "阶段编码")
private String stageCode;
@ApiModelProperty(notes = "阶段名称")
private String stageName;
@ApiModelProperty(notes = "阶段描述")
private String stageDesc;
@ApiModelProperty(notes = "客户查询SQL模板")
private String querySql;
@ApiModelProperty(notes = "排序序号")
private Integer sortOrder;
}
\ No newline at end of file
package cn.com.glsx.dj.strategy.dto.sop;
import cn.com.glsx.dj.strategy.dto.MerchantInfo;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
......@@ -11,7 +12,7 @@ public class SopStrategyCreateReqDTO {
@ApiModelProperty(value = "策略名称")
private String strategyName;
@ApiModelProperty(value = "业务类型:1-试驾 2-售后 3-续保 4-金融")
@ApiModelProperty(value = "业务类型:1-轻改")
private Integer bizType;
@ApiModelProperty(value = "门店范围类型:1-指定门店 2-全部门店")
......@@ -23,13 +24,10 @@ public class SopStrategyCreateReqDTO {
@ApiModelProperty(value = "触发类型:关联sop_strategy_meta_trigger.trigger_code")
private String triggerType;
@ApiModelProperty(value = "客户行为类型(事件触发时使用)")
private Integer customerBehaviorType;
@ApiModelProperty(value = "日期变量类型:关联sop_strategy_meta_date_variable.date_code")
private String dateVariableType;
@ApiModelProperty(value = "相对日期类型:1-购车日 2-生日 3-保养日")
@ApiModelProperty(notes = "相对日期类型(0提前/1当前/2推后)")
private Integer relativeDateType;
@ApiModelProperty(value = "相对天数(相对日期类型时使用)")
......@@ -45,7 +43,7 @@ public class SopStrategyCreateReqDTO {
private Integer actionConfirmType;
@ApiModelProperty(value = "门店ID列表")
private List<Long> storeIds;
private List<MerchantInfo> storeIds;
@ApiModelProperty(value = "第二步条件规则列表(规则条件)")
private List<SopConditionGroupReqDTO> step2ConditionGroups;
......@@ -56,6 +54,4 @@ public class SopStrategyCreateReqDTO {
@ApiModelProperty(value = "创建人")
private String createdBy;
@ApiModelProperty(value = "创建人UUID")
private String createdUUid;
}
\ No newline at end of file
......@@ -10,72 +10,75 @@ import java.util.List;
@Data
public class SopStrategyDetailDTO {
@ApiModelProperty(value = "策略ID")
@ApiModelProperty(notes = "策略ID")
private Integer strategyId;
@ApiModelProperty(value = "策略编码")
@ApiModelProperty(notes = "策略编码")
private String strategyCode;
@ApiModelProperty(value = "策略名称")
@ApiModelProperty(notes = "策略名称")
private String strategyName;
@ApiModelProperty(value = "业务类型:1-试驾 2-售后 3-续保 4-金融")
@ApiModelProperty(notes = "业务类型:1-试驾 2-售后 3-续保 4-金融")
private Integer bizType;
@ApiModelProperty(value = "门店范围类型:1-指定门店 2-全部门店")
@ApiModelProperty(notes = "门店范围类型:1-指定门店 2-全部门店")
private Integer storeScopeType;
@ApiModelProperty(value = "营销阶段:关联sop_strategy_meta_marketing_stage.stage_code")
@ApiModelProperty(notes = "营销阶段:关联sop_strategy_meta_marketing_stage.stage_code")
private String marketingStage;
@ApiModelProperty(value = "触发类型:关联sop_strategy_meta_trigger.trigger_code")
@ApiModelProperty(notes = "触发类型:关联sop_strategy_meta_trigger.trigger_code")
private String triggerType;
@ApiModelProperty(value = "客户行为类型(事件触发时使用)")
@ApiModelProperty(notes = "客户行为类型(事件触发时使用)")
private Integer customerBehaviorType;
@ApiModelProperty(value = "日期变量类型:关联sop_strategy_meta_date_variable.date_code")
@ApiModelProperty(notes = "日期变量类型:关联sop_strategy_meta_date_variable.date_code")
private String dateVariableType;
@ApiModelProperty(value = "相对日期类型:1-购车日 2-生日 3-保养日")
@ApiModelProperty(notes = "相对日期类型:0-提前 1-当前 2-推后")
private Integer relativeDateType;
@ApiModelProperty(value = "相对天数(相对日期类型时使用)")
@ApiModelProperty(notes = "相对天数(相对日期类型时使用)")
private Integer relativeDays;
@ApiModelProperty(value = "触发小时")
@ApiModelProperty(notes = "触发小时")
private Integer triggerHour;
@ApiModelProperty(value = "触发分钟")
@ApiModelProperty(notes = "触发分钟")
private Integer triggerMinute;
@ApiModelProperty(value = "动作确认类型:1-自动执行 2-需确认")
@ApiModelProperty(notes = "动作确认类型:1-自动执行 2-需确认")
private Integer actionConfirmType;
@ApiModelProperty(value = "状态:0-禁用 1-启用")
@ApiModelProperty(notes = "状态:0-禁用 1-启用")
private Integer status;
@ApiModelProperty(value = "版本号")
@ApiModelProperty(notes = "版本号")
private Integer version;
@ApiModelProperty(value = "门店列表")
@ApiModelProperty(notes = "门店列表")
private List<SopStrategyStoreDTO> stores;
@ApiModelProperty(value = "第二步条件规则列表(规则条件)")
@ApiModelProperty(notes = "第二步条件规则列表(规则条件)")
private List<SopConditionGroupDTO> step2ConditionGroups;
@ApiModelProperty(value = "分支列表")
@ApiModelProperty(notes = "分支列表")
private List<SopBranchDTO> branches;
@ApiModelProperty(value = "分支列表")
@ApiModelProperty(notes = "分支列表(原始实体)")
private List<SopStrategyBranch> branchList;
@ApiModelProperty(value = "创建人")
@ApiModelProperty(notes = "创建人")
private String createdBy;
@ApiModelProperty(value = "创建时间")
@ApiModelProperty(notes = "创建人UUID")
private String createdUUid;
@ApiModelProperty(notes = "创建时间")
private Date createdTime;
@ApiModelProperty(value = "更新时间")
@ApiModelProperty(notes = "更新时间")
private Date updatedTime;
}
\ No newline at end of file
......@@ -9,45 +9,45 @@ import java.util.List;
@Data
public class SopStrategyListDTO {
@ApiModelProperty(value = "策略ID")
@ApiModelProperty(notes = "策略ID")
private Long strategyId;
@ApiModelProperty(value = "策略编码")
@ApiModelProperty(notes = "策略编码")
private String strategyCode;
@ApiModelProperty(value = "策略名称")
@ApiModelProperty(notes = "策略名称")
private String strategyName;
@ApiModelProperty(value = "业务类型:1-试驾 2-售后 3-续保 4-金融")
@ApiModelProperty(notes = "业务类型:1-试驾 2-售后 3-续保 4-金融")
private Integer bizType;
@ApiModelProperty(value = "门店范围类型:1-指定门店 2-全部门店")
@ApiModelProperty(notes = "门店范围类型:1-指定门店 2-全部门店")
private Integer storeScopeType;
@ApiModelProperty(value = "营销阶段:关联sop_strategy_meta_marketing_stage.stage_code")
@ApiModelProperty(notes = "营销阶段:关联sop_strategy_meta_marketing_stage.stage_code")
private String marketingStage;
@ApiModelProperty(value = "触发类型:关联sop_strategy_meta_trigger.trigger_code")
@ApiModelProperty(notes = "触发类型:关联sop_strategy_meta_trigger.trigger_code")
private String triggerType;
@ApiModelProperty(value = "动作确认类型:1-自动执行 2-需确认")
@ApiModelProperty(notes = "动作确认类型:1-自动执行 2-需确认")
private Integer actionConfirmType;
@ApiModelProperty(value = "状态:0-禁用 1-启用")
@ApiModelProperty(notes = "状态:0-禁用 1-启用")
private Integer status;
@ApiModelProperty(value = "版本号")
@ApiModelProperty(notes = "版本号")
private Integer version;
@ApiModelProperty(value = "门店列表")
@ApiModelProperty(notes = "门店列表")
private List<SopStrategyStoreDTO> stores;
@ApiModelProperty(value = "创建人")
@ApiModelProperty(notes = "创建人")
private String createdBy;
@ApiModelProperty(value = "创建时间")
@ApiModelProperty(notes = "创建时间")
private Date createdTime;
@ApiModelProperty(value = "更新时间")
@ApiModelProperty(notes = "更新时间")
private Date updatedTime;
}
\ No newline at end of file
......@@ -11,31 +11,31 @@ import java.util.List;
@Data
public class SopStrategyMetaDTO {
@ApiModelProperty(value = "营销阶段列表")
@ApiModelProperty(notes = "营销阶段列表")
private List<SopStageDTO> stages;
@ApiModelProperty(value = "条件变量列表(所有步骤可用)")
@ApiModelProperty(notes = "条件变量列表(所有步骤可用)")
private List<SopConditionVariableDTO> conditionVariables;
@ApiModelProperty(value = "第二步可用条件变量列表")
@ApiModelProperty(notes = "第二步可用条件变量列表")
private List<SopConditionVariableDTO> step2ConditionVariables;
@ApiModelProperty(value = "操作符列表")
@ApiModelProperty(notes = "操作符列表")
private List<SopMetaItemDTO> operators;
@ApiModelProperty(value = "触发类型列表")
@ApiModelProperty(notes = "触发类型列表")
private List<SopMetaItemDTO> triggers;
@ApiModelProperty(value = "客户行为列表")
@ApiModelProperty(notes = "客户行为列表")
private List<SopMetaItemDTO> customerBehaviors;
@ApiModelProperty(value = "日期变量列表")
@ApiModelProperty(notes = "日期变量列表")
private List<SopMetaItemDTO> dateVariables;
@ApiModelProperty(value = "相对日期类型列表")
@ApiModelProperty(notes = "相对日期类型列表")
private List<SopMetaItemDTO> relativeDateTypes;
@ApiModelProperty(value = "消息变量列表")
@ApiModelProperty(notes = "消息变量列表")
private List<SopMetaItemDTO> messageVariables;
/**
......@@ -44,16 +44,16 @@ public class SopStrategyMetaDTO {
@Data
public static class SopMetaItemDTO {
@ApiModelProperty(value = "编码")
@ApiModelProperty(notes = "编码")
private String code;
@ApiModelProperty(value = "名称")
@ApiModelProperty(notes = "名称")
private String name;
@ApiModelProperty(value = "类型")
@ApiModelProperty(notes = "类型")
private Integer type;
@ApiModelProperty(value = "描述")
@ApiModelProperty(notes = "描述")
private String description;
}
}
\ No newline at end of file
......@@ -8,42 +8,42 @@ import java.util.Date;
@Data
public class SopStrategyRecordDTO {
@ApiModelProperty(value = "执行记录ID")
@ApiModelProperty(notes = "执行记录ID")
private Long recordId;
@ApiModelProperty(value = "任务ID")
@ApiModelProperty(notes = "任务ID")
private Long taskId;
@ApiModelProperty(value = "策略ID")
@ApiModelProperty(notes = "策略ID")
private Long strategyId;
@ApiModelProperty(value = "策略版本")
@ApiModelProperty(notes = "策略版本")
private Integer strategyVersion;
@ApiModelProperty(value = "客户实例ID")
@ApiModelProperty(notes = "客户实例ID")
private Long customerInstanceId;
@ApiModelProperty(value = "客户姓名")
@ApiModelProperty(notes = "客户姓名")
private String customerName;
@ApiModelProperty(value = "客户手机号")
@ApiModelProperty(notes = "客户手机号")
private String customerPhone;
@ApiModelProperty(value = "门店ID")
@ApiModelProperty(notes = "门店ID")
private Long storeId;
@ApiModelProperty(value = "触发时间")
@ApiModelProperty(notes = "触发时间")
private Date triggerTime;
@ApiModelProperty(value = "执行时间")
@ApiModelProperty(notes = "执行时间")
private Date executeTime;
@ApiModelProperty(value = "执行结果:0-待执行 1-成功 2-失败")
@ApiModelProperty(notes = "执行结果:0-待执行 1-成功 2-失败")
private Integer executeResult;
@ApiModelProperty(value = "错误码")
@ApiModelProperty(notes = "错误码")
private String errorCode;
@ApiModelProperty(value = "错误信息")
@ApiModelProperty(notes = "错误信息")
private String errorMessage;
}
\ No newline at end of file
package cn.com.glsx.dj.strategy.dto.sop;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.Date;
......@@ -7,57 +8,84 @@ import java.util.Date;
@Data
public class SopStrategyRecordDetailDTO {
@ApiModelProperty(notes = "执行记录ID")
private Integer recordId;
@ApiModelProperty(notes = "任务ID")
private Long taskId;
@ApiModelProperty(notes = "策略ID")
private Long strategyId;
@ApiModelProperty(notes = "策略版本号")
private Integer strategyVersion;
@ApiModelProperty(notes = "客户实例ID")
private Long customerInstanceId;
@ApiModelProperty(notes = "客户姓名")
private String customerName;
@ApiModelProperty(notes = "客户手机号")
private String customerPhone;
@ApiModelProperty(notes = "门店ID")
private Long storeId;
@ApiModelProperty(notes = "触发时间")
private Date triggerTime;
@ApiModelProperty(notes = "执行时间")
private Date executeTime;
@ApiModelProperty(notes = "执行结果:0-失败 1-成功")
private Integer executeResult;
@ApiModelProperty(notes = "错误码")
private String errorCode;
@ApiModelProperty(notes = "错误信息")
private String errorMessage;
@ApiModelProperty(notes = "策略快照JSON")
private String strategySnapshotJson;
@ApiModelProperty(notes = "触发快照JSON")
private String triggerSnapshotJson;
@ApiModelProperty(notes = "动作快照JSON")
private String actionSnapshotJson;
@ApiModelProperty(notes = "客户快照JSON")
private String customerSnapshotJson;
@ApiModelProperty(notes = "客户快照-客户姓名")
private String customerNameSnapshot;
@ApiModelProperty(notes = "客户快照-客户手机号")
private String customerPhoneSnapshot;
@ApiModelProperty(notes = "客户快照-门店ID")
private Long storeIdSnapshot;
@ApiModelProperty(notes = "客户快照-门店名称")
private String storeNameSnapshot;
@ApiModelProperty(notes = "客户快照-大定日期")
private Date depositDateSnapshot;
@ApiModelProperty(notes = "客户快照-交付日期")
private Date deliveryDateSnapshot;
@ApiModelProperty(notes = "客户快照-新车品牌")
private String carBrandSnapshot;
@ApiModelProperty(notes = "客户快照-新车车系")
private String carSeriesSnapshot;
@ApiModelProperty(notes = "客户快照-新车车系等级")
private String carSeriesLevelSnapshot;
@ApiModelProperty(notes = "客户快照-客户分类")
private String customerCategorySnapshot;
}
\ No newline at end of file
package cn.com.glsx.dj.strategy.dto.sop;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
@Data
public class SopStrategyStoreDTO {
@ApiModelProperty(notes = "门店ID")
private Long storeId;
@ApiModelProperty(notes = "门店名称")
private String storeName;
@ApiModelProperty(notes = "门店编码")
private String storeCode;
}
\ No newline at end of file
package cn.com.glsx.dj.strategy.dto.sop;
import cn.com.glsx.dj.strategy.dto.MerchantInfo;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
......@@ -14,7 +15,7 @@ public class SopStrategyUpdateReqDTO {
@ApiModelProperty(value = "策略名称")
private String strategyName;
@ApiModelProperty(value = "业务类型:1-试驾 2-售后 3-续保 4-金融")
@ApiModelProperty(value = "业务类型:1-轻改")
private Integer bizType;
@ApiModelProperty(value = "门店范围类型:1-指定门店 2-全部门店")
......@@ -26,13 +27,10 @@ public class SopStrategyUpdateReqDTO {
@ApiModelProperty(value = "触发类型:关联sop_strategy_meta_trigger.trigger_code")
private String triggerType;
@ApiModelProperty(value = "客户行为类型(事件触发时使用)")
private Integer customerBehaviorType;
@ApiModelProperty(value = "日期变量类型:关联sop_strategy_meta_date_variable.date_code")
private String dateVariableType;
@ApiModelProperty(value = "相对日期类型:1-购车日 2-生日 3-保养日")
@ApiModelProperty(notes = "相对日期类型(0提前/1当前/2推后)")
private Integer relativeDateType;
@ApiModelProperty(value = "相对天数(相对日期类型时使用)")
......@@ -48,7 +46,7 @@ public class SopStrategyUpdateReqDTO {
private Integer actionConfirmType;
@ApiModelProperty(value = "门店ID列表")
private List<Long> storeIds;
private List<MerchantInfo> storeIds;
@ApiModelProperty(value = "第二步条件规则列表(规则条件)")
private List<SopConditionGroupReqDTO> step2ConditionGroups;
......
......@@ -121,6 +121,7 @@ public class SopStrategy implements Serializable {
@Column(name = "created_by")
private String createdBy;
/**
* 创建时间
*/
......
......@@ -82,6 +82,24 @@ public class SopStrategyAction implements Serializable {
private String jumpUrl;
/**
* 网页背景色(消息类型为4时使用)
*/
@Column(name = "bg_color", length = 50)
private String bgColor;
/**
* 素材配置JSON(消息类型为4时使用)
*/
@Column(name = "material_json", columnDefinition = "text")
private String materialJson;
/**
* 素材间隔(像素)(消息类型为4时使用)
*/
@Column(name = "interval_px")
private Integer intervalPx;
/**
* 延迟执行秒数
*/
@Column(name = "delay_seconds")
......
package cn.com.glsx.dj.strategy.mapper.sop;
import cn.com.glsx.dj.strategy.model.sop.SopStrategyMetaMessageVariable;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.oreframework.datasource.mybatis.mapper.OreMapper;
import java.util.List;
@Mapper
public interface SopStrategyMetaMessageVariableMapper extends OreMapper<SopStrategyMetaMessageVariable> {
List<SopStrategyMetaMessageVariable> selectByStatus(@Param("status") Integer status);
SopStrategyMetaMessageVariable selectByVariableCode(@Param("variableCode") String variableCode);
}
\ No newline at end of file
package cn.com.glsx.dj.strategy.service;
import cn.com.glsx.dj.strategy.mapper.sop.SopStrategyMetaMessageVariableMapper;
import cn.com.glsx.dj.strategy.model.sop.SopStrategyCustomerSnapshot;
import cn.com.glsx.dj.strategy.model.sop.SopStrategyMetaMessageVariable;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.StrUtil;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import java.util.*;
@Slf4j
@Service
@RequiredArgsConstructor
public class SopMessageVariableResolverService {
private final SopStrategyMetaMessageVariableMapper metaMessageVariableMapper;
private final JdbcTemplate jdbcTemplate;
public static final String DATA_SOURCE_SNAPSHOT = "SNAPSHOT";
public static final String DATA_SOURCE_SQL = "SQL";
public Map<String, Object> resolveVariables(Long customerInstanceId, Integer taskId, Map<String, Object> context) {
Map<String, Object> result = new HashMap<>();
List<SopStrategyMetaMessageVariable> variables = metaMessageVariableMapper.selectByStatus(1);
if (variables.isEmpty()) {
log.warn("未配置任何消息变量");
return result;
}
SopStrategyCustomerSnapshot snapshot = getCustomerSnapshot(taskId, customerInstanceId);
for (SopStrategyMetaMessageVariable variable : variables) {
String variableCode = variable.getVariableCode();
try {
Object value = resolveVariable(variable, snapshot, context);
if (value != null) {
result.put(variableCode, value);
} else if (StrUtil.isNotBlank(variable.getDefaultValue())) {
result.put(variableCode, variable.getDefaultValue());
}
} catch (Exception e) {
log.error("解析消息变量失败, variableCode:{}, error:{}", variableCode, e.getMessage(), e);
if (StrUtil.isNotBlank(variable.getDefaultValue())) {
result.put(variableCode, variable.getDefaultValue());
}
}
}
if (context != null) {
result.putAll(context);
}
return result;
}
private Object resolveVariable(SopStrategyMetaMessageVariable variable,
SopStrategyCustomerSnapshot snapshot, Map<String, Object> context) {
String dataSource = variable.getDataSource();
if (DATA_SOURCE_SNAPSHOT.equals(dataSource)) {
return resolveFromSnapshot(variable, snapshot, context);
} else if (DATA_SOURCE_SQL.equals(dataSource)) {
return resolveFromSql(variable, context);
} else {
log.warn("未知数据来源, dataSource:{}, variableCode:{}", dataSource, variable.getVariableCode());
return null;
}
}
private Object resolveFromSnapshot(SopStrategyMetaMessageVariable variable,
SopStrategyCustomerSnapshot snapshot, Map<String, Object> context) {
String snapshotField = variable.getSnapshotField();
if (StrUtil.isBlank(snapshotField)) {
log.warn("快照字段未配置, variableCode:{}", variable.getVariableCode());
return null;
}
Object value;
if (snapshot != null) {
value = BeanUtil.getFieldValue(snapshot, snapshotField);
} else {
value = null;
}
if (value == null && context != null) {
value = context.get(snapshotField);
}
if (value == null) {
return null;
}
return formatValue(value, variable);
}
private Object resolveFromSql(SopStrategyMetaMessageVariable variable, Map<String, Object> context) {
String sqlQuery = variable.getSqlQuery();
if (StrUtil.isBlank(sqlQuery)) {
log.warn("SQL查询语句未配置, variableCode:{}", variable.getVariableCode());
return null;
}
String resolvedSql = sqlQuery;
if (context != null) {
for (Map.Entry<String, Object> entry : context.entrySet()) {
String placeholder = "${" + entry.getKey() + "}";
resolvedSql = resolvedSql.replace(placeholder, String.valueOf(entry.getValue()));
}
}
try {
List<Map<String, Object>> results = jdbcTemplate.queryForList(resolvedSql);
if (results == null || results.isEmpty()) {
log.debug("SQL查询无结果, variableCode:{}, sql:{}", variable.getVariableCode(), resolvedSql);
return null;
}
Map<String, Object> firstRow = results.get(0);
Object value = firstRow.values().iterator().next();
return formatValue(value, variable);
} catch (Exception e) {
log.error("SQL查询失败, variableCode:{}, sql:{}, error:{}",
variable.getVariableCode(), resolvedSql, e.getMessage(), e);
return null;
}
}
private Object formatValue(Object value, SopStrategyMetaMessageVariable variable) {
if (value == null) {
return null;
}
String dateFormat = variable.getDateFormat();
String valueType = variable.getValueType();
if (value instanceof Date) {
if (StrUtil.isNotBlank(dateFormat)) {
return DateUtil.format((Date) value, dateFormat);
}
return DateUtil.format((Date) value, "yyyy-MM-dd");
}
if (value instanceof java.sql.Date) {
if (StrUtil.isNotBlank(dateFormat)) {
return DateUtil.format(new Date(((java.sql.Date) value).getTime()), dateFormat);
}
return DateUtil.format(new Date(((java.sql.Date) value).getTime()), "yyyy-MM-dd");
}
if ("NUMBER".equals(valueType)) {
try {
return String.valueOf(value);
} catch (Exception e) {
return value;
}
}
if ("DATE".equals(valueType)) {
try {
Date date = DateUtil.parse(String.valueOf(value));
if (StrUtil.isNotBlank(dateFormat)) {
return DateUtil.format(date, dateFormat);
}
return DateUtil.format(date, "yyyy-MM-dd");
} catch (Exception e) {
return value;
}
}
return String.valueOf(value);
}
private SopStrategyCustomerSnapshot getCustomerSnapshot(Integer taskId, Long customerInstanceId) {
if (taskId == null || customerInstanceId == null) {
return null;
}
try {
String sql = "SELECT * FROM sop_strategy_customer_snapshot " +
"WHERE task_id = ? AND customer_instance_id = ? AND deleted_flag = 'N'";
List<SopStrategyCustomerSnapshot> snapshots = jdbcTemplate.query(sql,
new Object[]{taskId, customerInstanceId},
(rs, rowNum) -> {
SopStrategyCustomerSnapshot snapshot = new SopStrategyCustomerSnapshot();
snapshot.setId(rs.getInt("id"));
snapshot.setStrategyId(rs.getInt("strategy_id"));
snapshot.setTaskId(rs.getInt("task_id"));
snapshot.setCustomerInstanceId(rs.getLong("customer_instance_id"));
snapshot.setCustomerName(rs.getString("customer_name"));
snapshot.setCustomerPhone(rs.getString("customer_phone"));
snapshot.setStoreId(rs.getLong("store_id"));
snapshot.setStoreCode(rs.getString("store_code"));
snapshot.setStoreName(rs.getString("store_name"));
snapshot.setStaffUuid(rs.getString("staff_uuid"));
snapshot.setStaffName(rs.getString("staff_name"));
snapshot.setDepositDate(rs.getDate("deposit_date"));
snapshot.setDeliveryDate(rs.getDate("delivery_date"));
snapshot.setCustomerCategory(rs.getString("customer_category"));
snapshot.setCarBrand(rs.getString("car_brand"));
snapshot.setCarSeries(rs.getString("car_series"));
snapshot.setCarSeriesLevel(rs.getString("car_series_level"));
snapshot.setGroupId(rs.getString("group_id"));
snapshot.setSnapshotData(rs.getString("snapshot_data"));
snapshot.setSnapshotTime(rs.getDate("snapshot_time"));
snapshot.setDeletedFlag(rs.getString("deleted_flag"));
return snapshot;
});
return snapshots.isEmpty() ? null : snapshots.get(0);
} catch (Exception e) {
log.error("查询客户快照失败, taskId:{}, customerInstanceId:{}, error:{}",
taskId, customerInstanceId, e.getMessage(), e);
return null;
}
}
public List<SopStrategyMetaMessageVariable> getAllMessageVariables() {
return metaMessageVariableMapper.selectByStatus(1);
}
}
\ No newline at end of file
......@@ -61,6 +61,9 @@ public class SopStrategyExecutionService {
@Autowired
private SopCustomerSnapshotService sopCustomerSnapshotService;
@Autowired
private SopMessageVariableResolverService sopMessageVariableResolverService;
private static final Integer STEP_3 = 3;
private static final String DESC_SUCCESS = "执行成功";
private static final String DESC_TIMEOUT = "超时未确认";
......@@ -222,6 +225,13 @@ public class SopStrategyExecutionService {
log.info("未找到快照数据, 使用任务基础变量, taskId:{}", task.getId());
}
Map<String, Object> messageVariables = sopMessageVariableResolverService.resolveVariables(
task.getCustomerInstanceId(), task.getId(), variables);
if (!messageVariables.isEmpty()) {
log.info("解析消息变量成功, taskId:{}, variableCount:{}", task.getId(), messageVariables.size());
variables.putAll(messageVariables);
}
return variables;
}
......
......@@ -14,6 +14,7 @@ import cn.com.glsx.dj.strategy.mapper.sop.SopStrategyMapper;
import cn.com.glsx.dj.strategy.mapper.sop.SopStrategyMetaConditionVariableMapper;
import cn.com.glsx.dj.strategy.mapper.sop.SopStrategyMetaEnumValueMapper;
import cn.com.glsx.dj.strategy.mapper.sop.SopStrategyMetaMarketingStageMapper;
import cn.com.glsx.dj.strategy.mapper.sop.SopStrategyMetaMessageVariableMapper;
import cn.com.glsx.dj.strategy.mapper.sop.SopStrategyMetaTriggerMapper;
import cn.com.glsx.dj.strategy.mapper.sop.SopStrategyStoreRelMapper;
import cn.com.glsx.dj.strategy.model.sop.*;
......@@ -54,6 +55,7 @@ public class StrategySopQueryService {
private final SopStrategyMetaConditionVariableMapper metaConditionVariableMapper;
private final SopStrategyMetaEnumValueMapper metaEnumValueMapper;
private final SopStrategyMetaTriggerMapper metaTriggerMapper;
private final SopStrategyMetaMessageVariableMapper metaMessageVariableMapper;
private final SopEnumDataSourceService sopEnumDataSourceService;
/**
......@@ -92,6 +94,8 @@ public class StrategySopQueryService {
private SopStrategyDetailDTO convertToDetailDTO(SopStrategy strategy) {
SopStrategyDetailDTO dto = BeanUtil.copyProperties(strategy, SopStrategyDetailDTO.class);
dto.setStrategyId(strategy.getId());
dto.setCreatedTime(strategy.getCreatedDate());
dto.setUpdatedTime(strategy.getUpdatedDate());
List<SopStrategyStoreRel> storeRels = sopStrategyStoreRelMapper.selectByStrategyId(strategy.getId());
dto.setStores(storeRels.stream()
......@@ -119,7 +123,6 @@ public class StrategySopQueryService {
*/
private SopBranchDTO convertToBranchDTO(SopStrategyBranch branch) {
SopBranchDTO dto = BeanUtil.copyProperties(branch, SopBranchDTO.class);
dto.setBranchId(branch.getId());
List<SopStrategyConditionGroup> conditionGroups = sopStrategyConditionGroupMapper.selectByBranchId(branch.getId());
dto.setConditionGroups(conditionGroups.stream()
......@@ -142,7 +145,6 @@ public class StrategySopQueryService {
*/
private SopConditionGroupDTO convertToConditionGroupDTO(SopStrategyConditionGroup group) {
SopConditionGroupDTO dto = BeanUtil.copyProperties(group, SopConditionGroupDTO.class);
dto.setGroupId(group.getId());
List<SopStrategyCondition> conditions = sopStrategyConditionMapper.selectByGroupId(group.getId());
dto.setConditions(conditions.stream()
......@@ -160,7 +162,6 @@ public class StrategySopQueryService {
*/
private SopActionDTO convertToActionDTO(SopStrategyAction action) {
SopActionDTO dto = BeanUtil.copyProperties(action, SopActionDTO.class);
dto.setActionId(action.getId());
List<SopStrategyActionMedia> medias = sopStrategyActionMediaMapper.selectByActionId(action.getId());
dto.setMedias(medias.stream()
......@@ -180,6 +181,20 @@ public class StrategySopQueryService {
meta.setStages(buildStages());
List<SopConditionVariableDTO> allConditionVariables = buildConditionVariables();
// 设置日期变量
List<SopConditionVariableDTO> collect = allConditionVariables.stream()
.filter(index -> index.getVariableType() == 1).map(index -> {
SopConditionVariableDTO variable = new SopConditionVariableDTO();
variable.setVariableCode(index.getVariableCode());
variable.setVariableName(index.getVariableName());
return variable;
}).collect(Collectors.toList());
for (SopConditionVariableDTO allConditionVariable : allConditionVariables) {
allConditionVariable.setSopConditionVariableDTOList(collect);
}
meta.setConditionVariables(allConditionVariables);
meta.setStep2ConditionVariables(filterStep2ConditionVariables(allConditionVariables));
meta.setTriggers(buildTriggers());
......@@ -397,21 +412,39 @@ public class StrategySopQueryService {
}
/**
* 构建消息变量列表
* 构建消息变量列表(从数据库配置获取)
*
* @return 消息变量元数据项列表
*/
private List<SopStrategyMetaDTO.SopMetaItemDTO> buildMessageVariables() {
List<SopStrategyMetaDTO.SopMetaItemDTO> items = new ArrayList<>();
items.add(createMetaItem("customerName", "客户姓名", 1, "消息中显示的客户姓名"));
items.add(createMetaItem("customerPhone", "客户手机号", 1, "消息中显示的客户手机号"));
items.add(createMetaItem("storeName", "门店名称", 1, "消息中显示的门店名称"));
items.add(createMetaItem("strategyName", "策略名称", 1, "消息中显示的策略名称"));
List<SopStrategyMetaMessageVariable> variables = metaMessageVariableMapper.selectByStatus(1);
if (CollUtil.isEmpty(variables)) {
items.add(createMetaItem("customerName", "客户姓名", 1, "消息中显示的客户姓名"));
items.add(createMetaItem("customerPhone", "客户手机号", 1, "消息中显示的客户手机号"));
items.add(createMetaItem("storeName", "门店名称", 1, "消息中显示的门店名称"));
items.add(createMetaItem("strategyName", "策略名称", 1, "消息中显示的策略名称"));
return items;
}
for (SopStrategyMetaMessageVariable variable : variables) {
items.add(createMetaItem(variable.getVariableCode(), variable.getVariableName(),
getValueType(variable.getValueType()), variable.getVariableName()));
}
return items;
}
private Integer getValueType(String valueType) {
if ("DATE".equals(valueType)) {
return 2;
} else if ("NUMBER".equals(valueType)) {
return 3;
}
return 1;
}
/**
* 创建元数据项DTO
*
......
package cn.com.glsx.dj.strategy.service;
import cn.com.glsx.dj.strategy.dto.MerchantInfo;
import cn.com.glsx.dj.strategy.dto.sop.*;
import cn.com.glsx.dj.strategy.enums.SopStrategyStatusEnum;
import cn.com.glsx.dj.strategy.exception.SopStrategyException;
......@@ -173,16 +174,16 @@ public class StrategySopService {
return "SOP" + System.currentTimeMillis() + UUID.randomUUID().toString().substring(0, 4).toUpperCase();
}
private void saveStrategyStores(Integer strategyId, List<Long> storeIds, String createdBy) {
private void saveStrategyStores(Integer strategyId, List<MerchantInfo> storeIds, String createdBy) {
if (CollUtil.isEmpty(storeIds)) {
return;
}
for (Long storeId : storeIds) {
for (MerchantInfo storeId : storeIds) {
SopStrategyStoreRel rel = new SopStrategyStoreRel();
rel.setStrategyId(strategyId);
rel.setStoreId(storeId);
rel.setStoreName("门店" + storeId);
rel.setStoreCode("STORE" + storeId);
rel.setStoreId(Long.valueOf(storeId.getMerchantId()));
rel.setStoreName("门店" + storeId.getMerchantName());
rel.setStoreCode("STORE" + storeId.getMerchantId());
rel.setDeletedFlag(DeleteFlagEnum.N.getValue());
rel.setCreatedBy(createdBy);
rel.setCreatedDate(new Date());
......@@ -200,6 +201,7 @@ public class StrategySopService {
branch.setDeletedFlag(DeleteFlagEnum.N.getValue());
branch.setCreatedBy(createdBy);
branch.setCreatedDate(new Date());
branch.setStep(3);
sopStrategyBranchMapper.insertSelective(branch);
Integer branchId = branch.getId();
......@@ -235,6 +237,7 @@ public class StrategySopService {
SopStrategyConditionGroup group = BeanUtil.copyProperties(groupReq, SopStrategyConditionGroup.class);
group.setStrategyId(strategyId);
group.setBranchId(branchId);
group.setStep(3);
group.setDeletedFlag(DeleteFlagEnum.N.getValue());
group.setCreatedBy(createdBy);
group.setCreatedDate(new Date());
......
......@@ -5,6 +5,17 @@
<resultMap id="BaseResultMap" type="cn.com.glsx.dj.strategy.model.sop.SopStrategyAction">
<id column="id" property="id"/>
<result column="branch_id" property="branchId"/>
<result column="strategy_id" property="strategyId"/>
<result column="message_type" property="messageType"/>
<result column="content" property="content"/>
<result column="media_ids" property="mediaIds"/>
<result column="jump_url" property="jumpUrl"/>
<result column="bg_color" property="bgColor"/>
<result column="material_json" property="materialJson"/>
<result column="interval_px" property="intervalPx"/>
<result column="delay_seconds" property="delaySeconds"/>
<result column="max_try_count" property="maxTryCount"/>
<result column="retry_interval_minutes" property="retryIntervalMinutes"/>
<result column="action_type" property="actionType"/>
<result column="action_name" property="actionName"/>
<result column="action_seq" property="actionSeq"/>
......@@ -19,7 +30,7 @@
<select id="selectByBranchId" resultMap="BaseResultMap">
SELECT * FROM sop_strategy_action
WHERE branch_id = #{branchId} AND deleted_flag = 'N'
ORDER BY sort_order ASC
ORDER BY action_seq ASC
</select>
<delete id="deleteByBranchId">
......
......@@ -18,7 +18,6 @@
<select id="selectByActionId" resultMap="BaseResultMap">
SELECT * FROM sop_strategy_action_media
WHERE action_id = #{actionId} AND deleted_flag = 'N'
ORDER BY sort_order ASC
</select>
<delete id="deleteByActionId">
......
......@@ -19,7 +19,7 @@
<select id="selectByBranchId" resultMap="BaseResultMap">
SELECT * FROM sop_strategy_condition_group
WHERE branch_id = #{branchId} AND deleted_flag = 'N'
ORDER BY sort_order ASC
ORDER BY group_seq ASC
</select>
<delete id="deleteByBranchId">
......@@ -30,7 +30,7 @@
<select id="selectByStrategyIdAndStep" resultMap="BaseResultMap">
SELECT * FROM sop_strategy_condition_group
WHERE strategy_id = #{strategyId} AND step = #{step} AND deleted_flag = 'N'
ORDER BY sort_order ASC
ORDER BY group_seq ASC
</select>
<delete id="deleteByStrategyIdAndStep">
......
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="cn.com.glsx.dj.strategy.mapper.sop.SopStrategyMetaConditionVariableMapper">
<resultMap id="BaseResultMap" type="cn.com.glsx.dj.strategy.model.sop.SopStrategyMetaConditionVariable">
<id column="id" property="id"/>
<result column="variable_code" property="variableCode"/>
<result column="variable_name" property="variableName"/>
<result column="variable_type" property="variableType"/>
<result column="step2_available" property="step2Available"/>
<result column="step3_available" property="step3Available"/>
<result column="value_logic" property="valueLogic"/>
<result column="sql_fragment" property="sqlFragment"/>
<result column="enum_data_source" property="enumDataSource"/>
<result column="rop_api_method" property="ropApiMethod"/>
<result column="sort_order" property="sortOrder"/>
<result column="status" property="status"/>
<result column="deleted_flag" property="deletedFlag"/>
<result column="created_by" property="createdBy"/>
<result column="created_date" property="createdDate"/>
<result column="updated_by" property="updatedBy"/>
<result column="updated_date" property="updatedDate"/>
</resultMap>
<select id="selectByStatus" resultMap="BaseResultMap">
SELECT * FROM sop_strategy_meta_condition_variable
WHERE deleted_flag = 'N'
<if test="status != null">
AND status = #{status}
</if>
ORDER BY sort_order ASC
</select>
<select id="selectByStepAvailable" resultMap="BaseResultMap">
SELECT * FROM sop_strategy_meta_condition_variable
WHERE deleted_flag = 'N' AND status = 1
<if test="step2Available != null">
AND step2_available = #{step2Available}
</if>
<if test="step3Available != null">
AND step3_available = #{step3Available}
</if>
ORDER BY sort_order ASC
</select>
</mapper>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="cn.com.glsx.dj.strategy.mapper.sop.SopStrategyMetaEnumValueMapper">
<resultMap id="BaseResultMap" type="cn.com.glsx.dj.strategy.model.sop.SopStrategyMetaEnumValue">
<id column="id" property="id"/>
<result column="variable_code" property="variableCode"/>
<result column="enum_code" property="enumCode"/>
<result column="enum_name" property="enumName"/>
<result column="enum_value" property="enumValue"/>
<result column="sort_order" property="sortOrder"/>
<result column="status" property="status"/>
<result column="deleted_flag" property="deletedFlag"/>
<result column="created_by" property="createdBy"/>
<result column="created_date" property="createdDate"/>
<result column="updated_by" property="updatedBy"/>
<result column="updated_date" property="updatedDate"/>
</resultMap>
<select id="selectByVariableCode" resultMap="BaseResultMap">
SELECT * FROM sop_strategy_meta_enum_value
WHERE variable_code = #{variableCode} AND deleted_flag = 'N'
<if test="status != null">
AND status = #{status}
</if>
ORDER BY sort_order ASC
</select>
<select id="selectByStatus" resultMap="BaseResultMap">
SELECT * FROM sop_strategy_meta_enum_value
WHERE deleted_flag = 'N'
<if test="status != null">
AND status = #{status}
</if>
ORDER BY sort_order ASC
</select>
</mapper>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="cn.com.glsx.dj.strategy.mapper.sop.SopStrategyMetaMarketingStageMapper">
<resultMap id="BaseResultMap" type="cn.com.glsx.dj.strategy.model.sop.SopStrategyMetaMarketingStage">
<id column="id" property="id"/>
<result column="stage_code" property="stageCode"/>
<result column="stage_name" property="stageName"/>
<result column="stage_desc" property="stageDesc"/>
<result column="query_sql" property="querySql"/>
<result column="single_query_sql" property="singleQuerySql"/>
<result column="sort_order" property="sortOrder"/>
<result column="status" property="status"/>
<result column="deleted_flag" property="deletedFlag"/>
<result column="created_by" property="createdBy"/>
<result column="created_date" property="createdDate"/>
<result column="updated_by" property="updatedBy"/>
<result column="updated_date" property="updatedDate"/>
</resultMap>
<select id="selectByStatus" resultMap="BaseResultMap">
SELECT * FROM sop_strategy_meta_marketing_stage
WHERE deleted_flag = 'N'
<if test="status != null">
AND status = #{status}
</if>
ORDER BY sort_order ASC
</select>
<select id="selectByStageCode" resultMap="BaseResultMap">
SELECT * FROM sop_strategy_meta_marketing_stage
WHERE stage_code = #{stageCode} AND deleted_flag = 'N'
</select>
</mapper>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="cn.com.glsx.dj.strategy.mapper.sop.SopStrategyMetaMessageVariableMapper">
<resultMap id="BaseResultMap" type="cn.com.glsx.dj.strategy.model.sop.SopStrategyMetaMessageVariable">
<id column="id" property="id"/>
<result column="variable_code" property="variableCode"/>
<result column="variable_name" property="variableName"/>
<result column="data_source" property="dataSource"/>
<result column="snapshot_field" property="snapshotField"/>
<result column="sql_query" property="sqlQuery"/>
<result column="date_format" property="dateFormat"/>
<result column="value_type" property="valueType"/>
<result column="default_value" property="defaultValue"/>
<result column="sort_order" property="sortOrder"/>
<result column="status" property="status"/>
<result column="deleted_flag" property="deletedFlag"/>
<result column="created_by" property="createdBy"/>
<result column="created_date" property="createdDate"/>
<result column="updated_by" property="updatedBy"/>
<result column="updated_date" property="updatedDate"/>
</resultMap>
<select id="selectByStatus" resultMap="BaseResultMap">
SELECT * FROM sop_strategy_meta_message_variable
WHERE deleted_flag = 'N'
<if test="status != null">
AND status = #{status}
</if>
ORDER BY sort_order ASC
</select>
<select id="selectByVariableCode" resultMap="BaseResultMap">
SELECT * FROM sop_strategy_meta_message_variable
WHERE variable_code = #{variableCode}
AND deleted_flag = 'N'
LIMIT 1
</select>
</mapper>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="cn.com.glsx.dj.strategy.mapper.sop.SopStrategyMetaTriggerMapper">
<resultMap id="BaseResultMap" type="cn.com.glsx.dj.strategy.model.sop.SopStrategyMetaTrigger">
<id column="id" property="id"/>
<result column="trigger_code" property="triggerCode"/>
<result column="trigger_name" property="triggerName"/>
<result column="trigger_desc" property="triggerDesc"/>
<result column="sort_order" property="sortOrder"/>
<result column="status" property="status"/>
<result column="deleted_flag" property="deletedFlag"/>
<result column="created_by" property="createdBy"/>
<result column="created_date" property="createdDate"/>
<result column="updated_by" property="updatedBy"/>
<result column="updated_date" property="updatedDate"/>
</resultMap>
<select id="selectByStatus" resultMap="BaseResultMap">
SELECT * FROM sop_strategy_meta_trigger
WHERE deleted_flag = 'N'
<if test="status != null">
AND status = #{status}
</if>
ORDER BY sort_order ASC
</select>
</mapper>
\ No newline at end of file
package cn.com.glsx.dj.strategy.service;
import cn.com.glsx.dj.strategy.mapper.sop.SopStrategyEventLogMapper;
import cn.com.glsx.dj.strategy.model.sop.SopStrategyEventLog;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import static org.junit.Assert.*;
import static org.mockito.Mockito.*;
@RunWith(SpringRunner.class)
@SpringBootTest(classes = cn.com.glsx.dj.strategy.Main.class)
public class SopStrategyEventLogServiceTest {
@Mock
private SopStrategyEventLogMapper sopStrategyEventLogMapper;
@Mock
private ObjectMapper objectMapper;
@InjectMocks
private SopStrategyEventLogService sopStrategyEventLogService;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
}
@Test
public void testRecordMenuEntryEvent() {
doNothing().when(sopStrategyEventLogMapper).insertSelective(any(SopStrategyEventLog.class));
sopStrategyEventLogService.recordMenuEntryEvent();
verify(sopStrategyEventLogMapper, times(1)).insertSelective(any(SopStrategyEventLog.class));
}
@Test
public void testRecordSubmitChangeEvent() {
doNothing().when(sopStrategyEventLogMapper).insertSelective(any(SopStrategyEventLog.class));
sopStrategyEventLogService.recordSubmitChangeEvent(1, 100L);
verify(sopStrategyEventLogMapper, times(1)).insertSelective(any(SopStrategyEventLog.class));
}
@Test
public void testRecordSubmitChangeEvent_NullExecutionRecordId() {
doNothing().when(sopStrategyEventLogMapper).insertSelective(any(SopStrategyEventLog.class));
sopStrategyEventLogService.recordSubmitChangeEvent(1, null);
verify(sopStrategyEventLogMapper, times(1)).insertSelective(any(SopStrategyEventLog.class));
}
@Test
public void testRecordH5PageViewEvent() {
doNothing().when(sopStrategyEventLogMapper).insertSelective(any(SopStrategyEventLog.class));
sopStrategyEventLogService.recordH5PageViewEvent(1, 100L, 200L, "门店A", "张三", "13800138000");
verify(sopStrategyEventLogMapper, times(1)).insertSelective(any(SopStrategyEventLog.class));
}
@Test
public void testRecordH5PageViewEvent_NullStrategyId() {
doNothing().when(sopStrategyEventLogMapper).insertSelective(any(SopStrategyEventLog.class));
sopStrategyEventLogService.recordH5PageViewEvent(null, 100L, 200L, "门店A", "张三", "13800138000");
verify(sopStrategyEventLogMapper, times(1)).insertSelective(any(SopStrategyEventLog.class));
}
@Test
public void testRecordH5PageViewEvent_NullCustomerInfo() {
doNothing().when(sopStrategyEventLogMapper).insertSelective(any(SopStrategyEventLog.class));
sopStrategyEventLogService.recordH5PageViewEvent(1, 100L, null, null, null, null);
verify(sopStrategyEventLogMapper, times(1)).insertSelective(any(SopStrategyEventLog.class));
}
@Test
public void testRecordEvent_Exception() {
doThrow(new RuntimeException("数据库异常")).when(sopStrategyEventLogMapper).insertSelective(any(SopStrategyEventLog.class));
sopStrategyEventLogService.recordMenuEntryEvent();
verify(sopStrategyEventLogMapper, times(1)).insertSelective(any(SopStrategyEventLog.class));
}
@Test
public void testEventCodeConstants() {
assertEquals("sop_strategy_web_menu_entry", SopStrategyEventLogService.EVENT_CODE_MENU_ENTRY);
assertEquals("sop_strategy_web_submit_change", SopStrategyEventLogService.EVENT_CODE_SUBMIT_CHANGE);
assertEquals("sop_strategy_h5_marketing_page_view", SopStrategyEventLogService.EVENT_CODE_H5_PAGE_VIEW);
}
}
\ No newline at end of file
package cn.com.glsx.dj.strategy.service;
import cn.com.glsx.dj.strategy.model.sop.SopStrategy;
import org.junit.Before;
import org.junit.Test;
import java.util.Calendar;
import java.util.Date;
import static org.junit.Assert.*;
public class SopTriggerTimeCalculatorTest {
private SopTriggerTimeCalculator calculator;
@Before
public void setUp() {
calculator = new SopTriggerTimeCalculator();
}
@Test
public void testCalculateTriggerTime_FixedDate_TriggerTimeNotReached() {
SopStrategy strategy = new SopStrategy();
strategy.setDateVariableType(null);
strategy.setTriggerHour(23);
strategy.setTriggerMinute(59);
Date triggerTime = calculator.calculateTriggerTime(strategy, 1L, null);
assertNotNull("触发时间不应为空", triggerTime);
Calendar expected = Calendar.getInstance();
expected.set(Calendar.HOUR_OF_DAY, 23);
expected.set(Calendar.MINUTE, 59);
expected.set(Calendar.SECOND, 0);
expected.set(Calendar.MILLISECOND, 0);
Calendar actual = Calendar.getInstance();
actual.setTime(triggerTime);
assertEquals("小时应该相等", expected.get(Calendar.HOUR_OF_DAY), actual.get(Calendar.HOUR_OF_DAY));
assertEquals("分钟应该相等", expected.get(Calendar.MINUTE), actual.get(Calendar.MINUTE));
}
@Test
public void testCalculateTriggerTime_FixedDate_TriggerTimeAlreadyPassed() {
SopStrategy strategy = new SopStrategy();
strategy.setDateVariableType(null);
strategy.setTriggerHour(0);
strategy.setTriggerMinute(0);
Date triggerTime = calculator.calculateTriggerTime(strategy, 1L, null);
assertNotNull("触发时间不应为空", triggerTime);
Calendar actual = Calendar.getInstance();
actual.setTime(triggerTime);
Calendar expected = Calendar.getInstance();
expected.add(Calendar.DAY_OF_MONTH, 1);
expected.set(Calendar.HOUR_OF_DAY, 0);
expected.set(Calendar.MINUTE, 0);
expected.set(Calendar.SECOND, 0);
expected.set(Calendar.MILLISECOND, 0);
assertEquals("触发时间应为明天", expected.get(Calendar.DAY_OF_YEAR), actual.get(Calendar.DAY_OF_YEAR));
}
@Test
public void testCalculateTriggerTime_RelativeDate_PositiveDays() {
SopStrategy strategy = new SopStrategy();
strategy.setDateVariableType("BUY_DATE");
strategy.setRelativeDays(7);
strategy.setTriggerHour(10);
strategy.setTriggerMinute(0);
Date customerBehaviorDate = new Date();
Date triggerTime = calculator.calculateTriggerTime(strategy, 1L, customerBehaviorDate);
assertNotNull("触发时间不应为空", triggerTime);
Calendar expected = Calendar.getInstance();
expected.setTime(customerBehaviorDate);
expected.add(Calendar.DAY_OF_MONTH, 7);
expected.set(Calendar.HOUR_OF_DAY, 10);
expected.set(Calendar.MINUTE, 0);
expected.set(Calendar.SECOND, 0);
expected.set(Calendar.MILLISECOND, 0);
Calendar actual = Calendar.getInstance();
actual.setTime(triggerTime);
assertEquals("天数应该相差7天", expected.get(Calendar.DAY_OF_YEAR), actual.get(Calendar.DAY_OF_YEAR));
assertEquals("小时应该为10", 10, actual.get(Calendar.HOUR_OF_DAY));
}
@Test
public void testCalculateTriggerTime_RelativeDate_NegativeDays() {
SopStrategy strategy = new SopStrategy();
strategy.setDateVariableType("BUY_DATE");
strategy.setRelativeDays(-3);
strategy.setTriggerHour(9);
strategy.setTriggerMinute(30);
Date customerBehaviorDate = new Date();
Date triggerTime = calculator.calculateTriggerTime(strategy, 1L, customerBehaviorDate);
assertNotNull("触发时间不应为空", triggerTime);
Calendar expected = Calendar.getInstance();
expected.setTime(customerBehaviorDate);
expected.add(Calendar.DAY_OF_MONTH, -3);
expected.set(Calendar.HOUR_OF_DAY, 9);
expected.set(Calendar.MINUTE, 30);
expected.set(Calendar.SECOND, 0);
expected.set(Calendar.MILLISECOND, 0);
Calendar actual = Calendar.getInstance();
actual.setTime(triggerTime);
assertEquals("天数应该相差-3天", expected.get(Calendar.DAY_OF_YEAR), actual.get(Calendar.DAY_OF_YEAR));
assertEquals("小时应该为9", 9, actual.get(Calendar.HOUR_OF_DAY));
assertEquals("分钟应该为30", 30, actual.get(Calendar.MINUTE));
}
@Test
public void testCalculateTriggerTime_RelativeDate_ZeroDays() {
SopStrategy strategy = new SopStrategy();
strategy.setDateVariableType("BUY_DATE");
strategy.setRelativeDays(0);
strategy.setTriggerHour(15);
strategy.setTriggerMinute(45);
Date customerBehaviorDate = new Date();
Date triggerTime = calculator.calculateTriggerTime(strategy, 1L, customerBehaviorDate);
assertNotNull("触发时间不应为空", triggerTime);
Calendar expected = Calendar.getInstance();
expected.setTime(customerBehaviorDate);
expected.set(Calendar.HOUR_OF_DAY, 15);
expected.set(Calendar.MINUTE, 45);
expected.set(Calendar.SECOND, 0);
expected.set(Calendar.MILLISECOND, 0);
Calendar actual = Calendar.getInstance();
actual.setTime(triggerTime);
assertEquals("天数应该相同", expected.get(Calendar.DAY_OF_YEAR), actual.get(Calendar.DAY_OF_YEAR));
assertEquals("小时应该为15", 15, actual.get(Calendar.HOUR_OF_DAY));
assertEquals("分钟应该为45", 45, actual.get(Calendar.MINUTE));
}
@Test
public void testCalculateTriggerTime_NullBehaviorDate() {
SopStrategy strategy = new SopStrategy();
strategy.setDateVariableType("BUY_DATE");
strategy.setRelativeDays(7);
strategy.setTriggerHour(10);
strategy.setTriggerMinute(0);
Date triggerTime = calculator.calculateTriggerTime(strategy, 1L, null);
assertNotNull("触发时间不应为空", triggerTime);
}
@Test
public void testIsTriggerTimeReached_TriggerTimeInPast() {
Date triggerTime = new Date(System.currentTimeMillis() - 1000);
boolean result = calculator.isTriggerTimeReached(triggerTime);
assertTrue("触发时间已过应该返回true", result);
}
@Test
public void testIsTriggerTimeReached_TriggerTimeInFuture() {
Date triggerTime = new Date(System.currentTimeMillis() + 1000 * 60 * 60);
boolean result = calculator.isTriggerTimeReached(triggerTime);
assertFalse("触发时间未到应该返回false", result);
}
@Test
public void testIsTriggerTimeReached_NullTriggerTime() {
boolean result = calculator.isTriggerTimeReached(null);
assertFalse("触发时间为空应该返回false", result);
}
@Test
public void testIsTriggerTimeInFuture_TriggerTimeInFuture() {
Date triggerTime = new Date(System.currentTimeMillis() + 1000 * 60 * 60 * 24 * 5);
boolean result = calculator.isTriggerTimeInFuture(triggerTime, 3);
assertTrue("触发时间在3天后应该返回true", result);
}
@Test
public void testIsTriggerTimeInFuture_TriggerTimeNotInFuture() {
Date triggerTime = new Date(System.currentTimeMillis() + 1000 * 60 * 60 * 24 * 2);
boolean result = calculator.isTriggerTimeInFuture(triggerTime, 3);
assertFalse("触发时间不在3天后应该返回false", result);
}
@Test
public void testIsTriggerTimeInFuture_NullTriggerTime() {
boolean result = calculator.isTriggerTimeInFuture(null, 3);
assertTrue("触发时间为空应该返回true", result);
}
@Test
public void testIsSameDay_SameDay() {
Date date1 = new Date();
Date date2 = new Date();
boolean result = calculator.isSameDay(date1, date2);
assertTrue("同一天应该返回true", result);
}
@Test
public void testIsSameDay_DifferentDay() {
Date date1 = new Date();
Date date2 = new Date(System.currentTimeMillis() + 24 * 60 * 60 * 1000);
boolean result = calculator.isSameDay(date1, date2);
assertFalse("不同天应该返回false", result);
}
@Test
public void testIsSameDay_NullDate() {
Date date1 = new Date();
boolean result1 = calculator.isSameDay(date1, null);
assertFalse("其中一个日期为空应该返回false", result1);
boolean result2 = calculator.isSameDay(null, date1);
assertFalse("其中一个日期为空应该返回false", result2);
boolean result3 = calculator.isSameDay(null, null);
assertFalse("两个日期都为空应该返回false", result3);
}
@Test
public void testCalculateTriggerTime_DefaultTriggerTime() {
SopStrategy strategy = new SopStrategy();
strategy.setDateVariableType(null);
strategy.setTriggerHour(null);
strategy.setTriggerMinute(null);
Date triggerTime = calculator.calculateTriggerTime(strategy, 1L, null);
assertNotNull("触发时间不应为空", triggerTime);
Calendar actual = Calendar.getInstance();
actual.setTime(triggerTime);
assertEquals("默认小时应该为0", 0, actual.get(Calendar.HOUR_OF_DAY));
assertEquals("默认分钟应该为0", 0, actual.get(Calendar.MINUTE));
}
}
\ No newline at end of file
package cn.com.glsx.dj.strategy.service;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import cn.com.glsx.dj.strategy.dto.sop.SopStrategyDetailDTO;
import cn.com.glsx.dj.strategy.dto.sop.SopStrategyMetaDTO;
import cn.com.glsx.dj.strategy.dto.sop.SopStrategyRecordDetailDTO;
import cn.com.glsx.dj.strategy.exception.SopStrategyException;
import cn.com.glsx.dj.strategy.model.sop.SopStrategy;
import cn.com.glsx.framework.core.beans.rpc.RpcPagination;
import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import lombok.extern.slf4j.Slf4j;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
@RunWith(SpringRunner.class)
@SpringBootTest(classes = cn.com.glsx.dj.strategy.Main.class)
@Slf4j
public class StrategySopQueryServiceTest {
@Autowired
private StrategySopQueryService strategySopQueryService;
@Test
public void testGetSopStrategyMeta_Success() {
SopStrategyMetaDTO meta = strategySopQueryService.getSopStrategyMeta();
assertNotNull("元数据不应为空", meta);
assertNotNull("营销阶段列表不应为空", meta.getStages());
assertNotNull("条件变量列表不应为空", meta.getConditionVariables());
assertNotNull("第二步条件变量列表不应为空", meta.getStep2ConditionVariables());
assertNotNull("触发类型列表不应为空", meta.getTriggers());
assertNotNull("消息变量列表不应为空", meta.getMessageVariables());
log.info("元数据:{}", JSONObject.toJSONString(meta));
}
@Test
public void testSelectSopStrategyPage_Success() {
PageHelper.startPage(1, 10);
Page<SopStrategy> page = strategySopQueryService.selectSopStrategyPage(buildPagination());
assertNotNull("分页结果不应为空", page);
assertNotNull("数据列表不应为空", page.getResult());
assertTrue("总记录数应大于等于0", page.getTotal() >= 0);
log.info("分页结果:{}",JSONObject.toJSONString( page));
}
@Test
public void testGetSopStrategyById_Success() {
Integer strategyId = 4;
SopStrategyDetailDTO detail = strategySopQueryService.getSopStrategyById(strategyId);
assertNotNull("策略详情不应为空", detail);
assertNotNull("策略名称不应为空", detail.getStrategyName());
assertNotNull("分支列表不应为空", detail.getBranches());
log.info("策略详情:{}",JSONObject.toJSONString(detail));
}
@Test(expected = SopStrategyException.class)
public void testGetSopStrategyById_NotFound() {
Integer strategyId = 99999;
strategySopQueryService.getSopStrategyById(strategyId);
}
@Test
public void testGetSopStrategyRecordDetail_Success() {
Long recordId = 1L;
SopStrategyRecordDetailDTO detail = strategySopQueryService.getSopStrategyRecordDetail(recordId);
assertNotNull("执行记录详情不应为空", detail);
assertNotNull("客户实例ID不应为空", detail.getCustomerInstanceId());
log.info("执行记录详情:记录ID={}, 客户姓名={}, 执行结果={}",
detail.getRecordId(), detail.getCustomerNameSnapshot(), detail.getExecuteResult());
}
@Test(expected = SopStrategyException.class)
public void testGetSopStrategyRecordDetail_NotFound() {
Long recordId = 99999L;
strategySopQueryService.getSopStrategyRecordDetail(recordId);
}
private RpcPagination<SopStrategy> buildPagination() {
RpcPagination<SopStrategy> pagination = new RpcPagination<>();
pagination.setPageNum(1);
pagination.setPageSize(10);
SopStrategy condition = new SopStrategy();
condition.setStrategyName("测试");
pagination.setCondition(condition);
return pagination;
}
}
\ No newline at end of file
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!