package com.hotent.uc.controller;

import com.hotent.base.service.LoginLogService;
import com.hotent.uc.api.model.IUser;
import com.hotent.uc.util.ContextUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;

import javax.annotation.Resource;

import org.springframework.web.bind.annotation.*;

import com.hotent.base.controller.BaseController;
import com.hotent.base.model.CommonResult;
import com.hotent.base.query.PageList;
import com.hotent.base.query.QueryFilter;
import com.hotent.base.util.StringUtil;
import com.hotent.uc.manager.LoginLogManager;
import com.hotent.uc.model.LoginLog;

import java.util.List;

/**
 * 
 * <pre> 
 * 描述：用户登录日志表 控制器类
 * 构建组：x7
 * 作者:zhangxw
 * 邮箱:zhangxw@jee-soft.cn
 * 日期:2020-06-19 18:42:21
 * 版权：广州宏天软件股份有限公司
 * </pre>
 */
@RestController
@RequestMapping(value="/uc/loginLog/v1")
@Api(tags="loginLogController")
public class LoginLogController extends BaseController<LoginLogManager,LoginLog>{
	@Resource
	LoginLogManager loginLogManager;
	@Resource
	LoginLogService loginLogService;
	
	/**
	 * 用户登录日志表列表(分页条件查询)数据
	 * @param request
	 * @return
	 * @throws Exception 
	 * PageJson
	 * @exception 
	 */
	@PostMapping("/listJson")
	@ApiOperation(value="用户登录日志表数据列表", httpMethod = "POST", notes = "获取用户登录日志表列表")
	public PageList<LoginLog> list(@ApiParam(name="queryFilter",value="查询对象")@RequestBody QueryFilter queryFilter) throws Exception{
		return loginLogManager.query(queryFilter);
	}
	
	/**
	 * 用户登录日志表明细页面
	 * @param id
	 * @return
	 * @throws Exception 
	 * ModelAndView
	 */
	@GetMapping(value="/getJson")
	@ApiOperation(value="用户登录日志表数据详情",httpMethod = "GET",notes = "用户登录日志表数据详情")
	public LoginLog get(@ApiParam(name="id",value="业务对象主键", required = true)@RequestParam String id) throws Exception{
		return loginLogManager.get(id);
	}
	
    /**
	 * 新增用户登录日志表
	 * @param loginLog
	 * @throws Exception 
	 * @return
	 * @exception 
	 */
	@PostMapping(value="save")
	@ApiOperation(value = "新增,更新用户登录日志表数据", httpMethod = "POST", notes = "新增,更新用户登录日志表数据")
	public CommonResult<String> save(@ApiParam(name="loginLog",value="用户登录日志表业务对象", required = true)@RequestBody LoginLog loginLog) throws Exception{
		String msg = "添加用户登录日志表成功";
		if(StringUtil.isEmpty(loginLog.getId())){
			loginLogManager.create(loginLog);
		}else{
			loginLogManager.update(loginLog);
			 msg = "更新用户登录日志表成功";
		}
		return new CommonResult<String>(msg);
	}
	
	/**
	 * 批量删除用户登录日志表记录
	 * @param ids
	 * @throws Exception 
	 * @return
	 * @exception 
	 */
	@DeleteMapping(value="/remove")
	@ApiOperation(value = "批量删除用户登录日志表记录", httpMethod = "DELETE", notes = "批量删除用户登录日志表记录")
	public CommonResult<String> removes(@ApiParam(name="ids",value="业务主键数组,多个业务主键之间用逗号分隔", required = true)@RequestParam String...ids) throws Exception{
		loginLogManager.removeByIds(ids);
		return new CommonResult<String>(true, "批量删除成功");
	}

	/**
	 * 用户登陆日志记录
	 * @param account
	 * @param loginType
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value="loginLog",method= RequestMethod.GET, produces = {
			"application/json; charset=utf-8" })
	@ApiOperation(value = "用户登陆日志记录", httpMethod = "GET", notes = "用户登陆日志记录")
	public CommonResult<String> loginLog(@ApiParam(name="account",value="登陆用户账号", required = true)@RequestParam String account,
										 @ApiParam(name="loginType",value="登陆类型", required = true)@RequestParam String loginType) throws Exception{
		loginLogService.log(account,loginType);
		return CommonResult.ok();
	}

	/**
	 * 获取当前用户登陆 日志记录
	 */
	@RequestMapping(value="queryLoginLogByUserId",method= RequestMethod.GET, produces = {"application/json; charset=utf-8" })
	@ApiOperation(value = "获取当前用户登陆 日志记录", httpMethod = "GET", notes = "获取当前用户登陆 日志记录")
	public CommonResult<LoginLog> queryLoginLogByUserId() throws Exception{
		IUser user = ContextUtil.getCurrentUser(); //获取当前用户
		LoginLog log = loginLogManager.get(user.getUserId());
		return new CommonResult<LoginLog>(true, "查询成功", log);
	}


	/**
	 * 用户登录日志表列表(分页条件查询)数据
	 * @param request
	 * @return
	 * @throws Exception
	 * PageJson
	 * @exception
	 */
	@RequestMapping(value="getLoginLogList",method= RequestMethod.GET, produces = {"application/json; charset=utf-8" })
	@ApiOperation(value="用户登录日志表数据列表", httpMethod = "GET", notes = "获取用户登录日志表列表")
	public CommonResult<?> getLoginLogList() throws Exception{
		return new CommonResult<>(true, "查询成功", loginLogManager.getLoginLogList());
	}
}
