| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352 |
- package cn.com.goldenwater.dcproj.utils;
- import org.apache.commons.collections.map.HashedMap;
- import java.text.DecimalFormat;
- import java.time.LocalDateTime;
- import java.util.Map;
- /**
- * Created by jinshui on 2019/11/13.
- */
- public class FormatFieldUtil {
- private FormatFieldUtil(){}
- private static Map<String,String> stbMap = new HashedMap();
- static {
- stbMap.put("1","前期与设计");
- stbMap.put("2","建设管理");
- stbMap.put("3","计划下达与执行");
- stbMap.put("4","资金使用与管理");
- stbMap.put("5","工程质量");
- stbMap.put("6","工程安全");
- }
- /**
- * 转换组类型
- * @param key
- * @return
- */
- public static String groupFormat(String key){
- if ("1".equals(key)) {
- return "一般库";
- }
- if ("2".equals(key)){
- return "备用库";
- }
- if ("3".equals(key)) {
- return "退役库";
- }
- if ("4".equals(key)){
- return "金名单";
- }
- if ("5".equals(key)) {
- return "红名单";
- }
- if ("6".equals(key)){
- return "蓝名单";
- }
- if ("7".equals(key)){
- return "见习专家库";
- }
- if ("一般库".equals(key)) {
- return "1";
- }
- if ("备用库".equals(key)){
- return "2";
- }
- if ("退役库".equals(key)) {
- return "3";
- }
- if ("金名单".equals(key)){
- return "4";
- }
- if ("红名单".equals(key)) {
- return "5";
- }
- if ("蓝名单".equals(key)){
- return "6";
- }
- if ("见习专家库".equals(key)){
- return "7";
- }
- return "";
- }
- /**
- * 转换角色类型
- * @param key
- * @return
- */
- public static String roleFormat(String key){
- if ("20".equals(key)) {
- return "特派员";
- }
- if ("19".equals(key)) {
- return "助理";
- }
- if ("11".equals(key)) {
- return "前期专家";
- }
- if ("12".equals(key)) {
- return "建管专家";
- }
- if ("13".equals(key)) {
- return "计划专家";
- }
- if ("14".equals(key)) {
- return "财务专家";
- }
- if ("15".equals(key)) {
- return "质量专家";
- }
- if ("16".equals(key)) {
- return "安全专家";
- }
- if ("特派员".equals(key)) {
- return "20";
- }
- if ("助理".equals(key)) {
- return "19";
- }
- if ("前期专家".equals(key)) {
- return "11";
- }
- if ("建管专家".equals(key)) {
- return "12";
- }
- if ("计划专家".equals(key)) {
- return "13";
- }
- if ("财务专家".equals(key)) {
- return "14";
- }
- if ("质量专家".equals(key)) {
- return "15";
- }
- if ("安全专家".equals(key)) {
- return "16";
- }
- return "";
- }
- /**
- * 转换学历
- * @param key
- * @return
- */
- public static String educationFormat(String key) {
- if ("1".equals(key)){
- return "专科及以下";
- }
- if ("2".equals(key)){
- return "本科";
- }
- if ("3".equals(key)){
- return "研究生";
- }
- if ("4".equals(key)){
- return "博士";
- }
- if ("专科及以下".equals(key)){
- return "1";
- }
- if ("本科".equals(key)){
- return "2";
- }
- if ("研究生".equals(key)){
- return "3";
- }
- if ("博士".equals(key)){
- return "4";
- }
- return "";
- }
- /**
- * @param key
- * @return
- */
- public static String unitRanksFormat(String key){
- if ("1".equals(key)) {
- return "省部级";
- }
- if ("2".equals(key)) {
- return "地市级";
- }
- if ("3".equals(key)) {
- return "县市级";
- }
- if ("省部级".equals(key)) {
- return "1";
- }
- if ("地市级".equals(key)) {
- return "2";
- }
- if ("县市级".equals(key)) {
- return "3";
- }
- return "";
- }
- public static String titlesFormat(String key){
- if ("1".equals(key)){
- return "正高";
- }
- if ("2".equals(key)){
- return "副高";
- }
- if ("3".equals(key)){
- return "中级";
- }
- if ("4".equals(key)){
- return "初级";
- }
- if ("正高".equals(key)){
- return "1";
- }
- if ("副高".equals(key)){
- return "2";
- }
- if ("中级".equals(key)){
- return "3";
- }
- if ("初级".equals(key)){
- return "4";
- }
- return "";
- }
- public static String commonFormat(String key){
- if ("1".equals(key)) {
- return "是";
- }
- if ("2".equals(key)) {
- return "否";
- }
- if ("是".equals(key)){
- return "1";
- }
- if ("否".equals(key)) {
- return "2";
- }
- return "";
- }
- public static String commonStateFormat(String key){
- if ("0".equals(key)) {
- return "未督查";
- }
- if ("1".equals(key)) {
- return "督查中";
- }
- if ("2".equals(key)) {
- return "已督查";
- }
- return "";
- }
- public static String commonReviConcFormat(String key) {
- if ("1".equals(key)) {
- return "已整改";
- }
- if ("2".equals(key)) {
- return "部分整改";
- }
- if ("3".equals(key)) {
- return "未整改";
- }
- return key;
- }
- public static String commonRectConcFormat(String key) {
- if ("1".equals(key)) {
- return "已销号";
- }
- if ("2".equals(key)) {
- return "未销号";
- }
- return key;
- }
- public static String commonPblmTypeFormat(String key) {
- if ("1".equals(key)) {
- return "乱占";
- }
- if ("2".equals(key)) {
- return "乱采";
- }
- if ("3".equals(key)) {
- return "乱堆";
- }
- if ("4".equals(key)) {
- return "乱建";
- }
- if ("5".equals(key)) {
- return "其他";
- }
- return key;
- }
- /**
- * 问题发生频度,定性一级分类转换
- * @param key
- * @return
- */
- public static String stbNameformat(String key) {
- if (key == null) {
- return "";
- }
- if (stbMap.containsKey(key)) {
- return stbMap.get(key);
- }
- if (stbMap.containsValue(key)) {
- for (String k : stbMap.keySet()) {
- if (key.equals(stbMap.get(k))) {
- return k;
- }
- }
- }
- return "";
- }
- /**
- * 根据身份证号计算年龄
- * @param idNo
- * @return
- */
- public static Double getAge(String idNo) {
- int year = Integer.valueOf(idNo.substring(6,10));
- Double month = Double.valueOf(idNo.substring(10,12));
- int day = Integer.valueOf(idNo.substring(12,14));
- LocalDateTime dateTime = LocalDateTime.now();
- int curYear = dateTime.getYear();
- Double curMonth = Double.valueOf(dateTime.getMonthValue());
- int curDay = dateTime.getDayOfMonth();
- int result = curYear - year;
- DecimalFormat df = new DecimalFormat("0.0");
- double decimal = 0;
- // compare month
- if (month > curMonth) {
- result --;
- decimal = curMonth / month;
- }
- if (month < curMonth) {
- decimal = (curMonth - month) / 12;
- }
- if (month.equals(curMonth)) {
- //compare day
- if (day > curDay) {
- result--;
- decimal = curDay / day;
- }
- if (day < curDay) {
- decimal = (curDay - day) / 365;
- }
- }
- return result + Double.valueOf(df.format(decimal));
- }
- }
|