package com.sw.mes.crucible.service.impl;

import com.sw.mes.core.api.system.StoreFeignClients;
import com.sw.mes.core.base.BaseServiceImpl;
import com.sw.mes.core.dto.store.WarehouseInventoryBo;
import com.sw.mes.core.response.Result;
import com.sw.mes.crucible.dao.CrucibleDao;
import com.sw.mes.crucible.dto.CrucibleDto;
import com.sw.mes.crucible.entity.Crucible;
import com.sw.mes.crucible.service.CrucibleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;

/**
 * @author lf
 * @description
 * @date 2024/1/6 14:40
 */
@Service
@Transactional
public class CrucibleServiceImpl extends BaseServiceImpl<Crucible> implements CrucibleService {

    CrucibleDao dao;

    @Autowired
    public void setDao(CrucibleDao dao) {
        super.setBaseDao(dao);
        this.dao = dao;
    }

    @Autowired
    private StoreFeignClients storeFeignClients;

    @Override
    public CrucibleDto findCodeByBatchNumber(String batchNumber) {
        if (StringUtils.isEmpty(batchNumber)) {
            return null;
        }
        Result<WarehouseInventoryBo> warehouseInventoryBoResult = storeFeignClients.findByBatchNo(batchNumber);
        if (warehouseInventoryBoResult.getCode() != 200 ||
                null == warehouseInventoryBoResult.getData().getMaterialModelCode() ||
                null == warehouseInventoryBoResult.getData().getMaterialModelName()) {
            return null;
        }
        CrucibleDto dto = new CrucibleDto();
        dto.setCode(warehouseInventoryBoResult.getData().getMaterialModelCode());
        dto.setCodeName(warehouseInventoryBoResult.getData().getMaterialModelName());
        return dto;
    }

    @Override
    public Crucible findByBatchNumber(String batchNumber) {
        return dao.findByBatchNumber(batchNumber);
    }
}
