package com.hxzk.controller;
|
|
import com.github.pagehelper.PageInfo;
|
import com.hxzk.pojo.TbKaoqing;
|
import com.hxzk.pojo.TbLoginLog;
|
import com.hxzk.service.KaoQinService;
|
import com.hxzk.service.LoginLogService;
|
import com.hxzk.util.result;
|
import com.hxzk.util.resultutil;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RestController;
|
|
import javax.servlet.http.HttpServletRequest;
|
import java.text.SimpleDateFormat;
|
import java.time.LocalDate;
|
import java.time.LocalDateTime;
|
import java.time.format.DateTimeFormatter;
|
import java.util.Date;
|
import java.util.List;
|
|
@RestController
|
@RequestMapping("/")
|
public class LoginLogController {
|
@Autowired
|
LoginLogService loginLogService;
|
@GetMapping("findTbLoginLog")
|
result<List<TbLoginLog>> findTbLoginLog(Integer page, Integer limit){
|
PageInfo<TbLoginLog> cz= loginLogService.findAll(page, limit);
|
return resultutil.returnSuccess(cz.getTotal(), cz.getList());
|
}
|
|
@GetMapping("addLoginLog")
|
public void addLoginLog(TbLoginLog loginLog, HttpServletRequest request){
|
String ipAddress = request.getHeader("X-Forwarded-For");
|
if (ipAddress == null) {
|
ipAddress = request.getHeader("Proxy-Client-IP");
|
}
|
if (ipAddress == null) {
|
ipAddress = request.getHeader("WL-Proxy-Client-IP");
|
}
|
if (ipAddress == null) {
|
ipAddress = request.getHeader("HTTP_CLIENT_IP");
|
}
|
if (ipAddress == null) {
|
ipAddress = request.getHeader("HTTP_X_FORWARDED_FOR");
|
}
|
if (ipAddress == null) {
|
ipAddress = request.getRemoteAddr();
|
}
|
loginLog.setIp(ipAddress);
|
LocalDateTime currentTime = LocalDateTime.now();
|
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
String formattedTime = currentTime.format(formatter);
|
loginLog.setAddtime(formattedTime);
|
loginLogService.addLoginLog(loginLog);
|
}
|
|
|
//查询今日数据
|
@GetMapping("findJinRiLog")
|
public Integer findJinRiLog(){
|
return loginLogService.findJinRiLog();
|
}
|
|
public String gettime(){
|
Date now = new Date();
|
// 创建日期格式化对象,设置格式为 "yyyy-MM-dd HH:mm"
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
|
// 格式化日期对象,输出字符串结果
|
String formattedDate = sdf.format(now);
|
return formattedDate;
|
}
|
}
|