| | |
| | | package org.jeecg.modules.dnc.service.impl; |
| | | |
| | | import cn.hutool.core.bean.BeanUtil; |
| | | import cn.hutool.core.collection.CollectionUtil; |
| | | import cn.hutool.core.util.StrUtil; |
| | | 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 liquibase.pro.packaged.S; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.shiro.SecurityUtils; |
| | | import org.jeecg.common.api.vo.Result; |
| | | import org.jeecg.common.system.vo.LoginUser; |
| | | import org.jeecg.modules.dnc.constant.DocAttributionTypeEnum; |
| | | import org.jeecg.modules.dnc.dto.ComponentExt; |
| | | import org.jeecg.modules.dnc.entity.*; |
| | | import org.jeecg.modules.dnc.exception.ExceptionCast; |
| | | import org.jeecg.modules.dnc.mapper.ProcessSpecVersionPermissionMapper; |
| | | import org.jeecg.modules.dnc.mapper.ProductInfoMapper; |
| | | import org.jeecg.modules.dnc.request.DocInfoQueryRequest; |
| | | import org.jeecg.modules.dnc.request.TreeInfoRequest; |
| | | import org.jeecg.modules.dnc.response.*; |
| | | import org.jeecg.modules.dnc.service.*; |
| | | import org.jeecg.modules.dnc.service.support.ProductTreeWrapper; |
| | | import org.jeecg.modules.dnc.ucenter.UserDepartExt; |
| | | import org.jeecg.modules.dnc.utils.ValidateUtil; |
| | | import org.jeecg.modules.dnc.entity.*; |
| | | import org.jeecg.modules.system.entity.MdcProduction; |
| | | import org.jeecg.modules.system.entity.SysUser; |
| | | import org.jeecg.modules.system.service.IMdcProductionService; |
| | | import org.jeecg.modules.system.service.ISysUserService; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.context.annotation.Lazy; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import redis.clients.jedis.Jedis; |
| | | |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | |
| | | private IProcessStreamPermissionService iProcessStreamPermissionService; |
| | | @Autowired |
| | | private IWorkStepPermissionService iWorkStepPermissionService; |
| | | @Autowired |
| | | private IProductMixService productMixService; |
| | | @Autowired |
| | | @Lazy |
| | | private IDocInfoService docInfoService; |
| | | @Autowired |
| | | private IDeviceTypeService deviceTypeService; |
| | | @Autowired |
| | | private IDeviceManagementService deviceManagementService; |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = {Exception.class}) |
| | |
| | | if (!b) { |
| | | ExceptionCast.cast(ProductInfoCode.PRODUCT_SAVE_ERROR); |
| | | } |
| | | //添加结构树 |
| | | ProductMix productMix = new ProductMix(Long.parseLong(productInfo.getProductId()),0L, |
| | | productInfo.getProductName(),productInfo.getProductNo(),1,new Date()); |
| | | productMixService.save(productMix); |
| | | //添加用户部门 |
| | | if(StrUtil.isNotBlank(user.getProductionIds())){ |
| | | String[] split = user.getProductionIds().split(","); |
| | | String[] departIds = split; |
| | | for (String departId : departIds) { |
| | | ProductDepartment productDepartment = new ProductDepartment(); |
| | | productDepartment.setProductId(productInfo.getProductId()); |
| | | productDepartment.setDepartId(departId); |
| | | productDepartmentService.save(productDepartment); |
| | | PermissionStreamNew stream = new PermissionStreamNew(); |
| | | stream.setBusinessId(productInfo.getProductId()); |
| | | stream.setDepartId(departId); |
| | | stream.setBusinessType(DocAttributionTypeEnum.PRODUCT.getCode().toString()); |
| | | permissionStreamNewService.save(stream); |
| | | } |
| | | } |
| | | //添加用户权限 |
| | | PermissionStreamNew stream = new PermissionStreamNew(); |
| | | stream.setBusinessId(productInfo.getProductId()); |
| | | stream.setUserId(userId); |
| | | stream.setBusinessType("1"); |
| | | return permissionStreamNewService.save(stream); |
| | | stream.setBusinessType(DocAttributionTypeEnum.PRODUCT.getCode().toString()); |
| | | return permissionStreamNewService.addPermissionStreamNew(stream); |
| | | } |
| | | |
| | | @Override |
| | |
| | | productInfo.setProductId(id); |
| | | productInfo.setProductStatus(null); |
| | | boolean b = super.updateById(productInfo); |
| | | //同步修改结构树 |
| | | ProductMix productMix = productMixService.getById(Long.parseLong(id)); |
| | | productMix.setName(productInfo.getProductName()); |
| | | productMix.setCode(productInfo.getProductNo()); |
| | | productMixService.updateById(productMix); |
| | | if (!b) |
| | | return false; |
| | | ProductPermission permission = productPermissionService.getByProductIdAndUserId(id, userId); |
| | |
| | | return false; |
| | | } |
| | | } |
| | | PermissionStreamNew stream = permissionStreamNewService.loadPermissionStreamNewByBusinessIdAndUserId(id, userId, "1"); |
| | | PermissionStreamNew stream = permissionStreamNewService.loadPermissionStreamNewByBusinessIdAndUserId(id, userId, DocAttributionTypeEnum.PRODUCT.getCode().toString()); |
| | | if (stream == null) { |
| | | stream = new PermissionStreamNew(); |
| | | stream.setBusinessId(productInfo.getProductId()); |
| | | stream.setUserId(userId); |
| | | stream.setBusinessType("1"); |
| | | stream.setBusinessType(DocAttributionTypeEnum.PRODUCT.getCode().toString()); |
| | | return permissionStreamNewService.save(stream); |
| | | } |
| | | return b; |
| | |
| | | ExceptionCast.cast(ProductInfoCode.PRODUCT_PROCESS_EXIST); |
| | | boolean b = productPermissionService.deleteByProductId(id); |
| | | //验证是否存在文档 |
| | | List<DocRelative> docRelativeList = iDocRelativeService.list(new QueryWrapper<DocRelative>().eq("attribution_type", "1").eq("attribution_id", id)); |
| | | List<DocRelative> docRelativeList = iDocRelativeService.list(new QueryWrapper<DocRelative>().eq("attribution_type", DocAttributionTypeEnum.PRODUCT.getCode() ).eq("attribution_id", id)); |
| | | if (!docRelativeList.isEmpty()) { |
| | | ExceptionCast.cast(ProductInfoCode.PRODUCT_DOC_EXIST); |
| | | } |
| | |
| | | b = productDepartmentService.deleteByProductId(id); |
| | | if (!b) |
| | | ExceptionCast.cast(CommonCode.FAIL); |
| | | b = permissionStreamNewService.deletePermissionStreamNewByBusinessId(id, "1","0"); |
| | | b = permissionStreamNewService.deletePermissionStreamNewByBusinessId(id, DocAttributionTypeEnum.PRODUCT.getCode().toString(),"0"); |
| | | if (!b) |
| | | ExceptionCast.cast(CommonCode.FAIL); |
| | | b = permissionStreamNewService.deletePermissionStreamNewByBusinessId(id, "1","1"); |
| | | b = permissionStreamNewService.deletePermissionStreamNewByBusinessId(id, DocAttributionTypeEnum.PRODUCT.getCode().toString(),"1"); |
| | | if (!b) |
| | | ExceptionCast.cast(CommonCode.FAIL); |
| | | b = productMixService.removeById(id); |
| | | if (!b) |
| | | ExceptionCast.cast(CommonCode.FAIL); |
| | | return super.removeById(id); |
| | |
| | | String userId = user.getId(); |
| | | if (!ValidateUtil.validateString(userId)) |
| | | ExceptionCast.cast(UcenterCode.UCENTER_ACCOUNT_NOT_EXIST); |
| | | if (nodeType == 1) { |
| | | if (nodeType.equals(DocAttributionTypeEnum.PRODUCT.getCode())) { |
| | | ProductInfo productInfo = super.getById(paramId); |
| | | if (productInfo == null) |
| | | ExceptionCast.cast(ProductInfoCode.PRODUCT_NOT_EXIST); |
| | | PermissionStreamNew permission = permissionStreamNewService.loadPermissionStreamNewByBusinessIdAndUserId(paramId, userId,"1"); |
| | | return permission != null; |
| | | } else if (nodeType == 2) { |
| | | } else if (nodeType.equals(DocAttributionTypeEnum.COMPONENT.getCode())) { |
| | | ComponentInfo componentInfo = componentInfoService.getById(paramId); |
| | | if (componentInfo == null) |
| | | ExceptionCast.cast(ComponentInfoCode.COMPONENT_NOT_EXIST); |
| | | PermissionStreamNew permission = permissionStreamNewService.loadPermissionStreamNewByBusinessIdAndUserId(componentInfo.getComponentId(), userId,"2"); |
| | | return permission != null; |
| | | } else if (nodeType == 3) { |
| | | } else if (nodeType.equals(DocAttributionTypeEnum.PARTS.getCode())) { |
| | | PartsInfo partsInfo = partsInfoService.getById(paramId); |
| | | if (partsInfo == null) |
| | | ExceptionCast.cast(PartsInfoCode.PARTS_NOT_EXIST); |
| | | PermissionStreamNew permission = permissionStreamNewService.loadPermissionStreamNewByBusinessIdAndUserId(partsInfo.getPartsId(), userId, "3"); |
| | | return permission != null; |
| | | } else if (nodeType == 4) { |
| | | } else if (nodeType.equals(DocAttributionTypeEnum.OPERATION.getCode())) { |
| | | ProcessSpecVersion processSpecVersion = processSpecVersionService.getById(paramId); |
| | | if (processSpecVersion == null) |
| | | ExceptionCast.cast(PartsInfoCode.PROCESSSPECVERSION_NOT_EXIST); |
| | | PermissionStreamNew permission = permissionStreamNewService.loadPermissionStreamNewByBusinessIdAndUserId(processSpecVersion.getId(),userId,"4"); |
| | | return permission != null; |
| | | } else if (nodeType == 5) { |
| | | } else if (nodeType.equals(DocAttributionTypeEnum.PROCESS.getCode())) { |
| | | ProcessStream processStream = processStreamService.getById(paramId); |
| | | if (processStream == null) |
| | | ExceptionCast.cast(ProcessInfoCode.PROCESS_NOT_EXIST); |
| | | PermissionStreamNew permission = permissionStreamNewService.loadPermissionStreamNewByBusinessIdAndUserId(processStream.getProcessId(), userId,"5"); |
| | | return permission != null; |
| | | } else if (nodeType == 6) { |
| | | } else if (nodeType.equals(DocAttributionTypeEnum.WORKSITE.getCode())) { |
| | | WorkStep workStep = workStepService.getById(paramId); |
| | | if (workStep == null) |
| | | ExceptionCast.cast(ProcessInfoCode.WORKSTEP_NOT_EXIST); |
| | |
| | | public List<UserDepartExt> getUserPermsList(Integer nodeType, String paramId) { |
| | | if (!ValidateUtil.validateInteger(nodeType) || !ValidateUtil.validateString(paramId)) |
| | | return null; |
| | | if (nodeType == 1) { |
| | | if (nodeType.equals(DocAttributionTypeEnum.PRODUCT.getCode())) { |
| | | return productPermissionService.getUserPermsByProductId(paramId); |
| | | } else if (nodeType == 2) { |
| | | } else if (nodeType.equals(DocAttributionTypeEnum.COMPONENT.getCode())) { |
| | | return componentPermissionService.getUserPermsByComponentId(paramId); |
| | | } else if (nodeType == 3) { |
| | | } else if (nodeType.equals(DocAttributionTypeEnum.PARTS.getCode())) { |
| | | return partsPermissionService.getUserPermsByProductId(paramId); |
| | | } else if (nodeType == 4) { |
| | | } else if (nodeType.equals(DocAttributionTypeEnum.OPERATION.getCode())) { |
| | | return processSpecVersionPermissionService.getUserPermsByProductId(paramId); |
| | | } else if (nodeType == 5) { |
| | | } else if (nodeType.equals(DocAttributionTypeEnum.PROCESS.getCode())) { |
| | | return iProcessStreamPermissionService.getUserPermsByProductId(paramId); |
| | | } else if (nodeType == 6) { |
| | | } else if (nodeType.equals(DocAttributionTypeEnum.WORKSITE.getCode())) { |
| | | return iWorkStepPermissionService.getUserPermsByProductId(paramId); |
| | | } else { |
| | | return null; |
| | |
| | | public List<SysUser> getUserNonPermsList(Integer nodeType, String paramId) { |
| | | if (!ValidateUtil.validateInteger(nodeType) || !ValidateUtil.validateString(paramId)) |
| | | return null; |
| | | if (nodeType == 1) { |
| | | if (nodeType.equals(DocAttributionTypeEnum.PRODUCT.getCode())) { |
| | | return productPermissionService.getUserNonPermsByProductId(paramId); |
| | | } else if (nodeType == 2) { |
| | | } else if (nodeType.equals(DocAttributionTypeEnum.COMPONENT.getCode())){ |
| | | return componentPermissionService.getUserNonPermsByComponentId(paramId); |
| | | } else if (nodeType == 3) { |
| | | } else if (nodeType.equals(DocAttributionTypeEnum.PARTS.getCode())) { |
| | | return partsPermissionService.getUserNonPermsByProductId(paramId); |
| | | } else if (nodeType == 4) { |
| | | } else if (nodeType.equals(DocAttributionTypeEnum.OPERATION.getCode())) { |
| | | return processSpecVersionPermissionService.getUserNonPermsByProductId(paramId); |
| | | } else if (nodeType == 5) { |
| | | } else if (nodeType.equals(DocAttributionTypeEnum.PROCESS.getCode())) { |
| | | return iProcessStreamPermissionService.getUserNonPermsByProductId(paramId); |
| | | } else if (nodeType == 6) { |
| | | } else if (nodeType.equals(DocAttributionTypeEnum.WORKSITE.getCode())) { |
| | | return iWorkStepPermissionService.getUserNonPermsByProductId(paramId); |
| | | } else { |
| | | return null; |
| | |
| | | public List<MdcProduction> getDepartPermsList(Integer nodeType, String paramId) { |
| | | if (!ValidateUtil.validateInteger(nodeType) || !ValidateUtil.validateString(paramId)) |
| | | return null; |
| | | if (nodeType == 1) { |
| | | if (nodeType.equals(DocAttributionTypeEnum.PRODUCT.getCode())) { |
| | | return productDepartmentService.getDepartPermsByProductId(paramId); |
| | | } else if (nodeType == 2) { |
| | | } else if (nodeType.equals(DocAttributionTypeEnum.COMPONENT.getCode())){ |
| | | return componentDepartmentService.getDepartPermsByComponentId(paramId); |
| | | } else if (nodeType == 3) { |
| | | } else if (nodeType.equals(DocAttributionTypeEnum.PARTS.getCode())) { |
| | | return partsDepartmentService.getDepartPermsByPartsId(paramId); |
| | | } else if (nodeType == 4) { |
| | | } else if (nodeType.equals(DocAttributionTypeEnum.OPERATION.getCode())) { |
| | | return processSpecVersionDepartmentService.getDepartPermsByPsvId(paramId); |
| | | }else if (nodeType == 5) { |
| | | } else if (nodeType.equals(DocAttributionTypeEnum.PROCESS.getCode())) { |
| | | return processionDepartmentService.getDepartPermsByProcessId(paramId); |
| | | } else if (nodeType == 6) { |
| | | } else if (nodeType.equals(DocAttributionTypeEnum.WORKSITE.getCode())) { |
| | | return workStepDepartmentService.getDepartPermsByStepId(paramId); |
| | | } |
| | | else { |
| | |
| | | public List<MdcProduction> getDepartNonPermsList(Integer nodeType, String paramId) { |
| | | if (!ValidateUtil.validateInteger(nodeType) || !ValidateUtil.validateString(paramId)) |
| | | return null; |
| | | if (nodeType == 1) { |
| | | if (nodeType.equals(DocAttributionTypeEnum.PRODUCT.getCode())) { |
| | | return productDepartmentService.getDepartNonPermsByProductId(paramId); |
| | | } else if (nodeType == 2) { |
| | | } else if (nodeType.equals(DocAttributionTypeEnum.COMPONENT.getCode())){ |
| | | return componentDepartmentService.getDepartNonPermsByComponentId(paramId); |
| | | } else if (nodeType == 3) { |
| | | } else if (nodeType.equals(DocAttributionTypeEnum.PARTS.getCode())) { |
| | | return partsDepartmentService.getDepartNonPermsByProductId(paramId); |
| | | } else if (nodeType == 4) { |
| | | } else if (nodeType.equals(DocAttributionTypeEnum.OPERATION.getCode())) { |
| | | return processionDepartmentService.getDepartNonPermsByProcessId(paramId); |
| | | } else if (nodeType == 5) { |
| | | } else if (nodeType.equals(DocAttributionTypeEnum.PROCESS.getCode())) { |
| | | return processionDepartmentService.getDepartNonPermsByProcessId(paramId); |
| | | } else if (nodeType == 6) { |
| | | } else if (nodeType.equals(DocAttributionTypeEnum.WORKSITE.getCode())) { |
| | | return workStepDepartmentService.getDepartNonPermsByStepId(paramId); |
| | | } else { |
| | | return null; |
| | |
| | | stream = new PermissionStreamNew(); |
| | | stream.setUserId(item.getId()); |
| | | stream.setBusinessId(productInfo.getProductId()); |
| | | stream.setBusinessType("1"); |
| | | stream.setBusinessType(DocAttributionTypeEnum.PRODUCT.getCode().toString()); |
| | | permissionStreamList.add(stream); |
| | | } |
| | | }); |
| | |
| | | stream = new PermissionStreamNew(); |
| | | stream.setDepartId(item.getId()); |
| | | stream.setBusinessId(productInfo.getProductId()); |
| | | stream.setBusinessType("1"); |
| | | stream.setBusinessType(DocAttributionTypeEnum.PRODUCT.getCode().toString()); |
| | | permissionStreamList.add(stream); |
| | | } |
| | | }); |
| | |
| | | public List<String> getDepartIdsByParams(Integer nodeType, String paramId) { |
| | | List<String> departIds = new ArrayList<>(); |
| | | //5-工序 |
| | | if (nodeType == 5) { |
| | | if (Objects.equals(nodeType, DocAttributionTypeEnum.PROCESS.getCode())) { |
| | | ProcessStream processStream = processStreamService.getById(paramId); |
| | | if (processStream == null) |
| | | return null; |
| | |
| | | departIds.add(item.getDepartId()); |
| | | }); |
| | | //6-工步 |
| | | } else if (nodeType == 6) { |
| | | } else if (Objects.equals(nodeType, DocAttributionTypeEnum.WORKSITE.getCode())) { |
| | | WorkStep workStep = workStepService.getById(paramId); |
| | | if (workStep == null) |
| | | return null; |
| | |
| | | |
| | | @Override |
| | | public List<CommonGenericTree> loadTree(String userId, Integer nodeType, String paramId) { |
| | | if (nodeType == 1) { |
| | | if (Objects.equals(nodeType, DocAttributionTypeEnum.PRODUCT.getCode())) { |
| | | List<ComponentInfo> componentInfoList = componentInfoService.getByProductIdAndUserId(paramId, userId); |
| | | if (componentInfoList == null || componentInfoList.isEmpty()) |
| | | return Collections.emptyList(); |
| | |
| | | node.setLabel(c.getComponentName()); |
| | | node.setParentId(c.getProductId()); |
| | | node.setIconClass(""); |
| | | node.setType(2); |
| | | node.setType(DocAttributionTypeEnum.COMPONENT.getCode()); |
| | | node.setRField(c.getProductId()); |
| | | node.setEntity(c); |
| | | list.add(node); |
| | | } |
| | | return list; |
| | | } else if (nodeType == 2) { |
| | | } else if (Objects.equals(nodeType, DocAttributionTypeEnum.COMPONENT.getCode())) { |
| | | List<ComponentInfo> componentInfoList = componentInfoService.getByParentIdAndUserId(paramId, userId); |
| | | List<CommonGenericTree> list = new ArrayList<>(); |
| | | CommonGenericTree<ComponentInfo> componentNode; |
| | |
| | | componentNode.setLabel(c.getComponentName()); |
| | | componentNode.setParentId(c.getParentId()); |
| | | componentNode.setIconClass(""); |
| | | componentNode.setType(2); |
| | | componentNode.setType(DocAttributionTypeEnum.COMPONENT.getCode()); |
| | | componentNode.setRField(c.getProductId()); |
| | | componentNode.setEntity(c); |
| | | list.add(componentNode); |
| | |
| | | partNode.setLabel(part.getPartsName()); |
| | | partNode.setParentId(part.getComponentId()); |
| | | partNode.setIconClass(""); |
| | | partNode.setType(3); |
| | | partNode.setType(DocAttributionTypeEnum.PARTS.getCode()); |
| | | partNode.setRField(part.getComponentId()); |
| | | partNode.setEntity(part); |
| | | partNode.setLeaf(true); |
| | |
| | | return false; |
| | | } |
| | | |
| | | @Override |
| | | public Result<?> getTreeById(String id, Integer type){ |
| | | if (StrUtil.isNotEmpty(id)||type!=null){ |
| | | switch (type){ |
| | | case 1: |
| | | //产品 |
| | | QueryWrapper<ProductInfo> productInfoQueryWrapper = new QueryWrapper<>(); |
| | | productInfoQueryWrapper.eq("product_id",id); |
| | | List<ProductInfo> productInfos = this.list(productInfoQueryWrapper); |
| | | return Result.OK(productInfos); |
| | | case 2: |
| | | //组件 |
| | | QueryWrapper<ComponentInfo> componentInfoQueryWrapper = new QueryWrapper<>(); |
| | | componentInfoQueryWrapper.eq("component_id",id); |
| | | List<ComponentInfo> componentInfos = componentInfoService.list(componentInfoQueryWrapper); |
| | | return Result.OK(componentInfos); |
| | | case 3: |
| | | //零件 |
| | | QueryWrapper<PartsInfo> partsInfoQueryWrapper = new QueryWrapper<>(); |
| | | partsInfoQueryWrapper.eq("parts_id",id); |
| | | List<PartsInfo> partsInfos = partsInfoService.list(partsInfoQueryWrapper); |
| | | return Result.OK(partsInfos); |
| | | case 4: |
| | | //工艺规划版本 |
| | | QueryWrapper<ProcessSpecVersion> processSpecVersionQueryWrapper = new QueryWrapper<>(); |
| | | processSpecVersionQueryWrapper.eq("id",id); |
| | | List<ProcessSpecVersion> processSpecVersions = processSpecVersionService.list(processSpecVersionQueryWrapper); |
| | | return Result.OK(processSpecVersions); |
| | | case 5: |
| | | //工序 |
| | | QueryWrapper<ProcessStream> processStreamQueryWrapper = new QueryWrapper<>(); |
| | | processStreamQueryWrapper.eq("process_id",id); |
| | | List<ProcessStream> processStreams = processStreamService.list(processStreamQueryWrapper); |
| | | return Result.OK(processStreams); |
| | | case 6: |
| | | //工步 |
| | | QueryWrapper<WorkStep> workStepQueryWrapper = new QueryWrapper<>(); |
| | | workStepQueryWrapper.eq("id",id); |
| | | List<WorkStep> workSteps = workStepService.list(workStepQueryWrapper); |
| | | return Result.OK(workSteps); |
| | | } |
| | | } |
| | | return Result.error("参数错误"); |
| | | } |
| | | |
| | | /** |
| | | * 通过代号、名称、材质等查询对应电子样板 |
| | | * @param treeInfoRequest |
| | | * @return |
| | | */ |
| | | @Override |
| | | public List<DocInfo> getByTreeOtherFileInfo(TreeInfoRequest treeInfoRequest){ |
| | | switch (treeInfoRequest.getAttributionType()){ |
| | | case 1: |
| | | LambdaQueryWrapper<ProductInfo> queryWrapper = new LambdaQueryWrapper<>(); |
| | | // 明确条件:仅当attributionType为1且attributionId非空时添加条件 |
| | | if (treeInfoRequest.getAttributionType() == 1 && StrUtil.isNotBlank(treeInfoRequest.getAttributionId())) { |
| | | queryWrapper.eq(ProductInfo::getProductId, treeInfoRequest.getAttributionId()); |
| | | } |
| | | // 简化条件判断 |
| | | queryWrapper.like(StrUtil.isNotBlank(treeInfoRequest.getTreeCode()), ProductInfo::getProductNo, treeInfoRequest.getTreeCode()) |
| | | .like(StrUtil.isNotBlank(treeInfoRequest.getTreeName()), ProductInfo::getProductName, treeInfoRequest.getTreeName()); |
| | | List<ProductInfo> productInfoList = super.list(queryWrapper); |
| | | List<DocInfo> docInfos = new ArrayList<>(); |
| | | if (StrUtil.isNotBlank(treeInfoRequest.getStructureType())){ |
| | | productInfoList=new ArrayList<>(); |
| | | } |
| | | if (CollectionUtil.isNotEmpty(productInfoList)) { |
| | | // 使用ID列表而非拼接字符串 |
| | | List<String> productIds = productInfoList.stream() |
| | | .map(ProductInfo::getProductId) |
| | | .collect(Collectors.toList()); |
| | | DocInfoQueryRequest docQuery = new DocInfoQueryRequest(); |
| | | BeanUtil.copyProperties(treeInfoRequest, docQuery); |
| | | docQuery.setAttributionIds(productIds.toString()); // 假设setAttributionIds接受List<String> |
| | | docQuery.setDocClassCode("OTHER"); |
| | | docQuery.setAttributionType(1); |
| | | docInfos = docInfoService.findListByDocQuery(docQuery); |
| | | } |
| | | // 创建新请求对象避免污染原参数 |
| | | TreeInfoRequest componentRequest = new TreeInfoRequest(); |
| | | BeanUtil.copyProperties(treeInfoRequest, componentRequest); |
| | | componentRequest.setProductIds(Collections.singletonList(treeInfoRequest.getAttributionId())); |
| | | // 合并查询结果 |
| | | docInfos.addAll(componentInfoService.getByComponentInfo(componentRequest)); |
| | | docInfos.addAll(partsInfoService.getByPartsInfo(componentRequest)); |
| | | docInfos.addAll(processSpecVersionService.getByProcessSpecVersion(componentRequest)); |
| | | return getByTreeOtherFileInfo(docInfos); |
| | | case 2: |
| | | return getByTreeOtherFileInfo(componentInfoService.getByComponentInfo(treeInfoRequest)); |
| | | case 3: |
| | | return getByTreeOtherFileInfo(partsInfoService.getByPartsInfo(treeInfoRequest)); |
| | | case 4: |
| | | return getByTreeOtherFileInfo(processSpecVersionService.getByProcessSpecVersion(treeInfoRequest)); |
| | | case 5: |
| | | return getByTreeOtherFileInfo(processStreamService.getByProcessStreamOtherFile(treeInfoRequest)); |
| | | case 6: |
| | | return getByTreeOtherFileInfo(workStepService.getByWorkStepOtherFile(treeInfoRequest)); |
| | | } |
| | | return new ArrayList<>(); |
| | | } |
| | | |
| | | /** |
| | | * 通过代号、名称、材质等查询对应NC文件 |
| | | * @param treeInfoRequest |
| | | * @return |
| | | */ |
| | | @Override |
| | | public List<DocInfo> getByTreeNcFileInfo(TreeInfoRequest treeInfoRequest){ |
| | | //产品、部件、零件、工艺规程版本都没有对应的NC文件,直接查询子结构 |
| | | switch (treeInfoRequest.getAttributionType()){ |
| | | case 1: |
| | | LambdaQueryWrapper<ProductInfo> queryWrapper = new LambdaQueryWrapper<>(); |
| | | // 明确条件:仅当attributionType为1且attributionId非空时添加条件 |
| | | if (StrUtil.isNotBlank(treeInfoRequest.getAttributionId())) { |
| | | queryWrapper.eq(ProductInfo::getProductId, treeInfoRequest.getAttributionId()); |
| | | } |
| | | // 简化条件判断 |
| | | queryWrapper.like(StrUtil.isNotBlank(treeInfoRequest.getTreeCode()), ProductInfo::getProductNo, treeInfoRequest.getTreeCode()) |
| | | .like(StrUtil.isNotBlank(treeInfoRequest.getTreeName()), ProductInfo::getProductName, treeInfoRequest.getTreeName()); |
| | | List<ProductInfo> productInfoList = super.list(queryWrapper); |
| | | if (CollectionUtil.isNotEmpty(productInfoList)) { |
| | | treeInfoRequest.setProductIds(productInfoList.stream().map(ProductInfo::getProductId).collect(Collectors.toList())); |
| | | } |
| | | return getByTreeNcFileInfo(processStreamService.getByProcessStreamNCFile(treeInfoRequest)); |
| | | case 2: |
| | | LambdaQueryWrapper<ComponentInfo> componentInfoLambdaQueryWrapper = new LambdaQueryWrapper<>(); |
| | | // 明确条件:仅当attributionType为1且attributionId非空时添加条件 |
| | | if (StrUtil.isNotBlank(treeInfoRequest.getAttributionId())) { |
| | | componentInfoLambdaQueryWrapper.eq(ComponentInfo::getComponentId, treeInfoRequest.getAttributionId()); |
| | | } |
| | | componentInfoLambdaQueryWrapper.like(StrUtil.isNotEmpty(treeInfoRequest.getTreeCode()),ComponentInfo::getComponentCode, treeInfoRequest.getTreeCode()); |
| | | componentInfoLambdaQueryWrapper.like(StrUtil.isNotEmpty(treeInfoRequest.getTreeName()),ComponentInfo::getComponentName, treeInfoRequest.getTreeName()); |
| | | componentInfoLambdaQueryWrapper.like(StrUtil.isNotEmpty(treeInfoRequest.getStructureType()),ComponentInfo::getStructureType, treeInfoRequest.getStructureType()); |
| | | componentInfoLambdaQueryWrapper.orderByDesc(ComponentInfo::getCreateTime); |
| | | List<ComponentInfo> componentInfoList = componentInfoService.list(componentInfoLambdaQueryWrapper); |
| | | if (CollectionUtil.isNotEmpty(componentInfoList)) { |
| | | treeInfoRequest.setComponentIds(componentInfoList.stream().map(ComponentInfo::getComponentId).collect(Collectors.toList())); |
| | | } |
| | | return getByTreeNcFileInfo(processStreamService.getByProcessStreamNCFile(treeInfoRequest)); |
| | | case 3: |
| | | LambdaQueryWrapper<PartsInfo> partsInfoLambdaQueryWrapper = new LambdaQueryWrapper<>(); |
| | | if (treeInfoRequest.getProductIds() != null && !treeInfoRequest.getProductIds().isEmpty()) { |
| | | partsInfoLambdaQueryWrapper.in(PartsInfo::getProductId, treeInfoRequest.getProductIds()); |
| | | } |
| | | if (treeInfoRequest.getComponentIds() != null && !treeInfoRequest.getComponentIds().isEmpty()) { |
| | | partsInfoLambdaQueryWrapper.in(PartsInfo::getComponentId, treeInfoRequest.getComponentIds()); |
| | | } |
| | | if (Objects.equals(treeInfoRequest.getAttributionType(), DocAttributionTypeEnum.PARTS.getCode())){ |
| | | partsInfoLambdaQueryWrapper.eq(StrUtil.isNotEmpty(treeInfoRequest.getAttributionId()),PartsInfo::getPartsId,treeInfoRequest.getAttributionId()); |
| | | } |
| | | partsInfoLambdaQueryWrapper.like(StrUtil.isNotEmpty(treeInfoRequest.getTreeCode()),PartsInfo::getPartsCode, treeInfoRequest.getTreeCode()); |
| | | partsInfoLambdaQueryWrapper.like(StrUtil.isNotEmpty(treeInfoRequest.getTreeName()),PartsInfo::getPartsName, treeInfoRequest.getTreeName()); |
| | | partsInfoLambdaQueryWrapper.like(StrUtil.isNotEmpty(treeInfoRequest.getStructureType()),PartsInfo::getStructureType, treeInfoRequest.getStructureType()); |
| | | partsInfoLambdaQueryWrapper.orderByDesc(PartsInfo::getCreateTime); |
| | | List<PartsInfo> list = partsInfoService.list(partsInfoLambdaQueryWrapper); |
| | | if (CollectionUtil.isNotEmpty(list)) { |
| | | treeInfoRequest.setPartsIds(list.stream().map(PartsInfo::getPartsId).collect(Collectors.toList())); |
| | | } |
| | | return getByTreeNcFileInfo(processStreamService.getByProcessStreamNCFile(treeInfoRequest)); |
| | | case 4: |
| | | LambdaQueryWrapper<ProcessSpecVersion> processSpecVersionLambdaQueryWrapper = new LambdaQueryWrapper<>(); |
| | | if (treeInfoRequest.getProductIds() != null && !treeInfoRequest.getProductIds().isEmpty()) { |
| | | processSpecVersionLambdaQueryWrapper.in(ProcessSpecVersion::getProductId, treeInfoRequest.getProductIds()); |
| | | } |
| | | if (treeInfoRequest.getComponentIds() != null && !treeInfoRequest.getComponentIds().isEmpty()) { |
| | | processSpecVersionLambdaQueryWrapper.in(ProcessSpecVersion::getComponentId, treeInfoRequest.getComponentIds()); |
| | | } |
| | | if (treeInfoRequest.getPartsIds() != null && !treeInfoRequest.getPartsIds().isEmpty()) { |
| | | processSpecVersionLambdaQueryWrapper.in(ProcessSpecVersion::getPartsId, treeInfoRequest.getPartsIds()); |
| | | } |
| | | if (Objects.equals(treeInfoRequest.getAttributionType(), DocAttributionTypeEnum.OPERATION.getCode())){ |
| | | processSpecVersionLambdaQueryWrapper.eq(StrUtil.isNotEmpty(treeInfoRequest.getAttributionId()),ProcessSpecVersion::getId,treeInfoRequest.getAttributionId()); |
| | | } |
| | | processSpecVersionLambdaQueryWrapper.like(StrUtil.isNotEmpty(treeInfoRequest.getTreeName()),ProcessSpecVersion::getProcessSpecVersionName, treeInfoRequest.getTreeName()); |
| | | processSpecVersionLambdaQueryWrapper.like(StrUtil.isNotEmpty(treeInfoRequest.getTreeCode()),ProcessSpecVersion::getProcessSpecVersionCode, treeInfoRequest.getTreeName()); |
| | | processSpecVersionLambdaQueryWrapper.orderByDesc(ProcessSpecVersion::getCreateTime); |
| | | List<ProcessSpecVersion> processSpecVersions = processSpecVersionService.list(processSpecVersionLambdaQueryWrapper); |
| | | if (CollectionUtil.isNotEmpty(processSpecVersions)) { |
| | | treeInfoRequest.setPsvIds(processSpecVersions.stream().map(ProcessSpecVersion::getId).collect(Collectors.toList())); |
| | | } |
| | | return getByTreeNcFileInfo(processStreamService.getByProcessStreamNCFile(treeInfoRequest)); |
| | | case 5: |
| | | return getByTreeNcFileInfo(processStreamService.getByProcessStreamNCFile(treeInfoRequest)); |
| | | case 6: |
| | | return getByTreeNcFileInfo(workStepService.getByWorkStepNCFile(treeInfoRequest)); |
| | | } |
| | | return new ArrayList<>(); |
| | | } |
| | | |
| | | private List<DocInfo> getByTreeOtherFileInfo(List<DocInfo> docInfos){ |
| | | //对所属id进行翻译 |
| | | if (docInfos != null && !docInfos.isEmpty()) { |
| | | docInfos.forEach(docInfo -> { |
| | | switch (docInfo.getAttributionType()){ |
| | | case 1: |
| | | ProductInfo productInfo=this.getById(docInfo.getAttributionId()); |
| | | docInfo.setNodeName(productInfo.getProductName()); |
| | | docInfo.setNodeCode(productInfo.getProductNo()); |
| | | break; |
| | | case 2: |
| | | ComponentInfo componentInfo=componentInfoService.getById(docInfo.getAttributionId()); |
| | | docInfo.setNodeName(componentInfo.getComponentName()); |
| | | docInfo.setNodeCode(componentInfo.getComponentCode()); |
| | | break; |
| | | case 3: |
| | | PartsInfo partsInfo=partsInfoService.getById(docInfo.getAttributionId()); |
| | | docInfo.setNodeCode(partsInfo.getPartsCode()); |
| | | docInfo.setNodeName(partsInfo.getPartsName()); |
| | | break; |
| | | case 4: |
| | | ProcessSpecVersion processSpecVersion=processSpecVersionService.getById(docInfo.getAttributionId()); |
| | | docInfo.setNodeName(processSpecVersion.getProcessSpecVersionName()); |
| | | docInfo.setNodeCode(processSpecVersion.getProcessSpecVersionCode()); |
| | | break; |
| | | case 5: |
| | | ProcessStream processStream=processStreamService.getById(docInfo.getAttributionId()); |
| | | docInfo.setNodeName(processStream.getProcessName()); |
| | | docInfo.setNodeCode(processStream.getProcessCode()); |
| | | break; |
| | | case 6: |
| | | WorkStep workStep=workStepService.getById(docInfo.getAttributionId()); |
| | | docInfo.setNodeName(workStep.getStepName()); |
| | | docInfo.setNodeCode(workStep.getStepName()); |
| | | break; |
| | | } |
| | | }); |
| | | } |
| | | return docInfos; |
| | | } |
| | | |
| | | private List<DocInfo> getByTreeNcFileInfo(List<DocInfo> docInfos){ |
| | | //对所属id进行翻译 |
| | | if (docInfos != null && !docInfos.isEmpty()) { |
| | | docInfos.forEach(docInfo -> { |
| | | //NC文件存在设备类下 |
| | | DeviceType deviceType=deviceTypeService.getById(docInfo.getAttributionId()); |
| | | DeviceManagement deviceManagement= deviceManagementService.getById(deviceType.getDeviceManagementId()); |
| | | docInfo.setDeviceName(deviceManagement.getDeviceManagementName()); |
| | | docInfo.setDeviceCode(deviceManagement.getDeviceManagementCode()); |
| | | if (deviceType.getAttributionType().equals(DocAttributionTypeEnum.PROCESS.getCode())){ |
| | | //工序下的设备类 |
| | | ProcessStream processStream=processStreamService.getById(deviceType.getAttributionId()); |
| | | docInfo.setNodeName(processStream.getProcessName()); |
| | | docInfo.setNodeCode(processStream.getProcessCode()); |
| | | }else { |
| | | //工步下的设备类 |
| | | WorkStep workStep=workStepService.getById(deviceType.getAttributionId()); |
| | | docInfo.setNodeName(workStep.getStepName()); |
| | | docInfo.setNodeCode(workStep.getStepName()); |
| | | } |
| | | }); |
| | | } |
| | | return docInfos; |
| | | } |
| | | |
| | | /** |
| | | * 验证输入参数 |
| | | */ |
| | |
| | | .map(PartsInfo::getPartsId) |
| | | .collect(Collectors.toList()); |
| | | handlePartsPermissions(partsIds, userList, partsPermissionList, permissionStreamList); |
| | | List<String> psvIds = processSpecVersionService.getByPartsIds(partsIds).stream().map(ProcessSpecVersion::getId).collect(Collectors.toList()); |
| | | handlePsvPermissions(psvIds, userList, processSpecVersionPermissionList, permissionStreamList); |
| | | List<ProcessSpecVersion> processSpecVersionList = processSpecVersionService.getByPartsIds(partsIds); |
| | | if (processSpecVersionList!= null &&!processSpecVersionList.isEmpty()) { |
| | | List<String> psvIds = processSpecVersionList.stream().map(ProcessSpecVersion::getId).collect(Collectors.toList()); |
| | | handlePsvPermissions(psvIds, userList, processSpecVersionPermissionList, permissionStreamList); |
| | | } |
| | | List<ProcessStream> processStreamList = processStreamService.getByComponentIdList(productId, componentIds, partsIds); |
| | | processStreamApi(productId, userList, processionPermissionList, workStepPermissionList, permissionStreamList, processStreamList); |
| | | } |
| | |
| | | componentPermissionList.add(cp); |
| | | ComponentInfo cpInfo = componentInfoMap.get(cp.getComponentId()); |
| | | PermissionStreamNew s = new PermissionStreamNew(); |
| | | s.setBusinessId(cpInfo.getProductId()); |
| | | s.setBusinessType("1"); |
| | | s.setBusinessId(cpInfo.getComponentId()); |
| | | s.setBusinessType(DocAttributionTypeEnum.COMPONENT.getCode().toString()); |
| | | s.setUserId(cp.getUserId()); |
| | | permissionStreamList.add(s); |
| | | } |
| | |
| | | PartsInfo ptInfo = partsInfoMap.get(pp.getPartsId()); |
| | | PermissionStreamNew s = new PermissionStreamNew(); |
| | | s.setBusinessId(ptInfo.getPartsId()); |
| | | s.setBusinessType("3"); |
| | | s.setBusinessType(DocAttributionTypeEnum.PARTS.getCode().toString()); |
| | | s.setUserId(pp.getUserId()); |
| | | permissionStreamList.add(s); |
| | | } |
| | |
| | | ProcessSpecVersion processSpecVersion = processStreamMap.get(pp.getPsvId()); |
| | | PermissionStreamNew s = new PermissionStreamNew(); |
| | | s.setBusinessId(processSpecVersion.getId()); |
| | | s.setBusinessType("4"); |
| | | s.setBusinessType(DocAttributionTypeEnum.OPERATION.getCode().toString()); |
| | | s.setUserId(pp.getUserId()); |
| | | permissionStreamList.add(s); |
| | | } |
| | |
| | | ProcessStream processStream = processStreamMap.get(pp.getProcessId()); |
| | | PermissionStreamNew s = new PermissionStreamNew(); |
| | | s.setBusinessId(processStream.getProcessId()); |
| | | s.setBusinessType("5"); |
| | | s.setBusinessType(DocAttributionTypeEnum.PROCESS.getCode().toString()); |
| | | s.setUserId(pp.getUserId()); |
| | | permissionStreamList.add(s); |
| | | } |
| | |
| | | WorkStep workStep = workStepHashMap.get(ws.getStepId()); |
| | | PermissionStreamNew s = new PermissionStreamNew(); |
| | | s.setBusinessId(workStep.getId()); |
| | | s.setBusinessType("6"); |
| | | s.setBusinessType(DocAttributionTypeEnum.WORKSITE.getCode().toString()); |
| | | s.setUserId(ws.getUserId()); |
| | | permissionStreamList.add(s); |
| | | } |
| | |
| | | .collect(Collectors.toList()); |
| | | } |
| | | componentIds.add(componentInfo.getComponentId()); |
| | | |
| | | |
| | | handleRelativePermissions(componentInfo.getProductId(), componentIds, null, null,null, userList); |
| | | } |
| | | }else { |
| | |
| | | WorkStep workStep = workStepMap.get(wsDep.getStepId()); |
| | | PermissionStreamNew permStream = new PermissionStreamNew(); |
| | | permStream.setBusinessId(workStep.getId()); |
| | | permStream.setBusinessType("6"); |
| | | permStream.setBusinessType(DocAttributionTypeEnum.WORKSITE.getCode().toString()); |
| | | permStream.setDepartId(wsDep.getDepartId()); |
| | | newPermissionStreams.add(permStream); |
| | | } |
| | |
| | | ProcessStream processStream = processStreamMap.get(procDep.getProcessId()); |
| | | PermissionStreamNew permStream = new PermissionStreamNew(); |
| | | permStream.setBusinessId(processStream.getProcessId()); |
| | | permStream.setBusinessType("5"); |
| | | permStream.setBusinessType(DocAttributionTypeEnum.PROCESS.getCode().toString()); |
| | | permStream.setDepartId(procDep.getDepartId()); |
| | | newPermissionStreams.add(permStream); |
| | | } |
| | |
| | | ComponentInfo componentInfo = componentInfoMap.get(compDep.getComponentId()); |
| | | PermissionStreamNew permStream = new PermissionStreamNew(); |
| | | permStream.setBusinessId(componentInfo.getComponentId()); |
| | | permStream.setBusinessType("2"); |
| | | permStream.setBusinessType(DocAttributionTypeEnum.COMPONENT.getCode().toString()); |
| | | permStream.setDepartId(compDep.getDepartId()); |
| | | newPermissionStreams.add(permStream); |
| | | } |
| | |
| | | childComponent = componentInfoMap.get(compDep.getComponentId()); |
| | | PermissionStreamNew permStream = new PermissionStreamNew(); |
| | | permStream.setBusinessId(childComponent.getComponentId()); |
| | | permStream.setBusinessType("2"); |
| | | permStream.setBusinessType(DocAttributionTypeEnum.COMPONENT.getCode().toString()); |
| | | permStream.setDepartId(compDep.getDepartId()); |
| | | newPermissionStreams.add(permStream); |
| | | } |
| | |
| | | |
| | | private void handlePartsRemovals(String productId, List<String> componentIds,Collection<SysUser> userList) { |
| | | List<PartsInfo> partsInfoList = partsInfoService.getByComponentIdList(productId, componentIds); |
| | | partsInfoList.forEach(item->{ |
| | | partsInfoService.assignRemoveUser(item,userList); |
| | | //删除 |
| | | handlePartRelatedRemovals(item, userList); |
| | | }); |
| | | if (partsInfoList!=null){ |
| | | partsInfoList.forEach(item->{ |
| | | partsInfoService.assignRemoveUser(item,userList); |
| | | //删除 |
| | | handlePartRelatedRemovals(item, userList); |
| | | }); |
| | | } |
| | | } |
| | | private void handlePartsDepartmentRemovals(String productId, List<String> componentIds, Collection<MdcProduction> mdcProductionList) { |
| | | List<PartsInfo> partsInfoList = partsInfoService.getByComponentIdList(productId, componentIds); |
| | | partsInfoList.forEach(item->{ |
| | | partsInfoService.assignRemoveDepart(item,mdcProductionList); |
| | | handlePartRelatedDepartmentRemovals(item, mdcProductionList); |
| | | }); |
| | | if (partsInfoList!=null) { |
| | | partsInfoList.forEach(item->{ |
| | | partsInfoService.assignRemoveDepart(item,mdcProductionList); |
| | | handlePartRelatedDepartmentRemovals(item, mdcProductionList); |
| | | }); |
| | | } |
| | | } |
| | | |
| | | private void handleComponentRelatedRemovals(ComponentInfo componentInfo, Collection<SysUser> userList, Collection<MdcProduction> mdcProductionList) { |