Eos平台java公共逻辑
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
/** * 获取超时时间 * * @param startDate 开始时间 * @param endDate 结束时间 * @return 时间字符串,如5.20 */ @Bizlet() public static String getOutTime(Date startDate, Date endDate) { long minutes = (endDate.getTime() - startDate.getTime()) / (1000 * 60); long hours = minutes / 60; //System.out.println("hours = "+hours); long minute = minutes % 60; StringBuffer str = new StringBuffer(""); if (minute < 10) { str.append(hours + ".0" + minute); } else { str.append(hours + "." + minute); } // System.out.println("str = "+str); return str.toString(); } /** * 拆分字符串获取Ids * * @param idsString id字符串 * @param spiltCode 拆分符号 * @return ids * @author lqy */ @Bizlet() public static int[] getIdsAfterSpilt(String idsString, String spiltCode) { List<Integer> idList = new ArrayList<Integer>(); if (idsString == null || idsString.trim().equals("")) { return null; } else { if (spiltCode == null || spiltCode.trim().equals("")) { spiltCode = ","; } String[] idArray = idsString.split(spiltCode); if (idArray != null && idArray.length > 0) { for (String string : idArray) { if (string != null && !string.trim().equals("")) { idList.add(Integer.parseInt(string.trim())); } } } } if (idList != null && idList.size() > 0) { int[] ids = new int[idList.size()]; for (int j = 0; j < idList.size(); j++) { ids[j] = idList.get(j); } return ids; } return null; } /** * 拆分字符串获取数组 * * @param str 字符串 * @param spiltCode 拆分符号 * @return String[] * @author lqy */ @Bizlet() public static String[] getArrayAfterSpilt(String str, String spiltCode) { if (str == null || str.trim().equals("")) { return null; }else{ if (spiltCode == null || spiltCode.trim().equals("")) { spiltCode = ","; } return str.split(spiltCode); } } /** * 删除字符串最后一位 * * @param str 字符串 * @return str * @author lqy */ @Bizlet() public static String removeLastCode(String str) { if (str == null || str.trim().equals("")) { str = ""; } else { str = str.trim().substring(0, (str.trim().length() - 1)); } return str; } /** * 替换字符 * * @param str 字符串 * @param oldCode 需要替换的原字符 * @param newCode 替换的新字符 * @return str * @author lqy */ @Bizlet() public static String replaceCode(String str, String oldCode, String newCode) { if (str != null && !str.trim().equals("")) { if (oldCode == null || oldCode.trim().equals("")) { oldCode = " "; } if (newCode == null) { newCode = ""; } str = str.trim().replaceAll(oldCode, newCode); } return str; } /** * 获取第一个id * * @param str 字符串 * @return id * @author lqy */ @Bizlet() public static String getFirstId(String str, String spiltCode) { if (spiltCode == null) { spiltCode = ","; } if (str.indexOf(spiltCode) > -1) { str = str.substring(0, str.indexOf(spiltCode)); } return str.trim(); } /** * 去分支机构名称中的机构名称 * @param originalStr 原字符串 * @param deleteStr 需要去掉的字符串 * @return string * @author lqy */ @Bizlet() public static String removeSamePart(String originalStr, String deleteStr) { if (originalStr != null && deleteStr != null) { originalStr = originalStr.replaceAll("\\(", "("); originalStr = originalStr.replaceAll("\\)", ")"); originalStr = originalStr.replaceAll(" | ", ""); deleteStr = deleteStr.replaceAll("\\(", "("); deleteStr = deleteStr.replaceAll("\\)", ")"); deleteStr = deleteStr.replaceAll(" | ", ""); if (originalStr.indexOf(deleteStr) > -1) { originalStr = originalStr.replaceAll(deleteStr, ""); } } return originalStr; } /** * 时间加减天数 * * @param startDate 要处理的时间,Null则为当前时间 * @param days 加减的天数 * @return Date * @author lqy */ @Bizlet() public static Date getDate(Date startDate, int days) { if (startDate == null) { startDate = new Date(); } Calendar c = Calendar.getInstance(); c.setTime(startDate); c.set(Calendar.DATE, c.get(Calendar.DATE) + days); return c.getTime(); } /** * 获取某时间相差多少年前后的时间 * * @param startDate 要处理的时间,Null则为当前时间 * @param years 加减的年数 * @return Date * @author lqy */ @Bizlet() public static Date getDifferYearDate(Date startDate, int years) { if (startDate == null) { startDate = new Date(); } Calendar c = Calendar.getInstance(); c.setTime(startDate); c.set(Calendar.YEAR, c.get(Calendar.YEAR) + years); return c.getTime(); } /** * 时间比较(如果myDate>compareDate返回1,<返回-1,相等返回0) * * @param myDate 时间 * @param compareDate 要比较的时间 * @return int * @author lqy */ @Bizlet() public static int dateCompare(Date myDate, Date compareDate) { Calendar myCal = Calendar.getInstance(); Calendar compareCal = Calendar.getInstance(); myCal.setTime(myDate); compareCal.setTime(compareDate); return myCal.compareTo(compareCal); } /** * 根据登记牌判断是否为助理,是返回1,否返回0(默认是助理) * @param licenceNo 登记牌 * @return String * @author lqy */ @Bizlet() public static int isAssistant(String licenceNo) { int result = 1; if(licenceNo.toLowerCase().indexOf("jz") < 0){ result = 0; } return result; } @Bizlet() public static String formatTime(Date date, String pattern) { if(pattern == null || pattern.trim().equals("")){ pattern = "yyyy年MM月"; //pattern = "yyyy年MM月dd日 HH时mm分ss秒"; } return new SimpleDateFormat(pattern).format(date); }