Commit 59e8fca5 by 范富荣

Merge remote-tracking branch 'origin/v5.8.2' into v5.8.2

2 parents 06e068d7 e0f0e8a5
Showing 81 changed files with 3549 additions and 34 deletions
package cn.com.glsx.dj.strategy.dto.projectgroup;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.ToString;
import java.io.Serializable;
/**
* 项目组下拉选项 DTO。
*
* @author yangwei_by_claude
* @version 1.0
* @since 2026/05/29 16:00
*/
@Data
@ToString
public class GroupOptionDTO implements Serializable {
private static final long serialVersionUID = -4879253148620973387L;
@ApiModelProperty(notes = "项目组id")
private Integer groupId;
@ApiModelProperty(notes = "项目组名称")
private String groupName;
}
...@@ -15,6 +15,9 @@ public class ProjectGroupMetricQueryDTO implements Serializable { ...@@ -15,6 +15,9 @@ public class ProjectGroupMetricQueryDTO implements Serializable {
private static final long serialVersionUID = -8450912935887202644L; private static final long serialVersionUID = -8450912935887202644L;
@ApiModelProperty(notes = "预警类型")
private Integer warningType;
@ApiModelProperty(notes = "应用业务") @ApiModelProperty(notes = "应用业务")
private Integer biz; private Integer biz;
......
package cn.com.glsx.dj.strategy.dto.projectgroup;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.ToString;
import java.io.Serializable;
/**
* 项目组下拉选项 DTO。
*/
@Data
@ToString
public class ProjectGroupOptionDTO implements Serializable {
private static final long serialVersionUID = 1538154399088770417L;
@ApiModelProperty(notes = "项目组id")
private Integer groupId;
@ApiModelProperty(notes = "项目组名称")
private String groupName;
}
...@@ -5,6 +5,8 @@ import lombok.Data; ...@@ -5,6 +5,8 @@ import lombok.Data;
import lombok.ToString; import lombok.ToString;
import java.io.Serializable; import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;
/** /**
* 项目组预警结果DTO。 * 项目组预警结果DTO。
...@@ -15,15 +17,90 @@ public class ProjectGroupWarningRecordDTO implements Serializable { ...@@ -15,15 +17,90 @@ public class ProjectGroupWarningRecordDTO implements Serializable {
private static final long serialVersionUID = 3916133447622354984L; private static final long serialVersionUID = 3916133447622354984L;
@ApiModelProperty(notes = "记录ID")
private Integer id;
@ApiModelProperty(notes = "项目组ID")
private Integer groupId;
@ApiModelProperty(notes = "配置ID")
private Integer configId;
@ApiModelProperty(notes = "门店id") @ApiModelProperty(notes = "门店id")
private Integer merchantId; private Integer merchantId;
@ApiModelProperty(notes = "门店名称") @ApiModelProperty(notes = "门店名称")
private String merchantName; private String merchantName;
@ApiModelProperty(notes = "员工ID")
private String staffId;
@ApiModelProperty(notes = "员工名称")
private String staffName;
@ApiModelProperty(notes = "员工手机号")
private String staffPhone;
@ApiModelProperty(notes = "预警类型") @ApiModelProperty(notes = "预警类型")
private Integer warningType; private Integer warningType;
@ApiModelProperty(notes = "预警类型名称") @ApiModelProperty(notes = "预警类型名称")
private String warningTypeName; private String warningTypeName;
@ApiModelProperty(notes = "业务类型")
private Integer businessType;
@ApiModelProperty(notes = "监控对象")
private Integer monitorTarget;
@ApiModelProperty(notes = "时间维度")
private String timeDimension;
@ApiModelProperty(notes = "周期开始")
private Date periodStart;
@ApiModelProperty(notes = "周期结束")
private Date periodEnd;
@ApiModelProperty(notes = "指标编码")
private String metricCode;
@ApiModelProperty(notes = "指标名称")
private String metricName;
@ApiModelProperty(notes = "指标值")
private BigDecimal metricValue;
@ApiModelProperty(notes = "指标展示值")
private BigDecimal metricDisplay;
@ApiModelProperty(notes = "阈值类型")
private Integer thresholdType;
@ApiModelProperty(notes = "阈值展示值")
private BigDecimal thresholdDisplay;
@ApiModelProperty(notes = "阈值下界展示")
private BigDecimal thresholdMinDisplay;
@ApiModelProperty(notes = "阈值上界展示")
private BigDecimal thresholdMaxDisplay;
@ApiModelProperty(notes = "生态系数")
private BigDecimal ecoCoefficient;
@ApiModelProperty(notes = "运算符")
private String operator;
@ApiModelProperty(notes = "预警文本")
private String warningText;
@ApiModelProperty(notes = "是否已下发策略")
private Integer isStrategySent;
@ApiModelProperty(notes = "状态")
private Integer status;
@ApiModelProperty(notes = "创建时间")
private Date createdTime;
} }
...@@ -39,4 +39,16 @@ public class ProjectGroupWarningRecordQueryDTO implements Serializable { ...@@ -39,4 +39,16 @@ public class ProjectGroupWarningRecordQueryDTO implements Serializable {
@ApiModelProperty(notes = "结束时间") @ApiModelProperty(notes = "结束时间")
private String periodEnd; private String periodEnd;
@ApiModelProperty(notes = "门店ID")
private Integer storeId;
@ApiModelProperty(notes = "员工ID")
private String staffId;
@ApiModelProperty(notes = "门店名称模糊搜索")
private String storeName;
@ApiModelProperty(notes = "是否已下发策略: 0=否 1=是")
private Integer isStrategySent;
} }
package cn.com.glsx.dj.strategy.dto.warning;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.ToString;
import java.io.Serializable;
/**
* 规则条件——rule_json 数组中的单个条件元素。
*
* @author yangwei_by_claude
* @version 1.0
* @since 2026/05/28 14:00
*/
@Data
@ToString
public class ConditionDTO implements Serializable {
private static final long serialVersionUID = -8086676469236141619L;
@ApiModelProperty(notes = "条件序号,从1开始递增")
private Integer seq;
@ApiModelProperty(notes = "指标引用")
private MetricRefDTO metric;
@ApiModelProperty(notes = "运算符: > < >= <= = >< >=<= >=< ><=")
private String operator;
@ApiModelProperty(notes = "阈值配置")
private ThresholdDTO threshold;
@ApiModelProperty(notes = "下一条逻辑: AND / OR / null(最后一条)")
private String nextLogic;
}
package cn.com.glsx.dj.strategy.dto.warning;
import cn.com.glsx.dj.strategy.dto.OperatorResponse;
import cn.com.glsx.dj.strategy.dto.StrategyTypeStatisticsRespDTO;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.ToString;
import java.io.Serializable;
import java.util.List;
/**
* 效果分析响应——按门店维度聚合,内含触发预警的各指标分析。
*
* @author yangwei_by_claude
* @version 1.0
* @since 2026/05/28 14:00
*/
@Data
@ToString
public class EffectAnalysisDTO implements Serializable {
private static final long serialVersionUID = 7832506478100376535L;
@ApiModelProperty(notes = "商户号")
private String merchantNo;
@ApiModelProperty(notes = "门店名称")
private String storeName;
@ApiModelProperty(
name = "mainServiceMerchantName",
notes = "主服务商名称",
example = "1"
)
private String mainServiceMerchantName;
@ApiModelProperty(notes = "主营品牌(逗号分隔)")
private String mainBrandsStr;
@ApiModelProperty(notes = "线上运营")
private List<OperatorResponse> onlineOperator;
@ApiModelProperty(notes = "区域运营")
private List<OperatorResponse> areaOperator;
@ApiModelProperty(
name = "flightSupervision",
notes = "区域督导"
)
private List<OperatorResponse> flightSupervision;
@ApiModelProperty(notes = "执行策略总数")
private Integer strategyTotalCount;
@ApiModelProperty(notes = "策略类型统计详情")
private List<StrategyTypeStatisticsRespDTO> strategyTypeStatisticsResponse;
@ApiModelProperty(notes = "触发预警的指标分析列表")
private List<MetricAnalysisDTO> metrics;
}
package cn.com.glsx.dj.strategy.dto.warning;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.ToString;
import java.io.Serializable;
/**
* 效果分析请求入参。
*
* @author yangwei_by_claude
* @version 1.0
* @since 2026/05/29 14:00
*/
@Data
@ToString
public class EffectAnalysisRequest implements Serializable {
private static final long serialVersionUID = 8179243105885129458L;
@ApiModelProperty(notes = "业务线: 1=延保 2=轻改 3=权益", required = true)
private Integer businessType;
@ApiModelProperty(notes = "预警类型: 5=黄色预警 4=红色预警 3=生态预警 2=兜底预警", required = true)
private Integer warningType;
@ApiModelProperty(notes = "时间维度: W/M/LDW/LDM", required = true)
private String timeDimension;
@ApiModelProperty(notes = "开始日期 yyyy-MM-dd", required = true)
private String startDate;
@ApiModelProperty(notes = "结束日期 yyyy-MM-dd", required = true)
private String endDate;
@ApiModelProperty(notes = "页码,默认1")
private Integer pageNum = 1;
@ApiModelProperty(notes = "每页数量,默认10")
private Integer pageSize = 10;
}
package cn.com.glsx.dj.strategy.dto.warning;
import lombok.Data;
import lombok.ToString;
import java.io.Serializable;
import java.util.List;
/**
* 门店筛选条件 DTO——品牌/区域/运营/督导多维度筛选后取门店交集。
*
* @author yangwei_by_claude
* @version 1.0
* @since 2026/05/28 14:00
*/
@Data
@ToString
public class MerchantFilterDTO implements Serializable {
private static final long serialVersionUID = -1071410850495914559L;
/** 业务类型: 1=延保 2=轻改 3=权益 */
private Integer businessType;
/** 区域ID(可选) */
private Integer regionId;
/** 一级品牌ID列表(可选) */
private List<Integer> firstbrandIds;
/** 二级品牌ID列表(可选) */
private List<Integer> twoBrandIds;
/** 线上运营人员ID(可选) */
private String onlineOperatorId;
/** 区域运营人员ID(可选) */
private String regionalOperatorId;
/** 飞行督导人员ID(可选) */
private String flyingSupervisorId;
/** 门店名称模糊搜索(可选) */
private String storeName;
/** 项目组ID(可选) */
private Integer groupId;
/** 是否已下发策略: 0=否 1=是(可选) */
private Integer isStrategySent;
/** 周期开始日期 yyyy-MM-dd(策略筛选时使用) */
private String startDate;
/** 周期结束日期 yyyy-MM-dd(策略筛选时使用) */
private String endDate;
}
package cn.com.glsx.dj.strategy.dto.warning;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.ToString;
import java.io.Serializable;
import java.math.BigDecimal;
/**
* 单指标效果分析——当前周期 vs 下一周期对比。
*
* @author yangwei_by_claude
* @version 1.0
* @since 2026/05/29 14:00
*/
@Data
@ToString
public class MetricAnalysisDTO implements Serializable {
private static final long serialVersionUID = 4621029849577301294L;
@ApiModelProperty(notes = "指标编码")
private String metricCode;
@ApiModelProperty(notes = "指标名称")
private String metricName;
@ApiModelProperty(notes = "扩展品类")
private String categoryExtension;
@ApiModelProperty(notes = "当前周期指标值")
private BigDecimal currentValue;
@ApiModelProperty(notes = "下一周期指标值")
private BigDecimal nextValue;
@ApiModelProperty(notes = "指标单位")
private String unit;
@ApiModelProperty(notes = "变化率")
private BigDecimal changeRate;
@ApiModelProperty(notes = "是否提升")
private boolean improved;
}
package cn.com.glsx.dj.strategy.dto.warning;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.ToString;
import java.io.Serializable;
/**
* 指标引用——rule_json 中 condition.metric 部分。
*
* @author yangwei_by_claude
* @version 1.0
* @since 2026/05/28 14:00
*/
@Data
@ToString
public class MetricRefDTO implements Serializable {
private static final long serialVersionUID = 754109325813660140L;
@ApiModelProperty(notes = "指标中文名")
private String name;
@ApiModelProperty(notes = "门店维度BI指标编码")
private String storeCode;
@ApiModelProperty(notes = "员工维度BI指标编码")
private String staffCode;
}
package cn.com.glsx.dj.strategy.dto.warning;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;
import java.io.Serializable;
import java.util.Date;
/**
* 统计周期起止日期。
*
* @author yangwei_by_claude
* @version 1.0
* @since 2026/05/28 14:00
*/
@Data
@ToString
@NoArgsConstructor
@AllArgsConstructor
public class PeriodRange implements Serializable {
private static final long serialVersionUID = -2669050403430560292L;
/** 周期开始 */
private Date start;
/** 周期结束 */
private Date end;
}
package cn.com.glsx.dj.strategy.dto.warning;
import cn.com.glsx.dj.strategy.dto.OperatorResponse;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.ToString;
import java.io.Serializable;
import java.util.List;
/**
* 门店预警汇总响应。
*
* @author yangwei_by_claude
* @version 1.0
* @since 2026/05/28 14:00
*/
@Data
@ToString
public class StoreWarningSummaryDTO implements Serializable {
private static final long serialVersionUID = 6874671301578247683L;
@ApiModelProperty(notes = "商户号")
private String merchantNo;
@ApiModelProperty(notes = "门店名称")
private String storeName;
@ApiModelProperty(notes = "主营品牌(逗号分隔)")
private String mainBrandsStr;
@ApiModelProperty(notes = "线上运营")
private List<OperatorResponse> onlineOperator;
@ApiModelProperty(notes = "区域运营")
private List<OperatorResponse> areaOperator;
@ApiModelProperty(notes = "区域督导")
private List<OperatorResponse> flightSupervision;
@ApiModelProperty(notes = "预警摘要(最多2条)")
private List<String> warningSummary;
@ApiModelProperty(notes = "预警总数")
private int warningTotalCount;
@ApiModelProperty(notes = "是否已下发策略")
private boolean strategySent;
}
package cn.com.glsx.dj.strategy.dto.warning;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.ToString;
import java.io.Serializable;
/**
* 阈值配置——rule_json 中 condition.threshold 部分。
*
* @author yangwei_by_claude
* @version 1.0
* @since 2026/05/28 14:00
*/
@Data
@ToString
public class ThresholdDTO implements Serializable {
private static final long serialVersionUID = -5949072911915986709L;
@ApiModelProperty(notes = "阈值类型: 1=固定值 2=动态SQL兜底 3=引用指标")
private Integer type;
@ApiModelProperty(notes = "type=1时存数值,type=2时存SQL,type=3时存指标编码")
private String value;
@ApiModelProperty(notes = "区间下界")
private String min;
@ApiModelProperty(notes = "区间上界")
private String max;
@ApiModelProperty(notes = "type=2区间时,SQL结果集中下界字段名")
private String minField;
@ApiModelProperty(notes = "type=2区间时,SQL结果集中上界字段名")
private String maxField;
}
package cn.com.glsx.dj.strategy.dto.warning;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;
import java.io.Serializable;
import java.math.BigDecimal;
/**
* 解析后的阈值——策略接口 resolve() 返回的统一结果。
*
* @author yangwei_by_claude
* @version 1.0
* @since 2026/05/28 14:00
*/
@Data
@ToString
@NoArgsConstructor
@AllArgsConstructor
public class ThresholdValue implements Serializable {
private static final long serialVersionUID = -4724071098513030311L;
@ApiModelProperty(notes = "单值阈值(单值运算符使用)")
private BigDecimal value;
@ApiModelProperty(notes = "区间下界(区间运算符使用)")
private BigDecimal min;
@ApiModelProperty(notes = "区间上界(区间运算符使用)")
private BigDecimal max;
@ApiModelProperty(notes = "单值展示值")
private BigDecimal display;
@ApiModelProperty(notes = "区间下界展示值")
private BigDecimal minDisplay;
@ApiModelProperty(notes = "区间上界展示值")
private BigDecimal maxDisplay;
public static ThresholdValue single(BigDecimal value, BigDecimal display) {
ThresholdValue tv = new ThresholdValue();
tv.value = value;
tv.display = display;
return tv;
}
public static ThresholdValue range(BigDecimal min, BigDecimal max, BigDecimal minDisplay, BigDecimal maxDisplay) {
ThresholdValue tv = new ThresholdValue();
tv.min = min;
tv.max = max;
tv.minDisplay = minDisplay;
tv.maxDisplay = maxDisplay;
return tv;
}
}
package cn.com.glsx.dj.strategy.dto.warning;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.ToString;
import java.io.Serializable;
/**
* 预警配置创建/更新请求。
*
* @author yangwei_by_claude
* @version 1.0
* @since 2026/05/28 14:00
*/
@Data
@ToString
public class WarningConfigCreateRequest implements Serializable {
private static final long serialVersionUID = 1774501266681146101L;
@ApiModelProperty(notes = "配置ID(更新时必填)")
private Integer id;
@ApiModelProperty(notes = "项目组ID")
private Integer groupId;
@ApiModelProperty(notes = "预警类型: 5=黄色预警 4=红色预警 3=生态预警 2=兜底预警")
private Integer warningType;
@ApiModelProperty(notes = "业务线: 1=延保 2=轻改 3=权益")
private Integer biz;
@ApiModelProperty(notes = "监控对象: 1=员工 2=门店")
private Integer monitorTarget;
@ApiModelProperty(notes = "规则JSON字符串")
private String ruleJson;
}
package cn.com.glsx.dj.strategy.dto.warning;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.ToString;
import java.io.Serializable;
import java.util.Date;
/**
* 预警配置响应。
*
* @author yangwei_by_claude
* @version 1.0
* @since 2026/05/28 14:00
*/
@Data
@ToString
public class WarningConfigDTO implements Serializable {
private static final long serialVersionUID = 668237476790997177L;
@ApiModelProperty(notes = "配置ID")
private Integer id;
@ApiModelProperty(notes = "项目组ID")
private Integer groupId;
@ApiModelProperty(notes = "预警类型: 5=黄色预警 4=红色预警 3=生态预警 2=兜底预警")
private Integer warningType;
@ApiModelProperty(notes = "业务线: 1=延保 2=轻改 3=权益")
private Integer biz;
@ApiModelProperty(notes = "监控对象: 1=员工 2=门店")
private Integer monitorTarget;
@ApiModelProperty(notes = "规则JSON")
private String ruleJson;
@ApiModelProperty(notes = "是否启用: 1=启用 0=禁用")
private Integer isEnabled;
@ApiModelProperty(notes = "创建人")
private String createdBy;
@ApiModelProperty(notes = "创建时间")
private Date createdDate;
@ApiModelProperty(notes = "更新人")
private String updatedBy;
@ApiModelProperty(notes = "更新时间")
private Date updatedDate;
}
package cn.com.glsx.dj.strategy.dto.warning;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.ToString;
import java.io.Serializable;
/**
* 预警配置查询请求。
*
* @author yangwei_by_claude
* @version 1.0
* @since 2026/05/28 14:00
*/
@Data
@ToString
public class WarningConfigQueryRequest implements Serializable {
private static final long serialVersionUID = -2248571333288266353L;
@ApiModelProperty(notes = "项目组ID")
private Integer groupId;
@ApiModelProperty(notes = "预警类型")
private Integer warningType;
@ApiModelProperty(notes = "业务线")
private Integer biz;
@ApiModelProperty(notes = "监控对象")
private Integer monitorTarget;
@ApiModelProperty(notes = "是否启用")
private Integer isEnabled;
}
package cn.com.glsx.dj.strategy.dto.warning;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.ToString;
import java.io.Serializable;
/**
* 预警配置启用/禁用请求。
*
* @author yangwei_by_claude
* @version 1.0
* @since 2026/05/28 14:00
*/
@Data
@ToString
public class WarningConfigToggleRequest implements Serializable {
private static final long serialVersionUID = 398216842671868181L;
@ApiModelProperty(notes = "配置ID")
private Integer configId;
@ApiModelProperty(notes = "1=启用 0=禁用")
private Integer isEnabled;
}
package cn.com.glsx.dj.strategy.dto.warning;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.ToString;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;
/**
* 预警记录响应。
*
* @author yangwei_by_claude
* @version 1.0
* @since 2026/05/28 14:00
*/
@Data
@ToString
public class WarningRecordDTO implements Serializable {
private static final long serialVersionUID = -4536558612388635010L;
@ApiModelProperty(notes = "记录ID")
private Integer id;
@ApiModelProperty(notes = "项目组ID")
private Integer groupId;
@ApiModelProperty(notes = "配置ID")
private Integer configId;
@ApiModelProperty(notes = "预警类型")
private Integer warningType;
@ApiModelProperty(notes = "预警类型名称")
private String warningTypeName;
@ApiModelProperty(notes = "业务类型")
private Integer businessType;
@ApiModelProperty(notes = "监控对象: 1=员工 2=门店")
private Integer monitorTarget;
@ApiModelProperty(notes = "时间维度")
private String timeDimension;
@ApiModelProperty(notes = "周期开始")
private Date periodStart;
@ApiModelProperty(notes = "周期结束")
private Date periodEnd;
@ApiModelProperty(notes = "门店ID")
private Integer storeId;
@ApiModelProperty(notes = "门店名称")
private String storeName;
@ApiModelProperty(notes = "员工ID")
private String staffId;
@ApiModelProperty(notes = "员工姓名")
private String staffName;
@ApiModelProperty(notes = "员工手机号")
private String staffPhone;
@ApiModelProperty(notes = "指标编码")
private String metricCode;
@ApiModelProperty(notes = "指标名称")
private String metricName;
@ApiModelProperty(notes = "指标值")
private BigDecimal metricValue;
@ApiModelProperty(notes = "指标展示值")
private BigDecimal metricDisplay;
@ApiModelProperty(notes = "阈值类型")
private Integer thresholdType;
@ApiModelProperty(notes = "阈值展示值")
private BigDecimal thresholdDisplay;
@ApiModelProperty(notes = "区间下界展示值")
private BigDecimal thresholdMinDisplay;
@ApiModelProperty(notes = "区间上界展示值")
private BigDecimal thresholdMaxDisplay;
@ApiModelProperty(notes = "生态系数")
private BigDecimal ecoCoefficient;
@ApiModelProperty(notes = "运算符")
private String operator;
@ApiModelProperty(notes = "预警描述文本")
private String warningText;
@ApiModelProperty(notes = "是否已下发策略")
private Integer isStrategySent;
@ApiModelProperty(notes = "状态")
private Integer status;
@ApiModelProperty(notes = "创建时间")
private Date createdTime;
}
package cn.com.glsx.dj.strategy.dto.warning;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.ToString;
import java.io.Serializable;
import java.util.List;
/**
* 预警记录查询请求。
*
* @author yangwei_by_claude
* @version 1.0
* @since 2026/05/28 14:00
*/
@Data
@ToString
public class WarningRecordQueryRequest implements Serializable {
private static final long serialVersionUID = 1652253646752099692L;
@ApiModelProperty(notes = "业务线: 1=延保 2=轻改 3=权益")
private Integer businessType;
@ApiModelProperty(notes = "预警类型: 5=黄色预警 4=红色预警 3=生态预警 2=兜底预警 (null=全部)")
private Integer warningType;
@ApiModelProperty(notes = "指标类型ID")
private Integer metricTypeId;
@ApiModelProperty(notes = "时间维度: W/M/LDW/LDM")
private String timeDimension;
@ApiModelProperty(notes = "开始日期 yyyy-MM-dd")
private String startDate;
@ApiModelProperty(notes = "结束日期 yyyy-MM-dd")
private String endDate;
@ApiModelProperty(notes = "项目组筛选")
private Integer groupId;
@ApiModelProperty(notes = "门店名称模糊搜索")
private String storeName;
@ApiModelProperty(notes = "是否已下发策略")
private Integer isStrategySent;
@ApiModelProperty(notes = "区域ID")
private Integer regionId;
@ApiModelProperty(notes = "监控对象 1=员工 2=门店")
private Integer monitorTarget;
@ApiModelProperty(notes = "一级品牌ID列表")
private List<Integer> firstbrandIds;
@ApiModelProperty(notes = "二级品牌ID列表")
private List<Integer> twoBrandIds;
@ApiModelProperty(notes = "区域运营人员ID")
private String regionalOperatorId;
@ApiModelProperty(notes = "线上运营人员ID")
private String onlineOperatorId;
@ApiModelProperty(notes = "区域督导人员ID")
private String flightSupervisionId;
@ApiModelProperty(notes = "门店ID(查询指定门店预警明细时使用)")
private Integer storeId;
@ApiModelProperty(notes = "员工ID(查询指定员工预警明细时使用)")
private String staffId;
}
package cn.com.glsx.dj.strategy.enums;
import lombok.AllArgsConstructor;
import lombok.Getter;
/**
* BI 聚合类型枚举——对应 BI 接口的 exts 参数,控制数据聚合维度。
*
* @author yangwei_by_claude
* @version 1.0
* @since 2026/05/28 14:00
*/
@Getter
@AllArgsConstructor
public enum BiAggregationTypeEnum {
/** 按门店聚合返回 */
MERCHANT("merchantIds", "按门店聚合"),
/** 按员工staffUUID聚合返回 */
STAFF("staffIds", "按员工聚合"),
/** 按业务聚合返回 */
BIZ("bizs", "按业务聚合"),
/** 按品牌聚合返回 */
BRAND("brandIds", "按品牌聚合"),
/** 按门店+员工聚合返回 */
MERCHANT_STAFF("merchantIds,staffIds", "按门店+员工聚合");
/** exts 参数值 */
private final String value;
/** 描述 */
private final String desc;
}
package cn.com.glsx.dj.strategy.enums;
import lombok.AllArgsConstructor;
import lombok.Getter;
/**
* BI 日期类型枚举——对应 BI 接口的 dateType 参数。
*
* @author yangwei_by_claude
* @version 1.0
* @since 2026/05/28 14:00
*/
@Getter
@AllArgsConstructor
public enum BiDateTypeEnum {
/** 按指定时段(由 startDate/endDate 决定) */
PERIOD(0, "按指定时段"),
/** 按周 */
WEEK(1, "按周"),
/** 按月 */
MONTH(2, "按月"),
/** 按年 */
YEAR(3, "按年"),
/** 全部(查询时间段汇总) */
ALL(4, "全部");
/** dateType 参数值 */
private final int value;
/** 描述 */
private final String desc;
}
package cn.com.glsx.dj.strategy.enums;
import lombok.AllArgsConstructor;
import lombok.Getter;
/**
* BI 指标代码枚举——维护 BI 系统的指标编码。
*
* @author yangwei_by_claude
* @version 1.0
* @since 2026/05/28 14:00
*/
@Getter
@AllArgsConstructor
public enum BiMetricCodeEnum {
/** 产值 */
OUTPUT_VALUE("A036", "产值");
/** 指标编码 */
private final String code;
/** 指标名称 */
private final String name;
/**
* 根据编码获取枚举。
*/
public static BiMetricCodeEnum fromCode(String code) {
for (BiMetricCodeEnum e : values()) {
if (e.code.equals(code)) {
return e;
}
}
throw new IllegalArgumentException("不支持的BI指标编码: " + code);
}
}
package cn.com.glsx.dj.strategy.enums;
import lombok.AllArgsConstructor;
import lombok.Getter;
@Getter
@AllArgsConstructor
public enum MonitorTargetEnum {
EMPLOYEE(1, "员工"),
SHOP(2, "门店");
private final Integer code;
private final String desc;
}
...@@ -24,6 +24,14 @@ public enum ProjectGroupBizEnum { ...@@ -24,6 +24,14 @@ public enum ProjectGroupBizEnum {
private final Integer biz; private final Integer biz;
private final String bizName; private final String bizName;
public Integer getBiz() {
return biz;
}
public String getBizName() {
return bizName;
}
/** /**
* 返回全部业务枚举。 * 返回全部业务枚举。
* *
......
package cn.com.glsx.dj.strategy.enums;
/**
* 策略记录数据来源,1-策略中心 2-区域督导助手小程序 3-区域运营助手小程序
* 对应表字段:dj_car_life_strategy_info.data_source
*/
public enum StrategyDataSourceEnum {
/**
* 策略中心
*/
STRATEGY_CENTER(1, "策略中心"),
/**
* 区域督导助手小程序
*/
SUPERVISOR_MINI(2, "区域督导助手小程序"),
/**
* 区域运营助手小程序
*/
OPERATION_MINI(3, "区域运营助手小程序"),
;
private Integer value;
private String displayName;
StrategyDataSourceEnum(Integer value, String displayName) {
this.value = value;
this.displayName = displayName;
}
public Integer getValue() {
return value;
}
public String getDisplayName() {
return displayName;
}
/**
* 根据 value 获取枚举
*/
public static StrategyDataSourceEnum getByValue(Integer value) {
if (value == null) {
return null;
}
for (StrategyDataSourceEnum item : values()) {
if (item.value.equals(value)) {
return item;
}
}
return null;
}
/**
* 根据 value 获取展示名称
*/
public static String getDisplayNameByValue(Integer value) {
StrategyDataSourceEnum item = getByValue(value);
return item == null ? null : item.displayName;
}
}
package cn.com.glsx.dj.strategy.enums;
import lombok.AllArgsConstructor;
import lombok.Getter;
/**
* 阈值类型枚举。
*
* <p>1=固定值 2=动态SQL兜底 3=引用指标。</p>
*
* @author yangwei_by_claude
* @version 1.0
* @since 2026/05/28 14:00
*/
@Getter
@AllArgsConstructor
public enum ThresholdTypeEnum {
FIXED(1, "固定值"),
DYNAMIC_SQL(2, "动态SQL兜底"),
REFERENCE_METRIC(3, "引用指标");
private final int type;
private final String desc;
/**
* 根据 type 值获取枚举。
*/
public static ThresholdTypeEnum fromType(int type) {
for (ThresholdTypeEnum t : values()) {
if (t.type == type) {
return t;
}
}
throw new IllegalArgumentException("不支持的阈值类型: " + type);
}
}
package cn.com.glsx.dj.strategy.enums;
import cn.com.glsx.dj.strategy.dto.warning.PeriodRange;
import lombok.AllArgsConstructor;
import lombok.Getter;
import java.util.Calendar;
import java.util.Date;
/**
* 时间维度枚举——封装周期计算逻辑。
*
* <p>W=自然周 M=自然月 LDW=截止周最新一天 LDM=截止月最新一天。</p>
*
* @author yangwei_by_claude
* @version 1.0
* @since 2026/05/28 14:00
*/
@Getter
@AllArgsConstructor
public enum TimeDimensionEnum {
W("W", "周") {
@Override
public PeriodRange calculate(Date date) {
return getWeekRange(date, true);
}
},
M("M", "月") {
@Override
public PeriodRange calculate(Date date) {
return getMonthRange(date, true);
}
},
LDW("LDW", "截止周最新一天") {
@Override
public PeriodRange calculate(Date date) {
return getWeekRange(date, false);
}
},
LDM("LDM", "截止月最新一天") {
@Override
public PeriodRange calculate(Date date) {
return getMonthRange(date, false);
}
};
private final String code;
private final String desc;
/**
* 计算指定日期对应的统计周期。
*
* @param date 参考日期
* @return 周期起止
*/
public abstract PeriodRange calculate(Date date);
/**
* 计算下一周期起止(endDate + 1 开始)。
*
* @param endDate 当前周期结束日期
* @return 下一周期起止
*/
public PeriodRange calcNextPeriod(Date endDate) {
Calendar cal = Calendar.getInstance();
cal.setTime(endDate);
cal.add(Calendar.DAY_OF_MONTH, 1);
Date nextStart = cal.getTime();
if (this == W || this == LDW) {
cal.add(Calendar.DAY_OF_MONTH, 6);
} else {
cal.set(Calendar.DAY_OF_MONTH, cal.getActualMaximum(Calendar.DAY_OF_MONTH));
}
Date nextEnd = cal.getTime();
return new PeriodRange(nextStart, nextEnd);
}
/**
* 根据 code 获取枚举。
*/
public static TimeDimensionEnum fromCode(String code) {
for (TimeDimensionEnum t : values()) {
if (t.code.equals(code)) {
return t;
}
}
throw new IllegalArgumentException("不支持的时间维度: " + code);
}
/**
* 周范围:completeWeek=true 返回完整周(周一~周日),false 返回周一~date。
*/
private static PeriodRange getWeekRange(Date date, boolean completeWeek) {
Calendar cal = toCalendar(date);
// 周一
cal.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);
Date start = cal.getTime();
Date end;
if (completeWeek) {
cal.add(Calendar.DAY_OF_MONTH, 6);
end = cal.getTime();
} else {
end = date;
}
return new PeriodRange(start, end);
}
/**
* 月范围:completeMonth=true 返回完整月(1日~月末),false 返回1日~date。
*/
private static PeriodRange getMonthRange(Date date, boolean completeMonth) {
Calendar cal = toCalendar(date);
cal.set(Calendar.DAY_OF_MONTH, 1);
Date start = cal.getTime();
Date end;
if (completeMonth) {
cal.set(Calendar.DAY_OF_MONTH, cal.getActualMaximum(Calendar.DAY_OF_MONTH));
end = cal.getTime();
} else {
end = date;
}
return new PeriodRange(start, end);
}
private static Calendar toCalendar(Date date) {
Calendar cal = Calendar.getInstance();
cal.setTime(date);
// 归一化到当天0点
cal.set(Calendar.HOUR_OF_DAY, 0);
cal.set(Calendar.MINUTE, 0);
cal.set(Calendar.SECOND, 0);
cal.set(Calendar.MILLISECOND, 0);
return cal;
}
}
package cn.com.glsx.dj.strategy.enums;
import lombok.AllArgsConstructor;
import lombok.Getter;
import java.math.BigDecimal;
import java.util.Arrays;
/**
* 预警运算符枚举——封装比对逻辑与告警文本模版。
*
* <p>单值运算符:{@code > < >= <= =};区间运算符:{@code >< >=<= >=< ><=}。</p>
*
* @author yangwei_by_claude
* @version 1.0
* @since 2026/05/28 14:00
*/
@Getter
@AllArgsConstructor
public enum WarningOperatorEnum {
// ==================== 单值运算符 ====================
GT(">", Category.SINGLE) {
@Override
public boolean evaluate(BigDecimal value, BigDecimal threshold, BigDecimal min, BigDecimal max) {
return value != null && threshold != null && value.compareTo(threshold) > 0;
}
@Override
public String buildWarningText(String metricName, BigDecimal metricDisplay,
BigDecimal thresholdDisplay, BigDecimal minDisplay, BigDecimal maxDisplay) {
return String.format("「%s」%.2f 高于 %.2f", metricName, metricDisplay, thresholdDisplay);
}
},
LT("<", Category.SINGLE) {
@Override
public boolean evaluate(BigDecimal value, BigDecimal threshold, BigDecimal min, BigDecimal max) {
return value != null && threshold != null && value.compareTo(threshold) < 0;
}
@Override
public String buildWarningText(String metricName, BigDecimal metricDisplay,
BigDecimal thresholdDisplay, BigDecimal minDisplay, BigDecimal maxDisplay) {
return String.format("「%s」%.2f 低于 %.2f", metricName, metricDisplay, thresholdDisplay);
}
},
GE(">=", Category.SINGLE) {
@Override
public boolean evaluate(BigDecimal value, BigDecimal threshold, BigDecimal min, BigDecimal max) {
return value != null && threshold != null && value.compareTo(threshold) >= 0;
}
@Override
public String buildWarningText(String metricName, BigDecimal metricDisplay,
BigDecimal thresholdDisplay, BigDecimal minDisplay, BigDecimal maxDisplay) {
return String.format("「%s」%.2f 高于或等于 %.2f", metricName, metricDisplay, thresholdDisplay);
}
},
LE("<=", Category.SINGLE) {
@Override
public boolean evaluate(BigDecimal value, BigDecimal threshold, BigDecimal min, BigDecimal max) {
return value != null && threshold != null && value.compareTo(threshold) <= 0;
}
@Override
public String buildWarningText(String metricName, BigDecimal metricDisplay,
BigDecimal thresholdDisplay, BigDecimal minDisplay, BigDecimal maxDisplay) {
return String.format("「%s」%.2f 低于或等于 %.2f", metricName, metricDisplay, thresholdDisplay);
}
},
EQ("=", Category.SINGLE) {
@Override
public boolean evaluate(BigDecimal value, BigDecimal threshold, BigDecimal min, BigDecimal max) {
return value != null && threshold != null && value.compareTo(threshold) == 0;
}
@Override
public String buildWarningText(String metricName, BigDecimal metricDisplay,
BigDecimal thresholdDisplay, BigDecimal minDisplay, BigDecimal maxDisplay) {
return String.format("「%s」%.2f 等于 %.2f", metricName, metricDisplay, thresholdDisplay);
}
},
// ==================== 区间运算符 ====================
OPEN_INTERVAL("><", Category.RANGE) {
@Override
public boolean evaluate(BigDecimal value, BigDecimal threshold, BigDecimal min, BigDecimal max) {
return value != null && min != null && max != null
&& value.compareTo(min) > 0 && value.compareTo(max) < 0;
}
@Override
public String buildWarningText(String metricName, BigDecimal metricDisplay,
BigDecimal thresholdDisplay, BigDecimal minDisplay, BigDecimal maxDisplay) {
return String.format("「%s」%.2f 在区间(%.2f, %.2f)内", metricName, metricDisplay, minDisplay, maxDisplay);
}
},
CLOSE_INTERVAL(">=<=", Category.RANGE) {
@Override
public boolean evaluate(BigDecimal value, BigDecimal threshold, BigDecimal min, BigDecimal max) {
return value != null && min != null && max != null
&& value.compareTo(min) >= 0 && value.compareTo(max) <= 0;
}
@Override
public String buildWarningText(String metricName, BigDecimal metricDisplay,
BigDecimal thresholdDisplay, BigDecimal minDisplay, BigDecimal maxDisplay) {
return String.format("「%s」%.2f 在区间[%.2f, %.2f]内", metricName, metricDisplay, minDisplay, maxDisplay);
}
},
LEFT_CLOSE_RIGHT_OPEN(">=<", Category.RANGE) {
@Override
public boolean evaluate(BigDecimal value, BigDecimal threshold, BigDecimal min, BigDecimal max) {
return value != null && min != null && max != null
&& value.compareTo(min) >= 0 && value.compareTo(max) < 0;
}
@Override
public String buildWarningText(String metricName, BigDecimal metricDisplay,
BigDecimal thresholdDisplay, BigDecimal minDisplay, BigDecimal maxDisplay) {
return String.format("「%s」%.2f 在区间[%.2f, %.2f)内", metricName, metricDisplay, minDisplay, maxDisplay);
}
},
LEFT_OPEN_RIGHT_CLOSE("><=", Category.RANGE) {
@Override
public boolean evaluate(BigDecimal value, BigDecimal threshold, BigDecimal min, BigDecimal max) {
return value != null && min != null && max != null
&& value.compareTo(min) > 0 && value.compareTo(max) <= 0;
}
@Override
public String buildWarningText(String metricName, BigDecimal metricDisplay,
BigDecimal thresholdDisplay, BigDecimal minDisplay, BigDecimal maxDisplay) {
return String.format("「%s」%.2f 在区间(%.2f, %.2f]内", metricName, metricDisplay, minDisplay, maxDisplay);
}
};
/** 运算符类别 */
@Getter
@AllArgsConstructor
public enum Category {
SINGLE("单值"),
RANGE("区间");
private final String desc;
}
private final String symbol;
private final Category category;
/**
* 评估条件是否成立。
*
* @param value 指标实际值
* @param threshold 阈值(单值运算符使用)
* @param min 区间下界(区间运算符使用)
* @param max 区间上界(区间运算符使用)
* @return true=条件成立
*/
public abstract boolean evaluate(BigDecimal value, BigDecimal threshold, BigDecimal min, BigDecimal max);
/**
* 生成告警描述文本(统一入口)。
*
* @param metricName 指标名称
* @param metricDisplay 指标展示值
* @param thresholdDisplay 阈值展示值(单值)或 null(区间)
* @param minDisplay 区间下界展示值(区间)或 null(单值)
* @param maxDisplay 区间上界展示值(区间)或 null(单值)
*/
public abstract String buildWarningText(String metricName, BigDecimal metricDisplay,
BigDecimal thresholdDisplay, BigDecimal minDisplay, BigDecimal maxDisplay);
/**
* 根据 symbol 获取枚举。
*/
public static WarningOperatorEnum fromSymbol(String symbol) {
return Arrays.stream(values())
.filter(op -> op.symbol.equals(symbol))
.findFirst()
.orElseThrow(() -> new IllegalArgumentException("不支持的运算符: " + symbol));
}
/**
* 判断是否为区间运算符。
*/
public boolean isRange() {
return category == Category.RANGE;
}
}
...@@ -2,6 +2,7 @@ package cn.com.glsx.dj.strategy.model; ...@@ -2,6 +2,7 @@ package cn.com.glsx.dj.strategy.model;
import cn.com.glsx.dj.strategy.dto.CollaborativeTaskDetailDTO; import cn.com.glsx.dj.strategy.dto.CollaborativeTaskDetailDTO;
import cn.com.glsx.dj.strategy.dto.MentoringApplicationDetailDTO; import cn.com.glsx.dj.strategy.dto.MentoringApplicationDetailDTO;
import cn.com.glsx.dj.strategy.enums.StrategyDataSourceEnum;
import cn.com.glsx.dj.strategy.enums.StrategyPushFlagEnum; import cn.com.glsx.dj.strategy.enums.StrategyPushFlagEnum;
import cn.com.glsx.dj.strategy.enums.StrategyPushType; import cn.com.glsx.dj.strategy.enums.StrategyPushType;
import cn.com.glsx.dj.strategy.enums.StrategyTypeEnum; import cn.com.glsx.dj.strategy.enums.StrategyTypeEnum;
...@@ -121,6 +122,21 @@ public class StrategyInfo implements Serializable { ...@@ -121,6 +122,21 @@ public class StrategyInfo implements Serializable {
private String createdUUid; private String createdUUid;
/** /**
* 数据来源,1-策略中心 2-区域督导助手小程序 3-区域运营助手小程序
* @see StrategyDataSourceEnum
*/
@ApiModelProperty(notes = "数据来源,1-策略中心 2-区域督导助手小程序 3-区域运营助手小程序")
@Column(name = "data_source")
private Integer dataSource;
/**
* 数据来源id
*/
@ApiModelProperty(notes = "数据来源id")
@Column(name = "data_source_id")
private Long dataSourceId;
/**
* 创建人 * 创建人
*/ */
@Column(name = "created_by") @Column(name = "created_by")
......
...@@ -44,6 +44,7 @@ public class StrategyStaffRel implements Serializable { ...@@ -44,6 +44,7 @@ public class StrategyStaffRel implements Serializable {
/** /**
* 岗位类型:0:驻店,6:飞行督导,8:1.1区域运营,9:2.1区域运营 * 岗位类型:0:驻店,6:飞行督导,8:1.1区域运营,9:2.1区域运营
* @see UserPositionEnum
*/ */
@ApiModelProperty(notes = "岗位类型:0:驻店,6:飞行督导,8:1.1区域运营,9:2.1区域运营。轻改=8,延保与权益=9") @ApiModelProperty(notes = "岗位类型:0:驻店,6:飞行督导,8:1.1区域运营,9:2.1区域运营。轻改=8,延保与权益=9")
@Column(name = "user_position") @Column(name = "user_position")
......
package cn.com.glsx.dj.strategy.model.projectgroup;
import lombok.Data;
import lombok.ToString;
import javax.persistence.Column;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import java.io.Serializable;
import java.util.Date;
/**
* 有产值门店记录模型。
*
* <p>定时任务预计算,记录各周期内有产值的门店。</p>
*
* @author yangwei_by_claude
* @version 1.0
* @since 2026/05/28 14:00
*/
@Data
@ToString
@Table(name = "pg_store_output")
public class PgStoreOutput implements Serializable {
private static final long serialVersionUID = -5540942633567676889L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id;
@Column(name = "business_type")
private Integer businessType;
@Column(name = "store_id")
private Integer storeId;
@Column(name = "store_name")
private String storeName;
@Column(name = "time_dimension")
private String timeDimension;
@Column(name = "period_start")
private Date periodStart;
@Column(name = "period_end")
private Date periodEnd;
@Column(name = "deleted_flag")
private String deletedFlag;
@Column(name = "created_by")
private String createdBy;
@Column(name = "created_date")
private Date createdDate;
@Column(name = "updated_by")
private String updatedBy;
@Column(name = "updated_date")
private Date updatedDate;
}
...@@ -6,6 +6,7 @@ import cn.com.glsx.dj.strategy.dto.projectgroup.ProjectGroupDetailDTO; ...@@ -6,6 +6,7 @@ import cn.com.glsx.dj.strategy.dto.projectgroup.ProjectGroupDetailDTO;
import cn.com.glsx.dj.strategy.dto.projectgroup.ProjectGroupIdDTO; import cn.com.glsx.dj.strategy.dto.projectgroup.ProjectGroupIdDTO;
import cn.com.glsx.dj.strategy.dto.projectgroup.ProjectGroupListDTO; import cn.com.glsx.dj.strategy.dto.projectgroup.ProjectGroupListDTO;
import cn.com.glsx.dj.strategy.dto.projectgroup.ProjectGroupMetricQueryDTO; import cn.com.glsx.dj.strategy.dto.projectgroup.ProjectGroupMetricQueryDTO;
import cn.com.glsx.dj.strategy.dto.projectgroup.ProjectGroupOptionDTO;
import cn.com.glsx.dj.strategy.dto.projectgroup.ProjectGroupQueryDTO; import cn.com.glsx.dj.strategy.dto.projectgroup.ProjectGroupQueryDTO;
import cn.com.glsx.dj.strategy.dto.projectgroup.ProjectGroupSaveDTO; import cn.com.glsx.dj.strategy.dto.projectgroup.ProjectGroupSaveDTO;
import cn.com.glsx.dj.strategy.dto.projectgroup.ProjectGroupStoreBatchAddDTO; import cn.com.glsx.dj.strategy.dto.projectgroup.ProjectGroupStoreBatchAddDTO;
...@@ -40,6 +41,17 @@ public interface ProjectGroupRemote { ...@@ -40,6 +41,17 @@ public interface ProjectGroupRemote {
RpcResponse<RpcPagination<ProjectGroupListDTO>> pageProjectGroup(RpcPagination<ProjectGroupQueryDTO> pagination); RpcResponse<RpcPagination<ProjectGroupListDTO>> pageProjectGroup(RpcPagination<ProjectGroupQueryDTO> pagination);
/** /**
* 查询项目组下拉列表。
*
* @param queryDTO 查询参数
* @return 项目组下拉列表
*/
@ApiMethod("查询项目组下拉列表")
@ApiParam(name = "queryDTO", notes = "查询参数", dataType = ApiParam.DataTypeEnum.OBJECT, required = true)
@ApiResponse("项目组下拉列表")
RpcResponse<List<ProjectGroupOptionDTO>> listProjectGroups(ProjectGroupQueryDTO queryDTO);
/**
* 查询项目组详情。 * 查询项目组详情。
* *
* @param groupIdDTO 项目组主键 * @param groupIdDTO 项目组主键
......
...@@ -25,6 +25,11 @@ public interface StrategyInfoRemote { ...@@ -25,6 +25,11 @@ public interface StrategyInfoRemote {
@ApiResponse("结果") @ApiResponse("结果")
RpcResponse<Boolean> batchCreate(BatchInsertStrategyInfo batchStrategyInfo); RpcResponse<Boolean> batchCreate(BatchInsertStrategyInfo batchStrategyInfo);
@ApiMethod("新增单个策略")
@ApiParam(name = "strategyInfo", notes = "策略信息(包含 merchantId/merchantName 以及 staffList/courseList/recordingList 等关联信息)", dataType = ApiParam.DataTypeEnum.OBJECT, required = true)
@ApiResponse("新创建的策略主键id")
RpcResponse<Integer> create(StrategyInfo strategyInfo);
@ApiMethod("删除策略") @ApiMethod("删除策略")
@ApiParam(name = "strategyInfo", notes = "策略信息", dataType = ApiParam.DataTypeEnum.OBJECT, required = true) @ApiParam(name = "strategyInfo", notes = "策略信息", dataType = ApiParam.DataTypeEnum.OBJECT, required = true)
@ApiResponse("结果") @ApiResponse("结果")
...@@ -71,10 +76,10 @@ public interface StrategyInfoRemote { ...@@ -71,10 +76,10 @@ public interface StrategyInfoRemote {
@ApiResponse("驻店员工分页列表") @ApiResponse("驻店员工分页列表")
RpcResponse<RpcPagination<ShopMerchantStaffRespDTO>> listShopMerchantStaff(RpcPagination<ShopMerchantStaffReqDTO> pagination); RpcResponse<RpcPagination<ShopMerchantStaffRespDTO>> listShopMerchantStaff(RpcPagination<ShopMerchantStaffReqDTO> pagination);
@ApiMethod("查询门店区域督导(飞行督导)信息") @ApiMethod("查询门店区域督导(飞行督导)信息列表")
@ApiParam(name = "request", notes = "查询条件", dataType = ApiParam.DataTypeEnum.OBJECT, required = true) @ApiParam(name = "request", notes = "查询条件", dataType = ApiParam.DataTypeEnum.OBJECT, required = true)
@ApiResponse("区域督导(飞行督导)信息") @ApiResponse("区域督导(飞行督导)信息列表")
RpcResponse<ShopMerchantSupervisorRespDTO> getShopMerchantSupervisor(ShopMerchantSupervisorReqDTO request); RpcResponse<List<ShopMerchantSupervisorRespDTO>> getShopMerchantSupervisor(ShopMerchantSupervisorReqDTO request);
@ApiMethod("查询当前门店+业务下的全部区域运营") @ApiMethod("查询当前门店+业务下的全部区域运营")
@ApiParam(name = "request", notes = "查询条件", dataType = ApiParam.DataTypeEnum.OBJECT, required = true) @ApiParam(name = "request", notes = "查询条件", dataType = ApiParam.DataTypeEnum.OBJECT, required = true)
......
package cn.com.glsx.dj.strategy.remote;
import cn.com.glsx.dj.strategy.dto.warning.WarningConfigCreateRequest;
import cn.com.glsx.dj.strategy.dto.warning.WarningConfigDTO;
import cn.com.glsx.dj.strategy.dto.warning.WarningConfigQueryRequest;
import cn.com.glsx.framework.core.annotation.ApiMethod;
import cn.com.glsx.framework.core.annotation.ApiParam;
import cn.com.glsx.framework.core.annotation.ApiResponse;
import cn.com.glsx.framework.core.beans.rpc.RpcResponse;
import java.util.List;
/**
* 预警配置管理远程接口。
*
* @author yangwei_by_claude
* @version 1.0
* @since 2026/05/28 14:00
*/
public interface WarningConfigRemote {
/**
* 配置列表。
*
* @param request 查询参数
* @return 配置列表
*/
@ApiMethod("配置列表")
@ApiParam(name = "request", notes = "查询参数", dataType = ApiParam.DataTypeEnum.OBJECT, required = true)
@ApiResponse("配置列表")
RpcResponse<List<WarningConfigDTO>> listConfigs(WarningConfigQueryRequest request);
/**
* 创建配置。
*
* @param request 创建参数
* @return 是否成功
*/
@ApiMethod("创建配置")
@ApiParam(name = "request", notes = "创建参数", dataType = ApiParam.DataTypeEnum.OBJECT, required = true)
@ApiResponse("是否成功")
RpcResponse<Boolean> createConfig(WarningConfigCreateRequest request);
/**
* 更新配置。
*
* @param request 更新参数
* @return 是否成功
*/
@ApiMethod("更新配置")
@ApiParam(name = "request", notes = "更新参数", dataType = ApiParam.DataTypeEnum.OBJECT, required = true)
@ApiResponse("是否成功")
RpcResponse<Boolean> updateConfig(WarningConfigCreateRequest request);
/**
* 删除配置。
*
* @param configId 配置ID
* @return 是否成功
*/
@ApiMethod("删除配置")
@ApiParam(name = "configId", notes = "配置ID", dataType = ApiParam.DataTypeEnum.INT, required = true)
@ApiResponse("是否成功")
RpcResponse<Boolean> deleteConfig(Integer configId);
/**
* 启用/禁用配置。
*
* @param configId 配置ID
* @param isEnabled 1=启用 0=禁用
* @return 是否成功
*/
@ApiMethod("启用/禁用")
@ApiParam(name = "configId", notes = "配置ID", dataType = ApiParam.DataTypeEnum.INT, required = true)
@ApiResponse("是否成功")
RpcResponse<Boolean> toggleEnable(Integer configId, Integer isEnabled);
}
package cn.com.glsx.dj.strategy.remote;
import cn.com.glsx.dj.strategy.dto.projectgroup.GroupOptionDTO;
import cn.com.glsx.dj.strategy.dto.projectgroup.MetricOptionDTO;
import cn.com.glsx.dj.strategy.dto.projectgroup.ProjectGroupMetricQueryDTO;
import cn.com.glsx.dj.strategy.dto.projectgroup.WarningTypeOptionDTO;
import cn.com.glsx.dj.strategy.dto.warning.EffectAnalysisDTO;
import cn.com.glsx.dj.strategy.dto.warning.EffectAnalysisRequest;
import cn.com.glsx.dj.strategy.dto.warning.StoreWarningSummaryDTO;
import cn.com.glsx.framework.core.beans.rpc.RpcPagination;
import cn.com.glsx.dj.strategy.dto.warning.WarningRecordDTO;
import cn.com.glsx.dj.strategy.dto.warning.WarningRecordQueryRequest;
import cn.com.glsx.framework.core.annotation.ApiMethod;
import cn.com.glsx.framework.core.annotation.ApiParam;
import cn.com.glsx.framework.core.annotation.ApiResponse;
import cn.com.glsx.framework.core.beans.rpc.RpcResponse;
import java.util.List;
/**
* 预警引擎查询远程接口。
*
* @author yangwei_by_claude
* @version 1.0
* @since 2026/05/28 14:00
*/
public interface WarningEngineRemote {
/**
* 门店预警汇总列表。
*
* @param request 查询参数
* @return 门店预警汇总列表
*/
@ApiMethod("门店预警汇总列表")
@ApiParam(name = "request", notes = "查询参数", dataType = ApiParam.DataTypeEnum.OBJECT, required = true)
@ApiResponse("门店预警汇总列表")
RpcResponse<List<StoreWarningSummaryDTO>> findWarningSummary(WarningRecordQueryRequest request);
/**
* 指定门店+员工预警明细。
*
* @param request 查询参数(含storeId/staffId)
* @return 预警明细列表
*/
@ApiMethod("指定门店员工预警明细")
@ApiParam(name = "request", notes = "查询参数", dataType = ApiParam.DataTypeEnum.OBJECT, required = true)
@ApiResponse("预警明细列表")
RpcResponse<List<WarningRecordDTO>> findWarningDetailByStoreAndStaff(WarningRecordQueryRequest request);
/**
* 预警类型下拉。
*
* @return 预警类型列表
*/
@ApiMethod("预警类型下拉")
@ApiResponse("预警类型列表")
RpcResponse<List<WarningTypeOptionDTO>> listWarningTypes();
/**
* 指标类型下拉。
*
* @param queryDTO 查询参数
* @return 指标列表
*/
@ApiMethod("指标类型下拉")
@ApiParam(name = "queryDTO", notes = "查询参数", dataType = ApiParam.DataTypeEnum.OBJECT, required = true)
@ApiResponse("指标列表")
RpcResponse<List<MetricOptionDTO>> listMetrics(ProjectGroupMetricQueryDTO queryDTO);
/**
* 效果分析——当前周期 vs 下一周期指标对比。
*
* @param request 查询参数
* @return 效果分析列表
*/
@ApiMethod("效果分析")
@ApiParam(name = "request", notes = "查询参数", dataType = ApiParam.DataTypeEnum.OBJECT, required = true)
@ApiResponse("效果分析列表")
RpcResponse<RpcPagination<EffectAnalysisDTO>> analysisEffect(EffectAnalysisRequest request);
/**
* 项目组下拉列表。
*
* @return 项目组列表
*/
@ApiMethod("项目组下拉列表")
@ApiResponse("项目组列表")
RpcResponse<List<GroupOptionDTO>> listGroups();
}
...@@ -15,6 +15,16 @@ ...@@ -15,6 +15,16 @@
<packaging>war</packaging> <packaging>war</packaging>
<dependencies> <dependencies>
<dependency> <dependency>
<groupId>cn.com.glsx.dj</groupId>
<artifactId>rpc-dj-taskcenter-api</artifactId>
<version>1.0.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>cn.com.glsx.dj</groupId>
<artifactId>rpc-dj-supervisor-api</artifactId>
<version>5.8.2-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>cn.com.glsx</groupId> <groupId>cn.com.glsx</groupId>
<artifactId>rpc-dj-mindworkplate-api</artifactId> <artifactId>rpc-dj-mindworkplate-api</artifactId>
<version>5.6.1-SNAPSHOT</version> <version>5.6.1-SNAPSHOT</version>
......
...@@ -22,4 +22,10 @@ public class KafkaTopicConfig { ...@@ -22,4 +22,10 @@ public class KafkaTopicConfig {
*/ */
@Value("${kafka.topic.unfinished-strategy-staff-topic:UNFINISHED_STRATEGY_STAFF_TOPIC}") @Value("${kafka.topic.unfinished-strategy-staff-topic:UNFINISHED_STRATEGY_STAFF_TOPIC}")
private String unfinishedStrategyStaffTopic; private String unfinishedStrategyStaffTopic;
/**
* 策略创建成功主题
*/
@Value("${kafka.topic.strategy-created-topic:STRATEGY_CREATED_TOPIC}")
private String strategyCreatedTopic;
} }
\ No newline at end of file \ No newline at end of file
package cn.com.glsx.dj.strategy.config;
import cn.com.glsx.dj.supervisor.remote.SupervisorSpecialCoachApprovalRemote;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class SupervisorDubboConfig extends DubboConfig {
@Bean
public SupervisorSpecialCoachApprovalRemote supervisorSpecialCoachApprovalRemote() {
return factory.builder(SupervisorSpecialCoachApprovalRemote.class).check(check).timeout(timeout).version("1.0.0").build();
}
}
package cn.com.glsx.dj.strategy.config;
import cn.com.glsx.dj.taskcenter.remote.TaskCenterRemote;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class TaskCenterDubboConfig extends DubboConfig {
@Bean
public TaskCenterRemote taskCenterRemote() {
return factory.builder(TaskCenterRemote.class).check(check).timeout(timeout).version("1.0.0").build();
}
}
package cn.com.glsx.dj.strategy.job;
import cn.com.glsx.dj.strategy.dto.warning.PeriodRange;
import cn.com.glsx.dj.strategy.enums.ProjectGroupBizEnum;
import cn.com.glsx.dj.strategy.enums.TimeDimensionEnum;
import cn.com.glsx.dj.strategy.mapper.PgGroupInfoMapper;
import cn.com.glsx.dj.strategy.mapper.PgGroupStoreRelMapper;
import cn.com.glsx.dj.strategy.model.projectgroup.PgGroupInfo;
import cn.com.glsx.dj.strategy.service.warning.StoreOutputService;
import cn.com.glsx.dj.strategy.service.warning.WarningEngineService;
import cn.hutool.core.date.DateUtil;
import com.dangdang.ddframe.job.api.ShardingContext;
import com.dangdang.ddframe.job.api.simple.SimpleJob;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.oreframework.boot.autoconfigure.elasticjob.annotation.ElasticJobConf;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
/**
* 预警计算定时任务——每天执行,计算有产值门店和预警数据。
*
* <p>执行顺序:有产值门店 → 门店维度预警 → 员工维度预警。</p>
*
* @author yangwei_by_claude
* @version 1.0
* @since 2026/05/28 14:00
*/
@Slf4j
@Component
@ElasticJobConf(name = "WarningComputeJob", cron = "0 0 2 * * ?", description = "预警计算定时任务", overwrite = false)
public class WarningComputeJob implements SimpleJob {
@Resource
private StoreOutputService storeOutputService;
@Resource
private WarningEngineService warningEngineService;
@Resource
private PgGroupInfoMapper groupInfoMapper;
@Resource
private PgGroupStoreRelMapper storeRelMapper;
private final ExecutorService dataQueryExecutor = Executors.newFixedThreadPool(10);
@Override
public void execute(ShardingContext shardingContext) {
log.info("预警计算定时任务开始执行");
Date today = new Date();
try {
// Step 1: 计算有产值门店(四种维度 × 三种业务)
storeOutputService.computeAll(today);
// Step 2: 加载所有启用项目组,并行计算预警
List<PgGroupInfo> groups = groupInfoMapper.selectAllEnabled();
if (CollectionUtils.isEmpty(groups)) {
log.info("无启用项目组,跳过预警计算");
return;
}
for (TimeDimensionEnum dim : TimeDimensionEnum.values()) {
PeriodRange range = dim.calculate(today);
for (ProjectGroupBizEnum biz : ProjectGroupBizEnum.values()) {
// 从 pg_store_output 获取有产值门店
List<Integer> outputStoreIds = storeOutputService.listStoreIdsWithOutput(
biz.getBiz(), dim.getCode(),
DateUtil.format(range.getStart(), "yyyy-MM-dd"),
DateUtil.format(range.getEnd(), "yyyy-MM-dd"));
if (CollectionUtils.isEmpty(outputStoreIds)) {
log.info("无有产值门店,跳过,biz={}, dim={}", biz.getBiz(), dim.getCode());
continue;
}
// 按项目组并行计算
List<CompletableFuture<Void>> futures = new ArrayList<>();
for (PgGroupInfo group : groups) {
futures.add(CompletableFuture.runAsync(() -> {
try {
// 项目组门店 ∩ 有产值门店
List<Integer> groupStoreIds = storeRelMapper.listMerchantIdsByGroupId(group.getId());
if (CollectionUtils.isEmpty(groupStoreIds)) {
return;
}
List<Integer> intersection = new ArrayList<>(groupStoreIds);
intersection.retainAll(outputStoreIds);
if (intersection.isEmpty()) {
return;
}
// 门店+员工维度预警(monitorTarget区分,引擎内自动处理)
warningEngineService.computeWarnings(dim.getCode(),
range.getStart(), range.getEnd(), biz.getBiz(), intersection);
} catch (Exception e) {
log.error("项目组预警计算失败,groupId={}, biz={}, dim={}",
group.getId(), biz.getBiz(), dim.getCode(), e);
}
}, dataQueryExecutor));
}
// 等待全部项目组计算完成
CompletableFuture.allOf(futures.toArray(new CompletableFuture[0])).join();
}
}
log.info("预警计算定时任务执行完成");
} catch (Exception e) {
log.error("预警计算定时任务执行异常", e);
}
}
}
package cn.com.glsx.dj.strategy.job;
import cn.com.glsx.dj.strategy.dto.warning.PeriodRange;
import cn.com.glsx.dj.strategy.enums.ProjectGroupBizEnum;
import cn.com.glsx.dj.strategy.enums.TimeDimensionEnum;
import cn.com.glsx.dj.strategy.mapper.PgGroupInfoMapper;
import cn.com.glsx.dj.strategy.service.warning.StoreOutputService;
import cn.com.glsx.dj.strategy.service.warning.WarningEngineService;
import com.dangdang.ddframe.job.api.ShardingContext;
import com.dangdang.ddframe.job.api.simple.SimpleJob;
import lombok.extern.slf4j.Slf4j;
import org.oreframework.boot.autoconfigure.elasticjob.annotation.ElasticJobConf;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.util.Calendar;
import java.util.Date;
/**
* 历史数据补跑定时任务——从 2026 年 1 月 1 日起逐周期回溯计算。
*
* <p>按周/月/截止周最新一天/截止月最新一天逐周期回溯,写入 warning_record 和 pg_store_output。
* 一次性执行,跑完后通过持久化标记跳过重复执行。</p>
*
* @author yangwei_by_claude
* @version 1.0
* @since 2026/05/28 14:00
*/
@Slf4j
@Component
@ElasticJobConf(name = "WarningHistoryBackfillJob", cron = "0 0 3 * * ?", description = "历史数据补跑定时任务", overwrite = false)
public class WarningHistoryBackfillJob implements SimpleJob {
@Resource
private StoreOutputService storeOutputService;
@Resource
private WarningEngineService warningEngineService;
@Resource
private PgGroupInfoMapper groupInfoMapper;
/** 历史数据起始日期:2026-01-01 */
private static final Date BACKFILL_START = getBackfillStartDate();
/** Redis key 标记是否已完成 */
private static final String BACKFILL_DONE_KEY = "warning:history:backfill:done";
@Override
public void execute(ShardingContext shardingContext) {
log.info("历史数据补跑任务开始执行");
try {
// TODO: 检查 Redis 标记,已执行过则跳过
// if (redisTemplate.hasKey(BACKFILL_DONE_KEY)) { skip }
Calendar startCal = Calendar.getInstance();
startCal.setTime(BACKFILL_START);
Calendar endCal = Calendar.getInstance();
endCal.setTime(new Date());
// 逐周回溯
Calendar weekCursor = (Calendar) startCal.clone();
while (weekCursor.before(endCal)) {
Date cursorDate = weekCursor.getTime();
PeriodRange weekRange = TimeDimensionEnum.W.calculate(cursorDate);
PeriodRange ldwRange = TimeDimensionEnum.LDW.calculate(cursorDate);
for (ProjectGroupBizEnum biz : ProjectGroupBizEnum.values()) {
storeOutputService.computeStoreOutputs(biz.getBiz(),
TimeDimensionEnum.W.getCode(), weekRange);
storeOutputService.computeStoreOutputs(biz.getBiz(),
TimeDimensionEnum.LDW.getCode(), ldwRange);
}
weekCursor.add(Calendar.WEEK_OF_YEAR, 1);
}
// 逐月回溯
Calendar monthCursor = (Calendar) startCal.clone();
while (monthCursor.before(endCal)) {
Date cursorDate = monthCursor.getTime();
PeriodRange monthRange = TimeDimensionEnum.M.calculate(cursorDate);
PeriodRange ldmRange = TimeDimensionEnum.LDM.calculate(cursorDate);
for (ProjectGroupBizEnum biz : ProjectGroupBizEnum.values()) {
storeOutputService.computeStoreOutputs(biz.getBiz(),
TimeDimensionEnum.M.getCode(), monthRange);
storeOutputService.computeStoreOutputs(biz.getBiz(),
TimeDimensionEnum.LDM.getCode(), ldmRange);
}
monthCursor.add(Calendar.MONTH, 1);
}
// TODO: 标记完成 Redis set(BACKFILL_DONE_KEY, "1")
log.info("历史数据补跑任务执行完成");
} catch (Exception e) {
log.error("历史数据补跑任务执行异常", e);
}
}
private static Date getBackfillStartDate() {
Calendar cal = Calendar.getInstance();
cal.set(2026, Calendar.JANUARY, 1, 0, 0, 0);
cal.set(Calendar.MILLISECOND, 0);
return cal.getTime();
}
}
package cn.com.glsx.dj.strategy.mapper;
import cn.com.glsx.dj.mindworkplate.model.EcoCoefficientRule;
import org.apache.ibatis.annotations.Mapper;
import org.oreframework.datasource.mybatis.mapper.OreMapper;
import java.util.List;
/**
* 生态系数规则 Mapper(复用 eco_coefficient_rule 表)。
*
* @author yangwei_by_claude
* @version 1.0
* @since 2026/05/28 14:00
*/
@Mapper
public interface EcoCoefficientRuleMapper extends OreMapper<EcoCoefficientRule> {
/**
* 查询所有启用的生态系数规则(按排序字段升序)。
*
* @return 规则列表
*/
List<EcoCoefficientRule> selectAllEnabled();
}
package cn.com.glsx.dj.strategy.mapper; package cn.com.glsx.dj.strategy.mapper;
import cn.com.glsx.dj.strategy.dto.projectgroup.ProjectGroupListDTO; import cn.com.glsx.dj.strategy.dto.projectgroup.ProjectGroupListDTO;
import cn.com.glsx.dj.strategy.dto.projectgroup.ProjectGroupOptionDTO;
import cn.com.glsx.dj.strategy.dto.projectgroup.ProjectGroupQueryDTO; import cn.com.glsx.dj.strategy.dto.projectgroup.ProjectGroupQueryDTO;
import cn.com.glsx.dj.strategy.model.projectgroup.PgGroupInfo; import cn.com.glsx.dj.strategy.model.projectgroup.PgGroupInfo;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
...@@ -10,6 +11,10 @@ import java.util.List; ...@@ -10,6 +11,10 @@ import java.util.List;
/** /**
* 项目组主表 Mapper。 * 项目组主表 Mapper。
*
* @author yangwei_by_claude
* @version 1.0
* @since 2026/05/28 14:00
*/ */
@Mapper @Mapper
public interface PgGroupInfoMapper extends OreMapper<PgGroupInfo> { public interface PgGroupInfoMapper extends OreMapper<PgGroupInfo> {
...@@ -21,4 +26,19 @@ public interface PgGroupInfoMapper extends OreMapper<PgGroupInfo> { ...@@ -21,4 +26,19 @@ public interface PgGroupInfoMapper extends OreMapper<PgGroupInfo> {
* @return 项目组列表 * @return 项目组列表
*/ */
List<ProjectGroupListDTO> selectProjectGroupPage(ProjectGroupQueryDTO queryDTO); List<ProjectGroupListDTO> selectProjectGroupPage(ProjectGroupQueryDTO queryDTO);
/**
* 查询所有启用的项目组(用于定时任务)。
*
* @return 项目组列表
*/
List<PgGroupInfo> selectAllEnabled();
/**
* 查询项目组下拉列表。
*
* @param queryDTO 查询条件
* @return 项目组下拉列表
*/
List<ProjectGroupOptionDTO> selectProjectGroupOptions(ProjectGroupQueryDTO queryDTO);
} }
...@@ -12,6 +12,10 @@ import java.util.Map; ...@@ -12,6 +12,10 @@ import java.util.Map;
/** /**
* 项目组门店关系 Mapper。 * 项目组门店关系 Mapper。
*
* @author yangwei_by_claude
* @version 1.0
* @since 2026/05/28 14:00
*/ */
@Mapper @Mapper
public interface PgGroupStoreRelMapper extends OreMapper<PgGroupStoreRel> { public interface PgGroupStoreRelMapper extends OreMapper<PgGroupStoreRel> {
......
package cn.com.glsx.dj.strategy.mapper;
import cn.com.glsx.dj.strategy.model.projectgroup.PgStoreOutput;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.oreframework.datasource.mybatis.mapper.OreMapper;
import java.util.List;
/**
* 有产值门店记录 Mapper。
*
* @author yangwei_by_claude
* @version 1.0
* @since 2026/05/28 14:00
*/
@Mapper
public interface PgStoreOutputMapper extends OreMapper<PgStoreOutput> {
/**
* 按条件查询有产值门店列表。
*
* @param businessType 业务类型
* @param timeDimension 时间维度
* @param periodStart 周期开始
* @param periodEnd 周期结束
* @return 有产值门店列表
*/
List<PgStoreOutput> selectByCondition(@Param("businessType") Integer businessType,
@Param("timeDimension") String timeDimension,
@Param("periodStart") String periodStart,
@Param("periodEnd") String periodEnd);
/**
* 按条件删除(幂等重算用)。
*
* @param businessType 业务类型
* @param timeDimension 时间维度
* @param periodStart 周期开始
* @param periodEnd 周期结束
* @return 删除条数
*/
int deleteByCondition(@Param("businessType") Integer businessType,
@Param("timeDimension") String timeDimension,
@Param("periodStart") String periodStart,
@Param("periodEnd") String periodEnd);
/**
* 批量插入有产值门店记录。
*
* @param list 记录列表
* @return 插入条数
*/
int batchInsert(@Param("list") List<PgStoreOutput> list);
}
...@@ -10,6 +10,10 @@ import java.util.Map; ...@@ -10,6 +10,10 @@ import java.util.Map;
/** /**
* 项目组预警配置 Mapper。 * 项目组预警配置 Mapper。
*
* @author yangwei_by_claude
* @version 1.0
* @since 2026/05/28 14:00
*/ */
@Mapper @Mapper
public interface PgWarningConfigMapper extends OreMapper<PgWarningConfig> { public interface PgWarningConfigMapper extends OreMapper<PgWarningConfig> {
...@@ -21,4 +25,27 @@ public interface PgWarningConfigMapper extends OreMapper<PgWarningConfig> { ...@@ -21,4 +25,27 @@ public interface PgWarningConfigMapper extends OreMapper<PgWarningConfig> {
* @return 统计结果 * @return 统计结果
*/ */
List<Map<String, Object>> countActiveByGroupIds(@Param("groupIds") List<Integer> groupIds); List<Map<String, Object>> countActiveByGroupIds(@Param("groupIds") List<Integer> groupIds);
/**
* 查询项目组下所有启用的配置。
*
* @param groupId 项目组ID
* @return 配置列表
*/
List<PgWarningConfig> selectEnabledByGroupId(@Param("groupId") Integer groupId);
/**
* 查询所有启用的配置(用于定时任务)。
*
* @return 配置列表
*/
List<PgWarningConfig> selectAllEnabled();
/**
* 按预警类型查询所有启用的配置(用于效果分析获取全部指标)。
*
* @param warningType 预警类型: 5=黄色预警 4=红色预警 3=生态预警 2=兜底预警
* @return 配置列表
*/
List<PgWarningConfig> selectEnabledByWarningType(@Param("warningType") Integer warningType);
} }
...@@ -11,6 +11,10 @@ import java.util.List; ...@@ -11,6 +11,10 @@ import java.util.List;
/** /**
* 预警指标字典 Mapper。 * 预警指标字典 Mapper。
*
* @author yangwei_by_claude
* @version 1.0
* @since 2026/05/28 14:00
*/ */
@Mapper @Mapper
public interface PgWarningMetricDictMapper extends OreMapper<PgWarningMetricDict> { public interface PgWarningMetricDictMapper extends OreMapper<PgWarningMetricDict> {
...@@ -22,4 +26,14 @@ public interface PgWarningMetricDictMapper extends OreMapper<PgWarningMetricDict ...@@ -22,4 +26,14 @@ public interface PgWarningMetricDictMapper extends OreMapper<PgWarningMetricDict
* @return 指标元数据列表 * @return 指标元数据列表
*/ */
List<MetricOptionDTO> listMetrics(@Param("queryDTO") ProjectGroupMetricQueryDTO queryDTO); List<MetricOptionDTO> listMetrics(@Param("queryDTO") ProjectGroupMetricQueryDTO queryDTO);
/**
* 按预警类型+业务线查询所有指标基础数据(用于效果分析批量获取 dataType/unit/categoryExtension)。
*
* @param warningType 预警类型
* @param biz 业务类型
* @return 指标字典列表
*/
List<PgWarningMetricDict> selectByWarningTypeAndBiz(@Param("warningType") Integer warningType,
@Param("biz") Integer biz);
} }
...@@ -4,12 +4,17 @@ import cn.com.glsx.dj.strategy.dto.projectgroup.ProjectGroupWarningRecordDTO; ...@@ -4,12 +4,17 @@ import cn.com.glsx.dj.strategy.dto.projectgroup.ProjectGroupWarningRecordDTO;
import cn.com.glsx.dj.strategy.dto.projectgroup.ProjectGroupWarningRecordQueryDTO; import cn.com.glsx.dj.strategy.dto.projectgroup.ProjectGroupWarningRecordQueryDTO;
import cn.com.glsx.dj.strategy.model.projectgroup.PgWarningRecord; import cn.com.glsx.dj.strategy.model.projectgroup.PgWarningRecord;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.oreframework.datasource.mybatis.mapper.OreMapper; import org.oreframework.datasource.mybatis.mapper.OreMapper;
import java.util.List; import java.util.List;
/** /**
* 预警结果 Mapper。 * 预警结果 Mapper。
*
* @author yangwei_by_claude
* @version 1.0
* @since 2026/05/28 14:00
*/ */
@Mapper @Mapper
public interface PgWarningRecordMapper extends OreMapper<PgWarningRecord> { public interface PgWarningRecordMapper extends OreMapper<PgWarningRecord> {
...@@ -21,4 +26,26 @@ public interface PgWarningRecordMapper extends OreMapper<PgWarningRecord> { ...@@ -21,4 +26,26 @@ public interface PgWarningRecordMapper extends OreMapper<PgWarningRecord> {
* @return 预警结果列表 * @return 预警结果列表
*/ */
List<ProjectGroupWarningRecordDTO> listWarningRecordsByCondition(ProjectGroupWarningRecordQueryDTO queryDTO); List<ProjectGroupWarningRecordDTO> listWarningRecordsByCondition(ProjectGroupWarningRecordQueryDTO queryDTO);
/**
* 批量插入预警记录。
*
* @param records 预警记录列表
* @return 插入条数
*/
int batchInsert(@Param("records") List<PgWarningRecord> records);
/**
* 按条件删除预警记录(用于幂等重算)。
*
* @param configId 配置ID
* @param timeDimension 时间维度
* @param periodStart 周期开始
* @param periodEnd 周期结束
* @return 删除条数
*/
int deleteByCondition(@Param("configId") Integer configId,
@Param("timeDimension") String timeDimension,
@Param("periodStart") String periodStart,
@Param("periodEnd") String periodEnd);
} }
...@@ -5,7 +5,11 @@ import org.apache.ibatis.annotations.Mapper; ...@@ -5,7 +5,11 @@ import org.apache.ibatis.annotations.Mapper;
import org.oreframework.datasource.mybatis.mapper.OreMapper; import org.oreframework.datasource.mybatis.mapper.OreMapper;
/** /**
* 预警类型字典 Mapper。 * 预警类型字典 Mapper(基础 CRUD 由 OreMapper 提供)。
*
* @author yangwei_by_claude
* @version 1.0
* @since 2026/05/28 14:00
*/ */
@Mapper @Mapper
public interface PgWarningTypeDictMapper extends OreMapper<PgWarningTypeDict> { public interface PgWarningTypeDictMapper extends OreMapper<PgWarningTypeDict> {
......
...@@ -29,4 +29,14 @@ public interface ShopMerchantDirectorConfigMapper extends OreMapper<ShopMerchant ...@@ -29,4 +29,14 @@ public interface ShopMerchantDirectorConfigMapper extends OreMapper<ShopMerchant
*/ */
List<ShopMerchantDirectorConfig> selectByMerchantIdAndType(@Param("merchantId") Integer merchantId, List<ShopMerchantDirectorConfig> selectByMerchantIdAndType(@Param("merchantId") Integer merchantId,
@Param("directorType") Integer directorType); @Param("directorType") Integer directorType);
/**
* 根据负责人用户ID和负责人类型查询关联的门店号列表。
*
* @param uuid 负责人用户ID
* @param typeValue 负责人类型(DirectorTypeEnum byte值)
* @return 门店号列表
*/
List<Integer> findMerchantIdsByUUidAndType(@Param("uuid") String uuid,
@Param("typeValue") byte typeValue);
} }
...@@ -95,4 +95,18 @@ public interface StrategyInfoMapper extends OreMapper<StrategyInfo> { ...@@ -95,4 +95,18 @@ public interface StrategyInfoMapper extends OreMapper<StrategyInfo> {
* @return * @return
*/ */
List<String> selectStaffTempSupport(@Param("merchantId") Integer merchantId, @Param("yearMonth") String yearMonth, @Param("userUuidList") List<String> userUuidList); List<String> selectStaffTempSupport(@Param("merchantId") Integer merchantId, @Param("yearMonth") String yearMonth, @Param("userUuidList") List<String> userUuidList);
/**
* 查询指定业务+周期内有策略记录的门店号列表。
*
* @param biz 业务类型
* @param merchantIds 门店号列表
* @param startDate 周期开始日期
* @param endDate 周期结束日期
* @return 有策略记录的门店号列表
*/
List<Integer> listMerchantIdsWithStrategy(@Param("biz") Integer biz,
@Param("merchantIds") List<Integer> merchantIds,
@Param("startDate") String startDate,
@Param("endDate") String endDate);
} }
\ No newline at end of file \ No newline at end of file
...@@ -22,9 +22,8 @@ import java.util.List; ...@@ -22,9 +22,8 @@ import java.util.List;
@Component @Component
public class StrategyPushConsumer extends KafkaConsumer { public class StrategyPushConsumer extends KafkaConsumer {
/** 新推送逻辑覆盖的策略类型 */ /** 新推送逻辑覆盖的策略类型(排除带教申请,已迁移至 StrategyCreatedConsumer) */
private static final List<Integer> NEW_PUSH_STRATEGY_TYPES = Arrays.asList( private static final List<Integer> NEW_PUSH_STRATEGY_TYPES = Arrays.asList(
StrategyTypeEnum.MENTORING_APPLICATION.getValue(),
StrategyTypeEnum.PERSONNEL_CHANGE_EVAL.getValue(), StrategyTypeEnum.PERSONNEL_CHANGE_EVAL.getValue(),
StrategyTypeEnum.BUSINESS_POLICY_UPDATE_EVAL.getValue(), StrategyTypeEnum.BUSINESS_POLICY_UPDATE_EVAL.getValue(),
StrategyTypeEnum.MULTI_CATEGORY_EXPANSION.getValue(), StrategyTypeEnum.MULTI_CATEGORY_EXPANSION.getValue(),
...@@ -95,10 +94,7 @@ public class StrategyPushConsumer extends KafkaConsumer { ...@@ -95,10 +94,7 @@ public class StrategyPushConsumer extends KafkaConsumer {
Integer strategyType = strategyInfo.getStrategyType(); Integer strategyType = strategyInfo.getStrategyType();
log.info("进入新推送逻辑,strategyId:{}, strategyType:{}", strategyInfo.getId(), strategyType); log.info("进入新推送逻辑,strategyId:{}, strategyType:{}", strategyInfo.getId(), strategyType);
if (StrategyTypeEnum.MENTORING_APPLICATION.getValue().equals(strategyType)) { if (Arrays.asList(
// 8-带教申请
processMentoringApplication(strategyInfo);
} else if (Arrays.asList(
StrategyTypeEnum.PERSONNEL_CHANGE_EVAL.getValue(), StrategyTypeEnum.PERSONNEL_CHANGE_EVAL.getValue(),
StrategyTypeEnum.BUSINESS_POLICY_UPDATE_EVAL.getValue(), StrategyTypeEnum.BUSINESS_POLICY_UPDATE_EVAL.getValue(),
StrategyTypeEnum.MULTI_CATEGORY_EXPANSION.getValue(), StrategyTypeEnum.MULTI_CATEGORY_EXPANSION.getValue(),
...@@ -109,14 +105,6 @@ public class StrategyPushConsumer extends KafkaConsumer { ...@@ -109,14 +105,6 @@ public class StrategyPushConsumer extends KafkaConsumer {
} }
/** /**
* 8-带教申请 推送处理
*/
private void processMentoringApplication(StrategyInfo strategyInfo) {
log.info("带教申请推送处理开始,strategyId:{}", strategyInfo.getId());
strategyInfoService.sendMentoringApplicationQWMessage(strategyInfo);
}
/**
* 9-人员更换评估、10-商务政策更新评估、11-多品类拓张、12-流量问题改善 推送处理 * 9-人员更换评估、10-商务政策更新评估、11-多品类拓张、12-流量问题改善 推送处理
*/ */
private void processWorktoolStrategy(StrategyInfo strategyInfo) { private void processWorktoolStrategy(StrategyInfo strategyInfo) {
......
...@@ -6,6 +6,7 @@ import cn.com.glsx.dj.strategy.dto.projectgroup.ProjectGroupDetailDTO; ...@@ -6,6 +6,7 @@ import cn.com.glsx.dj.strategy.dto.projectgroup.ProjectGroupDetailDTO;
import cn.com.glsx.dj.strategy.dto.projectgroup.ProjectGroupIdDTO; import cn.com.glsx.dj.strategy.dto.projectgroup.ProjectGroupIdDTO;
import cn.com.glsx.dj.strategy.dto.projectgroup.ProjectGroupListDTO; import cn.com.glsx.dj.strategy.dto.projectgroup.ProjectGroupListDTO;
import cn.com.glsx.dj.strategy.dto.projectgroup.ProjectGroupMetricQueryDTO; import cn.com.glsx.dj.strategy.dto.projectgroup.ProjectGroupMetricQueryDTO;
import cn.com.glsx.dj.strategy.dto.projectgroup.ProjectGroupOptionDTO;
import cn.com.glsx.dj.strategy.dto.projectgroup.ProjectGroupQueryDTO; import cn.com.glsx.dj.strategy.dto.projectgroup.ProjectGroupQueryDTO;
import cn.com.glsx.dj.strategy.dto.projectgroup.ProjectGroupSaveDTO; import cn.com.glsx.dj.strategy.dto.projectgroup.ProjectGroupSaveDTO;
import cn.com.glsx.dj.strategy.dto.projectgroup.ProjectGroupStoreBatchAddDTO; import cn.com.glsx.dj.strategy.dto.projectgroup.ProjectGroupStoreBatchAddDTO;
...@@ -52,6 +53,19 @@ public class ProjectGroupRemoteImpl implements ProjectGroupRemote { ...@@ -52,6 +53,19 @@ public class ProjectGroupRemoteImpl implements ProjectGroupRemote {
} }
@Override @Override
public RpcResponse<List<ProjectGroupOptionDTO>> listProjectGroups(ProjectGroupQueryDTO queryDTO) {
try {
return RpcResponse.success(projectGroupService.listProjectGroups(queryDTO));
} catch (RpcServiceException e) {
log.error("查询项目组下拉列表失败", e);
return RpcResponse.error(e.getError(), e.getMessage());
} catch (Exception e) {
log.error("查询项目组下拉列表异常", e);
return RpcResponse.error(DefaultErrorEnum.SERVICE_ERROR, e.getMessage());
}
}
@Override
public RpcResponse<ProjectGroupDetailDTO> getProjectGroupDetail(ProjectGroupIdDTO groupIdDTO) { public RpcResponse<ProjectGroupDetailDTO> getProjectGroupDetail(ProjectGroupIdDTO groupIdDTO) {
try { try {
return RpcResponse.success(projectGroupService.getProjectGroupDetail(groupIdDTO.getGroupId())); return RpcResponse.success(projectGroupService.getProjectGroupDetail(groupIdDTO.getGroupId()));
......
...@@ -62,6 +62,19 @@ public class StrategyInfoRemoteImpl implements StrategyInfoRemote { ...@@ -62,6 +62,19 @@ public class StrategyInfoRemoteImpl implements StrategyInfoRemote {
} }
@Override @Override
public RpcResponse<Integer> create(StrategyInfo strategyInfo) {
try {
return RpcResponse.success(strategyInfoService.create(strategyInfo));
} catch (RpcServiceException e) {
log.error(e.getMessage(), e);
return RpcResponse.error(e.getError(), e.getMessage());
} catch (Exception e) {
log.error(e.getMessage(), e);
return RpcResponse.error(DefaultErrorEnum.SERVICE_ERROR, e.getMessage());
}
}
@Override
public RpcResponse<Boolean> delete(StrategyInfo strategyInfo) { public RpcResponse<Boolean> delete(StrategyInfo strategyInfo) {
try { try {
return RpcResponse.success(strategyInfoService.delete(strategyInfo)); return RpcResponse.success(strategyInfoService.delete(strategyInfo));
...@@ -197,15 +210,15 @@ public class StrategyInfoRemoteImpl implements StrategyInfoRemote { ...@@ -197,15 +210,15 @@ public class StrategyInfoRemoteImpl implements StrategyInfoRemote {
} }
@Override @Override
public RpcResponse<ShopMerchantSupervisorRespDTO> getShopMerchantSupervisor(ShopMerchantSupervisorReqDTO request) { public RpcResponse<List<ShopMerchantSupervisorRespDTO>> getShopMerchantSupervisor(ShopMerchantSupervisorReqDTO request) {
try { try {
ShopMerchantSupervisorRespDTO result = shopMerchantService.getShopMerchantSupervisor(request); List<ShopMerchantSupervisorRespDTO> result = shopMerchantService.getShopMerchantSupervisor(request);
return RpcResponse.success(result); return RpcResponse.success(result);
} catch (RpcServiceException e) { } catch (RpcServiceException e) {
log.error("查询门店区域督导(飞行督导)信息 occur RpcServiceException", e); log.error("查询门店区域督导(飞行督导)信息列表 occur RpcServiceException", e);
return RpcResponse.error(e); return RpcResponse.error(e);
} catch (Exception e) { } catch (Exception e) {
log.error("查询门店区域督导(飞行督导)信息 occur Exception", e); log.error("查询门店区域督导(飞行督导)信息列表 occur Exception", e);
return RpcResponse.error(e); return RpcResponse.error(e);
} }
} }
......
...@@ -101,6 +101,20 @@ public class ProjectGroupService { ...@@ -101,6 +101,20 @@ public class ProjectGroupService {
} }
/** /**
* 查询项目组下拉列表。
*
* @param queryDTO 查询条件
* @return 项目组下拉列表
*/
public List<ProjectGroupOptionDTO> listProjectGroups(ProjectGroupQueryDTO queryDTO) {
log.info("查询项目组下拉列表,queryDTO: {}", queryDTO);
ProjectGroupQueryDTO condition = queryDTO == null ? new ProjectGroupQueryDTO() : queryDTO;
condition.setGroupName(StringUtils.trimToNull(condition.getGroupName()));
return Optional.ofNullable(pgGroupInfoMapper.selectProjectGroupOptions(condition))
.orElse(Collections.emptyList());
}
/**
* 查询项目组详情。 * 查询项目组详情。
* *
* @param groupId 项目组id * @param groupId 项目组id
......
...@@ -116,30 +116,33 @@ public class ShopMerchantService { ...@@ -116,30 +116,33 @@ public class ShopMerchantService {
} }
/** /**
* 根据门店商户号和业务类型查询区域督导(飞行督导)信息 * 根据门店商户号和业务类型查询区域督导(飞行督导)信息列表
* 业务类型映射规则: * 业务类型映射规则:
* 1-延保 → 2.1飞行督导(directorType=13) * 1-延保 → 2.1飞行督导(directorType=13)
* 2-轻改 → 1.1飞行督导(directorType=6) * 2-轻改 → 1.1飞行督导(directorType=6)
* 3-权益 → 2.1飞行督导(directorType=13) * 3-权益 → 2.1飞行督导(directorType=13)
* *
* @param condition 查询条件(门店商户号、业务类型) * @param condition 查询条件(门店商户号、业务类型)
* @return 区域督导(飞行督导)信息,最多一条 * @return 区域督导(飞行督导)信息列表
*/ */
public ShopMerchantSupervisorRespDTO getShopMerchantSupervisor(ShopMerchantSupervisorReqDTO condition) { public List<ShopMerchantSupervisorRespDTO> getShopMerchantSupervisor(ShopMerchantSupervisorReqDTO condition) {
Integer directorType = convertBusinessTypeToDirectorType(condition.getBusinessType()); Integer directorType = convertBusinessTypeToDirectorType(condition.getBusinessType());
List<ShopMerchantDirectorConfig> list = shopMerchantDirectorConfigMapper List<ShopMerchantDirectorConfig> list = shopMerchantDirectorConfigMapper
.selectByMerchantIdAndType(condition.getMerchantId(), directorType); .selectByMerchantIdAndType(condition.getMerchantId(), directorType);
if (CollectionUtils.isEmpty(list)) { if (CollectionUtils.isEmpty(list)) {
return null; return new ArrayList<>();
} }
ShopMerchantDirectorConfig config = list.get(0); List<ShopMerchantSupervisorRespDTO> result = new ArrayList<>();
for (ShopMerchantDirectorConfig config : list) {
ShopMerchantSupervisorRespDTO dto = new ShopMerchantSupervisorRespDTO(); ShopMerchantSupervisorRespDTO dto = new ShopMerchantSupervisorRespDTO();
dto.setMerchantId(config.getMerchantId()); dto.setMerchantId(config.getMerchantId());
dto.setDirectorType(config.getDirectorType()); dto.setDirectorType(config.getDirectorType());
dto.setDirectorUserId(config.getDirectorUserId()); dto.setDirectorUserId(config.getDirectorUserId());
dto.setDirectorName(config.getDirectorName()); dto.setDirectorName(config.getDirectorName());
dto.setDirectorPhone(config.getDirectorPhone()); dto.setDirectorPhone(config.getDirectorPhone());
return dto; result.add(dto);
}
return result;
} }
/** /**
......
...@@ -14,6 +14,7 @@ import cn.com.glsx.dj.smartcarlife.remote.StaffInfoRemote; ...@@ -14,6 +14,7 @@ import cn.com.glsx.dj.smartcarlife.remote.StaffInfoRemote;
import cn.com.glsx.dj.strategy.config.DataStatsConfig; import cn.com.glsx.dj.strategy.config.DataStatsConfig;
import cn.com.glsx.dj.strategy.config.KafkaTopicConfig; import cn.com.glsx.dj.strategy.config.KafkaTopicConfig;
import cn.com.glsx.dj.strategy.config.MentoringApplicationConfig; import cn.com.glsx.dj.strategy.config.MentoringApplicationConfig;
import cn.com.glsx.dj.supervisor.remote.SupervisorSpecialCoachApprovalRemote;
import cn.com.glsx.scrm.wechat.dto.workwechat.message.WorkWechatTextMessageDTO; import cn.com.glsx.scrm.wechat.dto.workwechat.message.WorkWechatTextMessageDTO;
import cn.com.glsx.scrm.wechat.dto.workwechat.message.request.SendWorkWechatMessageRequestDTO; import cn.com.glsx.scrm.wechat.dto.workwechat.message.request.SendWorkWechatMessageRequestDTO;
import cn.com.glsx.scrm.wechat.dto.workwechat.message.response.SendWorkWechatMessageResponseDTO; import cn.com.glsx.scrm.wechat.dto.workwechat.message.response.SendWorkWechatMessageResponseDTO;
...@@ -28,6 +29,9 @@ import cn.com.glsx.dj.strategy.dto.OrderStrategyCheckReqDTO; ...@@ -28,6 +29,9 @@ import cn.com.glsx.dj.strategy.dto.OrderStrategyCheckReqDTO;
import cn.com.glsx.dj.strategy.dto.OrderStrategyCheckRespDTO; import cn.com.glsx.dj.strategy.dto.OrderStrategyCheckRespDTO;
import cn.com.glsx.dj.strategy.dto.StaffHistoryRecordDTO; import cn.com.glsx.dj.strategy.dto.StaffHistoryRecordDTO;
import cn.com.glsx.dj.strategy.dto.StaffInfoDTO; import cn.com.glsx.dj.strategy.dto.StaffInfoDTO;
import cn.com.glsx.dj.strategy.enums.BiAggregationTypeEnum;
import cn.com.glsx.dj.strategy.enums.BiDateTypeEnum;
import cn.com.glsx.dj.strategy.enums.BiMetricCodeEnum;
import cn.com.glsx.dj.strategy.enums.StrategyErrorEnum; import cn.com.glsx.dj.strategy.enums.StrategyErrorEnum;
import cn.com.glsx.dj.strategy.enums.StrategyPushFlagEnum; import cn.com.glsx.dj.strategy.enums.StrategyPushFlagEnum;
import cn.com.glsx.dj.strategy.enums.StrategyPushType; import cn.com.glsx.dj.strategy.enums.StrategyPushType;
...@@ -114,6 +118,9 @@ public class StrategyInfoService { ...@@ -114,6 +118,9 @@ public class StrategyInfoService {
@Resource @Resource
private SceneRemote sceneRemote; private SceneRemote sceneRemote;
@Resource
private SupervisorSpecialCoachApprovalRemote supervisorSpecialCoachApprovalRemote;
public List<StrategyInfo> queryStrategyInfoList(Integer strategyType) { public List<StrategyInfo> queryStrategyInfoList(Integer strategyType) {
Example example = new Example(StrategyInfo.class); Example example = new Example(StrategyInfo.class);
...@@ -146,7 +153,7 @@ public class StrategyInfoService { ...@@ -146,7 +153,7 @@ public class StrategyInfoService {
strategyInfo.setDeletedFlag(DeleteFlagEnum.N.getValue()); strategyInfo.setDeletedFlag(DeleteFlagEnum.N.getValue());
strategyInfo.setCreatedDate(date); strategyInfo.setCreatedDate(date);
strategyInfo.setCreatedBy(batchStrategyInfo.getCreatedBy()); strategyInfo.setCreatedBy(batchStrategyInfo.getCreatedBy());
strategyInfo.setPushFlag(StrategyPushFlagEnum.NOT_PUSHED.getValue()); strategyInfo.setPushFlag(resolveInitPushFlag(baseStrategyInfo.getStrategyType()));
strategyInfo.setCreatedUUid(batchStrategyInfo.getCreatedUUid()); strategyInfo.setCreatedUUid(batchStrategyInfo.getCreatedUUid());
return strategyInfo; return strategyInfo;
}).collect(Collectors.toList()); }).collect(Collectors.toList());
...@@ -168,10 +175,64 @@ public class StrategyInfoService { ...@@ -168,10 +175,64 @@ public class StrategyInfoService {
}).start(); }).start();
} }
//创建成功后发送 MQ 消息(异步发送,避免受未提交事务影响)
new Thread(() -> strategyInfoList.forEach(x -> sendStrategyCreatedMessage(x.getId()))).start();
return Boolean.TRUE; return Boolean.TRUE;
} }
/** /**
* 创建单个策略记录
* <p>逻辑与 {@link #batchCreate(BatchInsertStrategyInfo)} 保持一致,
* 仅针对单个门店场景,门店信息、关联人员/课程/录音、
* 创建人以及数据来源等字段均从 {@link StrategyInfo} 本身传入。</p>
*
* @param strategyInfo 策略信息(含 merchantId/merchantName/staffList/courseList/recordingList 等)
* @return 新创建的策略主键id
*/
@Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
public Integer create(StrategyInfo strategyInfo) {
if (Objects.isNull(strategyInfo)) {
throw new RpcServiceException(DefaultErrorEnum.SERVICE_ERROR, "策略信息不能为空");
}
if (Objects.isNull(strategyInfo.getMerchantId())) {
throw new RpcServiceException(DefaultErrorEnum.SERVICE_ERROR, "门店ID不能为空");
}
//设置默认推送方式
if (Objects.isNull(strategyInfo.getPushType())) {
strategyInfo.setPushType(StrategyPushType.TIMED_PUSH.getValue());
}
Date date = new Date();
strategyInfo.setDeletedFlag(DeleteFlagEnum.N.getValue());
strategyInfo.setCreatedDate(date);
strategyInfo.setPushFlag(resolveInitPushFlag(strategyInfo.getStrategyType()));
//插入策略基础信息(主键回填到 strategyInfo.id)
strategyInfoMapper.insertSelective(strategyInfo);
List<StrategyInfo> strategyInfoList = Collections.singletonList(strategyInfo);
//插入策略人员关联信息
if (!CollectionUtils.isEmpty(strategyInfo.getStaffList())) {
strategyStaffRelService.batchInsert(strategyInfoList, strategyInfo.getStaffList(), SceneTypeEnum.SCENE1_0.getValue());
}
//插入策略课程关联关系
if (!CollectionUtils.isEmpty(strategyInfo.getCourseList())) {
strategyCourseRelService.batchInsert(strategyInfoList, strategyInfo.getCourseList());
}
//插入策略-录音关联关系
if (!CollectionUtils.isEmpty(strategyInfo.getRecordingList())) {
strategyRecordingRelService.batchInsert(strategyInfoList, strategyInfo.getRecordingList());
}
//判断是否需要立即推送消息
if (StrategyPushType.IMMEDIATE_PUSH.getValue().equals(strategyInfo.getPushType())) {
final Integer strategyId = strategyInfo.getId();
new Thread(() -> sendStrategyPushMessage(strategyId)).start();
}
//创建成功后发送 MQ 消息(异步发送,避免受未提交事务影响)
final Integer createdStrategyId = strategyInfo.getId();
new Thread(() -> sendStrategyCreatedMessage(createdStrategyId)).start();
return strategyInfo.getId();
}
/**
* 需要"未完成"状态才能删除的策略类型集合 * 需要"未完成"状态才能删除的策略类型集合
* 人员更换评估(9)、商务政策更新评估(10)、多品类拓张(11)、流量问题改善(12) * 人员更换评估(9)、商务政策更新评估(10)、多品类拓张(11)、流量问题改善(12)
*/ */
...@@ -183,6 +244,24 @@ public class StrategyInfoService { ...@@ -183,6 +244,24 @@ public class StrategyInfoService {
)); ));
/** /**
* 根据策略类型计算 pushFlag 初始状态。
* <ul>
* <li>带教申请(8):初始为 APPROVING(审批中=3)</li>
* <li>人员更换评估(9)/商务政策更新评估(10)/多品类拓张(11)/流量问题改善(12):初始为 UNFINISHED(未完成=2)</li>
* <li>其他类型:保持原有逻辑初始为 NOT_PUSHED(未推送=0)</li>
* </ul>
*/
private Integer resolveInitPushFlag(Integer strategyType) {
if (StrategyTypeEnum.MENTORING_APPLICATION.getValue().equals(strategyType)) {
return StrategyPushFlagEnum.APPROVING.getValue();
}
if (UNFINISHED_DELETABLE_TYPES.contains(strategyType)) {
return StrategyPushFlagEnum.UNFINISHED.getValue();
}
return StrategyPushFlagEnum.NOT_PUSHED.getValue();
}
/**
* 删除策略 * 删除策略
* 删除规则: * 删除规则:
* 1. 带教申请(MENTORING_APPLICATION=8):仅状态=审批中(APPROVING=3) 可删除 * 1. 带教申请(MENTORING_APPLICATION=8):仅状态=审批中(APPROVING=3) 可删除
...@@ -351,6 +430,7 @@ public class StrategyInfoService { ...@@ -351,6 +430,7 @@ public class StrategyInfoService {
MentoringApplicationDetailDTO detail = new MentoringApplicationDetailDTO(); MentoringApplicationDetailDTO detail = new MentoringApplicationDetailDTO();
// 1. 查询审批信息(TODO: 对接外部remote接口) // 1. 查询审批信息(TODO: 对接外部remote接口)
// supervisorSpecialCoachApprovalRemote.getApprovalTaskDetail()
MentoringApprovalInfoDTO approvalInfo = queryMentoringApprovalInfo(strategyInfo.getId()); MentoringApprovalInfoDTO approvalInfo = queryMentoringApprovalInfo(strategyInfo.getId());
detail.setApprovalInfo(approvalInfo); detail.setApprovalInfo(approvalInfo);
...@@ -652,6 +732,27 @@ public class StrategyInfoService { ...@@ -652,6 +732,27 @@ public class StrategyInfoService {
} }
/** /**
* 发送策略创建成功kafka消息。
* <p>仅发送 strategyId,不报出异常以免影响外部事务。</p>
*
* @param strategyId 策略主键id
*/
public void sendStrategyCreatedMessage(Integer strategyId) {
if (strategyId == null) {
log.warn("策略ID为空,无法发送策略创建成功消息");
return;
}
try {
String message = String.valueOf(strategyId);
log.info("准备发送策略创建成功消息,策略ID:{}, Topic:{}", strategyId, kafkaTopicConfig.getStrategyCreatedTopic());
kafkaProducer.send(kafkaTopicConfig.getStrategyCreatedTopic(), message.getBytes());
log.info("策略创建成功消息发送成功,策略ID:{}", strategyId);
} catch (Exception e) {
log.error("策略创建成功消息发送异常,策略ID:{}", strategyId, e);
}
}
/**
* 策略中心-门店分析-历史人员记录 * 策略中心-门店分析-历史人员记录
* *
* @param merchantId * @param merchantId
...@@ -670,9 +771,9 @@ public class StrategyInfoService { ...@@ -670,9 +771,9 @@ public class StrategyInfoService {
queryParams.setBrandIds(dataStatsConfig.defaultBrandId); queryParams.setBrandIds(dataStatsConfig.defaultBrandId);
queryParams.setBizs(bizs); queryParams.setBizs(bizs);
queryParams.setMerchantIds(String.valueOf(merchantId)); queryParams.setMerchantIds(String.valueOf(merchantId));
queryParams.setItemCodes("A036"); queryParams.setItemCodes(BiMetricCodeEnum.OUTPUT_VALUE.getCode());
queryParams.setDateType(2); queryParams.setDateType(BiDateTypeEnum.MONTH.getValue());
queryParams.setExts("staffIds"); queryParams.setExts(BiAggregationTypeEnum.STAFF.getValue());
queryParams.setStartDate(DateUtil.formatDate(strategyMerchantTimelineList.get(0).getNodeDate())); queryParams.setStartDate(DateUtil.formatDate(strategyMerchantTimelineList.get(0).getNodeDate()));
queryParams.setEndDate(DateUtil.formatDate(strategyMerchantTimelineList.get(strategyMerchantTimelineList.size() - 1).getNodeDate())); queryParams.setEndDate(DateUtil.formatDate(strategyMerchantTimelineList.get(strategyMerchantTimelineList.size() - 1).getNodeDate()));
List<DataBusinessDTO> totalOutputList = getTotalOutputGroupByMerchant(queryParams); List<DataBusinessDTO> totalOutputList = getTotalOutputGroupByMerchant(queryParams);
......
package cn.com.glsx.dj.strategy.service.warning;
import cn.com.glsx.framework.core.exception.RpcServiceException;
import cn.com.glsx.dj.strategy.util.DateUtil;
import com.alibaba.fastjson.JSON;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import lombok.ToString;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import org.springframework.web.client.RestTemplate;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.List;
/**
* BI 指标查询服务——仿 DateService(rpc-mindworkplate),调用同一 BI HTTP API。
*
* @author yangwei_by_claude
* @version 1.0
* @since 2026/05/28 14:00
*/
@Slf4j
@Service
public class BiMetricQueryService {
@Autowired
private Environment environment;
public static final String DATE_METHOD = "data/";
private static final String DETAIL_METHOD = "detail/";
private String getBaseUrl() {
return environment.getProperty("tianqi.query.base.url", "http://192.168.3.211:8021/");
}
/**
* 获取时间区间指标数据。
*
* @param queryParams 查询参数
* @param method 接口方法(data/ 或 detail/)
* @return 指标明细列表
*/
public List<ItemDetail> getItemDetail(QueryParams queryParams, String method) {
RestTemplate restTemplate = new RestTemplate();
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON));
HttpEntity<QueryParams> entity = new HttpEntity<>(queryParams, headers);
log.info("BI请求参数:{}, 请求方法:{}", JSON.toJSONString(queryParams), method);
ResponseEntity<String> response = restTemplate.postForEntity(getBaseUrl() + method, entity, String.class);
log.info("BI返回结果:{}", response.getBody());
Response response1;
try {
response1 = JSON.parseObject(response.getBody(), Response.class);
} catch (Exception e) {
log.error("BI返回结果解析异常:{}", e.getMessage(), e);
throw new RpcServiceException(e.getMessage());
}
if (response1 == null) {
throw new RpcServiceException("调用BI获取数据异常!");
}
if (response1.getCode() != 200) {
throw new RpcServiceException(response1.getMsg());
}
if (StringUtils.isEmpty(response1.getContent())) {
return new ArrayList<>();
}
try {
return JSON.parseArray(JSON.toJSONString(response1.getContent()), ItemDetail.class);
} catch (Exception e) {
log.error("BI返回结果解析异常:{}", e.getMessage(), e);
throw new RpcServiceException(e.getMessage());
}
}
// ==================== 内部类 ====================
@ToString
@Data
public static class Response<T> implements Serializable {
private T content;
private String msg;
private int code;
}
@ToString
@Data
public static class QueryParams implements Serializable {
/** 业务: 1=延保 2=轻改 3=权益 */
private Integer bizs;
/** 指标代码 */
private String itemCodes;
/** 品牌ID */
private String brandIds;
/** 门店号列表 */
private String merchantIds;
/** 产品ID */
private String productIds;
/** 车系 */
private String series;
/** 扩展参数 */
private String exts;
private Integer year;
/** 员工ID列表 */
private String staffIds;
/** 员工手机号列表 */
private String staffPhones;
/** 开始日期 */
private String startDate;
/** 结束日期 */
private String endDate;
private Integer step;
/** 日期类型: 0=按日 1=按周 2=按月 3=按年 4=按查询时间段汇总 */
private Integer dateType;
}
@ToString
@Data
public static class ItemDetail implements Serializable {
private String biz;
private String rowkey;
private String itemCode;
@JsonFormat(pattern = DateUtil.PATTERN_YYYY_MM_DD, timezone = "GMT+8")
private Date date;
private String merchantId;
private String merchantName;
private String staffId;
private String staffName;
private String staffPhone;
private String productId;
private String brandId;
private String productName;
private String series;
/** 指标值 */
private BigDecimal itemValue;
/** 上一周期值(环比) */
private BigDecimal preValue;
/** 环比 */
private BigDecimal rate;
@JsonFormat(pattern = DateUtil.PATTERN_YYYY_MM_DD, timezone = "GMT+8")
private Date createTime;
private String remark;
@JsonFormat(pattern = DateUtil.PATTERN_YYYY_MM_DD, timezone = "GMT+8")
private Date startDate;
@JsonFormat(pattern = DateUtil.PATTERN_YYYY_MM_DD, timezone = "GMT+8")
private Date endDate;
}
}
package cn.com.glsx.dj.strategy.service.warning;
import cn.com.glsx.dj.mindworkplate.model.EcoCoefficientRule;
import cn.com.glsx.dj.strategy.mapper.EcoCoefficientRuleMapper;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;
/**
* 指标生态系数规则查询服务——仿 EcoCoefficientService(rpc-dj-pe-analysis)。
*
* <p>加载 eco_coefficient_rule 中已启用的规则到内存缓存,按指标编码和指标值匹配生态系数。</p>
*
* @author yangwei_by_claude
* @version 1.0
* @since 2026/05/28 14:00
*/
@Slf4j
@Service
public class EcoCoefficientQueryService implements ApplicationListener<ApplicationReadyEvent> {
@Resource
private EcoCoefficientRuleMapper ecoCoefficientRuleMapper;
private final Map<String, List<EcoCoefficientRule>> ruleCache = new ConcurrentHashMap<>();
@Override
public void onApplicationEvent(ApplicationReadyEvent event) {
reloadRules();
log.info("生态系数规则查询服务初始化完成");
}
/**
* 重新加载已启用的生态系数规则到内存缓存。
*/
public void reloadRules() {
List<EcoCoefficientRule> rules = ecoCoefficientRuleMapper.selectAllEnabled();
Map<String, List<EcoCoefficientRule>> groupedRules = (rules == null ? Collections.<EcoCoefficientRule>emptyList() : rules)
.stream()
.filter(rule -> StringUtils.isNotBlank(rule.getIndicatorCode()))
.filter(rule -> rule.getCoefficient() != null)
.collect(Collectors.groupingBy(
EcoCoefficientRule::getIndicatorCode,
Collectors.collectingAndThen(Collectors.toList(), this::sortRules)
));
ruleCache.clear();
ruleCache.putAll(groupedRules);
log.info("生态系数规则加载完成,规则数:{},指标数:{}",
rules == null ? 0 : rules.size(), groupedRules.size());
}
/**
* 根据指标编码和指标值获取生态系数。
*
* @param indicatorCode 指标编码
* @param metricValue 指标值
* @return 命中时返回生态系数,未命中返回 BigDecimal.ZERO
*/
public BigDecimal getCoefficient(String indicatorCode, BigDecimal metricValue) {
if (StringUtils.isBlank(indicatorCode) || metricValue == null) {
return null;
}
List<EcoCoefficientRule> rules = ruleCache.get(indicatorCode);
if (CollectionUtils.isEmpty(rules)) {
log.info("未找到生态系数规则,indicatorCode:{}", indicatorCode);
return null;
}
BigDecimal coefficient = matchRules(rules, metricValue);
if (coefficient != null) {
return coefficient;
}
log.warn("生态系数规则未命中,indicatorCode:{},metricValue:{}", indicatorCode, metricValue);
return BigDecimal.ZERO;
}
private BigDecimal matchRules(List<EcoCoefficientRule> rules, BigDecimal metricValue) {
for (EcoCoefficientRule rule : rules) {
BigDecimal minValue = rule.getMinPenetration() == null ? BigDecimal.ZERO : rule.getMinPenetration();
BigDecimal maxValue = rule.getMaxPenetration();
boolean match = metricValue.compareTo(minValue) >= 0
&& (maxValue == null || metricValue.compareTo(maxValue) < 0);
if (match) {
log.info("生态系数规则命中,indicatorCode:{},metricValue:{},range:[{}~{}],coefficient:{}",
rule.getIndicatorCode(), metricValue, minValue, maxValue, rule.getCoefficient());
return rule.getCoefficient();
}
}
return null;
}
private List<EcoCoefficientRule> sortRules(List<EcoCoefficientRule> rules) {
return rules.stream()
.sorted(Comparator
.comparing(EcoCoefficientRule::getSortOrder, Comparator.nullsLast(Integer::compareTo))
.thenComparing(EcoCoefficientRule::getMinPenetration, Comparator.nullsFirst(BigDecimal::compareTo)))
.collect(Collectors.toList());
}
}
package cn.com.glsx.dj.strategy.service.warning;
import cn.com.glsx.dj.strategy.dto.warning.PeriodRange;
import cn.com.glsx.dj.strategy.enums.BiAggregationTypeEnum;
import cn.com.glsx.dj.strategy.enums.BiDateTypeEnum;
import cn.com.glsx.dj.strategy.enums.BiMetricCodeEnum;
import cn.com.glsx.dj.strategy.enums.ProjectGroupBizEnum;
import cn.com.glsx.dj.strategy.enums.TimeDimensionEnum;
import cn.com.glsx.dj.strategy.mapper.PgStoreOutputMapper;
import cn.com.glsx.dj.strategy.model.projectgroup.PgStoreOutput;
import cn.hutool.core.date.DateUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;
/**
* 有产值门店服务——计算有产值门店 + 读写 pg_store_output。
*
* @author yangwei_by_claude
* @version 1.0
* @since 2026/05/28 14:00
*/
@Slf4j
@Service
public class StoreOutputService {
@Resource
private PgStoreOutputMapper storeOutputMapper;
@Resource
private BiMetricQueryService biMetricQueryService;
/**
* 计算指定周期+业务的有产值门店,写入 pg_store_output(幂等:先删后插)。
*
* @param biz 业务类型
* @param timeDimension 时间维度
* @param range 周期起止
*/
public void computeStoreOutputs(Integer biz, String timeDimension, PeriodRange range) {
String periodStart = DateUtil.format(range.getStart(), "yyyy-MM-dd");
String periodEnd = DateUtil.format(range.getEnd(), "yyyy-MM-dd");
// 查询BI有产值门店
BiMetricQueryService.QueryParams params = new BiMetricQueryService.QueryParams();
params.setBizs(biz);
params.setItemCodes(BiMetricCodeEnum.OUTPUT_VALUE.getCode());
params.setDateType(BiDateTypeEnum.ALL.getValue());
params.setExts(BiAggregationTypeEnum.MERCHANT.getValue());
params.setStartDate(periodStart);
params.setEndDate(periodEnd);
List<BiMetricQueryService.ItemDetail> items;
try {
items = biMetricQueryService.getItemDetail(params, "data/");
} catch (Exception e) {
log.error("查询有产值门店失败,biz={}, timeDimension={}", biz, timeDimension, e);
return;
}
if (CollectionUtils.isEmpty(items)) {
log.info("无有产值门店,biz={}, timeDimension={}", biz, timeDimension);
return;
}
// 幂等删除旧记录
storeOutputMapper.deleteByCondition(biz, timeDimension, periodStart, periodEnd);
// 构造 PgStoreOutput 列表
List<PgStoreOutput> outputs = new ArrayList<>();
for (BiMetricQueryService.ItemDetail item : items) {
if (item.getMerchantId() == null) {
continue;
}
PgStoreOutput output = new PgStoreOutput();
output.setBusinessType(biz);
output.setStoreId(Integer.valueOf(item.getMerchantId()));
output.setStoreName(item.getMerchantName());
output.setTimeDimension(timeDimension);
output.setPeriodStart(range.getStart());
output.setPeriodEnd(range.getEnd());
output.setDeletedFlag("N");
output.setCreatedDate(new Date());
output.setUpdatedDate(new Date());
outputs.add(output);
}
if (CollectionUtils.isNotEmpty(outputs)) {
storeOutputMapper.batchInsert(outputs);
log.info("有产值门店写入完成,biz={}, timeDimension={}, 门店数={}", biz, timeDimension, outputs.size());
}
}
/**
* 查询当前周期+业务的有产值门店号列表。
*
* @param businessType 业务类型
* @param timeDimension 时间维度
* @param periodStart 周期开始
* @param periodEnd 周期结束
* @return 门店号列表
*/
public List<Integer> listStoreIdsWithOutput(Integer businessType, String timeDimension,
String periodStart, String periodEnd) {
List<PgStoreOutput> list = listStoreOutputs(businessType, timeDimension, periodStart, periodEnd);
if (CollectionUtils.isEmpty(list)) {
return new ArrayList<>();
}
return list.stream().map(PgStoreOutput::getStoreId).collect(Collectors.toList());
}
/**
* 查询当前周期+业务的有产值门店完整记录。
*
* @param businessType 业务类型
* @param timeDimension 时间维度
* @param periodStart 周期开始
* @param periodEnd 周期结束
* @return 有产值门店记录列表
*/
public List<PgStoreOutput> listStoreOutputs(Integer businessType, String timeDimension,
String periodStart, String periodEnd) {
return storeOutputMapper.selectByCondition(businessType, timeDimension, periodStart, periodEnd);
}
/**
* 对有产值门店批量执行(四种维度 × 三种业务)。
*
* @param date 参考日期
*/
public void computeAll(Date date) {
for (TimeDimensionEnum dim : TimeDimensionEnum.values()) {
PeriodRange range = dim.calculate(date);
for (ProjectGroupBizEnum biz : ProjectGroupBizEnum.values()) {
try {
computeStoreOutputs(biz.getBiz(), dim.getCode(), range);
} catch (Exception e) {
log.error("有产值门店计算失败,biz={}, dim={}", biz.getBiz(), dim.getCode(), e);
}
}
}
}
}
package cn.com.glsx.dj.strategy.service.warning;
import cn.com.glsx.dj.strategy.dto.projectgroup.ProjectGroupWarningRecordDTO;
import cn.com.glsx.dj.strategy.dto.projectgroup.ProjectGroupWarningRecordQueryDTO;
import cn.com.glsx.dj.strategy.dto.warning.StoreWarningSummaryDTO;
import cn.com.glsx.dj.strategy.dto.warning.WarningRecordDTO;
import cn.com.glsx.dj.strategy.dto.warning.WarningRecordQueryRequest;
import cn.com.glsx.dj.strategy.mapper.PgWarningRecordMapper;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
* 预警记录查询服务——动态查询 + 门店汇总。
*
* @author yangwei_by_claude
* @version 1.0
* @since 2026/05/28 14:00
*/
@Slf4j
@Service
public class WarningRecordService {
@Resource
private PgWarningRecordMapper recordMapper;
/**
* 按条件动态查询预警记录。
*
* @param request 查询条件
* @param merchantIds 门店交集筛选(可为空)
* @return 预警记录列表
*/
public List<WarningRecordDTO> queryRecords(WarningRecordQueryRequest request, List<Integer> merchantIds) {
ProjectGroupWarningRecordQueryDTO queryDTO = buildQueryDTO(request);
if (CollectionUtils.isNotEmpty(merchantIds)) {
queryDTO.setMerchantIds(merchantIds);
}
List<ProjectGroupWarningRecordDTO> list = recordMapper.listWarningRecordsByCondition(queryDTO);
if (list == null) {
return new ArrayList<>();
}
return list.stream().map(dto -> {
WarningRecordDTO record = new WarningRecordDTO();
record.setId(dto.getId());
record.setGroupId(dto.getGroupId());
record.setConfigId(dto.getConfigId());
record.setWarningType(dto.getWarningType());
record.setWarningTypeName(dto.getWarningTypeName());
record.setBusinessType(dto.getBusinessType());
record.setMonitorTarget(dto.getMonitorTarget());
record.setTimeDimension(dto.getTimeDimension());
record.setPeriodStart(dto.getPeriodStart());
record.setPeriodEnd(dto.getPeriodEnd());
record.setStoreId(dto.getMerchantId());
record.setStoreName(dto.getMerchantName());
record.setStaffId(dto.getStaffId());
record.setStaffName(dto.getStaffName());
record.setStaffPhone(dto.getStaffPhone());
record.setMetricCode(dto.getMetricCode());
record.setMetricName(dto.getMetricName());
record.setMetricValue(dto.getMetricValue());
record.setMetricDisplay(dto.getMetricDisplay());
record.setThresholdType(dto.getThresholdType());
record.setThresholdDisplay(dto.getThresholdDisplay());
record.setThresholdMinDisplay(dto.getThresholdMinDisplay());
record.setThresholdMaxDisplay(dto.getThresholdMaxDisplay());
record.setEcoCoefficient(dto.getEcoCoefficient());
record.setOperator(dto.getOperator());
record.setWarningText(dto.getWarningText());
record.setIsStrategySent(dto.getIsStrategySent());
record.setStatus(dto.getStatus());
record.setCreatedTime(dto.getCreatedTime());
return record;
}).collect(Collectors.toList());
}
/**
* 按门店汇总预警——返回门店预警卡片列表。
*
* @param request 查询条件
* @param merchantIds 限定门店列表
* @return 门店预警汇总列表
*/
public List<StoreWarningSummaryDTO> queryStoreSummary(WarningRecordQueryRequest request,
List<Integer> merchantIds) {
ProjectGroupWarningRecordQueryDTO queryDTO = buildQueryDTO(request);
if (CollectionUtils.isNotEmpty(merchantIds)) {
queryDTO.setMerchantIds(merchantIds);
}
List<ProjectGroupWarningRecordDTO> records = recordMapper.listWarningRecordsByCondition(queryDTO);
if (records == null || records.isEmpty()) {
return new ArrayList<>();
}
// 按 merchantId 分组
Map<Integer, List<ProjectGroupWarningRecordDTO>> grouped = records.stream()
.filter(r -> r.getMerchantId() != null)
.collect(Collectors.groupingBy(ProjectGroupWarningRecordDTO::getMerchantId));
List<StoreWarningSummaryDTO> result = new ArrayList<>();
for (Map.Entry<Integer, List<ProjectGroupWarningRecordDTO>> entry : grouped.entrySet()) {
StoreWarningSummaryDTO summary = new StoreWarningSummaryDTO();
summary.setMerchantNo(String.valueOf(entry.getKey()));
List<ProjectGroupWarningRecordDTO> storeRecords = entry.getValue();
if (!storeRecords.isEmpty()) {
ProjectGroupWarningRecordDTO first = storeRecords.get(0);
summary.setStoreName(first.getMerchantName());
}
summary.setWarningTotalCount(storeRecords.size());
// 预警摘要:取前2条 warningTypeName
List<String> warnSummary = storeRecords.stream()
.limit(2)
.map(ProjectGroupWarningRecordDTO::getWarningTypeName)
.collect(Collectors.toList());
summary.setWarningSummary(warnSummary);
result.add(summary);
}
return result;
}
private ProjectGroupWarningRecordQueryDTO buildQueryDTO(WarningRecordQueryRequest request) {
ProjectGroupWarningRecordQueryDTO dto = new ProjectGroupWarningRecordQueryDTO();
dto.setProjectGroupId(request.getGroupId());
dto.setBusinessType(request.getBusinessType());
dto.setWarningType(request.getWarningType());
dto.setTimeDimension(request.getTimeDimension());
dto.setPeriodStart(request.getStartDate());
dto.setPeriodEnd(request.getEndDate());
dto.setMonitorTarget(request.getMonitorTarget());
dto.setStoreId(request.getStoreId());
dto.setStaffId(request.getStaffId());
dto.setStoreName(request.getStoreName());
dto.setIsStrategySent(request.getIsStrategySent());
return dto;
}
}
package cn.com.glsx.dj.strategy.service.warning.threshold;
import cn.com.glsx.dj.strategy.dto.warning.ConditionDTO;
import cn.com.glsx.dj.strategy.dto.warning.ThresholdDTO;
import cn.com.glsx.dj.strategy.dto.warning.ThresholdValue;
import cn.com.glsx.dj.strategy.enums.ThresholdTypeEnum;
import lombok.extern.slf4j.Slf4j;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
/**
* 动态SQL阈值策略——批量执行SQL,按 merchantNo 分组返回阈值。
*
* @author yangwei_by_claude
* @version 1.0
* @since 2026/05/28 14:00
*/
@Slf4j
@Component
public class DynamicSqlThresholdStrategy implements ThresholdStrategy {
@Resource
private JdbcTemplate jdbcTemplate;
@Override
public ThresholdTypeEnum supportedType() {
return ThresholdTypeEnum.DYNAMIC_SQL;
}
@Override
public ThresholdValue resolve(ConditionDTO condition) {
throw new UnsupportedOperationException("动态SQL阈值请使用 batchResolve() 批量预加载");
}
@Override
public Map<Integer, ThresholdValue> batchResolve(List<ConditionDTO> conditions) {
Map<Integer, ThresholdValue> result = new LinkedHashMap<>();
for (ConditionDTO cond : conditions) {
ThresholdDTO t = cond.getThreshold();
if (t == null || t.getType() == null || t.getType() != ThresholdTypeEnum.DYNAMIC_SQL.getType()) {
continue;
}
try {
String sql = t.getValue();
if (sql == null || sql.trim().isEmpty()) {
continue;
}
// 动态SQL只允许SELECT
String upperSql = sql.trim().toUpperCase();
if (!upperSql.startsWith("SELECT")) {
log.warn("动态SQL不是SELECT语句,跳过: {}", sql);
continue;
}
List<Map<String, Object>> rows = jdbcTemplate.queryForList(sql);
// 按条件序号保存,后续使用时按 merchantNo 匹配
ThresholdValue tv = buildThresholdValue(t, rows);
result.put(cond.getSeq(), tv);
} catch (Exception e) {
log.error("动态SQL阈值预加载失败,seq={}", cond.getSeq(), e);
}
}
return result;
}
private ThresholdValue buildThresholdValue(ThresholdDTO t, List<Map<String, Object>> rows) {
if (rows.isEmpty()) {
return ThresholdValue.single(null, null);
}
Map<String, Object> firstRow = rows.get(0);
String minField = t.getMinField();
String maxField = t.getMaxField();
if (minField != null || maxField != null) {
BigDecimal min = toBigDecimal(firstRow.get(minField));
BigDecimal max = toBigDecimal(firstRow.get(maxField));
return ThresholdValue.range(min, max, min, max);
}
// 取第一个数值字段作为单值阈值
for (Object val : firstRow.values()) {
if (val instanceof Number) {
BigDecimal v = new BigDecimal(val.toString());
return ThresholdValue.single(v, v);
}
}
return ThresholdValue.single(null, null);
}
private BigDecimal toBigDecimal(Object obj) {
if (obj == null) {
return null;
}
return new BigDecimal(obj.toString());
}
}
package cn.com.glsx.dj.strategy.service.warning.threshold;
import cn.com.glsx.dj.strategy.dto.warning.ConditionDTO;
import cn.com.glsx.dj.strategy.dto.warning.ThresholdDTO;
import cn.com.glsx.dj.strategy.dto.warning.ThresholdValue;
import cn.com.glsx.dj.strategy.enums.ThresholdTypeEnum;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import java.math.BigDecimal;
/**
* 固定值阈值策略——直接读取 threshold.value / min / max。
*
* @author yangwei_by_claude
* @version 1.0
* @since 2026/05/28 14:00
*/
@Slf4j
@Component
public class FixedThresholdStrategy implements ThresholdStrategy {
@Override
public ThresholdTypeEnum supportedType() {
return ThresholdTypeEnum.FIXED;
}
@Override
public ThresholdValue resolve(ConditionDTO condition) {
ThresholdDTO t = condition.getThreshold();
BigDecimal value = toBigDecimal(t.getValue());
BigDecimal min = toBigDecimal(t.getMin());
BigDecimal max = toBigDecimal(t.getMax());
if (min != null || max != null) {
return ThresholdValue.range(min, max, min, max);
}
return ThresholdValue.single(value, value);
}
private BigDecimal toBigDecimal(String str) {
if (str == null || str.trim().isEmpty()) {
return null;
}
return new BigDecimal(str.trim());
}
}
package cn.com.glsx.dj.strategy.service.warning.threshold;
import cn.com.glsx.dj.strategy.dto.warning.ConditionDTO;
import cn.com.glsx.dj.strategy.dto.warning.ThresholdDTO;
import cn.com.glsx.dj.strategy.dto.warning.ThresholdValue;
import cn.com.glsx.dj.strategy.enums.BiDateTypeEnum;
import cn.com.glsx.dj.strategy.enums.ThresholdTypeEnum;
import cn.com.glsx.dj.strategy.service.warning.BiMetricQueryService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.math.BigDecimal;
/**
* 引用指标阈值策略——调用 BI 获取引用指标值作为阈值。
*
* @author yangwei_by_claude
* @version 1.0
* @since 2026/05/28 14:00
*/
@Slf4j
@Component
public class ReferenceMetricThresholdStrategy implements ThresholdStrategy {
@Resource
private BiMetricQueryService biMetricQueryService;
@Override
public ThresholdTypeEnum supportedType() {
return ThresholdTypeEnum.REFERENCE_METRIC;
}
@Override
public ThresholdValue resolve(ConditionDTO condition) {
ThresholdDTO t = condition.getThreshold();
if (t == null || t.getValue() == null) {
return ThresholdValue.single(null, null);
}
// t.value 存的是引用指标的 itemCode
BiMetricQueryService.QueryParams params = new BiMetricQueryService.QueryParams();
params.setItemCodes(t.getValue());
params.setDateType(BiDateTypeEnum.ALL.getValue());
try {
java.util.List<BiMetricQueryService.ItemDetail> items =
biMetricQueryService.getItemDetail(params, BiMetricQueryService.DATE_METHOD);
if (items != null && !items.isEmpty()) {
BigDecimal refValue = items.get(0).getItemValue();
return ThresholdValue.single(refValue, refValue);
}
} catch (Exception e) {
log.error("引用指标查询失败,itemCode={}", t.getValue(), e);
}
return ThresholdValue.single(null, null);
}
}
package cn.com.glsx.dj.strategy.service.warning.threshold;
import cn.com.glsx.dj.strategy.dto.warning.ConditionDTO;
import cn.com.glsx.dj.strategy.dto.warning.ThresholdValue;
import cn.com.glsx.dj.strategy.enums.ThresholdTypeEnum;
import java.util.Collections;
import java.util.List;
import java.util.Map;
/**
* 阈值解析策略接口。
*
* @author yangwei_by_claude
* @version 1.0
* @since 2026/05/28 14:00
*/
public interface ThresholdStrategy {
/**
* 支持的阈值类型。
*
* @return 阈值类型枚举
*/
ThresholdTypeEnum supportedType();
/**
* 单条条件解析(用于固定值/引用指标)。
*
* @param condition 条件DTO
* @return 解析后的阈值
*/
ThresholdValue resolve(ConditionDTO condition);
/**
* 批量预加载(用于动态SQL,避免逐条查库)。
*
* @param conditions 条件列表
* @return condition.seq → ThresholdValue
*/
default Map<Integer, ThresholdValue> batchResolve(List<ConditionDTO> conditions) {
return Collections.emptyMap();
}
}
package cn.com.glsx.dj.strategy.service.warning.threshold;
import cn.com.glsx.dj.strategy.dto.warning.ConditionDTO;
import cn.com.glsx.dj.strategy.dto.warning.ThresholdValue;
import cn.com.glsx.dj.strategy.enums.ThresholdTypeEnum;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import javax.annotation.PostConstruct;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;
/**
* 阈值策略工厂——根据 threshold.type 路由到对应策略实现。
*
* @author yangwei_by_claude
* @version 1.0
* @since 2026/05/28 14:00
*/
@Slf4j
@Component
public class ThresholdStrategyFactory {
@Autowired
private List<ThresholdStrategy> strategies;
private Map<ThresholdTypeEnum, ThresholdStrategy> strategyMap;
@PostConstruct
public void init() {
strategyMap = strategies.stream()
.collect(Collectors.toMap(ThresholdStrategy::supportedType, Function.identity(),
(a, b) -> a, LinkedHashMap::new));
log.info("阈值策略工厂初始化完成,已注册 {} 种策略", strategyMap.size());
}
/**
* 根据阈值类型获取对应策略。
*
* @param type 阈值类型
* @return 策略实现
*/
public ThresholdStrategy getStrategy(ThresholdTypeEnum type) {
ThresholdStrategy strategy = strategyMap.get(type);
if (strategy == null) {
throw new IllegalArgumentException("未找到阈值策略: " + type);
}
return strategy;
}
/**
* 对条件列表中 type=2(动态SQL)的条件批量预加载。
*
* @param conditions 条件列表
* @return seq → ThresholdValue
*/
public Map<Integer, ThresholdValue> batchResolve(List<ConditionDTO> conditions) {
ThresholdStrategy strategy = getStrategy(ThresholdTypeEnum.DYNAMIC_SQL);
return strategy.batchResolve(conditions);
}
}
package cn.com.glsx.dj.strategy.util;
import cn.com.glsx.framework.core.beans.rpc.RpcPagination;
import java.util.ArrayList;
import java.util.List;
/**
* 内存分页工具——对已加载的 List 进行内存分页,封装为 {@link RpcPagination} 返回。
*
* @author yangwei_by_claude
* @version 1.0
* @since 2026/05/29 14:00
*/
public final class MemoryPageUtil {
private MemoryPageUtil() {
throw new UnsupportedOperationException("Utility class");
}
/**
* 对全量列表进行内存分页。
*
* @param fullList 全量数据
* @param pageNum 页码(从1开始)
* @param pageSize 每页数量
* @param <T> 数据类型
* @return RpcPagination 分页结果
*/
public static <T> RpcPagination<T> page(List<T> fullList, int pageNum, int pageSize) {
RpcPagination<T> pagination = new RpcPagination<>();
if (fullList == null || fullList.isEmpty()) {
pagination.setPageNum(pageNum);
pagination.setPageSize(pageSize);
pagination.setTotal(0);
pagination.setPages(0);
pagination.setList(new ArrayList<>());
return pagination;
}
int total = fullList.size();
int pages = (total + pageSize - 1) / pageSize;
// 页码修正
if (pageNum < 1) {
pageNum = 1;
}
if (pageNum > pages) {
pageNum = pages;
}
int fromIndex = (pageNum - 1) * pageSize;
int toIndex = Math.min(fromIndex + pageSize, total);
List<T> pageList = fullList.subList(fromIndex, toIndex);
pagination.setPageNum(pageNum);
pagination.setPageSize(pageSize);
pagination.setTotal(total);
pagination.setPages(pages);
pagination.setList(pageList);
return pagination;
}
}
<?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.EcoCoefficientRuleMapper">
<select id="selectAllEnabled" resultType="cn.com.glsx.dj.mindworkplate.model.EcoCoefficientRule">
SELECT
id, indicator_code, min_penetration, max_penetration,
coefficient, sort_order, enabled, create_time, update_time
FROM eco_coefficient_rule
WHERE enabled = 1
ORDER BY indicator_code ASC, sort_order ASC
</select>
</mapper>
...@@ -19,4 +19,28 @@ ...@@ -19,4 +19,28 @@
ORDER BY g.created_date DESC, g.id DESC ORDER BY g.created_date DESC, g.id DESC
</select> </select>
<select id="selectProjectGroupOptions"
parameterType="cn.com.glsx.dj.strategy.dto.projectgroup.ProjectGroupQueryDTO"
resultType="cn.com.glsx.dj.strategy.dto.projectgroup.ProjectGroupOptionDTO">
SELECT
g.id AS groupId,
g.group_name AS groupName
FROM pg_group_info g
WHERE g.deleted_flag = 'N'
<if test="groupName != null and groupName != ''">
AND g.group_name LIKE CONCAT('%', #{groupName}, '%')
</if>
ORDER BY g.created_date DESC, g.id DESC
</select>
<select id="selectAllEnabled" resultType="cn.com.glsx.dj.strategy.model.projectgroup.PgGroupInfo">
SELECT
id, group_name, remark, is_enabled,
created_by, created_date, updated_by, updated_date, deleted_flag
FROM pg_group_info
WHERE deleted_flag = 'N'
AND is_enabled = 1
ORDER BY id ASC
</select>
</mapper> </mapper>
<?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.PgStoreOutputMapper">
<select id="selectByCondition" resultType="cn.com.glsx.dj.strategy.model.projectgroup.PgStoreOutput">
SELECT
id, business_type, store_id, store_name,
time_dimension, period_start, period_end,
deleted_flag, created_by, created_date, updated_by, updated_date
FROM pg_store_output
WHERE deleted_flag = 'N'
AND business_type = #{businessType}
AND time_dimension = #{timeDimension}
AND period_start = #{periodStart}
AND period_end = #{periodEnd}
ORDER BY store_id ASC
</select>
<delete id="deleteByCondition">
DELETE FROM pg_store_output
WHERE business_type = #{businessType}
AND time_dimension = #{timeDimension}
AND period_start = #{periodStart}
AND period_end = #{periodEnd}
</delete>
<insert id="batchInsert" parameterType="java.util.List">
INSERT INTO pg_store_output (
business_type, store_id, store_name,
time_dimension, period_start, period_end,
deleted_flag, created_by, created_date
) VALUES
<foreach collection="list" item="item" separator=",">
(
#{item.businessType}, #{item.storeId}, #{item.storeName},
#{item.timeDimension}, #{item.periodStart}, #{item.periodEnd},
'N', #{item.createdBy}, #{item.createdDate}
)
</foreach>
</insert>
</mapper>
...@@ -15,4 +15,36 @@ ...@@ -15,4 +15,36 @@
GROUP BY group_id GROUP BY group_id
</select> </select>
<select id="selectEnabledByGroupId" resultType="cn.com.glsx.dj.strategy.model.projectgroup.PgWarningConfig">
SELECT
id, group_id, warning_type, biz, monitor_target, rule_json, is_enabled,
created_by, created_date, updated_by, updated_date, deleted_flag
FROM pg_warning_config
WHERE deleted_flag = 'N'
AND is_enabled = 1
AND group_id = #{groupId}
ORDER BY id ASC
</select>
<select id="selectAllEnabled" resultType="cn.com.glsx.dj.strategy.model.projectgroup.PgWarningConfig">
SELECT
id, group_id, warning_type, biz, monitor_target, rule_json, is_enabled,
created_by, created_date, updated_by, updated_date, deleted_flag
FROM pg_warning_config
WHERE deleted_flag = 'N'
AND is_enabled = 1
ORDER BY group_id ASC, id ASC
</select>
<select id="selectEnabledByWarningType" resultType="cn.com.glsx.dj.strategy.model.projectgroup.PgWarningConfig">
SELECT
id, group_id, warning_type, biz, monitor_target, rule_json, is_enabled,
created_by, created_date, updated_by, updated_date, deleted_flag
FROM pg_warning_config
WHERE deleted_flag = 'N'
AND is_enabled = 1
AND warning_type = #{warningType}
ORDER BY id ASC
</select>
</mapper> </mapper>
...@@ -40,4 +40,20 @@ ...@@ -40,4 +40,20 @@
</if> </if>
</select> </select>
<select id="selectByWarningTypeAndBiz"
resultType="cn.com.glsx.dj.strategy.model.projectgroup.PgWarningMetricDict">
SELECT
m.id, m.index_name, m.business_type, m.category_extension,
m.store_index_code, m.staff_index_code,
m.data_type, m.unit, m.sort_order,
m.created_by, m.created_date, m.updated_by, m.updated_date, m.deleted_flag
FROM pg_warning_metric_dict m
INNER JOIN pg_warning_type_metric_rel tm
ON tm.metric_id = m.id AND tm.deleted_flag = 'N'
WHERE m.deleted_flag = 'N'
AND tm.warning_type = #{warningType}
AND m.business_type = #{biz}
ORDER BY m.sort_order ASC, m.id ASC
</select>
</mapper> </mapper>
...@@ -6,10 +6,35 @@ ...@@ -6,10 +6,35 @@
parameterType="cn.com.glsx.dj.strategy.dto.projectgroup.ProjectGroupWarningRecordQueryDTO" parameterType="cn.com.glsx.dj.strategy.dto.projectgroup.ProjectGroupWarningRecordQueryDTO"
resultType="cn.com.glsx.dj.strategy.dto.projectgroup.ProjectGroupWarningRecordDTO"> resultType="cn.com.glsx.dj.strategy.dto.projectgroup.ProjectGroupWarningRecordDTO">
SELECT DISTINCT SELECT DISTINCT
r.id AS id,
r.group_id AS groupId,
r.config_id AS configId,
r.store_id AS merchantId, r.store_id AS merchantId,
r.store_name AS merchantName, r.store_name AS merchantName,
r.staff_id AS staffId,
r.staff_name AS staffName,
r.staff_phone AS staffPhone,
r.warning_type AS warningType, r.warning_type AS warningType,
t.warning_type_name AS warningTypeName t.warning_type_name AS warningTypeName,
r.business_type AS businessType,
r.monitor_target AS monitorTarget,
r.time_dimension AS timeDimension,
r.period_start AS periodStart,
r.period_end AS periodEnd,
r.metric_code AS metricCode,
r.metric_name AS metricName,
r.metric_value AS metricValue,
r.metric_display AS metricDisplay,
r.threshold_type AS thresholdType,
r.threshold_display AS thresholdDisplay,
r.threshold_min_display AS thresholdMinDisplay,
r.threshold_max_display AS thresholdMaxDisplay,
r.eco_coefficient AS ecoCoefficient,
r.operator AS operator,
r.warning_text AS warningText,
r.is_strategy_sent AS isStrategySent,
r.status AS status,
r.created_time AS createdTime
FROM warning_record r FROM warning_record r
LEFT JOIN pg_warning_type_dict t LEFT JOIN pg_warning_type_dict t
ON r.warning_type = t.warning_type ON r.warning_type = t.warning_type
...@@ -42,7 +67,52 @@ ...@@ -42,7 +67,52 @@
#{merchantId} #{merchantId}
</foreach> </foreach>
</if> </if>
<if test="storeId != null">
AND r.store_id = #{storeId}
</if>
<if test="staffId != null and staffId != ''">
AND r.staff_id = #{staffId}
</if>
<if test="storeName != null and storeName != ''">
AND r.store_name LIKE CONCAT('%', #{storeName}, '%')
</if>
<if test="isStrategySent != null">
AND r.is_strategy_sent = #{isStrategySent}
</if>
ORDER BY merchantId ASC, warningType ASC ORDER BY merchantId ASC, warningType ASC
</select> </select>
<insert id="batchInsert" parameterType="java.util.List">
INSERT INTO warning_record (
group_id, config_id, warning_type, business_type, monitor_target,
time_dimension, period_start, period_end,
store_id, store_name, staff_id, staff_name, staff_phone,
metric_code, metric_name, metric_value, metric_display,
threshold_type, threshold_value, threshold_min, threshold_max,
threshold_display, threshold_min_display, threshold_max_display,
eco_coefficient, operator, warning_text,
is_strategy_sent, status, created_time, deleted_flag
) VALUES
<foreach collection="records" item="r" separator=",">
(
#{r.groupId}, #{r.configId}, #{r.warningType}, #{r.businessType}, #{r.monitorTarget},
#{r.timeDimension}, #{r.periodStart}, #{r.periodEnd},
#{r.storeId}, #{r.storeName}, #{r.staffId}, #{r.staffName}, #{r.staffPhone},
#{r.metricCode}, #{r.metricName}, #{r.metricValue}, #{r.metricDisplay},
#{r.thresholdType}, #{r.thresholdValue}, #{r.thresholdMin}, #{r.thresholdMax},
#{r.thresholdDisplay}, #{r.thresholdMinDisplay}, #{r.thresholdMaxDisplay},
#{r.ecoCoefficient}, #{r.operator}, #{r.warningText},
#{r.isStrategySent}, #{r.status}, #{r.createdTime}, 'N'
)
</foreach>
</insert>
<delete id="deleteByCondition">
DELETE FROM warning_record
WHERE config_id = #{configId}
AND time_dimension = #{timeDimension}
AND period_start = #{periodStart}
AND period_end = #{periodEnd}
</delete>
</mapper> </mapper>
...@@ -39,4 +39,12 @@ ...@@ -39,4 +39,12 @@
AND director_type = #{directorType} AND director_type = #{directorType}
ORDER BY id DESC ORDER BY id DESC
</select> </select>
<select id="findMerchantIdsByUUidAndType" resultType="java.lang.Integer">
SELECT merchant_id
FROM dj_car_life_shop_merchant_director_config
WHERE deleted_flag = 'N'
AND director_user_id = #{uuid}
AND director_type = #{typeValue}
</select>
</mapper> </mapper>
...@@ -24,6 +24,8 @@ ...@@ -24,6 +24,8 @@
<result column="biz" property="biz" /> <result column="biz" property="biz" />
<result column="push_flag" property="pushFlag"/> <result column="push_flag" property="pushFlag"/>
<result column="created_uuid" property="createdUUid"/> <result column="created_uuid" property="createdUUid"/>
<result column="data_source" property="dataSource" jdbcType="INTEGER" />
<result column="data_source_id" property="dataSourceId" jdbcType="BIGINT" />
<collection property="staffList" ofType="cn.com.glsx.dj.strategy.model.StrategyStaffRel" column="id" select="cn.com.glsx.dj.strategy.mapper.StrategyStaffRelMapper.selectByStrategyId" /> <collection property="staffList" ofType="cn.com.glsx.dj.strategy.model.StrategyStaffRel" column="id" select="cn.com.glsx.dj.strategy.mapper.StrategyStaffRelMapper.selectByStrategyId" />
<collection property="courseList" ofType="cn.com.glsx.dj.strategy.model.StrategyCourseRel" column="id" select="cn.com.glsx.dj.strategy.mapper.StrategyCourseRelMapper.selectByStrategyId" /> <collection property="courseList" ofType="cn.com.glsx.dj.strategy.model.StrategyCourseRel" column="id" select="cn.com.glsx.dj.strategy.mapper.StrategyCourseRelMapper.selectByStrategyId" />
<collection property="recordingList" ofType="cn.com.glsx.dj.strategy.model.StrategyRecordingRel" column="id" select="cn.com.glsx.dj.strategy.mapper.StrategyRecordingRelMapper.selectByStrategyId" /> <collection property="recordingList" ofType="cn.com.glsx.dj.strategy.model.StrategyRecordingRel" column="id" select="cn.com.glsx.dj.strategy.mapper.StrategyRecordingRelMapper.selectByStrategyId" />
...@@ -39,7 +41,8 @@ ...@@ -39,7 +41,8 @@
WARNING - @mbg.generated WARNING - @mbg.generated
--> -->
id, strategy_type, title, sub_title, merchant_id, merchant_name, start_date, end_date, description, handler_type, id, strategy_type, title, sub_title, merchant_id, merchant_name, start_date, end_date, description, handler_type,
push_type, created_by, created_date, updated_by, updated_date, deleted_flag, merchant_id, merchant_name, biz, push_flag, created_uuid push_type, created_by, created_date, updated_by, updated_date, deleted_flag, merchant_id, merchant_name, biz, push_flag, created_uuid,
data_source, data_source_id
</sql> </sql>
<sql id="Blob_Column_List" > <sql id="Blob_Column_List" >
<!-- <!--
...@@ -241,4 +244,19 @@ ...@@ -241,4 +244,19 @@
#{uuid} #{uuid}
</foreach> </foreach>
</select> </select>
<select id="listMerchantIdsWithStrategy" resultType="java.lang.Integer">
SELECT DISTINCT merchant_id
FROM dj_car_life_strategy_info
WHERE deleted_flag = 'N'
AND biz = #{biz}
<if test="merchantIds != null and merchantIds.size() > 0">
AND merchant_id IN
<foreach item="merchantId" collection="merchantIds" open="(" separator="," close=")">
#{merchantId}
</foreach>
</if>
AND start_date &lt;= #{endDate}
AND end_date &gt;= #{startDate}
</select>
</mapper> </mapper>
\ No newline at end of file \ No newline at end of file
  • @wangxw1
    commented
    Master

    一、关键问题与优化建议(Top 3)

    1. 缺乏请求参数与空指针校验(功能正确性与健壮性)

    • 问题描述:OrderStrategyCheckReqDTO 中的字段仅使用了 Swagger 的 @ApiModelProperty(required = true) 注解,这仅用于接口文档,在运行时不具备真正的校验能力。同时,在 StrategyInfoService.checkOrderStrategyRestriction 方法入口处,未对 reqDTO 本身及其核心必填字段(如 merchantId, strategyType)进行非空校验。
    • 影响分析:
      • 若调用方传入的 reqDTO 为 null,执行 reqDTO.getMerchantId() 时将直接引发 NullPointerException。
      • 若 merchantId 或 strategyType 为 null,tk.mybatis 构建的 SQL 可能会变成 WHERE merchant_id IS NULL,导致查不到数据从而错误地限制提单,引发业务逻辑异常。
    • 优化建议:在 Service 层增加对 reqDTO 的判空处理;在 DTO 中引入 javax.validation 注解(如 @NotNull, @NotEmpty),并在 RPC 层或 Service 层进行显式校验。 java // 建议在 Service 层头部增加基础校验 if (reqDTO == null || reqDTO.getMerchantId() == null || reqDTO.getStrategyType() == null) { throw new RpcServiceException("下单策略校验请求参数不完整"); }

    2. 判断数据是否存在时使用了低效的查询方式(性能与资源利用)

    • 问题描述:在 StrategyInfoService 中,业务目的仅是为了判断是否存在匹配的策略记录(CollectionUtils.isEmpty(list)),但使用了 strategyInfoMapper.selectByExample(example),这会触发 SELECT * 查询并映射完整的数据对象列表。
    • 影响分析:当匹配的数据量较大或表中包含大字段时,将所有列的数据从数据库拉取到应用内存中,会造成不必要的数据库 I/O 消耗、网络带宽浪费以及 JVM 内存占用(GC 压力)。
    • 优化建议:既然只关心数据“是否存在”,建议改用 selectCountByExample 查询数量,或者通过 Example 限制只查询主键 ID。 ```java // 优化方案 1:使用 count 查询(推荐) int count = strategyInfoMapper.selectCountByExample(example); if (count == 0) { respDTO.setRestricted(true); // ... 组装 message }

    // 优化方案 2:仅查询 ID 列 // example.selectProperties("id"); // List list = strategyInfoMapper.selectByExample(example);

    
    #### 3. 提示信息分支逻辑存在扩展性隐患(最佳实践与可维护性)
    - **问题描述**:在拼装限制提示信息时,代码使用了 `if (StrategyTypeEnum.FINAL_INVENTORY.getValue().equals(reqDTO.getStrategyType()))` 判断类型 6,而对于类型 5(强力促销)使用了 `else` 兜底处理。
    - **影响分析**:目前 DTO 注释说明只有 5 和 6 两种类型。但如果未来业务扩展,新增了策略类型(例如类型 7),现有的 `else` 逻辑会错误地将类型 7 也提示为“当前时间段无打折相关策略”,导致提示信息与实际业务不符,增加排查成本。
    - **优化建议**:建议对策略类型进行严格的枚举匹配,消除魔术数字的隐性依赖,并为未知的策略类型提供统一的默认提示或抛出异常。
      ```java
      if (StrategyTypeEnum.FINAL_INVENTORY.getValue().equals(reqDTO.getStrategyType())) {
          respDTO.setMessage("当前时间段无冲量策略,请联系运营处理");
      } else if (StrategyTypeEnum.STRONG_PROMOTION.getValue().equals(reqDTO.getStrategyType())) { // 假设存在强力促销枚举
          respDTO.setMessage("当前时间段无打折相关策略,请联系运营处理");
      } else {
          respDTO.setMessage("当前时间段无可用策略,请联系运营处理");
      }
    

    二、评分明细

    1. 功能实现的正确性与健壮性(34/40分)

      • 理由:未违反 MyBatis 子查询和 Dubbo 参数变更的红线规则。核心业务逻辑基本通顺,但严重缺乏对核心入参的空值和有效性校验,存在较高的 NPE 风险和业务逻辑击穿风险,扣 6 分。
    2. 安全性与潜在风险(30/30分)

      • 理由:使用了 tk.mybatis 的 Example 进行查询,底层采用预编译处理,无 SQL 注入风险。未见越权或敏感信息泄露风险,满分。
    3. 最佳实践与可维护性(17/20分)

      • 理由:代码结构清晰,DTO 命名规范,Swagger 注解完备。但在业务分支判断上过度依赖 else 兜底,未充分利用枚举的严谨性,扩展性存在瑕疵,扣 3 分。
    4. 性能与资源利用(2/5分)

      • 理由:使用 SELECT *(selectByExample)来代替 SELECT COUNT 判断数据是否存在,属于典型的 ORM 框架使用反模式,造成了不必要的性能损耗,扣 3 分。
    5. 提交信息质量(5/5分)

      • 理由:Commit 信息“精品升级下单新增策略类型校验”清晰明了,准确概括了本次代码提交的业务意图,满分。

    总分:88分

Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!