|
@@ -1,6 +1,7 @@
|
|
package cn.iocoder.yudao.module.system.service.dept;
|
|
package cn.iocoder.yudao.module.system.service.dept;
|
|
|
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
|
+import cn.hutool.core.collection.CollectionUtil;
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
|
|
import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
|
|
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
|
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
|
@@ -8,7 +9,9 @@ import cn.iocoder.yudao.framework.datapermission.core.annotation.DataPermission;
|
|
import cn.iocoder.yudao.module.system.controller.admin.dept.vo.dept.DeptListReqVO;
|
|
import cn.iocoder.yudao.module.system.controller.admin.dept.vo.dept.DeptListReqVO;
|
|
import cn.iocoder.yudao.module.system.controller.admin.dept.vo.dept.DeptSaveReqVO;
|
|
import cn.iocoder.yudao.module.system.controller.admin.dept.vo.dept.DeptSaveReqVO;
|
|
import cn.iocoder.yudao.module.system.dal.dataobject.dept.DeptDO;
|
|
import cn.iocoder.yudao.module.system.dal.dataobject.dept.DeptDO;
|
|
|
|
+import cn.iocoder.yudao.module.system.dal.dataobject.deptsaporg.DeptSapOrgDO;
|
|
import cn.iocoder.yudao.module.system.dal.mysql.dept.DeptMapper;
|
|
import cn.iocoder.yudao.module.system.dal.mysql.dept.DeptMapper;
|
|
|
|
+import cn.iocoder.yudao.module.system.dal.mysql.deptsaporg.DeptSapOrgMapper;
|
|
import cn.iocoder.yudao.module.system.dal.redis.RedisKeyConstants;
|
|
import cn.iocoder.yudao.module.system.dal.redis.RedisKeyConstants;
|
|
import com.google.common.annotations.VisibleForTesting;
|
|
import com.google.common.annotations.VisibleForTesting;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
@@ -22,6 +25,7 @@ import javax.annotation.Resource;
|
|
import java.util.*;
|
|
import java.util.*;
|
|
|
|
|
|
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
|
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
|
|
|
+import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList;
|
|
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet;
|
|
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet;
|
|
import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.*;
|
|
import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.*;
|
|
|
|
|
|
@@ -37,8 +41,8 @@ public class DeptServiceImpl implements DeptService {
|
|
|
|
|
|
@Resource
|
|
@Resource
|
|
private DeptMapper deptMapper;
|
|
private DeptMapper deptMapper;
|
|
-// @Resource
|
|
|
|
-// private IotTreeMapper iotTreeMapper;
|
|
|
|
|
|
+ @Resource
|
|
|
|
+ private DeptSapOrgMapper deptSapOrgMapper;
|
|
|
|
|
|
@Override
|
|
@Override
|
|
@CacheEvict(cacheNames = RedisKeyConstants.DEPT_CHILDREN_ID_LIST,
|
|
@CacheEvict(cacheNames = RedisKeyConstants.DEPT_CHILDREN_ID_LIST,
|
|
@@ -56,6 +60,22 @@ public class DeptServiceImpl implements DeptService {
|
|
// 插入部门
|
|
// 插入部门
|
|
DeptDO dept = BeanUtils.toBean(createReqVO, DeptDO.class);
|
|
DeptDO dept = BeanUtils.toBean(createReqVO, DeptDO.class);
|
|
deptMapper.insert(dept);
|
|
deptMapper.insert(dept);
|
|
|
|
+ // 2.2 插入关联SAP工厂
|
|
|
|
+ if (CollectionUtil.isNotEmpty(dept.getFactoryIds())) {
|
|
|
|
+ deptSapOrgMapper.insertBatch(convertList(dept.getFactoryIds(),
|
|
|
|
+ factoryId -> new DeptSapOrgDO().setDeptId(dept.getId()).setFactoryId(factoryId)));
|
|
|
|
+ }
|
|
|
|
+ // 2.2 插入关联SAP成本中心
|
|
|
|
+ if (CollectionUtil.isNotEmpty(dept.getCostCenterIds())) {
|
|
|
|
+ deptSapOrgMapper.insertBatch(convertList(dept.getCostCenterIds(),
|
|
|
|
+ costCenterId -> new DeptSapOrgDO().setDeptId(dept.getId()).setCostCenterId(costCenterId)));
|
|
|
|
+ }
|
|
|
|
+ // 2.2 插入关联SAP库存地点
|
|
|
|
+ if (CollectionUtil.isNotEmpty(dept.getStockLocationIds())) {
|
|
|
|
+ deptSapOrgMapper.insertBatch(convertList(dept.getStockLocationIds(),
|
|
|
|
+ stockLocationId -> new DeptSapOrgDO().setDeptId(dept.getId()).setStockLocationId(stockLocationId)));
|
|
|
|
+ }
|
|
|
|
+
|
|
return dept.getId();
|
|
return dept.getId();
|
|
}
|
|
}
|
|
|
|
|
|
@@ -77,6 +97,55 @@ public class DeptServiceImpl implements DeptService {
|
|
DeptDO updateObj = BeanUtils.toBean(updateReqVO, DeptDO.class);
|
|
DeptDO updateObj = BeanUtils.toBean(updateReqVO, DeptDO.class);
|
|
|
|
|
|
deptMapper.updateById(updateObj);
|
|
deptMapper.updateById(updateObj);
|
|
|
|
+
|
|
|
|
+ // 2.2 更新SAP工厂/成本中心/库存地点
|
|
|
|
+ updateSapOrg(updateReqVO, updateObj);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void updateSapOrg(DeptSaveReqVO updateReqVO, DeptDO updateObj) {
|
|
|
|
+ Long deptId = updateReqVO.getId();
|
|
|
|
+ // 查询部门已经关联的SAP工厂
|
|
|
|
+ Set<Long> dbFactoryIds = convertSet(deptSapOrgMapper.selectListByDeptId(deptId), DeptSapOrgDO::getFactoryId);
|
|
|
|
+ // 查询部门已经关联的SAP成本中心
|
|
|
|
+ Set<Long> dbCostCenterIds = convertSet(deptSapOrgMapper.selectListByDeptId(deptId), DeptSapOrgDO::getCostCenterId);
|
|
|
|
+ // 查询部门已经关联的SAP库存地点
|
|
|
|
+ Set<Long> dbStockLocationIds = convertSet(deptSapOrgMapper.selectListByDeptId(deptId), DeptSapOrgDO::getStockLocationId);
|
|
|
|
+ // 计算新增和删除的SAP工厂编号
|
|
|
|
+ Set<Long> factoryIds = CollUtil.emptyIfNull(updateObj.getFactoryIds());
|
|
|
|
+ Collection<Long> createFactoryIds = CollUtil.subtract(factoryIds, dbFactoryIds);
|
|
|
|
+ Collection<Long> deleteFactoryIds = CollUtil.subtract(dbFactoryIds, factoryIds);
|
|
|
|
+ // 执行新增和删除。对于已经授权的 SAP工厂,不用做任何处理
|
|
|
|
+ if (!CollectionUtil.isEmpty(createFactoryIds)) {
|
|
|
|
+ deptSapOrgMapper.insertBatch(convertList(createFactoryIds,
|
|
|
|
+ factoryId -> new DeptSapOrgDO().setDeptId(deptId).setFactoryId(factoryId)));
|
|
|
|
+ }
|
|
|
|
+ if (!CollectionUtil.isEmpty(deleteFactoryIds)) {
|
|
|
|
+ deptSapOrgMapper.deleteByDeptIdAndFactoryId(deptId, deleteFactoryIds);
|
|
|
|
+ }
|
|
|
|
+ // 计算新增和删除的SAP成本中心
|
|
|
|
+ Set<Long> costCenterIds = CollUtil.emptyIfNull(updateObj.getCostCenterIds());
|
|
|
|
+ Collection<Long> createCostCenterIds = CollUtil.subtract(costCenterIds, dbCostCenterIds);
|
|
|
|
+ Collection<Long> deleteCostCenterIds = CollUtil.subtract(dbCostCenterIds, costCenterIds);
|
|
|
|
+ // 执行新增和删除。对于已经授权的 SAP成本中心,不用做任何处理
|
|
|
|
+ if (!CollectionUtil.isEmpty(createCostCenterIds)) {
|
|
|
|
+ deptSapOrgMapper.insertBatch(convertList(createCostCenterIds,
|
|
|
|
+ costCenterId -> new DeptSapOrgDO().setDeptId(deptId).setCostCenterId(costCenterId)));
|
|
|
|
+ }
|
|
|
|
+ if (!CollectionUtil.isEmpty(deleteCostCenterIds)) {
|
|
|
|
+ deptSapOrgMapper.deleteByDeptIdAndCostCenterId(deptId, deleteCostCenterIds);
|
|
|
|
+ }
|
|
|
|
+ // 计算新增和删除的SAP库存地点
|
|
|
|
+ Set<Long> stockLocationIds = CollUtil.emptyIfNull(updateObj.getStockLocationIds());
|
|
|
|
+ Collection<Long> createStockLocationIds = CollUtil.subtract(stockLocationIds, dbStockLocationIds);
|
|
|
|
+ Collection<Long> deleteStockLocationIds = CollUtil.subtract(dbStockLocationIds, stockLocationIds);
|
|
|
|
+ // 执行新增和删除。对于已经授权的 SAP库存地点,不用做任何处理
|
|
|
|
+ if (!CollectionUtil.isEmpty(createStockLocationIds)) {
|
|
|
|
+ deptSapOrgMapper.insertBatch(convertList(createStockLocationIds,
|
|
|
|
+ stockLocationId -> new DeptSapOrgDO().setDeptId(deptId).setStockLocationId(stockLocationId)));
|
|
|
|
+ }
|
|
|
|
+ if (!CollectionUtil.isEmpty(deleteStockLocationIds)) {
|
|
|
|
+ deptSapOrgMapper.deleteByDeptIdAndStockLocationId(deptId, deleteStockLocationIds);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|