package com.cool.store.dao;

import com.cool.store.entity.OldShopDO;
import com.cool.store.mapper.OldShopMapper;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Repository;
import tk.mybatis.mapper.entity.Example;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author: WangShuo
 * @Date: 2025/04/12/18:36
 * @Version 1.0
 * @注释:
 */
@Repository
public class OldShopDAO {
    @Resource
    private OldShopMapper oldShopMapper;

    public List<OldShopDO> getByMobile(String mobile) {
        if (StringUtils.isBlank(mobile)){
            return null;
        }
        Example example = new Example(OldShopDO.class);
        example.createCriteria().andEqualTo("mobile", mobile);
        return oldShopMapper.selectByExample(example);
    }


    public OldShopDO getByCode(String code) {
        if (StringUtils.isBlank(code)){
            return null;
        }
        Example example = new Example(OldShopDO.class);
        example.createCriteria().andEqualTo("shopCode", code);
        example.setOrderByClause("id ASC LIMIT 1");
        List<OldShopDO> list = oldShopMapper.selectByExample(example);
        return list.isEmpty() ? null : list.get(0);
    }

    public void insertSelective(OldShopDO oldShopDO) {
        oldShopMapper.insertSelective(oldShopDO);
    }
}
