|
@ -1,20 +1,23 @@ |
|
|
package com.digiwin.athena.app.service.purchase; |
|
|
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.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.entity.PurchaseOrderDetailEntity; |
|
|
|
|
|
import com.digiwin.athena.app.infra.repository.PurchaseOrderDetailRepository; |
|
|
import com.digiwin.athena.app.infra.service.PurchaseDemoService; |
|
|
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.EAIUtil; |
|
|
import com.digiwin.athena.opt.common.eai.service.AbsEAIService; |
|
|
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.stereotype.Service; |
|
|
|
|
|
import org.springframework.util.StringUtils; |
|
|
|
|
|
|
|
|
import javax.annotation.Resource; |
|
|
import javax.annotation.Resource; |
|
|
import java.util.HashMap; |
|
|
import java.util.HashMap; |
|
|
import java.util.List; |
|
|
import java.util.List; |
|
|
import java.util.Map; |
|
|
import java.util.Map; |
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
|
import java.util.Objects; |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* @author lz |
|
|
* @author lz |
|
@ -25,6 +28,9 @@ import java.util.stream.Collectors; |
|
|
@Service |
|
|
@Service |
|
|
public class PurchaseDemoCreateService extends AbsEAIService { |
|
|
public class PurchaseDemoCreateService extends AbsEAIService { |
|
|
|
|
|
|
|
|
|
|
|
@Resource |
|
|
|
|
|
PurchaseOrderDetailRepository purchaseOrderDetailRepository; |
|
|
|
|
|
|
|
|
@Resource |
|
|
@Resource |
|
|
PurchaseDemoService purchaseDemoService; |
|
|
PurchaseDemoService purchaseDemoService; |
|
|
|
|
|
|
|
@ -35,19 +41,71 @@ public class PurchaseDemoCreateService extends AbsEAIService { |
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
public DWEAIResult execute(Map<String, String> headers, String messageBody) throws Exception { |
|
|
public DWEAIResult execute(Map<String, String> headers, String messageBody) throws Exception { |
|
|
//将入参值转换为DTO |
|
|
|
|
|
List<PurchaseOrderDetailDTO> purchaseOrderDetailDTOS = TransferUtil.string2List(messageBody, PurchaseOrderDetailDTO.class, "purchase_info"); |
|
|
|
|
|
|
|
|
|
|
|
//插入数据库 |
|
|
|
|
|
List<PurchaseOrderDetailEntity> 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<PurchaseOrderDetailEntity> purchaseInfos = request.getObject("purchase_info", PurchaseUtil.LIST_ENTITY_PURCHASE); |
|
|
|
|
|
|
|
|
|
|
|
//入参非空校验 |
|
|
|
|
|
validateParameter(purchaseInfos); |
|
|
|
|
|
|
|
|
|
|
|
//集合不为空,插入数据库 |
|
|
|
|
|
if (!purchaseInfos.isEmpty()) { |
|
|
|
|
|
purchaseDemoService.saveBatch(purchaseInfos); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
return EAIUtil.buildEAIResult(new HashMap<>()); |
|
|
return EAIUtil.buildEAIResult(new HashMap<>()); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* @throws |
|
|
|
|
|
* @description 校验字段不为空 |
|
|
|
|
|
* @author lz |
|
|
|
|
|
* @time 2023/9/5 15:01 |
|
|
|
|
|
*/ |
|
|
|
|
|
private void validateParameter(List<PurchaseOrderDetailEntity> 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<PurchaseOrderDetailEntity> 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<PurchaseOrderDetailEntity> purchaseOrderList = purchaseOrderDetailRepository.selectList(queryWrapper); |
|
|
|
|
|
if (purchaseOrderList != null && purchaseOrderList.size() > 0) { |
|
|
|
|
|
throw new DWBusinessException("请购单号+请购单序号已存在!"); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
} |
|
|
} |