package com.fjhx.mes.service;

import com.fjhx.mes.entity.production.dto.ProductionOrderDto;
import com.fjhx.mes.entity.production.po.ProductionOrder;
import com.fjhx.mes.service.production.ProduceOrderService;
import com.fjhx.sale.service.SaleService;
import com.ruoyi.common.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class SaleServiceImpl implements SaleService {

    @Autowired
    private ProduceOrderService produceOrderService;

    @Override
    public void directProd(Long contractId, Date deliveryPeriod, Long produceCompanyId) {
        //下发生产
        ProductionOrderDto produceOrderDto = new ProductionOrderDto();
        produceOrderDto.setContractId(contractId);
        produceOrderDto.setDeliveryPeriod(deliveryPeriod);
        produceOrderDto.setProduceCompanyId(produceCompanyId);
        produceOrderService.createOrder(produceOrderDto);

        //确认交期
        produceOrderDto.setConfirmStatus(1);
        produceOrderService.deliveryConfirm(produceOrderDto);
    }

    @Override
    public void updateProdOrderStatusByContractIds(List<Long> contractIds, Integer status) {
        produceOrderService.update(q -> q
                .in(ProductionOrder::getContractId, contractIds)
                .set(ProductionOrder::getProduceStatus, status)
                .set(ProductionOrder::getUpdateUser, SecurityUtils.getUserId())
                .set(ProductionOrder::getUpdateTime, new Date())
        );
    }

}
