Browse Source

上传图片接口修改

gao.qiang 2 years ago
parent
commit
27f426f2cd

+ 1 - 1
business-service/src/main/java/com/ozs/service/entity/BaseAccountManagement.java

@@ -61,7 +61,7 @@ public class BaseAccountManagement extends BaseEntity implements Serializable {
      * 行别
      */
     @Excel(name = "行别")
-    private String lineType;
+    private Integer lineType;
 
     /**
      * 监控相机安装里程位置

+ 0 - 3
business-service/src/main/java/com/ozs/service/entity/MsgAlarm.java

@@ -81,9 +81,6 @@ public class MsgAlarm extends BaseEntity implements Serializable {
      * 报警病害属性(可以给出泥石流的框定范围)
      */
     private String alarmArrr;
-
-    private String files;
-
     /**
      * 报警图片地址
      */

+ 22 - 4
hazard-admin/src/main/java/com/ozs/web/controller/upload/UploadController.java

@@ -1,10 +1,15 @@
 package com.ozs.web.controller.upload;
 
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.ozs.common.core.domain.AjaxResult;
 import com.ozs.common.utils.MinioUtils;
 import com.ozs.common.utils.StringUtils;
 import com.ozs.common.utils.uuid.IdUtils;
+import com.ozs.service.entity.MsgAlarm;
+import com.ozs.service.service.MsgAlarmService;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
+import org.springframework.util.ObjectUtils;
 import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestParam;
@@ -14,6 +19,7 @@ import org.springframework.web.multipart.MultipartFile;
 import javax.annotation.Resource;
 import java.text.SimpleDateFormat;
 import java.util.Date;
+import java.util.List;
 
 @RestController
 @RequestMapping("/system/upLoad")
@@ -24,26 +30,38 @@ public class UploadController {
 
     @Resource
     MinioUtils minioUtils;
+    @Autowired
+    MsgAlarmService msgAlarmService;
 
 
     @PostMapping("/upLoadImage")
     public AjaxResult upLoadImage(@RequestParam("file") MultipartFile image,
-                                  @RequestParam(value = "storagePath", required = false) String storagePath) throws Exception {
+                                  @RequestParam(value = "cameraCode", required = false) String cameraCode,
+                                  @RequestParam(value = "lineType", required = false) String lineType) throws Exception {
         if (image.isEmpty()) {
             return AjaxResult.error("不能上传空文件哦");
         }
         //图片保存路径
         //String fileUploadPath ="/"+userId+"/image";
-        String uploadFile=null;
+        String uploadFile = null;
         if (image != null && !image.isEmpty()) {
 
             String imageName = image.getOriginalFilename();
             if (StringUtils.isNotBlank(imageName)) {
+                LambdaQueryWrapper<MsgAlarm> lw = new LambdaQueryWrapper<MsgAlarm>();
+                if (!ObjectUtils.isEmpty(cameraCode)) {
+                    lw.eq(MsgAlarm::getAlarmCamera, cameraCode);
+                    lw.orderByDesc(MsgAlarm::getAlarmTime);
+                }
+                List<MsgAlarm> list = msgAlarmService.list(lw);
+                MsgAlarm msgAlarm = list.get(0);
                 String date = new SimpleDateFormat("yyyyMMddHHmmss").format(new Date());
                 String filename = IdUtils.fastSimpleUUID() + image.getOriginalFilename().substring(image.getOriginalFilename().lastIndexOf("."));
-                String imgName = storagePath + "/" + filename;
+                SimpleDateFormat dateFormat1 = new SimpleDateFormat("yyyy-MM-dd");
+                String format1 = dateFormat1.format(new Date(msgAlarm.getAlarmTime()));
+                String imgName = msgAlarm.getAlarmLine() + "/" + lineType + "/" + msgAlarm.getAlarmMile() + format1 + "/" + filename;
                 minioUtils.minIoClientUpload(image.getInputStream(), imgName);
-                uploadFile =  "/" + storagePath + "/" + filename;
+                uploadFile = "/" + msgAlarm.getAlarmLine() + "/" + lineType + "/" + msgAlarm.getAlarmMile() + "/" + format1 + "/" + filename;
 
             }
         } else {

+ 4 - 4
hazard-admin/src/main/resources/application.yml

@@ -18,7 +18,7 @@ base:
 # 开发环境配置
 server:
   # 服务器的HTTP端口,默认为8080
-  port: 8081
+  port: 18819
   servlet:
     # 应用的访问路径
     context-path: /
@@ -70,13 +70,13 @@ spring:
   # redis 配置
   redis:
     # 地址
-    host: 124.70.58.209
+    host: 124.71.171.71
     # 端口,默认为6379
-    port: 7001
+    port: 18879
     # 数据库索引
     database: 0
     # 密码
-    password: 106@qwe123
+    password: tysfrz123
     # 连接超时时间
     timeout: 100s
     lettuce:

+ 32 - 0
hazard-sdk/pom.xml

@@ -9,6 +9,8 @@
         <relativePath>../pom.xml</relativePath>
     </parent>
     <modelVersion>4.0.0</modelVersion>
+    <packaging>jar</packaging>
+    <version>1.0</version>
     <artifactId>hazard-sdk</artifactId>
 
     <dependencies>
@@ -41,4 +43,34 @@
             </exclusions>
         </dependency>
     </dependencies>
+
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.springframework.boot</groupId>
+                <artifactId>spring-boot-maven-plugin</artifactId>
+                <version>2.1.1.RELEASE</version>
+                <configuration>
+                    <fork>true</fork> <!-- 如果没有该配置,devtools不会生效 -->
+                </configuration>
+                <executions>
+                    <execution>
+                        <goals>
+                            <goal>repackage</goal>
+                        </goals>
+                    </execution>
+                </executions>
+            </plugin>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-war-plugin</artifactId>
+                <version>3.1.0</version>
+                <configuration>
+                    <failOnMissingWebXml>false</failOnMissingWebXml>
+                    <warName>${project.artifactId}</warName>
+                </configuration>
+            </plugin>
+        </plugins>
+        <finalName>${project.artifactId}</finalName>
+    </build>
 </project>

+ 3 - 3
hazard-sdk/src/main/java/com/ozs/controller/upload/GeoHazardMonitorTokenController.java

@@ -91,7 +91,7 @@ public class GeoHazardMonitorTokenController {
                 respGeoHazardMonitorVo.setAccessToken(objects.get(1));
                 respGeoHazardMonitorVo.setExpiresIn(Long.valueOf(objects.get(0)));
                 respGeoHazardMonitorVo.setTokenType("令牌类型");
-                return new Result(1, "成功", respGeoHazardMonitorVo);
+                return new Result(1, "成功", SM4Utils.encryptData_ECB(JSONObject.toJSONString(respGeoHazardMonitorVo), "4370780c9a8c43e5"));
             } else {
                 return new Result(2, "失败", "生成token失败!!");
             }
@@ -158,7 +158,7 @@ public class GeoHazardMonitorTokenController {
             }
             return new Result(1, "成功", SM4Utils.encryptData_ECB(JSONObject.toJSONString(respMsgAlarmVo), "4370780c9a8c43e5"));
         } else {
-            return new Result(2, "失败", "获取token失败!!");
+            return new Result(2, "失败", "token验证失败!!");
         }
     }
 
@@ -185,7 +185,7 @@ public class GeoHazardMonitorTokenController {
             }
             return new Result(2, "失败");
         } else {
-            return new Result(2, "失败", "获取token失败!!");
+            return new Result(2, "失败", "token验证失败!!");
         }
     }
 }

+ 23 - 4
hazard-sdk/src/main/java/com/ozs/controller/upload/UploadController.java

@@ -1,10 +1,16 @@
 package com.ozs.controller.upload;
 
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.ozs.common.core.domain.AjaxResult;
 import com.ozs.common.utils.MinioUtils;
 import com.ozs.common.utils.StringUtils;
 import com.ozs.common.utils.uuid.IdUtils;
+import com.ozs.service.entity.BaseDynamicManagement;
+import com.ozs.service.entity.MsgAlarm;
+import com.ozs.service.service.MsgAlarmService;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
+import org.springframework.util.ObjectUtils;
 import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestParam;
@@ -14,6 +20,7 @@ import org.springframework.web.multipart.MultipartFile;
 import javax.annotation.Resource;
 import java.text.SimpleDateFormat;
 import java.util.Date;
+import java.util.List;
 
 @RestController
 @RequestMapping("/system/upLoad")
@@ -24,26 +31,38 @@ public class UploadController {
 
     @Resource
     MinioUtils minioUtils;
+    @Autowired
+    MsgAlarmService msgAlarmService;
 
 
     @PostMapping("/upLoadImage")
     public AjaxResult upLoadImage(@RequestParam("file") MultipartFile image,
-                                  @RequestParam(value = "storagePath", required = false) String storagePath) throws Exception {
+                                  @RequestParam(value = "cameraCode", required = false) String cameraCode,
+                                  @RequestParam(value = "lineType", required = false) String lineType) throws Exception {
         if (image.isEmpty()) {
             return AjaxResult.error("不能上传空文件哦");
         }
         //图片保存路径
         //String fileUploadPath ="/"+userId+"/image";
-        String uploadFile=null;
+        String uploadFile = null;
         if (image != null && !image.isEmpty()) {
 
             String imageName = image.getOriginalFilename();
             if (StringUtils.isNotBlank(imageName)) {
+                LambdaQueryWrapper<MsgAlarm> lw = new LambdaQueryWrapper<MsgAlarm>();
+                if (!ObjectUtils.isEmpty(cameraCode)) {
+                    lw.eq(MsgAlarm::getAlarmCamera, cameraCode);
+                    lw.orderByDesc(MsgAlarm::getAlarmTime);
+                }
+                List<MsgAlarm> list = msgAlarmService.list(lw);
+                MsgAlarm msgAlarm = list.get(0);
                 String date = new SimpleDateFormat("yyyyMMddHHmmss").format(new Date());
                 String filename = IdUtils.fastSimpleUUID() + image.getOriginalFilename().substring(image.getOriginalFilename().lastIndexOf("."));
-                String imgName = storagePath + "/" + filename;
+                SimpleDateFormat dateFormat1 = new SimpleDateFormat("yyyy-MM-dd");
+                String format1 = dateFormat1.format(new Date(msgAlarm.getAlarmTime()));
+                String imgName = msgAlarm.getAlarmLine() + "/" + lineType + "/" + msgAlarm.getAlarmMile() + format1 + "/" + filename;
                 minioUtils.minIoClientUpload(image.getInputStream(), imgName);
-                uploadFile =  "/" + storagePath + "/" + filename;
+                uploadFile = "/" + msgAlarm.getAlarmLine() + "/" + lineType + "/" + msgAlarm.getAlarmMile() + "/" + format1 + "/" + filename;
 
             }
         } else {

+ 0 - 2
hazard-sdk/src/main/java/com/ozs/vo/ReqMsgAlarmVo.java

@@ -45,6 +45,4 @@ public class ReqMsgAlarmVo implements Serializable {
     
     /** 报警图片地址 */
     private String imageUrl;
-    
-    private String files;
 }

+ 4 - 4
hazard-sdk/src/main/resources/application.yml

@@ -18,7 +18,7 @@ base:
 # 开发环境配置
 server:
   # 服务器的HTTP端口,默认为8080
-  port: 8082
+  port: 18818
   servlet:
     # 应用的访问路径
     context-path: /
@@ -70,13 +70,13 @@ spring:
   # redis 配置
   redis:
     # 地址
-    host: 124.70.58.209
+    host: 124.71.171.71
     # 端口,默认为6379
-    port: 7001
+    port: 18879
     # 数据库索引
     database: 0
     # 密码
-    password: 106@qwe123
+    password: tysfrz123
     # 连接超时时间
     timeout: 100s
     lettuce: