|
|
@@ -16,11 +16,13 @@ import okhttp3.Request; |
|
|
|
import okhttp3.Response; |
|
|
|
import org.apache.poi.ss.usermodel.*; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.core.io.ClassPathResource; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
|
|
|
import javax.servlet.http.HttpServletResponse; |
|
|
|
import java.io.FileInputStream; |
|
|
|
import java.io.IOException; |
|
|
|
import java.io.InputStream; |
|
|
|
import java.math.BigDecimal; |
|
|
|
import java.text.SimpleDateFormat; |
|
|
|
import java.time.*; |
|
|
@@ -112,19 +114,32 @@ public class DkRecordServiceImpl implements DkRecordService { |
|
|
|
public void exportNew(DkCheckInRecordDTO dkCheckInRecordDTO, HttpServletResponse response) { |
|
|
|
// 获取所有人员 |
|
|
|
LambdaQueryWrapper<DkCheckInRecord> queryWrapper = buildQueryWrapper(dkCheckInRecordDTO, "export"); |
|
|
|
|
|
|
|
// 查询出所有人员 |
|
|
|
List<DkCheckInRecordDTO> dkCheckInRecordDTOS = dkMapper.selectVoList(queryWrapper); |
|
|
|
if(dkCheckInRecordDTOS.size() == 0){ |
|
|
|
return; |
|
|
|
} |
|
|
|
try { |
|
|
|
FileInputStream templateFile = null; |
|
|
|
InputStream inputStream = null; |
|
|
|
Workbook workbook; |
|
|
|
// 加载模板文件 |
|
|
|
if(Constans.GUONEI.equals(dkCheckInRecordDTO.getModelType())){ |
|
|
|
templateFile = new FileInputStream("template-guonei.xlsx"); |
|
|
|
// DkRecordServiceImpl.class.getClassLoader().getResourceAsStream("template/template-guonei.xlsx"); |
|
|
|
ClassPathResource resource = new ClassPathResource("template/template-guonei.xlsx"); |
|
|
|
inputStream = resource.getInputStream(); |
|
|
|
} |
|
|
|
if(Constans.RIBEN.equals(dkCheckInRecordDTO.getModelType())){ |
|
|
|
templateFile = new FileInputStream("template-riben.xlsx"); |
|
|
|
ClassPathResource resource = new ClassPathResource("template/template-riben.xlsx"); |
|
|
|
inputStream = resource.getInputStream(); |
|
|
|
} |
|
|
|
workbook = WorkbookFactory.create(templateFile); |
|
|
|
workbook = WorkbookFactory.create(inputStream); |
|
|
|
Sheet templateSheet = workbook.getSheetAt(0); |
|
|
|
|
|
|
|
// 遍历所有人员 |
|
|
|
for (int i = 0; i < dkCheckInRecordDTOS.size(); i++){ |
|
|
|
DkCheckInRecordDTO dk = dkCheckInRecordDTOS.get(i); |
|
|
|
|
|
|
@@ -148,14 +163,24 @@ public class DkRecordServiceImpl implements DkRecordService { |
|
|
|
// 准备数据 |
|
|
|
dkCheckInRecordDTO.setSysUserId(dk.getSysUserId()); |
|
|
|
dkCheckInRecordDTO.setSysUserName(dk.getSysUserName()); |
|
|
|
// 国内模版 |
|
|
|
if(Constans.GUONEI.equals(dkCheckInRecordDTO.getModelType())){ |
|
|
|
// 构造导出数据 |
|
|
|
EmployeeAttendance attendanceData = prepareSampleData(dkCheckInRecordDTO); |
|
|
|
// 填充数据到模板 |
|
|
|
if (attendanceData.getDayRecords().size() == 0){ |
|
|
|
return; |
|
|
|
} |
|
|
|
fillTemplate(newSheet, attendanceData); |
|
|
|
} |
|
|
|
// 日本模版 |
|
|
|
if(Constans.RIBEN.equals(dkCheckInRecordDTO.getModelType())){ |
|
|
|
// 构造导出数据 |
|
|
|
EmployeeAttendance attendanceData = prepareSampleDataRiBen(dkCheckInRecordDTO); |
|
|
|
// 填充数据到模板 |
|
|
|
if (attendanceData.getDayRecords().size() == 0){ |
|
|
|
return; |
|
|
|
} |
|
|
|
fillTemplateRiBen(newSheet, attendanceData); |
|
|
|
} |
|
|
|
|
|
|
@@ -227,6 +252,9 @@ public class DkRecordServiceImpl implements DkRecordService { |
|
|
|
// 根据用户的ID查询该用户所有的打卡记录 |
|
|
|
LambdaQueryWrapper<DkCheckInRecord> queryWrapper = buildQueryWrapper(dkCheckInRecordDTO, null); |
|
|
|
List<DkCheckInRecordDTO> dkCheckInRecordDTOS = dkMapper.selectVoList(queryWrapper); |
|
|
|
if (dkCheckInRecordDTOS == null && dkCheckInRecordDTOS.isEmpty()){ |
|
|
|
return data; |
|
|
|
} |
|
|
|
// 构造excel数据 |
|
|
|
for(DkCheckInRecordDTO dk : dkCheckInRecordDTOS){ |
|
|
|
// 根据打卡时间获取日期 |