LoginLogController.java 6.6 KB

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