| | |
| | | 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 org.jeecg.modules.dnc.entity.*; |
| | | import org.jeecg.modules.dnc.exception.ExceptionCast; |
| | | 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; |
| | |
| | | private IWorkStepPermissionService iWorkStepPermissionService; |
| | | @Autowired |
| | | private IProductMixService productMixService; |
| | | @Autowired |
| | | @Lazy |
| | | private IDocInfoService docInfoService; |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = {Exception.class}) |
| | |
| | | ExceptionCast.cast(ProductInfoCode.PRODUCT_SAVE_ERROR); |
| | | } |
| | | //添加结构树 |
| | | ProductMix productMix = new ProductMix(Long.parseLong(productInfo.getProductId()),0L,productInfo.getProductName(),productInfo.getProductNo(),1); |
| | | 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("1"); |
| | | permissionStreamNewService.save(stream); |
| | | } |
| | | } |
| | | //添加用户权限 |
| | | PermissionStreamNew stream = new PermissionStreamNew(); |
| | | stream.setBusinessId(productInfo.getProductId()); |
| | | stream.setUserId(userId); |
| | | stream.setBusinessType("1"); |
| | | return permissionStreamNewService.save(stream); |
| | | return permissionStreamNewService.addPermissionStreamNew(stream); |
| | | } |
| | | |
| | | @Override |
| | |
| | | } |
| | | |
| | | /** |
| | | * 通过代号、名称、材质等查询对应电子样板 |
| | | * @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)); |
| | | } |
| | | 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()); |
| | | } |
| | | }); |
| | | } |
| | | return docInfos; |
| | | } |
| | | |
| | | /** |
| | | * 验证输入参数 |
| | | */ |
| | | private void validateInputParameters(Integer nodeType, String paramId, Integer relativeFlag, String type, String[] paramIds) { |