package com.jeesharp.business.modules.mall.service.impl;

import com.jeesharp.business.modules.mall.entity.MallSkuLevelPrice;
import com.jeesharp.business.modules.mall.mapper.MallSkuLevelPriceMapper;
import com.jeesharp.business.modules.mall.service.MallSkuLevelPriceService;
import com.jeesharp.business.modules.mall.vo.MallSkuLevelPriceQueryVO;
import com.jeesharp.framework.mybatis.core.service.CrudService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.math.BigDecimal;
import java.util.Arrays;
import java.util.List;

/**
 * 会员价 Service 实现类
 */
@Service
@Transactional(readOnly = true)
public class MallSkuLevelPriceServiceImpl extends CrudService<MallSkuLevelPriceMapper, MallSkuLevelPrice, MallSkuLevelPriceQueryVO> implements MallSkuLevelPriceService {

    private static final String IDS_SEPARATOR = ",";

    @Override
    @Transactional(readOnly = false)
    public void createLevelPrice(MallSkuLevelPrice entity) {
        save(entity);
    }

    @Override
    @Transactional(readOnly = false)
    public void updateLevelPrice(MallSkuLevelPrice entity) {
        update(entity);
    }

    @Override
    public BigDecimal getMemberPrice(String skuId, String memberLevelCode) {
        MallSkuLevelPriceQueryVO query = new MallSkuLevelPriceQueryVO();
        query.setSkuId(skuId);
        query.setMemberLevelCode(memberLevelCode);
        List<MallSkuLevelPrice> prices = findList(query);
        return prices.isEmpty() ? null : prices.get(0).getPrice();
    }

    @Override
    public List<MallSkuLevelPrice> getMemberPricesBySku(String skuId) {
        MallSkuLevelPriceQueryVO query = new MallSkuLevelPriceQueryVO();
        query.setSkuId(skuId);
        return findList(query);
    }
}
