|
@@ -5,7 +5,11 @@ import java.util.Iterator;
|
|
|
import java.util.List;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
+import com.ruoyi.common.constant.UserConstants;
|
|
|
import com.ruoyi.common.core.domain.TreeSelect;
|
|
|
+import com.ruoyi.common.core.domain.entity.SysDept;
|
|
|
+import com.ruoyi.common.core.text.Convert;
|
|
|
+import com.ruoyi.common.exception.ServiceException;
|
|
|
import com.ruoyi.common.utils.DateUtils;
|
|
|
import com.ruoyi.common.utils.StringUtils;
|
|
|
import com.ruoyi.common.utils.spring.SpringUtils;
|
|
@@ -60,6 +64,14 @@ public class IndustryCategoryServiceImpl implements IIndustryCategoryService
|
|
|
@Override
|
|
|
public int insertIndustryCategory(IndustryCategory industryCategory)
|
|
|
{
|
|
|
+
|
|
|
+ IndustryCategory industry = industryCategoryMapper.selectIndustryCategoryByCategoryId(industryCategory.getParentId());
|
|
|
+ // 如果父节点不为正常状态,则不允许新增子节点
|
|
|
+ if (!UserConstants.DEPT_NORMAL.equals(industry.getStatus()))
|
|
|
+ {
|
|
|
+ throw new ServiceException("类别停用,不允许新增");
|
|
|
+ }
|
|
|
+ industryCategory.setAncestors(industry.getAncestors() + "," + industryCategory.getParentId());
|
|
|
industryCategory.setCreateTime(DateUtils.getNowDate());
|
|
|
return industryCategoryMapper.insertIndustryCategory(industryCategory);
|
|
|
}
|
|
@@ -73,8 +85,56 @@ public class IndustryCategoryServiceImpl implements IIndustryCategoryService
|
|
|
@Override
|
|
|
public int updateIndustryCategory(IndustryCategory industryCategory)
|
|
|
{
|
|
|
+ IndustryCategory newParentIndustry = industryCategoryMapper.selectIndustryCategoryByCategoryId(industryCategory.getParentId());
|
|
|
+ IndustryCategory oldIndustry = industryCategoryMapper.selectIndustryCategoryByCategoryId(industryCategory.getCategoryId());
|
|
|
+ if (StringUtils.isNotNull(newParentIndustry) && StringUtils.isNotNull(oldIndustry))
|
|
|
+ {
|
|
|
+ String newAncestors = newParentIndustry.getAncestors() + "," + newParentIndustry.getCategoryId();
|
|
|
+ String oldAncestors = oldIndustry.getAncestors();
|
|
|
+ industryCategory.setAncestors(newAncestors);
|
|
|
+ updateDeptChildren(industryCategory.getCategoryId(), newAncestors, oldAncestors);
|
|
|
+ }
|
|
|
industryCategory.setUpdateTime(DateUtils.getNowDate());
|
|
|
- return industryCategoryMapper.updateIndustryCategory(industryCategory);
|
|
|
+ int result = industryCategoryMapper.updateIndustryCategory(industryCategory);
|
|
|
+ if (UserConstants.DEPT_NORMAL.equals(industryCategory.getStatus()) && StringUtils.isNotEmpty(industryCategory.getAncestors())
|
|
|
+ && !StringUtils.equals("0", industryCategory.getAncestors()))
|
|
|
+ {
|
|
|
+ // 如果该行业是启用状态,则启用该行业的所有上级部门
|
|
|
+ updateParentDeptStatusNormal(industryCategory);
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 修改该行业的父级部门状态
|
|
|
+ *
|
|
|
+ * @param industryCategory 当前行业
|
|
|
+ */
|
|
|
+ private void updateParentDeptStatusNormal(IndustryCategory industryCategory)
|
|
|
+ {
|
|
|
+ String ancestors = industryCategory.getAncestors();
|
|
|
+ Long[] ids = Convert.toLongArray(ancestors);
|
|
|
+ industryCategoryMapper.updateDeptStatusNormal(ids);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 修改子元素关系
|
|
|
+ *
|
|
|
+ * @param id 被修改的ID
|
|
|
+ * @param newAncestors 新的父ID集合
|
|
|
+ * @param oldAncestors 旧的父ID集合
|
|
|
+ */
|
|
|
+ public void updateDeptChildren(Long id, String newAncestors, String oldAncestors)
|
|
|
+ {
|
|
|
+ List<IndustryCategory> children = industryCategoryMapper.selectChildrenIndustryById(id);
|
|
|
+ for (IndustryCategory child : children)
|
|
|
+ {
|
|
|
+ child.setAncestors(child.getAncestors().replaceFirst(oldAncestors, newAncestors));
|
|
|
+ }
|
|
|
+ if (children.size() > 0)
|
|
|
+ {
|
|
|
+ industryCategoryMapper.updateIndustryChildren(children);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/**
|