YgEnumInterface.java 8.1 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
import io.swagger.annotations.ApiModelProperty;
12 13 14
import lombok.Getter;

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

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

28 29 30
		private Integer type;

		private String name;
31

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

37
		public static String isMan(String index) {
38 39 40
			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();
41 42
		}
	}
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
	
	/**
	 * 部门 岗位
	 */
	@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;
		}
		
	}
61
	
62 63 64 65
	/**
	 * 员工类型
	 */
	@Getter
66
	enum YgJobType implements YgEnumInterface {
67
		QUANZHI(0, "全职"), SHIXI(1, "实习"), JIANZHI(2, "兼职"), LWPQ(3, "劳务派遣"), LAOWU(4, "劳务"), PAIQIAN(5, "派遣"),
68
		WAIBAO(6, "外包"), TUIXIU(7, "退休");
69 70 71 72 73 74 75 76 77 78 79 80

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

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

98 99 100
		private Integer type;

		private String name;
101

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

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

115
	}
116

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

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

		private String name;

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

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

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

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

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

182 183
		}
	}
184

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

192 193 194
		private Integer type;

		private String name;
195

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

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

东州 翁 committed
213 214 215 216
	/**
	 * 工龄
	 */
	@Getter
217 218 219 220 221
	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
222 223 224
		private Integer begin;
		private Integer end;
		private Integer number;
225 226

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

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

259 260 261 262
	/**
	 * 年龄
	 */
	@Getter
263 264 265 266
	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);

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

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

277 278 279 280 281 282 283
		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++) {
284 285 286
					if (index >= age.values()[i].begin && index <= age.values()[i].end)
						age.values()[i].number++;
					j++;
287 288 289 290 291 292 293 294 295 296
				}
				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);
297
			Integer pInjun = j > 0 ? (average / j) : 0;
298
			result.put("平均年龄", pInjun);
299 300 301 302 303 304
			CHILD.number = 0;
			TEEN.number = 0;
			YOUNG.number = 0;
			MAN.number = 0;
			MIDDLE.number = 0;
			OLD.number = 0;
东州 翁 committed
305 306 307
			return result;
		}
	}
308
}