package com.auth.service.base.service.impl;

import com.auth.common.model.common.result.PageResult;
import com.auth.model.base.dto.OperationLogDto;
import com.auth.model.base.vo.OperationLogVo;
import com.auth.dao.base.entity.OperationLogEntity;
import com.auth.dao.base.mapper.v1.OperationLogMapper;
import com.auth.service.base.service.OperationLogService;
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 java.util.List;

/**
 * <p>
 * 系统操作日志 服务实现类
 * </p>
 *
 * @author Bunny
 * @since 2025-07-17 23:06:38
 */
@Service
@Transactional
public class OperationLogServiceImpl extends ServiceImpl<OperationLogMapper, OperationLogEntity> implements OperationLogService {

    /**
     * 系统操作日志 服务实现类
     *
     * @param pageParams 系统操作日志分页查询page对象
     * @param dto        系统操作日志分页查询对象
     * @return 查询分页系统操作日志返回对象
     */
    @Override
    public PageResult<OperationLogVo> getOperationLogPage(Page<OperationLogEntity> pageParams, OperationLogDto dto) {
        IPage<OperationLogVo> page = baseMapper.selectListByPage(pageParams, dto);

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

    /**
     * 根据id查询系统操作日志详情
     *
     * @param id 主键
     * @return 系统操作日志详情 OperationLogVo}
     */
    public OperationLogVo getOperationLogById(Long id) {
        OperationLogEntity operationLogEntity = getById(id);

        OperationLogVo operationLogVo = new OperationLogVo();
        BeanUtils.copyProperties(operationLogEntity, operationLogVo);

        return operationLogVo;
    }

    /**
     * 添加系统操作日志
     *
     * @param dto 系统操作日志添加
     */
    @Override
    public void addOperationLog(OperationLogDto dto) {
        OperationLogEntity operationLog = new OperationLogEntity();
        BeanUtils.copyProperties(dto, operationLog);

        save(operationLog);
    }

    /**
     * 更新系统操作日志
     *
     * @param dto 系统操作日志更新
     */
    @Override
    public void updateOperationLog(OperationLogDto dto) {
        OperationLogEntity operationLog = new OperationLogEntity();
        BeanUtils.copyProperties(dto, operationLog);

        updateById(operationLog);
    }

    /**
     * 删除|批量删除系统操作日志
     *
     * @param ids 删除id列表
     */
    @Override
    public void deleteOperationLog(List<Long> ids) {
        removeByIds(ids);
    }
}