fengxiang
2018-02-05 baaff76ba638ac37f5b1dcffb27ba9f5a9fff937
src/main/java/com/moral/controller/MapController.java
@@ -10,6 +10,8 @@
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;
@@ -29,6 +31,7 @@
@Controller
@RequestMapping("map")
public class MapController {
    public  final  static String REFRESH_TOKEN = "_refresh_token";
    public  static Logger log = Logger.getLogger(MapController.class);
    @Resource
    DeviceService deviceService;
@@ -41,17 +44,23 @@
    @Resource
    MonitorPointService monitorPointService;
    @RequestMapping(value = "/main-page", method = RequestMethod.GET)
    public String map(Model model,@RequestParam("areaCode")int code,@RequestParam("accountId")int accountId){
        Account account = accountService.getAccountById(accountId);
    @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&&regionName!=null){
            Object sensors = sensorService.queryAll();
            JSONObject params = new JSONObject();
            params.put("regionCode",code);
            params.put("regionName",regionName);
            params.put("accountId", accountId);
            params.put("orgId", account.getOrganizationId());
            //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);
@@ -60,17 +69,18 @@
            StringBuilder msg = new StringBuilder();
            msg.append(" param[0] areaCode:");
            msg.append(code);
            msg.append(" param[0] accountId:");
            msg.append(accountId);
            msg.append(" param[0] token:");
            msg.append(token);
            log.warn(msg);
            return "401";
        }
    }
    @RequestMapping(value="/get-monitorpoints",method = RequestMethod.GET)
    @RequestMapping(value="get-monitorpoints",method = RequestMethod.GET)
    @ResponseBody
    public ResultBean getMonitorpointList(@RequestParam("orgId")String orgId,MapBounds mapBounds){
    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);
@@ -81,11 +91,11 @@
    @RequestMapping(value = "get-devices-for-popup",method = RequestMethod.GET)
    @ResponseBody
    public PageResult getDevicesForPopup(
            @RequestParam("orgId")Integer orgId,
            JwtAuthenticationToken authenticationToken,
            String name,
            Integer pageSize,
            Integer pageNo
    ){
    ){  Integer orgId = authenticationToken.getPrincipal().getOrganizationId();
        return  deviceService.query(orgId,name,pageSize,pageNo);
    }
}