zhitong.yu
2024-10-11 eb7075c41933b7d8043a66912631076eed13ae08
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
package com.hxzk.service.impl;
 
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hxzk.mapper.GpsTrackDao;
import com.hxzk.pojo.TbAchor;
import com.hxzk.pojo.TbGpsTrack;
import com.hxzk.pojo.TbTag;
import com.hxzk.pojo.TbTrackGps;
import com.hxzk.service.GpsTrackService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
@Service
public class GpsTrackServiceImpl extends ServiceImpl<GpsTrackDao, TbGpsTrack> implements GpsTrackService {
    @Autowired
    GpsTrackDao gpsTrackDao;
 
    @Override
    public PageInfo<TbGpsTrack> findAll(Integer page, Integer limit, String time) {
        List<TbGpsTrack> gps = gpsTrackDao.findAll(time);
        PageInfo<TbGpsTrack> info = new PageInfo<>(gps);
        return info;
    }
 
    @Override
    public List<TbTrackGps> getTagtrack(String tag_id, String begin_time, String end_time, String floor) throws ParseException {
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date now = dateFormat.parse(begin_time);
        SimpleDateFormat dateFormat2 = new SimpleDateFormat("yyyyMMdd");
        String now2 = dateFormat2.format(now);
        return gpsTrackDao.getTagtrack(tag_id,begin_time,end_time,floor,now2);
    }
 
    @Override
    public  PageInfo<TbGpsTrack>  findJingWeiSearch(Integer page, Integer limit, String tagid, String datte) throws ParseException {
        Integer pages = 0;
        LocalDate today = LocalDate.now();
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMdd");
        String formattedDate = today.format(formatter);
        List<TbGpsTrack> gps = new ArrayList<>();
        if (datte.equals("") || datte == null){
             gps = gpsTrackDao.findJingWeiSearch(tagid,formattedDate,pages);
        }else{
            SimpleDateFormat inputFormat = new SimpleDateFormat("yyyy-MM-dd");
            SimpleDateFormat outputFormat = new SimpleDateFormat("yyyyMMdd");
            Date date = inputFormat.parse(datte);
            String outputDate = outputFormat.format(date);
             gps = gpsTrackDao.findJingWeiSearch(tagid,outputDate,pages);
        }
        PageInfo<TbGpsTrack> info = new PageInfo<>(gps);
        return info;
    }
 
    @Override
    public List findHourceCount(String dates, String tagid) {
        // 定义解析的时间格式
        SimpleDateFormat originalFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
        // 定义目标时间格式
        SimpleDateFormat targetFormat = new SimpleDateFormat("yyyy-MM-dd");
        SimpleDateFormat targetFormat1 = new SimpleDateFormat("yyyyMMdd");
        List Nums = new ArrayList<>();
        try {
            // 解析原始时间字符串
            Date date = originalFormat.parse(dates);
            // 格式化为目标时间格式
            String formattedDateStr = targetFormat.format(date);
            String formattedDateStr1 = targetFormat1.format(date);
            for (int i = 0 ; i < 24;i++){
                String num;
                if (i<10){
                    num=formattedDateStr+" "+"0"+i+":%";
                }else{
                    num=formattedDateStr+" "+i+":%";
                }
                Integer number = 0;
                if (tagid == ""){
                    number = gpsTrackDao.findCountJw1(num,formattedDateStr1);
                }else{
                    number = gpsTrackDao.findCountJw(num,formattedDateStr1,tagid);
                }
 
                Nums.add(number);
            }
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return Nums;
    }
 
    @Override
    public List findHourceCountHaiBa(String dates, String tagid) throws ParseException {
        // 定义目标时间格式
        SimpleDateFormat targetFormat = new SimpleDateFormat("yyyy-MM-dd");
        SimpleDateFormat targetFormat1 = new SimpleDateFormat("yyyyMMdd");
        Date date = targetFormat.parse(dates);
        List Nums = new ArrayList<>();
        String formattedDateStr = targetFormat.format(date);
        String formattedDateStr1 = targetFormat1.format(date);
        for (int i = 0 ; i < 24;i++){
            String num;
            if (i<10){
                num=formattedDateStr+" "+"0"+i+":%";
            }else{
                num=formattedDateStr+" "+i+":%";
            }
            Double number = gpsTrackDao.findHourceCountHaiBa1(formattedDateStr1,num,tagid);
            if (number == null){
                number = (double) 0;
            }
            Nums.add(number);
        }
        return Nums;
    }
 
 
}