package jj.tech.paolu.biz.webadmin.service;

import static org.mybatis.dynamic.sql.SqlBuilder.isEqualTo;

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

import jj.tech.paolu.repository.mybatis.dao.Idc9998AdminInfoMapper;
import jj.tech.paolu.repository.mybatis.dao.support.Idc9998AdminInfoDynamicSqlSupport;
import jj.tech.paolu.repository.mybatis.entity.Idc9998AdminInfo;

@Service
public class Idc9998Sevice {
	@Autowired Idc9998AdminInfoMapper idc9998AdminInfoMapper;
	
	
	public Idc9998AdminInfo getByUserName(String userName){
		return
		idc9998AdminInfoMapper.selectOne(s->
			s.where()
			.and(Idc9998AdminInfoDynamicSqlSupport.user_name, isEqualTo(userName))
			.limit(1)
		).orElse(null);
	}
	
	
	public String getLoginInfo(String userName){
		Idc9998AdminInfo bean = 
		idc9998AdminInfoMapper.selectOne(s->
			s.where()
			.and(Idc9998AdminInfoDynamicSqlSupport.user_name, isEqualTo(userName))
			.limit(1)
		).orElse(null);
		if(bean!=null) {
			return bean.getLogin_info();
		}
		return null;
	}
	
	
	public void updateLoginInfo(String userName, String loginInfo, Integer isOnline){
		idc9998AdminInfoMapper.update(up->
			up
			.set(Idc9998AdminInfoDynamicSqlSupport.login_info).equalTo(loginInfo)
			.set(Idc9998AdminInfoDynamicSqlSupport.is_online).equalTo(isOnline)
			.where(Idc9998AdminInfoDynamicSqlSupport.user_name, isEqualTo(userName))
			.limit(1)
		);
	}
	
	public void updateIsOnline(String userName, Integer isOnline){
		idc9998AdminInfoMapper.update(up->
			up
			.set(Idc9998AdminInfoDynamicSqlSupport.is_online).equalTo(isOnline)
			.where(Idc9998AdminInfoDynamicSqlSupport.user_name, isEqualTo(userName))
			.limit(1)
		);
	}
	
//	public void updateIsOnline(String userName, Integer isOnline){
//		idc9998AdminInfoMapper.update(up->
//			up.set(Idc9998AdminInfoDynamicSqlSupport.is_online).equalTo(isOnline)
//			.where(Idc9998AdminInfoDynamicSqlSupport.user_name, isEqualTo(userName))
//			.limit(1)
//		);
//	}

}
