jinpengyong
2021-08-23 3bc57d8582d3d13e7e653b0f04dd09742c3b2c15
走航车轨迹数据单因子-》所有因子
5 files modified
55 ■■■■ changed files
screen-api/src/main/java/com/moral/api/controller/SpecialDeviceController.java 6 ●●●● patch | view | raw | blame | history
screen-api/src/main/java/com/moral/api/entity/SpecialDevice.java 7 ●●●●● patch | view | raw | blame | history
screen-api/src/main/java/com/moral/api/service/impl/SpecialDeviceServiceImpl.java 33 ●●●● patch | view | raw | blame | history
screen-api/src/main/resources/mapper/HistorySecondSpecialMapper.xml 8 ●●●● patch | view | raw | blame | history
screen-manage/src/main/java/com/moral/api/service/impl/HistorySecondSpecialServiceImpl.java 1 ●●●● patch | view | raw | blame | history
screen-api/src/main/java/com/moral/api/controller/SpecialDeviceController.java
@@ -6,6 +6,7 @@
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
@@ -40,16 +41,15 @@
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "token", value = "token", required = true, paramType = "header", dataType = "String"),
            @ApiImplicitParam(name = "mac", value = "设备mac", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "sensorCode", value = "传感器code", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "time", value = "时间,2021-08-18", required = true, paramType = "query", dataType = "String")
    })
    public ResultMessage carTrajectory(HttpServletRequest request) {
        Map<String, Object> params = WebUtils.getParametersStartingWith(request, null);
        if (!params.containsKey("mac") || !params.containsKey("sensorCode") || !params.containsKey("time")) {
        if (!params.containsKey("mac") || !params.containsKey("time")) {
            return ResultMessage.fail(ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode(), ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg());
        }
        List<Map<String, Object>> response = specialDeviceService.carTrajectory(params);
        return ResultMessage.ok(response);
        return ObjectUtils.isEmpty(response) ? ResultMessage.ok() : ResultMessage.ok(response);
    }
}
screen-api/src/main/java/com/moral/api/entity/SpecialDevice.java
@@ -1,6 +1,7 @@
package com.moral.api.entity;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.extension.activerecord.Model;
import com.baomidou.mybatisplus.annotation.TableId;
import java.io.Serializable;
@@ -74,6 +75,12 @@
     */
    private String isDelete;
    /*
     * 设备型号
     * */
    @TableField(exist = false)
    private Version version;
    @Override
    protected Serializable pkVal() {
screen-api/src/main/java/com/moral/api/service/impl/SpecialDeviceServiceImpl.java
@@ -14,16 +14,21 @@
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.moral.api.service.SysDictDataService;
import com.moral.constant.Constants;
import com.moral.constant.RedisConstants;
import com.moral.util.DateUtils;
import com.moral.util.GeodesyUtils;
import com.moral.util.TokenUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
 * <p>
@@ -45,6 +50,9 @@
    @Autowired
    private SysDictDataService sysDictDataService;
    @Autowired
    private RedisTemplate redisTemplate;
    private final static Double dis = 50d;
    @Override
@@ -60,14 +68,29 @@
        String sensorUnit = sysDictDataService.getOne(sysDictDataQueryWrapper).getDataValue();
        params.put("sensorUnit", sensorUnit);*/
        Map<String, Object> userInfo = (Map<String, Object>) TokenUtils.getUserInfo();
        Map<String, Object> orgInfo = (Map<String, Object>) userInfo.get("organization");
        Integer orgId = (Integer) orgInfo.get("id");
        params.put("orgId", orgId);
        //从秒数据表获取走航车数据
        List<Map<String, Object>> data = historySecondSpecialMapper.getSpecialDeviceData(params);
        if (ObjectUtils.isEmpty(data)) {
            return data;
        }
        data.removeIf(o -> {
            //经度
            double lng = Double.parseDouble(o.get(Constants.SENSOR_CODE_LON).toString());
            //纬度
            double lat = Double.parseDouble(o.get(Constants.SENSOR_CODE_LAT).toString());
            return lng < 70 || lng > 150 || lat > 60 || lat < 20;
            Map<String, Object> value = JSONObject.parseObject(o.remove("value").toString(), Map.class);
            Object flylon = value.get("flylon");
            Object flylat = value.get("flylat");
            if (ObjectUtils.isEmpty(flylon) || ObjectUtils.isEmpty(flylat)) {
                return true;
            }
            double lon = Double.parseDouble(flylon.toString());
            double lat = Double.parseDouble(flylat.toString());
            if (lon < 70 || lon > 150 || lat < 20 || lat > 60) {
                return true;
            }
            o.putAll(value);
            return false;
        });
        return filterData(data);
    }
screen-api/src/main/resources/mapper/HistorySecondSpecialMapper.xml
@@ -12,13 +12,13 @@
    </resultMap>
    <select id="getSpecialDeviceData" resultType="java.util.Map">
        SELECT JSON_UNQUOTE(`value`->'$.${sensorCode}') AS '${sensorCode}',
        JSON_UNQUOTE(`value`->'$.flylon') AS 'flylon',
        JSON_UNQUOTE(`value`->'$.flylat') AS 'flylat',
        DATE_FORMAT(`time`, #{dateFormat}) AS 'time'
        SELECT
        DATE_FORMAT(`time`, #{dateFormat}) AS `time`,
        `value`
        FROM `history_second_special`
        WHERE mac = #{mac}
        AND `time` LIKE #{time}"%"
        AND organization_id = #{orgId}
    </select>
</mapper>
screen-manage/src/main/java/com/moral/api/service/impl/HistorySecondSpecialServiceImpl.java
@@ -75,6 +75,7 @@
        historySecondSpecial.setMac(mac);
        historySecondSpecial.setTime(time);
        historySecondSpecial.setValue(JSONObject.toJSONString(data));
        historySecondSpecial.setOrganizationId(specialDevice.getOrganizationId());
        historySecondSpecial.setBatch(batchTime);
        historySecondSpecialMapper.insert(historySecondSpecial);
    }