| | |
| | | package org.jeecg.modules.system.service.impl; |
| | | |
| | | import cn.hutool.core.collection.CollectionUtil; |
| | | import cn.hutool.core.util.StrUtil; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; |
| | | import com.baomidou.mybatisplus.core.toolkit.IdWorker; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import org.apache.commons.lang3.StringUtils; |
| | |
| | | mdcProduction.setOrgType(String.valueOf(orgType)); |
| | | mdcProduction.setDelFlag(CommonConstant.DEL_FLAG_0.toString()); |
| | | this.save(mdcProduction); |
| | | |
| | | //处理存在父子关系 mdc标记统一的问题 |
| | | //1.mdc标记 为 1 开启 父级节点要统一开启 |
| | | //2.mdc标记 为 0 关闭 子级节点要统一关闭 新增操作 不存在此情况 |
| | | if(StringUtils.isNotBlank(parentId) && CommonConstant.DEFAULT_1.equals(mdcProduction.getMdcFlag())){ |
| | | openParentMdcFlag(parentId); |
| | | } |
| | | } |
| | | } |
| | | |
| | |
| | | public boolean updateProductionDataById(MdcProduction mdcProduction) { |
| | | if (mdcProduction != null) { |
| | | this.updateById(mdcProduction); |
| | | |
| | | //处理存在父子关系 mdc标记统一的问题 |
| | | //1.mdc标记 为 1 开启 父级节点要统一开启 |
| | | //2.mdc标记 为 0 关闭 子级节点要统一关闭 |
| | | String parentId = mdcProduction.getParentId(); |
| | | if(StringUtils.isNotBlank(parentId) && CommonConstant.DEFAULT_1.equals(mdcProduction.getMdcFlag())){ |
| | | openParentMdcFlag(parentId); |
| | | } |
| | | if(CommonConstant.DEFAULT_0.equals(mdcProduction.getMdcFlag())){ |
| | | //关闭 |
| | | closeChildrenMdcFlag(mdcProduction.getId()); |
| | | } |
| | | return true; |
| | | } |
| | | return false; |
| | |
| | | public List<String> findAllProductionIds(List<String> ids){ |
| | | return this.baseMapper.recursionChildrenByList(ids); |
| | | } |
| | | |
| | | @Override |
| | | public List<String> findParentIdsForProduction(String parentId, List<String> idList) { |
| | | if (StringUtils.isEmpty(parentId)) { |
| | | return null; |
| | | } |
| | | if (idList == null || idList.isEmpty()) { |
| | | idList = new ArrayList<>(); |
| | | } |
| | | boolean p = true; |
| | | if (p) { |
| | | MdcProduction en = super.getById(parentId); |
| | | if (en != null) { |
| | | idList.add(0, en.getId()); |
| | | } |
| | | if (StringUtils.isNotBlank(en.getParentId())) { |
| | | parentId = en.getParentId(); |
| | | findParentIdsForProduction(parentId, idList); |
| | | } else { |
| | | p = false; |
| | | return idList; |
| | | } |
| | | } |
| | | return idList; |
| | | } |
| | | |
| | | /** |
| | | * 打开 父节点 及 以上的mdc标记 |
| | | * @param parentId |
| | | */ |
| | | private void openParentMdcFlag(String parentId) { |
| | | List<String> listParentTree = findParentIdsForProduction(parentId, new ArrayList<>()); |
| | | if (!CollectionUtil.isEmpty(listParentTree)) { |
| | | UpdateWrapper<MdcProduction> updateWrapper = new UpdateWrapper<>(); |
| | | updateWrapper.in("id", listParentTree); |
| | | updateWrapper.set("mdc_flag", "1"); |
| | | super.update(updateWrapper); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 关闭所有子节点的mdc标记 |
| | | * @param productionId |
| | | */ |
| | | private void closeChildrenMdcFlag(String productionId) { |
| | | List<String> childrenList = recursionChildren(productionId); |
| | | if (!CollectionUtil.isEmpty(childrenList)) { |
| | | UpdateWrapper<MdcProduction> updateWrapper = new UpdateWrapper<>(); |
| | | updateWrapper.in("id", childrenList); |
| | | updateWrapper.set("mdc_flag", "0"); |
| | | super.update(updateWrapper); |
| | | } |
| | | } |
| | | } |