|
@@ -0,0 +1,77 @@
|
|
|
+package com.abi.qms.platform.service.impl;
|
|
|
+
|
|
|
+import cn.hutool.core.collection.CollectionUtil;
|
|
|
+import com.abi.qms.platform.dao.entity.BaseSapOrginzation;
|
|
|
+import com.abi.qms.platform.dao.mapper.BaseSapOrginzationMapper;
|
|
|
+import com.abi.qms.platform.dto.req.BatchImportOrginzationReq;
|
|
|
+import com.abi.qms.platform.infrastructure.util.AssertUtil;
|
|
|
+import com.abi.qms.platform.service.BaseSapOrginzationService;
|
|
|
+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 BaseSapOrginzationServiceImpl implements BaseSapOrginzationService {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private BaseSapOrginzationMapper baseSapOrginzationMapper;
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public void batchImportOrginzation(BatchImportOrginzationReq req) {
|
|
|
+ List<BatchImportOrginzationReq.SapOrginzation> orginzationList = req.getOrginzationList();
|
|
|
+
|
|
|
+ for (BatchImportOrginzationReq.SapOrginzation sap : orginzationList) {
|
|
|
+
|
|
|
+ BaseSapOrginzation orginzation = new BaseSapOrginzation();
|
|
|
+ orginzation.setCustomerCode(sap.getCustomerCode());
|
|
|
+ orginzation.setCustomerName(sap.getCustomerName());
|
|
|
+ orginzation.setOrginzationLevel(sap.getOrginzationLevel());
|
|
|
+ orginzation.setParentCode(sap.getParentCode());
|
|
|
+ orginzation.setProvince(sap.getProvince());
|
|
|
+ orginzation.setId(sap.getId());
|
|
|
+
|
|
|
+ saveBaseSapOrginzation(orginzation);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ public void saveBaseSapOrginzation(BaseSapOrginzation bso) {
|
|
|
+
|
|
|
+ //校验入参 code不能重复
|
|
|
+ QueryWrapper<BaseSapOrginzation> qw = new QueryWrapper<>();
|
|
|
+ qw.eq("customer_code", bso.getCustomerCode());
|
|
|
+ if (bso.getId() != null) {
|
|
|
+ qw.ne("id", bso.getId());
|
|
|
+ }
|
|
|
+ List<BaseSapOrginzation> orginzationList = baseSapOrginzationMapper.selectList(qw);
|
|
|
+ if (CollectionUtil.isNotEmpty(orginzationList)) {
|
|
|
+ throw new BusinessException(ErrorCodeEnum.ERROR_PARAM.getCode(), "组织架构ID已存在");
|
|
|
+ }
|
|
|
+
|
|
|
+ //声明对象
|
|
|
+ if (bso.getId() != null) {
|
|
|
+ BaseSapOrginzation baseSapOrginzation = baseSapOrginzationMapper.selectById(bso.getId());
|
|
|
+ AssertUtil.isNull(baseSapOrginzation, "组织架构不存在");
|
|
|
+ }
|
|
|
+
|
|
|
+ //新增or修改
|
|
|
+ if (bso.getId() != null) {
|
|
|
+ baseSapOrginzationMapper.updateById(bso);
|
|
|
+ } else {
|
|
|
+ baseSapOrginzationMapper.insert(bso);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+}
|