Sfoglia il codice sorgente

站点可用车位数

skyline 1 anno fa
parent
commit
9d8fc55aa3

+ 88 - 0
car-wash-entity/src/main/java/com/kym/entity/miniapp/vo/WashStationVo.java

@@ -0,0 +1,88 @@
+package com.kym.entity.miniapp.vo;
+
+import com.kym.entity.BaseEntity;
+import lombok.Data;
+
+/**
+ * 洗车站点表
+ */
+@Data
+public class WashStationVo extends BaseEntity {
+
+    private static final long serialVersionUID = 1L;
+
+    /**
+     * 站点id
+     */
+    private String stationId;
+
+    /**
+     * 站点名称
+     */
+    private String stationName;
+
+    /**
+     * 地址
+     */
+    private String address;
+
+    /**
+     * 站点电话
+     */
+    private String stationTel;
+
+    /**
+     * 服务电话
+     */
+    private String serviceTel;
+
+    /**
+     * 站点类型:Public:公共站 2:Private:内部站(不对外开放)
+     */
+    private String stationType;
+
+    /**
+     * 站点状态:Unknown:未知,Normal:正常运营,Offline:关闭下线,Repair:维护中
+     */
+    private String stationStatus;
+
+    /**
+     * 空闲工位数量
+     */
+    private Integer idleParkingNum;
+
+    /**
+     * 工位数量
+     */
+    private Integer parkingNum;
+
+    /**
+     * 停车费描述:eg:洗车费用满10元减免1小时停车费
+     */
+    private String parkingFee;
+
+    /**
+     * 站点坐标
+     */
+    private String location;
+
+    /**
+     * 站点引导
+     */
+    private String siteGuide;
+
+    /**
+     * 站点照片
+     */
+    private String pictures;
+
+    /**
+     * 营业时间描述
+     */
+    private String businessHours;
+
+    /**
+     * 备注
+     */
+    private String remark;
+}

+ 2 - 1
car-wash-service/src/main/java/com/kym/service/miniapp/WashStationService.java

@@ -3,6 +3,7 @@ package com.kym.service.miniapp;
 import com.kym.entity.common.PageBean;
 import com.kym.entity.miniapp.WashStation;
 import com.kym.entity.miniapp.queryParams.StationQueryParams;
+import com.kym.entity.miniapp.vo.WashStationVo;
 import com.kym.service.mybatisplus.MyBaseService;
 
 /**
@@ -16,7 +17,7 @@ import com.kym.service.mybatisplus.MyBaseService;
 public interface WashStationService extends MyBaseService<WashStation> {
 
     //region 小程序接口
-    PageBean<WashStation> listStationForApp(StationQueryParams params);
+    PageBean<WashStationVo> listStationForApp(StationQueryParams params);
     //endregion
 
 

+ 31 - 13
car-wash-service/src/main/java/com/kym/service/miniapp/impl/WashStationServiceImpl.java

@@ -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);
 
     }