| | |
| | | import com.ruoyi.common.core.domain.AjaxResult; |
| | | import com.ruoyi.system.dto.SysVisitorRecordDetailRequest; |
| | | import com.ruoyi.system.dto.SysVisitorRecordPageRequest; |
| | | import com.ruoyi.system.service.ISysVersionUpdateService; |
| | | import com.ruoyi.system.service.ISysVisitorRecordService; |
| | | import com.ruoyi.system.vo.SysVersionUpdateVO; |
| | | import com.ruoyi.system.vo.SysVisitorRecordDetailVO; |
| | | import com.ruoyi.system.vo.SysVisitorRecordVO; |
| | | import io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import io.swagger.annotations.ApiResponse; |
| | | import io.swagger.annotations.ApiResponses; |
| | | import org.apache.poi.ss.usermodel.Cell; |
| | | import org.apache.poi.ss.usermodel.CellStyle; |
| | | import org.apache.poi.ss.usermodel.Font; |
| | | import org.apache.poi.ss.usermodel.HorizontalAlignment; |
| | | import org.apache.poi.ss.usermodel.Row; |
| | | import org.apache.poi.ss.usermodel.Sheet; |
| | | import org.apache.poi.xssf.streaming.SXSSFWorkbook; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.web.bind.annotation.PostMapping; |
| | | import org.springframework.web.bind.annotation.RequestBody; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.io.IOException; |
| | | import java.net.URLEncoder; |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * 管理侧访客记录接口 |
| | |
| | | { |
| | | @Autowired |
| | | private ISysVisitorRecordService visitorRecordService; |
| | | |
| | | @Autowired |
| | | private ISysVersionUpdateService versionUpdateService; |
| | | |
| | | /** |
| | | * 分页查询访客记录 |
| | |
| | | } |
| | | |
| | | /** |
| | | * 导出访客记录 |
| | | */ |
| | | @ApiOperation( |
| | | value = "导出访客记录", |
| | | notes = "按分页查询接口的筛选条件查询全部访客记录并导出 Excel,不进行分页" |
| | | ) |
| | | @PostMapping("/export") |
| | | public void export(HttpServletResponse response, |
| | | @RequestBody(required = false) SysVisitorRecordPageRequest request) throws IOException |
| | | { |
| | | List<SysVisitorRecordVO> records = visitorRecordService.list(request); |
| | | response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"); |
| | | response.setCharacterEncoding("utf-8"); |
| | | String fileName = URLEncoder.encode("访客记录", "UTF-8").replace("+", "%20"); |
| | | response.setHeader("Content-disposition", "attachment;filename*=utf-8''" + fileName + ".xlsx"); |
| | | |
| | | SXSSFWorkbook workbook = new SXSSFWorkbook(500); |
| | | try |
| | | { |
| | | writeVisitorRecordSheet(workbook, records); |
| | | workbook.write(response.getOutputStream()); |
| | | response.flushBuffer(); |
| | | } |
| | | finally |
| | | { |
| | | workbook.dispose(); |
| | | workbook.close(); |
| | | } |
| | | } |
| | | |
| | | private void writeVisitorRecordSheet(SXSSFWorkbook workbook, List<SysVisitorRecordVO> records) |
| | | { |
| | | String[] headers = { |
| | | "登记编号", "访客姓名", "证件号码", "登记类型", "被访人", "被访部门", "访问区域", |
| | | "车牌号", "来访事由", "有效期开始时间", "有效期结束时间", "状态", "登记时间" |
| | | }; |
| | | int[] columnWidths = {20, 16, 24, 16, 16, 20, 24, 16, 24, 22, 22, 20, 22}; |
| | | Sheet sheet = workbook.createSheet("访客记录"); |
| | | sheet.createFreezePane(0, 1); |
| | | CellStyle headerStyle = createHeaderStyle(workbook); |
| | | Row headerRow = sheet.createRow(0); |
| | | for (int index = 0; index < headers.length; index++) |
| | | { |
| | | Cell cell = headerRow.createCell(index); |
| | | cell.setCellValue(headers[index]); |
| | | cell.setCellStyle(headerStyle); |
| | | sheet.setColumnWidth(index, columnWidths[index] * 256); |
| | | } |
| | | |
| | | SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
| | | for (int index = 0; index < records.size(); index++) |
| | | { |
| | | SysVisitorRecordVO record = records.get(index); |
| | | Row row = sheet.createRow(index + 1); |
| | | setCellValue(row, 0, record.getRegisterNo()); |
| | | setCellValue(row, 1, record.getVisitorName()); |
| | | setCellValue(row, 2, record.getIdCard()); |
| | | setCellValue(row, 3, registerTypeName(record.getRegisterType())); |
| | | setCellValue(row, 4, record.getIntervieweeName()); |
| | | setCellValue(row, 5, record.getIntervieweeDept()); |
| | | setCellValue(row, 6, record.getVisitAreaNames()); |
| | | setCellValue(row, 7, record.getPlateNo()); |
| | | setCellValue(row, 8, record.getVisitReason()); |
| | | setCellValue(row, 9, formatDate(dateFormat, record.getValidStartTime())); |
| | | setCellValue(row, 10, formatDate(dateFormat, record.getValidEndTime())); |
| | | setCellValue(row, 11, statusName(record.getStatus())); |
| | | setCellValue(row, 12, formatDate(dateFormat, record.getRegisterTime())); |
| | | } |
| | | } |
| | | |
| | | private CellStyle createHeaderStyle(SXSSFWorkbook workbook) |
| | | { |
| | | Font font = workbook.createFont(); |
| | | font.setBold(true); |
| | | CellStyle style = workbook.createCellStyle(); |
| | | style.setFont(font); |
| | | style.setAlignment(HorizontalAlignment.CENTER); |
| | | return style; |
| | | } |
| | | |
| | | private void setCellValue(Row row, int columnIndex, String value) |
| | | { |
| | | row.createCell(columnIndex).setCellValue(value == null ? "" : value); |
| | | } |
| | | |
| | | private String formatDate(SimpleDateFormat dateFormat, java.util.Date date) |
| | | { |
| | | return date == null ? "" : dateFormat.format(date); |
| | | } |
| | | |
| | | private String registerTypeName(String registerType) |
| | | { |
| | | if ("APPOINTMENT".equalsIgnoreCase(registerType)) |
| | | { |
| | | return "预约登记"; |
| | | } |
| | | if ("ONSITE".equalsIgnoreCase(registerType)) |
| | | { |
| | | return "现场登记"; |
| | | } |
| | | return registerType; |
| | | } |
| | | |
| | | private String statusName(String status) |
| | | { |
| | | if ("VISITING".equalsIgnoreCase(status)) |
| | | { |
| | | return "来访中"; |
| | | } |
| | | if ("SIGNED_OUT".equalsIgnoreCase(status)) |
| | | { |
| | | return "已签离"; |
| | | } |
| | | if ("PENDING_CONFIRM".equalsIgnoreCase(status)) |
| | | { |
| | | return "逾期滞留"; |
| | | } |
| | | if ("OVERDUE_AUTO_SIGNED_OUT".equalsIgnoreCase(status)) |
| | | { |
| | | return "超期自动签离"; |
| | | } |
| | | if ("CANCELLED".equalsIgnoreCase(status)) |
| | | { |
| | | return "已取消"; |
| | | } |
| | | return status; |
| | | } |
| | | |
| | | /** |
| | | * 查询访客记录详情 |
| | | */ |
| | | @ApiOperation( |
| | |
| | | { |
| | | return success(visitorRecordService.detail(request)); |
| | | } |
| | | |
| | | /** |
| | | * 获取最新版本信息 |
| | | */ |
| | | @ApiOperation( |
| | | value = "获取最新版本信息", |
| | | notes = "返回最新一条未删除的版本更新记录", |
| | | response = SysVersionUpdateVO.class |
| | | ) |
| | | @ApiResponses({ |
| | | @ApiResponse( |
| | | code = 200, |
| | | message = "成功", |
| | | response = AjaxResult.class, |
| | | responseContainer = "Data" |
| | | ) |
| | | }) |
| | | @PostMapping("/latestVersion") |
| | | public AjaxResult<SysVersionUpdateVO> latestVersion() |
| | | { |
| | | return success(versionUpdateService.latest()); |
| | | } |
| | | } |