kongdeqiang
2025-04-15 963ec1b990fc094de3234250c4888b5ca94ac5bc
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
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
package com.boying.controller;
 
import cn.hutool.core.date.DateUtil;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.boying.common.R;
import com.boying.entity.*;
import com.boying.service.*;
import com.boying.util.DateUtilOther;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
 
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.*;
 
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.util.Date;
import java.util.List;
import java.util.concurrent.TimeUnit;
 
/**
 * 入场表
 *
 * @author kdq
 * @date 2023-01-23 09:46:32
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("ffzf/enterpark" )
@Api(value = "enterpark", tags = "入场表管理")
public class EnterParkController {
 
    private final EnterParkService enterParkService;
    private final OutParkService outParkService;
    private final OutParkLogService outParkLogService;
    private final BarrierService barrierService;
    private final ParkService parkService;
    private final CostRuleService costRuleService;
    private final WhiteListService whiteListService;
    private final StringRedisTemplate redisTemplate;
 
    /**
     * 分页查询
     * @param page 泊车分页对象
     * @param
     * @return
     */
//    @ApiOperation(value = "分页查询", notes = "分页查询")
//    @GetMapping("/page" )
//    public R getEnterParkPage(Page page, EnterPark enterPark, String date) throws ParseException {
//        List<EnterPark> list = enterParkService.getList(page.getCurrent(), page.getSize(), enterPark.getCarNo(),enterPark.getParkId(), date);
//        long count = enterParkService.getCount(enterPark.getCarNo(), enterPark.getParkId(), date);
//        Page page1 = new Page();
//        for (EnterPark record : list) {
//            record.setParkName(parkService.getById(record.getParkId()).getName());
//            if(record.getImgId() != null){
//                record.setImgPath("/ffzf/fileinfo/showImgById/"+record.getImgId());
//            }
//        }
//        page1.setRecords(list);
//        page1.setCurrent(page.getCurrent());
//        page1.setSize(page.getSize());
//        page1.setTotal(count);
//        return R.ok(page1);
//    }
 
    @PostMapping("/findPage")
    public Object findPage(Page page, String  carNo,Integer parkId,String date) throws ParseException {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        if(StringUtils.isNotBlank(date)){
            System.out.println(date);
            Date parse = sdf.parse(date);
            date = sdf.format(parse);
        }
        List<EnterPark> list = enterParkService.getList(page.getCurrent(), page.getSize(), carNo,parkId, date);
        long count = enterParkService.getCount(carNo,parkId, date);
        for (EnterPark record : list) {
            record.setParkName(parkService.getById(record.getParkId()).getName());
            if(record.getImgId() != null){
                record.setImgPath("/ffzf/fileinfo/showImgById/"+record.getImgId());
            }
        }
        page.setRecords(list);
        page.setTotal(count);
        return R.ok(page);
    }
 
    @PostMapping("/findByCar")
    public Object findByCar(String carNo,Integer parkId) {
        if(StringUtils.isBlank(carNo)){
            return R.failed("请输入正确车牌号");
        }else {
            QueryWrapper<EnterPark> queryWrapper = new QueryWrapper<>();
            queryWrapper.lambda()
                    .eq(EnterPark::getCarNo,carNo)
                    .eq(EnterPark::getParkId,parkId);
            List<EnterPark> list = enterParkService.list(queryWrapper);
            if(list !=null && list.size()>0){
                for (EnterPark enterPark : list) {
                    enterPark.setParkName(parkService.getById(enterPark.getParkId()).getName());
                }
                return R.ok(list);
            }else {
                return R.failed("该车牌未查询到入场记录");
            }
        }
    }
 
    @PostMapping("/getByBarrierId")
    public Object getByBarrierId(Integer barrierId) throws ParseException {
        Barrier byId1 = barrierService.getById(barrierId);
        OutPark byId = outParkService.findByCarNoAndBarrierId(byId1.getCarNo(), barrierId);
        if(byId==null){
            return R.failed("未查询到出场记录");
        }else {
            return R.ok(byId);
        }
 
    }
 
    @PostMapping("/editOutByEnter")
    public Object editOutByEnter(Integer outParkId,String carNo,Integer enterId) throws ParseException {
        double money = 0.0;
        OutPark outPark = outParkService.getById(outParkId);
        EnterPark enterPark = enterParkService.getById(enterId);
        outPark.setCarNo(enterPark.getCarNo());
        outPark.setEnterTime(enterPark.getCreateTime());
        try {
            long l = outPark.getCreateTime().toInstant(ZoneOffset.of("+8")).toEpochMilli() - enterPark.getCreateTime().toInstant(ZoneOffset.of("+8")).toEpochMilli();
            outPark.setTime(l/(1000*60));
            money = costRuleService.getMoney(enterPark.getParkId(), outPark.getEnterTime(), outPark.getCreateTime(), 1);
            //入场记录保存一下
            if(enterPark.getIsPay() != null && enterPark.getIsPay()==1){
                money = money - enterPark.getPrice();
            }else {
                enterPark.setPrice(money);
                enterPark.setIsPay(0);
                enterParkService.updateById(enterPark);
            }
        } catch (ParseException e) {
            e.printStackTrace();
        }
        outPark.setPrice(money);
        outPark.setStatus3(0);
        outParkService.saveOrUpdate(outPark);
        Barrier barrier =barrierService.getById(outPark.getBarrierId());
        barrier.setCarNo(carNo);
        //判断是否在白名单
        QueryWrapper<WhiteList> wrapper = new QueryWrapper<>();
        wrapper.lambda()
                .eq(WhiteList::getCarNo,carNo);
        List<WhiteList> all = whiteListService.list(wrapper);
        if(all.size() >0){
            for(WhiteList w : all){
                if(w.getType()==0){
                    outPark.setStatus(2);
                    outPark.setStatus2(1);
                    outParkService.saveOrUpdate(outPark);
                    barrierService.saveOrUpdate(barrier);
                    String jsonValue2 = JSON.toJSONString(barrier);
                    redisTemplate.opsForValue().set("barrier-"+barrier.getCode(), jsonValue2);
                    String jsonValue = JSON.toJSONString(outPark);
                    redisTemplate.opsForValue().set("outPark_dif_"+ outPark.getBarrierId(), jsonValue);
                    //缓存在redis里,心跳接口去抬杆
                    String jsonValue1 = JSON.toJSONString(outPark);
                    redisTemplate.opsForValue().set("outPark-"+outPark.getBarrierId(), jsonValue1);
                    redisTemplate.opsForValue().set("park_change_in_"+outPark.getParkId(),"true",1, TimeUnit.DAYS);
                    return R.ok(null,"操作成功");
                }else{
                    if(StringUtils.isNotBlank(w.getParkIds())){
                        if(w.getEndTime()!=null){
                            String parkIds = w.getParkIds();
                            String[] split = parkIds.split(",");
                            for (String s : split) {
                                int pid = Integer.parseInt(s);
                                if(pid == outPark.getParkId() && System.currentTimeMillis()<w.getEndTime().getTime()){
                                    outPark.setStatus(2);
                                    outPark.setStatus2(1);
                                    outParkService.saveOrUpdate(outPark);
                                    barrierService.saveOrUpdate(barrier);
                                    String jsonValue2 = JSON.toJSONString(barrier);
                                    redisTemplate.opsForValue().set("barrier-"+barrier.getCode(), jsonValue2);
                                    String jsonValue = JSON.toJSONString(outPark);
                                    redisTemplate.opsForValue().set("outPark_dif_"+ outPark.getBarrierId(), jsonValue);
                                    //缓存在redis里,心跳接口去抬杆
                                    String jsonValue1 = JSON.toJSONString(outPark);
                                    redisTemplate.opsForValue().set("outPark-"+outPark.getBarrierId(), jsonValue1);
                                    redisTemplate.opsForValue().set("park_change_in_"+outPark.getParkId(),"true",1, TimeUnit.DAYS);
                                    return R.ok(null,"操作成功");
                                }
                            }
                        }
                    }
                }
            }
        }else {
            barrierService.saveOrUpdate(barrier);
            String jsonValue2 = JSON.toJSONString(barrier);
            redisTemplate.opsForValue().set("barrier-"+barrier.getCode(), jsonValue2);
            if(outPark.getPrice()==0&&outPark.getStatus3()==0){
                String jsonValue = JSON.toJSONString(outPark);
                redisTemplate.opsForValue().set("outPark_dif_"+ barrier.getId(), jsonValue);
                String jsonValue1 = JSON.toJSONString(outPark);
                redisTemplate.opsForValue().set("outPark-"+outPark.getBarrierId(), jsonValue1);
                redisTemplate.opsForValue().set("park_change_in_"+outPark.getParkId(),"true",1, TimeUnit.DAYS);
                return R.ok(null,"操作成功");
            }else {
                //需要缴费或者有违章
                OutParkLog byOutPark = outParkLogService.getByOutPark(outPark.getCarNo(), outPark.getId());
                byOutPark.setOutTime(outPark.getCreateTime());
                byOutPark.setParkId(outPark.getParkId());
                byOutPark.setCarNo(carNo);
                outParkLogService.saveOrUpdate(byOutPark);
                String jsonValue = JSON.toJSONString(outPark);
                redisTemplate.opsForValue().set("outPark_dif_"+ barrier.getId(), jsonValue);
                return R.ok(null,"操作成功,请扫码缴费");
            }
        }
       return R.failed("操作失败");
    }
 
    /**
     * 通过id查询入场表
     * @param id id
     * @return R
     */
    @ApiOperation(value = "通过id查询", notes = "通过id查询")
    @GetMapping("/{id}" )
    public R getById(@PathVariable("id" ) Integer id) {
        return R.ok(enterParkService.getById(id));
    }
 
    /**
     * 新增入场表
     * @param enterPark 入场表
     * @return R
     */
    @ApiOperation(value = "新增入场表", notes = "新增入场表")
    @PostMapping
    public R save(@RequestBody EnterPark enterPark) {
        return R.ok(enterParkService.save(enterPark));
    }
 
    /**
     * 修改入场表
     * @param enterPark 入场表
     * @return R
     */
    @ApiOperation(value = "修改入场表", notes = "修改入场表")
    @PutMapping
    public R updateById(@RequestBody EnterPark enterPark) {
        return R.ok(enterParkService.updateById(enterPark));
    }
 
    /**
     * 通过id删除入场表
     * @param id id
     * @return R
     */
    @ApiOperation(value = "通过id删除入场表", notes = "通过id删除入场表")
    @DeleteMapping("/{id}" )
    public R removeById(@PathVariable Integer id) {
        return R.ok(enterParkService.removeById(id));
    }
 
 
    /**
     * 导出excel 表格
     * @param enterPark 查询条件
     * @return excel 文件流
     */
    @GetMapping("/export")
    public List<EnterPark> export(EnterPark enterPark) {
        return enterParkService.list(Wrappers.query(enterPark));
    }
}