package com.storlead.sales.service.impl.sku;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.storlead.framework.common.constant.DSConstants;
import com.storlead.framework.common.result.Result;
import com.storlead.sales.pojo.entity.sku.SsdProduct;
import com.storlead.sales.pojo.entity.sku.SsdProductType;
import com.storlead.sales.pojo.vo.sku.SsdProductVO;
import com.storlead.sales.mapper.sku.SsdProductMapper;
import com.storlead.sales.mapper.sku.SsdProductTypeMapper;
import com.storlead.sales.service.sku.SsdProductService;
import com.storlead.sales.service.sku.SsdProductTypeService;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
@DS(DSConstants.DATASOURCE_MANAGEMENT)
public class SsdProductServiceImpl extends ServiceImpl<SsdProductMapper, SsdProduct> implements SsdProductService {

    @Override
    public Result queryProductList(SsdProductVO ssdProductVO) {

        if (ssdProductVO.getSsdProductTypeId() == null || ssdProductVO.getSsdProductTypeId() <= 0) {
            return Result.error("参数异常");
        }

        Page<SsdProductVO> page = new Page<>(ssdProductVO.getPageIndex(), ssdProductVO.getPageSize());
        ssdProductVO.setPageIndex((ssdProductVO.getPageIndex() -1 ) * ssdProductVO.getPageSize());
        page.setRecords(baseMapper.queryProductPageList(ssdProductVO));
        page.setTotal(baseMapper.queryProductTotal(ssdProductVO));

        return Result.result(page);
    }

    @Override
    public Integer getSubProductCount(Integer ssdProductTypeId) {
        return baseMapper.getSubProductCount(ssdProductTypeId);
    }

}
