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 specification2 = new Specification() { @Override public Predicate toPredicate(Root root, CriteriaQuery cq, CriteriaBuilder cb) { List list = new ArrayList(); 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 all = enterParkService.findAll(specification2); return success("",all); } //停车场内有违法的车辆 @PostMapping("illegalCar2") public Object illegalCar2(){ Specification specification2 = new Specification() { @Override public Predicate toPredicate(Root root, CriteriaQuery cq, CriteriaBuilder cb) { List list = new ArrayList(); list.add(cb.equal(root.get("status"), 1)); Predicate[] arr = new Predicate[list.size()]; cq.where(list.toArray(arr)); return null; } }; List 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 specification2 = new Specification() { @Override public Predicate toPredicate(Root root, CriteriaQuery cq, CriteriaBuilder cb) { List list = new ArrayList(); 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 all = enterParkService.findPage(pageable,specification2); return success("",all); } }