47869f3f17c7c4b0a79f8676a5a396aa303703f4.svn-base 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. package cn.com.goldenwater.dcproj.utils.impexcel;
  2. import org.springframework.web.multipart.MultipartFile;
  3. import java.io.File;
  4. import java.util.Calendar;
  5. import java.util.regex.Matcher;
  6. import java.util.regex.Pattern;
  7. import static java.util.regex.Pattern.compile;
  8. /**
  9. * <p>
  10. * 一些公用的工具方法
  11. * </p>
  12. *
  13. * @author liyz
  14. * @date 2019/7/8 19:26
  15. **/
  16. public class ImpUtil {
  17. public static final String XLS = "xls";
  18. public static final String XLSX = "xlsx";
  19. public static final String ZIP = "zip";
  20. public static final String ALL = "ALL";
  21. public static final String ERR = "$E$";
  22. public static final String WARN = "$W$";
  23. public static boolean checkIsDate(String value) {
  24. Pattern pattern = compile("^\\d{4}(\\-|\\/|\\.)\\d{1,2}\\1\\d{1,2}$");
  25. Matcher isDate = pattern.matcher(value);
  26. return isDate.matches();
  27. }
  28. public static String getDateFormatPath(String basePath) {
  29. //按时间日期存文件
  30. Calendar dat = Calendar.getInstance();
  31. if (!basePath.endsWith("/")) {
  32. return basePath
  33. + File.separator + dat.get(Calendar.YEAR)
  34. + File.separator + (dat.get(Calendar.MONTH) + 1)
  35. + File.separator + dat.get(Calendar.DAY_OF_MONTH);
  36. } else {
  37. return basePath
  38. + dat.get(Calendar.YEAR)
  39. + File.separator + (dat.get(Calendar.MONTH) + 1)
  40. + File.separator + dat.get(Calendar.DAY_OF_MONTH);
  41. }
  42. }
  43. public static boolean checkFileExt(MultipartFile file, String fileExt) {
  44. if (file != null) {
  45. // 获取上传过来的名称
  46. String fileName = file.getOriginalFilename();
  47. // 获取扩展名称
  48. String ext = fileName.substring(1 + fileName.lastIndexOf("."));
  49. // 返回是否匹配,因为扩展名大小写不敏感,所以都转为小写进行比较
  50. return ext.toLowerCase().endsWith(fileExt.toLowerCase());
  51. } else {
  52. return false;
  53. }
  54. }
  55. public static boolean checkIsInt(String value) {
  56. if (value == null || "".equals(value)) {
  57. return false;
  58. }
  59. Pattern pattern = compile("[0-9]*");
  60. Matcher isNum = pattern.matcher(value);
  61. return isNum.matches();
  62. }
  63. }