package com.fjhx.u.service.impl;

import cn.hutool.extra.servlet.ServletUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fjhx.entity.u.ULoginLog;
import com.fjhx.params.u.ULoginLogVo;
import com.fjhx.u.mapper.ULoginLogMapper;
import com.fjhx.u.service.ULoginLogService;
import com.fjhx.utils.wrapperUtil.IWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import java.util.Date;
import java.util.Map;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author ${author}
 * @since 2023-01-31
 */
@Service
public class ULoginLogServiceImpl extends ServiceImpl<ULoginLogMapper, ULoginLog> implements ULoginLogService {

    @Autowired
    private HttpServletRequest request;

    @Override
    public Page<ULoginLog> getPage(Map<String, Object> condition) {

        IWrapper<ULoginLog> wrapper = IWrapper.getWrapper(condition);

        return page(condition, wrapper);
    }

    @Override
    public void add(ULoginLogVo uLoginLogVo) {
        String clientIP = ServletUtil.getClientIP(request);
        uLoginLogVo.setLoginTime(new Date());
        uLoginLogVo.setLoginIp(clientIP);
        save(uLoginLogVo);
    }

    @Override
    public void edit(ULoginLogVo uLoginLogVo) {
        updateById(uLoginLogVo);
    }

    @Override
    public void delete(ULoginLogVo uLoginLogVo) {
        removeById(uLoginLogVo.getId());
    }

}
