package com.mortals.xhx.module.product.service.impl;

import com.mortals.xhx.module.product.model.ProductEntity;
import com.mortals.xhx.module.product.model.ProductVersionQuery;
import com.mortals.xhx.module.product.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.mortals.framework.service.impl.AbstractCRUDServiceImpl;
import com.mortals.framework.exception.AppException;
import com.mortals.framework.model.Context;
import com.mortals.xhx.module.product.dao.ProductVersionDao;
import com.mortals.xhx.module.product.model.ProductVersionEntity;
import com.mortals.xhx.module.product.service.ProductVersionService;
import org.springframework.util.ObjectUtils;

import java.util.Date;

/**
 * ProductVersionService
 * 产品客户端版本 service实现
 *
 * @author zxfei
 * @date 2022-08-22
 */
@Service("productVersionService")
public class ProductVersionServiceImpl extends AbstractCRUDServiceImpl<ProductVersionDao, ProductVersionEntity, Long> implements ProductVersionService {

    @Autowired
    private ProductService productService;


    @Override
    protected void saveBefore(ProductVersionEntity entity, Context context) throws AppException {
        if (!ObjectUtils.isEmpty(entity.getProductId())) {
            ProductEntity productEntity = productService.get(entity.getProductId(), context);
            if (!ObjectUtils.isEmpty(productEntity)) {
                entity.setProductName(productEntity.getProductName());
                entity.setProductCode(productEntity.getProductCode());
            }
        }
    }
}