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;
}
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);
}
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);
}
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);
}
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;
}
Aggregations