package com.boying.controller;
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.boying.common.R;
|
import com.boying.entity.Barrier;
|
import com.boying.entity.OutPark;
|
import com.boying.service.BarrierService;
|
import com.boying.service.OutParkService;
|
import lombok.RequiredArgsConstructor;
|
import org.springframework.web.bind.annotation.PostMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RestController;
|
|
import java.time.LocalDateTime;
|
import java.time.ZoneOffset;
|
import java.util.List;
|
|
@RestController
|
@RequestMapping("barrier")
|
@RequiredArgsConstructor
|
public class BarrierController {
|
|
private final BarrierService barrierService;
|
private final OutParkService outParkService;
|
|
@PostMapping("findPage")
|
public Object findPage(Page page, String parkId) {
|
QueryWrapper<Barrier> wrapper = new QueryWrapper<>();
|
wrapper.lambda()
|
.eq(Barrier::getParkId,Integer.parseInt(parkId));
|
Page page1 = barrierService.page(page, wrapper);
|
List<Barrier> records = page1.getRecords();
|
for(Barrier barrier:records){
|
long l = System.currentTimeMillis() - barrier.getUpdateTime().toInstant(ZoneOffset.of("+8")).toEpochMilli();
|
System.out.println(l);
|
if(l>10000){
|
barrier.setStatus(1);
|
}
|
}
|
page1.setRecords(records);
|
return R.ok(page1);
|
}
|
|
@PostMapping("save")
|
public Object save(Barrier barrier) {
|
barrier.setUpdateTime(LocalDateTime.now());
|
barrierService.saveOrUpdate(barrier);
|
return R.ok("保存成功");
|
}
|
|
@PostMapping("delete")
|
public Object delete(Integer id) {
|
barrierService.removeById(id);
|
return R.ok("删除成功");
|
}
|
|
@PostMapping("findAll")
|
public Object findAll(Long parkId) {
|
if (parkId==null) {
|
return R.failed("未发现该停车场");
|
}
|
QueryWrapper<Barrier> wrapper = new QueryWrapper<>();
|
wrapper.lambda()
|
.eq(Barrier::getParkId,parkId);
|
return R.ok(barrierService.list(wrapper));
|
}
|
|
@PostMapping("open")
|
public Object open(Long barrierId) {
|
Barrier b= barrierService.getById(barrierId);
|
if (b==null) {
|
return R.failed("未找到该道闸");
|
}
|
b.setType2(1);
|
b.setUpdateTime(LocalDateTime.now());
|
barrierService.saveOrUpdate(b);
|
return R.ok("请求成功");
|
}
|
|
@PostMapping("openBarrier")
|
public Object openBarrier(Long barrierId,Integer type) {
|
Barrier b= barrierService.getById(barrierId);
|
if (b==null) {
|
return R.failed("未找到该道闸");
|
}else {
|
if(b.getType() == 1){
|
System.out.println("手动开入口闸");
|
//入口闸,直接开启
|
b.setType2(1);
|
b.setUpdateTime(LocalDateTime.now());
|
barrierService.saveOrUpdate(b);
|
return R.ok("请求成功");
|
}else {
|
System.out.println("手动开出口闸");
|
//出口闸,判断状态
|
if(type == null || type == 0){
|
//取消计费
|
OutPark outPark = outParkService.findByCarNoAndBarrierId(b.getCarNo(), b.getId());
|
if(outPark != null){
|
outPark.setPrice(0);
|
outPark.setUpdateTime(LocalDateTime.now());
|
outParkService.saveOrUpdate(outPark);
|
}
|
b.setType2(1);
|
b.setUpdateTime(LocalDateTime.now());
|
barrierService.saveOrUpdate(b);
|
return R.ok("请求成功");
|
}else {
|
//计费
|
b.setType2(1);
|
b.setUpdateTime(LocalDateTime.now());
|
barrierService.saveOrUpdate(b);
|
return R.ok("请求成功");
|
}
|
}
|
}
|
}
|
}
|