package com.caimei.www.service.page.impl;

import com.caimei.www.mapper.ProductDao;
import com.caimei.www.pojo.page.ProductDetail;
import com.caimei.www.service.page.ProductService;
import io.netty.util.internal.StringUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;


/**
 * Description
 *
 * @author : Charles
 * @date : 2020/7/8
 */
@Slf4j
@Service
public class ProductServiceImpl implements ProductService {
    @Value("${caimei.wwwDomain}")
    private String domain;
    @Resource
    private ProductDao productDao;

    /**
     * 根据商品Id获取详情
     *
     * @param productId
     * @return
     */
    @Override
    public ProductDetail getProductDetailById(Integer productId) {
        ProductDetail product = productDao.getProductDetailById(productId);
        if(!StringUtil.isNullOrEmpty(product.getTags())){
            product.setTagList(product.getTags().split(","));
        }
        // 价格等级
        if (product.getPrice() > 50 * 5000) {
            product.setPriceGrade(5);
        } else if (product.getPrice() > 25 * 5000) {
            product.setPriceGrade(4);
        } else if (product.getPrice() > 10 * 5000) {
            product.setPriceGrade(3);
        } else if (product.getPrice() > 2.5 * 5000) {
            product.setPriceGrade(2);
        } else {
            product.setPriceGrade(1);
        }
        return product;
    }

}
