package com.ruoyi.wx.web.service.impl;

import com.ruoyi.common.utils.bean.BeanUtils;
import com.ruoyi.framework.recovery.domain.RecBrand;
import com.ruoyi.framework.recovery.domain.RecCommodity;
import com.ruoyi.framework.recovery.mapper.RecBrandMapper;
import com.ruoyi.framework.recovery.mapper.RecCommodityMapper;
import com.ruoyi.wx.web.domain.vo.GoodsInfoVo;
import com.ruoyi.wx.web.service.IWxQuotationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;


@Service
public class WxQuotationServiceImpl implements IWxQuotationService {
    @Autowired
    private RecBrandMapper recBrandMapper;

    @Autowired
    private RecCommodityMapper commodityMapper;

    @Override
    public List<RecBrand> getBrands() {
        RecBrand recBrand = new RecBrand();
        recBrand.setParentId(0L);
        List<RecBrand> brands = recBrandMapper.selectRecBrandList(recBrand);
        return brands;
    }

    @Override
    public List<RecBrand> getBrandSeries(Long id) {
        RecBrand recBrand = new RecBrand();
        recBrand.setParentId(id);
        List<RecBrand> seriesList =  recBrandMapper.selectRecBrandList(recBrand);
        return seriesList;
    }

    @Override
    public List<GoodsInfoVo> getGoodsInfo(Long id) {
        RecCommodity commodity = new RecCommodity();
        commodity.setBrandId(id);
        List<RecCommodity> commodityList = commodityMapper.selectRecCommodityList(commodity);
        List<GoodsInfoVo> goodsInfoVos = new ArrayList<>();
        commodityList.forEach(com -> {
            GoodsInfoVo goodsInfoVo = new GoodsInfoVo();
            BeanUtils.copyBeanProp(goodsInfoVo, com);
            goodsInfoVo.setArbitrage(goodsInfoVo.getMarket().subtract(goodsInfoVo.getSale()));
            goodsInfoVos.add(goodsInfoVo);
        });
        return goodsInfoVos;
    }
}
