Commit 2d1e86cd by 谢春璐

加班信息导入

parent 0d4c5114
......@@ -7,8 +7,11 @@ import com.zanchina.check.service.FileService;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.stream.Collectors;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
......@@ -49,10 +52,11 @@ public class FileController {
.getFiles("file");
List<Staff> staffList = new ArrayList<>();
Map<String, Set<String>> overtimeMap = new HashMap<>();
files = files.stream().filter(f -> StringUtils.isNotBlank(f.getOriginalFilename()))
.collect(Collectors.toList());
files.forEach(file -> {
for (MultipartFile file : files) {
try {
InputStream inputStream = file.getInputStream();
......@@ -66,6 +70,9 @@ public class FileController {
} else if (fileName.contains("外出打卡_日报")) {
data = inst.parse(inputStream, fileName, false, 2);
staffs = fileService.wechatWorkOutStatistics(data);
} else if (fileName.contains("审批记录")) {//加班
data = inst.parse(inputStream, fileName, false, 0);
overtimeMap = fileService.overtimeRecord(data);
} else if (fileName.contains("考勤导出")) {
data = inst.parse(inputStream, fileName, false, 0);
staffs = fileService.workRecord(data);
......@@ -78,10 +85,10 @@ public class FileController {
} catch (IOException e) {
e.printStackTrace();
}
});
}
List<Staff> staffList1 = fileService.staffListCollect(staffList);
return fileService.checkExport(staffList1);
return fileService.checkExport(staffList1, overtimeMap);
} catch (Exception e) {
try {
......
......@@ -3,7 +3,11 @@ package com.zanchina.check.service;
import com.zanchina.check.common.ExcelData;
import com.zanchina.check.domain.Staff;
import java.text.ParseException;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.xml.crypto.Data;
import org.springframework.http.ResponseEntity;
/**
......@@ -12,7 +16,7 @@ import org.springframework.http.ResponseEntity;
public interface FileService {
ResponseEntity<byte[]> checkExport(List<Staff> staffList) throws Exception;
ResponseEntity<byte[]> checkExport(List<Staff> staffList, Map<String, Set<String>> map) throws Exception;
List<Staff> wechatWorkOutStatistics(ExcelData data);
......@@ -23,4 +27,6 @@ public interface FileService {
List<Staff> staffListCollect(List<Staff> staffList);
List<Staff> dingdingWorkStatistics(ExcelData data);
Map<String, Set<String>> overtimeRecord(ExcelData data);
}
......@@ -8,13 +8,21 @@ import com.zanchina.check.domain.WorkCheck;
import com.zanchina.check.service.FileService;
import java.io.File;
import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.temporal.ChronoUnit;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import javax.xml.crypto.Data;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.StringUtils;
......@@ -316,7 +324,8 @@ public class FileServiceImpl implements FileService {
}
@Override
public ResponseEntity<byte[]> checkExport(List<Staff> staffList) throws Exception {
public ResponseEntity<byte[]> checkExport(List<Staff> staffList, Map<String, Set<String>> overtimeMap)
throws Exception {
ExcelData data = new ExcelData();
......@@ -357,6 +366,9 @@ public class FileServiceImpl implements FileService {
staffList.forEach(staff -> {
String[] d = new String[titleStrArr.length];
//查看此人是否有加班数据
Set<String> strings = overtimeMap.get(staff.getName());
for (String title : titleList) {
if ("姓名".equalsIgnoreCase(title)) {
d[0] = staff.getName().concat("(").concat(staff.getDepartment()).concat(")");
......@@ -368,18 +380,33 @@ public class FileServiceImpl implements FileService {
boolean isWeekend = week.equalsIgnoreCase(Integer.toString(6)) || week
.equalsIgnoreCase(Integer.toString(7));
String today = title.substring(0, title.indexOf("("));
String detail = "";
Boolean isOverTime = false;
// 判断当天是否有加班数据
if (Objects.nonNull(strings) && !strings.isEmpty()) {
List<String> overtime = strings.stream().filter(s -> s.equalsIgnoreCase(today))
.collect(Collectors.toList());
if (Objects.nonNull(overtime) && overtime.size() > 0) {
isOverTime = true;
}
}
for (WorkCheck check : staff.getWorkCheckList()) {
if (title.substring(0, title.indexOf("(")).equalsIgnoreCase(
if (today.equalsIgnoreCase(
DateUtils.format(DateUtils.parseDate(check.getDate()), DateUtils.yyyyMMdd))) {
isExist = true;
String detail = "";
if (!isWeekend) {
detail = check.getState().concat(",").concat(check.getApprove());
}
if (isExist && isWeekend) {
detail = "加班";
if (isOverTime) {
detail.concat("加班");
}
d[index] = detail.concat("(")
......@@ -396,11 +423,15 @@ public class FileServiceImpl implements FileService {
}
if (!isExist) {
if (!isWeekend) {
d[index] = "无记录";
if (isWeekend) {
if (isOverTime) {
d[index] = "加班";
} else {
d[index] = "未加班";
}
} else {
d[index] = "无记录";
}
}
}
}
......@@ -420,4 +451,42 @@ public class FileServiceImpl implements FileService {
headers.setContentDispositionFormData("attachment", dfileName);
return new ResponseEntity<>(FileUtils.readFileToByteArray(dst), headers, HttpStatus.CREATED);
}
@Override
public Map<String, Set<String>> overtimeRecord(ExcelData data) {
//1. 根据员工姓名分组
Map<String, List<String[]>> map = data.getDatas().stream().collect(Collectors.groupingBy(d -> d[2]));
Map<String, Set<String>> overtimeData = new HashMap<>();
map.entrySet().forEach(entry -> {
String name = entry.getKey();
List<String[]> value = entry.getValue();
Set<String> dateList = new HashSet<>();
value.stream().filter(strings -> strings[9].equalsIgnoreCase("已通过"))
.forEach(strings1 -> {
try {
String start = DateUtils
.formatDate(DateUtils.parseDate(strings1[6], DateUtils.yyyyMMddHHmm1),
DateUtils.yyyyMMdd);
String end = DateUtils
.formatDate(DateUtils.parseDate(strings1[7], DateUtils.yyyyMMddHHmm1),
DateUtils.yyyyMMdd);
dateList.addAll(DateUtils.getAllDatesOfTwoDate(start, end));
} catch (Exception e) {
e.printStackTrace();
}
});
overtimeData.put(name, dateList);
});
return overtimeData;
}
}
......@@ -23,6 +23,14 @@
<td><input type="file" name="file"/></td>
</tr>
<tr>
<th scope="row">企业微信加班审批记录:</th>
<td><input type="file" name="file"/></td>
</tr>
<tr>
<th scope="row">企业微信请假审批记录:</th>
<td><input type="file" name="file"/></td>
</tr>
<tr>
<th scope="row">打卡机考勤记录:</th>
<td><input type="file" name="file"/></td>
</tr>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment