| | |
| | | package org.jeecg.modules.system.service.impl; |
| | | |
| | | import cn.hutool.core.collection.CollectionUtil; |
| | | import cn.hutool.core.util.StrUtil; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | 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; |
| | | import org.jeecg.common.exception.JeecgBootException; |
| | | import org.jeecg.common.util.FillRuleUtil; |
| | | import org.jeecg.common.util.OrgCodeSplitUtil; |
| | | import org.jeecg.common.util.oConvertUtils; |
| | | import org.jeecg.modules.system.entity.BaseFactory; |
| | | import org.jeecg.modules.system.entity.BaseFactoryUser; |
| | |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * @Description: 设备车间管理 |
| | |
| | | if (keyWord.contains("/")) { |
| | | return searchByHierarchy(keyWord); |
| | | } else { |
| | | return searchByCode(keyWord); |
| | | return searchByCodeOrName(keyWord); |
| | | } |
| | | } |
| | | |
| | |
| | | String[] levels = path.split("/"); |
| | | int depth = levels.length; |
| | | |
| | | // 检查层级深度 |
| | | // 支持格式:中心/工区、中心/工段、中心/工区/工段 |
| | | if (depth < 2 || depth > 3) { |
| | | return null; // 无效的层级深度 |
| | | return null; |
| | | } |
| | | |
| | | // 查询第一级中心 |
| | | // 从顶层开始查询 - 第1级:中心节点 |
| | | BaseFactory center = findFactory(levels[0], 1, null); |
| | | if (center == null) return null; |
| | | |
| | | // 查询第二级工区 |
| | | BaseFactory workArea = findFactory(levels[1], null, center.getId()); |
| | | if (workArea == null || depth == 2) return workArea; |
| | | // 第2级查询:工区或工段 |
| | | BaseFactory secondLevel; |
| | | if (depth == 2) { |
| | | // 兼容方案:优先查工段再查工区 |
| | | secondLevel = findFactory(levels[1], 3, center.getId()); |
| | | if (secondLevel == null) { |
| | | secondLevel = findFactory(levels[1], 2, center.getId()); |
| | | } |
| | | return secondLevel; // 可能为null |
| | | } else { |
| | | // 第2级必须是工区 |
| | | BaseFactory workArea = findFactory(levels[1], 2, center.getId()); |
| | | if (workArea == null) return null; |
| | | |
| | | // 查询第三级工段 |
| | | return findFactory(levels[2], null, workArea.getId()); |
| | | // 第3级:工段 |
| | | return findFactory(levels[2], 3, workArea.getId()); |
| | | } |
| | | } |
| | | |
| | | private BaseFactory searchByCode(String code) { |
| | | // 保持不变 |
| | | private BaseFactory searchByCodeOrName(String keyword) { |
| | | LambdaQueryWrapper<BaseFactory> query = new LambdaQueryWrapper<>(); |
| | | query.like(BaseFactory::getFactoryCode, code); |
| | | return this.baseMapper.selectOne(query); // 使用selectOne避免多个结果 |
| | | 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); |
| | | |
| | | return this.baseMapper.selectOne(query); |
| | | Page<BaseFactory> page = new Page<>(1, 1); |
| | | Page<BaseFactory> resultPage = baseMapper.selectPage(page, query); |
| | | return resultPage.getRecords().isEmpty() ? null : resultPage.getRecords().get(0); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 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; |
| | | } |
| | | |
| | | @Override |
| | | public List<String> queryFactoryIdsByOrgCode(String orgCode) { |
| | | //分割 orgCode |
| | | List<String> orgCodeArr = OrgCodeSplitUtil.splitOrgCode(orgCode); |
| | | if(CollectionUtil.isEmpty(orgCodeArr)){ |
| | | return Collections.emptyList(); |
| | | } |
| | | LambdaQueryWrapper<BaseFactory> query = new LambdaQueryWrapper<>(); |
| | | query.in(BaseFactory::getOrgCode, orgCodeArr); |
| | | query.eq(BaseFactory::getDelFlag, CommonConstant.DEL_FLAG_0); |
| | | List<BaseFactory> list = this.getBaseMapper().selectList(query); |
| | | Set<String> collect = list.stream().map(BaseFactory::getId).collect(Collectors.toSet()); |
| | | if(CollectionUtil.isEmpty(collect)){ |
| | | return Collections.emptyList(); |
| | | } |
| | | return new ArrayList<>(collect); |
| | | } |
| | | } |