package cn.iocoder.yudao.module.product.api.harvestbatch;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.module.product.api.harvestbatch.dto.HarvestBatchDTO;
import cn.iocoder.yudao.module.product.convert.harvestbatch.HarvestBatchConvert;
import cn.iocoder.yudao.module.product.dal.dataobject.harvestbatch.HarvestBatchDO;
import cn.iocoder.yudao.module.product.dal.mysql.harvestbatch.HarvestBatchMapper;
import cn.iocoder.yudao.module.product.service.harvestbatch.HarvestBatchService;
import cn.iocoder.yudao.module.system.enums.ApiConstants;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController // 提供 RESTful API 接口，给 Feign 调用
@DubboService(version = ApiConstants.VERSION) // 提供 Dubbo RPC 接口，给 Dubbo Consumer 调用
@Validated
public class harvesBatchApiImpl implements HarvestBatchApi {

    @Resource
    private HarvestBatchMapper harvestBatchMapper;

    @Resource
    private HarvestBatchService harvestBatchService;

    @Override
    public CommonResult<List<HarvestBatchDTO>> getHarvestInfoListByInputId(List<String> ids) {
        return CommonResult.success(HarvestBatchConvert.INSTANCE.convertListDTO(harvestBatchMapper.selectList(HarvestBatchDO::getHarvestBatchId, ids)));
    }

    @Override
    public CommonResult<List<HarvestBatchDTO>> getHarvestInfoListByGoodsId(String goodsId) {
        return CommonResult.success(HarvestBatchConvert.INSTANCE.convertListDTO(harvestBatchMapper.selectList(HarvestBatchDO::getGoodsId, goodsId)));
    }


    @Override
    public CommonResult<HarvestBatchDTO> getHarvestBatchById(String harvestBatchId) {
        return CommonResult.success(HarvestBatchConvert.INSTANCE.convertDTO(harvestBatchService.getHarvestBatchById(harvestBatchId)));
    }

}
