cjl
2023-11-10 6e734d7297e2a1be9cddc377a6e1c0cdb3c22438
fix:补充提交
1 files added
3 files modified
191 ■■■■■ changed files
screen-manage/src/main/java/com/moral/api/mapper/HistorySecondCruiserMapper.java 3 ●●●●● patch | view | raw | blame | history
screen-manage/src/main/java/com/moral/api/pojo/dto/cruiser/CruiserListDTO.java 35 ●●●●● patch | view | raw | blame | history
screen-manage/src/main/java/com/moral/api/service/impl/HistorySecondCruiserServiceImpl.java 103 ●●●● patch | view | raw | blame | history
screen-manage/src/main/resources/mapper/HistorySecondCruiserMapper.xml 50 ●●●●● patch | view | raw | blame | history
screen-manage/src/main/java/com/moral/api/mapper/HistorySecondCruiserMapper.java
@@ -6,6 +6,7 @@
import com.moral.api.entity.HistorySecondCruiser;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.moral.api.pojo.dto.cruiser.CruiserDTO;
import com.moral.api.pojo.dto.cruiser.CruiserListDTO;
/**
 * <p>
@@ -19,4 +20,6 @@
    List<CruiserDTO> getCruiserInfo(Map<String,Object> params);
    List<CruiserListDTO> cruiserList(Map<String,Object> params);
}
screen-manage/src/main/java/com/moral/api/pojo/dto/cruiser/CruiserListDTO.java
New file
@@ -0,0 +1,35 @@
package com.moral.api.pojo.dto.cruiser;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;
import java.util.Objects;
@Data
public class CruiserListDTO {
    /**
     * 数据时间
     */
    private String time;
    /**
     * 纬度
     */
    private Double flyLat;
    /**
     * 经度
     */
    private Double flyLon;
    private Integer coordinateId;
    private Integer id;
    private Integer state;
}
screen-manage/src/main/java/com/moral/api/service/impl/HistorySecondCruiserServiceImpl.java
@@ -2,6 +2,7 @@
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.moral.api.entity.HistorySecondCruiser;
import com.moral.api.entity.ManageCoordinateDetail;
import com.moral.api.entity.Sensor;
@@ -10,28 +11,20 @@
import com.moral.api.mapper.ManageCoordinateDetailMapper;
import com.moral.api.mapper.SpecialDeviceMapper;
import com.moral.api.pojo.dto.cruiser.CruiserDTO;
import com.moral.api.service.DeviceService;
import com.moral.api.pojo.dto.cruiser.CruiserListDTO;
import com.moral.api.service.HistorySecondCruiserService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.moral.api.service.SpecialDeviceService;
import com.moral.api.util.RoadUtils;
import com.moral.constant.Constants;
import com.moral.constant.RedisConstants;
import com.moral.util.DateUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import org.springframework.util.ObjectUtils;
import java.sql.Wrapper;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -172,82 +165,34 @@
    @Override
    public Map<String, Object> getCruiserCompare(Map<String, Object> params) {
        HashMap<String,Object> rsMap = new HashMap<>();
        String mac = params.get("mac").toString();
        String time1 = params.get("time1").toString();
        List<CruiserListDTO> list = historySecondCruiserMapper.cruiserList(params);
        List<CruiserDTO> cruiserInfo = new ArrayList<>();
        ArrayList<ManageCoordinateDetail> rsList1 = new ArrayList<>();
        params.put("dateFormat", "%Y-%m-%d %H:%i:%s");
        List<ManageCoordinateDetail> manageCoordinateDetails = manageCoordinateDetailMapper.selectList(null);
        List<CruiserDTO> cruiserInfo = (List<CruiserDTO>) redisTemplate.opsForHash().get(RedisConstants.DATE_COORDINATE, mac + time1);
        if (ObjectUtils.isEmpty(cruiserInfo)){
            cruiserInfo = historySecondCruiserMapper.getCruiserInfo(params);
            cruiserInfo = cruiserInfo.stream().distinct().collect(Collectors.toList());
            cruiserInfo.removeIf(o->{
                if (ObjectUtils.isEmpty(o.getFlyLon()) || ObjectUtils.isEmpty(o.getFlyLat())) {
                    return true;
                }
                double lon = o.getFlyLon();
                double lat = o.getFlyLat();
                double[] doubles = RoadUtils.transformWGS84ToBD09(lon, lat);
                Matcher matcher = Pattern.compile("\\d*\\.\\d{8}").matcher(""+doubles[0]);
                matcher.find();
                String s = matcher.group();
                Matcher matcher1 = Pattern.compile("\\d*\\.\\d{8}").matcher(""+doubles[1]);
                matcher1.find();
                String s1 = matcher1.group();
                o.setFlyLon(Double.parseDouble(s));
                o.setFlyLat(Double.parseDouble(s1));
                o.setData(lon+"_"+lat);
//            o.setFlyLon(doubles[0]);
//            o.setFlyLat(doubles[1]);
                if (lon < 70 || lon > 150 || lat < 20 || lat > 60) {
                    return true;
                }
                return false;
            });
            redisTemplate.opsForHash().put(RedisConstants.DATE_COORDINATE,mac+time1,cruiserInfo);
            //设置过期时间
            redisTemplate.opsForHash().getOperations().expire(RedisConstants.DATE_COORDINATE,6000, TimeUnit.SECONDS);
        }
//        List<CruiserDTO> cruiserInfo = historySecondCruiserMapper.getCruiserInfo(params);
        log.info(""+cruiserInfo.size());
        if (ObjectUtils.isEmpty(manageCoordinateDetails)){
            rsMap.put("rsData",cruiserInfo);
            rsMap.put("data",rsList1);
            return rsMap;
        }
        for (int i=cruiserInfo.size()-1;i>0;i--) {
            CruiserDTO cruiserDTO = cruiserInfo.get(i);
            String data = cruiserDTO.getData();
            String[] rs = data.split("_");
            String flyLon = rs[0];
            String flyLat = rs[1];
//            double lonDouble = Double.parseDouble(flyLon);
//            double latDouble = Double.parseDouble(flyLat);
            for (ManageCoordinateDetail manageCoordinateDetail : manageCoordinateDetails) {
                String latitude = manageCoordinateDetail.getLatitude().toString();
                String longitude = manageCoordinateDetail.getLongitude().toString();
//                double lonDouble1 = Double.parseDouble(longitude);
//                double latDouble1 = Double.parseDouble(latitude);
//                if (latDouble1==latDouble && lonDouble==lonDouble1){
                    if (flyLon.equals(longitude) && flyLat.equals(latitude)){
                    manageCoordinateDetail.setCode(data);
                    manageCoordinateDetail.setLongitude(cruiserDTO.getFlyLon());
                    manageCoordinateDetail.setLatitude(cruiserDTO.getFlyLat());
                    rsList1.add(manageCoordinateDetail);
                    cruiserInfo.remove(i);
                    break;
                }
        for(CruiserListDTO c : list){
            String date = new StringBuilder().append(c.getFlyLon()).append("_").append(c.getFlyLat()).toString();
            if(c.getState().equals(0)){
                CruiserDTO cruiserDTO = new CruiserDTO();
                cruiserDTO.setTime(c.getTime());
                cruiserDTO.setFlyLat(c.getFlyLat());
                cruiserDTO.setFlyLon(c.getFlyLon());
                cruiserDTO.setData(date);
                cruiserDTO.setState("1");
                cruiserInfo.add(cruiserDTO);
            }else {
                ManageCoordinateDetail detail = new ManageCoordinateDetail();
                detail.setId(c.getId());
                detail.setCoordinateId(c.getCoordinateId());
                detail.setLongitude(c.getFlyLon());
                detail.setLatitude(c.getFlyLat());
                detail.setState(c.getState().toString());
                detail.setCode(date);
                rsList1.add(detail);
            }
        }
        rsMap.put("rsData",cruiserInfo);
        rsMap.put("data",rsList1);
        rsMap.put("message","有"+cruiserInfo.size()+"个不在里面,"+"一共有"+(cruiserInfo.size()+rsList1.size())+"个");
        return rsMap;
    }
}
screen-manage/src/main/resources/mapper/HistorySecondCruiserMapper.xml
@@ -20,4 +20,54 @@
        order by time
    </select>
    <select id="cruiserList" resultType="com.moral.api.pojo.dto.cruiser.CruiserListDTO">
        WITH zb AS (
        SELECT
        DATE_FORMAT( `time`, '%Y-%m-%d %H:%i:%s' ) AS time,VALUE->> '$.flylat' AS flyLat,VALUE->> '$.flylon' AS flyLon
        FROM
        history_second_cruiser
        WHERE
        mac =  #{mac}
        AND `time` <![CDATA[>=]]> #{time1}
        AND `time` <![CDATA[<=]]> #{time2}
        ORDER BY
        time
        ),
        resultList AS (
        SELECT
        t1.time,
        t1.flyLat,
        t1.flyLon
        FROM
        zb t1
        INNER JOIN ( SELECT flyLon, flyLat, MAX( time ) AS max_time FROM zb GROUP BY flyLat, flyLon ) t2 ON t1.flyLon = t2.flyLon
        AND t1.flyLat = t2.flyLat
        AND t1.time = t2.max_time
        ),
        mx AS (
        SELECT t2.latitude,
            t2.longitude,
            t2.state,
            t2.coordinate_id ,max(t2.id) id
        FROM
        manage_coordinate t1
        LEFT JOIN manage_coordinate_detail t2 ON t1.coordinate_id = t2.coordinate_id
        LEFT JOIN special_device t3 ON t1.organization_id = t3.organization_id
        WHERE
        t1.is_del = 0
        AND t3.mac = #{mac} group by t2.latitude,
            t2.longitude,
            t2.state,
            t2.coordinate_id
        ) SELECT
        tt.time,
        tt.flyLat,
        tt.flyLon,
        COALESCE ( tt1.state, 0 ) AS state ,tt1.coordinate_id,tt1.id as id
        FROM
        resultList tt
        LEFT JOIN mx tt1 ON tt.flyLat = tt1.latitude
        AND tt.flyLon = tt1.longitude
    </select>
</mapper>