package com.fuzamei.service.serviceImpl;

import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.fuzamei.entity.Token;
import com.fuzamei.entity.User;
import com.fuzamei.entity.UserDetail;
import com.fuzamei.mapperInterface.LoginMapper;
import com.fuzamei.service.LoginService;
import com.fuzamei.util.JSONUtil;
@Service
public class LoginServiceImpl implements LoginService{
	@Autowired
	private LoginMapper  loginMapper;
	
	@Override
	public User queryUser(String username, String password) {
		return loginMapper.queryUser(username,password);
	}

	@Override
	@Transactional(rollbackFor=Exception.class)
	public void updateToken(Integer userId, String token) {
		int num = loginMapper.updateToken(userId,token);
		if(num!=1){
			throw new RuntimeException("更改token失败");
		}
	}
	@Override
	@Transactional(rollbackFor=Exception.class)
	public void insertToken(Integer userId, String token) {
		int num = loginMapper.insertToken(userId,token);
		if(num!=1){
			throw new RuntimeException("插入token失败");
		}
	}

	@Override
	public UserDetail queryAdminExistence() {
		return loginMapper.queryAdminExistence();
	}

	@Override
	public void insertAdmin(UserDetail user) {
		loginMapper.insertAdmin(user);
		loginMapper.insertToken(1,user.getToken());
	}
	
	
	
	
}
