From 884d0ab1e35b930ecbe5dbbe10b421c0429611c0 Mon Sep 17 00:00:00 2001 From: wuchunlei Date: Wed, 25 Jun 2025 18:04:13 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B0=8F=E7=8F=AD=E8=87=AA=E8=80=83=E8=AF=81?= =?UTF-8?q?=E4=B9=A6=E5=AF=BC=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/UserCertificateController.java | 98 +++++++++++++++++++ 1 file changed, 98 insertions(+) diff --git a/src/main/java/com/peanut/modules/master/controller/UserCertificateController.java b/src/main/java/com/peanut/modules/master/controller/UserCertificateController.java index 5efb271a..c542e3fe 100644 --- a/src/main/java/com/peanut/modules/master/controller/UserCertificateController.java +++ b/src/main/java/com/peanut/modules/master/controller/UserCertificateController.java @@ -3,6 +3,7 @@ package com.peanut.modules.master.controller; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.github.yulichang.wrapper.MPJLambdaWrapper; +import com.peanut.common.utils.DateUtils; import com.peanut.common.utils.R; import com.peanut.modules.common.entity.*; import com.peanut.modules.common.service.ClassEntityService; @@ -12,11 +13,20 @@ import com.peanut.modules.common.service.UserCertificateService; import com.peanut.modules.master.service.CourseService; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang.StringUtils; +import org.apache.poi.ss.usermodel.Row; +import org.apache.poi.ss.usermodel.Sheet; +import org.apache.poi.ss.util.CellRangeAddress; +import org.apache.poi.xssf.usermodel.XSSFWorkbook; import org.springframework.beans.factory.annotation.Autowired; 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.io.OutputStream; +import java.net.URLEncoder; +import java.util.ArrayList; import java.util.List; import java.util.Map; @@ -37,6 +47,94 @@ public class UserCertificateController { @Autowired private CourseService courseService; + //小班自考证书列表 + @RequestMapping("/userClassAndZKCertificateList") + public R userClassAndZKCertificateList(@RequestBody Map params) { + MPJLambdaWrapper wrapper = new MPJLambdaWrapper(); + wrapper.leftJoin(MyUserEntity.class,MyUserEntity::getId,UserCertificate::getUserId); + wrapper.in(UserCertificate::getLabelId,5,8); + wrapper.select("count(1) as count,user_id userId,name,tel,email"); + wrapper.groupBy(UserCertificate::getUserId); + wrapper.orderByDesc("count"); + Page> certificatePage = userCertificateService.pageMaps(new Page<>( + Long.parseLong(params.get("current").toString()),Long.parseLong(params.get("limit").toString())),wrapper); + for (Map map:certificatePage.getRecords()){ + map.put("certificate",userCertificateService.list(new LambdaQueryWrapper() + .eq(UserCertificate::getUserId,map.get("userId")) + .in(UserCertificate::getLabelId,5,8))); + } + return R.ok().put("certificateList", certificatePage); + } + + //导出小班自考证书 + @RequestMapping("/exportUserClassAndZKCertificate") + public void exportUserClassAndZKCertificate(HttpServletResponse response, @RequestBody Map params) { + R r = userClassAndZKCertificateList(params); + if ("0".equals(r.get("code").toString())){ + Page> certificateList = (Page>) r.get("certificateList"); + XSSFWorkbook wb = new XSSFWorkbook(); + Sheet sheet = wb.createSheet("用户证书"); + Row titleRow = sheet.createRow(0); + titleRow.createCell(0).setCellValue("序号"); + titleRow.createCell(1).setCellValue("姓名"); + titleRow.createCell(2).setCellValue("电话"); + titleRow.createCell(3).setCellValue("邮箱"); + titleRow.createCell(4).setCellValue("编号"); + titleRow.createCell(5).setCellValue("证书"); + //序号,默认为1 + int cell = 1; + //遍历 + int no = 1; + int startI = 1; + int i = 1; + for (Map map : certificateList.getRecords()) { + List list = (List)map.get("certificate"); + for (UserCertificate uc:list){ + Row row = sheet.createRow(cell); + row.createCell(0).setCellValue(no); + row.createCell(1).setCellValue(map.get("name").toString()); + row.createCell(2).setCellValue(map.get("tel").toString()); + row.createCell(3).setCellValue(map.get("email").toString()); + row.createCell(4).setCellValue(uc.getCertificateNo()); + row.createCell(5).setCellValue((uc.getLabelId()==5?"小班":"自考")+"-"+uc.getTitle()); + //序号自增 + cell++; + i++; + } + // 合并单元格 + if(startI!=i-1){ + sheet.addMergedRegion(new CellRangeAddress(startI, i-1, 0, 0)); + sheet.addMergedRegion(new CellRangeAddress(startI, i-1, 1, 1)); + sheet.addMergedRegion(new CellRangeAddress(startI, i-1, 2, 2)); + sheet.addMergedRegion(new CellRangeAddress(startI, i-1, 3, 3)); + } + startI = i; + no++; + } + String fileName = "小班自考证书.xlsx"; + OutputStream outputStream =null; + try { + //文件名编码格式 + fileName = URLEncoder.encode(fileName,"UTF-8"); + //设置ContentType请求信息格式 + response.setContentType("application/vnd.ms-excel"); + //设置标头 + response.setHeader("Content-disposition", "attachment;filename=" + fileName); + outputStream = response.getOutputStream(); + wb.write(outputStream); + } catch (IOException e) { + e.printStackTrace(); + }finally { + try { + outputStream.flush(); + outputStream.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + } + } + //新增证书 @RequestMapping("/addCertificate") public R addCertificate(@RequestBody UserCertificate userCertificate) {