From baaff76ba638ac37f5b1dcffb27ba9f5a9fff937 Mon Sep 17 00:00:00 2001 From: fengxiang <110431245@qq.com> Date: Mon, 05 Feb 2018 13:30:16 +0800 Subject: [PATCH] token放在get请求参数中 --- src/main/java/com/moral/controller/MapController.java | 91 ++++++++++++++++++++++++++++++++++++++++++--- 1 files changed, 84 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/moral/controller/MapController.java b/src/main/java/com/moral/controller/MapController.java index 1bc9ade..9d0f0a8 100644 --- a/src/main/java/com/moral/controller/MapController.java +++ b/src/main/java/com/moral/controller/MapController.java @@ -2,12 +2,27 @@ import com.alibaba.fastjson.JSONObject; +import com.moral.common.bean.Constants; +import com.moral.common.bean.PageBean; +import com.moral.common.bean.PageResult; +import com.moral.common.bean.ResultBean; +import com.moral.entity.Account; +import com.moral.entity.Device; +import com.moral.entity.MapBounds; +import com.moral.entity.MonitorPoint; +import com.moral.security.auth.JwtAuthenticationToken; +import com.moral.security.config.WebSecurityConfig; +import com.moral.service.*; +import lombok.extern.log4j.Log4j; +import org.apache.log4j.Logger; import org.springframework.stereotype.Controller; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestMethod; -import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.ui.Model; +import org.springframework.web.bind.annotation.*; import org.springframework.web.servlet.ModelAndView; +import javax.annotation.Resource; +import java.util.HashMap; +import java.util.List; import java.util.Map; /** @@ -16,9 +31,71 @@ @Controller @RequestMapping("map") public class MapController { - @RequestMapping(value = "/main-page", method = RequestMethod.GET) - public String map(){ - ModelAndView mv = new ModelAndView("map"); - return "map"; + public final static String REFRESH_TOKEN = "_refresh_token"; + public static Logger log = Logger.getLogger(MapController.class); + @Resource + DeviceService deviceService; + @Resource + AreaService areaService; + @Resource + AccountService accountService; + @Resource + SensorService sensorService; + @Resource + MonitorPointService monitorPointService; + + @RequestMapping(value = "/screen-main", method = RequestMethod.GET) + public String map(Model model, + @RequestParam("areaCode")int code, + @RequestParam(WebSecurityConfig.AUTHENTICATION_PARAM_NAME)String token, + @RequestParam(REFRESH_TOKEN)String refreshToke, + JwtAuthenticationToken authenticationToken){ + String accountName = authenticationToken.getPrincipal().getUsername(); + Account account = accountService.getAccountByAccountName(accountName); + String regionName = areaService.selectFullNameByCode(code); + if(account!=null&®ionName!=null){ + Object sensors = sensorService.queryAll(); + JSONObject params = new JSONObject(); + params.put("regionCode",code); + params.put("regionName",regionName); + //token ������������ + params.put(WebSecurityConfig.AUTHENTICATION_PARAM_NAME, token); + params.put(REFRESH_TOKEN,refreshToke); + params.put("sensors", sensors); + String paramsJson = params.toJSONString(); + model.addAttribute("mapParams",paramsJson); + return "map"; + } else { + StringBuilder msg = new StringBuilder(); + msg.append(" param[0] areaCode:"); + msg.append(code); + msg.append(" param[0] token:"); + msg.append(token); + log.warn(msg); + return "401"; + } + } + @RequestMapping(value="get-monitorpoints",method = RequestMethod.GET) + @ResponseBody + public ResultBean getMonitorpointList(JwtAuthenticationToken authenticationToken,MapBounds mapBounds){ + ResultBean< List<MonitorPoint>> resultBean = new ResultBean(); + Map<String,Object> paramMap = new HashMap<String, Object>(); + Integer orgId = authenticationToken.getPrincipal().getOrganizationId(); + paramMap.put("orgId", orgId); + paramMap.put("mapBounds",mapBounds); + List<MonitorPoint> list = monitorPointService.queryWithStateByMap(paramMap); + resultBean.setData(list); + resultBean.setCode(ResultBean.SUCCESS); + return resultBean; + } + @RequestMapping(value = "get-devices-for-popup",method = RequestMethod.GET) + @ResponseBody + public PageResult getDevicesForPopup( + JwtAuthenticationToken authenticationToken, + String name, + Integer pageSize, + Integer pageNo + ){ Integer orgId = authenticationToken.getPrincipal().getOrganizationId(); + return deviceService.query(orgId,name,pageSize,pageNo); } } -- Gitblit v1.8.0