LoginLogController.java 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. package com.huaxu.controller;
  2. import com.baomidou.mybatisplus.core.metadata.IPage;
  3. import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
  4. import com.huaxu.common.EasyExcelUtil;
  5. import com.huaxu.dto.LoginLogDto;
  6. import com.huaxu.entity.LoginLogEntity;
  7. import com.huaxu.model.AjaxMessage;
  8. import com.huaxu.model.Pagination;
  9. import com.huaxu.model.ResultStatus;
  10. import com.huaxu.service.LoginLogService;
  11. import io.swagger.annotations.Api;
  12. import io.swagger.annotations.ApiOperation;
  13. import io.swagger.annotations.ApiParam;
  14. import lombok.extern.slf4j.Slf4j;
  15. import org.apache.commons.lang3.StringUtils;
  16. import org.springframework.beans.factory.annotation.Autowired;
  17. import org.springframework.beans.factory.annotation.Value;
  18. import org.springframework.web.bind.annotation.*;
  19. import java.text.DateFormat;
  20. import java.text.ParseException;
  21. import java.text.SimpleDateFormat;
  22. import java.util.Date;
  23. import java.util.List;
  24. /**
  25. * @description 登录日志管理控制层
  26. * @auto wangli
  27. * @data 2020-10-27 9:19
  28. */
  29. @RestController
  30. @RequestMapping("/loginLog")
  31. @Api(tags = "登录日志管理")
  32. @Slf4j
  33. public class LoginLogController {
  34. @Autowired
  35. private LoginLogService loginLogService;
  36. @Value("${UMIS.sys_excel_path}")
  37. private String baseDir;
  38. /**
  39. * 通过主键查询单条数据
  40. *
  41. * @param id
  42. * @return 单条数据
  43. */
  44. @RequestMapping(value = "get", method = RequestMethod.POST)
  45. @ApiOperation(value = "根据id查询登录日志")
  46. public AjaxMessage<LoginLogDto> selectOne(
  47. @ApiParam(value = "登录日志信息", required = true) @RequestParam Long id) {
  48. LoginLogDto result = loginLogService.selectById(id);
  49. return new AjaxMessage<>(ResultStatus.OK, result);
  50. }
  51. /**
  52. * 查询登录日志信息
  53. *
  54. * @param loginLogDto 参数对象
  55. * @return 多条数据
  56. */
  57. @RequestMapping(value = "selectList", method = RequestMethod.POST)
  58. @ApiOperation(value = "查询登录日志信息")
  59. public AjaxMessage<List<LoginLogDto>> selectList(
  60. @ApiParam(value = "登录日志信息", required = true) @RequestBody LoginLogDto loginLogDto) {
  61. List<LoginLogDto> result = loginLogService.selectList(loginLogDto);
  62. return new AjaxMessage<>(ResultStatus.OK, result);
  63. }
  64. /**
  65. * 新增一条数据
  66. *
  67. * @param loginLogEntity 实体类
  68. * @return Response对象
  69. */
  70. @RequestMapping(value = "insert", method = RequestMethod.POST)
  71. @ApiOperation(value = "插入登录日志信息")
  72. public AjaxMessage<Integer> insert(@ApiParam(value = "登录日志信息", required = true) @RequestBody LoginLogEntity loginLogEntity) {
  73. int result = loginLogService.insert(loginLogEntity);
  74. return new AjaxMessage<>(ResultStatus.OK, result);
  75. }
  76. /**
  77. * 修改一条数据
  78. *
  79. * @param loginLogEntity 实体类
  80. * @return Response对象
  81. */
  82. @RequestMapping(value = "update", method = RequestMethod.POST)
  83. @ApiOperation(value = "修改登录日志信息")
  84. public AjaxMessage<Integer> update(@ApiParam(value = "登录日志信息", required = true) @RequestBody LoginLogEntity loginLogEntity) {
  85. int result = loginLogService.update(loginLogEntity);
  86. return new AjaxMessage<>(ResultStatus.OK, result);
  87. }
  88. /**
  89. * 单条删除数据
  90. *
  91. * @param id
  92. * @return Response对象
  93. */
  94. @RequestMapping(value = "delete", method = RequestMethod.POST)
  95. @ApiOperation(value = "删除登录日志信息")
  96. public AjaxMessage<Integer> delete(@ApiParam(value = "登录日志信息", required = true) @RequestParam Long id) {
  97. int result = loginLogService.deleteById(id);
  98. return new AjaxMessage<>(ResultStatus.OK, result);
  99. }
  100. /**
  101. * 分页查询
  102. *
  103. * @return Response对象
  104. */
  105. @RequestMapping(value = "selectPage", method = RequestMethod.POST)
  106. @ApiOperation(value = "查询登录日志信息列表")
  107. public AjaxMessage<Pagination<LoginLogDto>> selectPage(
  108. @ApiParam(value = "查询条件(用户名/手机号)") @RequestParam(required = false) String condition,
  109. @ApiParam(value = "部门id") @RequestParam(required = false) Long departmentId,
  110. @ApiParam(value = "开始时间yyyy-MM-dd") @RequestParam(required = false) String beginTime,
  111. @ApiParam(value = "结束时间yyyy-MM-dd") @RequestParam(required = false) String endTime,
  112. @ApiParam(value = "页数,非必传,默认第一页", defaultValue = "1") @RequestParam(required = false, defaultValue = "1") Integer pageNum,
  113. @ApiParam(value = "条数,非必传,默认30条", defaultValue = "30") @RequestParam(required = false, defaultValue = "30") Integer pageSize
  114. ) {
  115. SimpleDateFormat f = new SimpleDateFormat("yyyy-MM-dd");
  116. LoginLogDto loginLogDto = new LoginLogDto();
  117. loginLogDto.setCondition(condition);
  118. loginLogDto.setDepartmentId(departmentId);
  119. try {
  120. if(StringUtils.isNotBlank(beginTime)){
  121. loginLogDto.setBeginTime(f.parse(beginTime));
  122. }
  123. if(StringUtils.isNotBlank(endTime)){
  124. loginLogDto.setBeginTime(f.parse(endTime));
  125. }
  126. }catch (ParseException e){
  127. log.error("登录日志查询时间转换错误,原数据:beginTime:{},endTime:{},异常信息:{}",beginTime,endTime,e.getMessage());
  128. loginLogDto.setBeginTime(new Date());
  129. loginLogDto.setBeginTime(new Date());
  130. }
  131. IPage<LoginLogDto> iPage = new Page<>(pageNum, pageSize);
  132. iPage = loginLogService.selectPage(iPage, loginLogDto);
  133. Pagination<LoginLogDto> pages = new Pagination<>(iPage);
  134. return new AjaxMessage<>(ResultStatus.OK, pages);
  135. }
  136. @RequestMapping(value = "/exportExcel", method = RequestMethod.POST)
  137. @ApiOperation(value = "登录日志导出")
  138. public AjaxMessage<String> exportExcel(@ApiParam(value = "日志IDS", required = true) @RequestParam Long[] ids) {
  139. List<LoginLogDto> result = loginLogService.selectListByIds(ids);
  140. String filePath = EasyExcelUtil.excelWrite(baseDir, LoginLogDto.class, "登录日志", result);
  141. return new AjaxMessage<>(ResultStatus.OK, filePath);
  142. }
  143. }