| | |
| | | import com.ruoyi.basic.entity.CoalField; |
| | | import com.ruoyi.basic.mapper.CoalFieldMapper; |
| | | import com.ruoyi.basic.service.CoalFieldService; |
| | | import com.ruoyi.common.exception.base.BaseException; |
| | | import com.ruoyi.common.utils.bean.BeanUtils; |
| | | import lombok.RequiredArgsConstructor; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.util.StringUtils; |
| | | |
| | | import java.util.Collections; |
| | | import java.util.List; |
| | | import java.util.Objects; |
| | | import java.util.Set; |
| | | import java.util.regex.Matcher; |
| | | import java.util.regex.Pattern; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * <p> |
| | |
| | | return coalFieldMapper.selectList(null); |
| | | } |
| | | |
| | | @Override |
| | | public List<CoalFieldDto> getFieldsByNames(Set<String> fieldNames) { |
| | | // 1. 参数校验 |
| | | if (fieldNames == null || fieldNames.isEmpty()) { |
| | | throw new IllegalArgumentException("字段名集合不能为空"); |
| | | } |
| | | |
| | | // 2. 过滤空值 |
| | | Set<String> filteredNames = fieldNames.stream() |
| | | .filter(name -> name != null && !name.trim().isEmpty()) |
| | | .collect(Collectors.toSet()); |
| | | |
| | | if (filteredNames.isEmpty()) { |
| | | return Collections.emptyList(); |
| | | } |
| | | |
| | | // 3. 查询数据库 |
| | | try { |
| | | List<CoalField> entities = coalFieldMapper.getFieldsByNames(filteredNames); |
| | | |
| | | // 4. 实体转DTO |
| | | return entities.stream() |
| | | .map(this::convertToDto) |
| | | .collect(Collectors.toList()); |
| | | |
| | | } catch (Exception e) { |
| | | throw new BaseException("查询煤质字段信息失败,请稍后重试"); |
| | | } |
| | | } |
| | | |
| | | private CoalFieldDto convertToDto(CoalField entity) { |
| | | CoalFieldDto dto = new CoalFieldDto(); |
| | | dto.setId(entity.getId()); |
| | | dto.setFields(entity.getFields()); |
| | | dto.setFieldName(entity.getFieldName()); |
| | | return dto; |
| | | } |
| | | |
| | | @Override |
| | | public Set<String> getFieldNamesByNames(Set<String> fieldNames) { |
| | | return coalFieldMapper.getFieldNamesByNames(fieldNames); |
| | | } |
| | | |
| | | private String generateNextFieldNumber() { |
| | | // 获取所有已存在的 CoalField 记录,包括已删除的 |
| | | LambdaQueryWrapper<CoalField> queryWrapper = new LambdaQueryWrapper<>(); |