package com.goafanti.businessCard.service.impl;

import com.goafanti.businessCard.service.AdminBusinessCardService;
import com.goafanti.common.dao.AdminBusinessCardMapper;
import com.goafanti.common.model.AdminBusinessCard;
import com.goafanti.core.mybatis.BaseMybatisDao;
import com.goafanti.core.mybatis.page.Pagination;
import com.goafanti.core.shiro.token.TokenManager;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * 用户名片表(AdminBusinessCard)表服务实现类
 *
 * @author makejava
 * @since 2025-06-27 15:10:05
 */
@Service("adminBusinessCardService")
public class AdminBusinessCardServiceImpl extends BaseMybatisDao<AdminBusinessCardMapper> implements AdminBusinessCardService {
    @Resource
    private AdminBusinessCardMapper adminBusinessCardMapper;


    @Override
    public Pagination<AdminBusinessCard> list(AdminBusinessCard adminBusinessCard, Integer pageNo, Integer pageSize) {
        Map<String, Object> params = new HashMap<>();
        params.put("in", adminBusinessCard);
        return (Pagination<AdminBusinessCard>) findPage("findAdminBusinessCardList",
                "findAdminBusinessCardCount", params, pageNo, pageSize);
    }

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public AdminBusinessCard queryById(Integer id) {
        return this.adminBusinessCardMapper.selectById(id);
    }


    /**
     * 新增数据
     *
     * @param adminBusinessCard 实例对象
     * @return 实例对象
     */
    @Override
    public AdminBusinessCard insert(AdminBusinessCard adminBusinessCard) {
        adminBusinessCard.setAid(TokenManager.getAdminId());
        adminBusinessCard.setCreateTime(new Date());
        this.adminBusinessCardMapper.insert(adminBusinessCard);
        return adminBusinessCard;
    }

    /**
     * 修改数据
     *
     * @param adminBusinessCard 实例对象
     * @return 实例对象
     */
    @Override
    public AdminBusinessCard update(AdminBusinessCard adminBusinessCard) {
        this.adminBusinessCardMapper.update(adminBusinessCard);
        return this.queryById(adminBusinessCard.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer id) {
        return this.adminBusinessCardMapper.deleteById(id) > 0;
    }
}
