package com.customization.doReadItProxy.proxyRequestListService;


import com.engine.core.cfg.annotation.ServiceDynamicProxy;
import com.engine.core.cfg.annotation.ServiceMethodDynamicProxy;
import com.engine.core.impl.aop.AbstractServiceProxy;
import com.engine.workflow.service.RequestListService;
import com.engine.workflow.service.impl.RequestListServiceImpl;
import com.wbi.util.ParamUtil;
import lombok.extern.slf4j.Slf4j;
import weaver.conn.RecordSet;
import weaver.general.StringUtil;
import weaver.general.Util;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

@ServiceDynamicProxy(target = RequestListServiceImpl.class, desc = "移动端小号拦截小红点")
@Slf4j
public class ProxyRequestListServiceImpl extends AbstractServiceProxy implements RequestListService {


    @Override
    @ServiceMethodDynamicProxy(desc="移动端小号拦截未读标记,异构系统待办")
    public Map<String, Object> doReadIt(HttpServletRequest httpServletRequest) {
        RecordSet rs = new RecordSet();
        String isOpen = rs.getPropValue("updateUnread", "isOpen");
        if (StringUtil.isEmpty(isOpen) || "0".equals(isOpen)){
            return (Map<String, Object>)executeMethod(httpServletRequest);
        }else if ("1".equals(isOpen)) {
            String loginidweaver = getCookie(httpServletRequest, "loginidweaver");
            log.info("loginidweaver==>{}",loginidweaver);
            Map paramMap = ParamUtil.request2Map(httpServletRequest);
            log.info("paramMap==>{}",paramMap);
            String ua = Util.null2String(paramMap.get("request_header_user_agent"));
            //此id为小号//不请求已读接口
            if(loginidweaver.length() == 8 && ua.contains("E-Mobile7")){
                return new HashMap<String, Object>();
            }else {
                return (Map<String, Object>)executeMethod(httpServletRequest);
            }
        }
        return new HashMap<String, Object>();
    }

    private String getCookie(HttpServletRequest request,String name){
        try {
            Cookie[] cookies = request.getCookies();
            if (cookies != null) {
                for (Cookie cookie : cookies) {
                    if(name.equals(cookie.getName())){
                        return Util.null2String(cookie.getValue());
                    }
                }
            }
        }catch (Exception e){
            log.error("getCookieError:{}",e.getMessage());
            e.printStackTrace();
        }
        return "";
    }


    @Override
    public Map<String, Object> doingBaseInfo(HttpServletRequest httpServletRequest) {
        return null;
    }

    @Override
    public Map<String, Object> doingCountInfo(HttpServletRequest httpServletRequest) {
        return null;
    }

    @Override
    public Map<String, Object> doneBaseInfo(HttpServletRequest httpServletRequest) {
        return null;
    }

    @Override
    public Map<String, Object> doneCountInfo(HttpServletRequest httpServletRequest) {
        return null;
    }

    @Override
    public Map<String, Object> mineBaseInfo(HttpServletRequest httpServletRequest) {
        return null;
    }

    @Override
    public Map<String, Object> mineCountInfo(HttpServletRequest httpServletRequest) {
        return null;
    }

    @Override
    public Map<String, Object> splitPageKey(HttpServletRequest httpServletRequest) {
        return null;
    }

    @Override
    public Map<String, Object> getDoingNewCount(HttpServletRequest httpServletRequest) {
        return null;
    }



    @Override
    public Map<String, Object> doSaveData(HttpServletRequest httpServletRequest) {
        return null;
    }

    @Override
    public Map<String, Object> getDefaultList(HttpServletRequest httpServletRequest) {
        return null;
    }

    @Override
    public Map<String, Object> getUnoperators(HttpServletRequest httpServletRequest) {
        return null;
    }

    @Override
    public Map<String, Object> getWfListParams(HttpServletRequest httpServletRequest) {
        return null;
    }

    @Override
    public Map<String, Object> getHendledReqIds(HttpServletRequest httpServletRequest) {
        return null;
    }

    @Override
    public Map<String, Object> continnuationProcessInfo(HttpServletRequest httpServletRequest) {
        return null;
    }

    @Override
    public Map<String, Object> judgeReloadList(HttpServletRequest httpServletRequest) {
        return null;
    }
}
