123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168 |
- package com.huaxu.controller;
- import com.baomidou.mybatisplus.core.metadata.IPage;
- import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
- import com.huaxu.common.EasyExcelUtil;
- import com.huaxu.dto.LoginLogDto;
- import com.huaxu.entity.LoginLogEntity;
- import com.huaxu.model.AjaxMessage;
- import com.huaxu.model.Pagination;
- import com.huaxu.model.ResultStatus;
- import com.huaxu.service.LoginLogService;
- import io.swagger.annotations.Api;
- import io.swagger.annotations.ApiOperation;
- import io.swagger.annotations.ApiParam;
- import lombok.extern.slf4j.Slf4j;
- import org.apache.commons.lang3.StringUtils;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.beans.factory.annotation.Value;
- import org.springframework.web.bind.annotation.*;
- import java.text.DateFormat;
- import java.text.ParseException;
- import java.text.SimpleDateFormat;
- import java.util.Date;
- import java.util.List;
- /**
- * @description 登录日志管理控制层
- * @auto wangli
- * @data 2020-10-27 9:19
- */
- @RestController
- @RequestMapping("/loginLog")
- @Api(tags = "登录日志管理")
- @Slf4j
- public class LoginLogController {
- @Autowired
- private LoginLogService loginLogService;
- @Value("${UMIS.sys_excel_path}")
- private String baseDir;
- /**
- * 通过主键查询单条数据
- *
- * @param id
- * @return 单条数据
- */
- @RequestMapping(value = "get", method = RequestMethod.POST)
- @ApiOperation(value = "根据id查询登录日志")
- public AjaxMessage<LoginLogDto> selectOne(
- @ApiParam(value = "登录日志信息", required = true) @RequestParam Long id) {
- LoginLogDto result = loginLogService.selectById(id);
- return new AjaxMessage<>(ResultStatus.OK, result);
- }
- /**
- * 查询登录日志信息
- *
- * @param loginLogDto 参数对象
- * @return 多条数据
- */
- @RequestMapping(value = "selectList", method = RequestMethod.POST)
- @ApiOperation(value = "查询登录日志信息")
- public AjaxMessage<List<LoginLogDto>> selectList(
- @ApiParam(value = "登录日志信息", required = true) @RequestBody LoginLogDto loginLogDto) {
- List<LoginLogDto> result = loginLogService.selectList(loginLogDto);
- return new AjaxMessage<>(ResultStatus.OK, result);
- }
- /**
- * 新增一条数据
- *
- * @param loginLogEntity 实体类
- * @return Response对象
- */
- @RequestMapping(value = "insert", method = RequestMethod.POST)
- @ApiOperation(value = "插入登录日志信息")
- public AjaxMessage<Integer> insert(@ApiParam(value = "登录日志信息", required = true) @RequestBody LoginLogEntity loginLogEntity) {
- int result = loginLogService.insert(loginLogEntity);
- return new AjaxMessage<>(ResultStatus.OK, result);
- }
- /**
- * 修改一条数据
- *
- * @param loginLogEntity 实体类
- * @return Response对象
- */
- @RequestMapping(value = "update", method = RequestMethod.POST)
- @ApiOperation(value = "修改登录日志信息")
- public AjaxMessage<Integer> update(@ApiParam(value = "登录日志信息", required = true) @RequestBody LoginLogEntity loginLogEntity) {
- int result = loginLogService.update(loginLogEntity);
- return new AjaxMessage<>(ResultStatus.OK, result);
- }
- /**
- * 单条删除数据
- *
- * @param id
- * @return Response对象
- */
- @RequestMapping(value = "delete", method = RequestMethod.POST)
- @ApiOperation(value = "删除登录日志信息")
- public AjaxMessage<Integer> delete(@ApiParam(value = "登录日志信息", required = true) @RequestParam Long id) {
- int result = loginLogService.deleteById(id);
- return new AjaxMessage<>(ResultStatus.OK, result);
- }
- /**
- * 分页查询
- *
- * @return Response对象
- */
- @RequestMapping(value = "selectPage", method = RequestMethod.POST)
- @ApiOperation(value = "查询登录日志信息列表")
- public AjaxMessage<Pagination<LoginLogDto>> selectPage(
- @ApiParam(value = "查询条件(用户名/手机号)") @RequestParam(required = false) String condition,
- @ApiParam(value = "部门id") @RequestParam(required = false) Long departmentId,
- @ApiParam(value = "开始时间yyyy-MM-dd") @RequestParam(required = false) String beginTime,
- @ApiParam(value = "结束时间yyyy-MM-dd") @RequestParam(required = false) String endTime,
- @ApiParam(value = "页数,非必传,默认第一页", defaultValue = "1") @RequestParam(required = false, defaultValue = "1") Integer pageNum,
- @ApiParam(value = "条数,非必传,默认30条", defaultValue = "30") @RequestParam(required = false, defaultValue = "30") Integer pageSize
- ) {
- SimpleDateFormat f = new SimpleDateFormat("yyyy-MM-dd");
- LoginLogDto loginLogDto = new LoginLogDto();
- loginLogDto.setCondition(condition);
- loginLogDto.setDepartmentId(departmentId);
- try {
- if(StringUtils.isNotBlank(beginTime)){
- loginLogDto.setBeginTime(f.parse(beginTime));
- }
- if(StringUtils.isNotBlank(endTime)){
- loginLogDto.setBeginTime(f.parse(endTime));
- }
- }catch (ParseException e){
- log.error("登录日志查询时间转换错误,原数据:beginTime:{},endTime:{},异常信息:{}",beginTime,endTime,e.getMessage());
- loginLogDto.setBeginTime(new Date());
- loginLogDto.setBeginTime(new Date());
- }
- IPage<LoginLogDto> iPage = new Page<>(pageNum, pageSize);
- iPage = loginLogService.selectPage(iPage, loginLogDto);
- Pagination<LoginLogDto> pages = new Pagination<>(iPage);
- return new AjaxMessage<>(ResultStatus.OK, pages);
- }
- @RequestMapping(value = "/exportExcel", method = RequestMethod.POST)
- @ApiOperation(value = "登录日志导出")
- public AjaxMessage<String> exportExcel(@ApiParam(value = "日志IDS", required = true) @RequestParam Long[] ids) {
- List<LoginLogDto> result = loginLogService.selectListByIds(ids);
- String filePath = EasyExcelUtil.excelWrite(baseDir, LoginLogDto.class, "登录日志", result);
- return new AjaxMessage<>(ResultStatus.OK, filePath);
- }
- }
|