| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 |
- package cn.com.goldenwater.dcproj.utils.impexcel;
- import org.springframework.web.multipart.MultipartFile;
- import java.io.File;
- import java.util.Calendar;
- import java.util.regex.Matcher;
- import java.util.regex.Pattern;
- import static java.util.regex.Pattern.compile;
- /**
- * <p>
- * 一些公用的工具方法
- * </p>
- *
- * @author liyz
- * @date 2019/7/8 19:26
- **/
- public class ImpUtil {
- public static final String XLS = "xls";
- public static final String XLSX = "xlsx";
- public static final String ZIP = "zip";
- public static final String ALL = "ALL";
- public static final String ERR = "$E$";
- public static final String WARN = "$W$";
- public static boolean checkIsDate(String value) {
- Pattern pattern = compile("^\\d{4}(\\-|\\/|\\.)\\d{1,2}\\1\\d{1,2}$");
- Matcher isDate = pattern.matcher(value);
- return isDate.matches();
- }
- public static String getDateFormatPath(String basePath) {
- //按时间日期存文件
- Calendar dat = Calendar.getInstance();
- if (!basePath.endsWith("/")) {
- return basePath
- + File.separator + dat.get(Calendar.YEAR)
- + File.separator + (dat.get(Calendar.MONTH) + 1)
- + File.separator + dat.get(Calendar.DAY_OF_MONTH);
- } else {
- return basePath
- + dat.get(Calendar.YEAR)
- + File.separator + (dat.get(Calendar.MONTH) + 1)
- + File.separator + dat.get(Calendar.DAY_OF_MONTH);
- }
- }
- public static boolean checkFileExt(MultipartFile file, String fileExt) {
- if (file != null) {
- // 获取上传过来的名称
- String fileName = file.getOriginalFilename();
- // 获取扩展名称
- String ext = fileName.substring(1 + fileName.lastIndexOf("."));
- // 返回是否匹配,因为扩展名大小写不敏感,所以都转为小写进行比较
- return ext.toLowerCase().endsWith(fileExt.toLowerCase());
- } else {
- return false;
- }
- }
- public static boolean checkIsInt(String value) {
- if (value == null || "".equals(value)) {
- return false;
- }
- Pattern pattern = compile("[0-9]*");
- Matcher isNum = pattern.matcher(value);
- return isNum.matches();
- }
- }
|