Browse Source

导出最终版

master
HY 1 month ago
parent
commit
a8be019759
3 changed files with 48 additions and 14 deletions
  1. +2
    -2
      jeecg-boot-base/jeecg-boot-base-core/pom.xml
  2. +45
    -11
      jeecg-boot-base/jeecg-boot-base-core/src/main/java/org/jeecg/modules/clockinlog/controller/ClockinLogController.java
  3. +1
    -1
      jeecg-boot-base/jeecg-boot-base-core/src/main/java/org/jeecg/modules/clockinlog/mapper/ClockinLogMapper.java

+ 2
- 2
jeecg-boot-base/jeecg-boot-base-core/pom.xml View File

@ -290,8 +290,8 @@
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml-schemas</artifactId>
<version>4.1.2</version>
<artifactId>poi-ooxml-full</artifactId>
<version>5.3.0</version>
</dependency>
</dependencies>


+ 45
- 11
jeecg-boot-base/jeecg-boot-base-core/src/main/java/org/jeecg/modules/clockinlog/controller/ClockinLogController.java View File

@ -17,6 +17,7 @@ import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.http.HttpHeaders;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbookFactory;
import org.apache.shiro.SecurityUtils;
@ -199,8 +200,8 @@ public class ClockinLogController extends JeecgController<ClockinLog, IClockinLo
@RequestMapping(value = "/exportXls2")
public ModelAndView exportXls3(HttpServletRequest request, ClockinLog clockinLog) throws IOException {
return this.exportXls2(request,ClockInLogExportResp.class, "打卡");
public Object exportXls3(HttpServletRequest request, ClockinLog clockinLog) throws IOException {
return this.exportXls3(request,ClockInLogExportResp.class, "打卡");
}
// @RequestMapping(value = "/exportXls2")
@ -391,15 +392,17 @@ public class ClockinLogController extends JeecgController<ClockinLog, IClockinLo
}
// 创建工作簿
XSSFWorkbookFactory xssfWorkbookFactory = new XSSFWorkbookFactory();
Workbook workbook = new XSSFWorkbook();
// 创建工作表
Sheet sheet = workbook.createSheet("考勤");
// 创建表头行
Row headerRow = sheet.createRow(0);
headerRow.createCell(0).setCellValue("日期");
headerRow.createCell(1).setCellValue("打卡时间");
// Row headerRow2 = sheet.createRow(2);
//
//
// headerRow2.createCell(0).setCellValue("日期");
// headerRow2.createCell(1).setCellValue("打卡时间");
List<Map<String, Object>> maps = new ArrayList<>();
Map<String, Object> map = new HashMap<>();
@ -441,6 +444,14 @@ public class ClockinLogController extends JeecgController<ClockinLog, IClockinLo
List<Map<String, Object>> list = new ArrayList<>();
List<String> strings = null;
List<ClockInLogExportResp> exportList = new ArrayList<>();
CellStyle wrapStyle = workbook.createCellStyle();
wrapStyle.setAlignment(HorizontalAlignment.CENTER);
wrapStyle.setBorderTop(BorderStyle.THIN); // 顶部边框
wrapStyle.setBorderBottom(BorderStyle.THIN); // 底部边框
wrapStyle.setBorderLeft(BorderStyle.THIN); // 左边边框
wrapStyle.setBorderRight(BorderStyle.THIN); // 右边边框
int headerRowNum = 0;
for (ClockinTeamLog clockinTeamLog:clockinTeamLogs){
ClockInProject clockInProject = clockInProjectService.lambdaQuery()
.eq(ClockInProject::getDelFlag, 0)
@ -461,9 +472,26 @@ public class ClockinLogController extends JeecgController<ClockinLog, IClockinLo
ClockInLogExportResp clockInLogExportResp = new ClockInLogExportResp();
clockInLogExportResp.setName(clockinAuth.getName());
clockInLogExportResp.setDate(nowYearMonth);
// 创建表头行
Row headerRow = sheet.createRow(headerRowNum);
Cell cell1 = headerRow.createCell(0);
cell1.setCellStyle(wrapStyle);
cell1.setCellValue("姓名:"+clockinAuth.getName()+" 日期:"+nowYearMonth);
sheet.addMergedRegion(new CellRangeAddress(headerRowNum,headerRowNum,0,day-1));
// Row row1 = sheet.createRow(1);
// row1.createCell(0).setCellValue(clockinAuth.getName());
sheet.setColumnWidth(0,256*10);
sheet.setColumnWidth(1,256*10);
map.put("name",clockinAuth.getName());
map.put("sex",nowYearMonth);
List<Map<String, Object>> maps1 = new ArrayList<>();
Row row = sheet.createRow(1+headerRowNum);
Row row2 = sheet.createRow(2+headerRowNum);
headerRowNum = headerRowNum + 3;
int num = 3;
for (int n= 1;n<=day;n++){
ClockInLogExportResp2 clockInLogExportResp2 = new ClockInLogExportResp2();
@ -480,11 +508,17 @@ public class ClockinLogController extends JeecgController<ClockinLog, IClockinLo
if(DayOfWeek.SATURDAY.equals(localDateTime.getDayOfWeek()) || DayOfWeek.SUNDAY.equals(localDateTime.getDayOfWeek())){
type = 1;
}
Row row = sheet.createRow(n);
row.createCell(0).setCellValue(yearMonthDay);
Cell cell2 = row.createCell(n - 1);
cell2.setCellValue(n);
cell2.setCellStyle(wrapStyle);
List<ClockInLogResp> clockInLogExpeort = clockinLogMapper.getClockInLogExpeort(yearMonthDay, clockInProject.getId(), clockinTeamLog.getUserId(),type);
String clockInTime = "";
for (ClockInLogResp clockInLogResp:clockInLogExpeort) {
if(StringUtils.isBlank(clockInLogResp.getTime())&&clockInLogResp.getType() == 2){
continue;
}
if(StringUtils.isBlank(clockInLogResp.getTime())){
clockInLogResp.setClockStartTime("缺卡");
@ -493,9 +527,9 @@ public class ClockinLogController extends JeecgController<ClockinLog, IClockinLo
// strings.add(clockInLogResp.getClockStartTime());
}
// 创建一个单元格样式用于自动换行
CellStyle wrapStyle = workbook.createCellStyle();
wrapStyle.setWrapText(true);
Cell cell = row.createCell(1);
Cell cell = row2.createCell(n-1);
cell.setCellValue(clockInTime);
cell.setCellStyle(wrapStyle);
Map<String, Object> map1 = new HashMap<>();


+ 1
- 1
jeecg-boot-base/jeecg-boot-base-core/src/main/java/org/jeecg/modules/clockinlog/mapper/ClockinLogMapper.java View File

@ -41,7 +41,7 @@ public interface ClockinLogMapper extends BaseMapper<ClockinLog> {
@Select("SELECT IFNULL(count(1),0) FROM clockin_log WHERE del_flag = 0 AND user_id = #{userId} AND clock_in_time like '%${date}%' AND type in (0,1)")
Integer getClockInTotal(@Param("userId") String userId,@Param("date") String date);
@Select("select clock_start_time,(select clock_in_time from clockin_log where project_item_id = a.id and del_flag = 0 and user_id = '${userId}' and clock_in_time like '%${date}%') time from clock_in_project_item a where project_id = '${projectId}' AND a.del_flag = 0 AND type = #{type}\n")
@Select("select clock_start_time,(select clock_in_time from clockin_log where project_item_id = a.id and del_flag = 0 and user_id = '${userId}' and clock_in_time like '%${date}%') time, a.type from clock_in_project_item a where project_id = '${projectId}' AND a.del_flag = 0 AND type in (${type},2)\n")
List<ClockInLogResp> getClockInLogExpeort(@Param("date") String date,@Param("projectId") String projectId,@Param("userId") String userId,@Param("type") Integer type);
}

Loading…
Cancel
Save