Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
dj
/
rpc-dj-strategy
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 94c78e91
authored
Jan 22, 2026
by
杨卫
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
feat:效果分析
1 parent
1c094d7b
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
31 changed files
with
1495 additions
and
7 deletions
rpc-dj-strategy-api/src/main/java/cn/com/glsx/dj/strategy/dto/MerchantStrategyStatisticsReqDTO.java
rpc-dj-strategy-api/src/main/java/cn/com/glsx/dj/strategy/dto/MerchantStrategyStatisticsRespDTO.java
rpc-dj-strategy-api/src/main/java/cn/com/glsx/dj/strategy/dto/MonthRangeDTO.java
rpc-dj-strategy-api/src/main/java/cn/com/glsx/dj/strategy/dto/PercentageResultDTO.java
rpc-dj-strategy-api/src/main/java/cn/com/glsx/dj/strategy/dto/StatisticItemDTO.java
rpc-dj-strategy-api/src/main/java/cn/com/glsx/dj/strategy/dto/StrategyDetailReqDTO.java
rpc-dj-strategy-api/src/main/java/cn/com/glsx/dj/strategy/dto/StrategyMerchantCountDTO.java
rpc-dj-strategy-api/src/main/java/cn/com/glsx/dj/strategy/dto/StrategyOnlineStatisticsRespDTO.java
rpc-dj-strategy-api/src/main/java/cn/com/glsx/dj/strategy/dto/StrategyStatisticsReqDTO.java
rpc-dj-strategy-api/src/main/java/cn/com/glsx/dj/strategy/dto/StrategyTotalStatisticsRespDTO.java
rpc-dj-strategy-api/src/main/java/cn/com/glsx/dj/strategy/dto/StrategyTypeStatisticsDTO.java
rpc-dj-strategy-api/src/main/java/cn/com/glsx/dj/strategy/dto/StrategyTypeStatisticsRespDTO.java
rpc-dj-strategy-api/src/main/java/cn/com/glsx/dj/strategy/enums/StrategyErrorEnum.java
rpc-dj-strategy-api/src/main/java/cn/com/glsx/dj/strategy/model/StrategyInfo.java
rpc-dj-strategy-api/src/main/java/cn/com/glsx/dj/strategy/remote/StrategyDetailRemote.java
rpc-dj-strategy/src/main/java/cn/com/glsx/dj/strategy/config/BeanConfig.java
rpc-dj-strategy/src/main/java/cn/com/glsx/dj/strategy/config/MerchantDubboConfig.java
rpc-dj-strategy/src/main/java/cn/com/glsx/dj/strategy/converter/StrategyInfoConverter.java
rpc-dj-strategy/src/main/java/cn/com/glsx/dj/strategy/mapper/StrategyInfoMapper.java
rpc-dj-strategy/src/main/java/cn/com/glsx/dj/strategy/remote/StrategyDetailRemoteImpl.java
rpc-dj-strategy/src/main/java/cn/com/glsx/dj/strategy/service/StrategyDetailService.java
rpc-dj-strategy/src/main/java/cn/com/glsx/dj/strategy/util/LocalDateUtil.java
rpc-dj-strategy/src/main/java/cn/com/glsx/dj/strategy/util/PercentageCalculator.java
rpc-dj-strategy/src/main/java/cn/com/glsx/dj/strategy/util/validation/BeanValidationUtils.java
rpc-dj-strategy/src/main/java/cn/com/glsx/dj/strategy/util/validation/ErrorDetail.java
rpc-dj-strategy/src/main/java/cn/com/glsx/dj/strategy/util/validation/ValidationResult.java
rpc-dj-strategy/src/main/java/cn/com/glsx/dj/strategy/util/validation/validator/DateCheck.java
rpc-dj-strategy/src/main/java/cn/com/glsx/dj/strategy/util/validation/validator/DateStringValidator.java
rpc-dj-strategy/src/main/java/cn/com/glsx/dj/strategy/util/validation/validator/InList.java
rpc-dj-strategy/src/main/java/cn/com/glsx/dj/strategy/util/validation/validator/InListValidator.java
rpc-dj-strategy/src/main/resources/META-INF/orm/StrategyInfoMapper.xml
rpc-dj-strategy-api/src/main/java/cn/com/glsx/dj/strategy/dto/MerchantStrategyStatisticsReqDTO.java
0 → 100644
View file @
94c78e9
package
cn
.
com
.
glsx
.
dj
.
strategy
.
dto
;
import
lombok.AllArgsConstructor
;
import
lombok.Data
;
import
lombok.NoArgsConstructor
;
import
lombok.experimental.Accessors
;
import
lombok.experimental.SuperBuilder
;
import
javax.validation.constraints.NotBlank
;
import
javax.validation.constraints.NotEmpty
;
import
javax.validation.constraints.NotNull
;
import
java.io.Serializable
;
import
java.util.Date
;
import
java.util.List
;
/**
* 门店策略统计请求对象
* @author yangwei
* @version 1.0
* @since 2026/01/16 15:02
*/
@Data
@SuperBuilder
@NoArgsConstructor
@AllArgsConstructor
@Accessors
(
chain
=
true
)
public
class
MerchantStrategyStatisticsReqDTO
implements
Serializable
{
private
static
final
long
serialVersionUID
=
-
8402719542496732084L
;
/**
* 开始日期
*/
@NotNull
(
message
=
"开始日期不能为空"
)
private
Date
startDate
;
/**
* 结束日期
*/
@NotNull
(
message
=
"结束日期不能为空"
)
private
Date
endDate
;
/**
* bi侧业务类型,1.延保 2.轻改 3.权益
*/
@NotBlank
(
message
=
"业务类型不能为空"
)
private
String
businessType
;
/**
* 门店编号列表
*/
@NotEmpty
(
message
=
"门店编号不能为空"
)
private
List
<
Integer
>
merchantNos
;
}
rpc-dj-strategy-api/src/main/java/cn/com/glsx/dj/strategy/dto/MerchantStrategyStatisticsRespDTO.java
0 → 100644
View file @
94c78e9
package
cn
.
com
.
glsx
.
dj
.
strategy
.
dto
;
import
lombok.Data
;
import
java.io.Serializable
;
/**
* 门店策略统计
* @author yangwei
* @version 1.0
* @since 2026/01/22 16:29
*/
@Data
public
class
MerchantStrategyStatisticsRespDTO
implements
Serializable
{
/**
* 门店编号
*/
private
Integer
merchantNo
;
/**
* 策略数量
*/
private
Integer
strategyCount
;
}
rpc-dj-strategy-api/src/main/java/cn/com/glsx/dj/strategy/dto/MonthRangeDTO.java
0 → 100644
View file @
94c78e9
package
cn
.
com
.
glsx
.
dj
.
strategy
.
dto
;
import
io.swagger.annotations.ApiModel
;
import
io.swagger.annotations.ApiModelProperty
;
import
lombok.AllArgsConstructor
;
import
lombok.Data
;
import
lombok.NoArgsConstructor
;
import
java.io.Serializable
;
/**
* 月份日期范围DTO
* @author yangwei
* @version 1.0
* @since 2026/01/21 15:30
*/
@Data
@NoArgsConstructor
@AllArgsConstructor
@ApiModel
(
description
=
"月份日期范围"
)
public
class
MonthRangeDTO
implements
Serializable
{
private
static
final
long
serialVersionUID
=
1L
;
/**
* 当月第一天
*/
@ApiModelProperty
(
name
=
"firstDay"
,
notes
=
"当月第一天"
,
example
=
"2026-01-01"
)
private
String
firstDay
;
/**
* 当月最后一天
*/
@ApiModelProperty
(
name
=
"lastDay"
,
notes
=
"当月最后一天"
,
example
=
"2026-01-31"
)
private
String
lastDay
;
}
rpc-dj-strategy-api/src/main/java/cn/com/glsx/dj/strategy/dto/PercentageResultDTO.java
0 → 100644
View file @
94c78e9
package
cn
.
com
.
glsx
.
dj
.
strategy
.
dto
;
import
io.swagger.annotations.ApiModel
;
import
io.swagger.annotations.ApiModelProperty
;
import
lombok.AllArgsConstructor
;
import
lombok.Data
;
import
lombok.NoArgsConstructor
;
import
java.io.Serializable
;
import
java.math.BigDecimal
;
/**
* 百分比统计结果DTO(通用)
* 适用于任何需要计算占比的统计场景
* @author yangwei
* @version 1.0
* @since 2026/01/21 17:03
* @param <T> 统计维度的类型(如:策略类型String、商户ID Integer等)
*/
@Data
@NoArgsConstructor
@AllArgsConstructor
@ApiModel
(
description
=
"百分比统计结果"
)
public
class
PercentageResultDTO
<
T
>
implements
Serializable
{
private
static
final
long
serialVersionUID
=
1L
;
/**
* 统计维度(如:策略类型、商户名称、业务类型等)
*/
@ApiModelProperty
(
name
=
"dimension"
,
notes
=
"统计维度"
,
example
=
"MENTORING"
)
private
T
dimension
;
/**
* 统计维度的显示名称(可选,用于前端展示)
*/
@ApiModelProperty
(
name
=
"dimensionName"
,
notes
=
"统计维度显示名称"
,
example
=
"师徒帮带"
)
private
String
dimensionName
;
/**
* 数值(支持任意数值类型)
*/
@ApiModelProperty
(
name
=
"value"
,
notes
=
"统计数值"
,
example
=
"150.50"
)
private
BigDecimal
value
;
/**
* 占比(百分数形式,如25.50 表示 25.50%)
*/
@ApiModelProperty
(
name
=
"percentage"
,
notes
=
"占比(百分数)"
,
example
=
"25.50"
)
private
BigDecimal
percentage
;
}
rpc-dj-strategy-api/src/main/java/cn/com/glsx/dj/strategy/dto/StatisticItemDTO.java
0 → 100644
View file @
94c78e9
package
cn
.
com
.
glsx
.
dj
.
strategy
.
dto
;
import
io.swagger.annotations.ApiModel
;
import
io.swagger.annotations.ApiModelProperty
;
import
lombok.Data
;
import
java.io.Serializable
;
import
java.math.BigDecimal
;
/**
* 统计数据项DTO(通用)
* 用于百分比计算的输入数据
* @author yangwei
* @version 1.0
* @since 2026/01/21 17:13
* @param <T> 统计维度的类型(如:策略类型String、商户ID Integer等)
*/
@Data
@ApiModel
(
description
=
"统计数据项"
)
public
class
StatisticItemDTO
<
T
>
implements
Serializable
{
private
static
final
long
serialVersionUID
=
1L
;
/**
* 统计维度(如:策略类型、商户ID、业务类型等)
*/
@ApiModelProperty
(
name
=
"dimension"
,
notes
=
"统计维度"
,
example
=
"MENTORING"
,
required
=
true
)
private
T
dimension
;
/**
* 统计维度的显示名称(可选,用于前端展示)
*/
@ApiModelProperty
(
name
=
"dimensionName"
,
notes
=
"统计维度显示名称"
,
example
=
"师徒帮带"
)
private
String
dimensionName
;
/**
* 数值(支持 Integer、Long、BigDecimal 等数值类型)
*/
@ApiModelProperty
(
name
=
"value"
,
notes
=
"统计数值"
,
example
=
"150.50"
,
required
=
true
)
private
BigDecimal
value
;
/**
* 构造函数(不含显示名称)
*/
public
StatisticItemDTO
(
T
dimension
,
String
dimensionName
,
BigDecimal
value
)
{
this
.
dimension
=
dimension
;
this
.
dimensionName
=
dimensionName
;
this
.
value
=
value
;
}
/**
* 构造函数(支持 Integer 类型)
*/
public
StatisticItemDTO
(
T
dimension
,
String
dimensionName
,
Integer
value
)
{
this
.
dimension
=
dimension
;
this
.
dimensionName
=
dimensionName
;
this
.
value
=
new
BigDecimal
(
value
);
}
/**
* 构造函数(支持 Long 类型)
*/
public
StatisticItemDTO
(
T
dimension
,
String
dimensionName
,
Long
value
)
{
this
.
dimension
=
dimension
;
this
.
dimensionName
=
dimensionName
;
this
.
value
=
new
BigDecimal
(
value
);
}
/**
* 构造函数(支持 Double 类型)
*/
public
StatisticItemDTO
(
T
dimension
,
String
dimensionName
,
Double
value
)
{
this
.
dimension
=
dimension
;
this
.
dimensionName
=
dimensionName
;
this
.
value
=
BigDecimal
.
valueOf
(
value
);
}
}
rpc-dj-strategy-api/src/main/java/cn/com/glsx/dj/strategy/dto/StrategyDetailReqDTO.java
View file @
94c78e9
...
...
@@ -2,6 +2,7 @@ package cn.com.glsx.dj.strategy.dto;
import
lombok.Data
;
import
javax.validation.constraints.NotNull
;
import
java.io.Serializable
;
/**
...
...
@@ -18,6 +19,7 @@ public class StrategyDetailReqDTO implements Serializable {
/**
* 策略id
*/
@NotNull
(
message
=
"策略id不能为空"
)
private
Integer
strategyId
;
}
rpc-dj-strategy-api/src/main/java/cn/com/glsx/dj/strategy/dto/StrategyMerchantCountDTO.java
0 → 100644
View file @
94c78e9
package
cn
.
com
.
glsx
.
dj
.
strategy
.
dto
;
import
lombok.Data
;
import
java.io.Serializable
;
/**
* @author yangwei
* @version 1.0
* @since 2026/01/21 15:34
*/
@Data
public
class
StrategyMerchantCountDTO
implements
Serializable
{
private
static
final
long
serialVersionUID
=
-
6338733625618914077L
;
/**
* 商家数量
*/
private
Integer
merchantCount
=
0
;
/**
* 策略数量
*/
private
Integer
strategyCount
=
0
;
}
rpc-dj-strategy-api/src/main/java/cn/com/glsx/dj/strategy/dto/StrategyOnlineStatisticsRespDTO.java
0 → 100644
View file @
94c78e9
package
cn
.
com
.
glsx
.
dj
.
strategy
.
dto
;
import
cn.com.glsx.dj.strategy.enums.StrategyTypeEnum
;
import
io.swagger.annotations.ApiModel
;
import
lombok.Data
;
import
java.io.Serializable
;
import
java.math.BigDecimal
;
/**
* 策略线上运营分布统计详情
* @author yangwei
* @version 1.0
* @since 2026/01/16 15:12
*/
@Data
@ApiModel
(
"策略总数统计详情"
)
public
class
StrategyOnlineStatisticsRespDTO
implements
Serializable
{
private
static
final
long
serialVersionUID
=
-
2260151727820104100L
;
/**
* 执行策略类型,0-学习类,1-优秀录音分享类,3-任务型
* * 2-带教、4-销售精英到店提拉、5-强力促销、6-最终盘点与低客单产品购入;
* @see StrategyTypeEnum
*/
private
Integer
strategyType
;
/**
* 员工姓名
*/
private
String
staffName
;
/**
* 员工UUID
*/
private
String
staffUuid
;
/**
* 百分占比
*/
private
BigDecimal
strategyCountPercent
;
/**
* 策略总数
*/
private
Integer
strategyCount
;
/**
* 门店总数
*/
private
Integer
storeCount
;
/**
* 占比
*/
private
BigDecimal
storeCountPercent
;
}
rpc-dj-strategy-api/src/main/java/cn/com/glsx/dj/strategy/dto/StrategyStatisticsReqDTO.java
0 → 100644
View file @
94c78e9
package
cn
.
com
.
glsx
.
dj
.
strategy
.
dto
;
import
lombok.Data
;
import
javax.validation.constraints.NotBlank
;
import
javax.validation.constraints.NotNull
;
import
java.io.Serializable
;
import
java.util.Date
;
/**
* 策略统计请求对象
* @author yangwei
* @version 1.0
* @since 2026/01/16 15:02
*/
@Data
public
class
StrategyStatisticsReqDTO
implements
Serializable
{
private
static
final
long
serialVersionUID
=
2934024393830108771L
;
/**
* 开始日期
*/
@NotNull
(
message
=
"开始日期不能为空"
)
private
Date
startDate
;
/**
* 结束日期
*/
@NotNull
(
message
=
"结束日期不能为空"
)
private
Date
endDate
;
/**
* bi侧业务类型,1.延保 2.轻改 3.权益
*/
@NotBlank
(
message
=
"业务类型不能为空"
)
private
String
businessType
;
}
rpc-dj-strategy-api/src/main/java/cn/com/glsx/dj/strategy/dto/StrategyTotalStatisticsRespDTO.java
0 → 100644
View file @
94c78e9
package
cn
.
com
.
glsx
.
dj
.
strategy
.
dto
;
import
lombok.AllArgsConstructor
;
import
lombok.Data
;
import
lombok.NoArgsConstructor
;
import
lombok.experimental.SuperBuilder
;
import
java.io.Serializable
;
/**
* 策略总数统计详情
* @author yangwei
* @version 1.0
* @since 2026/01/16 15:12
*/
@Data
@SuperBuilder
@NoArgsConstructor
@AllArgsConstructor
public
class
StrategyTotalStatisticsRespDTO
implements
Serializable
{
private
static
final
long
serialVersionUID
=
-
7934594462061655485L
;
/**
* 策略总数
*/
private
Integer
strategyTotalCount
=
0
;
/**
* 本月策略总数
*/
private
Integer
strategyTotalCountInMonth
=
0
;
/**
* 门店总数
*/
private
Integer
merchantTotalCount
=
0
;
/**
* 本月门店总数
*/
private
Integer
merchantTotalCountInMonth
=
0
;
}
rpc-dj-strategy-api/src/main/java/cn/com/glsx/dj/strategy/dto/StrategyTypeStatisticsDTO.java
0 → 100644
View file @
94c78e9
package
cn
.
com
.
glsx
.
dj
.
strategy
.
dto
;
import
io.swagger.annotations.ApiModel
;
import
lombok.Data
;
import
javax.validation.constraints.NotEmpty
;
import
javax.validation.constraints.NotNull
;
import
java.io.Serializable
;
import
java.util.Date
;
/**
* 策略类型统计请求对象
* @author yangwei
* @version 1.0
* @since 2026/01/16 15:02
*/
@Data
@ApiModel
(
value
=
"策略类型统计请求对象"
)
public
class
StrategyTypeStatisticsDTO
implements
Serializable
{
private
static
final
long
serialVersionUID
=
297689654517812838L
;
/**
* 开始日期
*/
@NotNull
(
message
=
"开始日期不能为空"
)
private
Date
startDate
;
/**
* 结束日期
*/
@NotNull
(
message
=
"结束日期不能为空"
)
private
Date
endDate
;
/**
* bi侧业务类型,1.延保 2.轻改 3.权益
*/
@NotEmpty
(
message
=
"bi侧业务类型不能为空"
)
private
String
businessType
;
/**
* 线上运营uuid
*/
private
String
uuid
;
}
rpc-dj-strategy-api/src/main/java/cn/com/glsx/dj/strategy/dto/StrategyTypeStatisticsRespDTO.java
0 → 100644
View file @
94c78e9
package
cn
.
com
.
glsx
.
dj
.
strategy
.
dto
;
import
cn.com.glsx.dj.strategy.enums.StrategyTypeEnum
;
import
lombok.AllArgsConstructor
;
import
lombok.Data
;
import
lombok.NoArgsConstructor
;
import
lombok.experimental.SuperBuilder
;
import
java.io.Serializable
;
import
java.math.BigDecimal
;
/**
* 策略总数统计详情
* @author yangwei
* @version 1.0
* @since 2026/01/16 15:12
*/
@Data
@SuperBuilder
@AllArgsConstructor
@NoArgsConstructor
public
class
StrategyTypeStatisticsRespDTO
implements
Serializable
{
private
static
final
long
serialVersionUID
=
1858914693424400418L
;
/**
* 执行策略类型,0-学习类,1-优秀录音分享类,3-任务型
* * 2-带教、4-销售精英到店提拉、5-强力促销、6-最终盘点与低客单产品购入;
* @see StrategyTypeEnum
*/
private
Integer
strategyType
;
/**
* 策略类型名称
*/
private
String
strategyTypeName
;
/**
* 百分占比
*/
private
BigDecimal
percent
;
/**
* 策略数
*/
private
Integer
strategyCount
;
}
rpc-dj-strategy-api/src/main/java/cn/com/glsx/dj/strategy/enums/StrategyErrorEnum.java
View file @
94c78e9
...
...
@@ -17,6 +17,8 @@ import java.util.Map;
@AllArgsConstructor
public
enum
StrategyErrorEnum
implements
ErrorEnum
{
VALIDATION_ERROR
(
"10000001"
,
"验证失败!"
),
COMMON_ERROR
(
"11000000"
,
"common error"
),
STRATEGY_NOT_EXISTS
(
"11010001"
,
"策略不存在"
),
...
...
@@ -24,7 +26,7 @@ public enum StrategyErrorEnum implements ErrorEnum {
STRATEGY_TYPE_NOT_SUPPORTED
(
"11010002"
,
"策略类型不支持"
),
BUSINESS_EXCEPTION
(
"11010003"
,
"业务异常"
),
;
TOTAL_COUNT_CANNOT_BE_ZERO
(
"11010003"
,
"总数量不能为0"
)
;
private
final
String
value
;
private
final
String
displayName
;
...
...
rpc-dj-strategy-api/src/main/java/cn/com/glsx/dj/strategy/model/StrategyInfo.java
View file @
94c78e9
...
...
@@ -4,13 +4,13 @@ import cn.com.glsx.dj.strategy.enums.StrategyPushFlagEnum;
import
cn.com.glsx.dj.strategy.enums.StrategyPushType
;
import
cn.com.glsx.dj.strategy.enums.StrategyTypeEnum
;
import
io.swagger.annotations.ApiModelProperty
;
import
java.util.List
;
import
lombok.Data
;
import
org.springframework.format.annotation.DateTimeFormat
;
import
javax.persistence.*
;
import
java.io.Serializable
;
import
java.util.Date
;
import
java
x.persistence.*
;
import
java
.util.List
;
@Data
@Table
(
name
=
"dj_car_life_strategy_info"
)
public
class
StrategyInfo
implements
Serializable
{
...
...
rpc-dj-strategy-api/src/main/java/cn/com/glsx/dj/strategy/remote/StrategyDetailRemote.java
View file @
94c78e9
package
cn
.
com
.
glsx
.
dj
.
strategy
.
remote
;
import
cn.com.glsx.dj.strategy.dto.StrategyDetailReqDTO
;
import
cn.com.glsx.dj.strategy.dto.StrategyDetailRespDTO
;
import
cn.com.glsx.dj.strategy.dto.*
;
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.annotation.ApiService
;
import
cn.com.glsx.framework.core.beans.rpc.RpcResponse
;
import
java.util.List
;
/**
* 策略中心-策略详情
* @author yangwei
...
...
@@ -22,4 +23,25 @@ public interface StrategyDetailRemote {
@ApiResponse
(
"查询记录下/任务型策略详情"
)
RpcResponse
<
StrategyDetailRespDTO
>
findStrategyDetail
(
StrategyDetailReqDTO
request
);
@ApiMethod
(
"策略分析-总数统计"
)
@ApiParam
(
name
=
"request"
,
notes
=
"请求对象"
,
dataType
=
ApiParam
.
DataTypeEnum
.
OBJECT
,
required
=
true
)
@ApiResponse
(
"策略分析-总数统计"
)
RpcResponse
<
StrategyTotalStatisticsRespDTO
>
findStrategyTotalStatisticsDetail
(
StrategyStatisticsReqDTO
request
);
@ApiMethod
(
"策略分析-策略类型分布"
)
@ApiParam
(
name
=
"request"
,
notes
=
"请求对象"
,
dataType
=
ApiParam
.
DataTypeEnum
.
OBJECT
,
required
=
true
)
@ApiResponse
(
"策略分析-策略类型分布"
)
RpcResponse
<
List
<
StrategyTypeStatisticsRespDTO
>>
findStrategyTypeDistribution
(
StrategyTypeStatisticsDTO
request
);
@ApiMethod
(
"策略分析-线上运营分布"
)
@ApiParam
(
name
=
"request"
,
notes
=
"请求对象"
,
dataType
=
ApiParam
.
DataTypeEnum
.
OBJECT
,
required
=
true
)
@ApiResponse
(
"策略分析-线上运营分布"
)
RpcResponse
<
List
<
StrategyOnlineStatisticsRespDTO
>>
findStrategyOnlineDistribution
(
StrategyStatisticsReqDTO
request
);
@ApiMethod
(
"策略分析-门店策略分布"
)
@ApiParam
(
name
=
"request"
,
notes
=
"请求对象"
,
dataType
=
ApiParam
.
DataTypeEnum
.
OBJECT
,
required
=
true
)
@ApiResponse
(
"策略分析-门店策略分布"
)
RpcResponse
<
List
<
MerchantStrategyStatisticsRespDTO
>>
findStrategyStatisticsGroupMerchantNo
(
MerchantStrategyStatisticsReqDTO
request
);
}
rpc-dj-strategy/src/main/java/cn/com/glsx/dj/strategy/config/BeanConfig.java
0 → 100644
View file @
94c78e9
package
cn
.
com
.
glsx
.
dj
.
strategy
.
config
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.scheduling.concurrent.CustomizableThreadFactory
;
import
java.util.concurrent.ArrayBlockingQueue
;
import
java.util.concurrent.ExecutorService
;
import
java.util.concurrent.ThreadPoolExecutor
;
import
java.util.concurrent.TimeUnit
;
/**
* bean 装配
* @author yangwei
* @version 1.0
* @since 2026/01/21 16:00
*/
@Configuration
public
class
BeanConfig
{
/**
* IO密集型任务线程池配置
* 适用场景:数据库查询、RPC调用等IO操作
* 线程数公式:核心线程数 = CPU核心数 * 2,最大线程数 = CPU核心数 * 4
*/
private
static
final
int
CPU_COUNT
=
Runtime
.
getRuntime
().
availableProcessors
();
private
static
final
int
CORE_POOL_SIZE
=
CPU_COUNT
*
2
;
private
static
final
int
MAX_POOL_SIZE
=
CPU_COUNT
*
4
;
/**
* 策略模块IO密集型异步任务线程池
* @author yangwei
* @since 2026/1/21 16:10
* @return java.util.concurrent.ExecutorService
*/
@Bean
(
name
=
"strategyExecutorService"
)
public
ExecutorService
executorService
()
{
return
new
ThreadPoolExecutor
(
CORE_POOL_SIZE
,
MAX_POOL_SIZE
,
60L
,
TimeUnit
.
SECONDS
,
new
ArrayBlockingQueue
<>(
1000
),
new
CustomizableThreadFactory
(
"strategy-async-"
),
new
ThreadPoolExecutor
.
CallerRunsPolicy
()
);
}
}
rpc-dj-strategy/src/main/java/cn/com/glsx/dj/strategy/config/MerchantDubboConfig.java
0 → 100644
View file @
94c78e9
package
cn
.
com
.
glsx
.
dj
.
strategy
.
config
;
import
cn.com.glsx.merchants.remote.MerchantStaffRemote
;
import
lombok.RequiredArgsConstructor
;
import
org.oreframework.boot.autoconfigure.dubbo.reference.ReferenceBuilderFactory
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
/**
* @author yangwei
* @version 1.0
* @since 2026/01/20 14:53
*/
@Configuration
@RequiredArgsConstructor
public
class
MerchantDubboConfig
{
private
final
ReferenceBuilderFactory
factory
;
@Bean
public
MerchantStaffRemote
merchantStaffRemote
()
{
return
factory
.
builder
(
MerchantStaffRemote
.
class
)
.
check
(
false
)
.
timeout
(
30000
)
.
build
();
}
}
rpc-dj-strategy/src/main/java/cn/com/glsx/dj/strategy/converter/StrategyInfoConverter.java
0 → 100644
View file @
94c78e9
package
cn
.
com
.
glsx
.
dj
.
strategy
.
converter
;
import
org.mapstruct.Mapper
;
/**
* @author yangwei
* @version 1.0
* @since 2026/01/21 17:56
*/
@Mapper
(
componentModel
=
"spring"
)
public
interface
StrategyInfoConverter
{
}
rpc-dj-strategy/src/main/java/cn/com/glsx/dj/strategy/mapper/StrategyInfoMapper.java
View file @
94c78e9
package
cn
.
com
.
glsx
.
dj
.
strategy
.
mapper
;
import
cn.com.glsx.dj.strategy.dto.*
;
import
cn.com.glsx.dj.strategy.model.StrategyInfo
;
import
org.apache.ibatis.annotations.Mapper
;
import
org.apache.ibatis.annotations.Param
;
import
org.oreframework.datasource.mybatis.mapper.OreMapper
;
import
java.util.List
;
...
...
@@ -16,4 +18,55 @@ public interface StrategyInfoMapper extends OreMapper<StrategyInfo> {
* @return 策略信息列表
*/
List
<
StrategyInfo
>
selectStrategyInfoPage
(
StrategyInfo
strategyInfo
);
/**
* 策略总数统计
* @author yangwei
* @since 2026/1/21 15:42
* @param businessType 业务类型
* @param startDate 开始时间
* @param endDate 结束时间
* @return cn.com.glsx.dj.strategy.dto.StrategyMerchantCountDTO 策略总统计信息
*/
StrategyMerchantCountDTO
strategyTotalStatistics
(
@Param
(
"businessType"
)
String
businessType
,
@Param
(
"startDate"
)
String
startDate
,
@Param
(
"endDate"
)
String
endDate
);
/**
* 策略类型分布统计
* @author yangwei
* @since 2026/1/21 17:42
* @param request 查询条件
* @return cn.com.glsx.dj.strategy.dto.StrategyTypeStatisticsRespDTO 策略类型统计信息
*/
List
<
StrategyTypeStatisticsRespDTO
>
findStrategyTypeDistribution
(
StrategyTypeStatisticsDTO
request
);
/**
* 策略分析-线上运营分布
* @author yangwei
* @since 2026/1/22 10:29
* @param request 请求对象
* @return cn.com.glsx.dj.strategy.dto.StrategyOnlineStatisticsRespDTO
*/
List
<
StrategyOnlineStatisticsRespDTO
>
findStrategyOnlineDistribution
(
StrategyStatisticsReqDTO
request
);
/**
* 根据uuid列表查询策略创建人,多项直接合并取任意一个名称
* @author yangwei
* @since 2026/1/22 11:00
* @param uuids uuid列表
* @return cn.com.glsx.dj.strategy.model.StrategyInfo 策略信息
*/
List
<
StrategyInfo
>
selectStaffNameByUuids
(
@Param
(
"uuids"
)
List
<
String
>
uuids
);
/**
* 按照门店分组统计策略数量
* @author yangwei
* @since 2026/1/22 16:29
* @param request 请求对象
* @return cn.com.glsx.dj.strategy.dto.MerchantStrategyStatisticsRespDTO
*/
List
<
MerchantStrategyStatisticsRespDTO
>
findStrategyStatisticsGroupMerchantNo
(
MerchantStrategyStatisticsReqDTO
request
);
}
\ No newline at end of file
rpc-dj-strategy/src/main/java/cn/com/glsx/dj/strategy/remote/StrategyDetailRemoteImpl.java
View file @
94c78e9
package
cn
.
com
.
glsx
.
dj
.
strategy
.
remote
;
import
cn.com.glsx.dj.strategy.dto.StrategyDetailReqDTO
;
import
cn.com.glsx.dj.strategy.dto.StrategyDetailRespDTO
;
import
cn.com.glsx.dj.strategy.dto.*
;
import
cn.com.glsx.dj.strategy.service.StrategyDetailService
;
import
cn.com.glsx.framework.core.beans.rpc.RpcResponse
;
import
cn.com.glsx.framework.core.exception.RpcServiceException
;
...
...
@@ -9,6 +8,8 @@ import lombok.RequiredArgsConstructor;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.dubbo.config.annotation.DubboService
;
import
java.util.List
;
/**
* 策略中心-策略详情
* @author yangwei
...
...
@@ -41,4 +42,85 @@ public class StrategyDetailRemoteImpl implements StrategyDetailRemote {
return
RpcResponse
.
error
(
e
);
}
}
/**
* 策略分析-总数统计
* @author yangwei
* @since 2026/1/21 15:16
* @param request 请求对象
* @return cn.com.glsx.framework.core.beans.rpc.RpcResponse<cn.com.glsx.dj.strategy.dto.StrategyTotalStatisticsRespDTO>
*/
@Override
public
RpcResponse
<
StrategyTotalStatisticsRespDTO
>
findStrategyTotalStatisticsDetail
(
StrategyStatisticsReqDTO
request
)
{
try
{
return
RpcResponse
.
success
(
strategyDetailService
.
findStrategyTotalStatisticsDetail
(
request
));
}
catch
(
RpcServiceException
e
)
{
log
.
error
(
"查询记录下/任务型策略详情 occur RpcServiceException"
,
e
);
return
RpcResponse
.
error
(
e
);
}
catch
(
Exception
e
)
{
log
.
error
(
"查询记录下/任务型策略详情 occur Exception"
,
e
);
return
RpcResponse
.
error
(
e
);
}
}
/**
* 策略分析-策略类型分布
* @author yangwei
* @since 2026/1/21 16:16
* @param request 请求对象
* @return cn.com.glsx.framework.core.beans.rpc.RpcResponse<java.util.List<cn.com.glsx.dj.strategy.dto.StrategyTypeStatisticsRespDTO>>
*/
@Override
public
RpcResponse
<
List
<
StrategyTypeStatisticsRespDTO
>>
findStrategyTypeDistribution
(
StrategyTypeStatisticsDTO
request
)
{
try
{
return
RpcResponse
.
success
(
strategyDetailService
.
findStrategyTypeDistribution
(
request
));
}
catch
(
RpcServiceException
e
)
{
log
.
error
(
"策略分析-策略类型分布 occur RpcServiceException"
,
e
);
return
RpcResponse
.
error
(
e
);
}
catch
(
Exception
e
)
{
log
.
error
(
"策略分析-策略类型分布 occur Exception"
,
e
);
return
RpcResponse
.
error
(
e
);
}
}
/**
* 策略分析-线上运营分布
* @author yangwei
* @since 2026/1/22 10:59
* @param request 请求对象
* @return cn.com.glsx.framework.core.beans.rpc.RpcResponse<java.util.List<cn.com.glsx.dj.strategy.dto.StrategyOnlineStatisticsRespDTO>>
*/
@Override
public
RpcResponse
<
List
<
StrategyOnlineStatisticsRespDTO
>>
findStrategyOnlineDistribution
(
StrategyStatisticsReqDTO
request
)
{
try
{
return
RpcResponse
.
success
(
strategyDetailService
.
findStrategyOnlineDistribution
(
request
));
}
catch
(
RpcServiceException
e
)
{
log
.
error
(
"策略分析-线上运营分布 occur RpcServiceException"
,
e
);
return
RpcResponse
.
error
(
e
);
}
catch
(
Exception
e
)
{
log
.
error
(
"策略分析-线上运营分布 occur Exception"
,
e
);
return
RpcResponse
.
error
(
e
);
}
}
/**
* 策略分析-门店策略分布
* @author yangwei
* @since 2026/1/22 16:29
* @param request 请求对象
* @return cn.com.glsx.framework.core.beans.rpc.RpcResponse<java.util.List<cn.com.glsx.dj.strategy.dto.MerchantStrategyStatisticsRespDTO>>
*/
@Override
public
RpcResponse
<
List
<
MerchantStrategyStatisticsRespDTO
>>
findStrategyStatisticsGroupMerchantNo
(
MerchantStrategyStatisticsReqDTO
request
)
{
try
{
return
RpcResponse
.
success
(
strategyDetailService
.
findStrategyStatisticsGroupMerchantNo
(
request
));
}
catch
(
RpcServiceException
e
)
{
log
.
error
(
"策略分析-门店策略分布 occur RpcServiceException"
,
e
);
return
RpcResponse
.
error
(
e
);
}
catch
(
Exception
e
)
{
log
.
error
(
"策略分析-门店策略分布 occur Exception"
,
e
);
return
RpcResponse
.
error
(
e
);
}
}
}
rpc-dj-strategy/src/main/java/cn/com/glsx/dj/strategy/service/StrategyDetailService.java
View file @
94c78e9
This diff is collapsed.
Click to expand it.
rpc-dj-strategy/src/main/java/cn/com/glsx/dj/strategy/util/LocalDateUtil.java
View file @
94c78e9
package
cn
.
com
.
glsx
.
dj
.
strategy
.
util
;
import
cn.com.glsx.dj.strategy.dto.MonthRangeDTO
;
import
cn.com.glsx.dj.strategy.enums.StrategyErrorEnum
;
import
cn.com.glsx.framework.core.exception.RpcServiceException
;
import
cn.hutool.core.date.DateUtil
;
import
java.time.LocalDate
;
import
java.time.LocalDateTime
;
import
java.time.ZoneId
;
import
java.time.format.DateTimeFormatter
;
import
java.time.temporal.ChronoUnit
;
import
java.time.temporal.TemporalAdjusters
;
import
java.util.Date
;
public
class
LocalDateUtil
{
...
...
@@ -67,6 +74,53 @@ public class LocalDateUtil {
return
ChronoUnit
.
DAYS
.
between
(
localDate1
,
localDate2
);
}
/**
*
* @author yangwei
* @since 2026/1/21 15:49
* @param date 日期
* @param pattern 格式 {@link cn.hutool.core.date.DatePattern}
* @return cn.com.glsx.dj.strategy.dto.MonthRangeDTO
*/
public
static
MonthRangeDTO
getMonthFirstAndLastDay
(
LocalDateTime
date
,
String
pattern
)
{
String
now
=
DateUtil
.
format
(
date
,
pattern
);
return
LocalDateUtil
.
getMonthFirstAndLastDay
(
now
,
pattern
);
}
/**
* 获取给定日期所在月份的第一天和最后一天
* @param dateStr 日期字符串
* @param pattern 日期格式(如 "yyyy-MM-dd", "yyyy/MM/dd" 等){@link cn.hutool.core.date.DatePattern}
* @return MonthRangeDTO,包含当月第一天和最后一天
*/
public
static
MonthRangeDTO
getMonthFirstAndLastDay
(
String
dateStr
,
String
pattern
)
{
if
(
dateStr
==
null
||
dateStr
.
trim
().
isEmpty
())
{
throw
new
RpcServiceException
(
StrategyErrorEnum
.
COMMON_ERROR
,
"日期字符串不能为空"
);
}
if
(
pattern
==
null
||
pattern
.
trim
().
isEmpty
())
{
throw
new
RpcServiceException
(
StrategyErrorEnum
.
COMMON_ERROR
,
"日期格式不能为空"
);
}
try
{
// 1. 根据指定的 pattern 解析日期字符串
DateTimeFormatter
formatter
=
DateTimeFormatter
.
ofPattern
(
pattern
);
LocalDate
date
=
LocalDate
.
parse
(
dateStr
,
formatter
);
// 2. 获取当月第一天
LocalDate
firstDay
=
date
.
with
(
TemporalAdjusters
.
firstDayOfMonth
());
// 3. 获取当月最后一天
LocalDate
lastDay
=
date
.
with
(
TemporalAdjusters
.
lastDayOfMonth
());
// 4. 封装为 DTO 并返回
return
new
MonthRangeDTO
(
firstDay
.
format
(
formatter
),
lastDay
.
format
(
formatter
)
);
}
catch
(
Exception
e
)
{
throw
new
RpcServiceException
(
StrategyErrorEnum
.
COMMON_ERROR
,
"日期解析失败,请检查日期格式是否正确。dateStr: "
+
dateStr
+
", pattern: "
+
pattern
+
", 错误信息: "
+
e
.
getMessage
());
}
}
}
rpc-dj-strategy/src/main/java/cn/com/glsx/dj/strategy/util/PercentageCalculator.java
0 → 100644
View file @
94c78e9
package
cn
.
com
.
glsx
.
dj
.
strategy
.
util
;
import
cn.com.glsx.dj.strategy.dto.PercentageResultDTO
;
import
cn.com.glsx.dj.strategy.dto.StatisticItemDTO
;
import
cn.com.glsx.dj.strategy.enums.StrategyErrorEnum
;
import
cn.com.glsx.framework.core.exception.RpcServiceException
;
import
java.math.BigDecimal
;
import
java.math.RoundingMode
;
import
java.util.List
;
import
java.util.stream.Collectors
;
/**
* 百分比计算工具类(通用)
* 支持百分数/小数格式,可指定小数位数,自动处理四舍五入和精度控制
* 使用泛型 DTO,适用于各种统计场景
* @author yangwei
* @version 1.0
* @since 2026/01/21 16:50
*/
public
class
PercentageCalculator
{
/**
* 计算百分比并调整总和为100%(使用实体类输入,通用方法)
* @param items 统计数据项列表
* @param isPercentage 是否返回百分数格式(true返回百分数,false返回小数)
* @param decimalPlaces 小数位数(0-整数,1-一位小数,2-两位小数,3-三位小数)
* @param <T> 统计维度的类型
* @return 包含维度、数值、占比的 DTO 列表
*/
public
static
<
T
>
List
<
PercentageResultDTO
<
T
>>
calculateAdjustPercentage
(
List
<
StatisticItemDTO
<
T
>>
items
,
boolean
isPercentage
,
int
decimalPlaces
)
{
List
<
PercentageResultDTO
<
T
>>
percentageResultDTOList
=
calculatePercentage
(
items
,
isPercentage
,
decimalPlaces
);
if
(
validateTotalPercentage
(
percentageResultDTOList
,
isPercentage
))
{
return
percentageResultDTOList
;
}
else
{
return
adjustTo100Percent
(
percentageResultDTOList
);
}
}
/**
* 计算百分比(使用实体类输入,通用方法)
* @param items 统计数据项列表
* @param isPercentage 是否返回百分数格式(true返回百分数,false返回小数)
* @param decimalPlaces 小数位数(0-整数,1-一位小数,2-两位小数,3-三位小数)
* @param <T> 统计维度的类型
* @return 包含维度、数值、占比的 DTO 列表
*/
public
static
<
T
>
List
<
PercentageResultDTO
<
T
>>
calculatePercentage
(
List
<
StatisticItemDTO
<
T
>>
items
,
boolean
isPercentage
,
int
decimalPlaces
)
{
// 参数验证
if
(
items
==
null
||
items
.
isEmpty
())
{
throw
new
IllegalArgumentException
(
"统计数据项不能为空"
);
}
if
(
decimalPlaces
<
0
)
{
throw
new
IllegalArgumentException
(
"小数位数不能为负数"
);
}
// 计算总数(支持 BigDecimal)
BigDecimal
total
=
items
.
stream
()
.
map
(
StatisticItemDTO:
:
getValue
)
.
reduce
(
BigDecimal
.
ZERO
,
BigDecimal:
:
add
);
if
(
total
.
compareTo
(
BigDecimal
.
ZERO
)
==
0
)
{
throw
new
RpcServiceException
(
StrategyErrorEnum
.
TOTAL_COUNT_CANNOT_BE_ZERO
);
}
// 使用Stream处理每个项的占比计算
return
items
.
stream
()
.
map
(
item
->
{
T
dimension
=
item
.
getDimension
();
String
dimensionName
=
item
.
getDimensionName
();
BigDecimal
value
=
item
.
getValue
();
// 计算占比(直接返回 BigDecimal,不格式化为字符串)
BigDecimal
percentage
=
calculateSinglePercentage
(
value
,
total
,
isPercentage
,
decimalPlaces
);
return
new
PercentageResultDTO
<>(
dimension
,
dimensionName
,
value
,
percentage
);
})
.
collect
(
Collectors
.
toList
());
}
/**
* 计算单个值的占比(支持 BigDecimal)
* @param part 部分值
* @param total 总值
* @param isPercentage 是否返回百分数形式(true:百分数如 25.50,false:小数如 0.2550)
* @param decimalPlaces 小数位数
* @return 占比值(BigDecimal)
*/
private
static
BigDecimal
calculateSinglePercentage
(
BigDecimal
part
,
BigDecimal
total
,
boolean
isPercentage
,
int
decimalPlaces
)
{
if
(
isPercentage
)
{
// 百分数形式:(part / total) * 100,如 25.50 表示 25.50%
BigDecimal
percentage
=
part
.
divide
(
total
,
decimalPlaces
+
2
,
RoundingMode
.
HALF_UP
)
.
multiply
(
new
BigDecimal
(
"100"
));
return
percentage
.
setScale
(
decimalPlaces
,
RoundingMode
.
HALF_UP
);
}
else
{
// 小数形式:part / total,如 0.2550 表示 25.50%
return
part
.
divide
(
total
,
decimalPlaces
,
RoundingMode
.
HALF_UP
);
}
}
/**
* 验证占比总和(确保四舍五入后不超过100%)
*/
public
static
<
T
>
boolean
validateTotalPercentage
(
List
<
PercentageResultDTO
<
T
>>
result
,
boolean
isPercentage
)
{
if
(!
isPercentage
)
{
return
true
;
}
BigDecimal
total
=
result
.
stream
()
.
map
(
PercentageResultDTO:
:
getPercentage
)
.
reduce
(
BigDecimal
.
ZERO
,
BigDecimal:
:
add
);
// 允许的误差范围(由于四舍五入)
BigDecimal
tolerance
=
new
BigDecimal
(
"0.001"
);
BigDecimal
expectedTotal
=
new
BigDecimal
(
"100"
);
return
total
.
subtract
(
expectedTotal
).
abs
().
compareTo
(
tolerance
)
<=
0
;
}
/**
* 调整占比以确保总和为100%
*/
public
static
<
T
>
List
<
PercentageResultDTO
<
T
>>
adjustTo100Percent
(
List
<
PercentageResultDTO
<
T
>>
result
)
{
BigDecimal
currentTotal
=
result
.
stream
()
.
map
(
PercentageResultDTO:
:
getPercentage
)
.
reduce
(
BigDecimal
.
ZERO
,
BigDecimal:
:
add
);
BigDecimal
difference
=
new
BigDecimal
(
"100"
).
subtract
(
currentTotal
);
if
(
difference
.
abs
().
compareTo
(
new
BigDecimal
(
"0.001"
))
<
0
)
{
// 差异很小,不需要调整
return
result
;
}
// 找到最大的项进行调整
int
maxIndex
=
0
;
BigDecimal
maxPercentage
=
BigDecimal
.
ZERO
;
for
(
int
i
=
0
;
i
<
result
.
size
();
i
++)
{
BigDecimal
percentage
=
result
.
get
(
i
).
getPercentage
();
if
(
percentage
.
compareTo
(
maxPercentage
)
>
0
)
{
maxPercentage
=
percentage
;
maxIndex
=
i
;
}
}
// 调整最大项的占比
final
PercentageResultDTO
<
T
>
maxItem
=
result
.
get
(
maxIndex
);
final
BigDecimal
adjustedPercentage
=
maxPercentage
.
add
(
difference
);
// 创建新的结果列表
return
result
.
stream
()
.
map
(
item
->
{
if
(
item
==
maxItem
)
{
return
new
PercentageResultDTO
<>(
item
.
getDimension
(),
item
.
getDimensionName
(),
item
.
getValue
(),
adjustedPercentage
);
}
return
item
;
})
.
collect
(
Collectors
.
toList
());
}
}
\ No newline at end of file
rpc-dj-strategy/src/main/java/cn/com/glsx/dj/strategy/util/validation/BeanValidationUtils.java
0 → 100644
View file @
94c78e9
package
cn
.
com
.
glsx
.
dj
.
strategy
.
util
.
validation
;
import
cn.com.glsx.dj.strategy.enums.StrategyErrorEnum
;
import
cn.com.glsx.framework.core.exception.RpcServiceException
;
import
javax.validation.ConstraintViolation
;
import
javax.validation.Validation
;
import
javax.validation.Validator
;
import
javax.validation.ValidatorFactory
;
import
java.util.*
;
/**
* BeanValidation 校验工具类
* 功能:支持单对象、集合、数组的校验,提供多种结果处理方式
* @author yangwei
* @version 1.0
* @since 2025/10/15 23:49
*/
public
class
BeanValidationUtils
{
private
static
final
Validator
validator
;
static
{
try
(
ValidatorFactory
validatorFactory
=
Validation
.
buildDefaultValidatorFactory
())
{
validator
=
validatorFactory
.
getValidator
();
}
}
private
BeanValidationUtils
()
{
// 工具类,防止实例化
}
/**
* 校验单个对象,返回校验结果
*/
public
static
<
T
>
ValidationResult
validate
(
T
object
)
{
return
validate
(
object
,
(
Class
<?>[])
null
);
}
/**
* 分组校验单个对象
*/
public
static
<
T
>
ValidationResult
validate
(
T
object
,
Class
<?>...
groups
)
{
Set
<
ConstraintViolation
<
T
>>
violations
=
validator
.
validate
(
object
,
groups
);
return
new
ValidationResult
(
violations
);
}
/**
* 校验集合中的所有对象
*/
public
static
<
T
>
List
<
ValidationResult
>
validateCollection
(
Collection
<
T
>
collection
)
{
if
(
collection
==
null
||
collection
.
isEmpty
())
{
return
Collections
.
emptyList
();
}
List
<
ValidationResult
>
results
=
new
ArrayList
<>();
for
(
T
item
:
collection
)
{
results
.
add
(
validate
(
item
));
}
return
results
;
}
/**
* 快速校验并抛出异常(如有错误)
*/
public
static
<
T
>
void
validateAndThrow
(
T
object
,
Class
<?>...
groups
)
{
ValidationResult
result
=
validate
(
object
,
groups
);
if
(
result
.
hasErrors
())
{
throw
new
RpcServiceException
(
StrategyErrorEnum
.
VALIDATION_ERROR
,
result
.
getFormattedMessage
());
}
}
/**
* 批量快速校验
*/
public
static
void
validateAllAndThrow
(
Object
...
objects
)
{
if
(
objects
==
null
)
{
return
;
}
for
(
Object
obj
:
objects
)
{
if
(
obj
instanceof
Collection
)
{
// 处理集合
for
(
Object
item
:
(
Collection
<?>)
obj
)
{
validateAndThrow
(
item
);
}
}
else
if
(
obj
!=
null
&&
obj
.
getClass
().
isArray
())
{
// 处理数组
for
(
Object
item
:
(
Object
[])
obj
)
{
validateAndThrow
(
item
);
}
}
else
{
// 处理单个对象
validateAndThrow
(
obj
);
}
}
}
}
\ No newline at end of file
rpc-dj-strategy/src/main/java/cn/com/glsx/dj/strategy/util/validation/ErrorDetail.java
0 → 100644
View file @
94c78e9
package
cn
.
com
.
glsx
.
dj
.
strategy
.
util
.
validation
;
import
lombok.AllArgsConstructor
;
import
lombok.Data
;
/**
* 错误详情记录
* @author yangwei
* @version 1.0
* @since 2025/10/15 23:56
*/
@Data
@AllArgsConstructor
public
class
ErrorDetail
{
private
final
String
field
;
private
final
String
message
;
private
final
Object
invalidValue
;
private
final
String
className
;
@Override
public
String
toString
()
{
return
String
.
format
(
"%s.%s: %s (实际值: %s)"
,
className
,
field
,
message
,
invalidValue
);
}
}
rpc-dj-strategy/src/main/java/cn/com/glsx/dj/strategy/util/validation/ValidationResult.java
0 → 100644
View file @
94c78e9
package
cn
.
com
.
glsx
.
dj
.
strategy
.
util
.
validation
;
import
cn.hutool.core.util.StrUtil
;
import
javax.validation.ConstraintViolation
;
import
java.util.Collections
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Set
;
import
java.util.stream.Collectors
;
/**
* 校验结果
* @author yangwei
* @version 1.0
* @since 2025/10/15 23:55
*/
public
class
ValidationResult
{
private
final
Set
<?
extends
ConstraintViolation
<?>>
violations
;
public
ValidationResult
(
Set
<?
extends
ConstraintViolation
<?>>
violations
)
{
this
.
violations
=
violations
!=
null
?
violations
:
Collections
.
emptySet
();
}
/**
* 是否有校验错误
*/
public
boolean
hasErrors
()
{
return
!
violations
.
isEmpty
();
}
/**
* 获取错误数量
*/
public
int
getErrorCount
()
{
return
violations
.
size
();
}
/**
* 获取所有错误信息(简单格式)
*/
public
List
<
String
>
getErrorMessages
()
{
return
violations
.
stream
()
.
map
(
ConstraintViolation:
:
getMessage
)
.
collect
(
Collectors
.
toList
());
}
/**
* 获取字段-错误的映射
*/
public
Map
<
String
,
String
>
getErrorsMap
()
{
return
violations
.
stream
()
.
collect
(
Collectors
.
toMap
(
violation
->
violation
.
getPropertyPath
().
toString
(),
ConstraintViolation:
:
getMessage
,
(
existing
,
replacement
)
->
existing
+
"; "
+
replacement
));
}
/**
* 获取详细错误信息
*/
public
List
<
ErrorDetail
>
getErrorDetails
()
{
return
violations
.
stream
()
.
map
(
violation
->
new
ErrorDetail
(
violation
.
getPropertyPath
().
toString
(),
violation
.
getMessage
(),
violation
.
getInvalidValue
(),
violation
.
getRootBeanClass
().
getSimpleName
()
))
.
collect
(
Collectors
.
toList
());
}
/**
* 获取格式化错误信息
*/
public
String
getFormattedMessage
()
{
if
(!
hasErrors
())
{
return
"校验通过"
;
}
return
StrUtil
.
join
(
";"
,
getErrorsMap
().
values
());
}
public
String
getFormattedMessageLineFeed
()
{
if
(!
hasErrors
())
{
return
"校验通过"
;
}
StringBuilder
sb
=
new
StringBuilder
(
"校验失败:\n"
);
getErrorsMap
().
forEach
((
field
,
message
)
->
sb
.
append
(
" "
).
append
(
field
).
append
(
": "
).
append
(
message
).
append
(
"\n"
)
);
return
sb
.
toString
();
}
}
rpc-dj-strategy/src/main/java/cn/com/glsx/dj/strategy/util/validation/validator/DateCheck.java
0 → 100644
View file @
94c78e9
package
cn
.
com
.
glsx
.
dj
.
strategy
.
util
.
validation
.
validator
;
import
javax.validation.Constraint
;
import
javax.validation.Payload
;
import
java.lang.annotation.*
;
/**
* 日期字符串校验注解,校验字符串是否符合指定的日期格式
* @author yangwei
* @since 2025/12/15 16:49
*/
@Documented
@Constraint
(
validatedBy
=
{
DateStringValidator
.
class
})
@Target
({
ElementType
.
FIELD
,
ElementType
.
PARAMETER
,
ElementType
.
METHOD
})
@Retention
(
RetentionPolicy
.
RUNTIME
)
public
@interface
DateCheck
{
/** 默认错误消息 */
String
message
()
default
"日期格式不正确"
;
/** 日期格式pattern */
String
pattern
()
default
"yyyy-MM-dd"
;
/** 分组校验支持 */
Class
<?>[]
groups
()
default
{};
/** 负载信息 */
Class
<?
extends
Payload
>[]
payload
()
default
{};
}
\ No newline at end of file
rpc-dj-strategy/src/main/java/cn/com/glsx/dj/strategy/util/validation/validator/DateStringValidator.java
0 → 100644
View file @
94c78e9
package
cn
.
com
.
glsx
.
dj
.
strategy
.
util
.
validation
.
validator
;
import
javax.validation.ConstraintValidator
;
import
javax.validation.ConstraintValidatorContext
;
import
java.text.ParseException
;
import
java.text.SimpleDateFormat
;
/**
* 日期字符串校验器
* @author yangwei
* @since 2025/12/15 16:49
*/
public
class
DateStringValidator
implements
ConstraintValidator
<
DateCheck
,
String
>
{
private
String
pattern
;
@Override
public
void
initialize
(
DateCheck
constraintAnnotation
)
{
this
.
pattern
=
constraintAnnotation
.
pattern
();
}
@Override
public
boolean
isValid
(
String
value
,
ConstraintValidatorContext
context
)
{
// null值交给@NotNull处理
if
(
value
==
null
)
{
return
true
;
}
try
{
SimpleDateFormat
sdf
=
new
SimpleDateFormat
(
pattern
);
// 设置为严格模式
sdf
.
setLenient
(
false
);
sdf
.
parse
(
value
);
return
true
;
}
catch
(
ParseException
e
)
{
return
false
;
}
}
}
\ No newline at end of file
rpc-dj-strategy/src/main/java/cn/com/glsx/dj/strategy/util/validation/validator/InList.java
0 → 100644
View file @
94c78e9
package
cn
.
com
.
glsx
.
dj
.
strategy
.
util
.
validation
.
validator
;
import
javax.validation.Constraint
;
import
javax.validation.Payload
;
import
java.lang.annotation.*
;
/**
* 列表校验注解,校验列表的值是否在指定的值列表中
* @author yangwei
* @since 2025/11/24 16:49
*/
@Documented
@Constraint
(
validatedBy
=
{
InListValidator
.
class
})
@Target
({
ElementType
.
FIELD
,
ElementType
.
PARAMETER
,
ElementType
.
METHOD
})
@Retention
(
RetentionPolicy
.
RUNTIME
)
public
@interface
InList
{
/** 默认错误消息,支持EL表达式 */
String
message
()
default
"值不在允许的范围内"
;
/** 允许的值列表,这是核心参数 */
String
[]
values
()
default
{};
/** 分组校验支持 */
Class
<?>[]
groups
()
default
{};
/** 负载信息 */
Class
<?
extends
Payload
>[]
payload
()
default
{};
/** 是否忽略大小写(可选功能) */
boolean
ignoreCase
()
default
false
;
}
\ No newline at end of file
rpc-dj-strategy/src/main/java/cn/com/glsx/dj/strategy/util/validation/validator/InListValidator.java
0 → 100644
View file @
94c78e9
package
cn
.
com
.
glsx
.
dj
.
strategy
.
util
.
validation
.
validator
;
import
javax.validation.ConstraintValidator
;
import
javax.validation.ConstraintValidatorContext
;
import
java.util.Arrays
;
import
java.util.List
;
import
java.util.stream.Collectors
;
/**
* 列表校验器
* @author yangwei
* @since 2025/11/24 16:49
*/
public
class
InListValidator
implements
ConstraintValidator
<
InList
,
Object
>
{
private
List
<
String
>
allowedValues
;
private
boolean
ignoreCase
;
@Override
public
void
initialize
(
InList
constraintAnnotation
)
{
// 获取注解配置的值列表
String
[]
values
=
constraintAnnotation
.
values
();
this
.
ignoreCase
=
constraintAnnotation
.
ignoreCase
();
if
(
ignoreCase
)
{
// 如果忽略大小写,将所有值转为小写
this
.
allowedValues
=
Arrays
.
stream
(
values
)
.
map
(
String:
:
toLowerCase
)
.
collect
(
Collectors
.
toList
());
}
else
{
this
.
allowedValues
=
Arrays
.
asList
(
values
);
}
}
@Override
public
boolean
isValid
(
Object
value
,
ConstraintValidatorContext
context
)
{
// null 交给 @NotNull 注解
if
(
value
==
null
)
{
return
true
;
}
String
valueStr
=
value
.
toString
();
if
(
ignoreCase
)
{
valueStr
=
valueStr
.
toLowerCase
();
}
return
allowedValues
.
contains
(
valueStr
);
}
}
\ No newline at end of file
rpc-dj-strategy/src/main/resources/META-INF/orm/StrategyInfoMapper.xml
View file @
94c78e9
...
...
@@ -69,4 +69,89 @@
</if>
ORDER BY created_date DESC
</select>
<select
id=
"strategyTotalStatistics"
resultType=
"cn.com.glsx.dj.strategy.dto.StrategyMerchantCountDTO"
>
select
count(*) strategyCount,
count(distinct merchant_id) merchantCount
from dj_car_life_strategy_info
where deleted_flag = 'N'
<if
test=
"biz != null"
>
AND biz = #{businessType}
</if>
<if
test=
"startDate != null and endDate != null and startDate != '' and endDate != ''"
>
AND DATE_FORMAT(created_date, '%Y%m%d') between #{startDate} and #{endDate}
</if>
</select>
<select
id=
"findStrategyTypeDistribution"
resultType=
"cn.com.glsx.dj.strategy.dto.StrategyTypeStatisticsRespDTO"
>
select
strategy_type strategyType,
count(*) strategyCount
from dj_car_life_strategy_info
where deleted_flag = 'N'
<if
test=
"businessType != null and businessType != ''"
>
AND biz = #{businessType}
</if>
<if
test=
"startDate != null and endDate != null and startDate != '' and endDate != ''"
>
AND DATE_FORMAT(created_date, '%Y%m%d') between #{startDate} and #{endDate}
</if>
<if
test=
"uuid != null and uuid != ''"
>
and created_uuid = #{uuid}
</if>
group by strategy_type order by strategyCount desc
</select>
<select
id=
"findStrategyOnlineDistribution"
resultType=
"cn.com.glsx.dj.strategy.dto.StrategyOnlineStatisticsRespDTO"
>
select
created_uuid staffUuid,
count(*) strategyCount,
count(distinct merchant_id) storeCount
from dj_car_life_strategy_info
where deleted_flag = 'N'
<if
test=
"businessType != null and businessType != ''"
>
AND biz = #{businessType}
</if>
<if
test=
"startDate != null and endDate != null and startDate != '' and endDate != ''"
>
AND DATE_FORMAT(created_date, '%Y%m%d') between #{startDate} and #{endDate}
</if>
group by created_uuid order by strategyCount desc
</select>
<select
id=
"selectStaffNameByUuids"
resultType=
"cn.com.glsx.dj.strategy.model.StrategyInfo"
>
select
created_uuid createdUUid,
created_by createdBy
from dj_car_life_strategy_info
where created_uuid in
<foreach
item=
"uuid"
index=
"index"
collection=
"uuids"
open=
"("
separator=
","
close=
")"
>
#{uuid}
</foreach>
and deleted_flag = 'N'
group by created_uuid
</select>
<select
id=
"findStrategyStatisticsGroupMerchantNo"
resultType=
"cn.com.glsx.dj.strategy.dto.MerchantStrategyStatisticsRespDTO"
>
select
merchant_id merchantNo,
count(*) strategyCount
from dj_car_life_strategy_info
where deleted_flag = 'N'
<if
test=
"businessType != null and businessType != ''"
>
AND biz = #{businessType}
</if>
<if
test=
"merchantNos != null and merchantNos.size() > 0"
>
AND merchant_id in
<foreach
item=
"merchantNo"
index=
"index"
collection=
"merchantNos"
open=
"("
separator=
","
close=
")"
>
#{merchantNo}
</foreach>
</if>
<if
test=
"startDate != null and endDate != null and startDate != '' and endDate != ''"
>
AND DATE_FORMAT(created_date, '%Y%m%d') between #{startDate} and #{endDate}
</if>
group by merchant_id order by strategyCount desc
</select>
</mapper>
\ No newline at end of file
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment