Merge remote-tracking branch 'origin/develop' into zhanghongwei_branch

# Conflicts:
#	src/main/java/com/campus/water/service/AreaService.java
pull/150/head
ZHW 2 months ago
commit e25b6c9c8c

@ -2,6 +2,7 @@ package com.campus.water.controller.web;
import com.campus.water.entity.Area;
import com.campus.water.service.AreaService;
import com.campus.water.entity.vo.AreaDeviceStatsVO;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
@ -148,4 +149,47 @@ public class AreaController {
.body(buildResponse(500, "查询区域详情失败:" + e.getMessage(), null));
}
}
/**
*
* //
*
*/
@GetMapping("/device-stats/{areaId}")
@PreAuthorize("hasAnyRole('SUPER_ADMIN', 'AREA_ADMIN')")
public ResponseEntity<Map<String, Object>> getAreaDeviceStats(@PathVariable String areaId) {
try {
AreaDeviceStatsVO statsVO = areaService.getAreaDeviceStats(areaId);
return ResponseEntity.ok(buildResponse(200, "统计成功", statsVO));
} catch (RuntimeException e) {
// 业务异常片区不存在、参数错误等返回400
return ResponseEntity.badRequest().body(buildResponse(400, e.getMessage(), null));
} catch (Exception e) {
// 系统异常返回500
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR)
.body(buildResponse(500, "统计片区设备失败:" + e.getMessage(), null));
}
}
/**
*
* //
*
*/
@GetMapping("/device-stats/city/{cityId}/campuses")
@PreAuthorize("hasAnyRole('SUPER_ADMIN', 'AREA_ADMIN')")
public ResponseEntity<Map<String, Object>> getCampusDeviceStatsUnderCity(@PathVariable String cityId) {
try {
List<AreaDeviceStatsVO> statsVOList = areaService.getCampusDeviceStatsUnderCity(cityId);
return ResponseEntity.ok(buildResponse(200, "统计成功", statsVOList));
} catch (RuntimeException e) {
// 业务异常非市区、市区不存在等返回400
return ResponseEntity.badRequest().body(buildResponse(400, e.getMessage(), null));
} catch (Exception e) {
// 系统异常返回500
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR)
.body(buildResponse(500, "统计市区下属校区设备失败:" + e.getMessage(), null));
}
}
}

@ -0,0 +1,16 @@
package com.campus.water.entity.vo;
import lombok.Data;
/**
* VO
*/
@Data
public class AreaDeviceStatsVO {
private String areaId; // 对应Area.areaId
private String areaName; // 对应Area.areaName
private String areaTypeDesc; // 对应Area.AreaType.desc市区/校园)
private int waterMakerCount; // 制水机数量
private int waterSupplyCount; // 供水机数量
private int terminalCount; // 终端数量基于DeviceTerminalMapping
}

@ -48,4 +48,6 @@ public interface DeviceRepository extends JpaRepository<Device, String> {
// 按设备类型加载加载设备(支持区域筛选)
List<Device> findByDeviceTypeAndAreaId(Device.DeviceType deviceType, String areaId);
long countByAreaIdAndDeviceType(String areaId, Device.DeviceType deviceType);
}

@ -30,4 +30,6 @@ public interface DeviceTerminalMappingRepository extends JpaRepository<DeviceTer
// 3. 按终端ID删除所有关联映射删除终端时级联清理映射数据
void deleteByTerminalId(String terminalId);
long countByAreaId(String areaId);
}
Loading…
Cancel
Save