Java tutorial
/** * Project: guahao-portal-web-home * * File Created at 2012-12-6 * * 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.mobile.patient; import java.util.List; import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; import org.apache.commons.lang.StringUtils; import org.springframework.stereotype.Controller; import org.springframework.ui.ModelMap; import org.springframework.validation.BindingResult; import org.springframework.web.bind.annotation.ModelAttribute; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestParam; import com.greenline.common.util.DESUtil; import com.greenline.guahao.biz.enums.CertTypEnum; import com.greenline.guahao.biz.manager.my.PatientManager; import com.greenline.guahao.biz.manager.user.dataobject.PatientInfoDO; import com.greenline.guahao.biz.manager.user.result.PatientResult; import com.greenline.guahao.web.module.common.annotation.MethodRemark; import com.greenline.guahao.web.module.common.constants.EncodeKeyConstants; import com.greenline.guahao.web.module.common.constants.MobileConstants; import com.greenline.guahao.web.module.common.constants.MobileMsgConstants; import com.greenline.guahao.web.module.common.cookie.UserCookieUtil; import com.greenline.guahao.web.module.home.controllers.mobile.user.MobileLoginProcess; import com.greenline.guahao.web.module.home.validator.user.PatientValidator; /** * @Type MobilePatientController * @Desc ?? * @author jianyun.zheng * @date 2012-12-6 * @Version V1.0 */ @Controller public class MobilePatientController { @Resource private HttpServletRequest request; @Resource private PatientManager patientManager; @Resource private MobileLoginProcess mobileLoginProcess; /** * html5 ?? * * @param model * @return String */ @MethodRemark(value = "remark=html??method=get") @RequestMapping(value = MobileConstants.M_PAIENT_LIST_PATH, method = RequestMethod.GET) public String patientList(ModelMap model) { // ?cookieuserId Long userId = UserCookieUtil.getUserId(request); // ?list List<PatientInfoDO> patientList = patientManager.ListMyPatient(userId); if (null == patientList || patientList.isEmpty()) { model.put("message", MobileMsgConstants.L_ERROR); return MobileConstants.M_ERROR; } for (PatientInfoDO patientInfoDO : patientList) { patientInfoDO.setEncodePatientId(DESUtil.DESEncode(String.valueOf(patientInfoDO.getPatient_id()), EncodeKeyConstants.PATIENT_ENCODE_KEY)); if (patientInfoDO.getRelationship() == 1) { if (StringUtils.isBlank(patientInfoDO.getPatient_name()) || StringUtils.isBlank(patientInfoDO.getPatient_cert_type()) || StringUtils.isBlank(patientInfoDO.getPatient_cert_no()) || StringUtils.isBlank(patientInfoDO.getPatient_mobile())) { model.put("updateProfile", true); } } } model.put("patientList", patientList); model.put("hasAdd", (patientList.size() < 3)); return MobileConstants.M_PAIENT_LIST; } /** * html5 ?? * * @param model * @return String */ @MethodRemark(value = "remark=?html??method=get") @RequestMapping(value = MobileConstants.M_ZFB_PAIENT_LIST_PATH, method = RequestMethod.GET) public String zfbPatientList(ModelMap model) { mobileLoginProcess.zfbAutoLogon(); // ?cookieuserId Long userId = UserCookieUtil.getUserId(request); if (null == userId) { return "redirect:" + MobileConstants.M_LOGIN_PATH; } // ?list List<PatientInfoDO> patientList = patientManager.ListMyPatient(userId); if (null == patientList || patientList.isEmpty()) { model.put("message", MobileMsgConstants.L_ERROR); return MobileConstants.M_ERROR; } for (PatientInfoDO patientInfoDO : patientList) { patientInfoDO.setEncodePatientId(DESUtil.DESEncode(String.valueOf(patientInfoDO.getPatient_id()), EncodeKeyConstants.PATIENT_ENCODE_KEY)); if (patientInfoDO.getRelationship() == 1) { if (StringUtils.isBlank(patientInfoDO.getPatient_name()) || StringUtils.isBlank(patientInfoDO.getPatient_cert_type()) || StringUtils.isBlank(patientInfoDO.getPatient_cert_no()) || StringUtils.isBlank(patientInfoDO.getPatient_mobile())) { model.put("updateProfile", true); } } } model.put("patientList", patientList); model.put("hasAdd", (patientList.size() < 3)); return MobileConstants.M_PAIENT_LIST; } /** * html5 ? * * @param model * @param patientId * @return String */ @MethodRemark(value = "remark=html?method=get") @RequestMapping(value = MobileConstants.M_PAIENT_INFO_PATH, method = RequestMethod.GET) public String patient(ModelMap model, @RequestParam("pid") String patientId) { // id String decodePatientId = DESUtil.DESDecode(patientId, EncodeKeyConstants.PATIENT_ENCODE_KEY); if (!StringUtils.isNumeric(decodePatientId)) { model.put("message", MobileMsgConstants.L_ERROR); return MobileConstants.M_ERROR; } else { PatientInfoDO patientInfoDO = patientManager.getPatientByPatientId(Long.parseLong(decodePatientId)); if (null != patientInfoDO) { Long userId = UserCookieUtil.getUserId(request); if (!userId.toString().equals(String.valueOf(patientInfoDO.getUser_id()))) { // ?? model.put("message", MobileMsgConstants.L_ERROR); return MobileConstants.M_ERROR; } else { PatientInfoDO patient = patientManager.getPatientByPatientId(Long.valueOf(decodePatientId)); if (null == patient) { model.put("message", MobileMsgConstants.L_ERROR); return MobileConstants.M_ERROR; } patient.setEncodePatientId(patientId); patient.setEncodeUserId(DESUtil.DESEncode(String.valueOf(patient.getUser_id()), EncodeKeyConstants.USER_ENCODE_KEY)); model.put("patient", patient); model.put("redict", patientManager.getRelationDictDef()); } } } return MobileConstants.M_PAIENT_INFO; } /** * html5 ? * * @param model * @return String */ @MethodRemark(value = "remark=html?method=get") @RequestMapping(value = MobileConstants.M_PAIENT_ADD_PATH, method = RequestMethod.GET) public String patientAdd(ModelMap model) { // ?cookieuserId String cuserId = UserCookieUtil.getUserId(request) + StringUtils.EMPTY; String encodeUserId = DESUtil.DESEncode(cuserId, EncodeKeyConstants.USER_ENCODE_KEY); model.put("encodeUserId", encodeUserId); model.put("redict", patientManager.getRelationDictDef()); model.put("patient", new PatientInfoDO()); return MobileConstants.M_PAIENT_ADD; } /** * html5 ??? * * @param model * @param encodeUserId * @param patient * @param result * @return String */ @MethodRemark(value = "remark=html???method=post") @RequestMapping(value = MobileConstants.M_PAIENT_ADD_PATH, method = RequestMethod.POST) public String doPatientAdd(ModelMap model, @RequestParam("encodeUserId") String encodeUserId, @ModelAttribute("patient") PatientInfoDO patient, BindingResult result) { String decodeUserId = DESUtil.DESDecode(encodeUserId, EncodeKeyConstants.USER_ENCODE_KEY); // ?cookieuserId Long cuserId = UserCookieUtil.getUserId(request); boolean hasError = Boolean.FALSE; String msg = ""; if (StringUtils.isBlank(decodeUserId) || !decodeUserId.equals(cuserId + StringUtils.EMPTY)) { hasError = Boolean.TRUE; msg = MobileMsgConstants.L_ERROR; } // ?? PatientValidator validator = new PatientValidator(); validator.validate(patient, result); if (result.hasErrors()) { hasError = Boolean.TRUE; } if (!hasError) { patient.setUser_id(cuserId); patient.setPatient_cert_type(CertTypEnum.IDCARD.getValue()); PatientResult pr = patientManager.addPatient(patient); if (pr.isSystemError()) { hasError = Boolean.TRUE; msg = pr.getResponseDesc(); } else { model.put("title", MobileMsgConstants.M_PATIENT_ADD_SUC); model.put("toUrl", MobileConstants.M_PAIENT_LIST_PATH); model.put("toTitle", ""); return MobileConstants.M_SUCCESS; } } model.put("encodeUserId", encodeUserId); model.put("hasError", hasError); model.put("redict", patientManager.getRelationDictDef()); model.put("message", msg); model.put("patient", patient); model.put("userId", cuserId); return MobileConstants.M_PAIENT_ADD; } /** * html5 ??? post * * @param model * @param patient * @param result * @return String */ @MethodRemark(value = "remark=html ???method=post") @RequestMapping(value = MobileConstants.M_PAIENT_UPDATE_PATH, method = RequestMethod.POST) public String patientUpdate(ModelMap model, @ModelAttribute("patient") PatientInfoDO patient, BindingResult result) { // ?cookieuserId Long cuserId = UserCookieUtil.getUserId(request); boolean hasError = Boolean.FALSE; String decodeUserId = DESUtil.DESDecode(patient.getEncodeUserId(), EncodeKeyConstants.USER_ENCODE_KEY); if (StringUtils.isBlank(decodeUserId) || !decodeUserId.equals(cuserId.toString())) { hasError = Boolean.TRUE; result.rejectValue("user_id", "user_id.error", "?."); } // ?? PatientValidator validator = new PatientValidator(); validator.validate(patient, result); if (result.hasErrors()) { hasError = Boolean.TRUE; } if (!hasError) { patient.setPatient_cert_type(CertTypEnum.IDCARD.getValue()); patient.setPatient_birthday(com.greenline.guahao.web.module.common.utils.UserUtil .getBirthdayByCardno(patient.getPatient_cert_no())); patient.setPatient_sex(com.greenline.guahao.web.module.common.utils.UserUtil .getSexByCardno(patient.getPatient_cert_no())); patient.setUser_id(Long.valueOf(decodeUserId)); String decodePatientId = DESUtil.DESDecode(patient.getEncodePatientId(), EncodeKeyConstants.PATIENT_ENCODE_KEY); patient.setPatient_id(Long.valueOf(decodePatientId)); PatientResult pr = patientManager.updatePatient(patient); if (pr.isSystemError()) { // hasError = Boolean.TRUE; model.put("message", pr.getResponseDesc()); } else { model.put("title", MobileMsgConstants.M_PATIENT_UPDATE_SUC); model.put("toUrl", MobileConstants.M_PAIENT_LIST_PATH); model.put("toTitle", "?"); return MobileConstants.M_SUCCESS; } } model.put("redict", patientManager.getRelationDictDef()); model.put("hasError", hasError); model.put("patient", patient); return MobileConstants.M_PAIENT_INFO; } }