YgEnumInterface.java 8.05 KB
Newer Older
1 2 3 4
package cn.timer.api.config.enuminterface;

import java.text.SimpleDateFormat;
import java.util.Date;
东州 翁 committed
5 6 7
import java.util.HashMap;
import java.util.List;
import java.util.Map;
8 9
import java.util.regex.Pattern;

东州 翁 committed
10
import cn.timer.api.dto.yggl.YgbintuDto;
11 12 13
import lombok.Getter;

/**
14
 * @date 2020年3月23日
15 16 17 18 19 20 21 22 23
 * @author 翁东州
 * @方法中文名称:
 */

public interface YgEnumInterface {
	/**
	 * 男女
	 */
	@Getter
24 25 26
	enum sex implements YgEnumInterface {
		MAN(0, "男"), WOMAN(1, "女");

27 28 29
		private Integer type;

		private String name;
30

31 32 33 34
		sex(Integer type, String name) {
			this.type = type;
			this.name = name;
		}
35

36
		public static String isMan(String index) {
37 38 39
			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();
40 41
		}
	}
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
	
	/**
	 * 部门 岗位
	 */
	@Getter
	enum OrgType implements YgEnumInterface {
		DEPARTMENT(0, "部门"), POST(1, "岗位");
		
		private Integer type;
		
		private String name;
		
		OrgType(Integer type, String name) {
			this.type = type;
			this.name = name;
		}
		
	}
60

61 62 63 64
	/**
	 * 员工类型
	 */
	@Getter
65 66 67
	enum YgJobType implements YgEnumInterface {
		QUANZHI(0, "全"), SHIXI(1, "实习"), JIANZHI(2, "兼"), LWPQ(3, "劳务派遣"), LAOWU(4, "劳务"), PAIQIAN(5, "派遣"),
		WAIBAO(6, "外包"), TUIXIU(7, "退休");
68 69 70 71 72 73 74 75 76 77 78 79

		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;
80 81
			if (index == null || index.length() == 0)
				return result.type.toString();
82
			for (YgJobType item : YgJobType.values()) {
83 84
				if (index.indexOf(item.getType()) != -1 || index.indexOf(item.getName()) != -1)
					result = item;
85 86 87 88
			}
			return result.type.toString();
		}
	}
89

90 91 92 93
	/**
	 * 员工状态
	 */
	@Getter
94
	enum jobStatus implements YgEnumInterface {
95
		SHIYONG(1, "试用"), ZHENSHI(2, "正式"), LIZHIZHONG(3, "离职中"), YILIZHI(4, "已离职");
96

97 98 99
		private Integer type;

		private String name;
100

101 102 103 104
		jobStatus(Integer type, String name) {
			this.type = type;
			this.name = name;
		}
105

106
		public static String isZhen(String index) {
107 108 109 110
			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;
111 112
			return zos.type.toString();
		}
113

114
	}
115

116 117 118 119
	/**
	 * 入职日期
	 */
	@Getter
120 121 122
	enum rzTime implements YgEnumInterface {
		ZHEN("--", "yyyy-M-d"), XIE("//", "yyyy/M/d"), DIAN("..", "yyyy.M.d"), NYR("年月日", "yyyy年M月d日");

123 124 125 126 127 128 129 130
		private String type;

		private String name;

		rzTime(String type, String name) {
			this.type = type;
			this.name = name;
		}
131

132
		public static String tranTime(String index) {
133
			// String str ="2013/11/12";
134 135 136
			if (index == null) {
				return null;
			}
137

东州 翁 committed
138 139 140 141 142
			String p = "年|月|日|号|时|/|//-";
			String result = index.replaceAll(p, "-");
			String p2 = "-$";
			String result2 = result.replaceAll(p2, "");
			return result2;
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

//		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;
//		}

171
		public static String tranTime2(String result) {
172
			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 )$";
173 174 175
			Pattern pattern = Pattern.compile(isYear);
			if (pattern.matcher(result).matches()) {
				return result;
176 177
			} else {
				result = new SimpleDateFormat(ZHEN.name).format(new Date());
178 179
				return result;
			}
180

181 182
		}
	}
183

184 185 186 187
	/**
	 * 试用期
	 */
	@Getter
188 189 190
	enum syq implements YgEnumInterface {
		ZERO(0, "无"), ONE(1, "一"), TWO(2, "二"), THREE(3, "三"), FOUR(4, "四"), FIVE(5, "五"), SIX(6, "六");

191 192 193
		private Integer type;

		private String name;
194

195 196 197 198
		syq(Integer type, String name) {
			this.type = type;
			this.name = name;
		}
199

200 201
		public static String choose(String index) {
			syq result = syq.ZERO;
202 203
			if (index == null || index.length() == 0)
				result.type.toString();
204
			for (syq item : syq.values()) {
205 206
				if (index.indexOf(item.getName()) != -1 || index.indexOf(item.getType()) != -1)
					result = item;
207 208 209 210
			}
			return result.type.toString();
		}
	}
211

东州 翁 committed
212 213 214 215
	/**
	 * 工龄
	 */
	@Getter
216 217 218 219 220
	enum workage implements YgEnumInterface {
		// NEW(0,183),HALF(1,365),ONE(2,548),ONEHALF(3,730),TWO(4,913),LONG(5,10000);
		NEW(0, 30, 0), ROOKIE(31, 183, 0), HALF(184, 365, 0), ONE(366, 548, 0), ONEHALF(549, 730, 0), TWO(731, 1000, 0),
		LONG(1001, 10000, 0);

东州 翁 committed
221 222 223
		private Integer begin;
		private Integer end;
		private Integer number;
224 225

		workage(Integer begin, Integer end, Integer number) {
东州 翁 committed
226 227 228 229
			this.begin = begin;
			this.end = end;
			this.number = number;
		}
230

东州 翁 committed
231 232 233 234
		public static Map<String, Integer> choose(List<YgbintuDto> bintu) {
			for (YgbintuDto b : bintu) {
				Integer index = b.getWorkage();
				for (workage item : workage.values()) {
235 236
					if (index >= item.begin && index <= item.end)
						item.number++;
东州 翁 committed
237 238 239
				}
			}
			Map<String, Integer> result = new HashMap<String, Integer>();
240
			result.put("本月新入职", NEW.number);
241
			result.put("x<0.5", NEW.number + ROOKIE.number);
东州 翁 committed
242 243 244 245 246
			result.put("0.5<x<1", HALF.number);
			result.put("1<x<1.5", ONE.number);
			result.put("1.5<x<2", ONEHALF.number);
			result.put("2<x<3", TWO.number);
			result.put("x++", LONG.number);
247 248 249 250 251 252 253
			NEW.number = 0;
			ROOKIE.number = 0;
			HALF.number = 0;
			ONE.number = 0;
			ONEHALF.number = 0;
			TWO.number = 0;
			LONG.number = 0;
254 255 256
			return result;
		}
	}
257

258 259 260 261
	/**
	 * 年龄
	 */
	@Getter
262 263 264 265
	enum age implements YgEnumInterface {
		// NEW(0,183),HALF(1,365),ONE(2,548),ONEHALF(3,730),TWO(4,913),LONG(5,10000);
		CHILD(1, 17, 0), TEEN(18, 25, 0), YOUNG(26, 32, 0), MAN(33, 38, 0), MIDDLE(39, 45, 0), OLD(46, 1000, 0);

266 267 268
		private Integer begin;
		private Integer end;
		private Integer number;
269 270

		age(Integer begin, Integer end, Integer number) {
271 272 273 274
			this.begin = begin;
			this.end = end;
			this.number = number;
		}
275

276 277 278 279 280 281 282
		public static Map<String, Integer> choose(List<YgbintuDto> bintu) {
			Integer average = 0;
			Integer i = 0;
			Integer j = 0;
			for (YgbintuDto b : bintu) {
				Integer index = b.getAge();
				for (; i < age.values().length; i++) {
283 284 285
					if (index >= age.values()[i].begin && index <= age.values()[i].end)
						age.values()[i].number++;
					j++;
286 287 288 289 290 291 292 293 294 295
				}
				average = average + index;
			}
			Map<String, Integer> result = new HashMap<String, Integer>();
			result.put("18以下", CHILD.number);
			result.put("18-25", TEEN.number);
			result.put("25-32", YOUNG.number);
			result.put("32-38", MAN.number);
			result.put("38-45", MIDDLE.number);
			result.put("45以上", OLD.number);
296
			Integer pInjun = j > 0 ? (average / j) : 0;
297
			result.put("平均年龄", pInjun);
298 299 300 301 302 303
			CHILD.number = 0;
			TEEN.number = 0;
			YOUNG.number = 0;
			MAN.number = 0;
			MIDDLE.number = 0;
			OLD.number = 0;
东州 翁 committed
304 305 306
			return result;
		}
	}
307
}