Просмотр исходного кода

Merge branch 'master' of https://gogs.dev.dazesoft.cn/dtm_organization/dtm

Gogs 3 месяцев назад
Родитель
Сommit
79801cd413

+ 1 - 1
dtm-admin/src/main/java/com/dtm/dtmApplication.java

@@ -16,7 +16,7 @@ public class dtmApplication
     {
         // System.setProperty("spring.devtools.restart.enabled", "false");
         SpringApplication.run(dtmApplication.class, args);
-        System.out.println("(♥◠‿◠)ノ゙  若依启动成功   ლ(´ڡ`ლ)゙  \n" +
+        System.out.println("(♥◠‿◠)ノ゙  springboot后端启动成功   ლ(´ڡ`ლ)゙  \n" +
                 " .-------.       ____     __        \n" +
                 " |  _ _   \\      \\   \\   /  /    \n" +
                 " | ( ' )  |       \\  _. /  '       \n" +

+ 3 - 3
dtm-admin/src/main/java/com/dtm/web/controller/statistics/LifecycleStatisticsController.java → dtm-admin/src/main/java/com/dtm/web/controller/lifecycle/LifecycleStatisticsController.java

@@ -1,4 +1,4 @@
-package com.dtm.web.controller.statistics;
+package com.dtm.web.controller.lifecycle;
 
 import java.util.Map;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -9,7 +9,7 @@ import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.bind.annotation.RestController;
 import org.springframework.web.multipart.MultipartFile;
 import com.dtm.common.core.domain.AjaxResult;
-import com.dtm.statistics.service.ILifecycleStatisticsService;
+import com.dtm.lifecycle.service.ILifecycleStatisticsService;
 
 /**
  * 生命周期统计分析控制器
@@ -17,7 +17,7 @@ import com.dtm.statistics.service.ILifecycleStatisticsService;
  * @author dtm
  */
 @RestController
-@RequestMapping("/statistics/lifecycle")
+@RequestMapping("/lifecycle")
 public class LifecycleStatisticsController 
 {
     @Autowired

+ 1 - 1
dtm-admin/src/main/resources/application.yml

@@ -57,7 +57,7 @@ spring:
   servlet:
     multipart:
       # 单个文件大小
-      max-file-size: 50MB
+      max-file-size: 300MB
       # 设置总上传的文件大小
       max-request-size: 500MB
   # 服务模块

+ 2 - 2
dtm-common/src/main/java/com/dtm/common/utils/file/FileUploadUtils.java

@@ -24,9 +24,9 @@ import com.dtm.common.utils.uuid.Seq;
 public class FileUploadUtils
 {
     /**
-     * 默认大小 50M
+     * 默认大小 300M
      */
-    public static final long DEFAULT_MAX_SIZE = 50 * 1024 * 1024L;
+    public static final long DEFAULT_MAX_SIZE = 300 * 1024 * 1024L;
 
     /**
      * 默认的文件名最大长度 100

+ 155 - 0
dtm-common/src/main/java/com/dtm/common/utils/http/FlaskApiClient.java

@@ -167,6 +167,161 @@ public class FlaskApiClient
         }
     }
     
+    /**
+     * 上传销售数据文件到Flask服务
+     * 
+     * @param file 上传的文件
+     * @return 响应结果
+     */
+    public static JSONObject uploadSalesFile(MultipartFile file) throws Exception
+    {
+        String url = getFlaskBaseUrl() + "/api/sales/upload";
+        
+        try
+        {
+            // 将MultipartFile转换为临时文件
+            File tempFile = convertMultipartFileToFile(file);
+            
+            try
+            {
+                // 创建请求体
+                MultiValueMap<String, Object> body = new LinkedMultiValueMap<>();
+                FileSystemResource resource = new FileSystemResource(tempFile);
+                body.add("file", resource);
+                
+                // 设置请求头
+                HttpHeaders headers = new HttpHeaders();
+                headers.setContentType(MediaType.MULTIPART_FORM_DATA);
+                
+                HttpEntity<MultiValueMap<String, Object>> requestEntity = new HttpEntity<>(body, headers);
+                
+                // 发送请求
+                log.info("调用Flask API上传销售数据文件: {}", url);
+                ResponseEntity<String> response = restTemplate.exchange(url, HttpMethod.POST, requestEntity, String.class);
+                
+                // 解析响应
+                JSONObject result = JSON.parseObject(response.getBody());
+                log.info("Flask API上传销售数据文件响应: {}", result);
+                
+                return result;
+            }
+            finally
+            {
+                // 删除临时文件
+                if (tempFile.exists())
+                {
+                    tempFile.delete();
+                }
+            }
+        }
+        catch (Exception e)
+        {
+            log.error("调用Flask API上传销售数据文件失败: {}", e.getMessage(), e);
+            throw new Exception("上传销售数据文件到Flask服务失败: " + e.getMessage(), e);
+        }
+    }
+    
+    /**
+     * 分析销售数据
+     * 
+     * @return 分析结果
+     */
+    public static JSONObject analyzeSalesFile() throws Exception
+    {
+        String url = getFlaskBaseUrl() + "/api/sales/analyze";
+        
+        try
+        {
+            HttpHeaders headers = new HttpHeaders();
+            headers.setContentType(MediaType.APPLICATION_JSON);
+            HttpEntity<String> requestEntity = new HttpEntity<>(headers);
+            
+            log.info("调用Flask API分析销售数据: {}", url);
+            ResponseEntity<String> response = restTemplate.exchange(url, HttpMethod.POST, requestEntity, String.class);
+            
+            JSONObject result = JSON.parseObject(response.getBody());
+            log.info("Flask API分析销售数据响应: {}", result);
+            
+            return result;
+        }
+        catch (Exception e)
+        {
+            log.error("调用Flask API分析销售数据失败: {}", e.getMessage(), e);
+            throw new Exception("分析销售数据失败: " + e.getMessage(), e);
+        }
+    }
+    
+    /**
+     * 获取销售分析结果
+     * 
+     * @return 分析结果
+     */
+    public static JSONObject getSalesResults() throws Exception
+    {
+        String url = getFlaskBaseUrl() + "/api/sales/results";
+        
+        try
+        {
+            HttpHeaders headers = new HttpHeaders();
+            headers.setContentType(MediaType.APPLICATION_JSON);
+            HttpEntity<String> requestEntity = new HttpEntity<>(headers);
+            
+            log.info("调用Flask API获取销售分析结果: {}", url);
+            ResponseEntity<String> response = restTemplate.exchange(url, HttpMethod.GET, requestEntity, String.class);
+            
+            JSONObject result = JSON.parseObject(response.getBody());
+            log.info("Flask API获取销售分析结果响应: {}", result);
+            
+            return result;
+        }
+        catch (Exception e)
+        {
+            log.error("调用Flask API获取销售分析结果失败: {}", e.getMessage(), e);
+            throw new Exception("获取销售分析结果失败: " + e.getMessage(), e);
+        }
+    }
+    
+    /**
+     * 预测销售趋势
+     * 
+     * @param sku SKU编码
+     * @param period 预测周期
+     * @return 预测结果
+     */
+    public static JSONObject predictSalesTrend(String sku, int period) throws Exception
+    {
+        String url = getFlaskBaseUrl() + "/api/sales/predict";
+        
+        try
+        {
+            // 创建请求体
+            JSONObject requestBody = new JSONObject();
+            requestBody.put("sku", sku);
+            requestBody.put("period", period);
+            
+            // 设置请求头
+            HttpHeaders headers = new HttpHeaders();
+            headers.setContentType(MediaType.APPLICATION_JSON);
+            
+            HttpEntity<String> requestEntity = new HttpEntity<>(requestBody.toJSONString(), headers);
+            
+            // 发送请求
+            log.info("调用Flask API预测销售趋势: {}, sku={}, period={}", url, sku, period);
+            ResponseEntity<String> response = restTemplate.exchange(url, HttpMethod.POST, requestEntity, String.class);
+            
+            // 解析响应
+            JSONObject result = JSON.parseObject(response.getBody());
+            log.info("Flask API预测销售趋势响应: {}", result);
+            
+            return result;
+        }
+        catch (Exception e)
+        {
+            log.error("调用Flask API预测销售趋势失败: {}", e.getMessage(), e);
+            throw new Exception("预测销售趋势失败: " + e.getMessage(), e);
+        }
+    }
+    
     /**
      * 将MultipartFile转换为File
      */

+ 1 - 1
dtm-system/src/main/java/com/dtm/statistics/service/ILifecycleStatisticsService.java → dtm-system/src/main/java/com/dtm/lifecycle/service/ILifecycleStatisticsService.java

@@ -1,4 +1,4 @@
-package com.dtm.statistics.service;
+package com.dtm.lifecycle.service;
 
 import java.util.Map;
 import org.springframework.web.multipart.MultipartFile;

+ 2 - 2
dtm-system/src/main/java/com/dtm/statistics/service/impl/LifecycleStatisticsService.java → dtm-system/src/main/java/com/dtm/lifecycle/service/impl/LifecycleStatisticsService.java

@@ -1,4 +1,4 @@
-package com.dtm.statistics.service.impl;
+package com.dtm.lifecycle.service.impl;
 
 import java.util.HashMap;
 import java.util.Map;
@@ -10,7 +10,7 @@ import com.alibaba.fastjson2.JSON;
 import com.alibaba.fastjson2.JSONObject;
 import com.dtm.common.utils.StringUtils;
 import com.dtm.common.utils.http.FlaskApiClient;
-import com.dtm.statistics.service.ILifecycleStatisticsService;
+import com.dtm.lifecycle.service.ILifecycleStatisticsService;
 
 /**
  * 生命周期统计分析服务实现类