feat: 按监测设备类型统计数量

dev
huangfeng 1 year ago
parent e056034fce
commit 6cfa65c2ed

@ -30,6 +30,13 @@ public class ModevTypeController extends BasicController {
return Response.success(result); return Response.success(result);
} }
@GetMapping("listAllCount")
@ApiOperation("查询数量列表")
public Response<List<ModevType>> listAllCount() {
List<ModevType> result = service.listAllCount();
return Response.success(result);
}
@PostMapping("add") @PostMapping("add")
@ApiOperation("新增") @ApiOperation("新增")
public Response<ModevType> add(@Validated @RequestBody ModevType item) throws Exception { public Response<ModevType> add(@Validated @RequestBody ModevType item) throws Exception {

@ -36,4 +36,6 @@ public class ModevType {
private String tablename; private String tablename;
@Transient
private long sensorCount;
} }

@ -23,5 +23,7 @@ public interface NSensorRepository extends JpaRepository<NSensor, Integer>, JpaS
List<NSensor> findByDevId(Integer devId); List<NSensor> findByDevId(Integer devId);
long countByZsbIdIn(List<Integer> list); Long countByZsbIdIn(List<Integer> list);
Long countByTypeId(Integer typeId);
} }

@ -8,6 +8,8 @@ public interface ModevTypeService {
List<ModevType> listAll(); List<ModevType> listAll();
List<ModevType> listAllCount();
ModevType add(ModevType item) throws Exception; ModevType add(ModevType item) throws Exception;
void update(ModevType item) throws Exception; void update(ModevType item) throws Exception;

@ -33,6 +33,16 @@ public class ModevTypeServiceImpl implements ModevTypeService {
return repository.findAll(); return repository.findAll();
} }
@Override
public List<ModevType> listAllCount() {
List<ModevType> list = repository.findAll();
for (ModevType modevType : list) {
long count = sensorRepository.countByTypeId(modevType.getId());
modevType.setSensorCount(count);
}
return list;
}
@Override @Override
public ModevType add(ModevType item) throws Exception { public ModevType add(ModevType item) throws Exception {
item.setId(null); item.setId(null);

Loading…
Cancel
Save