From d0b51c6d6f2b7a530c0557b6279cc6dfced223cf Mon Sep 17 00:00:00 2001
From: zhubaomin <470473919@qq.com>
Date: 星期日, 27 四月 2025 19:01:04 +0800
Subject: [PATCH] 各轮灌组开阀时间提前10分钟,第一组除外,改为配置文件设置
---
pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/dyFile/FileOperate.java | 350 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 350 insertions(+), 0 deletions(-)
diff --git a/pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/dyFile/FileOperate.java b/pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/dyFile/FileOperate.java
new file mode 100644
index 0000000..5d00701
--- /dev/null
+++ b/pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/dyFile/FileOperate.java
@@ -0,0 +1,350 @@
+package com.dy.pipIrrGlobal.dyFile;
+
+import com.dy.common.util.NumUtil;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.HttpEntity;
+import org.springframework.http.HttpHeaders;
+import org.springframework.http.MediaType;
+import org.springframework.stereotype.Component;
+import org.springframework.util.LinkedMultiValueMap;
+import org.springframework.util.MultiValueMap;
+import org.springframework.web.client.RestTemplate;
+import org.springframework.web.multipart.MultipartFile;
+
+import java.util.Arrays;
+import java.util.List;
+
+@Component
+public class FileOperate {
+
+ @Autowired
+ private RestTemplate restTemplate ;
+
+ /**
+ * 鎷嗗垎涓婅浇鏂囦欢鐨勫悕绉�
+ * @param file
+ * @return
+ */
+ public String[] splitFileName(MultipartFile file){
+ String[] grp = new String[2] ;
+ if(file != null) {
+ String fileName = file.getOriginalFilename();
+ int lastDotIndex = fileName.lastIndexOf('.');
+ if (lastDotIndex >= 0) {
+ grp[0] = fileName.substring(0, lastDotIndex);
+ grp[1] = fileName.substring(lastDotIndex + 1);
+ if(grp[0].trim().equals("")){
+ grp[0] = "鍖垮悕" ;
+ }
+ }
+ }
+ return grp ;
+ }
+
+ /**
+ * 寰楀埌涓婅浇鐨勬枃浠舵墿灞曞悕
+ * @param file
+ * @return
+ */
+ public String getFileExtName(MultipartFile file){
+ String fileExtName = null ;
+ if(file != null) {
+ String filename = file.getOriginalFilename();
+ int lastDotIndex = filename.lastIndexOf('.');
+ if (lastDotIndex >= 0) {
+ fileExtName = filename.substring(lastDotIndex + 1);
+ }
+ }
+ return fileExtName ;
+ }
+
+ /**
+ * 寰楀埌涓婅浇鐨勬枃浠朵富鍚�
+ * @param fileName
+ * @return
+ */
+ public String getFileMainName(String fileName){
+ String fileMainName = null ;
+ if(fileName != null) {
+ int lastDotIndex = fileName.lastIndexOf('.');
+ if (lastDotIndex >= 0) {
+ fileMainName = fileName.substring(0, lastDotIndex);
+ }
+ }
+ if(fileMainName == null){
+ fileMainName = "noName" ;
+ }
+ return fileMainName ;
+ }
+
+ /**
+ * 閫氳繃鐓х墖璺緞锛屽緱鍒板搴旂缉鐣ュ浘鐨勮矾寰�
+ * @param filePath
+ * @return
+ */
+ public String getFileZipPath(String filePath){
+ String path_ = null ;
+ String prePath = null ;
+ String tailPath = null ;
+ if(filePath != null && !filePath.trim().equals("")) {
+ int lastDotIndex = filePath.lastIndexOf('.');
+ if (lastDotIndex >= 0) {
+ prePath = filePath.substring(0, lastDotIndex);
+ tailPath = filePath.substring(lastDotIndex);
+ path_ = prePath + "_" + tailPath ;
+ }
+ }
+ if(path_ == null){
+ path_ = filePath;
+ }
+ return path_ ;
+ }
+
+ /**
+ * 閫氳繃瑙嗛璺緞锛屽緱鍒板搴旂缉鐣ュ浘鐨勮矾寰�
+ * @param filePath
+ * @return
+ */
+ public String getFileZipPath(String filePath, String extName){
+ String path_ = null ;
+ String prePath = null ;
+ if(filePath != null && !filePath.trim().equals("")) {
+ int lastDotIndex = filePath.lastIndexOf('.');
+ if (lastDotIndex >= 0) {
+ prePath = filePath.substring(0, lastDotIndex);
+ path_ = prePath + "_." + extName ;
+ }
+ }
+ if(path_ == null){
+ path_ = filePath;
+ }
+ return path_ ;
+ }
+
+ /**
+ * web鍒嗗竷寮忔枃浠剁郴缁熶繚瀛樻枃浠�
+ * @param file
+ * @param fmUrl
+ * @param fileCtrlRqMp
+ * @param fileMethodMp
+ * @param regionNum
+ * @param fileExtName
+ * @param json
+ * @return
+ * @throws Exception
+ */
+ public FileRestVo saveFile(MultipartFile file,
+ String fmUrl,
+ String fileCtrlRqMp,
+ String fileMethodMp,
+ String regionNum,
+ String fileExtName,
+ String json) throws Exception{
+ FileRestVo rvo = null ;
+ if(file != null && file.getBytes() != null && file.getBytes().length > 0){
+ rvo = this.restCreateFileName(fmUrl, fileExtName) ;
+ if(rvo != null){
+ String relativeFilePath = this.restSaveFile(fileCtrlRqMp, fileMethodMp, file, regionNum, json, rvo);
+ rvo.fileWebPath = relativeFilePath ;
+ //if(relativeFilePath != null){
+ // rvo.createFilePath(relativeFilePath, rvo.fileNameHash);
+ //}
+ }
+ }
+ return rvo ;
+ }
+
+ /**
+ * 鐢熸垚鏂囦欢鍚嶇О
+ * @return
+ */
+ private FileRestVo restCreateFileName(String fmUrl, String fileExtName) throws Exception{
+ // 鍑嗗璇锋眰鏁版嵁
+ MultiValueMap<String, Object> multipartRequestData = new LinkedMultiValueMap<>();
+ multipartRequestData.add(FileConstant.fmPostMapping_create_paramName, fileExtName);
+
+ // 璁剧疆璇锋眰澶撮儴锛岃繖閲屽亣璁炬湇鍔″櫒鎺ユ敹multipart/form-data绫诲瀷鐨勬暟鎹�
+ HttpHeaders headers = new HttpHeaders();
+ headers.setContentType(MediaType.MULTIPART_FORM_DATA);
+
+ // 灏佽璇锋眰浣�
+ HttpEntity<MultiValueMap<String, Object>> requestEntity = new HttpEntity<>(multipartRequestData, headers);
+
+ String webUrl = fmUrl + "/" + FileConstant.fmRequestMapping + "/" + FileConstant.fmPostMapping_create;
+ // 鍙戦�丳OST璇锋眰
+ FileRestVo rvo = restTemplate.postForObject(webUrl, requestEntity, FileRestVo.class);
+
+ return rvo ;
+ }
+
+ /**
+ * 鎶婃枃浠跺瓨鍌ㄥ埌鏂囦欢绯荤粺涓�
+ * @param file
+ * @param regionNum
+ * @param json json鏁版嵁
+ * @param rvo
+ * @return
+ * @throws Exception
+ */
+ private String restSaveFile(String fileCtrlRqMp,
+ String fileMethodMp,
+ MultipartFile file,
+ String regionNum,
+ String json,
+ FileRestVo rvo) throws Exception{
+ // 鍑嗗璇锋眰鏁版嵁
+ MultiValueMap<String, Object> multipartRequestData = new LinkedMultiValueMap<>();
+ multipartRequestData.add(FileConstant.filePostMapping_paramName_file, file.getResource());
+ multipartRequestData.add(FileConstant.filePostMapping_paramName_regionNum, regionNum);
+ multipartRequestData.add(FileConstant.filePostMapping_paramName_json, (json==null?"":json));
+ multipartRequestData.add(FileConstant.filePostMapping_paramName_absolutePath, rvo.fileSysAbsolutePath);
+ multipartRequestData.add(FileConstant.filePostMapping_paramName_relativePath, rvo.fileSysRelativePath);
+ multipartRequestData.add(FileConstant.filePostMapping_paramName_fileName, rvo.fileName);
+
+ // 璁剧疆璇锋眰澶撮儴锛岃繖閲屽亣璁炬湇鍔″櫒鎺ユ敹multipart/form-data绫诲瀷鐨勬暟鎹�
+ HttpHeaders headers = new HttpHeaders();
+ headers.setContentType(MediaType.MULTIPART_FORM_DATA);
+ //headers.setContentLength(file.getSize());
+
+ // 灏佽璇锋眰浣�
+ HttpEntity<MultiValueMap<String, Object>> requestEntity = new HttpEntity<>(multipartRequestData, headers);
+
+ String fileRestUrl = rvo.fileSysRestUrl ;
+ if(!fileRestUrl.endsWith("/") && !fileRestUrl.endsWith("\\\\")){
+ fileRestUrl += "/" ;
+ }
+ fileRestUrl += (fileCtrlRqMp + "/" + fileMethodMp) ;
+
+ // 鍙戦�丳OST璇锋眰
+ return restTemplate.postForObject(fileRestUrl, requestEntity, Object.class).toString();
+ }
+
+ /**
+ * 瑙f瀽鏂囦欢鍚嶇О
+ * @param fmUrl
+ * @param filePath
+ * @return
+ */
+ public FileRestVo parse(String fmUrl, String filePath){
+ // 鍑嗗璇锋眰鏁版嵁
+ MultiValueMap<String, Object> multipartRequestData = new LinkedMultiValueMap<>();
+ multipartRequestData.add(FileConstant.fmPostMapping_parsePath_paramName, filePath);
+
+ // 璁剧疆璇锋眰澶撮儴锛岃繖閲屽亣璁炬湇鍔″櫒鎺ユ敹multipart/form-data绫诲瀷鐨勬暟鎹�
+ HttpHeaders headers = new HttpHeaders();
+ headers.setContentType(MediaType.MULTIPART_FORM_DATA);
+
+ // 灏佽璇锋眰浣�
+ HttpEntity<MultiValueMap<String, Object>> requestEntity = new HttpEntity<>(multipartRequestData, headers);
+
+ String webUrl = fmUrl + "/" + FileConstant.fmRequestMapping + "/" + FileConstant.fmPostMapping_parsePath;
+ // 鍙戦�丳OST璇锋眰
+ FileRestVo rvo = restTemplate.postForObject(webUrl, requestEntity, FileRestVo.class);
+
+ return rvo ;
+ }
+
+
+ /**
+ * 瑙f瀽鏂囦欢鍚嶇О
+ * @param fmUrl
+ * @param filePaths
+ * @return
+ */
+ public List<FileRestVo> parse(String fmUrl, List<String> filePaths) throws Exception{
+ List<FileRestVo> rList = null ;
+ if(filePaths != null && filePaths.size() > 0) {
+ MultiValueMap<String, Object> multipartRequestData = new LinkedMultiValueMap<>();
+ multipartRequestData.add(FileConstant.fmPostMapping_parsePathList_paramName, filePaths);
+
+ // 璁剧疆璇锋眰澶撮儴锛岃繖閲屽亣璁炬湇鍔″櫒鎺ユ敹multipart/form-data绫诲瀷鐨勬暟鎹�
+ HttpHeaders headers = new HttpHeaders();
+ headers.setContentType(MediaType.MULTIPART_FORM_DATA);
+
+ // 灏佽璇锋眰浣�
+ HttpEntity<MultiValueMap<String, Object>> requestEntity = new HttpEntity<>(multipartRequestData, headers);
+
+ String webUrl = fmUrl + "/" + FileConstant.fmRequestMapping + "/" + FileConstant.fmPostMapping_parsePathList;
+ // 鍙戦�丳OST璇锋眰
+ FileRestVo[] rvos = restTemplate.postForObject(webUrl, requestEntity, FileRestVo[].class);
+ rList = Arrays.asList(rvos) ;
+ }
+ return rList ;
+ }
+
+ /**
+ * 瑙f瀽鏂囦欢鍝堝笇鍊�
+ * @param fmUrl
+ * @param hashcode
+ * @return
+ */
+ public FileRestVo parseHashcode(String fmUrl, Integer hashcode){
+ // 鍑嗗璇锋眰鏁版嵁
+ MultiValueMap<String, Object> multipartRequestData = new LinkedMultiValueMap<>();
+ multipartRequestData.add(FileConstant.fmPostMapping_parseHashcode_paramName, hashcode);
+
+ // 璁剧疆璇锋眰澶撮儴锛岃繖閲屽亣璁炬湇鍔″櫒鎺ユ敹multipart/form-data绫诲瀷鐨勬暟鎹�
+ HttpHeaders headers = new HttpHeaders();
+ headers.setContentType(MediaType.MULTIPART_FORM_DATA);
+
+ // 灏佽璇锋眰浣�
+ HttpEntity<MultiValueMap<String, Object>> requestEntity = new HttpEntity<>(multipartRequestData, headers);
+
+ String webUrl = fmUrl + "/" + FileConstant.fmRequestMapping + "/" + FileConstant.fmPostMapping_parseHashcode;
+ // 鍙戦�丳OST璇锋眰
+ FileRestVo rvo = restTemplate.postForObject(webUrl, requestEntity, FileRestVo.class);
+
+ return rvo ;
+ }
+
+ /**
+ * 瑙f瀽鏂囦欢鍝堝笇鍊�
+ * @param fmUrl
+ * @param hashCodes
+ * @return
+ */
+ public List<FileRestVo> parseHashcode(String fmUrl, List<Integer> hashCodes){
+ List<FileRestVo> rList = null ;
+ if(hashCodes != null && hashCodes.size() > 0) {
+ // 鍑嗗璇锋眰鏁版嵁
+ MultiValueMap<String, Object> multipartRequestData = new LinkedMultiValueMap<>();
+ multipartRequestData.add(FileConstant.fmPostMapping_parseHashcodeList_paramName, hashCodes);
+
+ // 璁剧疆璇锋眰澶撮儴锛岃繖閲屽亣璁炬湇鍔″櫒鎺ユ敹multipart/form-data绫诲瀷鐨勬暟鎹�
+ HttpHeaders headers = new HttpHeaders();
+ headers.setContentType(MediaType.MULTIPART_FORM_DATA);
+
+ // 灏佽璇锋眰浣�
+ HttpEntity<MultiValueMap<String, Object>> requestEntity = new HttpEntity<>(multipartRequestData, headers);
+
+ String webUrl = fmUrl + "/" + FileConstant.fmRequestMapping + "/" + FileConstant.fmPostMapping_parseHashcodeList;
+ // 鍙戦�丳OST璇锋眰
+ FileRestVo[] rvos = restTemplate.postForObject(webUrl, requestEntity, FileRestVo[].class);
+ rList = Arrays.asList(rvos) ;
+ }
+ return rList ;
+ }
+
+ /**
+ * 瑙f瀽鏂囦欢鏂囦欢璺緞涓殑鍝堝笇鍊煎苟杩斿洖鍥剧墖瀹屾暣璺緞
+ * @param fmUrl
+ * @param filePath
+ * @return
+ */
+ public String getFilePath(String fmUrl, String filePath){
+ FileRestVo rvo = null ;
+ if(filePath != null && !filePath.trim().equals("")){
+ String[] strs = filePath.split("\\?") ;
+ String hashValStr = strs[strs.length - 1] ;
+ if(hashValStr != null && !hashValStr.trim().equals("") && NumUtil.isPlusIntNumber(hashValStr)){
+ int hashVal = Integer.valueOf(hashValStr) ;
+ rvo = parseHashcode(fmUrl, hashVal) ;
+ }
+ }
+ if(rvo != null){
+ return rvo.getFileWebUrl() + filePath ;
+ }
+ return null ;
+ }
+
+}
--
Gitblit v1.8.0