Java tutorial
/* * Project: min-portal-web-home * * File Created at 2014-5-13 * * Copyright 2012 Greenline.com Corporation Limited. * All rights reserved. * * This software is the confidential and proprietary information of * Greenline Company. ("Confidential Information"). You shall not * disclose such Confidential Information and shall use it only in * accordance with the terms of the license agreement you entered into * with Greenline.com. */ package com.greenline.guahao.web.module.home.controllers.vip; import java.util.List; import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; import org.apache.commons.lang.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.springframework.stereotype.Controller; import org.springframework.ui.ModelMap; import org.springframework.web.bind.annotation.ModelAttribute; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.ResponseBody; import com.greenline.common.util.RegexUtil; import com.greenline.guahao.biz.enums.VCodeCachePrefixEnum; import com.greenline.guahao.biz.enums.VerifyTypeEnum; import com.greenline.guahao.biz.manager.cache.valid.CodeCacheManager; import com.greenline.guahao.biz.manager.common.LocalResponseDO; import com.greenline.guahao.biz.manager.hrs.DepartmentManager; import com.greenline.guahao.biz.manager.hrs.ExpertManager; import com.greenline.guahao.biz.manager.hrs.dataobject.ExpertDO; import com.greenline.guahao.biz.manager.hrs.dataobject.HospitalDepartmentDO; import com.greenline.guahao.biz.manager.order.ShiftCaseManager; import com.greenline.guahao.biz.manager.order.dataobject.ShiftCaseDO; import com.greenline.guahao.biz.manager.orderremind.OrderRemindManager; import com.greenline.guahao.biz.manager.orderremind.dataobject.OrderRemindDO; import com.greenline.guahao.biz.manager.orderremind.dataobject.OrderRemindProfileDO; import com.greenline.guahao.biz.manager.user.UserManager; import com.greenline.guahao.biz.manager.user.dataobject.UserDO; import com.greenline.guahao.biz.manager.user.result.UserResult; import com.greenline.guahao.biz.util.HttpClientUtil; import com.greenline.guahao.web.module.common.annotation.MethodRemark; import com.greenline.guahao.web.module.common.constants.GlobalConstants; import com.greenline.guahao.web.module.common.constants.UserProfileConstants; import com.greenline.guahao.web.module.common.cookie.CookieUser; import com.greenline.guahao.web.module.common.cookie.UserCookieUtil; import com.greenline.guahao.web.module.common.json.BaseJsonObject; import com.greenline.guahao.web.module.common.utils.CommonUtils; import com.greenline.guahao.web.module.home.controllers.expert.ExpertProcess; import com.greenline.guahao.web.module.home.controllers.pub.orderremind.OrderRemindProcessor; /** * @Type OrderRemindController * @Desc ??? * @author alex * @date 2014-5-13 * @Version V1.0 */ @Controller @RequestMapping("/vip/orderremind") public class OrderRemindController { private static final Log logger = LogFactory.getLog(OrderRemindController.class); /** * ? */ private static final String PATH_PRE = "/vip/orderremind/"; /** * ?? */ private static final String FTL_PRE = "vip/orderremind/"; @Resource private HttpServletRequest request; @Resource private OrderRemindManager orderRemindManager; @Resource private ExpertManager expertManager; @Resource private ShiftCaseManager shiftCaseManager; @Resource private ExpertProcess expertProcess; @Resource private DepartmentManager departmentManager; @Resource private UserManager userManager; @Resource private CodeCacheManager codeCacheManager; @Resource private OrderRemindProcessor orderRemindProcessor; /** * ????? * * @param model * @param expertId ? * @param hospDeptId ? * @return */ @RequestMapping("/countconfirm/{eid}/{hdid}") @MethodRemark("remark=?????") public String goCountConfirm(ModelMap model, @PathVariable("eid") String expertId, @PathVariable("hdid") String hospDeptId) { model.put("expertId", expertId); model.put("hospDeptId", hospDeptId); if (UserCookieUtil.isLogin(request)) { CookieUser user = UserCookieUtil.getUserCookie(request); model.put("user", user); LocalResponseDO<Object> lrd = new LocalResponseDO<Object>(); OrderRemindProfileDO count = orderRemindManager.findOrderRemindCount(lrd, orderRemindProcessor.getCurrentUser()); if (lrd.isSuccess()) { model.put("count", count); if (null == UserCookieUtil.getCustomerId(request) && !orderRemindProcessor.pushCustomerIdToCookieAfterLogin()) { return CommonUtils.goErrorPage(model, "???"); } } else { return CommonUtils.goErrorPage(model, lrd.getMessage()); } } return FTL_PRE + "count_confirm"; } /** * ???? * * @param model * @param expertId ? * @param hospDeptId ? * @return */ @RequestMapping("/goapply/{eid}/{hdid}") @MethodRemark("remark=????") public String goApply(ModelMap model, @PathVariable("eid") String expertId, @PathVariable("hdid") String hospDeptId) { String result = checkUserInfo(); if (null != result) { return result; } ExpertDO expert = expertManager.getExpert(expertId); if (null == expert) { logger.warn(String.format("[%S]??", expertId)); return CommonUtils.goErrorPage(model, "??"); } else { model.put("expert", expert); // ?? expertProcess.setExpertCommentAndFavoriteCount(expert); } model.put("user", orderRemindProcessor.getCurrentUser()); if (StringUtils.isNotBlank(hospDeptId)) { if (hospDeptId.indexOf(",") > 0) { logger.warn( String.format("??%s?", hospDeptId)); hospDeptId = hospDeptId.substring(0, hospDeptId.indexOf(",")); } model.put("deptId", hospDeptId); HospitalDepartmentDO hospDept = departmentManager.getHospitalDept(hospDeptId); if (null != hospDept && StringUtils.isNotBlank(hospDept.getName())) { model.put("deptName", hospDept.getName()); } } else { logger.error("?"); return CommonUtils.goErrorPage(model, "?"); } LocalResponseDO<Object> lrd = new LocalResponseDO<Object>(); List<ShiftCaseDO> shiftCases = shiftCaseManager.listStaticShiftCases(lrd, expertId, hospDeptId); if (lrd.isSuccess()) { if (null == shiftCases || shiftCases.size() == 0) { return CommonUtils.goErrorPage(model, "???"); } model.put("shiftCases", shiftCases); } else { return CommonUtils.goErrorPage(model, "??"); } return FTL_PRE + "apply"; } /** * ???? * * @param model * @param orderRemind ? * @return */ @RequestMapping(value = "/apply", method = RequestMethod.POST) @MethodRemark("remark=????,method=post") public String apply(ModelMap model, @ModelAttribute("apply") OrderRemindDO apply) { LocalResponseDO<Object> lrd = new LocalResponseDO<Object>(); UserDO user = orderRemindProcessor.getCurrentUser(); apply.setUserId(user.getUserId().toString()); // ? apply.setUserName(user.getUserName()); // ?? apply.setUserMobile(user.getMobile()); // ? apply.setUserIdCard(user.getCertNo()); // ?? apply.setCustomerId(UserCookieUtil.getCustomerId(request)); // ? orderRemindManager.applyOrderRemind(lrd, apply); if (!lrd.isSuccess()) { return CommonUtils.goErrorPage(model, lrd.getMessage()); } else { OrderRemindDO orderRemind = orderRemindManager.findOrderRemind(lrd, (String) lrd.getData()); if (lrd.isSuccess()) { model.put("remind", orderRemind); ExpertDO expert = expertManager.getExpert(apply.getExpertId()); if (null == expert) { expert = new ExpertDO(); } model.put("expert", expert); } else { return CommonUtils.goErrorPage(model, lrd.getMessage()); } } return FTL_PRE + "apply_suc"; } /** * ??? * * @param model * @param state ?? * @return */ @RequestMapping("/query") @MethodRemark("remark=???") public String queryList(ModelMap model, @ModelAttribute("state") String state) { LocalResponseDO<Object> lrd = new LocalResponseDO<Object>(); OrderRemindDO query = new OrderRemindDO(); query.setState(state); query.setCustomerId(UserCookieUtil.getCustomerId(request)); List<OrderRemindDO> list = orderRemindManager.queryOrderRemindDOs(lrd, query); if (lrd.isSuccess()) { model.put("list", list); } else { return CommonUtils.goErrorPage(model, ""); } return FTL_PRE + "list"; } /** * ???? * * @param model * @param orid ? * @return */ @ResponseBody @RequestMapping("/cancel/{orid}") @MethodRemark("remark=????") public BaseJsonObject cancel(ModelMap model, @PathVariable("orid") String orderRemindId) { BaseJsonObject json = new BaseJsonObject(); LocalResponseDO<Object> lrd = new LocalResponseDO<Object>(); boolean suc = orderRemindManager.cancelOrderRemind(lrd, orderRemindId); if (!suc) { json.setHasError(true); json.setMessage(lrd.getMessage()); } return json; } /** * ??? * * @param model * @param orid ? * @return */ @RequestMapping("/{orid}") @MethodRemark("remark=???") public String detail(ModelMap model, @PathVariable("orid") String orderRemindId) { LocalResponseDO<Object> lrd = new LocalResponseDO<Object>(); OrderRemindDO orderRemind = orderRemindManager.findOrderRemind(lrd, orderRemindId); if (lrd.isSuccess()) { model.put("remind", orderRemind); } else { return CommonUtils.goErrorPage(model, ""); } return FTL_PRE + "detail"; } /** * ???????? * * @return null??? */ public String checkUserInfo() { UserDO user = orderRemindProcessor.getCurrentUser(); if (isBindedMobile(user)) { // return null; } else { String target = request.getRequestURL().toString(); String encodeTarget = HttpClientUtil.URLEncode(target); return GlobalConstants.REDIRECT_PER + PATH_PRE + "toPerfect?et=" + encodeTarget; } } /** * ??? * * @return */ private boolean isBindedMobile(UserDO user) { return 1 == user.getBindMobile() && StringUtils.isNotBlank(user.getMobile()); } /** * ?? * * @param model * @param encodeTarget ??? * @return */ @RequestMapping("/toPerfect") public String toPerfectUserInfo(ModelMap model, @RequestParam("et") String encodeTarget) { model.put("user", orderRemindProcessor.getCurrentUser()); model.put("target", HttpClientUtil.URLDencode(encodeTarget)); return FTL_PRE + "perfect_user_info"; } /** * ??????? * * @param model * @param target ??? * @return */ @RequestMapping(value = "/perfect", method = RequestMethod.POST) @MethodRemark("remark=???????,method=post,target=???,validCode=??,target=?") public String perfectUserInfo(ModelMap model, @RequestParam("mobile") String mobile, @RequestParam("validCode") String validCode, @RequestParam("target") String target) { Boolean suc = bindMobile(model, UserCookieUtil.getUserId(request), mobile, validCode); if (suc) { return GlobalConstants.REDIRECT_PER + target; } else { model.put("mobile", mobile); return toPerfectUserInfo(model, target); } } public boolean bindMobile(ModelMap model, long userId, String mobile, String validCode) { try { // ? if (!RegexUtil.isMobile(StringUtils.trim(mobile))) { logger.error(UserProfileConstants.ERR_MSG_MOBILE_FORMAT_ERROR); model.put("errorMessage", UserProfileConstants.ERR_MSG_MOBILE_FORMAT_ERROR); return false; } UserDO userCheck = orderRemindProcessor.getCurrentUser(); if (isBindedMobile(userCheck)) { return true; } UserResult urr = userManager.valiMobileNo(userCheck.getUserId(), mobile, userCheck.getReg_type()); if (urr != null && urr.getUserDO() != null) { // ?? UserDO userdo = urr.getUserDO(); logger.warn("??[" + userdo.getUserId() + "]"); model.put("errorMessage", "??"); return false; } if (codeCacheManager.verifyMobileCode(VerifyTypeEnum.UPDATE_PROFILE, mobile, validCode)) { // ?? UserDO user = new UserDO(); user.setUserId(userId); user.setMobile(mobile); user.setBindMobile(1); UserResult r = userManager.bindUserMobile(user); if (r.isSystemError()) { logger.error(r.getResponseDesc()); model.put("errorMessage", r.getResponseDesc()); return false; } codeCacheManager.delCode(VerifyTypeEnum.UPDATE_PROFILE, VCodeCachePrefixEnum.CODE_PRE.getValue() + mobile); return true; } else { logger.error(UserProfileConstants.ERR_MSG_MOBILE_CODE); model.put("errorMessage", UserProfileConstants.ERR_MSG_MOBILE_CODE); return false; } } catch (Exception e) { logger.error(UserProfileConstants.ERR_MSG_SYSTEM_ERROR, e); model.put("errorMessage", UserProfileConstants.ERR_MSG_SYSTEM_ERROR); return false; } } }