1140e68ad6e713998bdad9f6d9ed404651c9c4a3.svn-base 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352
  1. package cn.com.goldenwater.dcproj.utils;
  2. import org.apache.commons.collections.map.HashedMap;
  3. import java.text.DecimalFormat;
  4. import java.time.LocalDateTime;
  5. import java.util.Map;
  6. /**
  7. * Created by jinshui on 2019/11/13.
  8. */
  9. public class FormatFieldUtil {
  10. private FormatFieldUtil(){}
  11. private static Map<String,String> stbMap = new HashedMap();
  12. static {
  13. stbMap.put("1","前期与设计");
  14. stbMap.put("2","建设管理");
  15. stbMap.put("3","计划下达与执行");
  16. stbMap.put("4","资金使用与管理");
  17. stbMap.put("5","工程质量");
  18. stbMap.put("6","工程安全");
  19. }
  20. /**
  21. * 转换组类型
  22. * @param key
  23. * @return
  24. */
  25. public static String groupFormat(String key){
  26. if ("1".equals(key)) {
  27. return "一般库";
  28. }
  29. if ("2".equals(key)){
  30. return "备用库";
  31. }
  32. if ("3".equals(key)) {
  33. return "退役库";
  34. }
  35. if ("4".equals(key)){
  36. return "金名单";
  37. }
  38. if ("5".equals(key)) {
  39. return "红名单";
  40. }
  41. if ("6".equals(key)){
  42. return "蓝名单";
  43. }
  44. if ("7".equals(key)){
  45. return "见习专家库";
  46. }
  47. if ("一般库".equals(key)) {
  48. return "1";
  49. }
  50. if ("备用库".equals(key)){
  51. return "2";
  52. }
  53. if ("退役库".equals(key)) {
  54. return "3";
  55. }
  56. if ("金名单".equals(key)){
  57. return "4";
  58. }
  59. if ("红名单".equals(key)) {
  60. return "5";
  61. }
  62. if ("蓝名单".equals(key)){
  63. return "6";
  64. }
  65. if ("见习专家库".equals(key)){
  66. return "7";
  67. }
  68. return "";
  69. }
  70. /**
  71. * 转换角色类型
  72. * @param key
  73. * @return
  74. */
  75. public static String roleFormat(String key){
  76. if ("20".equals(key)) {
  77. return "特派员";
  78. }
  79. if ("19".equals(key)) {
  80. return "助理";
  81. }
  82. if ("11".equals(key)) {
  83. return "前期专家";
  84. }
  85. if ("12".equals(key)) {
  86. return "建管专家";
  87. }
  88. if ("13".equals(key)) {
  89. return "计划专家";
  90. }
  91. if ("14".equals(key)) {
  92. return "财务专家";
  93. }
  94. if ("15".equals(key)) {
  95. return "质量专家";
  96. }
  97. if ("16".equals(key)) {
  98. return "安全专家";
  99. }
  100. if ("特派员".equals(key)) {
  101. return "20";
  102. }
  103. if ("助理".equals(key)) {
  104. return "19";
  105. }
  106. if ("前期专家".equals(key)) {
  107. return "11";
  108. }
  109. if ("建管专家".equals(key)) {
  110. return "12";
  111. }
  112. if ("计划专家".equals(key)) {
  113. return "13";
  114. }
  115. if ("财务专家".equals(key)) {
  116. return "14";
  117. }
  118. if ("质量专家".equals(key)) {
  119. return "15";
  120. }
  121. if ("安全专家".equals(key)) {
  122. return "16";
  123. }
  124. return "";
  125. }
  126. /**
  127. * 转换学历
  128. * @param key
  129. * @return
  130. */
  131. public static String educationFormat(String key) {
  132. if ("1".equals(key)){
  133. return "专科及以下";
  134. }
  135. if ("2".equals(key)){
  136. return "本科";
  137. }
  138. if ("3".equals(key)){
  139. return "研究生";
  140. }
  141. if ("4".equals(key)){
  142. return "博士";
  143. }
  144. if ("专科及以下".equals(key)){
  145. return "1";
  146. }
  147. if ("本科".equals(key)){
  148. return "2";
  149. }
  150. if ("研究生".equals(key)){
  151. return "3";
  152. }
  153. if ("博士".equals(key)){
  154. return "4";
  155. }
  156. return "";
  157. }
  158. /**
  159. * @param key
  160. * @return
  161. */
  162. public static String unitRanksFormat(String key){
  163. if ("1".equals(key)) {
  164. return "省部级";
  165. }
  166. if ("2".equals(key)) {
  167. return "地市级";
  168. }
  169. if ("3".equals(key)) {
  170. return "县市级";
  171. }
  172. if ("省部级".equals(key)) {
  173. return "1";
  174. }
  175. if ("地市级".equals(key)) {
  176. return "2";
  177. }
  178. if ("县市级".equals(key)) {
  179. return "3";
  180. }
  181. return "";
  182. }
  183. public static String titlesFormat(String key){
  184. if ("1".equals(key)){
  185. return "正高";
  186. }
  187. if ("2".equals(key)){
  188. return "副高";
  189. }
  190. if ("3".equals(key)){
  191. return "中级";
  192. }
  193. if ("4".equals(key)){
  194. return "初级";
  195. }
  196. if ("正高".equals(key)){
  197. return "1";
  198. }
  199. if ("副高".equals(key)){
  200. return "2";
  201. }
  202. if ("中级".equals(key)){
  203. return "3";
  204. }
  205. if ("初级".equals(key)){
  206. return "4";
  207. }
  208. return "";
  209. }
  210. public static String commonFormat(String key){
  211. if ("1".equals(key)) {
  212. return "是";
  213. }
  214. if ("2".equals(key)) {
  215. return "否";
  216. }
  217. if ("是".equals(key)){
  218. return "1";
  219. }
  220. if ("否".equals(key)) {
  221. return "2";
  222. }
  223. return "";
  224. }
  225. public static String commonStateFormat(String key){
  226. if ("0".equals(key)) {
  227. return "未督查";
  228. }
  229. if ("1".equals(key)) {
  230. return "督查中";
  231. }
  232. if ("2".equals(key)) {
  233. return "已督查";
  234. }
  235. return "";
  236. }
  237. public static String commonReviConcFormat(String key) {
  238. if ("1".equals(key)) {
  239. return "已整改";
  240. }
  241. if ("2".equals(key)) {
  242. return "部分整改";
  243. }
  244. if ("3".equals(key)) {
  245. return "未整改";
  246. }
  247. return key;
  248. }
  249. public static String commonRectConcFormat(String key) {
  250. if ("1".equals(key)) {
  251. return "已销号";
  252. }
  253. if ("2".equals(key)) {
  254. return "未销号";
  255. }
  256. return key;
  257. }
  258. public static String commonPblmTypeFormat(String key) {
  259. if ("1".equals(key)) {
  260. return "乱占";
  261. }
  262. if ("2".equals(key)) {
  263. return "乱采";
  264. }
  265. if ("3".equals(key)) {
  266. return "乱堆";
  267. }
  268. if ("4".equals(key)) {
  269. return "乱建";
  270. }
  271. if ("5".equals(key)) {
  272. return "其他";
  273. }
  274. return key;
  275. }
  276. /**
  277. * 问题发生频度,定性一级分类转换
  278. * @param key
  279. * @return
  280. */
  281. public static String stbNameformat(String key) {
  282. if (key == null) {
  283. return "";
  284. }
  285. if (stbMap.containsKey(key)) {
  286. return stbMap.get(key);
  287. }
  288. if (stbMap.containsValue(key)) {
  289. for (String k : stbMap.keySet()) {
  290. if (key.equals(stbMap.get(k))) {
  291. return k;
  292. }
  293. }
  294. }
  295. return "";
  296. }
  297. /**
  298. * 根据身份证号计算年龄
  299. * @param idNo
  300. * @return
  301. */
  302. public static Double getAge(String idNo) {
  303. int year = Integer.valueOf(idNo.substring(6,10));
  304. Double month = Double.valueOf(idNo.substring(10,12));
  305. int day = Integer.valueOf(idNo.substring(12,14));
  306. LocalDateTime dateTime = LocalDateTime.now();
  307. int curYear = dateTime.getYear();
  308. Double curMonth = Double.valueOf(dateTime.getMonthValue());
  309. int curDay = dateTime.getDayOfMonth();
  310. int result = curYear - year;
  311. DecimalFormat df = new DecimalFormat("0.0");
  312. double decimal = 0;
  313. // compare month
  314. if (month > curMonth) {
  315. result --;
  316. decimal = curMonth / month;
  317. }
  318. if (month < curMonth) {
  319. decimal = (curMonth - month) / 12;
  320. }
  321. if (month.equals(curMonth)) {
  322. //compare day
  323. if (day > curDay) {
  324. result--;
  325. decimal = curDay / day;
  326. }
  327. if (day < curDay) {
  328. decimal = (curDay - day) / 365;
  329. }
  330. }
  331. return result + Double.valueOf(df.format(decimal));
  332. }
  333. }