package com.customization.doReadItProxy.ProxyRequestFormService;

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.entity.requestForm.AutoApproveEntity;
import com.engine.workflow.service.RequestFormService;
import com.engine.workflow.service.impl.RequestFormServiceImpl;
import com.wbi.util.ParamUtil;
import lombok.extern.slf4j.Slf4j;
import weaver.conn.RecordSet;
import weaver.general.StringUtil;
import weaver.general.Util;
import weaver.workflow.request.RequestManager;

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

/**
 *
 */
@ServiceDynamicProxy(target = RequestFormServiceImpl.class, desc = "移动端小号拦截小红点")
@Slf4j
public class ProxyRequestFormServiceImpl extends AbstractServiceProxy implements RequestFormService {


    @Override
    @ServiceMethodDynamicProxy(desc="移动端小号拦截未读标记,OA系统流程")
    public Map<String, Object> updateReqInfo(HttpServletRequest httpServletRequest) {
        RecordSet rs = new RecordSet();
        String isOpen = rs.getPropValue("updateUnread", "isOpen");
        //为空默认不开启,1开启,0不开启
        try {
            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);
                //此id为小号//不请求已读接口
                if(loginidweaver.length() == 8 && "1".equals(paramMap.get("ismobile"))){
                    return new HashMap<>();
                }else {
                    return  (Map<String, Object>)executeMethod(httpServletRequest);
                }
            }
        }catch (Exception e){
            e.printStackTrace();
            log.error(e.getMessage());
            return (Map<String, Object>) executeMethod(httpServletRequest);
        }
        return new HashMap<>();
    }

    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> judgeCreateRight(HttpServletRequest httpServletRequest) {
        return null;
    }

    @Override
    public String loadForm(HttpServletRequest httpServletRequest) {
        return null;
    }

    @Override
    public String loadPreView(Map<String, Object> map) {
        return null;
    }

    @Override
    public Map<String, Object> loadDetailData(Map<String, Object> map) {
        return null;
    }

    @Override
    public Map<String, Object> saveDetailPaging(Map<String, Object> map) {
        return null;
    }

    @Override
    public Map<String, Object> copyCustomPageFile(String s) {
        return null;
    }



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

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

    @Override
    public Map<String, Object> getStatusData(Map<String, Object> map) {
        return null;
    }

    @Override
    public Map<String, Object> getStatusCount(Map<String, Object> map) {
        return null;
    }

    @Override
    public Map<String, Object> getResourcesKey(Map<String, Object> map) {
        return null;
    }

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

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

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

    @Override
    public Map<String, Object> getRejectOption(Map<String, Object> map) {
        return null;
    }

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

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

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

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

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

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

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

    @Override
    public Map<String, Object> getFileFieldObj(Map<String, Object> map) {
        return null;
    }

    @Override
    public Map<String, Object> createWfCode(Map<String, Object> map) {
        return null;
    }

    @Override
    public Map<String, Object> getWfCodeFieldValue(Map<String, Object> map) {
        return null;
    }

    @Override
    public Map<String, Object> requestImport(Map<String, Object> map) {
        return null;
    }

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

    @Override
    public Map<String, Object> chooseExceptionOperator(Map<String, Object> map) {
        return null;
    }

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

    @Override
    public Map<String, Object> getPrintLogBase(Map<String, Object> map) {
        return null;
    }

    @Override
    public Map<String, Object> getPrintLogData(Map<String, Object> map) {
        return null;
    }

    @Override
    public Map<String, Object> freeFlowRead(Map<String, Object> map) {
        return null;
    }

    @Override
    public Map<String, Object> freeFlowSave(Map<String, Object> map) {
        return null;
    }

    @Override
    public Map<String, Object> editLockOper(Map<String, Object> map) {
        return null;
    }

    @Override
    public Map<String, Object> loadPrintTemplates(Map<String, Object> map) {
        return null;
    }

    @Override
    public Map<String, Object> doEvalExpression(Map<String, Object> map) {
        return null;
    }

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

    @Override
    public Map<String, Object> getForwardDatas(Map<String, Object> map) {
        return null;
    }

    @Override
    public Map<String, Object> doBack(Map<String, Object> map) {
        return null;
    }

    @Override
    public Map<String, Object> getFormTab(Map<String, Object> map) {
        return null;
    }

    @Override
    public Map<String, Object> getSelectNextFlowCondition(Map<String, Object> map) {
        return null;
    }

    @Override
    public Map<String, Object> getSelectNextFlowNodes(Map<String, Object> map) {
        return null;
    }

    @Override
    public Map<String, Object> getRemindData(Map<String, Object> map) {
        return null;
    }

    @Override
    public Map<String, Object> judgeRequestIsValid(Map<String, Object> map) {
        return null;
    }

    @Override
    public Map<String, Object> takeBack(Map<String, Object> map) {
        return null;
    }

    @Override
    public Map<String, Object> getCustomOperation(Map<String, Object> map) {
        return null;
    }

    @Override
    public Map<String, Object> runCustomOperationAction(Map<String, Object> map) {
        return null;
    }

    @Override
    public Map<String, Object> JudgeAutoApprove(AutoApproveEntity autoApproveEntity) {
        return null;
    }

    @Override
    public Map<String, Object> delApproveLog(AutoApproveEntity autoApproveEntity) {
        return null;
    }

    @Override
    public Map<String, Object> verifyRequestForView(Map<String, Object> map) {
        return null;
    }

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

    @Override
    public Map<String, Object> importFieldLinkageCfg(Map<String, Object> map) {
        return null;
    }

    @Override
    public Map<String, Object> importFormulaCfg(Map<String, Object> map) {
        return null;
    }

    @Override
    public Map<String, Object> getDetailDataKeyId(Map<String, Object> map) {
        return null;
    }

    @Override
    public Map<String, Object> judgeWorkflowPenetrate(AutoApproveEntity autoApproveEntity, RequestManager requestManager) {
        return null;
    }

    @Override
    public Map<String, Object> getThPreviewUrl(Map<String, Object> map) {
        return null;
    }

    @Override
    public Map<String, Object> getThMouldList(Map<String, Object> map) {
        return null;
    }

    @Override
    public Map<String, Object> getDetailExpSet(Map<String, Object> map) {
        return null;
    }

    @Override
    public Map<String, Object> saveDetailExpSet(Map<String, Object> map) {
        return null;
    }

    @Override
    public Map<String, Object> exportFieldSet(Map<String, Object> map) {
        return null;
    }

    @Override
    public Map<String, Object> getNextNodeContent(Map<String, Object> map) {
        return null;
    }

    @Override
    public Map<String, Object> delRequestVerify(Map<String, Object> map) {
        return null;
    }

    @Override
    public Map<String, Object> getFreeNodeBrowserItem(Map<String, Object> map) {
        return null;
    }

    @Override
    public Map<String, Object> saveFreeNodeFormConfig(Map<String, Object> map) {
        return null;
    }

    @Override
    public Map<String, Object> conformCheck(Map<String, Object> map) {
        return null;
    }

    @Override
    public Map<String, Object> getDetailByRequestId(Map<String, Object> map) {
        return null;
    }
}
