com.greenline.guahao.web.module.home.controllers.json.patient.JsonPatientController.java Source code

Java tutorial

Introduction

Here is the source code for com.greenline.guahao.web.module.home.controllers.json.patient.JsonPatientController.java

Source

/**
 * Project: guahao-portal-web-home
 * 
 * File Created at 2012-12-7
 * 
 * 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.json.patient;

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.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.greenline.common.util.DESUtil;
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.JsonPathConstants;
import com.greenline.guahao.web.module.common.constants.MobileMsgConstants;
import com.greenline.guahao.web.module.common.constants.ReservationConstants;
import com.greenline.guahao.web.module.common.cookie.UserCookieUtil;
import com.greenline.guahao.web.module.common.json.BaseJsonObject;

/**
 * @Type JsonPatientController
 * @Desc
 * @author jianyun.zheng
 * @date 2012-12-7
 * @Version V1.0
 */
@Controller
public class JsonPatientController {
    @Resource
    private PatientManager patientManager;
    @Resource
    private HttpServletRequest request;

    /**
     * json
     * 
     * @param model
     * @param patientId
     * @return OperationJsonObject
     */
    @MethodRemark(value = "remark=json,method=ajax,patientId=id")
    @RequestMapping(value = JsonPathConstants.J_PATIENT_DEL_PATH, method = RequestMethod.GET)
    public @ResponseBody BaseJsonObject patientDel(ModelMap model, @PathVariable("pid") String patientId) {
        BaseJsonObject json = new BaseJsonObject(Boolean.FALSE, MobileMsgConstants.M_PATIENT_DEL_SUC);
        // id
        String decodePatientId = DESUtil.DESDecode(patientId, EncodeKeyConstants.PATIENT_ENCODE_KEY);
        if (!StringUtils.isNumeric(decodePatientId)) {
            // id?
            json.setHasError(Boolean.TRUE);
            json.setCode(ReservationConstants.RESERVATION_ERROR_CODE_JSON);
            json.setMessage("?");
        } 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()))) {
                    // ??
                    json.setHasError(Boolean.TRUE);
                    json.setCode(ReservationConstants.RESERVATION_ERROR_CODE_JSON);
                    json.setMessage("?");
                } else {
                    PatientResult pr = patientManager.removePatient(Long.valueOf(decodePatientId));
                    if (pr.isSystemError()) {
                        json.setHasError(Boolean.TRUE);
                        json.setMessage(pr.getResponseDesc());
                    }
                }
            }
        }
        return json;
    }

}