|
|
@@ -16,6 +16,7 @@ import com.management.platform.util.*;
|
|
|
import org.apache.poi.EncryptedDocumentException;
|
|
|
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
|
|
|
import org.apache.poi.ss.usermodel.*;
|
|
|
+import org.apache.poi.xssf.streaming.SXSSFWorkbook;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.util.StringUtils;
|
|
|
@@ -2534,16 +2535,10 @@ public class UserCorpwxTimeController {
|
|
|
}
|
|
|
|
|
|
|
|
|
- @RequestMapping("/getUserFictitiousAttendanceList")
|
|
|
- public HttpRespMsg getUserFictitiousAttendanceList(String month, Integer pageIndex, Integer pageSize){
|
|
|
+ @RequestMapping("/getUserCorpwvTimeList")
|
|
|
+ public HttpRespMsg getUserCorpwvTimeList(String month, Integer pageIndex, Integer pageSize){
|
|
|
HttpRespMsg httpRespMsg = new HttpRespMsg();
|
|
|
try {
|
|
|
- if (pageIndex == null || pageIndex < 1) {
|
|
|
- pageIndex = 1;
|
|
|
- }
|
|
|
- if (pageSize == null || pageSize < 1) {
|
|
|
- pageSize = 20;
|
|
|
- }
|
|
|
String token = request.getHeader("TOKEN");
|
|
|
User loginUser = userMapper.selectById(token);
|
|
|
if (loginUser == null) {
|
|
|
@@ -2556,10 +2551,13 @@ public class UserCorpwxTimeController {
|
|
|
LocalDate monthStart = LocalDate.parse(month + "-01", DateTimeFormatter.ofPattern("yyyy-MM-dd"));
|
|
|
LocalDate monthEnd = monthStart.plusMonths(1).minusDays(1);
|
|
|
int daysInMonth = monthStart.lengthOfMonth();
|
|
|
- List<SysRichFunction> functionList = sysFunctionMapper.getRoleFunctions(loginUser.getRoleId(), "全部员工假勤数据");
|
|
|
+ List<SysRichFunction> functionList = sysFunctionMapper.getRoleFunctions(loginUser.getRoleId(), "全部员工考勤数据");
|
|
|
+ QueryWrapper<User> userWrapper = new QueryWrapper<User>()
|
|
|
+ .eq("company_id", loginUser.getCompanyId());
|
|
|
QueryWrapper<UserCorpwxTime> monthQuery = new QueryWrapper<UserCorpwxTime>()
|
|
|
.eq("company_id", loginUser.getCompanyId())
|
|
|
.between("create_date", monthStart, monthEnd);
|
|
|
+ monthQuery.orderByAsc("create_date", "name");
|
|
|
if (functionList == null || functionList.isEmpty()) {
|
|
|
Integer manageDeptId = loginUser.getManageDeptId();
|
|
|
List<Integer> deptIds = new ArrayList<>();
|
|
|
@@ -2568,27 +2566,32 @@ public class UserCorpwxTimeController {
|
|
|
deptIds = departmentService.getAllManagedDeptIdList(loginUser, allDeptList);
|
|
|
}
|
|
|
if (deptIds.isEmpty()) {
|
|
|
- monthQuery.in("corpwx_userid", Collections.singletonList("__NONE__"));
|
|
|
+ userWrapper.in("corpwx_userid", Collections.singletonList("__NONE__"));
|
|
|
} else {
|
|
|
List<User> deptUserList = userMapper.selectList(new QueryWrapper<User>().eq("company_id", loginUser.getCompanyId()).in("department_id", deptIds));
|
|
|
List<String> deptCorpwxUserIds = deptUserList.stream().map(User::getCorpwxUserid).filter(org.springframework.util.StringUtils::hasText).collect(Collectors.toList());
|
|
|
List<String> deptNames = deptUserList.stream().map(User::getName).filter(org.springframework.util.StringUtils::hasText).collect(Collectors.toList());
|
|
|
if (!deptCorpwxUserIds.isEmpty() && !deptNames.isEmpty()) {
|
|
|
- monthQuery.and(q -> q.in("corpwx_userid", deptCorpwxUserIds).or().in("name", deptNames));
|
|
|
+ userWrapper.and(q -> q.in("corpwx_userid", deptCorpwxUserIds).or().in("name", deptNames));
|
|
|
} else if (!deptCorpwxUserIds.isEmpty()) {
|
|
|
- monthQuery.in("corpwx_userid", deptCorpwxUserIds);
|
|
|
+ userWrapper.in("corpwx_userid", deptCorpwxUserIds);
|
|
|
} else if (!deptNames.isEmpty()) {
|
|
|
- monthQuery.in("name", deptNames);
|
|
|
+ userWrapper.in("name", deptNames);
|
|
|
} else {
|
|
|
- monthQuery.in("corpwx_userid", Collections.singletonList("__NONE__"));
|
|
|
+ userWrapper.in("corpwx_userid", Collections.singletonList("__NONE__"));
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- monthQuery.orderByAsc("create_date", "name");
|
|
|
- Page<UserCorpwxTime> page = new Page<>(pageIndex, pageSize);
|
|
|
- IPage<UserCorpwxTime> monthPage = userCorpwxTimeMapper.selectPage(page, monthQuery);
|
|
|
- List<UserCorpwxTime> monthList = monthPage.getRecords();
|
|
|
|
|
|
+ Page<User> userPage = new Page<>(pageIndex, pageSize);
|
|
|
+ IPage<User> userIPage = userMapper.selectPage(userPage, userWrapper);
|
|
|
+ List<User> userList = userIPage.getRecords();
|
|
|
+ List<String> userIds = userList.stream().map(User::getCorpwxUserid).distinct().collect(Collectors.toList());
|
|
|
+ if(userIds.size()>0){
|
|
|
+ monthQuery.in("corpwx_userid",userIds);
|
|
|
+ }
|
|
|
+ monthQuery.orderByAsc("create_date", "name");
|
|
|
+ List<UserCorpwxTime> monthList = userCorpwxTimeMapper.selectList(monthQuery);
|
|
|
List<LocalDate> restDayDates = WorkDayCalculateUtils.getNonWorkDaysListInRange(
|
|
|
monthStart.format(DateTimeFormatter.ofPattern("yyyy-MM-dd")),
|
|
|
monthEnd.format(DateTimeFormatter.ofPattern("yyyy-MM-dd"))
|
|
|
@@ -2596,39 +2599,404 @@ public class UserCorpwxTimeController {
|
|
|
List<String> restDayList = restDayDates.stream().map(d -> d.format(DateTimeFormatter.ofPattern("yyyy-MM-dd"))).collect(Collectors.toList());
|
|
|
|
|
|
Map<String, List<UserCorpwxTime>> grouped = monthList.stream()
|
|
|
- .collect(Collectors.groupingBy(item -> item.getCorpwxUserid() != null ? item.getCorpwxUserid() : item.getName(), LinkedHashMap::new, Collectors.toList()));
|
|
|
+ .collect(Collectors.groupingBy(item -> {
|
|
|
+ if (item.getCorpwxUserid() != null && !item.getCorpwxUserid().isEmpty()) {
|
|
|
+ return item.getCorpwxUserid();
|
|
|
+ }
|
|
|
+ return item.getName();
|
|
|
+ }, LinkedHashMap::new, Collectors.toList()));
|
|
|
|
|
|
List<Map<String, Object>> attendanceList = new ArrayList<>();
|
|
|
DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
|
|
+ for (User sysUser : userList) {
|
|
|
+ Map<String, Object> row = new HashMap<>();
|
|
|
+ List<UserCorpwxTime> userTimes = monthList.stream().filter(i->i.getCorpwxUserid().equals(sysUser.getCorpwxUserid())).collect(Collectors.toList());
|
|
|
+ row.put("userId", sysUser.getId());
|
|
|
+ row.put("employeeName", sysUser.getCorpwxUserid());
|
|
|
+ row.put("jobNumber", sysUser.getJobNumber());
|
|
|
+ row.put("departmentName",sysUser.getCorpwxDeptid());
|
|
|
+ Map<String, UserCorpwxTime> dayMap = userTimes.stream()
|
|
|
+ .collect(Collectors.toMap(t -> t.getCreateDate().format(df), t -> t, (a, b) -> a));
|
|
|
+ List<String> attendanceArray = new ArrayList<>();
|
|
|
+ double legalHolidayCount = 0D;
|
|
|
+ double yearLeaveCount = 0D;
|
|
|
+ double marriageLeaveCount = 0D;
|
|
|
+ double paternityLeaveCount = 0D;
|
|
|
+ double maternityLeaveCount = 0D;
|
|
|
+ double bereavementLeaveCount = 0D;
|
|
|
+ double transferLeaveCount = 0D;
|
|
|
+ double sickLeaveCount = 0D;
|
|
|
+ double personalLeaveCount = 0D;
|
|
|
+ int lateCount = 0;
|
|
|
+ int missingCardCount = 0;
|
|
|
+ Set<String> nonWorkDaySet = new HashSet<>(restDayList);
|
|
|
+ legalHolidayCount=nonWorkDaySet.size();
|
|
|
+ for (int i = 1; i <= daysInMonth; i++) {
|
|
|
+ LocalDate date = monthStart.withDayOfMonth(i);
|
|
|
+ String dateStr = date.format(df);
|
|
|
+ UserCorpwxTime time = dayMap.get(dateStr);
|
|
|
+ String value = "";
|
|
|
+ if (time != null) {
|
|
|
+ String leaveType = StringUtils.hasText(time.getAskLeaveType()) ? time.getAskLeaveType().trim() : "";
|
|
|
+ if (time.getAskLeaveTime() != null && time.getAskLeaveTime() > 0) {
|
|
|
+ if ("年假".equals(leaveType)) {
|
|
|
+ yearLeaveCount +=1;
|
|
|
+ } else if ("婚假".equals(leaveType)) {
|
|
|
+ marriageLeaveCount +=1;
|
|
|
+ } else if ("陪产假".equals(leaveType)) {
|
|
|
+ paternityLeaveCount +=1;
|
|
|
+ } else if ("产假".equals(leaveType)) {
|
|
|
+ maternityLeaveCount +=1;
|
|
|
+ } else if ("丧假".equals(leaveType)) {
|
|
|
+ bereavementLeaveCount +=1;
|
|
|
+ } else if ("T".equals(leaveType)) {
|
|
|
+ transferLeaveCount +=1;
|
|
|
+ } else if ("B".equals(leaveType)) {
|
|
|
+ sickLeaveCount +=1;
|
|
|
+ } else if ("事假".equals(leaveType)) {
|
|
|
+ personalLeaveCount +=1;
|
|
|
+ }
|
|
|
+ value = leaveType+time.getAskLeaveTime();
|
|
|
+ } else if (time.getWorkHours() != null && time.getWorkHours() > 0) {
|
|
|
+ value ="√";
|
|
|
+ } else if (time.getCardTime() != null && time.getCardTime() > 0) {
|
|
|
+ value = String.valueOf(time.getCardTime());
|
|
|
+ }
|
|
|
+ if (time.getOtStatus() != null && time.getOtStatus() == 2) {
|
|
|
+ missingCardCount += 1;
|
|
|
+ }
|
|
|
+ if (time.getCardTime() != null && time.getCardTime() > 0 && time.getCardTime() < 1.0) {
|
|
|
+ lateCount += 1;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ attendanceArray.add(value);
|
|
|
+ }
|
|
|
+ row.put("attendanceArray", attendanceArray);
|
|
|
+ row.put("legalHolidayCount", legalHolidayCount);
|
|
|
+ row.put("yearLeaveCount", yearLeaveCount);
|
|
|
+ row.put("marriageLeaveCount", marriageLeaveCount);
|
|
|
+ row.put("paternityLeaveCount", paternityLeaveCount);
|
|
|
+ row.put("maternityLeaveCount", maternityLeaveCount);
|
|
|
+ row.put("bereavementLeaveCount", bereavementLeaveCount);
|
|
|
+ row.put("transferLeaveCount", transferLeaveCount);
|
|
|
+ row.put("sickLeaveCount", sickLeaveCount);
|
|
|
+ row.put("personalLeaveCount", personalLeaveCount);
|
|
|
+ row.put("lateCount", lateCount);
|
|
|
+ row.put("missingCardCount", missingCardCount);
|
|
|
+ row.put("shouldAttendCount", daysInMonth - restDayList.size());
|
|
|
+ row.put("actualAttendanceCount", attendanceArray.stream().filter(s -> s != null && !s.isEmpty() && "√".equals(s)).count());
|
|
|
+ row.put("daysCount", daysInMonth);
|
|
|
+ attendanceList.add(row);
|
|
|
+ }
|
|
|
for (Map.Entry<String, List<UserCorpwxTime>> entry : grouped.entrySet()) {
|
|
|
List<UserCorpwxTime> userTimes = entry.getValue();
|
|
|
if (userTimes.isEmpty()) {
|
|
|
continue;
|
|
|
}
|
|
|
- UserCorpwxTime first = userTimes.get(0);
|
|
|
- Map<String, Object> row = new HashMap<>();
|
|
|
- row.put("userId", first.getCorpwxUserid());
|
|
|
- row.put("employeeName", first.getName());
|
|
|
- row.put("jobNumber", null);
|
|
|
- User sysUser = null;
|
|
|
- if (first.getCorpwxUserid() != null) {
|
|
|
- sysUser = userMapper.selectOne(new QueryWrapper<User>().eq("corpwx_userid", first.getCorpwxUserid()).eq("company_id", loginUser.getCompanyId()));
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ Map<String, Object> result = new HashMap<>();
|
|
|
+ List<String> dateList = new ArrayList<>();
|
|
|
+ List<String> weekList = new ArrayList<>();
|
|
|
+ for (int i = 1; i <= daysInMonth; i++) {
|
|
|
+ LocalDate date = monthStart.withDayOfMonth(i);
|
|
|
+ dateList.add(String.valueOf(i));
|
|
|
+ weekList.add(date.getDayOfWeek().getDisplayName(TextStyle.SHORT, Locale.CHINESE).replace("星期", ""));
|
|
|
+ }
|
|
|
+ result.put("dateList", dateList);
|
|
|
+ result.put("weekList", weekList);
|
|
|
+ result.put("restDayList", restDayList);
|
|
|
+ result.put("list", attendanceList);
|
|
|
+ result.put("records", attendanceList);
|
|
|
+ result.put("total", userPage.getTotal());
|
|
|
+ httpRespMsg.data = result;
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ httpRespMsg.setError("获取员工考勤数据失败:" + e.getMessage());
|
|
|
+ }
|
|
|
+ return httpRespMsg;
|
|
|
+ }
|
|
|
+
|
|
|
+ @RequestMapping("/exportEmployeeHolidayExcel")
|
|
|
+ public HttpRespMsg exportEmployeeHolidayExcel(String month) throws Exception {
|
|
|
+ HttpRespMsg msg = new HttpRespMsg();
|
|
|
+ String token = request.getHeader("TOKEN");
|
|
|
+ User loginUser = userMapper.selectById(token);
|
|
|
+ if (loginUser == null) {
|
|
|
+ msg.setError("未获取到登录用户");
|
|
|
+ return msg;
|
|
|
+ }
|
|
|
+ if (month == null || month.trim().isEmpty()) {
|
|
|
+ month = LocalDate.now().format(DateTimeFormatter.ofPattern("yyyy-MM"));
|
|
|
+ }
|
|
|
+ HttpRespMsg ret = getUserFictitiousAttendanceList(month, -1, -1);
|
|
|
+ if (ret == null || ret.data == null) {
|
|
|
+ msg.setError("获取员工假勤数据失败");
|
|
|
+ return msg;
|
|
|
+ }
|
|
|
+ HashMap map = (HashMap) ret.data;
|
|
|
+ List<Map<String, Object>> list = (List<Map<String, Object>>) map.get("list");
|
|
|
+ List<String> dateList = (List<String>) map.get("dateList");
|
|
|
+ List<String> weekList = (List<String>) map.get("weekList");
|
|
|
+ List<String> restDayList = (List<String>) map.get("restDayList");
|
|
|
+ String fileName = System.currentTimeMillis() + "员工假勤表_" + month;
|
|
|
+ WxCorpInfo wxCorpInfo = wxCorpInfoMapper.selectOne(new LambdaQueryWrapper<WxCorpInfo>().eq(WxCorpInfo::getCompanyId, loginUser.getCompanyId()));
|
|
|
+ CompanyDingding dingding = companyDingdingMapper.selectOne(new LambdaQueryWrapper<CompanyDingding>().eq(CompanyDingding::getCompanyId, loginUser.getCompanyId()));
|
|
|
+ String fileUrl = exportAttendanceWithMergedHeader(wxCorpInfo,fileName, month, dateList, weekList, restDayList, list, false);
|
|
|
+ if (loginUser.getCompanyId() != null) {
|
|
|
+ if ((wxCorpInfo != null && wxCorpInfo.getSaasSyncContact() == 1) || (dingding != null && dingding.getContactNeedTranslate() == 1)) {
|
|
|
+ msg.data = excelExportService.exportTranForwx(wxCorpInfo, dingding, fileName).data;
|
|
|
+ return msg;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ msg.data = fileUrl;
|
|
|
+ return msg;
|
|
|
+ }
|
|
|
+
|
|
|
+ @RequestMapping("/exportEmployeeCorpTimeExcel")
|
|
|
+ public HttpRespMsg exportEmployeeCorpTimeExcel(String month) throws Exception {
|
|
|
+ HttpRespMsg msg = new HttpRespMsg();
|
|
|
+ String token = request.getHeader("TOKEN");
|
|
|
+ User loginUser = userMapper.selectById(token);
|
|
|
+ if (loginUser == null) {
|
|
|
+ msg.setError("未获取到登录用户");
|
|
|
+ return msg;
|
|
|
+ }
|
|
|
+ if (month == null || month.trim().isEmpty()) {
|
|
|
+ month = LocalDate.now().format(DateTimeFormatter.ofPattern("yyyy-MM"));
|
|
|
+ }
|
|
|
+ HttpRespMsg ret = getUserCorpwvTimeList(month, -1, -1);
|
|
|
+ if (ret == null || ret.data == null) {
|
|
|
+ msg.setError("获取员工考勤数据失败");
|
|
|
+ return msg;
|
|
|
+ }
|
|
|
+ HashMap map = (HashMap) ret.data;
|
|
|
+ List<Map<String, Object>> list = (List<Map<String, Object>>) map.get("list");
|
|
|
+ List<String> dateList = (List<String>) map.get("dateList");
|
|
|
+ List<String> weekList = (List<String>) map.get("weekList");
|
|
|
+ List<String> restDayList = (List<String>) map.get("restDayList");
|
|
|
+ String fileName = System.currentTimeMillis() + "员工考勤表_" + month;
|
|
|
+ WxCorpInfo wxCorpInfo = wxCorpInfoMapper.selectOne(new LambdaQueryWrapper<WxCorpInfo>().eq(WxCorpInfo::getCompanyId, loginUser.getCompanyId()));
|
|
|
+ CompanyDingding dingding = companyDingdingMapper.selectOne(new LambdaQueryWrapper<CompanyDingding>().eq(CompanyDingding::getCompanyId, loginUser.getCompanyId()));
|
|
|
+ String fileUrl = exportAttendanceWithMergedHeader(wxCorpInfo,fileName, month, dateList, weekList, restDayList, list, true);
|
|
|
+ if (loginUser.getCompanyId() != null) {
|
|
|
+ if ((wxCorpInfo != null && wxCorpInfo.getSaasSyncContact() == 1) || (dingding != null && dingding.getContactNeedTranslate() == 1)) {
|
|
|
+ msg.data = excelExportService.exportTranForwx(wxCorpInfo, dingding, fileName).data;
|
|
|
+ return msg;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ msg.data = fileUrl;
|
|
|
+ return msg;
|
|
|
+ }
|
|
|
+
|
|
|
+ private String exportAttendanceWithMergedHeader(WxCorpInfo wxCorpInfo,String fileName, String month, List<String> dateList, List<String> weekList, List<String> restDayList, List<Map<String, Object>> rows, boolean isCorpTime) throws Exception {
|
|
|
+ SXSSFWorkbook workBook = new SXSSFWorkbook();
|
|
|
+ Sheet sheet = workBook.createSheet();
|
|
|
+ sheet.setDefaultColumnWidth(14);
|
|
|
+ sheet.createFreezePane(0, 2);
|
|
|
+ Font headFont = workBook.createFont();
|
|
|
+ headFont.setBold(true);
|
|
|
+ headFont.setFontHeightInPoints((short) 10);
|
|
|
+ headFont.setFontName("黑体");
|
|
|
+ Font font = workBook.createFont();
|
|
|
+ font.setFontHeightInPoints((short) 10);
|
|
|
+ font.setFontName("宋体");
|
|
|
+ CellStyle headStyle = workBook.createCellStyle();
|
|
|
+ headStyle.setFont(headFont);
|
|
|
+ headStyle.setAlignment(HorizontalAlignment.CENTER);
|
|
|
+ headStyle.setVerticalAlignment(VerticalAlignment.CENTER);
|
|
|
+ headStyle.setWrapText(true);
|
|
|
+ headStyle.setBorderBottom(BorderStyle.THIN);
|
|
|
+ headStyle.setBorderLeft(BorderStyle.THIN);
|
|
|
+ headStyle.setBorderTop(BorderStyle.THIN);
|
|
|
+ headStyle.setBorderRight(BorderStyle.THIN);
|
|
|
+ CellStyle cellStyle = workBook.createCellStyle();
|
|
|
+ cellStyle.setFont(font);
|
|
|
+ cellStyle.setAlignment(HorizontalAlignment.CENTER);
|
|
|
+ cellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
|
|
|
+ cellStyle.setWrapText(true);
|
|
|
+ cellStyle.setBorderBottom(BorderStyle.THIN);
|
|
|
+ cellStyle.setBorderLeft(BorderStyle.THIN);
|
|
|
+ cellStyle.setBorderTop(BorderStyle.THIN);
|
|
|
+ cellStyle.setBorderRight(BorderStyle.THIN);
|
|
|
+
|
|
|
+ CellStyle restDayStyle = workBook.createCellStyle();
|
|
|
+ restDayStyle.cloneStyleFrom(cellStyle);
|
|
|
+ restDayStyle.setFillForegroundColor(IndexedColors.BRIGHT_GREEN.getIndex());
|
|
|
+ restDayStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
|
|
|
+
|
|
|
+ Row header1 = sheet.createRow(0);
|
|
|
+ Row header2 = sheet.createRow(1);
|
|
|
+ header1.setHeightInPoints(24);
|
|
|
+ header2.setHeightInPoints(24);
|
|
|
+ String[] fixedHeaders = new String[]{"序号", "姓名", "部门"};
|
|
|
+ for (int i = 0; i < fixedHeaders.length; i++) {
|
|
|
+ Cell c1 = header1.createCell(i);
|
|
|
+ c1.setCellStyle(headStyle);
|
|
|
+ c1.setCellValue(fixedHeaders[i]);
|
|
|
+ Cell c2 = header2.createCell(i);
|
|
|
+ c2.setCellStyle(headStyle);
|
|
|
+ c2.setCellValue("");
|
|
|
+ sheet.addMergedRegion(new org.apache.poi.ss.util.CellRangeAddress(0, 1, i, i));
|
|
|
+ }
|
|
|
+ int col = 3;
|
|
|
+ for (int i = 0; i < dateList.size(); i++) {
|
|
|
+ Cell c1 = header1.createCell(col);
|
|
|
+ c1.setCellStyle(headStyle);
|
|
|
+ c1.setCellValue(dateList.get(i));
|
|
|
+ Cell c2 = header2.createCell(col);
|
|
|
+ c2.setCellStyle(headStyle);
|
|
|
+ c2.setCellValue(weekList != null && i < weekList.size() ? weekList.get(i) : "");
|
|
|
+ col++;
|
|
|
+ }
|
|
|
+ String[] tailHeaders = isCorpTime ? new String[]{"法定假/天", "年休假/天", "婚假/天", "陪产假/天", "产假/天", "丧假/天", "调休假/天", "病假/天", "事假/天", "迟到", "缺卡", "本月应出勤天数", "本月实际出勤天数"} : new String[]{"本月请假工时(h)"};
|
|
|
+ for (String tailHeader : tailHeaders) {
|
|
|
+ Cell c1 = header1.createCell(col);
|
|
|
+ c1.setCellStyle(headStyle);
|
|
|
+ c1.setCellValue(tailHeader);
|
|
|
+ Cell c2 = header2.createCell(col);
|
|
|
+ c2.setCellStyle(headStyle);
|
|
|
+ c2.setCellValue("");
|
|
|
+ sheet.addMergedRegion(new org.apache.poi.ss.util.CellRangeAddress(0, 1, col, col));
|
|
|
+ col++;
|
|
|
+ }
|
|
|
+
|
|
|
+ for (int r = 0; r < rows.size(); r++) {
|
|
|
+ Map<String, Object> row = rows.get(r);
|
|
|
+ Row dataRow = sheet.createRow(r + 2);
|
|
|
+ dataRow.setHeightInPoints(24);
|
|
|
+ int c = 0;
|
|
|
+ setCell(dataRow, c++, String.valueOf(r + 1), cellStyle);
|
|
|
+ if(wxCorpInfo != null && wxCorpInfo.getSaasSyncContact() == 1){
|
|
|
+ setCell(dataRow, c++, String.valueOf(row.get("employeeName") == null ? "" :("$userName="+row.get("employeeName")+"$")) , cellStyle);
|
|
|
+ setCell(dataRow, c++, String.valueOf(row.get("departmentName") == null ? "" : ("$departmentName="+row.get("departmentName")+"$")), cellStyle);
|
|
|
+ }else {
|
|
|
+ setCell(dataRow, c++, String.valueOf(row.get("employeeName") == null ? "" : row.get("employeeName")), cellStyle);
|
|
|
+ setCell(dataRow, c++, String.valueOf(row.get("departmentName") == null ? "" : row.get("departmentName")), cellStyle);
|
|
|
+ }
|
|
|
+ List<?> arr = (List<?>) row.get(isCorpTime ? "attendanceArray" : "fictitiousAttendanceArray");
|
|
|
+ Set<String> restDaySet = restDayList == null ? new HashSet<>() : new HashSet<>(restDayList);
|
|
|
+ for (int i = 0; i < dateList.size(); i++) {
|
|
|
+ Object v = arr != null && i < arr.size() ? arr.get(i) : "";
|
|
|
+ boolean isRestDay = restDaySet.contains(monthToDateString(dateList.get(i), month));
|
|
|
+ setCell(dataRow, c++, v == null ? "" : String.valueOf(v), isRestDay ? restDayStyle : cellStyle);
|
|
|
+ }
|
|
|
+ if (isCorpTime) {
|
|
|
+ String[] keys = new String[]{"legalHolidayCount", "yearLeaveCount", "marriageLeaveCount", "paternityLeaveCount", "maternityLeaveCount", "bereavementLeaveCount", "transferLeaveCount", "sickLeaveCount", "personalLeaveCount", "lateCount", "missingCardCount", "shouldAttendCount", "actualAttendanceCount"};
|
|
|
+ for (String key : keys) {
|
|
|
+ Object v = row.get(key);
|
|
|
+ setCell(dataRow, c++, v == null ? "0" : String.valueOf(v), cellStyle);
|
|
|
}
|
|
|
- if (sysUser == null && first.getName() != null) {
|
|
|
- sysUser = userMapper.selectOne(new QueryWrapper<User>().eq("name", first.getName()).eq("company_id", loginUser.getCompanyId()));
|
|
|
+ } else {
|
|
|
+ Object v = row.get("holidayCount");
|
|
|
+ setCell(dataRow, c++, v == null ? "0" : String.valueOf(v), cellStyle);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ File dir = new File(path);
|
|
|
+ if (!dir.exists()) {
|
|
|
+ dir.mkdirs();
|
|
|
+ }
|
|
|
+ FileOutputStream os = new FileOutputStream(path + fileName + ".xlsx");
|
|
|
+ workBook.write(os);
|
|
|
+ os.flush();
|
|
|
+ os.close();
|
|
|
+ workBook.dispose();
|
|
|
+ return "/upload/" + fileName + ".xlsx";
|
|
|
+ }
|
|
|
+
|
|
|
+ private void setCell(Row row, int index, String value, CellStyle style) {
|
|
|
+ Cell cell = row.createCell(index);
|
|
|
+ cell.setCellStyle(style);
|
|
|
+ cell.setCellValue(value == null ? "" : value);
|
|
|
+ }
|
|
|
+
|
|
|
+ private String monthToDateString(String dayText, String month) {
|
|
|
+ if (dayText == null || dayText.trim().isEmpty() || month == null || month.trim().isEmpty()) {
|
|
|
+ return "";
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ int day = Integer.parseInt(dayText.trim());
|
|
|
+ return month + "-" + String.format("%02d", day);
|
|
|
+ } catch (Exception e) {
|
|
|
+ return "";
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @RequestMapping("/getUserFictitiousAttendanceList")
|
|
|
+ public HttpRespMsg getUserFictitiousAttendanceList(String month, Integer pageIndex, Integer pageSize){
|
|
|
+ HttpRespMsg httpRespMsg = new HttpRespMsg();
|
|
|
+ try {
|
|
|
+ String token = request.getHeader("TOKEN");
|
|
|
+ User loginUser = userMapper.selectById(token);
|
|
|
+ if (loginUser == null) {
|
|
|
+ httpRespMsg.setError("未获取到登录用户");
|
|
|
+ return httpRespMsg;
|
|
|
+ }
|
|
|
+ if (month == null || month.trim().isEmpty()) {
|
|
|
+ month = LocalDate.now().format(DateTimeFormatter.ofPattern("yyyy-MM"));
|
|
|
+ }
|
|
|
+ LocalDate monthStart = LocalDate.parse(month + "-01", DateTimeFormatter.ofPattern("yyyy-MM-dd"));
|
|
|
+ LocalDate monthEnd = monthStart.plusMonths(1).minusDays(1);
|
|
|
+ int daysInMonth = monthStart.lengthOfMonth();
|
|
|
+ List<SysRichFunction> functionList = sysFunctionMapper.getRoleFunctions(loginUser.getRoleId(), "全部员工假勤数据");
|
|
|
+ QueryWrapper<User> userWrapper = new QueryWrapper<User>()
|
|
|
+ .eq("company_id", loginUser.getCompanyId());
|
|
|
+ QueryWrapper<UserCorpwxTime> monthQuery = new QueryWrapper<UserCorpwxTime>()
|
|
|
+ .eq("company_id", loginUser.getCompanyId())
|
|
|
+ .between("create_date", monthStart, monthEnd);
|
|
|
+ if (functionList == null || functionList.isEmpty()) {
|
|
|
+ Integer manageDeptId = loginUser.getManageDeptId();
|
|
|
+ List<Integer> deptIds = new ArrayList<>();
|
|
|
+ if (manageDeptId != null && manageDeptId != 0) {
|
|
|
+ List<Department> allDeptList = departmentMapper.selectList(new QueryWrapper<Department>().eq("company_id", loginUser.getCompanyId()));
|
|
|
+ deptIds = departmentService.getAllManagedDeptIdList(loginUser, allDeptList);
|
|
|
}
|
|
|
- if (sysUser != null) {
|
|
|
- row.put("userId", sysUser.getId());
|
|
|
- row.put("employeeName", sysUser.getName());
|
|
|
- row.put("jobNumber", sysUser.getJobNumber());
|
|
|
- Department dept = null;
|
|
|
- if (sysUser.getDepartmentId() != null) {
|
|
|
- dept = departmentMapper.selectById(sysUser.getDepartmentId());
|
|
|
- }
|
|
|
- row.put("departmentName", dept == null ? "" : dept.getCorpwxDeptid());
|
|
|
+ if (deptIds.isEmpty()) {
|
|
|
+ userWrapper.in("corpwx_userid", Collections.singletonList("__NONE__"));
|
|
|
} else {
|
|
|
- row.put("departmentName", "");
|
|
|
+ List<User> deptUserList = userMapper.selectList(new QueryWrapper<User>().eq("company_id", loginUser.getCompanyId()).in("department_id", deptIds));
|
|
|
+ List<String> deptCorpwxUserIds = deptUserList.stream().map(User::getCorpwxUserid).filter(org.springframework.util.StringUtils::hasText).collect(Collectors.toList());
|
|
|
+ List<String> deptNames = deptUserList.stream().map(User::getName).filter(org.springframework.util.StringUtils::hasText).collect(Collectors.toList());
|
|
|
+ if (!deptCorpwxUserIds.isEmpty() && !deptNames.isEmpty()) {
|
|
|
+ userWrapper.and(q -> q.in("corpwx_userid", deptCorpwxUserIds).or().in("name", deptNames));
|
|
|
+ } else if (!deptCorpwxUserIds.isEmpty()) {
|
|
|
+ userWrapper.in("corpwx_userid", deptCorpwxUserIds);
|
|
|
+ } else if (!deptNames.isEmpty()) {
|
|
|
+ userWrapper.in("name", deptNames);
|
|
|
+ } else {
|
|
|
+ userWrapper.in("corpwx_userid", Collections.singletonList("__NONE__"));
|
|
|
+ }
|
|
|
}
|
|
|
+ }
|
|
|
+ monthQuery.orderByAsc("create_date", "name");
|
|
|
+ Page<User> userPage = new Page<>(pageIndex, pageSize);
|
|
|
+ IPage<User> userIPage = userMapper.selectPage(userPage, userWrapper);
|
|
|
+ List<User> userList = userIPage.getRecords();
|
|
|
+ List<String> userIds = userList.stream().map(User::getCorpwxUserid).distinct().collect(Collectors.toList());
|
|
|
+ if(userIds.size()>0){
|
|
|
+ monthQuery.in("corpwx_userid",userIds);
|
|
|
+ }
|
|
|
+ List<UserCorpwxTime> monthList = userCorpwxTimeMapper.selectList(monthQuery);
|
|
|
+ List<LocalDate> restDayDates = WorkDayCalculateUtils.getNonWorkDaysListInRange(
|
|
|
+ monthStart.format(DateTimeFormatter.ofPattern("yyyy-MM-dd")),
|
|
|
+ monthEnd.format(DateTimeFormatter.ofPattern("yyyy-MM-dd"))
|
|
|
+ );
|
|
|
+ List<String> restDayList = restDayDates.stream().map(d -> d.format(DateTimeFormatter.ofPattern("yyyy-MM-dd"))).collect(Collectors.toList());
|
|
|
+
|
|
|
+ Map<String, List<UserCorpwxTime>> grouped = monthList.stream()
|
|
|
+ .collect(Collectors.groupingBy(item -> item.getCorpwxUserid() != null ? item.getCorpwxUserid() : item.getName(), LinkedHashMap::new, Collectors.toList()));
|
|
|
+
|
|
|
+ List<Map<String, Object>> attendanceList = new ArrayList<>();
|
|
|
+ DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
|
|
+ for (User sysUser : userList) {
|
|
|
+ List<UserCorpwxTime> userTimes = monthList.stream().filter(i->i.getCorpwxUserid().equals(sysUser.getCorpwxUserid())).collect(Collectors.toList());
|
|
|
+ Map<String, Object> row = new HashMap<>();
|
|
|
+ row.put("userId", sysUser.getCorpwxUserid());
|
|
|
+ row.put("employeeName", sysUser.getCorpwxUserid());
|
|
|
+ row.put("jobNumber", sysUser.getJobNumber());
|
|
|
+ row.put("departmentName", sysUser.getCorpwxDeptid());
|
|
|
Map<String, UserCorpwxTime> dayMap = userTimes.stream().collect(Collectors.toMap(t -> t.getCreateDate().format(df), t -> t, (a, b) -> a));
|
|
|
List<String> attendanceArray = new ArrayList<>();
|
|
|
double holidayCount = 0;
|
|
|
@@ -2656,8 +3024,7 @@ public class UserCorpwxTimeController {
|
|
|
row.put("holidayCount", holidayCount);
|
|
|
attendanceList.add(row);
|
|
|
}
|
|
|
-
|
|
|
- int total = (int) monthPage.getTotal();
|
|
|
+ int total = (int) userPage.getTotal();
|
|
|
List<Map<String, Object>> pageList = attendanceList;
|
|
|
|
|
|
Map<String, Object> result = new HashMap<>();
|