|
@@ -1,15 +1,19 @@
|
|
|
package com.ozs.controller.upload;
|
|
|
|
|
|
+import cn.hutool.core.date.DateTime;
|
|
|
import com.alibaba.fastjson2.JSONObject;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.ozs.common.core.domain.AjaxResult;
|
|
|
+import com.ozs.common.utils.AppendUtils;
|
|
|
import com.ozs.common.utils.MinioUtils;
|
|
|
import com.ozs.common.utils.StringUtils;
|
|
|
import com.ozs.common.utils.stateSecrets.SM4Utils;
|
|
|
import com.ozs.common.utils.uuid.IdUtils;
|
|
|
import com.ozs.service.entity.BaseCameraManagement;
|
|
|
+import com.ozs.service.entity.BaseRailwayManagement;
|
|
|
import com.ozs.service.entity.MsgAlarm;
|
|
|
import com.ozs.service.service.BaseCameraManagementService;
|
|
|
+import com.ozs.service.service.BaseRailwayManagementService;
|
|
|
import com.ozs.service.service.MsgAlarmService;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
@@ -22,6 +26,8 @@ import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
+import java.time.LocalDate;
|
|
|
+import java.time.LocalTime;
|
|
|
import java.util.Date;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
@@ -39,6 +45,8 @@ public class UploadController {
|
|
|
BaseCameraManagementService baseCameraManagementService;
|
|
|
@Value("${base.imgUrl}")
|
|
|
private String imgUrl;
|
|
|
+ @Autowired
|
|
|
+ private BaseRailwayManagementService baseRailwayManagementService;
|
|
|
|
|
|
|
|
|
@PostMapping("/putObject")
|
|
@@ -79,7 +87,7 @@ public class UploadController {
|
|
|
}
|
|
|
String imgName = baseCameraManagement.getRailwayCode() + "/" + line + "/" + baseCameraManagement.getInstallMile() + "/" + format1 + "/" + filename;
|
|
|
minioUtils.minIoClientUpload(stream.getInputStream(), imgName);
|
|
|
- uploadFile = imgUrl+"/" + baseCameraManagement.getRailwayCode() + "/" + line + "/" + baseCameraManagement.getInstallMile() + "/" + format1 + "/" + filename;
|
|
|
+ uploadFile = imgUrl + "/" + baseCameraManagement.getRailwayCode() + "/" + line + "/" + baseCameraManagement.getInstallMile() + "/" + format1 + "/" + filename;
|
|
|
}
|
|
|
} else {
|
|
|
jsonObject.put("resultCode", 2);
|
|
@@ -95,32 +103,79 @@ public class UploadController {
|
|
|
return jsonObject;
|
|
|
}
|
|
|
|
|
|
-// public static void main(String[] args) {
|
|
|
-// String[] sre = new String[3];
|
|
|
-// sre[0] = "/1244/1/25/2023-03-03/63a1fe3084f24928915dafcf8a47a925.png";
|
|
|
-// sre[1] = "/1244/1/25/2023-03-03/63a1fe3084f24928915dafcf8a47a925.png";
|
|
|
-// sre[2] = "/1244/1/25/2023-03-03/63a1fe3084f24928915dafcf8a47a925.png";
|
|
|
-// JSONObject res = new JSONObject();
|
|
|
-// res.put("alarmCamera", "123");
|
|
|
-// res.put("alarmId", "6588");
|
|
|
-// res.put("alarmTime", 68822222222L);
|
|
|
-// res.put("alarmMile", "1,2,6,8,6,7");
|
|
|
-// res.put("content", "报警内容");
|
|
|
-// res.put("alarmConfidence", 88);
|
|
|
-// res.put("lineDir", 1);
|
|
|
-// res.put("alarmAttr", "aaa");
|
|
|
-// res.put("alarmType", 1);
|
|
|
-// res.put("imageUrls", sre);
|
|
|
-// String s = SM4Utils.encryptData_ECB(JSONObject.toJSONString(res), "4370780c9a8c43e5");
|
|
|
-// System.out.println(s);
|
|
|
-// }
|
|
|
-public static void main(String[] args) {
|
|
|
- JSONObject res = new JSONObject();
|
|
|
- res.put("cameraCode", "654321");
|
|
|
- res.put("time", "1232456789");
|
|
|
- res.put("electricity", 88);
|
|
|
- res.put("cameraState", 1);
|
|
|
- String s = SM4Utils.encryptData_ECB(JSONObject.toJSONString(res), "4370780c9a8c43e5");
|
|
|
- System.out.println(s);
|
|
|
-}
|
|
|
+ /**
|
|
|
+ *
|
|
|
+ * 云端上传图片
|
|
|
+ * @param stream
|
|
|
+ * @param cameraCode
|
|
|
+ * @param size
|
|
|
+ * @param contentType
|
|
|
+ * @param lineDir
|
|
|
+ * @return
|
|
|
+ * @throws Exception
|
|
|
+ */
|
|
|
+ @PostMapping("/cloud/putObject")
|
|
|
+ public JSONObject cloudUpLoadImage(@RequestParam("stream") MultipartFile stream,
|
|
|
+ @RequestParam(value = "cameraCode", required = false) String cameraCode,
|
|
|
+ @RequestParam(value = "size", required = false) Long size,
|
|
|
+ @RequestParam(value = "contentType", required = false) String contentType,
|
|
|
+ @RequestParam(value = "lineDir", required = false) Integer lineDir) throws Exception {
|
|
|
+
|
|
|
+ JSONObject jsonObject = new JSONObject();
|
|
|
+ if (stream.isEmpty()) {
|
|
|
+ jsonObject.put("resultCode", 2);
|
|
|
+ jsonObject.put("message", "失败");
|
|
|
+ jsonObject.put("data", "不能上传空文件哦");
|
|
|
+ return jsonObject;
|
|
|
+ }
|
|
|
+ if (StringUtils.isEmpty(cameraCode)) {
|
|
|
+ jsonObject.put("resultCode", 2);
|
|
|
+ jsonObject.put("message", "失败");
|
|
|
+ jsonObject.put("data", "相机编码不能为空");
|
|
|
+ return jsonObject;
|
|
|
+ }
|
|
|
+ String uploadFile = null;
|
|
|
+ if (stream != null && !stream.isEmpty()) {
|
|
|
+
|
|
|
+ String imageName = stream.getOriginalFilename();
|
|
|
+ if (StringUtils.isNotBlank(imageName)) {
|
|
|
+ LambdaQueryWrapper<BaseCameraManagement> wrapper = new LambdaQueryWrapper<BaseCameraManagement>();
|
|
|
+ if (!ObjectUtils.isEmpty(cameraCode)) {
|
|
|
+ wrapper.eq(BaseCameraManagement::getCameraCode, cameraCode);
|
|
|
+ }
|
|
|
+ //"/"+railwayName+"/"+installMiles+"/"+ LocalDate.now().getYear() +"/"+ LocalDate.now().getMonthValue() +"/"+LocalDate.now().getDayOfMonth()+ "/"+ LocalTime.now().getHour()
|
|
|
+ BaseCameraManagement baseCameraManagement = baseCameraManagementService.getOne(wrapper);
|
|
|
+ String filename = cameraCode + "-" +
|
|
|
+ DateTime.now().toString("yyyyMMddHHmmss") + stream.getOriginalFilename().substring(stream.getOriginalFilename().lastIndexOf("."));
|
|
|
+ SimpleDateFormat dateFormat1 = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
+ String format1 = dateFormat1.format(new Date());
|
|
|
+ BaseRailwayManagement baseRailwayManagement = baseRailwayManagementService.getOne(new LambdaQueryWrapper<BaseRailwayManagement>()
|
|
|
+ .eq(BaseRailwayManagement::getRailwayCode, baseCameraManagement.getRailwayCode()));
|
|
|
+ String imgName = baseRailwayManagement.getRailwayName() + "/" + AppendUtils.stringAppend(baseCameraManagement.getInstallMile()) + "/" + LocalDate.now().getYear() + "/" + LocalDate.now().getMonthValue() + "/" + LocalDate.now().getDayOfMonth() + "/" + LocalTime.now().getHour() + "/" + filename;
|
|
|
+ minioUtils.minIoClientUpload(stream.getInputStream(), imgName);
|
|
|
+ uploadFile = imgUrl + "/" + baseRailwayManagement.getRailwayName() + "/" + AppendUtils.stringAppend(baseCameraManagement.getInstallMile()) + "/" + LocalDate.now().getYear() + "/" + LocalDate.now().getMonthValue() + "/" + LocalDate.now().getDayOfMonth() + "/" + LocalTime.now().getHour() + "/" + filename;
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ jsonObject.put("resultCode", 2);
|
|
|
+ jsonObject.put("message", "失败");
|
|
|
+ jsonObject.put("data", "图片为null");
|
|
|
+ return jsonObject;
|
|
|
+ }
|
|
|
+ Map<String, Object> map = new HashMap<>();
|
|
|
+ map.put("imageUrl", uploadFile);
|
|
|
+ jsonObject.put("resultCode", 1);
|
|
|
+ jsonObject.put("message", "成功");
|
|
|
+ jsonObject.put("data", map);
|
|
|
+ return jsonObject;
|
|
|
+ }
|
|
|
+
|
|
|
+ public static void main(String[] args) {
|
|
|
+ JSONObject res = new JSONObject();
|
|
|
+ res.put("cameraCode", "654321");
|
|
|
+ res.put("time", "1232456789");
|
|
|
+ res.put("electricity", 88);
|
|
|
+ res.put("cameraState", 1);
|
|
|
+ String s = SM4Utils.encryptData_ECB(JSONObject.toJSONString(res), "4370780c9a8c43e5");
|
|
|
+ System.out.println(s);
|
|
|
+ }
|
|
|
}
|