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 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> selectList( @ApiParam(value = "登录日志信息", required = true) @RequestBody LoginLogDto loginLogDto) { List result = loginLogService.selectList(loginLogDto); return new AjaxMessage<>(ResultStatus.OK, result); } /** * 新增一条数据 * * @param loginLogEntity 实体类 * @return Response对象 */ @RequestMapping(value = "insert", method = RequestMethod.POST) @ApiOperation(value = "插入登录日志信息") public AjaxMessage 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 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 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> 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 iPage = new Page<>(pageNum, pageSize); iPage = loginLogService.selectPage(iPage, loginLogDto); Pagination pages = new Pagination<>(iPage); return new AjaxMessage<>(ResultStatus.OK, pages); } @RequestMapping(value = "/exportExcel", method = RequestMethod.POST) @ApiOperation(value = "登录日志导出") public AjaxMessage exportExcel(@ApiParam(value = "日志IDS", required = true) @RequestParam Long[] ids) { List result = loginLogService.selectListByIds(ids); String filePath = EasyExcelUtil.excelWrite(baseDir, LoginLogDto.class, "登录日志", result); return new AjaxMessage<>(ResultStatus.OK, filePath); } }