| | |
| | | package org.jeecg.modules.dnc.service.impl; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.jeecg.common.constant.CommonConstant; |
| | | import org.jeecg.modules.dnc.entity.DevicePermission; |
| | | import org.jeecg.modules.dnc.mapper.DevicePermissionMapper; |
| | | import org.jeecg.modules.dnc.ucenter.UserDepartExt; |
| | | import org.jeecg.modules.dnc.utils.ValidateUtil; |
| | | import org.jeecg.modules.mdc.entity.MdcEquipment; |
| | | import org.jeecg.modules.mdc.mapper.MdcEquipmentMapper; |
| | | import org.jeecg.modules.mdc.model.MdcEquipmentTree; |
| | | import org.jeecg.modules.mdc.util.FindsEquipmentProductionUtil; |
| | | import org.jeecg.modules.system.entity.MdcProduction; |
| | | import org.jeecg.modules.system.entity.SysUser; |
| | | import org.jeecg.modules.dnc.service.IDevicePermissionService; |
| | | import org.jeecg.modules.system.service.IMdcProductionService; |
| | | import org.jeecg.modules.system.service.IMdcUserProductionService; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.util.ArrayList; |
| | | import java.util.Collections; |
| | | import java.util.List; |
| | | import java.util.stream.Collectors; |
| | | |
| | | @Service |
| | | public class DevicePermissionServiceImpl extends ServiceImpl<DevicePermissionMapper, DevicePermission> implements IDevicePermissionService { |
| | | @Resource |
| | | private IMdcProductionService mdcProductionService; |
| | | @Resource |
| | | private IMdcUserProductionService mdcUserProductionService; |
| | | @Resource |
| | | private MdcEquipmentMapper mdcEquipmentMapper; |
| | | |
| | | @Override |
| | | public DevicePermission getByUserIdAndDeviceId(String userId, String deviceId) { |
| | | if(!ValidateUtil.validateString(userId) || !ValidateUtil.validateString(deviceId)) |
| | |
| | | list = Collections.emptyList(); |
| | | return list; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 加载产线设备树 |
| | | */ |
| | | @Override |
| | | public List<MdcEquipmentTree> DncLoadTreeListByProduction(String userId){ |
| | | //获取所有产线数据 |
| | | List<MdcProduction> productionList = mdcProductionService.list(new LambdaQueryWrapper<MdcProduction>().eq(MdcProduction::getDelFlag, CommonConstant.DEL_FLAG_0.toString()).orderByAsc(MdcProduction::getProductionOrder)); |
| | | //根据用户id获取拥有的产线信息集合 |
| | | List<String> productionIds = mdcUserProductionService.queryProductionIdsByUserId(userId); |
| | | List<String> allProductionIds = new ArrayList<>(); |
| | | //找到所有产线id的上级id |
| | | if (productionIds != null && !productionIds.isEmpty()) { |
| | | for (String productionId : productionIds) { |
| | | this.getAllProductionIds(productionList, productionId, allProductionIds); |
| | | } |
| | | } |
| | | //过滤产线数据 |
| | | List<MdcProduction> list = productionList.stream().filter((MdcProduction mdcProduction) -> allProductionIds.contains(mdcProduction.getId())).collect(Collectors.toList()); |
| | | //组装产线设备树 |
| | | List<MdcEquipmentTree> treeList = FindsEquipmentProductionUtil.wrapEquipmentProductionTreeList(list); |
| | | //填充设备数据 |
| | | FillEquipmentByProduction(treeList,userId); |
| | | return treeList; |
| | | } |
| | | |
| | | /** |
| | | * 获取所有的产线id(包含所有上级) |
| | | */ |
| | | private void getAllProductionIds(List<MdcProduction> productionList, String productionId, List<String> allProductionIds) { |
| | | if (!allProductionIds.contains(productionId)) { |
| | | allProductionIds.add(productionId); |
| | | } |
| | | for (MdcProduction mdcProduction : productionList) { |
| | | if (StringUtils.isEmpty(mdcProduction.getParentId())) { |
| | | continue; |
| | | } |
| | | if (productionId.equals(mdcProduction.getId())) { |
| | | if (!allProductionIds.contains(mdcProduction.getParentId())) { |
| | | allProductionIds.add(mdcProduction.getParentId()); |
| | | getAllProductionIds(productionList, mdcProduction.getParentId(), allProductionIds); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 产线设备树填充设备数据 |
| | | */ |
| | | private void FillEquipmentByProduction(List<MdcEquipmentTree> treeList,String userId) { |
| | | //获取已分配权限设备数据 |
| | | List<String> deviceIds=super.list(new QueryWrapper<DevicePermission>().eq("user_id",userId)).stream().map(DevicePermission::getDeviceId).collect(Collectors.toList()); |
| | | if (!deviceIds.isEmpty()){ |
| | | for (MdcEquipmentTree mdcEquipmentTree : treeList) { |
| | | List<MdcEquipment> equipmentList = mdcEquipmentMapper.queryByProductionIdAndType(mdcEquipmentTree.getKey(),deviceIds); |
| | | if (equipmentList != null && !equipmentList.isEmpty()) { |
| | | for (MdcEquipment mdcEquipment : equipmentList) { |
| | | MdcEquipmentTree tree = new MdcEquipmentTree().convert(mdcEquipment); |
| | | tree.setParentId(mdcEquipmentTree.getKey()); |
| | | tree.setEntity(mdcEquipment); |
| | | tree.setType(2); |
| | | mdcEquipmentTree.getChildren().add(tree); |
| | | } |
| | | mdcEquipmentTree.setLeaf(false); |
| | | } |
| | | if (!mdcEquipmentTree.getChildren().isEmpty()) { |
| | | FillEquipmentByProduction(mdcEquipmentTree.getChildren(),userId); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | } |