| | |
| | | import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import io.micrometer.core.instrument.binder.BaseUnits; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.apache.shiro.SecurityUtils; |
| | | import org.jeecg.common.constant.CommonConstant; |
| | |
| | | import org.jeecg.common.system.vo.LoginUser; |
| | | import org.jeecg.common.util.oConvertUtils; |
| | | import org.jeecg.modules.eam.aspect.annotation.EquipmentHistoryLog; |
| | | import org.jeecg.modules.eam.base.entity.BaseFactory; |
| | | import org.jeecg.modules.eam.base.entity.BaseFactoryUser; |
| | | import org.jeecg.modules.eam.base.service.IBaseFactoryService; |
| | | import org.jeecg.modules.eam.base.service.IBaseFactoryUserService; |
| | | import org.jeecg.modules.eam.constant.AssetStatusEnum; |
| | | import org.jeecg.modules.eam.constant.EquipmentMaintenanceStatus; |
| | | import org.jeecg.modules.eam.constant.EquipmentOperationTagEnum; |
| | | import org.jeecg.modules.eam.constant.EquipmentRepairStatus; |
| | | import org.jeecg.modules.eam.constant.*; |
| | | import org.jeecg.modules.eam.entity.EamEquipment; |
| | | import org.jeecg.modules.eam.entity.EamEquipmentExtend; |
| | | import org.jeecg.modules.eam.mapper.EamEquipmentMapper; |
| | | import org.jeecg.modules.eam.request.EamEquipmentQuery; |
| | | import org.jeecg.modules.eam.service.IEamEquipmentExtendService; |
| | | import org.jeecg.modules.eam.service.IEamEquipmentService; |
| | | import org.jeecg.modules.eam.tree.FindsEquipmentEamCenterUtil; |
| | | import org.jeecg.modules.eam.tree.FindsEquipmentProductionUtil; |
| | | import org.jeecg.modules.eam.vo.EamEquipmentTree; |
| | | import org.jeecg.modules.eam.vo.EquipmentSearchResult; |
| | | import org.jeecg.modules.system.entity.BaseFactory; |
| | | import org.jeecg.modules.system.entity.BaseFactoryUser; |
| | | import org.jeecg.modules.system.entity.MdcProduction; |
| | | import org.jeecg.modules.system.service.IBaseFactoryService; |
| | | import org.jeecg.modules.system.service.IBaseFactoryUserService; |
| | | import org.jeecg.modules.system.service.IMdcProductionService; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.util.ArrayList; |
| | | import java.util.Arrays; |
| | | import java.util.Collections; |
| | | import java.util.List; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | |
| | | return treeList; |
| | | } |
| | | |
| | | /** |
| | | * 获取EAM中心下的设备信息 |
| | | * @param ids EAM中心ids |
| | | * @return |
| | | */ |
| | | @Override |
| | | public List<EamEquipmentTree> loadTreeListByEamCenterIds(String ids){ |
| | | List<String> baseFactoryIds = Arrays.asList(ids.split(",")); |
| | | //获取所有EAM数据 |
| | | List<BaseFactory> baseFactoryList = baseFactoryService.list(new LambdaQueryWrapper<BaseFactory>().eq(BaseFactory::getDelFlag, CommonConstant.DEL_FLAG_0.toString()).orderByAsc(BaseFactory::getSorter)); |
| | | List<String> allBaseFactoryIds = new ArrayList<>(); |
| | | //找到所有产线id的上级id |
| | | if (!baseFactoryIds.isEmpty()) { |
| | | for (String baseFactoryId : baseFactoryIds) { |
| | | this.getAllBaseFactoryIds(baseFactoryList, baseFactoryId, allBaseFactoryIds); |
| | | } |
| | | } |
| | | //过滤EAM数据 |
| | | List<BaseFactory> list = baseFactoryList.stream().filter((BaseFactory baseFactory) -> allBaseFactoryIds.contains(baseFactory.getId())).collect(Collectors.toList()); |
| | | //组装EAM设备树 |
| | | List<EamEquipmentTree> treeList = FindsEquipmentEamCenterUtil.wrapEquipmentBaseFactoryTreeList(list); |
| | | //填充设备数据 |
| | | fillEquipmentByBaseFactory(treeList); |
| | | return treeList; |
| | | } |
| | | |
| | | @Override |
| | | public IPage<EamEquipment> queryPageList(IPage<EamEquipment> page, EamEquipmentQuery eamEquipment) { |
| | | QueryWrapper<EamEquipment> queryWrapper = new QueryWrapper<>(); |
| | |
| | | List<BaseFactoryUser> baseFactoryUserList=baseFactoryUserService. |
| | | list(new LambdaQueryWrapper<BaseFactoryUser>().eq(BaseFactoryUser::getUserId,sysUser.getId())); |
| | | if(!CollectionUtils.isEmpty(baseFactoryUserList)){ |
| | | List<String> factoryIds = baseFactoryUserList.stream().map(BaseFactoryUser::getFactoryId).collect(Collectors.toList()); |
| | | List<String> factoryCode= baseFactoryService.listByIds(factoryIds).stream().map(BaseFactory::getFactoryCode).collect(Collectors.toList()); |
| | | queryWrapper.in("e.factory_code", factoryCode); |
| | | Set<String> factoryIds = baseFactoryUserList.stream().map(BaseFactoryUser::getFactoryId).collect(Collectors.toSet()); |
| | | Set<String> factoryCode= baseFactoryService.listByIds(factoryIds).stream().map(BaseFactory::getOrgCode).collect(Collectors.toSet()); |
| | | queryWrapper.in("e.factory_org_code", factoryCode); |
| | | }else { |
| | | return page; |
| | | } |
| | | } |
| | | //查询条件过滤 |
| | |
| | | if (StringUtils.isNotBlank(eamEquipment.getEquipmentCategory())) { |
| | | queryWrapper.like("e.equipment_category", eamEquipment.getEquipmentCategory()); |
| | | } |
| | | if (StringUtils.isNotBlank(eamEquipment.getFactoryOrgCode())) { |
| | | queryWrapper.like("e.factory_org_code", eamEquipment.getFactoryOrgCode()); |
| | | } |
| | | if (StringUtils.isNotBlank(eamEquipment.getRepairDepartOrgCode())) { |
| | | queryWrapper.like("e.repair_depart_org_code", eamEquipment.getRepairDepartOrgCode()); |
| | | } |
| | | if (StringUtils.isNotBlank(eamEquipment.getId())) { |
| | | queryWrapper.eq("e.id", eamEquipment.getId()); |
| | | } |
| | |
| | | } |
| | | |
| | | @Override |
| | | public List<EquipmentSearchResult> asyncLoadEquipment(String keyword, Integer pageSize, String id) { |
| | | public List<EquipmentSearchResult> asyncLoadEquipment(String keyword, Integer pageSize, String id, String factoryOrgCode) { |
| | | if (StringUtils.isNotBlank(id)) { |
| | | EamEquipment eamEquipment = eamEquipmentMapper.selectById(id); |
| | | if (eamEquipment != null) { |
| | |
| | | List<BaseFactoryUser> baseFactoryUserList=baseFactoryUserService. |
| | | list(new LambdaQueryWrapper<BaseFactoryUser>().eq(BaseFactoryUser::getUserId,sysUser.getId())); |
| | | if(!CollectionUtils.isEmpty(baseFactoryUserList)){ |
| | | List<String> factoryIds = baseFactoryUserList.stream().map(BaseFactoryUser::getFactoryId).collect(Collectors.toList()); |
| | | List<String> factoryCode= baseFactoryService.listByIds(factoryIds).stream().map(BaseFactory::getFactoryCode).collect(Collectors.toList()); |
| | | queryWrapper.in("e.factory_code", factoryCode); |
| | | Set<String> factoryIds = baseFactoryUserList.stream().map(BaseFactoryUser::getFactoryId).collect(Collectors.toSet()); |
| | | Set<String> factoryCode = baseFactoryService.listByIds(factoryIds).stream().map(BaseFactory::getOrgCode).collect(Collectors.toSet()); |
| | | queryWrapper.in("e.factory_org_code", factoryCode); |
| | | } else { |
| | | return Collections.emptyList(); |
| | | } |
| | | } |
| | | |
| | | if (StringUtils.isNotBlank(keyword)) { |
| | | queryWrapper.like("equipment_code", keyword); |
| | | queryWrapper.or().like("equipment_name", keyword); |
| | | queryWrapper.like("e.equipment_code", keyword); |
| | | queryWrapper.or().like("e.equipment_name", keyword); |
| | | } |
| | | queryWrapper.eq("del_flag", CommonConstant.DEL_FLAG_0); |
| | | if(StringUtils.isNotBlank(factoryOrgCode)){ |
| | | queryWrapper.likeRight("e.factory_org_code", factoryOrgCode); |
| | | } |
| | | queryWrapper.eq("e.del_flag", CommonConstant.DEL_FLAG_0); |
| | | IPage<EamEquipment> pageResult = eamEquipmentMapper.queryPageList(page, queryWrapper); |
| | | if (pageResult != null && CollectionUtil.isNotEmpty(pageResult.getRecords())) { |
| | | List<EquipmentSearchResult> resultList = new ArrayList<>(); |
| | |
| | | if (sysUser == null) { |
| | | return null; |
| | | } |
| | | if (StringUtils.isNotBlank(sysUser.getEquipmentIds())) { |
| | | if (StringUtils.isNotBlank(sysUser.getEamEquipmentIds())) { |
| | | //选择了设备,根据设备id过滤设备 |
| | | List<String> equipArr = Arrays.asList(sysUser.getEquipmentIds().split(",")); |
| | | List<String> equipArr = Arrays.asList(sysUser.getEamEquipmentIds().split(",")); |
| | | queryWrapper.in("equipment_code", equipArr); |
| | | } else { |
| | | //没有选择设备,根据车间过滤设备 |
| | | queryWrapper.exists("select 1 from mdc_user_production t where t.user_id={0} and t.pro_id=org_id", sysUser.getId()); |
| | | List<BaseFactoryUser> baseFactoryUserList = baseFactoryUserService. |
| | | list(new LambdaQueryWrapper<BaseFactoryUser>().eq(BaseFactoryUser::getUserId, sysUser.getId())); |
| | | if (!CollectionUtils.isEmpty(baseFactoryUserList)) { |
| | | Set<String> factoryIds = baseFactoryUserList.stream().map(BaseFactoryUser::getFactoryId).collect(Collectors.toSet()); |
| | | Set<String> factoryCodeList = baseFactoryService.listByIds(factoryIds).stream().map(BaseFactory::getOrgCode).collect(Collectors.toSet()); |
| | | queryWrapper.in("factory_org_code", factoryCodeList); |
| | | } else { |
| | | return null; |
| | | } |
| | | |
| | | } |
| | | queryWrapper.eq("equipment_code", equipmentCode); |
| | | queryWrapper.eq("del_flag", CommonConstant.DEL_FLAG_0); |
| | |
| | | List<BaseFactoryUser> baseFactoryUserList=baseFactoryUserService. |
| | | list(new LambdaQueryWrapper<BaseFactoryUser>().eq(BaseFactoryUser::getUserId,sysUser.getId())); |
| | | if(!CollectionUtils.isEmpty(baseFactoryUserList)){ |
| | | List<String> factoryIds = baseFactoryUserList.stream().map(BaseFactoryUser::getFactoryId).collect(Collectors.toList()); |
| | | List<String> factoryCode= baseFactoryService.listByIds(factoryIds).stream().map(BaseFactory::getFactoryCode).collect(Collectors.toList()); |
| | | queryWrapper.in("e.factory_code", factoryCode); |
| | | Set<String> factoryIds = baseFactoryUserList.stream().map(BaseFactoryUser::getFactoryId).collect(Collectors.toSet()); |
| | | Set<String> factoryCode= baseFactoryService.listByIds(factoryIds).stream().map(BaseFactory::getOrgCode).collect(Collectors.toSet()); |
| | | queryWrapper.in("e.factory_org_code", factoryCode); |
| | | }else { |
| | | return Collections.emptyList(); |
| | | } |
| | | |
| | | } |
| | |
| | | return eamEquipmentMapper.queryList(queryWrapper); |
| | | } |
| | | |
| | | @Override |
| | | public List<EamEquipment> selectTechnicalEquipmentList() { |
| | | QueryWrapper<EamEquipment> queryWrapper = new QueryWrapper<>(); |
| | | queryWrapper.eq("e.del_flag", CommonConstant.DEL_FLAG_0); |
| | | queryWrapper.ne("ext.technology_status", TechnologyStatusEnum.PROHIBITED.name()); |
| | | queryWrapper.isNotNull("ext.technology_check_period"); |
| | | queryWrapper.isNotNull("ext.next_technology_check"); |
| | | return this.getBaseMapper().selectTechnicalEquipmentList(queryWrapper); |
| | | } |
| | | |
| | | /** |
| | | * 获取所有的产线id(包含所有上级) |
| | | */ |
| | |
| | | if (!allProductionIds.contains(mdcProduction.getParentId())) { |
| | | allProductionIds.add(mdcProduction.getParentId()); |
| | | getAllProductionIds(productionList, mdcProduction.getParentId(), allProductionIds); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 获取所有的产线id(包含所有上级) |
| | | */ |
| | | private void getAllBaseFactoryIds(List<BaseFactory> baseFactoryList, String baseFactoryId, List<String> allBaseFactoryIds) { |
| | | if (!allBaseFactoryIds.contains(baseFactoryId)) { |
| | | allBaseFactoryIds.add(baseFactoryId); |
| | | } |
| | | for (BaseFactory baseFactory : baseFactoryList) { |
| | | if (StringUtils.isEmpty(baseFactory.getParentId())) { |
| | | continue; |
| | | } |
| | | if (baseFactoryId.equals(baseFactory.getId())) { |
| | | if (!allBaseFactoryIds.contains(baseFactory.getParentId())) { |
| | | allBaseFactoryIds.add(baseFactory.getParentId()); |
| | | getAllBaseFactoryIds(baseFactoryList, baseFactory.getParentId(), allBaseFactoryIds); |
| | | } |
| | | } |
| | | } |
| | |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 产线设备树填充设备数据 |
| | | */ |
| | | private void fillEquipmentByBaseFactory(List<EamEquipmentTree> treeList) { |
| | | for (EamEquipmentTree mdcEquipmentTree : treeList) { |
| | | List<EamEquipment> equipmentList = eamEquipmentMapper.queryByEamCenterId(mdcEquipmentTree.getKey()); |
| | | if (CollectionUtil.isNotEmpty(equipmentList)) { |
| | | for (EamEquipment mdcEquipment : equipmentList) { |
| | | EamEquipmentTree tree = new EamEquipmentTree().convert(mdcEquipment); |
| | | tree.setParentId(mdcEquipmentTree.getKey()); |
| | | tree.setType(2); |
| | | mdcEquipmentTree.getChildren().add(tree); |
| | | } |
| | | mdcEquipmentTree.setLeaf(false); |
| | | } |
| | | if (CollectionUtil.isNotEmpty(mdcEquipmentTree.getChildren())) { |
| | | fillEquipmentByBaseFactory(mdcEquipmentTree.getChildren()); |
| | | } |
| | | } |
| | | } |
| | | |
| | | } |