diff --git a/demo-athenaopt_backend/develop/src/main/java/com/digiwin/athena/app/infra/common/utils/ResponseUtil.java b/demo-athenaopt_backend/develop/src/main/java/com/digiwin/athena/app/infra/common/utils/ResponseUtil.java new file mode 100644 index 0000000..a1fdfb1 --- /dev/null +++ b/demo-athenaopt_backend/develop/src/main/java/com/digiwin/athena/app/infra/common/utils/ResponseUtil.java @@ -0,0 +1,97 @@ +package com.digiwin.athena.app.infra.common.utils; + +import com.digiwin.athena.app.infra.constant.ParameterConstant; + +import java.lang.reflect.Field; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * @description 响应结果转换 + * @throws + * @time 2023/8/30 13:21 + */ +public class ResponseUtil { + /** + * 把对象中的 String 类型的null字段,转换为空字符串 + * + * @param 待转化对象类型 + * @param cls 待转化对象 + * @return 转化好的对象 + */ + public static T noNullStringAttr(T cls) { + Field[] fields = cls.getClass().getDeclaredFields(); + if (fields == null || fields.length == 0) { + return cls; + } + for (Field field : fields) { + if (ParameterConstant.STRING.equals(field.getType().getSimpleName())) { + field.setAccessible(true); + try { + Object value = field.get(cls); + if (value == null) { + field.set(cls, ""); + } + } catch (IllegalArgumentException | IllegalAccessException e) { + e.printStackTrace(); + } + } + } + return cls; + } + + /** + * 把集合中的所有对象中的String类型的null字段,转换为空字符串 + * 注意:只能转换String类型的字段 + * + * @param sourceList 待转化的集合 + * @return 转化好的集合 + */ + public static List listNullToString(List sourceList) { + ArrayList resultList = new ArrayList<>(); + for (T cls : sourceList) { + Field[] fields = cls.getClass().getDeclaredFields(); + if (fields == null || fields.length == 0) { + resultList.add(cls); + } + for (Field field : fields) { + if (ParameterConstant.STRING.equals(field.getType().getSimpleName())) { + field.setAccessible(true); + try { + Object value = field.get(cls); + if (value == null) { + field.set(cls, ""); + } + } catch (IllegalArgumentException | IllegalAccessException e) { + e.printStackTrace(); + } + } + } + resultList.add(cls); + } + return resultList; + } + + /** + * 注意:只能转换String类型的字段 + * + * @param sourceList 待转化的集合 + * @return 转化好的集合 + */ + public static List> listMapToLowerCase(List> sourceList) { + List> response = new ArrayList<>(); + for (Map map : sourceList) { + Map newMap = new HashMap<>(); + for (Map.Entry entry : map.entrySet()) { + String key = entry.getKey().toLowerCase(); + Object value = entry.getValue(); + newMap.put(key, value); + } + response.add(newMap); + } + return response; + } + +} diff --git a/demo-athenaopt_backend/develop/src/main/java/com/digiwin/athena/app/infra/constant/ParameterConstant.java b/demo-athenaopt_backend/develop/src/main/java/com/digiwin/athena/app/infra/constant/ParameterConstant.java index c2855f0..fdd4d68 100644 --- a/demo-athenaopt_backend/develop/src/main/java/com/digiwin/athena/app/infra/constant/ParameterConstant.java +++ b/demo-athenaopt_backend/develop/src/main/java/com/digiwin/athena/app/infra/constant/ParameterConstant.java @@ -12,4 +12,6 @@ public class ParameterConstant { public static final String STATUS = "status"; public static final String SET_NUMBER = "1"; + + public static final String STRING = "String"; } 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 new file mode 100644 index 0000000..94b5b4d --- /dev/null +++ b/demo-athenaopt_backend/develop/src/main/java/com/digiwin/athena/app/infra/dto/PurchaseOrderDetailDTO.java @@ -0,0 +1,133 @@ +package com.digiwin.athena.app.infra.dto; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.math.BigDecimal; +import java.util.Date; + +/** + * @author lz + * @version 1.0 + * @title CaPurchaseOrderDetailDTO + * @description + * @create 2023/8/30 11:14 + */ +@Data +@AllArgsConstructor +@NoArgsConstructor +@JsonIgnoreProperties(ignoreUnknown = true) +public class PurchaseOrderDetailDTO { + + /** + * 请购单号 + */ + @JsonProperty(value = "purchase_order_no") + private String purchaseOrderNo; + + /** + * 请购单序号 + */ + @JsonProperty(value = "purchase_order_seq") + private String purchaseOrderSeq; + + /** + * 品号 + */ + @JsonProperty(value = "item_no") + private String itemNo; + + /** + * 品名 + */ + @JsonProperty(value = "item_name") + private String itemName; + + /** + * 规格 + */ + @JsonProperty(value = "item_spec") + private String itemSpec; + + /** + * 供应商名称 + */ + @JsonProperty(value = "supplier_name") + private String supplierName; + + /** + * 供应商编号 + */ + @JsonProperty(value = "supplier_no") + private String supplierNo; + + /** + * 请购数量 + */ + @JsonProperty(value = "requisition_num") + private Integer requisitionNum; + + /** + * 采购数量 + */ + @JsonProperty(value = "purchase_num") + private Integer purchaseNum; + + /** + * 采购单价 + */ + @JsonProperty(value = "purchase_price") + private BigDecimal purchase_price; + + /** + * 金额 + */ + @JsonProperty(value = "amount") + private BigDecimal amount; + + /** + * 采购剩余数量 + */ + @JsonProperty(value = "purchase_residue_num") + private Integer purchaseResidueNum; + + /** + * 采购执行人 + */ + @JsonProperty(value = "procurement_executor_code") + private String procurementExecutorCode; + + /** + * 采购需求日期 + */ + @JsonProperty(value = "purchase_date") + private Date purchaseDate; + + /** + * 预计到货日 + */ + @JsonProperty(value = "expected_date") + private Date expectedDate; + + /** + * 异常处理方式 + */ + @JsonProperty(value = "abnormal_handle_plan") + private String abnormal_handle_plan; + + /** + * 任务卡状态 + */ + @JsonProperty(value = "tab_status") + private String tabStatus; + + /** + * 任务卡类型:1是采购任务,2是交期回复任务,3是异常排除任务 + */ + @JsonProperty(value = "task_type") + private String taskType; + +} 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 new file mode 100644 index 0000000..8bd0f15 --- /dev/null +++ b/demo-athenaopt_backend/develop/src/main/java/com/digiwin/athena/app/infra/entity/PurchaseOrderDetailEntity.java @@ -0,0 +1,131 @@ +package com.digiwin.athena.app.infra.entity; + + +import com.baomidou.mybatisplus.annotation.TableName; +import com.digiwin.athena.opt.persistence.domain.BaseMgrEntity; +import com.google.gson.annotations.SerializedName; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.math.BigDecimal; +import java.util.Date; + +/** + * @author lz + * @description 请购采购单表 + * @throws + * @time 2023/8/29 16:21 + */ +@Data +@AllArgsConstructor +@NoArgsConstructor +@Builder +@TableName(value = "cim_purchase_order_detail", autoResultMap = true) +public class PurchaseOrderDetailEntity extends BaseMgrEntity { + + + /** + * 请购单号 + */ + @SerializedName(value = "purchase_order_no") + private String purchaseOrderNo; + + /** + * 请购单序号 + */ + @SerializedName(value = "purchase_order_seq") + private String purchaseOrderSeq; + + /** + * 品号 + */ + @SerializedName(value = "item_no") + private String itemNo; + + /** + * 品名 + */ + @SerializedName(value = "item_name") + private String itemName; + + /** + * 供应商名称 + */ + @SerializedName(value = "supplier_name") + private String supplierName; + + /** + * 供应商编号 + */ + @SerializedName(value = "supplier_no") + private String supplierNo; + + /** + * 请购数量 + */ + @SerializedName(value = "requisition_num") + private Integer requisitionNum; + + /** + * 采购数量 + */ + @SerializedName(value = "purchase_num") + private Integer purchaseNum; + + /** + * 采购单价 + */ + @SerializedName(value = "purchase_price") + private BigDecimal purchase_price; + + /** + * 金额 + */ + @SerializedName(value = "amount") + private BigDecimal amount; + + /** + * 采购剩余数量 + */ + @SerializedName(value = "purchase_residue_num") + private Integer purchaseResidueNum; + + /** + * 采购执行人 + */ + @SerializedName(value = "procurement_executor_code") + private String procurementExecutorCode; + + /** + * 采购需求日期 + */ + @SerializedName(value = "purchase_date") + private Date purchaseDate; + + /** + * 预计到货日 + */ + @SerializedName(value = "expected_date") + private Date expectedDate; + + /** + * 异常处理方式 + */ + @SerializedName(value = "abnormal_handle_plan") + private String abnormal_handle_plan; + + /** + * 任务卡状态 + */ + @SerializedName(value = "tab_status") + private String tabStatus; + + /** + * 任务卡类型:1是采购任务,2是交期回复任务,3是异常排除任务 + */ + @SerializedName(value = "task_type") + private String taskType; + +} diff --git a/demo-athenaopt_backend/develop/src/main/java/com/digiwin/athena/app/infra/repository/PurchaseOrderDetailRepository.java b/demo-athenaopt_backend/develop/src/main/java/com/digiwin/athena/app/infra/repository/PurchaseOrderDetailRepository.java new file mode 100644 index 0000000..85f84f5 --- /dev/null +++ b/demo-athenaopt_backend/develop/src/main/java/com/digiwin/athena/app/infra/repository/PurchaseOrderDetailRepository.java @@ -0,0 +1,13 @@ +package com.digiwin.athena.app.infra.repository; + +import com.digiwin.athena.app.infra.entity.PurchaseOrderDetailEntity; +import com.digiwin.athena.opt.persistence.repository.BaseRepository; + +/** + * @author lz + * @description + * @throws + * @time 2023/8/29 16:35 + */ +public interface PurchaseOrderDetailRepository extends BaseRepository { +} diff --git a/demo-athenaopt_backend/develop/src/main/java/com/digiwin/athena/app/infra/service/Impl/PurchaseDemoServiceImpl.java b/demo-athenaopt_backend/develop/src/main/java/com/digiwin/athena/app/infra/service/Impl/PurchaseDemoServiceImpl.java new file mode 100644 index 0000000..567e01c --- /dev/null +++ b/demo-athenaopt_backend/develop/src/main/java/com/digiwin/athena/app/infra/service/Impl/PurchaseDemoServiceImpl.java @@ -0,0 +1,18 @@ +package com.digiwin.athena.app.infra.service.Impl; + +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.persistence.service.impl.AbsBaseService; +import org.springframework.stereotype.Service; + +/** + * @author lz + * @description 请购单业务类 + * @throws + * @time 2023/8/29 16:38 + */ +@Service +public class PurchaseDemoServiceImpl extends AbsBaseService implements PurchaseDemoService { + +} diff --git a/demo-athenaopt_backend/develop/src/main/java/com/digiwin/athena/app/infra/service/PurchaseDemoService.java b/demo-athenaopt_backend/develop/src/main/java/com/digiwin/athena/app/infra/service/PurchaseDemoService.java new file mode 100644 index 0000000..e74993e --- /dev/null +++ b/demo-athenaopt_backend/develop/src/main/java/com/digiwin/athena/app/infra/service/PurchaseDemoService.java @@ -0,0 +1,16 @@ +package com.digiwin.athena.app.infra.service; + +import com.digiwin.athena.app.infra.entity.PurchaseOrderDetailEntity; +import com.digiwin.athena.opt.persistence.service.IBaseService; + +import java.util.List; + +/** + * @description + * @author lz + * @throws + * @time 2023/8/29 16:18 + */ +public interface PurchaseDemoService extends IBaseService { + +} diff --git a/demo-athenaopt_backend/develop/src/main/java/com/digiwin/athena/app/provider/PurchaseDemoEAIService.java b/demo-athenaopt_backend/develop/src/main/java/com/digiwin/athena/app/provider/PurchaseDemoEAIService.java new file mode 100644 index 0000000..8c67163 --- /dev/null +++ b/demo-athenaopt_backend/develop/src/main/java/com/digiwin/athena/app/provider/PurchaseDemoEAIService.java @@ -0,0 +1,25 @@ +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.purchase.PurchaseUtil; + +import java.util.Map; + +/** + * @author lz + * @description 请购单EAI + * @throws + * @time 2023/8/29 16:41 + */ +public interface PurchaseDemoEAIService extends DWService { + + @EAIService(id = PurchaseUtil.DEMO_PURCHASE_DEMO_CREATE) + DWEAIResult create(Map headers, String messageBody) throws Exception; + + @EAIService(id = PurchaseUtil.DEMO_PURCHASE_DEMO_GET) + DWEAIResult get(Map headers, String messageBody) throws Exception; + + +} \ No newline at end of file diff --git a/demo-athenaopt_backend/develop/src/main/java/com/digiwin/athena/app/provider/impl/PurchaseDemoEAIServiceImpl.java b/demo-athenaopt_backend/develop/src/main/java/com/digiwin/athena/app/provider/impl/PurchaseDemoEAIServiceImpl.java new file mode 100644 index 0000000..87a0f4a --- /dev/null +++ b/demo-athenaopt_backend/develop/src/main/java/com/digiwin/athena/app/provider/impl/PurchaseDemoEAIServiceImpl.java @@ -0,0 +1,32 @@ +package com.digiwin.athena.app.provider.impl; + +import com.digiwin.app.service.DWEAIResult; +import com.digiwin.athena.app.provider.PurchaseDemoEAIService; +import com.digiwin.athena.app.service.purchase.PurchaseUtil; +import com.digiwin.athena.opt.common.eai.service.EAIServiceContext; + +import javax.annotation.Resource; +import java.util.Map; + +/** + * @author lz + * @version 1.0 + * @title PurchaseDemoEAIServiceImpl + * @description + * @create 2023/8/30 16:50 + */ +public class PurchaseDemoEAIServiceImpl implements PurchaseDemoEAIService { + + @Resource + private EAIServiceContext eaiServiceContext; + + @Override + public DWEAIResult create(Map headers, String messageBody) throws Exception { + return eaiServiceContext.execute(PurchaseUtil.DEMO_PURCHASE_DEMO_CREATE, headers, messageBody); + } + + @Override + public DWEAIResult get(Map headers, String messageBody) throws Exception { + return eaiServiceContext.execute(PurchaseUtil.DEMO_PURCHASE_DEMO_GET, headers, messageBody); + } +} 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 new file mode 100644 index 0000000..8373a20 --- /dev/null +++ b/demo-athenaopt_backend/develop/src/main/java/com/digiwin/athena/app/service/purchase/PurchaseDemoCreateService.java @@ -0,0 +1,53 @@ +package com.digiwin.athena.app.service.purchase; + +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.service.PurchaseDemoService; +import com.digiwin.athena.opt.common.eai.EAIUtil; +import com.digiwin.athena.opt.common.eai.service.AbsEAIService; +import org.springframework.beans.BeanUtils; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +/** + * @author lz + * @description 创建请购单 + * @throws + * @time 2023/8/29 16:16 + */ +@Service +public class PurchaseDemoCreateService extends AbsEAIService { + + @Resource + PurchaseDemoService purchaseDemoService; + + @Override + public String getServiceName() { + return PurchaseUtil.DEMO_PURCHASE_DEMO_CREATE; + } + + @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); + + return EAIUtil.buildEAIResult(new HashMap<>()); + } +} 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 new file mode 100644 index 0000000..e2dbe97 --- /dev/null +++ b/demo-athenaopt_backend/develop/src/main/java/com/digiwin/athena/app/service/purchase/PurchaseDemoGetService.java @@ -0,0 +1,78 @@ +package com.digiwin.athena.app.service.purchase; + +import com.alibaba.fastjson.JSON; +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.common.utils.ResponseUtil; +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.EAIUtil; +import com.digiwin.athena.opt.common.eai.service.AbsEAIService; +import com.digiwin.athena.opt.common.security.SecurityUtil; +import com.fasterxml.jackson.databind.ObjectMapper; +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; +import java.util.Objects; + +/** + * @author lizhuangzhuang + * @description 查询请购单 + * @throws + * @time 2023/8/30 11:07 + */ +@Service +public class PurchaseDemoGetService extends AbsEAIService { + + @Resource + PurchaseOrderDetailRepository purchaseOrderDetailRepository; + + @Override + public String getServiceName() { + return PurchaseUtil.DEMO_PURCHASE_DEMO_GET; + } + + @Override + public DWEAIResult execute(Map headers, String messageBody) throws Exception { + + //将入参值转换为Dto类存储 + List purchaseOrderDetailDTOS = TransferUtil.string2List(messageBody, PurchaseOrderDetailDTO.class, "purchase_info"); + + //根据请购单号+请购单序号+状态+任务卡类型查询 + LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); + queryWrapper.eq(PurchaseOrderDetailEntity::getTenantSid, SecurityUtil.getUserProfile().getTenantSid()); + queryWrapper.and( + queryWrapperInner -> { + for (PurchaseOrderDetailDTO purchaseOrderDetailDTO : purchaseOrderDetailDTOS) { + 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()) + + ); + } + } + ); + List entities = purchaseOrderDetailRepository.selectList(queryWrapper); + + //String类型的null字段,转换为空字符串 + List purchaseOrderDetailEntities = ResponseUtil.listNullToString(entities); + + List purchaseInfo = new ArrayList<>(); + for (PurchaseOrderDetailEntity e : purchaseOrderDetailEntities) { + purchaseInfo.add(JSON.parseObject(new ObjectMapper().writeValueAsString(e))); + } + + return EAIUtil.buildEAIResult(new JSONObject().fluentPut("purchase_info", purchaseInfo)); + + } +} 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 new file mode 100644 index 0000000..7dde132 --- /dev/null +++ b/demo-athenaopt_backend/develop/src/main/java/com/digiwin/athena/app/service/purchase/PurchaseUtil.java @@ -0,0 +1,19 @@ +package com.digiwin.athena.app.service.purchase; + +/** + * @author lz + * @version 1.0 + * @title Purchase + * @description 请购单API + * @create 2023/8/29 16:08 + */ +public class PurchaseUtil { + + //创建请购单 + public static final String DEMO_PURCHASE_DEMO_CREATE = "demo.purchase.order.create"; + + //查询请购单 + public static final String DEMO_PURCHASE_DEMO_GET = "demo.purchase.order.get"; + + +}