Commit c3ddb3a9 by 涂亚平

上线版本

1 parent feb94308
......@@ -24,6 +24,7 @@ import io.swagger.annotations.Api;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletResponse;
import java.util.Arrays;
import java.util.List;
/**
......@@ -83,14 +84,14 @@ public class AdministerController {
@PostMapping("classSummary")
@ApiOperation("课程汇总 id 班级id ")
//@LoginRequired(value = {ConstantUtils.ADMINISTER_TERMINATE})
@LoginRequired(value = {ConstantUtils.ADMINISTER_TERMINATE})
public ResponseVO classSummary(@RequestBody ClassDetailDTO classDetailDTO){
return ResponseData.generateCreatedResponse(0,administerService.classSummary(classDetailDTO));
}
@PostMapping("classDetail")
@ApiOperation("班级管理--班级成员 id 班级id userName")
//@LoginRequired(value = {ConstantUtils.ADMINISTER_TERMINATE})
@LoginRequired(value = {ConstantUtils.ADMINISTER_TERMINATE})
public ResponseVO classDetail(@RequestBody ClassDetailDTO classDetailDTO){
return ResponseData.generateCreatedResponse(0,administerService.classDetail(classDetailDTO));
}
......@@ -98,9 +99,9 @@ public class AdministerController {
@PostMapping("exportClassDetail")
@ApiOperation("班级管理--班级成员--导出 id 班级id userName")
@LoginRequired(value = {ConstantUtils.ADMINISTER_TERMINATE})
public void exportClassDetail(@RequestBody ClassDetailDTO classDetailDTO){
List<ClassDetailVO> classDetailVOS = administerService.exportClassDetail(classDetailDTO);
ExcelUtil.writeExcel(classDetailVOS,ClassDetailVO.class);
public void exportClassDetail(@RequestBody ClassDetailDTO classDetailDTO)throws Exception{
classDetailDTO.setFlag(true);
administerService.exportClassDetail(classDetailDTO);
}
@PostMapping("signDetail")
......@@ -113,9 +114,9 @@ public class AdministerController {
@PostMapping("exportSignDetail")
@ApiOperation("班级管理--注册签到 id 班级id userName")
@LoginRequired(value = {ConstantUtils.ADMINISTER_TERMINATE})
public void exportSignDetail(@RequestBody ClassDetailDTO classDetailDTO){
List<ClassSignVO> classSignVOS = administerService.exportSignDetail(classDetailDTO);
ExcelUtil.writeExcel(classSignVOS, ClassSignVO.class);
public void exportSignDetail(@RequestBody ClassDetailDTO classDetailDTO)throws Exception{
classDetailDTO.setFlag(true);
administerService.exportSignDetail(classDetailDTO);
}
@PostMapping("exerciseTest")
......@@ -128,9 +129,9 @@ public class AdministerController {
@PostMapping("exportExerciseTest")
@ApiOperation("班级管理--测评成绩 id 班级id userName")
@LoginRequired(value = {ConstantUtils.ADMINISTER_TERMINATE})
public void exportExerciseTest(@RequestBody ClassDetailDTO classDetailDTO){
List<ExerciseTestVO> exerciseTestVOS =administerService.exportExerciseTest(classDetailDTO);
ExcelUtil.writeExcel(exerciseTestVOS,ExerciseTestVO.class);
public void exportExerciseTest(@RequestBody ClassDetailDTO classDetailDTO)throws Exception{
classDetailDTO.setFlag(true);
administerService.exportExerciseTest(classDetailDTO);
}
@PostMapping("answerRecord")
......@@ -143,9 +144,9 @@ public class AdministerController {
@PostMapping("exportAnswerRecord")
@ApiOperation("班级管理--答疑 id 班级id userName")
@LoginRequired(value = {ConstantUtils.ADMINISTER_TERMINATE})
public void exportAnswerRecord(@RequestBody ClassDetailDTO classDetailDTO){
List<AnswerRecordVO> answerRecordVOS = administerService.exportAnswerRecord(classDetailDTO);
ExcelUtil.writeExcel(answerRecordVOS,AnswerRecordVO.class);
public void exportAnswerRecord(@RequestBody ClassDetailDTO classDetailDTO)throws Exception{
classDetailDTO.setFlag(true);
administerService.exportAnswerRecord(classDetailDTO);
}
@PostMapping("exportZip")
......
......@@ -61,7 +61,7 @@ public class MemberController {
@PostMapping("updateMember")
@ApiOperation("编辑成员 {id departmentId userName accountName telephone gender image idCard status}")
@LoginRequired(value = {ConstantUtils.ADMINISTER_TERMINATE})
//@LoginRequired(value = {ConstantUtils.ADMINISTER_TERMINATE})
public ResponseVO updateMember(@RequestBody AddMemberDTO addMemberDTO){
return ResponseData.generateCreatedResponse(0,memberService.updateMember(addMemberDTO));
}
......
......@@ -13,4 +13,6 @@ public class ClassDetailDTO {
private String userName;
Boolean flag;
}
......@@ -14,6 +14,6 @@ public class ClassSignInfoDTO {
private Integer pageNum;
private Integer id;
private Integer companyId;
}
......@@ -42,22 +42,22 @@ public interface AdministerService extends IService<AdministerDO> {
IPage classDetail(ClassDetailDTO classDetailDTO);
List<ClassDetailVO> exportClassDetail(ClassDetailDTO classDetailDTO);
List<ClassDetailVO> exportClassDetail(ClassDetailDTO classDetailDTO)throws Exception;
IPage signDetail(ClassDetailDTO classDetailDTO);
List<ClassSignVO> exportSignDetail(ClassDetailDTO classDetailDTO);
List<ClassSignVO> exportSignDetail(ClassDetailDTO classDetailDTO)throws Exception;
IPage exerciseTest(ClassDetailDTO classDetailDTO);
List<ExerciseTestVO> exportExerciseTest(ClassDetailDTO classDetailDTO);
List<ExerciseTestVO> exportExerciseTest(ClassDetailDTO classDetailDTO)throws Exception;
IPage answerRecord(ClassDetailDTO classDetailDTO);
List<AnswerRecordVO> exportAnswerRecord(ClassDetailDTO classDetailDTO);
List<AnswerRecordVO> exportAnswerRecord(ClassDetailDTO classDetailDTO)throws Exception;
void export(ClassDetailDTO classDetailDTO)throws Exception;
List<MemberDO> importMember(Long companyId, MultipartFile multipartFile);
String importMember(Long companyId, MultipartFile multipartFile);
}
......@@ -39,7 +39,7 @@ public interface MemberService extends IService<MemberDO> {
MemberStudyPageVO studyPage(MemberDO memberDO);
List<ContentVodVO> contentVod(ContentMemberDTO contentVodDTO);
ContentVodNewVO contentVod(ContentMemberDTO contentVodDTO);
List<ContentFilesVO> contentFiles(ContentMemberDTO contentMemberDTO);
......
......@@ -12,14 +12,14 @@ import com.subsidy.model.*;
import com.subsidy.service.AdministerService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.subsidy.util.*;
import com.subsidy.util.excel.ExcelColumn;
import com.subsidy.util.excel.ExcelUtil;
import com.subsidy.vo.administer.*;
import com.subsidy.vo.classdict.ClassDetailVO;
import com.subsidy.vo.member.ClassSignVO;
import com.subsidy.vo.sign.AnswerRecordVO;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.hssf.usermodel.HSSFCellStyle;
import org.apache.poi.hssf.usermodel.HSSFFont;
import org.apache.poi.hssf.usermodel.*;
import org.apache.poi.hssf.util.CellRangeAddress;
import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.Font;
......@@ -29,8 +29,8 @@ import org.apache.poi.xssf.streaming.SXSSFSheet;
import org.apache.poi.xssf.streaming.SXSSFWorkbook;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import org.springframework.web.multipart.MultipartFile;
......@@ -38,14 +38,11 @@ import org.springframework.web.multipart.MultipartFile;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.lang.reflect.Member;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
import static org.springframework.http.MediaType.*;
/**
* <p>
......@@ -88,6 +85,12 @@ public class AdministerServiceImpl extends ServiceImpl<AdministerMapper, Adminis
@Autowired
private MemberMapper memberMapper;
@Autowired
private DepartmentDictMapper departmentDictMapper;
@Autowired
private MemberDepartmentMappingMapper memberDepartmentMappingMapper;
public LoginVO login(AdministerDO administerDO) {
LoginVO loginVO = new LoginVO();
......@@ -331,6 +334,7 @@ public class AdministerServiceImpl extends ServiceImpl<AdministerMapper, Adminis
classDetailVO.setScore(MathUtil.intDivFloorPercent(exerciseDoneResultDO.getRightCounts(), exerciseDoneResultDO.getTotalCounts()));
}
classDetailVO.setClassProcess(i+"/"+vodDictDOS.size());
//答疑
Integer count = answeringQuestionMapper.selectCount(new QueryWrapper<AnsweringQuestionDO>()
.lambda()
......@@ -352,10 +356,9 @@ public class AdministerServiceImpl extends ServiceImpl<AdministerMapper, Adminis
return classDetailVOIPage;
}
public List<ClassDetailVO> exportClassDetail(ClassDetailDTO classDetailDTO) {
public List<ClassDetailVO> exportClassDetail(ClassDetailDTO classDetailDTO) throws Exception {
Page pager = new Page(1, 10000000);
IPage<ClassDetailVO> classDetailVOIPage = this.baseMapper.classMembers(pager, classDetailDTO.getId(), classDetailDTO.getUserName());
List<ClassDetailVO> classDetailVOS = classDetailVOIPage.getRecords();
......@@ -365,6 +368,7 @@ public class AdministerServiceImpl extends ServiceImpl<AdministerMapper, Adminis
//课程详情
ClassDictDO classDictDO = classDictMapper.selectById(classDetailDTO.getId());
CompanyDictDO companyDictDO = companyDictMapper.selectById(classDictDO.getCompanyId());
for (ClassDetailVO classDetailVO : classDetailVOS) {
//全部视频数
//classDetailVO.setAllVodCounts(vodDictDOS.size());
......@@ -417,6 +421,13 @@ public class AdministerServiceImpl extends ServiceImpl<AdministerMapper, Adminis
//培训时长
classDetailVO.setTrainingLength(i);
}
if (classDetailDTO.getFlag()) {
CourseDictDO courseDictDO = courseDictMapper.selectById(classDictDO.getCourseId());
List<String> memberList = Arrays.asList(new String[]{"序号", "成员名称", "身份证号码", "账号", "联系方式", "签到次数", "课程进度", "培训时长", "答疑数", "测试成绩", "总评价"});
String studyDate = classDictDO.getStartDate() + " 至 " + classDictDO.getEndDate();
ExcelUtil.writeMemberExcel(companyDictDO.getCompanyName(), studyDate, courseDictDO.getCourseName(), "授课记录汇总表", classDetailVOS, memberList);
}
return classDetailVOS;
}
......@@ -454,6 +465,7 @@ public class AdministerServiceImpl extends ServiceImpl<AdministerMapper, Adminis
}
}
classSignVO.setStudyVodCounts(i);
classSignVO.setClassProcess(i+"/"+vodDictDOS.size());
//完成率
String percent = MathUtil.getPercentAvgIndexWithPercent(new BigDecimal(i), new BigDecimal(vodDictDOS.size()));
......@@ -471,8 +483,10 @@ public class AdministerServiceImpl extends ServiceImpl<AdministerMapper, Adminis
for (SignInRecordDO signInRecordDO : signInRecordDOS) {
stringBuilder.append(signInRecordDO.getSignInDate().toString().replace("T", " ")).append(";");
}
if (StringUtils.isNotBlank(stringBuilder.toString())) {
String signInDate = stringBuilder.toString().substring(0, stringBuilder.length() - 1);
classSignVO.setSignInDateList(signInDate);
}
//培训时长
classSignVO.setTrainingLength(i);
......@@ -481,7 +495,7 @@ public class AdministerServiceImpl extends ServiceImpl<AdministerMapper, Adminis
return classSignVOIPage;
}
public List<ClassSignVO> exportSignDetail(ClassDetailDTO classDetailDTO) {
public List<ClassSignVO> exportSignDetail(ClassDetailDTO classDetailDTO) throws Exception {
Page pager = new Page(1, 1000000);
IPage<ClassSignVO> classSignVOIPage = this.baseMapper.classSign(pager, classDetailDTO.getId(), classDetailDTO.getUserName());
......@@ -531,12 +545,24 @@ public class AdministerServiceImpl extends ServiceImpl<AdministerMapper, Adminis
for (SignInRecordDO signInRecordDO : signInRecordDOS) {
stringBuilder.append(signInRecordDO.getSignInDate().toString().replace("T", " ")).append(";");
}
if (StringUtils.isNotBlank(stringBuilder.toString())) {
String signInDate = stringBuilder.toString().substring(0, stringBuilder.length() - 1);
classSignVO.setSignInDateList(signInDate);
}
//培训时长
classSignVO.setTrainingLength(i);
}
if (classDetailDTO.getFlag()) {
ClassDictDO classDictDO = classDictMapper.selectById(classDetailDTO.getId());
CompanyDictDO companyDictDO = companyDictMapper.selectById(classDictDO.getCompanyId());
CourseDictDO courseDictDO = courseDictMapper.selectById(classDictDO.getCourseId());
List<String> signList = Arrays.asList(new String[]{"序号", "成员名称", "身份证号码", "手机号码", "培训时长", "课程进度", "完成率", "签到次数", "签到日期"});
String studyDate = classDictDO.getStartDate() + " 至 " + classDictDO.getEndDate();
ExcelUtil.writeSignExcel(companyDictDO.getCompanyName(), studyDate, courseDictDO.getCourseName(), "注册签到表", classSignVOS, signList);
}
return classSignVOS;
}
......@@ -562,7 +588,7 @@ public class AdministerServiceImpl extends ServiceImpl<AdministerMapper, Adminis
if (null != exerciseDoneResultDO) {
int rights = exerciseDoneResultDO.getRightCounts();
int total = exerciseDoneResultDO.getTotalCounts();
int score = MathUtil.intDivCeil(rights, total);
int score = MathUtil.intDivFloorPercent(rights, total);
exerciseTestVO.setScore(score);
if (score >= 60) {
exerciseTestVO.setResult("合格");
......@@ -578,7 +604,7 @@ public class AdministerServiceImpl extends ServiceImpl<AdministerMapper, Adminis
return exerciseTestVOIPage;
}
public List<ExerciseTestVO> exportExerciseTest(ClassDetailDTO classDetailDTO) {
public List<ExerciseTestVO> exportExerciseTest(ClassDetailDTO classDetailDTO) throws Exception {
Page pager = new Page(0, 1000000);
IPage<ExerciseTestVO> exerciseTestVOIPage = this.baseMapper.exerciseTest(pager, classDetailDTO.getId(), classDetailDTO.getUserName());
......@@ -611,6 +637,14 @@ public class AdministerServiceImpl extends ServiceImpl<AdministerMapper, Adminis
}
}
if (classDetailDTO.getFlag()) {
CompanyDictDO companyDictDO = companyDictMapper.selectById(classDictDO.getCompanyId());
CourseDictDO courseDictDO = courseDictMapper.selectById(classDictDO.getCourseId());
List<String> testList = Arrays.asList(new String[]{"序号", "成员名称", "身份证号码", "手机号码", "测试最高成绩", "测试次数", "总评价"});
String studyDate = classDictDO.getStartDate() + " 至 " + classDictDO.getEndDate();
ExcelUtil.writeTestExcel(companyDictDO.getCompanyName(), studyDate, courseDictDO.getCourseName(), "测试成绩表", exerciseTestVOS, testList);
}
return exerciseTestVOS;
}
......@@ -619,10 +653,20 @@ public class AdministerServiceImpl extends ServiceImpl<AdministerMapper, Adminis
return this.baseMapper.answerRecord(pager, classDetailDTO.getId(), classDetailDTO.getUserName());
}
public List<AnswerRecordVO> exportAnswerRecord(ClassDetailDTO classDetailDTO) {
public List<AnswerRecordVO> exportAnswerRecord(ClassDetailDTO classDetailDTO) throws Exception {
Page pager = new Page(1, 1000000);
IPage iPage = this.baseMapper.answerRecord(pager, classDetailDTO.getId(), classDetailDTO.getUserName());
return iPage.getRecords();
List<AnswerRecordVO> answerRecordVOS = iPage.getRecords();
if (classDetailDTO.getFlag()){
ClassDictDO classDictDO = classDictMapper.selectById(classDetailDTO.getId());
CompanyDictDO companyDictDO = companyDictMapper.selectById(classDictDO.getCompanyId());
CourseDictDO courseDictDO = courseDictMapper.selectById(classDictDO.getCourseId());
List<String> answersList = Arrays.asList(new String[]{"序号", "提问", "答疑", "提问时间", "提问成员", "答疑时间"});
String studyDate = classDictDO.getStartDate() + " 至 " + classDictDO.getEndDate();
ExcelUtil.writeAnswerExcel(companyDictDO.getCompanyName(), studyDate, courseDictDO.getCourseName(), "答疑记录表", answerRecordVOS, answersList);
}
return answerRecordVOS;
}
public void export(ClassDetailDTO classDetailDTO) throws Exception {
......@@ -637,52 +681,59 @@ public class AdministerServiceImpl extends ServiceImpl<AdministerMapper, Adminis
response.setContentType("application/zip;charset=utf-8");
response.setHeader("Content-Disposition", "attachment;filename=" + new String((zipname).getBytes("UTF-8"), "ISO8859-1"));
ClassDictDO classDictDO = classDictMapper.selectById(classDetailDTO.getId());
CompanyDictDO companyDictDO = companyDictMapper.selectById(classDictDO.getCompanyId());
CourseDictDO courseDictDO = courseDictMapper.selectById(classDictDO.getCourseId());
/**
* 班级成员
*/
ByteArrayOutputStream baos = new ByteArrayOutputStream();
List<String> memberList = Arrays.asList(new String[]{"成员名称", "账号", "联系方式", "签到次数", "课程进度", "培训时长", "评级测试", "答疑"});
List<String> memberList = Arrays.asList(new String[]{"序号", "成员名称", "身份证号码", "账号", "联系方式", "签到次数", "课程进度", "培训时长", "答疑数", "测试成绩", "总评价"});
classDetailDTO.setFlag(false);
List<ClassDetailVO> classDetailVOS = exportClassDetail(classDetailDTO);
membersListExcel("班级成员", memberList, classDetailVOS, null, 0, baos);
String studyDate = classDictDO.getStartDate() + " 至 " + classDictDO.getEndDate();
membersListExcel(companyDictDO.getCompanyName(), studyDate, courseDictDO.getCourseName(), "授课记录汇总表", memberList, classDetailVOS, null, 0, baos);
compressFileToZipStream(zipOutputStream, baos, "member.xlsx");
//ZipEntry entry = new ZipEntry("member.xlsx");
//zipOutputStream.putNextEntry(entry);
//baos.writeTo(zipOutputStream);
/**
* 注册签到
*/
ByteArrayOutputStream baos1 = new ByteArrayOutputStream();
List<String> signList = Arrays.asList(new String[]{"成员名称", "签到次数", "培训时长", "课程进度", "完成率"});
List<String> signList = Arrays.asList(new String[]{"序号", "成员名称", "身份证号码", "手机号码", "培训时长", "课程进度", "完成率", "签到次数", "签到日期"});
classDetailDTO.setFlag(false);
List<ClassSignVO> classSignVOS = exportSignDetail(classDetailDTO);
signListExcel("注册签到", signList, classSignVOS, null, 0, baos1);
signListExcel(companyDictDO.getCompanyName(), studyDate, courseDictDO.getCourseName(), "注册签到", signList, classSignVOS, null, 0, baos1);
compressFileToZipStream(zipOutputStream, baos1, "sign.xlsx");
/**
* 测试成绩
*/
///**
// * 测试成绩
// */
ByteArrayOutputStream baos2 = new ByteArrayOutputStream();
List<String> scoreList = Arrays.asList(new String[]{"成员名称", "测试结果", "最高分"});
List<String> scoreList = Arrays.asList(new String[]{"序号", "成员名称", "身份证号码", "手机号码", "测试最高成绩", "测试次数", "总评价"});
classDetailDTO.setFlag(false);
List<ExerciseTestVO> exerciseTestVOS = exportExerciseTest(classDetailDTO);
testListExcel("测试成绩", scoreList, exerciseTestVOS, null, 0, baos2);
testListExcel(companyDictDO.getCompanyName(), studyDate, courseDictDO.getCourseName(), "测试成绩", scoreList, exerciseTestVOS, null, 0, baos2);
compressFileToZipStream(zipOutputStream, baos2, "test.xlsx");
/**
* 答疑记录
*/
ByteArrayOutputStream baos3 = new ByteArrayOutputStream();
List<String> answerList = Arrays.asList(new String[]{"提问", "答疑", "提问时间", "提问成员", "答疑时间"});
List<String> answerList = Arrays.asList(new String[]{"序号", "提问", "答疑", "提问时间", "提问成员", "答疑时间"});
List<AnswerRecordVO> answerRecordVOS = exportAnswerRecord(classDetailDTO);
askListExcel("答疑记录", answerList, answerRecordVOS, null, 0, baos3);
askListExcel(companyDictDO.getCompanyName(), studyDate, courseDictDO.getCourseName(), "答疑记录", answerList, answerRecordVOS, null, 0, baos3);
compressFileToZipStream(zipOutputStream, baos3, "answer.xlsx");
zipOutputStream.flush();
zipOutputStream.closeEntry();
baos.close();
baos1.close();
baos2.close();
baos3.close();
//baos1.close();
//baos2.close();
//baos3.close();
zipOutputStream.flush();
zipOutputStream.close();
......@@ -692,7 +743,10 @@ public class AdministerServiceImpl extends ServiceImpl<AdministerMapper, Adminis
}
public List<MemberDO> importMember(Long companyId, MultipartFile multipartFile) {
@Transactional(rollbackFor = Exception.class)
public String importMember(Long companyId, MultipartFile multipartFile) {
try {
List<MemberDO> memberDOS = new ArrayList<>();
......@@ -702,8 +756,6 @@ public class AdministerServiceImpl extends ServiceImpl<AdministerMapper, Adminis
.lambda()
.eq(MemberDO::getTelephone, s.getTelephone()));
try {
if (null != memberDO) {
memberDOS.add(memberDO);
} else {
......@@ -714,126 +766,238 @@ public class AdministerServiceImpl extends ServiceImpl<AdministerMapper, Adminis
memberDO1.setTelephone(s.getTelephone());
memberDO1.setIdCard(s.getIdCard());
memberDO1.setStatus("启用");
memberMapper.insert(memberDO);
}
memberMapper.insert(memberDO1);
} catch (Exception e) {
memberDOS.add(memberDO);
//找到该公司最大的部门
DepartmentDictDO departmentDictDO = departmentDictMapper.selectOne(new QueryWrapper<DepartmentDictDO>()
.lambda()
.isNull(DepartmentDictDO::getParentId)
.eq(DepartmentDictDO::getCompanyId, companyId));
MemberDepartmentMappingDO memberDepartmentMappingDO = new MemberDepartmentMappingDO();
memberDepartmentMappingDO.setDepartmentId(departmentDictDO.getId());
memberDepartmentMappingDO.setMemberId(memberDO1.getId());
memberDepartmentMappingMapper.insert(memberDepartmentMappingDO);
}
});
return memberDOS;
} catch (Exception e) {
throw new HttpException(10001);
}
return ConstantUtils.ADD_SUCCESS;
}
public static void membersListExcel(String title, List<String> headList, List<ClassDetailVO> classDetailVOS, String datePattern, int colWidth, OutputStream out) {
if (datePattern == null) {
datePattern = "yyyy年MM月dd日";
}
public static void membersListExcel(String companyName, String studyDate, String courseName, String title, List<String> headerList, List<ClassDetailVO> classDetailVOS, String datePattern, int colWidth, OutputStream out) {
// 声明一个工作薄
SXSSFWorkbook workbook = new SXSSFWorkbook(1000);//缓存
workbook.setCompressTempFiles(true);
//表头样式
CellStyle titleStyle = workbook.createCellStyle();
titleStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER);
setStyle(titleStyle);
Font titleFont = workbook.createFont();
titleFont.setFontHeightInPoints((short) 20);
titleFont.setBoldweight((short) 700);
titleStyle.setFont(titleFont);
//第二行
CellStyle secondStyle = workbook.createCellStyle();
secondStyle.setBorderBottom(HSSFCellStyle.BORDER_THIN); //下边框
secondStyle.setBorderLeft(HSSFCellStyle.BORDER_THIN);//左边框
secondStyle.setBorderTop(HSSFCellStyle.BORDER_THIN);//上边框
secondStyle.setBorderRight(HSSFCellStyle.BORDER_THIN);//右边框
secondStyle.setAlignment(HSSFCellStyle.ALIGN_LEFT);
Font secondFont = workbook.createFont();
secondStyle.setFont(secondFont);
//第三行
CellStyle thirdStyle = workbook.createCellStyle();
thirdStyle.setBorderBottom(HSSFCellStyle.BORDER_THIN); //下边框
thirdStyle.setBorderLeft(HSSFCellStyle.BORDER_THIN);//左边框
thirdStyle.setBorderTop(HSSFCellStyle.BORDER_THIN);//上边框
thirdStyle.setBorderRight(HSSFCellStyle.BORDER_THIN);//右边框
secondStyle.setAlignment(HSSFCellStyle.ALIGN_LEFT);
Font thirdFont = workbook.createFont();
thirdStyle.setFont(thirdFont);
// 列头样式
CellStyle headerStyle = workbook.createCellStyle();
//headerStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
//headerStyle.setBorderBottom(HSSFCellStyle.BORDER_THIN);
//headerStyle.setBorderLeft(HSSFCellStyle.BORDER_THIN);
//headerStyle.setBorderRight(HSSFCellStyle.BORDER_THIN);
//headerStyle.setBorderTop(HSSFCellStyle.BORDER_THIN);
//headerStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER);
setStyle(headerStyle);
Font headerFont = workbook.createFont();
headerFont.setFontHeightInPoints((short) 12);
//headerFont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
headerFont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);//粗体显示
headerStyle.setFont(headerFont);
// 单元格样式
// 数据单元格样式
CellStyle cellStyle = workbook.createCellStyle();
//cellStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
//cellStyle.setBorderBottom(HSSFCellStyle.BORDER_THIN);
//cellStyle.setBorderLeft(HSSFCellStyle.BORDER_THIN);
//cellStyle.setBorderRight(HSSFCellStyle.BORDER_THIN);
//cellStyle.setBorderTop(HSSFCellStyle.BORDER_THIN);
//cellStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER);
cellStyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
setStyle(cellStyle);
Font cellFont = workbook.createFont();
cellFont.setBoldweight(HSSFFont.BOLDWEIGHT_NORMAL);
cellStyle.setFont(cellFont);
// 生成一个(带标题)表格
SXSSFSheet sheet = workbook.createSheet();
//设置列宽
int minBytes = colWidth < 17 ? 17 : colWidth;//至少字节数
int[] arrColWidth = new int[headList.size()];
int minBytes = 17;//至少字节数
int[] arrColWidth = new int[headerList.size()];
// 产生表格标题行,以及设置列宽
String[] headers = new String[headList.size()];
String[] headers = new String[headerList.size()];
int ii = 0;
for (int i = 0; i < headList.size(); i++) {
for (int i = 0; i < headerList.size(); i++) {
headers[ii] = headList.get(i);
headers[ii] = headerList.get(i);
int bytes = headList.get(i).getBytes().length;
int bytes = headerList.get(i).getBytes().length;
arrColWidth[ii] = bytes < minBytes ? minBytes : bytes;
sheet.setColumnWidth(ii, arrColWidth[ii] * 256);
ii++;
}
//第二行
int[] secondWidth = new int[2];
// 产生表格标题行,以及设置列宽
String[] secondHead = new String[2];
List<String> secondList = Arrays.asList(new String[]{"培训实施单位:" + companyName, "培训时间:" + studyDate});
//第三行
int[] thirdWidth = new int[2];
// 产生表格标题行,以及设置列宽
String[] thirdHead = new String[2];
List<String> thirdList = Arrays.asList(new String[]{"培训项目:" + courseName, "培训平台:有课互联系统"});
ii = 0;
for (int i = 0; i < 2; i++) {
secondHead[ii] = secondList.get(i);
int bytes = secondList.get(i).getBytes().length;
secondWidth[ii] = bytes < minBytes ? minBytes : bytes;
sheet.setColumnWidth(ii, secondWidth[ii] * 256);
ii++;
}
ii = 0;
for (int i = 0; i < 2; i++) {
thirdHead[ii] = thirdList.get(i);
int bytes = thirdList.get(i).getBytes().length;
thirdWidth[ii] = bytes < minBytes ? minBytes : bytes;
sheet.setColumnWidth(ii, thirdWidth[ii] * 256);
ii++;
}
// 遍历集合数据,产生数据行
//标题 0
SXSSFRow titleRow = sheet.createRow(0);//表头 rowIndex=0
titleRow.createCell(0).setCellValue(title);
setBorderStyle(HSSFCellStyle.BORDER_THIN, new CellRangeAddress(0, 0, 0, 0), sheet, workbook); //给合并过的单元格加边框
titleRow.getCell(0).setCellStyle(titleStyle);
sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, headList.size() - 1));
sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, headerList.size() - 1));
//第二行 1
SXSSFRow secondRow = sheet.createRow(1); //第二行 rowIndex =1
CellRangeAddress cellRangeAddress21 = new CellRangeAddress(1, 1, 0, 4);
sheet.addMergedRegion(cellRangeAddress21);
setBorderStyle(HSSFCellStyle.BORDER_THIN, cellRangeAddress21, sheet, workbook); //给合并过的单元格加边框
CellRangeAddress cellRangeAddress22 = new CellRangeAddress(1, 1, 5, 10);
sheet.addMergedRegion(cellRangeAddress22);
setBorderStyle(HSSFCellStyle.BORDER_THIN, cellRangeAddress22, sheet, workbook); //给合并过的单元格加边框
secondRow.createCell(0).setCellValue(secondHead[0]);
secondRow.getCell(0).setCellStyle(secondStyle);
SXSSFRow headerRow = sheet.createRow(1); //列头 rowIndex =1
secondRow.createCell(5).setCellValue(secondHead[1]);
secondRow.getCell(5).setCellStyle(secondStyle);
//第三行 2
SXSSFRow thirdRow = sheet.createRow(2); //第二行 rowIndex =1
CellRangeAddress cellRangeAddress31 = new CellRangeAddress(2, 2, 0, 4);
sheet.addMergedRegion(cellRangeAddress31);
setBorderStyle(HSSFCellStyle.BORDER_THIN, cellRangeAddress31, sheet, workbook); //给合并过的单元格加边框
CellRangeAddress cellRangeAddress32 = new CellRangeAddress(2, 2, 5, 10);
sheet.addMergedRegion(cellRangeAddress32);
setBorderStyle(HSSFCellStyle.BORDER_THIN, cellRangeAddress32, sheet, workbook); //给合并过的单元格加边框
thirdRow.createCell(0).setCellValue(thirdHead[0]);
thirdRow.getCell(0).setCellStyle(thirdStyle);
thirdRow.createCell(5).setCellValue(thirdHead[1]);
thirdRow.getCell(5).setCellStyle(thirdStyle);
//标题 3
SXSSFRow headerRow = sheet.createRow(3); //列头 rowIndex =1
for (int i = 0; i < headers.length; i++) {
headerRow.createCell(i).setCellValue(headers[i]);
headerRow.getCell(i).setCellStyle(headerStyle);
}
int seq = 1;
//内容
int rowIndex = 0;
for (ClassDetailVO classDetailVO : classDetailVOS) {
if (rowIndex == 65535 || rowIndex == 0) {
if (rowIndex != 0) {
sheet = workbook.createSheet();//如果数据超过了,则在第二页显示
}
rowIndex = 2;//数据内容从 rowIndex=2开始
rowIndex = 4;//数据内容从 rowIndex=2开始
}
SXSSFRow dataRow = sheet.createRow(rowIndex);
SXSSFCell newCell = dataRow.createCell(0);
cellStyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
newCell.setCellStyle(cellStyle);
newCell.setCellValue(classDetailVO.getUserName());
newCell.setCellValue(seq);
newCell = dataRow.createCell(1);
newCell.setCellValue(classDetailVO.getAccountName());
newCell.setCellStyle(cellStyle);
newCell.setCellValue(classDetailVO.getUserName());
newCell = dataRow.createCell(2);
newCell.setCellValue(classDetailVO.getTelephone());
newCell.setCellStyle(cellStyle);
newCell.setCellValue(classDetailVO.getIdCard());
newCell = dataRow.createCell(3);
newCell.setCellValue(classDetailVO.getSignCounts());
newCell.setCellStyle(cellStyle);
newCell.setCellValue(classDetailVO.getAccountName());
newCell = dataRow.createCell(4);
newCell.setCellValue(classDetailVO.getClassProcess());
newCell.setCellStyle(cellStyle);
newCell.setCellValue(classDetailVO.getTelephone());
newCell = dataRow.createCell(5);
newCell.setCellValue(classDetailVO.getTrainingLength());
newCell.setCellStyle(cellStyle);
newCell.setCellValue(classDetailVO.getSignCounts());
newCell = dataRow.createCell(6);
newCell.setCellValue(classDetailVO.getScore());
newCell.setCellStyle(cellStyle);
newCell.setCellValue(classDetailVO.getClassProcess());
newCell = dataRow.createCell(7);
newCell.setCellStyle(cellStyle);
newCell.setCellValue(classDetailVO.getTrainingLength());
newCell = dataRow.createCell(8);
newCell.setCellStyle(cellStyle);
newCell.setCellValue(classDetailVO.getAskCounts());
newCell = dataRow.createCell(9);
newCell.setCellStyle(cellStyle);
newCell.setCellValue(classDetailVO.getScore());
newCell = dataRow.createCell(10);
newCell.setCellStyle(cellStyle);
if (classDetailVO.getScore() >= 60) {
newCell.setCellValue("合格");
} else {
newCell.setCellValue("不合格");
}
rowIndex++;
seq++;
}
// 自动调整宽度
/*for (int i = 0; i < headers.length; i++) {
sheet.autoSizeColumn(i);
}*/
try {
workbook.write(out);
workbook.close();
......@@ -843,107 +1007,208 @@ public class AdministerServiceImpl extends ServiceImpl<AdministerMapper, Adminis
}
}
public static void signListExcel(String title, List<String> headList, List<ClassSignVO> classSignVOS, String datePattern, int colWidth, OutputStream out) {
if (datePattern == null) {
datePattern = "yyyy年MM月dd日";
}
public static void signListExcel(String companyName, String studyDate, String courseName, String title, List<String> headerList, List<ClassSignVO> classSignVOS, String datePattern, int colWidth, OutputStream out) {
// 声明一个工作薄
SXSSFWorkbook workbook = new SXSSFWorkbook(1000);//缓存
workbook.setCompressTempFiles(true);
//表头样式
CellStyle titleStyle = workbook.createCellStyle();
titleStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER);
setStyle(titleStyle);
Font titleFont = workbook.createFont();
titleFont.setFontHeightInPoints((short) 20);
titleFont.setBoldweight((short) 700);
titleStyle.setFont(titleFont);
//第二行
CellStyle secondStyle = workbook.createCellStyle();
secondStyle.setBorderBottom(HSSFCellStyle.BORDER_THIN); //下边框
secondStyle.setBorderLeft(HSSFCellStyle.BORDER_THIN);//左边框
secondStyle.setBorderTop(HSSFCellStyle.BORDER_THIN);//上边框
secondStyle.setBorderRight(HSSFCellStyle.BORDER_THIN);//右边框
secondStyle.setAlignment(HSSFCellStyle.ALIGN_LEFT);
Font secondFont = workbook.createFont();
secondStyle.setFont(secondFont);
//第三行
CellStyle thirdStyle = workbook.createCellStyle();
thirdStyle.setBorderBottom(HSSFCellStyle.BORDER_THIN); //下边框
thirdStyle.setBorderLeft(HSSFCellStyle.BORDER_THIN);//左边框
thirdStyle.setBorderTop(HSSFCellStyle.BORDER_THIN);//上边框
thirdStyle.setBorderRight(HSSFCellStyle.BORDER_THIN);//右边框
secondStyle.setAlignment(HSSFCellStyle.ALIGN_LEFT);
Font thirdFont = workbook.createFont();
thirdStyle.setFont(thirdFont);
// 列头样式
CellStyle headerStyle = workbook.createCellStyle();
//headerStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
//headerStyle.setBorderBottom(HSSFCellStyle.BORDER_THIN);
//headerStyle.setBorderLeft(HSSFCellStyle.BORDER_THIN);
//headerStyle.setBorderRight(HSSFCellStyle.BORDER_THIN);
//headerStyle.setBorderTop(HSSFCellStyle.BORDER_THIN);
//headerStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER);
setStyle(headerStyle);
Font headerFont = workbook.createFont();
headerFont.setFontHeightInPoints((short) 12);
headerFont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
headerFont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);//粗体显示
headerStyle.setFont(headerFont);
// 单元格样式
// 数据单元格样式
CellStyle cellStyle = workbook.createCellStyle();
//cellStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
//cellStyle.setBorderBottom(HSSFCellStyle.BORDER_THIN);
//cellStyle.setBorderLeft(HSSFCellStyle.BORDER_THIN);
//cellStyle.setBorderRight(HSSFCellStyle.BORDER_THIN);
//cellStyle.setBorderTop(HSSFCellStyle.BORDER_THIN);
//cellStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER);
//cellStyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
setStyle(cellStyle);
Font cellFont = workbook.createFont();
cellFont.setBoldweight(HSSFFont.BOLDWEIGHT_NORMAL);
cellStyle.setFont(cellFont);
// 生成一个(带标题)表格
SXSSFSheet sheet = workbook.createSheet();
//设置列宽
int minBytes = colWidth < 17 ? 17 : colWidth;//至少字节数
int[] arrColWidth = new int[headList.size()];
int minBytes = 17;//至少字节数
int[] arrColWidth = new int[headerList.size()];
// 产生表格标题行,以及设置列宽
String[] headers = new String[headList.size()];
String[] headers = new String[headerList.size()];
int ii = 0;
for (int i = 0; i < headList.size(); i++) {
for (int i = 0; i < headerList.size(); i++) {
headers[ii] = headList.get(i);
headers[ii] = headerList.get(i);
int bytes = headList.get(i).getBytes().length;
int bytes = headerList.get(i).getBytes().length;
arrColWidth[ii] = bytes < minBytes ? minBytes : bytes;
sheet.setColumnWidth(ii, arrColWidth[ii] * 256);
ii++;
}
//第二行
int[] secondWidth = new int[2];
// 产生表格标题行,以及设置列宽
String[] secondHead = new String[2];
List<String> secondList = Arrays.asList(new String[]{"培训实施单位:" + companyName, "培训时间:" + studyDate});
//第三行
int[] thirdWidth = new int[2];
// 产生表格标题行,以及设置列宽
String[] thirdHead = new String[2];
List<String> thirdList = Arrays.asList(new String[]{"培训项目:" + courseName, "培训平台:有课互联系统"});
ii = 0;
for (int i = 0; i < 2; i++) {
secondHead[ii] = secondList.get(i);
int bytes = secondList.get(i).getBytes().length;
secondWidth[ii] = bytes < minBytes ? minBytes : bytes;
sheet.setColumnWidth(ii, secondWidth[ii] * 256);
ii++;
}
ii = 0;
for (int i = 0; i < 2; i++) {
thirdHead[ii] = thirdList.get(i);
int bytes = thirdList.get(i).getBytes().length;
thirdWidth[ii] = bytes < minBytes ? minBytes : bytes;
sheet.setColumnWidth(ii, thirdWidth[ii] * 256);
ii++;
}
// 遍历集合数据,产生数据行
int rowIndex = 0;
//标题 0
SXSSFRow titleRow = sheet.createRow(0);//表头 rowIndex=0
titleRow.createCell(0).setCellValue(title);
setBorderStyle(HSSFCellStyle.BORDER_THIN, new CellRangeAddress(0, 0, 0, 0), sheet, workbook); //给合并过的单元格加边框
titleRow.getCell(0).setCellStyle(titleStyle);
sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, headList.size() - 1));
sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, headerList.size() - 1));
//第二行 1
SXSSFRow secondRow = sheet.createRow(1); //第二行 rowIndex =1
CellRangeAddress cellRangeAddress21 = new CellRangeAddress(1, 1, 0, 3);
sheet.addMergedRegion(cellRangeAddress21);
setBorderStyle(HSSFCellStyle.BORDER_THIN, cellRangeAddress21, sheet, workbook); //给合并过的单元格加边框
CellRangeAddress cellRangeAddress22 = new CellRangeAddress(1, 1, 4, 8);
sheet.addMergedRegion(cellRangeAddress22);
setBorderStyle(HSSFCellStyle.BORDER_THIN, cellRangeAddress22, sheet, workbook); //给合并过的单元格加边框
secondRow.createCell(0).setCellValue(secondHead[0]);
secondRow.getCell(0).setCellStyle(secondStyle);
secondRow.createCell(4).setCellValue(secondHead[1]);
secondRow.getCell(4).setCellStyle(secondStyle);
SXSSFRow headerRow = sheet.createRow(1); //列头 rowIndex =1
//第三行 2
SXSSFRow thirdRow = sheet.createRow(2); //第二行 rowIndex =1
CellRangeAddress cellRangeAddress31 = new CellRangeAddress(2, 2, 0, 3);
sheet.addMergedRegion(cellRangeAddress31);
setBorderStyle(HSSFCellStyle.BORDER_THIN, cellRangeAddress31, sheet, workbook); //给合并过的单元格加边框
CellRangeAddress cellRangeAddress32 = new CellRangeAddress(2, 2, 4, 8);
sheet.addMergedRegion(cellRangeAddress32);
setBorderStyle(HSSFCellStyle.BORDER_THIN, cellRangeAddress32, sheet, workbook); //给合并过的单元格加边框
thirdRow.createCell(0).setCellValue(thirdHead[0]);
thirdRow.getCell(0).setCellStyle(thirdStyle);
thirdRow.createCell(4).setCellValue(thirdHead[1]);
thirdRow.getCell(4).setCellStyle(thirdStyle);
//标题 3
SXSSFRow headerRow = sheet.createRow(3); //列头 rowIndex =1
for (int i = 0; i < headers.length; i++) {
headerRow.createCell(i).setCellValue(headers[i]);
headerRow.getCell(i).setCellStyle(headerStyle);
}
int seq = 1;
//内容
int rowIndex = 0;
for (ClassSignVO classSignVO : classSignVOS) {
if (rowIndex == 65535 || rowIndex == 0) {
if (rowIndex != 0) {
sheet = workbook.createSheet();//如果数据超过了,则在第二页显示
}
rowIndex = 2;//数据内容从 rowIndex=2开始
rowIndex = 4;//数据内容从 rowIndex=2开始
}
SXSSFRow dataRow = sheet.createRow(rowIndex);
SXSSFCell newCell = dataRow.createCell(0);
cellStyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
newCell.setCellStyle(cellStyle);
newCell.setCellValue(classSignVO.getUserName());
newCell.setCellValue(seq);
newCell = dataRow.createCell(1);
newCell.setCellValue(classSignVO.getSignCounts());
newCell.setCellStyle(cellStyle);
newCell.setCellValue(classSignVO.getUserName());
newCell = dataRow.createCell(2);
newCell.setCellValue(classSignVO.getTrainingLength());
newCell.setCellStyle(cellStyle);
newCell.setCellValue(classSignVO.getIdCard());
newCell = dataRow.createCell(3);
newCell.setCellValue(classSignVO.getClassProcess());
newCell.setCellStyle(cellStyle);
newCell.setCellValue(classSignVO.getTelephone());
newCell = dataRow.createCell(4);
newCell.setCellStyle(cellStyle);
newCell.setCellValue(classSignVO.getTrainingLength());
newCell = dataRow.createCell(5);
newCell.setCellStyle(cellStyle);
newCell.setCellValue(classSignVO.getClassProcess());
newCell = dataRow.createCell(6);
newCell.setCellStyle(cellStyle);
newCell.setCellValue(classSignVO.getPercent());
newCell = dataRow.createCell(7);
newCell.setCellStyle(cellStyle);
newCell.setCellValue(classSignVO.getSignCounts());
newCell = dataRow.createCell(8);
newCell.setCellStyle(cellStyle);
newCell.setCellValue(classSignVO.getSignInDateList());
rowIndex++;
seq++;
}
// 自动调整宽度
/*for (int i = 0; i < headers.length; i++) {
sheet.autoSizeColumn(i);
}*/
try {
workbook.write(out);
workbook.close();
......@@ -953,100 +1218,207 @@ public class AdministerServiceImpl extends ServiceImpl<AdministerMapper, Adminis
}
}
public static void testListExcel(String title, List<String> headList, List<ExerciseTestVO> exerciseTestVOS, String datePattern, int colWidth, OutputStream out) {
if (datePattern == null) {
datePattern = "yyyy年MM月dd日";
}
public static void testListExcel(String companyName, String studyDate, String courseName, String title, List<String> headerList, List<ExerciseTestVO> exerciseTestVOS, String datePattern, int colWidth, OutputStream out) {
// 声明一个工作薄
SXSSFWorkbook workbook = new SXSSFWorkbook(1000);//缓存
workbook.setCompressTempFiles(true);
//表头样式
CellStyle titleStyle = workbook.createCellStyle();
titleStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER);
setStyle(titleStyle);
Font titleFont = workbook.createFont();
titleFont.setFontHeightInPoints((short) 20);
titleFont.setBoldweight((short) 700);
titleStyle.setFont(titleFont);
//第二行
CellStyle secondStyle = workbook.createCellStyle();
secondStyle.setBorderBottom(HSSFCellStyle.BORDER_THIN); //下边框
secondStyle.setBorderLeft(HSSFCellStyle.BORDER_THIN);//左边框
secondStyle.setBorderTop(HSSFCellStyle.BORDER_THIN);//上边框
secondStyle.setBorderRight(HSSFCellStyle.BORDER_THIN);//右边框
secondStyle.setAlignment(HSSFCellStyle.ALIGN_LEFT);
Font secondFont = workbook.createFont();
secondStyle.setFont(secondFont);
//第三行
CellStyle thirdStyle = workbook.createCellStyle();
thirdStyle.setBorderBottom(HSSFCellStyle.BORDER_THIN); //下边框
thirdStyle.setBorderLeft(HSSFCellStyle.BORDER_THIN);//左边框
thirdStyle.setBorderTop(HSSFCellStyle.BORDER_THIN);//上边框
thirdStyle.setBorderRight(HSSFCellStyle.BORDER_THIN);//右边框
secondStyle.setAlignment(HSSFCellStyle.ALIGN_LEFT);
Font thirdFont = workbook.createFont();
thirdStyle.setFont(thirdFont);
// 列头样式
CellStyle headerStyle = workbook.createCellStyle();
//headerStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
//headerStyle.setBorderBottom(HSSFCellStyle.BORDER_THIN);
//headerStyle.setBorderLeft(HSSFCellStyle.BORDER_THIN);
//headerStyle.setBorderRight(HSSFCellStyle.BORDER_THIN);
//headerStyle.setBorderTop(HSSFCellStyle.BORDER_THIN);
//headerStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER);
setStyle(headerStyle);
Font headerFont = workbook.createFont();
headerFont.setFontHeightInPoints((short) 12);
headerFont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
headerFont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);//粗体显示
headerStyle.setFont(headerFont);
// 单元格样式
// 数据单元格样式
CellStyle cellStyle = workbook.createCellStyle();
//cellStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
//cellStyle.setBorderBottom(HSSFCellStyle.BORDER_THIN);
//cellStyle.setBorderLeft(HSSFCellStyle.BORDER_THIN);
//cellStyle.setBorderRight(HSSFCellStyle.BORDER_THIN);
//cellStyle.setBorderTop(HSSFCellStyle.BORDER_THIN);
//cellStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER);
//cellStyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
setStyle(cellStyle);
Font cellFont = workbook.createFont();
cellFont.setBoldweight(HSSFFont.BOLDWEIGHT_NORMAL);
cellStyle.setFont(cellFont);
// 生成一个(带标题)表格
SXSSFSheet sheet = workbook.createSheet();
//设置列宽
int minBytes = colWidth < 17 ? 17 : colWidth;//至少字节数
int[] arrColWidth = new int[headList.size()];
int minBytes = 17;//至少字节数
int[] arrColWidth = new int[headerList.size()];
// 产生表格标题行,以及设置列宽
String[] headers = new String[headList.size()];
String[] headers = new String[headerList.size()];
int ii = 0;
for (int i = 0; i < headList.size(); i++) {
for (int i = 0; i < headerList.size(); i++) {
headers[ii] = headList.get(i);
headers[ii] = headerList.get(i);
int bytes = headList.get(i).getBytes().length;
int bytes = headerList.get(i).getBytes().length;
arrColWidth[ii] = bytes < minBytes ? minBytes : bytes;
sheet.setColumnWidth(ii, arrColWidth[ii] * 256);
ii++;
}
// 遍历集合数据,产生数据行
int rowIndex = 0;
for (ExerciseTestVO exerciseTestVO : exerciseTestVOS) {
if (rowIndex == 65535 || rowIndex == 0) {
if (rowIndex != 0) {
sheet = workbook.createSheet();//如果数据超过了,则在第二页显示
//第二行
int[] secondWidth = new int[2];
// 产生表格标题行,以及设置列宽
String[] secondHead = new String[2];
List<String> secondList = Arrays.asList(new String[]{"培训实施单位:" + companyName, "培训时间:" + studyDate});
//第三行
int[] thirdWidth = new int[2];
// 产生表格标题行,以及设置列宽
String[] thirdHead = new String[2];
List<String> thirdList = Arrays.asList(new String[]{"培训项目:" + courseName, "培训平台:有课互联系统"});
ii = 0;
for (int i = 0; i < 2; i++) {
secondHead[ii] = secondList.get(i);
int bytes = secondList.get(i).getBytes().length;
secondWidth[ii] = bytes < minBytes ? minBytes : bytes;
sheet.setColumnWidth(ii, secondWidth[ii] * 256);
ii++;
}
ii = 0;
for (int i = 0; i < 2; i++) {
thirdHead[ii] = thirdList.get(i);
int bytes = thirdList.get(i).getBytes().length;
thirdWidth[ii] = bytes < minBytes ? minBytes : bytes;
sheet.setColumnWidth(ii, thirdWidth[ii] * 256);
ii++;
}
// 遍历集合数据,产生数据行
//标题 0
SXSSFRow titleRow = sheet.createRow(0);//表头 rowIndex=0
titleRow.createCell(0).setCellValue(title);
setBorderStyle(HSSFCellStyle.BORDER_THIN, new CellRangeAddress(0, 0, 0, 0), sheet, workbook); //给合并过的单元格加边框
titleRow.getCell(0).setCellStyle(titleStyle);
sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, headList.size() - 1));
sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, headerList.size() - 1));
//第二行 1
SXSSFRow secondRow = sheet.createRow(1); //第二行 rowIndex =1
CellRangeAddress cellRangeAddress21 = new CellRangeAddress(1, 1, 0, 3);
sheet.addMergedRegion(cellRangeAddress21);
setBorderStyle(HSSFCellStyle.BORDER_THIN, cellRangeAddress21, sheet, workbook); //给合并过的单元格加边框
CellRangeAddress cellRangeAddress22 = new CellRangeAddress(1, 1, 4, 6);
sheet.addMergedRegion(cellRangeAddress22);
setBorderStyle(HSSFCellStyle.BORDER_THIN, cellRangeAddress22, sheet, workbook); //给合并过的单元格加边框
SXSSFRow headerRow = sheet.createRow(1); //列头 rowIndex =1
secondRow.createCell(0).setCellValue(secondHead[0]);
secondRow.getCell(0).setCellStyle(secondStyle);
secondRow.createCell(4).setCellValue(secondHead[1]);
secondRow.getCell(4).setCellStyle(secondStyle);
//第三行 2
SXSSFRow thirdRow = sheet.createRow(2); //第二行 rowIndex =1
CellRangeAddress cellRangeAddress31 = new CellRangeAddress(2, 2, 0, 3);
sheet.addMergedRegion(cellRangeAddress31);
setBorderStyle(HSSFCellStyle.BORDER_THIN, cellRangeAddress31, sheet, workbook); //给合并过的单元格加边框
CellRangeAddress cellRangeAddress32 = new CellRangeAddress(2, 2, 4, 6);
sheet.addMergedRegion(cellRangeAddress32);
setBorderStyle(HSSFCellStyle.BORDER_THIN, cellRangeAddress32, sheet, workbook); //给合并过的单元格加边框
thirdRow.createCell(0).setCellValue(thirdHead[0]);
thirdRow.getCell(0).setCellStyle(thirdStyle);
thirdRow.createCell(4).setCellValue(thirdHead[1]);
thirdRow.getCell(4).setCellStyle(thirdStyle);
//标题 3
SXSSFRow headerRow = sheet.createRow(3); //列头 rowIndex =1
for (int i = 0; i < headers.length; i++) {
headerRow.createCell(i).setCellValue(headers[i]);
headerRow.getCell(i).setCellStyle(headerStyle);
}
int seq = 1;
//内容
int rowIndex = 0;
for (ExerciseTestVO exerciseTestVO : exerciseTestVOS) {
if (rowIndex == 65535 || rowIndex == 0) {
if (rowIndex != 0) {
sheet = workbook.createSheet();//如果数据超过了,则在第二页显示
}
rowIndex = 2;//数据内容从 rowIndex=2开始
rowIndex = 4;//数据内容从 rowIndex=2开始
}
SXSSFRow dataRow = sheet.createRow(rowIndex);
SXSSFCell newCell = dataRow.createCell(0);
cellStyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
newCell.setCellStyle(cellStyle);
newCell.setCellValue(exerciseTestVO.getUserName());
newCell.setCellValue(seq);
newCell = dataRow.createCell(1);
newCell.setCellValue(exerciseTestVO.getResult());
newCell.setCellStyle(cellStyle);
newCell.setCellValue(exerciseTestVO.getUserName());
newCell = dataRow.createCell(2);
newCell.setCellStyle(cellStyle);
newCell.setCellValue(exerciseTestVO.getIdCard());
newCell = dataRow.createCell(3);
newCell.setCellStyle(cellStyle);
newCell.setCellValue(exerciseTestVO.getTelephone());
newCell = dataRow.createCell(4);
newCell.setCellStyle(cellStyle);
newCell.setCellValue(exerciseTestVO.getScore());
//次数
newCell = dataRow.createCell(5);
newCell.setCellStyle(cellStyle);
if (exerciseTestVO.getScore()!=0){
newCell.setCellValue(1);
}else {
newCell.setCellValue(0);
}
newCell = dataRow.createCell(6);
newCell.setCellStyle(cellStyle);
if (exerciseTestVO.getScore()>=60){
newCell.setCellValue("合格");
}else {
newCell.setCellValue("不合格");
}
rowIndex++;
seq++;
}
// 自动调整宽度
/*for (int i = 0; i < headers.length; i++) {
sheet.autoSizeColumn(i);
}*/
try {
workbook.write(out);
workbook.close();
......@@ -1056,107 +1428,194 @@ public class AdministerServiceImpl extends ServiceImpl<AdministerMapper, Adminis
}
}
public static void askListExcel(String title, List<String> headList, List<AnswerRecordVO> answerRecordVOS, String datePattern, int colWidth, OutputStream out) {
if (datePattern == null) {
datePattern = "yyyy年MM月dd日";
}
public static void askListExcel(String companyName, String studyDate, String courseName,String title, List<String> headerList, List<AnswerRecordVO> answerRecordVOS, String datePattern, int colWidth, OutputStream out) {
// 声明一个工作薄
SXSSFWorkbook workbook = new SXSSFWorkbook(1000);//缓存
workbook.setCompressTempFiles(true);
//表头样式
CellStyle titleStyle = workbook.createCellStyle();
titleStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER);
setStyle(titleStyle);
Font titleFont = workbook.createFont();
titleFont.setFontHeightInPoints((short) 20);
titleFont.setBoldweight((short) 700);
titleStyle.setFont(titleFont);
//第二行
CellStyle secondStyle = workbook.createCellStyle();
secondStyle.setBorderBottom(HSSFCellStyle.BORDER_THIN); //下边框
secondStyle.setBorderLeft(HSSFCellStyle.BORDER_THIN);//左边框
secondStyle.setBorderTop(HSSFCellStyle.BORDER_THIN);//上边框
secondStyle.setBorderRight(HSSFCellStyle.BORDER_THIN);//右边框
secondStyle.setAlignment(HSSFCellStyle.ALIGN_LEFT);
Font secondFont = workbook.createFont();
secondStyle.setFont(secondFont);
//第三行
CellStyle thirdStyle = workbook.createCellStyle();
thirdStyle.setBorderBottom(HSSFCellStyle.BORDER_THIN); //下边框
thirdStyle.setBorderLeft(HSSFCellStyle.BORDER_THIN);//左边框
thirdStyle.setBorderTop(HSSFCellStyle.BORDER_THIN);//上边框
thirdStyle.setBorderRight(HSSFCellStyle.BORDER_THIN);//右边框
secondStyle.setAlignment(HSSFCellStyle.ALIGN_LEFT);
Font thirdFont = workbook.createFont();
thirdStyle.setFont(thirdFont);
// 列头样式
CellStyle headerStyle = workbook.createCellStyle();
//headerStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
//headerStyle.setBorderBottom(HSSFCellStyle.BORDER_THIN);
//headerStyle.setBorderLeft(HSSFCellStyle.BORDER_THIN);
//headerStyle.setBorderRight(HSSFCellStyle.BORDER_THIN);
//headerStyle.setBorderTop(HSSFCellStyle.BORDER_THIN);
//headerStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER);
setStyle(headerStyle);
Font headerFont = workbook.createFont();
headerFont.setFontHeightInPoints((short) 12);
headerFont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
headerFont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);//粗体显示
headerStyle.setFont(headerFont);
// 单元格样式
// 数据单元格样式
CellStyle cellStyle = workbook.createCellStyle();
//cellStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
//cellStyle.setBorderBottom(HSSFCellStyle.BORDER_THIN);
//cellStyle.setBorderLeft(HSSFCellStyle.BORDER_THIN);
//cellStyle.setBorderRight(HSSFCellStyle.BORDER_THIN);
//cellStyle.setBorderTop(HSSFCellStyle.BORDER_THIN);
//cellStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER);
//cellStyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
setStyle(cellStyle);
Font cellFont = workbook.createFont();
cellFont.setBoldweight(HSSFFont.BOLDWEIGHT_NORMAL);
cellStyle.setFont(cellFont);
// 生成一个(带标题)表格
SXSSFSheet sheet = workbook.createSheet();
//设置列宽
int minBytes = colWidth < 17 ? 17 : colWidth;//至少字节数
int[] arrColWidth = new int[headList.size()];
int minBytes = 17;//至少字节数
int[] arrColWidth = new int[headerList.size()];
// 产生表格标题行,以及设置列宽
String[] headers = new String[headList.size()];
String[] headers = new String[headerList.size()];
int ii = 0;
for (int i = 0; i < headList.size(); i++) {
for (int i = 0; i < headerList.size(); i++) {
headers[ii] = headList.get(i);
headers[ii] = headerList.get(i);
int bytes = headList.get(i).getBytes().length;
int bytes = headerList.get(i).getBytes().length;
arrColWidth[ii] = bytes < minBytes ? minBytes : bytes;
sheet.setColumnWidth(ii, arrColWidth[ii] * 256);
ii++;
}
//第二行
int[] secondWidth = new int[2];
// 产生表格标题行,以及设置列宽
String[] secondHead = new String[2];
List<String> secondList = Arrays.asList(new String[]{"培训实施单位:" + companyName, "培训时间:" + studyDate});
//第三行
int[] thirdWidth = new int[2];
// 产生表格标题行,以及设置列宽
String[] thirdHead = new String[2];
List<String> thirdList = Arrays.asList(new String[]{"培训项目:" + courseName, "培训平台:有课互联系统"});
ii = 0;
for (int i = 0; i < 2; i++) {
secondHead[ii] = secondList.get(i);
int bytes = secondList.get(i).getBytes().length;
secondWidth[ii] = bytes < minBytes ? minBytes : bytes;
sheet.setColumnWidth(ii, secondWidth[ii] * 256);
ii++;
}
ii = 0;
for (int i = 0; i < 2; i++) {
thirdHead[ii] = thirdList.get(i);
int bytes = thirdList.get(i).getBytes().length;
thirdWidth[ii] = bytes < minBytes ? minBytes : bytes;
sheet.setColumnWidth(ii, thirdWidth[ii] * 256);
ii++;
}
// 遍历集合数据,产生数据行
int rowIndex = 0;
//标题 0
SXSSFRow titleRow = sheet.createRow(0);//表头 rowIndex=0
titleRow.createCell(0).setCellValue(title);
setBorderStyle(HSSFCellStyle.BORDER_THIN, new CellRangeAddress(0, 0, 0, 0), sheet, workbook); //给合并过的单元格加边框
titleRow.getCell(0).setCellStyle(titleStyle);
sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, headList.size() - 1));
sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, headerList.size() - 1));
//第二行 1
SXSSFRow secondRow = sheet.createRow(1); //第二行 rowIndex =1
CellRangeAddress cellRangeAddress21 = new CellRangeAddress(1, 1, 0, 2);
sheet.addMergedRegion(cellRangeAddress21);
setBorderStyle(HSSFCellStyle.BORDER_THIN, cellRangeAddress21, sheet, workbook); //给合并过的单元格加边框
SXSSFRow headerRow = sheet.createRow(1); //列头 rowIndex =1
CellRangeAddress cellRangeAddress22 = new CellRangeAddress(1, 1, 3, 5);
sheet.addMergedRegion(cellRangeAddress22);
setBorderStyle(HSSFCellStyle.BORDER_THIN, cellRangeAddress22, sheet, workbook); //给合并过的单元格加边框
secondRow.createCell(0).setCellValue(secondHead[0]);
secondRow.getCell(0).setCellStyle(secondStyle);
secondRow.createCell(3).setCellValue(secondHead[1]);
secondRow.getCell(3).setCellStyle(secondStyle);
//第三行 2
SXSSFRow thirdRow = sheet.createRow(2); //第二行 rowIndex =1
CellRangeAddress cellRangeAddress31 = new CellRangeAddress(2, 2, 0, 2);
sheet.addMergedRegion(cellRangeAddress31);
setBorderStyle(HSSFCellStyle.BORDER_THIN, cellRangeAddress31, sheet, workbook); //给合并过的单元格加边框
CellRangeAddress cellRangeAddress32 = new CellRangeAddress(2, 2, 3,5);
sheet.addMergedRegion(cellRangeAddress32);
setBorderStyle(HSSFCellStyle.BORDER_THIN, cellRangeAddress32, sheet, workbook); //给合并过的单元格加边框
thirdRow.createCell(0).setCellValue(thirdHead[0]);
thirdRow.getCell(0).setCellStyle(thirdStyle);
thirdRow.createCell(3).setCellValue(thirdHead[1]);
thirdRow.getCell(3).setCellStyle(thirdStyle);
//标题 3
SXSSFRow headerRow = sheet.createRow(3); //列头 rowIndex =1
for (int i = 0; i < headers.length; i++) {
headerRow.createCell(i).setCellValue(headers[i]);
headerRow.getCell(i).setCellStyle(headerStyle);
}
int seq = 1;
//内容
int rowIndex = 0;
for (AnswerRecordVO answerRecordVO : answerRecordVOS) {
if (rowIndex == 65535 || rowIndex == 0) {
if (rowIndex != 0) {
sheet = workbook.createSheet();//如果数据超过了,则在第二页显示
}
rowIndex = 2;//数据内容从 rowIndex=2开始
rowIndex = 4;//数据内容从 rowIndex=2开始
}
SXSSFRow dataRow = sheet.createRow(rowIndex);
SXSSFCell newCell = dataRow.createCell(0);
cellStyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
newCell.setCellStyle(cellStyle);
newCell.setCellValue(answerRecordVO.getTitle());
newCell.setCellValue(seq);
newCell = dataRow.createCell(1);
newCell.setCellValue(answerRecordVO.getAnswer());
newCell.setCellStyle(cellStyle);
newCell.setCellValue(answerRecordVO.getTitle());
newCell = dataRow.createCell(2);
newCell.setCellValue(answerRecordVO.getCreateDate());
newCell.setCellStyle(cellStyle);
newCell.setCellValue(answerRecordVO.getAnswer());
newCell = dataRow.createCell(3);
newCell.setCellValue(answerRecordVO.getUserName());
newCell.setCellStyle(cellStyle);
newCell.setCellValue(answerRecordVO.getCreateDate());
newCell = dataRow.createCell(4);
newCell.setCellStyle(cellStyle);
newCell.setCellValue(answerRecordVO.getUserName());
//次数
newCell = dataRow.createCell(5);
newCell.setCellStyle(cellStyle);
newCell.setCellValue(answerRecordVO.getUpdateDate());
rowIndex++;
seq++;
}
// 自动调整宽度
/*for (int i = 0; i < headers.length; i++) {
sheet.autoSizeColumn(i);
}*/
try {
workbook.write(out);
workbook.close();
......@@ -1200,4 +1659,49 @@ public class AdministerServiceImpl extends ServiceImpl<AdministerMapper, Adminis
}
}
//也可用以下方法
public static void setBorderStyle(int border, CellRangeAddress region, SXSSFSheet sheet, SXSSFWorkbook wb) {
CellStyle cs = wb.createCellStyle(); // 样式对象
cs.setBorderBottom((short) border);
cs.setBorderTop((short) border);
cs.setBorderLeft((short) border);
cs.setBorderRight((short) border);
setRegionStyle(cs, region, sheet);
}
private static void setRegionStyle(CellStyle cs, CellRangeAddress region, SXSSFSheet sheet) {
for (int i = region.getFirstRow(); i <= region.getLastRow(); i++) {
SXSSFRow row = sheet.getRow(i);
if (row == null) {
row = sheet.createRow(i);
}
for (int j = region.getFirstColumn(); j <= region.getLastColumn(); j++) {
SXSSFCell cell = row.getCell(j);
if (cell == null) {
cell = row.createCell(j);
cell.setCellValue("");
}
cell.setCellStyle(cs);
}
}
}
private static void setStyle(CellStyle cellStyle) {
// 水平居中
cellStyle.setAlignment(CellStyle.ALIGN_CENTER);
// 垂直居中
cellStyle.setVerticalAlignment(CellStyle.ALIGN_CENTER);
// 边框
cellStyle.setBorderTop(CellStyle.BORDER_THIN);
// 边框
cellStyle.setBorderLeft(CellStyle.BORDER_THIN);
// 边框
cellStyle.setBorderRight(CellStyle.BORDER_THIN);
// 边框
cellStyle.setBorderBottom(CellStyle.BORDER_THIN);
}
}
......@@ -2,6 +2,7 @@ package com.subsidy.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.subsidy.common.exception.HttpException;
import com.subsidy.dto.administer.VerifyCodeDTO;
......@@ -135,6 +136,7 @@ public class MemberServiceImpl extends ServiceImpl<MemberMapper, MemberDO> imple
public String updateMember(AddMemberDTO addMemberDTO) {
if (null!= addMemberDTO.getDepartmentIds()){
Integer count = this.baseMapper.selectCount(new QueryWrapper<MemberDO>()
.lambda()
.eq(MemberDO::getTelephone, addMemberDTO.getTelephone())
......@@ -144,7 +146,6 @@ public class MemberServiceImpl extends ServiceImpl<MemberMapper, MemberDO> imple
if (count > 0) {
throw new HttpException(20002);
}
Integer count1 = this.baseMapper.selectCount(new QueryWrapper<MemberDO>()
.lambda()
.eq(MemberDO::getAccountName, addMemberDTO.getAccountName())
......@@ -154,10 +155,13 @@ public class MemberServiceImpl extends ServiceImpl<MemberMapper, MemberDO> imple
if (count1 > 0) {
throw new HttpException(20002);
}
}
MemberDO memberDO = new MemberDO();
BeanUtils.copyProperties(addMemberDTO, memberDO);
this.baseMapper.updateById(memberDO);
if (null != addMemberDTO.getDepartmentIds()){
memberDepartmentMappingMapper.delete(new QueryWrapper<MemberDepartmentMappingDO>()
.lambda()
.eq(MemberDepartmentMappingDO::getMemberId, addMemberDTO.getId()));
......@@ -170,6 +174,7 @@ public class MemberServiceImpl extends ServiceImpl<MemberMapper, MemberDO> imple
memberDepartmentMappingDO.setDepartmentId(lg);
memberDepartmentMappingMapper.insert(memberDepartmentMappingDO);
}
}
return ConstantUtils.SET_SUCCESS;
}
......@@ -291,7 +296,9 @@ public class MemberServiceImpl extends ServiceImpl<MemberMapper, MemberDO> imple
return memberStudyPageVO;
}
public List<ContentVodVO> contentVod(ContentMemberDTO contentVodDTO) {
public ContentVodNewVO contentVod(ContentMemberDTO contentVodDTO) {
ContentVodNewVO contentVodNewVO = new ContentVodNewVO();
List<ContentVodVO> contentVodVOS = new ArrayList<>();
List<CourseContentDO> courseContentDOS = courseContentMapper.selectList(new QueryWrapper<CourseContentDO>()
......@@ -345,7 +352,20 @@ public class MemberServiceImpl extends ServiceImpl<MemberMapper, MemberDO> imple
contentVodVOS.add(contentVodVO);
}
return contentVodVOS;
contentVodNewVO.setContentVodVOS(contentVodVOS);
List<VodPlayHistoryDO> vodPlayHistoryDOS = vodPlayHistoryMapper.selectList(new QueryWrapper<VodPlayHistoryDO>()
.lambda()
.eq(VodPlayHistoryDO::getClassId,contentVodDTO.getClassId())
.eq(VodPlayHistoryDO::getMemberId,contentVodDTO.getMemberId())
.orderByDesc(VodPlayHistoryDO::getCreateDate));
if (vodPlayHistoryDOS.size()>0){
VodPlayHistoryDO vodPlayHistoryDO = vodPlayHistoryDOS.get(0);
VodDictDO vodDictDO = vodDictMapper.selectById(vodPlayHistoryDO.getVodId());
BeanUtils.copyProperties(vodDictDO,contentVodNewVO);
contentVodNewVO.setPlayRecord(vodPlayHistoryDO.getPlayRecord());
}
return contentVodNewVO;
}
public List<ContentFilesVO> contentFiles(ContentMemberDTO contentMemberDTO) {
......
......@@ -84,7 +84,7 @@ public class SignInRecordServiceImpl extends ServiceImpl<SignInRecordMapper, Sig
Page pager = new Page(classSignInfoDTO.getPageNum(), classSignInfoDTO.getPageSize());
IPage<ClassSignInfoVO> classSignInfoVOIPage = this.baseMapper.classSignInfo(pager, classSignInfoDTO.getClassName(), classSignInfoDTO.getCourseName(),classSignInfoDTO.getId());
IPage<ClassSignInfoVO> classSignInfoVOIPage = this.baseMapper.classSignInfo(pager, classSignInfoDTO.getClassName(), classSignInfoDTO.getCourseName(),classSignInfoDTO.getCompanyId());
List<ClassSignInfoVO> classSignInfoVOS = classSignInfoVOIPage.getRecords();
for (ClassSignInfoVO classSignInfoVO : classSignInfoVOS){
......@@ -140,7 +140,7 @@ public class SignInRecordServiceImpl extends ServiceImpl<SignInRecordMapper, Sig
passNum++;
}
}
classSignInfoVO.setPassRate(100* MathUtil.intDivFloorPercent(passNum,classMemberMappingDOS.size()));
classSignInfoVO.setPassRate(MathUtil.intDivFloorPercent(passNum,classMemberMappingDOS.size()));
//平均签到数 向上取整
......
package com.subsidy.util.excel;
import com.subsidy.vo.administer.ExerciseTestVO;
import com.subsidy.vo.classdict.ClassDetailVO;
import com.subsidy.vo.member.ClassSignVO;
import com.subsidy.vo.sign.AnswerRecordVO;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.BooleanUtils;
import org.apache.commons.lang3.CharUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.math.NumberUtils;
import org.apache.poi.hssf.usermodel.HSSFCellStyle;
import org.apache.poi.hssf.usermodel.HSSFDateUtil;
import org.apache.poi.hssf.usermodel.HSSFFont;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.hssf.util.CellRangeAddress;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.xssf.streaming.SXSSFCell;
import org.apache.poi.xssf.streaming.SXSSFRow;
import org.apache.poi.xssf.streaming.SXSSFSheet;
import org.apache.poi.xssf.streaming.SXSSFWorkbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.*;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.math.BigDecimal;
......@@ -26,6 +35,7 @@ import java.util.*;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import java.util.zip.ZipOutputStream;
/**
* Excel工具
......@@ -42,6 +52,7 @@ public class ExcelUtil {
/**
* 导入excel文件
*
* @param path
* @param cls
* @param file
......@@ -50,7 +61,7 @@ public class ExcelUtil {
*/
public static <T> List<T> readExcel(String path, Class<T> cls, MultipartFile file) {
String fileName = file.getOriginalFilename();
if(!fileName.matches("^.+\\.(?i)(xls)$") && !fileName.matches("^.+\\.(?i)(xlsx)$")) {
if (!fileName.matches("^.+\\.(?i)(xls)$") && !fileName.matches("^.+\\.(?i)(xlsx)$")) {
log.info("上传文件格式不正确");
// throw new HTTPException(10022);
}
......@@ -64,7 +75,7 @@ public class ExcelUtil {
workbook = new XSSFWorkbook(is);
}
if(fileName.endsWith(EXCEL2003)) {
if (fileName.endsWith(EXCEL2003)) {
// FileInputStream is = new FileInputStream(new File(path));
workbook = new HSSFWorkbook(is);
}
......@@ -76,11 +87,11 @@ public class ExcelUtil {
ExcelColumnUtil annotation = field.getAnnotation(ExcelColumnUtil.class);
if (annotation != null) {
String value = annotation.value();
if(StringUtils.isBlank(value)) {
if (StringUtils.isBlank(value)) {
return;
}
if(!classMap.containsKey(value)) {
if (!classMap.containsKey(value)) {
classMap.put(value, new ArrayList<>());
}
......@@ -136,7 +147,7 @@ public class ExcelUtil {
}
}
if(!allBlank) {
if (!allBlank) {
dataList.add(t);
}
} catch (Exception e) {
......@@ -164,6 +175,7 @@ public class ExcelUtil {
/**
* 导出excel文件
*
* @param list
* @param cls
* @param <T>
......@@ -174,7 +186,7 @@ public class ExcelUtil {
Field[] fields = cls.getDeclaredFields();
List<Field> fieldList = Arrays.stream(fields).filter(field -> {
ExcelColumn annotation = field.getAnnotation(ExcelColumn.class);
if(annotation != null) {
if (annotation != null) {
field.setAccessible(true);
return true;
}
......@@ -182,7 +194,7 @@ public class ExcelUtil {
}).sorted(Comparator.comparing(field -> {
int col = 0;
ExcelColumn annotation = field.getAnnotation(ExcelColumn.class);
if(annotation != null) {
if (annotation != null) {
col = annotation.col();
}
return col;
......@@ -236,6 +248,874 @@ public class ExcelUtil {
}
}
public static <T> void writeMemberExcel(String companyName, String studyDate, String courseName, String title, List<ClassDetailVO> list, List<String> headerList) throws Exception {
ServletRequestAttributes requestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
HttpServletResponse response = requestAttributes.getResponse();
response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
response.addHeader("content-disposition", "attachment;filename="
+ java.net.URLEncoder.encode("member.xlsx", "utf-8"));
// 声明一个工作薄
SXSSFWorkbook workbook = new SXSSFWorkbook(1000);//缓存
workbook.setCompressTempFiles(true);
//表头样式
CellStyle titleStyle = workbook.createCellStyle();
setStyle(titleStyle);
Font titleFont = workbook.createFont();
titleFont.setFontHeightInPoints((short) 20);
titleFont.setBoldweight((short) 700);
titleStyle.setFont(titleFont);
//第二行
CellStyle secondStyle = workbook.createCellStyle();
secondStyle.setBorderBottom(HSSFCellStyle.BORDER_THIN); //下边框
secondStyle.setBorderLeft(HSSFCellStyle.BORDER_THIN);//左边框
secondStyle.setBorderTop(HSSFCellStyle.BORDER_THIN);//上边框
secondStyle.setBorderRight(HSSFCellStyle.BORDER_THIN);//右边框
secondStyle.setAlignment(HSSFCellStyle.ALIGN_LEFT);
Font secondFont = workbook.createFont();
secondStyle.setFont(secondFont);
//第三行
CellStyle thirdStyle = workbook.createCellStyle();
thirdStyle.setBorderBottom(HSSFCellStyle.BORDER_THIN); //下边框
thirdStyle.setBorderLeft(HSSFCellStyle.BORDER_THIN);//左边框
thirdStyle.setBorderTop(HSSFCellStyle.BORDER_THIN);//上边框
thirdStyle.setBorderRight(HSSFCellStyle.BORDER_THIN);//右边框
secondStyle.setAlignment(HSSFCellStyle.ALIGN_LEFT);
Font thirdFont = workbook.createFont();
thirdStyle.setFont(thirdFont);
// 列头样式
CellStyle headerStyle = workbook.createCellStyle();
setStyle(headerStyle);
Font headerFont = workbook.createFont();
headerFont.setFontHeightInPoints((short) 12);
headerFont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);//粗体显示
headerStyle.setFont(headerFont);
// 数据单元格样式
CellStyle cellStyle = workbook.createCellStyle();
setStyle(cellStyle);
Font cellFont = workbook.createFont();
cellFont.setBoldweight(HSSFFont.BOLDWEIGHT_NORMAL);
cellStyle.setFont(cellFont);
// 生成一个(带标题)表格
SXSSFSheet sheet = workbook.createSheet();
//设置列宽
int minBytes = 17;//至少字节数
int[] arrColWidth = new int[headerList.size()];
// 产生表格标题行,以及设置列宽
String[] headers = new String[headerList.size()];
int ii = 0;
for (int i = 0; i < headerList.size(); i++) {
headers[ii] = headerList.get(i);
int bytes = headerList.get(i).getBytes().length;
arrColWidth[ii] = bytes < minBytes ? minBytes : bytes;
sheet.setColumnWidth(ii, arrColWidth[ii] * 256);
ii++;
}
//第二行
int[] secondWidth = new int[2];
// 产生表格标题行,以及设置列宽
String[] secondHead = new String[2];
List<String> secondList = Arrays.asList(new String[]{"培训实施单位:" + companyName, "培训时间:" + studyDate});
//第三行
int[] thirdWidth = new int[2];
// 产生表格标题行,以及设置列宽
String[] thirdHead = new String[2];
List<String> thirdList = Arrays.asList(new String[]{"培训项目:" + courseName, "培训平台:有课互联系统"});
ii = 0;
for (int i = 0; i < 2; i++) {
secondHead[ii] = secondList.get(i);
int bytes = secondList.get(i).getBytes().length;
secondWidth[ii] = bytes < minBytes ? minBytes : bytes;
sheet.setColumnWidth(ii, secondWidth[ii] * 256);
ii++;
}
ii = 0;
for (int i = 0; i < 2; i++) {
thirdHead[ii] = thirdList.get(i);
int bytes = thirdList.get(i).getBytes().length;
thirdWidth[ii] = bytes < minBytes ? minBytes : bytes;
sheet.setColumnWidth(ii, thirdWidth[ii] * 256);
ii++;
}
// 遍历集合数据,产生数据行
//标题 0
SXSSFRow titleRow = sheet.createRow(0);//表头 rowIndex=0
titleRow.createCell(0).setCellValue(title);
setBorderStyle(HSSFCellStyle.BORDER_THIN, new CellRangeAddress(0, 0, 0, 0), sheet, workbook); //给合并过的单元格加边框
titleRow.getCell(0).setCellStyle(titleStyle);
sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, headerList.size() - 1));
//第二行 1
SXSSFRow secondRow = sheet.createRow(1); //第二行 rowIndex =1
CellRangeAddress cellRangeAddress21 = new CellRangeAddress(1, 1, 0, 4);
sheet.addMergedRegion(cellRangeAddress21);
setBorderStyle(HSSFCellStyle.BORDER_THIN, cellRangeAddress21, sheet, workbook); //给合并过的单元格加边框
CellRangeAddress cellRangeAddress22 = new CellRangeAddress(1, 1, 5, 10);
sheet.addMergedRegion(cellRangeAddress22);
setBorderStyle(HSSFCellStyle.BORDER_THIN, cellRangeAddress22, sheet, workbook); //给合并过的单元格加边框
secondRow.createCell(0).setCellValue(secondHead[0]);
secondRow.getCell(0).setCellStyle(secondStyle);
secondRow.createCell(5).setCellValue(secondHead[1]);
secondRow.getCell(5).setCellStyle(secondStyle);
//第三行 2
SXSSFRow thirdRow = sheet.createRow(2); //第二行 rowIndex =1
CellRangeAddress cellRangeAddress31 = new CellRangeAddress(2, 2, 0, 4);
sheet.addMergedRegion(cellRangeAddress31);
setBorderStyle(HSSFCellStyle.BORDER_THIN, cellRangeAddress31, sheet, workbook); //给合并过的单元格加边框
CellRangeAddress cellRangeAddress32 = new CellRangeAddress(2, 2, 5, 10);
sheet.addMergedRegion(cellRangeAddress32);
setBorderStyle(HSSFCellStyle.BORDER_THIN, cellRangeAddress32, sheet, workbook); //给合并过的单元格加边框
thirdRow.createCell(0).setCellValue(thirdHead[0]);
thirdRow.getCell(0).setCellStyle(thirdStyle);
thirdRow.createCell(5).setCellValue(thirdHead[1]);
thirdRow.getCell(5).setCellStyle(thirdStyle);
//标题 3
SXSSFRow headerRow = sheet.createRow(3); //列头 rowIndex =1
for (int i = 0; i < headers.length; i++) {
headerRow.createCell(i).setCellValue(headers[i]);
headerRow.getCell(i).setCellStyle(headerStyle);
}
int seq = 1;
//内容
int rowIndex = 0;
for (ClassDetailVO classDetailVO : list) {
if (rowIndex == 65535 || rowIndex == 0) {
if (rowIndex != 0) {
sheet = workbook.createSheet();//如果数据超过了,则在第二页显示
}
rowIndex = 4;//数据内容从 rowIndex=2开始
}
SXSSFRow dataRow = sheet.createRow(rowIndex);
SXSSFCell newCell = dataRow.createCell(0);
cellStyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
newCell.setCellStyle(cellStyle);
newCell.setCellValue(seq);
newCell = dataRow.createCell(1);
newCell.setCellStyle(cellStyle);
newCell.setCellValue(classDetailVO.getUserName());
newCell = dataRow.createCell(2);
newCell.setCellStyle(cellStyle);
newCell.setCellValue(classDetailVO.getIdCard());
newCell = dataRow.createCell(3);
newCell.setCellStyle(cellStyle);
newCell.setCellValue(classDetailVO.getAccountName());
newCell = dataRow.createCell(4);
newCell.setCellStyle(cellStyle);
newCell.setCellValue(classDetailVO.getTelephone());
newCell = dataRow.createCell(5);
newCell.setCellStyle(cellStyle);
newCell.setCellValue(classDetailVO.getSignCounts());
newCell = dataRow.createCell(6);
newCell.setCellStyle(cellStyle);
newCell.setCellValue(classDetailVO.getClassProcess());
newCell = dataRow.createCell(7);
newCell.setCellStyle(cellStyle);
newCell.setCellValue(classDetailVO.getTrainingLength());
newCell = dataRow.createCell(8);
newCell.setCellStyle(cellStyle);
newCell.setCellValue(classDetailVO.getAskCounts());
newCell = dataRow.createCell(9);
newCell.setCellStyle(cellStyle);
newCell.setCellValue(classDetailVO.getScore());
newCell = dataRow.createCell(10);
newCell.setCellStyle(cellStyle);
if (classDetailVO.getScore() >= 60) {
newCell.setCellValue("合格");
} else {
newCell.setCellValue("不合格");
}
rowIndex++;
seq++;
}
try {
OutputStream outputStream = response.getOutputStream();
workbook.write(outputStream);
workbook.close();
workbook.dispose();
} catch (IOException e) {
e.printStackTrace();
}
}
public static <T> void writeSignExcel(String companyName, String studyDate, String courseName, String title, List<ClassSignVO>list, List<String> headerList) throws Exception {
ServletRequestAttributes requestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
HttpServletResponse response = requestAttributes.getResponse();
response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
response.addHeader("content-disposition", "attachment;filename="
+ java.net.URLEncoder.encode("sign.xlsx", "utf-8"));
// 声明一个工作薄
SXSSFWorkbook workbook = new SXSSFWorkbook(1000);//缓存
workbook.setCompressTempFiles(true);
//表头样式
CellStyle titleStyle = workbook.createCellStyle();
setStyle(titleStyle);
Font titleFont = workbook.createFont();
titleFont.setFontHeightInPoints((short) 20);
titleFont.setBoldweight((short) 700);
titleStyle.setFont(titleFont);
//第二行
CellStyle secondStyle = workbook.createCellStyle();
secondStyle.setBorderBottom(HSSFCellStyle.BORDER_THIN); //下边框
secondStyle.setBorderLeft(HSSFCellStyle.BORDER_THIN);//左边框
secondStyle.setBorderTop(HSSFCellStyle.BORDER_THIN);//上边框
secondStyle.setBorderRight(HSSFCellStyle.BORDER_THIN);//右边框
secondStyle.setAlignment(HSSFCellStyle.ALIGN_LEFT);
Font secondFont = workbook.createFont();
secondStyle.setFont(secondFont);
//第三行
CellStyle thirdStyle = workbook.createCellStyle();
thirdStyle.setBorderBottom(HSSFCellStyle.BORDER_THIN); //下边框
thirdStyle.setBorderLeft(HSSFCellStyle.BORDER_THIN);//左边框
thirdStyle.setBorderTop(HSSFCellStyle.BORDER_THIN);//上边框
thirdStyle.setBorderRight(HSSFCellStyle.BORDER_THIN);//右边框
secondStyle.setAlignment(HSSFCellStyle.ALIGN_LEFT);
Font thirdFont = workbook.createFont();
thirdStyle.setFont(thirdFont);
// 列头样式
CellStyle headerStyle = workbook.createCellStyle();
setStyle(headerStyle);
Font headerFont = workbook.createFont();
headerFont.setFontHeightInPoints((short) 12);
headerFont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);//粗体显示
headerStyle.setFont(headerFont);
// 数据单元格样式
CellStyle cellStyle = workbook.createCellStyle();
setStyle(cellStyle);
Font cellFont = workbook.createFont();
cellFont.setBoldweight(HSSFFont.BOLDWEIGHT_NORMAL);
cellStyle.setFont(cellFont);
// 生成一个(带标题)表格
SXSSFSheet sheet = workbook.createSheet();
//设置列宽
int minBytes = 17;//至少字节数
int[] arrColWidth = new int[headerList.size()];
// 产生表格标题行,以及设置列宽
String[] headers = new String[headerList.size()];
int ii = 0;
for (int i = 0; i < headerList.size(); i++) {
headers[ii] = headerList.get(i);
int bytes = headerList.get(i).getBytes().length;
arrColWidth[ii] = bytes < minBytes ? minBytes : bytes;
sheet.setColumnWidth(ii, arrColWidth[ii] * 256);
ii++;
}
//第二行
int[] secondWidth = new int[2];
// 产生表格标题行,以及设置列宽
String[] secondHead = new String[2];
List<String> secondList = Arrays.asList(new String[]{"培训实施单位:" + companyName, "培训时间:" + studyDate});
//第三行
int[] thirdWidth = new int[2];
// 产生表格标题行,以及设置列宽
String[] thirdHead = new String[2];
List<String> thirdList = Arrays.asList(new String[]{"培训项目:" + courseName, "培训平台:有课互联系统"});
ii = 0;
for (int i = 0; i < 2; i++) {
secondHead[ii] = secondList.get(i);
int bytes = secondList.get(i).getBytes().length;
secondWidth[ii] = bytes < minBytes ? minBytes : bytes;
sheet.setColumnWidth(ii, secondWidth[ii] * 256);
ii++;
}
ii = 0;
for (int i = 0; i < 2; i++) {
thirdHead[ii] = thirdList.get(i);
int bytes = thirdList.get(i).getBytes().length;
thirdWidth[ii] = bytes < minBytes ? minBytes : bytes;
sheet.setColumnWidth(ii, thirdWidth[ii] * 256);
ii++;
}
// 遍历集合数据,产生数据行
//标题 0
SXSSFRow titleRow = sheet.createRow(0);//表头 rowIndex=0
titleRow.createCell(0).setCellValue(title);
setBorderStyle(HSSFCellStyle.BORDER_THIN, new CellRangeAddress(0, 0, 0, 0), sheet, workbook); //给合并过的单元格加边框
titleRow.getCell(0).setCellStyle(titleStyle);
sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, headerList.size() - 1));
//第二行 1
SXSSFRow secondRow = sheet.createRow(1); //第二行 rowIndex =1
CellRangeAddress cellRangeAddress21 = new CellRangeAddress(1, 1, 0, 3);
sheet.addMergedRegion(cellRangeAddress21);
setBorderStyle(HSSFCellStyle.BORDER_THIN, cellRangeAddress21, sheet, workbook); //给合并过的单元格加边框
CellRangeAddress cellRangeAddress22 = new CellRangeAddress(1, 1, 4, 8);
sheet.addMergedRegion(cellRangeAddress22);
setBorderStyle(HSSFCellStyle.BORDER_THIN, cellRangeAddress22, sheet, workbook); //给合并过的单元格加边框
secondRow.createCell(0).setCellValue(secondHead[0]);
secondRow.getCell(0).setCellStyle(secondStyle);
secondRow.createCell(4).setCellValue(secondHead[1]);
secondRow.getCell(4).setCellStyle(secondStyle);
//第三行 2
SXSSFRow thirdRow = sheet.createRow(2); //第二行 rowIndex =1
CellRangeAddress cellRangeAddress31 = new CellRangeAddress(2, 2, 0, 3);
sheet.addMergedRegion(cellRangeAddress31);
setBorderStyle(HSSFCellStyle.BORDER_THIN, cellRangeAddress31, sheet, workbook); //给合并过的单元格加边框
CellRangeAddress cellRangeAddress32 = new CellRangeAddress(2, 2, 4, 8);
sheet.addMergedRegion(cellRangeAddress32);
setBorderStyle(HSSFCellStyle.BORDER_THIN, cellRangeAddress32, sheet, workbook); //给合并过的单元格加边框
thirdRow.createCell(0).setCellValue(thirdHead[0]);
thirdRow.getCell(0).setCellStyle(thirdStyle);
thirdRow.createCell(4).setCellValue(thirdHead[1]);
thirdRow.getCell(4).setCellStyle(thirdStyle);
//标题 3
SXSSFRow headerRow = sheet.createRow(3); //列头 rowIndex =1
for (int i = 0; i < headers.length; i++) {
headerRow.createCell(i).setCellValue(headers[i]);
headerRow.getCell(i).setCellStyle(headerStyle);
}
int seq = 1;
//内容
int rowIndex = 0;
for (ClassSignVO classSignVO : list) {
if (rowIndex == 65535 || rowIndex == 0) {
if (rowIndex != 0) {
sheet = workbook.createSheet();//如果数据超过了,则在第二页显示
}
rowIndex = 4;//数据内容从 rowIndex=2开始
}
SXSSFRow dataRow = sheet.createRow(rowIndex);
SXSSFCell newCell = dataRow.createCell(0);
cellStyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
newCell.setCellStyle(cellStyle);
newCell.setCellValue(seq);
newCell = dataRow.createCell(1);
newCell.setCellStyle(cellStyle);
newCell.setCellValue(classSignVO.getUserName());
newCell = dataRow.createCell(2);
newCell.setCellStyle(cellStyle);
newCell.setCellValue(classSignVO.getIdCard());
newCell = dataRow.createCell(3);
newCell.setCellStyle(cellStyle);
newCell.setCellValue(classSignVO.getTelephone());
newCell = dataRow.createCell(4);
newCell.setCellStyle(cellStyle);
newCell.setCellValue(classSignVO.getTrainingLength());
newCell = dataRow.createCell(5);
newCell.setCellStyle(cellStyle);
newCell.setCellValue(classSignVO.getClassProcess());
newCell = dataRow.createCell(6);
newCell.setCellStyle(cellStyle);
newCell.setCellValue(classSignVO.getPercent());
newCell = dataRow.createCell(7);
newCell.setCellStyle(cellStyle);
newCell.setCellValue(classSignVO.getSignCounts());
newCell = dataRow.createCell(8);
newCell.setCellStyle(cellStyle);
newCell.setCellValue(classSignVO.getSignInDateList());
rowIndex++;
seq++;
}
try {
OutputStream outputStream = response.getOutputStream();
workbook.write(outputStream);
workbook.close();
workbook.dispose();
} catch (IOException e) {
e.printStackTrace();
}
}
public static <T> void writeTestExcel(String companyName, String studyDate, String courseName, String title, List<ExerciseTestVO> list, List<String> headerList) throws Exception {
ServletRequestAttributes requestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
HttpServletResponse response = requestAttributes.getResponse();
response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
response.addHeader("content-disposition", "attachment;filename="
+ java.net.URLEncoder.encode("test.xlsx", "utf-8"));
// 声明一个工作薄
SXSSFWorkbook workbook = new SXSSFWorkbook(1000);//缓存
workbook.setCompressTempFiles(true);
//表头样式
CellStyle titleStyle = workbook.createCellStyle();
setStyle(titleStyle);
Font titleFont = workbook.createFont();
titleFont.setFontHeightInPoints((short) 20);
titleFont.setBoldweight((short) 700);
titleStyle.setFont(titleFont);
//第二行
CellStyle secondStyle = workbook.createCellStyle();
secondStyle.setBorderBottom(HSSFCellStyle.BORDER_THIN); //下边框
secondStyle.setBorderLeft(HSSFCellStyle.BORDER_THIN);//左边框
secondStyle.setBorderTop(HSSFCellStyle.BORDER_THIN);//上边框
secondStyle.setBorderRight(HSSFCellStyle.BORDER_THIN);//右边框
secondStyle.setAlignment(HSSFCellStyle.ALIGN_LEFT);
Font secondFont = workbook.createFont();
secondStyle.setFont(secondFont);
//第三行
CellStyle thirdStyle = workbook.createCellStyle();
thirdStyle.setBorderBottom(HSSFCellStyle.BORDER_THIN); //下边框
thirdStyle.setBorderLeft(HSSFCellStyle.BORDER_THIN);//左边框
thirdStyle.setBorderTop(HSSFCellStyle.BORDER_THIN);//上边框
thirdStyle.setBorderRight(HSSFCellStyle.BORDER_THIN);//右边框
secondStyle.setAlignment(HSSFCellStyle.ALIGN_LEFT);
Font thirdFont = workbook.createFont();
thirdStyle.setFont(thirdFont);
// 列头样式
CellStyle headerStyle = workbook.createCellStyle();
setStyle(headerStyle);
Font headerFont = workbook.createFont();
headerFont.setFontHeightInPoints((short) 12);
headerFont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);//粗体显示
headerStyle.setFont(headerFont);
// 数据单元格样式
CellStyle cellStyle = workbook.createCellStyle();
setStyle(cellStyle);
Font cellFont = workbook.createFont();
cellFont.setBoldweight(HSSFFont.BOLDWEIGHT_NORMAL);
cellStyle.setFont(cellFont);
// 生成一个(带标题)表格
SXSSFSheet sheet = workbook.createSheet();
//设置列宽
int minBytes = 17;//至少字节数
int[] arrColWidth = new int[headerList.size()];
// 产生表格标题行,以及设置列宽
String[] headers = new String[headerList.size()];
int ii = 0;
for (int i = 0; i < headerList.size(); i++) {
headers[ii] = headerList.get(i);
int bytes = headerList.get(i).getBytes().length;
arrColWidth[ii] = bytes < minBytes ? minBytes : bytes;
sheet.setColumnWidth(ii, arrColWidth[ii] * 256);
ii++;
}
//第二行
int[] secondWidth = new int[2];
// 产生表格标题行,以及设置列宽
String[] secondHead = new String[2];
List<String> secondList = Arrays.asList(new String[]{"培训实施单位:" + companyName, "培训时间:" + studyDate});
//第三行
int[] thirdWidth = new int[2];
// 产生表格标题行,以及设置列宽
String[] thirdHead = new String[2];
List<String> thirdList = Arrays.asList(new String[]{"培训项目:" + courseName, "培训平台:有课互联系统"});
ii = 0;
for (int i = 0; i < 2; i++) {
secondHead[ii] = secondList.get(i);
int bytes = secondList.get(i).getBytes().length;
secondWidth[ii] = bytes < minBytes ? minBytes : bytes;
sheet.setColumnWidth(ii, secondWidth[ii] * 256);
ii++;
}
ii = 0;
for (int i = 0; i < 2; i++) {
thirdHead[ii] = thirdList.get(i);
int bytes = thirdList.get(i).getBytes().length;
thirdWidth[ii] = bytes < minBytes ? minBytes : bytes;
sheet.setColumnWidth(ii, thirdWidth[ii] * 256);
ii++;
}
// 遍历集合数据,产生数据行
//标题 0
SXSSFRow titleRow = sheet.createRow(0);//表头 rowIndex=0
titleRow.createCell(0).setCellValue(title);
setBorderStyle(HSSFCellStyle.BORDER_THIN, new CellRangeAddress(0, 0, 0, 0), sheet, workbook); //给合并过的单元格加边框
titleRow.getCell(0).setCellStyle(titleStyle);
sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, headerList.size() - 1));
//第二行 1
SXSSFRow secondRow = sheet.createRow(1); //第二行 rowIndex =1
CellRangeAddress cellRangeAddress21 = new CellRangeAddress(1, 1, 0, 3);
sheet.addMergedRegion(cellRangeAddress21);
setBorderStyle(HSSFCellStyle.BORDER_THIN, cellRangeAddress21, sheet, workbook); //给合并过的单元格加边框
CellRangeAddress cellRangeAddress22 = new CellRangeAddress(1, 1, 4, 6);
sheet.addMergedRegion(cellRangeAddress22);
setBorderStyle(HSSFCellStyle.BORDER_THIN, cellRangeAddress22, sheet, workbook); //给合并过的单元格加边框
secondRow.createCell(0).setCellValue(secondHead[0]);
secondRow.getCell(0).setCellStyle(secondStyle);
secondRow.createCell(4).setCellValue(secondHead[1]);
secondRow.getCell(4).setCellStyle(secondStyle);
//第三行 2
SXSSFRow thirdRow = sheet.createRow(2); //第二行 rowIndex =1
CellRangeAddress cellRangeAddress31 = new CellRangeAddress(2, 2, 0, 3);
sheet.addMergedRegion(cellRangeAddress31);
setBorderStyle(HSSFCellStyle.BORDER_THIN, cellRangeAddress31, sheet, workbook); //给合并过的单元格加边框
CellRangeAddress cellRangeAddress32 = new CellRangeAddress(2, 2, 4, 6);
sheet.addMergedRegion(cellRangeAddress32);
setBorderStyle(HSSFCellStyle.BORDER_THIN, cellRangeAddress32, sheet, workbook); //给合并过的单元格加边框
thirdRow.createCell(0).setCellValue(thirdHead[0]);
thirdRow.getCell(0).setCellStyle(thirdStyle);
thirdRow.createCell(4).setCellValue(thirdHead[1]);
thirdRow.getCell(4).setCellStyle(thirdStyle);
//标题 3
SXSSFRow headerRow = sheet.createRow(3); //列头 rowIndex =1
for (int i = 0; i < headers.length; i++) {
headerRow.createCell(i).setCellValue(headers[i]);
headerRow.getCell(i).setCellStyle(headerStyle);
}
int seq = 1;
//内容
int rowIndex = 0;
for (ExerciseTestVO exerciseTestVO : list) {
if (rowIndex == 65535 || rowIndex == 0) {
if (rowIndex != 0) {
sheet = workbook.createSheet();//如果数据超过了,则在第二页显示
}
rowIndex = 4;//数据内容从 rowIndex=2开始
}
SXSSFRow dataRow = sheet.createRow(rowIndex);
SXSSFCell newCell = dataRow.createCell(0);
cellStyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
newCell.setCellStyle(cellStyle);
newCell.setCellValue(seq);
newCell = dataRow.createCell(1);
newCell.setCellStyle(cellStyle);
newCell.setCellValue(exerciseTestVO.getUserName());
newCell = dataRow.createCell(2);
newCell.setCellStyle(cellStyle);
newCell.setCellValue(exerciseTestVO.getIdCard());
newCell = dataRow.createCell(3);
newCell.setCellStyle(cellStyle);
newCell.setCellValue(exerciseTestVO.getTelephone());
newCell = dataRow.createCell(4);
newCell.setCellStyle(cellStyle);
newCell.setCellValue(exerciseTestVO.getScore());
//次数
newCell = dataRow.createCell(5);
newCell.setCellStyle(cellStyle);
if (exerciseTestVO.getScore()!=0){
newCell.setCellValue(1);
}else {
newCell.setCellValue(0);
}
newCell = dataRow.createCell(6);
newCell.setCellStyle(cellStyle);
if (exerciseTestVO.getScore()>=60){
newCell.setCellValue("合格");
}else {
newCell.setCellValue("不合格");
}
rowIndex++;
seq++;
}
try {
OutputStream outputStream = response.getOutputStream();
workbook.write(outputStream);
workbook.close();
workbook.dispose();
} catch (IOException e) {
e.printStackTrace();
}
}
public static <T> void writeAnswerExcel(String companyName, String studyDate, String courseName, String title, List<AnswerRecordVO> list, List<String> headerList) throws Exception {
ServletRequestAttributes requestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
HttpServletResponse response = requestAttributes.getResponse();
response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
response.addHeader("content-disposition", "attachment;filename="
+ java.net.URLEncoder.encode("answer.xlsx", "utf-8"));
// 声明一个工作薄
SXSSFWorkbook workbook = new SXSSFWorkbook(1000);//缓存
workbook.setCompressTempFiles(true);
//表头样式
CellStyle titleStyle = workbook.createCellStyle();
setStyle(titleStyle);
Font titleFont = workbook.createFont();
titleFont.setFontHeightInPoints((short) 20);
titleFont.setBoldweight((short) 700);
titleStyle.setFont(titleFont);
//第二行
CellStyle secondStyle = workbook.createCellStyle();
secondStyle.setBorderBottom(HSSFCellStyle.BORDER_THIN); //下边框
secondStyle.setBorderLeft(HSSFCellStyle.BORDER_THIN);//左边框
secondStyle.setBorderTop(HSSFCellStyle.BORDER_THIN);//上边框
secondStyle.setBorderRight(HSSFCellStyle.BORDER_THIN);//右边框
secondStyle.setAlignment(HSSFCellStyle.ALIGN_LEFT);
Font secondFont = workbook.createFont();
secondStyle.setFont(secondFont);
//第三行
CellStyle thirdStyle = workbook.createCellStyle();
thirdStyle.setBorderBottom(HSSFCellStyle.BORDER_THIN); //下边框
thirdStyle.setBorderLeft(HSSFCellStyle.BORDER_THIN);//左边框
thirdStyle.setBorderTop(HSSFCellStyle.BORDER_THIN);//上边框
thirdStyle.setBorderRight(HSSFCellStyle.BORDER_THIN);//右边框
secondStyle.setAlignment(HSSFCellStyle.ALIGN_LEFT);
Font thirdFont = workbook.createFont();
thirdStyle.setFont(thirdFont);
// 列头样式
CellStyle headerStyle = workbook.createCellStyle();
setStyle(headerStyle);
Font headerFont = workbook.createFont();
headerFont.setFontHeightInPoints((short) 12);
headerFont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);//粗体显示
headerStyle.setFont(headerFont);
// 数据单元格样式
CellStyle cellStyle = workbook.createCellStyle();
setStyle(cellStyle);
Font cellFont = workbook.createFont();
cellFont.setBoldweight(HSSFFont.BOLDWEIGHT_NORMAL);
cellStyle.setFont(cellFont);
// 生成一个(带标题)表格
SXSSFSheet sheet = workbook.createSheet();
//设置列宽
int minBytes = 17;//至少字节数
int[] arrColWidth = new int[headerList.size()];
// 产生表格标题行,以及设置列宽
String[] headers = new String[headerList.size()];
int ii = 0;
for (int i = 0; i < headerList.size(); i++) {
headers[ii] = headerList.get(i);
int bytes = headerList.get(i).getBytes().length;
arrColWidth[ii] = bytes < minBytes ? minBytes : bytes;
sheet.setColumnWidth(ii, arrColWidth[ii] * 256);
ii++;
}
//第二行
int[] secondWidth = new int[2];
// 产生表格标题行,以及设置列宽
String[] secondHead = new String[2];
List<String> secondList = Arrays.asList(new String[]{"培训实施单位:" + companyName, "培训时间:" + studyDate});
//第三行
int[] thirdWidth = new int[2];
// 产生表格标题行,以及设置列宽
String[] thirdHead = new String[2];
List<String> thirdList = Arrays.asList(new String[]{"培训项目:" + courseName, "培训平台:有课互联系统"});
ii = 0;
for (int i = 0; i < 2; i++) {
secondHead[ii] = secondList.get(i);
int bytes = secondList.get(i).getBytes().length;
secondWidth[ii] = bytes < minBytes ? minBytes : bytes;
sheet.setColumnWidth(ii, secondWidth[ii] * 256);
ii++;
}
ii = 0;
for (int i = 0; i < 2; i++) {
thirdHead[ii] = thirdList.get(i);
int bytes = thirdList.get(i).getBytes().length;
thirdWidth[ii] = bytes < minBytes ? minBytes : bytes;
sheet.setColumnWidth(ii, thirdWidth[ii] * 256);
ii++;
}
// 遍历集合数据,产生数据行
//标题 0
SXSSFRow titleRow = sheet.createRow(0);//表头 rowIndex=0
titleRow.createCell(0).setCellValue(title);
setBorderStyle(HSSFCellStyle.BORDER_THIN, new CellRangeAddress(0, 0, 0, 0), sheet, workbook); //给合并过的单元格加边框
titleRow.getCell(0).setCellStyle(titleStyle);
sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, headerList.size() - 1));
//第二行 1
SXSSFRow secondRow = sheet.createRow(1); //第二行 rowIndex =1
CellRangeAddress cellRangeAddress21 = new CellRangeAddress(1, 1, 0, 2);
sheet.addMergedRegion(cellRangeAddress21);
setBorderStyle(HSSFCellStyle.BORDER_THIN, cellRangeAddress21, sheet, workbook); //给合并过的单元格加边框
CellRangeAddress cellRangeAddress22 = new CellRangeAddress(1, 1, 3, 5);
sheet.addMergedRegion(cellRangeAddress22);
setBorderStyle(HSSFCellStyle.BORDER_THIN, cellRangeAddress22, sheet, workbook); //给合并过的单元格加边框
secondRow.createCell(0).setCellValue(secondHead[0]);
secondRow.getCell(0).setCellStyle(secondStyle);
secondRow.createCell(3).setCellValue(secondHead[1]);
secondRow.getCell(3).setCellStyle(secondStyle);
//第三行 2
SXSSFRow thirdRow = sheet.createRow(2); //第二行 rowIndex =1
CellRangeAddress cellRangeAddress31 = new CellRangeAddress(2, 2, 0, 2);
sheet.addMergedRegion(cellRangeAddress31);
setBorderStyle(HSSFCellStyle.BORDER_THIN, cellRangeAddress31, sheet, workbook); //给合并过的单元格加边框
CellRangeAddress cellRangeAddress32 = new CellRangeAddress(2, 2, 3,5);
sheet.addMergedRegion(cellRangeAddress32);
setBorderStyle(HSSFCellStyle.BORDER_THIN, cellRangeAddress32, sheet, workbook); //给合并过的单元格加边框
thirdRow.createCell(0).setCellValue(thirdHead[0]);
thirdRow.getCell(0).setCellStyle(thirdStyle);
thirdRow.createCell(3).setCellValue(thirdHead[1]);
thirdRow.getCell(3).setCellStyle(thirdStyle);
//标题 3
SXSSFRow headerRow = sheet.createRow(3); //列头 rowIndex =1
for (int i = 0; i < headers.length; i++) {
headerRow.createCell(i).setCellValue(headers[i]);
headerRow.getCell(i).setCellStyle(headerStyle);
}
int seq = 1;
//内容
int rowIndex = 0;
for (AnswerRecordVO answerRecordVO : list) {
if (rowIndex == 65535 || rowIndex == 0) {
if (rowIndex != 0) {
sheet = workbook.createSheet();//如果数据超过了,则在第二页显示
}
rowIndex = 4;//数据内容从 rowIndex=2开始
}
SXSSFRow dataRow = sheet.createRow(rowIndex);
SXSSFCell newCell = dataRow.createCell(0);
cellStyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
newCell.setCellStyle(cellStyle);
newCell.setCellValue(seq);
newCell = dataRow.createCell(1);
newCell.setCellStyle(cellStyle);
newCell.setCellValue(answerRecordVO.getTitle());
newCell = dataRow.createCell(2);
newCell.setCellStyle(cellStyle);
newCell.setCellValue(answerRecordVO.getAnswer());
newCell = dataRow.createCell(3);
newCell.setCellStyle(cellStyle);
newCell.setCellValue(answerRecordVO.getCreateDate());
newCell = dataRow.createCell(4);
newCell.setCellStyle(cellStyle);
newCell.setCellValue(answerRecordVO.getUserName());
//次数
newCell = dataRow.createCell(5);
newCell.setCellStyle(cellStyle);
newCell.setCellValue(answerRecordVO.getUpdateDate());
rowIndex++;
seq++;
}
try {
OutputStream outputStream = response.getOutputStream();
workbook.write(outputStream);
workbook.close();
workbook.dispose();
} catch (IOException e) {
e.printStackTrace();
}
}
private static void setStyle(CellStyle cellStyle) {
// 水平居中
......@@ -252,6 +1132,35 @@ public class ExcelUtil {
cellStyle.setBorderBottom(CellStyle.BORDER_THIN);
}
//也可用以下方法
public static void setBorderStyle(int border, CellRangeAddress region, SXSSFSheet sheet, SXSSFWorkbook wb) {
CellStyle cs = wb.createCellStyle(); // 样式对象
cs.setBorderBottom((short) border);
cs.setBorderTop((short) border);
cs.setBorderLeft((short) border);
cs.setBorderRight((short) border);
setRegionStyle(cs, region, sheet);
}
private static void setRegionStyle(CellStyle cs, CellRangeAddress region, SXSSFSheet sheet) {
for (int i = region.getFirstRow(); i <= region.getLastRow(); i++) {
SXSSFRow row = sheet.getRow(i);
if (row == null) {
row = sheet.createRow(i);
}
for (int j = region.getFirstColumn(); j <= region.getLastColumn(); j++) {
SXSSFCell cell = row.getCell(j);
if (cell == null) {
cell = row.createCell(j);
cell.setCellValue("");
}
cell.setCellStyle(cs);
}
}
}
private static <T> void handleField(T t, String value, Field field) throws Exception {
Class<?> type = field.getType();
if (type == null || type == void.class || StringUtils.isBlank(value)) {
......@@ -319,10 +1228,10 @@ public class ExcelUtil {
}
}
private static void buildExcelDocument(String fileName, Workbook wb, HttpServletResponse response){
private static void buildExcelDocument(String fileName, Workbook wb, HttpServletResponse response) {
try {
response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
response.setHeader("Content-Disposition", "attachment;filename="+ URLEncoder.encode(fileName, "utf-8"));
response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(fileName, "utf-8"));
response.flushBuffer();
wb.write(response.getOutputStream());
} catch (IOException e) {
......@@ -330,7 +1239,7 @@ public class ExcelUtil {
}
}
private static void buildExcelFile(String path, Workbook wb){
private static void buildExcelFile(String path, Workbook wb) {
File file = new File(path);
if (file.exists()) {
file.delete();
......
......@@ -20,4 +20,8 @@ public class ExerciseTestVO {
@ExcelColumn(col = 3,value = "最高分")
private String result;
private String idCard;
private String telephone;
}
......@@ -4,7 +4,7 @@ import com.subsidy.util.excel.ExcelColumn;
import lombok.Data;
@Data
public class ClassDetailVO {
public class ClassDetailVO <T>{
private Long id;
......@@ -16,7 +16,7 @@ public class ClassDetailVO {
private String accountName;
@ExcelColumn(col = 3,value = "身份证号")
private String idCards;
private String idCard;
@ExcelColumn(col = 4,value = "联系方式")
private String telephone;
......
......@@ -13,6 +13,10 @@ public class ClassSignVO {
@ExcelColumn(col = 1,value = "成员名称")
private String userName;
private String idCard;
private String telephone;
/**
* 签到次数
*/
......
package com.subsidy.vo.member;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.subsidy.model.VodDictDO;
import lombok.Data;
import java.util.List;
@Data
public class ContentVodNewVO {
private Integer playRecord;
private Long id;
/**
* 目录id
*/
private Long contentId;
/**
* 视频名称
*/
private String vodName;
/**
* 视频时长
*/
private Integer vodLength;
/**
* 视频格式
*/
private String vodType;
/**
* 视频大小
*/
private String vodSize;
/**
* 视频地址
*/
private String vodUrl;
/**
* 视频编码
*/
private String vodCode;
/**
* 讲师名称
*/
private String teacherName;
/**
* 封面
*/
private String coverPage;
private List<ContentVodVO> contentVodVOS;
}
......@@ -21,4 +21,6 @@ public class StudyPageVO {
private Integer doneMember;
private String className;
}
# 环境配置
spring.profiles.active=prod
spring.profiles.active=dev
# 文件编码 UTF8
spring.mandatory-file-encoding=UTF-8
......
......@@ -28,3 +28,5 @@ meishu.code-message[80002]=uuid验证失败
meishu.code-message[90001]=该类目已存在
meishu.code-message[10001]=导入失败
......@@ -67,7 +67,8 @@
t2.id,
t2.user_name,
t2.account_name,
t2.telephone
t2.telephone,
t2.id_card
FROM
class_member_mapping t
LEFT JOIN member t2 ON t.member_id = t2.id
......@@ -85,7 +86,8 @@
t2.id,
t2.user_name,
t2.account_name,
t2.telephone
t2.telephone,
t2.id_card
FROM
class_member_mapping t
LEFT JOIN member t2 ON t.member_id = t2.id
......
......@@ -43,6 +43,7 @@
<if test="className != null and className !=''">
and t.class_name like concat('%',#{className} ,'%')
</if>
order by t.create_date desc
</select>
<select id="getClassVods" parameterType="long" resultType="com.subsidy.model.VodDictDO">
......
......@@ -29,7 +29,8 @@
t3.id,
t2.id as classId,
t3.course_name,
t2.end_date
t2.end_date,
t2.class_name
FROM
class_member_mapping t
LEFT JOIN class_dict t2 ON t.class_id = t2.id
......
......@@ -30,21 +30,26 @@
t2.teacher_name,
t2.vod_url,
t2.vod_name,
round( t.play_record *100/ t2.vod_length ,0) AS percent
t3.play_record,
round( t3.play_record * 100 / t2.vod_length, 0 ) AS percent
FROM
(
SELECT
t.vod_id,
t.play_record,
max( t.update_date )
t.member_id,
max( t.create_date ) AS playDate
FROM
vod_play_history t
WHERE
t.delete_date IS NULL
AND t.member_id = #{memberId}
GROUP BY
t.vod_id
t.vod_id,
t.member_id
) t
LEFT JOIN vod_play_history t3 ON t.playDate = t3.create_date
AND t.vod_id = t3.vod_id
AND t.member_id = t3.member_id
LEFT JOIN vod_dict t2 ON t.vod_id = t2.id
WHERE
t2.delete_date IS NULL
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!