BiAnalyseBackgroundController.java
19.4 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
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
package cn.com.glsx.dj.script.controller;
import cn.com.glsx.dj.peanalysis.dto.analysis.*;
import cn.com.glsx.dj.peanalysis.enums.BiErrorEnum;
import cn.com.glsx.dj.peanalysis.remote.BiAnalyseBackgroundRemote;
import cn.com.glsx.dj.script.converter.MerchantBiMatterConvert;
import cn.com.glsx.dj.script.converter.MerchantProfitRecordConvert;
import cn.com.glsx.dj.script.converter.ProvinceOrganizationConvert;
import cn.com.glsx.dj.script.request.analysis.*;
import cn.com.glsx.dj.script.request.common.CommonTemplateReq;
import cn.com.glsx.dj.script.request.common.SingleUploadRequest;
import cn.com.glsx.dj.script.response.analysis.MerchantBiMatterResp;
import cn.com.glsx.dj.script.response.analysis.MerchantProfitRecordDetailResp;
import cn.com.glsx.dj.script.response.analysis.MerchantProfitRecordResp;
import cn.com.glsx.dj.script.response.analysis.ProvinceOrganizationResp;
import cn.com.glsx.dj.script.service.BiAnalyseBackgroundService;
import cn.com.glsx.dj.script.service.ExcelAsyncImportService;
import cn.com.glsx.dj.script.utils.CommonUtil;
import cn.com.glsx.dj.smartcarlife.dto.LoginUserDTO;
import cn.com.glsx.framework.core.beans.rpc.RpcPagination;
import cn.com.glsx.framework.core.beans.rpc.RpcResponse;
import cn.com.glsx.framework.core.enums.DefaultErrorEnum;
import cn.com.glsx.framework.core.exception.RpcServiceException;
import cn.com.glsx.framework.rop.response.RopResponse;
import cn.hutool.core.bean.BeanUtil;
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.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.Optional;
/**
* bi 指标分析后台服务控制器
* @author yangwei
* @version 1.0
* @since 2025/12/11 17:17
*/
@Slf4j
@Api("BI指标分析后台")
@RequiredArgsConstructor
@RestController
@ServiceMethodBean(version = "1.0.0", needInSession = NeedInSessionType.YES)
public class BiAnalyseBackgroundController {
private final ExcelAsyncImportService excelAsyncImportService;
private final MerchantBiMatterConvert merchantBiMatterConvert;
private final BiAnalyseBackgroundRemote biAnalyseBackgroundRemote;
private final BiAnalyseBackgroundService biAnalyseBackgroundService;
private final MerchantProfitRecordConvert merchantProfitRecordConvert;
private final ProvinceOrganizationConvert provinceOrganizationConvert;
@ApiOperation("BI-门店毛利额分页记录")
@ServiceMethod(method = "dj.api.script.merchant.profit.record.page", needInSession = NeedInSessionType.YES)
public RopResponse<RpcPagination<MerchantProfitRecordResp>> merchantProfitRecordPage(MerchantProfitRecordQryPageReq request) {
try {
RpcPagination<MerchantProfitRecordQryDTO> rpcPagination = CommonUtil.getRpcPagination(MerchantProfitRecordQryDTO.class);
MerchantProfitRecordQryDTO condition = BeanUtil.copyProperties(request, MerchantProfitRecordQryDTO.class);
rpcPagination.setCondition(condition);
RpcResponse<RpcPagination<MerchantProfitRecordDTO>> response = biAnalyseBackgroundRemote.merchantProfitRecordPage(rpcPagination);
RpcPagination<MerchantProfitRecordDTO> result = response.getResult();
if (response.isFailed()) {
throw new RpcServiceException(response.getError(), response.getMessage());
}
return RopResponse.success(merchantProfitRecordConvert.merchantProfitRecordDto2ResponsePage(result));
} catch (RpcServiceException e) {
log.info("dj.api.script.merchant.profit.record.page occur error!", e);
return RopResponse.error(e);
} catch (Exception e) {
log.info("dj.api.script.merchant.profit.record.page occur error!", e);
return RopResponse.result(DefaultErrorEnum.SERVICE_ERROR);
}
}
@ApiOperation("BI-门店毛利额详情")
@ServiceMethod(method = "dj.api.script.merchant.profit.record.detail", needInSession = NeedInSessionType.YES)
public RopResponse<MerchantProfitRecordDetailResp> merchantProfitRecordDetail(MerchantProfitRecordSingleIdReq request) {
try {
MerchantProfitRecordSingleIdDTO rpcDTO = MerchantProfitRecordSingleIdDTO.builder().recordId(request.getRecordId()).build();
RpcResponse<MerchantProfitRecordDetailDTO> rpcResponse = biAnalyseBackgroundRemote.merchantProfitRecordDetail(rpcDTO);
if (rpcResponse.isFailed()) {
throw new RpcServiceException(rpcResponse.getError(), rpcResponse.getMessage());
}
MerchantProfitRecordDetailResp merchantProfitRecordDetailResp = merchantProfitRecordConvert.merchantProfitRecordDetailDto2Response(rpcResponse.getResult());
return RopResponse.success(merchantProfitRecordDetailResp);
} catch (RpcServiceException e) {
log.info("dj.api.script.merchant.profit.record.detail occur error!", e);
return RopResponse.error(e);
} catch (Exception e) {
log.info("dj.api.script.merchant.profit.record.detail occur error!", e);
return RopResponse.result(DefaultErrorEnum.SERVICE_ERROR);
}
}
@ApiOperation("BI-门店毛利额新增")
@ServiceMethod(method = "dj.api.script.merchant.profit.record.add", needInSession = NeedInSessionType.YES)
public RopResponse<Boolean> merchantProfitRecordAdd(MerchantProfitRecordAddReq request) {
try {
String userName = Optional.ofNullable(CommonUtil.getLoginUser())
.orElseThrow(() -> new RpcServiceException(BiErrorEnum.LOGIN_USER_NOT_EXIST))
.getUserName();
MerchantProfitRecordOperationDTO rpcDto = BeanUtil.copyProperties(request, MerchantProfitRecordOperationDTO.class);
rpcDto.setOperator(userName);
RpcResponse<Boolean> rpcResponse = biAnalyseBackgroundRemote.merchantProfitRecordAdd(rpcDto);
if (rpcResponse.isFailed()) {
throw new RpcServiceException(rpcResponse.getError(), rpcResponse.getMessage());
}
return RopResponse.success(rpcResponse.getResult());
} catch (RpcServiceException e) {
log.info("dj.api.script.merchant.profit.record.add occur error!", e);
return RopResponse.error(e);
} catch (Exception e) {
log.info("dj.api.script.merchant.profit.record.add occur error!", e);
return RopResponse.result(DefaultErrorEnum.SERVICE_ERROR);
}
}
@ApiOperation("BI-门店毛利额修改")
@ServiceMethod(method = "dj.api.script.merchant.profit.record.upd", needInSession = NeedInSessionType.YES)
public RopResponse<Boolean> merchantProfitRecordUpd(MerchantProfitRecordUpdReq request) {
try {
String userName = Optional.ofNullable(CommonUtil.getLoginUser())
.orElseThrow(() -> new RpcServiceException(BiErrorEnum.LOGIN_USER_NOT_EXIST))
.getUserName();
MerchantProfitRecordOperationDTO rpcDto = BeanUtil.copyProperties(request, MerchantProfitRecordOperationDTO.class);
rpcDto.setOperator(userName);
RpcResponse<Boolean> rpcResponse = biAnalyseBackgroundRemote.merchantProfitRecordUpd(rpcDto);
if (rpcResponse.isFailed()) {
throw new RpcServiceException(rpcResponse.getError(), rpcResponse.getMessage());
}
return RopResponse.success(rpcResponse.getResult());
} catch (RpcServiceException e) {
log.info("dj.api.script.merchant.profit.record.upd occur error!", e);
return RopResponse.error(e);
} catch (Exception e) {
log.info("dj.api.script.merchant.profit.record.upd occur error!", e);
return RopResponse.result(DefaultErrorEnum.SERVICE_ERROR);
}
}
@ApiOperation("BI-门店毛利额删除")
@ServiceMethod(method = "dj.api.script.merchant.profit.record.delete", needInSession = NeedInSessionType.YES)
public RopResponse<Boolean> merchantProfitRecordDelete(MerchantProfitRecordSingleIdReq request) {
try {
String userName = Optional.ofNullable(CommonUtil.getLoginUser())
.orElseThrow(() -> new RpcServiceException(BiErrorEnum.LOGIN_USER_NOT_EXIST))
.getUserName();
MerchantProfitRecordOperationDTO rpcDto = MerchantProfitRecordOperationDTO.builder()
.recordId(request.getRecordId()).operator(userName).build();
RpcResponse<Boolean> rpcResponse = biAnalyseBackgroundRemote.merchantProfitRecordDelete(rpcDto);
if (rpcResponse.isFailed()) {
throw new RpcServiceException(rpcResponse.getError(), rpcResponse.getMessage());
}
return RopResponse.success(rpcResponse.getResult());
} catch (RpcServiceException e) {
log.info("dj.api.script.merchant.profit.record.delete occur error!", e);
return RopResponse.error(e);
} catch (Exception e) {
log.info("dj.api.script.merchant.profit.record.delete occur error!", e);
return RopResponse.result(DefaultErrorEnum.SERVICE_ERROR);
}
}
@ApiOperation(
value = "BI-门店毛利额记录异步导出",
notes = "异步导出门店毛利额记录,返回生成的文件UUID,可通过该UUID下载导出文件"
)
@ServiceMethod(method = "dj.api.script.merchant.profit.record.async.export", needInSession = NeedInSessionType.YES)
public RopResponse<String> merchantProfitRecordAsyncExport(MerchantProfitRecordQryReq request) {
try {
return excelAsyncImportService.exportAsync(request, biAnalyseBackgroundService::exportMerchantProfitRecord);
} catch (RpcServiceException e) {
log.info("dj.api.script.merchant.profit.record.async.export occur error!", e);
return RopResponse.error(e);
} catch (Exception e) {
log.info("dj.api.script.merchant.profit.record.async.export occur error!", e);
return RopResponse.result(DefaultErrorEnum.SERVICE_ERROR);
}
}
@ApiOperation("通用模版导出-用于已存在的excel模版")
@ServiceMethod(method = "dj.api.script.common.template.async.export.async.export", needInSession = NeedInSessionType.YES)
public RopResponse<String> commonTemplateAsyncExport(CommonTemplateReq request) {
try {
return excelAsyncImportService.exportAsync(request, biAnalyseBackgroundService::commonTemplateAsyncExport);
} catch (RpcServiceException e) {
log.info("dj.api.script.common.template.async.export.async.export occur error!", e);
return RopResponse.error(e);
} catch (Exception e) {
log.info("dj.api.script.common.template.async.export.async.export occur error!", e);
return RopResponse.result(DefaultErrorEnum.SERVICE_ERROR);
}
}
@ApiOperation(
value = "BI-门店毛利额记录异步导入",
notes = "门店毛利额记录异步导入,返回生成的导入进度条UUID,可通过该UUID获取进度条、导入成功条数,导入失败条数,导入失败文件的url"
)
@ServiceMethod(method = "dj.api.script.merchant.profit.record.async.import", needInSession = NeedInSessionType.YES)
public RopResponse<String> merchantProfitRecordAsyncImport(SingleUploadRequest request) {
try {
String processId = biAnalyseBackgroundService.merchantProfitRecordAsyncImport(request);
return RopResponse.success(processId);
} catch (RpcServiceException e) {
log.info("dj.api.script.common.template.async.export.async.import occur error!", e);
return RopResponse.error(e);
} catch (Exception e) {
log.info("dj.api.script.common.template.async.export.async.import occur error!", e);
return RopResponse.result(DefaultErrorEnum.SERVICE_ERROR);
}
}
@ApiOperation("BI-区域运营管理列表")
@ServiceMethod(method = "dj.api.script.province.organization.list", needInSession = NeedInSessionType.YES)
@PostMapping("/dj.api.script.province.organization.list/1.0.0")
public RopResponse<RpcPagination<ProvinceOrganizationResp>> provinceOrganizationList(ProvinceOrganizationQryPageReq request) {
try {
RpcPagination<?> rpcPagination = CommonUtil.getRpcPagination(MerchantProfitRecordQryDTO.class);
RpcResponse<RpcPagination<ProvinceOrganizationDTO>> response = biAnalyseBackgroundRemote.provinceOrganizationList(rpcPagination);
if (response.isFailed()) {
throw new RpcServiceException(response.getError(), response.getMessage());
}
return RopResponse.success(provinceOrganizationConvert.provinceOrganization2ResponsePage(response.getResult()));
} catch (RpcServiceException e) {
log.info("dj.api.script.province.organization.list occur error!", e);
return RopResponse.error(e);
} catch (Exception e) {
log.info("dj.api.script.province.organization.list occur error!", e);
return RopResponse.result(DefaultErrorEnum.SERVICE_ERROR);
}
}
@ApiOperation("BI-区域运营管理编辑")
@ServiceMethod(method = "dj.api.script.province.organization.upd", needInSession = NeedInSessionType.YES)
@PostMapping("/dj.api.script.province.organization.upd/1.0.0")
public RopResponse<Boolean> provinceOrganizationUpd(ProvinceOrganizationBaseReq request) {
try {
String userName = Optional.ofNullable(CommonUtil.getLoginUser())
.orElseThrow(() -> new RpcServiceException(BiErrorEnum.LOGIN_USER_NOT_EXIST))
.getUserName();
ProvinceOrganizationBaseDTO rpcDto = BeanUtil.copyProperties(request, ProvinceOrganizationBaseDTO.class);
rpcDto.setOperator(userName);
RpcResponse<Boolean> rpcResponse = biAnalyseBackgroundRemote.provinceOrganizationUpd(rpcDto);
if (rpcResponse.isFailed()) {
throw new RpcServiceException(rpcResponse.getError(), rpcResponse.getMessage());
}
return RopResponse.success(rpcResponse.getResult());
} catch (RpcServiceException e) {
log.info("dj.api.script.province.organization.upd occur error!", e);
return RopResponse.error(e);
} catch (Exception e) {
log.info("dj.api.script.province.organization.upd occur error!", e);
return RopResponse.result(DefaultErrorEnum.SERVICE_ERROR);
}
}
@ApiOperation("BI-事项管理分页列表")
@ServiceMethod(method = "dj.api.script.merchant.bi.matter.page", needInSession = NeedInSessionType.YES)
public RopResponse<RpcPagination<MerchantBiMatterResp>> merchantBiMatterPage(MerchantBiMatterQryPageReq request) {
try {
RpcPagination<MerchantBiMatterBaseQryDTO> rpcPagination = CommonUtil.getRpcPagination(MerchantBiMatterBaseQryDTO.class);
MerchantBiMatterBaseQryDTO condition = BeanUtil.copyProperties(request, MerchantBiMatterBaseQryDTO.class);
rpcPagination.setCondition(condition);
RpcResponse<RpcPagination<MerchantBiMatterDTO>> response = biAnalyseBackgroundRemote.merchantBiMatterPage(rpcPagination);
if (response.isFailed()) {
throw new RpcServiceException(response.getError(), response.getMessage());
}
return RopResponse.success(merchantBiMatterConvert.merchantBiMatterDto2ResponsePage(response.getResult()));
} catch (RpcServiceException e) {
log.info("dj.api.script.merchant.bi.matter.page occur error!", e);
return RopResponse.error(e);
} catch (Exception e) {
log.info("dj.api.script.merchant.bi.matter.page occur error!", e);
return RopResponse.result(DefaultErrorEnum.SERVICE_ERROR);
}
}
@ApiOperation("BI-事项管理处理")
@ServiceMethod(method = "dj.api.script.merchant.bi.matter.handle", needInSession = NeedInSessionType.YES)
public RopResponse<Boolean> merchantBiMatterHandle(MerchantBiMatterHandleReq request) {
try {
LoginUserDTO loginUserDTO = Optional.ofNullable(CommonUtil.getLoginUser())
.orElseThrow(() -> new RpcServiceException(BiErrorEnum.LOGIN_USER_NOT_EXIST));
String userName = loginUserDTO.getUserName();
String uuid = loginUserDTO.getUuid();
MerchantBiMatterHandleDTO merchantBiMatterHandleDTO = BeanUtil.copyProperties(request, MerchantBiMatterHandleDTO.class);
merchantBiMatterHandleDTO.setOperator(userName);
merchantBiMatterHandleDTO.setOperatorUniqueKey(uuid);
RpcResponse<Boolean> rpcResponse = biAnalyseBackgroundRemote.merchantBiMatterHandle(merchantBiMatterHandleDTO);
if (rpcResponse.isFailed()) {
throw new RpcServiceException(rpcResponse.getError(), rpcResponse.getMessage());
}
return RopResponse.success(rpcResponse.getResult());
} catch (RpcServiceException e) {
log.info("dj.api.script.merchant.bi.matter.handle occur error!", e);
return RopResponse.error(e);
} catch (Exception e) {
log.info("dj.api.script.merchant.bi.matter.handle occur error!", e);
return RopResponse.result(DefaultErrorEnum.SERVICE_ERROR);
}
}
@ApiOperation("BI-事项管理删除")
@ServiceMethod(method = "dj.api.script.merchant.bi.matter.delete", needInSession = NeedInSessionType.YES)
public RopResponse<Boolean> merchantBiMatterDelete(MerchantBiMatterSingleIdReq request) {
try {
MerchantBiMatterSingleIdDTO merchantBiMatterSingleIdDTO = BeanUtil.copyProperties(request, MerchantBiMatterSingleIdDTO.class);
RpcResponse<Boolean> rpcResponse = biAnalyseBackgroundRemote.merchantBiMatterDelete(merchantBiMatterSingleIdDTO);
if (rpcResponse.isFailed()) {
throw new RpcServiceException(rpcResponse.getError(), rpcResponse.getMessage());
}
return RopResponse.success(rpcResponse.getResult());
} catch (RpcServiceException e) {
log.info("dj.api.script.merchant.bi.matter.delete occur error!", e);
return RopResponse.error(e);
} catch (Exception e) {
log.info("dj.api.script.merchant.bi.matter.delete occur error!", e);
return RopResponse.result(DefaultErrorEnum.SERVICE_ERROR);
}
}
@ApiOperation(
value = "BI-事项管理记录异步导出",
notes = "异步导出事项管理记录,返回生成的文件UUID,可通过该UUID下载导出文件"
)
@ServiceMethod(method = "dj.api.script.merchant.bi.matter.async.export", needInSession = NeedInSessionType.YES)
public RopResponse<String> merchantBiMatterAsyncExport(MerchantBiMatterBaseQryReq request) {
try {
return excelAsyncImportService.exportAsync(request, biAnalyseBackgroundService::merchantBiMatterAsyncExport);
} catch (RpcServiceException e) {
log.info("dj.api.script.merchant.bi.matter.async.export occur error!", e);
return RopResponse.error(e);
} catch (Exception e) {
log.info("dj.api.script.merchant.bi.matter.async.export occur error!", e);
return RopResponse.result(DefaultErrorEnum.SERVICE_ERROR);
}
}
}