|
@@ -34,6 +34,7 @@ import com.sd.framework.util.Assert;
|
|
|
import com.sd.mq.enums.WorkOrderStatusEnum;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import java.util.*;
|
|
|
import java.util.function.Function;
|
|
@@ -162,6 +163,47 @@ public class ProductionOrderServiceImpl implements ProductionOrderService {
|
|
|
|
|
|
}
|
|
|
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ @Override
|
|
|
+ public void finishOrder(Long id) {
|
|
|
+ OrderInfo orderInfo = orderService.getById(id);
|
|
|
+ if (orderInfo == null) {
|
|
|
+ throw new ServiceException("未找到订单");
|
|
|
+ }
|
|
|
+ if (!orderInfo.getStatus().equals(OrderStatusEnum.IN_PRODUCTION.getKey())) {
|
|
|
+ throw new ServiceException("订单已被处理");
|
|
|
+ }
|
|
|
+
|
|
|
+ Date date = new Date();
|
|
|
+ orderService.update(q -> q
|
|
|
+ .eq(BaseIdPo::getId, id)
|
|
|
+ .set(OrderInfo::getStatus, OrderStatusEnum.COMPLETION_PRODUCTION.getKey())
|
|
|
+ .set(OrderInfo::getShippingTime, date)
|
|
|
+ .set(BasePo::getUpdateUser, SecurityUtils.getUserId())
|
|
|
+ .set(BasePo::getUpdateTime, date));
|
|
|
+
|
|
|
+ // 订单生产完成时,一键完成生产任务
|
|
|
+ productionWorkOrderService.update(q -> q
|
|
|
+ .eq(ProductionWorkOrder::getOrderId, id)
|
|
|
+ .notIn(ProductionWorkOrder::getStatus, WorkOrderStatusEnum.PRODUCTION_ANOMALY.getKey(), WorkOrderStatusEnum.RESCHEDULE.getKey())
|
|
|
+ .set(ProductionWorkOrder::getStatus, WorkOrderStatusEnum.PRODUCTION_COMPLETION.getKey())
|
|
|
+ .set(ProductionWorkOrder::getCompleteTime, date)
|
|
|
+ .set(BasePo::getUpdateTime, date)
|
|
|
+ .set(BasePo::getUpdateUser, SecurityUtils.getUserId()));
|
|
|
+
|
|
|
+ // 生成对账单
|
|
|
+ StatementOfAccountDto statement = new StatementOfAccountDto();
|
|
|
+ statement.setDepartmentId(orderInfo.getDepartmentId());
|
|
|
+ statement.setOrderIdList(Collections.singletonList(orderInfo.getId()));
|
|
|
+ statementOfAccountService.add(statement);
|
|
|
+
|
|
|
+ // 生产入库
|
|
|
+ inventoryFinishedService.productionWarehousing(Collections.singletonList(id));
|
|
|
+
|
|
|
+ // 库存销售出库
|
|
|
+ inventoryFinishedService.saleOutOfWarehouse(Collections.singletonList(id));
|
|
|
+ }
|
|
|
+
|
|
|
private List<ProductionOrderDetailVo.SkuSpec> getSkuSpecList(Long orderId) {
|
|
|
|
|
|
// 获取订单sku规格
|