package com.zanxiang.game.module.sdk.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zanxiang.game.module.mybatis.entity.UserLoginLog;
import com.zanxiang.game.module.mybatis.mapper.UserLoginLogMapper;
import com.zanxiang.game.module.sdk.pojo.param.UserData;
import com.zanxiang.game.module.sdk.service.IUserLoginLogService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;

/**
 * @author : lingfeng
 * @time : 2022-06-13
 * @description : 用户登录日志
 */
@Slf4j
@Service
public class UserLoginLogServiceImpl extends ServiceImpl<UserLoginLogMapper, UserLoginLog> implements IUserLoginLogService {

    @Override
    public Boolean createRoleLoginLog(UserData userData, String roleId, String roleName, Integer type) {
        //创建对象
        return super.save(UserLoginLog.builder()
                .userId(userData.getUserId())
                .gameId(userData.getGameId())
                .roleId(roleId)
                .roleName(roleName)
                .os(userData.getDeviceSystem())
                .ip(userData.getIp())
                .deviceType(userData.getDeviceType())
                .type(type)
                .createTime(LocalDateTime.now())
                .build());
    }

    @Override
    public Boolean createUserLoginLog(UserData userData, Integer type) {
        return super.save(UserLoginLog.builder()
                .userId(userData.getUserId())
                .gameId(userData.getGameId())
                .os(userData.getDeviceSystem())
                .ip(userData.getIp())
                .deviceType(userData.getDeviceType())
                .type(type)
                .createTime(LocalDateTime.now())
                .build());
    }
}
