Browse Source

[fix]

生产管理 生产入库
去除生产入库service委内有关方法;
dev
王晓迪 4 days ago
parent
commit
c6f9ff4c2d
  1. 246
      ruoyi-admin/src/main/java/com/ruoyi/erp/service/impl/ErpInboundOrderServiceImpl.java

246
ruoyi-admin/src/main/java/com/ruoyi/erp/service/impl/ErpInboundOrderServiceImpl.java

@ -109,112 +109,10 @@ public class ErpInboundOrderServiceImpl implements IErpInboundOrderService
/**
* 生产订单新增委内加工入库单先品质
*
* @param erpInboundOrder 委内加工入库单
* @return 结果
*/
*/
@Override
@Transactional(rollbackFor = Exception.class)
public int insertErpInboundOrder(ErpInboundOrder erpInboundOrder)
{
QualityOrder qualityOrder = new QualityOrder();
String loginName = ShiroUtils.getLoginName();
erpInboundOrder.setCreateBy(loginName);
erpInboundOrder.setCreateTime(DateUtils.getNowDate());
// 生成编号,年月日规则
String qualityOrderCode = redisCache.generateBillNo("PZ");
qualityOrder.setQualityOrderCode(qualityOrderCode);
//设置关联单号
qualityOrder.setRelatedOrderCode(erpInboundOrder.getMakeNo());
//设置为待品质
qualityOrder.setQualityStatus("0");
//设置为委内入库
qualityOrder.setQualityStorageStatus("1");
//设置订单类型
qualityOrder.setQualityOrderType("1");
qualityOrder.setCreateTime(new Date());
qualityOrder.setCreateBy(loginName);
// 获取所有makeorderBomId对应的SysMakeorderBom对象
List<SysMakeorderBom> sysMakeorderBoms = erpInboundOrder.getInboundDetails().stream()
.map(ErpInboundOrderDetail::getMakeorderBomId)
.map(this::getSysMakeorderBomById)
.collect(Collectors.toList());
// 筛选加工方式只有委内加工的数据
List<SysMakeorderBom> filterSysMakeorderBoms = sysMakeorderBoms.stream()
.filter(sysMakeorderBom -> "1".equals(sysMakeorderBom.getProcessMethod()))
.collect(Collectors.toList());
// 创建一个Set来存储filterSysMakeorderBoms中的所有物料号MaterialNo
Set<String> materialNoSet = filterSysMakeorderBoms.stream()
.map(SysMakeorderBom::getMaterialNo)
.collect(Collectors.toSet());
// 使用materialNoSet来过滤erpInboundOrder.getInboundDetails()
List<ErpInboundOrderDetail> filteredErpInboundOrderDetails = erpInboundOrder.getInboundDetails().stream()
.filter(detail -> materialNoSet.contains(detail.getMaterialNo()) && detail.getCurrentNum() != null)
.collect(Collectors.toList());
// 首先,创建一个Map来收集每个物料号及其对应的加工费单价的列表
Map<String, List<BigDecimal>> processFeesByMaterialNo = filteredErpInboundOrderDetails.stream()
.collect(Collectors.groupingBy(
ErpInboundOrderDetail::getMaterialNo, // 分组依据:物料号
Collectors.mapping(
ErpInboundOrderDetail::getProcessFeeUnitPrice, // 映射:从每个细节中获取加工费单价
Collectors.toList() // 收集:将映射结果收集到List中
)
));
// 然后,检查是否有任何物料号的加工费单价不一致
boolean hasInconsistentFees = processFeesByMaterialNo.values().stream()
.anyMatch(prices -> prices.stream().distinct().count() > 1);
// 如果发现加工费单价不一致,则抛出异常
if (hasInconsistentFees) {
throw new BusinessException("请保持委内加工费单价一致");
}
// 计算本次委内完成数合计
long addCurrentNum = filteredErpInboundOrderDetails.stream()
.mapToLong(ErpInboundOrderDetail::getCurrentNum) // 假设getCurrentNum()返回的是int或long类型
.sum();
// 将long类型的addCurrentNum转换为BigDecimal类型
BigDecimal bigAddCurrentNum = BigDecimal.valueOf(addCurrentNum);
// 检查是否存在加工费单价为null的情况
boolean hasMakeInTotalPriceNull = filteredErpInboundOrderDetails.stream()
.anyMatch(item -> item.getProcessFeeUnitPrice() == null);
if (hasMakeInTotalPriceNull) {
throw new BusinessException("存在委内加工费为空,请检查!");
}
// 确保processFeeUnitPrice不为null,避免NullPointerException
BigDecimal processFeeUnitPrice = filteredErpInboundOrderDetails.get(0).getProcessFeeUnitPrice();
if (processFeeUnitPrice == null) {
throw new BusinessException("加工费单价未找到,请检查!");
}
// 计算委内加工费总价
BigDecimal makeInTotalPrice = bigAddCurrentNum.multiply(processFeeUnitPrice);
//加入到品质单中
qualityOrder.setMakeInTotalPrice(makeInTotalPrice);
//添加委内加工品质单详情数据
addQualityOrderDetail(erpInboundOrder, filteredErpInboundOrderDetails,qualityOrderCode,filterSysMakeorderBoms);
//添加委内加工品质单报告数据
addQualityOrderReport(filteredErpInboundOrderDetails,qualityOrderCode,filterSysMakeorderBoms);
//插入品质单
return qualityOrderMapper.insertQualityOrder(qualityOrder);
public int insertErpInboundOrder(ErpInboundOrder erpInboundOrder) {
return erpInboundOrderMapper.insertErpInboundOrder(erpInboundOrder);
}
// 提取公共方法
@ -223,39 +121,39 @@ public class ErpInboundOrderServiceImpl implements IErpInboundOrderService
}
//添加委内加工品质单报告数据
private void addQualityOrderReport(List<ErpInboundOrderDetail> filteredErpInboundOrderDetails,String qualityOrderCode,List<SysMakeorderBom> sysMakeorderBoms) {
// List<ErpInboundOrderDetail> inboundDetails = erpInboundOrder.getInboundDetails();
// if (CollectionUtils.isEmpty(inboundDetails)) {
// throw new BusinessException("委内加工详情数据为空");
// private void addQualityOrderReport(List<ErpInboundOrderDetail> filteredErpInboundOrderDetails,String qualityOrderCode,List<SysMakeorderBom> sysMakeorderBoms) {
//// List<ErpInboundOrderDetail> inboundDetails = erpInboundOrder.getInboundDetails();
//// if (CollectionUtils.isEmpty(inboundDetails)) {
//// throw new BusinessException("委内加工详情数据为空");
//// }
// for (int i = 0; i < filteredErpInboundOrderDetails.size(); i++) {
// ErpInboundOrderDetail inboundDetail = filteredErpInboundOrderDetails.get(i);
// SysMakeorderBom sysMakeorderBom = sysMakeorderBoms.get(i);
// QualityOrderReport qualityOrderReport = new QualityOrderReport();
// qualityOrderReport.setQualityOrderCode(qualityOrderCode);
// qualityOrderReport.setMaterialNo(sysMakeorderBom.getMaterialNo());
//
// QualityOrderReport tempQualityOrderReport = qualityOrderReportMapper.selectMakeInOrderReportByNoAndCode(qualityOrderReport);
// if (tempQualityOrderReport != null){
// qualityOrderReport.setQualityOrderReportId(tempQualityOrderReport.getQualityOrderReportId());
// Long currentNum = inboundDetail.getCurrentNum();
//// qualityOrderReport.setMakeInNum((int) (tempQualityOrderReport.getMakeInNum()+currentNum));
// int updateQualityOrderReportResult = qualityOrderReportMapper.updateQualityOrderReportById(qualityOrderReport);
// if (updateQualityOrderReportResult <= 0){
// throw new BusinessException("更新品质单报告数据失败");
// }
// }else {
// qualityOrderReport.setMaterialName(sysMakeorderBom.getMaterialName());
// //添加委内已完成数
//// qualityOrderReport.setMakeInNum(Math.toIntExact(inboundDetail.getCurrentNum()));
// qualityOrderReport.setCreateBy(ShiroUtils.getLoginName());
// qualityOrderReport.setCreateTime(new Date());
// qualityOrderReportMapper.insertQualityOrderReport(qualityOrderReport);
// }
//
//
// }
for (int i = 0; i < filteredErpInboundOrderDetails.size(); i++) {
ErpInboundOrderDetail inboundDetail = filteredErpInboundOrderDetails.get(i);
SysMakeorderBom sysMakeorderBom = sysMakeorderBoms.get(i);
QualityOrderReport qualityOrderReport = new QualityOrderReport();
qualityOrderReport.setQualityOrderCode(qualityOrderCode);
qualityOrderReport.setMaterialNo(sysMakeorderBom.getMaterialNo());
QualityOrderReport tempQualityOrderReport = qualityOrderReportMapper.selectMakeInOrderReportByNoAndCode(qualityOrderReport);
if (tempQualityOrderReport != null){
qualityOrderReport.setQualityOrderReportId(tempQualityOrderReport.getQualityOrderReportId());
Long currentNum = inboundDetail.getCurrentNum();
qualityOrderReport.setMakeInNum((int) (tempQualityOrderReport.getMakeInNum()+currentNum));
int updateQualityOrderReportResult = qualityOrderReportMapper.updateQualityOrderReportById(qualityOrderReport);
if (updateQualityOrderReportResult <= 0){
throw new BusinessException("更新品质单报告数据失败");
}
}else {
qualityOrderReport.setMaterialName(sysMakeorderBom.getMaterialName());
//添加委内已完成数
qualityOrderReport.setMakeInNum(Math.toIntExact(inboundDetail.getCurrentNum()));
qualityOrderReport.setCreateBy(ShiroUtils.getLoginName());
qualityOrderReport.setCreateTime(new Date());
qualityOrderReportMapper.insertQualityOrderReport(qualityOrderReport);
}
}
}
// }
//添加委内加工品质单详情数据
private void addQualityOrderDetail(ErpInboundOrder erpInboundOrder,List<ErpInboundOrderDetail> filteredErpInboundOrderDetails,String qualityOrderCode,List<SysMakeorderBom> sysMakeorderBoms) {
@ -263,43 +161,43 @@ public class ErpInboundOrderServiceImpl implements IErpInboundOrderService
// if (CollectionUtils.isEmpty(inboundDetails)) {
// throw new BusinessException("委内加工详情数据为空");
// }
for (int i = 0; i < filteredErpInboundOrderDetails.size(); i++) {
ErpInboundOrderDetail inboundDetail = filteredErpInboundOrderDetails.get(i);
SysMakeorderBom sysMakeorderBom = sysMakeorderBoms.get(i);
QualityOrderDetail qualityOrderDetail = new QualityOrderDetail();
qualityOrderDetail.setMaterialNo(sysMakeorderBom.getMaterialNo());
qualityOrderDetail.setQualityOrderCode(qualityOrderCode);
QualityOrderDetail tempQualityOrderDetail = qualityOrderDetailMapper.selectMakeInOrderDetailByCodeAndNo(qualityOrderDetail);
if (tempQualityOrderDetail != null){
qualityOrderDetail.setQualityOrderDetailId(tempQualityOrderDetail.getQualityOrderDetailId());
Long currentNum = inboundDetail.getCurrentNum();
qualityOrderDetail.setMakeInNum((int) (tempQualityOrderDetail.getMakeInNum()+currentNum));
int updateQualityOrderDetailResult = qualityOrderDetailMapper.updateQualityOrderDetail(qualityOrderDetail);
if (updateQualityOrderDetailResult <= 0){
throw new BusinessException("更新品质单详情数据失败");
}
}else {
qualityOrderDetail.setRelatedOrderCode(erpInboundOrder.getMakeNo());
qualityOrderDetail.setMaterialName(sysMakeorderBom.getMaterialName());
qualityOrderDetail.setMaterialBrand(sysMakeorderBom.getBrand());
qualityOrderDetail.setMaterialDescribe(sysMakeorderBom.getDescribe());
qualityOrderDetail.setMaterialProcessMethod(sysMakeorderBom.getProcessMethod());
qualityOrderDetail.setMaterialDeptType(sysMakeorderBom.getWarehouseDept());
qualityOrderDetail.setMaterialPhotourl(sysMakeorderBom.getPhotoUrl());
qualityOrderDetail.setMaterialUnit(sysMakeorderBom.getUnit());
qualityOrderDetail.setMaterialType(sysMakeorderBom.getMaterialType());
//添加委内已完成数
qualityOrderDetail.setMakeInNum(Math.toIntExact(inboundDetail.getCurrentNum()));
//添加委内加工费单价
qualityOrderDetail.setMakeInUnitPrice(inboundDetail.getProcessFeeUnitPrice());
qualityOrderDetail.setCreateBy(ShiroUtils.getLoginName());
qualityOrderDetail.setCreateTime(new Date());
qualityOrderDetailMapper.insertQualityOrderDetail(qualityOrderDetail);
}
}
// for (int i = 0; i < filteredErpInboundOrderDetails.size(); i++) {
// ErpInboundOrderDetail inboundDetail = filteredErpInboundOrderDetails.get(i);
// SysMakeorderBom sysMakeorderBom = sysMakeorderBoms.get(i);
//
// QualityOrderDetail qualityOrderDetail = new QualityOrderDetail();
// qualityOrderDetail.setMaterialNo(sysMakeorderBom.getMaterialNo());
// qualityOrderDetail.setQualityOrderCode(qualityOrderCode);
// QualityOrderDetail tempQualityOrderDetail = qualityOrderDetailMapper.selectMakeInOrderDetailByCodeAndNo(qualityOrderDetail);
// if (tempQualityOrderDetail != null){
// qualityOrderDetail.setQualityOrderDetailId(tempQualityOrderDetail.getQualityOrderDetailId());
// Long currentNum = inboundDetail.getCurrentNum();
// qualityOrderDetail.setMakeInNum((int) (tempQualityOrderDetail.getMakeInNum()+currentNum));
// int updateQualityOrderDetailResult = qualityOrderDetailMapper.updateQualityOrderDetail(qualityOrderDetail);
// if (updateQualityOrderDetailResult <= 0){
// throw new BusinessException("更新品质单详情数据失败");
// }
// }else {
// qualityOrderDetail.setRelatedOrderCode(erpInboundOrder.getMakeNo());
//
// qualityOrderDetail.setMaterialName(sysMakeorderBom.getMaterialName());
// qualityOrderDetail.setMaterialBrand(sysMakeorderBom.getBrand());
// qualityOrderDetail.setMaterialDescribe(sysMakeorderBom.getDescribe());
// qualityOrderDetail.setMaterialProcessMethod(sysMakeorderBom.getProcessMethod());
// qualityOrderDetail.setMaterialDeptType(sysMakeorderBom.getWarehouseDept());
// qualityOrderDetail.setMaterialPhotourl(sysMakeorderBom.getPhotoUrl());
// qualityOrderDetail.setMaterialUnit(sysMakeorderBom.getUnit());
// qualityOrderDetail.setMaterialType(sysMakeorderBom.getMaterialType());
// //添加委内已完成数
// qualityOrderDetail.setMakeInNum(Math.toIntExact(inboundDetail.getCurrentNum()));
// //添加委内加工费单价
// qualityOrderDetail.setMakeInUnitPrice(inboundDetail.getProcessFeeUnitPrice());
// qualityOrderDetail.setCreateBy(ShiroUtils.getLoginName());
// qualityOrderDetail.setCreateTime(new Date());
// qualityOrderDetailMapper.insertQualityOrderDetail(qualityOrderDetail);
// }
//
// }
}
/**

Loading…
Cancel
Save