kongdeqiang
2022-09-19 a9862e81851bbe037edc6bb1c7f562c1e55c0d7f
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
package com.boying.controller.phone;
 
import com.boying.common.BaseController;
import com.boying.entity.EnterPark;
import com.boying.entity.Park;
import com.boying.service.EnterParkService;
import com.boying.service.ParkService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
 
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;
import java.util.ArrayList;
import java.util.List;
 
@RestController
@RequestMapping("notice")
public class NoticeController extends BaseController {
 
    @Autowired
    private EnterParkService enterParkService;
    @Autowired
    private ParkService parkService;
 
    //停车场内有违法的车辆
    @PostMapping("illegalCar")
    public Object illegalCar(Long parkId){
        Specification<EnterPark> specification2 = new Specification<EnterPark>() {
            @Override
            public Predicate toPredicate(Root<EnterPark> root, CriteriaQuery<?> cq, CriteriaBuilder cb) {
                List<Predicate> list = new ArrayList<Predicate>();
                list.add(cb.equal(root.get("status"), 1));
                list.add(cb.equal(root.get("parkId"), parkId));
                Predicate[] arr = new Predicate[list.size()];
                cq.where(list.toArray(arr));
                return null;
            }
        };
        List<EnterPark> all = enterParkService.findAll(specification2);
        return success("",all);
    }
 
    //停车场内有违法的车辆
    @PostMapping("illegalCar2")
    public Object illegalCar2(){
        Specification<EnterPark> specification2 = new Specification<EnterPark>() {
            @Override
            public Predicate toPredicate(Root<EnterPark> root, CriteriaQuery<?> cq, CriteriaBuilder cb) {
                List<Predicate> list = new ArrayList<Predicate>();
                list.add(cb.equal(root.get("status"), 1));
                Predicate[] arr = new Predicate[list.size()];
                cq.where(list.toArray(arr));
                return null;
            }
        };
        List<EnterPark> all = enterParkService.findAll(specification2);
        for(EnterPark enterPark:all){
            Park park = (Park) parkService.findById(enterPark.getId());
            enterPark.setParkName(park.getName());
        }
        return success("",all);
    }
 
    //停车场内的车辆 根据状态查询
    @PostMapping("enterPark")
    public Object enterPark(Integer status,int page,int pageSize){
        Pageable pageable = PageRequest.of(page-1,pageSize, Sort.Direction.DESC,"id");
        if(status==null){
            return success("",enterParkService.findPage(pageable));
        }
        Specification<EnterPark> specification2 = new Specification<EnterPark>() {
            @Override
            public Predicate toPredicate(Root<EnterPark> root, CriteriaQuery<?> cq, CriteriaBuilder cb) {
                List<Predicate> list = new ArrayList<Predicate>();
                list.add(cb.equal(root.get("status").as(Integer.class), status));
                Predicate[] arr = new Predicate[list.size()];
                cq.where(list.toArray(arr));
                return null;
            }
        };
        Page<EnterPark> all = enterParkService.findPage(pageable,specification2);
        return success("",all);
    }
}