|
|
@@ -3,14 +3,19 @@ package com.kym.service.miniapp.impl;
|
|
|
import com.github.pagehelper.PageHelper;
|
|
|
import com.kym.common.utils.CommUtil;
|
|
|
import com.kym.entity.common.PageBean;
|
|
|
+import com.kym.entity.miniapp.WashDevice;
|
|
|
import com.kym.entity.miniapp.WashStation;
|
|
|
import com.kym.entity.miniapp.queryParams.StationQueryParams;
|
|
|
+import com.kym.entity.miniapp.vo.WashStationVo;
|
|
|
import com.kym.mapper.miniapp.WashStationMapper;
|
|
|
+import com.kym.service.miniapp.WashDeviceService;
|
|
|
import com.kym.service.miniapp.WashStationService;
|
|
|
import com.kym.service.mybatisplus.MyBaseServiceImpl;
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.util.List;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* <p>
|
|
|
@@ -23,32 +28,38 @@ import java.util.List;
|
|
|
@Service
|
|
|
public class WashStationServiceImpl extends MyBaseServiceImpl<WashStationMapper, WashStation> implements WashStationService {
|
|
|
|
|
|
+ private final WashDeviceService washDeviceService;
|
|
|
+
|
|
|
+ public WashStationServiceImpl(WashDeviceService washDeviceService) {
|
|
|
+ this.washDeviceService = washDeviceService;
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
// ====================================================== 运营平台接口 Start ===========================================================
|
|
|
|
|
|
@Override
|
|
|
public void add(WashStation station) {
|
|
|
- CommUtil.assertsNonNulls(List.of(station.getStationName(),station.getStationId(),station.getStationType()),"参数异常");
|
|
|
+ CommUtil.assertsNonNulls(List.of(station.getStationName(), station.getStationId(), station.getStationType()), "参数异常");
|
|
|
Long count = lambdaQuery().eq(WashStation::getStationName, station.getStationName()).count();
|
|
|
- CommUtil.asserts(count==0,"站点已存在");
|
|
|
+ CommUtil.asserts(count == 0, "站点已存在");
|
|
|
save(station);
|
|
|
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void modify(WashStation station) {
|
|
|
- CommUtil.assertsNonNulls(List.of(station.getStationName(),station.getStationId(),station.getStationType(),station.getId()),"参数异常");
|
|
|
+ CommUtil.assertsNonNulls(List.of(station.getStationName(), station.getStationId(), station.getStationType(), station.getId()), "参数异常");
|
|
|
List<WashStation> list = lambdaQuery().eq(WashStation::getStationName, station.getStationName()).list();
|
|
|
- CommUtil.asserts(list.size()<=1,"站点信息异常");
|
|
|
- if(list.size()==1){
|
|
|
- CommUtil.asserts(list.get(0).getStationName().equalsIgnoreCase(station.getStationName()),"站点已存在");
|
|
|
+ CommUtil.asserts(list.size() <= 1, "站点信息异常");
|
|
|
+ if (list.size() == 1) {
|
|
|
+ CommUtil.asserts(list.get(0).getStationName().equalsIgnoreCase(station.getStationName()), "站点已存在");
|
|
|
}
|
|
|
updateById(station);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public PageBean<WashStation> list(StationQueryParams query) {
|
|
|
- PageHelper.startPage(query.getPageNum(),query.getPageSize());
|
|
|
+ PageHelper.startPage(query.getPageNum(), query.getPageSize());
|
|
|
List<WashStation> list = lambdaQuery()
|
|
|
.like(CommUtil.isNotEmptyAndNull(query.getStationName()), WashStation::getStationName, query.getStationName())
|
|
|
.like(CommUtil.isNotEmptyAndNull(query.getAddress()), WashStation::getAddress, query.getAddress())
|
|
|
@@ -69,17 +80,24 @@ public class WashStationServiceImpl extends MyBaseServiceImpl<WashStationMapper,
|
|
|
// ====================================================== 运营平台接口 Start ===========================================================
|
|
|
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
// ====================================================== 小程序接口 Start ===========================================================
|
|
|
@Override
|
|
|
- public PageBean<WashStation> listStationForApp(StationQueryParams params) {
|
|
|
+ public PageBean<WashStationVo> listStationForApp(StationQueryParams params) {
|
|
|
PageHelper.startPage(params.getPageNum(), params.getPageSize());
|
|
|
- var res = lambdaQuery()
|
|
|
+ var stationList = lambdaQuery()
|
|
|
.like(CommUtil.isNotEmptyAndNull(params.getStationName()), WashStation::getStationName, params.getStationName())
|
|
|
.list();
|
|
|
- return new PageBean<>(res);
|
|
|
+ // 查询站点下的所有设备,按照站点统计可用设备数量
|
|
|
+ var res = washDeviceService.lambdaQuery().in(WashDevice::getStationId, stationList.stream().map(WashStation::getStationId).toList())
|
|
|
+ .eq(WashDevice::getState, WashDevice.STATE_空闲)
|
|
|
+ .list().stream().collect(Collectors.groupingBy(WashDevice::getStationId, Collectors.counting()));
|
|
|
+ var voList = stationList.stream().map(station -> {
|
|
|
+ var vo = new WashStationVo();
|
|
|
+ BeanUtils.copyProperties(station, vo);
|
|
|
+ vo.setIdleParkingNum(Math.toIntExact(res.getOrDefault(station.getStationId(), 0L)));
|
|
|
+ return vo;
|
|
|
+ }).toList();
|
|
|
+ return new PageBean<>(voList);
|
|
|
|
|
|
}
|
|
|
|