com.daoke.mobileserver.user.controller.UserController.java Source code

Java tutorial

Introduction

Here is the source code for com.daoke.mobileserver.user.controller.UserController.java

Source

package com.daoke.mobileserver.user.controller;

import org.springframework.web.bind.annotation.RequestMapping;

import com.daoke.mobileserver.common.config.RedisVariable;
import com.daoke.mobileserver.common.model.CommonJsonResult;
import com.daoke.mobileserver.common.page.PageList;
import com.daoke.mobileserver.common.service.DrivingRedisService;
import com.daoke.mobileserver.custom.service.CustomService;
import com.daoke.mobileserver.map.service.impl.MapServiceImpl;
import com.daoke.mobileserver.report.dto.AssociateAccount;
import com.daoke.mobileserver.user.entity.*;
import com.daoke.mobileserver.user.service.*;
import com.daoke.mobileserver.user.service.impl.UserRochelleRuleServiceImpl;
import com.daoke.mobileserver.util.*;
import com.daoke.mobileserver.weibo.service.WeiBoService;
import net.sf.json.JSONObject;
import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import org.springframework.web.multipart.commons.CommonsMultipartResolver;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.*;

/**
 * @author wangliming
 * @version 1.0
 * @date 2014-9-26 ?10:19:43
 */
@Controller
public class UserController {

    private final Logger logger = Logger.getLogger(UserController.class);
    private Map<String, Object> map = new HashMap<String, Object>();

    @Value("#{apiConfig[getImeiPhone]}")
    private String getImeiPhone;

    @Value("#{apiConfig[getMirrtalkInfoByImei]}")
    private String getMirrtalkInfoByImei;

    @Value("#{apiConfig[userBindAccountMirrtalk]}")
    private String userBindAccountMirrtalk;

    @Value("#{apiConfig[fixUserInfo]}")
    private String fixUserInfo;

    @Value("#{apiConfig[getUserInfo]}")
    private String getUserInfo;

    @Value("#{apiConfig[checkLogin]}")
    private String checkLogin;

    @Value("#{apiConfig[checkRegistration]}")
    private String checkRegistration;

    @Value("#{apiConfig[sendSms]}")
    private String sendSms;

    @Value("#{apiConfig[addCustomAccount]}")
    private String addCustomAccount;

    @Value("#{apiConfig[resetUserPassword]}")
    private String resetUserPassword;

    @Value("#{apiConfig[updateUserPassword]}")
    private String updateUserPassword;

    @Value("#{apiConfig[verifyEmailOrMobile]}")
    private String verifyEmailOrMobile;

    @Value("#{apiConfig[getAccountIDFromMobile]}")
    private String getAccountIDFromMobile;

    @Value("#{apiConfig[associateAccountWithAccountID]}")
    private String associateAccountWithAccountID;

    @Value("#{apiConfig[createAccountID]}")
    private String createAccountID;

    @Value("#{apiConfig[disconnectAccount]}")
    private String disconnectAccount;

    @Value("#{apiConfig[checkImei]}")
    private String checkImei;

    @Value("#{contentConfig[message]}")
    private String content;

    @Value("#{apiConfig[checkMobileRegister]}")
    private String checkMobileRegister;

    @Value("#{apiConfig[sendPersonalWeibo]}")
    private String sendPersonalWeibo;

    @Value("#{apiConfig[userBindMobile]}")
    private String userBindMobile;

    @Value("#{apiConfig[callBackReceiveRochelle]}")
    private String callBackReceiveRochelle;

    @Value("#{apiConfig[callBackAddFriend]}")
    private String callBackAddFriend;

    @Autowired
    private UserService userService;

    @Autowired
    private IFriendSettingService friendSettingService;

    @Autowired
    private IUserFriendService userFriendService;

    @Autowired
    private IUserTalkRecordService userTalkRecordService;

    @Autowired
    private WeiBoService weiBoService;

    @Autowired
    private IUserRochelleDetailService userRochelleDetailService;
    @Autowired
    private IUserGradeService userGradeService;
    @Autowired
    private CustomService customService;
    @Autowired
    private DrivingRedisService drivingRedisService;

    @Value("#{apiConfig[saveFile]}")
    private String saveFile;

    @Autowired
    private IUserRankDetailService userRankDetailService;

    @Autowired
    private IUserRochelleRuleService userRochelleRuleService;

    @Autowired
    private IIndexRankingDetailService indexRankingDetailService;
    @Autowired
    private IUserRankInfoService UserRankInfoService;
    @Autowired
    private IReportInfoService reportInfoService;

    @Value("#{apiConfig[getSecretchannelRelationByUserkey]}")
    private String getSecretchannelRelationByUserkey;

    //??
    private final int DEFAULT_BEGAN = 0;
    //???
    private final int DEFAULT_FINISH = 100;

    /**
     * ??imei??
     *
     * @param appKey
     * @param accountID
     * @return
     */
    @ResponseBody
    @RequestMapping("/getImeiPhone")
    public String getImeiPhone(String appKey, String accountID) {
        String result = null;
        String appkey = ConstantsUtil.getAppKey(appKey);
        String secret = ConstantsUtil.getSecret(appKey);
        try {
            result = userService.getImeiPhone(appkey, secret, accountID, getImeiPhone);
            logger.info(appKey + "===>" + result);
        } catch (Exception e) {
            result = JsonPuserUtil.jsonToString(ConstantsUtil.ERRORCODE_SERVICE_ERROR,
                    ConstantsUtil.RESULT_SERVICE_ERROR);
            logger.error(appKey + "===>"
                    + JsonPuserUtil.jsonToString(ConstantsUtil.ERRORCODE_SERVICE_ERROR, e.toString()));
        }

        return result;
    }

    /**
     * imei??
     *
     * @param appKey
     * @param IMEI
     * @return
     */
    @ResponseBody
    @RequestMapping("/getMirrtalkInfoByImei")
    public String getMirrtalkInfoByImei(String appKey, String IMEI) {
        String result = null;
        String appkey = ConstantsUtil.getAppKey(appKey);
        String secret = ConstantsUtil.getSecret(appKey);
        try {
            result = userService.getMirrtalkInfoByImei(appkey, secret, IMEI, getMirrtalkInfoByImei);
            logger.info(appKey + "===>" + result);
        } catch (Exception e) {
            result = JsonPuserUtil.jsonToString(ConstantsUtil.ERRORCODE_SERVICE_ERROR,
                    ConstantsUtil.RESULT_SERVICE_ERROR);
            logger.error(appKey + "===>"
                    + JsonPuserUtil.jsonToString(ConstantsUtil.ERRORCODE_SERVICE_ERROR, e.toString()));
        }

        return result;
    }

    /**
     * ?
     *
     * @param appKey
     * @param accountID
     * @param IMEI
     * @return
     */
    @ResponseBody
    @RequestMapping("/userBindAccountMirrtalk")
    public String userBindAccountMirrtalk(String appKey, String accountID, String IMEI) {
        String result = null;
        String appkey = ConstantsUtil.getAppKey(appKey);
        String secret = ConstantsUtil.getSecret(appKey);
        try {
            //String ruleCode = "bindWEME";
            List<UserRochelleDetail> userRochelleDetailList = userRochelleDetailService
                    .queryByAccountIDAndRuleCode(accountID, ConstantsUtil.Grade.BINDING_WEME);
            if (userRochelleDetailList.size() == 0) {

                //
                Object[] obj = userGradeService.toReward(accountID, IMEI, ConstantsUtil.Grade.BINDING_WEME);
                logger.info(":" + obj.toString());
                UserGrade userGrade = this.userGradeService.queryByAccountID(accountID);
                String terminalText = "";
                if (userGrade != null && StringUtils.isNotBlank(userGrade.getNickName()) && obj != null
                        && obj[3] != null) {
                    terminalText = obj[3].toString().replace("", userGrade.getNickName());
                } else {
                    // ?IMEI??
                    if (StringUtils.isNotBlank(IMEI)) {
                        terminalText = obj[3].toString().replace("",
                                "?" + IMEI.substring(IMEI.length() - 4, IMEI.length()));
                    } else {
                        terminalText = obj[3].toString().replace("", "");
                    }
                }
                //?
                Map<String, Object> param = new HashMap<String, Object>();
                //?
                param.put("rewardID", (Integer) obj[2]);
                param.put("ruleType",
                        UserRochelleRuleServiceImpl.ruleTypeMap.get(ConstantsUtil.Grade.BINDING_WEME));
                userService.pushMessage("", accountID, obj[4].toString(), "rochelleReward", param);

                //??
                SendMessageUtil.sendToTerminal(sendPersonalWeibo, callBackReceiveRochelle, (Integer) obj[2],
                        accountID, terminalText);
            }
            result = userService.userBindAccountMirrtalk(appkey, secret, accountID, IMEI, userBindAccountMirrtalk);
            logger.info(appKey + "===>" + result);
        } catch (Exception e) {
            e.printStackTrace();
            result = JsonPuserUtil.jsonToString(ConstantsUtil.ERRORCODE_SERVICE_ERROR,
                    ConstantsUtil.RESULT_SERVICE_ERROR);
            logger.error(appKey + "===>"
                    + JsonPuserUtil.jsonToString(ConstantsUtil.ERRORCODE_SERVICE_ERROR, e.toString()));
        }

        return result;
    }

    /**
     * ?
     *
     * @param appKey
     * @param accountID
     * @param name
     * @return
     */
    @ResponseBody
    @RequestMapping("/fixUserInfo")
    public String fixUserInfo(String appKey, String accountID, String name, String nickname, String gender,
            String plateNumber, String drivingLicense, String homeAddress, String areaCode) {
        String result = null;
        String appkey = ConstantsUtil.getAppKey(appKey);
        String secret = ConstantsUtil.getSecret(appKey);
        try {
            String userInfo = userService.getUserInfo(appkey, secret, accountID, getUserInfo);
            org.json.JSONObject userInfoJson = new org.json.JSONObject(userInfo);
            Object resultObj = userInfoJson.get("RESULT");
            org.json.JSONObject resultJson = new org.json.JSONObject(resultObj.toString());
            String oldNickname = resultJson.getString("nickname");
            if (StringUtils.isNotBlank(nickname)) {
                if (!nickname.equals(oldNickname)) {
                    //   String ruleCode = "settingNickName";
                    List<UserRochelleDetail> userRochelleDetailList = userRochelleDetailService
                            .queryByAccountIDAndRuleCode(accountID, ConstantsUtil.Grade.SET_NICKNAME);
                    if (userRochelleDetailList.size() == 0) {
                        //
                        //
                        Object[] obj = userGradeService.toReward(accountID, null, ConstantsUtil.Grade.SET_NICKNAME);
                        logger.info(":" + obj.toString());
                        UserGrade userGrade = this.userGradeService.queryByAccountID(accountID);
                        String terminalText = "";
                        if (userGrade != null && StringUtils.isNotBlank(userGrade.getNickName()) && obj != null
                                && obj[3] != null) {
                            terminalText = obj[3].toString().replace("", userGrade.getNickName());
                        } else {
                            terminalText = obj[3].toString().replace("", "");
                        }
                        //?
                        Map<String, Object> param = new HashMap<String, Object>();
                        //?
                        param.put("rewardID", (Integer) obj[2]);
                        param.put("ruleType",
                                UserRochelleRuleServiceImpl.ruleTypeMap.get(ConstantsUtil.Grade.SET_NICKNAME));
                        userService.pushMessage("", accountID, obj[4].toString(), "rochelleReward",
                                param);

                        //??
                        SendMessageUtil.sendToTerminal(sendPersonalWeibo, callBackReceiveRochelle, (Integer) obj[2],
                                accountID, terminalText);
                    }
                }
            }
            result = userService.fixUserInfo(appkey, secret, accountID, name, nickname, gender, plateNumber,
                    drivingLicense, homeAddress, fixUserInfo);
            Map<String, String> map = new HashMap<String, String>();
            if (StringUtils.isNotBlank(nickname)) {
                map.put("nickName", nickname);
            } else if (StringUtils.isNotBlank(gender)) {
                map.put("gender", gender);
            } else if (StringUtils.isNotBlank(areaCode)) {
                map.put("userAreaCode", areaCode);
            }
            map.put("accountID", accountID);
            if (map.size() > 1) {
                userGradeService.updateUserInfo(map);
            }
            logger.info(appKey + "===>" + result);
        } catch (Exception e) {
            result = JsonPuserUtil.jsonToString(ConstantsUtil.ERRORCODE_SERVICE_ERROR, "");
            logger.error(appKey + "===>"
                    + JsonPuserUtil.jsonToString(ConstantsUtil.ERRORCODE_SERVICE_ERROR, e.toString()));
        }

        return result;
    }

    /**
     * ??
     *
     * @param appKey
     * @param accountID
     * @return
     */
    @ResponseBody
    @RequestMapping("/getUserInfo")
    public CommonJsonResult getUserInfo(String appKey, String accountID, HttpServletResponse response) {
        String result = null;
        String appkey = ConstantsUtil.getAppKey(appKey);
        String secret = ConstantsUtil.getSecret(appKey);
        CommonJsonResult jsonResult = null;
        try {
            result = userService.getUserInfo(appkey, secret, accountID, getUserInfo);

            jsonResult = (CommonJsonResult) JsonMapper.fromJson(result, CommonJsonResult.class);
            //                    response.getOutputStream().write(result.getBytes("utf-8"));
            if (jsonResult.getERRORCODE().equals("0")) {
                Map<String, String> map = (Map<String, String>) jsonResult.getRESULT();
                UserGrade ug = userGradeService.queryByAccountID(accountID);
                if (ug != null) {
                    map.put("userHeadName", ug.getUserHeadName());
                    map.put("userAreaCode", MapServiceImpl.CITY_CODE.get(ug.getUserAreaCode()));
                    map.put("gender", ug.getGender() + "");
                    jsonResult.setRESULT(map);
                    return jsonResult;
                }
            } else {
                return jsonResult;
            }
            logger.info(appKey + "===>" + result);
            result = null;

        } catch (Exception e) {
            result = JsonPuserUtil.jsonToString(ConstantsUtil.ERRORCODE_SERVICE_ERROR,
                    ConstantsUtil.RESULT_SERVICE_ERROR);
            logger.error(appKey + "===>"
                    + JsonPuserUtil.jsonToString(ConstantsUtil.ERRORCODE_SERVICE_ERROR, e.toString()));
        }

        return jsonResult;
    }

    /**
     * 
     *
     * @param appKey
     * @param username
     * @param daokePassword
     * @param request
     * @return
     */
    @ResponseBody
    @RequestMapping("/checkLogin")
    public String checkLogin(
            @RequestHeader(value = "X-Real-IP", required = false, defaultValue = "172.16") String realIP,
            String appKey, String username, String daokePassword, HttpServletRequest request,
            HttpServletResponse response) {
        String result = null;
        String appkey = ConstantsUtil.getAppKey(appKey);
        String secret = ConstantsUtil.getSecret(appKey);
        String clientIP = request.getRemoteAddr();
        logger.info("X-Real-IP=======>" + realIP);
        if (clientIP.startsWith("172.16")) {
            clientIP = realIP;
        }
        try {
            result = userService.checkLogin(appkey, secret, username, daokePassword, clientIP, checkLogin);
            //????? ??
            CommonJsonResult jsonResult = (CommonJsonResult) JsonMapper.fromJson(result, CommonJsonResult.class);
            if (jsonResult != null && jsonResult.getERRORCODE().equals(ConstantsUtil.ERRORCODE_OK)) {
                Map map = (Map) jsonResult.getRESULT();
                userGradeService.updateUserInfo(map.get("accountID").toString(), null, null,
                        map.get("nickname").toString());
            }

            logger.info(appKey + "===>" + result);
            response.getOutputStream().write(result.getBytes("utf-8"));
            result = null;
        } catch (Exception e) {
            e.printStackTrace();
            result = JsonPuserUtil.jsonToString(ConstantsUtil.ERRORCODE_SERVICE_ERROR,
                    ConstantsUtil.RESULT_SERVICE_ERROR);
            logger.error(e.getMessage());
        }

        return result;
    }

    /**
     * 
     *
     * @param appKey
     * @param mobile
     * @param request
     * @return
     */
    //    @ResponseBody
    //    @RequestMapping(value = "/toReg")
    //    public String toReg(String appKey, String mobile, HttpServletRequest request) {
    //        String result = null;
    //        String appkey = ConstantsUtil.getAppKey(appKey);
    //        String secret = ConstantsUtil.getSecret(appKey);
    //        try {
    //            result = userService.checkRegistration(appkey, secret, mobile, checkRegistration);
    //            JSONObject jsonObject = JSONObject.fromObject(result);
    //            String ERRORCODE = jsonObject.getString("ERRORCODE");
    //            if (("0").equals(ERRORCODE)) {
    //                String message = new String(content.getBytes("iso-8859-1"), "utf-8");
    //                result = weiBoService.sendSms(appkey, secret, mobile, message, sendSms);
    //                jsonObject = JSONObject.fromObject(result);
    //                ERRORCODE = jsonObject.getString("ERRORCODE");
    //                if (("0").equals(ERRORCODE)) {
    ////                    JSONObject RESULT = jsonObject.getJSONObject("RESULT");
    ////                    String verificationCode = RESULT.getString("verificationCode");
    ////                    map.put(mobile, verificationCode);
    //                    result = JsonPuserUtil.jsonToString(ConstantsUtil.ERRORCODE_OK,
    //                            ConstantsUtil.RESULT_OK);
    //                    logger.info(appKey + "===>" + result);
    ////                    userGradeService.updateUserGrade(RESULT.getString("accountID"), 0,0);
    //                } else {
    //                    logger.warn(appKey + "===>" + result);
    //                }
    //            } else {
    //                logger.warn(appKey + "===>" + result);
    //            }
    //        } catch (Exception e) {
    //            result = JsonPuserUtil.jsonToString(ConstantsUtil.ERRORCODE_SERVICE_ERROR,
    //                    ConstantsUtil.RESULT_SERVICE_ERROR);
    //            logger.error(appKey
    //                    + "===>"
    //                    + JsonPuserUtil.jsonToString(ConstantsUtil.ERRORCODE_SERVICE_ERROR,
    //                    e.toString()));
    //        }
    //
    //        return result;
    //    }
    @ResponseBody
    @RequestMapping(value = "/toReg")
    public CommonJsonResult toReg(String appKey, String mobile, HttpServletRequest request) {
        CommonJsonResult jsonResult = new CommonJsonResult();
        String verifyCode = String.valueOf(RandomNumberUtil.genRandomNum(6));
        String appkey = ConstantsUtil.getAppKey(appKey);
        String secret = ConstantsUtil.getSecret(appKey);
        try {

            request.getHeader("");

            String result = userService.checkRegistration(appkey, secret, mobile, checkRegistration);
            jsonResult = (CommonJsonResult) JsonMapper.fromJson(result, CommonJsonResult.class);
            //  JSONObject jsonObject = JSONObject.fromObject(result);
            // String ERRORCODE = jsonObject.getString("ERRORCODE");
            if (("0").equals(jsonResult.getERRORCODE())) {
                //1
                boolean isSuc = SendTemplateSMSUtil.sendTemplateSMS(mobile, "21109", verifyCode, "1");
                if (isSuc) {
                    //???
                    userService.insertIdentifyingCode(mobile, verifyCode, "1", "1");
                    //1.0
                    jsonResult.setERRORCODE(ConstantsUtil.ERRORCODE_OK);
                    jsonResult.setRESULT("?????");
                } else {
                    jsonResult.setERRORCODE(ConstantsUtil.ERRORCODE_OK);
                    jsonResult.setRESULT("????");
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
            logger.error("????", e);
            jsonResult.setERRORCODE(ConstantsUtil.ERRORCODE_SERVICE_ERROR);
            jsonResult.setRESULT("????");
        }
        return jsonResult;
    }

    /**
     * ???
     * @param appKey
     * @param mobile
     * @param request
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/v2/toReg")
    public CommonJsonResult toRegV2(String appKey, String mobile, HttpServletRequest request) {
        CommonJsonResult jsonResult = new CommonJsonResult();
        String verifyCode = String.valueOf(RandomNumberUtil.genRandomNum(6));
        String appkey = ConstantsUtil.getAppKey(appKey);
        String secret = ConstantsUtil.getSecret(appKey);
        try {
            String result = userService.checkRegistration(appkey, secret, mobile, checkRegistration);
            jsonResult = (CommonJsonResult) JsonMapper.fromJson(result, CommonJsonResult.class);
            if (("0").equals(jsonResult.getERRORCODE())) {
                //1
                boolean isSuc = SendTemplateSMSUtil.sendTemplateSMS(mobile, "21109", verifyCode, "1");
                if (isSuc) {
                    //???
                    userService.insertIdentifyingCode(mobile, verifyCode, "1", "1");
                    jsonResult.setERRORCODE(ConstantsUtil.ERRORCODE_OK);
                    jsonResult.setRESULT("?????");
                } else {
                    jsonResult.setERRORCODE(ConstantsUtil.ERRORCODE_OK);
                    jsonResult.setRESULT("????");
                }

            }

        } catch (Exception e) {
            e.printStackTrace();
            logger.error("????", e);
            jsonResult.setERRORCODE(ConstantsUtil.ERRORCODE_SERVICE_ERROR);
            jsonResult.setRESULT("????");
        }
        return jsonResult;
    }

    /**
     * 
     *
     * @param appKey
     * @param daokePassword
     * @param nickname
     * @param mobile
     * @param verificationCode
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/addCustomAccount")
    public String addCustomAccount(String appKey, String daokePassword, String nickname, String mobile,
            String verificationCode) {
        String result = null;
        String appkey = ConstantsUtil.getAppKey(appKey);
        String secret = ConstantsUtil.getSecret(appKey);

        try {

            if (StringUtils.isNotEmpty(verificationCode)
                    && userService.findValidCode(verificationCode, mobile) > 0) {
                result = userService.addCustomAccount(appkey, secret, daokePassword, "2", nickname, mobile,
                        addCustomAccount);
                JSONObject jsonObject = JSONObject.fromObject(result);
                String ERRORCODE = jsonObject.getString("ERRORCODE");
                JSONObject resultJsonObject = JSONObject.fromObject(jsonObject.getString("RESULT"));
                if (("0").equals(ERRORCODE)) {
                    logger.info(appKey + "===>" + result);
                    userGradeService.updateUserGrade(resultJsonObject.getString("accountID"), nickname, 0, 0);
                } else {
                    logger.warn(appKey + "===>" + result);
                }
            } else {
                result = JsonPuserUtil.jsonToString(ConstantsUtil.ERRORCODE_VERICODE,
                        ConstantsUtil.RESULT_VERICODE);
                logger.warn(appKey + "===>" + result);
            }
        } catch (Exception e) {
            result = JsonPuserUtil.jsonToString(ConstantsUtil.ERRORCODE_SERVICE_ERROR,
                    ConstantsUtil.RESULT_SERVICE_ERROR);
            logger.error(appKey + "===>"
                    + JsonPuserUtil.jsonToString(ConstantsUtil.ERRORCODE_SERVICE_ERROR, e.toString()));
        }

        return result;
    }

    /**
     * ??
     *
     * @param appKey
     * @param accountID
     * @return
     */
    @ResponseBody
    @RequestMapping("/resetUserPassword")
    public String resetUserPassword(String appKey, String accountID) {
        String result = null;
        String appkey = ConstantsUtil.getAppKey(appKey);
        String secret = ConstantsUtil.getSecret(appKey);
        try {
            result = userService.resetUserPassword(appkey, secret, accountID, resetUserPassword);
            logger.info(appKey + "===>" + result);
        } catch (Exception e) {
            result = JsonPuserUtil.jsonToString(ConstantsUtil.ERRORCODE_SERVICE_ERROR,
                    ConstantsUtil.RESULT_SERVICE_ERROR);
            logger.error(appKey + "===>" + result);
        }

        return result;
    }

    /**
     * ?
     *
     * @param appKey
     * @param accountID
     * @param oldPassword
     * @param newPassword
     * @return
     */
    @ResponseBody
    @RequestMapping("/updateUserPassword")
    public String updateUserPassword(String appKey, String accountID, String oldPassword, String newPassword) {
        String result = null;
        String appkey = ConstantsUtil.getAppKey(appKey);
        String secret = ConstantsUtil.getSecret(appKey);
        try {
            result = userService.updateUserPassword(appkey, secret, accountID, oldPassword, newPassword,
                    updateUserPassword);
            logger.info(appKey + "===>" + result);
        } catch (Exception e) {
            result = JsonPuserUtil.jsonToString(ConstantsUtil.ERRORCODE_SERVICE_ERROR,
                    ConstantsUtil.RESULT_SERVICE_ERROR);
            logger.error(appKey + "===>" + appKey + "===>" + result);
        }

        return result;
    }

    /**
     * ???
     *
     * @param appKey
     * @param mobile
     * @param accountID
     * @param oldPassword
     * @param newPassword
     * @return
     */
    @ResponseBody
    @RequestMapping("/verifyAndreset")
    public String verifyAndreset(String appKey, String mobile, String verificationCode, String accountID,
            String oldPassword, String newPassword) {
        String result = null;
        String appkey = ConstantsUtil.getAppKey(appKey);
        String secret = ConstantsUtil.getSecret(appKey);
        if (mobile != null && (mobile.replaceAll(" ", "").length() >= 6)) {
            try {
                result = userService.getImeiPhone(appkey, secret, accountID, getImeiPhone);
                String phone = JSONObject.fromObject(result).getJSONObject("RESULT").getString("phone");
                if (StringUtils.isEmpty(phone)) {
                    if (StringUtils.isNotEmpty(verificationCode) && verificationCode.equals(map.get(mobile))) {
                        result = userService.verifyAndreset(appkey, secret, mobile, accountID, oldPassword,
                                newPassword, verifyEmailOrMobile, updateUserPassword);
                        logger.info(appKey + "===>" + result);
                    } else {
                        result = JsonPuserUtil.jsonToString(ConstantsUtil.ERRORCODE_VERICODE,
                                ConstantsUtil.RESULT_VERICODE);
                        logger.warn(appKey + "===>" + result);
                    }
                } else {
                    result = userService.updateUserPassword(appkey, secret, accountID, "", newPassword,
                            updateUserPassword);
                    logger.info(appKey + "===>" + result);
                }
            } catch (Exception e) {
                result = JsonPuserUtil.jsonToString(ConstantsUtil.ERRORCODE_PHONE, ConstantsUtil.RESULT_PHONE);
                logger.error(appKey + "===>" + e.getMessage());
            }
        } else {
            result = JsonPuserUtil.jsonToString(ConstantsUtil.ERRORCODE_PHONE, ConstantsUtil.RESULT_PHONE);
            logger.error(appKey + "===>" + result);
        }
        return result;
    }

    /**
     * ?????
     *
     * @param appKey
     * @param mobile
     * @return
     */
    @ResponseBody
    @RequestMapping("/getAccountIDFromMobile")
    public String getAccountIDFromMobile(String appKey, String mobile, HttpServletResponse response) {
        String result = null;
        String appkey = ConstantsUtil.getAppKey(appKey);
        String secret = ConstantsUtil.getSecret(appKey);
        try {
            result = userService.getAccountIDFromMobile(appkey, secret, mobile, getAccountIDFromMobile);
            response.getOutputStream().write(result.getBytes("utf-8"));
            logger.info(appKey + "===>" + result);
            result = null;
        } catch (Exception e) {
            result = JsonPuserUtil.jsonToString(ConstantsUtil.ERRORCODE_SERVICE_ERROR,
                    ConstantsUtil.RESULT_SERVICE_ERROR);
            logger.error(appKey + "===>" + appKey + "===>" + result);
        }

        return result;
    }

    /**
     * ???
     *
     * @param associateAccount
     * @return
     */
    @ResponseBody
    @RequestMapping("/associateAccountWithAccountID")
    public String associateAccountWithAccountID(AssociateAccount associateAccount) {
        String result = null;
        try {
            result = userService.associateAccountWithAccountID(associateAccount, associateAccountWithAccountID);
            logger.info(result);
        } catch (Exception e) {
            result = JsonPuserUtil.jsonToString(ConstantsUtil.ERRORCODE_SERVICE_ERROR,
                    ConstantsUtil.RESULT_SERVICE_ERROR);
            logger.error(e.getMessage());
        }
        return result;
    }

    /**
     * ???
     *
     * @param appKey
     * @param account
     * @param loginType
     * @param token
     * @param accessToken
     * @param accessTokenExpiration
     * @param nickname
     * @return
     */
    @ResponseBody
    @RequestMapping("/createAccountID")
    public String createAccountID(String appKey, String account, String loginType, String token, String accessToken,
            String accessTokenExpiration, String nickname, String username, String daokePassword,
            HttpServletResponse response) {
        String result = null;
        String appkey = ConstantsUtil.getAppKey(appKey);
        String secret = ConstantsUtil.getSecret(appKey);
        try {
            result = userService.createAccountID(appkey, secret, account, loginType, token, accessToken,
                    accessTokenExpiration, nickname, username, daokePassword, createAccountID);
            response.getOutputStream().write(result.getBytes("utf-8"));
            logger.info("account===>" + account);
            logger.info(appKey + "===>" + result);
            result = null;
        } catch (Exception e) {
            result = JsonPuserUtil.jsonToString(ConstantsUtil.ERRORCODE_SERVICE_ERROR,
                    ConstantsUtil.RESULT_SERVICE_ERROR);
            logger.error(appKey + "===>" + e.getMessage());
        }
        return result;
    }

    /**
     * 
     *
     * @param appKey
     * @param accountID
     * @return
     */
    @ResponseBody
    @RequestMapping("/disconnectAccount")
    public String disconnectAccount(String appKey, String accountID) {
        String result = null;
        String appkey = ConstantsUtil.getAppKey(appKey);
        String secret = ConstantsUtil.getSecret(appKey);
        try {
            result = userService.disconnectAccount(appkey, secret, accountID, disconnectAccount);
            logger.info(appKey + "===>" + result);
        } catch (Exception e) {
            result = JsonPuserUtil.jsonToString(ConstantsUtil.ERRORCODE_SERVICE_ERROR,
                    ConstantsUtil.RESULT_SERVICE_ERROR);
            logger.error(appKey + "===>"
                    + JsonPuserUtil.jsonToString(ConstantsUtil.ERRORCODE_SERVICE_ERROR, e.toString()));
        }

        return result;
    }

    /**
     * imei??
     *
     * @param appKey
     * @param IMEI
     * @return
     */
    @ResponseBody
    @RequestMapping("/checkImei")
    public String checkImei(String appKey, String IMEI) {
        String result = null;
        String appkey = ConstantsUtil.getAppKey(appKey);
        String secret = ConstantsUtil.getSecret(appKey);
        try {
            result = userService.checkImei(appkey, secret, IMEI, checkImei);
            logger.info(appKey + "===>" + result);
        } catch (Exception e) {
            result = JsonPuserUtil.jsonToString(ConstantsUtil.ERRORCODE_SERVICE_ERROR,
                    ConstantsUtil.RESULT_SERVICE_ERROR);
            logger.error(appKey + "===>"
                    + JsonPuserUtil.jsonToString(ConstantsUtil.ERRORCODE_SERVICE_ERROR, e.toString()));
        }

        return result;
    }

    /*  *//**
          * ?
          *
          * @param appKey
          * @param response
          * @return
          *//*
             @RequestMapping("/uploadImage")
             public @ResponseBody String uploadImage(String appKey,String accountID,HttpServletRequest request,
                                                        HttpServletResponse response){
             String result = null;
             String appkey = ConstantsUtil.getAppKey(appKey);
             String secret = ConstantsUtil.getSecret(appKey);
             String channelCatalogUrl ="";
                 
             try {
                 //url
                 CommonsMultipartResolver multipartResolver= new CommonsMultipartResolver(request.getSession().getServletContext());
                 if(multipartResolver.isMultipart(request)){
                     MultipartHttpServletRequest multiRequest = (MultipartHttpServletRequest)request;
                     Iterator<String> iter = multiRequest.getFileNames();
                     while (iter.hasNext()) {
                         MultipartFile file = multiRequest.getFile(iter.next());
                         String fileResultUrl = customService.saveFile(appkey, secret, file, saveFile);
                         CommonJsonResult fileResult = (CommonJsonResult) JsonMapper.fromJson(fileResultUrl, CommonJsonResult.class);
                         Map<String,String> param = (Map<String, String>) fileResult.getRESULT();
                         channelCatalogUrl =  param.get("url");
                         break;
                     }
                 }
             } catch (Exception e1) {
                 e1.printStackTrace();
                 result = JsonPuserUtil.jsonToString(ConstantsUtil.ERRORCODE_SERVICE_ERROR,
                         ConstantsUtil.RESULT_SERVICE_ERROR);
                 logger.error(appKey
                         + "===>"
                         + JsonPuserUtil.jsonToString(ConstantsUtil.ERRORCODE_SERVICE_ERROR,
                         e1.toString()));
                 return result;
             }
                 
             return result;
             }*/

    /**
     * ?
     *
     * @param appKey
     * @param accountID
     * @param request
     * @return
     */
    @RequestMapping("/uploadHeadImage")
    public @ResponseBody CommonJsonResult uploadImage(@RequestParam String appKey, @RequestParam String accountID,
            HttpServletRequest request) {
        CommonJsonResult res = new CommonJsonResult();
        String appkey = ConstantsUtil.getAppKey(appKey);
        String secret = ConstantsUtil.getSecret(appKey);
        String headImageUrl = "";

        try {
            //url
            CommonsMultipartResolver multipartResolver = new CommonsMultipartResolver(
                    request.getSession().getServletContext());
            if (multipartResolver.isMultipart(request)) {
                MultipartHttpServletRequest multiRequest = (MultipartHttpServletRequest) request;
                Iterator<String> iter = multiRequest.getFileNames();
                while (iter.hasNext()) {
                    MultipartFile file = multiRequest.getFile(iter.next());
                    String fileResultUrl = customService.saveFile(appkey, secret, file, saveFile);
                    CommonJsonResult fileResult = (CommonJsonResult) JsonMapper.fromJson(fileResultUrl,
                            CommonJsonResult.class);
                    Map<String, String> param = (Map<String, String>) fileResult.getRESULT();
                    headImageUrl = param.get("url");
                    break;
                }
            }

            if (headImageUrl != null) {
                if (userGradeService.uploadHeadImage(accountID, headImageUrl) > 0) {
                    res.setERRORCODE(ConstantsUtil.ERRORCODE_OK);
                    Map<String, String> map = new HashMap<String, String>();
                    map.put("headImageUrl", headImageUrl);
                    res.setRESULT(map);
                } else {
                    res.setERRORCODE(ConstantsUtil.ERRORCODE_SERVICE_ERROR);
                    res.setRESULT("?");
                }
            }

        } catch (Exception e1) {
            e1.printStackTrace();
            logger.error("?:" + e1.getMessage());
            res.setERRORCODE(ConstantsUtil.ERRORCODE_SERVICE_ERROR);
            res.setRESULT("?");
        }

        return res;
    }

    @RequestMapping("/updateUserInfo")
    @ResponseBody
    public CommonJsonResult updateUserInfo(@RequestParam String appKey, @RequestParam String accountID,
            HttpServletRequest request, String userArea, int gender, String nickName) {
        CommonJsonResult result = new CommonJsonResult();
        try {
            int is = userGradeService.updateUserInfo(accountID, userArea, gender, nickName);
            result.setERRORCODE(ConstantsUtil.ERRORCODE_OK);
            result.setRESULT(ConstantsUtil.RESULT_OK);
        } catch (Exception e) {
            e.printStackTrace();
            result.setERRORCODE(ConstantsUtil.ERRORCODE_SERVICE_ERROR);
            result.setRESULT("");
        }

        return result;
    }

    /**
     * ???
     *
     * @param appKey    ? ios  android
     * @param accountID accountID
     * @return
     */
    @RequestMapping("/getList")
    @ResponseBody
    public CommonJsonResult getList(@RequestParam String appKey, @RequestParam String accountID) {
        CommonJsonResult jsonResult = new CommonJsonResult();
        try {
            Map<String, Object> map = new HashMap<String, Object>();
            Map<String, Object> result = userRochelleDetailService.getDetailUserList(accountID, appKey,
                    getSecretchannelRelationByUserkey);
            if (result != null) {
                map.put("accountID", result.get("accountID"));//accountID
                //
                map.put("grade", result.get("grade"));//
                map.put("gradeTitle", result.get("gradeTitle")); //??
                map.put("rochelle", result.get("rochelle")); //
                map.put("nextGradeRochelle",
                        result.get("nextGradeRochelle") == null ? "0" : result.get("nextGradeRochelle").toString()); //?
                //??
                map.put("allRanking", result.get("allRanking")); //???
                map.put("monthRanking", result.get("monthRanking")); //???
                //
                map.put("influenceIndex", result.get("influenceIndex")); //?
                map.put("closeIndex", result.get("closeIndex")); //
                map.put("interactIndex", result.get("interactIndex")); //??
                map.put("meetIndex", result.get("meetIndex")); //?
                //
                map.put("addMileageSum", result.get("addMileageSum")); //
                map.put("mileageCostTime", result.get("mileageCostTime")); //
                map.put("mePoint", result.get("mePoint")); //??
                map.put("driverDaysMonth", result.get("driverDays")); //
                map.put("driverGrade", result.get("driverGrade")); //
                map.put("tweetCount", result.get("tweetCount")); //??
                map.put("taskIndex", result.get("taskIndex")); //
                map.put("environmentalIndex", result.get("environmentalIndex")); //?
                //
                map.put("addMileageSumStar", RankingStarsTool.getRuleTextWithRankType(1,
                        result.get("addMileageSum") == null ? -1 : (Integer) result.get("addMileageSum")));//
                map.put("mileageCostTimeStar", RankingStarsTool.getRuleTextWithRankType(2, Integer.parseInt(
                        result.get("mileageCostTime") == null ? "-1" : result.get("mileageCostTime").toString()))); //
                map.put("mePointStar", RankingStarsTool.getRuleTextWithRankType(3, (int) Double
                        .parseDouble(result.get("mePoint") == null ? "-1" : result.get("mePoint").toString()))); //??
                map.put("driverDaysMonthStar", RankingStarsTool.getRuleTextWithRankType(4, Integer
                        .parseInt(result.get("driverDays") == null ? "-1" : result.get("driverDays").toString()))); //
                map.put("driverGradeStar", RankingStarsTool.getRuleTextWithRankType(5, Integer.parseInt(
                        result.get("driverGrade") == null ? "-1" : result.get("driverGrade").toString()))); //
                map.put("tweetCountStar", result.get("tweetCount")); //??
                map.put("taskIndexStar", RankingStarsTool.getRuleTextWithRankType(7, Integer
                        .parseInt(result.get("taskIndex") == null ? "-1" : result.get("taskIndex").toString()))); //
                map.put("environmentalIndexStar",
                        RankingStarsTool.getRuleTextWithRankType(8,
                                Integer.parseInt(result.get("environmentalIndex") == null ? "-1"
                                        : result.get("environmentalIndex").toString()))); //?

                //?
                map.put("driverCityNum", result.get("cityNum")); //
                map.put("driverHotNum", result.get("hotNum")); //
                map.put("driverLocusNum", result.get("locusNum")); //
                map.put("driverDays", result.get("days")); //
                map.put("driverMileageSum", result.get("mileageSum")); //?

                jsonResult.setERRORCODE(ConstantsUtil.ERRORCODE_OK);
                jsonResult.setRESULT(map);
            } else {
                jsonResult.setERRORCODE(ConstantsUtil.ERRORCODE_SERVICE_ERROR);
                jsonResult.setRESULT("?");
            }

        } catch (Exception e) {
            e.printStackTrace();
        }

        return jsonResult;
    }

    /**
     * ???
     *
     * @param appKey    ? ios  android
     * @param accountID accountID
     * @return customType 1,???  2,???  3?+?
     */
    //@RequestMapping("/getRankInfo")
    @RequestMapping("/getUserRankInfo")
    @ResponseBody
    public CommonJsonResult getList(@RequestParam String appKey, @RequestParam String accountID,
            @RequestParam int rankType) {
        CommonJsonResult result = new CommonJsonResult();
        int customType = 3;
        List<Map<String, Object>> lis = new ArrayList<Map<String, Object>>();
        try {
            lis = UserRankInfoService.getRankMember(accountID, customType, rankType, appKey,
                    getSecretchannelRelationByUserkey);

            Map<String, Object> resultMap = new HashMap<String, Object>();
            resultMap.put("rank", lis == null ? new ArrayList<Map<String, Object>>() : lis);
            Map<String, Object> resultMap1 = UserRankInfoService.getRankMyselfInfo(accountID, rankType);
            //itemValue
            //        resultMap1.put("star",RankingStarsTool.getRuleTextWithRankType(rankType,Integer.parseInt(resultMap1.get("itemValue").toString())));
            resultMap.put("myRankInfo", resultMap1 == null ? "" : resultMap1);
            resultMap.put("rankRuleText", RankingStarsTool.getRuleTextWithRankTypeTitle(rankType) + "|"
                    + RankingStarsTool.getRuleTextWithRankType(rankType));
            result.setRESULT(resultMap);
            result.setERRORCODE(ConstantsUtil.ERRORCODE_OK);
        } catch (Exception e) {
            logger.error("??", e);
            result.setRESULT("??");
            result.setERRORCODE(ConstantsUtil.ERRORCODE_SERVICE_ERROR);
            e.printStackTrace();
        }
        return result;

    }
    //    @RequestMapping("/getMileageRank")
    //    @ResponseBody
    //    public CommonJsonResult getMileageRank(@RequestParam String appKey,
    //                                    @RequestParam String accountID,
    //                                    @RequestParam int customType) {
    //        CommonJsonResult result = new CommonJsonResult();
    //        List<Map<String,Object>> lis =   UserRankInfoService.getMileageSumRankList(accountID,customType);
    //        result.setRESULT(lis);
    //        result.setERRORCODE(ConstantsUtil.ERRORCODE_OK);
    //        return result;
    //
    //    }

    @RequestMapping("/getRankListInfoByShellAll")
    @ResponseBody
    public CommonJsonResult getRankListInfoByShellAll(@RequestParam String appKey, @RequestParam String accountID) {
        CommonJsonResult result = new CommonJsonResult();
        Map<String, Object> resultMap = new HashMap<String, Object>();
        try {
            resultMap.put("rank", UserRankInfoService.getRankListInfoByShellAll(accountID, appKey,
                    getSecretchannelRelationByUserkey));
            resultMap.put("myRankInfo", UserRankInfoService.getRankMyselfInfoByShellAll(accountID));
            result.setRESULT(resultMap);
            result.setERRORCODE(ConstantsUtil.ERRORCODE_OK);
        } catch (Exception e) {
            logger.error("?", e);
            result.setERRORCODE(ConstantsUtil.ERRORCODE_OK);
            result.setRESULT(ConstantsUtil.ERRORCODE_SERVICE_ERROR);
        }

        return result;

    }

    @RequestMapping("/getRankListInfoByShell")
    @ResponseBody
    public CommonJsonResult getRankListInfoByShell(@RequestParam String appKey, @RequestParam String accountID) {
        CommonJsonResult result = new CommonJsonResult();
        Map<String, Object> resultMap = new HashMap<String, Object>();
        try {
            resultMap.put("rank", UserRankInfoService.getRankListInfoByShell(accountID, appKey,
                    getSecretchannelRelationByUserkey));
            resultMap.put("myRankInfo", UserRankInfoService.getRankMyselfInfoByShell(accountID));
            result.setRESULT(resultMap);
            result.setERRORCODE(ConstantsUtil.ERRORCODE_OK);
        } catch (Exception e) {
            logger.error("?", e);
            result.setERRORCODE(ConstantsUtil.ERRORCODE_OK);
            result.setRESULT(ConstantsUtil.ERRORCODE_SERVICE_ERROR);
        }

        return result;

    }

    /**
     * @param appKey
     * @param accountID
     * @param taskInfoType 1. 2  3 4 ?
     * @return
     */
    @RequestMapping("/getUserTaskInfo")
    @ResponseBody
    public CommonJsonResult getUserTaskInfo(@RequestParam String appKey, @RequestParam String accountID,
            @RequestParam int taskInfoType) {
        CommonJsonResult result = new CommonJsonResult();
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        List<Map<String, Object>> map = null;
        Map<String, Object> resultMap = new HashMap<String, Object>();
        Map<String, Object> taskInfo = null;
        long resultInfo = 0;
        String viewInfo = "";
        try {

            if (taskInfoType == 1) {
                Long dis = drivingRedisService.getHRuleValue(RedisVariable.powerDay.POWEROFF_SEVEN_DAY, accountID);
                resultInfo = dis % 1000;
                Calendar cd = Calendar.getInstance();
                //1970-01-01
                long allDays = AbDateUtil.getAllDays();
                long restDays = dis / 1000;
                if (((allDays - restDays) + 1) != resultInfo) {
                    resultInfo = 0;
                }
                viewInfo = "" + resultInfo + "";
                map = userRochelleRuleService.queryRochellReceiveStatus(accountID, taskInfoType,
                        format.format(cd.getTime()));
            }
            if (taskInfoType == 2) {
                Long dis = drivingRedisService.getHRuleValue(RedisVariable.Mileage.DRIVER_MILEAGE_WEEKLY,
                        accountID);
                resultInfo = dis % 100000000;
                viewInfo = "" + (resultInfo / 1000) + "";
                Calendar cal = Calendar.getInstance();
                cal.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);
                map = userRochelleRuleService.queryRochellReceiveStatus(accountID, taskInfoType,
                        format.format(cal.getTime()));

            }
            if (taskInfoType == 3) {
                Calendar c = Calendar.getInstance();
                c.add(Calendar.MONTH, 0);
                c.set(Calendar.DAY_OF_MONTH, 1);
                Long dis = drivingRedisService.getHRuleValue(RedisVariable.Mileage.DRIVER_MILEAGE_MONTH, accountID);
                resultInfo = dis % 100000000;
                viewInfo = "" + (resultInfo / 1000) + "";
                map = userRochelleRuleService.queryRochellReceiveStatus(accountID, taskInfoType,
                        format.format(c.getTime()));
            }
            if (taskInfoType == 4) {
                UserGrade ug = userGradeService.queryByAccountID(accountID);
                viewInfo = "" + (ug == null ? 0 : ug.getGrade()) + "";
                map = userRochelleRuleService.queryRochellReceiveStatus(accountID, taskInfoType, null);
            }
        } catch (Exception e) {
            result.setERRORCODE(ConstantsUtil.ERRORCODE_SERVICE_ERROR);
            result.setRESULT(ConstantsUtil.RESULT_SERVICE_ERROR);
            return result;
        }
        result.setERRORCODE(ConstantsUtil.ERRORCODE_OK);
        resultMap.put("taskInfo", map);
        resultMap.put("resultInfo", viewInfo);
        result.setRESULT(resultMap);
        return result;
    }

    /**
     * ????
     */
    @RequestMapping("/currentRanking")
    @ResponseBody
    public CommonJsonResult currentRanking(@RequestParam String accountID, @RequestParam String appKey) {
        CommonJsonResult jsonResult = new CommonJsonResult();
        try {
            UserRankDetail userRankDetail = userRankDetailService.getCurrentRank(accountID);
            jsonResult.setRESULT(userRankDetail);
            jsonResult.setERRORCODE(ConstantsUtil.ERRORCODE_OK);
        } catch (Exception e) {
            logger.error("?????" + e.toString());
            jsonResult.setRESULT(ConstantsUtil.ERRORCODE_SERVICE_ERROR);
            jsonResult.setFailure("????");
            e.printStackTrace();
        }
        return jsonResult;
    }

    /**
     * ??
     *
     * @param appKey
     * @param accountID
     * @return
     */
    @RequestMapping("/rankingAll")
    @ResponseBody
    public CommonJsonResult rankingAll(@RequestParam String accountID, String appKey) {
        CommonJsonResult jsonResult = new CommonJsonResult();
        try {
            List<UserGrade> userGradeList = userGradeService.getAllRochelleRanking(DEFAULT_BEGAN, DEFAULT_FINISH);
            jsonResult.setRESULT(userGradeList);
            jsonResult.setERRORCODE(ConstantsUtil.ERRORCODE_OK);
        } catch (Exception e) {
            jsonResult.setERRORCODE(ConstantsUtil.ERRORCODE_SERVICE_ERROR);
            jsonResult.setFailure("???");
            logger.error("???" + e.toString());
        }

        return jsonResult;
    }

    /**
     * ??
     *
     * @param accountID
     * @param appKey
     * @return
     */
    @RequestMapping("/rankingMonth")
    @ResponseBody
    public CommonJsonResult rankingMonth(@RequestParam String accountID, String appKey) {
        CommonJsonResult jsonResult = new CommonJsonResult();
        try {
            String pattern = "yyyyMMdd";
            String firstDay = AbDateUtil.getFirstDayOfMonth(pattern);
            String lastDay = AbDateUtil.getLastDayOfMonth(pattern);
            DateFormat df = new SimpleDateFormat(pattern);
            long firstUnixTime = (df.parse(firstDay).getTime()) / 1000;
            long lastUnixTime = (df.parse(lastDay).getTime()) / 1000;
            List<UserGrade> userGradeList = userGradeService.getMonthRochelleRanking(firstUnixTime, lastUnixTime,
                    DEFAULT_BEGAN, DEFAULT_FINISH);
            jsonResult.setRESULT(userGradeList);
            jsonResult.setERRORCODE(ConstantsUtil.ERRORCODE_OK);
        } catch (Exception e) {
            jsonResult.setERRORCODE(ConstantsUtil.ERRORCODE_SERVICE_ERROR);
            jsonResult.setFailure("???");
            logger.error("???" + e.toString());
        }
        return jsonResult;
    }

    /**
     * ??
     *
     * @param accountID
     * @param appKey
     * @return
     */
    @RequestMapping("/mileageCostTimeRankingDetail")
    @ResponseBody
    public CommonJsonResult mileageCostTimeRankingDetail(@RequestParam String accountID,
            @RequestParam String appKey) {
        CommonJsonResult jsonResult = new CommonJsonResult();
        try {
            List<IndexRankingDetail> list = indexRankingDetailService.getMileageCostTimeList(accountID,
                    DEFAULT_BEGAN, DEFAULT_FINISH);
            jsonResult.setERRORCODE(ConstantsUtil.ERRORCODE_OK);
            jsonResult.setRESULT(list);
        } catch (Exception e) {
            logger.error("??" + e.toString());
            jsonResult.setERRORCODE(ConstantsUtil.ERRORCODE_SERVICE_ERROR);
            jsonResult.setFailure("??");
            e.printStackTrace();
        }
        return jsonResult;
    }

    /**
     * ??
     *
     * @param accountID
     * @param appKey
     * @return
     */
    @RequestMapping("/mileageSumRankingDetail")
    @ResponseBody
    public CommonJsonResult mileageSumRankingDetail(@RequestParam String accountID, @RequestParam String appKey) {
        CommonJsonResult jsonResult = new CommonJsonResult();
        try {
            List<IndexRankingDetail> list = indexRankingDetailService.getMileageSumList(accountID, DEFAULT_BEGAN,
                    DEFAULT_FINISH);
            jsonResult.setERRORCODE(ConstantsUtil.ERRORCODE_OK);
            jsonResult.setRESULT(list);
        } catch (Exception e) {
            logger.error("??" + e.toString());
            jsonResult.setERRORCODE(ConstantsUtil.ERRORCODE_SERVICE_ERROR);
            jsonResult.setFailure("??");
            e.printStackTrace();
        }
        return jsonResult;
    }

    /**
     * ????
     *
     * @param accountID
     * @param appKey
     * @return
     */
    @RequestMapping("/mePointRankingDetail")
    @ResponseBody
    public CommonJsonResult mePointRankingDetail(@RequestParam String accountID, @RequestParam String appKey) {
        CommonJsonResult jsonResult = new CommonJsonResult();
        try {
            List<IndexRankingDetail> list = indexRankingDetailService.getMePointList(accountID, DEFAULT_BEGAN,
                    DEFAULT_FINISH);
            jsonResult.setERRORCODE(ConstantsUtil.ERRORCODE_OK);
            jsonResult.setRESULT(list);
        } catch (Exception e) {
            logger.error("????" + e.toString());
            jsonResult.setERRORCODE(ConstantsUtil.ERRORCODE_SERVICE_ERROR);
            jsonResult.setFailure("????");
            e.printStackTrace();
        }
        return jsonResult;
    }

    /**
     * ??
     *
     * @param accountID
     * @param appKey
     * @return
     */
    @RequestMapping("/driverDaysRankingDetail")
    @ResponseBody
    public CommonJsonResult driverDaysRankingDetail(@RequestParam String accountID, @RequestParam String appKey) {
        CommonJsonResult jsonResult = new CommonJsonResult();
        try {
            List<IndexRankingDetail> list = indexRankingDetailService.getDriverDaysList(accountID, DEFAULT_BEGAN,
                    DEFAULT_FINISH);
            jsonResult.setERRORCODE(ConstantsUtil.ERRORCODE_OK);
            jsonResult.setRESULT(list);
        } catch (Exception e) {
            logger.error("??" + e.toString());
            jsonResult.setERRORCODE(ConstantsUtil.ERRORCODE_SERVICE_ERROR);
            jsonResult.setFailure("??");
            e.printStackTrace();
        }
        return jsonResult;
    }

    /**
     * ????
     *
     * @param accountID
     * @param appKey
     * @return
     */
    @RequestMapping("/tweetCountRankingDetail")
    @ResponseBody
    public CommonJsonResult tweetCountRankingDetail(@RequestParam String accountID, @RequestParam String appKey) {
        CommonJsonResult jsonResult = new CommonJsonResult();
        try {
            List<IndexRankingDetail> list = indexRankingDetailService.getTweetCountList(accountID, DEFAULT_BEGAN,
                    DEFAULT_FINISH);
            jsonResult.setERRORCODE(ConstantsUtil.ERRORCODE_OK);
            jsonResult.setRESULT(list);
        } catch (Exception e) {
            logger.error("????" + e.toString());
            jsonResult.setERRORCODE(ConstantsUtil.ERRORCODE_SERVICE_ERROR);
            jsonResult.setFailure("????");
            e.printStackTrace();
        }
        return jsonResult;
    }

    /**
     * ??
     *
     * @param accountID
     * @param appKey
     * @return
     */
    @RequestMapping("/driverGradeRankingDetail")
    @ResponseBody
    public CommonJsonResult driverGradeRankingDetail(@RequestParam String accountID, @RequestParam String appKey) {
        CommonJsonResult jsonResult = new CommonJsonResult();
        try {
            List<IndexRankingDetail> list = indexRankingDetailService.getDriverGradeList(accountID, DEFAULT_BEGAN,
                    DEFAULT_FINISH);
            jsonResult.setERRORCODE(ConstantsUtil.ERRORCODE_OK);
            jsonResult.setRESULT(list);
        } catch (Exception e) {
            logger.error("??" + e.toString());
            jsonResult.setERRORCODE(ConstantsUtil.ERRORCODE_SERVICE_ERROR);
            jsonResult.setFailure("??");
            e.printStackTrace();
        }
        return jsonResult;
    }

    /**
     * ?
     *
     * @param accountID
     * @param friendAccountID
     * @return
     */
    @RequestMapping("/addFriend")
    @ResponseBody
    public CommonJsonResult addFriend(String msgContent, @RequestParam String accountID, String accountNickName,
            @RequestParam String friendAccountID, String friendNickName, Integer gender, String userArea) {
        CommonJsonResult jsonResult = new CommonJsonResult();
        try {
            //?
            if (StringUtils.isNotBlank(msgContent)) {
                Boolean flag = userFriendService.addFriend(accountID, friendAccountID,
                        ConstantsUtil.NEED_VERIFY_OPINION);
                if (flag) {
                    Map<String, Object> params = new HashMap<String, Object>(4);
                    params.put("verifyMessage", msgContent == null ? "" : msgContent);
                    params.put("accountNickName", accountNickName == null ? "" : accountNickName);
                    params.put("gender", gender == null ? "" : gender);
                    params.put("userArea", userArea == null ? "" : userArea);
                    //??
                    Integer messageID = userService.pushMessage(ConstantsUtil.Push.PUSH_TITLE, friendAccountID,
                            accountNickName + " ???",
                            ConstantsUtil.Push.ADD_FRIEND_TYPE, params, accountID);
                    params = new HashMap<String, Object>(6);
                    params.put("accountID", accountID == null ? "" : accountID);
                    params.put("accountNickName", accountNickName == null ? "" : accountNickName);
                    params.put("friendAccountID", friendAccountID == null ? "" : friendAccountID);
                    params.put("friendNickName", friendNickName == null ? "" : friendNickName);
                    params.put("gender", gender == null ? "" : gender);
                    params.put("messageID", messageID == null ? "" : messageID);
                    SendMessageUtil.sendToTerminalV2(sendPersonalWeibo, callBackAddFriend, params, friendAccountID,
                            "?" + friendNickName + "" + accountNickName
                                    + "???" + msgContent
                                    + "?????");
                    jsonResult.setERRORCODE(ConstantsUtil.ERRORCODE_OK);
                    jsonResult.setRESULT(ConstantsUtil.RESULT_OK);
                } else {
                    jsonResult.setERRORCODE(ConstantsUtil.ERRORCODE_SERVICE_ERROR);
                    jsonResult.setRESULT("?");
                }
            } else {
                boolean flag = userFriendService.addFriend(accountID, friendAccountID,
                        ConstantsUtil.NO_NEED_VERIFY_OPINION);
                if (!flag) {
                    jsonResult.setERRORCODE(ConstantsUtil.ERRORCODE_SERVICE_ERROR);
                    jsonResult.setRESULT("?");
                } else {
                    jsonResult.setERRORCODE(ConstantsUtil.ERRORCODE_OK);
                    jsonResult.setRESULT(ConstantsUtil.RESULT_OK);
                }
            }
        } catch (Exception e) {
            logger.error("?", e);
            jsonResult.setERRORCODE(ConstantsUtil.ERRORCODE_SERVICE_ERROR);
            jsonResult.setRESULT("?");
            e.printStackTrace();
        }
        return jsonResult;
    }

    /**
     * weme  ? 
     *
     * @return
     */
    @RequestMapping("/user/v1.0/callBackAddFriend")
    @ResponseBody
    public CommonJsonResult callBackAgreeAddFriend(HttpServletRequest request) throws Exception {
        CommonJsonResult jsonResult = new CommonJsonResult();

        Map<String, String> params = new HashMap<String, String>();
        Map requestParams = request.getParameterMap();
        for (Iterator iter = requestParams.keySet().iterator(); iter.hasNext();) {
            String name = (String) iter.next();
            String[] values = (String[]) requestParams.get(name);
            String valueStr = "";
            for (int i = 0; i < values.length; i++) {
                valueStr = (i == values.length - 1) ? valueStr + values[i] : valueStr + values[i] + ",";
            }
            params.put(name, valueStr);
        }
        String actionType = params.get("actionType");
        String accountID = params.get("accountID");
        String friendAccountID = params.get("friendAccountID");
        Integer gender = new Integer(params.get("gender"));
        String accountNickName = params.get("accountNickName");
        String friendNickName = params.get("friendNickName");
        String messageID = params.get("messageID");
        /**
         * actionType ?
         :1-?1;2-?2;3-??,4-,5-??,6-yes?,7-no?,8-,9-,10-?,bizid
         ?? 6 YES, 7 NO, 10?
         */
        if ("6".equals(actionType)) {
            //???
            userFriendService.agreeAddFriend(accountID, friendAccountID, new Integer(messageID));
            //??
            String ta = "";
            if (1 == gender) {
                ta = "";
            } else if (0 == gender) {
                ta = "";
            } else {
                ta = "TA";
            }
            userService.pushMessage(ConstantsUtil.Push.PUSH_TITLE, friendAccountID,
                    accountNickName + " ???" + ta + "???",
                    ConstantsUtil.Push.AGREE_ADD_FRIEND_TYPE, null);

        } else if ("7".equals(actionType)) {
            userService.pushMessage(ConstantsUtil.Push.PUSH_TITLE, accountID,
                    friendNickName + " ??????",
                    ConstantsUtil.Push.DIS_AGREE_ADD_FRIEND_TYPE, null);
        }
        jsonResult.setERRORCODE(ConstantsUtil.ERRORCODE_OK);
        jsonResult.setRESULT(ConstantsUtil.RESULT_OK);
        return jsonResult;
    }

    /**
     * ???
     *
     * @param accountID
     * @param friendAccountID
     * @param accountNickName
     * @return
     */
    @RequestMapping("/agreeAddFriend")
    @ResponseBody
    public CommonJsonResult agreeAddFriend(@RequestParam String accountNickName, @RequestParam String accountID,
            @RequestParam String friendAccountID, @RequestParam Integer gender, Integer messageID) {
        CommonJsonResult jsonResult = new CommonJsonResult();
        try {
            //???
            Boolean flag = userFriendService.agreeAddFriend(accountID, friendAccountID, messageID);
            if (flag) {
                //??
                String ta = "";
                if (1 == gender) {
                    ta = "";
                } else if (0 == gender) {
                    ta = "";
                } else {
                    ta = "TA";
                }
                userService.pushMessage(ConstantsUtil.Push.PUSH_TITLE, friendAccountID,
                        accountNickName + " ???" + ta + "???",
                        ConstantsUtil.Push.AGREE_ADD_FRIEND_TYPE, null, accountID);
                jsonResult.setERRORCODE(ConstantsUtil.ERRORCODE_OK);
                jsonResult.setRESULT(ConstantsUtil.RESULT_OK);
            } else {
                jsonResult.setERRORCODE(ConstantsUtil.ERRORCODE_OK);
                jsonResult.setRESULT("?");
            }
        } catch (Exception e) {
            logger.error("???", e);
            jsonResult.setERRORCODE(ConstantsUtil.ERRORCODE_SERVICE_ERROR);
            jsonResult.setFailure("???");
            e.printStackTrace();
        }
        return jsonResult;
    }

    /**
     * ????
     *
     * @param accountNickName
     * @param friendAccountID
     * @return
     */
    @RequestMapping("/disAgreeAddFriend")
    @ResponseBody
    public CommonJsonResult disAgreeAddFriend(@RequestParam String accountNickName,
            @RequestParam String friendAccountID, @RequestParam String accountID, Integer messageID) {
        CommonJsonResult jsonResult = new CommonJsonResult();
        try {
            //??
            userService.pushMessage(ConstantsUtil.Push.PUSH_TITLE, friendAccountID,
                    accountNickName + " ??????",
                    ConstantsUtil.Push.DIS_AGREE_ADD_FRIEND_TYPE, null, accountID);
            userFriendService.disAgreeAddFriend(messageID);
            jsonResult.setERRORCODE(ConstantsUtil.ERRORCODE_OK);
            jsonResult.setRESULT(ConstantsUtil.RESULT_OK);
        } catch (Exception e) {
            logger.error("??", e);
            jsonResult.setERRORCODE(ConstantsUtil.ERRORCODE_SERVICE_ERROR);
            jsonResult.setFailure("??");
            e.printStackTrace();
        }
        return jsonResult;
    }

    /**
     * ?
     *
     * @param accountID
     * @return
     */
    @RequestMapping("/queryUserFriend")
    @ResponseBody
    public CommonJsonResult queryUserFriend(@RequestParam String accountID, Integer startPage, Integer pageCount) {
        CommonJsonResult jsonResult = new CommonJsonResult();
        try {
            //            List<UserFriend> userFriendList = userFriendService.getAllFriends(accountID);
            if (startPage == null || "".equals(startPage)) {
                startPage = 1;
            }
            if (pageCount == null || "".equals(pageCount)) {
                pageCount = 15;
            }
            PageList userFriendPageList = userFriendService.pageQueryFriends(accountID, startPage, pageCount);
            List<UserFriend> userFriendList = userFriendPageList.getRecords();
            if (userFriendList != null && userFriendList.size() != 0) {
                List<String> friendAccountIDList = new ArrayList<String>();
                List<Map<String, Object>> list = new ArrayList<Map<String, Object>>(friendAccountIDList.size());
                for (UserFriend userFriend : userFriendList) {
                    Map<String, Object> friendAccount = new HashMap<String, Object>();
                    if (accountID.equals(userFriend.getAccountID())) {
                        friendAccountIDList.add(userFriend.getFriendAccountID());
                        friendAccount.put("accountID", userFriend.getFriendAccountID());
                        list.add(friendAccount);
                    } else if (accountID.equals(userFriend.getFriendAccountID())) {
                        friendAccountIDList.add(userFriend.getAccountID());
                        friendAccount.put("accountID", userFriend.getAccountID());
                        list.add(friendAccount);
                    }
                }
                //?
                List<UserDetailVo> userGradeList = userGradeService.queryUserFriendDetailList(friendAccountIDList);
                for (Map<String, Object> friendAccount : list) {
                    //?
                    for (UserDetailVo userDetailVo : userGradeList) {
                        if (friendAccount.get("accountID").equals(userDetailVo.getAccountID())) {
                            friendAccount.put("userHeadName",
                                    userDetailVo.getUserHeadName() == null ? "" : userDetailVo.getUserHeadName());
                            friendAccount.put("nickName",
                                    userDetailVo.getNickName() == null ? "" : userDetailVo.getNickName());
                            friendAccount.put("gender",
                                    userDetailVo.getGender() == null ? "" : userDetailVo.getGender());
                            friendAccount.put("userArea",
                                    userDetailVo.getUserAreaCode() == null ? ""
                                            : MapServiceImpl.CITY_CODE.get(userDetailVo.getUserAreaCode()) == null
                                                    ? ""
                                                    : MapServiceImpl.CITY_CODE.get(userDetailVo.getUserAreaCode()));
                        }
                    }
                }
                userFriendPageList.setRecords(list);
                jsonResult.setERRORCODE(ConstantsUtil.ERRORCODE_OK);
                jsonResult.setRESULT(userFriendPageList);
            } else {
                jsonResult.setERRORCODE(ConstantsUtil.ERRORCODE_OK);
                jsonResult.setRESULT("?");
            }
        } catch (Exception e) {
            logger.error("?", e);
            jsonResult.setERRORCODE(ConstantsUtil.ERRORCODE_SERVICE_ERROR);
            jsonResult.setFailure("?");
            e.printStackTrace();
        }
        return jsonResult;
    }

    /**
     * ?
     *
     * @param accountID
     * @param friendAccountID
     * @return
     */
    @RequestMapping("/removeUserFriend")
    @ResponseBody
    public CommonJsonResult removeUserFriend(@RequestParam String accountID, @RequestParam String friendAccountID) {
        CommonJsonResult jsonResult = new CommonJsonResult();
        try {
            userFriendService.removeUserFriend(accountID, friendAccountID);
            jsonResult.setERRORCODE(ConstantsUtil.ERRORCODE_OK);
            jsonResult.setRESULT(ConstantsUtil.RESULT_OK);
        } catch (Exception e) {
            logger.error("?", e);
            jsonResult.setERRORCODE(ConstantsUtil.ERRORCODE_SERVICE_ERROR);
            jsonResult.setFailure("?");
            e.printStackTrace();
        }
        return jsonResult;
    }

    /**
     * ?
     *
     * @param accountID
     * @param isAllowedOpinion       ??? 1:? 0:??
     * @param isVerifyOpinion        ???? 1: 0:?
     * @param isReceiveNotifyOpinion ?? 1: 0:?
     * @return
     */
    @RequestMapping("/friendSetting")
    @ResponseBody
    public CommonJsonResult friendSetting(@RequestParam String accountID, Integer isAllowedOpinion,
            Integer isVerifyOpinion, Integer isReceiveNotifyOpinion) {
        CommonJsonResult jsonResult = new CommonJsonResult();
        try {
            friendSettingService.updateFriendSetting(accountID, isAllowedOpinion, isVerifyOpinion,
                    isReceiveNotifyOpinion);
            jsonResult.setERRORCODE(ConstantsUtil.ERRORCODE_OK);
            jsonResult.setRESULT(ConstantsUtil.RESULT_OK);
        } catch (Exception e) {
            logger.error("?", e);
            jsonResult.setERRORCODE(ConstantsUtil.ERRORCODE_SERVICE_ERROR);
            jsonResult.setFailure("?");
            e.printStackTrace();
        }
        return jsonResult;
    }

    /**
     * ?
     *
     * @param accountID
     * @return
     */
    @RequestMapping("/queryFriendSetting")
    @ResponseBody
    public CommonJsonResult queryFriendSetting(@RequestParam String accountID) {
        CommonJsonResult jsonResult = new CommonJsonResult();
        try {
            FriendSetting friendSetting = friendSettingService.queryFriendSetting(accountID);
            jsonResult.setERRORCODE(ConstantsUtil.ERRORCODE_OK);
            jsonResult.setRESULT(friendSetting);
        } catch (Exception e) {
            logger.error("?", e);
            jsonResult.setERRORCODE(ConstantsUtil.ERRORCODE_SERVICE_ERROR);
            jsonResult.setFailure("?");
            e.printStackTrace();
        }
        return jsonResult;
    }

    /**
     * ??
     *
     * @param mobiles
     * @return
     */
    @RequestMapping("/judgeIsWeMeAccount")
    @ResponseBody
    public CommonJsonResult judgeIsWeMeAccount(@RequestParam String appKey, @RequestParam String[] mobiles,
            @RequestParam String accountID) {
        CommonJsonResult jsonResult = new CommonJsonResult();
        String appkey = ConstantsUtil.getAppKey(appKey);
        String secret = ConstantsUtil.getSecret(appKey);
        try {
            List<Map<String, Object>> list = new ArrayList<Map<String, Object>>(mobiles.length);
            List<String> friendAccountIDList = new ArrayList<String>();
            String mobileString = "";
            if (mobiles != null && mobiles.length > 0) {
                for (String mobile : mobiles) {
                    mobile = mobile.trim();
                    if (mobile.length() != 11 && mobile.length() != 13) {
                        continue;
                    } else if (mobile.length() == 13 && mobile.substring(2).startsWith("1")) {
                        mobile = mobile.substring(2);
                    } else if (mobile.length() == 11 && !mobile.startsWith("1")) {
                        continue;
                    }
                    mobileString += "," + mobile;
                }
                mobileString = mobileString.substring(1);
                Map<String, String> param = new HashMap<String, String>(3);
                param.put("appKey", appkey);
                param.put("secret", secret);
                param.put("mobile", mobileString);
                //??
                String sign = SHASignature.sign(ParameterUtil.getDaokeSignData(param));
                param.put("sign", sign);
                HttpRequester requester = new HttpRequester();
                HttpRespons respons = requester.sendPost(getAccountIDFromMobile, param);
                if (respons.getCode() == ConstantsUtil.HttpStatusCode.OK) {
                    String content = respons.getContent();
                    CommonJsonResult j = (CommonJsonResult) JsonMapper.fromJson(content, CommonJsonResult.class);
                    Map resultMap = (Map) JsonMapper.fromJson(content, Map.class);

                    if ("0".equals(j.getERRORCODE())) {
                        List<Map> accounts = (List<Map>) j.getRESULT();
                        if (accounts != null && accounts.size() > 0) {
                            for (Map a : accounts) {
                                Map<String, Object> map = new HashMap<String, Object>(3);
                                map.put("mobile", a.get("mobile").toString());
                                map.put("isWeMeAccount", ConstantsUtil.IS_WEME_ACCOUNT);
                                String accountIDTemp = a.get("accountID").toString();
                                String nickNameTemp = a.get("nickname").toString();
                                if (accountIDTemp != null && !"".equals(accountIDTemp)) {
                                    friendAccountIDList.add(accountIDTemp);
                                    map.put("accountID", accountIDTemp);
                                    map.put("nickName", nickNameTemp);
                                    list.add(map);
                                }
                            }
                        }

                    }
                }

                if (friendAccountIDList.size() != 0) {
                    //?
                    List<UserDetailVo> userGradeList = userGradeService
                            .queryUserFriendDetailList(friendAccountIDList);
                    //?
                    List<UserFriend> userFriendList = userFriendService.getAllFriends(accountID);

                    for (Map<String, Object> friendAccount : list) {
                        //?
                        for (UserDetailVo userDetailVo : userGradeList) {
                            if (friendAccount.get("accountID").equals(userDetailVo.getAccountID())) {
                                friendAccount.put("userHeadName", userDetailVo.getUserHeadName() == null ? ""
                                        : userDetailVo.getUserHeadName());
                                friendAccount.put("gender",
                                        userDetailVo.getGender() == null ? "" : userDetailVo.getGender());
                                friendAccount.put("isAllowedOpinion", userDetailVo.getIsAllowedOpinion());
                                friendAccount.put("isVerifyOpinion", userDetailVo.getIsVerifyOpinion());
                                friendAccount.put("userArea", userDetailVo.getUserAreaCode() == null ? ""
                                        : MapServiceImpl.CITY_CODE.get(userDetailVo.getUserAreaCode()) == null ? ""
                                                : MapServiceImpl.CITY_CODE.get(userDetailVo.getUserAreaCode()));
                            }
                        }
                        for (UserFriend userFriend : userFriendList) {
                            //??
                            if (userFriend.getIsAgree() == 1 && ((accountID.equals(userFriend.getAccountID())
                                    && friendAccount.get("accountID").equals(userFriend.getFriendAccountID()))
                                    || (accountID.equals(userFriend.getFriendAccountID())
                                            && friendAccount.get("accountID").equals(userFriend.getAccountID())))) {
                                friendAccount.put("isFriend", 1);
                            }
                        }
                        if (friendAccount.get("isFriend") == null) {
                            friendAccount.put("isFriend", 0);
                        }
                    }

                    jsonResult.setERRORCODE(ConstantsUtil.ERRORCODE_OK);
                    jsonResult.setRESULT(list);
                } else {
                    jsonResult.setERRORCODE(ConstantsUtil.ERRORCODE_OK);
                    jsonResult.setRESULT("");
                }
            } else {
                jsonResult.setERRORCODE(ConstantsUtil.ERRORCODE_OK);
                jsonResult.setRESULT("?");
            }
        } catch (Exception e) {
            logger.error("??", e);
            jsonResult.setERRORCODE(ConstantsUtil.ERRORCODE_SERVICE_ERROR);
            jsonResult.setFailure("??");
            e.printStackTrace();
        }
        return jsonResult;
    }

    /**
     * ??
     *
     * @param accountID
     * @param friendAccountID
     * @param msgContent
     * @return
     */
    @RequestMapping("/talkPushMessage")
    @ResponseBody
    public CommonJsonResult talkPushMessage(@RequestParam String accountID, @RequestParam String friendAccountID,
            @RequestParam String accountNickName, @RequestParam String senderUserHeadName,
            @RequestParam String friendNickName, @RequestParam Integer gender, @RequestParam String msgContent) {
        CommonJsonResult jsonResult = new CommonJsonResult();
        try {
            Map<String, Object> params = new HashMap<String, Object>(7);
            params.put("talkContent", msgContent);
            //??
            String ta = "";
            if (1 == gender) {
                ta = "";
            } else if (0 == gender) {
                ta = "";
            } else {
                ta = "TA";
            }
            Long createTime = System.currentTimeMillis() / 1000;
            params.put("friendNickName", friendNickName);
            params.put("accountNickName", accountNickName);
            params.put("senderUserHeadName", senderUserHeadName);
            params.put("pushTime", createTime);
            params.put("accountID", accountID);
            params.put("ta", ta);
            String paramsJson = JsonMapper.toJson(params, false);
            //??
            MessageCentre messageContre = new MessageCentre();
            messageContre.setIsValid(1);
            messageContre.setCreateTime(createTime);
            messageContre.setAccountID(friendAccountID);
            messageContre.setContent(
                    friendNickName + "" + accountNickName + " ?" + ta + "??");
            messageContre.setMsgTitle("");
            messageContre.setParam(paramsJson);
            messageContre.setSenderAccountID(accountID);
            messageContre.setMessageType("talk");
            messageContre.setIsRead(0);
            userService.insert(messageContre);
            String messageContreJson = JsonMapper.toJson(messageContre, false);
            SendMessageUtil.pushMessage("talk", messageContreJson, friendAccountID);

            UserTalkRecord userTalkRecord = new UserTalkRecord();
            userTalkRecord.setIsValid(1);
            userTalkRecord.setAccountID(accountID);
            userTalkRecord.setFriendAccountID(friendAccountID);
            userTalkRecord.setTalkContent(msgContent);
            userTalkRecord.setCreateTime(createTime);
            userTalkRecordService.insert(userTalkRecord);
            jsonResult.setERRORCODE(ConstantsUtil.ERRORCODE_OK);
            jsonResult.setRESULT(ConstantsUtil.RESULT_OK);
        } catch (Exception e) {
            logger.error("??", e);
            jsonResult.setERRORCODE(ConstantsUtil.ERRORCODE_SERVICE_ERROR);
            jsonResult.setFailure("??");
            e.printStackTrace();
        }
        return jsonResult;
    }

    /**
     * ?
     *
     * @param accountID
     * @return
     */
    @RequestMapping("/queryMessageCentre")
    @ResponseBody
    public CommonJsonResult queryMessageCentre(@RequestParam String accountID, String messageType,
            @RequestParam Integer pageNo, @RequestParam Integer pageCount) {
        CommonJsonResult jsonResult = new CommonJsonResult();
        try {
            PageList<MessageCentre> pushMessagePageList = userService.queryMessageCentre(accountID, messageType,
                    pageNo, pageCount);
            jsonResult.setERRORCODE(ConstantsUtil.ERRORCODE_OK);
            jsonResult.setRESULT(pushMessagePageList);
        } catch (Exception e) {
            logger.error("?", e);
            jsonResult.setERRORCODE(ConstantsUtil.ERRORCODE_SERVICE_ERROR);
            jsonResult.setFailure("?");
            e.printStackTrace();
        }
        return jsonResult;
    }

    /**
     * ??
     *
     * @param accountID
     * @return
     */
    @RequestMapping("/countNewMessageCentre")
    @ResponseBody
    public CommonJsonResult countNewMessageCentre(@RequestParam String accountID) {
        CommonJsonResult jsonResult = new CommonJsonResult();
        try {
            Map<String, Integer> map = new HashMap<String, Integer>(1);
            int count = userService.countNewMessageCentre(accountID);
            map.put("newMessageCount", count);
            jsonResult.setERRORCODE(ConstantsUtil.ERRORCODE_OK);
            jsonResult.setRESULT(map);
        } catch (Exception e) {
            logger.error("??", e);
            jsonResult.setERRORCODE(ConstantsUtil.ERRORCODE_SERVICE_ERROR);
            jsonResult.setFailure("??");
            e.printStackTrace();
        }
        return jsonResult;
    }

    /**
     * ?
     *
     * @param messageCentreIDs
     * @return
     */
    @RequestMapping("/removeMessageCentre")
    @ResponseBody
    public CommonJsonResult removeMessageCentre(Integer[] messageCentreIDs, String accountID) {
        CommonJsonResult jsonResult = new CommonJsonResult();
        try {
            userService.removeMessageCentre(messageCentreIDs, accountID);
            jsonResult.setERRORCODE(ConstantsUtil.ERRORCODE_OK);
            jsonResult.setRESULT(ConstantsUtil.RESULT_OK);
        } catch (Exception e) {
            logger.error("?", e);
            jsonResult.setERRORCODE(ConstantsUtil.ERRORCODE_SERVICE_ERROR);
            jsonResult.setFailure("?");
            e.printStackTrace();
        }
        return jsonResult;
    }

    /**
     * ?
     *
     * @param messageID
     * @return
     */
    @RequestMapping("/updateMessageIsRead")
    @ResponseBody
    public CommonJsonResult updateMessageIsRead(@RequestParam Integer messageID) {
        CommonJsonResult jsonResult = new CommonJsonResult();
        try {
            userService.updateMessageIsRead(messageID);
            jsonResult.setERRORCODE(ConstantsUtil.ERRORCODE_OK);
            jsonResult.setRESULT(ConstantsUtil.RESULT_OK);
        } catch (Exception e) {
            logger.error("?", e);
            jsonResult.setERRORCODE(ConstantsUtil.ERRORCODE_SERVICE_ERROR);
            jsonResult.setFailure("?");
            e.printStackTrace();
        }
        return jsonResult;
    }

    /**
     * 
     *
     * @param accountID
     * @param reportType
     * @param reportObject
     * @return
     */
    @RequestMapping("/insertReportInfo")
    @ResponseBody
    public CommonJsonResult insertReportInfo(@RequestParam String accountID, @RequestParam Integer reportType,
            @RequestParam String reportObject, @RequestParam String content) {
        CommonJsonResult jsonResult = new CommonJsonResult();
        try {
            ReportInfo reportInfo = new ReportInfo();
            reportInfo.setIsValid(1);
            reportInfo.setContent(content);
            reportInfo.setAccountID(accountID);
            reportInfo.setReportObject(reportObject);
            reportInfo.setReportType(reportType);
            reportInfo.setCreateTime(System.currentTimeMillis() / 1000);
            reportInfoService.insertReportInfo(reportInfo);
            jsonResult.setERRORCODE(ConstantsUtil.ERRORCODE_OK);
            jsonResult.setRESULT(ConstantsUtil.RESULT_OK);
        } catch (Exception e) {
            logger.error("", e);
            jsonResult.setERRORCODE(ConstantsUtil.ERRORCODE_SERVICE_ERROR);
            jsonResult.setFailure("");
            e.printStackTrace();
        }
        return jsonResult;
    }

    /**
     * weme  ?  
     *
     * @return
     */
    @RequestMapping("/user/v1.0/callBackReceiveRochelle")
    @ResponseBody
    public CommonJsonResult callBackRochelleTerminal(HttpServletRequest request) throws Exception {
        CommonJsonResult jsonResult = new CommonJsonResult();

        Map<String, String> params = new HashMap<String, String>();
        Map requestParams = request.getParameterMap();
        for (Iterator iter = requestParams.keySet().iterator(); iter.hasNext();) {
            String name = (String) iter.next();
            String[] values = (String[]) requestParams.get(name);
            String valueStr = "";
            for (int i = 0; i < values.length; i++) {
                valueStr = (i == values.length - 1) ? valueStr + values[i] : valueStr + values[i] + ",";
            }
            params.put(name, valueStr);
        }

        String actionType = params.get("actionType");
        //String accountID = params.get("accountID");
        String recordID = params.get("rewardID");
        /**
         * actionType ?
         :1-?1;2-?2;3-??,4-,5-??,6-yes?,7-no?,8-,9-,10-?,bizid
         ?? 6 YES, 7 NO, 10?
         */
        if (actionType.equals("6")) {
            UserRochelleDetail userRochelleDetail = userRochelleDetailService
                    .getUserRochelleDetailByRecordID(Integer.valueOf(recordID));
            if (userRochelleDetail != null && userRochelleDetail.getReceiveStatus() == 0) {
                Calendar cal = Calendar.getInstance();

                if (AbDateUtil.getOffectHour(cal.getTimeInMillis(),
                        userRochelleDetail.getCreateDate().getTime()) <= 24) {

                    Object[] objects = userGradeService.updateUserGrade(userRochelleDetail.getAccountID(), "",
                            userRochelleDetail.getRochelle(), Integer.valueOf(recordID));
                    //?
                    if (objects != null) {
                        //??
                        // SendMessageUtil.sendToMobile(userRochelleDetail.getAccountID(),"?","");
                        SendMessageUtil.sendToTerminal(sendPersonalWeibo, callBackReceiveRochelle,
                                (Integer) objects[2], userRochelleDetail.getAccountID(),
                                objects[3] == null ? "" : objects[3].toString());
                    }
                }

            }
        }
        jsonResult.setERRORCODE(ConstantsUtil.ERRORCODE_OK);
        jsonResult.setRESULT("??");
        return jsonResult;
    }

    /**
     * ??
     *
     * @return
     */
    @RequestMapping("/rankCofig")
    @ResponseBody
    public CommonJsonResult rankCofig(HttpServletRequest request) {
        CommonJsonResult result = new CommonJsonResult();
        result.setERRORCODE(ConstantsUtil.ERRORCODE_OK);
        result.setRESULT(ConstantsUtil.rankCofig);
        return result;

    }

    //    /**
    //     * ?
    //     *
    //     * @return
    //     */
    //    @RequestMapping("/testPushReward")
    //    @ResponseBody
    //    public CommonJsonResult testPushReward(HttpServletRequest request) {
    //        CommonJsonResult result = new CommonJsonResult();
    //        Map<String,Object> param = new HashMap<String,Object>();
    //        //?
    //        param.put("rewardID", 27849802);
    //        param.put("ruleType", UserRochelleRuleServiceImpl.ruleTypeMap.get("drive300KmMonth"));
    //        try {
    //            userService.pushMessage("", "kxl1QuHKCD", "?????", "rochelleReward", param);
    //        }catch (Exception e){
    //
    //        }
    //
    //        result.setERRORCODE(ConstantsUtil.ERRORCODE_OK);
    //        result.setRESULT(ConstantsUtil.RESULT_OK);
    //        return result;
    //
    //    }
    /**
     * ?
     *
     * @param accountID ?ID
     * @param rewardID
     * @return
     */
    @RequestMapping("/user/v1.0/mobileRewardRochelle")
    @ResponseBody
    public CommonJsonResult mobileRewardRochelle(@RequestParam String accountID, @RequestParam String rewardID)
            throws Exception {
        CommonJsonResult commonJsonResult = new CommonJsonResult();

        UserRochelleDetail userRochelleDetail = userRochelleDetailService
                .getUserRochelleDetailByRecordID(Integer.valueOf(rewardID));
        try {
            if (userRochelleDetail != null && userRochelleDetail.getReceiveStatus() == 0) {
                Calendar cal = Calendar.getInstance();

                Object[] objects = userGradeService.updateUserGrade(accountID, "", userRochelleDetail.getRochelle(),
                        Integer.valueOf(rewardID));
                //?
                if (objects != null) {
                    //??
                    // SendMessageUtil.sendToMobile(userRochelleDetail.getAccountID(),"?","");
                    SendMessageUtil.sendToTerminal(sendPersonalWeibo, callBackReceiveRochelle, (Integer) objects[2],
                            userRochelleDetail.getAccountID(), objects[3] == null ? "" : objects[3].toString());
                }
                commonJsonResult.setERRORCODE(ConstantsUtil.ERRORCODE_OK);
                commonJsonResult.setRESULT("??");
            } else {
                commonJsonResult.setERRORCODE(ConstantsUtil.ERRORCODE_OK);
                commonJsonResult.setRESULT("?");
            }
        } catch (Exception e) {
            logger.error("?");
            commonJsonResult.setERRORCODE(ConstantsUtil.ERRORCODE_SERVICE_ERROR);
            commonJsonResult.setRESULT("?");
        }
        return commonJsonResult;
    }

    /**
     *?
     */
    @ResponseBody
    @RequestMapping("/userBindMobile")
    public CommonJsonResult userBindMobile(@RequestParam String appKey, String mobile, String accountID,
            @RequestParam String newmobile, String validateCode) {
        CommonJsonResult jsonResult = new CommonJsonResult();
        String appkey = ConstantsUtil.getAppKey(appKey);
        String secret = ConstantsUtil.getSecret(appKey);
        try {
            int codeInDBCount = userService.findValidCode(validateCode, newmobile);
            if (codeInDBCount < 1) {
                throw new Exception("1");
            }
            Map<String, String> param = new HashMap<String, String>(5);
            param.put("appKey", appkey);
            param.put("secret", secret);
            param.put("mobile", mobile == null ? "" : mobile);
            param.put("accountID", accountID == null ? "" : accountID);
            param.put("newmobile", newmobile);
            //??
            String sign = SHASignature.sign(ParameterUtil.getDaokeSignData(param));
            param.put("sign", sign);
            HttpRequester requester = new HttpRequester();
            HttpRespons respons = requester.sendPost(userBindMobile, param);
            if (respons.getCode() == ConstantsUtil.HttpStatusCode.OK) {
                String content = respons.getContent();
                jsonResult = (CommonJsonResult) JsonMapper.fromJson(content, CommonJsonResult.class);
            }
        } catch (Exception e) {
            if ("1".equals(e.getMessage())) {
                logger.error("??", e);
                jsonResult.setERRORCODE(ConstantsUtil.ERRORCODE_VERICODE);
                jsonResult.setRESULT(ConstantsUtil.RESULT_VERICODE);
            } else {
                logger.error("?", e);
                jsonResult.setERRORCODE(ConstantsUtil.ERRORCODE_SERVICE_ERROR);
                jsonResult.setRESULT("?");
            }
        }
        return jsonResult;
    }

    /**
     *????
     */
    @ResponseBody
    @RequestMapping("/sendBindVerifyMessage")
    public CommonJsonResult sendBindVerifyMessage(@RequestParam String mobile) {
        CommonJsonResult jsonResult = new CommonJsonResult();
        String verifyCode = String.valueOf(RandomNumberUtil.genRandomNum(6));
        try {
            SendTemplateSMSUtil.sendTemplateSMS(mobile, "21109", verifyCode, "5");
            //???
            userService.insertIdentifyingCode(mobile, verifyCode, "3", "5");
            jsonResult.setERRORCODE(ConstantsUtil.ERRORCODE_OK);
            jsonResult.setRESULT("?????");
        } catch (Exception e) {
            logger.error("????", e);
            jsonResult.setERRORCODE(ConstantsUtil.ERRORCODE_SERVICE_ERROR);
            jsonResult.setRESULT("????");
        }
        return jsonResult;
    }

    /**
     *?
     * @param appKey
     * @param accountID
     * @param mobile
     * @return
     */
    @ResponseBody
    @RequestMapping("/checkMobileRegister")
    public CommonJsonResult checkMobileRegister(@RequestParam String appKey, @RequestParam String accountID,
            String mobile) {
        CommonJsonResult jsonResult = new CommonJsonResult();
        String appkey = ConstantsUtil.getAppKey(appKey);
        String secret = ConstantsUtil.getSecret(appKey);
        try {
            Map<String, String> param = new HashMap<String, String>(4);
            param.put("appKey", appkey);
            param.put("secret", secret);
            param.put("mobile", mobile);
            param.put("accountID", accountID);
            //??
            String sign = SHASignature.sign(ParameterUtil.getDaokeSignData(param));
            param.put("sign", sign);
            HttpRequester requester = new HttpRequester();
            HttpRespons respons = requester.sendPost(checkMobileRegister, param);
            if (respons.getCode() == ConstantsUtil.HttpStatusCode.OK) {
                String content = respons.getContent();
                jsonResult = (CommonJsonResult) JsonMapper.fromJson(content, CommonJsonResult.class);
            }
        } catch (Exception e) {
            e.printStackTrace();
            logger.error("?", e);
            jsonResult.setERRORCODE(ConstantsUtil.ERRORCODE_SERVICE_ERROR);
            jsonResult.setRESULT("?");
        }
        return jsonResult;
    }
    /**
     * ?
     *
     * @return
     */
    //    @RequestMapping("/user/exceutePush")
    //    @ResponseBody
    //    public CommonJsonResult exceutePush() {
    //        CommonJsonResult commonJsonResult = new CommonJsonResult();
    //        try {
    //            //??
    //            final ExecutorService threadPool_thread = Executors.newFixedThreadPool(4);
    //            for (int i = 0; i < 4; i++) {
    //                threadPool_thread.execute(
    //                        new Runnable() {
    //                            @Override
    //                            public void run() {
    //                                while (true) {
    //                                    try {
    //                                        //????ID
    //                                        final String message = receiveRochelleMessage.receive();
    //                                        try {
    //                                            RuleRewardMq ruleRewardMq = (RuleRewardMq) me.daoke.common.mq.util.JsonMapper.fromJson(message, RuleRewardMq.class);
    //                                            logger.info("ruleRewardMq:"+ ruleRewardMq);
    //                                            // System.out.println("ruleRewardMq: " + ruleRewardMq);
    //                                            //
    //                                            Object[] obj = userGradeService.toReward(ruleRewardMq.getAccountID(), ruleRewardMq.getIMEI(), ruleRewardMq.getRuleCode());
    //                                            logger.info(":"+ obj.toString());
    //                                            UserGrade userGrade = userGradeService.queryByAccountID(ruleRewardMq.getAccountID());
    //                                            String terminalText = "";
    //                                            if (userGrade != null && StringUtils.isNotBlank(userGrade.getNickName()) && obj != null && obj[3] != null) {
    //                                                terminalText = obj[3].toString().replace("",userGrade.getNickName());
    //                                                //terminalText = "," + String.format(obj[3].toString(), userGrade.getNickName(), obj[1]);
    //                                            } else {
    //                                                // ?IMEI??
    //                                                if(StringUtils.isNotBlank(ruleRewardMq.getIMEI())){
    //                                                    terminalText = obj[3].toString().replace("","?"+ruleRewardMq.getIMEI().substring(ruleRewardMq.getIMEI().length() -4 ,ruleRewardMq.getIMEI().length()));
    //                                                } else{
    //                                                    terminalText = obj[3].toString().replace("","");
    //                                                }
    //
    //                                            }
    //
    //                                            //?
    //
    //                                            Map<String,Object> param = new HashMap<String,Object>();
    //                                            //?
    //
    //                                            param.put("rewardID", (Integer) obj[2]);
    //                                            param.put("ruleType", UserRochelleRuleServiceImpl.ruleTypeMap.get(ruleRewardMq.getRuleCode()));
    //                                            userService.pushMessage("", ruleRewardMq.getAccountID(), obj[4].toString(), "rochelleReward", param);
    //
    //
    //                                            //??
    //                                            SendMessageUtil.sendToTerminal(sendPersonalWeibo, callBackReceiveRochelle, (Integer) obj[2], ruleRewardMq.getAccountID(), terminalText);
    //
    //
    //                                        } catch (Exception e) {
    //                                            logger.error("? ?", e);
    //                                            e.printStackTrace();
    //                                        }
    //                                    } catch (Exception e) {
    //                                        e.printStackTrace();
    //                                        logger.error("ExceptionMessage: {" + e.getMessage() + "}");
    //                                        logger.error("StackTrace: ", e);
    //                                    }
    //                                }
    //                            }
    //                        });
    //            }
    //            threadPool_thread.shutdown();
    //            commonJsonResult.setERRORCODE(ConstantsUtil.ERRORCODE_OK);
    //            commonJsonResult.setRESULT("?");
    //        } catch (Exception e) {
    //            commonJsonResult.setERRORCODE(ConstantsUtil.ERRORCODE_SERVICE_ERROR);
    //            commonJsonResult.setRESULT("");
    //            e.printStackTrace();
    //        }
    //
    //        return commonJsonResult;
    //    }
}