| | |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.toolkit.IdWorker; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.jeecg.common.constant.CommonConstant; |
| | | import org.jeecg.common.constant.FillRuleConstant; |
| | |
| | | return Collections.emptyList(); |
| | | } |
| | | |
| | | public BaseFactory searchCenterByKeyWord(String keyWord) { |
| | | if (StringUtils.isBlank(keyWord)) { |
| | | return null; |
| | | } |
| | | |
| | | if (keyWord.contains("/")) { |
| | | return searchByHierarchy(keyWord); |
| | | } else { |
| | | return searchByCodeOrName(keyWord); |
| | | } |
| | | } |
| | | |
| | | private BaseFactory searchByHierarchy(String path) { |
| | | String[] levels = path.split("/"); |
| | | int depth = levels.length; |
| | | |
| | | // 支持多种格式:中心/工区、中心/工段、中心/工区/工段 |
| | | if (depth < 2 || depth > 3) { |
| | | return null; |
| | | } |
| | | |
| | | // 从底层开始查询:最后一级可能是工区或工段 |
| | | String lastName = levels[depth - 1]; |
| | | BaseFactory lastLevel = searchForLastLevel(lastName); |
| | | if (lastLevel == null) return null; |
| | | |
| | | return validatePath(levels, lastLevel); |
| | | } |
| | | |
| | | private BaseFactory validatePath(String[] levels, BaseFactory lastLevel) { |
| | | if (levels.length == 2) { |
| | | // 中心/工区 或 中心/工段 |
| | | BaseFactory center = findParentCenter(lastLevel); |
| | | if (center != null && |
| | | center.getFactoryName().equals(levels[0]) && |
| | | ("1").equals(center.getFactoryCategory())) { |
| | | return lastLevel; |
| | | } |
| | | } else { |
| | | // 中心/工区/工段 |
| | | if (!("3").equals(lastLevel.getFactoryCategory())) return null; |
| | | |
| | | BaseFactory workArea = getById(lastLevel.getParentId()); |
| | | if (workArea == null || |
| | | !("2").equals(workArea.getFactoryCategory())) return null; |
| | | |
| | | BaseFactory center = getById(workArea.getParentId()); |
| | | if (center == null || |
| | | !("1").equals(center.getFactoryCategory())) return null; |
| | | |
| | | if (workArea.getFactoryName().equals(levels[1]) && |
| | | center.getFactoryName().equals(levels[0])) { |
| | | return lastLevel; |
| | | } |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | private BaseFactory searchForLastLevel(String name) { |
| | | // 先尝试查询工段(类别3) |
| | | BaseFactory workshop = findFactory(name, 3, null); |
| | | if (workshop != null) return workshop; |
| | | |
| | | // 如果没有找到工段,尝试查询工区(类别2) |
| | | return findFactory(name, 2, null); |
| | | } |
| | | |
| | | private BaseFactory findParentCenter(BaseFactory entity) { |
| | | if (("1").equals(entity.getFactoryCategory())) { |
| | | return entity; // 本身就是中心 |
| | | } |
| | | |
| | | BaseFactory parent = getById(entity.getParentId()); |
| | | if (parent == null) return null; |
| | | |
| | | if (("1").equals(parent.getFactoryCategory())) { |
| | | return parent; // 直接父级是中心 |
| | | } |
| | | |
| | | // 如果父级不是中心,尝试找父级的父级 |
| | | return getById(parent.getParentId()); |
| | | } |
| | | |
| | | private BaseFactory searchByCodeOrName(String keyword) { |
| | | // 使用分页方式兼容SQL Server |
| | | LambdaQueryWrapper<BaseFactory> query = new LambdaQueryWrapper<>(); |
| | | query.and(q -> q.eq(BaseFactory::getFactoryName, keyword) |
| | | .or() |
| | | .like(BaseFactory::getFactoryCode, keyword)); |
| | | |
| | | // 使用分页查询获取第一条记录 |
| | | Page<BaseFactory> page = new Page<>(1, 1); |
| | | Page<BaseFactory> resultPage = baseMapper.selectPage(page, query); |
| | | |
| | | return resultPage.getRecords().isEmpty() ? null : resultPage.getRecords().get(0); |
| | | } |
| | | |
| | | private BaseFactory findFactory(String name, Integer category, String parentId) { |
| | | LambdaQueryWrapper<BaseFactory> query = new LambdaQueryWrapper<>(); |
| | | query.eq(BaseFactory::getFactoryName, name); |
| | | |
| | | if (category != null) query.eq(BaseFactory::getFactoryCategory, category); |
| | | if (parentId != null) query.eq(BaseFactory::getParentId, parentId); |
| | | |
| | | // 使用分页方式兼容SQL Server |
| | | Page<BaseFactory> page = new Page<>(1, 1); |
| | | Page<BaseFactory> resultPage = baseMapper.selectPage(page, query); |
| | | |
| | | return resultPage.getRecords().isEmpty() ? null : resultPage.getRecords().get(0); |
| | | } |
| | | |
| | | private BaseFactory getById(String id) { |
| | | if (StringUtils.isBlank(id)) return null; |
| | | return baseMapper.selectById(id); |
| | | } |
| | | |
| | | /** |
| | | * saveProductionData 对应 add 保存用户在页面添加的新的设备车间管理对象数据 |
| | |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 通过orgCode置换中心名称 |
| | | * @param orgCode |
| | | */ |
| | | @Override |
| | | public String factoryDataNameByOrgCode(String orgCode){ |
| | | BaseFactory baseFactory = baseMapper.selectOne(new LambdaQueryWrapper<BaseFactory>().eq(BaseFactory::getOrgCode, orgCode)); |
| | | if (baseFactory != null) { |
| | | return baseFactory.getFactoryName(); |
| | | } |
| | | return null; |
| | | } |
| | | } |