@Override public void stop() { Logger.warn("can not stop client!"); }
@Override public boolean safeSet(String key, Object value, int expiration) { try { set(key, value, expiration); return true; } catch (Exception e) { Logger.warn(e.getMessage()); return false; } }
@Override public boolean safeAdd(String key, Object value, int expiration) { try { add(key, value, expiration); return true; } catch (Exception e) { Logger.warn(e.getMessage()); return false; } }
@Override public boolean safeReplace(String key, Object value, int expiration) { try { replace(key, value, expiration); return true; } catch (Exception e) { Logger.warn(e.getMessage()); return false; } }
@Override public boolean safeDelete(String key) { try { delete(key); return true; } catch (Exception e) { Logger.warn(e.getMessage()); return false; } }
/** * 债权表获取 偿还方式 * 默认 等额本息 * @param repayWay * @return * @throws Exception */ @Override public Repay queryRepayObj(String repayWay) throws Exception{ List<Repay> repayList = repayService.findByNameAndStatusIn(repayWay, Repay.Status.VALID); if(repayList == null || repayList.size() == 0){ Logger.warn("根据 偿还方式="+repayWay+"状态="+Repay.Status.VALID+",获取对象为空"); return null; }else{ return repayList.get(0); } } /**
/** * 解析并格式化时间日期字符串<br> * 如果发生异常返回默认字符串 * * @param parsePattern * @param formatPattern * @param source * @param defaultValue * @return */ public static String parseAndFormat(String parsePattern, String formatPattern, String source, String defaultValue) { try { return parseAndFormat(parsePattern, formatPattern, source); } catch (ParseException e) { Logger.warn(e.getMessage()); return defaultValue; } }
@Override public String getMessage(String key, Object... args) { try { return String.format(applicationContext.getMessage(key, null, getLocale()), args); } catch (Exception e) { Logger.warn(e.getMessage()); return key; } }
/** * 读取当前用户名称 * * @return */ public String getCurrentUserName() { try { String name = App.user().getName(); return name; } catch (Exception e) { Logger.warn("can not get current user id for reason: " + e.getMessage()); return null; } }
/** * 读取当前用户编号 * * @return */ public static String getCurrentUserId() { try { return App.user().getId(); } catch (Exception e) { Logger.warn("can not get current user id for reason: " + e.getMessage()); return null; } }
/** * 设置权限 */ protected void setAuthorities() { authorities = new LinkedList<GrantedAuthority>(); try { for (Role role: user.getRoles()) { authorities.add(new com.jlfex.hermes.service.security.GrantedAuthority(role)); } } catch (NullPointerException e) { Logger.warn("user %s has no role.", user.getEmail()); } } }
/** * 转换图片 * * @param file * @return */ public static String toBase64(File image) { InputStream is = null; try { is = new FileInputStream(image); byte[] bytes = new byte[(int) image.length()]; is.read(bytes); return toBase64(Files.getMimeType(image.getName()), bytes); } catch (FileNotFoundException e) { throw new ServiceException("cannot convert '" + image.getName() + "' to base64", e); } catch (IOException e) { throw new ServiceException("cannot convert '" + image.getName() + "' to base64", e); } finally { if (is != null) { try { is.close(); } catch (IOException e) { Logger.warn(e.getMessage()); } } } }
/** * 安全移除数据 * * @param key * @return */ public static boolean safeDelete(String key) { Logger.info("remove %s from cache.", key); if (getCache().safeDelete(key)) return true; Logger.warn("remove %s from cache failure!", key); return false; }
/** * 债权标 流标后 更新债权信息 状态 * @param loan */ public void creditAutoBidDeal(Loan loan) { try { if (loan != null) { String status = CrediteInfo.Status.WAIT_ASSIGN; CrediteInfo creditInfo = creditInfoRepository.findOne(loan.getCreditIndex()); Date deadTime = creditInfo.getDeadTime(); if (deadTime != null) { if (deadTime.before(new Date())) { status = CrediteInfo.Status.FAIL_ASSIGNING; } } creditInfo.setStatus(status); } else { Logger.warn("债权标 流标后 更新债权信息状态:标信息为空"); } } catch (Exception e) { Logger.error("债权标 流标更新债权信息 状态异常:", e); } }
Logger.warn("failure do job '%s'", this.getClass().getSimpleName());
/** * 安全替换数据 * * @param key * @param value * @param expiration * @return */ public static boolean safeReplace(String key, Object value, int expiration) { checkSerializable(value); Logger.info("replace %s - %s into cache for %d seconds.", key, value, expiration); if (getCache().safeReplace(key, value, expiration)) return true; Logger.warn("replace %s - %s into cache failure!", key, value); return false; }
/** * 安全设置数据 * * @param key * @param value * @param expiration * @return */ public static boolean safeSet(String key, Object value, int expiration) { checkSerializable(value); Logger.info("set %s - %s into cache for %d seconds.", key, value, expiration); if (getCache().safeSet(key, value, expiration)) return true; Logger.warn("set %s - %s into cache failure!", key, value); return false; }
@Override public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain) throws IOException, ServletException { if (!WebApp.isResource(req)) { String token = req.getParameter(PARAM_TOKEN); if (!Strings.empty(token)) { if (!Strings.equals(token, App.current().getToken())) { Logger.warn("token令牌不匹配: %s and %s.", token, App.current().getToken()); throw new ServiceException("token令牌不匹配:", "app.exception.token"); } String newToken = App.current().updateToken(); Logger.info("重新生成token="+newToken); } } chain.doFilter(req, resp); }
/** * 安全添加数据 * * @param key * @param value * @param expiration * @return */ public static boolean safeAdd(String key, Object value, int expiration) { checkSerializable(value); Logger.info("add %s - %s into cache for %d seconds.", key, Strings.toString(value), expiration); if (getCache().safeAdd(key, value, expiration)) return true; Logger.warn("add %s - %s into cache failure!", key, Strings.toString(value)); return false; }
try { if (Strings.empty(userId)) { Logger.warn("注销用户: 用户id为空!"); result.setType(com.jlfex.hermes.common.Result.Type.FAILURE); result.addMessage("注销用户: 用户id为空!");