Browse Source

创建请购单代码修改

master
李壮壮 1 year ago
parent
commit
4e0c09c7c4
6 changed files with 98 additions and 29 deletions
  1. +2
    -2
      demo-athenaopt_backend/develop/src/main/java/com/digiwin/athena/app/infra/dto/PurchaseOrderDetailDTO.java
  2. +2
    -2
      demo-athenaopt_backend/develop/src/main/java/com/digiwin/athena/app/infra/entity/PurchaseOrderDetailEntity.java
  3. +3
    -0
      demo-athenaopt_backend/develop/src/main/java/com/digiwin/athena/app/provider/PurchaseDemoEAIService.java
  4. +74
    -16
      demo-athenaopt_backend/develop/src/main/java/com/digiwin/athena/app/service/purchase/PurchaseDemoCreateService.java
  5. +9
    -8
      demo-athenaopt_backend/develop/src/main/java/com/digiwin/athena/app/service/purchase/PurchaseDemoGetService.java
  6. +8
    -1
      demo-athenaopt_backend/develop/src/main/java/com/digiwin/athena/app/service/purchase/PurchaseUtil.java

+ 2
- 2
demo-athenaopt_backend/develop/src/main/java/com/digiwin/athena/app/infra/dto/PurchaseOrderDetailDTO.java View File

@ -80,7 +80,7 @@ public class PurchaseOrderDetailDTO {
* 采购单价 * 采购单价
*/ */
@JsonProperty(value = "purchase_price") @JsonProperty(value = "purchase_price")
private BigDecimal purchase_price;
private BigDecimal purchasePrice;
/** /**
* 金额 * 金额
@ -116,7 +116,7 @@ public class PurchaseOrderDetailDTO {
* 异常处理方式 * 异常处理方式
*/ */
@JsonProperty(value = "abnormal_handle_plan") @JsonProperty(value = "abnormal_handle_plan")
private String abnormal_handle_plan;
private String abnormalHandlePlan;
/** /**
* 任务卡状态 * 任务卡状态


+ 2
- 2
demo-athenaopt_backend/develop/src/main/java/com/digiwin/athena/app/infra/entity/PurchaseOrderDetailEntity.java View File

@ -79,7 +79,7 @@ public class PurchaseOrderDetailEntity extends BaseMgrEntity<PurchaseOrderDetail
* 采购单价 * 采购单价
*/ */
@SerializedName(value = "purchase_price") @SerializedName(value = "purchase_price")
private BigDecimal purchase_price;
private BigDecimal purchasePrice;
/** /**
* 金额 * 金额
@ -117,7 +117,7 @@ public class PurchaseOrderDetailEntity extends BaseMgrEntity<PurchaseOrderDetail
* 异常处理方式 * 异常处理方式
*/ */
@SerializedName(value = "abnormal_handle_plan") @SerializedName(value = "abnormal_handle_plan")
private String abnormal_handle_plan;
private String abnormalHandlePlan;
/** /**
* 任务卡状态 * 任务卡状态


+ 3
- 0
demo-athenaopt_backend/develop/src/main/java/com/digiwin/athena/app/provider/PurchaseDemoEAIService.java View File

@ -1,5 +1,6 @@
package com.digiwin.athena.app.provider; package com.digiwin.athena.app.provider;
import com.digiwin.app.service.AllowAnonymous;
import com.digiwin.app.service.DWEAIResult; import com.digiwin.app.service.DWEAIResult;
import com.digiwin.app.service.DWService; import com.digiwin.app.service.DWService;
import com.digiwin.app.service.eai.EAIService; import com.digiwin.app.service.eai.EAIService;
@ -15,9 +16,11 @@ import java.util.Map;
*/ */
public interface PurchaseDemoEAIService extends DWService { public interface PurchaseDemoEAIService extends DWService {
@AllowAnonymous
@EAIService(id = PurchaseUtil.DEMO_PURCHASE_DEMO_CREATE) @EAIService(id = PurchaseUtil.DEMO_PURCHASE_DEMO_CREATE)
DWEAIResult create(Map<String, String> headers, String messageBody) throws Exception; DWEAIResult create(Map<String, String> headers, String messageBody) throws Exception;
@AllowAnonymous
@EAIService(id = PurchaseUtil.DEMO_PURCHASE_DEMO_GET) @EAIService(id = PurchaseUtil.DEMO_PURCHASE_DEMO_GET)
DWEAIResult get(Map<String, String> headers, String messageBody) throws Exception; DWEAIResult get(Map<String, String> headers, String messageBody) throws Exception;


+ 74
- 16
demo-athenaopt_backend/develop/src/main/java/com/digiwin/athena/app/service/purchase/PurchaseDemoCreateService.java View File

@ -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("请购单号+请购单序号已存在!");
}
}
} }

+ 9
- 8
demo-athenaopt_backend/develop/src/main/java/com/digiwin/athena/app/service/purchase/PurchaseDemoGetService.java View File

@ -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.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.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.EAIUtil;
import com.digiwin.athena.opt.common.eai.service.AbsEAIService; import com.digiwin.athena.opt.common.eai.service.AbsEAIService;
import com.digiwin.athena.opt.common.security.SecurityUtil; import com.digiwin.athena.opt.common.security.SecurityUtil;
@ -42,21 +43,21 @@ public class PurchaseDemoGetService 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");
EAIRequest request = new EAIRequest(messageBody);
List<PurchaseOrderDetailEntity> purchaseInfos = request.getObject("purchase_info", PurchaseUtil.LIST_ENTITY_PURCHASE);
//根据请购单号+请购单序号+状态+任务卡类型查询 //根据请购单号+请购单序号+状态+任务卡类型查询
LambdaQueryWrapper<PurchaseOrderDetailEntity> queryWrapper = new LambdaQueryWrapper<>(); LambdaQueryWrapper<PurchaseOrderDetailEntity> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(PurchaseOrderDetailEntity::getTenantSid, SecurityUtil.getUserProfile().getTenantSid()); queryWrapper.eq(PurchaseOrderDetailEntity::getTenantSid, SecurityUtil.getUserProfile().getTenantSid());
queryWrapper.and( queryWrapper.and(
queryWrapperInner -> { queryWrapperInner -> {
for (PurchaseOrderDetailDTO purchaseOrderDetailDTO : purchaseOrderDetailDTOS) {
for (PurchaseOrderDetailEntity purchaseOrderDetail : purchaseInfos) {
queryWrapperInner.or( queryWrapperInner.or(
wrapper -> wrapper 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))); 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));
} }
} }

+ 8
- 1
demo-athenaopt_backend/develop/src/main/java/com/digiwin/athena/app/service/purchase/PurchaseUtil.java View File

@ -1,5 +1,10 @@
package com.digiwin.athena.app.service.purchase; 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 * @author lz
* @version 1.0 * @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 String DEMO_PURCHASE_ORDER_ABNORMAL_UPDATE = "demo.purchase.order.abnormal.update";
public static final TypeReference<List<PurchaseOrderDetailEntity>> LIST_ENTITY_PURCHASE = new TypeReference<List<PurchaseOrderDetailEntity>>() {
}
};
}

Loading…
Cancel
Save