Search in sources :

Example 96 with ServletRequestAttributes

use of org.springframework.web.context.request.ServletRequestAttributes in project summer by foxsugar.

the class TodayChargeAction method showCost.

@AuthChecker
@RequestMapping("/dCost")
public AgentResponse showCost(String start, String end) {
    // 转化为标准字符串
    logger.info("dCost==========start:{},end:{}", start, end);
    start = DateUtil.becomeStandardSTime(start);
    end = DateUtil.becomeStandardSTime(end);
    logger.info("dCost==========start:{},end:{}", start, end);
    ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
    HttpServletRequest request = attributes.getRequest();
    long agentId = AgentUtil.getAgentByRequest(request);
    List<String> list = DateUtil.getDateListIn(end, start);
    AgentBean agentBean = RedisManager.getAgentRedisService().getAgentBean(agentId);
    AgentInfo agentInfo = agentBean.getAgentInfo();
    List<DChildCostVo> li = new ArrayList<>();
    double oneLevel = 0d;
    double twoLevel = 0d;
    double threeLevel = 0d;
    for (String dateStr : list) {
        ChildCost childCost = agentInfo.getEveryDayCost().get(dateStr);
        DChildCostVo dChildCostVo = new DChildCostVo();
        if (childCost != null) {
            BeanUtils.copyProperties(childCost, dChildCostVo);
        }
        dChildCostVo.setDateStr(dateStr);
        li.add(dChildCostVo);
        oneLevel += dChildCostVo.getFirstLevel();
        twoLevel += dChildCostVo.getSecondLevel();
        threeLevel += dChildCostVo.getThirdLevel();
    }
    // double total = oneLevel * 0.2 * 0.01 + twoLevel * 0.1 * 0.01 + threeLevel *0.1 * 0.01;
    double total = (oneLevel + twoLevel + threeLevel) * 0.01;
    Map<String, Object> result = new HashMap<>();
    result.put("li", li);
    result.put("total", total);
    // result.put("oneLevel", oneLevel * 0.2 * 0.01);
    // result.put("twoLevel", twoLevel * 0.1 * 0.01);
    // result.put("threeLevel", threeLevel *0.1 * 0.01);
    result.put("oneLevel", oneLevel * 0.01);
    result.put("twoLevel", twoLevel * 0.01);
    result.put("threeLevel", threeLevel * 0.01);
    result.put("start", list.get(list.size() - 1));
    result.put("end", list.get(0));
    double income = oneLevel * 0.2 * 0.01 + twoLevel * 0.1 * 0.01 + threeLevel * 0.1 * 0.01;
    result.put("income", income);
    AgentResponse agentResponse = new AgentResponse(200, result);
    return agentResponse;
}
Also used : ServletRequestAttributes(org.springframework.web.context.request.ServletRequestAttributes) HttpServletRequest(javax.servlet.http.HttpServletRequest) AgentBean(com.code.server.constant.game.AgentBean) ChildCost(com.code.server.constant.db.ChildCost) AgentInfo(com.code.server.constant.db.AgentInfo) AuthChecker(com.code.server.login.anotation.AuthChecker) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 97 with ServletRequestAttributes

use of org.springframework.web.context.request.ServletRequestAttributes in project weixin-java-mp-demo-springboot by binarywang.

the class WxMenuController method menuCreateSample.

@GetMapping("/create")
public String menuCreateSample(@PathVariable String appid) throws WxErrorException, MalformedURLException {
    WxMenu menu = new WxMenu();
    WxMenuButton button1 = new WxMenuButton();
    button1.setType(MenuButtonType.CLICK);
    button1.setName("今日歌曲");
    button1.setKey("V1001_TODAY_MUSIC");
    // WxMenuButton button2 = new WxMenuButton();
    // button2.setType(WxConsts.BUTTON_MINIPROGRAM);
    // button2.setName("小程序");
    // button2.setAppId("wx286b93c14bbf93aa");
    // button2.setPagePath("pages/lunar/index.html");
    // button2.setUrl("http://mp.weixin.qq.com");
    WxMenuButton button3 = new WxMenuButton();
    button3.setName("菜单");
    menu.getButtons().add(button1);
    // menu.getButtons().add(button2);
    menu.getButtons().add(button3);
    WxMenuButton button31 = new WxMenuButton();
    button31.setType(MenuButtonType.VIEW);
    button31.setName("搜索");
    button31.setUrl("http://www.soso.com/");
    WxMenuButton button32 = new WxMenuButton();
    button32.setType(MenuButtonType.VIEW);
    button32.setName("视频");
    button32.setUrl("http://v.qq.com/");
    WxMenuButton button33 = new WxMenuButton();
    button33.setType(MenuButtonType.CLICK);
    button33.setName("赞一下我们");
    button33.setKey("V1001_GOOD");
    WxMenuButton button34 = new WxMenuButton();
    button34.setType(MenuButtonType.VIEW);
    button34.setName("获取用户信息");
    ServletRequestAttributes servletRequestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
    if (servletRequestAttributes != null) {
        HttpServletRequest request = servletRequestAttributes.getRequest();
        URL requestURL = new URL(request.getRequestURL().toString());
        String url = this.wxService.switchoverTo(appid).getOAuth2Service().buildAuthorizationUrl(String.format("%s://%s/wx/redirect/%s/greet", requestURL.getProtocol(), requestURL.getHost(), appid), WxConsts.OAuth2Scope.SNSAPI_USERINFO, null);
        button34.setUrl(url);
    }
    button3.getSubButtons().add(button31);
    button3.getSubButtons().add(button32);
    button3.getSubButtons().add(button33);
    button3.getSubButtons().add(button34);
    this.wxService.switchover(appid);
    return this.wxService.getMenuService().menuCreate(menu);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) WxMenu(me.chanjar.weixin.common.bean.menu.WxMenu) ServletRequestAttributes(org.springframework.web.context.request.ServletRequestAttributes) WxMenuButton(me.chanjar.weixin.common.bean.menu.WxMenuButton) URL(java.net.URL)

Example 98 with ServletRequestAttributes

use of org.springframework.web.context.request.ServletRequestAttributes in project dq-easy-cloud by dq-open-cloud.

the class EcLogBO method buildRequestPath.

/**
 * <p>
 * 构建请求路径
 * </p>
 *
 * @return
 * @author daiqi 创建时间 2018年2月9日 下午4:46:14
 */
private EcLogBO buildRequestPath() {
    RequestAttributes ra = RequestContextHolder.getRequestAttributes();
    ServletRequestAttributes sra = (ServletRequestAttributes) ra;
    if (EcBaseUtils.isNull(sra)) {
        return this;
    }
    HttpServletRequest request = sra.getRequest();
    String requestPath = request.getServletPath().toString();
    if (EcStringUtils.isEmpty(requestPath)) {
        requestPath = request.getPathInfo();
    }
    if (EcStringUtils.isEmpty(requestPath)) {
        requestPath = request.getRequestURI();
    }
    return buildRequestPath(requestPath);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) ServletRequestAttributes(org.springframework.web.context.request.ServletRequestAttributes) ServletRequestAttributes(org.springframework.web.context.request.ServletRequestAttributes) RequestAttributes(org.springframework.web.context.request.RequestAttributes)

Example 99 with ServletRequestAttributes

use of org.springframework.web.context.request.ServletRequestAttributes in project Saturn by vipshop.

the class TestAspectClass method prepareRequest.

private void prepareRequest(String ip, String uri, String username) {
    given(request.getHeader("X-FORWARDED-FOR")).willReturn(ip);
    given(request.getRequestURI()).willReturn(uri);
    given(httpSession.getAttribute(SessionAttributeKeys.LOGIN_USER_NAME)).willReturn(username);
    given(request.getSession()).willReturn(httpSession);
    ServletRequestAttributes servletRequestAttributes = new ServletRequestAttributes(request);
    RequestContextHolder.setRequestAttributes(servletRequestAttributes);
}
Also used : ServletRequestAttributes(org.springframework.web.context.request.ServletRequestAttributes)

Example 100 with ServletRequestAttributes

use of org.springframework.web.context.request.ServletRequestAttributes in project ranger by apache.

the class BaseTest method startRequest.

/*
	 * Create New MockHttpServletRequest
	 */
protected MockHttpServletRequest startRequest() {
    request = new MockHttpServletRequest();
    request.setSession(session);
    RequestContextHolder.setRequestAttributes(new ServletRequestAttributes(request));
    return request;
}
Also used : MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) ServletRequestAttributes(org.springframework.web.context.request.ServletRequestAttributes)

Aggregations

ServletRequestAttributes (org.springframework.web.context.request.ServletRequestAttributes)204 HttpServletRequest (javax.servlet.http.HttpServletRequest)92 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)62 RequestAttributes (org.springframework.web.context.request.RequestAttributes)50 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)32 Test (org.junit.jupiter.api.Test)28 lombok.val (lombok.val)25 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)22 Test (org.junit.Test)18 AuthChecker (com.code.server.login.anotation.AuthChecker)17 HttpSession (javax.servlet.http.HttpSession)12 Before (org.junit.Before)12 HashMap (java.util.HashMap)11 Method (java.lang.reflect.Method)8 Date (java.util.Date)7 AbstractTracingSpan (org.apache.skywalking.apm.agent.core.context.trace.AbstractTracingSpan)7 TraceSegment (org.apache.skywalking.apm.agent.core.context.trace.TraceSegment)7 HttpServletRequest (jakarta.servlet.http.HttpServletRequest)6 Map (java.util.Map)6 BeforeEach (org.junit.jupiter.api.BeforeEach)6