package com.czg.service.market.service.impl;

import com.czg.market.vo.SmsShopMoneyVO;
import com.czg.sa.StpKit;
import com.czg.utils.PageUtil;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.mybatisflex.core.paginate.Page;
import com.mybatisflex.core.query.QueryWrapper;
import com.mybatisflex.spring.service.impl.ServiceImpl;
import com.czg.market.entity.SmsShopMoney;
import com.czg.market.service.SmsShopMoneyService;
import com.czg.service.market.mapper.SmsShopMoneyMapper;
import org.springframework.stereotype.Service;

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

/**
 * 店铺短信余额 服务层实现。
 *
 * @author ww
 * @since 2025-10-16
 */
@Service
public class SmsShopMoneyServiceImpl extends ServiceImpl<SmsShopMoneyMapper, SmsShopMoney> implements SmsShopMoneyService {

    @Override
    public SmsShopMoney getShopMoney(Long shopId) {
        SmsShopMoney shopMoney = getOne((
                new QueryWrapper().eq(SmsShopMoney::getShopId,shopId)));
        if (shopMoney == null) {
            shopMoney = new SmsShopMoney();
            shopMoney.setShopId(shopId);
            shopMoney.setMoney(BigDecimal.ZERO);
            save(shopMoney);
        }
        return shopMoney;
    }

    @Override
    public Page<SmsShopMoneyVO> getShopMoneyPage(Integer page, Integer size, String name) {
        PageHelper.startPage(page, size);
        List<SmsShopMoneyVO> list = mapper.selectWithShopInfo(name);
        return PageUtil.convert(new PageInfo<>(list));
    }
}
