|
@@ -0,0 +1,76 @@
|
|
|
|
+package com.abi.qms.platform.service.impl;
|
|
|
|
+
|
|
|
|
+import cn.hutool.core.collection.CollectionUtil;
|
|
|
|
+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.abi.task.common.api.exception.BusinessException;
|
|
|
|
+import com.abi.task.common.api.exception.ErrorCodeEnum;
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
|
+
|
|
|
|
+import java.util.List;
|
|
|
|
+
|
|
|
|
+/**
|
|
|
|
+ * @author: fangxinjian
|
|
|
|
+ * @date: 2021/06/01 17:20
|
|
|
|
+ * @description:
|
|
|
|
+ */
|
|
|
|
+@Service
|
|
|
|
+public class BaseSapOrganizationServiceImpl implements BaseSapOrganizationService {
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private BaseSapOrganizationMapper baseSapOrganizationMapper;
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
|
+ public void batchImportOrganization(BatchImportOrganizationReq req) {
|
|
|
|
+ List<BatchImportOrganizationReq.SapOrganization> organizationList = req.getOrganizationList();
|
|
|
|
+
|
|
|
|
+ for (BatchImportOrganizationReq.SapOrganization sap : organizationList) {
|
|
|
|
+
|
|
|
|
+ BaseSapOrganization organization = new BaseSapOrganization();
|
|
|
|
+ organization.setCustomerCode(sap.getCustomerCode());
|
|
|
|
+ organization.setCustomerName(sap.getCustomerName());
|
|
|
|
+ organization.setOrganizationLevel(sap.getOrganizationLevel());
|
|
|
|
+ organization.setParentCode(sap.getParentCode());
|
|
|
|
+ organization.setProvince(sap.getProvince());
|
|
|
|
+ organization.setId(sap.getId());
|
|
|
|
+
|
|
|
|
+ saveBaseSapOrganization(organization);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public void saveBaseSapOrganization(BaseSapOrganization bso) {
|
|
|
|
+
|
|
|
|
+ //校验入参 code不能重复
|
|
|
|
+ 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)) {
|
|
|
|
+ throw new BusinessException(ErrorCodeEnum.ERROR_PARAM.getCode(), "组织架构ID已存在");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (bso.getId() != null) {
|
|
|
|
+ BaseSapOrganization baseSapOrganization = baseSapOrganizationMapper.selectById(bso.getId());
|
|
|
|
+ AssertUtil.isNull(baseSapOrganization, "组织架构不存在");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //新增or修改
|
|
|
|
+ if (bso.getId() != null) {
|
|
|
|
+ baseSapOrganizationMapper.updateById(bso);
|
|
|
|
+ } else {
|
|
|
|
+ baseSapOrganizationMapper.insert(bso);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+}
|