package com.jy.log.dao;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jy.framework.model.base.BaseDao;
import com.jy.log.mapper.LogUserOperationMapper;
import com.jy.log.model.dto.LogUserOperationSelectDto;
import com.jy.log.model.entity.LogUserOperation;
import com.jy.log.model.table.LogUserOperationTable;
import com.jy.log.model.vo.LogUserOperationVo;
import com.jy.system.service.AuthService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

@Service
public class LogUserOperationDao extends BaseDao<LogUserOperationMapper, LogUserOperation> {

    @Resource
    private AuthService authService;

    /**
     * 用户操作日志分页
     */
    public Page<LogUserOperationVo> getPage(LogUserOperationSelectDto dto) {
        LogUserOperationTable luo = LogUserOperationTable.luo;

        return sql(LogUserOperationVo.class)
                .select(
                        luo.all
                )
                .from(luo)
                .where(
                        luo.moduleName.like(dto.getModuleName()),
                        luo.operatorId.eq(dto.getOperatorId()),
                        luo.operationType.eq(dto.getOperationType()),
                        luo.auditStatus.eq(dto.getAuditStatus()),
                        luo.businessId.eq(dto.getBusinessId())
                )
                .orderBy(
                        luo.id.desc()
                )
                .page(dto.getPage());
    }

    /**
     * 用户操作日志明细
     */
    public LogUserOperationVo getDetail(Long id) {
        LogUserOperationTable luo = LogUserOperationTable.luo;

        return sql(LogUserOperationVo.class)
                .select(
                        luo.all
                )
                .from(luo)
                .where(
                        luo.id.eq(id)
                )
                .one();
    }

}
