递归遍历树结构,前端传入一整颗树,后端处置处罚这个树,包罗天生树的id和pid等信息,

[复制链接]
发表于 2026-4-24 08:58:57 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?立即注册

×
递归逻辑

递归遍历树结构,将树结构转换list聚集 并添加到 flowStepTree 聚集
  1.         // 递归遍历树结构,将树结构转换list集合 并添加到 flowStepTree 集合
  2.         private static void settingTree(ProductFlowStepVO node, Long parentId, String ancestors, List<ProductFlowStepVO> flowStepTree) {
  3.                 long currentId = IdWorker.getId();
  4.                 node.setId(currentId);
  5.                 node.setParentId(parentId);
  6.                 node.setAncestors(ancestors + "," + node.getParentId());  // 层级码 通过 , 号隔离
  7.                 flowStepTree.add(node);
  8.                 List<ProductFlowStepVO> children = node.getChildren();
  9.                 if (CollectionUtils.isNotEmpty(children)) {
  10.                         children.forEach(c -> settingTree(c, currentId, ancestors + "," + node.getParentId(), flowStepTree));
  11.                 }
  12.         }
复制代码
吸取前端树的结构 ProductFlowVO   由于除了树结构尚有其他参数,

吸取的树结构 ProductFlowVO  和其他数据
  1. package com.bluebird.code.vo;
  2. import com.bluebird.code.entity.ProductFlowEntity;
  3. import io.swagger.annotations.ApiModelProperty;
  4. import lombok.Data;
  5. import lombok.EqualsAndHashCode;
  6. import java.util.List;
  7. /**
  8. * 赋码 -产品流程表 视图实体类
  9. */
  10. @Data
  11. @EqualsAndHashCode(callSuper = true)
  12. public class ProductFlowVO extends ProductFlowEntity {
  13.         private static final long serialVersionUID = 1L;
  14.         @ApiModelProperty(value = "树子元素")
  15.         private List<ProductFlowStepVO> flowStepTree;
  16.         //详情返回使用
  17.         @ApiModelProperty(value = "集合转树结构")
  18.         private List<ProductFlowStepTreeVO> listTree;
  19.         /**
  20.          * 产品名称
  21.          */
  22.         @ApiModelProperty(value = "产品名称")
  23.         private String codeProName;
  24.         @ApiModelProperty(value = "开始更新时间")
  25.         private String startUpdateDate;
  26.         @ApiModelProperty(value = "结束更新时间")
  27.         private String endUpdateDate;
  28.         @ApiModelProperty(value = "产品id集合")
  29.         private String productIds;
  30.         /**
  31.          * 产品名称集合
  32.          */
  33.         @ApiModelProperty(value = "产品名称集合Id")
  34.         private String productIdList;
  35. }
复制代码
继承的实体类 ProductFlowEntity 
  1. package com.bluebird.code.entity;
  2. import com.baomidou.mybatisplus.annotation.TableName;
  3. import com.bluebird.core.tenant.mp.TenantEntity;
  4. import io.swagger.annotations.ApiModel;
  5. import io.swagger.annotations.ApiModelProperty;
  6. import lombok.Data;
  7. import lombok.EqualsAndHashCode;
  8. /**
  9. * 赋码 -产品流程表 实体类
  10. */
  11. @Data
  12. @TableName("t_code_product_flow")
  13. @ApiModel(value = "ProductFlow对象", description = "赋码 -产品流程表")
  14. @EqualsAndHashCode(callSuper = true)
  15. public class ProductFlowEntity extends TenantEntity {
  16.         /**
  17.          * 企业Id
  18.          */
  19.         @ApiModelProperty(value = "企业Id")
  20.         private Long enterpriseId;
  21.         /**
  22.          * 产品ID
  23.          */
  24.         @ApiModelProperty(value = "产品ID")
  25.         private Long proId;
  26.         /**
  27.          * 流程步骤名称
  28.          */
  29.         @ApiModelProperty(value = "流程步骤名称")
  30.         private String stepName;
  31.         /**
  32.          * 排序
  33.          */
  34.         @ApiModelProperty(value = "排序")
  35.         private Integer sort;
  36.         /**
  37.          * 备注
  38.          */
  39.         @ApiModelProperty(value = "备注")
  40.         private String remark;
  41.         /**
  42.          * 类型 1:公司 2:部门 3:小组 0:其他
  43.          */
  44.         @ApiModelProperty(value = "类型 1:公司 2:部门 3:小组 0:其他")
  45.         private Integer category;
  46.         /**
  47.          * 产品id
  48.          */
  49.         @ApiModelProperty(value = "产品id")
  50.         private Long productId;
  51.         @ApiModelProperty(value = "产品名字集合")
  52.         private String productName;
  53.         @ApiModelProperty(value = "创建人名称")
  54.         private String createName;
  55. }
复制代码
树结构的对象和继承类
  1. package com.bluebird.code.vo;
  2. import com.bluebird.code.entity.ProductFlowStepEntity;
  3. import lombok.Data;
  4. import lombok.EqualsAndHashCode;
  5. import java.util.List;
  6. // 接收前端树的结构
  7. @Data
  8. @EqualsAndHashCode(callSuper = true)
  9. public class ProductFlowStepVO extends ProductFlowStepEntity {
  10.         private static final long serialVersionUID = 1L;
  11.         private List<ProductFlowStepVO> children;
  12. }
复制代码
继承的实体类 ProductFlowStepEntity
  1. package com.bluebird.code.entity;
  2. import com.baomidou.mybatisplus.annotation.TableName;
  3. import com.bluebird.core.tenant.mp.TenantEntity;
  4. import io.swagger.annotations.ApiModel;
  5. import io.swagger.annotations.ApiModelProperty;
  6. import lombok.Data;
  7. import lombok.EqualsAndHashCode;
  8. /**
  9. * 赋码 -产品流程步骤表 实体类
  10. *
  11. */
  12. @Data
  13. @TableName("t_code_product_flow_step")
  14. @ApiModel(value = "ProductFlowStep对象", description = "赋码 -产品流程步骤表")
  15. @EqualsAndHashCode(callSuper = true)
  16. public class ProductFlowStepEntity extends TenantEntity {
  17.         /**
  18.          * 企业Id
  19.          */
  20.         @ApiModelProperty(value = "企业Id")
  21.         private Long enterpriseId;
  22.         /**
  23.          * 产品流程ID
  24.          */
  25.         @ApiModelProperty(value = "产品流程ID")
  26.         private Long flowId;
  27.         /**
  28.          * 父主键
  29.          */
  30.         @ApiModelProperty(value = "父主键")
  31.         private Long parentId;
  32.         /**
  33.          * 目录名
  34.          */
  35.         @ApiModelProperty(value = "目录名")
  36.         private String name;
  37.         /**
  38.          * 全称
  39.          */
  40.         @ApiModelProperty(value = "全称")
  41.         private String fullName;
  42.         /**
  43.          * 祖级列表
  44.          */
  45.         @ApiModelProperty(value = "祖级列表")
  46.         private String ancestors;
  47.         /**
  48.          * 备注
  49.          */
  50.         @ApiModelProperty(value = "备注")
  51.         private String remark;
  52.         /**
  53.          * 是否公开 (0:否 1:是 2:草稿 9:其他)
  54.          */
  55.         @ApiModelProperty(value = "是否公开 (0:否 1:是 2:草稿 9:其他)")
  56.         private Integer isPublic;
  57.         /**
  58.          * 是否继承 (0:否 1:是)
  59.          */
  60.         @ApiModelProperty(value = "是否继承 (0:否 1:是)")
  61.         private Integer isInherit;
  62.         /**
  63.          * 排序
  64.          */
  65.         @ApiModelProperty(value = "排序")
  66.         private Integer sort;
  67.         /**
  68.          * 类型 1:公司 2:部门 3:小组 0:其他
  69.          */
  70.         @ApiModelProperty(value = "类型 1:公司 2:部门 3:小组 0:其他")
  71.         private Integer category;
  72.         /**
  73.          * 产品id
  74.          */
  75.         @ApiModelProperty(value = "产品id")
  76.         private Long productId;
  77. }
复制代码
组装树结构 ProductFlowStepTreeVO对象(一样平常返回前端组装数据使用)
  1. package com.bluebird.code.vo;
  2. import com.bluebird.code.entity.CodeProductFlowBatchStepDataEntity;
  3. import com.bluebird.core.tool.node.INode;
  4. import com.fasterxml.jackson.annotation.JsonInclude;
  5. import com.fasterxml.jackson.databind.annotation.JsonSerialize;
  6. import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
  7. import io.swagger.annotations.ApiModel;
  8. import lombok.Data;
  9. import lombok.EqualsAndHashCode;
  10. import java.util.ArrayList;
  11. import java.util.List;
  12. /**
  13. * 赋码 -产品流程树 用户详情回显使用
  14. *
  15. */
  16. @Data
  17. @EqualsAndHashCode()
  18. @ApiModel(value = "ProductFilesVO对象", description = "ProductFilesVO对象")
  19. public class ProductFlowStepTreeVO  implements INode<ProductFlowStepTreeVO> {
  20.         private static final long serialVersionUID = 1L;
  21.         /**
  22.          * 主键ID
  23.          */
  24.         @JsonSerialize(using = ToStringSerializer.class)
  25.         private Long id;
  26.         /**
  27.          * 父节点ID
  28.          */
  29.         @JsonSerialize(using = ToStringSerializer.class)
  30.         private Long parentId;
  31.         /**
  32.          * 子孙节点
  33.          */
  34.         @JsonInclude(JsonInclude.Include.NON_EMPTY)
  35.         private List<ProductFlowStepTreeVO> children;
  36.         /**
  37.          * 是否有子孙节点
  38.          */
  39.         @JsonInclude(JsonInclude.Include.NON_EMPTY)
  40.         private Boolean hasChildren;
  41.         @Override
  42.         public List<ProductFlowStepTreeVO> getChildren() {
  43.                 if (this.children == null) {
  44.                         this.children = new ArrayList<>();
  45.                 }
  46.                 return this.children;
  47.         }
  48.         /**
  49.          * 名称
  50.          */
  51.         private String name;
  52.         /**
  53.          * 是否公开 (0:否 1:是 2:草稿 9:其他)
  54.          */
  55.         private Integer isPublic;
  56.         // 产品批次流程步骤数据表
  57.         List<CodeProductFlowBatchStepDataEntity> flowBatchStepDataList;
  58. }
复制代码
整个service实现类
  1. package com.bluebird.code.service.impl;import com.alibaba.nacos.common.utils.CollectionUtils;import com.baomidou.mybatisplus.core.conditions.Wrapper;import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;import com.baomidou.mybatisplus.core.metadata.IPage;import com.baomidou.mybatisplus.core.toolkit.IdWorker;import com.bluebird.code.entity.*;import com.bluebird.code.excel.ProductFlowExcel;import com.bluebird.code.mapper.*;import com.bluebird.code.service.IProductFlowService;import com.bluebird.code.service.IProductFlowStepService;import com.bluebird.code.vo.ProductFlowStepTreeVO;import com.bluebird.code.vo.ProductFlowStepVO;import com.bluebird.code.vo.ProductFlowVO;import com.bluebird.code.vo.ProductVO;import com.bluebird.common.constant.CommonConstant;import com.bluebird.common.enums.common.EYn;import com.bluebird.common.utils.IotAuthUtil;import com.bluebird.core.log.exception.ServiceException;import com.bluebird.core.mp.base.BaseServiceImpl;import com.bluebird.core.tool.constant.HulkConstant;import com.bluebird.core.tool.node.ForestNodeMerger;import com.bluebird.core.tool.utils.StringPool;import org.springframework.beans.BeanUtils;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.stereotype.Service;import org.springframework.transaction.annotation.Transactional;import java.util.*;import java.util.stream.Collectors;/** * 赋码 -产物流程表 服务实现类  */@Servicepublic class ProductFlowServiceImpl extends BaseServiceImpl<ProductFlowMapper, ProductFlowEntity> implements IProductFlowService {        @Autowired        IProductFlowStepService productFlowStepService;        @Autowired        ProductFlowStepMapper productFlowStepMapper;        @Autowired        ProducttAssociationFlowMapper producttAssociationFlowMapper;        @Autowired        ProductFlowMapper productFlowMapper;        @Autowired        CodeProductFlowBatchStepDataMapper flowBatchStepDataMapper;        @Autowired        ProductFlowBatchStepMapper productFlowBatchStepMapper;        @Override        public IPage<ProductFlowVO> selectProductFlowPage(IPage<ProductFlowVO> page, ProductFlowVO productFlow) {                String tenantId = IotAuthUtil.getTenantId();                if (tenantId.equals(CommonConstant.ADMIN_TENANT_ID)) {                        productFlow.setTenantId(null);                        productFlow.setEnterpriseId(null);                } else {                        if (!tenantId.equals(CommonConstant.ADMIN_TENANT_ID) && IotAuthUtil.getEnterpriseId().equals(EYn.YES.getValue())) {                                productFlow.setTenantId(tenantId);                                productFlow.setEnterpriseId(null);                        } else {                                productFlow.setTenantId(tenantId);                                productFlow.setEnterpriseId(IotAuthUtil.getEnterpriseId());                        }                }                List<ProductFlowVO> list = baseMapper.selectProductFlowPage(page, productFlow);                /*if (list != null && list.size() > 0) {                        for (ProductFlowVO flowVO : list) {                                List<ProductVO> listProductName = productFlowMapper.selectProductFlowById(flowVO.getId());                                if (listProductName != null && listProductName.size() > 0) {                                        flowVO.setCodeProNameList(listProductName.stream().map(ProductVO::getCodeProName).collect(Collectors.joining(",")));                                        flowVO.setProductIdList(listProductName.stream().map(ProductVO::getProductId).map(String::valueOf).collect(Collectors.joining(",")));                                }                        }                }*/                return page.setRecords(list);        }        @Override        public List<ProductFlowExcel> exportProductFlow(Wrapper<ProductFlowEntity> queryWrapper) {                List<ProductFlowExcel> productFlowList = baseMapper.exportProductFlow(queryWrapper);                //productFlowList.forEach(productFlow -> {                //        productFlow.setTypeName(DictCache.getValue(DictEnum.YES_NO, ProductFlow.getType()));                //});                return productFlowList;        }        // 新增 产物流程和流程步调        @Override        @Transactional(rollbackFor = Exception.class)        public boolean saveProductFlowAndStep(ProductFlowVO productFlowVO) {                Long enterpriseId = IotAuthUtil.getEnterpriseId();                String tenantId = IotAuthUtil.getTenantId();                Long userId = IotAuthUtil.getUserId();                String deptId = IotAuthUtil.getDeptId();                //添加流程                ProductFlowEntity productFlow = new ProductFlowEntity();                BeanUtils.copyProperties(productFlowVO, productFlow);                productFlow.setEnterpriseId(enterpriseId);                productFlow.setCreateName(IotAuthUtil.getNickName());                save(productFlow);                // 处置处罚绑定的流程                List<Long> listProductId = Arrays.stream(productFlowVO.getProductIds().split(",")).map(Long::valueOf).collect(Collectors.toList());                for (Long productId : listProductId) {                        ProducttAssociationFlowEntity entity = new ProducttAssociationFlowEntity();                        entity.setProductId(productId);                        entity.setFlowId(productFlow.getId());                        producttAssociationFlowMapper.insert(entity);                }                //添加流程步调 吸取树结构                List<ProductFlowStepVO> flowStepTree = productFlowVO.getFlowStepTree();                List<ProductFlowStepVO> listAll = new ArrayList<>();                //处置处罚树结构后的数据 添加到聚集 listAll                flowStepTree.forEach(node -> settingTree(node, 0L, "", listAll));                List<ProductFlowStepEntity> list = new ArrayList<>();                for (ProductFlowStepVO flowStepVO : listAll) {                        ProductFlowStepEntity productFlowStep = new ProductFlowStepEntity();                        BeanUtils.copyProperties(flowStepVO, productFlowStep);                        if (EYn.NO.getValue().equals(flowStepVO.getIsDeleted())) { // 前端有大概添加3个数据,删除2个数据,又添加 1 个数据,末了实际有用的数据的是 2 条                                productFlowStep.setFlowId(productFlow.getId());                                productFlowStep.setProductId(productFlowVO.getProductId());                                productFlowStep.setCreateUser(userId);                                productFlowStep.setCreateTime(new Date());                                productFlowStep.setUpdateUser(userId);                                productFlowStep.setUpdateTime(new Date());                                productFlowStep.setCreateDept(Long.valueOf(deptId));                                productFlowStep.setEnterpriseId(enterpriseId);                                productFlowStep.setTenantId(tenantId);                                productFlowStep.setIsDeleted(HulkConstant.DB_NOT_DELETED);                                list.add(productFlowStep);                        }                }                productFlowStepService.saveBatch(list);                return true;        }        // 修改 产物流程和流程步调        @Override        @Transactional(rollbackFor = Exception.class)        public boolean updateProductFlowAndStepById(ProductFlowVO productFlowVO) {                Long enterpriseId = IotAuthUtil.getEnterpriseId();                String tenantId = IotAuthUtil.getTenantId();                Long userId = IotAuthUtil.getUserId();                String deptId = IotAuthUtil.getDeptId();                //修改流程                ProductFlowEntity productFlow = new ProductFlowEntity();                BeanUtils.copyProperties(productFlowVO, productFlow);                productFlowMapper.updateById(productFlow);                // 处置处罚流程产物关联表                LambdaQueryWrapper<ProducttAssociationFlowEntity> queryWrapper = new LambdaQueryWrapper<>();                queryWrapper.eq(ProducttAssociationFlowEntity::getFlowId, productFlow.getId());                producttAssociationFlowMapper.delete(queryWrapper);                List<Long> listProductId = Arrays.stream(productFlowVO.getProductIds().split(",")).map(Long::valueOf).collect(Collectors.toList());                for (Long productId : listProductId) {                        ProducttAssociationFlowEntity entity = new ProducttAssociationFlowEntity();                        entity.setProductId(productId);                        entity.setFlowId(productFlow.getId());                        producttAssociationFlowMapper.insert(entity);                }                //修改流程步调 包罗 新增/修改/删除                List<ProductFlowStepEntity> addList = new ArrayList<>();                List<ProductFlowStepEntity> updateList = new ArrayList<>();                List<ProductFlowStepEntity> deleteList = new ArrayList<>();                List<ProductFlowStepVO> list = productFlowVO.getFlowStepTree();                List<ProductFlowStepVO> listAdd = new ArrayList<>();                List<ProductFlowStepVO> listUpdate = new ArrayList<>();                list.forEach(node -> settingTreeAddOrUpdate(node, 0L, "", listAdd, listUpdate));                for (ProductFlowStepVO flowStepVO : listAdd) {                        ProductFlowStepEntity productFlowStep = new ProductFlowStepEntity();                        BeanUtils.copyProperties(flowStepVO, productFlowStep);                        productFlowStep.setFlowId(productFlow.getId());                        productFlowStep.setProductId(productFlowVO.getProductId());                        productFlowStep.setCreateUser(userId);                        productFlowStep.setCreateTime(new Date());                        productFlowStep.setUpdateUser(userId);                        productFlowStep.setUpdateTime(new Date());                        productFlowStep.setCreateDept(Long.valueOf(deptId));                        productFlowStep.setEnterpriseId(enterpriseId);                        productFlowStep.setTenantId(tenantId);                        productFlowStep.setIsDeleted(HulkConstant.DB_NOT_DELETED);                        addList.add(productFlowStep);                }                for (ProductFlowStepVO flowStepVO : listUpdate) {                        ProductFlowStepEntity productFlowStep = new ProductFlowStepEntity();                        BeanUtils.copyProperties(flowStepVO, productFlowStep);                        if (Objects.equals(flowStepVO.getIsDeleted(), HulkConstant.DB_NOT_DELETED)) {                                updateList.add(productFlowStep);                        } else {                                deleteList.add(productFlowStep);                        }                }                if (addList != null && addList.size() > 0) {                        productFlowStepService.saveBatch(addList);                }                if (updateList != null && updateList.size() > 0) {                        //处置处罚修改                        productFlowStepService.updateBatchById(updateList);                }                if (deleteList != null && deleteList.size() > 0) {                        //  删除 判断是否有流程步调的数据                        for (ProductFlowStepEntity flowStep : deleteList) {                                LambdaQueryWrapper<CodeProductFlowBatchStepDataEntity> lambdaQueryWrapper = new LambdaQueryWrapper<>();                                lambdaQueryWrapper.eq(CodeProductFlowBatchStepDataEntity::getIsDeleted, HulkConstant.DB_NOT_DELETED);                                lambdaQueryWrapper.eq(CodeProductFlowBatchStepDataEntity::getOneStepId, flowStep.getId());                                lambdaQueryWrapper.eq(CodeProductFlowBatchStepDataEntity::getEnterpriseId, IotAuthUtil.getEnterpriseId());                                Long count = flowBatchStepDataMapper.selectCount(lambdaQueryWrapper);                                if (count > 0) {                                        throw new ServiceException(flowStep.getName() + " 流程步调下有流程步调数据,请先删除流程步调数据!");                                }                        }                        productFlowStepService.removeBatchByIds(deleteList);                }                return true;        }        // 详情        @Override        public ProductFlowVO getDetail(ProductFlowEntity flowEntity) {                ProductFlowVO productFlowVO = new ProductFlowVO();                ProductFlowEntity productFlow = getById(flowEntity.getId());                BeanUtils.copyProperties(productFlow, productFlowVO);                List<ProductVO> listProductName = productFlowMapper.selectProductFlowById(flowEntity.getId());                if (listProductName != null && listProductName.size() > 0) {                        productFlowVO.setProductIdList(listProductName.stream().map(ProductVO::getProductId).map(String::valueOf).collect(Collectors.joining(",")));                }                // 查询树聚集                List<ProductFlowStepTreeVO> list = productFlowStepMapper.selectListFlowStep(flowEntity.getId());                List<ProductFlowStepTreeVO> merge = ForestNodeMerger.merge(list);                productFlowVO.setListTree(merge);                return productFlowVO;        }        // 根据流程 id 查询 产物名称 产物id 产物型号        @Override        public List<ProductVO> selectProductByFlowId(Long flowId) {                List<ProductVO> listProductName = productFlowMapper.selectProductFlowById(flowId);                return listProductName;        }        //  产物流程表 判断流程是否有树 树下面是否有溯源数据        @Override        @Transactional(rollbackFor = Exception.class)        public boolean deleteProductFlow(List<Long> toLongList) {                //  判断流程是否有树 树下面是否有溯源数据                LambdaQueryWrapper<ProductFlowStepEntity> queryWrapper = new LambdaQueryWrapper<>();                queryWrapper.in(ProductFlowStepEntity::getFlowId, toLongList);                List<ProductFlowStepEntity> list = productFlowStepService.list(queryWrapper);                List<Long> listStepId = new ArrayList<>();                if (list != null && list.size() > 0) {                        for (ProductFlowStepEntity step : list) {                                //  删除 判断是否有流程步调的数据                                LambdaQueryWrapper<CodeProductFlowBatchStepDataEntity> lambdaQueryWrapper = new LambdaQueryWrapper<>();                                lambdaQueryWrapper.eq(CodeProductFlowBatchStepDataEntity::getIsDeleted, HulkConstant.DB_NOT_DELETED);                                lambdaQueryWrapper.eq(CodeProductFlowBatchStepDataEntity::getOneStepId, step.getId());                                lambdaQueryWrapper.eq(CodeProductFlowBatchStepDataEntity::getEnterpriseId, IotAuthUtil.getEnterpriseId());                                Long count = flowBatchStepDataMapper.selectCount(lambdaQueryWrapper);                                if (count > 0) {                                        throw new ServiceException(step.getName() + " 流程步调下有流程步调数据,请先删除流程步调数据!");                                }                                listStepId.add(step.getId());                        }                }                // 判断流程下面是否有数据维护的数据                for (Long flowId : toLongList) {                        LambdaQueryWrapper<ProductFlowBatchStepEntity> queryWrapperFlowBatchStep = new LambdaQueryWrapper<>();                        queryWrapperFlowBatchStep.eq(ProductFlowBatchStepEntity::getFlowId, flowId);                        queryWrapperFlowBatchStep.eq(ProductFlowBatchStepEntity::getIsDeleted, HulkConstant.DB_NOT_DELETED);                        queryWrapperFlowBatchStep.eq(ProductFlowBatchStepEntity::getEnterpriseId, IotAuthUtil.getEnterpriseId());                        List<ProductFlowBatchStepEntity> listFlowBatchStep = productFlowBatchStepMapper.selectList(queryWrapperFlowBatchStep);                        if (listFlowBatchStep != null && listFlowBatchStep.size() > 0) {                                ProductFlowEntity productFlow = getById(flowId);                                String stepName = "";                                if (productFlow != null) {                                        stepName = productFlow.getStepName();                                }                                for (ProductFlowBatchStepEntity flowBatchStep : listFlowBatchStep) {                                        throw new ServiceException("该流程下有流程名称为【" + stepName + "】的数据维护,请先删除数据维护!");                                }                        }                }                // 删除流程                boolean remove = removeByIds(toLongList);                //删除流程下面的树                productFlowStepService.removeBatchByIds(listStepId);                // 删除产物和流程的关联表                LambdaQueryWrapper<ProducttAssociationFlowEntity> queryWrapperFlow = new LambdaQueryWrapper();                queryWrapperFlow.in(ProducttAssociationFlowEntity::getFlowId, toLongList);                producttAssociationFlowMapper.delete(queryWrapperFlow);                return remove;        }        // 修改调用  由于修改涉及 添加/删除和修改        private static void settingTreeAddOrUpdate(ProductFlowStepVO node, Long parentId, String ancestors, List<ProductFlowStepVO> addList, List<ProductFlowStepVO> updateList) {                if (node.getId() == null) {                        long currentId = IdWorker.getId();                        node.setId(currentId);                        node.setParentId(parentId);                        node.setAncestors(ancestors + StringPool.COMMA + node.getParentId());                        addList.add(node);                        List<ProductFlowStepVO> children = node.getChildren();                        if (CollectionUtils.isNotEmpty(children)) {                                children.forEach(c -> settingTreeAddOrUpdate(c, currentId, ancestors + StringPool.COMMA + node.getParentId(), addList, updateList));                        }                } else {                        Long currentId = node.getId();                        node.setParentId(parentId);                        node.setAncestors(ancestors + StringPool.COMMA + node.getParentId());                        updateList.add(node);                        List<ProductFlowStepVO> children = node.getChildren();                        if (CollectionUtils.isNotEmpty(children)) {                                children.forEach(c -> settingTreeAddOrUpdate(c, currentId, ancestors + StringPool.COMMA + node.getParentId(), addList, updateList));                        }                }        }
  2.         // 递归遍历树结构,将树结构转换list集合 并添加到 flowStepTree 集合
  3.         private static void settingTree(ProductFlowStepVO node, Long parentId, String ancestors, List<ProductFlowStepVO> flowStepTree) {
  4.                 long currentId = IdWorker.getId();
  5.                 node.setId(currentId);
  6.                 node.setParentId(parentId);
  7.                 node.setAncestors(ancestors + "," + node.getParentId());  // 层级码 通过 , 号隔离
  8.                 flowStepTree.add(node);
  9.                 List<ProductFlowStepVO> children = node.getChildren();
  10.                 if (CollectionUtils.isNotEmpty(children)) {
  11.                         children.forEach(c -> settingTree(c, currentId, ancestors + "," + node.getParentId(), flowStepTree));
  12.                 }
  13.         }}
复制代码
前端传参树结构的数据格式,包罗其他数据,
  1. {
  2.     "stepName": "测试流程",
  3.     "productName": "汽车制造",
  4.     "flowStepTree": [
  5.         {
  6.             "key": 1,
  7.             "name": "第一步1",
  8.             "parentKey": 0,
  9.             "isDeleted": 0,
  10.             "children": [
  11.                 {
  12.                     "key": 2,
  13.                     "name": "第一步2",
  14.                     "parentKey": 1,
  15.                     "isDeleted": 0
  16.                 }
  17.             ]
  18.         },
  19.         {
  20.             "key": 3,
  21.             "name": "第二步1",
  22.             "parentKey": 0,
  23.             "isDeleted": 0,
  24.             "children": [
  25.                 {
  26.                     "key": 4,
  27.                     "name": "第二步2",
  28.                     "parentKey": 3,
  29.                     "isDeleted": 0
  30.                 },
  31.                 {
  32.                     "key": 5,
  33.                     "name": "第二步3-删除",
  34.                     "parentKey": 3,
  35.                     "isDeleted": 1
  36.                 },
  37.                 {
  38.                     "key": 6,
  39.                     "name": "第二步4",
  40.                     "parentKey": 3,
  41.                     "isDeleted": 0
  42.                 }
  43.             ]
  44.         }
  45.     ],
  46.     "productIds": "1808434897288286210"
  47. }
复制代码
控制器 ProductFlowController 
  1. package com.bluebird.code.controller;
  2. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  3. import com.baomidou.mybatisplus.core.metadata.IPage;
  4. import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
  5. import com.bluebird.code.entity.ProductFlowEntity;
  6. import com.bluebird.code.excel.ProductFlowExcel;
  7. import com.bluebird.code.service.IProductFlowService;
  8. import com.bluebird.code.service.IProductFlowStepService;
  9. import com.bluebird.code.util.MyEnterpriseUtils;
  10. import com.bluebird.code.vo.ProductFlowVO;
  11. import com.bluebird.code.vo.ProductVO;
  12. import com.bluebird.code.wrapper.ProductFlowWrapper;
  13. import com.bluebird.common.utils.IotAuthUtil;
  14. import com.bluebird.core.boot.ctrl.HulkController;
  15. import com.bluebird.core.excel.util.ExcelUtil;
  16. import com.bluebird.core.mp.support.Condition;
  17. import com.bluebird.core.mp.support.Query;
  18. import com.bluebird.core.secure.HulkUser;
  19. import com.bluebird.core.tool.api.R;
  20. import com.bluebird.core.tool.constant.HulkConstant;
  21. import com.bluebird.core.tool.utils.DateUtil;
  22. import com.bluebird.core.tool.utils.Func;
  23. import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
  24. import io.swagger.annotations.Api;
  25. import io.swagger.annotations.ApiOperation;
  26. import io.swagger.annotations.ApiParam;
  27. import lombok.AllArgsConstructor;
  28. import org.springframework.web.bind.annotation.*;
  29. import springfox.documentation.annotations.ApiIgnore;
  30. import javax.servlet.http.HttpServletResponse;
  31. import javax.validation.Valid;
  32. import java.util.List;
  33. import java.util.Map;
  34. /**
  35. * 赋码 -产品流程表 控制器
  36. */
  37. @RestController
  38. @AllArgsConstructor
  39. @RequestMapping("/productFlow")
  40. @Api(value = "赋码 -产品流程表", tags = "赋码 -产品流程表接口")
  41. public class ProductFlowController extends HulkController {
  42.         private final IProductFlowService productFlowService;
  43.         private final IProductFlowStepService productFlowStepService;
  44.         /**
  45.          * 赋码 -产品流程表 详情
  46.          */
  47.         @GetMapping("/detail")
  48.         @ApiOperationSupport(order = 1)
  49.         @ApiOperation(value = "详情", notes = "传入productFlow")
  50.         public R<ProductFlowVO> detail(ProductFlowEntity productFlow) {
  51.                 ProductFlowVO detail = productFlowService.getDetail(productFlow);
  52.                 return R.data(ProductFlowWrapper.build().entityVO(detail));
  53.         }
  54.         /**
  55.          * 赋码 -产品流程表 分页
  56.          */
  57.         @GetMapping("/list")
  58.         @ApiOperationSupport(order = 2)
  59.         @ApiOperation(value = "分页", notes = "传入productFlow")
  60.         public R<IPage<ProductFlowVO>> list(@ApiIgnore @RequestParam Map<String, Object> productFlow, Query query) {
  61.                 IPage<ProductFlowEntity> pages = productFlowService.page(Condition.getPage(query), Condition.getQueryWrapper(productFlow, ProductFlowEntity.class));
  62.                 return R.data(ProductFlowWrapper.build().pageVO(pages));
  63.         }
  64.         /**
  65.          * 赋码 -产品流程表 自定义分页
  66.          */
  67.         @GetMapping("/page")
  68.         @ApiOperationSupport(order = 3)
  69.         @ApiOperation(value = "分页", notes = "传入productFlow")
  70.         public R<IPage<ProductFlowVO>> page(ProductFlowVO productFlow, Query query) {
  71.                 IPage<ProductFlowVO> pages = productFlowService.selectProductFlowPage(Condition.getPage(query), productFlow);
  72.                 return R.data(pages);
  73.         }
  74.         /**
  75.          * 赋码 -产品流程表 新增
  76.          */
  77.         @PostMapping("/save")
  78.         @ApiOperationSupport(order = 4)
  79.         @ApiOperation(value = "新增", notes = "传入productFlow")
  80.         public R save(@Valid @RequestBody ProductFlowVO productFlow) {
  81.                 String toData = MyEnterpriseUtils.determineIsEnterprise("产品流程");
  82.                 if (Func.isNotBlank(toData)) {
  83.                         return R.fail(toData);
  84.                 }
  85.                 if (Func.isEmpty(productFlow.getStepName())) {
  86.                         return R.fail("流程名称不能为空!");
  87.                 }
  88.                 if (Func.isEmpty(productFlow.getProductIds())) {
  89.                         return R.fail("请先选择产品!");
  90.                 }
  91.                 if (Func.isEmpty(productFlow.getFlowStepTree())) {
  92.                         return R.fail("流程步骤不能为空!");
  93.                 }
  94.                 //判断产品流程名称是否重复
  95.                 Long count = new LambdaQueryChainWrapper<>(productFlowService.getBaseMapper())
  96.                         .eq(ProductFlowEntity::getStepName, productFlow.getStepName())
  97.                         .eq(ProductFlowEntity::getEnterpriseId, IotAuthUtil.getEnterpriseId()).count();
  98.                 if (count > 0) {
  99.                         return R.fail("流程名称已存在,不能重复!");
  100.                 }
  101.                 return R.status(productFlowService.saveProductFlowAndStep(productFlow));
  102.         }
  103.         /**
  104.          * 赋码 -产品流程表 修改
  105.          */
  106.         @PostMapping("/update")
  107.         @ApiOperationSupport(order = 5)
  108.         @ApiOperation(value = "修改", notes = "传入productFlow")
  109.         public R update(@Valid @RequestBody ProductFlowVO productFlow) {
  110.                 String toData = MyEnterpriseUtils.determineIsEnterprise("产品流程");
  111.                 if (Func.isNotBlank(toData)) {
  112.                         return R.fail(toData);
  113.                 }
  114.                 if (Func.isEmpty(productFlow.getStepName())) {
  115.                         return R.fail("流程名称不能为空!");
  116.                 }
  117.                 if (Func.isEmpty(productFlow.getProductIds())) {
  118.                         return R.fail("请先选择产品!");
  119.                 }
  120.                 if (Func.isEmpty(productFlow.getFlowStepTree())) {
  121.                         return R.fail("流程步骤不能为空!");
  122.                 }
  123.                 //判断产品流程名称是否重复
  124.                 Long count = new LambdaQueryChainWrapper<>(productFlowService.getBaseMapper())
  125.                         .ne(ProductFlowEntity::getId, productFlow.getId())
  126.                         .eq(ProductFlowEntity::getStepName, productFlow.getStepName())
  127.                         .eq(ProductFlowEntity::getEnterpriseId, IotAuthUtil.getEnterpriseId()).count();
  128.                 if (count > 0) {
  129.                         return R.fail("流程名称已存在,不能重复!");
  130.                 }
  131.                 return R.status(productFlowService.updateProductFlowAndStepById(productFlow));
  132.         }
  133.         /**
  134.          * 赋码 -产品流程表 新增或修改
  135.          */
  136.         @PostMapping("/submit")
  137.         @ApiOperationSupport(order = 6)
  138.         @ApiOperation(value = "新增或修改", notes = "传入productFlow")
  139.         public R submit(@Valid @RequestBody ProductFlowEntity productFlow) {
  140.                 return R.status(productFlowService.saveOrUpdate(productFlow));
  141.         }
  142.         /**
  143.          * 赋码 -产品流程表 删除
  144.          */
  145.         @PostMapping("/remove")
  146.         @ApiOperationSupport(order = 7)
  147.         @ApiOperation(value = "逻辑删除", notes = "传入ids")
  148.         public R remove(@ApiParam(value = "主键集合", required = true) @RequestParam String ids) {
  149.                 return R.status(productFlowService.deleteProductFlow(Func.toLongList(ids)));
  150.         }
  151.         /**
  152.          * 导出数据
  153.          */
  154.         @GetMapping("/export-productFlow")
  155.         @ApiOperationSupport(order = 9)
  156.         @ApiOperation(value = "导出数据", notes = "传入productFlow")
  157.         public void exportProductFlow(@ApiIgnore @RequestParam Map<String, Object> productFlow, HulkUser hulkUser, HttpServletResponse response) {
  158.                 QueryWrapper<ProductFlowEntity> queryWrapper = Condition.getQueryWrapper(productFlow, ProductFlowEntity.class);
  159.                 //if (!AuthUtil.isAdministrator()) {
  160.                 //        queryWrapper.lambda().eq(ProductFlow::getTenantId, hulkUser.getTenantId());
  161.                 //}
  162.                 queryWrapper.lambda().eq(ProductFlowEntity::getIsDeleted, HulkConstant.DB_NOT_DELETED);
  163.                 List<ProductFlowExcel> list = productFlowService.exportProductFlow(queryWrapper);
  164.                 ExcelUtil.export(response, "赋码 -产品流程表数据" + DateUtil.time(), "赋码 -产品流程表数据表", list, ProductFlowExcel.class);
  165.         }
  166.         /**
  167.          * 根据流程 id 查询 产品名称 产品id 产品型号
  168.          */
  169.         @GetMapping("/selectProductByFlowId")
  170.         @ApiOperationSupport(order = 1)
  171.         @ApiOperation(value = "根据流程 id 查询 产品名称/产品id/产品型号", notes = "传入productFlow")
  172.         public R<List<ProductVO>> selectProductByFlowId(@RequestParam Long flowId) {
  173.                 List<ProductVO> productVO = productFlowService.selectProductByFlowId(flowId);
  174.                 return R.data( productVO );
  175.         }
  176. }
复制代码

回复

使用道具 举报

登录后关闭弹窗

登录参与点评抽奖  加入IT实名职场社区
去登录
快速回复 返回顶部 返回列表