修改小班自考证书列表

This commit is contained in:
wuchunlei
2025-07-08 15:35:31 +08:00
parent 6ef9c9fb15
commit ff4cc8ad21
2 changed files with 85 additions and 103 deletions

View File

@@ -40,5 +40,7 @@ public class UserCertificate {
@TableField(exist = false)
private MyUserEntity user;
@TableField(exist = false)
private String selective;
}

View File

@@ -3,32 +3,20 @@ 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;
import com.peanut.modules.common.service.MyUserService;
import com.peanut.modules.common.service.UserCertificateLabelService;
import com.peanut.modules.common.service.UserCertificateService;
import com.peanut.modules.common.service.*;
import com.peanut.modules.master.service.CourseMedicalService;
import com.peanut.modules.master.service.CourseService;
import com.peanut.modules.master.service.CourseToMedicalService;
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 jakarta.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;
import java.util.*;
import java.util.stream.Collectors;
/**
* 证书管理
@@ -46,105 +34,97 @@ public class UserCertificateController {
private MyUserService myUserService;
@Autowired
private CourseService courseService;
@Autowired
private CourseMedicalService courseMedicalService;
@Autowired
private CourseToMedicalService courseToMedicalService;
//小班自考证书列表
@RequestMapping("/userClassAndZKCertificateList")
public R userClassAndZKCertificateList(@RequestBody Map<String,Object> params) {
List list = new ArrayList<>();
//查询顶级标签下子标签
if ("13".equals(params.get("labelId").toString())) {
bottomLabel(1,list);
}else {
bottomLabel(2,list);
}
//标签下课程
List<Integer> bixiuList = courseToMedicalService.list(new LambdaQueryWrapper<CourseToMedicine>()
.eq(CourseToMedicine::getSelective,1)
.in(CourseToMedicine::getMedicalId,list)).stream().map(CourseToMedicine::getCourseId).collect(Collectors.toList());
List<Integer> xuanxiuList = courseToMedicalService.list(new LambdaQueryWrapper<CourseToMedicine>()
.eq(CourseToMedicine::getSelective,2)
.in(CourseToMedicine::getMedicalId,list)).stream().map(CourseToMedicine::getCourseId).collect(Collectors.toList());
//拥有小班证书的人
MPJLambdaWrapper<MyUserEntity> wrapper = new MPJLambdaWrapper();
wrapper.leftJoin(UserCertificate.class,UserCertificate::getUserId,MyUserEntity::getId);
wrapper.rightJoin(UserCertificate.class,UserCertificate::getUserId,MyUserEntity::getId);
wrapper.in(UserCertificate::getLabelId,5,8);
wrapper.and(t->t.in(UserCertificate::getCourseId,bixiuList)
.or().in(UserCertificate::getCourseId,xuanxiuList));
//过滤获得国际中医师证和国际针灸师证得人
wrapper.notExists("select 1 from (" +
"select count(1) c,user_id from user_certificate where label_id in (13,19) group by user_id having c>1) s " +
"where s.user_id = t.id ");
wrapper.notExists("select 1 from user_certificate where label_id = "+params.get("labelId")+" and user_id = t.id ");
wrapper.select("count(1) as count,user_id userId,name,tel,email");
wrapper.groupBy(UserCertificate::getUserId);
wrapper.orderByDesc("count");
Page<Map<String,Object>> certificatePage = myUserService.pageMaps(new Page<>(
Long.parseLong(params.get("current").toString()),Long.parseLong(params.get("limit").toString())),wrapper);
for (Map<String,Object> map:certificatePage.getRecords()){
map.put("certificate",userCertificateService.list(new LambdaQueryWrapper<UserCertificate>()
List<Map<String,Object>> certificateMaps = myUserService.listMaps(wrapper);
List<Map<String,Object>> resList = new ArrayList<>();
for (Map<String,Object> map:certificateMaps){
if ((long)map.get("count")>0){
//用户获取得证书
List<UserCertificate> certificateList = userCertificateService.list(new LambdaQueryWrapper<UserCertificate>()
.eq(UserCertificate::getUserId,map.get("userId"))
.in(UserCertificate::getLabelId,5,8,13,19)
.orderByDesc(UserCertificate::getLabelId)));
.in(UserCertificate::getLabelId,5,8)
.and(t->t.in(UserCertificate::getCourseId,bixiuList)
.or().in(UserCertificate::getCourseId,xuanxiuList)));
map.put("msg","");
if (certificateList.size()>0){
int bACount=0,bBCount=0,bZKCount=0,xCount=0;
for (UserCertificate uc : certificateList) {
if (bixiuList.contains(uc.getCourseId())){
uc.setSelective("必修");
if (uc.getCertificateNo().contains("ZK0")){
bZKCount++;
}else {
if (uc.getCertificateNo().contains("-B")){
bBCount++;
}else {
bACount++;
}
return R.ok().put("certificateList", certificatePage);
}
}else if (xuanxiuList.contains(uc.getCourseId())){
uc.setSelective("选修");
xCount++;
}
}
map.put("msg","A证"+bACount+"B证"+bBCount+",自考:"+bZKCount+",选修:"+xCount);
}
map.put("certificate",certificateList);
resList.add(map);
}
}
resList = resList.stream().sorted((map1,map2)->{
return Long.compare(((List)map2.get("certificate")).size(),((List)map1.get("certificate")).size());
}).collect(Collectors.toList());
Page<Map<String,Object>> page = new Page();
page.setRecords(resList);
page.setTotal(resList.size());
page.setCurrent((int)params.get("current"));
page.setSize((int)params.get("limit"));
return R.ok().put("certificateList", page);
}
//导出小班自考证书
@RequestMapping("/exportUserClassAndZKCertificate")
public void exportUserClassAndZKCertificate(HttpServletResponse response) {
MPJLambdaWrapper<UserCertificate> 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");
List<Map<String,Object>> certificateList = userCertificateService.listMaps(wrapper);
for (Map<String,Object> map:certificateList){
map.put("certificate",userCertificateService.list(new LambdaQueryWrapper<UserCertificate>()
.eq(UserCertificate::getUserId,map.get("userId"))
.in(UserCertificate::getLabelId,5,8)));
}
if (certificateList.size() > 0){
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<String,Object> map : certificateList) {
List<UserCertificate> 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")==null?"":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();
//查询顶级标签下子标签
public void bottomLabel(int labelId,List list) {
CourseMedicine cm = courseMedicalService.getById(labelId);
if (cm != null) {
if (cm.getIsLast()==1){
list.add(cm.getId());
}else {
List<CourseMedicine> cms = courseMedicalService.list(new LambdaQueryWrapper<CourseMedicine>()
.eq(CourseMedicine::getPid,cm.getId()));
for (CourseMedicine ccm:cms){
bottomLabel(ccm.getId(),list);
}
}
}