| | |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.ruoyi.basic.entity.CoalField; |
| | | import com.ruoyi.basic.entity.CoalValue; |
| | | import com.ruoyi.basic.mapper.CoalFieldMapper; |
| | | import com.ruoyi.basic.mapper.CoalValueMapper; |
| | | import com.ruoyi.business.dto.OfficialInventoryDto; |
| | | import com.ruoyi.business.entity.OfficialInventory; |
| | | import com.ruoyi.business.mapper.OfficialInventoryMapper; |
| | | import com.ruoyi.business.mapper.PendingInventoryMapper; |
| | | import com.ruoyi.business.service.OfficialInventoryService; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import org.springframework.stereotype.Service; |
| | | import com.ruoyi.common.utils.bean.BeanUtils; |
| | | import lombok.RequiredArgsConstructor; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * <p> |
| | |
| | | |
| | | private final OfficialInventoryMapper officialInventoryMapper; |
| | | |
| | | private final CoalValueMapper coalValueMapper; |
| | | |
| | | private final CoalFieldMapper coalFieldMapper; |
| | | |
| | | private final PendingInventoryMapper pendingInventoryMapper; |
| | | |
| | | @Override |
| | | public IPage<OfficialInventory> selectOfficialInventoryList(Page page, OfficialInventoryDto officialInventoryDto) { |
| | | public IPage<OfficialInventoryDto> selectOfficialInventoryList(Page page, OfficialInventoryDto officialInventoryDto) { |
| | | |
| | | // 先查出原始数据(OfficialInventory) |
| | | LambdaQueryWrapper<OfficialInventory> queryWrapper = new LambdaQueryWrapper<>(); |
| | | return officialInventoryMapper.selectPage(page, queryWrapper); |
| | | IPage<OfficialInventory> entityPage = officialInventoryMapper.selectPage(page, queryWrapper); |
| | | |
| | | // 创建一个新的 Dto 分页结果 |
| | | IPage<OfficialInventoryDto> dtoPage = new Page<>(); |
| | | BeanUtils.copyProperties(entityPage, dtoPage); |
| | | |
| | | List<OfficialInventoryDto> dtoList = new ArrayList<>(); |
| | | |
| | | // 查询所有可用字段(CoalField) |
| | | List<CoalField> coalFields = coalFieldMapper.selectList(null); |
| | | List<String> allFieldNames = coalFields.stream() |
| | | .map(CoalField::getFields) |
| | | .distinct() |
| | | .collect(Collectors.toList()); |
| | | |
| | | // 遍历每条记录,进行转换并填充 fields |
| | | for (OfficialInventory entity : entityPage.getRecords()) { |
| | | OfficialInventoryDto dto = new OfficialInventoryDto(); |
| | | BeanUtils.copyProperties(entity, dto); |
| | | |
| | | Long pendingId = entity.getPendingId(); |
| | | |
| | | // 查询该 pendingId 对应的 CoalValue 数据 |
| | | List<CoalValue> coalValues = coalValueMapper.selectList( |
| | | new LambdaQueryWrapper<CoalValue>().eq(CoalValue::getPlanId, pendingId) |
| | | ); |
| | | |
| | | // 构建 Map<fieldName, value> |
| | | Map<String, String> fieldValueMap = coalValues.stream() |
| | | .collect(Collectors.toMap( |
| | | CoalValue::getFields, |
| | | CoalValue::getCoalValue, |
| | | (existing, replacement) -> existing // 重复字段保留第一个 |
| | | )); |
| | | |
| | | // 构造最终 fields 列表,包含所有字段名,并设置默认值 "-" |
| | | List<Map<String, String>> fields = new ArrayList<>(); |
| | | for (String field : allFieldNames) { |
| | | Map<String, String> fieldMap = new HashMap<>(); |
| | | fieldMap.put(field, fieldValueMap.getOrDefault(field, "-")); |
| | | fields.add(fieldMap); |
| | | } |
| | | |
| | | // 设置到 DTO 中 |
| | | dto.setFields(fields); |
| | | dtoList.add(dto); |
| | | } |
| | | |
| | | dtoPage.setRecords(dtoList); // 设置转换后的 DtoList |
| | | return dtoPage; |
| | | } |
| | | } |