|
@@ -2,14 +2,16 @@ package com.ruoyi.basicData.service.impl;
|
|
|
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
-import com.ruoyi.basicData.domain.TWarehouse;
|
|
|
+import com.ruoyi.common.core.domain.entity.TWarehouse;
|
|
|
import com.ruoyi.basicData.domain.TWarehouseArea;
|
|
|
import com.ruoyi.basicData.mapper.TWarehouseAreaMapper;
|
|
|
import com.ruoyi.basicData.mapper.TWarehouseMapper;
|
|
|
import com.ruoyi.basicData.service.ITWarehouseService;
|
|
|
import com.ruoyi.common.constant.UserConstants;
|
|
|
import com.ruoyi.common.core.domain.AjaxResult;
|
|
|
+import com.ruoyi.common.core.domain.TreeSelect;
|
|
|
import com.ruoyi.common.core.domain.model.LoginUser;
|
|
|
+import com.ruoyi.common.exception.CustomException;
|
|
|
import com.ruoyi.common.utils.DateUtils;
|
|
|
import com.ruoyi.common.utils.StringUtils;
|
|
|
import com.ruoyi.warehouseBusiness.domain.TWarehouseBills;
|
|
@@ -19,10 +21,8 @@ import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.transaction.interceptor.TransactionAspectSupport;
|
|
|
|
|
|
-import java.util.Date;
|
|
|
-import java.util.HashMap;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
+import java.util.*;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* 仓库Service业务层处理
|
|
@@ -90,6 +90,12 @@ public class TWarehouseServiceImpl implements ITWarehouseService {
|
|
|
@Transactional
|
|
|
public int insertTWarehouse(TWarehouse tWarehouse) {
|
|
|
tWarehouse.setCreateTime(DateUtils.getNowDate());
|
|
|
+ TWarehouse info = tWarehouseMapper.selectTWarehouseById(tWarehouse.getParentId());
|
|
|
+ // 如果父节点不为正常状态,则不允许新增子节点
|
|
|
+ if (!UserConstants.DEPT_NORMAL.equals(info.getfStatus())) {
|
|
|
+ throw new CustomException("部门停用,不允许新增");
|
|
|
+ }
|
|
|
+ tWarehouse.setAncestors(info.getAncestors() + "," + tWarehouse.getParentId());
|
|
|
return tWarehouseMapper.insertTWarehouse(tWarehouse);
|
|
|
}
|
|
|
|
|
@@ -172,6 +178,53 @@ public class TWarehouseServiceImpl implements ITWarehouseService {
|
|
|
return AjaxResult.success();
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public int updateTWarehouses(TWarehouse tWarehouse) {
|
|
|
+ TWarehouse newParentTWarehouse = tWarehouseMapper.selectTWarehouseById(tWarehouse.getParentId());
|
|
|
+ TWarehouse oldTWarehouse = tWarehouseMapper.selectTWarehouseById(tWarehouse.getfId());
|
|
|
+ if (StringUtils.isNotNull(newParentTWarehouse) && StringUtils.isNotNull(oldTWarehouse)) {
|
|
|
+ String newAncestors = newParentTWarehouse.getAncestors() + "," + newParentTWarehouse.getfId();
|
|
|
+ String oldAncestors = oldTWarehouse.getAncestors();
|
|
|
+ tWarehouse.setAncestors(newAncestors);
|
|
|
+ updateDeptChildren(tWarehouse.getfId(), newAncestors, oldAncestors);
|
|
|
+ }
|
|
|
+ int result = tWarehouseMapper.updateTWarehouse(tWarehouse);
|
|
|
+ if (UserConstants.DEPT_NORMAL.equals(tWarehouse.getfStatus())) {
|
|
|
+ // 如果该部门是启用状态,则启用该部门的所有上级部门
|
|
|
+ updateParentDeptStatus(tWarehouse);
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 修改子元素关系
|
|
|
+ *
|
|
|
+ * @param deptId 被修改的部门ID
|
|
|
+ * @param newAncestors 新的父ID集合
|
|
|
+ * @param oldAncestors 旧的父ID集合
|
|
|
+ */
|
|
|
+ public void updateDeptChildren(Long deptId, String newAncestors, String oldAncestors) {
|
|
|
+ List<TWarehouse> children = tWarehouseMapper.selectChildrenDeptById(deptId);
|
|
|
+ for (TWarehouse child : children) {
|
|
|
+ child.setAncestors(child.getAncestors().replace(oldAncestors, newAncestors));
|
|
|
+ }
|
|
|
+ if (children.size() > 0) {
|
|
|
+ tWarehouseMapper.updateDeptChildren(children);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 修改该部门的父级部门状态
|
|
|
+ *
|
|
|
+ * @param tWarehouse 当前部门
|
|
|
+ */
|
|
|
+ private void updateParentDeptStatus(TWarehouse tWarehouse) {
|
|
|
+ String updateBy = tWarehouse.getUpdateBy();
|
|
|
+ tWarehouse = tWarehouseMapper.selectTWarehouseById(tWarehouse.getfId());
|
|
|
+ tWarehouse.setUpdateBy(updateBy);
|
|
|
+ tWarehouseMapper.updateDeptStatus(tWarehouse);
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 批量删除仓库
|
|
|
*
|
|
@@ -255,4 +308,87 @@ public class TWarehouseServiceImpl implements ITWarehouseService {
|
|
|
return UserConstants.UNIQUE;
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public int selectNormalChildrenDeptById(Long fId) {
|
|
|
+ return tWarehouseMapper.selectNormalChildrenDeptById(fId);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<TreeSelect> buildDeptTreeSelect(List<TWarehouse> tWarehouses) {
|
|
|
+ List<TWarehouse> deptTrees = buildDeptTree(tWarehouses);
|
|
|
+ return deptTrees.stream().map(TreeSelect::new).collect(Collectors.toList());
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 构建前端所需要树结构
|
|
|
+ *
|
|
|
+ * @param depts 部门列表
|
|
|
+ * @return 树结构列表
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public List<TWarehouse> buildDeptTree(List<TWarehouse> depts) {
|
|
|
+ List<TWarehouse> returnList = new ArrayList<TWarehouse>();
|
|
|
+ List<Long> tempList = new ArrayList<Long>();
|
|
|
+ for (TWarehouse dept : depts) {
|
|
|
+ tempList.add(dept.getfId());
|
|
|
+ }
|
|
|
+ for (Iterator<TWarehouse> iterator = depts.iterator(); iterator.hasNext(); ) {
|
|
|
+ TWarehouse dept = (TWarehouse) iterator.next();
|
|
|
+ // 如果是顶级节点, 遍历该父节点的所有子节点
|
|
|
+ if (!tempList.contains(dept.getParentId())) {
|
|
|
+ recursionFn(depts, dept);
|
|
|
+ returnList.add(dept);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (returnList.isEmpty()) {
|
|
|
+ returnList = depts;
|
|
|
+ }
|
|
|
+ return returnList;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public String checkUFAreUnique(TWarehouse tWarehouse) {
|
|
|
+ TWarehouseArea tWarehouseArea = tWarehouseAreaMapper.selectTWarehouseAreaByWarehouseId(tWarehouse.getParentId());
|
|
|
+ if (StringUtils.isNotNull(tWarehouseArea) ) {
|
|
|
+ return UserConstants.NOT_UNIQUE;
|
|
|
+ }
|
|
|
+ return UserConstants.UNIQUE;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 递归列表
|
|
|
+ */
|
|
|
+ private void recursionFn(List<TWarehouse> list, TWarehouse t) {
|
|
|
+ // 得到子节点列表
|
|
|
+ List<TWarehouse> childList = getChildList(list, t);
|
|
|
+ t.setChildren(childList);
|
|
|
+ for (TWarehouse tChild : childList) {
|
|
|
+ if (hasChild(list, tChild)) {
|
|
|
+ recursionFn(list, tChild);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 得到子节点列表
|
|
|
+ */
|
|
|
+ private List<TWarehouse> getChildList(List<TWarehouse> list, TWarehouse t) {
|
|
|
+ List<TWarehouse> tlist = new ArrayList<TWarehouse>();
|
|
|
+ Iterator<TWarehouse> it = list.iterator();
|
|
|
+ while (it.hasNext()) {
|
|
|
+ TWarehouse n = (TWarehouse) it.next();
|
|
|
+ if (StringUtils.isNotNull(n.getParentId()) && n.getParentId().longValue() == t.getfId().longValue()) {
|
|
|
+ tlist.add(n);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return tlist;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 判断是否有子节点
|
|
|
+ */
|
|
|
+ private boolean hasChild(List<TWarehouse> list, TWarehouse t) {
|
|
|
+ return getChildList(list, t).size() > 0 ? true : false;
|
|
|
+ }
|
|
|
+
|
|
|
}
|