|
|
@@ -13,10 +13,10 @@ import org.springframework.web.bind.annotation.RequestParam;
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
+import java.util.Collections;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
-import java.util.Collections;
|
|
|
|
|
|
@Anonymous
|
|
|
@RestController
|
|
|
@@ -38,6 +38,11 @@ public class ShopDataImportController {
|
|
|
return "Shop data store ready. Path: " + shopDataFolderPath;
|
|
|
}
|
|
|
|
|
|
+ @GetMapping("/max-date")
|
|
|
+ public String getMaxSalesDate() {
|
|
|
+ return shopAnalysisService.getMaxSalesDate();
|
|
|
+ }
|
|
|
+
|
|
|
@GetMapping("/import-sales-data")
|
|
|
public ResponseEntity<Map<String, Object>> importSalesData() {
|
|
|
Map<String, Object> response = new HashMap<>();
|
|
|
@@ -87,176 +92,137 @@ public class ShopDataImportController {
|
|
|
}
|
|
|
|
|
|
@GetMapping("/channel-contribution")
|
|
|
- public ResponseEntity<Map<String, Object>> getChannelContribution() {
|
|
|
- Map<String, Object> response = new HashMap<>();
|
|
|
+ public ResponseEntity<Map<String, Object>> getChannelContribution(
|
|
|
+ @RequestParam(required = false) String startDate,
|
|
|
+ @RequestParam(required = false) String endDate) {
|
|
|
try {
|
|
|
- Map<String, Double> contributionData = shopAnalysisService.getChannelSalesContribution();
|
|
|
-
|
|
|
+ Map<String, Double> contributionData = shopAnalysisService.getChannelSalesContribution(startDate, endDate);
|
|
|
if (contributionData == null || contributionData.isEmpty()) {
|
|
|
- return ResponseEntity.ok(buildEmptyResponse("请先上传店铺价值文件", new HashMap<>()));
|
|
|
+ return ResponseEntity.ok(buildEmptyResponse("请先上传店铺价值 CSV 文件", new HashMap<>()));
|
|
|
}
|
|
|
-
|
|
|
- response.put("success", true);
|
|
|
- response.put("message", "Channel contribution ready.");
|
|
|
- response.put("data", contributionData);
|
|
|
- return ResponseEntity.ok(response);
|
|
|
+ return ResponseEntity.ok(buildSuccessResponse("Channel contribution ready.", contributionData));
|
|
|
} catch (Exception e) {
|
|
|
- response.put("success", false);
|
|
|
- response.put("message", "Analysis failed: " + e.getMessage());
|
|
|
- return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(response);
|
|
|
+ return buildFailureResponse(e);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@GetMapping("/channel-roi-value")
|
|
|
- public ResponseEntity<Map<String, Object>> getChannelRoiValue() {
|
|
|
- Map<String, Object> response = new HashMap<>();
|
|
|
+ public ResponseEntity<Map<String, Object>> getChannelRoiValue(
|
|
|
+ @RequestParam(required = false) String startDate,
|
|
|
+ @RequestParam(required = false) String endDate) {
|
|
|
try {
|
|
|
- Map<String, Double> roiData = shopAnalysisService.getChannelRoiValue();
|
|
|
-
|
|
|
+ Map<String, Double> roiData = shopAnalysisService.getChannelRoiValue(startDate, endDate);
|
|
|
if (roiData == null || roiData.isEmpty()) {
|
|
|
- return ResponseEntity.ok(buildEmptyResponse("请先上传店铺价值文件", new HashMap<>()));
|
|
|
+ return ResponseEntity.ok(buildEmptyResponse("请先上传店铺价值 CSV 文件", new HashMap<>()));
|
|
|
}
|
|
|
-
|
|
|
- response.put("success", true);
|
|
|
- response.put("message", "Channel ROI ready.");
|
|
|
- response.put("data", roiData);
|
|
|
- return ResponseEntity.ok(response);
|
|
|
+ return ResponseEntity.ok(buildSuccessResponse("Channel ROI ready.", roiData));
|
|
|
} catch (Exception e) {
|
|
|
- response.put("success", false);
|
|
|
- response.put("message", "Analysis failed: " + e.getMessage());
|
|
|
- return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(response);
|
|
|
+ return buildFailureResponse(e);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@GetMapping("/unit-contribution")
|
|
|
- public ResponseEntity<Map<String, Object>> getUnitContribution() {
|
|
|
- Map<String, Object> response = new HashMap<>();
|
|
|
- List<Map<String, Object>> data = shopAnalysisService.getUnitContribution();
|
|
|
-
|
|
|
+ public ResponseEntity<Map<String, Object>> getUnitContribution(
|
|
|
+ @RequestParam(required = false) String startDate,
|
|
|
+ @RequestParam(required = false) String endDate) {
|
|
|
+ List<Map<String, Object>> data = shopAnalysisService.getUnitContribution(startDate, endDate);
|
|
|
if (data == null || data.isEmpty()) {
|
|
|
- return ResponseEntity.ok(buildEmptyResponse("请先上传店铺价值文件", Collections.emptyList()));
|
|
|
+ return ResponseEntity.ok(buildEmptyResponse("请先上传店铺价值 CSV 文件", Collections.emptyList()));
|
|
|
}
|
|
|
-
|
|
|
- response.put("success", true);
|
|
|
- response.put("message", "Unit contribution ready.");
|
|
|
- response.put("data", data);
|
|
|
- return ResponseEntity.ok(response);
|
|
|
+ return ResponseEntity.ok(buildSuccessResponse("Unit contribution ready.", data));
|
|
|
}
|
|
|
|
|
|
@GetMapping("/channel-total-contribution")
|
|
|
- public ResponseEntity<Map<String, Object>> getChannelTotalContribution() {
|
|
|
- Map<String, Object> response = new HashMap<>();
|
|
|
- List<Map<String, Object>> data = shopAnalysisService.getChannelTotalContribution();
|
|
|
-
|
|
|
+ public ResponseEntity<Map<String, Object>> getChannelTotalContribution(
|
|
|
+ @RequestParam(required = false) String startDate,
|
|
|
+ @RequestParam(required = false) String endDate) {
|
|
|
+ List<Map<String, Object>> data = shopAnalysisService.getChannelTotalContribution(startDate, endDate);
|
|
|
if (data == null || data.isEmpty()) {
|
|
|
- return ResponseEntity.ok(buildEmptyResponse("请先上传店铺价值文件", Collections.emptyList()));
|
|
|
+ return ResponseEntity.ok(buildEmptyResponse("请先上传店铺价值 CSV 文件", Collections.emptyList()));
|
|
|
}
|
|
|
-
|
|
|
- response.put("success", true);
|
|
|
- response.put("message", "Channel total contribution ready.");
|
|
|
- response.put("data", data);
|
|
|
- return ResponseEntity.ok(response);
|
|
|
+ return ResponseEntity.ok(buildSuccessResponse("Channel total contribution ready.", data));
|
|
|
}
|
|
|
|
|
|
@GetMapping("/platform-total-contribution")
|
|
|
- public ResponseEntity<Map<String, Object>> getPlatformTotalContribution() {
|
|
|
- Map<String, Object> response = new HashMap<>();
|
|
|
- List<Map<String, Object>> data = shopAnalysisService.getPlatformTotalContribution();
|
|
|
-
|
|
|
+ public ResponseEntity<Map<String, Object>> getPlatformTotalContribution(
|
|
|
+ @RequestParam(required = false) String startDate,
|
|
|
+ @RequestParam(required = false) String endDate) {
|
|
|
+ List<Map<String, Object>> data = shopAnalysisService.getPlatformTotalContribution(startDate, endDate);
|
|
|
if (data == null || data.isEmpty()) {
|
|
|
- return ResponseEntity.ok(buildEmptyResponse("请先上传店铺价值文件", Collections.emptyList()));
|
|
|
+ return ResponseEntity.ok(buildEmptyResponse("请先上传店铺价值 CSV 文件", Collections.emptyList()));
|
|
|
}
|
|
|
-
|
|
|
- response.put("success", true);
|
|
|
- response.put("message", "Platform total contribution ready.");
|
|
|
- response.put("data", data);
|
|
|
- return ResponseEntity.ok(response);
|
|
|
+ return ResponseEntity.ok(buildSuccessResponse("Platform total contribution ready.", data));
|
|
|
}
|
|
|
|
|
|
@GetMapping("/top-product-contribution")
|
|
|
- public ResponseEntity<Map<String, Object>> getTopProductContribution() {
|
|
|
- Map<String, Object> response = new HashMap<>();
|
|
|
+ public ResponseEntity<Map<String, Object>> getTopProductContribution(
|
|
|
+ @RequestParam(required = false) String startDate,
|
|
|
+ @RequestParam(required = false) String endDate) {
|
|
|
try {
|
|
|
- Map<String, Object> result = shopAnalysisService.getTopProductContribution();
|
|
|
-
|
|
|
+ Map<String, Object> result = shopAnalysisService.getTopProductContribution(startDate, endDate);
|
|
|
if (result == null || result.isEmpty()) {
|
|
|
- return ResponseEntity.ok(buildEmptyResponse("请先上传店铺价值文件", new HashMap<>()));
|
|
|
+ return ResponseEntity.ok(buildEmptyResponse("请先上传店铺价值 CSV 文件", new HashMap<>()));
|
|
|
}
|
|
|
-
|
|
|
- response.put("success", true);
|
|
|
- response.put("message", "Top product contribution ready.");
|
|
|
- response.put("data", result);
|
|
|
- return ResponseEntity.ok(response);
|
|
|
+ return ResponseEntity.ok(buildSuccessResponse("Top product contribution ready.", result));
|
|
|
} catch (Exception e) {
|
|
|
- response.put("success", false);
|
|
|
- response.put("message", "Analysis failed: " + e.getMessage());
|
|
|
- return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(response);
|
|
|
+ return buildFailureResponse(e);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@GetMapping("/cross-selling-products")
|
|
|
- public ResponseEntity<Map<String, Object>> getCrossSellingProducts() {
|
|
|
- Map<String, Object> response = new HashMap<>();
|
|
|
+ public ResponseEntity<Map<String, Object>> getCrossSellingProducts(
|
|
|
+ @RequestParam(required = false) String startDate,
|
|
|
+ @RequestParam(required = false) String endDate,
|
|
|
+ @RequestParam(required = false) String skuKeyword) {
|
|
|
try {
|
|
|
- List<Map<String, Object>> data = shopAnalysisService.getCrossSellingProducts();
|
|
|
-
|
|
|
+ List<Map<String, Object>> data = shopAnalysisService.getCrossSellingProducts(startDate, endDate, skuKeyword);
|
|
|
if (data == null || data.isEmpty()) {
|
|
|
- return ResponseEntity.ok(buildEmptyResponse("请先上传店铺价值文件", Collections.emptyList()));
|
|
|
+ return ResponseEntity.ok(buildEmptyResponse("请先上传店铺价值 CSV 文件或调整 SKU 条件", Collections.emptyList()));
|
|
|
}
|
|
|
-
|
|
|
- response.put("success", true);
|
|
|
- response.put("message", "Cross-selling products ready.");
|
|
|
- response.put("data", data);
|
|
|
- return ResponseEntity.ok(response);
|
|
|
+ return ResponseEntity.ok(buildSuccessResponse("Cross-selling products ready.", data));
|
|
|
} catch (Exception e) {
|
|
|
- response.put("success", false);
|
|
|
- response.put("message", "Analysis failed: " + e.getMessage());
|
|
|
- return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(response);
|
|
|
+ return buildFailureResponse(e);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@GetMapping("/department-efficiency")
|
|
|
- public ResponseEntity<Map<String, Object>> getDepartmentOperationalEfficiency() {
|
|
|
- Map<String, Object> response = new HashMap<>();
|
|
|
+ public ResponseEntity<Map<String, Object>> getDepartmentOperationalEfficiency(
|
|
|
+ @RequestParam(required = false) String startDate,
|
|
|
+ @RequestParam(required = false) String endDate) {
|
|
|
try {
|
|
|
- Map<String, Double> data = shopAnalysisService.getDepartmentOperationalEfficiency();
|
|
|
-
|
|
|
+ Map<String, Double> data = shopAnalysisService.getDepartmentOperationalEfficiency(startDate, endDate);
|
|
|
if (data == null || data.isEmpty()) {
|
|
|
- return ResponseEntity.ok(buildEmptyResponse("请先上传店铺价值文件", new HashMap<>()));
|
|
|
+ return ResponseEntity.ok(buildEmptyResponse("请先上传店铺价值 CSV 文件", new HashMap<>()));
|
|
|
}
|
|
|
-
|
|
|
- response.put("success", true);
|
|
|
- response.put("message", "Department efficiency ready.");
|
|
|
- response.put("data", data);
|
|
|
- return ResponseEntity.ok(response);
|
|
|
+ return ResponseEntity.ok(buildSuccessResponse("Department efficiency ready.", data));
|
|
|
} catch (Exception e) {
|
|
|
- response.put("success", false);
|
|
|
- response.put("message", "Analysis failed: " + e.getMessage());
|
|
|
- return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(response);
|
|
|
+ return buildFailureResponse(e);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@GetMapping("/channel-diversity")
|
|
|
- public ResponseEntity<Map<String, Object>> getChannelProductDiversity() {
|
|
|
- Map<String, Object> response = new HashMap<>();
|
|
|
+ public ResponseEntity<Map<String, Object>> getChannelProductDiversity(
|
|
|
+ @RequestParam(required = false) String startDate,
|
|
|
+ @RequestParam(required = false) String endDate) {
|
|
|
try {
|
|
|
- Map<String, Long> data = shopAnalysisService.getChannelProductDiversity();
|
|
|
-
|
|
|
+ Map<String, Long> data = shopAnalysisService.getChannelProductDiversity(startDate, endDate);
|
|
|
if (data == null || data.isEmpty()) {
|
|
|
- return ResponseEntity.ok(buildEmptyResponse("请先上传店铺价值文件", new HashMap<>()));
|
|
|
+ return ResponseEntity.ok(buildEmptyResponse("请先上传店铺价值 CSV 文件", new HashMap<>()));
|
|
|
}
|
|
|
-
|
|
|
- response.put("success", true);
|
|
|
- response.put("message", "Channel diversity ready.");
|
|
|
- response.put("data", data);
|
|
|
- return ResponseEntity.ok(response);
|
|
|
+ return ResponseEntity.ok(buildSuccessResponse("Channel diversity ready.", data));
|
|
|
} catch (Exception e) {
|
|
|
- response.put("success", false);
|
|
|
- response.put("message", "Analysis failed: " + e.getMessage());
|
|
|
- return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(response);
|
|
|
+ return buildFailureResponse(e);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ private Map<String, Object> buildSuccessResponse(String message, Object data) {
|
|
|
+ Map<String, Object> response = new HashMap<>();
|
|
|
+ response.put("success", true);
|
|
|
+ response.put("message", message);
|
|
|
+ response.put("data", data);
|
|
|
+ return response;
|
|
|
+ }
|
|
|
+
|
|
|
private Map<String, Object> buildEmptyResponse(String message, Object data) {
|
|
|
Map<String, Object> response = new HashMap<>();
|
|
|
response.put("success", true);
|
|
|
@@ -265,4 +231,11 @@ public class ShopDataImportController {
|
|
|
response.put("data", data);
|
|
|
return response;
|
|
|
}
|
|
|
+
|
|
|
+ private ResponseEntity<Map<String, Object>> buildFailureResponse(Exception e) {
|
|
|
+ Map<String, Object> response = new HashMap<>();
|
|
|
+ response.put("success", false);
|
|
|
+ response.put("message", "Analysis failed: " + e.getMessage());
|
|
|
+ return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(response);
|
|
|
+ }
|
|
|
}
|