YgEnumInterface.java 4.61 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171
/**
 * @date 2020年3月23日  
 * @author 翁东州
 * @方法中文名称:
 */
package cn.timer.api.config.enuminterface;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.regex.Pattern;


import lombok.Getter;

/**
 * @date 2020年3月23日  
 * @author 翁东州
 * @方法中文名称:
 */

public interface YgEnumInterface {
	/**
	 * 男女
	 */
	@Getter
	enum sex implements YgEnumInterface{
		MAN(0,"男"),WOMAN(1,"女");
		
		private Integer type;

		private String name;
		
		sex(Integer type, String name) {
			this.type = type;
			this.name = name;
		}
		public static String isMan(String index) {
			sex mow = (index == null || index.length() == 0) ? sex.MAN : (index.indexOf(sex.MAN.name)!= -1)||(index.indexOf(sex.MAN.type)!= -1) ? sex.MAN:sex.WOMAN;
			return mow.type.toString();			
		}
	}
	/**
	 * 员工类型
	 */
	@Getter
	enum YgJobType  implements YgEnumInterface{
		QUANZHI(1, "全"),SHIXI(2, "实习"),JIANZHI(3, "兼"),LWPQ(4, "劳务派遣"),
		LAOWU(5, "劳务"),PAIQIAN(6, "派遣"),WAIBAO(7, "外包"),TUIXIU(8, "退休");

		private Integer type;

		private String name;

		YgJobType(Integer type, String name) {
			this.type = type;
			this.name = name;
		}

		public static String choose(String index) {
			YgJobType result = YgJobType.QUANZHI;
			if(index == null || index.length() == 0) return result.type.toString();
			for (YgJobType item : YgJobType.values()) {
				if (index.indexOf(item.getType()) !=-1 ||index.indexOf(item.getName()) !=-1 ) result = item;
			}
			return result.type.toString();
		}
	}
	
	/**
	 * 员工状态
	 */
	@Getter
	enum jobStatus implements YgEnumInterface{
		ZHENSHI(0,"正式"),SHIYONG(1,"试用");
		
		private Integer type;

		private String name;
		
		jobStatus(Integer type, String name) {
			this.type = type;
			this.name = name;
		}
		public static String isZhen(String index) {
			jobStatus zos = (index == null || index.length() == 0) ? YgEnumInterface.jobStatus.ZHENSHI: (index.indexOf(jobStatus.ZHENSHI.name)!= -1)||(index.indexOf(jobStatus.ZHENSHI.type)!= -1) ? jobStatus.ZHENSHI:jobStatus.SHIYONG;
			return zos.type.toString();
		}
	}
	
	/**
	 * 入职日期
	 */
	@Getter
	enum rzTime  implements YgEnumInterface{
		ZHEN("--","yyyy-M-d"),XIE("//","yyyy/M/d"),
		DIAN("..","yyyy.M.d"),NYR("年月日","yyyy年M月d日");
		
		private String type;

		private String name;

		rzTime(String type, String name) {
			this.type = type;
			this.name = name;
		}
		
		public static String tranTime(String index) {
			DateFormat zhenFormat = new SimpleDateFormat(ZHEN.name);
			String result = zhenFormat.format(new Date());
			if (index == null || index.length() == 0) return result;
			Pattern pattern = Pattern.compile("^[0-9]{8}$"); 
		    if (pattern.matcher(index).matches()) {
				result = index.substring(0, 4) + "-" + index.substring(4, 6) + "-" + index.substring(6, 8);
				return result;
			}
			String s = index.replaceAll("([1-9]+[0-9]*|0)(\\.[\\d]+)?", "");
			for (rzTime item : rzTime.values()) {
				if (s.indexOf(item.type) != -1) {
					  DateFormat dateFormat = new SimpleDateFormat(item.name);
					try {
						result = new SimpleDateFormat(ZHEN.name).format(dateFormat.parse(index));
						return result;
					} catch (ParseException e) {
						e.printStackTrace();
						return result;
					}
				}
			}
			return result;
		}
		
		
		public static String tranTime2(String result) {
			String isYear ="^(?:(?!0000)[0-9]{4} -(?:(?:0[1-9]|1[0-2]) -(?:0[1-9]|1[0-9]|2[0-8]) |(?:0[13-9]|1[0-2]) -(?:29|30) |(?:0[13578]|1[02]) -31 )|(?:[0-9]{2}(?:0[48]|[2468][048]|[13579][26])|(?:0[48]|[2468][048]|[13579][26])00) -02 -29 )$";
			Pattern pattern = Pattern.compile(isYear);
			if (pattern.matcher(result).matches()) {
				return result;
			}else {
				 result = new SimpleDateFormat(ZHEN.name).format(new Date());
				return result;
			}
			
		}
	}
	/**
	 * 试用期
	 */
	@Getter
	enum syq implements YgEnumInterface{
		ZERO(0,"无"),ONE(1,"一"),TWO(2,"二"),THREE(3,"三"),FOUR(4,"四"),FIVE(5,"五"),SIX(6,"六");
		
		private Integer type;

		private String name;
		
		syq(Integer type, String name) {
			this.type = type;
			this.name = name;
		}
		public static String choose(String index) {
			syq result = syq.ZERO;
			if (index == null || index.length() == 0) result.type.toString();
			for (syq item : syq.values()) {
				if (index.indexOf(item.getName()) !=-1 ||index.indexOf(item.getType()) !=-1 ) result=item;
			}
			return result.type.toString();
		}
	}
}