package com.sw.common.accessory.scheduled;

import com.alibaba.fastjson.JSON;
import com.sw.common.accessory.server.dto.ProductionScheduleDto;
import com.sw.common.accessory.server.entity.AccessoryProductionOrder;
import com.sw.common.accessory.server.service.AccessoryProductionOrderService;
import com.xxl.job.core.handler.annotation.XxlJob;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

import java.util.List;

@Slf4j
@Component("AccessoryAutoScheduling")
public class AccessoryAutoScheduling {
    @Autowired
    private AccessoryProductionOrderService accessoryProductionOrderService;
    @XxlJob("automaticProductionOrderToSAP")
    public void automaticProductionOrderToSAP(){
        List<AccessoryProductionOrder> allProductionOrderNo = accessoryProductionOrderService.findAllProductionOrderNo();
        log.info("【石墨件工单维度自动上报参数】" + JSON.toJSONString(allProductionOrderNo) + " * * * * * * * * * * *");
        if(!CollectionUtils.isEmpty(allProductionOrderNo)){
            allProductionOrderNo.forEach(entity->{
                ProductionScheduleDto productionScheduleDto = new ProductionScheduleDto();
                BeanUtils.copyProperties(entity,productionScheduleDto);
                accessoryProductionOrderService.productionOrderToSAPs(productionScheduleDto);
            });
        }
    }

    @XxlJob("automaticProductionMaterialToSAP")
    public void automaticProductionMaterialToSAP(){
        List<AccessoryProductionOrder> allMaterialOrderNo = accessoryProductionOrderService.findAllMaterialOrderNo();
        log.info("【石墨件物料维度自动上报参数】" + JSON.toJSONString(allMaterialOrderNo) + " * * * * * * * * * * *");
        if(!CollectionUtils.isEmpty(allMaterialOrderNo)){
            allMaterialOrderNo.forEach(entity->{
                ProductionScheduleDto productionScheduleDto = new ProductionScheduleDto();
                BeanUtils.copyProperties(entity,productionScheduleDto);
                accessoryProductionOrderService.productionMaterialToSAPs(productionScheduleDto);
            });
        }
    }
}
