package com.hzs.system.base.provider;

import cn.hutool.core.bean.BeanUtil;
import com.hzs.common.core.domain.R;
import com.hzs.common.domain.system.config.ext.BdBarCodeItemsExt;
import com.hzs.system.base.IBarCodeServiceApi;
import com.hzs.system.base.dto.BarCodeDTO;
import com.hzs.system.base.dto.BarCodeUseDTO;
import com.hzs.system.config.service.IBdBarCodeItemsService;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * @Description: 条码dubbo服务
 * @Author: jiang chao
 * @Time: 2022/11/2 11:59
 * @Classname: BarCodeServiceProvider
 * @PackageName: com.hzs.system.base.provider
 */
@DubboService
public class BarCodeServiceProvider implements IBarCodeServiceApi {

    @Autowired
    private IBdBarCodeItemsService iBdBarCodeItemsService;

    @Override
    public R<List<BarCodeDTO>> queryPrintBarCode(List<String> barCodeList, Integer pkCountry) {
        // 查询条码数据
        List<BdBarCodeItemsExt> barCodeItemsList = iBdBarCodeItemsService.queryPrintBarCode(barCodeList, pkCountry);
        // 返回数据
        List<BarCodeDTO> resultList = BeanUtil.copyToList(barCodeItemsList, BarCodeDTO.class);

        return R.ok(resultList);
    }

    @Override
    public R<String> useBarCode(List<BarCodeUseDTO> barCodeUseList, Integer pkCountry, Long userId) {
        try {
            if (iBdBarCodeItemsService.useBarCode(barCodeUseList, pkCountry, userId)) {
                return R.ok();
            }
            return R.fail();
        } catch (Exception e) {
            return R.fail(e.getMessage());
        }
    }

    @Override
    public R<String> clearBarCode(List<Integer> barCodeItemsIdList, Integer pkCountry, Long userId) {
        if (iBdBarCodeItemsService.clearBarCode(barCodeItemsIdList, pkCountry, userId)) {
            return R.ok();
        }
        return R.fail();
    }

}
