package com.mall.member.service.impl;

import com.mall.member.mapper.MemberLoginLogMapper;
import com.mall.member.service.MemberLoginLogService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.mall.member.service.MemberLoginLogService;
import com.mall.member.domain.dto.MemberLoginLogDto;
import com.mall.member.domain.entity.MemberLoginLog;
import com.mall.member.domain.vo.MemberLoginLogVo;
import com.mall.common.domain.vo.result.PageResult;
import com.mall.common.domain.vo.result.Result;
import com.mall.common.domain.vo.result.ResultCodeEnum;

import java.util.List;

/**
 * <p>
 * 会员登录记录 服务实现类
 * </p>
 *
 * @author Bunny
 * @since 2025-07-05 19:30:06
 */
@Service
@Transactional
public class MemberLoginLogServiceImpl extends ServiceImpl<MemberLoginLogMapper, MemberLoginLog> implements MemberLoginLogService {

    /**
     * * 会员登录记录 服务实现类
     *
     * @param pageParams 会员登录记录分页查询page对象
     * @param dto        会员登录记录分页查询对象
     * @return 查询分页会员登录记录返回对象
     */
    @Override
    public PageResult<MemberLoginLogVo> getMemberLoginLogPage(Page<MemberLoginLog> pageParams, MemberLoginLogDto dto) {
        IPage<MemberLoginLogVo> page = baseMapper.selectListByPage(pageParams, dto);

        return PageResult.<MemberLoginLogVo>builder()
                .list(page.getRecords())
                .pageNo(page.getCurrent())
                .pageSize(page.getSize())
                .total(page.getTotal())
                .build();
    }

    /**
     * 添加会员登录记录
     *
     * @param dto 会员登录记录添加
     */
    @Override
    public void addMemberLoginLog(MemberLoginLogDto dto) {
        MemberLoginLog memberLoginLog =new MemberLoginLog();
        BeanUtils.copyProperties(dto, memberLoginLog);
        save(memberLoginLog);
    }

    /**
     * 更新会员登录记录
     *
     * @param dto 会员登录记录更新
     */
    @Override
    public void updateMemberLoginLog(MemberLoginLogDto dto) {
        MemberLoginLog memberLoginLog =new MemberLoginLog();
        BeanUtils.copyProperties(dto, memberLoginLog);
        updateById(memberLoginLog);
    }

    /**
     * 删除|批量删除会员登录记录
     *
     * @param ids 删除id列表
     */
    @Override
    public void deleteMemberLoginLog(List<Long> ids) {
        removeByIds(ids);
    }
}