package com.customization.wps.doc.impl;


import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.wbi.util.ParamUtil;
import com.wbi.util.StringUtil;
import com.weaverboot.frame.ioc.anno.classAnno.WeaIocReplaceComponent;
import com.weaverboot.frame.ioc.anno.methodAnno.WeaReplaceAfter;
import com.weaverboot.frame.ioc.handler.replace.weaReplaceParam.impl.WeaAfterReplaceParam;
import weaver.general.BaseBean;
import weaver.general.Util;
import weaver.hrm.HrmUserVarify;
import weaver.hrm.User;

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

@WeaIocReplaceComponent
public class FileInfoAvatarProxy {
    @WeaReplaceAfter(
            value = "/api/wps/doccenter/outter/v1/3rd/file/info",
            order = 1,
            description = "修改头像"
    )
    public String after(WeaAfterReplaceParam weaAfterReplaceParam) {
        HttpServletRequest request = weaAfterReplaceParam.getRequest();
        HttpServletResponse response = weaAfterReplaceParam.getResponse();
        String data = weaAfterReplaceParam.getData();
        Map paramMap = ParamUtil.request2Map(request);
        // User user = HrmUserVarify.getUser(request, response);
        BaseBean baseBean = new BaseBean();
        baseBean.writeLog(paramMap);
        baseBean.writeLog(data);
        JSONObject result = JSON.parseObject(data);
        if (result.containsKey("user")){
            Map<String, String>  user = JSONObject.parseObject(result.getString("user"), Map.class);
            user.put("avatar_url","http://14.1.209.146:8080/mobilemode/piclibrary/02-E9_017afd/addressbook.png");
            result.put("user",user);
            baseBean.writeLog(JSONObject.toJSONString(result));
            return JSONObject.toJSONString(result);
        }
        return data;
    }
}
