diff --git a/src/main/java/com/subsidy/controller/AdministerController.java b/src/main/java/com/subsidy/controller/AdministerController.java index 4be2380..35be4ae 100644 --- a/src/main/java/com/subsidy/controller/AdministerController.java +++ b/src/main/java/com/subsidy/controller/AdministerController.java @@ -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 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 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 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 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") diff --git a/src/main/java/com/subsidy/controller/MemberController.java b/src/main/java/com/subsidy/controller/MemberController.java index 9027025..1a3d061 100644 --- a/src/main/java/com/subsidy/controller/MemberController.java +++ b/src/main/java/com/subsidy/controller/MemberController.java @@ -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)); } diff --git a/src/main/java/com/subsidy/dto/administer/ClassDetailDTO.java b/src/main/java/com/subsidy/dto/administer/ClassDetailDTO.java index 79c89db..4615d99 100644 --- a/src/main/java/com/subsidy/dto/administer/ClassDetailDTO.java +++ b/src/main/java/com/subsidy/dto/administer/ClassDetailDTO.java @@ -13,4 +13,6 @@ public class ClassDetailDTO { private String userName; + Boolean flag; + } diff --git a/src/main/java/com/subsidy/dto/sign/ClassSignInfoDTO.java b/src/main/java/com/subsidy/dto/sign/ClassSignInfoDTO.java index bced7dc..57f6571 100644 --- a/src/main/java/com/subsidy/dto/sign/ClassSignInfoDTO.java +++ b/src/main/java/com/subsidy/dto/sign/ClassSignInfoDTO.java @@ -14,6 +14,6 @@ public class ClassSignInfoDTO { private Integer pageNum; - private Integer id; + private Integer companyId; } diff --git a/src/main/java/com/subsidy/service/AdministerService.java b/src/main/java/com/subsidy/service/AdministerService.java index ef6985f..ead20d2 100644 --- a/src/main/java/com/subsidy/service/AdministerService.java +++ b/src/main/java/com/subsidy/service/AdministerService.java @@ -42,22 +42,22 @@ public interface AdministerService extends IService { IPage classDetail(ClassDetailDTO classDetailDTO); - List exportClassDetail(ClassDetailDTO classDetailDTO); + List exportClassDetail(ClassDetailDTO classDetailDTO)throws Exception; IPage signDetail(ClassDetailDTO classDetailDTO); - List exportSignDetail(ClassDetailDTO classDetailDTO); + List exportSignDetail(ClassDetailDTO classDetailDTO)throws Exception; IPage exerciseTest(ClassDetailDTO classDetailDTO); - List exportExerciseTest(ClassDetailDTO classDetailDTO); + List exportExerciseTest(ClassDetailDTO classDetailDTO)throws Exception; IPage answerRecord(ClassDetailDTO classDetailDTO); - List exportAnswerRecord(ClassDetailDTO classDetailDTO); + List exportAnswerRecord(ClassDetailDTO classDetailDTO)throws Exception; void export(ClassDetailDTO classDetailDTO)throws Exception; - List importMember(Long companyId, MultipartFile multipartFile); + String importMember(Long companyId, MultipartFile multipartFile); } diff --git a/src/main/java/com/subsidy/service/MemberService.java b/src/main/java/com/subsidy/service/MemberService.java index d8de6aa..d501328 100644 --- a/src/main/java/com/subsidy/service/MemberService.java +++ b/src/main/java/com/subsidy/service/MemberService.java @@ -39,7 +39,7 @@ public interface MemberService extends IService { MemberStudyPageVO studyPage(MemberDO memberDO); - List contentVod(ContentMemberDTO contentVodDTO); + ContentVodNewVO contentVod(ContentMemberDTO contentVodDTO); List contentFiles(ContentMemberDTO contentMemberDTO); diff --git a/src/main/java/com/subsidy/service/impl/AdministerServiceImpl.java b/src/main/java/com/subsidy/service/impl/AdministerServiceImpl.java index cf31f82..175458b 100644 --- a/src/main/java/com/subsidy/service/impl/AdministerServiceImpl.java +++ b/src/main/java/com/subsidy/service/impl/AdministerServiceImpl.java @@ -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.*; /** *

@@ -88,6 +85,12 @@ public class AdministerServiceImpl extends ServiceImpl() .lambda() @@ -352,10 +356,9 @@ public class AdministerServiceImpl extends ServiceImpl exportClassDetail(ClassDetailDTO classDetailDTO) { + public List exportClassDetail(ClassDetailDTO classDetailDTO) throws Exception { Page pager = new Page(1, 10000000); - IPage classDetailVOIPage = this.baseMapper.classMembers(pager, classDetailDTO.getId(), classDetailDTO.getUserName()); List classDetailVOS = classDetailVOIPage.getRecords(); @@ -365,6 +368,7 @@ public class AdministerServiceImpl extends ServiceImpl 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 exportSignDetail(ClassDetailDTO classDetailDTO) { + public List exportSignDetail(ClassDetailDTO classDetailDTO) throws Exception { Page pager = new Page(1, 1000000); IPage classSignVOIPage = this.baseMapper.classSign(pager, classDetailDTO.getId(), classDetailDTO.getUserName()); @@ -531,12 +545,24 @@ public class AdministerServiceImpl extends ServiceImpl 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= 60) { exerciseTestVO.setResult("合格"); @@ -578,7 +604,7 @@ public class AdministerServiceImpl extends ServiceImpl exportExerciseTest(ClassDetailDTO classDetailDTO) { + public List exportExerciseTest(ClassDetailDTO classDetailDTO) throws Exception { Page pager = new Page(0, 1000000); IPage exerciseTestVOIPage = this.baseMapper.exerciseTest(pager, classDetailDTO.getId(), classDetailDTO.getUserName()); @@ -611,6 +637,14 @@ public class AdministerServiceImpl extends ServiceImpl 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 exportAnswerRecord(ClassDetailDTO classDetailDTO) { + public List 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 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 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 memberList = Arrays.asList(new String[]{"成员名称", "账号", "联系方式", "签到次数", "课程进度", "培训时长", "评级测试", "答疑"}); + List memberList = Arrays.asList(new String[]{"序号", "成员名称", "身份证号码", "账号", "联系方式", "签到次数", "课程进度", "培训时长", "答疑数", "测试成绩", "总评价"}); + classDetailDTO.setFlag(false); List 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 signList = Arrays.asList(new String[]{"成员名称", "签到次数", "培训时长", "课程进度", "完成率"}); + List signList = Arrays.asList(new String[]{"序号", "成员名称", "身份证号码", "手机号码", "培训时长", "课程进度", "完成率", "签到次数", "签到日期"}); + classDetailDTO.setFlag(false); List 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 scoreList = Arrays.asList(new String[]{"成员名称", "测试结果", "最高分"}); + List scoreList = Arrays.asList(new String[]{"序号", "成员名称", "身份证号码", "手机号码", "测试最高成绩", "测试次数", "总评价"}); + classDetailDTO.setFlag(false); List 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 answerList = Arrays.asList(new String[]{"提问", "答疑", "提问时间", "提问成员", "答疑时间"}); + List answerList = Arrays.asList(new String[]{"序号", "提问", "答疑", "提问时间", "提问成员", "答疑时间"}); List 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,17 +743,18 @@ public class AdministerServiceImpl extends ServiceImpl importMember(Long companyId, MultipartFile multipartFile) { + @Transactional(rollbackFor = Exception.class) + public String importMember(Long companyId, MultipartFile multipartFile) { - List memberDOS = new ArrayList<>(); + try { - ExcelUtil.readExcel(null, ImportMemberDTO.class, multipartFile).forEach(s -> { + List memberDOS = new ArrayList<>(); - MemberDO memberDO = memberMapper.selectOne(new QueryWrapper() - .lambda() - .eq(MemberDO::getTelephone, s.getTelephone())); + ExcelUtil.readExcel(null, ImportMemberDTO.class, multipartFile).forEach(s -> { - try { + MemberDO memberDO = memberMapper.selectOne(new QueryWrapper() + .lambda() + .eq(MemberDO::getTelephone, s.getTelephone())); if (null != memberDO) { memberDOS.add(memberDO); @@ -714,126 +766,238 @@ public class AdministerServiceImpl extends ServiceImpl() + .lambda() + .isNull(DepartmentDictDO::getParentId) + .eq(DepartmentDictDO::getCompanyId, companyId)); + + MemberDepartmentMappingDO memberDepartmentMappingDO = new MemberDepartmentMappingDO(); + memberDepartmentMappingDO.setDepartmentId(departmentDictDO.getId()); + memberDepartmentMappingDO.setMemberId(memberDO1.getId()); + memberDepartmentMappingMapper.insert(memberDepartmentMappingDO); } - - } catch (Exception e) { - memberDOS.add(memberDO); - } - }); - return memberDOS; + }); + } catch (Exception e) { + throw new HttpException(10001); + } + return ConstantUtils.ADD_SUCCESS; } - public static void membersListExcel(String title, List headList, List 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 headerList, List 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 secondList = Arrays.asList(new String[]{"培训实施单位:" + companyName, "培训时间:" + studyDate}); + + //第三行 + int[] thirdWidth = new int[2]; + // 产生表格标题行,以及设置列宽 + String[] thirdHead = new String[2]; + List 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 headList, List 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 headerList, List 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 secondList = Arrays.asList(new String[]{"培训实施单位:" + companyName, "培训时间:" + studyDate}); + + //第三行 + int[] thirdWidth = new int[2]; + // 产生表格标题行,以及设置列宽 + String[] thirdHead = new String[2]; + List 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); //给合并过的单元格加边框 - 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, 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 headList, List 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 headerList, List 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[] secondWidth = new int[2]; + // 产生表格标题行,以及设置列宽 + String[] secondHead = new String[2]; + List secondList = Arrays.asList(new String[]{"培训实施单位:" + companyName, "培训时间:" + studyDate}); + + //第三行 + int[] thirdWidth = new int[2]; + // 产生表格标题行,以及设置列宽 + String[] thirdHead = new String[2]; + List 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 : exerciseTestVOS) { if (rowIndex == 65535 || rowIndex == 0) { if (rowIndex != 0) { sheet = workbook.createSheet();//如果数据超过了,则在第二页显示 } - SXSSFRow titleRow = sheet.createRow(0);//表头 rowIndex=0 - titleRow.createCell(0).setCellValue(title); - titleRow.getCell(0).setCellStyle(titleStyle); - sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, headList.size() - 1)); - - SXSSFRow headerRow = sheet.createRow(1); //列头 rowIndex =1 - for (int i = 0; i < headers.length; i++) { - headerRow.createCell(i).setCellValue(headers[i]); - headerRow.getCell(i).setCellStyle(headerStyle); - - } - 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 headList, List 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 headerList, List 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 secondList = Arrays.asList(new String[]{"培训实施单位:" + companyName, "培训时间:" + studyDate}); + + //第三行 + int[] thirdWidth = new int[2]; + // 产生表格标题行,以及设置列宽 + String[] thirdHead = new String[2]; + List 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); //给合并过的单元格加边框 + + 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); - SXSSFRow headerRow = sheet.createRow(1); //列头 rowIndex =1 + 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 imple public String updateMember(AddMemberDTO addMemberDTO) { - Integer count = this.baseMapper.selectCount(new QueryWrapper() - .lambda() - .eq(MemberDO::getTelephone, addMemberDTO.getTelephone()) - .eq(MemberDO::getDepartmentId, addMemberDTO.getDepartmentId()) - .ne(MemberDO::getId, addMemberDTO.getId())); - - if (count > 0) { - throw new HttpException(20002); - } + if (null!= addMemberDTO.getDepartmentIds()){ + Integer count = this.baseMapper.selectCount(new QueryWrapper() + .lambda() + .eq(MemberDO::getTelephone, addMemberDTO.getTelephone()) + .eq(MemberDO::getDepartmentId, addMemberDTO.getDepartmentId()) + .ne(MemberDO::getId, addMemberDTO.getId())); - Integer count1 = this.baseMapper.selectCount(new QueryWrapper() - .lambda() - .eq(MemberDO::getAccountName, addMemberDTO.getAccountName()) - .eq(MemberDO::getDepartmentId, addMemberDTO.getDepartmentId()) - .ne(MemberDO::getId, addMemberDTO.getId())); + if (count > 0) { + throw new HttpException(20002); + } + Integer count1 = this.baseMapper.selectCount(new QueryWrapper() + .lambda() + .eq(MemberDO::getAccountName, addMemberDTO.getAccountName()) + .eq(MemberDO::getDepartmentId, addMemberDTO.getDepartmentId()) + .ne(MemberDO::getId, addMemberDTO.getId())); - if (count1 > 0) { - throw new HttpException(20002); + if (count1 > 0) { + throw new HttpException(20002); + } } + MemberDO memberDO = new MemberDO(); BeanUtils.copyProperties(addMemberDTO, memberDO); this.baseMapper.updateById(memberDO); - memberDepartmentMappingMapper.delete(new QueryWrapper() - .lambda() - .eq(MemberDepartmentMappingDO::getMemberId, addMemberDTO.getId())); - - //部门 - List longs = addMemberDTO.getDepartmentIds(); - for (Long lg : longs) { - MemberDepartmentMappingDO memberDepartmentMappingDO = new MemberDepartmentMappingDO(); - memberDepartmentMappingDO.setMemberId(memberDO.getId()); - memberDepartmentMappingDO.setDepartmentId(lg); - memberDepartmentMappingMapper.insert(memberDepartmentMappingDO); + if (null != addMemberDTO.getDepartmentIds()){ + memberDepartmentMappingMapper.delete(new QueryWrapper() + .lambda() + .eq(MemberDepartmentMappingDO::getMemberId, addMemberDTO.getId())); + + //部门 + List longs = addMemberDTO.getDepartmentIds(); + for (Long lg : longs) { + MemberDepartmentMappingDO memberDepartmentMappingDO = new MemberDepartmentMappingDO(); + memberDepartmentMappingDO.setMemberId(memberDO.getId()); + memberDepartmentMappingDO.setDepartmentId(lg); + memberDepartmentMappingMapper.insert(memberDepartmentMappingDO); + } } return ConstantUtils.SET_SUCCESS; @@ -291,7 +296,9 @@ public class MemberServiceImpl extends ServiceImpl imple return memberStudyPageVO; } - public List contentVod(ContentMemberDTO contentVodDTO) { + public ContentVodNewVO contentVod(ContentMemberDTO contentVodDTO) { + + ContentVodNewVO contentVodNewVO = new ContentVodNewVO(); List contentVodVOS = new ArrayList<>(); List courseContentDOS = courseContentMapper.selectList(new QueryWrapper() @@ -345,7 +352,20 @@ public class MemberServiceImpl extends ServiceImpl imple contentVodVOS.add(contentVodVO); } - return contentVodVOS; + contentVodNewVO.setContentVodVOS(contentVodVOS); + + List vodPlayHistoryDOS = vodPlayHistoryMapper.selectList(new QueryWrapper() + .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 contentFiles(ContentMemberDTO contentMemberDTO) { diff --git a/src/main/java/com/subsidy/service/impl/SignInRecordServiceImpl.java b/src/main/java/com/subsidy/service/impl/SignInRecordServiceImpl.java index 878420c..68947a7 100644 --- a/src/main/java/com/subsidy/service/impl/SignInRecordServiceImpl.java +++ b/src/main/java/com/subsidy/service/impl/SignInRecordServiceImpl.java @@ -84,7 +84,7 @@ public class SignInRecordServiceImpl extends ServiceImpl classSignInfoVOIPage = this.baseMapper.classSignInfo(pager, classSignInfoDTO.getClassName(), classSignInfoDTO.getCourseName(),classSignInfoDTO.getId()); + IPage classSignInfoVOIPage = this.baseMapper.classSignInfo(pager, classSignInfoDTO.getClassName(), classSignInfoDTO.getCourseName(),classSignInfoDTO.getCompanyId()); List classSignInfoVOS = classSignInfoVOIPage.getRecords(); for (ClassSignInfoVO classSignInfoVO : classSignInfoVOS){ @@ -140,7 +140,7 @@ public class SignInRecordServiceImpl extends ServiceImpl List readExcel(String path, Class 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 @@ -174,7 +186,7 @@ public class ExcelUtil { Field[] fields = cls.getDeclaredFields(); List 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 void writeMemberExcel(String companyName, String studyDate, String courseName, String title, List list, List 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 secondList = Arrays.asList(new String[]{"培训实施单位:" + companyName, "培训时间:" + studyDate}); + + //第三行 + int[] thirdWidth = new int[2]; + // 产生表格标题行,以及设置列宽 + String[] thirdHead = new String[2]; + List 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 void writeSignExcel(String companyName, String studyDate, String courseName, String title, Listlist, List 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 secondList = Arrays.asList(new String[]{"培训实施单位:" + companyName, "培训时间:" + studyDate}); + + //第三行 + int[] thirdWidth = new int[2]; + // 产生表格标题行,以及设置列宽 + String[] thirdHead = new String[2]; + List 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 void writeTestExcel(String companyName, String studyDate, String courseName, String title, List list, List 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 secondList = Arrays.asList(new String[]{"培训实施单位:" + companyName, "培训时间:" + studyDate}); + + //第三行 + int[] thirdWidth = new int[2]; + // 产生表格标题行,以及设置列宽 + String[] thirdHead = new String[2]; + List 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 void writeAnswerExcel(String companyName, String studyDate, String courseName, String title, List list, List 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 secondList = Arrays.asList(new String[]{"培训实施单位:" + companyName, "培训时间:" + studyDate}); + + //第三行 + int[] thirdWidth = new int[2]; + // 产生表格标题行,以及设置列宽 + String[] thirdHead = new String[2]; + List 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 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(); diff --git a/src/main/java/com/subsidy/vo/administer/ExerciseTestVO.java b/src/main/java/com/subsidy/vo/administer/ExerciseTestVO.java index acca0e6..17e1c5b 100644 --- a/src/main/java/com/subsidy/vo/administer/ExerciseTestVO.java +++ b/src/main/java/com/subsidy/vo/administer/ExerciseTestVO.java @@ -20,4 +20,8 @@ public class ExerciseTestVO { @ExcelColumn(col = 3,value = "最高分") private String result; + private String idCard; + + private String telephone; + } diff --git a/src/main/java/com/subsidy/vo/classdict/ClassDetailVO.java b/src/main/java/com/subsidy/vo/classdict/ClassDetailVO.java index 2c90300..8f607c7 100644 --- a/src/main/java/com/subsidy/vo/classdict/ClassDetailVO.java +++ b/src/main/java/com/subsidy/vo/classdict/ClassDetailVO.java @@ -4,7 +4,7 @@ import com.subsidy.util.excel.ExcelColumn; import lombok.Data; @Data -public class ClassDetailVO { +public class ClassDetailVO { 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; diff --git a/src/main/java/com/subsidy/vo/member/ClassSignVO.java b/src/main/java/com/subsidy/vo/member/ClassSignVO.java index 879764e..cbc8204 100644 --- a/src/main/java/com/subsidy/vo/member/ClassSignVO.java +++ b/src/main/java/com/subsidy/vo/member/ClassSignVO.java @@ -13,6 +13,10 @@ public class ClassSignVO { @ExcelColumn(col = 1,value = "成员名称") private String userName; + private String idCard; + + private String telephone; + /** * 签到次数 */ diff --git a/src/main/java/com/subsidy/vo/member/ContentVodNewVO.java b/src/main/java/com/subsidy/vo/member/ContentVodNewVO.java new file mode 100644 index 0000000..c4ec7a3 --- /dev/null +++ b/src/main/java/com/subsidy/vo/member/ContentVodNewVO.java @@ -0,0 +1,64 @@ +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 contentVodVOS; + +} diff --git a/src/main/java/com/subsidy/vo/member/StudyPageVO.java b/src/main/java/com/subsidy/vo/member/StudyPageVO.java index 699f4e9..dc234c6 100644 --- a/src/main/java/com/subsidy/vo/member/StudyPageVO.java +++ b/src/main/java/com/subsidy/vo/member/StudyPageVO.java @@ -21,4 +21,6 @@ public class StudyPageVO { private Integer doneMember; + private String className; + } diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 81ef4bb..cd7ba36 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -1,5 +1,5 @@ # 环境配置 -spring.profiles.active=prod +spring.profiles.active=dev # 文件编码 UTF8 spring.mandatory-file-encoding=UTF-8 diff --git a/src/main/resources/code.properties b/src/main/resources/code.properties index 1ff9904..1e16acb 100644 --- a/src/main/resources/code.properties +++ b/src/main/resources/code.properties @@ -28,3 +28,5 @@ meishu.code-message[80002]=uuid验证失败 meishu.code-message[90001]=该类目已存在 +meishu.code-message[10001]=导入失败 + diff --git a/src/main/resources/mapper/AdministerMapper.xml b/src/main/resources/mapper/AdministerMapper.xml index b155fbd..f88f415 100644 --- a/src/main/resources/mapper/AdministerMapper.xml +++ b/src/main/resources/mapper/AdministerMapper.xml @@ -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 diff --git a/src/main/resources/mapper/ClassDictMapper.xml b/src/main/resources/mapper/ClassDictMapper.xml index 84b60ef..7cc0d76 100644 --- a/src/main/resources/mapper/ClassDictMapper.xml +++ b/src/main/resources/mapper/ClassDictMapper.xml @@ -43,6 +43,7 @@ and t.class_name like concat('%',#{className} ,'%') + order by t.create_date desc