WarningController.java
10.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
package cn.com.glsx.dj.strategy.controller;
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.dj.strategy.remote.ProjectGroupRemote;
import cn.com.glsx.dj.strategy.remote.WarningEngineRemote;
import cn.com.glsx.dj.strategy.request.EffectAnalysisRopRequest;
import cn.com.glsx.dj.strategy.request.WarningDetailQueryRopRequest;
import cn.com.glsx.dj.strategy.request.WarningGroupListRopRequest;
import cn.com.glsx.dj.strategy.request.WarningMetricListRopRequest;
import cn.com.glsx.dj.strategy.request.WarningRecordQueryRopRequest;
import cn.com.glsx.dj.strategy.service.StoreDetailService;
import cn.com.glsx.dj.strategy.service.StrategyDetailService;
import cn.com.glsx.dj.strategy.uitl.CommonUtil;
import cn.com.glsx.framework.core.beans.rpc.RpcResponse;
import cn.com.glsx.framework.core.exception.RpcServiceException;
import cn.com.glsx.framework.rop.response.RopResponse;
import cn.hutool.core.collection.CollUtil;
import com.rop.AbstractRopRequest;
import com.rop.annotation.NeedInSessionType;
import com.rop.annotation.ServiceMethod;
import com.rop.annotation.ServiceMethodBean;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import java.text.SimpleDateFormat;
import java.util.List;
/**
* 预警引擎查询控制器。
*
* @author yangwei_by_claude
* @version 1.0
* @since 2026/05/28 14:00
*/
@Slf4j
@ServiceMethodBean(version = "1.0.0", needInSession = NeedInSessionType.YES)
@Api("预警引擎")
public class WarningController {
@Autowired
private WarningEngineRemote warningEngineRemote;
@Autowired
private ProjectGroupRemote projectGroupRemote;
@Autowired
private StrategyDetailService strategyDetailService;
@Autowired
private StoreDetailService storeDetailService;
@ApiOperation("预警类型下拉")
@ServiceMethod(method = "dj.api.strategy.warning.type.list")
public RopResponse<List<WarningTypeOptionDTO>> listWarningTypes(AbstractRopRequest request) {
try {
RpcResponse<List<WarningTypeOptionDTO>> response = projectGroupRemote.listWarningTypes();
if (response.hasError()) {
log.error(response.getMessage());
return RopResponse.error(response.getError(), response.getMessage());
}
return RopResponse.success(response.getResult());
} catch (RpcServiceException e) {
log.error("dj.api.strategy.warning.type.list rpcServiceException", e);
return RopResponse.error(e);
} catch (Exception e) {
log.error("dj.api.strategy.warning.type.list exception", e);
return RopResponse.error(e.getMessage());
}
}
@ApiOperation("项目组下拉列表")
@ServiceMethod(method = "dj.api.strategy.warning.group.list")
public RopResponse<List<GroupOptionDTO>> listGroups(WarningGroupListRopRequest request) {
try {
RpcResponse<List<GroupOptionDTO>> response = warningEngineRemote.listGroups();
if (response.hasError()) {
log.error(response.getMessage());
return RopResponse.error(response.getError(), response.getMessage());
}
return RopResponse.success(response.getResult());
} catch (RpcServiceException e) {
log.error("dj.api.strategy.warning.group.list rpcServiceException", e);
return RopResponse.error(e);
} catch (Exception e) {
log.error("dj.api.strategy.warning.group.list exception", e);
return RopResponse.error(e.getMessage());
}
}
@ApiOperation("指标类型下拉")
@ServiceMethod(method = "dj.api.strategy.warning.metric.list")
public RopResponse<List<MetricOptionDTO>> listMetrics(WarningMetricListRopRequest request) {
try {
ProjectGroupMetricQueryDTO dto = new ProjectGroupMetricQueryDTO();
dto.setWarningType(request.getWarningType());
dto.setBiz(request.getBusinessType());
RpcResponse<List<MetricOptionDTO>> response = warningEngineRemote.listMetrics(dto);
if (response.hasError()) {
log.error(response.getMessage());
return RopResponse.error(response.getError(), response.getMessage());
}
return RopResponse.success(response.getResult());
} catch (RpcServiceException e) {
log.error("dj.api.strategy.warning.metric.list rpcServiceException", e);
return RopResponse.error(e);
} catch (Exception e) {
log.error("dj.api.strategy.warning.metric.list exception", e);
return RopResponse.error(e.getMessage());
}
}
@ApiOperation("门店预警汇总列表")
@ServiceMethod(method = "dj.api.strategy.warning.summary", needInSession = NeedInSessionType.YES)
public RopResponse<List<StoreWarningSummaryDTO>> findWarningSummary(WarningRecordQueryRopRequest request) {
try {
WarningRecordQueryRequest req = CommonUtil.convertRequest(WarningRecordQueryRequest.class);
req.setQueryStartDate(req.getStartDate());
req.setQueryEndDate(req.getEndDate());
// cycleType → timeDimension + 起止日期
String[] resolved = CommonUtil.resolveTimeDimension(request.getCycleType(), req.getStartDate(), req.getEndDate());
req.setTimeDimension(resolved[0]);
req.setStartDate(resolved[1]);
req.setEndDate(resolved[2]);
RpcResponse<List<StoreWarningSummaryDTO>> response = warningEngineRemote.findWarningSummaryFromRelation(req);
if (response.hasError()) {
log.error(response.getMessage());
return RopResponse.error(response.getError(), response.getMessage());
}
List<StoreWarningSummaryDTO> result = response.getResult();
if (CollUtil.isNotEmpty(result) && request.getBusinessType() != null) {
storeDetailService.enrichStoreWarningSummaries(result, request.getBusinessType());
}
return RopResponse.success(result);
} catch (RpcServiceException e) {
log.error("dj.api.strategy.warning.summary rpcServiceException", e);
return RopResponse.error(e);
} catch (Exception e) {
log.error("dj.api.strategy.warning.summary exception", e);
return RopResponse.error(e.getMessage());
}
}
@ApiOperation("指定门店+员工预警明细")
@ServiceMethod(method = "dj.api.strategy.warning.store.staff.detail", needInSession = NeedInSessionType.YES)
public RopResponse<List<WarningRecordDTO>> findWarningDetailByStoreAndStaff(WarningDetailQueryRopRequest request) {
try {
WarningRecordQueryRequest req = CommonUtil.convertRequest(WarningRecordQueryRequest.class);
if (request.getCycleType() == 4) {
return RopResponse.success(CollUtil.newArrayList());
}
// cycleType → timeDimension + 起止日期
String[] resolved = CommonUtil.resolveTimeDimension(request.getCycleType(), req.getStartDate(), req.getEndDate());
req.setTimeDimension(resolved[0]);
req.setStartDate(resolved[1]);
req.setEndDate(resolved[2]);
RpcResponse<List<WarningRecordDTO>> response = warningEngineRemote.findWarningDetailByStoreAndStaff(req);
if (response.hasError()) {
log.error(response.getMessage());
return RopResponse.error(response.getError(), response.getMessage());
}
return RopResponse.success(response.getResult());
} catch (RpcServiceException e) {
log.error("dj.api.strategy.warning.store.staff.detail rpcServiceException", e);
return RopResponse.error(e);
} catch (Exception e) {
log.error("dj.api.strategy.warning.store.staff.detail exception", e);
return RopResponse.error(e.getMessage());
}
}
@ApiOperation("效果分析")
@ServiceMethod(method = "dj.api.strategy.analysis.effect", needInSession = NeedInSessionType.YES)
public RopResponse<RpcPagination<EffectAnalysisDTO>> analysisEffect(EffectAnalysisRopRequest request) {
try {
// cycleType → timeDimension + 起止日期
String[] resolved = CommonUtil.resolveTimeDimension(request.getCycleType(), request.getStartDate(), request.getEndDate());
EffectAnalysisRequest req = new EffectAnalysisRequest();
req.setBusinessType(request.getBusinessType());
req.setWarningType(request.getWarningType());
req.setTimeDimension(resolved[0]);
req.setStartDate(resolved[1]);
req.setEndDate(resolved[2]);
req.setPageNum(request.getPageNum());
req.setPageSize(request.getPageSize());
RpcResponse<RpcPagination<EffectAnalysisDTO>> response = warningEngineRemote.analysisEffect(req);
if (response.hasError()) {
log.error(response.getMessage());
return RopResponse.error(response.getError(), response.getMessage());
}
// 填充门店详情(品牌、运营人员、策略统计)
RpcPagination<EffectAnalysisDTO> pageResult = response.getResult();
if (pageResult != null && CollUtil.isNotEmpty(pageResult.getList())) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
storeDetailService.enrichStoreDetails(pageResult.getList(),
request.getBusinessType(),
sdf.parse(request.getStartDate()),
sdf.parse(request.getEndDate()));
}
return RopResponse.success(pageResult);
} catch (RpcServiceException e) {
log.error("dj.api.strategy.analysis.effect rpcServiceException", e);
return RopResponse.error(e);
} catch (Exception e) {
log.error("dj.api.strategy.analysis.effect exception", e);
return RopResponse.error(e.getMessage());
}
}
}