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
package com.boying.controller;
 
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.boying.common.R;
import com.boying.entity.ViolationType;
import com.boying.entity.WhiteList;
import com.boying.service.ParkService;
import com.boying.service.WhiteListService;
import lombok.RequiredArgsConstructor;
import org.apache.catalina.security.SecurityUtil;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
 
import java.security.Security;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
 
 
@RestController
@RequestMapping("ffzf/whiteList")
@RequiredArgsConstructor
public class WhiteListController{
 
    private final WhiteListService whiteListService;
    private final ParkService parkService;
 
    @PostMapping("/findPage")
    //@Operation(summary = "分页查询" , description = "分页查询" )
    public Object findPage(Page page, String carNo) {
        QueryWrapper<WhiteList> wrapper = new QueryWrapper<>();
        wrapper.lambda()
                .like(StringUtils.isNotBlank(carNo),WhiteList::getCarNo,carNo)
                .orderByDesc(WhiteList::getId);
        Page<WhiteList> page1 = whiteListService.page(page, wrapper);
        for (WhiteList record : page1.getRecords()) {
            if(record.getParkId() != null){
                record.setName(parkService.getById(record.getParkId()).getName());
            }
        }
        return R.ok(page1);
    }
 
    @PostMapping("/findPageNew")
    public Object findPageNew(Page page, String carNo,Integer type,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);
        }
        QueryWrapper<WhiteList> wrapper = new QueryWrapper<>();
        wrapper.lambda()
                .orderByDesc(WhiteList::getId)
                .like(StringUtils.isNotBlank(carNo),WhiteList::getCarNo,carNo)
                .eq(type!=null,WhiteList::getType,type)
                .le(StringUtils.isNotBlank(date),WhiteList::getEndTime,date);
        Page<WhiteList> page1 = whiteListService.page(page, wrapper);
        for (WhiteList record : page1.getRecords()) {
            if(StringUtils.isNotBlank(record.getParkIds())){
                String s = "";
                String parkIds = record.getParkIds();
                String[] split = parkIds.split(",");
                for (int i = 0; i < split.length; i++) {
                    int id = Integer.parseInt(split[i]);
                    if(i != split.length -1){
                        s += parkService.getById(id).getName()+",";
                    }else {
                        s += parkService.getById(id).getName();
                    }
                }
                record.setName(s);
            }
        }
        return R.ok(page1);
    }
 
    @PostMapping("/save")
    public Object save(WhiteList whiteList) {
        if(StringUtils.isNotBlank(whiteList.getCarNo())){
            return R.failed("请输入正确车牌号");
        }
        whiteList.setCarNo(whiteList.getCarNo().replaceAll("\\s", ""));
        whiteListService.saveOrUpdate(whiteList);
        return R.ok("保存成功");
    }
 
    @PostMapping("/delete")
    public Object delete(Long id) {
        whiteListService.removeById(id);
        return R.ok("删除成功");
    }
}