From 1300e2434cb457e7d4d06ea66d90a04492f6c4e9 Mon Sep 17 00:00:00 2001 From: liurunyu <lry9898@163.com> Date: 星期二, 23 四月 2024 14:22:09 +0800 Subject: [PATCH] 1、完善系统架构,增加了分布式web文件模块 --- pms-parent/pms-web-file/src/main/java/com/dy/dyFile/files/FileCtrl.java | 196 ++++ pms-parent/pms-web-file/src/main/java/com/dy/dyFile/util/FileIconUtil.java | 38 pms-parent/pms-web-file/src/main/java/com/dy/dyFile/util/FileUtil.java | 122 ++ pms-parent/pms-web-file/src/main/java/com/dy/dyFile/util/FileDocumentUtil.java | 46 + pms-parent/pms-global/src/main/java/com/dy/pmsGlobal/dyFile/FileVo.java | 29 pms-parent/pms-global/src/main/resources/application-global.yml | 151 +++ pms-parent/pms-global/src/main/java/com/dy/pmsGlobal/pojoOth/OthFile.java | 50 + pms-parent/pms-web-file/src/main/java/com/dy/dyFile/util/FilePhotoUtil.java | 39 pms-parent/pom.xml | 2 pms-parent/pms-global/src/main/java/com/dy/pmsGlobal/global/WebFileCtrl.java | 200 ++++ pms-parent/pms-web-other/src/main/java/com/dy/pmsOther/dyFm/FileNameIdUtil.java | 112 ++ pms-parent/pms-web-other/src/main/java/com/dy/pmsOther/dyFm/RestHashDeal.java | 95 ++ pms-parent/pms-web-other/src/main/java/com/dy/pmsOther/dyFm/FileRestVo.java | 28 pms-parent/pms-global/src/main/java/com/dy/pmsGlobal/dyFile/FileOperate.java | 301 +++++++ pms-parent/pms-global/src/main/java/com/dy/pmsGlobal/dyFile/NameValue.java | 26 pms-parent/pms-web-other/src/main/java/com/dy/pmsOther/dyFm/FileName.java | 20 pms-parent/pms-web-other/src/main/java/com/dy/pmsOther/dyFm/DyFileSvConf.java | 159 +++ pms-parent/pms-common/src/main/java/com/dy/common/util/MurmurHash.java | 302 +++++++ pms-parent/pms-web-file/src/main/java/com/dy/dyFile/DyFileApplication.java | 8 pms-parent/pms-web-file/src/main/resources/application.yml | 2 pms-parent/pms-global/src/main/resources/mapper/OthFileMapper.xml | 111 ++ pms-parent/pms-web-other/src/main/java/com/dy/pmsOther/dyFm/FmCtrl.java | 133 +++ pms-parent/pms-global/src/main/java/com/dy/pmsGlobal/global/WebFileSv.java | 21 pms-parent/pms-web-file/src/main/java/com/dy/dyFile/util/FileConstant.java | 13 pms-parent/pms-web-file/src/main/java/com/dy/dyFile/util/ZipImg.java | 63 + pms-parent/pms-global/src/main/java/com/dy/pmsGlobal/dyFile/FileRestVo.java | 44 + pms-parent/pms-global/src/main/java/com/dy/pmsGlobal/daoOth/OthFileMapper.java | 19 pms-parent/pms-global/src/main/java/com/dy/pmsGlobal/dyFile/FileConstant.java | 31 pms-parent/pms-web-file/src/main/java/com/dy/dyFile/util/FileVideoUtil.java | 39 pms-parent/pms-web-file/pom.xml | 6 pms-parent/pms-web-base/src/main/java/com/dy/pmsBase/PmsBaseApplication.java | 2 pms-parent/pms-web-other/src/main/java/com/dy/pmsOther/dyFm/DyFmListener.java | 67 + pms-parent/pms-web-file/src/main/java/com/dy/dyFile/util/FilePhoneUtil.java | 41 pms-parent/pms-web-file/src/main/java/com/dy/dyFile/download/DownloadFileCtr.java | 18 34 files changed, 2,526 insertions(+), 8 deletions(-) diff --git a/pms-parent/pms-common/src/main/java/com/dy/common/util/MurmurHash.java b/pms-parent/pms-common/src/main/java/com/dy/common/util/MurmurHash.java new file mode 100644 index 0000000..822c87c --- /dev/null +++ b/pms-parent/pms-common/src/main/java/com/dy/common/util/MurmurHash.java @@ -0,0 +1,302 @@ +package com.dy.common.util; + +/** + * MurmurHash绠楁硶锛氶珮杩愮畻鎬ц兘锛屼綆纰版挒鐜囷紝鐢盇ustin Appleby鍒涘缓浜�2008骞达紝 + * 鐜板凡搴旂敤鍒癏adoop銆乴ibstdc++銆乶ginx銆乴ibmemcached绛夊紑婧愮郴缁熴��2011骞� + * Appleby琚獹oogle闆囦剑锛岄殢鍚嶨oogle鎺ㄥ嚭鍏跺彉绉嶇殑CityHash绠楁硶銆� + * + * 瀹樻柟缃戠珯锛歨ttps://sites.google.com/site/murmurhash/ + * + * MurmurHash绠楁硶锛岃嚜绉拌秴绾у揩鐨刪ash绠楁硶锛屾槸FNV鐨�4-5鍊嶃�傚畼鏂规暟鎹涓嬶細 + * + * OneAtATime 鈥� 354.163715 mb/sec + * FNV 鈥� 443.668038 mb/sec + * SuperFastHash 鈥� 985.335173 mb/sec + * lookup3 鈥� 988.080652 mb/sec + * MurmurHash 1.0 鈥� 1363.293480 mb/sec + * MurmurHash 2.0 鈥� 2056.885653 mb/sec + * + * 浣嗕篃鏈夋枃绔犲0绉帮紝鍙湁褰搆ey鐨勯暱搴﹀ぇ浜�10瀛楄妭鐨勬椂鍊欙紝MurmurHash鐨勮繍绠楅�� + * 搴︽墠蹇簬DJB銆備粠璁$畻閫熷害涓婃潵鐪嬶紝MurmurHash鍙�傜敤浜庡凡鐭ラ暱搴︾殑銆侀暱搴︽瘮 + * 杈冮暱鐨勫瓧绗︺�� + * + * 鍝堝笇鍊煎垎甯冮潪甯稿潎鍖�锛屽嵆浣庣鎾炵巼 + * 姣擟rc16鏇翠负鍧囧寑 + */ +public final class MurmurHash { + + private byte[] toBytesWithoutEncoding(String str) { + int len = str.length(); + int pos = 0; + byte[] buf = new byte[len << 1]; + for (int i = 0; i < len; i++) { + char c = str.charAt(i); + buf[pos++] = (byte) (c & 0xFF); + buf[pos++] = (byte) (c >> 8); + } + return buf; + } + + /** + * 鍒樻鼎鐜夊鍔犳柟娉曚簬2016-12-02 + * @param data + * @param length + * @return + */ + public int hash16_plus(final byte[] data, int length) { + int hash = hash32(data, length, 0x9747b28c); + hash = hash % 65535 ; + if(hash < 0){ + hash = - hash ; + } + return hash ; + } + /** + * 鍒樻鼎鐜夊鍔犳柟娉曚簬2016-12-02 + * @param data + * @return + */ + public int hash16_plus(final String data) { + byte[] bytes = toBytesWithoutEncoding(data); + int hash = hash32(bytes, bytes.length, 0x9747b28c); + hash = hash % 65535 ; + if(hash < 0){ + hash = - hash ; + } + return hash ; + } + + /** + * Generates 32 bit hash from byte array with default seed value. + * @param data byte array to hash + * @param length length of the array to hash + * @return 32 bit hash of the given array + */ + public int hash32(final byte[] data, int length) { + return hash32(data, length, 0x9747b28c); + } + + public int hash32(final String data) { + byte[] bytes = toBytesWithoutEncoding(data); + return hash32(bytes, bytes.length, 0x9747b28c); + } + + /** + * Generates 64 bit hash from byte array with default seed value. + * @param data byte array to hash + * @param length length of the array to hash + * @return 64 bit hash of the given string + */ + public long hash64(final byte[] data, int length) { + return hash64(data, length, 0xe17a1465); + } + + + public long hash64(final String data) { + byte[] bytes = toBytesWithoutEncoding(data); + return hash64(bytes, bytes.length); + } + /** + * Generates 32 bit hash from byte array of the given length and seed. + * @param data byte array to hash + * @param length length of the array + * @param seed initial seed value + * @return 32 bit hash of the given array + */ + public int hash32(final byte[] data, int length, int seed) { + // 'm' and 'r' are mixing constants generated offline. + // They're not really 'magic', they just happen to work well. + final int m = 0x5bd1e995; + final int r = 24; + // Initialize the hash to a random value + int h = seed ^ length; + int length4 = length / 4; + for (int i = 0; i < length4; i++) { + final int i4 = i * 4; + int k = (data[i4 + 0] & 0xff) + ((data[i4 + 1] & 0xff) << 8) + + ((data[i4 + 2] & 0xff) << 16) + + ((data[i4 + 3] & 0xff) << 24); + k *= m; + k ^= k >>> r; + k *= m; + h *= m; + h ^= k; + } + // Handle the last few bytes of the input array + switch (length % 4) { + case 3: + h ^= (data[(length & ~3) + 2] & 0xff) << 16; + case 2: + h ^= (data[(length & ~3) + 1] & 0xff) << 8; + case 1: + h ^= (data[length & ~3] & 0xff); + h *= m; + } + h ^= h >>> 13; + h *= m; + h ^= h >>> 15; + return h; + } + /** + * Generates 64 bit hash from byte array of the given length and seed. + * @param data byte array to hash + * @param length length of the array to hash + * @param seed initial seed value + * @return 64 bit hash of the given array + */ + public long hash64(final byte[] data, int length, int seed) { + final long m = 0xc6a4a7935bd1e995L; + final int r = 47; + long h = (seed & 0xffffffffl) ^ (length * m); + int length8 = length / 8; + for (int i = 0; i < length8; i++) { + final int i8 = i * 8; + long k = ((long) data[i8 + 0] & 0xff) + + (((long) data[i8 + 1] & 0xff) << 8) + + (((long) data[i8 + 2] & 0xff) << 16) + + (((long) data[i8 + 3] & 0xff) << 24) + + (((long) data[i8 + 4] & 0xff) << 32) + + (((long) data[i8 + 5] & 0xff) << 40) + + (((long) data[i8 + 6] & 0xff) << 48) + + (((long) data[i8 + 7] & 0xff) << 56); + k *= m; + k ^= k >>> r; + k *= m; + h ^= k; + h *= m; + } + switch (length % 8) { + case 7: + h ^= (long) (data[(length & ~7) + 6] & 0xff) << 48; + case 6: + h ^= (long) (data[(length & ~7) + 5] & 0xff) << 40; + case 5: + h ^= (long) (data[(length & ~7) + 4] & 0xff) << 32; + case 4: + h ^= (long) (data[(length & ~7) + 3] & 0xff) << 24; + case 3: + h ^= (long) (data[(length & ~7) + 2] & 0xff) << 16; + case 2: + h ^= (long) (data[(length & ~7) + 1] & 0xff) << 8; + case 1: + h ^= (long) (data[length & ~7] & 0xff); + h *= m; + } + ; + h ^= h >>> r; + h *= m; + h ^= h >>> r; + return h; + } + public static void main(String[] args) { + test1() ; + test2() ; + } + + public static void test1() { + String regionNum = "110000" ; + String temp = "" ; + String rtuAddr = "" ; + + int total0 = 0 ; + int total1 = 0 ; + int total2 = 0 ; + int total3 = 0 ; + int total4 = 0 ; + int total5 = 0 ; + int totalx = 0 ; + int totaly = 0 ; + MurmurHash mhash = new MurmurHash() ; + Long start = System.currentTimeMillis() ; + for(int i = 0 ; i < 10000; i++){ + temp = "" + i ; + while(temp.length() < 5){ + temp = "0" + temp ; + } + rtuAddr = regionNum + temp ; + int hash = mhash.hash16_plus(rtuAddr) ; + if(hash < 0){ + total0++ ; + } + if(hash >= 0 && hash < 1000){ + total1++ ; + } + if(hash >= 1000 && hash < 2000){ + total2++ ; + } + if(hash >= 2000 && hash < 3000){ + total3++ ; + } + if(hash >= 3000 && hash < 4000){ + total4++ ; + } + if(hash >= 4000 && hash < 5000){ + total5++ ; + } + if(hash >= 64535 && hash < 65535){ + totalx++ ; + } + if(hash > 65535){ + totaly++ ; + } + //System.out.println(rtuAddr + "-" + crc); + } + Long end = System.currentTimeMillis() ; + System.out.println("鐢ㄦ椂" + ":" + (end - start)); + System.out.println("0浠ヤ笅" + ":" + total0); + System.out.println("0-1000" + ":" + total1); + System.out.println("1000-2000" + ":" + total2); + System.out.println("2000-3000" + ":" + total3); + System.out.println("3000-4000" + ":" + total4); + System.out.println("5000-6000" + ":" + total5); + System.out.println("64535-65535" + ":" + totalx); + System.out.println("65535浠ヤ笂" + ":" + totaly); + System.out.println("================="); + } + public static void test2() { + String regionNum = "110000" ; + String temp = "" ; + String rtuAddr = "" ; + + int total1 = 0 ; + int total2 = 0 ; + int total3 = 0 ; + int total4 = 0 ; + int total5 = 0 ; + MurmurHash mhash = new MurmurHash() ; + Long start = System.currentTimeMillis() ; + for(int i = 0 ; i < 10000; i++){ + temp = "" ; + temp = "" + i ; + while(temp.length() < 5){ + temp = "0" + temp ; + } + rtuAddr = regionNum + temp ; + int hash = mhash.hash32(rtuAddr) ; + if(hash > 0 && hash < 10000000){ + total1++ ; + } + if(hash >= 10000000 && hash < 20000000){ + total2++ ; + } + if(hash >= 20000000 && hash < 30000000){ + total3++ ; + } + if(hash >= 30000000 && hash < 40000000){ + total4++ ; + } + if(hash >= 40000000 && hash < 50000000){ + total5++ ; + } + //System.out.println(rtuAddr + "-" + crc); + } + Long end = System.currentTimeMillis() ; + System.out.println("鐢ㄦ椂" + ":" + (end - start)); + System.out.println("0-10000000" + ":" + total1); + System.out.println("10000000-20000000" + ":" + total2); + System.out.println("20000000-30000000" + ":" + total3); + System.out.println("30000000-40000000" + ":" + total4); + System.out.println("50000000-60000000" + ":" + total5); + System.out.println("================="); + } +} diff --git a/pms-parent/pms-global/src/main/java/com/dy/pmsGlobal/daoOth/OthFileMapper.java b/pms-parent/pms-global/src/main/java/com/dy/pmsGlobal/daoOth/OthFileMapper.java new file mode 100644 index 0000000..3fbe311 --- /dev/null +++ b/pms-parent/pms-global/src/main/java/com/dy/pmsGlobal/daoOth/OthFileMapper.java @@ -0,0 +1,19 @@ +package com.dy.pmsGlobal.daoOth; + +import com.dy.pmsGlobal.pojoOth.OthFile; +import org.apache.ibatis.annotations.Mapper; + +@Mapper +public interface OthFileMapper { + OthFile selectByPrimaryKey(Long id); + + int insert(OthFile record); + + int insertSelective(OthFile record); + + int updateByPrimaryKeySelective(OthFile record); + + int updateByPrimaryKey(OthFile record); + + int deleteByPrimaryKey(Long id); +} \ No newline at end of file diff --git a/pms-parent/pms-global/src/main/java/com/dy/pmsGlobal/dyFile/FileConstant.java b/pms-parent/pms-global/src/main/java/com/dy/pmsGlobal/dyFile/FileConstant.java new file mode 100644 index 0000000..a19ba04 --- /dev/null +++ b/pms-parent/pms-global/src/main/java/com/dy/pmsGlobal/dyFile/FileConstant.java @@ -0,0 +1,31 @@ +package com.dy.pmsGlobal.dyFile; + +public class FileConstant { + public static final String NotRegionNum = "-1"; //鍦╳eb鏂囦欢绯荤粺dyFile涓紝濡傛灉琛屾斂鍖哄垝鏄�"-1"锛屽垯璁や负涓嶅瓨鍦ㄨ鏀垮尯鍒掑睘鎬� + + public static final String fmRequestMapping = "fm" ;//controller 璺緞 + public static final String fmPostMapping_create = "create" ;//鏂规硶璺緞 + public static final String fmPostMapping_create_paramName = "fileExtName" ;//鍙傛暟鍚嶇О + public static final String fmPostMapping_parsePath = "parsePath" ;//鏂规硶璺緞 + public static final String fmPostMapping_parsePath_paramName = "filePath" ;//鍙傛暟鍚嶇О + public static final String fmPostMapping_parsePathList = "parsePathList" ;//鏂规硶璺緞 + public static final String fmPostMapping_parsePathList_paramName = "filePaths" ;//鍙傛暟鍚嶇О + public static final String fmPostMapping_parseHashcode = "parseHashcode" ;//鏂规硶璺緞 + public static final String fmPostMapping_parseHashcode_paramName = "hashCode" ;//鍙傛暟鍚嶇О + + public static final String fileRequestMapping = "file" ;//controller 璺緞 + public static final String filePostMapping_photo = "savePhoto" ;//鏂规硶璺緞 + public static final String filePostMapping_phone = "savePhone" ;//涓婁紶璇煶鎺ュ彛璺緞 + public static final String filePostMapping_video = "saveVideo" ;//涓婁紶褰曞儚鎺ュ彛璺緞 + public static final String filePostMapping_document = "saveDocument" ;//涓婁紶鏂囨。鎺ュ彛璺緞 + + public static final String filePostMapping_paramName_file = "file" ;//鍙傛暟鍚嶇О + public static final String filePostMapping_paramName_regionNum = "regionNum" ;//鍙傛暟鍚嶇О + public static final String filePostMapping_paramName_json = "json" ;//鍙傛暟鍚嶇О + public static final String filePostMapping_paramName_absolutePath = "absolutePath" ;//鍙傛暟鍚嶇О + public static final String filePostMapping_paramName_relativePath = "relativePath" ;//鍙傛暟鍚嶇О + public static final String filePostMapping_paramName_fileName = "fileName" ;//鍙傛暟鍚嶇О + + public static final String fileRestDownloadUrl = "DownloadFile!download.action?" ;//涓嬭浇鏂囦欢action璺緞 + +} diff --git a/pms-parent/pms-global/src/main/java/com/dy/pmsGlobal/dyFile/FileOperate.java b/pms-parent/pms-global/src/main/java/com/dy/pmsGlobal/dyFile/FileOperate.java new file mode 100644 index 0000000..c9774c6 --- /dev/null +++ b/pms-parent/pms-global/src/main/java/com/dy/pmsGlobal/dyFile/FileOperate.java @@ -0,0 +1,301 @@ +package com.dy.pmsGlobal.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 imgPath + * @return + */ + public String getImgFileZipPath(String imgPath){ + String path_ = null ; + String prePath = null ; + String tailPath = null ; + if(imgPath != null && !imgPath.trim().equals("")) { + int lastDotIndex = imgPath.lastIndexOf('.'); + if (lastDotIndex >= 0) { + prePath = imgPath.substring(0, lastDotIndex); + tailPath = imgPath.substring(lastDotIndex); + path_ = prePath + "_" + tailPath ; + } + } + if(path_ == null){ + path_ = imgPath ; + } + 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); + //log.info("瀛樺偍鏂囦欢鐢熸垚鏂囦欢璺緞锛�" + 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 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 ; + } + +} diff --git a/pms-parent/pms-global/src/main/java/com/dy/pmsGlobal/dyFile/FileRestVo.java b/pms-parent/pms-global/src/main/java/com/dy/pmsGlobal/dyFile/FileRestVo.java new file mode 100644 index 0000000..f25b474 --- /dev/null +++ b/pms-parent/pms-global/src/main/java/com/dy/pmsGlobal/dyFile/FileRestVo.java @@ -0,0 +1,44 @@ +package com.dy.pmsGlobal.dyFile; + +import lombok.Data; + +@Data +public class FileRestVo { + + + public String fileName ; //鐢熸垚鐨勬枃浠跺悕绉帮紝渚嬪20170818153254_100000007.jpg + public Integer fileNameHash ; //鏂囦欢鍚嶇О鐨勫搱甯屽�� + public String fileSysId; //鏂囦欢鍚嶇О鐨勫搱甯屽�煎搴旂殑鏂囦欢绯荤粺鐨刬d锛屽湪閰嶇疆鏂囦欢涓厤缃� + public String fileSysAbsolutePath; //鏂囦欢鍚嶇О鐨勫搱甯屽�煎搴旂殑鏂囦欢鏈�缁堝瓨鍌ㄧ粷瀵硅矾寰勪腑鐨勬牴鐩綍锛屽湪閰嶇疆鏂囦欢涓厤缃� + public String fileSysRelativePath; //鏂囦欢鍚嶇О鐨勫搱甯屽�煎搴旂殑鏂囦欢鏈�缁堝瓨鍌ㄧ浉瀵硅矾寰勭殑鐩綍锛屽湪閰嶇疆鏂囦欢涓厤缃� + public String fileSysRestUrl; //鏂囦欢鍚嶇О鐨勫搱甯屽�煎搴旂殑鏂囦欢绯荤粺鐨剅estful URL锛屽湪閰嶇疆鏂囦欢涓厤缃� + public String fileWebPath; //鏂囦欢鍚嶇О鐨勫搱甯屽�煎搴旂殑鏂囦欢绯荤粺鐨勪笅杞芥枃浠剁殑web path锛屽姩鎬佺敓鎴� + public String fileWebUrl; //鏂囦欢鍚嶇О鐨勫搱甯屽�煎搴旂殑鏂囦欢绯荤粺鐨勪笅杞芥枃浠剁殑web URL锛屽湪閰嶇疆鏂囦欢涓厤缃� + public String fileWebDownloadUrl; //鏂囦欢鍚嶇О鐨勫搱甯屽�煎搴旂殑鏂囦欢绯荤粺鐨凙ction涓嬭浇鏂囦欢鐨剋eb URL锛屽湪閰嶇疆鏂囦欢涓厤缃� + + public String toString(){ + return "fileName=" + fileName + "\n" + + "fileNameHash=" + fileNameHash + "\n" + + "fileSysId=" + fileSysId + "\n" + + "fileSysAbsolutePath=" + fileSysAbsolutePath + "\n" + + "fileSysRelativePath=" + fileSysRelativePath + "\n" + + "fileSysRestUrl=" + fileSysRestUrl + "\n" + + "fileWebPath=" + fileWebPath + "\n" + + "fileWebUrl=" + fileWebUrl + "\n" + + "fileWebDownloadUrl=" + fileWebDownloadUrl; + } + + /** + * 閲嶆柊鍒涘缓fileSysWebUrl + * @param relativeFilePath + * @param hashcode + */ + public void createFilePath(String relativeFilePath, Integer hashcode){ + if(relativeFilePath != null){ + if(relativeFilePath.indexOf("?") < 0){ + this.fileWebPath = relativeFilePath + "?" + hashcode; + } + } + } + +} diff --git a/pms-parent/pms-global/src/main/java/com/dy/pmsGlobal/dyFile/FileVo.java b/pms-parent/pms-global/src/main/java/com/dy/pmsGlobal/dyFile/FileVo.java new file mode 100644 index 0000000..45fcf4d --- /dev/null +++ b/pms-parent/pms-global/src/main/java/com/dy/pmsGlobal/dyFile/FileVo.java @@ -0,0 +1,29 @@ +package com.dy.pmsGlobal.dyFile; + +import lombok.Data; + +@Data +public class FileVo { + public Long id ; //鏁版嵁搴撳疄浣撲富閿� + public Integer hash ;//鏂囦欢鍚峢ash + public String orgName ;//鏂囦欢鍘熷悕 + public String extName ;//鏂囦欢鎵╁睍鍚� + public String webPath ;//web鏂囦欢璁块棶璺緞 + public String webPathZip;//鐓х墖鏂囦欢缂╃暐鍥捐闂矾寰勶紝鍏朵粬绫诲瀷鏂囦欢姝ゅ睘鎬т负null + + public FileVo(){} + + public FileVo(Long id, + Integer hash, + String orgName, + String extName, + String webPath, + String webPathZip){ + this.id = id ; + this.hash = hash ; + this.orgName = orgName ; + this.extName = extName ; + this.webPath = webPath ; + this.webPathZip = webPathZip ; + } +} diff --git a/pms-parent/pms-global/src/main/java/com/dy/pmsGlobal/dyFile/NameValue.java b/pms-parent/pms-global/src/main/java/com/dy/pmsGlobal/dyFile/NameValue.java new file mode 100644 index 0000000..d4d674b --- /dev/null +++ b/pms-parent/pms-global/src/main/java/com/dy/pmsGlobal/dyFile/NameValue.java @@ -0,0 +1,26 @@ +package com.dy.pmsGlobal.dyFile; + +public class NameValue { + + public String name ; + public String value ; + public NameValue(){ + } + public NameValue(String name, String value){ + this.name = name ; + this.value = value ; + } + + public String getName() { + return name; + } + public void setName(String name) { + this.name = name; + } + public String getValue() { + return value; + } + public void setValue(String value) { + this.value = value; + } +} diff --git a/pms-parent/pms-global/src/main/java/com/dy/pmsGlobal/global/WebFileCtrl.java b/pms-parent/pms-global/src/main/java/com/dy/pmsGlobal/global/WebFileCtrl.java new file mode 100644 index 0000000..7472b24 --- /dev/null +++ b/pms-parent/pms-global/src/main/java/com/dy/pmsGlobal/global/WebFileCtrl.java @@ -0,0 +1,200 @@ +package com.dy.pmsGlobal.global; + + +import com.dy.common.aop.SsoPowerAop; +import com.dy.common.webUtil.BaseResponse; +import com.dy.common.webUtil.BaseResponseUtils; +import com.dy.pmsGlobal.dyFile.FileConstant; +import com.dy.pmsGlobal.dyFile.FileOperate; +import com.dy.pmsGlobal.dyFile.FileRestVo; +import com.dy.pmsGlobal.dyFile.FileVo; +import com.dy.pmsGlobal.pojoOth.OthFile; +import jakarta.servlet.http.HttpServletRequest; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.multipart.MultipartFile; + +/** + * web鏂囦欢涓婁紶绀轰緥 + */ +@Slf4j +@RestController +@RequestMapping(path="webFile") +@SuppressWarnings("unchecked")//java鐗堟湰瓒婇珮锛屽娉涘瀷绾︽潫瓒婁弗锛屾墍浠ラ厤缃甋uppressWarnings("unchecked" +public class WebFileCtrl { + + @Autowired + private FileOperate fileOp ; + + @Autowired + private WebFileSv sv ; + + @Value("${dy.webFile.fmUrl}") + private String fmUrl ; + + @PostMapping("/upPhoto") + @SsoPowerAop(power = "-1") //鐧诲綍涓庢潈闄愬悓鏃堕獙璇� + //https://blog.zhengru.top/posts/33486.html#%E5%8D%95%E6%96%87%E4%BB%B6%E4%B8%8A%E4%BC%A0 + public BaseResponse<?> upPhoto(MultipartFile file, HttpServletRequest req) { + try { + if (file != null) { + String[] fileNameGrp = fileOp.splitFileName(file) ; + if(fileNameGrp != null && fileNameGrp[0] != null && fileNameGrp[1] != null){ + if(!fileNameGrp[1].trim().equals("")){ + FileRestVo frVo = fileOp.saveFile(file, + fmUrl, + FileConstant.fileRequestMapping, + FileConstant.filePostMapping_photo, + FileConstant.NotRegionNum, + fileNameGrp[1], + null); + String fileMainName = fileOp.getFileMainName(frVo.fileName) ; + Long id = this.saveFileInfo(fileNameGrp[0], fileNameGrp[1], fileMainName, frVo.fileNameHash, frVo.fileWebPath); + FileVo fvo = new FileVo(id, frVo.fileNameHash, fileNameGrp[0], fileNameGrp[1], (frVo.getFileWebUrl() + frVo.getFileWebPath()), fileOp.getImgFileZipPath(frVo.getFileWebUrl() + frVo.getFileWebPath())) ; + return BaseResponseUtils.buildSuccess(fvo) ; + }else { + return BaseResponseUtils.buildError("鏈緱鍒颁笂浼犳枃浠剁殑鎵╁睍鍚�"); + } + }else { + return BaseResponseUtils.buildError("鏈兘鎷嗗垎涓婁紶鏂囦欢鍚嶇О"); + } + } else { + return BaseResponseUtils.buildError("鏈笂浼犳枃浠�"); + } + } catch (Exception e) { + log.error("涓婁紶鐓х墖鏂囦欢寮傚父", e); + return BaseResponseUtils.buildException(e.getMessage()); + } + } + + @PostMapping("/upPhone") + @SsoPowerAop(power = "-1") + public BaseResponse<?> upPhone(MultipartFile file, HttpServletRequest req) { + try { + if (file != null) { + String[] fileNameGrp = fileOp.splitFileName(file) ; + if(fileNameGrp != null && fileNameGrp[0] != null && fileNameGrp[1] != null){ + if(!fileNameGrp[1].trim().equals("")){ + FileRestVo frVo = fileOp.saveFile(file, + fmUrl, + FileConstant.fileRequestMapping, + FileConstant.filePostMapping_phone, + FileConstant.NotRegionNum, + fileNameGrp[1], + null); + String fileMainName = fileOp.getFileMainName(frVo.fileName) ; + Long id = this.saveFileInfo(fileNameGrp[0], fileNameGrp[1], fileMainName, frVo.fileNameHash, frVo.fileWebPath); + FileVo fvo = new FileVo(id, frVo.fileNameHash, fileNameGrp[0], fileNameGrp[1],frVo.getFileWebUrl() + frVo.getFileWebPath(), null) ; + return BaseResponseUtils.buildSuccess(fvo) ; + }else { + return BaseResponseUtils.buildError("鏈緱鍒颁笂浼犳枃浠剁殑鎵╁睍鍚�"); + } + }else { + return BaseResponseUtils.buildError("鏈兘鎷嗗垎涓婁紶鏂囦欢鍚嶇О"); + } + } else { + return BaseResponseUtils.buildError("鏈笂浼犳枃浠�"); + } + } catch (Exception e) { + log.error("涓婁紶鐓х墖鏂囦欢寮傚父", e); + return BaseResponseUtils.buildException(e.getMessage()); + } + } + + + + @PostMapping("/upVideo") + @SsoPowerAop(power = "-1") + public BaseResponse<?> upVideo(MultipartFile file, HttpServletRequest req) { + try { + if (file != null) { + String[] fileNameGrp = fileOp.splitFileName(file) ; + if(fileNameGrp != null && fileNameGrp[0] != null && fileNameGrp[1] != null){ + if(!fileNameGrp[1].trim().equals("")){ + FileRestVo frVo = fileOp.saveFile(file, + fmUrl, + FileConstant.fileRequestMapping, + FileConstant.filePostMapping_video, + FileConstant.NotRegionNum, + fileNameGrp[1], + null); + String fileMainName = fileOp.getFileMainName(frVo.fileName) ; + Long id = this.saveFileInfo(fileNameGrp[0], fileNameGrp[1], fileMainName, frVo.fileNameHash, frVo.fileWebPath); + FileVo fvo = new FileVo(id, frVo.fileNameHash, fileNameGrp[0], fileNameGrp[1],frVo.getFileWebUrl() + frVo.getFileWebPath(), null) ; + return BaseResponseUtils.buildSuccess(fvo) ; + }else { + return BaseResponseUtils.buildError("鏈緱鍒颁笂浼犳枃浠剁殑鎵╁睍鍚�"); + } + }else { + return BaseResponseUtils.buildError("鏈兘鎷嗗垎涓婁紶鏂囦欢鍚嶇О"); + } + } else { + return BaseResponseUtils.buildError("鏈笂浼犳枃浠�"); + } + } catch (Exception e) { + log.error("涓婁紶鐓х墖鏂囦欢寮傚父", e); + return BaseResponseUtils.buildException(e.getMessage()); + } + } + + + + @PostMapping("/upDocument") + @SsoPowerAop(power = "-1") + public BaseResponse<?> upDocument(MultipartFile file, HttpServletRequest req) { + try { + if (file != null) { + String[] fileNameGrp = fileOp.splitFileName(file) ; + if(fileNameGrp != null && fileNameGrp[0] != null && fileNameGrp[1] != null){ + if(!fileNameGrp[1].trim().equals("")){ + FileRestVo frVo = fileOp.saveFile(file, + fmUrl, + FileConstant.fileRequestMapping, + FileConstant.filePostMapping_document, + FileConstant.NotRegionNum, + fileNameGrp[1], + null); + String fileMainName = fileOp.getFileMainName(frVo.fileName) ; + Long id = this.saveFileInfo(fileNameGrp[0], fileNameGrp[1], fileMainName, frVo.fileNameHash, frVo.fileWebPath); + FileVo fvo = new FileVo(id, frVo.fileNameHash, fileNameGrp[0], fileNameGrp[1],frVo.getFileWebUrl() + frVo.getFileWebPath(), null) ; + return BaseResponseUtils.buildSuccess(fvo) ; + }else { + return BaseResponseUtils.buildError("鏈緱鍒颁笂浼犳枃浠剁殑鎵╁睍鍚�"); + } + }else { + return BaseResponseUtils.buildError("鏈兘鎷嗗垎涓婁紶鏂囦欢鍚嶇О"); + } + } else { + return BaseResponseUtils.buildError("鏈笂浼犳枃浠�"); + } + } catch (Exception e) { + log.error("涓婁紶鐓х墖鏂囦欢寮傚父", e); + return BaseResponseUtils.buildException(e.getMessage()); + } + } + + + /** + * 鏁版嵁搴撳瓨鍌� + * @param orgName 鏂囦欢鍘熷悕绉� + * @param extName 鏂囦欢鎵╁睍鍚� + * @param newName 鏂囦欢鏂板悕绉� + * @param hash 鏂囦欢鏂板悕绉扮殑鍝堝笇鍊� + * @param filePath 鏂囦欢鏈嶅姟绔瓨鍌ㄧ浉瀵硅矾寰� + * @return + */ + private Long saveFileInfo(String orgName, String extName, String newName, Integer hash, String filePath){ + OthFile po = new OthFile() ; + po.orgName = orgName ; + po.extName = extName ; + po.newName = newName ; + po.hash = hash ; + po.filePath = filePath ; + return this.sv.save(po) ; + } + +} diff --git a/pms-parent/pms-global/src/main/java/com/dy/pmsGlobal/global/WebFileSv.java b/pms-parent/pms-global/src/main/java/com/dy/pmsGlobal/global/WebFileSv.java new file mode 100644 index 0000000..0c8d92b --- /dev/null +++ b/pms-parent/pms-global/src/main/java/com/dy/pmsGlobal/global/WebFileSv.java @@ -0,0 +1,21 @@ +package com.dy.pmsGlobal.global; + +import com.dy.pmsGlobal.daoOth.OthFileMapper; +import com.dy.pmsGlobal.pojoOth.OthFile; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +@Slf4j +@Service +public class WebFileSv { + @Autowired + private OthFileMapper dao; + + @Transactional + public Long save(OthFile po){ + this.dao.insertSelective(po) ; + return po.id ; + } +} diff --git a/pms-parent/pms-global/src/main/java/com/dy/pmsGlobal/pojoOth/OthFile.java b/pms-parent/pms-global/src/main/java/com/dy/pmsGlobal/pojoOth/OthFile.java new file mode 100644 index 0000000..8bc69f8 --- /dev/null +++ b/pms-parent/pms-global/src/main/java/com/dy/pmsGlobal/pojoOth/OthFile.java @@ -0,0 +1,50 @@ +package com.dy.pmsGlobal.pojoOth; + +import com.baomidou.mybatisplus.annotation.TableName; +import com.dy.common.po.BaseEntity; +import lombok.*; + +/** + * 涓婅浇鐨勬枃浠朵俊鎭� + */ +//2024-04-12涓嬮潰TableName涓嶇敤閰嶇疆琛ㄥ悕绉帮紙value="BaUser"鎴栤�渂a_user鈥濓級 +//鍙閫氳繃椹煎嘲鍛藉悕娉曞垯绫诲悕涓庤〃鍚嶅搴旇捣鏉ュ氨鍙互浜嗭紝濡傛灉涓嶈兘瀵瑰簲璧锋潵锛岄渶瑕佹寚瀹氳〃鍚嶇О +//渚嬪@TableName(value="TestUser" autoResultMap = true) +@TableName(value="ba_role", autoResultMap = true) +@Data +@Builder +@ToString +@NoArgsConstructor +@AllArgsConstructor +public class OthFile implements BaseEntity { + /** + * 涓婚敭 + */ + public Long id; + + /** + * 鏂囦欢鍘熷悕绉� + */ + public String orgName; + + /** + * 鎵╁睍鍚� + */ + public String extName; + + /** + * 涓婁紶鏂囦欢鍚庣郴缁熻嚜鍔ㄧ粰鏂囦欢璧嬬殑鏂板悕绉� + */ + public String newName; + + /** + * 鏂囦欢hash鍊� + */ + public Integer hash; + + /** + * 鏂囦欢鍦ㄦ湇鍔$瀛樺偍鐨勭浉瀵硅矾寰� + */ + public String filePath; + +} \ No newline at end of file diff --git a/pms-parent/pms-global/src/main/resources/application-global.yml b/pms-parent/pms-global/src/main/resources/application-global.yml index 8c25880..bf9e58b 100644 --- a/pms-parent/pms-global/src/main/resources/application-global.yml +++ b/pms-parent/pms-global/src/main/resources/application-global.yml @@ -1,3 +1,9 @@ +spring: + servlet: + multipart: + # 鍓嶇涓婁紶鏂囦欢锛岄檺鍒跺崟涓枃浠剁殑澶у皬鍜岄檺鍒舵墍鏈夋枃浠剁殑澶у皬 + max-file-size: 1MB + max-request-size: 10MB logging: charset: console: UTF-8 @@ -36,12 +42,15 @@ lazy-load-trigger-methods: "" # 闃绘尅涓嶇浉骞茬殑鎿嶄綔瑙﹀彂锛屽疄鐜版噿鍔犺浇 cache-enabled: true #鎵撳紑鍏ㄥ眬缂撳瓨寮�鍏筹紙浜岀骇鐜锛夛紝榛樿鍊兼槸true #default-enum-type-handler: com.dy.common.mybatis.envm.EnumCodeTypeHandler + pms: global: dev: true #鏄惁寮�鍙戦樁娈碉紝true鎴杅alse锛屽紑鍙戦樁娈典笉杩涜鐧诲綍楠岃瘉鍙婃潈闄愰獙璇� ssoUserExpireAfterAccess: 60 #sso鐧诲綍鍚庯紝鐢ㄦ埛鍦ㄤ竴瀹氭椂闂达紙ssoUserExpireAfterAccess锛夛紙鍒嗛挓锛夊唴鏈闂郴缁燂紝绯荤粺娓呴櫎缂撳瓨淇℃伅锛屼娇鐢ㄩ噸鏂扮櫥褰曠郴缁� ssoCacheSizeInit: 10 #sso缂撳瓨鍒濆瀹归噺 ssoCacheSizeMax: 10000 #sso缂撳瓨鏈�澶у閲忥紝鍗虫敮鎸乻soCacheSizeMax涓敤鎴峰悓鏃剁櫥褰� + nginx: + webPort: 8000 sso: checkUrl: http://127.0.0.1:12344/sso/sso/ssoCheck webPort: 12344 @@ -58,6 +67,144 @@ other: webPort: 12348 idSuffix: 5 + file: - webPort: 12349 - idSuffix: 6 + idSuffix: 99 + file1: + webPort: 12380 + file2: + webPort: 12380 + file3: + webPort: 12380 + file4: + webPort: 12380 + file5: + webPort: 12380 + file6: + webPort: 12380 + file7: + webPort: 12380 + file8: + webPort: 12380 + file9: + webPort: 12380 + file10: + webPort: 12380 + file11: + webPort: 12380 + file12: + webPort: 12380 + +#web鍒嗗竷寮忔枃浠剁郴缁� +dy: + photoZipWidth: 400 #缂╃暐鍥惧昂瀵� + webFile: + fmUrl: http://127.0.0.1:${pms.other.webPort}/other # fm鐨剋eb涓婁笅鏂� URL + sv1: + id: dyFile1 + absolutePath: E:/java/nginx-1.24.0/html/webfiles/ + relativePath: webFile1 + hashStart: 0 + hashEnd: 5461 + restUrl: http://127.0.0.1:${pms.file1.webPort}/file #file鏄笂涓嬫枃 + webUrl: http://127.0.0.1:${pms.nginx.webPort}/webfiles/ #nginx鏈嶅姟璺緞 + webDownloadUrl: http://127.0.0.1:${pms.file1.webPort}/file/download/down + sv2: + id: dyFile2 + absolutePath: E:/java/nginx-1.24.0/html/webfiles/ + relativePath: webFile2 + hashStart: 5462 + hashEnd: 10923 + restUrl: http://127.0.0.1:${pms.file2.webPort}/file + webUrl: http://127.0.0.1:${pms.nginx.webPort}/webfiles/ + webDownloadUrl: http://127.0.0.1:${pms.file2.webPort}/file/download/down + sv3: + id: dyFile3 + absolutePath: E:/java/nginx-1.24.0/html/webfiles/ + relativePath: webFile3 + hashStart: 10924 + hashEnd: 16385 + restUrl: http://127.0.0.1:${pms.file3.webPort}/file + webUrl: http://127.0.0.1:${pms.nginx.webPort}/webfiles/ + webDownloadUrl: http://127.0.0.1:${pms.file3.webPort}/file/download/down + sv4: + id: dyFile4 + absolutePath: E:/java/nginx-1.24.0/html/webfiles/ + relativePath: webFile4 + hashStart: 16386 + hashEnd: 21847 + restUrl: http://127.0.0.1:${pms.file4.webPort}/file + webUrl: http://127.0.0.1:${pms.nginx.webPort}/webfiles/ + webDownloadUrl: http://127.0.0.1:${pms.file4.webPort}/file/download/down + sv5: + id: dyFile5 + absolutePath: E:/java/nginx-1.24.0/html/webfiles/ + relativePath: webFile5 + hashStart: 21848 + hashEnd: 27309 + restUrl: http://127.0.0.1:${pms.file5.webPort}/file + webUrl: http://127.0.0.1:${pms.nginx.webPort}/webfiles/ + webDownloadUrl: http://127.0.0.1:${pms.file5.webPort}/file/download/down + sv6: + id: dyFile6 + absolutePath: E:/java/nginx-1.24.0/html/webfiles/ + relativePath: webFile6 + hashStart: 27310 + hashEnd: 32767 + restUrl: http://127.0.0.1:${pms.file6.webPort}/file + webUrl: http://127.0.0.1:${pms.nginx.webPort}/webfiles/ + webDownloadUrl: http://127.0.0.1:${pms.file6.webPort}/file/download/down + sv7: + id: dyFile7 + absolutePath: E:/java/nginx-1.24.0/html/webfiles/ + relativePath: webFile7 + hashStart: 32768 + hashEnd: 38229 + restUrl: http://127.0.0.1:${pms.file7.webPort}/file + webUrl: http://127.0.0.1:${pms.nginx.webPort}/webfiles/ + webDownloadUrl: http://127.0.0.1:${pms.file7.webPort}/file/download/down + sv8: + id: dyFile8 + absolutePath: E:/java/nginx-1.24.0/html/webfiles/ + relativePath: webFile8 + hashStart: 38230 + hashEnd: 43691 + restUrl: http://127.0.0.1:${pms.file8.webPort}/file + webUrl: http://127.0.0.1:${pms.nginx.webPort}/webfiles/ + webDownloadUrl: http://127.0.0.1:${pms.file8.webPort}/file/download/down + sv9: + id: dyFile9 + absolutePath: E:/java/nginx-1.24.0/html/webfiles/ + relativePath: webFile9 + hashStart: 43692 + hashEnd: 49153 + restUrl: http://127.0.0.1:${pms.file9.webPort}/file + webUrl: http://127.0.0.1:${pms.nginx.webPort}/webfiles/ + webDownloadUrl: http://127.0.0.1:${pms.file9.webPort}/file/download/down + sv10: + id: dyFile10 + absolutePath: E:/java/nginx-1.24.0/html/webfiles/ + relativePath: webFile10 + hashStart: 49154 + hashEnd: 54615 + restUrl: http://127.0.0.1:${pms.file10.webPort}/file + webUrl: http://127.0.0.1:${pms.nginx.webPort}/webfiles/ + webDownloadUrl: http://127.0.0.1:${pms.file10.webPort}/file/download/down + sv11: + id: dyFile11 + absolutePath: E:/java/nginx-1.24.0/html/webfiles/ + relativePath: webFile11 + hashStart: 54616 + hashEnd: 60077 + restUrl: http://127.0.0.1:${pms.file11.webPort}/file + webUrl: http://127.0.0.1:${pms.nginx.webPort}/webfiles/ + webDownloadUrl: http://127.0.0.1:${pms.file11.webPort}/file/download/down + sv12: + id: dyFile12 + absolutePath: E:/java/nginx-1.24.0/html/webfiles/ + relativePath: webFile12 + hashStart: 60078 + hashEnd: 65535 + restUrl: http://127.0.0.1:${pms.file12.webPort}/file + webUrl: http://127.0.0.1:${pms.nginx.webPort}/webfiles/ + webDownloadUrl: http://127.0.0.1:${pms.file12.webPort}/file/download/down diff --git a/pms-parent/pms-global/src/main/resources/mapper/OthFileMapper.xml b/pms-parent/pms-global/src/main/resources/mapper/OthFileMapper.xml new file mode 100644 index 0000000..2ce8b6c --- /dev/null +++ b/pms-parent/pms-global/src/main/resources/mapper/OthFileMapper.xml @@ -0,0 +1,111 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> +<mapper namespace="com.dy.pmsGlobal.daoOth.OthFileMapper"> + <resultMap id="BaseResultMap" type="com.dy.pmsGlobal.pojoOth.OthFile"> + <!--@mbg.generated--> + <!--@Table oth_file--> + <id column="id" property="id" /> + <result column="org_name" property="orgName" /> + <result column="ext_name" property="extName" /> + <result column="new_name" property="newName" /> + <result column="hash" property="hash" /> + <result column="file_path" property="filePath" /> + </resultMap> + <sql id="Base_Column_List"> + <!--@mbg.generated--> + id, org_name, ext_name, new_name, hash, file_path + </sql> + <select id="selectByPrimaryKey" parameterType="java.lang.Long" resultMap="BaseResultMap"> + <!--@mbg.generated--> + select + <include refid="Base_Column_List" /> + from oth_file + where id = #{id} + </select> + <delete id="deleteByPrimaryKey" parameterType="java.lang.Long"> + <!--@mbg.generated--> + delete from oth_file + where id = #{id} + </delete> + <insert id="insert" parameterType="com.dy.pmsGlobal.pojoOth.OthFile"> + <!--@mbg.generated--> + insert into oth_file (id, org_name, ext_name, new_name, hash, file_path) + values (#{id}, #{orgName}, #{extName}, #{newName}, #{hash}, #{filePath}) + </insert> + <insert id="insertSelective" parameterType="com.dy.pmsGlobal.pojoOth.OthFile"> + <!--@mbg.generated--> + insert into oth_file + <trim prefix="(" suffix=")" suffixOverrides=","> + <if test="id != null"> + id, + </if> + <if test="orgName != null"> + org_name, + </if> + <if test="extName != null"> + ext_name, + </if> + <if test="newName != null"> + new_name, + </if> + <if test="hash != null"> + hash, + </if> + <if test="filePath != null"> + file_path, + </if> + </trim> + <trim prefix="values (" suffix=")" suffixOverrides=","> + <if test="id != null"> + #{id}, + </if> + <if test="orgName != null"> + #{orgName}, + </if> + <if test="extName != null"> + #{extName}, + </if> + <if test="newName != null"> + #{newName}, + </if> + <if test="hash != null"> + #{hash}, + </if> + <if test="filePath != null"> + #{filePath}, + </if> + </trim> + </insert> + <update id="updateByPrimaryKeySelective" parameterType="com.dy.pmsGlobal.pojoOth.OthFile"> + <!--@mbg.generated--> + update oth_file + <set> + <if test="orgName != null"> + org_name = #{orgName}, + </if> + <if test="extName != null"> + ext_name = #{extName}, + </if> + <if test="newName != null"> + new_name = #{newName}, + </if> + <if test="hash != null"> + hash = #{hash}, + </if> + <if test="filePath != null"> + file_path = #{filePath}, + </if> + </set> + where id = #{id} + </update> + <update id="updateByPrimaryKey" parameterType="com.dy.pmsGlobal.pojoOth.OthFile"> + <!--@mbg.generated--> + update oth_file + set org_name = #{orgName}, + ext_name = #{extName}, + new_name = #{newName}, + hash = #{hash}, + file_path = #{filePath} + where id = #{id} + </update> +</mapper> \ No newline at end of file diff --git a/pms-parent/pms-web-base/src/main/java/com/dy/pmsBase/PmsBaseApplication.java b/pms-parent/pms-web-base/src/main/java/com/dy/pmsBase/PmsBaseApplication.java index 74a49f6..e8d985c 100644 --- a/pms-parent/pms-web-base/src/main/java/com/dy/pmsBase/PmsBaseApplication.java +++ b/pms-parent/pms-web-base/src/main/java/com/dy/pmsBase/PmsBaseApplication.java @@ -9,7 +9,7 @@ @SpringBootApplication @EnableAspectJAutoProxy @ComponentScan(basePackages = {"com.dy.common", "com.dy.pmsGlobal", "com.dy.pmsBase"}) -@MapperScan(basePackages={"com.dy.pmsGlobal.daoBa"}) +@MapperScan(basePackages={"com.dy.pmsGlobal.daoBa","com.dy.pmsGlobal.daoOth"}) public class PmsBaseApplication { public static void main(String[] args) { diff --git a/pms-parent/pms-web-file/pom.xml b/pms-parent/pms-web-file/pom.xml index edba121..952d371 100644 --- a/pms-parent/pms-web-file/pom.xml +++ b/pms-parent/pms-web-file/pom.xml @@ -29,6 +29,12 @@ <artifactId>pms-global</artifactId> <version>1.0.0</version> </dependency> + + <dependency> + <groupId>net.coobird</groupId> + <artifactId>thumbnailator</artifactId> + <version>${thumbnailator.version}</version> + </dependency> </dependencies> <build> diff --git a/pms-parent/pms-web-file/src/main/java/com/dy/pmsFile/PmsFileApplication.java b/pms-parent/pms-web-file/src/main/java/com/dy/dyFile/DyFileApplication.java similarity index 79% rename from pms-parent/pms-web-file/src/main/java/com/dy/pmsFile/PmsFileApplication.java rename to pms-parent/pms-web-file/src/main/java/com/dy/dyFile/DyFileApplication.java index f64233a..209ce4e 100644 --- a/pms-parent/pms-web-file/src/main/java/com/dy/pmsFile/PmsFileApplication.java +++ b/pms-parent/pms-web-file/src/main/java/com/dy/dyFile/DyFileApplication.java @@ -1,4 +1,4 @@ -package com.dy.pmsFile; +package com.dy.dyFile; import org.mybatis.spring.annotation.MapperScan; import org.springframework.boot.SpringApplication; @@ -8,12 +8,12 @@ @SpringBootApplication @EnableAspectJAutoProxy -@ComponentScan(basePackages = {"com.dy.common", "com.dy.pmsGlobal", "com.dy.pmsFile"}) +@ComponentScan(basePackages = {"com.dy.common", "com.dy.pmsGlobal", "com.dy.dyFile"}) @MapperScan(basePackages={"com.dy.pmsGlobal.daoBa", "com.dy.pmsGlobal.daoOth"}) -public class PmsFileApplication { +public class DyFileApplication { public static void main(String[] args) { - SpringApplication.run(PmsFileApplication.class, args); + SpringApplication.run(DyFileApplication.class, args); } } diff --git a/pms-parent/pms-web-file/src/main/java/com/dy/dyFile/download/DownloadFileCtr.java b/pms-parent/pms-web-file/src/main/java/com/dy/dyFile/download/DownloadFileCtr.java new file mode 100644 index 0000000..912fead --- /dev/null +++ b/pms-parent/pms-web-file/src/main/java/com/dy/dyFile/download/DownloadFileCtr.java @@ -0,0 +1,18 @@ +package com.dy.dyFile.download; + +import lombok.extern.slf4j.Slf4j; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +/** + * web鏂囦欢涓嬭浇 + */ +@Slf4j +@RestController +@RequestMapping(path="download") +@SuppressWarnings("unchecked")//java鐗堟湰瓒婇珮锛屽娉涘瀷绾︽潫瓒婁弗锛屾墍浠ラ厤缃甋uppressWarnings("unchecked") +public class DownloadFileCtr { + public String down(){ + return null ; + } +} diff --git a/pms-parent/pms-web-file/src/main/java/com/dy/dyFile/files/FileCtrl.java b/pms-parent/pms-web-file/src/main/java/com/dy/dyFile/files/FileCtrl.java new file mode 100644 index 0000000..5e85b07 --- /dev/null +++ b/pms-parent/pms-web-file/src/main/java/com/dy/dyFile/files/FileCtrl.java @@ -0,0 +1,196 @@ +package com.dy.dyFile.files; + +import com.dy.common.util.NumUtil; +import com.dy.dyFile.util.*; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.multipart.MultipartFile; + +import java.io.File; +import java.io.InputStream; + +/** + * web鏂囦欢涓婁紶 + */ +@Slf4j +@RestController +@RequestMapping(path="file") +@SuppressWarnings("unchecked")//java鐗堟湰瓒婇珮锛屽娉涘瀷绾︽潫瓒婁弗锛屾墍浠ラ厤缃甋uppressWarnings("unchecked") +public class FileCtrl { + + @Value("${dy.photoZipWidth}") + private String photoZipWidthStr ; + + /** + * web鍒嗗竷寮忔枃浠剁郴缁熶繚瀛樼収鐗囨枃浠� + * @param file + * @param regionNum + * @param json 姘村嵃淇℃伅 + * @param absolutePath + * @param relativePath + * @param fileName + * @return + */ + @PostMapping("/savePhoto") + public String savePhoto(MultipartFile file, + String regionNum, + String json, + String absolutePath, + String relativePath, + String fileName) { + Integer photoZipWidth = 400 ; + if(photoZipWidthStr != null && NumUtil.isPlusIntNumber(photoZipWidthStr)){ + photoZipWidth = Integer.parseInt(photoZipWidthStr) ; + } + String fileRelativePath = null ; + try { + if (file != null) { + if(absolutePath != null && relativePath != null && fileName != null){ + InputStream input = file.getInputStream() ; + //鐢熸垚鏂版枃浠剁浉瀵硅矾寰� + FilePhotoUtil fUtil = new FilePhotoUtil() ; + fileRelativePath = fUtil.newFileRelativityPath(absolutePath, relativePath, regionNum) + fileName ; + String filePath = absolutePath + fileRelativePath ; + if(!fUtil.saveFile(filePath, input)){ + fileRelativePath = null ; + }else { + //瀛樺偍鎴愬姛 + File fPic = new File(filePath) ; + //鐢熸垚缂╃暐鍥� + int index = filePath.lastIndexOf(".") ; + String zipFilePath1 = filePath.substring(0, index) ; + String zipFilePath2 = filePath.substring(index) ; + String zipFilePath = zipFilePath1 + "_" + zipFilePath2 ; + InputStream zipFileInput = null ; + if(zipFilePath2.equalsIgnoreCase(".png")){ + zipFileInput = ZipImg.zipToPng(fPic, photoZipWidth, photoZipWidth) ; + }else{ + zipFileInput = ZipImg.zipToJpg(fPic, photoZipWidth, photoZipWidth) ; + } + boolean zipOk = new FileUtil().saveFile(zipFilePath, zipFileInput) ; + } + } + } + } catch (Exception e) { + log.error("淇濆瓨鐓х墖鏂囦欢寮傚父", e); + } + return fileRelativePath ; + } + + /** + * web鍒嗗竷寮忔枃浠剁郴缁熶繚瀛樺綍闊抽煶棰戞枃浠� + * @param file + * @param regionNum + * @param json 姘村嵃淇℃伅 + * @param absolutePath + * @param relativePath + * @param fileName + * @return + */ + @PostMapping("/savePhone") + public String savePhone(MultipartFile file, + String regionNum, + String json, + String absolutePath, + String relativePath, + String fileName) { + String fileRelativePath = null ; + try { + if (file != null) { + if(absolutePath != null && relativePath != null && fileName != null){ + InputStream input = file.getInputStream() ; + //鐢熸垚鏂版枃浠剁浉瀵硅矾寰� + FilePhoneUtil fUtil = new FilePhoneUtil() ; + fileRelativePath = fUtil.newFileRelativityPath(absolutePath, relativePath, regionNum) + fileName ; + String filePath = absolutePath + fileRelativePath ; + if(!fUtil.saveFile(filePath, input)){ + fileRelativePath = null ; + } + } + } + } catch (Exception e) { + log.error("淇濆瓨褰曢煶闊抽鏂囦欢寮傚父", e); + } + return fileRelativePath ; + } + + + /** + * web鍒嗗竷寮忔枃浠剁郴缁熶繚瀛樺綍鍍忚棰戞枃浠� + * @param file + * @param regionNum + * @param json 姘村嵃淇℃伅 + * @param absolutePath + * @param relativePath + * @param fileName + * @return + */ + @PostMapping("/saveVideo") + public String saveVideo(MultipartFile file, + String regionNum, + String json, + String absolutePath, + String relativePath, + String fileName) { + String fileRelativePath = null ; + try { + if (file != null) { + if(absolutePath != null && relativePath != null && fileName != null){ + InputStream input = file.getInputStream() ; + //鐢熸垚鏂版枃浠剁浉瀵硅矾寰� + FileVideoUtil fUtil = new FileVideoUtil() ; + fileRelativePath = fUtil.newFileRelativityPath(absolutePath, relativePath, regionNum) + fileName ; + String filePath = absolutePath + fileRelativePath ; + if(!fUtil.saveFile(filePath, input)){ + fileRelativePath = null ; + } + } + } + } catch (Exception e) { + log.error("淇濆瓨褰曞儚瑙嗛鏂囦欢寮傚父", e); + } + return fileRelativePath ; + } + + + /** + * web鍒嗗竷寮忔枃浠剁郴缁熶繚瀛樻枃妗f枃浠� + * @param file + * @param regionNum + * @param json 姘村嵃淇℃伅 + * @param absolutePath + * @param relativePath + * @param fileName + * @return + */ + @PostMapping("/saveDocument") + public String saveDocument(MultipartFile file, + String regionNum, + String json, + String absolutePath, + String relativePath, + String fileName) { + String fileRelativePath = null ; + try { + if (file != null) { + if(absolutePath != null && relativePath != null && fileName != null){ + InputStream input = file.getInputStream() ; + //鐢熸垚鏂版枃浠剁浉瀵硅矾寰� + FileDocumentUtil fUtil = new FileDocumentUtil() ; + fileRelativePath = fUtil.newFileRelativityPath(absolutePath, relativePath, regionNum) + fileName ; + String filePath = absolutePath + fileRelativePath ; + if(!fUtil.saveFile(filePath, input)){ + fileRelativePath = null ; + } + } + } + } catch (Exception e) { + log.error("淇濆瓨鏂囨。鏂囦欢寮傚父", e); + } + return fileRelativePath ; + } + +} diff --git a/pms-parent/pms-web-file/src/main/java/com/dy/dyFile/util/FileConstant.java b/pms-parent/pms-web-file/src/main/java/com/dy/dyFile/util/FileConstant.java new file mode 100644 index 0000000..79fab04 --- /dev/null +++ b/pms-parent/pms-web-file/src/main/java/com/dy/dyFile/util/FileConstant.java @@ -0,0 +1,13 @@ +package com.dy.dyFile.util; + + +public class FileConstant { + public static final String YES = "1" ; + public static final String NO = "0" ; + + public static final String phoneFileBasePath = "/phone/" ;//褰曢煶鏂囦欢 + public static final String photoFileBasePath = "/photo/" ;//鐓х墖鏂囦欢 + public static final String videoFileBasePath = "/video/" ;//瑙嗛鏂囦欢 + public static final String iconFileBasePath = "/icon/" ;//澶村儚鏂囦欢 + public static final String documentFileBasePath = "/document/" ;//鏂囨。鏂囦欢 +} diff --git a/pms-parent/pms-web-file/src/main/java/com/dy/dyFile/util/FileDocumentUtil.java b/pms-parent/pms-web-file/src/main/java/com/dy/dyFile/util/FileDocumentUtil.java new file mode 100644 index 0000000..a1fe5cd --- /dev/null +++ b/pms-parent/pms-web-file/src/main/java/com/dy/dyFile/util/FileDocumentUtil.java @@ -0,0 +1,46 @@ +package com.dy.dyFile.util; + +import com.dy.common.util.DateTime; +import com.dy.pmsGlobal.dyFile.FileConstant; + +import java.io.File; + + +/** + * 鏂囨。绫� + * @author Administrator + * + */ +public class FileDocumentUtil extends FileUtil { + + /** + * 鐢熸垚鏂囦欢鐩稿璺緞鍚嶇О + * + * @param absolutePath + * @param relativePath + * @param regionNum + * @return + */ + public String newFileRelativityPath(String absolutePath, String relativePath, String regionNum) { + String relativityPath = relativePath ; + if(regionNum != null && !regionNum.trim().equals("") && !regionNum.trim().equals(FileConstant.NotRegionNum)){ + relativityPath += regionNum ; + }else{ + if(com.dy.dyFile.util.FileConstant.documentFileBasePath.startsWith("/")){ + if(relativityPath.endsWith("/")){ + relativityPath = relativityPath.substring(0, relativityPath.length() - 1) ; + } + } + } + relativityPath += com.dy.dyFile.util.FileConstant.documentFileBasePath + DateTime.yyyyMMdd() + "/"; + + String basePath = absolutePath + relativityPath; + File dir = new File(basePath); + if (!dir.exists()) { + dir.mkdirs(); + } + return relativityPath; + } + + +} diff --git a/pms-parent/pms-web-file/src/main/java/com/dy/dyFile/util/FileIconUtil.java b/pms-parent/pms-web-file/src/main/java/com/dy/dyFile/util/FileIconUtil.java new file mode 100644 index 0000000..5a30061 --- /dev/null +++ b/pms-parent/pms-web-file/src/main/java/com/dy/dyFile/util/FileIconUtil.java @@ -0,0 +1,38 @@ +package com.dy.dyFile.util; + +import com.dy.pmsGlobal.dyFile.FileConstant; + +import java.io.File; + +public class FileIconUtil extends FileUtil { + + /** + * 鐢熸垚鏂囦欢鐩稿璺緞鍚嶇О + * + * @param absolutePath + * @param relativePath + * @param regionNum + * @return + */ + public String newFileRelativityPath(String absolutePath, String relativePath, String regionNum) { + String relativityPath = relativePath ; + if(regionNum != null && !regionNum.trim().equals("") && !regionNum.trim().equals(FileConstant.NotRegionNum)){ + relativityPath += regionNum ; + }else{ + if(com.dy.dyFile.util.FileConstant.iconFileBasePath.startsWith("/")){ + if(relativityPath.endsWith("/")){ + relativityPath = relativityPath.substring(0, relativityPath.length() - 1) ; + } + } + } + relativityPath += com.dy.dyFile.util.FileConstant.iconFileBasePath; + + String basePath = absolutePath + relativityPath; + File dir = new File(basePath); + if (!dir.exists()) { + dir.mkdirs(); + } + return relativityPath; + } + +} diff --git a/pms-parent/pms-web-file/src/main/java/com/dy/dyFile/util/FilePhoneUtil.java b/pms-parent/pms-web-file/src/main/java/com/dy/dyFile/util/FilePhoneUtil.java new file mode 100644 index 0000000..93168e5 --- /dev/null +++ b/pms-parent/pms-web-file/src/main/java/com/dy/dyFile/util/FilePhoneUtil.java @@ -0,0 +1,41 @@ +package com.dy.dyFile.util; + +import com.dy.common.util.DateTime; +import com.dy.pmsGlobal.dyFile.FileConstant; + +import java.io.File; + +public class FilePhoneUtil extends FileUtil { + + /** + * 鐢熸垚鏂囦欢鐩稿璺緞鍚嶇О + * + * @param absolutePath + * @param relativePath + * @param regionNum + * @return + */ + public String newFileRelativityPath(String absolutePath, String relativePath, String regionNum) { + String relativityPath = relativePath ; + if(regionNum != null && !regionNum.trim().equals("") && !regionNum.trim().equals(FileConstant.NotRegionNum)){ + relativityPath += regionNum ; + }else{ + if(com.dy.dyFile.util.FileConstant.phoneFileBasePath.startsWith("/")){ + if(relativityPath.endsWith("/")){ + relativityPath = relativityPath.substring(0, relativityPath.length() - 1) ; + } + } + } + relativityPath += com.dy.dyFile.util.FileConstant.phoneFileBasePath + DateTime.yyyyMMdd() + "/"; + + String basePath = absolutePath + relativityPath; + File dir = new File(basePath); + if (!dir.exists()) { + dir.mkdirs(); + } + return relativityPath; + } + + + +} diff --git a/pms-parent/pms-web-file/src/main/java/com/dy/dyFile/util/FilePhotoUtil.java b/pms-parent/pms-web-file/src/main/java/com/dy/dyFile/util/FilePhotoUtil.java new file mode 100644 index 0000000..556f8fe --- /dev/null +++ b/pms-parent/pms-web-file/src/main/java/com/dy/dyFile/util/FilePhotoUtil.java @@ -0,0 +1,39 @@ +package com.dy.dyFile.util; + +import com.dy.common.util.DateTime; +import com.dy.pmsGlobal.dyFile.FileConstant; + +import java.io.File; + +public class FilePhotoUtil extends FileUtil { + + + /** + * 鐢熸垚鏂囦欢鐩稿璺緞鍚嶇О + * + * @param absolutePath + * @param relativePath + * @param regionNum + * @return + */ + public String newFileRelativityPath(String absolutePath, String relativePath, String regionNum) { + String relativityPath = relativePath ; + if(regionNum != null && !regionNum.trim().equals("") && !regionNum.trim().equals(FileConstant.NotRegionNum)){ + relativityPath += ("-" + regionNum) ; + }else{ + if(com.dy.dyFile.util.FileConstant.photoFileBasePath.startsWith("/")){ + if(relativityPath.endsWith("/")){ + relativityPath = relativityPath.substring(0, relativityPath.length() - 1) ; + } + } + } + relativityPath += com.dy.dyFile.util.FileConstant.photoFileBasePath + DateTime.yyyyMMdd() + "/"; + String filePath = absolutePath + relativityPath; + File dir = new File(filePath); + if (!dir.exists()) { + dir.mkdirs(); + } + return relativityPath; + } + +} diff --git a/pms-parent/pms-web-file/src/main/java/com/dy/dyFile/util/FileUtil.java b/pms-parent/pms-web-file/src/main/java/com/dy/dyFile/util/FileUtil.java new file mode 100644 index 0000000..61d432e --- /dev/null +++ b/pms-parent/pms-web-file/src/main/java/com/dy/dyFile/util/FileUtil.java @@ -0,0 +1,122 @@ +package com.dy.dyFile.util; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.io.RandomAccessFile; +import java.nio.channels.FileChannel; + +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + + +public class FileUtil { + + protected static final Logger log = LogManager.getLogger(FileUtil.class.getName()) ; + /** + * 淇濆瓨鏂囦欢 + * @param fileAbsolutelyPath 鏂囦欢缁濆璺緞 + * @param input + * @return 淇濆瓨鏂囦欢鐨勬槸鍚︽垚鍔熺殑缁撴灉 + */ + public boolean saveFile(String fileAbsolutelyPath , InputStream input){ + boolean success = true ; + if(fileAbsolutelyPath == null || input == null){ + success = false ; + }else{ + OutputStream os = null; + try { + os = new FileOutputStream(fileAbsolutelyPath); + byte[] b = new byte[1024] ; + int len = input.read(b) ; + while(len > 0){ + os.write(b, 0, len); + len = input.read(b) ; + os.flush(); + } + } catch (Exception e) { + e.printStackTrace(); + success = false ; + } finally { + try { + if(os != null){ + os.close(); + } + } catch (IOException e) { + e.printStackTrace(); + } + } + } + return success ; + } + /** + * 澶嶅埗鏂囦欢 + * @param fromFile + * @param realPath 缁濆璺緞 + * @param newFileRelativityPath 鐩稿璺緞 + * @return + */ + public boolean copyFile(File fromFile, String realPath, String newFileRelativityPath){ + boolean flag = true ; + FileChannel fromChannel = null ; + FileChannel toChannel = null ; + try { + fromChannel = new RandomAccessFile(fromFile, "r").getChannel(); + toChannel = new RandomAccessFile(new File(realPath + newFileRelativityPath), "rw").getChannel(); + fromChannel.transferTo(0, fromChannel.size(), toChannel); + } catch (FileNotFoundException e) { + flag = false ; + log.error("澶嶅埗鏂囦欢鍑洪敊:" + e.getMessage()) ; + } catch (IOException e) { + flag = false ; + log.error("澶嶅埗鏂囦欢鍑洪敊:" + e.getMessage()) ; + }finally{ + try{ + if(fromChannel != null){ + fromChannel.close() ; + } + if(toChannel != null){ + toChannel.close() ; + } + }catch(Exception e){}finally{} + } + return flag ; + } + + /** + * 鍒犻櫎鏂囦欢 + * @param f + */ + public boolean deleteFile(File f){ + boolean flag = false ; + try{ + if(f != null){ + flag = f.delete() ; + } + }catch(Exception e){ + }finally{} + return flag ; + } + + /** + * 鍒犻櫎鏂囦欢 + * @param path + */ + public boolean deleteFile(String path){ + boolean flag = false ; + try{ + if(path != null && !path.equals("")){ + File f = new File(path) ; + if(f != null && f.exists()){ + flag = f.delete() ; + } + } + }catch(Exception e){ + }finally{} + return flag ; + } + +} diff --git a/pms-parent/pms-web-file/src/main/java/com/dy/dyFile/util/FileVideoUtil.java b/pms-parent/pms-web-file/src/main/java/com/dy/dyFile/util/FileVideoUtil.java new file mode 100644 index 0000000..f56bd4b --- /dev/null +++ b/pms-parent/pms-web-file/src/main/java/com/dy/dyFile/util/FileVideoUtil.java @@ -0,0 +1,39 @@ +package com.dy.dyFile.util; + +import com.dy.common.util.DateTime; +import com.dy.pmsGlobal.dyFile.FileConstant; + +import java.io.File; + +public class FileVideoUtil extends FileUtil { + + /** + * 鐢熸垚鏂囦欢鐩稿璺緞鍚嶇О + * + * @param absolutePath + * @param relativePath + * @param regionNum + * @return + */ + public String newFileRelativityPath(String absolutePath, String relativePath, String regionNum) { + String relativityPath = relativePath ; + if(regionNum != null && !regionNum.trim().equals("") && !regionNum.trim().equals(FileConstant.NotRegionNum)){ + relativityPath += regionNum ; + }else{ + if(com.dy.dyFile.util.FileConstant.videoFileBasePath.startsWith("/")){ + if(relativityPath.endsWith("/")){ + relativityPath = relativityPath.substring(0, relativityPath.length() - 1) ; + } + } + } + relativityPath += com.dy.dyFile.util.FileConstant.videoFileBasePath + DateTime.yyyyMMdd() + "/"; + + String basePath = absolutePath + relativityPath; + File dir = new File(basePath); + if (!dir.exists()) { + dir.mkdirs(); + } + return relativityPath; + } + +} diff --git a/pms-parent/pms-web-file/src/main/java/com/dy/dyFile/util/ZipImg.java b/pms-parent/pms-web-file/src/main/java/com/dy/dyFile/util/ZipImg.java new file mode 100644 index 0000000..a9101f5 --- /dev/null +++ b/pms-parent/pms-web-file/src/main/java/com/dy/dyFile/util/ZipImg.java @@ -0,0 +1,63 @@ +package com.dy.dyFile.util; + +import net.coobird.thumbnailator.Thumbnails; + +import javax.imageio.ImageIO; + +import java.awt.image.BufferedImage; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.File; +import java.io.InputStream; + +/** + * 鐢熸垚鍥剧墖鐨勭缉鐣ュ浘 + */ +public class ZipImg { + public static InputStream zipToJpg(File file, int xSize, int ySize) throws Exception{ + return zip(file, "jpg", xSize, ySize) ; + } + + public static InputStream zipToPng(File file, int xSize, int ySize) throws Exception{ + return zip(file, "png", xSize, ySize) ; + } + + public static void zipToFile(File file, File toFile, int xSize, int ySize) throws Exception{ + Thumbnails.of(file).size(xSize, ySize).outputQuality(0.5f).toFile(toFile);//0f-1f 璐ㄩ噺瓒婇珮 + } + + + private static InputStream zip(File file, String type, int xSize, int ySize) throws Exception{ + BufferedImage bi = Thumbnails.of(file).size(xSize, ySize).outputQuality(1f).asBufferedImage(); + ByteArrayOutputStream os = new ByteArrayOutputStream(); + ImageIO.write(bi, type, os); + InputStream in = new ByteArrayInputStream(os.toByteArray()); + bi = null ; + os = null ; + return in ; + } + + public static void main(String[] args){ + File f = new File("D:/test.jpg") ; + String name = f.getName() ; + String path = f.getPath() ; + System.out.println(name); + System.out.println(path); + + int index = path.lastIndexOf(".") ; + String s1 = path.substring(0, index) ; + String s2 = path.substring(index) ; + System.out.println(s1); + System.out.println(s2); + + String newFilePath = s1 + "_" + s2 ; + try { + InputStream input = zipToJpg(f, 400, 400) ; + new FileUtil().saveFile(newFilePath, input) ; + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + +} diff --git a/pms-parent/pms-web-file/src/main/resources/application.yml b/pms-parent/pms-web-file/src/main/resources/application.yml index 3525991..2770a29 100644 --- a/pms-parent/pms-web-file/src/main/resources/application.yml +++ b/pms-parent/pms-web-file/src/main/resources/application.yml @@ -4,7 +4,7 @@ #web鏈嶅姟绔彛锛宼omcat榛樿鏄�8080 server: - port: ${pms.file.webPort} + port: ${pms.file1.webPort} servlet: context-path: /file #web璁块棶涓婁笅鏂囪矾寰� context-parameters: diff --git a/pms-parent/pms-web-other/src/main/java/com/dy/pmsOther/dyFm/DyFileSvConf.java b/pms-parent/pms-web-other/src/main/java/com/dy/pmsOther/dyFm/DyFileSvConf.java new file mode 100644 index 0000000..6e314ec --- /dev/null +++ b/pms-parent/pms-web-other/src/main/java/com/dy/pmsOther/dyFm/DyFileSvConf.java @@ -0,0 +1,159 @@ +package com.dy.pmsOther.dyFm; + +import java.util.ArrayList; +import java.util.List; + +public class DyFileSvConf { + + public static class Group{ + public List<Vo> list ; + public Group(){ + this.list = new ArrayList<Vo>() ; + } + public void add(Vo vo)throws Exception{ + if(vo == null){ + throw new Exception("鍑洪敊锛岄鍔犲叆闆嗗悎Vo涓虹┖浜嗭紒") ; + } + if(list.size() > 0){ + for(Vo lvo : list){ + lvo.checkEqual(vo) ; + } + this.list.add(vo) ; + }else{ + this.list.add(vo) ; + } + } + public void check() throws Exception{ + Integer startV = 0 ; + doCheck(startV) ; + } + private void doCheck(Integer startV) throws Exception{ + boolean find = false ; + for(Vo vo : list){ + if(vo.hashStart.intValue() == startV.intValue()){ + startV = vo.hashEnd + 1; + find = true ; + break ; + } + } + if(!find){ + throw new Exception("涓ラ噸閿欒锛屾湭鍙戠幇鍝堝笇鍊间负" + startV + "鏂囦欢鏈嶅姟鍣紒") ; + } + if(startV.intValue() <= 65535){ + doCheck(startV) ; + } + } + } + + public static class Vo{ + public String id ;//id鎴栧悕绉� + public String fileSysAbsolutePath; //鏂囦欢鍚嶇О鐨勫搱甯屽�煎搴旂殑鏂囦欢鏈�缁堝瓨鍌ㄧ粷瀵硅矾寰勪腑鐨勬牴鐩綍锛屽湪閰嶇疆鏂囦欢涓厤缃� + public String fileSysRelativePath; //鏂囦欢鍚嶇О鐨勫搱甯屽�煎搴旂殑鏂囦欢鏈�缁堝瓨鍌ㄧ浉瀵硅矾寰勭殑鐩綍锛屽湪閰嶇疆鏂囦欢涓厤缃� + public String restUrl;//鏂囦欢绯荤粺璺緞 + public String webUrl ;//涓嬭浇鏂囨。鐨剋eb璺緞 + public String webDownloadUrl ;//Action涓嬭浇鏂囨。鐨剋eb璺緞 + public Integer hashStart ;//鍝堝笇鍊煎惎濮嬪�硷紙鍖呭惈锛� + public Integer hashEnd ;//鍝堝笇鍊兼埅姝㈠�硷紙鍖呭惈锛� + + public Vo(){} + public Vo(String id, + String fileSysAbsolutePath, + String fileSysBasePath, + String restUrl, + String webUrl, + String webDownloadUrl, + Integer hashStart, + Integer hashEnd)throws Exception{ + this.id = id ; + this.fileSysAbsolutePath = fileSysAbsolutePath ; + this.fileSysRelativePath = fileSysBasePath ; + this.restUrl = restUrl ; + this.webUrl = webUrl ; + this.webDownloadUrl = webDownloadUrl ; + this.hashStart = hashStart ; + this.hashEnd = hashEnd ; + if(this.id == null || this.id.trim().equals("")){ + throw new Exception("鍑洪敊锛宨d涓虹┖浜嗭紒") ; + }else{ + this.id = this.id.trim() ; + } + if(this.fileSysAbsolutePath == null || this.fileSysAbsolutePath.trim().equals("")){ + throw new Exception("鍑洪敊锛宖ileSysAbsolutePath涓虹┖浜嗭紒") ; + }else{ + this.fileSysAbsolutePath = this.fileSysAbsolutePath.trim() ; + this.fileSysAbsolutePath = this.fileSysAbsolutePath.replaceAll("\\\\", "/") ; + if(!this.fileSysAbsolutePath.endsWith("/")){ + this.fileSysAbsolutePath = this.fileSysAbsolutePath + "/" ; + } + } + if(this.fileSysRelativePath == null || this.fileSysRelativePath.trim().equals("")){ + throw new Exception("鍑洪敊锛宖ileSysBasePath涓虹┖浜嗭紒") ; + }else{ + this.fileSysRelativePath = this.fileSysRelativePath.trim() ; + } + if(this.webUrl == null || this.webUrl.trim().equals("")){ + throw new Exception("鍑洪敊锛寃ebUrl涓虹┖浜嗭紒") ; + }else{ + this.webUrl = this.webUrl.trim() ; + if(!this.webUrl.endsWith("/") && !this.webUrl.endsWith("\\")){ + this.webUrl += "/" ; + } + } + if(this.webDownloadUrl == null || this.webDownloadUrl.trim().equals("")){ + throw new Exception("鍑洪敊锛寃ebDownloadUrl涓虹┖浜嗭紒") ; + }else{ + this.webDownloadUrl = this.webDownloadUrl.trim() ; + if(!this.webDownloadUrl.endsWith("/") && !this.webDownloadUrl.endsWith("\\")){ + this.webDownloadUrl += "/" ; + } + } + if(this.hashStart == null){ + throw new Exception("鍑洪敊锛宧ashStart涓虹┖浜嗭紒") ; + }else if(this.hashStart.intValue() < 0){ + throw new Exception("鍑洪敊锛宧ashStart灏忎簬0浜嗭紒") ; + }else if(this.hashStart.intValue() > 65535){ + throw new Exception("鍑洪敊锛宧ashStart澶т簬65535浜嗭紒") ; + } + if(this.hashEnd == null){ + throw new Exception("鍑洪敊锛宧ashEnd涓虹┖浜嗭紒") ; + }else if(this.hashEnd.intValue() < 0){ + throw new Exception("鍑洪敊锛宧ashEnd灏忎簬0浜嗭紒") ; + }else if(this.hashEnd.intValue() > 65535){ + throw new Exception("鍑洪敊锛宧ashEnd澶т簬65535浜嗭紒") ; + } + if(this.hashEnd < this.hashStart){ + throw new Exception("鍑洪敊锛宧ashEnd灏忎簬hashStart浜嗭紒") ; + } + } + public String toString(){ + return "id=" + id + "\n" + + "fileSysAbsolutePath=" + fileSysAbsolutePath + "\n" + + "fileSysBasePath=" + fileSysRelativePath + "\n" + + "restUrl=" + restUrl + "\n" + + "webUrl=" + webUrl + "\n" + + "webDownloadUrl=" + webDownloadUrl + "\n" + + "hashStart=" + hashStart + "\n" + + "hashEnd=" + hashEnd ; + } + + + private boolean checkEqual(Vo vo)throws Exception{ + if(this.id.equalsIgnoreCase(vo.id)){ + throw new Exception("鍑洪敊锛宨d鏈夐噸澶嶏紒") ; + } + if(this.hashStart.intValue() == vo.hashStart.intValue()){ + throw new Exception("鍑洪敊锛宧ashStart鏈夐噸澶嶏紒") ; + } + if(this.hashEnd.intValue() == vo.hashEnd.intValue()){ + throw new Exception("鍑洪敊锛宧ashEnd鏈夐噸澶嶏紒") ; + } + if(this.hashStart.intValue() == vo.hashEnd.intValue()){ + throw new Exception("鍑洪敊锛宧ashStart涓巋ashEnd鏈夐噸澶嶏紒") ; + } + if(this.hashEnd.intValue() == vo.hashStart.intValue()){ + throw new Exception("鍑洪敊锛宧ashEnd涓巋ashStart鏈夐噸澶嶏紒") ; + } + return true ; + } + } +} diff --git a/pms-parent/pms-web-other/src/main/java/com/dy/pmsOther/dyFm/DyFmListener.java b/pms-parent/pms-web-other/src/main/java/com/dy/pmsOther/dyFm/DyFmListener.java new file mode 100644 index 0000000..1595b63 --- /dev/null +++ b/pms-parent/pms-web-other/src/main/java/com/dy/pmsOther/dyFm/DyFmListener.java @@ -0,0 +1,67 @@ +package com.dy.pmsOther.dyFm; + +import com.dy.common.util.NumUtil; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.context.event.ApplicationReadyEvent; +import org.springframework.context.ApplicationListener; +import org.springframework.core.env.Environment; +import org.springframework.lang.NonNull; +import org.springframework.stereotype.Component; + +@Component +public class DyFmListener implements ApplicationListener<ApplicationReadyEvent> { + + @Autowired + private Environment env; + + public static DyFileSvConf.Group dyFileGroup = new DyFileSvConf.Group() ; + + /** + * SpringBoot瀹瑰櫒宸茬粡鍑嗗濂戒簡 + * @param event 浜嬩欢 + */ + @Override + public void onApplicationEvent(@NonNull ApplicationReadyEvent event) { + try { + //绛�1绉掞紝绛夊緟com.alibaba.druid.pool.DruidDataSource瀹炲鍖栧畬鎴� + Thread.sleep(1000L); + } catch (InterruptedException e) { + e.printStackTrace(); + }finally { + try{ + parseConfig() ; + }catch(Exception e){ + e.printStackTrace(); + dyFileGroup = null ; + } + } + } + private void parseConfig() throws Exception{ + String fmUrl = env.getProperty("dy.webFile.fmUrl"); + for(int i = 1 ; i <= 12 ; i++){ + String id = env.getProperty("dy.webFile.sv" + i + ".id"); + String absolutePath = env.getProperty("dy.webFile.sv" + i + ".absolutePath"); + String relativePath = env.getProperty("dy.webFile.sv" + i + ".relativePath"); + String hashStart = env.getProperty("dy.webFile.sv" + i + ".hashStart"); + String hashEnd = env.getProperty("dy.webFile.sv" + i + ".hashEnd"); + String restUrl = env.getProperty("dy.webFile.sv" + i + ".restUrl"); + String webUrl = env.getProperty("dy.webFile.sv" + i + ".webUrl"); + String webDownloadUrl = env.getProperty("dy.webFile.sv" + i + ".webDownloadUrl"); + if(!NumUtil.isPlusIntNumber(hashStart)){ + throw new Exception("閰嶇疆dy.webFile.sv" + i + ".hashStart 涓嶆槸鏁存暟") ; + } + if(!NumUtil.isPlusIntNumber(hashEnd)){ + throw new Exception("閰嶇疆dy.webFile.sv" + i + ".hashEnd 涓嶆槸鏁存暟") ; + } + dyFileGroup.add(new DyFileSvConf.Vo(id, + absolutePath, + relativePath, + restUrl, + webUrl, + webDownloadUrl, + Integer.parseInt(hashStart), + Integer.parseInt(hashEnd))) ; + } + dyFileGroup.check(); + } +} diff --git a/pms-parent/pms-web-other/src/main/java/com/dy/pmsOther/dyFm/FileName.java b/pms-parent/pms-web-other/src/main/java/com/dy/pmsOther/dyFm/FileName.java new file mode 100644 index 0000000..8595e88 --- /dev/null +++ b/pms-parent/pms-web-other/src/main/java/com/dy/pmsOther/dyFm/FileName.java @@ -0,0 +1,20 @@ +package com.dy.pmsOther.dyFm; + +import com.dy.common.util.DateTime; + +public class FileName { + + + public static String createFileName(boolean useYmdhms, String id, String fileExtName){ + if(useYmdhms){ + return DateTime.yyyyMMddHHmmss() + "_" + id + "." + fileExtName ; + }else{ + return id + "." + fileExtName ; + } + } + + public static String createIconName(String clientId, String fileExtName){ + return clientId + "_" + DateTime.yyyyMMddHHmmss() + "." + fileExtName ; + } + +} diff --git a/pms-parent/pms-web-other/src/main/java/com/dy/pmsOther/dyFm/FileNameIdUtil.java b/pms-parent/pms-web-other/src/main/java/com/dy/pmsOther/dyFm/FileNameIdUtil.java new file mode 100644 index 0000000..5578451 --- /dev/null +++ b/pms-parent/pms-web-other/src/main/java/com/dy/pmsOther/dyFm/FileNameIdUtil.java @@ -0,0 +1,112 @@ +package com.dy.pmsOther.dyFm; + +import java.util.Calendar; + +public class FileNameIdUtil { + + private static int add = 0 ; + private static int chengShu = 1000 ; + private static int maxAdd = 999 ; + private static long last = 0 ; + + //鍚庣紑 + //鍦ㄥ垎甯冨紡绯荤粺涓紝渚嬪澶氫釜涓氬姟涓棿浠禿ataMw锛屽涓郴缁熼兘浼氬悜鏁版嵁搴撲腑鎻掑叆鏁版嵁锛岀敤鐨勯兘鏄ID鐢熸垚鍣紝 + //姝D鐢熸垚鍣ㄥ湪鍚勪釜瀛愮郴缁熶腑闅惧厤涓哄悓涓�绫绘暟鎹敓鎴愮浉鍚岀殑ID锛岄�犳垚鏁版嵁搴撴彃鍏ュ洜涓婚敭鐩稿悓鑰屾姤閿�, + //鎵�浠ヨ璁℃鍚庣紑锛屾瘡涓瓙绯荤粺鍚庣紑涓嶅悓 + private static String suffix = "0" ; + + static { + last = current() ; + } + + /** + * 涓鸿嚜瀹炵幇绋嬪簭鎻愪緵鐨処D鐢熸垚鍣� + * 15闀垮害ID锛屽勾搴﹀彇涓や綅锛屽鏋滄槸17浣嶉暱搴D锛屽勾搴﹀彇鍥涗綅锛岄偅17浣嶆暟瀛楄秴鍑轰簡javascript鐨勮〃鏁拌寖鍥� + */ + public String generate(){ + return doGenerate() ; + } + + /** + * 璁剧疆鍚庣紑锛屼笉鍚屽瓙绯荤粺璁剧疆涓嶅悓鐨勫悗缂� + * @param suffix + */ + public static void setSuffix(String suffix)throws Exception{ + if(suffix == null || suffix.trim().equals("")){ + throw new Exception("鍚庣紑涓嶈兘涓虹┖") ; + } + FileNameIdUtil.suffix = suffix.trim() ; + } + + /** + * 鎵ц鐢熸垚 + * @return + */ + private synchronized String doGenerate(){ + Long id = null ; + long now = current() ; + if(now != last){ + //涓婃鐢熸垚ID 涓庢湰娆$敓鎴怚D 涓嶅湪鍚屼竴绉掑唴 + last = now ; + add = 0 ; + id = last * chengShu + add ++; + }else{ + //涓婃鐢熸垚ID 涓庢湰娆$敓鎴怚D 鍦ㄥ悓涓�绉掑唴 + if(add == maxAdd){ + //闄勫姞閲忓凡缁忕敤灏� + waitNextSecond(last) ;//绛夊埌涓嬩竴绉� + id = last * chengShu + add ++ ;//杩斿洖涓婁竴绉掔敓鎴愮殑ID + add = 0 ;//闄勫姞閲忓綊闆讹紝涓轰笅涓�绉掑噯澶� + }else{ + //闄勫姞閲忔湭鐢ㄥ敖 + id = last * chengShu + add ++ ; + } + } + return id + suffix ; + } + /** + * 绛夊緟涓嬩竴绉掑埌鏉� + * @param last + */ + private void waitNextSecond(Long last){ + try { + Thread.sleep(10); + } catch (InterruptedException e) { + }finally{ + long now = current() ; + if(now == last){ + waitNextSecond(last) ; + } + } + } + + + + /** + * 鏍煎紡涓� 150516010203 + * @return + */ + private static long current(){ + Calendar cal = Calendar.getInstance(); + long d = (cal.get(Calendar.YEAR) % 100) * 10000000000L + + (cal.get(Calendar.MONTH) + 1) * 100000000L + + cal.get(Calendar.DAY_OF_MONTH) * 1000000L + + cal.get(Calendar.HOUR_OF_DAY) * 10000L + + cal.get(Calendar.MINUTE) * 100L + + cal.get(Calendar.SECOND) ; + + return d ; + } + + public static void main(String args[]){ + FileNameIdUtil o = new FileNameIdUtil() ; + int total = 800 ; + long start = System.currentTimeMillis() ; + for(int i = 0 ; i < total ; i++){ + System.out.println((String)(o.generate())) ; + } + long end = System.currentTimeMillis() ; + System.out.println("浜х敓" + total + "ID鐢ㄦ椂" + (end - start) + "姣"); + } + +} diff --git a/pms-parent/pms-web-other/src/main/java/com/dy/pmsOther/dyFm/FileRestVo.java b/pms-parent/pms-web-other/src/main/java/com/dy/pmsOther/dyFm/FileRestVo.java new file mode 100644 index 0000000..b176b10 --- /dev/null +++ b/pms-parent/pms-web-other/src/main/java/com/dy/pmsOther/dyFm/FileRestVo.java @@ -0,0 +1,28 @@ +package com.dy.pmsOther.dyFm; + +import lombok.Data; + +@Data +public class FileRestVo { + + public String fileName ; //鐢熸垚鐨勬枃浠跺悕绉帮紝渚嬪20170818153254_100000007.jpg + public Integer fileNameHash ; //鏂囦欢鍚嶇О鐨勫搱甯屽�� + public String fileSysId; //鏂囦欢鍚嶇О鐨勫搱甯屽�煎搴旂殑鏂囦欢绯荤粺鐨刬d锛屽湪閰嶇疆鏂囦欢涓厤缃� + public String fileSysAbsolutePath; //鏂囦欢鍚嶇О鐨勫搱甯屽�煎搴旂殑鏂囦欢鏈�缁堝瓨鍌ㄧ粷瀵硅矾寰勪腑鐨勬牴鐩綍锛屽湪閰嶇疆鏂囦欢涓厤缃� + public String fileSysRelativePath; //鏂囦欢鍚嶇О鐨勫搱甯屽�煎搴旂殑鏂囦欢鏈�缁堝瓨鍌ㄧ浉瀵硅矾寰勭殑鐩綍锛屽湪閰嶇疆鏂囦欢涓厤缃� + public String fileSysRestUrl; //鏂囦欢鍚嶇О鐨勫搱甯屽�煎搴旂殑鏂囦欢绯荤粺鐨剅estful URL锛屽湪閰嶇疆鏂囦欢涓厤缃� + public String fileWebUrl; //鏂囦欢鍚嶇О鐨勫搱甯屽�煎搴旂殑鏂囦欢绯荤粺鐨勪笅杞芥枃浠剁殑web URL锛屽湪閰嶇疆鏂囦欢涓厤缃� + public String fileWebDownloadUrl; //鏂囦欢鍚嶇О鐨勫搱甯屽�煎搴旂殑鏂囦欢绯荤粺鐨凙ction涓嬭浇鏂囦欢鐨剋eb URL锛屽湪閰嶇疆鏂囦欢涓厤缃� + + public String toString(){ + return "fileName=" + fileName + "\n" + + "fileNameHash=" + fileNameHash + "\n" + + "sysId=" + fileSysId + "\n" + + "fileSysAbsolutePath=" + fileSysAbsolutePath + "\n" + + "fileSysRelativePath=" + fileSysRelativePath + "\n" + + "restUrl=" + fileSysRestUrl + "\n" + + "fileWebUrl=" + fileWebUrl + "\n" + + "fileWebDownloadUrl=" + fileWebDownloadUrl ; + } + +} diff --git a/pms-parent/pms-web-other/src/main/java/com/dy/pmsOther/dyFm/FmCtrl.java b/pms-parent/pms-web-other/src/main/java/com/dy/pmsOther/dyFm/FmCtrl.java new file mode 100644 index 0000000..df8e93d --- /dev/null +++ b/pms-parent/pms-web-other/src/main/java/com/dy/pmsOther/dyFm/FmCtrl.java @@ -0,0 +1,133 @@ +package com.dy.pmsOther.dyFm; + +import lombok.extern.slf4j.Slf4j; +import org.springframework.http.MediaType; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.util.ArrayList; +import java.util.List; + +/** + * 鍗曠偣鐧诲綍锛� + */ +@Slf4j +@RestController +@RequestMapping(path="fm") +@SuppressWarnings("unchecked")//java鐗堟湰瓒婇珮锛屽娉涘瀷绾︽潫瓒婁弗锛屾墍浠ラ厤缃甋uppressWarnings("unchecked") +public class FmCtrl { + + /** + * 鐢熸垚鏂囦欢鍚嶏紝骞朵笖璁$畻鍑鸿鏂囦欢鍚嶅搴旂殑鏂囦欢鏈嶅姟鍣ㄥ睘鎬� + * 鏂囦欢鍚嶇О鏄笉甯﹁矾寰勭殑鍚嶇О锛屼緥濡傦細20170818153254_100000007.jpg锛屾枃浠跺悕涓笉鑳芥湁鈥�/鈥濇垨鈥淺鈥濆瓧绗� + * @param fileExtName 鏂囦欢鎵╁睍鍚� + * @return + */ + @PostMapping(path = "create") + public FileRestVo create(String fileExtName){ + FileRestVo rvo = new FileRestVo() ; + if(fileExtName != null && !fileExtName.trim().equals("")){ + try { + String id = new FileNameIdUtil().generate(); + if(id != null){ + rvo.fileName = FileName.createFileName(false, id, fileExtName) ; + rvo = new RestHashDeal().fileTransRest(rvo.fileName, rvo) ; + } + } catch (Exception e) { + e.printStackTrace(); + } + } + return rvo ; + } + + /** + * 瑙f瀽鏂囦欢鍚嶏紙甯︽垨涓嶅甫鐩稿璺緞锛夛紝璁$畻鍑鸿鏂囦欢鍚嶅搴旂殑鏂囦欢鏈嶅姟鍣ㄥ睘鎬� + * 鏂囦欢鍚嶇О鍙互鏄笉甯﹁矾寰勭殑鍚嶇О锛屼緥濡傦細20170818153254_100000007.jpg + * 鏂囦欢鍚嶇О鍙互鏄甫璺緞鐨勫悕绉帮紝渚嬪锛歸ebFile/photo/20170818153254_100000007.jpg + * @param filePath + * @return + */ + @PostMapping(path = "parsePath") + public FileRestVo parsePath(String filePath){ + FileRestVo rvo = new FileRestVo() ; + if(filePath != null && !filePath.trim().equals("")){ + try { + int index = filePath.lastIndexOf("\\") ; + if(index > 0){ + filePath = filePath.substring(index + 1); + } + index = filePath.lastIndexOf("/") ; + if(index > 0){ + filePath = filePath.substring(index + 1); + } + index = filePath.lastIndexOf("?") ; + if(index > 0){ + filePath = filePath.substring(0, index); + } + rvo.fileName = filePath ; + rvo = new RestHashDeal().fileTransRest(filePath, rvo) ; + } catch (Exception e) { + e.printStackTrace(); + } + } + return rvo ; + } + /** + * 瑙f瀽鏂囦欢鍚嶏紝骞朵笖璁$畻鍑鸿鏂囦欢鍚嶅搴旂殑鏂囦欢鏈嶅姟鍣ㄥ睘鎬� + * 鏂囦欢鍚嶇О鍙互鏄笉甯﹁矾寰勭殑鍚嶇О锛屼緥濡傦細20170818153254_100000007.jpg + * 鏂囦欢鍚嶇О鍙互鏄甫璺緞鐨勫悕绉帮紝渚嬪锛歸ebFile/photo/20170818153254_100000007.jpg + * @param filePaths + * @return + */ + @PostMapping(path = "parsePathList", consumes = MediaType.APPLICATION_JSON_VALUE)//鍓嶇鎻愪氦json鏁版嵁 + public FileRestVo[] parsePathList(List<String> filePaths){ + List<FileRestVo> rList = new ArrayList<FileRestVo>() ; + if(filePaths != null && filePaths.size() > 0){ + try { + for(String filePath : filePaths){ + FileRestVo rvo = new FileRestVo() ; + int index = filePath.lastIndexOf("\\") ; + if(index > 0){ + filePath = filePath.substring(index + 1); + } + index = filePath.lastIndexOf("/") ; + if(index > 0){ + filePath = filePath.substring(index + 1); + } + index = filePath.lastIndexOf("?") ; + if(index > 0){ + filePath = filePath.substring(0, index); + } + rvo.fileName = filePath ; + rvo = new RestHashDeal().fileTransRest(filePath, rvo) ; + rList.add(rvo) ; + } + } catch (Exception e) { + e.printStackTrace(); + } + } + return rList.toArray(new FileRestVo[0]) ; + } + + /** + * 瑙f瀽鍝堝笇鍊硷紝璁$畻鍑鸿鍝堝笇鍊煎搴旂殑鏂囦欢鏈嶅姟鍣ㄥ睘鎬� + * @param hashCode + * @return + */ + @PostMapping(path = "parseHashcode") + public FileRestVo parseHashcode(Integer hashCode){ + FileRestVo rvo = new FileRestVo() ; + if(hashCode != null){ + try { + rvo.fileName = null ; + rvo = new RestHashDeal().fileTransRest(hashCode, rvo) ; + } catch (Exception e) { + e.printStackTrace(); + } + } + return rvo ; + } + + +} diff --git a/pms-parent/pms-web-other/src/main/java/com/dy/pmsOther/dyFm/RestHashDeal.java b/pms-parent/pms-web-other/src/main/java/com/dy/pmsOther/dyFm/RestHashDeal.java new file mode 100644 index 0000000..2eba6d0 --- /dev/null +++ b/pms-parent/pms-web-other/src/main/java/com/dy/pmsOther/dyFm/RestHashDeal.java @@ -0,0 +1,95 @@ +package com.dy.pmsOther.dyFm; + +import com.dy.common.util.MurmurHash ; + +public class RestHashDeal { + + + /** + * 鏂囦欢鍚嶇О璁$畻杞崲 + * @param fileName + * @param rvo + * @return + * @throws Exception + */ + public FileRestVo fileTransRest(String fileName, FileRestVo rvo) throws Exception{ + if(fileName != null + && !fileName.trim().equals("") + && rvo != null){ + if(DyFmListener.dyFileGroup == null + || DyFmListener.dyFileGroup.list == null + || DyFmListener.dyFileGroup.list.size() == 0){ + throw new Exception("涓ラ噸閿欒锛屾枃浠舵湇鍔″櫒restful鏈厤缃紒") ; + }else{ + DyFileSvConf.Vo confVo = null ; + Integer hash = null ; + if(DyFmListener.dyFileGroup.list.size() == 1){ + confVo = DyFmListener.dyFileGroup.list.get(0) ; + }else{ + hash = new MurmurHash().hash16_plus(fileName) ; + for(DyFileSvConf.Vo lvo : DyFmListener.dyFileGroup.list){ + if(hash >= lvo.hashStart.intValue() + && hash <= lvo.hashEnd.intValue()){ + confVo = lvo ; + break ; + } + } + } + if(confVo != null){ + rvo.fileSysId = confVo.id; + rvo.fileNameHash = hash; + rvo.fileSysAbsolutePath = confVo.fileSysAbsolutePath; + rvo.fileSysRelativePath = confVo.fileSysRelativePath; + rvo.fileSysRestUrl = confVo.restUrl; + rvo.fileWebUrl = confVo.webUrl ; + rvo.fileWebDownloadUrl = confVo.webDownloadUrl ; + } + } + } + return rvo ; + } + + + /** + * 鍝堝笇鍊艰绠楄浆鎹� + * @param hashcode + * @param rvo + * @return + * @throws Exception + */ + public FileRestVo fileTransRest(Integer hashcode, FileRestVo rvo) throws Exception{ + if(hashcode != null + && rvo != null){ + if(DyFmListener.dyFileGroup == null + || DyFmListener.dyFileGroup.list == null + || DyFmListener.dyFileGroup.list.size() == 0){ + throw new Exception("涓ラ噸閿欒锛屾枃浠舵湇鍔″櫒restful鏈厤缃紒") ; + }else{ + DyFileSvConf.Vo confVo = null ; + Integer hash = hashcode ; + if(DyFmListener.dyFileGroup.list.size() == 1){ + confVo = DyFmListener.dyFileGroup.list.get(0) ; + }else{ + for(DyFileSvConf.Vo lvo : DyFmListener.dyFileGroup.list){ + if(hash >= lvo.hashStart.intValue() + && hash <= lvo.hashEnd.intValue()){ + confVo = lvo ; + break ; + } + } + } + if(confVo != null){ + rvo.fileSysId = confVo.id; + rvo.fileNameHash = hash; + rvo.fileSysAbsolutePath = confVo.fileSysAbsolutePath; + rvo.fileSysRelativePath = confVo.fileSysRelativePath; + rvo.fileSysRestUrl = confVo.restUrl; + rvo.fileWebUrl = confVo.webUrl ; + rvo.fileWebDownloadUrl = confVo.webDownloadUrl ; + } + } + } + return rvo ; + } + +} diff --git a/pms-parent/pom.xml b/pms-parent/pom.xml index aa88ff1..a1c8821 100644 --- a/pms-parent/pom.xml +++ b/pms-parent/pom.xml @@ -48,6 +48,8 @@ <!-- sso鐢ㄥ埌鐨勭紦瀛樻鏋� --> <spring-boot-starter-cache.version>3.2.4</spring-boot-starter-cache.version> <caffeine.version>3.1.8</caffeine.version> + <!-- 鐢熸垚鍥剧墖缂╃暐鍥� --> + <thumbnailator.version>0.4.20</thumbnailator.version> <spring-boot-maven-plugin.version>3.2.0</spring-boot-maven-plugin.version> <maven-jar-plugin-plugin.version>3.3.0</maven-jar-plugin-plugin.version> -- Gitblit v1.8.0