src/main/java/com/moral/controller/WebController.java
@@ -6,20 +6,16 @@
import com.moral.common.util.*;
import com.moral.common.webAnno.UserLoginToken;
import com.moral.entity.*;
import com.moral.mapper.MapPathMapper;
import com.moral.service.*;
import com.moral.util.DateUtil;
import com.moral.util.LatLngTransformation;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import jdk.nashorn.internal.runtime.logging.Logger;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.*;
import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
@@ -65,12 +61,17 @@
    SensorService sensorService;
    @Resource
    OrganizationSensorsService organizationSensorsService;
    @Resource
    MapPathService mapPathService;
    @UserLoginToken
    @GetMapping("test")
    public String add() {
        return "test success!";
    public ResultBean<List<WebProvince>> add(HttpServletRequest request) {
        String token =  request.getHeader("token");
        List<WebProvince> mapPath = mapPathService.getMapPath(token);
        if(ObjectUtils.isEmpty(mapPath))
            return new ResultBean<>("获取地图信息失败",ResultBean.FAIL);
        return new ResultBean<>(mapPath);
    }
    /**
@@ -87,7 +88,7 @@
            resultMap.put("msg", "用户名及密码不允许为空!");
            resultMap.put("accountId", -1);
        } else {
            resultMap = accountService.webLogin(parameters);
            resultMap = accountService.bsWebLogin(parameters);
            String accountId = String.valueOf(resultMap.get("accountId"));
            if (!accountId.equals("-1")) {
                redisHashUtil.deleteMapVal("webToken", accountId);
@@ -248,7 +249,7 @@
     */
    @GetMapping("fiveMinuteAvgData")
    public ResultBean<List<Map<String, Object>>> getSensorFiveMinuteAvgData(HttpServletRequest request) {
    public ResultBean<Map<String,Object>> getSensorFiveMinuteAvgData(HttpServletRequest request) {
        //获取参数,传感器和monitorpointId
        Map<String, Object> parameters = WebUtils.getParametersStartingWith(request, null);
        if ((!parameters.containsKey("sensorKey")) || (!parameters.containsKey("monitorPointId")))
@@ -280,12 +281,102 @@
            parameters.put("time", time);
            datas = historyFiveMinutelyService.getFiveMinutesDataByMacsAndTime(parameters);
        }
        datas = insertDeviceInfo(datas, devices);
        return new ResultBean<List<Map<String, Object>>>(datas);
        //根据monitorPointId获取国控站坐标
        List<Map<String,Object>> coordinate = new ArrayList<>();
        MonitorPoint monitorPoint = monitorPointService.queryMonitorPointById(monitorPointId);
        Integer orgId = monitorPoint.getOrganizationId();
        List<MonitorPoint> monitorPoints = monitorPointService.getMonitorPointsByOrganizationId(orgId);
        monitorPoints.forEach(value->{
            if("国控站".equals(value.getDescription())) {
                List list = LatLngTransformation.Convert_BD09_To_GCJ02(value.getLatitude(), value.getLongitude());
                Map<String,Object> controlStation = new HashMap<>();
                controlStation.put("name",value.getName());
                controlStation.put("longitude", list.get(0));
                controlStation.put("latitude", list.get(1));
                coordinate.add(controlStation);
            }
        });
        Map<String,Object> datasMap = new HashMap<>();
        datasMap.put("coordinate",coordinate);
        datasMap.put("device",datas);
        return new ResultBean<Map<String,Object>>(datasMap);
    }
    @GetMapping("cangzhouMIdGetAllDevice")
    public ResultBean<Map<String,Object>> cangzhouMIdGetAllDevice(HttpServletRequest request) {
        //获取参数,传感器和monitorpointId
        Map<String, Object> parameters = WebUtils.getParametersStartingWith(request, null);
        if ((!parameters.containsKey("sensorKey")) || (!parameters.containsKey("monitorPointId")))
            return ResultBean.fail("参数为null");
        String sensorKey = (String) parameters.get("sensorKey");
        Integer monitorPointId = Integer.parseInt((String) parameters.get("monitorPointId"));
        MonitorPoint mPoint = monitorPointService.queryMonitorPointById(monitorPointId);
        Integer code = mPoint.getCityCode();
        List<Device> devices = null;
        if (code == 130900){
             devices = deviceService.getDeviceByCode();
        }else {
             devices = deviceService.getDevicesByMonitorPointId(monitorPointId);
        }
        //根据monitorpointId获取该站点下所有设备mac集合
        if (ObjectUtils.isEmpty(devices))
            return ResultBean.fail("站点下无设备或monitorPointId错误");
        List<String> macs = new ArrayList<>();
        devices.forEach(p -> {
            macs.add(p.getMac());
        });
        //根据时间和mac号集合以及传感器参数查询五分钟平均数据
        Map<String, Object> timeAndYearMonth = getTimeAndYearMonthForFiveMinuteData();
        String time = (String) timeAndYearMonth.get("time");
        String yearAndMonth = (String) timeAndYearMonth.get("yearAndMonth");
        parameters.put("time", time);
        parameters.put("yearAndMonth", yearAndMonth);
        parameters.put("macs", macs);
        List<Map<String, Object>> datas = historyFiveMinutelyService.getFiveMinutesDataByMacsAndTime(parameters);
        //如果当前五分钟数据还没有插入,则提取前五分钟数据返回
        if (ObjectUtils.isEmpty(datas)) {
            time = getFiveMinuteAgoTime(time);
            parameters.put("time", time);
            datas = historyFiveMinutelyService.getFiveMinutesDataByMacsAndTime(parameters);
        }
        datas = insertDeviceInfo(datas, devices);
        //根据monitorPointId获取国控站坐标
        List<Map<String,Object>> coordinate = new ArrayList<>();
        MonitorPoint monitorPoint = monitorPointService.queryMonitorPointById(monitorPointId);
        Integer orgId = monitorPoint.getOrganizationId();
        List<MonitorPoint> monitorPoints = monitorPointService.getMonitorPointsByOrganizationId(orgId);
        monitorPoints.forEach(value->{
            if("国控站".equals(value.getDescription())) {
                List list = LatLngTransformation.Convert_BD09_To_GCJ02(value.getLatitude(), value.getLongitude());
                Map<String,Object> controlStation = new HashMap<>();
                controlStation.put("name",value.getName());
                controlStation.put("longitude", list.get(0));
                controlStation.put("latitude", list.get(1));
                coordinate.add(controlStation);
            }
        });
        Map<String,Object> datasMap = new HashMap<>();
        datasMap.put("coordinate",coordinate);
        datasMap.put("device",datas);
        return new ResultBean<Map<String,Object>>(datasMap);
    }
    /**
    * @Description: 根据mac号获取单台设备信息,特殊客户只显示客户需要的传感器信息
            * @Param: [request]
            * @return: com.moral.common.bean.ResultBean<java.util.Map<java.lang.String,java.lang.Object>>
            * @Author: 下雨听风
            * @Date: 2020/10/22
            */
    @GetMapping("fiveMinuteAvgDataByMac")
    public ResultBean<Map<String, Object>> fiveMinuteAvgDataByMac(HttpServletRequest request) {
        //获取参数,mac号
@@ -334,7 +425,7 @@
        });
        //添加设备名称
        Map<String, Object> sortDatas = new LinkedHashMap<>();
        Map<String, Object> sortDatas = new LinkedHashMap<>();//排序后的数据,用于发送前端
        Device device = deviceService.getDeviceByMac(mac, true);
        sortDatas.put("名称", device.getName());
@@ -355,6 +446,17 @@
        return new ResultBean<Map<String, Object>>(sortDatas);
    }
    @GetMapping("mapPath")
    public ResultBean<List<WebProvince>> mapPath(HttpServletRequest request) {
        String token =  request.getHeader("token");
        List<WebProvince> mapPath = mapPathService.getMapPath(token);
        if(ObjectUtils.isEmpty(mapPath))
            return new ResultBean<>("获取地图信息失败",ResultBean.FAIL);
        return new ResultBean<>(mapPath);
    }
    /**
     * @Description: 返回结果添加设备经纬度以及state
@@ -363,7 +465,7 @@
     * @Author: 下雨听风
     * @Date: 2020/10/19
     */
    public List<Map<String, Object>> insertDeviceInfo(List<Map<String, Object>> datas, List<Device> devices) {
    private List<Map<String, Object>> insertDeviceInfo(List<Map<String, Object>> datas, List<Device> devices) {
        Map<String, Device> map = new HashMap<>();
        devices.forEach(p -> {
            map.put(p.getMac(), p);
@@ -422,7 +524,7 @@
     * @Author: 下雨听风
     * @Date: 2020/10/20
     */
    public String getFiveMinuteAgoTime(String time) {
    private String getFiveMinuteAgoTime(String time) {
        try {
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            Date date = sdf.parse(time);