diff --git a/demo-athenaopt_backend/develop/src/main/java/com/digiwin/athena/app/infra/entity/ItemExecutorEntity.java b/demo-athenaopt_backend/develop/src/main/java/com/digiwin/athena/app/infra/entity/ItemExecutorEntity.java new file mode 100644 index 0000000..217c636 --- /dev/null +++ b/demo-athenaopt_backend/develop/src/main/java/com/digiwin/athena/app/infra/entity/ItemExecutorEntity.java @@ -0,0 +1,56 @@ +package com.digiwin.athena.app.infra.entity; + +import com.baomidou.mybatisplus.annotation.TableName; +import com.digiwin.athena.opt.persistence.domain.BaseMgrEntity; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.google.gson.annotations.SerializedName; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * @Author: xieps + * @Date: 2023/8/30 14:03 + * @Version 1.0 + * @Description + */ +@Data +@AllArgsConstructor +@NoArgsConstructor +@Builder +@JsonIgnoreProperties(ignoreUnknown = true) +@TableName(value = "cim_item_execute", autoResultMap = true) +public class ItemExecutorEntity extends BaseMgrEntity { + + /** + * 品号 + */ + @SerializedName(value = "item_no") + @JsonProperty(value = "item_no") + private String itemNo; + + /** + * 品名 + */ + @SerializedName(value = "item_name") + @JsonProperty(value = "item_name") + private String itemName; + + /** + * 执行人编号 + */ + @SerializedName(value = "procurement_executor_code") + @JsonProperty(value = "procurement_executor_code") + private String procurementExecutorCode; + + /** + * 执行人名称 + */ + @SerializedName(value = "procurement_executor_name") + @JsonProperty(value = "procurement_executor_name") + private String procurementExecutorName; + + +} diff --git a/demo-athenaopt_backend/develop/src/main/java/com/digiwin/athena/app/infra/mapper/ItemExecutorMapper.xml b/demo-athenaopt_backend/develop/src/main/java/com/digiwin/athena/app/infra/mapper/ItemExecutorMapper.xml new file mode 100644 index 0000000..4d9f0ef --- /dev/null +++ b/demo-athenaopt_backend/develop/src/main/java/com/digiwin/athena/app/infra/mapper/ItemExecutorMapper.xml @@ -0,0 +1,21 @@ + + + + + + + + UPDATE cim_item_execute + + `item_name` = #{item.itemName}, + `procurement_executor_name` = #{item.procurementExecutorName} + + WHERE `tenantsid`=#{tenantSid} AND + `item_no`= #{item.itemNo} AND `procurement_executor_code` = #{item.procurementExecutorCode} + + + + + \ No newline at end of file diff --git a/demo-athenaopt_backend/develop/src/main/java/com/digiwin/athena/app/infra/repository/ItemExecutorRepository.java b/demo-athenaopt_backend/develop/src/main/java/com/digiwin/athena/app/infra/repository/ItemExecutorRepository.java new file mode 100644 index 0000000..6096f59 --- /dev/null +++ b/demo-athenaopt_backend/develop/src/main/java/com/digiwin/athena/app/infra/repository/ItemExecutorRepository.java @@ -0,0 +1,24 @@ +package com.digiwin.athena.app.infra.repository; + +import com.digiwin.athena.app.infra.entity.ItemExecutorEntity; +import com.digiwin.athena.opt.persistence.repository.BaseRepository; +import org.apache.ibatis.annotations.Param; + +import java.util.List; + +/** + * @Author: xieps + * @Date: 2023/8/30 14:21 + * @Version 1.0 + * @Description + */ +public interface ItemExecutorRepository extends BaseRepository { + + /** + * 批量更新 + * + * @param itemExecutorInfo + * @param tenantSid + */ + void updateBatch(@Param("list") List itemExecutorInfo, @Param("tenantSid") long tenantSid); +} diff --git a/demo-athenaopt_backend/develop/src/main/java/com/digiwin/athena/app/infra/service/Impl/ItemExecutorServiceImpl.java b/demo-athenaopt_backend/develop/src/main/java/com/digiwin/athena/app/infra/service/Impl/ItemExecutorServiceImpl.java new file mode 100644 index 0000000..2c1449a --- /dev/null +++ b/demo-athenaopt_backend/develop/src/main/java/com/digiwin/athena/app/infra/service/Impl/ItemExecutorServiceImpl.java @@ -0,0 +1,17 @@ +package com.digiwin.athena.app.infra.service.Impl; + +import com.digiwin.athena.app.infra.entity.ItemExecutorEntity; +import com.digiwin.athena.app.infra.repository.ItemExecutorRepository; +import com.digiwin.athena.app.infra.service.ItemExecutorService; +import com.digiwin.athena.opt.persistence.service.impl.AbsBaseService; +import org.springframework.stereotype.Service; + +/** + * @Author: xieps + * @Date: 2023/8/30 14:20 + * @Version 1.0 + * @Description + */ +@Service +public class ItemExecutorServiceImpl extends AbsBaseService implements ItemExecutorService { +} diff --git a/demo-athenaopt_backend/develop/src/main/java/com/digiwin/athena/app/infra/service/ItemExecutorService.java b/demo-athenaopt_backend/develop/src/main/java/com/digiwin/athena/app/infra/service/ItemExecutorService.java new file mode 100644 index 0000000..ab0f133 --- /dev/null +++ b/demo-athenaopt_backend/develop/src/main/java/com/digiwin/athena/app/infra/service/ItemExecutorService.java @@ -0,0 +1,13 @@ +package com.digiwin.athena.app.infra.service; + +import com.digiwin.athena.app.infra.entity.ItemExecutorEntity; +import com.digiwin.athena.opt.persistence.service.IBaseService; + +/** + * @Author: xieps + * @Date: 2023/8/30 14:19 + * @Version 1.0 + * @Description + */ +public interface ItemExecutorService extends IBaseService { +} diff --git a/demo-athenaopt_backend/develop/src/main/java/com/digiwin/athena/app/provider/ItemExecutorEAIService.java b/demo-athenaopt_backend/develop/src/main/java/com/digiwin/athena/app/provider/ItemExecutorEAIService.java new file mode 100644 index 0000000..357af7c --- /dev/null +++ b/demo-athenaopt_backend/develop/src/main/java/com/digiwin/athena/app/provider/ItemExecutorEAIService.java @@ -0,0 +1,71 @@ +package com.digiwin.athena.app.provider; + +import com.digiwin.app.service.DWEAIResult; +import com.digiwin.app.service.DWService; +import com.digiwin.app.service.eai.EAIService; +import com.digiwin.athena.app.service.executor.ExecutorUtil; + +import java.util.Map; + +/** + * @Author: xieps + * @Date: 2023/9/4 10:28 + * @Version 1.0 + * @Description + */ +public interface ItemExecutorEAIService extends DWService { + + + /** + * 品号执行人信息新增 + * + * @param headers + * @param messageBody + * @return + * @throws Exception + */ + @EAIService(id = ExecutorUtil.DEMO_ITEM_EXECUTOR_INFO_CREATE) + DWEAIResult itemExecutorInfoCreate(Map headers, String messageBody) throws Exception; + + + + /** + * 品号执行人信息查询 + * + * @param headers + * @param messageBody + * @return + * @throws Exception + */ + @EAIService(id = ExecutorUtil.DEMO_ITEM_EXECUTOR_INFO_GET) + DWEAIResult itemExecutorInfoGet(Map headers, String messageBody) throws Exception; + + + + /** + * 品号执行人信息删除 + * + * @param headers + * @param messageBody + * @return + * @throws Exception + */ + @EAIService(id = ExecutorUtil.DEMO_ITEM_EXECUTOR_INFO_DELETE) + DWEAIResult itemExecutorInfoDelete(Map headers, String messageBody) throws Exception; + + + + /** + * 品号执行人信息更新 + * + * @param headers + * @param messageBody + * @return + * @throws Exception + */ + @EAIService(id = ExecutorUtil.DEMO_ITEM_EXECUTOR_INFO_UPDATE) + DWEAIResult itemExecutorInfoUpdate(Map headers, String messageBody) throws Exception; + + + +} diff --git a/demo-athenaopt_backend/develop/src/main/java/com/digiwin/athena/app/provider/impl/ItemExecutorEAIServiceImpl.java b/demo-athenaopt_backend/develop/src/main/java/com/digiwin/athena/app/provider/impl/ItemExecutorEAIServiceImpl.java new file mode 100644 index 0000000..e16e7c7 --- /dev/null +++ b/demo-athenaopt_backend/develop/src/main/java/com/digiwin/athena/app/provider/impl/ItemExecutorEAIServiceImpl.java @@ -0,0 +1,44 @@ +package com.digiwin.athena.app.provider.impl; + +import com.digiwin.app.service.DWEAIResult; +import com.digiwin.athena.app.provider.ItemExecutorEAIService; +import com.digiwin.athena.app.service.executor.ExecutorUtil; +import com.digiwin.athena.opt.common.eai.service.EAIServiceContext; + +import javax.annotation.Resource; +import java.util.Map; + +/** + * @Author: xieps + * @Date: 2023/9/4 10:31 + * @Version 1.0 + * @Description + */ +public class ItemExecutorEAIServiceImpl implements ItemExecutorEAIService { + + @Resource + private EAIServiceContext eaiServiceContext; + + + @Override + public DWEAIResult itemExecutorInfoCreate(Map headers, String messageBody) throws Exception { + return eaiServiceContext.execute(ExecutorUtil.DEMO_ITEM_EXECUTOR_INFO_CREATE, headers, messageBody); + } + + @Override + public DWEAIResult itemExecutorInfoGet(Map headers, String messageBody) throws Exception { + return eaiServiceContext.execute(ExecutorUtil.DEMO_ITEM_EXECUTOR_INFO_GET, headers, messageBody); + } + + @Override + public DWEAIResult itemExecutorInfoDelete(Map headers, String messageBody) throws Exception { + return eaiServiceContext.execute(ExecutorUtil.DEMO_ITEM_EXECUTOR_INFO_DELETE, headers, messageBody); + } + + @Override + public DWEAIResult itemExecutorInfoUpdate(Map headers, String messageBody) throws Exception { + return eaiServiceContext.execute(ExecutorUtil.DEMO_ITEM_EXECUTOR_INFO_UPDATE, headers, messageBody); + } + + +} diff --git a/demo-athenaopt_backend/develop/src/main/java/com/digiwin/athena/app/service/executor/ExecutorUtil.java b/demo-athenaopt_backend/develop/src/main/java/com/digiwin/athena/app/service/executor/ExecutorUtil.java new file mode 100644 index 0000000..6da0d99 --- /dev/null +++ b/demo-athenaopt_backend/develop/src/main/java/com/digiwin/athena/app/service/executor/ExecutorUtil.java @@ -0,0 +1,25 @@ +package com.digiwin.athena.app.service.executor; + +import com.alibaba.fastjson.TypeReference; +import com.digiwin.athena.app.infra.entity.ItemExecutorEntity; + +import java.util.List; + +/** + * @Author: xieps + * @Date: 2023/8/30 13:32 + * @Version 1.0 + * @Description + */ +public class ExecutorUtil { + + public static final String DEMO_ITEM_EXECUTOR_INFO_CREATE = "demo.item.executor.info.create"; + public static final String DEMO_ITEM_EXECUTOR_INFO_UPDATE = "demo.item.executor.info.update"; + public static final String DEMO_ITEM_EXECUTOR_INFO_GET = "demo.item.executor.info.get"; + public static final String DEMO_ITEM_EXECUTOR_INFO_DELETE = "demo.item.executor.info.delete"; + + + public static final TypeReference> ITEM_EXECUTOR_LIST = new TypeReference>() { + }; + +} diff --git a/demo-athenaopt_backend/develop/src/main/java/com/digiwin/athena/app/service/executor/ItemExecutorCreateEAIService.java b/demo-athenaopt_backend/develop/src/main/java/com/digiwin/athena/app/service/executor/ItemExecutorCreateEAIService.java new file mode 100644 index 0000000..ed366ce --- /dev/null +++ b/demo-athenaopt_backend/develop/src/main/java/com/digiwin/athena/app/service/executor/ItemExecutorCreateEAIService.java @@ -0,0 +1,128 @@ +package com.digiwin.athena.app.service.executor; + +import com.alibaba.fastjson.JSON; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.digiwin.app.container.exceptions.DWBusinessException; +import com.digiwin.app.service.DWEAIResult; +import com.digiwin.athena.app.infra.entity.ItemExecutorEntity; +import com.digiwin.athena.app.infra.repository.ItemExecutorRepository; +import com.digiwin.athena.app.infra.service.ItemExecutorService; +import com.digiwin.athena.opt.common.eai.EAIRequest; +import com.digiwin.athena.opt.common.eai.EAIUtil; +import com.digiwin.athena.opt.common.eai.service.AbsEAIService; +import com.digiwin.athena.opt.common.security.SecurityUtil; +import lombok.extern.log4j.Log4j2; +import org.springframework.stereotype.Service; +import org.springframework.util.StringUtils; + +import javax.annotation.Resource; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.concurrent.ConcurrentSkipListMap; +import java.util.function.Function; +import java.util.function.Predicate; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +/** + * @Author: xieps + * @Date: 2023/8/30 14:33 + * @Version 1.0 + * @Description + */ +@Service +@Log4j2 +public class ItemExecutorCreateEAIService extends AbsEAIService { + + + @Resource + private ItemExecutorRepository itemExecutorRepository; + + + @Resource + private ItemExecutorService itemExecutorService; + + + @Override + public String getServiceName() { + return ExecutorUtil.DEMO_ITEM_EXECUTOR_INFO_CREATE; + } + + @Override + public DWEAIResult execute(Map headers, String messageBody) throws Exception { + + EAIRequest request = new EAIRequest(messageBody); + List itemExecutorInfo = request.getToList("item_executor_info", ItemExecutorEntity.class); + + //对必传参数 且 品号和执行人编号不可以重复 进行校验 + validateParameter(itemExecutorInfo); + + //进行批量新增 + itemExecutorService.saveBatch(itemExecutorInfo); + + return EAIUtil.buildEAIResult(new HashMap<>()); + } + + + /** + * 对入参进行参数校验 + * + * @param itemExecutorInfo + * @throws DWBusinessException + */ + private void validateParameter(List itemExecutorInfo) throws DWBusinessException { + if (Objects.isNull(itemExecutorInfo) || itemExecutorInfo.isEmpty()) { + throw new DWBusinessException("入参数据为空~~"); + } + for (ItemExecutorEntity item : itemExecutorInfo) { + if (StringUtils.isEmpty(item.getItemNo())) { + throw new DWBusinessException("品号字段值不为空或者NULL~"); + } + if (StringUtils.isEmpty(item.getItemName())) { + throw new DWBusinessException("品名字段值不为空或者NULL~"); + } + if (StringUtils.isEmpty(item.getProcurementExecutorCode())) { + throw new DWBusinessException("执行人编号字段值不为空或者NULL~"); + } + if (StringUtils.isEmpty(item.getProcurementExecutorName())) { + throw new DWBusinessException("执行人名称字段值不为空或者NULL~"); + } + } + List distinctList = itemExecutorInfo.stream().filter(distinctByKey(item -> Stream.of(item.getItemNo(), item.getProcurementExecutorCode()).toArray())).collect(Collectors.toList()); + if (itemExecutorInfo.size() > distinctList.size()) { + throw new DWBusinessException("品号和执行人编号入参重复~"); + } + + LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); + queryWrapper.eq(ItemExecutorEntity::getTenantSid, SecurityUtil.getUserProfile().getTenantSid()); + List entityList = itemExecutorRepository.selectList(queryWrapper); + + if (!entityList.isEmpty()) { + for (ItemExecutorEntity executorEntity : entityList) { + String itemNo = executorEntity.getItemNo(); + String executorNo = executorEntity.getProcurementExecutorCode(); + boolean match = itemExecutorInfo.stream().anyMatch(item -> Objects.equals(item.getItemNo(), itemNo) + && Objects.equals(item.getProcurementExecutorCode(), executorNo)); + if (match) { + throw new DWBusinessException("品号和执行人编号已重复~"); + } + } + } + } + + + /** + * 用于对象去重 + * + * @param keyExtractor 需要去重的属性 + * @param + * @return + */ + private static Predicate distinctByKey(Function keyExtractor) { + //记录已有对象或者属性 + ConcurrentSkipListMap skipListMap = new ConcurrentSkipListMap<>(); + return t -> skipListMap.putIfAbsent(JSON.toJSONString(keyExtractor.apply(t)), Boolean.TRUE) == null; + } +} diff --git a/demo-athenaopt_backend/develop/src/main/java/com/digiwin/athena/app/service/executor/ItemExecutorDeleteEAIService.java b/demo-athenaopt_backend/develop/src/main/java/com/digiwin/athena/app/service/executor/ItemExecutorDeleteEAIService.java new file mode 100644 index 0000000..f63a769 --- /dev/null +++ b/demo-athenaopt_backend/develop/src/main/java/com/digiwin/athena/app/service/executor/ItemExecutorDeleteEAIService.java @@ -0,0 +1,57 @@ +package com.digiwin.athena.app.service.executor; + +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; +import com.digiwin.app.service.DWEAIResult; +import com.digiwin.athena.app.infra.repository.ItemExecutorRepository; +import com.digiwin.athena.opt.common.eai.EAIRequest; +import com.digiwin.athena.opt.common.eai.EAIUtil; +import com.digiwin.athena.opt.common.eai.service.AbsEAIService; +import lombok.extern.log4j.Log4j2; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; +import java.util.*; + +/** + * @Author: xieps + * @Date: 2023/8/30 14:25 + * @Version 1.0 + * @Description + */ +@Service +@Log4j2 +public class ItemExecutorDeleteEAIService extends AbsEAIService { + + + @Resource + private ItemExecutorRepository itemExecutorRepository; + + + @Override + public String getServiceName() { + return ExecutorUtil.DEMO_ITEM_EXECUTOR_INFO_DELETE; + } + + @Override + public DWEAIResult execute(Map headers, String messageBody) throws Exception { + + JSONObject parameter = new EAIRequest(messageBody).getParameter(); + JSONArray itemExecutorInfo = parameter.getJSONArray("item_executor_info"); + + List idList = new ArrayList<>(); + for (Iterator iterator = itemExecutorInfo.iterator(); iterator.hasNext(); ) { + JSONObject item = (JSONObject) iterator.next(); + Long id = item.getLong("id"); + if (!Objects.isNull(id)) { + idList.add(id); + } + } + + if (!idList.isEmpty()) { + itemExecutorRepository.deleteBatchIds(idList); + } + + return EAIUtil.buildEAIResult(new HashMap<>()); + } +} diff --git a/demo-athenaopt_backend/develop/src/main/java/com/digiwin/athena/app/service/executor/ItemExecutorGetEAIService.java b/demo-athenaopt_backend/develop/src/main/java/com/digiwin/athena/app/service/executor/ItemExecutorGetEAIService.java new file mode 100644 index 0000000..2dbe3ba --- /dev/null +++ b/demo-athenaopt_backend/develop/src/main/java/com/digiwin/athena/app/service/executor/ItemExecutorGetEAIService.java @@ -0,0 +1,68 @@ +package com.digiwin.athena.app.service.executor; + +import com.alibaba.fastjson.JSONObject; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.digiwin.app.service.DWEAIResult; +import com.digiwin.athena.app.infra.entity.ItemExecutorEntity; +import com.digiwin.athena.app.infra.repository.ItemExecutorRepository; +import com.digiwin.athena.opt.common.eai.EAIRequest; +import com.digiwin.athena.opt.common.eai.EAIUtil; +import com.digiwin.athena.opt.common.eai.service.AbsEAIService; +import com.digiwin.athena.opt.common.security.SecurityUtil; +import lombok.extern.log4j.Log4j2; +import org.apache.commons.lang.StringUtils; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +/** + * @Author: xieps + * @Date: 2023/8/30 13:55 + * @Version 1.0 + * @Description 品号执行人Get + */ +@Service +@Log4j2 +public class ItemExecutorGetEAIService extends AbsEAIService { + + + @Resource + private ItemExecutorRepository itemExecutorRepository; + + + @Override + public String getServiceName() { + return ExecutorUtil.DEMO_ITEM_EXECUTOR_INFO_GET; + } + + @Override + public DWEAIResult execute(Map headers, String messageBody) throws Exception { + + EAIRequest request = new EAIRequest(messageBody); + List itemExecutorInfo = request.getToList("item_executor_info", ItemExecutorEntity.class); + //组装查询条件 进行查询 + LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); + queryWrapper.eq(ItemExecutorEntity::getTenantSid, SecurityUtil.getUserProfile().getTenantSid()); + if (!itemExecutorInfo.isEmpty()) { + queryWrapper.and( + queryWrapperInner -> { + for (ItemExecutorEntity item : itemExecutorInfo) { + queryWrapperInner.or( + wrapper -> wrapper + .eq(!StringUtils.isEmpty(item.getItemNo()), ItemExecutorEntity::getItemNo, item.getItemNo()) + .eq(!StringUtils.isEmpty(item.getItemName()), ItemExecutorEntity::getItemName, item.getItemName()) + .eq(!StringUtils.isEmpty(item.getProcurementExecutorCode()), ItemExecutorEntity::getProcurementExecutorCode, item.getProcurementExecutorCode()) + .eq(!StringUtils.isEmpty(item.getProcurementExecutorName()), ItemExecutorEntity::getProcurementExecutorName, item.getProcurementExecutorName()) + ); + } + } + ); + + } + List itemExecutorEntities = itemExecutorRepository.selectList(queryWrapper); + return EAIUtil.buildEAIResult(new JSONObject().fluentPut("item_executor_info", itemExecutorEntities)); + } +} diff --git a/demo-athenaopt_backend/develop/src/main/java/com/digiwin/athena/app/service/executor/ItemExecutorUpdateEAIService.java b/demo-athenaopt_backend/develop/src/main/java/com/digiwin/athena/app/service/executor/ItemExecutorUpdateEAIService.java new file mode 100644 index 0000000..e76aa96 --- /dev/null +++ b/demo-athenaopt_backend/develop/src/main/java/com/digiwin/athena/app/service/executor/ItemExecutorUpdateEAIService.java @@ -0,0 +1,111 @@ +package com.digiwin.athena.app.service.executor; + +import com.alibaba.fastjson.JSON; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.digiwin.app.container.exceptions.DWBusinessException; +import com.digiwin.app.service.DWEAIResult; +import com.digiwin.athena.app.infra.entity.ItemExecutorEntity; +import com.digiwin.athena.app.infra.repository.ItemExecutorRepository; +import com.digiwin.athena.app.infra.service.ItemExecutorService; +import com.digiwin.athena.opt.common.eai.EAIRequest; +import com.digiwin.athena.opt.common.eai.EAIUtil; +import com.digiwin.athena.opt.common.eai.service.AbsEAIService; +import com.digiwin.athena.opt.common.security.SecurityUtil; +import lombok.extern.log4j.Log4j2; +import org.springframework.stereotype.Service; +import org.springframework.util.StringUtils; + +import javax.annotation.Resource; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.concurrent.ConcurrentSkipListMap; +import java.util.function.Function; +import java.util.function.Predicate; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +/** + * @Author: xieps + * @Date: 2023/8/30 14:59 + * @Version 1.0 + * @Description + */ +@Service +@Log4j2 +public class ItemExecutorUpdateEAIService extends AbsEAIService { + + @Resource + private ItemExecutorService itemExecutorService; + + + @Resource + private ItemExecutorRepository itemExecutorRepository; + + @Override + public String getServiceName() { + return ExecutorUtil.DEMO_ITEM_EXECUTOR_INFO_UPDATE; + } + + @Override + public DWEAIResult execute(Map headers, String messageBody) throws Exception { + + EAIRequest request = new EAIRequest(messageBody); + List itemExecutorInfo = request.getToList("item_executor_info", ItemExecutorEntity.class); + + //对必传参数 且 品号和执行人编号不可以重复 进行校验 + validateParameter(itemExecutorInfo); + + //根据品号和执行人编号进行更新 + itemExecutorRepository.updateBatch(itemExecutorInfo, SecurityUtil.getUserProfile().getTenantSid()); + + return EAIUtil.buildEAIResult(new HashMap<>()); + } + + + /** + * 对入参进行参数校验 + * + * @param itemExecutorInfo + * @throws DWBusinessException + */ + private void validateParameter(List itemExecutorInfo) throws DWBusinessException { + if (Objects.isNull(itemExecutorInfo) || itemExecutorInfo.isEmpty()) { + throw new DWBusinessException("入参数据为空~~"); + } + for (ItemExecutorEntity item : itemExecutorInfo) { + if (StringUtils.isEmpty(item.getItemNo())) { + throw new DWBusinessException("品号字段值不为空或者NULL~"); + } + if (StringUtils.isEmpty(item.getItemName())) { + throw new DWBusinessException("品名字段值不为空或者NULL~"); + } + if (StringUtils.isEmpty(item.getProcurementExecutorCode())) { + throw new DWBusinessException("执行人编号字段值不为空或者NULL~"); + } + if (StringUtils.isEmpty(item.getProcurementExecutorName())) { + throw new DWBusinessException("执行人名称字段值不为空或者NULL~"); + } + } + List distinctList = itemExecutorInfo.stream().filter(distinctByKey(item -> Stream.of(item.getItemNo(), item.getProcurementExecutorCode()).toArray())).collect(Collectors.toList()); + if (itemExecutorInfo.size() > distinctList.size()) { + throw new DWBusinessException("品号和执行人编号入参重复~"); + } + + } + + + /** + * 用于对象去重 + * + * @param keyExtractor 需要去重的属性 + * @param + * @return + */ + private static Predicate distinctByKey(Function keyExtractor) { + //记录已有对象或者属性 + ConcurrentSkipListMap skipListMap = new ConcurrentSkipListMap<>(); + return t -> skipListMap.putIfAbsent(JSON.toJSONString(keyExtractor.apply(t)), Boolean.TRUE) == null; + } +}