package com.zhiqiyun.open.core.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zhiqiyun.open.core.mapper.UserLoginLogMapper;
import com.zhiqiyun.open.core.models.user.UserLoginLog;
import com.zhiqiyun.open.core.service.Ip2RegionService;
import com.zhiqiyun.open.core.service.UserLoginLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class UserLoginLogServiceImpl extends ServiceImpl<UserLoginLogMapper, UserLoginLog> implements UserLoginLogService {

    @Autowired
    private Ip2RegionService ip2RegionService;


    @Override
    public boolean save(UserLoginLog entity) {
        try {
            entity.setLoginLocal(this.ip2RegionService.getRegion(entity.getLoginIp()));
        } finally {
            this.baseMapper.insert(entity);
        }
        return true;
    }
}
