实时车辆进出数据和今日车位统计中利用率修改

This commit is contained in:
XinWei 2024-08-19 11:47:40 +08:00
parent 3021ea045a
commit 9306b3b653
3 changed files with 46 additions and 44 deletions

View File

@ -16,11 +16,13 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.util.List;
import java.util.Optional;
@Tag(name = "大屏服务 - 停车场接口")
@RestController
@RequestMapping("/datacenter/h5/vehicleAccess")
@ -45,7 +47,7 @@ public class VehicleAccessApi {
RevenueRepository revenueRepository;
@GetMapping("/list")
public ResponseVO list(){
public ResponseVO list() {
// 获取今天的日期
LocalDate today = LocalDate.now();
LocalDateTime startOfDay = LocalDateTime.of(today, LocalTime.MIN);
@ -61,13 +63,13 @@ public class VehicleAccessApi {
revenue.setPlate("京A 88888");
revenueRepository.insert(revenue);
return ResponseVO.success(200,"添加成功",null,0);
return ResponseVO.success(200, "添加成功", null, 0);
}
//获取实时车辆进出数据和今日车位统计
@GetMapping("/parkingLotData")
public ResponseVO parkAndVacancy(){
public ResponseVO parkAndVacancy() {
//时间最新的一条数据
@ -79,7 +81,7 @@ public class VehicleAccessApi {
ParkingLotDataVO parkingLotDataVO = new ParkingLotDataVO();
int parkingNum = heartbeat.getSpaceCount() - heartbeat.getFreeSpaceCount();
int residualStopNum = heartbeat.getSpaceCount() - parkingNum ;
int residualStopNum = heartbeat.getSpaceCount() - parkingNum;
//车辆进出实时数据
parkingLotDataVO.setParkingNum(parkingNum);//实时停车数
@ -99,28 +101,28 @@ public class VehicleAccessApi {
parkingLotDataVO.setTotalParkingSpace(heartbeat.getSpaceCount());//车位总数
parkingLotDataVO.setResidualTotal(residualStopNum);//余位总数
// 计算利用率
int useRatio = (parkingNum / residualStopNum) * 100;
Double useRatio = Math.round(((parkingNum * 1.0 / heartbeat.getSpaceCount()) * 10000)) / 100.0;
parkingLotDataVO.setUseRatio(useRatio);//总利用率
//设置区域停车场数据
for (int i = 0; i < heartbeat.getAreaList().size(); i++) {
AreaDataVO areaDataVO = new AreaDataVO();
areaDataVO.setAreaName(heartbeat.getAreaList().get(i).getAreaName());
areaDataVO.setParkingCount(heartbeat.getAreaList().get(i).getSpaceCount());
areaDataVO.setLastSpaceCount(heartbeat.getAreaList().get(i).getLastSpaceCount());
areaDataVO.setUseRatio((heartbeat.getAreaList().get(i).getLastSpaceCount() / heartbeat.getAreaList().get(i).getSpaceCount()) * 100);
// 计算利用率
areaDataVO.setUseRatio(Math.round((heartbeat.getAreaList().get(i).getLastSpaceCount() * 1.0 / heartbeat.getAreaList().get(i).getSpaceCount()) * 10000) / 100.0);
parkingLotDataVO.getAreaDataVOList().add(areaDataVO);
}
return ResponseVO.success(200,"",parkingLotDataVO,0);
return ResponseVO.success(200, "", parkingLotDataVO, 0);
}
return ResponseVO.error(500,"");
return ResponseVO.error(500, "");
}
//车辆进出趋势数据
@GetMapping("/tendencyChart")
public ResponseVO tendencyChart(){
public ResponseVO tendencyChart() {
ParkingLotDataVO parkingLotDataVO = new ParkingLotDataVO();
@ -156,27 +158,27 @@ public class VehicleAccessApi {
for (int i = 0; i < entryRecordList.size(); i++) {
EntryRecord entryRecord = entryRecordList.get(i);
if (entryRecord.getCreateTime().isAfter(startTime1) && entryRecord.getCreateTime().isBefore(endTime1)){
if (entryRecord.getCreateTime().isAfter(startTime1) && entryRecord.getCreateTime().isBefore(endTime1)) {
count1++;
continue;
}
if (entryRecord.getCreateTime().isAfter(startTime2) && entryRecord.getCreateTime().isBefore(endTime2)){
if (entryRecord.getCreateTime().isAfter(startTime2) && entryRecord.getCreateTime().isBefore(endTime2)) {
count2++;
continue;
}
if (entryRecord.getCreateTime().isAfter(startTime3) && entryRecord.getCreateTime().isBefore(endTime3)){
if (entryRecord.getCreateTime().isAfter(startTime3) && entryRecord.getCreateTime().isBefore(endTime3)) {
count3++;
continue;
}
if (entryRecord.getCreateTime().isAfter(startTime4) && entryRecord.getCreateTime().isBefore(endTime4)){
if (entryRecord.getCreateTime().isAfter(startTime4) && entryRecord.getCreateTime().isBefore(endTime4)) {
count4++;
continue;
}
if (entryRecord.getCreateTime().isAfter(startTime5) && entryRecord.getCreateTime().isBefore(endTime5)){
if (entryRecord.getCreateTime().isAfter(startTime5) && entryRecord.getCreateTime().isBefore(endTime5)) {
count5++;
continue;
}
if (entryRecord.getCreateTime().isAfter(startTime6) && entryRecord.getCreateTime().isBefore(endTime6)){
if (entryRecord.getCreateTime().isAfter(startTime6) && entryRecord.getCreateTime().isBefore(endTime6)) {
count6++;
}
}
@ -198,27 +200,27 @@ public class VehicleAccessApi {
for (int i = 0; i < appearanceRecordList.size(); i++) {
AppearanceRecord appearanceRecord = appearanceRecordList.get(i);
if (appearanceRecord.getCreateTime().isAfter(startTime1) && appearanceRecord.getCreateTime().isBefore(endTime1)){
if (appearanceRecord.getCreateTime().isAfter(startTime1) && appearanceRecord.getCreateTime().isBefore(endTime1)) {
count1++;
continue;
}
if (appearanceRecord.getCreateTime().isAfter(startTime2) && appearanceRecord.getCreateTime().isBefore(endTime2)){
if (appearanceRecord.getCreateTime().isAfter(startTime2) && appearanceRecord.getCreateTime().isBefore(endTime2)) {
count2++;
continue;
}
if (appearanceRecord.getCreateTime().isAfter(startTime3) && appearanceRecord.getCreateTime().isBefore(endTime3)){
if (appearanceRecord.getCreateTime().isAfter(startTime3) && appearanceRecord.getCreateTime().isBefore(endTime3)) {
count3++;
continue;
}
if (appearanceRecord.getCreateTime().isAfter(startTime4) && appearanceRecord.getCreateTime().isBefore(endTime4)){
if (appearanceRecord.getCreateTime().isAfter(startTime4) && appearanceRecord.getCreateTime().isBefore(endTime4)) {
count4++;
continue;
}
if (appearanceRecord.getCreateTime().isAfter(startTime5) && appearanceRecord.getCreateTime().isBefore(endTime5)){
if (appearanceRecord.getCreateTime().isAfter(startTime5) && appearanceRecord.getCreateTime().isBefore(endTime5)) {
count5++;
continue;
}
if (appearanceRecord.getCreateTime().isAfter(startTime6) && appearanceRecord.getCreateTime().isBefore(endTime6)){
if (appearanceRecord.getCreateTime().isAfter(startTime6) && appearanceRecord.getCreateTime().isBefore(endTime6)) {
count6++;
}
}
@ -230,13 +232,13 @@ public class VehicleAccessApi {
parkingLotDataVO.getOutCount().add(count5);
parkingLotDataVO.getOutCount().add(count6);
return ResponseVO.success(200,"",parkingLotDataVO,0);
return ResponseVO.success(200, "", parkingLotDataVO, 0);
}
//车辆出入实时记录图
@GetMapping("/recordOfAccess")
public ResponseVO recordOfAccess(int page){
public ResponseVO recordOfAccess(int page) {
// 获取今天的日期
LocalDate today = LocalDate.now();
@ -249,13 +251,13 @@ public class VehicleAccessApi {
Pageable pageable = PageRequest.of(page, 4);
// Page<VehicleRecord> recordOfAccessList = vehicleRecordRepository.findByCreateTimeBetweenOrderByCreateTimeAsc(startOfDay, endOfDay, pageable);
Page<VehicleRecord> recordOfAccessList = vehicleRecordRepository.findAll(pageable); // TODO 暂时获取全部数据分页
return ResponseVO.success(200,"",recordOfAccessList,total);
return ResponseVO.success(200, "", recordOfAccessList, total);
}
//车辆营收统计
@GetMapping("/revenue")
public ResponseVO revenue(String date,String areaName){
public ResponseVO revenue(String date, String areaName) {
List<Revenue> revenueList;
@ -263,25 +265,25 @@ public class VehicleAccessApi {
LocalDateTime endOfDay = null;
if (date.equals("今日")){
if (date.equals("今日")) {
// 获取今天的日期
LocalDate today = LocalDate.now();
startOfDay = LocalDateTime.of(today, LocalTime.MIN);
endOfDay = LocalDateTime.of(today, LocalTime.MAX);
}
if (date.equals("近一周")){
if (date.equals("近一周")) {
endOfDay = LocalDateTime.now(); // 结束时间为当前时间
startOfDay = endOfDay.minusDays(7); // 开始时间为当前时间的前7天
}
if (date.equals("近一月")){
if (date.equals("近一月")) {
endOfDay = LocalDateTime.now(); // 结束时间为当前时间
startOfDay = endOfDay.minusMonths(1); // 开始时间为当前时间的前一个月
}
if (areaName.equals("全部")){
if (areaName.equals("全部")) {
revenueList = revenueRepository.findByCreateTimeBetween(startOfDay, endOfDay);
}else {
} else {
revenueList = revenueRepository.findByCreateTimeAndAreaName(startOfDay, endOfDay, areaName);
}
@ -297,15 +299,15 @@ public class VehicleAccessApi {
for (int i = 0; i < revenueList.size(); i++) {
Revenue revenue = revenueList.get(i);
BigDecimal charge = new BigDecimal(revenue.getPayCharge());
if (revenue.getPayKind().equals("现金")){
if (revenue.getPayKind().equals("现金")) {
xj = xj.add(charge);
} else if (revenue.getPayKind().equals("微信")){
} else if (revenue.getPayKind().equals("微信")) {
wx = wx.add(charge);
} else if (revenue.getPayKind().equals("支付宝")){
} else if (revenue.getPayKind().equals("支付宝")) {
zfb = zfb.add(charge);
} else if (revenue.getPayKind().equals("银联")){
} else if (revenue.getPayKind().equals("银联")) {
yl = yl.add(charge);
} else if (revenue.getPayKind().equals("公交卡")){
} else if (revenue.getPayKind().equals("公交卡")) {
gjk = gjk.add(charge);
}
}
@ -322,18 +324,15 @@ public class VehicleAccessApi {
revenueVO.setZfb(zfb);
return ResponseVO.success(200,"",revenueVO ,0);
return ResponseVO.success(200, "", revenueVO, 0);
}
//预警信息栏
@GetMapping("/warning_information_bar")
public ResponseVO warningInformation(){
return ResponseVO.success(200,"今日实时客流人数125同比上月实时人数提升12%。今日车辆数量135同比上月实时人数提升13%。今日沿海阵风3级.....",null ,0);
public ResponseVO warningInformation() {
return ResponseVO.success(200, "今日实时客流人数125同比上月实时人数提升12%。今日车辆数量135同比上月实时人数提升13%。今日沿海阵风3级.....", null, 0);
}
}

View File

@ -2,6 +2,8 @@ package cn.iocoder.yudao.module.datacenter.controller.admin.vehicleaccess.vo;
import lombok.Data;
import java.math.BigDecimal;
@Data
public class AreaDataVO {
@ -15,5 +17,5 @@ public class AreaDataVO {
private int lastSpaceCount;
//区域利用率
private int useRatio;
private Double useRatio;
}

View File

@ -2,6 +2,7 @@ package cn.iocoder.yudao.module.datacenter.controller.admin.vehicleaccess.vo;
import lombok.Data;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
@ -30,7 +31,7 @@ public class ParkingLotDataVO {
private int residualTotal;
//总利用率
private int useRatio;
private Double useRatio;
//区域停车场数据集合
private List<AreaDataVO> areaDataVOList = new ArrayList<>();