package com.vincent.rsf.server.api.service.impl;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.vincent.rsf.framework.common.R;
|
import com.vincent.rsf.framework.exception.CoolException;
|
import com.vincent.rsf.server.api.controller.params.BaseMatParms;
|
import com.vincent.rsf.server.api.controller.params.QueryOrderParam;
|
import com.vincent.rsf.server.api.controller.params.WkOrderDto;
|
import com.vincent.rsf.server.common.domain.BaseParam;
|
import com.vincent.rsf.server.common.domain.PageParam;
|
import com.vincent.rsf.server.manager.entity.*;
|
import com.vincent.rsf.server.manager.enums.OrderType;
|
import com.vincent.rsf.server.manager.service.*;
|
import com.vincent.rsf.server.manager.service.impl.MatnrServiceImpl;
|
import com.vincent.rsf.server.system.constant.SerialRuleCode;
|
import com.vincent.rsf.server.api.controller.params.OrderParams;
|
import com.vincent.rsf.server.system.entity.Fields;
|
import com.vincent.rsf.server.system.service.FieldsItemService;
|
import com.vincent.rsf.server.system.service.FieldsService;
|
import com.vincent.rsf.server.system.utils.SerialRuleUtils;
|
import com.vincent.rsf.server.api.service.ReceiveMsgService;
|
import lombok.extern.slf4j.Slf4j;
|
import org.springframework.beans.BeanUtils;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Service;
|
import org.springframework.transaction.annotation.Transactional;
|
|
import java.util.*;
|
|
/**
|
* @author Ryan
|
* @version 1.0
|
* @title ErpApiServiceImpl
|
* @description
|
* @create 2025/3/4 16:27
|
*/
|
@Slf4j
|
@Service("erpApiService")
|
public class ReceiveMsgServiceImpl implements ReceiveMsgService {
|
|
@Autowired
|
private PurchaseService purchaseService;
|
@Autowired
|
private PurchaseItemService purchaseItemService;
|
@Autowired
|
private FieldsService fieldsService;
|
@Autowired
|
private FieldsItemService fieldsItemService;
|
@Autowired
|
private MatnrGroupService matnrGroupService;
|
@Autowired
|
private MatnrServiceImpl matnrService;
|
@Autowired
|
private AsnOrderService asnOrderService;
|
@Autowired
|
private AsnOrderItemService asnOrderItemService;
|
@Autowired
|
private DeliveryService deliveryService;
|
@Autowired
|
private DeliveryItemService deliveryItemService;
|
@Autowired
|
private LocService locService;
|
@Autowired
|
private LocItemService locItemService;
|
|
/**
|
* @author Ryan
|
* @date 2025/8/15
|
* @description: 保存PO/DO单据
|
* @version 1.0
|
*/
|
@Override
|
@Transactional(rollbackFor = Exception.class)
|
public boolean syncPurchasee(List<OrderParams> orders) {
|
if (orders.isEmpty()) {
|
throw new CoolException("单据内容不能为空!!");
|
}
|
orders.forEach(ors -> {
|
if (ors.getType().equals("po")) {
|
Purchase purchase = new Purchase();
|
BeanUtils.copyProperties(ors, purchase);
|
String wkVal = SerialRuleUtils.generateRuleCode(SerialRuleCode.PURCHASE_CODE, purchase);
|
purchase.setCode(wkVal)
|
.setType(OrderType.ORDER_IN.type);
|
if (!purchaseService.save(purchase)) {
|
throw new CoolException("采购单据保存失败");
|
}
|
|
//查询扩展字段是否存在
|
List<Fields> fields = fieldsService.list(new LambdaQueryWrapper<Fields>().eq(Fields::getStatus, 1).eq(Fields::getFlagEnable, 1));
|
|
//判断子列表不为空
|
if (!ors.getChildren().isEmpty()) {
|
ArrayList<PurchaseItem> list = new ArrayList<>();
|
ors.getChildren().forEach(orderItem -> {
|
PurchaseItem item = new PurchaseItem();
|
BeanUtils.copyProperties(orderItem, item);
|
// if (!fields.isEmpty()) {
|
// List<String> fieldValue = fields.stream().map(Fields::getFields).collect(Collectors.toList());
|
// fieldValue.forEach(value -> {
|
//
|
// });
|
// }
|
item.setPurchaseId(purchase.getId());
|
list.add(item);
|
});
|
if (!purchaseItemService.saveBatch(list)) {
|
throw new CoolException("采购单明细保存失败!!");
|
}
|
}
|
} else {
|
Delivery delivery = new Delivery();
|
BeanUtils.copyProperties(ors, delivery);
|
String wkVal = SerialRuleUtils.generateRuleCode(SerialRuleCode.SYS_DELIVERY_RULE_CODE, delivery);
|
delivery.setCode(wkVal)
|
.setType(OrderType.ORDER_OUT.type);
|
if (!deliveryService.save(delivery)) {
|
throw new CoolException("采购单据保存失败");
|
}
|
|
//查询扩展字段是否存在
|
List<Fields> fields = fieldsService.list(new LambdaQueryWrapper<Fields>().eq(Fields::getStatus, 1).eq(Fields::getFlagEnable, 1));
|
|
//判断子列表不为空
|
if (!ors.getChildren().isEmpty()) {
|
ArrayList<DeliveryItem> list = new ArrayList<>();
|
ors.getChildren().forEach(orderItem -> {
|
DeliveryItem item = new DeliveryItem();
|
BeanUtils.copyProperties(orderItem, item);
|
// if (!fields.isEmpty()) {
|
// List<String> fieldValue = fields.stream().map(Fields::getFields).collect(Collectors.toList());
|
// fieldValue.forEach(value -> {
|
//
|
// });
|
// }
|
item.setDeliveryId(delivery.getId());
|
list.add(item);
|
});
|
if (!deliveryItemService.saveBatch(list)) {
|
throw new CoolException("采购单明细保存失败!!");
|
}
|
}
|
}
|
});
|
|
return true;
|
}
|
|
/**
|
* 物料信息同步
|
*
|
* @param matnrs
|
*/
|
@Override
|
public void syncMatnrs(List<BaseMatParms> matnrs) {
|
List<Matnr> syncMatnrs = new ArrayList<>();
|
if (!matnrs.isEmpty()) {
|
matnrs.forEach(matnr -> {
|
Matnr mat = new Matnr();
|
if (Objects.isNull(matnr.getMatnr())) {
|
throw new RuntimeException("物料编码不能为空!!");
|
}
|
BeanUtils.copyProperties(matnr, mat);
|
mat.setCode(matnr.getMatnr()).setName(matnr.getMaktx());
|
if (!Objects.isNull(matnr.getGroupName())) {
|
MatnrGroup matnrGroup = matnrGroupService.getOne(new LambdaQueryWrapper<MatnrGroup>().eq(MatnrGroup::getName, matnr.getGroupName()), false);
|
if (Objects.isNull(matnrGroup)) {
|
mat.setGroupCode(matnrGroup.getCode()).setGroupId(matnrGroup.getId());
|
}
|
}
|
syncMatnrs.add(mat);
|
});
|
|
if (!matnrService.saveOrUpdateBatch(syncMatnrs)) {
|
throw new CoolException("物料信息保存成功!!");
|
}
|
}
|
}
|
|
/**
|
* @author Ryan
|
* @date 2025/8/15
|
* @description: 订单查询
|
* @version 1.0
|
*/
|
@Override
|
public R queryOrderStatus(QueryOrderParam queryParams) {
|
WkOrder wkOrders = asnOrderService.getOne(new LambdaQueryWrapper<WkOrder>()
|
.eq(WkOrder::getCode, queryParams.getOrderNo())
|
.eq(WkOrder::getType, queryParams.getType()));
|
if (Objects.isNull(wkOrders)) {
|
throw new CoolException("单据不存在!!");
|
}
|
List<WkOrderItem> orderItems = asnOrderItemService.list(new LambdaQueryWrapper<WkOrderItem>().eq(WkOrderItem::getOrderId, wkOrders.getId()));
|
|
WkOrderDto wkorderDto = new WkOrderDto();
|
wkorderDto.setOrder(wkOrders).setOrderItems(orderItems);
|
|
return R.ok().add(wkorderDto);
|
}
|
|
/**
|
* @author Ryan
|
* @date 2025/8/15
|
* @description: 同步库位信息
|
* @version 1.0
|
*/
|
@Override
|
public R syncLocsDetl(PageParam<Loc, BaseParam> pageParam, QueryWrapper<Loc> wrapper) {
|
Page<Object> page = new Page<>();
|
page.setCurrent(pageParam.getCurrent()).setSize(pageParam.getSize());
|
|
|
return null;
|
}
|
|
|
}
|