| | |
| | | package com.yuanchu.mom.utils; |
| | | |
| | | import org.springframework.stereotype.Component; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.Date; |
| | |
| | | * @return 返回随机加密盐 |
| | | */ |
| | | public static String getSalt(int n) { |
| | | char[] chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz01234567890!@#$%^&*()+-=/[];~.".toCharArray(); |
| | | char[] chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz01234567890!@$%^&*.?".toCharArray(); |
| | | StringBuilder sb = new StringBuilder(); |
| | | for (int i = 0; i < n; i++) { |
| | | char c = chars[new Random().nextInt(chars.length)]; |
| | |
| | | String sixIncr = String.format("%06d", incrNum); |
| | | return prefix + timeStr + sixIncr; |
| | | } |
| | | |
| | | /** |
| | | * 判断是否为excel |
| | | * @param file |
| | | * @return |
| | | */ |
| | | public static boolean isExcelFile(MultipartFile file) { |
| | | if (file.isEmpty()) { |
| | | return false; |
| | | } |
| | | String originalFilename = file.getOriginalFilename(); |
| | | if (originalFilename == null) { |
| | | return false; |
| | | } |
| | | String[] parts = originalFilename.split("\\."); |
| | | if (parts.length == 0) { |
| | | return false; |
| | | } |
| | | String fileExtension = parts[parts.length - 1].toLowerCase(); |
| | | return fileExtension.equals("xls") || fileExtension.equals("xlsx"); |
| | | } |
| | | } |