package com.sqx.modules.shop.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sqx.common.utils.PageUtils;
import com.sqx.common.utils.Result;
import com.sqx.modules.shop.dao.ShopTypeDao;
import com.sqx.modules.shop.entity.ShopType;
import com.sqx.modules.shop.service.ShopTypeService;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ShopTypeServiceImpl extends ServiceImpl<ShopTypeDao, ShopType> implements ShopTypeService {
    @Override
    public Result insertShopType(ShopType shopType) {
        baseMapper.insert(shopType);
        return Result.success();
    }

    @Override
    public Result updateShopType(ShopType shopType) {
        baseMapper.updateById(shopType);
        return Result.success();
    }

    @Override
    public Result deleteShopType(Long shopTypeId) {
        baseMapper.deleteById(shopTypeId);
        return Result.success();
    }

    @Override
    public Result selectShopTypeList(Integer page, Integer limit) {
        if(page!=null&&limit!=null){
            Page<ShopType> pages = new Page<>(page, limit);
            PageUtils pageUtils = new PageUtils(baseMapper.selectPage(pages, null));
            return Result.success().put("data", pageUtils);
        }else {
            List<ShopType> shopTypes = baseMapper.selectList(null);
            return Result.success().put("data", shopTypes);
        }
    }

}
