kongdeqiang
2024-04-09 fb050c0dafa5363a73540dd9e52b78487e25ba0a
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
package com.boying.service.impl;
 
import cn.hutool.core.date.DateUtil;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.boying.entity.Barrier;
import com.boying.entity.OutPark;
import com.boying.entity.Park;
import com.boying.entity.Statistic;
import com.boying.mapper.OutParkMapper;
import com.boying.mapper.StatisticMapper;
import com.boying.service.OutParkService;
import com.boying.service.StatisticService;
import com.boying.util.RedisJsonUtil;
import com.boying.util.StringUtil;
import lombok.AllArgsConstructor;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;
 
import java.io.IOException;
import java.time.LocalDateTime;
import java.util.Date;
import java.util.List;
import java.util.Map;
 
/**
 * @author kdq
 * @version 1.0.0
 * @ClassName OutParkServiceImpl.java
 * @Description TODO
 * @createTime 2022年11月20日 10:20:00
 */
@Service
@AllArgsConstructor
public class OutParkServiceImpl extends ServiceImpl<OutParkMapper, OutPark> implements OutParkService {
    private final OutParkMapper outParkMapper;
    private StringRedisTemplate redisTemplate;
 
 
    @Override
    public int count1() {
        QueryWrapper<OutPark> wrapper = new QueryWrapper<>();
        wrapper.lambda()
                .between(OutPark::getCreateTime, DateUtil.beginOfDay(new Date()),DateUtil.endOfDay(new Date()))
                .eq(OutPark::getStatus,1);
        return outParkMapper.selectCount(wrapper);
    }
 
    @Override
    public int count2() {
        QueryWrapper<OutPark> wrapper = new QueryWrapper<>();
        wrapper.lambda()
                .between(OutPark::getCreateTime, DateUtil.beginOfDay(new Date()),DateUtil.endOfDay(new Date()))
                .ge(OutPark::getPrice,0);
        return outParkMapper.selectCount(wrapper);
    }
 
    @Override
    public int count5() {
        QueryWrapper<OutPark> wrapper = new QueryWrapper<>();
        wrapper.lambda()
                .between(OutPark::getCreateTime, DateUtil.beginOfDay(new Date()),DateUtil.endOfDay(new Date()));
        return outParkMapper.selectCount(wrapper);
    }
 
    @Override
    public double sumByPrice() {
        QueryWrapper<OutPark> wrapper = new QueryWrapper<>();
        wrapper.lambda()
                .between(OutPark::getCreateTime, DateUtil.beginOfDay(new Date()),DateUtil.endOfDay(new Date()))
                        .eq(OutPark::getStatus,1);
        wrapper.select("IFNULL(ROUND(SUM(price)),0) as num");
        Map<String, Object> map = getMap(wrapper);
        String a = map.get("num").toString();
        if(a!=null){
            return Double.parseDouble(a);
        }else{
            return 0.0;
        }
    }
 
    @Override
    public int count3() {
        QueryWrapper<OutPark> wrapper = new QueryWrapper<>();
        wrapper.lambda()
                .between(OutPark::getCreateTime, DateUtil.beginOfMonth(new Date()),DateUtil.endOfMonth(new Date()));
        return outParkMapper.selectCount(wrapper);
    }
 
    @Override
    public double sumByPrice2() {
        QueryWrapper<OutPark> wrapper = new QueryWrapper<>();
        wrapper.lambda()
                .between(OutPark::getCreateTime, DateUtil.beginOfMonth(new Date()),DateUtil.endOfMonth(new Date()))
                        .eq(OutPark::getStatus,1);
        wrapper.select("IFNULL(ROUND(SUM(price)),0) as num");
        Map<String, Object> map = getMap(wrapper);
        String a = map.get("num").toString();
        if(a!=null){
            return Double.parseDouble(a);
        }else{
            return 0.0;
        }
    }
 
    @Override
    public OutPark findByCarNo(String serialno) {
        QueryWrapper<OutPark> wrapper = new QueryWrapper<>();
        wrapper.lambda()
                .eq(OutPark::getCarNo,serialno);
        List<OutPark> outParks = outParkMapper.selectList(wrapper);
        if(outParks.size()>0){
            return outParks.get(0);
        }else{
            return null;
        }
    }
 
    @Override
    public OutPark count4(Integer bId) {
        OutPark outPark = null;
        try {
            String s  =  redisTemplate.opsForValue().get("outPark-"+bId);
            if(!StringUtil.isNullOrEmpty(s)){
                outPark =  JSON.parseObject(s, OutPark.class);
                return outPark;
            }else {
                return null;
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
//
//        QueryWrapper<OutPark> wrapper = new QueryWrapper<>();
//        wrapper.lambda()
//                .eq(OutPark::getBarrierId,bId)
//                .eq(OutPark::getStatus,1)
//                .eq(OutPark::getStatus2,0)
//                .orderByDesc(OutPark::getCreateTime);
//        List<OutPark> outParks = outParkMapper.selectList(wrapper);
//        if(outParks.size()>0){
//            return outParks.get(0);
//        }else{
//            return null;
//        }
    }
 
    @Override
    public OutPark findByCarNoAndBarrierId(String carNo, Integer id) {
        QueryWrapper<OutPark> wrapper = new QueryWrapper<>();
        wrapper.lambda()
                .eq(OutPark::getBarrierId,id)
                .eq(OutPark::getCarNo,carNo)
                .orderByDesc(OutPark::getCreateTime);
        List<OutPark> outParks = outParkMapper.selectList(wrapper);
        if(outParks.size()>0){
            return outParks.get(0);
        }else{
            return null;
        }
    }
 
    @Override
    public OutPark findByPayCode(String payCode) {
        QueryWrapper<OutPark> wrapper = new QueryWrapper<>();
        wrapper.lambda()
                .eq(OutPark::getCode2,payCode)
                .orderByDesc(OutPark::getCreateTime);
        List<OutPark> outParks = outParkMapper.selectList(wrapper);
        if(outParks.size()>0){
            return outParks.get(0);
        }else{
            return null;
        }
    }
 
    @Override
    public OutPark findByOrderId(String txnOrderId) {
        QueryWrapper<OutPark> wrapper = new QueryWrapper<>();
        wrapper.lambda()
                .eq(OutPark::getTxnOrderId,txnOrderId)
                .orderByDesc(OutPark::getCreateTime);
        List<OutPark> outParks = outParkMapper.selectList(wrapper);
        if(outParks.size()>0){
            return outParks.get(0);
        }else{
            return null;
        }
    }
 
    @Override
    public OutPark findBy5min(String carNo, Integer parkId,LocalDateTime dateTime) {
        LocalDateTime localDateTime = dateTime.minusMinutes(5);
        QueryWrapper<OutPark> wrapper = new QueryWrapper<>();
        wrapper.lambda()
                .eq(OutPark::getCarNo,carNo)
                .eq(OutPark::getParkId,parkId)
                .ge(OutPark::getCreateTime,localDateTime)
                .isNotNull(OutPark::getEnterTime);
        List<OutPark> outParks = outParkMapper.selectList(wrapper);
        if(outParks != null && outParks.size()>0){
            for (OutPark outPark : outParks) {
                if(outPark.getPrice() == 0){
                    return outPark;
                }
                if(outPark.getPrice() != 0 && outPark.getStatus() == 1){
                    return outPark;
                }
            }
        }
        return null;
    }
    @Override
    public OutPark findBy10min(String carNo, Integer parkId,LocalDateTime dateTime,Integer outParkId) {
        LocalDateTime localDateTime = dateTime.minusMinutes(10);
        QueryWrapper<OutPark> wrapper = new QueryWrapper<>();
        wrapper.lambda()
                .eq(OutPark::getCarNo,carNo)
                .eq(OutPark::getParkId,parkId)
                .ge(OutPark::getCreateTime,localDateTime)
                .ge(OutPark::getPrice,0)
                .ne(OutPark::getId,outParkId)
                .isNotNull(OutPark::getPayCode)
                .isNotNull(OutPark::getEnterTime);
        List<OutPark> outParks = outParkMapper.selectList(wrapper);
        if(outParks != null && outParks.size()>0){
            return outParks.get(0);
        }
        return null;
    }
 
    @Override
    public OutPark findBy5min2(String carNo, Integer parkId,LocalDateTime dateTime) {
        LocalDateTime localDateTime = dateTime.minusMinutes(7);
        QueryWrapper<OutPark> wrapper = new QueryWrapper<>();
        wrapper.lambda()
                .eq(OutPark::getCarNo,carNo)
                .eq(OutPark::getParkId,parkId)
                .ge(OutPark::getCreateTime,localDateTime)
                .ge(OutPark::getPrice,0)
                .ne(OutPark::getStatus,1)
                .isNotNull(OutPark::getPayCode)
                .isNotNull(OutPark::getEnterTime);
        List<OutPark> outParks = outParkMapper.selectList(wrapper);
        if(outParks != null && outParks.size()>0){
           return outParks.get(0);
        }
        return null;
    }
 
    @Override
    public List<OutPark> getList(long current, long size, String carNo, Long parkId, String payCode, String date) {
        return outParkMapper.getList((current-1)*size,size,carNo,parkId,payCode,date);
    }
 
    @Override
    public long getCount(String carNo, Long parkId, String payCode, String date) {
        return outParkMapper.getCount(carNo,parkId,payCode,date);
    }
}