diff --git a/ruoyi-admin/src/main/java/com/ruoyi/aftersales/mapper/AftersalesOutOrderDetailMapper.java b/ruoyi-admin/src/main/java/com/ruoyi/aftersales/mapper/AftersalesOutOrderDetailMapper.java index 660374cd..7a93f0ed 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/aftersales/mapper/AftersalesOutOrderDetailMapper.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/aftersales/mapper/AftersalesOutOrderDetailMapper.java @@ -74,4 +74,10 @@ public interface AftersalesOutOrderDetailMapper * @return 结果 */ public int restoreAftersalesOutOrderDetailById(Long outOrderDetailId); + + /** + * 批量新增售后维护设备出库详情 + * */ + int insertBatchAftersalesOutOrderDetail(List aftersalesOutOrderDetails); + } diff --git a/ruoyi-admin/src/main/java/com/ruoyi/warehouse/service/impl/WarehouseOutOrderServiceImpl.java b/ruoyi-admin/src/main/java/com/ruoyi/warehouse/service/impl/WarehouseOutOrderServiceImpl.java index 3480711b..0cd82f3b 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/warehouse/service/impl/WarehouseOutOrderServiceImpl.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/warehouse/service/impl/WarehouseOutOrderServiceImpl.java @@ -4,6 +4,10 @@ import java.math.BigDecimal; import java.util.*; import java.util.stream.Collectors; +import com.ruoyi.aftersales.domain.AftersalesOutOrder; +import com.ruoyi.aftersales.domain.AftersalesOutOrderDetail; +import com.ruoyi.aftersales.mapper.AftersalesOutOrderDetailMapper; +import com.ruoyi.aftersales.mapper.AftersalesOutOrderMapper; import com.ruoyi.common.core.redis.RedisCache; import com.ruoyi.common.exception.BusinessException; import com.ruoyi.common.utils.DateUtils; @@ -25,6 +29,7 @@ import com.ruoyi.warehouse.mapper.WarehouseInventoryInquiryDetailMapper; import com.ruoyi.warehouse.mapper.WarehouseInventoryInquiryMapper; import com.ruoyi.warehouse.mapper.WarehouseOutOrderDetailMapper; import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import com.ruoyi.warehouse.mapper.WarehouseOutOrderMapper; @@ -95,6 +100,12 @@ public class WarehouseOutOrderServiceImpl implements IWarehouseOutOrderService @Autowired private QualityRefundsExchangesMapper refundsExchangesMapper; + @Autowired + private AftersalesOutOrderMapper aftersalesOutOrderMapper; + + @Autowired + private AftersalesOutOrderDetailMapper aftersalesOutOrderDetailMapper; + /** * 查询仓库出库单 * @@ -200,7 +211,7 @@ public class WarehouseOutOrderServiceImpl implements IWarehouseOutOrderService /** * 修改保存销售单-准备物料 * */ - @Transactional + @Transactional(rollbackFor = Exception.class) @Override public int updatePrepareMaterial(WarehouseOutOrder warehouseOutOrder) { @@ -216,19 +227,15 @@ public class WarehouseOutOrderServiceImpl implements IWarehouseOutOrderService } //过滤掉准备出库数为0的数据,相当于本次不出库 List filterOutOrderDetailList = warehouseOutOrderDetailList.stream().filter(item -> item.getPrepareOutOrderSum() != 0).collect(Collectors.toList()); - for (WarehouseOutOrderDetail warehouseOutOrderDetail : filterOutOrderDetailList) { - warehouseOutOrderDetail.setUpdateBy(loginName); - warehouseOutOrderDetail.setUpdateTime(new Date()); - warehouseOutOrderDetail.setRemark(warehouseOutOrder.getRemark()); - Integer prepareOutOrderSum = warehouseOutOrderDetail.getPrepareOutOrderSum(); - Integer applyOutOrderSum = warehouseOutOrderDetail.getApplyOutOrderSum(); - //准备出库数 必须等于 申请出库数 - if (!Objects.equals(prepareOutOrderSum, applyOutOrderSum)){ - throw new BusinessException("准备出库数必须等于申请出库数"); - } - //更新数据库记录 - int updateOutOrderDetail = outOrderDetailMapper.updateWarehouseOutOrderDetail(warehouseOutOrderDetail); - if (updateOutOrderDetail <= 0){ + + // 校验子表数据 + checkWarehouseOutOrderDetailList(filterOutOrderDetailList, loginName,warehouseOutOrder); + + + // 更新出库单详情数据 + for (WarehouseOutOrderDetail detail : filterOutOrderDetailList) { + int updateResult = outOrderDetailMapper.updateWarehouseOutOrderDetail(detail); + if (updateResult <= 0) { throw new BusinessException("更新出库单详情数据失败"); } } @@ -245,12 +252,76 @@ public class WarehouseOutOrderServiceImpl implements IWarehouseOutOrderService log.warn("出库单号为空:{}",warehouseOutOrder.getOutOrderCode()); throw new BusinessException("更新销售出库单数据失败"); } + //生成售后出库单 + int insertAftersalesOutOrderResult = buildAftersalesOutOrder(warehouseOutOrder); + if (insertAftersalesOutOrderResult <= 0){ + throw new BusinessException("生成售后出库单失败"); + } + //生成售后出库单详情 + int insertAftersalesOutOrderDetailResult = buildAftersalesOutOrderDetail(filterOutOrderDetailList); + if (insertAftersalesOutOrderDetailResult <= 0){ + throw new BusinessException("生成售后出库单详情失败"); + } int updateWarehouseOutOrderResult = warehouseOutOrderMapper.updateWarehouseOutOrder(warehouseOutOrder); return updateWarehouseOutOrderResult; } + //检验出库单详情数据 + private void checkWarehouseOutOrderDetailList(List details, String loginName, WarehouseOutOrder warehouseOutOrder) { + for (WarehouseOutOrderDetail detail : details) { + detail.setUpdateBy(loginName); + detail.setUpdateTime(new Date()); + detail.setRemark(warehouseOutOrder.getRemark()); + + Integer prepareOutOrderSum = detail.getPrepareOutOrderSum(); + Integer applyOutOrderSum = detail.getApplyOutOrderSum(); + + if (prepareOutOrderSum == null || applyOutOrderSum == null) { + throw new BusinessException("准备出库数或申请出库数不能为空"); + } + + if (!Objects.equals(prepareOutOrderSum, applyOutOrderSum)) { + throw new BusinessException("准备出库数必须等于申请出库数"); + } + } + } + + + + //生成售后出库单详情 + private int buildAftersalesOutOrderDetail(List filterOutOrderDetailList) { + String loginName = ShiroUtils.getLoginName(); + List aftersalesOutOrderDetails = new ArrayList<>(); + for (WarehouseOutOrderDetail warehouseOutOrderDetail : filterOutOrderDetailList) { + AftersalesOutOrderDetail aftersalesOutOrderDetail = new AftersalesOutOrderDetail(); + BeanUtils.copyProperties(warehouseOutOrderDetail,aftersalesOutOrderDetail); + aftersalesOutOrderDetail.setCreateBy(loginName); + aftersalesOutOrderDetail.setCreateTime(new Date()); + aftersalesOutOrderDetails.add(aftersalesOutOrderDetail); + + } + return aftersalesOutOrderDetailMapper.insertBatchAftersalesOutOrderDetail(aftersalesOutOrderDetails); + + } + + //生成售后出库单 + private int buildAftersalesOutOrder(WarehouseOutOrder warehouseOutOrder) { + + AftersalesOutOrder aftersalesOutOrder = new AftersalesOutOrder(); + + String loginName = ShiroUtils.getLoginName(); + warehouseOutOrder.setCreateBy(loginName); + warehouseOutOrder.setCreateTime(new Date()); + //更改出库状态为 第一次维护设备信息 + warehouseOutOrder.setWarehouseOutStatus("1"); + BeanUtils.copyProperties(warehouseOutOrder,aftersalesOutOrder); + return aftersalesOutOrderMapper.insertAftersalesOutOrder(aftersalesOutOrder); + + } + + /** * 修改保存销售单-出库 */ diff --git a/ruoyi-admin/src/main/resources/mapper/aftersales/AftersalesOutOrderDetailMapper.xml b/ruoyi-admin/src/main/resources/mapper/aftersales/AftersalesOutOrderDetailMapper.xml index 5277b8f7..6c5938b6 100644 --- a/ruoyi-admin/src/main/resources/mapper/aftersales/AftersalesOutOrderDetailMapper.xml +++ b/ruoyi-admin/src/main/resources/mapper/aftersales/AftersalesOutOrderDetailMapper.xml @@ -178,6 +178,116 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" + + + insert into aftersales_out_order_detail ( + out_order_code, + make_no, + warehouse_out_status, + related_order_code, + sales_order_code, + warehouse_order_type, + out_make_code, + requisitioning_code, + warehouse_out_type, + business_name, + aftersales_name, + warehouse_name, + shipping_device_id, + material_no, + material_name, + material_type, + material_photoUrl, + material_brand, + material_unit, + material_describe, + material_process_method, + material_model, + material_specification, + material_sum, + enterprise_sum, + make_num, + out_order_sum, + has_out_order_sum, + apply_out_order_sum, + prepare_out_order_sum, + actual_out_order_sum, + out_order_name, + out_order_time, + supplier_code, + supplier_name, + customer_id, + customer_name, + plan_delivery_time, + delivery_date, + delivery_condition, + apply_name, + delivery_address, + delivery_name, + delivery_number, + remark, + create_by, + create_time, + update_by, + update_time + ) values + + ( + #{item.outOrderCode}, + #{item.makeNo}, + #{item.warehouseOutStatus}, + #{item.relatedOrderCode}, + #{item.salesOrderCode}, + #{item.warehouseOrderType}, + #{item.outMakeCode}, + #{item.requisitioningCode}, + #{item.warehouseOutType}, + #{item.businessName}, + #{item.aftersalesName}, + #{item.warehouseName}, + #{item.shippingDeviceId}, + #{item.materialNo}, + #{item.materialName}, + #{item.materialType}, + #{item.materialPhotourl}, + #{item.materialBrand}, + #{item.materialUnit}, + #{item.materialDescribe}, + #{item.materialProcessMethod}, + #{item.materialModel}, + #{item.materialSpecification}, + #{item.materialSum}, + #{item.enterpriseSum}, + #{item.makeNum}, + #{item.outOrderSum}, + #{item.hasOutOrderSum}, + #{item.applyOutOrderSum}, + #{item.prepareOutOrderSum}, + #{item.actualOutOrderSum}, + #{item.outOrderName}, + #{item.outOrderTime}, + #{item.supplierCode}, + #{item.supplierName}, + #{item.customerId}, + #{item.customerName}, + #{item.planDeliveryTime}, + #{item.deliveryDate}, + #{item.deliveryCondition}, + #{item.applyName}, + #{item.deliveryAddress}, + #{item.deliveryName}, + #{item.deliveryNumber}, + #{item.remark}, + #{item.createBy}, + #{item.createTime}, + #{item.updateBy}, + #{item.updateTime} + ) + + + + + update aftersales_out_order_detail diff --git a/ruoyi-admin/src/main/resources/mapper/warehouse/WarehouseOutOrderMapper.xml b/ruoyi-admin/src/main/resources/mapper/warehouse/WarehouseOutOrderMapper.xml index 5204a59b..8af5804d 100644 --- a/ruoyi-admin/src/main/resources/mapper/warehouse/WarehouseOutOrderMapper.xml +++ b/ruoyi-admin/src/main/resources/mapper/warehouse/WarehouseOutOrderMapper.xml @@ -82,6 +82,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" and delivery_date = #{deliveryDate} and warehouse_order_type = "0" + order by create_time desc