package com.customization.customWf.impl;

import com.engine.core.cfg.annotation.CommandDynamicProxy;
import com.engine.core.interceptor.AbstractCommandProxy;
import com.engine.core.interceptor.Command;
import com.engine.workflow.cmd.requestForm.UpdateReqInfoCmd;
import com.wbi.util.ParamUtil;
import com.weaverboot.frame.ioc.anno.classAnno.WeaIocReplaceComponent;
import com.weaverboot.frame.ioc.anno.methodAnno.WeaReplaceBefore;
import com.weaverboot.frame.ioc.handler.replace.weaReplaceParam.impl.WeaBeforeReplaceParam;
import lombok.extern.slf4j.Slf4j;
import weaver.hrm.HrmUserVarify;
import weaver.hrm.User;

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


@WeaIocReplaceComponent
@Slf4j
public class UpdateReqInfoApiProxy {

    @WeaReplaceBefore(
            value = "/api/workflow/reqform/updateReqInfo",
            order = 1,
            description = "qwer"
    )
    public void before(WeaBeforeReplaceParam weaBeforeReplaceParam) {

        HttpServletRequest request = weaBeforeReplaceParam.getRequest();
        HttpServletResponse response = weaBeforeReplaceParam.getResponse();
        // Map paramMap = ParamUtil.request2Map(request);
        User user = HrmUserVarify.getUser(request, response);
        Map paramMap = weaBeforeReplaceParam.getParamMap();
        Object requestid = paramMap.get("requestid");
        paramMap.put("requestid","123123");

    }

    private String getCookie(HttpServletRequest request,String name){
        Cookie[] cookies = request.getCookies();
        if (cookies != null) {
            for (Cookie cookie : cookies) {
                if(name.equals(cookie.getName())){
                    return cookie.getValue();
                }
            }
        }
        return "";
    }
}
