package com.hzs.ground.product.provider;/**
 * @Description:
 * @Author: yuhui
 * @Time: 2023/11/23 18:00
 * @Classname: IProductBasServiceProvider
 * @PackageName: com.hzs.scm.product.provider
 */

import cn.hutool.core.bean.BeanUtil;
import com.hzs.common.core.constant.CacheConstants;
import com.hzs.common.core.domain.R;
import com.hzs.common.core.service.RedisService;
import com.hzs.common.domain.sale.product.BdProductBas;
import com.hzs.ground.product.service.IBdProductBasService;
import com.hzs.scm.product.IProductBasServiceApi;
import com.hzs.scm.product.dto.ProductBasDTO;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

/**
 *@BelongsProject: hzs_cloud
 *@BelongsPackage: com.hzs.scm.product.provider
 *@Author: yh
 *@CreateTime: 2023-11-23  18:00
 *@Description: TODO
 *@Version: 1.0
 */
@Slf4j
@DubboService
public class IProductBasServiceProvider implements IProductBasServiceApi {

    @Autowired
    private IBdProductBasService productBasService;
    @Autowired
    private RedisService redisService;

    /**
     * 批量新增
     * @param productBas
     * @return
     */
    public R<BdProductBas> save(BdProductBas productBas){
        boolean isSave = productBasService.save(productBas);
        if (isSave){
            return R.ok(productBas);
        }else {
            return R.fail();
        }
    }
    /**
     * 根据id 修改
     */
    @Override
    public R<Boolean> updateById(BdProductBas productBas) {
        productBasService.updateById(productBas);
        redisService.deleteObject(CacheConstants.BD_PRODUCT_BAS + productBas.getPkId());
        redisService.deleteObject(CacheConstants.BD_PRODUCT_BAS + productBas.getProductCode());
        return R.ok();
    }
    /**
     * 根据id 查询
     * @return
     */
    @Override
    public R<ProductBasDTO> getProductBasById(Integer pkId) {
        BdProductBas productBas =  productBasService.getProductBasById(pkId);
        return R.ok(BeanUtil.copyProperties(productBas, ProductBasDTO.class));
    }

    /**
     * 根据产品编号 查询
     * @return
     */
    @Override
    public R<ProductBasDTO> getProductBasByProductCode(String productCode) {
        BdProductBas productBas =  productBasService.getProductBasByProductCode(productCode);
        return R.ok(BeanUtil.copyProperties(productBas, ProductBasDTO.class));
    }


}
