/**
 * @Title: PreregXmlController.java
 * @Package com.platform.controller.prereg
 * @Description: TODO(用一句话描述该文件做什么)
 * @author kiosk
 * @date 2017年12月4日 上午8:59:49
 * @version V1.0
 */
package com.platform.controller.prereg;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import com.platform.pojo.*;
import org.json.JSONException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.platform.request.prereg.xml.RequestParameter;
import com.platform.request.prereg.xml.RequestParameterForPrereg;
import com.platform.response.prereg.xml.ResponseParameter;
import com.platform.service.IPreregService;
import com.platform.util.ClassUtil;
import com.platform.util.EpayMD5;
import com.platform.util.JSONUtil;
import com.platform.util.JaxbUtil2;
import com.platform.util.JaxbUtil2.CollectionWrapper;

/**
 * @ClassName: PreregXmlController
 * @Description: TODO(这里用一句话描述这个类的作用)
 * @author kiosk
 * @date 2017年12月4日 上午8:59:49
 *
 */
@Controller
@RequestMapping("/preregxml")
public class PreregXmlController {
    // 定义日志文件操作类对象
    private static Logger logger = (Logger) LoggerFactory.getLogger(PreregXmlController.class);
    // 引入医院基础信息查询接口Service
    @Resource
    private IPreregService preregService;

    // 定义厂商信息List
    List<VendorInfo> vendorInfos = new ArrayList<VendorInfo>();

    /**
     *
     * @Title: getSign @Description: TODO(获取签名接口) @param @param
     *         requestParameter @param @return 设定文件 @return String 返回类型 @throws
     */
    @RequestMapping(value = "/getSign", consumes = "application/xml", method = RequestMethod.POST)
    @ResponseBody
    public String getSign(@RequestBody RequestParameter requestParameter) {
        logger.debug("###################################################执行获取签名接口getSign方法开始");
        logger.debug("###################################################接收到的body值：" + requestParameter);
        String resultStr = null;
        String str = null;
        String errorString = null;
        ObjectMapper mapper = new ObjectMapper(); // 转换器
        // 全局DeserializationFeature配置：配置该objectMapper在反序列化时，忽略目标对象没有的属性。凡是使用该objectMapper反序列化时，都会拥有该特性。
        mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
        try {
            // 将传入的Java类转换为Json串
            str = JSONUtil.objectToJson(requestParameter).toString();
            logger.debug("##########################################body值转换为Json串：" + str);
            // 签名准备工作
            RequestParameterForPrereg requestParamForPrereg = new RequestParameterForPrereg();
            requestParamForPrereg = (RequestParameterForPrereg) mapper.readValue(str, RequestParameterForPrereg.class);
            Map<String, String> params = new HashMap<String, String>();
            params = ClassUtil.setConditionMap(requestParamForPrereg);
            logger.debug("##########################################签名准备工作获取到的map值：" + params);
            // 签名有两个步骤，先按一定规则拼接要签名的原始串，再选择具体的算法和密钥计算出签名结果。
            // 拼接原始串
            Map<String, String> filterMap = EpayMD5.paraFilter(params);
            String linkStr = EpayMD5.createLinkString(filterMap);
            logger.debug("######################################MD5签名拼原始串的值：" + linkStr);
            // Example查询类
            logger.debug("###########################################查询厂商授权私钥记录开始");
            VendorInfoExample example = new VendorInfoExample();
            example.or().andVendorCodeEqualTo(requestParameter.getVendorCode())
                    .andVendorNameEqualTo(requestParameter.getVendorName()).andDeleteFlagEqualTo(1);
            vendorInfos = preregService.selectVendorList(example);
            logger.debug("###########################################查询厂商授权私钥记录条数：" + vendorInfos.size());
            if (vendorInfos.size() > 0) {
                logger.debug("###########################################查询厂商授权私钥记录条数大于0，条数为：" + vendorInfos.size());
                if (vendorInfos.size() == 1) {
                    logger.debug("###########################################查询厂商授权私钥记录条数为1，即找到唯一一条记录，签名开始");
                    String sign = EpayMD5.sign(linkStr, vendorInfos.get(0).getLicenseCode(), "UTF-8");
                    logger.debug("###################################私钥（key）加入进行MD5签名后的值：" + sign);
                    ResponseParameter responseParameter = new ResponseParameter();
                    responseParameter.setCode("0");
                    responseParameter.setMsg("签名成功");
                    responseParameter.setSign(sign);
                    // 将java对象转换为XML字符串
                    JaxbUtil2 requestBinder = new JaxbUtil2(ResponseParameter.class, CollectionWrapper.class);
                    resultStr = requestBinder.toXml(responseParameter, "utf-8");
                    logger.debug("###########################################签名成功后返回的resultStr为：" + resultStr);
                    logger.debug("###########################################查询厂商授权私钥记录条数为1，即找到唯一一条记录，签名结束");
                } else {
                    errorString = "找到重复的厂商信息";
                    resultStr = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?> <response> <code>" + "-1"
                            + "</code><msg>" + errorString + "</msg></response> ";
                    logger.debug("################################################################找到重复的厂商信息");
                }
            } else {
                errorString = "没有该厂商的授权信息";
                resultStr = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?> <response> <code>" + "-1"
                        + "</code><msg>" + errorString + "</msg></response> ";
                logger.debug("################################################################没有该厂商的信息");
            }
        } catch (JSONException e) {
            errorString = "数据转换错误(JSONException)";
            resultStr = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?> <response> <code>" + "-1"
                    + "</code><msg>" + errorString + "</msg></response> ";
            logger.debug("################################################################数据转换错误(JSONException)："
                    + e.toString());
        } catch (IOException e) {
            errorString = "流异常(IOException)";
            resultStr = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?> <response> <code>" + "-1"
                    + "</code><msg>" + errorString + "</msg></response> ";
            logger.debug("#######################################################################流异常(IOException)："
                    + e.toString());
        }
        return resultStr;
    }

    @RequestMapping(value = "/querySectionTypes", consumes = "application/xml", method = RequestMethod.POST)
    @ResponseBody
    public String querySectionTypes(@RequestBody RequestParameter requestParameter) {
        logger.debug("###########################################查询排班科室信息接口querySectionTypes方法开始");
        logger.debug("###################################################接收到的body值：" + requestParameter);
        String resultStr = null;
        String str = null;
        String errorString = null;
        String resXML = null;
        ObjectMapper mapper = new ObjectMapper(); // 转换器
        // 全局DeserializationFeature配置：配置该objectMapper在反序列化时，忽略目标对象没有的属性。凡是使用该objectMapper反序列化时，都会拥有该特性。
        mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
        try {
            logger.debug("###########################################查询厂商授权私钥记录开始");
            // Example查询类
            VendorInfoExample example = new VendorInfoExample();
            example.or().andVendorCodeEqualTo(requestParameter.getVendorCode())
                    .andVendorNameEqualTo(requestParameter.getVendorName()).andDeleteFlagEqualTo(1);
            vendorInfos = preregService.selectVendorList(example);
            logger.debug("###########################################查询厂商授权私钥记录条数：" + vendorInfos.size());
            if (vendorInfos.size() > 0) {
                logger.debug("###########################################查询厂商授权私钥记录条数大于0，条数为：" + vendorInfos.size());
                if (vendorInfos.size() == 1) {
                    logger.debug("###########################################查询厂商授权私钥记录条数为1，即找到唯一一条记录，签名开始");
                    // 将传入的Java类转换为Json串
                    str = JSONUtil.objectToJson(requestParameter).toString();
                    logger.debug("##########################################body值转换为Json串：" + str);
                    // 准备签名工作
                    RequestParameterForPrereg requestParamForPrereg = new RequestParameterForPrereg();
                    requestParamForPrereg = (RequestParameterForPrereg) mapper.readValue(str,
                            RequestParameterForPrereg.class);
                    Map<String, String> params = new HashMap<String, String>();
                    params = ClassUtil.setConditionMap(requestParamForPrereg);
                    // 签名有两个步骤，先按一定规则拼接要签名的原始串，再选择具体的算法和密钥计算出签名结果。
                    // 拼原始串
                    Map<String, String> filterMap = EpayMD5.paraFilter(params);
                    String linkStr = EpayMD5.createLinkString(filterMap);
                    logger.debug("######################################MD5签名拼原始串的值：" + linkStr);
                    // 签名（签名时把私钥（key）加入进行MD5签名）
                    String serverSign = EpayMD5.sign(linkStr, vendorInfos.get(0).getLicenseCode(), "UTF-8");
                    logger.debug("###################################私钥（key）加入进行MD5签名后的值：" + serverSign);
                    // 验签过程
                    if (serverSign.equals(requestParameter.getSign())) {
                        Long clientTime = new Long(requestParameter.getTimeStamp());
                        Date serverDate = new Date();
                        Long serverTime = serverDate.getTime() / 1000;
                        try {
                            long interval = serverTime - clientTime;
                            // 验证是否过期:默认300s
                            if (interval < 300) {
                                List<SectionType> sectionTypes = preregService.selectAllSectionTypes();
                                if (sectionTypes.size() > 0) {
                                    ResponseParameter responseParameter = new ResponseParameter();
                                    responseParameter.setCode("0");
                                    responseParameter.setMsg("请求成功");
                                    responseParameter.setSign(requestParameter.getSign());
                                    responseParameter.setSectionTypes(sectionTypes);
                                    // 将java对象转换为XML字符串
                                    JaxbUtil2 requestBinder = new JaxbUtil2(ResponseParameter.class,
                                            CollectionWrapper.class);
                                    resXML = requestBinder.toXml(responseParameter, "utf-8");
                                    resultStr = resXML;
                                } else {
                                    errorString = "未查询到科室大类记录";
                                    resultStr = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?> <response> <code>"
                                            + "-1" + "</code><msg>" + errorString + "</msg></response> ";
                                }
                            } else {
                                errorString = "请求已经过期";
                                resultStr = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?> <response> <code>"
                                        + "-1" + "</code><msg>" + errorString + "</msg></response> ";
                            }
                        } catch (Exception e) {
                            errorString = "出现未知异常";
                            resultStr = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?> <response> <code>"
                                    + "-1" + "</code><msg>" + errorString + "</msg></response> ";
                            logger.debug("################################################################出现未知异常"
                                    + e.getStackTrace());
                        }
                    } else {
                        errorString = "签名认证失败";
                        resultStr = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?> <response> <code>"
                                + "-1" + "</code><msg>" + errorString + "</msg></response> ";
                        logger.debug("################################################################签名认证失败");
                    }
                } else {
                    errorString = "找到重复的厂商信息";
                    resultStr = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?> <response> <code>" + "-1"
                            + "</code><msg>" + errorString + "</msg></response> ";
                    logger.debug("################################################################找到重复的厂商信息");
                }
            } else {
                errorString = "没有该厂商的授权信息";
                resultStr = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?> <response> <code>" + "-1"
                        + "</code><msg>" + errorString + "</msg></response> ";
                logger.debug("################################################################没有该厂商的信息");
            }
        } catch (JSONException e) {
            errorString = "数据转换错误(JSONException)";
            resultStr = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\" ?> <response> <code>" + "-1"
                    + "</code><msg>" + errorString + "</msg></response> ";
            logger.debug("################################################################数据转换错误(JSONException)："
                    + e.toString());
        } catch (Exception e) {
            errorString = "流异常(IOException)";
            resultStr = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?> <response> <code>" + "-1"
                    + "</code><msg>" + errorString + "</msg></response> ";
            logger.debug("#######################################################################流异常(IOException)："
                    + e.toString());
        }
        return resultStr;
    }


    /**
     *
     * @Title: queryAllSection @Description: TODO(查询排班科室信息接口) @param @param
     *         requestParameter @param @return 设定文件 @return String 返回类型 @throws
     */
    @RequestMapping(value = "/querySections", consumes = "application/xml", method = RequestMethod.POST)
    @ResponseBody
    public String querySections(@RequestBody RequestParameter requestParameter) {
        logger.debug("###########################################查询排班科室信息接口querySections方法开始");
        logger.debug("###################################################接收到的body值：" + requestParameter);
        String resultStr = null;
        String str = null;
        String errorString = null;
        String resXML = null;
        ObjectMapper mapper = new ObjectMapper(); // 转换器
        // 全局DeserializationFeature配置：配置该objectMapper在反序列化时，忽略目标对象没有的属性。凡是使用该objectMapper反序列化时，都会拥有该特性。
        mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
        try {
            logger.debug("###########################################查询厂商授权私钥记录开始");
            // Example查询类
            VendorInfoExample example = new VendorInfoExample();
            example.or().andVendorCodeEqualTo(requestParameter.getVendorCode())
                    .andVendorNameEqualTo(requestParameter.getVendorName()).andDeleteFlagEqualTo(1);
            vendorInfos = preregService.selectVendorList(example);
            logger.debug("###########################################查询厂商授权私钥记录条数：" + vendorInfos.size());
            if (vendorInfos.size() > 0) {
                logger.debug("###########################################查询厂商授权私钥记录条数大于0，条数为：" + vendorInfos.size());
                if (vendorInfos.size() == 1) {
                    logger.debug("###########################################查询厂商授权私钥记录条数为1，即找到唯一一条记录，签名开始");
                    // 将传入的Java类转换为Json串
                    str = JSONUtil.objectToJson(requestParameter).toString();
                    logger.debug("##########################################body值转换为Json串：" + str);
                    // 准备签名工作
                    RequestParameterForPrereg requestParamForPrereg = new RequestParameterForPrereg();
                    requestParamForPrereg = (RequestParameterForPrereg) mapper.readValue(str,
                            RequestParameterForPrereg.class);
                    Map<String, String> params = new HashMap<String, String>();
                    params = ClassUtil.setConditionMap(requestParamForPrereg);
                    // 签名有两个步骤，先按一定规则拼接要签名的原始串，再选择具体的算法和密钥计算出签名结果。
                    // 拼原始串
                    Map<String, String> filterMap = EpayMD5.paraFilter(params);
                    String linkStr = EpayMD5.createLinkString(filterMap);
                    logger.debug("######################################MD5签名拼原始串的值：" + linkStr);
                    // 签名（签名时把私钥（key）加入进行MD5签名）
                    String serverSign = EpayMD5.sign(linkStr, vendorInfos.get(0).getLicenseCode(), "UTF-8");
                    logger.debug("###################################私钥（key）加入进行MD5签名后的值：" + serverSign);
                    // 验签过程
                    if (serverSign.equals(requestParameter.getSign())) {
                        Long clientTime = new Long(requestParameter.getTimeStamp());
                        Date serverDate = new Date();
                        Long serverTime = serverDate.getTime() / 1000;
                        try {
                            long interval = serverTime - clientTime;
                            // 验证是否过期:默认300s
                            if (interval < 300) {
                                List<Section> sections = preregService.selectSecions(requestParameter.getStartDate(),
                                        requestParameter.getEndDate(), requestParameter.getTimeInteval(), requestParameter.getSectionType());
                                if (sections.size() > 0) {
                                    ResponseParameter responseParameter = new ResponseParameter();
                                    responseParameter.setCode("0");
                                    responseParameter.setMsg("请求成功");
                                    responseParameter.setSign(requestParameter.getSign());
                                    responseParameter.setSections(sections);
                                    // 将java对象转换为XML字符串
                                    JaxbUtil2 requestBinder = new JaxbUtil2(ResponseParameter.class,
                                            CollectionWrapper.class);
                                    resXML = requestBinder.toXml(responseParameter, "utf-8");
                                    resultStr = resXML;
                                } else {
                                    errorString = "当前日期内没有科室排班记录";
                                    resultStr = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?> <response> <code>"
                                            + "-1" + "</code><msg>" + errorString + "</msg></response> ";
                                }
                            } else {
                                errorString = "请求已经过期";
                                resultStr = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?> <response> <code>"
                                        + "-1" + "</code><msg>" + errorString + "</msg></response> ";
                            }
                        } catch (Exception e) {
                            errorString = "出现未知异常";
                            resultStr = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?> <response> <code>"
                                    + "-1" + "</code><msg>" + errorString + "</msg></response> ";
                            logger.debug("################################################################出现未知异常"
                                    + e.getStackTrace());
                        }
                    } else {
                        errorString = "签名认证失败";
                        resultStr = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?> <response> <code>"
                                + "-1" + "</code><msg>" + errorString + "</msg></response> ";
                        logger.debug("################################################################签名认证失败");
                    }
                } else {
                    errorString = "找到重复的厂商信息";
                    resultStr = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?> <response> <code>" + "-1"
                            + "</code><msg>" + errorString + "</msg></response> ";
                    logger.debug("################################################################找到重复的厂商信息");
                }
            } else {
                errorString = "没有该厂商的授权信息";
                resultStr = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?> <response> <code>" + "-1"
                        + "</code><msg>" + errorString + "</msg></response> ";
                logger.debug("################################################################没有该厂商的信息");
            }
        } catch (JSONException e) {
            errorString = "数据转换错误(JSONException)";
            resultStr = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\" ?> <response> <code>" + "-1"
                    + "</code><msg>" + errorString + "</msg></response> ";
            logger.debug("################################################################数据转换错误(JSONException)："
                    + e.toString());
        } catch (Exception e) {
            errorString = "流异常(IOException)";
            resultStr = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?> <response> <code>" + "-1"
                    + "</code><msg>" + errorString + "</msg></response> ";
            logger.debug("#######################################################################流异常(IOException)："
                    + e.toString());
        }
        return resultStr;
    }

    /**
     *
     * @Title: queryDoctors @Description: TODO(查询选定科室下的排班医生) @param @param
     *         requestParameter @param @return 设定文件 @return String 返回类型 @throws
     */
    @RequestMapping(value = "/queryDoctors", consumes = "application/xml", method = RequestMethod.POST)
    @ResponseBody
    public String queryDoctors(@RequestBody RequestParameter requestParameter) {
        logger.debug("###########################################查询排班医生信息接口queryDoctors方法开始");
        logger.debug("###################################################接收到的body值：" + requestParameter);
        String resultStr = null;
        String str = null;
        String errorString = null;
        String resXML = null;
        ObjectMapper mapper = new ObjectMapper(); // 转换器
        // 全局DeserializationFeature配置：配置该objectMapper在反序列化时，忽略目标对象没有的属性。凡是使用该objectMapper反序列化时，都会拥有该特性。
        mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
        try {
            logger.debug("###########################################查询厂商授权私钥记录开始");
            // Example查询类
            VendorInfoExample example = new VendorInfoExample();
            example.or().andVendorCodeEqualTo(requestParameter.getVendorCode())
                    .andVendorNameEqualTo(requestParameter.getVendorName()).andDeleteFlagEqualTo(1);
            vendorInfos = preregService.selectVendorList(example);
            logger.debug("###########################################查询厂商授权私钥记录条数：" + vendorInfos.size());
            if (vendorInfos.size() > 0) {
                logger.debug("###########################################查询厂商授权私钥记录条数大于0，条数为：" + vendorInfos.size());
                if (vendorInfos.size() == 1) {
                    logger.debug("###########################################查询厂商授权私钥记录条数为1，即找到唯一一条记录，签名开始");
                    // 将传入的Java类转换为Json串
                    str = JSONUtil.objectToJson(requestParameter).toString();
                    logger.debug("##########################################body值转换为Json串：" + str);
                    // 准备签名工作
                    RequestParameterForPrereg requestParamForPrereg = new RequestParameterForPrereg();
                    requestParamForPrereg = (RequestParameterForPrereg) mapper.readValue(str,
                            RequestParameterForPrereg.class);
                    Map<String, String> params = new HashMap<String, String>();
                    params = ClassUtil.setConditionMap(requestParamForPrereg);
                    // 签名有两个步骤，先按一定规则拼接要签名的原始串，再选择具体的算法和密钥计算出签名结果。
                    // 拼原始串
                    Map<String, String> filterMap = EpayMD5.paraFilter(params);
                    String linkStr = EpayMD5.createLinkString(filterMap);
                    logger.debug("######################################MD5签名拼原始串的值：" + linkStr);
                    // 签名（签名时把私钥（key）加入进行MD5签名）
                    String serverSign = EpayMD5.sign(linkStr, vendorInfos.get(0).getLicenseCode(), "UTF-8");
                    logger.debug("###################################私钥（key）加入进行MD5签名后的值：" + serverSign);
                    // 验签过程
                    if (serverSign.equals(requestParameter.getSign())) {
                        Long clientTime = new Long(requestParameter.getTimeStamp());
                        Date serverDate = new Date();
                        Long serverTime = serverDate.getTime() / 1000;
                        try {
                            long interval = serverTime - clientTime;
                            // 验证是否过期:默认300s
                            if (interval < 300) {
                                List<Doctor> doctors = preregService.selectDoctors(requestParameter.getStartDate(),
                                        requestParameter.getEndDate(), requestParameter.getTimeInteval(),
                                        requestParameter.getSectionNo());
                                if (doctors.size() > 0) {
                                    int i = 1;
                                    for (Doctor doctor : doctors) {
                                        doctor.setSerailNo(String.valueOf(i));
                                        i++;
                                    }
                                    ResponseParameter responseParameter = new ResponseParameter();
                                    responseParameter.setCode("0");
                                    responseParameter.setMsg("请求成功");
                                    responseParameter.setSign(requestParameter.getSign());
                                    responseParameter.setDoctors(doctors);
                                    // 将java对象转换为XML字符串
                                    JaxbUtil2 requestBinder = new JaxbUtil2(ResponseParameter.class,
                                            CollectionWrapper.class);
                                    resXML = requestBinder.toXml(responseParameter, "utf-8");
                                    resultStr = resXML;
                                } else {
                                    errorString = "当前日期内没有该科室的医生排班记录";
                                    resultStr = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?> <response> <code>"
                                            + "-1" + "</code><msg>" + errorString + "</msg></response> ";
                                }
                            } else {
                                errorString = "请求已经过期";
                                resultStr = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?> <response> <code>"
                                        + "-1" + "</code><msg>" + errorString + "</msg></response> ";
                            }
                        } catch (Exception e) {
                            errorString = "出现未知异常";
                            resultStr = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?> <response> <code>"
                                    + "-1" + "</code><msg>" + errorString + "</msg></response> ";
                            logger.debug("################################################################出现未知异常"
                                    + e.getStackTrace());
                        }
                    } else {
                        errorString = "签名认证失败";
                        resultStr = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?> <response> <code>"
                                + "-1" + "</code><msg>" + errorString + "</msg></response> ";
                        logger.debug("################################################################签名认证失败");
                    }
                } else {
                    errorString = "找到重复的厂商信息";
                    resultStr = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?> <response> <code>" + "-1"
                            + "</code><msg>" + errorString + "</msg></response> ";
                    logger.debug("################################################################找到重复的厂商信息");
                }
            } else {
                errorString = "没有该厂商的授权信息";
                resultStr = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?> <response> <code>" + "-1"
                        + "</code><msg>" + errorString + "</msg></response> ";
                logger.debug("################################################################没有该厂商的信息");
            }
        } catch (JSONException e) {
            errorString = "数据转换错误(JSONException)";
            resultStr = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\" ?> <response> <code>" + "-1"
                    + "</code><msg>" + errorString + "</msg></response> ";
            logger.debug("################################################################数据转换错误(JSONException)："
                    + e.toString());
        } catch (Exception e) {
            errorString = "流异常(IOException)";
            resultStr = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?> <response> <code>" + "-1"
                    + "</code><msg>" + errorString + "</msg></response> ";
            logger.debug("#######################################################################流异常(IOException)："
                    + e.toString());
        }
        return resultStr;
    }


    /**
     * 预约锁号接口：根据传入的条件，按照号表序号进行顺序依次锁号
     * @param requestParameter
     * @return
     */
    @RequestMapping(value = "/lockTickets", consumes = "application/xml", method = RequestMethod.POST)
    @ResponseBody
    public String lockTickets(@RequestBody RequestParameter requestParameter) {
        logger.debug("###########################################根据条件进行预约锁号接口lockTickets方法开始");
        logger.debug("###################################################接收到的body值：" + requestParameter);
        String resultStr = null;
        String str = null;
        String errorString = null;
        String resXML = null;
        ObjectMapper mapper = new ObjectMapper(); // 转换器
        //全局DeserializationFeature配置：配置该objectMapper在反序列化时，忽略目标对象没有的属性。凡是使用该objectMapper反序列化时，都会拥有该特性。
        mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
        try {
            logger.debug("###########################################查询厂商授权私钥记录开始");
            // Example查询类
            VendorInfoExample example = new VendorInfoExample();
            example.or().andVendorCodeEqualTo(requestParameter.getVendorCode())
                    .andVendorNameEqualTo(requestParameter.getVendorName()).andDeleteFlagEqualTo(1);
            vendorInfos = preregService.selectVendorList(example);
            logger.debug("###########################################查询厂商授权私钥记录条数：" + vendorInfos.size());
            if (vendorInfos.size() > 0) {
                logger.debug("###########################################查询厂商授权私钥记录条数大于0，条数为：" + vendorInfos.size());
                if (vendorInfos.size() == 1) {
                    logger.debug("###########################################查询厂商授权私钥记录条数为1，即找到唯一一条记录，签名开始");
                    // 将传入的Java类转换为Json串
                    str = JSONUtil.objectToJson(requestParameter).toString();
                    logger.debug("##########################################body值转换为Json串：" + str);
                    // 准备签名工作
                    RequestParameterForPrereg requestParamForPrereg = new RequestParameterForPrereg();
                    requestParamForPrereg = (RequestParameterForPrereg) mapper.readValue(str,
                            RequestParameterForPrereg.class);
                    Map<String, String> params = new HashMap<String, String>();
                    params = ClassUtil.setConditionMap(requestParamForPrereg);
                    // 签名有两个步骤，先按一定规则拼接要签名的原始串，再选择具体的算法和密钥计算出签名结果。
                    // 拼原始串
                    Map<String, String> filterMap = EpayMD5.paraFilter(params);
                    String linkStr = EpayMD5.createLinkString(filterMap);
                    logger.debug("######################################MD5签名拼原始串的值：" + linkStr);
                    // 签名（签名时把私钥（key）加入进行MD5签名）
                    String serverSign = EpayMD5.sign(linkStr, vendorInfos.get(0).getLicenseCode(), "UTF-8");
                    logger.debug("###################################私钥（key）加入进行MD5签名后的值：" + serverSign);
                    // 验签过程
                    if (serverSign.equals(requestParameter.getSign())) {
                        Long clientTime = new Long(requestParameter.getTimeStamp());
                        Date serverDate = new Date();
                        Long serverTime = serverDate.getTime() / 1000;
                        try {
                            long interval = serverTime - clientTime;
                            // 验证是否过期:默认300s
                            if (interval < 300) {
                                List<Ticket> tickets;
                                //显示保留号：根据sortNo升序排列
                                if (vendorInfos.get(0).getRetainShowFlag().equals("0")) {
                                    tickets = preregService.selectTicketsAll(requestParameter.getStartDate(),
                                            requestParameter.getEndDate(), requestParameter.getTimeInteval(),
                                            requestParameter.getSectionNo(), requestParameter.getDoctorNo());
                                } else {//不显示保留号：根据sortNo升序排列
                                    tickets = preregService.selectTicketsNoRetain(requestParameter.getStartDate(),
                                            requestParameter.getEndDate(), requestParameter.getTimeInteval(),
                                            requestParameter.getSectionNo(), requestParameter.getDoctorNo());
                                }
                                if (tickets.size() > 0) {
                                    Ticket ticket;
                                    List<Ticket> ticketsForReturn=new ArrayList<Ticket>();
                                    ticket=tickets.get(0);
                                    ResponseParameter responseParameter = new ResponseParameter();
                                    //根据主键(id)更新号表状态为锁号(7)
                                    int updateNum=preregService.updateSchedulesPlanByPrimaryKey(ticket.getPlanId()
                                            ,"7");
                                    if (updateNum>0){
                                        responseParameter.setCode("10000");
                                        responseParameter.setMsg("请求成功");
                                        responseParameter.setSign(requestParameter.getSign());
                                        ticketsForReturn.add(ticket);
                                        responseParameter.setTickets(ticketsForReturn);
                                        // 将java对象转换为XML字符串
                                        JaxbUtil2 requestBinder = new JaxbUtil2(ResponseParameter.class,
                                                CollectionWrapper.class);
                                        resXML = requestBinder.toXml(responseParameter, "utf-8");
                                        resultStr = resXML;
                                    }else {
                                        errorString = "锁号失败！请联系管理员";
                                        resultStr = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?> <response> <code>"
                                                + "10013" + "</code><msg>" + errorString + "</msg></response> ";
                                    }
                                } else {
                                    errorString = "当前条件没有可用的号源记录";
                                    resultStr = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?> <response> <code>"
                                            + "10012" + "</code><msg>" + errorString + "</msg></response> ";
                                }

                            } else {
                                errorString = "请求已经过期";
                                resultStr = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?> <response> <code>"
                                        + "10002" + "</code><msg>" + errorString + "</msg></response> ";
                            }
                        } catch (Exception e) {
                            errorString = "出现未知异常";
                            resultStr = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?> <response> <code>"
                                    + "99999" + "</code><msg>" + errorString + "</msg></response> ";
                            logger.debug("################################################################出现未知异常"
                                    + e.getStackTrace());
                        }
                    } else {
                        errorString = "签名认证失败";
                        resultStr = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?> <response> <code>"
                                + "10008" + "</code><msg>" + errorString + "</msg></response> ";
                        logger.debug("################################################################签名认证失败");
                    }
                } else {
                    errorString = "找到重复的厂商信息";
                    resultStr = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?> <response> <code>" + "10003"
                            + "</code><msg>" + errorString + "</msg></response> ";
                    logger.debug("################################################################找到重复的厂商信息");
                }
            } else {
                errorString = "没有该厂商的授权信息";
                resultStr = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?> <response> <code>" + "10004"
                        + "</code><msg>" + errorString + "</msg></response> ";
                logger.debug("################################################################没有该厂商的信息");
            }
        } catch (JSONException e) {
            errorString = "数据转换错误(JSONException)";
            resultStr = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\" ?> <response> <code>" + "10006"
                    + "</code><msg>" + errorString + "</msg></response> ";
            logger.debug("################################################################数据转换错误(JSONException)："
                    + e.toString());
        } catch (Exception e) {
            errorString = "流异常(IOException)";
            resultStr = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?> <response> <code>" + "10007"
                    + "</code><msg>" + errorString + "</msg></response> ";
            logger.debug("#######################################################################流异常(IOException)："
                    + e.toString());
        }
        return resultStr;
    }



    /**
     *
     * @Title: queryTicketList @Description:
     *         TODO(查询所有符合条件的可预约号源明细记录list) @param @param
     *         requestParameter @param @return 设定文件 @return String 返回类型 @throws
     */
    @RequestMapping(value = "/queryTicketList", consumes = "application/xml", method = RequestMethod.POST)
    @ResponseBody
    public String queryTicketList(@RequestBody RequestParameter requestParameter) {
        logger.debug("###########################################查询可预约号列表接口queryTicketList方法开始");
        logger.debug("###################################################接收到的body值：" + requestParameter);
        String resultStr = null;
        String str = null;
        String errorString = null;
        String resXML = null;
        ObjectMapper mapper = new ObjectMapper(); // 转换器
        // 全局DeserializationFeature配置：配置该objectMapper在反序列化时，忽略目标对象没有的属性。凡是使用该objectMapper反序列化时，都会拥有该特性。
        mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
        try {
            logger.debug("###########################################查询厂商授权私钥记录开始");
            // Example查询类
            VendorInfoExample example = new VendorInfoExample();
            example.or().andVendorCodeEqualTo(requestParameter.getVendorCode())
                    .andVendorNameEqualTo(requestParameter.getVendorName()).andDeleteFlagEqualTo(1);
            vendorInfos = preregService.selectVendorList(example);
            logger.debug("###########################################查询厂商授权私钥记录条数：" + vendorInfos.size());
            if (vendorInfos.size() > 0) {
                logger.debug("###########################################查询厂商授权私钥记录条数大于0，条数为：" + vendorInfos.size());
                if (vendorInfos.size() == 1) {
                    logger.debug("###########################################查询厂商授权私钥记录条数为1，即找到唯一一条记录，签名开始");
                    // 将传入的Java类转换为Json串
                    str = JSONUtil.objectToJson(requestParameter).toString();
                    logger.debug("##########################################body值转换为Json串：" + str);
                    // 准备签名工作
                    RequestParameterForPrereg requestParamForPrereg = new RequestParameterForPrereg();
                    requestParamForPrereg = (RequestParameterForPrereg) mapper.readValue(str,
                            RequestParameterForPrereg.class);
                    Map<String, String> params = new HashMap<String, String>();
                    params = ClassUtil.setConditionMap(requestParamForPrereg);
                    // 签名有两个步骤，先按一定规则拼接要签名的原始串，再选择具体的算法和密钥计算出签名结果。
                    // 拼原始串
                    Map<String, String> filterMap = EpayMD5.paraFilter(params);
                    String linkStr = EpayMD5.createLinkString(filterMap);
                    logger.debug("######################################MD5签名拼原始串的值：" + linkStr);
                    // 签名（签名时把私钥（key）加入进行MD5签名）
                    String serverSign = EpayMD5.sign(linkStr, vendorInfos.get(0).getLicenseCode(), "UTF-8");
                    logger.debug("###################################私钥（key）加入进行MD5签名后的值：" + serverSign);
                    // 验签过程
                    if (serverSign.equals(requestParameter.getSign())) {
                        Long clientTime = new Long(requestParameter.getTimeStamp());
                        Date serverDate = new Date();
                        Long serverTime = serverDate.getTime() / 1000;
                        try {
                            long interval = serverTime - clientTime;
                            // 验证是否过期:默认300s
                            if (interval < 300) {
                                List<Ticket> tickets = null;
                                // 显示保留号
                                if (vendorInfos.get(0).getRetainShowFlag().equals("0")) {
                                    tickets = preregService.selectTicketsAll(requestParameter.getStartDate(),
                                            requestParameter.getEndDate(), requestParameter.getTimeInteval(),
                                            requestParameter.getSectionNo(), requestParameter.getDoctorNo());
                                } else {// 不显示保留号
                                    tickets = preregService.selectTicketsNoRetain(requestParameter.getStartDate(),
                                            requestParameter.getEndDate(), requestParameter.getTimeInteval(),
                                            requestParameter.getSectionNo(), requestParameter.getDoctorNo());
                                }
                                if (tickets.size() > 0) {
                                    ResponseParameter responseParameter = new ResponseParameter();
                                    responseParameter.setCode("0");
                                    responseParameter.setMsg("请求成功");
                                    responseParameter.setSign(requestParameter.getSign());
                                    responseParameter.setTickets(tickets);
                                    // 将java对象转换为XML字符串
                                    JaxbUtil2 requestBinder = new JaxbUtil2(ResponseParameter.class,
                                            CollectionWrapper.class);
                                    resXML = requestBinder.toXml(responseParameter, "utf-8");
                                    resultStr = resXML;
                                } else {
                                    errorString = "当前条件没有可用的号源记录";
                                    resultStr = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?> <response> <code>"
                                            + "-1" + "</code><msg>" + errorString + "</msg></response> ";
                                }
                            } else {
                                errorString = "请求已经过期";
                                resultStr = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?> <response> <code>"
                                        + "-1" + "</code><msg>" + errorString + "</msg></response> ";
                            }
                        } catch (Exception e) {
                            errorString = "出现未知异常";
                            resultStr = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?> <response> <code>"
                                    + "-1" + "</code><msg>" + errorString + "</msg></response> ";
                            logger.debug("################################################################出现未知异常"
                                    + e.getStackTrace());
                        }
                    } else {
                        errorString = "签名认证失败";
                        resultStr = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?> <response> <code>"
                                + "-1" + "</code><msg>" + errorString + "</msg></response> ";
                        logger.debug("################################################################签名认证失败");
                    }
                } else {
                    errorString = "找到重复的厂商信息";
                    resultStr = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?> <response> <code>" + "-1"
                            + "</code><msg>" + errorString + "</msg></response> ";
                    logger.debug("################################################################找到重复的厂商信息");
                }
            } else {
                errorString = "没有该厂商的授权信息";
                resultStr = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?> <response> <code>" + "-1"
                        + "</code><msg>" + errorString + "</msg></response> ";
                logger.debug("################################################################没有该厂商的信息");
            }
        } catch (JSONException e) {
            errorString = "数据转换错误(JSONException)";
            resultStr = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\" ?> <response> <code>" + "-1"
                    + "</code><msg>" + errorString + "</msg></response> ";
            logger.debug("################################################################数据转换错误(JSONException)："
                    + e.toString());
        } catch (Exception e) {
            errorString = "流异常(IOException)";
            resultStr = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?> <response> <code>" + "-1"
                    + "</code><msg>" + errorString + "</msg></response> ";
            logger.debug("#######################################################################流异常(IOException)："
                    + e.toString());
        }
        return resultStr;
    }

    /**
     *
     * @Title: reserveById @Description: TODO(这里用一句话描述这个方法的作用) @param @param
     * requestParameter @param @return 设定文件 @return String 返回类型 @throws
     */
    @RequestMapping(value = "/reserveById", consumes = "application/xml", method = RequestMethod.POST)
    @ResponseBody
    public String reserveById(@RequestBody RequestParameter requestParameter) {
        logger.debug("###########################################根据主键预约接口reserveById方法开始");
        logger.debug("###################################################接收到的body值：" + requestParameter);
        String resultStr = null;
        String str = null;
        String errorString = null;
        String resXML = null;
        ObjectMapper mapper = new ObjectMapper(); // 转换器
        // 全局DeserializationFeature配置：配置该objectMapper在反序列化时，忽略目标对象没有的属性。凡是使用该objectMapper反序列化时，都会拥有该特性。
        mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
        try {
            logger.debug("###########################################查询厂商授权私钥记录开始");
            // Example查询类
            VendorInfoExample example = new VendorInfoExample();
            example.or().andVendorCodeEqualTo(requestParameter.getVendorCode())
                    .andVendorNameEqualTo(requestParameter.getVendorName()).andDeleteFlagEqualTo(1);
            vendorInfos = preregService.selectVendorList(example);
            logger.debug("###########################################查询厂商授权私钥记录条数：" + vendorInfos.size());
            if (vendorInfos.size() > 0) {
                logger.debug("###########################################查询厂商授权私钥记录条数大于0，条数为：" + vendorInfos.size());
                if (vendorInfos.size() == 1) {
                    logger.debug("###########################################查询厂商授权私钥记录条数为1，即找到唯一一条记录，签名开始");
                    // 将传入的Java类转换为Json串
                    str = JSONUtil.objectToJson(requestParameter).toString();
                    logger.debug("##########################################body值转换为Json串：" + str);
                    // 准备签名工作
                    RequestParameterForPrereg requestParamForPrereg = new RequestParameterForPrereg();
                    requestParamForPrereg = (RequestParameterForPrereg) mapper.readValue(str,
                            RequestParameterForPrereg.class);
                    Map<String, String> params = new HashMap<String, String>();
                    params = ClassUtil.setConditionMap(requestParamForPrereg);
                    // 签名有两个步骤，先按一定规则拼接要签名的原始串，再选择具体的算法和密钥计算出签名结果。
                    // 拼原始串
                    Map<String, String> filterMap = EpayMD5.paraFilter(params);
                    String linkStr = EpayMD5.createLinkString(filterMap);
                    logger.debug("######################################MD5签名拼原始串的值：" + linkStr);
                    // 签名（签名时把私钥（key）加入进行MD5签名）
                    String serverSign = EpayMD5.sign(linkStr, vendorInfos.get(0).getLicenseCode(), "UTF-8");
                    logger.debug("###################################私钥（key）加入进行MD5签名后的值：" + serverSign);
                    // 验签过程
                    if (serverSign.equals(requestParameter.getSign())) {
                        Long clientTime = new Long(requestParameter.getTimeStamp());
                        Date serverDate = new Date();
                        Long serverTime = serverDate.getTime() / 1000;
                        try {
                            long interval = serverTime - clientTime;
                            // 验证是否过期:默认300s
                            if (interval < 300) {
                                // 插入预约表，并更新原号表记录标记为已预约
                                OrderReg orderReg = new OrderReg();
                                orderReg.setId(requestParameter.getPlanId());
                                orderReg.setOrderDate(requestParameter.getOrderDate());
                                orderReg.setOrderName(requestParameter.getOrderName());
                                orderReg.setPhoneNumber(requestParameter.getPhoneNo());
                                orderReg.setOrderSectionNo(requestParameter.getSectionNo());
                                orderReg.setOrderSectionName(requestParameter.getSectionName());
                                orderReg.setOrderDoctorNo(requestParameter.getDoctorNo());
                                orderReg.setOrderDoctorName(requestParameter.getDoctorName());
                                orderReg.setOrderType(requestParameter.getOrderType());
                                orderReg.setRegType(requestParameter.getTimeInteval());
                                orderReg.setRegCategoryNo(requestParameter.getSchedulesNo());
                                orderReg.setRegCategoryName(requestParameter.getSchedulesName());
                                orderReg.setOrderSource(requestParameter.getOrderSource());
                                orderReg.setSortNo(requestParameter.getSortNo());
                                orderReg.setPatientCardNo(requestParameter.getCardNo());
                                orderReg.setPatientIdcardNo(requestParameter.getIdNo());
                                orderReg.setRegStatus("0");// 预约状态：0-正常，1-取号， 2-作废， 9-取消；默认0-正常
                                orderReg.setOrderTime(requestParameter.getOrderTime());
                                orderReg.setPlanId(requestParameter.getPlanId());
                                int num = preregService.insertAndUpdate(orderReg);
                                ResponseParameter responseParameter = new ResponseParameter();
                                if (num == 2) {
                                    responseParameter.setCode("0");
                                    responseParameter.setMsg("预约成功");
                                    responseParameter.setSign(requestParameter.getSign());
                                } else {
                                    responseParameter.setCode("-1");
                                    responseParameter.setMsg("预约失败");
                                    responseParameter.setSign(requestParameter.getSign());
                                }
                                // 将java对象转换为XML字符串
                                JaxbUtil2 requestBinder = new JaxbUtil2(ResponseParameter.class,
                                        CollectionWrapper.class);
                                resXML = requestBinder.toXml(responseParameter, "utf-8");
                                resultStr = resXML;
                            } else {
                                errorString = "请求已经过期";
                                resultStr = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?> <response> <code>"
                                        + "-1" + "</code><msg>" + errorString + "</msg></response> ";
                            }
                        } catch (Exception e) {
                            errorString = "出现未知异常";
                            resultStr = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?> <response> <code>"
                                    + "-1" + "</code><msg>" + errorString + "</msg></response> ";
                            logger.debug("################################################################出现未知异常"
                                    + e.getStackTrace());
                        }
                    } else {
                        errorString = "签名认证失败";
                        resultStr = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?> <response> <code>"
                                + "-1" + "</code><msg>" + errorString + "</msg></response> ";
                        logger.debug("################################################################签名认证失败");
                    }
                } else {
                    errorString = "找到重复的厂商信息";
                    resultStr = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?> <response> <code>" + "-1"
                            + "</code><msg>" + errorString + "</msg></response> ";
                    logger.debug("################################################################找到重复的厂商信息");
                }
            } else {
                errorString = "没有该厂商的授权信息";
                resultStr = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?> <response> <code>" + "-1"
                        + "</code><msg>" + errorString + "</msg></response> ";
                logger.debug("################################################################没有该厂商的信息");
            }
        } catch (JSONException e) {
            errorString = "数据转换错误(JSONException)";
            resultStr = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\" ?> <response> <code>" + "-1"
                    + "</code><msg>" + errorString + "</msg></response> ";
            logger.debug("################################################################数据转换错误(JSONException)："
                    + e.toString());
        } catch (Exception e) {
            errorString = "流异常(IOException)";
            resultStr = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?> <response> <code>" + "-1"
                    + "</code><msg>" + errorString + "</msg></response> ";
            logger.debug("#######################################################################流异常(IOException)："
                    + e.toString());
        }
        return resultStr;
    }

    /**
     *
     * @Title: reserveByRegTime @Description: TODO(这里用一句话描述这个方法的作用) @param @param
     * requestParameter @param @return 设定文件 @return String 返回类型 @throws
     */
    @RequestMapping(value = "/reserveByRegTime", consumes = "application/xml", method = RequestMethod.POST)
    @ResponseBody
    public String reserveByRegTime(@RequestBody RequestParameter requestParameter) {
        logger.debug("###########################################根据挂号时间预约接口reserveByRegTime方法开始");
        logger.debug("###################################################接收到的body值：" + requestParameter);
        String resultStr = null;
        String str = null;
        String errorString = null;
        String resXML = null;
        ObjectMapper mapper = new ObjectMapper(); // 转换器
        // 全局DeserializationFeature配置：配置该objectMapper在反序列化时，忽略目标对象没有的属性。凡是使用该objectMapper反序列化时，都会拥有该特性。
        mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
        try {
            logger.debug("###########################################查询厂商授权私钥记录开始");
            // Example查询类
            VendorInfoExample example = new VendorInfoExample();
            example.or().andVendorCodeEqualTo(requestParameter.getVendorCode())
                    .andVendorNameEqualTo(requestParameter.getVendorName()).andDeleteFlagEqualTo(1);
            vendorInfos = preregService.selectVendorList(example);
            logger.debug("###########################################查询厂商授权私钥记录条数：" + vendorInfos.size());
            if (vendorInfos.size() > 0) {
                logger.debug("###########################################查询厂商授权私钥记录条数大于0，条数为：" + vendorInfos.size());
                if (vendorInfos.size() == 1) {
                    logger.debug("###########################################查询厂商授权私钥记录条数为1，即找到唯一一条记录，签名开始");
                    // 将传入的Java类转换为Json串
                    str = JSONUtil.objectToJson(requestParameter).toString();
                    logger.debug("##########################################body值转换为Json串：" + str);
                    // 准备签名工作
                    RequestParameterForPrereg requestParamForPrereg = new RequestParameterForPrereg();
                    requestParamForPrereg = (RequestParameterForPrereg) mapper.readValue(str,
                            RequestParameterForPrereg.class);
                    Map<String, String> params = new HashMap<String, String>();
                    params = ClassUtil.setConditionMap(requestParamForPrereg);
                    // 签名有两个步骤，先按一定规则拼接要签名的原始串，再选择具体的算法和密钥计算出签名结果。
                    // 拼原始串
                    Map<String, String> filterMap = EpayMD5.paraFilter(params);
                    String linkStr = EpayMD5.createLinkString(filterMap);
                    logger.debug("######################################MD5签名拼原始串的值：" + linkStr);
                    // 签名（签名时把私钥（key）加入进行MD5签名）
                    String serverSign = EpayMD5.sign(linkStr, vendorInfos.get(0).getLicenseCode(), "UTF-8");
                    logger.debug("###################################私钥（key）加入进行MD5签名后的值：" + serverSign);
                    // 验签过程
                    if (serverSign.equals(requestParameter.getSign())) {
                        Long clientTime = new Long(requestParameter.getTimeStamp());
                        Date serverDate = new Date();
                        Long serverTime = serverDate.getTime() / 1000;
                        try {
                            long interval = serverTime - clientTime;
                            // 验证是否过期:默认300s
                            if (interval < 300) {
                                List<Ticket> tickets = null;
                                // 显示保留号
                                tickets = preregService.selectTicketsByRegTime(requestParameter.getRegTime(),
                                        requestParameter.getTimeInteval(), requestParameter.getSectionNo(),
                                        requestParameter.getDoctorNo());
                                if (tickets.size() > 0) {
                                    // 插入预约表，并更新原号表记录标记为已预约
                                    OrderReg orderReg = new OrderReg();
                                    orderReg.setId(tickets.get(0).getPlanId());
                                    orderReg.setOrderDate(requestParameter.getOrderDate());
                                    orderReg.setOrderName(requestParameter.getOrderName());
                                    orderReg.setPhoneNumber(requestParameter.getPhoneNo());
                                    orderReg.setPatientCardNo(requestParameter.getCardNo());
                                    orderReg.setPatientIdcardNo(requestParameter.getIdNo());
                                    orderReg.setOrderSectionNo(requestParameter.getSectionNo());
                                    orderReg.setOrderSectionName(requestParameter.getSectionName());
                                    orderReg.setOrderDoctorNo(requestParameter.getDoctorNo());
                                    orderReg.setOrderDoctorName(requestParameter.getDoctorName());
                                    orderReg.setOrderType(requestParameter.getOrderType());
                                    orderReg.setRegType(requestParameter.getTimeInteval());
                                    orderReg.setRegCategoryNo(tickets.get(0).getSchedulesNo());
                                    orderReg.setRegCategoryName(tickets.get(0).getSchedulesName());
                                    orderReg.setOrderSource(requestParameter.getOrderSource());
                                    orderReg.setSortNo(tickets.get(0).getSortNo());
                                    orderReg.setRegStatus("0");// 预约状态：0-正常，1-取号， 2-作废， 9-取消；默认0-正常
                                    orderReg.setOrderTime(requestParameter.getOrderTime());
                                    orderReg.setPlanId(tickets.get(0).getPlanId());
                                    int num = preregService.insertAndUpdate(orderReg);
                                    ResponseParameter responseParameter = new ResponseParameter();
                                    if (num == 2) {
                                        responseParameter.setCode("0");
                                        responseParameter.setMsg("预约成功");
                                        responseParameter.setSign(requestParameter.getSign());
                                    } else {
                                        responseParameter.setCode("-1");
                                        responseParameter.setMsg("预约失败");
                                        responseParameter.setSign(requestParameter.getSign());
                                    }
                                    // 将java对象转换为XML字符串
                                    JaxbUtil2 requestBinder = new JaxbUtil2(ResponseParameter.class,
                                            CollectionWrapper.class);
                                    resXML = requestBinder.toXml(responseParameter, "utf-8");
                                    resultStr = resXML;
                                } else {
                                    errorString = "没有可预约的号源";
                                    resultStr = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?> <response> <code>"
                                            + "-1" + "</code><msg>" + errorString + "</msg></response> ";
                                }
                            } else {
                                errorString = "请求已经过期";
                                resultStr = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?> <response> <code>"
                                        + "-1" + "</code><msg>" + errorString + "</msg></response> ";
                            }
                        } catch (Exception e) {
                            errorString = "出现未知异常";
                            resultStr = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?> <response> <code>"
                                    + "-1" + "</code><msg>" + errorString + "</msg></response> ";
                            logger.debug("################################################################出现未知异常"
                                    + e.getStackTrace());
                        }
                    } else {
                        errorString = "签名认证失败";
                        resultStr = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?> <response> <code>"
                                + "-1" + "</code><msg>" + errorString + "</msg></response> ";
                        logger.debug("################################################################签名认证失败");
                    }
                } else {
                    errorString = "找到重复的厂商信息";
                    resultStr = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?> <response> <code>" + "-1"
                            + "</code><msg>" + errorString + "</msg></response> ";
                    logger.debug("################################################################找到重复的厂商信息");
                }
            } else {
                errorString = "没有该厂商的授权信息";
                resultStr = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?> <response> <code>" + "-1"
                        + "</code><msg>" + errorString + "</msg></response> ";
                logger.debug("################################################################没有该厂商的信息");
            }
        } catch (JSONException e) {
            errorString = "数据转换错误(JSONException)";
            resultStr = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\" ?> <response> <code>" + "-1"
                    + "</code><msg>" + errorString + "</msg></response> ";
            logger.debug("################################################################数据转换错误(JSONException)："
                    + e.toString());
        } catch (Exception e) {
            errorString = "流异常(IOException)";
            resultStr = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?> <response> <code>" + "-1"
                    + "</code><msg>" + errorString + "</msg></response> ";
            logger.debug("#######################################################################流异常(IOException)："
                    + e.toString());
        }
        return resultStr;
    }


    /**
     *查询预约列表接口
     * @Title: reserveByRegTime @Description: TODO(查询患者的预约信息) @param @param
     * requestParameter @param @return 设定文件 @return String 返回类型 @throws
     */
    @RequestMapping(value = "/queryPreregedTickets", consumes = "application/xml", method = RequestMethod.POST)
    @ResponseBody
    public String queryPreregedTickets(@RequestBody RequestParameter requestParameter) {
        logger.debug("###########################################查询患者的预约信息接口queryPreregedTickets方法开始");
        logger.debug("###################################################接收到的body值：" + requestParameter);
        String resultStr = null;
        String str = null;
        String errorString = null;
        String resXML = null;
        ObjectMapper mapper = new ObjectMapper(); // 转换器
        // 全局DeserializationFeature配置：配置该objectMapper在反序列化时，忽略目标对象没有的属性。凡是使用该objectMapper反序列化时，都会拥有该特性。
        mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
        try {
            logger.debug("###########################################查询厂商授权私钥记录开始");
            // Example查询类
            VendorInfoExample example = new VendorInfoExample();
            example.or().andVendorCodeEqualTo(requestParameter.getVendorCode())
                    .andVendorNameEqualTo(requestParameter.getVendorName()).andDeleteFlagEqualTo(1);
            vendorInfos = preregService.selectVendorList(example);
            logger.debug("###########################################查询厂商授权私钥记录条数：" + vendorInfos.size());
            if (vendorInfos.size() > 0) {
                logger.debug("###########################################查询厂商授权私钥记录条数大于0，条数为：" + vendorInfos.size());
                if (vendorInfos.size() == 1) {
                    logger.debug("###########################################查询厂商授权私钥记录条数为1，即找到唯一一条记录，签名开始");
                    // 将传入的Java类转换为Json串
                    str = JSONUtil.objectToJson(requestParameter).toString();
                    logger.debug("##########################################body值转换为Json串：" + str);
                    // 准备签名工作
                    RequestParameterForPrereg requestParamForPrereg = new RequestParameterForPrereg();
                    requestParamForPrereg = (RequestParameterForPrereg) mapper.readValue(str,
                            RequestParameterForPrereg.class);
                    Map<String, String> params = new HashMap<String, String>();
                    params = ClassUtil.setConditionMap(requestParamForPrereg);
                    // 签名有两个步骤，先按一定规则拼接要签名的原始串，再选择具体的算法和密钥计算出签名结果。
                    // 拼原始串
                    Map<String, String> filterMap = EpayMD5.paraFilter(params);
                    String linkStr = EpayMD5.createLinkString(filterMap);
                    logger.debug("######################################MD5签名拼原始串的值：" + linkStr);
                    // 签名（签名时把私钥（key）加入进行MD5签名）
                    String serverSign = EpayMD5.sign(linkStr, vendorInfos.get(0).getLicenseCode(), "UTF-8");
                    logger.debug("###################################私钥（key）加入进行MD5签名后的值：" + serverSign);
                    // 验签过程
                    if (serverSign.equals(requestParameter.getSign())) {
                        Long clientTime = new Long(requestParameter.getTimeStamp());
                        Date serverDate = new Date();
                        Long serverTime = serverDate.getTime() / 1000;
                        try {
                            long interval = serverTime - clientTime;
                            // 验证是否过期:默认300s
                            if (interval < 300) {
                                List<OrderTicket> orderTickets = null;
                                // 预约记录list
                                orderTickets = preregService.selectPreregedTickets(requestParameter.getCardNo(),requestParameter.getVisitDate());
                                if (orderTickets.size() > 0) {
                                    ResponseParameter responseParameter = new ResponseParameter();
                                    responseParameter.setCode("0");
                                    responseParameter.setMsg("查询成功");
                                    responseParameter.setSign(requestParameter.getSign());
                                    responseParameter.setOrderTickets(orderTickets);
                                    // 将java对象转换为XML字符串
                                    JaxbUtil2 requestBinder = new JaxbUtil2(ResponseParameter.class,
                                            CollectionWrapper.class);
                                    resXML = requestBinder.toXml(responseParameter, "utf-8");
                                    resultStr = resXML;
                                } else {
                                    errorString = "您没有预约记录";
                                    resultStr = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?> <response> <code>"
                                            + "-1" + "</code><msg>" + errorString + "</msg></response> ";
                                }
                            } else {
                                errorString = "请求已经过期";
                                resultStr = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?> <response> <code>"
                                        + "-1" + "</code><msg>" + errorString + "</msg></response> ";
                            }
                        } catch (Exception e) {
                            errorString = "出现未知异常";
                            resultStr = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?> <response> <code>"
                                    + "-1" + "</code><msg>" + errorString + "</msg></response> ";
                            logger.debug("################################################################出现未知异常"
                                    + e.getStackTrace());
                        }
                    } else {
                        errorString = "签名认证失败";
                        resultStr = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?> <response> <code>"
                                + "-1" + "</code><msg>" + errorString + "</msg></response> ";
                        logger.debug("################################################################签名认证失败");
                    }
                } else {
                    errorString = "找到重复的厂商信息";
                    resultStr = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?> <response> <code>" + "-1"
                            + "</code><msg>" + errorString + "</msg></response> ";
                    logger.debug("################################################################找到重复的厂商信息");
                }
            } else {
                errorString = "没有该厂商的授权信息";
                resultStr = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?> <response> <code>" + "-1"
                        + "</code><msg>" + errorString + "</msg></response> ";
                logger.debug("################################################################没有该厂商的信息");
            }
        } catch (JSONException e) {
            errorString = "数据转换错误(JSONException)";
            resultStr = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\" ?> <response> <code>" + "-1"
                    + "</code><msg>" + errorString + "</msg></response> ";
            logger.debug("################################################################数据转换错误(JSONException)："
                    + e.toString());
        } catch (Exception e) {
            errorString = "流异常(IOException)";
            resultStr = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?> <response> <code>" + "-1"
                    + "</code><msg>" + errorString + "</msg></response> ";
            logger.debug("#######################################################################流异常(IOException)："
                    + e.toString());
        }
        return resultStr;
    }


    /**
     *预约取号接口
     * @param requestParameter
     * @return
     */
    @RequestMapping(value = "/getTickets", consumes = "application/xml", method = RequestMethod.POST)
    @ResponseBody
    public String getPreregedTickets(@RequestBody RequestParameter requestParameter) {
        logger.debug("###########################################取号接口getTickets方法开始");
        logger.debug("###################################################接收到的body值：" + requestParameter);
        String resultStr = null;
        String str = null;
        String errorString = null;
        String resXML = null;
        ObjectMapper mapper = new ObjectMapper(); // 转换器
        // 全局DeserializationFeature配置：配置该objectMapper在反序列化时，忽略目标对象没有的属性。凡是使用该objectMapper反序列化时，都会拥有该特性。
        mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
        try {
            logger.debug("###########################################查询厂商授权私钥记录开始");
            // Example查询类
            VendorInfoExample example = new VendorInfoExample();
            example.or().andVendorCodeEqualTo(requestParameter.getVendorCode())
                    .andVendorNameEqualTo(requestParameter.getVendorName()).andDeleteFlagEqualTo(1);
            vendorInfos = preregService.selectVendorList(example);
            logger.debug("###########################################查询厂商授权私钥记录条数：" + vendorInfos.size());
            if (vendorInfos.size() > 0) {
                logger.debug("###########################################查询厂商授权私钥记录条数大于0，条数为：" + vendorInfos.size());
                if (vendorInfos.size() == 1) {
                    logger.debug("###########################################查询厂商授权私钥记录条数为1，即找到唯一一条记录，签名开始");
                    // 将传入的Java类转换为Json串
                    str = JSONUtil.objectToJson(requestParameter).toString();
                    logger.debug("##########################################body值转换为Json串：" + str);
                    // 准备签名工作
                    RequestParameterForPrereg requestParamForPrereg = new RequestParameterForPrereg();
                    requestParamForPrereg = (RequestParameterForPrereg) mapper.readValue(str,
                            RequestParameterForPrereg.class);
                    Map<String, String> params = new HashMap<String, String>();
                    params = ClassUtil.setConditionMap(requestParamForPrereg);
                    // 签名有两个步骤，先按一定规则拼接要签名的原始串，再选择具体的算法和密钥计算出签名结果。
                    // 拼原始串
                    Map<String, String> filterMap = EpayMD5.paraFilter(params);
                    String linkStr = EpayMD5.createLinkString(filterMap);
                    logger.debug("######################################MD5签名拼原始串的值：" + linkStr);
                    // 签名（签名时把私钥（key）加入进行MD5签名）
                    String serverSign = EpayMD5.sign(linkStr, vendorInfos.get(0).getLicenseCode(), "UTF-8");
                    logger.debug("###################################私钥（key）加入进行MD5签名后的值：" + serverSign);
                    // 验签过程
                    if (serverSign.equals(requestParameter.getSign())) {
                        Long clientTime = new Long(requestParameter.getTimeStamp());
                        Date serverDate = new Date();
                        Long serverTime = serverDate.getTime() / 1000;
                        try {
                            long interval = serverTime - clientTime;
                            // 验证是否过期:默认300s
                            if (interval < 300) {
                                if (!requestParameter.getPlanId().equals("") && !requestParameter.getPlanId().equals(null)) {
                                    ResponseParameter responseParameter = new ResponseParameter();
                                    int num=preregService.updateStatusFlag(requestParameter.getPlanId());
                                    if (num>0){
                                        responseParameter.setCode("0");
                                        responseParameter.setMsg("取号成功");
                                        responseParameter.setSign(requestParameter.getSign());
                                    }else {
                                        responseParameter.setCode("-1");
                                        responseParameter.setMsg("取号失败");
                                    }
                                    // 将java对象转换为XML字符串
                                    JaxbUtil2 requestBinder = new JaxbUtil2(ResponseParameter.class,
                                            CollectionWrapper.class);
                                    resXML = requestBinder.toXml(responseParameter, "utf-8");
                                    resultStr = resXML;
                                } else {
                                    errorString = "预约记录ID不能为空";
                                    resultStr = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?> <response> <code>"
                                            + "-1" + "</code><msg>" + errorString + "</msg></response> ";
                                }
                            } else {
                                errorString = "请求已经过期";
                                resultStr = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?> <response> <code>"
                                        + "-1" + "</code><msg>" + errorString + "</msg></response> ";
                            }
                        } catch (Exception e) {
                            errorString = "出现未知异常";
                            resultStr = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?> <response> <code>"
                                    + "-1" + "</code><msg>" + errorString + "</msg></response> ";
                            logger.debug("################################################################出现未知异常"
                                    + e.getStackTrace());
                        }
                    } else {
                        errorString = "签名认证失败";
                        resultStr = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?> <response> <code>"
                                + "-1" + "</code><msg>" + errorString + "</msg></response> ";
                        logger.debug("################################################################签名认证失败");
                    }
                } else {
                    errorString = "找到重复的厂商信息";
                    resultStr = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?> <response> <code>" + "-1"
                            + "</code><msg>" + errorString + "</msg></response> ";
                    logger.debug("################################################################找到重复的厂商信息");
                }
            } else {
                errorString = "没有该厂商的授权信息";
                resultStr = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?> <response> <code>" + "-1"
                        + "</code><msg>" + errorString + "</msg></response> ";
                logger.debug("################################################################没有该厂商的信息");
            }
        } catch (JSONException e) {
            errorString = "数据转换错误(JSONException)";
            resultStr = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\" ?> <response> <code>" + "-1"
                    + "</code><msg>" + errorString + "</msg></response> ";
            logger.debug("################################################################数据转换错误(JSONException)："
                    + e.toString());
        } catch (Exception e) {
            errorString = "流异常(IOException)";
            resultStr = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?> <response> <code>" + "-1"
                    + "</code><msg>" + errorString + "</msg></response> ";
            logger.debug("#######################################################################流异常(IOException)："
                    + e.toString());
        }
        return resultStr;
    }



    /**
     *查询某医生的预约病人信息列表接口
     * @Title: reserveByRegTime @Description: TODO(查询患者的预约信息) @param @param
     * requestParameter @param @return 设定文件 @return String 返回类型 @throws
     */
    @RequestMapping(value = "/queryPreregedPatients", consumes = "application/xml", method = RequestMethod.POST)
    @ResponseBody
    public String queryPreregedPatients(@RequestBody RequestParameter requestParameter) {
        logger.debug("###########################################查询某医生的预约病人信息列表接口queryPreregedPatients方法开始");
        logger.debug("###################################################接收到的body值：" + requestParameter);
        String resultStr = null;
        String str = null;
        String errorString = null;
        String resXML = null;
        ObjectMapper mapper = new ObjectMapper(); // 转换器
        // 全局DeserializationFeature配置：配置该objectMapper在反序列化时，忽略目标对象没有的属性。凡是使用该objectMapper反序列化时，都会拥有该特性。
        mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
        try {
            logger.debug("###########################################查询厂商授权私钥记录开始");
            // Example查询类
            VendorInfoExample example = new VendorInfoExample();
            example.or().andVendorCodeEqualTo(requestParameter.getVendorCode())
                    .andVendorNameEqualTo(requestParameter.getVendorName()).andDeleteFlagEqualTo(1);
            vendorInfos = preregService.selectVendorList(example);
            logger.debug("###########################################查询厂商授权私钥记录条数：" + vendorInfos.size());
            if (vendorInfos.size() > 0) {
                logger.debug("###########################################查询厂商授权私钥记录条数大于0，条数为：" + vendorInfos.size());
                if (vendorInfos.size() == 1) {
                    logger.debug("###########################################查询厂商授权私钥记录条数为1，即找到唯一一条记录，签名开始");
                    // 将传入的Java类转换为Json串
                    str = JSONUtil.objectToJson(requestParameter).toString();
                    logger.debug("##########################################body值转换为Json串：" + str);
                    // 准备签名工作
                    RequestParameterForPrereg requestParamForPrereg = new RequestParameterForPrereg();
                    requestParamForPrereg = (RequestParameterForPrereg) mapper.readValue(str,
                            RequestParameterForPrereg.class);
                    Map<String, String> params = new HashMap<String, String>();
                    params = ClassUtil.setConditionMap(requestParamForPrereg);
                    // 签名有两个步骤，先按一定规则拼接要签名的原始串，再选择具体的算法和密钥计算出签名结果。
                    // 拼原始串
                    Map<String, String> filterMap = EpayMD5.paraFilter(params);
                    String linkStr = EpayMD5.createLinkString(filterMap);
                    logger.debug("######################################MD5签名拼原始串的值：" + linkStr);
                    // 签名（签名时把私钥（key）加入进行MD5签名）
                    String serverSign = EpayMD5.sign(linkStr, vendorInfos.get(0).getLicenseCode(), "UTF-8");
                    logger.debug("###################################私钥（key）加入进行MD5签名后的值：" + serverSign);
                    // 验签过程
                    if (serverSign.equals(requestParameter.getSign())) {
                        Long clientTime = new Long(requestParameter.getTimeStamp());
                        Date serverDate = new Date();
                        Long serverTime = serverDate.getTime() / 1000;
                        try {
                            long interval = serverTime - clientTime;
                            // 验证是否过期:默认300s
                            if (interval < 300) {
                                List<PreregedPatient> patients = null;
                                // 预约记录list
                                patients = preregService.selectPreregedPatients(requestParameter.getDoctorNo(),requestParameter.getStartDate(),requestParameter.getEndDate());
                                if (patients.size() > 0) {
                                    ResponseParameter responseParameter = new ResponseParameter();
                                    responseParameter.setCode("0");
                                    responseParameter.setMsg("查询成功");
                                    responseParameter.setSign(requestParameter.getSign());
                                    responseParameter.setPatients(patients);
                                    // 将java对象转换为XML字符串
                                    JaxbUtil2 requestBinder = new JaxbUtil2(ResponseParameter.class,
                                            CollectionWrapper.class);
                                    resXML = requestBinder.toXml(responseParameter, "utf-8");
                                    resultStr = resXML;
                                } else {
                                    errorString = "没有预约病人记录";
                                    resultStr = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?> <response> <code>"
                                            + "-1" + "</code><msg>" + errorString + "</msg></response> ";
                                }
                            } else {
                                errorString = "请求已经过期";
                                resultStr = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?> <response> <code>"
                                        + "-1" + "</code><msg>" + errorString + "</msg></response> ";
                            }
                        } catch (Exception e) {
                            errorString = "出现未知异常";
                            resultStr = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?> <response> <code>"
                                    + "-1" + "</code><msg>" + errorString + "</msg></response> ";
                            logger.debug("################################################################出现未知异常"
                                    + e.getStackTrace());
                        }
                    } else {
                        errorString = "签名认证失败";
                        resultStr = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?> <response> <code>"
                                + "-1" + "</code><msg>" + errorString + "</msg></response> ";
                        logger.debug("################################################################签名认证失败");
                    }
                } else {
                    errorString = "找到重复的厂商信息";
                    resultStr = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?> <response> <code>" + "-1"
                            + "</code><msg>" + errorString + "</msg></response> ";
                    logger.debug("################################################################找到重复的厂商信息");
                }
            } else {
                errorString = "没有该厂商的授权信息";
                resultStr = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?> <response> <code>" + "-1"
                        + "</code><msg>" + errorString + "</msg></response> ";
                logger.debug("################################################################没有该厂商的信息");
            }
        } catch (JSONException e) {
            errorString = "数据转换错误(JSONException)";
            resultStr = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\" ?> <response> <code>" + "-1"
                    + "</code><msg>" + errorString + "</msg></response> ";
            logger.debug("################################################################数据转换错误(JSONException)："
                    + e.toString());
        } catch (Exception e) {
            errorString = "流异常(IOException)";
            resultStr = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?> <response> <code>" + "-1"
                    + "</code><msg>" + errorString + "</msg></response> ";
            logger.debug("#######################################################################流异常(IOException)："
                    + e.toString());
        }
        return resultStr;
    }

}
