feat(meter): 添加计量设备最近读数查询功能
- 引入 EmsEnergyConsumption 和 EmsEnergyConsumptionMapper 依赖 - 注入 consumptionMapper 用于查询能耗数据 - 在查询分页列表时为每个计量设备添加最近读数信息 - 从能耗消费表查询最近的两条读数并取最新一条作为最后读数 - 在 EmsMeterVo 中添加 lastReading 字段用于存储最后读数
This commit is contained in:
@@ -101,4 +101,6 @@ public class EmsMeterVo {
|
||||
@ExcelIgnore
|
||||
private String warehouseName;
|
||||
|
||||
//最后一次读数
|
||||
private BigDecimal lastReading;
|
||||
}
|
||||
|
||||
@@ -8,6 +8,8 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.klp.common.utils.StringUtils;
|
||||
import com.klp.common.utils.poi.ExcelUtil;
|
||||
import com.klp.ems.domain.EmsEnergyConsumption;
|
||||
import com.klp.ems.mapper.EmsEnergyConsumptionMapper;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
@@ -41,6 +43,8 @@ public class EmsMeterServiceImpl implements IEmsMeterService {
|
||||
private final EmsMeterMapper baseMapper;
|
||||
private final EmsEnergyTypeMapper energyTypeMapper;
|
||||
|
||||
private final EmsEnergyConsumptionMapper consumptionMapper;
|
||||
|
||||
/**
|
||||
* 查询计量设备(阈值移至此处)
|
||||
*/
|
||||
@@ -56,6 +60,15 @@ public class EmsMeterServiceImpl implements IEmsMeterService {
|
||||
public TableDataInfo<EmsMeterVo> queryPageList(EmsMeterBo bo, PageQuery pageQuery) {
|
||||
LambdaQueryWrapper<EmsMeter> lqw = buildQueryWrapper(bo);
|
||||
Page<EmsMeterVo> result = baseMapper.selectVoPage(pageQuery.build(), lqw);
|
||||
result.getRecords().forEach(vo -> {
|
||||
// 根据计量设备的 ID 查询最近的读数
|
||||
List<EmsEnergyConsumption> emsEnergyConsumptions = consumptionMapper.selectLatestTwoReadings(vo.getMeterId());
|
||||
// 由于是最近的两条只需要最新的一条即可
|
||||
if (emsEnergyConsumptions != null && !emsEnergyConsumptions.isEmpty()) {
|
||||
EmsEnergyConsumption latestReading = emsEnergyConsumptions.get(0);
|
||||
vo.setLastReading(latestReading.getEndReading());
|
||||
}
|
||||
});
|
||||
return TableDataInfo.build(result);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user