@ -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 <T> 待转化对象类型 | |||
* @param cls 待转化对象 | |||
* @return 转化好的对象 | |||
*/ | |||
public static <T> 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 <T> List<T> listNullToString(List<T> sourceList) { | |||
ArrayList<T> 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<Map<String, Object>> listMapToLowerCase(List<Map<String, Object>> sourceList) { | |||
List<Map<String, Object>> response = new ArrayList<>(); | |||
for (Map<String, Object> map : sourceList) { | |||
Map<String, Object> newMap = new HashMap<>(); | |||
for (Map.Entry<String, Object> entry : map.entrySet()) { | |||
String key = entry.getKey().toLowerCase(); | |||
Object value = entry.getValue(); | |||
newMap.put(key, value); | |||
} | |||
response.add(newMap); | |||
} | |||
return response; | |||
} | |||
} |
@ -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; | |||
} |
@ -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<PurchaseOrderDetailEntity> { | |||
/** | |||
* 请购单号 | |||
*/ | |||
@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; | |||
} |
@ -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<PurchaseOrderDetailEntity> { | |||
} |
@ -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<PurchaseOrderDetailRepository, PurchaseOrderDetailEntity> implements PurchaseDemoService { | |||
} |
@ -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<PurchaseOrderDetailEntity> { | |||
} |
@ -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<String, String> headers, String messageBody) throws Exception; | |||
@EAIService(id = PurchaseUtil.DEMO_PURCHASE_DEMO_GET) | |||
DWEAIResult get(Map<String, String> headers, String messageBody) throws Exception; | |||
} |
@ -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<String, String> headers, String messageBody) throws Exception { | |||
return eaiServiceContext.execute(PurchaseUtil.DEMO_PURCHASE_DEMO_CREATE, headers, messageBody); | |||
} | |||
@Override | |||
public DWEAIResult get(Map<String, String> headers, String messageBody) throws Exception { | |||
return eaiServiceContext.execute(PurchaseUtil.DEMO_PURCHASE_DEMO_GET, headers, messageBody); | |||
} | |||
} |
@ -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<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); | |||
return EAIUtil.buildEAIResult(new HashMap<>()); | |||
} | |||
} |
@ -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<String, String> headers, String messageBody) throws Exception { | |||
//将入参值转换为Dto类存储 | |||
List<PurchaseOrderDetailDTO> purchaseOrderDetailDTOS = TransferUtil.string2List(messageBody, PurchaseOrderDetailDTO.class, "purchase_info"); | |||
//根据请购单号+请购单序号+状态+任务卡类型查询 | |||
LambdaQueryWrapper<PurchaseOrderDetailEntity> 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<PurchaseOrderDetailEntity> entities = purchaseOrderDetailRepository.selectList(queryWrapper); | |||
//String类型的null字段,转换为空字符串 | |||
List<PurchaseOrderDetailEntity> purchaseOrderDetailEntities = ResponseUtil.listNullToString(entities); | |||
List<JSONObject> purchaseInfo = new ArrayList<>(); | |||
for (PurchaseOrderDetailEntity e : purchaseOrderDetailEntities) { | |||
purchaseInfo.add(JSON.parseObject(new ObjectMapper().writeValueAsString(e))); | |||
} | |||
return EAIUtil.buildEAIResult(new JSONObject().fluentPut("purchase_info", purchaseInfo)); | |||
} | |||
} |
@ -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"; | |||
} |