Java tutorial
/** * @(#)UsrServiceImpl.java 2013-3-25 * * Copyright 2013 Neusoft Group Ltd. All rights reserved. * Neusoft PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. */ package com.neusoft.mid.clwapi.service.usr; import java.util.List; import javax.ws.rs.core.Context; import javax.ws.rs.core.HttpHeaders; import javax.ws.rs.core.Response; import org.apache.commons.lang.StringUtils; import org.apache.cxf.jaxrs.ext.MessageContext; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import com.neusoft.mid.clwapi.common.ErrorConstant; import com.neusoft.mid.clwapi.common.ModCommonConstant; import com.neusoft.mid.clwapi.common.UserInfoKey; import com.neusoft.mid.clwapi.entity.usr.ConsultantInfo; import com.neusoft.mid.clwapi.entity.usr.ConsultantInfoResp; import com.neusoft.mid.clwapi.entity.usr.UserBehavior; import com.neusoft.mid.clwapi.entity.usr.UserModifyPwdReq; import com.neusoft.mid.clwapi.exception.common.ApplicationException; import com.neusoft.mid.clwapi.mapper.UsrMapper; import com.neusoft.mid.clwapi.tools.CheckRequestParam; import com.neusoft.mid.clwapi.tools.JacksonUtils; /** * @author <a href="mailto:majch@neusoft.com">majch </a> * @version $Revision 1.0 $ 2013-3-25 ?8:50:21 */ public class UsrServiceImpl implements UsrService { /** * . */ private static Logger logger = LoggerFactory.getLogger(ModCommonConstant.LOGGER_NAME); @Autowired private UsrMapper usrMapper; @Context private MessageContext context; /** * ??. * * @param token * ?. * @param oldPwd * ?. * @return ??. */ @Override public Response checkOldPwd(String token, String oldPwd) { logger.info("????"); String userId = context.getHttpHeaders().getHeaderString("usr_id"); int userCount = usrMapper.getUserCountByPwd(userId, oldPwd); if (1 == userCount) { logger.info("ID:" + userId + "?" + oldPwd + ""); return Response.ok().header(HttpHeaders.CACHE_CONTROL, "no-store").header("Pragma", "no-cache").build(); } else { logger.info("ID:" + userId + "?" + oldPwd + "?"); return Response.status(Response.Status.NO_CONTENT).header(HttpHeaders.CACHE_CONTROL, "no-store") .header("Pragma", "no-cache").build(); } } /** * ??. * * @param token * ?. * @param modifyPwdInfo * ??. * @return ?. */ @Override public Response modifyPwd(String token, String modifyPwdInfo) { logger.info("???"); // ????? UserModifyPwdReq reqInfo = JacksonUtils.fromJsonRuntimeException(modifyPwdInfo, UserModifyPwdReq.class); if (null != reqInfo) { if (CheckRequestParam.isEmpty((reqInfo.getOldPwd())) || CheckRequestParam.isEmpty((reqInfo.getNewPwd()))) { logger.error("???[?]?"); // ??? throw new ApplicationException(ErrorConstant.ERROR10002, Response.Status.BAD_REQUEST); } else { String userId = context.getHttpHeaders().getHeaderString("usr_id"); int userCount = usrMapper.getUserCountByPwd(userId, reqInfo.getOldPwd()); if (1 == userCount) { usrMapper.updateUserPwd(userId, reqInfo.getOldPwd(), reqInfo.getNewPwd()); return Response.ok().header(HttpHeaders.CACHE_CONTROL, "no-store").header("Pragma", "no-cache") .build(); } else { logger.info("ID:" + userId + "?" + reqInfo.getOldPwd() + "?"); return Response.status(Response.Status.NO_CONTENT).header(HttpHeaders.CACHE_CONTROL, "no-store") .header("Pragma", "no-cache").build(); } } } else { logger.error("???"); throw new ApplicationException(ErrorConstant.ERROR10001, Response.Status.BAD_REQUEST); } } /** * ??. * * @param behaviorInfo * ?. * @return . */ @Override public Response behavior(String token, String behaviorInfo) { logger.info("???"); // ? UserBehavior userBehavior = JacksonUtils.fromJsonRuntimeException(behaviorInfo, UserBehavior.class); // ??? if (null != userBehavior) { // ???? if (StringUtils.isEmpty(StringUtils.strip(userBehavior.getModuleId())) || StringUtils.isEmpty(StringUtils.strip(userBehavior.getModuleSonId()))) { logger.error("??[?]?"); // ??? throw new ApplicationException(ErrorConstant.ERROR10002, Response.Status.BAD_REQUEST); } else { String userId = context.getHttpHeaders().getHeaderString(UserInfoKey.USR_ID); String enterpriseId = context.getHttpHeaders().getHeaderString(UserInfoKey.ENTERPRISE_ID); if (StringUtils.isEmpty(userId) || StringUtils.isEmpty(enterpriseId)) { logger.info("??USER_IDENTERPRISE_ID?"); // ??? throw new ApplicationException(ErrorConstant.ERROR90000, Response.Status.INTERNAL_SERVER_ERROR); } else { userBehavior.setUsrId(userId); userBehavior.setEntrepriseId(enterpriseId); // ??? usrMapper.insertUserBehavior(userBehavior); return Response.ok().build(); } } } else { logger.error("???"); throw new ApplicationException(ErrorConstant.ERROR10001, Response.Status.BAD_REQUEST); } } /** * ???. * * @param token * ?. * @return ??. */ @Override public Response consultant(String token) { String enterpriseId = context.getHttpHeaders().getHeaderString(UserInfoKey.ENTERPRISE_ID); if (StringUtils.isEmpty(enterpriseId)) { logger.error("???ID?"); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(ErrorConstant.ERROR90000.toJson()) .header(HttpHeaders.CACHE_CONTROL, "no-store").header("Pragma", "no-cache").build(); } else { ConsultantInfoResp consultantInfoResp = new ConsultantInfoResp(); List<ConsultantInfo> consultantList = usrMapper.getConsultantInfos(enterpriseId); if (null == consultantList || consultantList.size() == 0) { logger.info("???ID=" + enterpriseId + "?"); return Response.status(Response.Status.NO_CONTENT).header(HttpHeaders.CACHE_CONTROL, "no-store") .header("Pragma", "no-cache").build(); } else { consultantInfoResp.setConsultantList(consultantList); logger.info("???ID=" + enterpriseId + "?"); return Response.ok().entity(JacksonUtils.toJsonRuntimeException(consultantInfoResp)) .header(HttpHeaders.CACHE_CONTROL, "no-store").header("Pragma", "no-cache").build(); } } } }