liding
12 小时以前 94509204d25f7c0ad213ae2322be2bd5bfd17424
basic-server/src/main/java/com/ruoyi/basic/service/impl/CoalFieldServiceImpl.java
@@ -9,15 +9,19 @@
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>
@@ -39,8 +43,8 @@
    @Override
    public IPage<CoalField> selectCoalFieldList(Page page, CoalFieldDto coalFieldDto) {
        LambdaQueryWrapper<CoalField> queryWrapper = new LambdaQueryWrapper<>();
        if (StringUtils.hasText(coalFieldDto.getFieldName())) {
            queryWrapper.like(CoalField::getFieldName, coalFieldDto.getFieldName());
        if (StringUtils.hasText(coalFieldDto.getSearchAll())) {
            queryWrapper.like(CoalField::getFieldName, coalFieldDto.getSearchAll());
        }
        queryWrapper.orderByDesc(CoalField::getCreateTime);
        return coalFieldMapper.selectPage(page, queryWrapper);
@@ -80,6 +84,49 @@
        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<>();