package com.house365.web.wechat;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.base.Strings;
import com.house365.beans.vo.BaseAttachment;
import com.house365.common.FastDFSUtil;
import com.house365.common.util.RestTemplateBean;
import com.house365.config.HgsProp;
import com.house365.config.WeChatProperties;
import com.house365.service.interfaces.WechatClient;
import com.house365.util.FileLocationAttribute;
import com.vdurmont.emoji.EmojiParser;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import org.apache.commons.lang3.StringUtils;
import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * Description
 * <p>
 * Created by 365 on 2017/3/7 0007.
 */
@Controller
@EnableAutoConfiguration
@RequestMapping("/project")
public class ProjectController {

    /**
     * 最大上传文件大小
     */
    private static final long MAX_SIZE_OF_UPLOAD_FILE = 10485760;
    private Logger logger = LoggerFactory.getLogger(ProjectController.class);
    @Autowired
    private HgsProp hgsProp;

    @Autowired
    private FastDFSUtil fastDFSUtil;

    @Autowired
    WechatClient wechatClient;
    @Autowired
    private WeChatProperties weChatProperties;

    @Autowired
    private RedisTemplate redisTemplate;

    @RequestMapping("/myprojects")
    public ModelAndView myProjects() {
        ModelAndView view = new ModelAndView();
        view.setViewName("wechat/project/onSite-project");
        return view;
    }

    @RequestMapping(value = "/getmyprojects", method = RequestMethod.POST, produces = "application/json;charset=utf-8")
    @ResponseBody
    public String getMyProjects(HttpServletRequest request) {
        String result = "";
        try {
            List<NameValuePair> params = new ArrayList<>();
            params.add(new BasicNameValuePair("serviceCode", "Wechat"));
            params.add(new BasicNameValuePair("serviceName", "getMyProjects"));
            params.add(new BasicNameValuePair("phone", getPhoneFromCookie(request)));
            result = RestTemplateBean.doGet(hgsProp.getHgsUrl(), params);
            logger.info("=======getMyProjects======result:{}", result);
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
        }
        return result;
    }

    @RequestMapping("/getprojectdetail")
    public ModelAndView getProjectDetail(String projectId) {
        ModelAndView view = new ModelAndView();
        view.setViewName("wechat/project/distribution");
        try {
            List<NameValuePair> params = new ArrayList<>();
            params.add(new BasicNameValuePair("serviceCode", "Wechat"));
            params.add(new BasicNameValuePair("serviceName", "getProjectDetail"));
            params.add(new BasicNameValuePair("projectId", projectId));
            String result = RestTemplateBean.doGet(hgsProp.getHgsUrl(), params);
            logger.info("=======getProjectDetail======result:{}", result);
            JSONObject data = JSONObject.fromObject(result).getJSONObject("data");

            view.addObject("project", data.getJSONObject("entity"));
            view.addObject("images", data.getJSONArray("list"));
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
        }
        return view;
    }

    private List<NameValuePair> getParams(String serviceName, HttpServletRequest request) {
        List<NameValuePair> params = new ArrayList<>();
        params.add(new BasicNameValuePair("serviceCode", "Wechat"));
        params.add(new BasicNameValuePair("serviceName", serviceName));
        params.add(new BasicNameValuePair("phone", getPhoneFromCookie(request)));
        return params;
    }

//    private JSONArray getUserData(HttpServletRequest request) throws URISyntaxException {
//        String usersInfo = "";
//        List<NameValuePair> userParams = getParams("getUserInfo", request);
//        usersInfo = RestTemplateBean.doGet(hgsProp.getHgsUrl(), userParams);
//
//        JSONArray users = new JSONArray();
//        JSONObject user = new JSONObject();
//        JSONObject usersData = null;
//        if (!Strings.isNullOrEmpty(usersInfo)) {
//            usersData = getData(usersInfo);
//
//            if (usersData.containsKey("list") && usersData.get("list") != null) {
//                user =  usersData.get("entity");
//            }
//        }
//
//        return users;
//    }

    private JSONObject getData(String json) {
        if (Strings.isNullOrEmpty(json)) {
            return new JSONObject();
        }

        JSONObject data = null;
        JSONObject jsonObject = JSONObject.fromObject(json);
        if ("1".equalsIgnoreCase(String.valueOf(jsonObject.get("result")))) {
            data = (JSONObject) jsonObject.get("data");
        } else {
            data = jsonObject;
        }
        return data;
    }


    @RequestMapping("/adddynamic")
    public String adddynamic(HttpServletRequest request, String projectId, String projectName, HttpServletResponse response, Model model) {
        model.addAttribute("projectId", projectId);
        model.addAttribute("projectName", projectName);
        try {
            List<NameValuePair> params = getParams("getUserInfo", request);
            String result = RestTemplateBean.doGet(hgsProp.getHgsUrl(), params);
            logger.error(result);
            JSONObject obj = getData(result);
            JSONObject jo = (JSONObject) obj.get("entity");
            model.addAttribute("createUserid", jo.get("id"));
            model.addAttribute("createUsername", jo.get("name"));
        } catch (Exception e) {
            e.printStackTrace();
        }
        return "wechat/project/adddynamic";
    }


    @RequestMapping("/getprojectdynamiccell")
    @ResponseBody
    public String getprojectdynamiccell(HttpServletRequest request, String projectId, String page, HttpServletResponse response, Model model) {
        List<NameValuePair> params = new ArrayList<>();
//        ModelAndView view = new ModelAndView();
        page = Strings.isNullOrEmpty(request.getParameter("page")) ? "0" : request.getParameter("page");
        Integer starPage = (Integer.valueOf(page) > 0 ? (Integer.valueOf(page) - 1) : Integer.valueOf(page)) * 20;
        params.add(new BasicNameValuePair("pageNo", String.valueOf(starPage)));
        params.add(new BasicNameValuePair("pageSize", "20"));
        try {
            params.add(new BasicNameValuePair("serviceCode", "Wechat"));
            params.add(new BasicNameValuePair("serviceName", "getProjectDynamicList"));
            params.add(new BasicNameValuePair("projectId", projectId));
            String result = RestTemplateBean.doGet(hgsProp.getHgsUrl(), params);
            logger.info("=======getProjectDetail======result:{}", result);
            JSONObject data = JSONObject.fromObject(result).getJSONObject("data");
            JSONArray list = data.getJSONArray("list");
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
            if (list == null || list.size() == 0) {
                return null;
            } else {
                JSONArray jarr = new JSONArray();
                for (int i = 0; i < list.size(); i++) {
                    JSONArray picArray = list.getJSONObject(i).getJSONArray("picList");
                    String pics = picArray.toString();
                    String createUsername = String.valueOf(list.getJSONObject(i).get("createUsername"));
                    String createTime = String.valueOf(list.getJSONObject(i).get("createTime"));
                    String dynamicId = String.valueOf(list.getJSONObject(i).get("dynamicId"));
                    String createUserid = String.valueOf(list.getJSONObject(i).get("createUserid"));
                    if (createTime.contains("time")) {
                        String[] str = createTime.split(",");
                        String[] time = str[6].split(":");
                        Date date = new Date();
                        date.setTime(Long.valueOf(time[1]));
                        createTime = sdf.format(date);
                    }
                    String dynamicContent = String.valueOf(list.getJSONObject(i).get("dynamicContent"));

                    JSONObject jo = new JSONObject();
                    jo.put("pics", pics);
                    jo.put("createUserid", createUserid);
                    jo.put("createUsername", createUsername);
                    jo.put("dynamicContent", EmojiParser.parseToUnicode(dynamicContent));
                    jo.put("createTime", createTime);
                    jo.put("dynamicId", dynamicId);
                    jarr.add(jo);
                }
                //获取当前用户
                List<NameValuePair> currentUserParams = getParams("getUserInfo", request);
                String currentUserResult = RestTemplateBean.doGet(hgsProp.getHgsUrl(), currentUserParams);
                logger.error(currentUserResult);
                JSONObject obj = getData(currentUserResult);
                JSONObject currentUserJo = (JSONObject) obj.get("entity");
                model.addAttribute("currentUser", currentUserJo.get("id"));
                model.addAttribute("data", jarr);
                return jarr.toString();
            }
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
        }
        return "wechat/project/dynamiclist";
    }

    @RequestMapping("/getprojectdynamiclist")
    public String getprojectdynamiclist(HttpServletRequest request, String projectId, String projectName, String page, HttpServletResponse response, Model model) {
        List<NameValuePair> params = new ArrayList<>();
        ModelAndView view = new ModelAndView();
        page = Strings.isNullOrEmpty(request.getParameter("page")) ? "0" : request.getParameter("page");
        model.addAttribute("projectId", projectId);
        model.addAttribute("projectName", projectName);
        Integer starPage = (Integer.valueOf(page) > 0 ? (Integer.valueOf(page) - 1) : Integer.valueOf(page)) * 20;
        params.add(new BasicNameValuePair("pageNo", String.valueOf(starPage)));
        params.add(new BasicNameValuePair("pageSize", "20"));
        try {
            params.add(new BasicNameValuePair("serviceCode", "Wechat"));
            params.add(new BasicNameValuePair("serviceName", "getProjectDynamicList"));
            params.add(new BasicNameValuePair("projectId", projectId));
            String result = RestTemplateBean.doGet(hgsProp.getHgsUrl(), params);
            logger.info("=======getProjectDetail======result:{}", result);
            JSONObject data = JSONObject.fromObject(result).getJSONObject("data");
            JSONArray list = data.getJSONArray("list");
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
            if (list == null || list.size() == 0) {
                return "wechat/project/nodata";
            } else {
                JSONArray jarr = new JSONArray();
                for (int i = 0; i < list.size(); i++) {
                    JSONArray picArray = list.getJSONObject(i).getJSONArray("picList");
                    String pics = picArray.toString();
                    String createUsername = String.valueOf(list.getJSONObject(i).get("createUsername"));
                    String createTime = String.valueOf(list.getJSONObject(i).get("createTime"));
                    if (createTime.contains("time")) {
                        String[] str = createTime.split(",");
                        String[] time = str[6].split(":");
                        Date date = new Date();
                        date.setTime(Long.valueOf(time[1]));
                        createTime = sdf.format(date);
                    }
                    String dynamicContent = String.valueOf(list.getJSONObject(i).get("dynamicContent"));
                    logger.error("***********dynamicContent********原始*****" + dynamicContent);
                    logger.error("***********dynamicContent********还原*****" + EmojiParser.parseToUnicode(dynamicContent));
                    JSONObject jo = new JSONObject();
                    jo.put("pics", pics);
                    jo.put("createUserid", list.getJSONObject(i).get("createUserid"));
                    jo.put("createUsername", createUsername);
                    jo.put("dynamicContent", EmojiParser.parseToUnicode(dynamicContent));
                    jo.put("createTime", createTime);
                    jo.put("dynamicId", list.getJSONObject(i).get("dynamicId"));
                    jarr.add(jo);
                }

                //获取当前用户
                List<NameValuePair> currentUserParams = getParams("getUserInfo", request);
                String currentUserResult = RestTemplateBean.doGet(hgsProp.getHgsUrl(), currentUserParams);
                logger.error(currentUserResult);
                JSONObject obj = getData(currentUserResult);
                JSONObject currentUserJo = (JSONObject) obj.get("entity");
                model.addAttribute("currentUser", currentUserJo.get("id"));

                model.addAttribute("data", jarr);

//                model.setViewName("wechat/project/dynamiclist");
            }
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
        }
        return "wechat/project/dynamiclist";
    }

    @RequestMapping("/distribution")
    public String distribution() {
        return "wechat/project/distribution";
    }

    @RequestMapping("/customers")
    public ModelAndView customers(String projectId, String keyword) {
        ModelAndView view = new ModelAndView();
        view.addObject("projectId", projectId);
        view.addObject("keyword", keyword);
        view.setViewName("wechat/project/client-list");
        return view;
    }

    @RequestMapping(value = "/getcustomers", method = RequestMethod.POST, produces = "application/json;charset=utf-8")
    @ResponseBody
    public String getCustomers(HttpServletRequest request, String projectId, String currentPage, String timeFilter,
                               String projectFilter, String buyIntentionFilter, String keyword) {
        String result = "";
        try {
            List<NameValuePair> params = new ArrayList<>();
            params.add(new BasicNameValuePair("serviceCode", "Wechat"));
            params.add(new BasicNameValuePair("serviceName", "getCustomers"));
            params.add(new BasicNameValuePair("phone", getPhoneFromCookie(request)));
            params.add(new BasicNameValuePair("projectId", projectId));
            params.add(new BasicNameValuePair("currentPage", currentPage));
            if (!Strings.isNullOrEmpty(timeFilter)) {
                params.add(new BasicNameValuePair("timeFilter", timeFilter));
            }
            if (!Strings.isNullOrEmpty(keyword)) {
                params.add(new BasicNameValuePair("keyword", keyword));
            }
            if (!Strings.isNullOrEmpty(projectFilter)) {
                params.add(new BasicNameValuePair("projectFilter", projectFilter));
            }
            if (!Strings.isNullOrEmpty(buyIntentionFilter)) {
                params.add(new BasicNameValuePair("buyIntentionFilter", buyIntentionFilter));
            }
            result = RestTemplateBean.doGet(hgsProp.getHgsUrl(), params);
            logger.info("=======getCustomers======result:{}", result);
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
        }
        return result;
    }

    /**
     * 获取CRM用户视图地址
     *
     * @param request
     * @return
     */
    @RequestMapping(value = "getCRMURL", method = RequestMethod.GET, produces = "application/json;charset=utf-8")
    @ResponseBody
    public String getCRM(HttpServletRequest request) {
        String customerId = request.getParameter("customerId");

        String result = "";
        try {
            List<NameValuePair> params = new ArrayList<>();
            params.add(new BasicNameValuePair("serviceCode", "Wechat"));
            params.add(new BasicNameValuePair("serviceName", "getCRMUrl"));
            params.add(new BasicNameValuePair("customerId", customerId));
            result = RestTemplateBean.doGet(hgsProp.getHgsUrl(), params);
            logger.info("=======getCRMURL======result:{}", result);
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
        }
        return result;
    }

    @RequestMapping("/projectcustomers")
    public ModelAndView projectCustomers(String customerId) {
        ModelAndView view = new ModelAndView();
        view.addObject("customerId", customerId);
        view.setViewName("wechat/project/report");
        return view;
    }

    @RequestMapping(value = "/getprojectcustomers", method = RequestMethod.POST, produces = "application/json;charset=utf-8")
    @ResponseBody
    public String getProjectCustomers(HttpServletRequest request, String customerId) {
        String result = "";
        try {
            List<NameValuePair> params = new ArrayList<>();
            params.add(new BasicNameValuePair("serviceCode", "Wechat"));
            params.add(new BasicNameValuePair("serviceName", "getProjectCustomers"));
            params.add(new BasicNameValuePair("phone", getPhoneFromCookie(request)));
            params.add(new BasicNameValuePair("customerId", customerId));
            result = RestTemplateBean.doGet(hgsProp.getHgsUrl(), params);
            logger.info("=======getProjectCustomers======result:{}", result);
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
        }
        return result;
    }


    @RequestMapping("/customerdetail")
    public ModelAndView customerDetail(String customerId) {
        ModelAndView view = new ModelAndView();
        view.setViewName("wechat/project/client-details");
        view.addObject("customerId", customerId);
        try {
            List<NameValuePair> params = new ArrayList<>();
            params.add(new BasicNameValuePair("serviceCode", "Wechat"));
            params.add(new BasicNameValuePair("serviceName", "getCustomerDetail"));
            params.add(new BasicNameValuePair("customerId", customerId));
            String result = RestTemplateBean.doGet(hgsProp.getHgsUrl(), params);
            logger.info("=======getCustomerDetail======result:{}", result);
            JSONObject data = JSONObject.fromObject(result).getJSONObject("data");
            JSONObject jsonData = data.getJSONObject("entity");
            view.addObject("customer", jsonData.get("customer"));
//            view.addObject("customer", data.getJSONObject("entity"));
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
        }
        return view;
    }

    @RequestMapping("/visitrecord")
    public ModelAndView visitRecord(String customerId, String buyIntention) {
        ModelAndView view = new ModelAndView();
        view.addObject("customerId", customerId);
        view.addObject("buyIntention", buyIntention);
        view.setViewName("wechat/project/visit-record");
        return view;
    }

    @RequestMapping(value = "/getvisitrecords", method = RequestMethod.POST, produces = "application/json;charset=utf-8")
    @ResponseBody
    public String getVisitRecords(String customerId) {
        JSONObject result = new JSONObject();
        try {
            List<NameValuePair> customerProjectParams = new ArrayList<>();
            customerProjectParams.add(new BasicNameValuePair("serviceCode", "Wechat"));
            customerProjectParams.add(new BasicNameValuePair("serviceName", "getVisitCallList"));
            customerProjectParams.add(new BasicNameValuePair("customerId", customerId));
            String customerProjectResult = RestTemplateBean.doGet(hgsProp.getHgsUrl(), customerProjectParams);
            result = JSONObject.fromObject(customerProjectResult);
            logger.info("=======getVisitCallList======result:{}", result);
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
        }
        return result.toString();
    }

    @RequestMapping(value = "/addcustomerstatus", method = RequestMethod.GET)
    public ModelAndView addCustomerStatus(
            HttpServletRequest request, String customerId, String customerProjectId, String customerProjectStatus
    ) {
        ModelAndView view = new ModelAndView();
        view.addObject("customerId", customerId);
        view.addObject("customerProjectId", customerProjectId);
        view.addObject("customerProjectStatus", customerProjectStatus);
        view.setViewName("wechat/project/add-status");
        JSONObject result = new JSONObject();
        try {
            List<NameValuePair> customerProjectParams = new ArrayList<>();
            customerProjectParams.add(new BasicNameValuePair("serviceCode", "Wechat"));
            customerProjectParams.add(new BasicNameValuePair("serviceName", "deleteAttachments"));
            customerProjectParams.add(new BasicNameValuePair("phone", getPhoneFromCookie(request)));
            String customerProjectResult = RestTemplateBean.doGet(hgsProp.getHgsUrl(), customerProjectParams);
            result = JSONObject.fromObject(customerProjectResult);
            logger.info("=======addCustomerStatusLog======result:{}", result);
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
        }
        return view;
    }

    @RequestMapping(value = "/addcustomerstatus", method = RequestMethod.POST, produces = "application/json;charset=utf-8")
    @ResponseBody
    public String addCustomerStatus(
            HttpServletRequest request, String userId, String customerId, String customerProjectId, String callContent, String occurTime,
            String customerStatus
    ) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
        occurTime = occurTime.replaceAll("T", " ");
        JSONObject result = new JSONObject();
        try {
            List<NameValuePair> customerProjectParams = new ArrayList<>();
            customerProjectParams.add(new BasicNameValuePair("serviceCode", "Wechat"));
            customerProjectParams.add(new BasicNameValuePair("serviceName", "addCustomerStatusLog"));
            customerProjectParams.add(new BasicNameValuePair("phone", getPhoneFromCookie(request)));
            customerProjectParams.add(new BasicNameValuePair("customerProjectId", customerProjectId));
            customerProjectParams.add(new BasicNameValuePair("customerId", customerId));
            customerProjectParams.add(new BasicNameValuePair("occurTime", occurTime));
            if (StringUtils.isNoneBlank(callContent)) {
                customerProjectParams.add(new BasicNameValuePair("callContent", callContent));
            }
            customerProjectParams.add(new BasicNameValuePair("customerStatus", customerStatus));
            String customerProjectResult = RestTemplateBean.doGet(hgsProp.getHgsUrl(), customerProjectParams);
            result = JSONObject.fromObject(customerProjectResult);
            logger.info("=======addCustomerStatusLog======result:{}", result);
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
        }
        return result.toString();
    }

    @RequestMapping(value = "/testupload", method = RequestMethod.GET)
    public ModelAndView testUpload(
            HttpServletRequest request, String customerId, String customerProjectId, String customerProjectStatus
    ) {
        ModelAndView view = new ModelAndView();
        view.addObject("customerId", customerId);
        view.addObject("customerProjectId", customerProjectId);
        view.addObject("customerProjectStatus", customerProjectStatus);
        view.setViewName("wechat/project/testUpload");
        JSONObject result = new JSONObject();
        try {
            List<NameValuePair> customerProjectParams = new ArrayList<>();
            customerProjectParams.add(new BasicNameValuePair("serviceCode", "Wechat"));
            customerProjectParams.add(new BasicNameValuePair("serviceName", "deleteAttachments"));
            customerProjectParams.add(new BasicNameValuePair("phone", getPhoneFromCookie(request)));
            String customerProjectResult = RestTemplateBean.doGet(hgsProp.getHgsUrl(), customerProjectParams);
            result = JSONObject.fromObject(customerProjectResult);
            logger.info("=======addCustomerStatusLog======result:{}", result);
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
        }
        return view;
    }

    /**
     * 功能描述: <br>
     * 保存附件
     *
     * @param request
     * @author chengjianfang
     * @version [v1.0.0, 2015年1月29日]
     * @since [产品/模块版本](可选)
     */
    @RequestMapping(value = "addSection", method = {RequestMethod.POST})
    @ResponseBody
    public String addSection(MultipartHttpServletRequest request) {
        List<BaseAttachment> attachments = new ArrayList<>();
        List<MultipartFile> files = request.getFiles("file[]");
        logger.debug("==addSelect==start=======");
        try {
            for (MultipartFile file : files) {
                logger.debug("==addSelect==fileName:{}==", file.getOriginalFilename());
                logger.debug("===>>fileType:{}>>===", file.getContentType());
                BaseAttachment attachment = new BaseAttachment();

                FileLocationAttribute fileLocationAttribute = new FileLocationAttribute(file);
                long fileSize = fileLocationAttribute.getSize();
                if (fileSize > MAX_SIZE_OF_UPLOAD_FILE) {
                    return "MAX_SIZE";
                }
                attachment.setName(file.getOriginalFilename());
                attachment.setResourceType("wechat");
                attachment.setSize(fileSize);
                attachment.setSuffix(fileLocationAttribute.getSuffix());
                String remotePath = fastDFSUtil.uploadFileByStream(file.getInputStream(), file.getOriginalFilename());
                attachment.setRemotePath(remotePath);

                attachments.add(attachment);
            }
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
        }
        JSONObject result = new JSONObject();
        result.put("status", true);
        result.put("images", attachments);
        String resultStr = result.toString();
        logger.debug("==addSelect==result:{}=======", resultStr);
        return resultStr;
    }

    @RequestMapping(value = "deldynamic", method = {RequestMethod.POST})
    @ResponseBody
    public String deldynamic(HttpServletRequest request, String dynamicId) {

        JSONObject result = new JSONObject();
        try {
            JSONObject dynamic = new JSONObject();
            dynamic.put("dynamicId", dynamicId);
            List<NameValuePair> params = new ArrayList<>();
            params.add(new BasicNameValuePair("serviceCode", "Wechat"));
            params.add(new BasicNameValuePair("serviceName", "deldynamic"));

            String customerProjectResult = RestTemplateBean.doPost(
                    RestTemplateBean.getUri(hgsProp.getHgsUrl(), params), dynamic);
            result = JSONObject.fromObject(customerProjectResult);
            if (result != null && result.containsKey("result")) {
                String flag = result.get("result").toString();
                return flag;
            }

        } catch (Exception e) {
            e.printStackTrace();
            logger.error(e.getMessage(), e);
        }
        return "";
    }


    /**
     * 保存项目动态表信息
     *
     * @param request
     * @return
     */
    @RequestMapping(value = "savedynamic", method = {RequestMethod.POST}, produces = "application/json;charset=utf-8")
    @ResponseBody
    public String savedynamic(HttpServletRequest request, String projectId, String createUserid, String createUsername, String dynamicId, String dynamicContent, String projectName) {

        JSONObject result = new JSONObject();
        try {
            JSONObject dynamic = new JSONObject();
            dynamic.put("projectId", projectId);
            dynamic.put("createUserid", createUserid);
            dynamic.put("createUsername", createUsername);
            dynamic.put("dynamicId", dynamicId);
            dynamic.put("dynamicContent", EmojiParser.parseToAliases(dynamicContent));

            dynamic.put("projectName", projectName);
            List<NameValuePair> params = new ArrayList<>();
            params.add(new BasicNameValuePair("serviceCode", "Wechat"));
            params.add(new BasicNameValuePair("serviceName", "savedynamic"));

            String customerProjectResult = RestTemplateBean.doPost(
                    RestTemplateBean.getUri(hgsProp.getHgsUrl(), params), dynamic);
            result = JSONObject.fromObject(customerProjectResult);
        } catch (Exception e) {
            e.printStackTrace();
            logger.error(e.getMessage(), e);
        }
        return result.toString();
    }

    /**
     * 支持多选图片上传
     *
     * @param request
     * @return
     */
    @RequestMapping(value = "adddynamicpic", method = {RequestMethod.POST})
    @ResponseBody
    public JSONObject addDynamicPic(HttpServletRequest request) {
        MultipartHttpServletRequest muRequest = (MultipartHttpServletRequest) request;
        List<BaseAttachment> attachments = new ArrayList<>();
        List<MultipartFile> files = muRequest.getFiles("file[]");
        logger.debug("==addSelect==start=======");
        try {
            for (MultipartFile file : files) {
                logger.debug("==addSelect==fileName:{}==", file.getOriginalFilename());
                logger.debug("===>>fileType:{}>>===", file.getContentType());
                BaseAttachment attachment = new BaseAttachment();

                FileLocationAttribute fileLocationAttribute = new FileLocationAttribute(file);
                long fileSize = fileLocationAttribute.getSize();
                attachment.setName(file.getOriginalFilename());
                attachment.setResourceType("wechatdynamic");
                attachment.setSize(fileSize);
                attachment.setSuffix(fileLocationAttribute.getSuffix());
                String remotePath = fastDFSUtil.uploadFileByStream(file.getInputStream(), file.getOriginalFilename());
                attachment.setRemotePath(remotePath);
                attachments.add(attachment);
            }
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
        }
        JSONObject result = new JSONObject();
//        result.put("status", true);
        result.put("data", attachments);
//        String resultStr = result.toString();
//        logger.debug("==addSelect==result:{}=======", resultStr);
        return result;
    }

    @RequestMapping(value = "/savePicInfo2Attachment", method = RequestMethod.POST, produces = "application/json;charset=utf-8")
    @ResponseBody
    public String savePicInfo2Attachment(
            HttpServletRequest request, String resourceType, String bizType, String name, String suffix, String dynamicId,
            String size, String remotePath
    ) {
        JSONObject result = new JSONObject();
        try {
            JSONObject attachment = new JSONObject();
            attachment.put("resourceId", dynamicId);
            attachment.put("resourceType", resourceType);
            attachment.put("bizType", bizType);
            attachment.put("name", name);
            attachment.put("suffix", suffix);
            attachment.put("size", size);
            attachment.put("remotePath", remotePath);
            List<NameValuePair> params = new ArrayList<>();
            params.add(new BasicNameValuePair("serviceCode", "Wechat"));
            params.add(new BasicNameValuePair("serviceName", "savePicInfo2Attachment"));

            String customerProjectResult = RestTemplateBean.doPost(
                    RestTemplateBean.getUri(hgsProp.getHgsUrl(), params), attachment);
            result = JSONObject.fromObject(customerProjectResult);
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
        }
        return result.toString();
    }


    @RequestMapping(value = "/addattachment", method = RequestMethod.POST, produces = "application/json;charset=utf-8")
    @ResponseBody
    public String addAttachment(
            HttpServletRequest request, String resourceType, String bizType, String name, String suffix,
            String size, String remotePath
    ) {
        JSONObject result = new JSONObject();
        try {
            JSONObject attachment = new JSONObject();
            attachment.put("resourceId", getPhoneFromCookie(request));
            attachment.put("resourceType", resourceType);
            attachment.put("bizType", bizType);
            attachment.put("name", name);
            attachment.put("suffix", suffix);
            attachment.put("size", size);
            attachment.put("remotePath", remotePath);
            List<NameValuePair> params = new ArrayList<>();
            params.add(new BasicNameValuePair("serviceCode", "Wechat"));
            params.add(new BasicNameValuePair("serviceName", "addBaseAttachment"));

            String customerProjectResult = RestTemplateBean.doPost(
                    RestTemplateBean.getUri(hgsProp.getHgsUrl(), params), attachment);
            result = JSONObject.fromObject(customerProjectResult);
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
        }
        return result.toString();
    }

    @RequestMapping(value = "/waitaddvisit", method = RequestMethod.GET)
    public ModelAndView waitaddvisit(String customerId, String buyIntention, String phone, HttpServletRequest request) {
        ModelAndView view = new ModelAndView();
        view.addObject("customerId", customerId);
        view.addObject("buyIntention", buyIntention);
        view.addObject("phone", phone);

        try {
            // 获取回访内容模板
            List<NameValuePair> params = new ArrayList<>();
            params.add(new BasicNameValuePair("serviceCode", "Wechat"));
            params.add(new BasicNameValuePair("serviceName", "getCustomerCallbackTemplateList"));
            params.add(new BasicNameValuePair("phone", getPhoneFromCookie(request)));
            String result = RestTemplateBean.doGet(hgsProp.getHgsUrl(), params);
            JSONObject data = JSONObject.fromObject(result).getJSONObject("data");
            if (data != null) {
                JSONArray list = data.getJSONArray("list");
                if (list != null) {
                    view.addObject("callbackTemplateList", list);
                }
            }
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
        }

        view.setViewName("wechat/project/waitaddvisit");
        return view;
    }

    @RequestMapping(value = "/waitaddvisit", method = RequestMethod.POST, produces = "application/json;charset=utf-8")
    @ResponseBody
    public String waitaddvisit(HttpServletRequest request, String customerId, String callContent) {
        JSONObject result = new JSONObject();
        try {
            List<NameValuePair> customerProjectParams = new ArrayList<>();
            customerProjectParams.add(new BasicNameValuePair("serviceCode", "Wechat"));
            customerProjectParams.add(new BasicNameValuePair("serviceName", "waitAddVisitCallContent"));
            customerProjectParams.add(new BasicNameValuePair("phone", getPhoneFromCookie(request)));
            customerProjectParams.add(new BasicNameValuePair("customerId", customerId));
            customerProjectParams.add(new BasicNameValuePair("callContent", callContent));

            String buyIntention = request.getParameter("buyIntention") == null ? "99" : request.getParameter(
                    "buyIntention");
            if (!Strings.isNullOrEmpty(buyIntention)) {
                customerProjectParams.add(new BasicNameValuePair("buyIntention", buyIntention));
            }

            String customerProjectResult = RestTemplateBean.doGet(hgsProp.getHgsUrl(), customerProjectParams);
            result = JSONObject.fromObject(customerProjectResult);
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
        }
        return result.toString();
    }

    @RequestMapping(value = "/addvisit", method = RequestMethod.GET)
    public ModelAndView addVisit(String customerId, String buyIntention, String phone, HttpServletRequest request) {
        ModelAndView view = new ModelAndView();
        view.addObject("customerId", customerId);
        view.addObject("buyIntention", buyIntention);
        view.addObject("phone", phone);

        try {
            // 获取回访内容模板
            List<NameValuePair> params = new ArrayList<>();
            params.add(new BasicNameValuePair("serviceCode", "Wechat"));
            params.add(new BasicNameValuePair("serviceName", "getCustomerCallbackTemplateList"));
            params.add(new BasicNameValuePair("phone", getPhoneFromCookie(request)));
            String result = RestTemplateBean.doGet(hgsProp.getHgsUrl(), params);
            JSONObject data = JSONObject.fromObject(result).getJSONObject("data");
            if (data != null) {
                JSONArray list = data.getJSONArray("list");
                if (list != null) {
                    view.addObject("callbackTemplateList", list);
                }
            }
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
        }

        view.setViewName("wechat/project/add-visit");
        return view;
    }

    @RequestMapping(value = "/addvisit", method = RequestMethod.POST, produces = "application/json;charset=utf-8")
    @ResponseBody
    public String addVisit(HttpServletRequest request, String customerId, String callContent) {
        JSONObject result = new JSONObject();
        try {
            List<NameValuePair> customerProjectParams = new ArrayList<>();
            customerProjectParams.add(new BasicNameValuePair("serviceCode", "Wechat"));
            customerProjectParams.add(new BasicNameValuePair("serviceName", "addVisitCallContent"));
            customerProjectParams.add(new BasicNameValuePair("phone", getPhoneFromCookie(request)));
            customerProjectParams.add(new BasicNameValuePair("customerId", customerId));
            customerProjectParams.add(new BasicNameValuePair("callContent", callContent));

            String buyIntention = request.getParameter("buyIntention") == null ? "99" : request.getParameter(
                    "buyIntention");
            if (!Strings.isNullOrEmpty(buyIntention)) {
                customerProjectParams.add(new BasicNameValuePair("buyIntention", buyIntention));
            }

            String customerProjectResult = RestTemplateBean.doGet(hgsProp.getHgsUrl(), customerProjectParams);
            result = JSONObject.fromObject(customerProjectResult);
            logger.info("=======addVisitCallContent======result:{}", result);
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
        }
        return result.toString();
    }

    @RequestMapping(value = "/reportcustomer", method = RequestMethod.GET)
    public ModelAndView reportCustomer(String customerProjectId) {
        ModelAndView view = new ModelAndView();
        view.setViewName("wechat/project/the-second");
        try {
            List<NameValuePair> customerProjectParams = new ArrayList<>();
            customerProjectParams.add(new BasicNameValuePair("serviceCode", "Wechat"));
            customerProjectParams.add(new BasicNameValuePair("serviceName", "getCustomerProject"));
            customerProjectParams.add(new BasicNameValuePair("customerProjectId", customerProjectId));
            String customerProjectResult = RestTemplateBean.doGet(hgsProp.getHgsUrl(), customerProjectParams);
            logger.info("=======getCustomerProject======result:{}", customerProjectResult);
            JSONObject customerProjectData = JSONObject.fromObject(customerProjectResult).getJSONObject("data");
            view.addObject("customer", customerProjectData.getJSONObject("entity"));
            view.addObject("statusProgress", customerProjectData.getJSONObject("entity").getJSONObject("statusProgress"));
            view.addObject("customerProject", customerProjectData.getJSONObject("entity").getJSONArray("cps").get(0));
            view.addObject("images", customerProjectData.getJSONArray("list"));

            String customerId = customerProjectData.getJSONObject("entity").getJSONArray("cps").getJSONObject(0).getString("customerId");
            String projectId = customerProjectData.getJSONObject("entity").getJSONArray("cps").getJSONObject(0).getString("projectId");
            // 获取状态变更记录
            String statusChangeLogs = getStatusChangeLogs(customerId, projectId);
            JSONArray statusChangeLogArray = JSONObject.fromObject(statusChangeLogs).getJSONObject("data").getJSONArray("list");
            view.addObject("statusChangeLogs", statusChangeLogArray);
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
        }
        return view;
    }

    @RequestMapping(value = "/reportcustomer", method = RequestMethod.POST, produces = "application/json;charset=utf-8")
    @ResponseBody
    public String reportCustomer(
            HttpServletRequest request, String customerId, String projectId, String consultantName,
            String consultantPhone, String recordedStatus, String loanStatus, String requireArea, String requireHouse,
            String requireHouseType, String requirePrice
    ) {
        JSONObject result = new JSONObject();
        try {
            JSONObject customerProject = new JSONObject();
            customerProject.put("customerId", customerId);
            customerProject.put("projectId", projectId);
//            customerProject.put("customerName", StringUtils.isBlank(customerName) ? "" : customerName);
            customerProject.put("consultantName", StringUtils.isBlank(consultantName) ? "" : consultantName);
            customerProject.put("consultantPhone", StringUtils.isBlank(consultantPhone) ? "" : consultantPhone);
            customerProject.put("recordedStatus", StringUtils.isBlank(recordedStatus) ? "99" : recordedStatus);
            customerProject.put("loanStatus", StringUtils.isBlank(loanStatus) ? "99" : loanStatus);
            customerProject.put("requireArea", StringUtils.isBlank(requireArea) ? "" : requireArea);
            customerProject.put("requireHouse", StringUtils.isBlank(requireHouse) ? "" : requireHouse);
            customerProject.put("requireHouseType", StringUtils.isBlank(requireHouseType) ? "" : requireHouseType);
            customerProject.put("requirePrice", StringUtils.isBlank(requirePrice) ? "" : requirePrice);
            List<NameValuePair> customerProjectParams = new ArrayList<>();
            customerProjectParams.add(new BasicNameValuePair("serviceCode", "Wechat"));
            customerProjectParams.add(new BasicNameValuePair("serviceName", "reportCustomer"));
            customerProjectParams.add(new BasicNameValuePair("phone", getPhoneFromCookie(request)));

            String customerProjectResult = RestTemplateBean.doPost(
                    RestTemplateBean.getUri(hgsProp.getHgsUrl(), customerProjectParams), customerProject);
            logger.info("=======reportCustomer======result:{}", customerProjectResult);
            result = JSONObject.fromObject(customerProjectResult);
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
        }
        return result.toString();
    }

    @RequestMapping(value = "/judgeCustomer", method = RequestMethod.GET)
    @ResponseBody
    public String judgeCustomer(String customerProjectId) {
        try {
            List<NameValuePair> customerProjectParams = new ArrayList<>();
            customerProjectParams.add(new BasicNameValuePair("serviceCode", "Wechat"));
            customerProjectParams.add(new BasicNameValuePair("serviceName", "getCustomerProject"));
            customerProjectParams.add(new BasicNameValuePair("customerProjectId", customerProjectId));
            String customerProjectResult = RestTemplateBean.doGet(hgsProp.getHgsUrl(), customerProjectParams);
            logger.info("=======judgeCustomer======result:{}", customerProjectResult);
            logger.info("=======judgeCustomer ==customerProjectId: ===  ", customerProjectId);
            System.out.println("customerProjectId======" + customerProjectId);
            ObjectMapper objectMapper = new ObjectMapper();
            Map<String, Object> result = objectMapper.readValue(customerProjectResult, Map.class);
            String code = result.get("result").toString();
            if ("0".equals(code)) {
                return "0";
            }

        } catch (Exception e) {
            e.printStackTrace();
            logger.error(e.getMessage(), e);
            return "0";
        }
        return "1";
    }

    @RequestMapping(value = "/toCustomerReport", method = RequestMethod.GET)
    public ModelAndView toCustomerReport() {
        ModelAndView view = new ModelAndView();
        view.setViewName("wechat/customerReport");
        return view;
    }

    @RequestMapping(value = "/customerReport", method = RequestMethod.POST)
    @ResponseBody
    public String customerReport(HttpServletRequest request, String name, String projectId, String projectName, String customerPhone, String content) {
        String message = "1";
        try {
            String phone = getPhoneFromCookie(request);
//            String phone = "15195854561";
            List<NameValuePair> customerProjectParams = new ArrayList<>();
            customerProjectParams.add(new BasicNameValuePair("serviceCode", "Wechat"));
            customerProjectParams.add(new BasicNameValuePair("serviceName", "customerReport"));
            customerProjectParams.add(new BasicNameValuePair("phone", phone.trim()));
            customerProjectParams.add(new BasicNameValuePair("name", name.trim()));
            customerProjectParams.add(new BasicNameValuePair("projectId", projectId.trim()));
            customerProjectParams.add(new BasicNameValuePair("projectName", projectName.trim()));
            customerProjectParams.add(new BasicNameValuePair("customerPhone", customerPhone.trim()));
            customerProjectParams.add(new BasicNameValuePair("content", content.trim()));

            String customerProjectResult = RestTemplateBean.doGet(hgsProp.getHgsUrl(), customerProjectParams);
            logger.info("=======customerReport======result:{}", customerProjectResult);
            System.out.println("projectId======" + projectId);
            ObjectMapper objectMapper = new ObjectMapper();
            Map<String, Object> data = objectMapper.readValue(customerProjectResult, Map.class);
            String code = data.get("result").toString();
            if ("0".equals(code)) {
                message = "4";
            }else if("101".equals(code)){
                message = "2";
            } else if("102".equals(code)){
                message = "3";
            }
        } catch (Exception e) {
            e.printStackTrace();
            logger.error(e.getMessage(), e);
            message = "4";
        }
        return message;
    }

    @RequestMapping(value = "/customerproject", method = RequestMethod.GET)
    public ModelAndView customerProject(String customerProjectId) {
        ModelAndView view = new ModelAndView();
        view.setViewName("wechat/project/customerProject");
        try {
            List<NameValuePair> customerProjectParams = new ArrayList<>();
            customerProjectParams.add(new BasicNameValuePair("serviceCode", "Wechat"));
            customerProjectParams.add(new BasicNameValuePair("serviceName", "getCustomerProject"));
            customerProjectParams.add(new BasicNameValuePair("customerProjectId", customerProjectId));
            String customerProjectResult = RestTemplateBean.doGet(hgsProp.getHgsUrl(), customerProjectParams);
            logger.info("=======getCustomerProject======result:{}", customerProjectResult);
            JSONObject customerProjectData = JSONObject.fromObject(customerProjectResult).getJSONObject("data");
            view.addObject("customer", customerProjectData.getJSONObject("entity"));
            view.addObject("customerProject", customerProjectData.getJSONObject("entity").getJSONArray("cps").get(0));
            view.addObject("images", customerProjectData.getJSONArray("list"));
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
        }
        return view;
    }

    @RequestMapping(value = "/modifytextarea", method = RequestMethod.GET)
    public ModelAndView modifyRemark(String customerProjectId, String key, String value) {
        ModelAndView view = new ModelAndView();
        view.addObject("customerProjectId", customerProjectId);
        view.addObject("key", key);
        String keyName = "";
        switch (key) {
            case "requireArea":
                keyName = "需求面积";
                break;
            case "requireHouse":
                keyName = "需求房号";
                break;
            case "requireHouseType":
                keyName = "意向房型";
                break;
            case "requirePrice":
                keyName = "总价预算";
                break;
            case "consultantName":
                keyName = "案场顾问";
                break;
            case "consultantPhone":
                keyName = "案场顾问电话";
                break;
            case "recordedStatus":
                keyName = "案场报备";
                break;
            case "loanStatus":
                keyName = "贷款状态";
                break;
            case "remark":
                keyName = "备注信息";
                break;
        }
        view.addObject("keyName", keyName);
        view.addObject("value", value);
        view.setViewName("wechat/project/modify-textarea");
        return view;
    }

    @RequestMapping(value = "/modifytextarea", method = RequestMethod.POST, produces = "application/json;charset=utf-8")
    @ResponseBody
    public String modifyRemark(
            HttpServletRequest request, String customerProjectId, String key, String value
    ) {
        String result = "";
        try {
            List<NameValuePair> params = new ArrayList<>();
            params.add(new BasicNameValuePair("serviceCode", "Wechat"));
            params.add(new BasicNameValuePair("serviceName", "modifyCustomerProject"));
            params.add(new BasicNameValuePair("phone", getPhoneFromCookie(request)));
            params.add(new BasicNameValuePair("customerProjectId", customerProjectId));
            params.add(new BasicNameValuePair("key", key));
            if (StringUtils.isBlank(value)) {
                value = "null";
            }
            params.add(new BasicNameValuePair("value", value));
            String uri = RestTemplateBean.getUri(hgsProp.getHgsUrl(), params);
            result = RestTemplateBean.doPost(uri, new JSONObject());
            logger.info("=======modifyCustomer======result:{}", result);
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
        }
        return result;
    }

    @RequestMapping("/statuschangelogs")
    public ModelAndView statusChangeLogs(
            String customerId, String projectId, String remark, String occurTime
    ) {
        ModelAndView view = new ModelAndView();
        view.addObject("customerId", customerId);
        view.addObject("projectId", projectId);
        view.addObject("remark", remark);
        view.addObject("occurTime", occurTime);
        view.setViewName("wechat/project/status-change-logs");
        return view;
    }

    @RequestMapping(value = "/getstatuschangelogs", method = RequestMethod.POST, produces = "application/json;charset=utf-8")
    @ResponseBody
    public String getStatusChangeLogs(String customerId, String projectId) {
        String result = "";
        try {
            List<NameValuePair> params = new ArrayList<>();
            params.add(new BasicNameValuePair("serviceCode", "Wechat"));
            params.add(new BasicNameValuePair("serviceName", "getCustomerStatusChangeLogs"));
            params.add(new BasicNameValuePair("customerId", customerId));
            params.add(new BasicNameValuePair("projectId", projectId));
            String uri = RestTemplateBean.getUri(hgsProp.getHgsUrl(), params);
            result = RestTemplateBean.doPost(uri, new JSONObject());
            logger.info("=======getCustomerStatusChangeLogs======result:{}", result);
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
        }
        return result;
    }

    @RequestMapping("/visitlogdetails")
    public ModelAndView visitLogDetails(String logId) {
        ModelAndView view = new ModelAndView();
        view.addObject("customerId", logId);
        view.setViewName("wechat/project/notice-details");
        JSONObject result = new JSONObject();
        try {
            List<NameValuePair> params = new ArrayList<>();
            params.add(new BasicNameValuePair("serviceCode", "Wechat"));
            params.add(new BasicNameValuePair("serviceName", "getVisitCallLog"));
            params.add(new BasicNameValuePair("logId", logId));
            String uri = RestTemplateBean.getUri(hgsProp.getHgsUrl(), params);
            String resultStr = RestTemplateBean.doPost(uri, new JSONObject());
            logger.info("=======getVisitCallLog======result:{}", resultStr);
            result = JSONObject.fromObject(resultStr);
            view.addObject("log", result.getJSONObject("data").getJSONObject("entity"));
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
        }
        return view;
    }

    @RequestMapping(value = "/changerecordedstatus", method = RequestMethod.POST, produces = "application/json;charset=utf-8")
    @ResponseBody
    public String changeRecordedStatus(HttpServletRequest request, String customerProjectId) {
        String result = "";
        try {
            List<NameValuePair> params = new ArrayList<>();
            params.add(new BasicNameValuePair("serviceCode", "Wechat"));
            params.add(new BasicNameValuePair("serviceName", "changeRecordedStatus"));
            params.add(new BasicNameValuePair("phone", getPhoneFromCookie(request)));
            params.add(new BasicNameValuePair("customerProjectId", customerProjectId));
            String uri = RestTemplateBean.getUri(hgsProp.getHgsUrl(), params);
            result = RestTemplateBean.doPost(uri, new JSONObject());
            logger.info("=======changeRecordedStatus======result:{}", result);
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
        }
        return result;
    }

    /**
     * 从cookie获取用户phone
     *
     * @param request
     * @return
     */
    private String getPhoneFromCookie(HttpServletRequest request) {
        String phone = "";
        Cookie[] cookies = request.getCookies();
        if (cookies == null) {
            logger.info("=====================cookie is null");
            return phone;
        }
        for (int i = 0; i < cookies.length; i++) {
            Cookie cookie = cookies[i];
            if (cookie.getName().equals("phone")) {
                phone = cookie.getValue();
            }
        }
//        return "15195854561";
        return phone;
    }
}
