@Override public UserResult getUserByName(String loginname) { UserResult ur = new UserResult(); try { if (!StringUtils.isBlank(loginname)) { User user = userService.findByLoginName(loginname); if (user != null) { if (user.getUsertype() == 2) { BusinessUserDetail businessUserdetail = businessUserDetailService.findByUserId(user.getId()); BusinessUserEntity businessUserVO = ConvertHelper.toBusinessUserEntity(user, businessUserdetail); ur.setBusinessUser(businessUserVO); } else { UserDetail userdetail = userDetailService.findByUserId(user.getId()); UserEntity userVO = ConvertHelper.toUserEntity(user, userdetail); ur.setUser(userVO); } } } ur.setErrorCode(0); ur.setErrorMessage(""); } catch (Exception ex) { ValidationError ve = ValidationError.SYSTEM_ERROR; ur.setErrorCode(ve.getErrorCode()); ur.setErrorMessage("系统错误"); logger.error(ex.getMessage()); } return ur; }
/** 修改企业用户 */ @Override public UserResult updateBusinessUser(BusinessUserEntity bu) { UserResult ur = new UserResult(); try { if (bu != null) { BusinessUserDetail businessUserdetail = null; String id = bu.getId(); int userid = 0; if (!StringUtils.isBlank(id)) { userid = Integer.parseInt(id); updateUserCommon( id, bu.getName(), bu.getPhone(), null, null, null, null, null, null, null); businessUserdetail = businessUserDetailService.findByUserId(userid); } if (userid > 0) { Date date = new Date(); if (businessUserdetail == null) { businessUserdetail = new BusinessUserDetail(); businessUserdetail.setUserid(userid); businessUserdetail.setCreateDate(date); } businessUserdetail.setAddress(bu.getAddress()); businessUserdetail.setBusinesslicence(bu.getBusinesslicence()); businessUserdetail.setContactor(bu.getContactor()); businessUserdetail.setIdentitycard(bu.getIdentitycard()); businessUserdetail.setScope(bu.getScope()); businessUserdetail.setZuoji(bu.getZuoji()); businessUserdetail.setUpdateDate(date); businessUserDetailService.saveOrUpdate(businessUserdetail); String uid = bu.getId(); if (StringUtils.isNotBlank(uid)) { User busr = userService.findById(Integer.parseInt(uid)); if (busr != null) { BusinessUserEntity busrEntity = ConvertHelper.toBusinessUserEntity(busr, businessUserdetail); ur.setBusinessUser(busrEntity); ur.setErrorCode(0); ur.setErrorMessage(""); } else { ValidationError er = ValidationError.USER_NOEXIST; int errorCode = er.getErrorCode(); String errorMessage = er.getErrorMessage(); ur.setErrorCode(errorCode); ur.setErrorMessage(errorMessage); } } } } } catch (Exception ex) { ValidationError ve = ValidationError.SYSTEM_ERROR; ur.setErrorCode(ve.getErrorCode()); ur.setErrorMessage("系统错误"); logger.error(ex.getMessage()); } return ur; }
@Override public UserResult getBusinessUser(String id) { UserResult ur = new UserResult(); try { if (!StringUtils.isBlank(id)) { User user = userService.findById(Integer.valueOf(id)); if (user != null) { BusinessUserDetail userdetail = businessUserDetailService.findByUserId(Integer.parseInt(id)); BusinessUserEntity userVO = ConvertHelper.toBusinessUserEntity(user, userdetail); ur.setBusinessUser(userVO); } } ur.setErrorCode(0); ur.setErrorMessage(""); } catch (Exception ex) { ValidationError ve = ValidationError.SYSTEM_ERROR; ur.setErrorCode(ve.getErrorCode()); ur.setErrorMessage("系统错误"); logger.error(ex.getMessage()); } return ur; }
/** 登录服务 return UserResult */ @Override public UserResult login(UserEntity user) { UserResult ur = new UserResult(); try { String username = user.getLoginname(); String password = MD5Util.md5(user.getPwd()); User u = null; u = userService.findByLoginNameAndPwd(username, password); if (u == null) { ValidationError er = ValidationError.LOGINFAILE; int errorCode = er.getErrorCode(); String errorMessage = er.getErrorMessage(); ur.setErrorCode(errorCode); ur.setErrorMessage(errorMessage); } else { if (u.getUsertype() == 2) { BusinessUserDetail businessUserdetail = businessUserDetailService.findByUserId(u.getId()); BusinessUserEntity businessUserVO = ConvertHelper.toBusinessUserEntity(u, businessUserdetail); ur.setBusinessUser(businessUserVO); } else { UserDetail userdetail = userDetailService.findByUserId(u.getId()); UserEntity userVO = ConvertHelper.toUserEntity(u, userdetail); ur.setUser(userVO); } ur.setErrorCode(0); ur.setErrorMessage(""); } } catch (Exception ex) { ValidationError er = ValidationError.SYSTEM_ERROR; ur.setErrorCode(er.getErrorCode()); ur.setErrorMessage("系统错误"); logger.error(ex.getMessage()); } return ur; }