From 4e0c09c7c437e3b2acb84fd5e1fb3f6f99485ddc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E5=A3=AE=E5=A3=AE?= Date: Tue, 5 Sep 2023 15:14:43 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=9B=E5=BB=BA=E8=AF=B7=E8=B4=AD=E5=8D=95?= =?UTF-8?q?=E4=BB=A3=E7=A0=81=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/infra/dto/PurchaseOrderDetailDTO.java | 4 +- .../entity/PurchaseOrderDetailEntity.java | 4 +- .../app/provider/PurchaseDemoEAIService.java | 3 + .../purchase/PurchaseDemoCreateService.java | 90 +++++++++++++++---- .../purchase/PurchaseDemoGetService.java | 17 ++-- .../app/service/purchase/PurchaseUtil.java | 9 +- 6 files changed, 98 insertions(+), 29 deletions(-) diff --git a/demo-athenaopt_backend/develop/src/main/java/com/digiwin/athena/app/infra/dto/PurchaseOrderDetailDTO.java b/demo-athenaopt_backend/develop/src/main/java/com/digiwin/athena/app/infra/dto/PurchaseOrderDetailDTO.java index 94b5b4d..c0041f5 100644 --- a/demo-athenaopt_backend/develop/src/main/java/com/digiwin/athena/app/infra/dto/PurchaseOrderDetailDTO.java +++ b/demo-athenaopt_backend/develop/src/main/java/com/digiwin/athena/app/infra/dto/PurchaseOrderDetailDTO.java @@ -80,7 +80,7 @@ public class PurchaseOrderDetailDTO { * 采购单价 */ @JsonProperty(value = "purchase_price") - private BigDecimal purchase_price; + private BigDecimal purchasePrice; /** * 金额 @@ -116,7 +116,7 @@ public class PurchaseOrderDetailDTO { * 异常处理方式 */ @JsonProperty(value = "abnormal_handle_plan") - private String abnormal_handle_plan; + private String abnormalHandlePlan; /** * 任务卡状态 diff --git a/demo-athenaopt_backend/develop/src/main/java/com/digiwin/athena/app/infra/entity/PurchaseOrderDetailEntity.java b/demo-athenaopt_backend/develop/src/main/java/com/digiwin/athena/app/infra/entity/PurchaseOrderDetailEntity.java index 1f4c056..e02a71e 100644 --- a/demo-athenaopt_backend/develop/src/main/java/com/digiwin/athena/app/infra/entity/PurchaseOrderDetailEntity.java +++ b/demo-athenaopt_backend/develop/src/main/java/com/digiwin/athena/app/infra/entity/PurchaseOrderDetailEntity.java @@ -79,7 +79,7 @@ public class PurchaseOrderDetailEntity extends BaseMgrEntity headers, String messageBody) throws Exception; + @AllowAnonymous @EAIService(id = PurchaseUtil.DEMO_PURCHASE_DEMO_GET) DWEAIResult get(Map headers, String messageBody) throws Exception; diff --git a/demo-athenaopt_backend/develop/src/main/java/com/digiwin/athena/app/service/purchase/PurchaseDemoCreateService.java b/demo-athenaopt_backend/develop/src/main/java/com/digiwin/athena/app/service/purchase/PurchaseDemoCreateService.java index 8373a20..600cab9 100644 --- a/demo-athenaopt_backend/develop/src/main/java/com/digiwin/athena/app/service/purchase/PurchaseDemoCreateService.java +++ b/demo-athenaopt_backend/develop/src/main/java/com/digiwin/athena/app/service/purchase/PurchaseDemoCreateService.java @@ -1,20 +1,23 @@ package com.digiwin.athena.app.service.purchase; +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.common.utils.TransferUtil; -import com.digiwin.athena.app.infra.dto.PurchaseOrderDetailDTO; import com.digiwin.athena.app.infra.entity.PurchaseOrderDetailEntity; +import com.digiwin.athena.app.infra.repository.PurchaseOrderDetailRepository; import com.digiwin.athena.app.infra.service.PurchaseDemoService; +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 org.springframework.beans.BeanUtils; +import com.digiwin.athena.opt.common.security.SecurityUtil; 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.stream.Collectors; +import java.util.Objects; /** * @author lz @@ -25,6 +28,9 @@ import java.util.stream.Collectors; @Service public class PurchaseDemoCreateService extends AbsEAIService { + @Resource + PurchaseOrderDetailRepository purchaseOrderDetailRepository; + @Resource PurchaseDemoService purchaseDemoService; @@ -35,19 +41,71 @@ public class PurchaseDemoCreateService extends AbsEAIService { @Override public DWEAIResult execute(Map headers, String messageBody) throws Exception { - //将入参值转换为DTO - List purchaseOrderDetailDTOS = TransferUtil.string2List(messageBody, PurchaseOrderDetailDTO.class, "purchase_info"); - - //插入数据库 - List entities = purchaseOrderDetailDTOS.stream() - .map(dto -> { - PurchaseOrderDetailEntity entity = new PurchaseOrderDetailEntity(); - BeanUtils.copyProperties(dto, entity); - return entity; - }) - .collect(Collectors.toList()); - purchaseDemoService.saveBatch(entities); + + EAIRequest request = new EAIRequest(messageBody); + List purchaseInfos = request.getObject("purchase_info", PurchaseUtil.LIST_ENTITY_PURCHASE); + + //入参非空校验 + validateParameter(purchaseInfos); + + //集合不为空,插入数据库 + if (!purchaseInfos.isEmpty()) { + purchaseDemoService.saveBatch(purchaseInfos); + } return EAIUtil.buildEAIResult(new HashMap<>()); } + + + /** + * @throws + * @description 校验字段不为空 + * @author lz + * @time 2023/9/5 15:01 + */ + private void validateParameter(List purchaseInfos) throws DWBusinessException { + if (Objects.isNull(purchaseInfos) || purchaseInfos.isEmpty()) { + throw new DWBusinessException("入参数据不能为空"); + } + for (PurchaseOrderDetailEntity item : purchaseInfos) { + if (StringUtils.isEmpty(item.getPurchaseOrderNo())) { + throw new DWBusinessException("请购单号不能为空或NULL"); + } + if (StringUtils.isEmpty(item.getPurchaseOrderSeq())) { + throw new DWBusinessException("请购单序号不能为空或NULL"); + } + 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 (item.getRequisitionNum() == 0) { + throw new DWBusinessException("请购数量必须大于0"); + } + } + + //根据请购单号和请购单序号查询是否存在 + LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); + queryWrapper.eq(PurchaseOrderDetailEntity::getTenantSid, SecurityUtil.getUserProfile().getTenantSid()); + queryWrapper.and( + queryWrapperInner -> { + for (PurchaseOrderDetailEntity purchaseOrderDetail : purchaseInfos) { + queryWrapperInner.or( + wrapper -> wrapper + .eq(!org.apache.commons.lang.StringUtils.isEmpty(purchaseOrderDetail.getPurchaseOrderNo()), PurchaseOrderDetailEntity::getPurchaseOrderNo, purchaseOrderDetail.getPurchaseOrderNo()) + .eq(!org.apache.commons.lang.StringUtils.isEmpty(purchaseOrderDetail.getPurchaseOrderSeq()), PurchaseOrderDetailEntity::getPurchaseOrderSeq, purchaseOrderDetail.getPurchaseOrderSeq()) + + ); + } + } + ); + List purchaseOrderList = purchaseOrderDetailRepository.selectList(queryWrapper); + if (purchaseOrderList != null && purchaseOrderList.size() > 0) { + throw new DWBusinessException("请购单号+请购单序号已存在!"); + } + } } diff --git a/demo-athenaopt_backend/develop/src/main/java/com/digiwin/athena/app/service/purchase/PurchaseDemoGetService.java b/demo-athenaopt_backend/develop/src/main/java/com/digiwin/athena/app/service/purchase/PurchaseDemoGetService.java index e2dbe97..aef6720 100644 --- a/demo-athenaopt_backend/develop/src/main/java/com/digiwin/athena/app/service/purchase/PurchaseDemoGetService.java +++ b/demo-athenaopt_backend/develop/src/main/java/com/digiwin/athena/app/service/purchase/PurchaseDemoGetService.java @@ -9,6 +9,7 @@ import com.digiwin.athena.app.infra.common.utils.TransferUtil; import com.digiwin.athena.app.infra.dto.PurchaseOrderDetailDTO; import com.digiwin.athena.app.infra.entity.PurchaseOrderDetailEntity; import com.digiwin.athena.app.infra.repository.PurchaseOrderDetailRepository; +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; @@ -42,21 +43,21 @@ public class PurchaseDemoGetService extends AbsEAIService { @Override public DWEAIResult execute(Map headers, String messageBody) throws Exception { - //将入参值转换为Dto类存储 - List purchaseOrderDetailDTOS = TransferUtil.string2List(messageBody, PurchaseOrderDetailDTO.class, "purchase_info"); + EAIRequest request = new EAIRequest(messageBody); + List purchaseInfos = request.getObject("purchase_info", PurchaseUtil.LIST_ENTITY_PURCHASE); //根据请购单号+请购单序号+状态+任务卡类型查询 LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); queryWrapper.eq(PurchaseOrderDetailEntity::getTenantSid, SecurityUtil.getUserProfile().getTenantSid()); queryWrapper.and( queryWrapperInner -> { - for (PurchaseOrderDetailDTO purchaseOrderDetailDTO : purchaseOrderDetailDTOS) { + for (PurchaseOrderDetailEntity purchaseOrderDetail : purchaseInfos) { queryWrapperInner.or( wrapper -> wrapper - .eq(!StringUtils.isEmpty(purchaseOrderDetailDTO.getPurchaseOrderNo()), PurchaseOrderDetailEntity::getPurchaseOrderNo, purchaseOrderDetailDTO.getPurchaseOrderNo()) - .eq(!StringUtils.isEmpty(purchaseOrderDetailDTO.getPurchaseOrderSeq()), PurchaseOrderDetailEntity::getPurchaseOrderSeq, purchaseOrderDetailDTO.getPurchaseOrderSeq()) - .eq(!Objects.isNull(purchaseOrderDetailDTO.getTabStatus()), PurchaseOrderDetailEntity::getTabStatus, purchaseOrderDetailDTO.getTabStatus()) - .eq(!Objects.isNull(purchaseOrderDetailDTO.getTaskType()), PurchaseOrderDetailEntity::getTaskType, purchaseOrderDetailDTO.getTaskType()) + .eq(!StringUtils.isEmpty(purchaseOrderDetail.getPurchaseOrderNo()), PurchaseOrderDetailEntity::getPurchaseOrderNo, purchaseOrderDetail.getPurchaseOrderNo()) + .eq(!StringUtils.isEmpty(purchaseOrderDetail.getPurchaseOrderSeq()), PurchaseOrderDetailEntity::getPurchaseOrderSeq, purchaseOrderDetail.getPurchaseOrderSeq()) + .eq(!StringUtils.isEmpty(purchaseOrderDetail.getTabStatus()), PurchaseOrderDetailEntity::getTabStatus, purchaseOrderDetail.getTabStatus()) + .eq(!StringUtils.isEmpty(purchaseOrderDetail.getTaskType()), PurchaseOrderDetailEntity::getTaskType, purchaseOrderDetail.getTaskType()) ); } @@ -72,7 +73,7 @@ public class PurchaseDemoGetService extends AbsEAIService { purchaseInfo.add(JSON.parseObject(new ObjectMapper().writeValueAsString(e))); } - return EAIUtil.buildEAIResult(new JSONObject().fluentPut("purchase_info", purchaseInfo)); + return EAIUtil.buildEAIResult(new JSONObject().fluentPut("purchase_info", purchaseOrderDetailEntities)); } } diff --git a/demo-athenaopt_backend/develop/src/main/java/com/digiwin/athena/app/service/purchase/PurchaseUtil.java b/demo-athenaopt_backend/develop/src/main/java/com/digiwin/athena/app/service/purchase/PurchaseUtil.java index cbced95..0b4594a 100644 --- a/demo-athenaopt_backend/develop/src/main/java/com/digiwin/athena/app/service/purchase/PurchaseUtil.java +++ b/demo-athenaopt_backend/develop/src/main/java/com/digiwin/athena/app/service/purchase/PurchaseUtil.java @@ -1,5 +1,10 @@ package com.digiwin.athena.app.service.purchase; +import com.alibaba.fastjson.TypeReference; +import com.digiwin.athena.app.infra.entity.PurchaseOrderDetailEntity; + +import java.util.List; + /** * @author lz * @version 1.0 @@ -18,5 +23,7 @@ public class PurchaseUtil { //异常排除更新 public static final String DEMO_PURCHASE_ORDER_ABNORMAL_UPDATE = "demo.purchase.order.abnormal.update"; + public static final TypeReference> LIST_ENTITY_PURCHASE = new TypeReference>() { -} + }; +} \ No newline at end of file