|
@@ -1,17 +1,16 @@
|
|
|
package com.abi.qms.platform.service.impl;
|
|
|
|
|
|
-import cn.hutool.core.collection.CollectionUtil;
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
import com.abi.qms.platform.dao.entity.BaseSapOrganization;
|
|
|
import com.abi.qms.platform.dao.mapper.BaseSapOrganizationMapper;
|
|
|
import com.abi.qms.platform.dto.req.BatchImportOrganizationReq;
|
|
|
-import com.abi.qms.platform.infrastructure.util.AssertUtil;
|
|
|
import com.abi.qms.platform.service.BaseSapOrganizationService;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
+import java.time.LocalDateTime;
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
@@ -40,7 +39,6 @@ public class BaseSapOrganizationServiceImpl implements BaseSapOrganizationServic
|
|
|
organization.setOrganizationLevel(sap.getOrganizationLevel());
|
|
|
organization.setParentCode(sap.getParentCode());
|
|
|
organization.setProvince(sap.getProvince());
|
|
|
- organization.setId(sap.getId());
|
|
|
|
|
|
saveBaseSapOrganization(organization);
|
|
|
} catch (Exception e) {
|
|
@@ -50,32 +48,66 @@ public class BaseSapOrganizationServiceImpl implements BaseSapOrganizationServic
|
|
|
|
|
|
}
|
|
|
|
|
|
- public void saveBaseSapOrganization(BaseSapOrganization bso) {
|
|
|
+ @Override
|
|
|
+ public void batchUpdateOrganization(BatchImportOrganizationReq req) {
|
|
|
+ List<BatchImportOrganizationReq.SapOrganization> organizationList = req.getOrganizationList();
|
|
|
|
|
|
-
|
|
|
- QueryWrapper<BaseSapOrganization> qw = new QueryWrapper<>();
|
|
|
- qw.eq("customer_code", bso.getCustomerCode());
|
|
|
- if (bso.getId() != null) {
|
|
|
- qw.ne("id", bso.getId());
|
|
|
- }
|
|
|
- List<BaseSapOrganization> organizationList = baseSapOrganizationMapper.selectList(qw);
|
|
|
- if (CollectionUtil.isNotEmpty(organizationList)) {
|
|
|
- log.info("组织架构代码:{}已存在", bso.getCustomerCode());
|
|
|
- }
|
|
|
+ for (BatchImportOrganizationReq.SapOrganization sap : organizationList) {
|
|
|
+
|
|
|
+ try {
|
|
|
+ BaseSapOrganization organization = new BaseSapOrganization();
|
|
|
+ organization.setCustomerCode(sap.getCustomerCode());
|
|
|
+ organization.setCustomerName(sap.getCustomerName());
|
|
|
+ organization.setOrganizationLevel(sap.getOrganizationLevel());
|
|
|
+ organization.setParentCode(sap.getParentCode());
|
|
|
+ organization.setProvince(sap.getProvince());
|
|
|
|
|
|
- if (bso.getId() != null) {
|
|
|
- BaseSapOrganization baseSapOrganization = baseSapOrganizationMapper.selectById(bso.getId());
|
|
|
- if (ObjectUtil.isNull(baseSapOrganization)) {
|
|
|
- log.info("组织架构代码:{}不存在", bso.getCustomerCode());
|
|
|
+ updateBeaseSapOrganization(organization);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("修改组织架构数据失败", e);
|
|
|
}
|
|
|
+
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- if (bso.getId() != null) {
|
|
|
- baseSapOrganizationMapper.updateById(bso);
|
|
|
- } else {
|
|
|
- baseSapOrganizationMapper.insert(bso);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void updateBeaseSapOrganization(BaseSapOrganization bso) {
|
|
|
+
|
|
|
+ BaseSapOrganization sapOrganization = getBaseSapOrganization(bso.getCustomerCode());
|
|
|
+
|
|
|
+ if (ObjectUtil.isNull(sapOrganization)) {
|
|
|
+ log.info("组织架构代码:{}不存在", bso.getCustomerCode());
|
|
|
+ }
|
|
|
+
|
|
|
+ bso.setId(sapOrganization.getId());
|
|
|
+ bso.setUpdateTime(LocalDateTime.now());
|
|
|
+ baseSapOrganizationMapper.updateById(bso);
|
|
|
+ }
|
|
|
+
|
|
|
+ public void saveBaseSapOrganization(BaseSapOrganization bso) {
|
|
|
+
|
|
|
+ BaseSapOrganization sapOrganization = getBaseSapOrganization(bso.getCustomerCode());
|
|
|
+
|
|
|
+ if (ObjectUtil.isNotNull(sapOrganization)) {
|
|
|
+ log.info("组织架构代码:{}已存在", bso.getCustomerCode());
|
|
|
+ return;
|
|
|
}
|
|
|
|
|
|
+ baseSapOrganizationMapper.insert(bso);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private BaseSapOrganization getBaseSapOrganization(String customerCode) {
|
|
|
+
|
|
|
+ QueryWrapper<BaseSapOrganization> qw = new QueryWrapper<>();
|
|
|
+ qw.eq("customer_code", customerCode);
|
|
|
+ qw.eq("is_delete", 0);
|
|
|
+
|
|
|
+
|
|
|
+ BaseSapOrganization baseSapOrganization = baseSapOrganizationMapper.selectOne(qw);
|
|
|
+
|
|
|
+ return baseSapOrganization;
|
|
|
+
|
|
|
}
|
|
|
}
|