package com.sw.mes.yb.seed.api.service.supplier.impl;

import com.sw.mes.core.api.system.StoreFeignClients;
import com.sw.mes.core.dto.WMSToSeedDto;
import com.sw.mes.core.dto.store.WarehouseOutputBillBo;
import com.sw.mes.core.response.Result;
import com.sw.mes.core.response.ResultGenerator;
import com.sw.mes.yb.seed.api.service.supplier.SeedSupplierService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class SeedSupplierServiceImpl implements SeedSupplierService {
    @Autowired
    private StoreFeignClients storeFeignClients;

    @Override
    public Result wmsReceive(WMSToSeedDto wmsToSeedDto) {
        if ("A".equals(wmsToSeedDto.getZshjg())) {
            Result<WarehouseOutputBillBo> result = storeFeignClients.findWarehouseOutputBillByCode(wmsToSeedDto.getZinbd());
            if(result.getCode().equals(200) && null != result.getData()){
                WarehouseOutputBillBo data = result.getData();
                Result<String> deduction = storeFeignClients.deduction(data);
                if (deduction.getCode().equals(200)) {
                    return ResultGenerator.success(deduction.getData());
                }
            }
        }
        if ("R".equals(wmsToSeedDto.getZshjg())) {
            Result<WarehouseOutputBillBo> result = storeFeignClients.findWarehouseOutputBillByCode(wmsToSeedDto.getZinbd());
            //WMS拒收 MES线边仓也需要把这一批库存出掉,状态保持一致即可
            if(result.getCode().equals(200) && null != result.getData()){
                WarehouseOutputBillBo data = result.getData();
                storeFeignClients.rejectApply(data);
            }

        }
        return ResultGenerator.success();
    }
}
