Commit 4e5df44f by zhouhaibao

[+]新增预警管理

1 parent d5af456b
Showing 28 changed files with 1078 additions and 42 deletions
package cn.com.glsx.dj.mindworkplate.dto;
import lombok.Data;
@Data
public class MerchantIdSceneDTO {
/**
* 商户号
*/
private Integer merchantId;
/**
* 场景
*/
private Integer sceneType;
}
package cn.com.glsx.dj.mindworkplate.dto.monitoring;
import java.util.List;
import lombok.Data;
/**
* 盯防指标筛选请求参数
*/
@Data
public class MonitorBaseRequest implements java.io.Serializable{
/**
* 业务 1.延保 2.轻改 3.权益
*/
private Integer businessType;
/**
* 盯防类型:1=兜底指标(默认),2=生态系数
*/
private Integer monitorType;
/**
* 指标类型ID
*/
private Integer metricTypeId;
/**
* 日期类型:0,按日;1,按周;2,按月;3,按年;4,按查询时间段汇总;
*/
private Integer periodType;
/**
* 开始日期,格式:yyyy-MM-dd
*/
private String startDate;
/**
* 结束日期,格式:yyyy-MM-dd
*/
private String endDate;
/**
* 商户ID列表
*/
List<Integer> merchantIds;
/**
* 用户ID
*/
private List<String> uuidLists;
/**
* 分组类型,如果不传默认策略配置的类型,1.员工 2.门店
*/
private Integer exts;
/**
* 是否查询下一时间段数据
*/
private boolean findNextTimeDataFlag=false;
}
\ No newline at end of file
package cn.com.glsx.dj.mindworkplate.dto.monitoring;
import lombok.Data;
import java.util.List;
/**
* 盯防指标筛选请求参数
*/
@Data
public class MonitorFilterRequest extends MonitorBaseRequest{
/**
* 区域ID:0=全部,其他为省份整型ID(如内部编码)
*/
private Integer regionId ;
/**
* 品牌ID列表:空列表表示“全部”,支持一级品牌ID
*/
private List<Integer> firstbrandIds;
/**
* 二级品牌ids
*/
private List<Integer> twoBrandIds;
/**
* 区域运营员工ID
*/
private String regionalOperatorId ;
/**
* 线上运营员工ID
*/
private String onlineOperatorId;
}
\ No newline at end of file
package cn.com.glsx.dj.mindworkplate.dto.monitoring;
import java.io.Serializable;
import lombok.Data;
import java.util.List;
/**
* 单个门店展示信息
*/
@Data
public class StoreItemResponse implements Serializable {
/**
* 商户号
*/
private String merchantNo;
/**
* 门店名称(商户名称)
*/
private String storeName;
/**
* 主营品牌(一级-子品牌),多个用 "/" 拼接,前端控制显示长度 + 悬浮窗
* 示例:"丰田-凯美瑞/本田-雅阁"
*/
private String mainBrands; // 如 "丰田-凯美瑞/本田-雅阁"
/**
* 线上运营人员姓名,多个用 "/" 拼接
* 示例:"张三/李四"
*/
private String onlineOperators;
/**
* 区域运营人员姓名,多个用 "/" 拼接
* 示例:"王五/赵六"
*/
private String regionalOperators;
/**
* 预警事项摘要:最多展示2条,用于列表快速预览
* 示例:
* - "「转化率」低于兜底目标「80%」"
* - "「生态系数-活跃度」低于「0.6」"
*/
private List<String> warningSummary;
/**
* 当前门店在当前筛选条件下存在的预警事项总数量
*/
private int warningTotalCount;
}
\ No newline at end of file
......@@ -117,5 +117,14 @@ public class EarlyWarningRuleCondition {
@Transient
private String endDate;
/**
* 分组类型,如果不传默认策略配置的类型,1.员工 2.门店
*/
@Transient
private Integer exts;
@Transient
private String ruleType;
}
\ No newline at end of file
package cn.com.glsx.dj.mindworkplate.model;
import java.math.BigDecimal;
import java.util.Date;
import javax.persistence.*;
@Table(name = "eco_coefficient_rule")
public class EcoCoefficientRule {
/**
* 主键
*/
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
/**
* 指标编码,如 A091, A077
*/
@Column(name = "indicator_code")
private String indicatorCode;
/**
* 渗透率下限(含),范围 [0.0000, 1.0000]
*/
@Column(name = "min_penetration")
private BigDecimal minPenetration;
/**
* 渗透率上限(不含),NULL 表示无穷大
*/
@Column(name = "max_penetration")
private BigDecimal maxPenetration;
/**
* 生态系数
*/
private BigDecimal coefficient;
/**
* 排序字段,用于区间顺序
*/
@Column(name = "sort_order")
private Integer sortOrder;
/**
* 是否启用:1-是,0-否
*/
private Boolean enabled;
@Column(name = "create_time")
private Date createTime;
@Column(name = "update_time")
private Date updateTime;
/**
* 获取主键
*
* @return id - 主键
*/
public Long getId() {
return id;
}
/**
* 设置主键
*
* @param id 主键
*/
public void setId(Long id) {
this.id = id;
}
/**
* 获取指标编码,如 A091, A077
*
* @return indicator_code - 指标编码,如 A091, A077
*/
public String getIndicatorCode() {
return indicatorCode;
}
/**
* 设置指标编码,如 A091, A077
*
* @param indicatorCode 指标编码,如 A091, A077
*/
public void setIndicatorCode(String indicatorCode) {
this.indicatorCode = indicatorCode == null ? null : indicatorCode.trim();
}
/**
* 获取渗透率下限(含),范围 [0.0000, 1.0000]
*
* @return min_penetration - 渗透率下限(含),范围 [0.0000, 1.0000]
*/
public BigDecimal getMinPenetration() {
return minPenetration;
}
/**
* 设置渗透率下限(含),范围 [0.0000, 1.0000]
*
* @param minPenetration 渗透率下限(含),范围 [0.0000, 1.0000]
*/
public void setMinPenetration(BigDecimal minPenetration) {
this.minPenetration = minPenetration;
}
/**
* 获取渗透率上限(不含),NULL 表示无穷大
*
* @return max_penetration - 渗透率上限(不含),NULL 表示无穷大
*/
public BigDecimal getMaxPenetration() {
return maxPenetration;
}
/**
* 设置渗透率上限(不含),NULL 表示无穷大
*
* @param maxPenetration 渗透率上限(不含),NULL 表示无穷大
*/
public void setMaxPenetration(BigDecimal maxPenetration) {
this.maxPenetration = maxPenetration;
}
/**
* 获取生态系数
*
* @return coefficient - 生态系数
*/
public BigDecimal getCoefficient() {
return coefficient;
}
/**
* 设置生态系数
*
* @param coefficient 生态系数
*/
public void setCoefficient(BigDecimal coefficient) {
this.coefficient = coefficient;
}
/**
* 获取排序字段,用于区间顺序
*
* @return sort_order - 排序字段,用于区间顺序
*/
public Integer getSortOrder() {
return sortOrder;
}
/**
* 设置排序字段,用于区间顺序
*
* @param sortOrder 排序字段,用于区间顺序
*/
public void setSortOrder(Integer sortOrder) {
this.sortOrder = sortOrder;
}
/**
* 获取是否启用:1-是,0-否
*
* @return enabled - 是否启用:1-是,0-否
*/
public Boolean getEnabled() {
return enabled;
}
/**
* 设置是否启用:1-是,0-否
*
* @param enabled 是否启用:1-是,0-否
*/
public void setEnabled(Boolean enabled) {
this.enabled = enabled;
}
/**
* @return create_time
*/
public Date getCreateTime() {
return createTime;
}
/**
* @param createTime
*/
public void setCreateTime(Date createTime) {
this.createTime = createTime;
}
/**
* @return update_time
*/
public Date getUpdateTime() {
return updateTime;
}
/**
* @param updateTime
*/
public void setUpdateTime(Date updateTime) {
this.updateTime = updateTime;
}
}
\ No newline at end of file
package cn.com.glsx.dj.mindworkplate.model;
import cn.com.glsx.dj.mindworkplate.model.warning.Rule;
import io.swagger.annotations.ApiModelProperty;
import java.io.Serializable;
import java.util.Date;
import java.util.List;
import javax.persistence.*;
import lombok.Data;
@Table(name = "monitor_type_dict")
@Data
public class MonitorTypeDict implements Serializable {
@Id
@Column(name = "id")
@ApiModelProperty(value = "盯防类型ID")
private Integer id;
/**
* 盯防类型编码:1-兜底指标,2-生态系数
*/
@Id
@Column(name = "type_code")
@ApiModelProperty(value = "盯防类型编码:1-兜底指标,2-生态系数")
private Byte typeCode;
/**
* 类型名称
*/
@Column(name = "type_name")
@ApiModelProperty(value = "类型名称")
private String typeName;
/**
* 描述
*/
@Column(name = "description")
@ApiModelProperty(value = "描述")
private String description;
/**
* 排序
*/
@Column(name = "sort_order")
@ApiModelProperty(value = "排序")
private Integer sortOrder;
/**
* 是否启用:1-启用,0-禁用
*/
@Column(name = "is_enabled")
@ApiModelProperty(value = "是否启用:1-启用,0-禁用")
private Boolean enabled;
@Column(name = "create_time")
@ApiModelProperty(value = "创建时间")
private Date createTime;
@Transient
@ApiModelProperty(value = "规则")
private List<Rule> rules;
}
\ No newline at end of file
package cn.com.glsx.dj.mindworkplate.model.warning;
import java.io.Serializable;
import java.math.BigDecimal;
import lombok.Data;
/**
* 学习效果分析 - 响应结果
*/
@Data
public class LearningEffectAnalysisDTO implements Serializable {
private static final long serialVersionUID = 1L;
/**
* 学习前指标
*/
private MonMetricsDTO beforeLearning;
/**
* 学习后指标
*/
private MonMetricsDTO afterLearning;
}
\ No newline at end of file
package cn.com.glsx.dj.mindworkplate.model.warning;
import java.io.Serializable;
import lombok.Data;
/**
* 学习效果分析 - 请求参数
*/
@Data
public class LearningEffectAnalysisRequest implements Serializable {
private static final long serialVersionUID = 1L;
/**
* 分析周期(单位:天)
* 7 -> 一周
* 14 -> 两周
* 30 -> 一月
*/
private Integer analysisPeriodDays; // 必填
/**
* 门店ID 或 用户ID(根据业务)
*/
private Integer merchantId;
/**
* 员工ID
*/
private String staffId;
/**
* 可选:开始日期(若不传,则自动计算为当前时间往前推 analysisPeriodDays)
*/
private String startDate; // 格式: yyyy-MM-dd
/**
* 可选:结束日期
*/
private String endDate; // 格式: yyyy-MM-dd
/**
* 业务类型:2.轻改(,3.权益,4.延保
*/
private Integer businessType;
}
\ No newline at end of file
package cn.com.glsx.dj.mindworkplate.model.warning;
import java.math.BigDecimal;
import lombok.Data;
/**
* 核心业务指标集合
*/
@Data
public class MonMetricsDTO implements java.io.Serializable {
/**
* 转化率(百分比数值,如 55.0 表示 55%)
*/
private BigDecimal conversionRate; // %
/**
* 客单价(金额)
*/
private BigDecimal avgOrderAmount; // 元
/**
* 套餐销售率(百分比)
*/
private BigDecimal packageSalesRate; // %
/**
* 整车延保渗透率(百分比)
*/
private BigDecimal wholeVehicleWarrantyPenetration; // %
/**
* 安心包渗透率(注意:UI 显示为金额,但逻辑应为百分比?)
* ⚠️ 根据你提供的数据:
* "安心包渗透率 8888.00 → 9600.00" —— 这看起来像 **客单价**,不是渗透率!
* 建议确认业务含义。
*
* 方案 A(按渗透率):用百分比(BigDecimal)
* 方案 B(按金额):用金额(BigDecimal),但字段名应为 `anxinPackageAvgPrice`
*
* 此处按 **渗透率(百分比)** 设计,若实际是金额,请重命名字段!
*/
private BigDecimal anxinPackagePenetration; // %
/**
* 电池渗透率(百分比)
*/
private BigDecimal batteryPenetration; // %
/**
* 轮胎渗透率(百分比)
*/
private BigDecimal tirePenetration; // %
}
\ No newline at end of file
package cn.com.glsx.dj.mindworkplate.model.warning;
import io.swagger.annotations.ApiModelProperty;
import java.io.Serializable;
import java.math.BigDecimal;
import lombok.Data;
@Data
public class MonitoringMsgDTO implements Serializable {
/**
* 生成预警消息的规则id
*/
private Integer ruleId;
/**
* 员工id
*/
private String staffId;
/**
* 员工姓名
*/
private String staffName;
/**
* 员工手机号
*/
private String staffPhone;
/**
* 4s店门店号
*/
private Integer merchantId4s;
/**
* 4s门店名称
*/
private String merchantName4s;
/**
* 预警类型
*/
private String ruleType;
/**
* 预警事项
*/
@ApiModelProperty(notes = "预警事项")
private String rule;
/**
* 预警明细说明
*/
private String msgDetail;
/**
* 周期指标值
*/
private BigDecimal cycleIndicator;
/**
* 兜底指标
*/
private BigDecimal fallbackIndicator;
@ApiModelProperty(notes = "预警明细")
private String ruleDetail;
@ApiModelProperty(notes = "盯店描述")
private String warningText;
/**
* 下期指标值
*/
private BigDecimal nextCycleIndicator;
}
\ No newline at end of file
package cn.com.glsx.dj.mindworkplate.model.warning;
import java.math.BigDecimal;
import java.util.List;
import lombok.Data;
import java.io.Serializable;
......@@ -146,4 +148,31 @@ public class Rule implements Serializable {
@Column(name = "static_cycle")
private Integer staticCycle;
/**
* 触发条件值
*/
@Column(name = "condition_value")
private BigDecimal conditionValue;
@Transient
private String startTime;
@Transient
private String endTime;
@Transient
private List<Integer> merchantIds;
@Transient
private List<String> uuidList;
/**
* 分组类型,如果不传默认策略配置的类型,1.员工 2.门店
*/
@Transient
private Integer exts;
}
\ No newline at end of file
......@@ -234,6 +234,10 @@ public class WarningMsg implements Serializable {
@ApiModelProperty(notes = "预警明细")
private String ruleDetail;
@Transient
@ApiModelProperty(notes = "盯店描述")
private String warningText;
public WarningMsg() {
}
......
package cn.com.glsx.dj.mindworkplate.remote;
import cn.com.glsx.dj.mindworkplate.dto.monitoring.MonitorBaseRequest;
import cn.com.glsx.dj.mindworkplate.model.warning.MonitoringMsgDTO;
import cn.com.glsx.framework.core.annotation.ApiMethod;
import cn.com.glsx.framework.core.annotation.ApiParam;
import cn.com.glsx.framework.core.annotation.ApiParam.DataTypeEnum;
import cn.com.glsx.framework.core.annotation.ApiResponse;
import cn.com.glsx.framework.core.annotation.ApiService;
import cn.com.glsx.framework.core.beans.rpc.RpcResponse;
import java.util.List;
@ApiService(value = "策略中心", owner = "zhouhb")
public interface MonitoringRemote {
@ApiMethod("根据条件查询所有预警")
@ApiParam(name="request",notes="入参",dataType= DataTypeEnum.OBJECT,required=true)
@ApiResponse("预警信息")
RpcResponse<List<MonitoringMsgDTO>> getMonitorListByCondition(MonitorBaseRequest request) ;
}
package cn.com.glsx.dj.mindworkplate.mapper;
import cn.com.glsx.dj.mindworkplate.model.EcoCoefficientRule;
import java.util.List;
import org.apache.ibatis.annotations.Mapper;
import org.oreframework.datasource.mybatis.mapper.OreMapper;
@Mapper
public interface EcoCoefficientRuleMapper extends OreMapper<EcoCoefficientRule> {
List<EcoCoefficientRule> selectAllEnabledRules();
}
\ No newline at end of file
package cn.com.glsx.dj.mindworkplate.mapper;
import cn.com.glsx.dj.mindworkplate.model.MonitorTypeDict;
import java.util.List;
import org.apache.ibatis.annotations.Mapper;
import org.oreframework.datasource.mybatis.mapper.OreMapper;
@Mapper
public interface MonitorTypeDictMapper extends OreMapper<MonitorTypeDict> {
List<MonitorTypeDict> findMonitorTypeDictList();
}
\ No newline at end of file
......@@ -20,4 +20,6 @@ public interface RuleMapper extends OreMapper<Rule> {
List<Rule> selectByType(@Param("type") Integer type);
List<WarningMsgRuleModel> executePrefixSql(@Param("ruleSql") String ruleSql);
List<Rule> selectByTypeAndMetricType(Integer businessType,Integer monitorType, Integer metricTypeId);
}
\ No newline at end of file
package cn.com.glsx.dj.mindworkplate.service.monitoring;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
public class LearningPeriodCalculator {
private static final DateTimeFormatter FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd");
/**
* 计算学习前、学习后的时间范围
*
* @param startDateStr 执行周期开始时间(格式: yyyy-MM-dd)
* @param endDateStr 执行周期结束时间(格式: yyyy-MM-dd)
* @param periodDays 分析周期天数(7=一周, 14=两周, 30=一月)
* @return 包含四个时间点的结果对象
*/
public static LearningTimeRange calculateLearningPeriod(
String startDateStr,
String endDateStr,
int periodDays) {
LocalDate startDate = LocalDate.parse(startDateStr, FORMATTER);
LocalDate endDate = LocalDate.parse(endDateStr, FORMATTER);
// 学习前:从 (startDate - periodDays) 到 startDate
LocalDate beforeStart = startDate.minusDays(periodDays);
LocalDate beforeEnd = startDate.minusDays(1); // 通常“前”不包含 start 当天
// 学习后:从 (endDate + 1) 到 (endDate + periodDays)
LocalDate afterStart = endDate.plusDays(1);
LocalDate afterEnd = endDate.plusDays(periodDays);
return new LearningTimeRange(
beforeStart.format(FORMATTER),
beforeEnd.format(FORMATTER),
afterStart.format(FORMATTER),
afterEnd.format(FORMATTER)
);
}
// -------------------------
// 结果封装类
// -------------------------
public static class LearningTimeRange {
private final String beforeStartDate; // 学习前开始
private final String beforeEndDate; // 学习前结束
private final String afterStartDate; // 学习后开始
private final String afterEndDate; // 学习后结束
public LearningTimeRange(String beforeStartDate, String beforeEndDate,
String afterStartDate, String afterEndDate) {
this.beforeStartDate = beforeStartDate;
this.beforeEndDate = beforeEndDate;
this.afterStartDate = afterStartDate;
this.afterEndDate = afterEndDate;
}
// Getters
public String getBeforeStartDate() { return beforeStartDate; }
public String getBeforeEndDate() { return beforeEndDate; }
public String getAfterStartDate() { return afterStartDate; }
public String getAfterEndDate() { return afterEndDate; }
@Override
public String toString() {
return String.format(
"学习前: [%s, %s], 学习后: [%s, %s]",
beforeStartDate, beforeEndDate, afterStartDate, afterEndDate
);
}
}
}
\ No newline at end of file
package cn.com.glsx.dj.mindworkplate.service.warning;
import cn.com.glsx.dj.mindworkplate.mapper.EcoCoefficientRuleMapper;
import cn.com.glsx.dj.mindworkplate.model.EcoCoefficientRule;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.annotation.PostConstruct;
import java.math.BigDecimal;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;
@Slf4j
@Service
public class EcoCoefficientService {
@Autowired
private EcoCoefficientRuleMapper ruleMapper;
// 内存缓存:Map<indicatorCode, List<规则(按min升序)>>
private final Map<String, List<EcoCoefficientRule>> ruleCache = new ConcurrentHashMap<>();
@PostConstruct
public void init() {
reloadRules();
}
/**
* 重新加载规则到内存(可用于定时刷新或配置变更后调用)
*/
public void reloadRules() {
List<EcoCoefficientRule> rules = ruleMapper.selectAllEnabledRules();
Map<String, List<EcoCoefficientRule>> grouped = rules.stream()
.collect(Collectors.groupingBy(
EcoCoefficientRule::getIndicatorCode,
Collectors.collectingAndThen(
Collectors.toList(),
list -> list.stream()
.sorted(Comparator.comparing(EcoCoefficientRule::getMinPenetration))
.collect(Collectors.toList())
)
));
ruleCache.clear();
ruleCache.putAll(grouped);
log.info("生态系数规则加载完成,共 {} 条规则,覆盖 {} 个指标", rules.size(), grouped.size());
}
/**
* 根据指标编码和渗透率获取生态系数
*
* @param indicatorCode 指标编码,如 "A091"
* @param penetration 渗透率(0.0 ~ 1.0),如 0.25 表示 25%
* @return 生态系数
* @throws IllegalArgumentException 如果未找到匹配规则
*/
public BigDecimal getCoefficient(String indicatorCode, double penetration) {
if (penetration < 0 || penetration > 1.0) {
throw new IllegalArgumentException("渗透率必须在 [0.0, 1.0] 范围内");
}
List<EcoCoefficientRule> rules = ruleCache.get(indicatorCode);
if (rules == null || rules.isEmpty()) {
throw new IllegalArgumentException("未配置指标 [" + indicatorCode + "] 的生态系数规则");
}
for (EcoCoefficientRule rule : rules) {
BigDecimal min = rule.getMinPenetration();
BigDecimal max = rule.getMaxPenetration();
boolean match = (new BigDecimal(penetration).compareTo(min) >= 0) &&
(max == null || new BigDecimal(penetration).compareTo(max) < 0);
if (match) {
return rule.getCoefficient();
}
}
throw new IllegalStateException("指标 [" + indicatorCode + "] 的规则未覆盖渗透率: " + penetration);
}
}
\ No newline at end of file
......@@ -282,4 +282,8 @@ public class RuleService {
public Rule selectById(Integer ruleId) {
return ruleMapper.selectByPrimaryKey(ruleId);
}
}
......@@ -33,25 +33,11 @@ public interface ConditionStrategy {
throw new RuntimeException("比较值值配置为空");
}
// 获取操作符、阈值和连续天数
Integer continuousDays = earlyWarningRuleCondition.getContinuousDays();
Integer dynamicTimeRangeValue = earlyWarningRuleCondition.getDynamicTimeRangeValue();
Integer fieldValueType = earlyWarningRuleCondition.getFieldValueType();
if (continuousDays == null && dynamicTimeRangeValue == null ) {
throw new RuntimeException("continuousDays或者dynamicTimeRangeValue是空");
}
if (fieldValueType == null ) {
throw new RuntimeException("fieldValueType是空");
}
return buildDateParam(earlyWarningRuleCondition);
}
List<WarningMsgRuleModel> evaluate(EarlyWarningRuleCondition earlyWarningRuleCondition, QueryParams prepare);
default List<WarningMsgRuleModel> aftereValuate(EarlyWarningRuleCondition context, List<WarningMsgRuleModel> warningMsgRuleModels, List<WarningMsgRuleModel> evaluate){
if(context.getLogicalRelation()==null){
return getUnion(warningMsgRuleModels,evaluate);
......@@ -148,9 +134,11 @@ public interface ConditionStrategy {
static List<WarningMsgRuleModel> getItemDetailByStaff(EarlyWarningRuleCondition earlyWarningRuleCondition,List<ItemDetail> itemDetails,Integer continuousDays,Integer dynamicTimeRangeValue){
Byte monitorType = earlyWarningRuleCondition.getMonitorType();
if (monitorType == 1) {
// 按日期 + 员工分组
// 按日期 +门店+ 员工分组
Map<String, List<ItemDetail>> groupByDateAndStaff = itemDetails.stream()
.collect(Collectors.groupingBy(item -> item.getStaffId()));
.collect(Collectors.groupingBy(item ->
item.getMerchantId() + "_" + item.getStaffId() // 或使用 Pair/自定义 key
));
if(groupByDateAndStaff.isEmpty()){
return null;
}
......@@ -159,11 +147,14 @@ public interface ConditionStrategy {
return itemDetailByCondition.entrySet().stream()
.map(entry -> {
WarningMsgRuleModel warningMsgRuleModel = new WarningMsgRuleModel();
warningMsgRuleModel.setStaffId(entry.getKey());
warningMsgRuleModel.setStaffId(entry.getValue().get(0).getStaffId());
warningMsgRuleModel.setStaffName(entry.getValue().get(0).getStaffName());
warningMsgRuleModel.setStaffPhone(entry.getValue().get(0).getStaffPhone());
warningMsgRuleModel.setMerchantId4s(entry.getValue().get(0).getMerchantId());
warningMsgRuleModel.setMerchantName4s(entry.getValue().get(0).getMerchantName());
warningMsgRuleModel.setConfigValue(entry.getValue().get(0).getConfigValue());
warningMsgRuleModel.setConfigValueOld(entry.getValue().get(0).getConfigValueOld());
warningMsgRuleModel.setItemValue(entry.getValue().get(0).getItemValue());
return warningMsgRuleModel;
})
.collect(Collectors.toList());
......@@ -258,9 +249,56 @@ public interface ConditionStrategy {
}
static QueryParams buildDateParam(EarlyWarningRuleCondition earlyWarningRuleCondition){
Integer dynamicTimeRangeType = earlyWarningRuleCondition.getDynamicTimeRangeType();
// 获取操作符、阈值和连续天数,如果不等于null,则设置动态时间参数
QueryParams queryParams=new QueryParams();
queryParams.setBizs(Integer.valueOf(earlyWarningRuleCondition.getBussinessType()));
queryParams.setItemCodes(earlyWarningRuleCondition.getFieldName());
queryParams.setMerchantIds(earlyWarningRuleCondition.getMerchantIds());
if (earlyWarningRuleCondition.getStartDate() == null && earlyWarningRuleCondition.getEndDate() == null){
setDynamicTime(earlyWarningRuleCondition);
queryParams.setDateType(bulidDateType(earlyWarningRuleCondition.getTimeUnit()));
}else{
// 指定日期的默认4
queryParams.setDateType(4);
}
queryParams.setStartDate(earlyWarningRuleCondition.getStartDate());
queryParams.setEndDate(earlyWarningRuleCondition.getEndDate());
String brandParam = earlyWarningRuleCondition.getBrandParam();
if (brandParam != null){
queryParams.setBrandIds(brandParam);
}
Byte monitorType = earlyWarningRuleCondition.getMonitorType();
if (earlyWarningRuleCondition.getExts()!=null){
// 如果传了,按照业务侧的分组
monitorType=earlyWarningRuleCondition.getExts().byteValue();
}
if(monitorType!=null){
if(monitorType.intValue()==1){
queryParams.setExts("merchantIds,staffIds");
}
if(monitorType.intValue()==2){
queryParams.setExts("merchantIds");
}
}
return queryParams;
}
static void setDynamicTime(EarlyWarningRuleCondition earlyWarningRuleCondition) {
Integer continuousDays = earlyWarningRuleCondition.getContinuousDays();
Integer dynamicTimeRangeValue = earlyWarningRuleCondition.getDynamicTimeRangeValue();
// TODO sql日期实现
Integer fieldValueType = earlyWarningRuleCondition.getFieldValueType();
if (continuousDays == null && dynamicTimeRangeValue == null ) {
throw new RuntimeException("continuousDays或者dynamicTimeRangeValue是空");
}
if (fieldValueType == null ) {
throw new RuntimeException("fieldValueType是空");
}
Integer dynamicTimeRangeType = earlyWarningRuleCondition.getDynamicTimeRangeType();
LocalDate today = LocalDate.now(); // 当前日期
LocalDate endDate; // 结束日期
......@@ -297,29 +335,6 @@ public interface ConditionStrategy {
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
earlyWarningRuleCondition.setStartDate(startDate.format(formatter));
earlyWarningRuleCondition.setEndDate(endDate.format(formatter));
QueryParams queryParams=new QueryParams();
queryParams.setBizs(Integer.valueOf(earlyWarningRuleCondition.getBussinessType()));
queryParams.setItemCodes(earlyWarningRuleCondition.getFieldName());
queryParams.setMerchantIds(earlyWarningRuleCondition.getMerchantIds());
queryParams.setStartDate(earlyWarningRuleCondition.getStartDate());
queryParams.setEndDate(earlyWarningRuleCondition.getEndDate());
String brandParam = earlyWarningRuleCondition.getBrandParam();
if (brandParam != null){
queryParams.setBrandIds(brandParam);
}
queryParams.setDateType(bulidDateType(earlyWarningRuleCondition.getTimeUnit()));
Byte monitorType = earlyWarningRuleCondition.getMonitorType();
if(monitorType!=null){
if(monitorType.intValue()==1){
queryParams.setExts("staffIds");
}
if(monitorType.intValue()==2){
queryParams.setExts("merchantIds");
}
}
return queryParams;
}
static Integer bulidDateType(String timeUnit) {
......
......@@ -5,10 +5,12 @@ import cn.com.glsx.dj.mindworkplate.model.WarningMsgRuleModel;
import cn.com.glsx.dj.mindworkplate.service.warning.DateCountService;
import cn.com.glsx.dj.mindworkplate.service.warning.DateService.ItemDetail;
import cn.com.glsx.dj.mindworkplate.service.warning.DateService.QueryParams;
import cn.com.glsx.dj.mindworkplate.service.warning.EcoCoefficientService;
import java.math.BigDecimal;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
/**
* 数值类型比较
......@@ -20,6 +22,9 @@ public class NumericConditionStrategy implements ConditionStrategy {
@Autowired
private DateCountService dateCountService;
@Autowired
private EcoCoefficientService ecoCoefficientService;
@Override
public List<WarningMsgRuleModel> evaluate(EarlyWarningRuleCondition earlyWarningRuleCondition,
QueryParams prepare) {
......@@ -33,6 +38,15 @@ public class NumericConditionStrategy implements ConditionStrategy {
Integer continuousDays = earlyWarningRuleCondition.getContinuousDays();
Integer dynamicTimeRangeValue = earlyWarningRuleCondition.getDynamicTimeRangeValue();
String ruleType = earlyWarningRuleCondition.getRuleType();
if (("生态系数").equals(ruleType)){
if (!CollectionUtils.isEmpty(itemDetails)){
for (ItemDetail itemDetail : itemDetails) {
BigDecimal coefficient = ecoCoefficientService.getCoefficient(itemDetail.getItemCode(), itemDetail.getItemValue().doubleValue());
itemDetail.setItemValue(coefficient);
}
}
}
// 获取满足条件值
List<ItemDetail> itemValues = ConditionStrategy.evaluateCondition(itemDetails, operator, BigDecimal.valueOf(threshold),earlyWarningRuleCondition.getFieldValueType());
......
......@@ -6,6 +6,8 @@ import cn.com.glsx.dj.mindworkplate.model.WarningMsgRuleModel;
import cn.com.glsx.dj.mindworkplate.service.warning.DateCountService;
import cn.com.glsx.dj.mindworkplate.service.warning.DateService.ItemDetail;
import cn.com.glsx.dj.mindworkplate.service.warning.DateService.QueryParams;
import cn.com.glsx.dj.mindworkplate.service.warning.EcoCoefficientService;
import java.math.BigDecimal;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
......@@ -22,6 +24,9 @@ public class SqlConditionStrategy implements ConditionStrategy {
@Autowired
private DateCountService dateCountService;
@Autowired
private EcoCoefficientService ecoCoefficientService;
@Override
public List<WarningMsgRuleModel> evaluate(EarlyWarningRuleCondition earlyWarningRuleCondition,
QueryParams prepare) {
......@@ -36,6 +41,15 @@ public class SqlConditionStrategy implements ConditionStrategy {
Integer continuousDays = earlyWarningRuleCondition.getContinuousDays();
Integer dynamicTimeRangeValue = earlyWarningRuleCondition.getDynamicTimeRangeValue();
String ruleType = earlyWarningRuleCondition.getRuleType();
if (("生态系数").equals(ruleType)){
if (!org.springframework.util.CollectionUtils.isEmpty(itemDetails)){
for (ItemDetail itemDetail : itemDetails) {
BigDecimal coefficient = ecoCoefficientService.getCoefficient(itemDetail.getItemCode(), itemDetail.getItemValue().doubleValue());
itemDetail.setConfigValue(coefficient);
}
}
}
// 获取满足条件值
List<ItemDetail> itemValues = evaluateConditionList(itemDetails, operator, warningMsgRuleModels,earlyWarningRuleCondition.getFieldValueType());
......
<?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.mindworkplate.mapper.EcoCoefficientRuleMapper" >
<resultMap id="BaseResultMap" type="cn.com.glsx.dj.mindworkplate.model.EcoCoefficientRule" >
<!--
WARNING - @mbg.generated
-->
<id column="id" property="id" jdbcType="BIGINT" />
<result column="indicator_code" property="indicatorCode" jdbcType="VARCHAR" />
<result column="min_penetration" property="minPenetration" jdbcType="DECIMAL" />
<result column="max_penetration" property="maxPenetration" jdbcType="DECIMAL" />
<result column="coefficient" property="coefficient" jdbcType="DECIMAL" />
<result column="sort_order" property="sortOrder" jdbcType="INTEGER" />
<result column="enabled" property="enabled" jdbcType="BIT" />
<result column="create_time" property="createTime" jdbcType="TIMESTAMP" />
<result column="update_time" property="updateTime" jdbcType="TIMESTAMP" />
</resultMap>
<sql id="Base_Column_List" >
<!--
WARNING - @mbg.generated
-->
id, indicator_code, min_penetration, max_penetration, coefficient, sort_order, enabled,
create_time, update_time
</sql>
<select id="selectAllEnabledRules"
resultMap="BaseResultMap">
select * from eco_coefficient_rule where enabled = 1 order by sort_order
</select>
</mapper>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="cn.com.glsx.dj.mindworkplate.mapper.MonitorTypeDictMapper" >
<resultMap id="BaseResultMap" type="cn.com.glsx.dj.mindworkplate.model.MonitorTypeDict" >
<!--
WARNING - @mbg.generated
-->
<id column="type_code" property="typeCode" jdbcType="TINYINT" />
<result column="type_name" property="typeName" jdbcType="VARCHAR" />
<result column="description" property="description" jdbcType="VARCHAR" />
<result column="sort_order" property="sortOrder" jdbcType="INTEGER" />
<result column="enabled" property="enabled" jdbcType="BIT" />
<result column="create_time" property="createTime" jdbcType="TIMESTAMP" />
<!-- 一对多:ruleList -->
<collection
property="rules" ofType="cn.com.glsx.dj.mindworkplate.model.warning.Rule"
javaType="java.util.ArrayList">
<!-- 子表字段映射 -->
<id property="id" column="ruleId"/>
<result property="rule" column="ruleName"/>
</collection>
</resultMap>
<sql id="Base_Column_List" >
<!--
WARNING - @mbg.generated
-->
type_code, type_name, description, sort_order, enabled, create_time
</sql>
<select id="findMonitorTypeDictList"
resultType="cn.com.glsx.dj.mindworkplate.model.MonitorTypeDict">
select
t1.type_code as typeCode,
t1.type_name as typeName,
t2.id as ruleId,
t2.rule as ruleName
from monitor_type_dict t1
left join early_warning_rule t2 on t1.type_code = t2.monitor_type_dict_id
where t1.enabled = 1 and t2.deleted_flag ='N'
order by t1.sort_order
</select>
</mapper>
\ No newline at end of file
......@@ -64,4 +64,15 @@
<select id="executePrefixSql" resultMap="MsgModelResultMap">
${ruleSql}
</select>
<select id="selectByTypeAndMetricType"
resultType="cn.com.glsx.dj.mindworkplate.model.warning.Rule">
SELECT * FROM early_warning_rule
where 1=1 and strategy_flag=1 and del_flag='N' and
<if test="monitorType!=null">
and monitor_type_dict_id=#{monitorType}
</if>
<if test="metricTypeId!=null">
AND id=#{metricTypeId}
</if>
</select>
</mapper>
\ No newline at end of file
package cn.com.glsx.dj.mindworkplate.service;
import cn.com.glsx.dj.mindworkplate.dto.monitoring.MonitorFilterRequest;
import cn.com.glsx.dj.mindworkplate.dto.monitoring.StoreItemResponse;
import cn.com.glsx.dj.mindworkplate.model.EarlyWarningThresholdConfig;
import cn.com.glsx.dj.mindworkplate.model.EmployeeWeeklyStatsDTO;
import cn.com.glsx.dj.mindworkplate.model.MonitorTypeDict;
import cn.com.glsx.dj.mindworkplate.model.WarningNotification;
import cn.com.glsx.dj.mindworkplate.model.WeekRange;
import cn.com.glsx.dj.mindworkplate.request.warning.EmployeeDailyStatsReq;
import cn.com.glsx.dj.mindworkplate.service.monitoring.MonitoringService;
import cn.com.glsx.dj.mindworkplate.service.warning.WarningNotificationService;
import cn.com.glsx.dj.smartcarlife.dto.worktoolpush.RecordRequestDTO;
import cn.com.glsx.dj.smartcarlife.enums.ActionReportTypeEnum;
......@@ -35,6 +39,9 @@ public class EarlyWarningTest extends BaseServiceTest{
@Autowired
private WarningNotificationService warningNotificationService;
@Autowired
private MonitoringService monitoringService;
@Test
public void addPushRecordRemoteTest() throws Exception {
RecordRequestDTO requestDTO = new RecordRequestDTO();
......@@ -121,4 +128,18 @@ public class EarlyWarningTest extends BaseServiceTest{
System.out.println("aa"+JSONObject.toJSONString(warningNotificationPage));
}
@Test
public void findMonitorListPage() throws ParseException {
MonitorFilterRequest request=new MonitorFilterRequest();
request.setStartDate("2024-11-01");
request.setEndDate("2024-11-18");
List<StoreItemResponse> monitorListPage = monitoringService.findMonitorListPage(request);
System.out.println("aa"+JSONObject.toJSONString(monitorListPage));
}
@Test
public void findMonitorTypeDictList() throws ParseException {
List<MonitorTypeDict> monitorTypeDictList = monitoringService.findMonitorTypeDictList();
System.out.println("aa"+JSONObject.toJSONString(monitorTypeDictList));
}
}
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!