| | |
| | | import cn.hutool.core.date.DateTime; |
| | | import cn.hutool.core.date.DateUtil; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.core.toolkit.ObjectUtils; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.util.ObjectUtils; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.text.SimpleDateFormat; |
| | |
| | | @Autowired |
| | | private EnumService enumService; |
| | | |
| | | public List<PerformanceShift> list = new ArrayList<>(); |
| | | |
| | | @Transactional(rollbackFor = Exception.class) |
| | | @Override |
| | | public void performanceShiftAdd(PerformanceShiftAddDto performanceShiftAddDto) { |
| | | List<PerformanceShift> list = new ArrayList<>(); |
| | | DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); |
| | | String formattedDateTime = performanceShiftAddDto.getStartWeek().format(formatter); |
| | | String[] splitUserId = performanceShiftAddDto.getUserId().split(","); |
| | |
| | | LocalDate lastDayOfMonth = performanceShiftAddDto.getEndWeek().toLocalDate().with(TemporalAdjusters.lastDayOfMonth()); |
| | | List<LocalDateTime> localDateTimesBetween = getLocalDateTimesBetween(firstDayOfMonth.atStartOfDay(), lastDayOfMonth.atStartOfDay()); |
| | | localDateTimesBetween.forEach(i -> { |
| | | for (String s : splitUserId) { |
| | | PerformanceShift performanceShift = new PerformanceShift(); |
| | | performanceShift.setUserId(Integer.valueOf(s)); |
| | | performanceShift.setWorkTime(i); |
| | | performanceShift.setShift(""); |
| | | list.add(performanceShift); |
| | | } |
| | | PerformanceShift performanceShift = new PerformanceShift(); |
| | | performanceShift.setUserId(Integer.valueOf(userId)); |
| | | performanceShift.setWorkTime(i); |
| | | performanceShift.setShift(""); |
| | | list.add(performanceShift); |
| | | if (list.size() >= 1000) { |
| | | baseMapper.insertBatchSomeColumn(list); |
| | | list.clear(); |
| | | } |
| | | }); |
| | | if (!list.isEmpty()) { |
| | | baseMapper.insertBatchSomeColumn(list); |
| | | } |
| | | } |
| | | } |
| | | if (!list.isEmpty()) { |
| | | baseMapper.insertBatchSomeColumn(list); |
| | | list.clear(); |
| | | } |
| | | // 再次更新 |
| | | List<LocalDateTime> datesBetween = getLocalDateTimesBetween(performanceShiftAddDto.getStartWeek(), performanceShiftAddDto.getEndWeek()); |
| | |
| | | } |
| | | |
| | | // 年分页与导出共同使用 |
| | | public List<Map<String, Object>> annualAttendanceProcessing(List<Map<String, Object>> mapYearList, List<Enums> shiftType){ |
| | | public List<Map<String, Object>> annualAttendanceProcessing(List<Map<String, Object>> mapYearList, List<Enums> shiftType) { |
| | | for (Map<String, Object> map : mapYearList) { |
| | | Map<String, Object> resultMap = new LinkedHashMap<>(); |
| | | Map<String, Object> hashMapYear = new LinkedHashMap<>(); |
| | |
| | | for (int i = 1; i < 13; i++) { |
| | | Map<String, Object> hashMapMonth = new LinkedHashMap<>(); |
| | | double totalMonthAttendance = 0; |
| | | for (Enums enums : shiftType) { |
| | | if (!hashMapYear.containsKey(enums.getLabel())) { |
| | | hashMapYear.put(enums.getLabel(), 0); |
| | | for (Enums shift : shiftType) { |
| | | // 初始化赋值 |
| | | if (!hashMapYear.containsKey(shift.getLabel())) { |
| | | hashMapYear.put(shift.getLabel(), 0); |
| | | } |
| | | // 月 |
| | | if (ObjectUtils.isNotEmpty(map.get("month_str")) && map.get("work_time").equals(i)) { |
| | | if (!ObjectUtils.isEmpty(map.get("month_str"))) { |
| | | String charArray = map.get("month_str").toString(); |
| | | int count = countOccurrences(charArray, i + ":" + enums.getValue()); |
| | | hashMapMonth.put(enums.getLabel(), count); |
| | | hashMapYear.put(enums.getLabel(), Integer.parseInt(hashMapYear.get(enums.getLabel()).toString()) + count ); |
| | | if (enums.getValue().equals("0") || enums.getValue().equals("1") || enums.getValue().equals("2") || enums.getValue().equals("6")) { |
| | | int count = countOccurrences(charArray, i + ":" + shift.getValue()); |
| | | hashMapMonth.put(shift.getLabel(), count); |
| | | hashMapYear.put(shift.getLabel(), new BigDecimal(hashMapYear.get(shift.getLabel()).toString()).add(new BigDecimal(count))); |
| | | // 早,中,夜,差 |
| | | if (shift.getValue().equals("0") || shift.getValue().equals("1") || shift.getValue().equals("2") || shift.getValue().equals("6")) { |
| | | totalMonthAttendance += count; |
| | | totalYearAttendance += count; |
| | | } |
| | | // 半,另外半天算给早 |
| | | if (enums.getValue().equals("5")) { |
| | | // 半,另外半天算给早 |
| | | if (shift.getValue().equals("5")) { |
| | | BigDecimal multiply = new BigDecimal("0.5").multiply(new BigDecimal(count)).setScale(1, BigDecimal.ROUND_CEILING); |
| | | hashMapMonth.put(shiftType.get(0).getLabel(), new BigDecimal(hashMapMonth.get(shiftType.get(0).getLabel()).toString()).add(multiply)); |
| | | hashMapYear.put(shiftType.get(0).getLabel(), new BigDecimal(hashMapYear.get(shiftType.get(0).getLabel()).toString()).add(multiply)); |
| | |
| | | // 空数据 |
| | | else { |
| | | map.put("work_time", i); |
| | | hashMapMonth.put(enums.getLabel(), 0); |
| | | hashMapMonth.put(shift.getLabel(), 0); |
| | | } |
| | | } |
| | | hashMapMonth.put("totalMonthAttendance", totalMonthAttendance); |
| | |
| | | public static int countOccurrences(String str, String target) { |
| | | int count = 0; |
| | | int index = 0; |
| | | while ((index = str.indexOf(target, index))!= -1) { |
| | | while ((index = str.indexOf(target, index)) != -1) { |
| | | count++; |
| | | index += target.length(); |
| | | } |
| | |
| | | List<PerformanceShiftMapDto> mapIPage = baseMapper.performanceShiftList(time, userName, laboratory); |
| | | mapIPage.forEach(i -> { |
| | | String[] shiftTimes = i.getShiftTime().split(";"); |
| | | int totalAttendance = 0; |
| | | double totalAttendance = 0; |
| | | List<Map<String, Object>> map = new ArrayList<>(); |
| | | // 分割日期 |
| | | for (String shiftTime : shiftTimes) { |
| | |
| | | i.getMonthlyAttendance().put(enums.getLabel(), 0); |
| | | } |
| | | if (enums.getValue().equals(shiftTimeAndShift[1])) { |
| | | Integer num = (Integer) i.getMonthlyAttendance().get(enums.getLabel()); |
| | | i.getMonthlyAttendance().put(enums.getLabel(), num += 1); |
| | | BigDecimal bigDecimal = new BigDecimal(i.getMonthlyAttendance().get(enums.getLabel()).toString()); |
| | | i.getMonthlyAttendance().put(enums.getLabel(), bigDecimal.add(new BigDecimal("1"))); |
| | | } |
| | | // 半,另外半天算给早 |
| | | if (shiftTimeAndShift[1].equals("5") && enums.getValue().equals("0")) { |
| | | BigDecimal bigDecimal = new BigDecimal(i.getMonthlyAttendance().get(enums.getLabel()).toString()); |
| | | i.getMonthlyAttendance().put(enums.getLabel(), bigDecimal.add(new BigDecimal("0.5"))); |
| | | } |
| | | } |
| | | if (shiftTimeAndShift[1].equals("1") || shiftTimeAndShift[1].equals("2") || shiftTimeAndShift[1].equals("0")) { |
| | | // 早,中,夜,差 |
| | | if (shiftTimeAndShift[1].equals("1") || shiftTimeAndShift[1].equals("2") || shiftTimeAndShift[1].equals("0") || shiftTimeAndShift[1].equals("6")) { |
| | | i.getMonthlyAttendance().put("totalAttendance", totalAttendance += 1); |
| | | } |
| | | // 半 |
| | | if (shiftTimeAndShift[1].equals("5")) { |
| | | i.getMonthlyAttendance().put("totalAttendance", totalAttendance += 0.5); |
| | | } |
| | | hashMap.put("id", shiftTimeAndShift[2]); |
| | | hashMap.put("shift", shiftTimeAndShift[1]); |
| | |
| | | |
| | | /** |
| | | * 返回表头 |
| | | * |
| | | * <p> |
| | | * 外层List代表行内层 List代表列 相同的列数据会被主动合并 |
| | | * 构造双列表头 |
| | | * @return List<List<String>> |
| | | * |
| | | * @return List<List < String>> |
| | | */ |
| | | private static List<List<String>> getYearHeader(String year, List<Enums> enums){ |
| | | private static List<List<String>> getYearHeader(String year, List<Enums> enums) { |
| | | List<List<String>> line = new ArrayList<>(); |
| | | line.add(Arrays.asList("考勤汇总", "序号", "序号")); |
| | | line.add(Arrays.asList("考勤汇总", "工号", "工号")); |
| | |
| | | line.add(Arrays.asList("出勤详情", year, "出勤")); |
| | | // 年 header |
| | | for (Enums anEnum : enums) { |
| | | line.add(Arrays.asList("考勤汇总", year, anEnum.getLabel())); |
| | | if (!anEnum.getValue().equals("5")) { |
| | | line.add(Arrays.asList("考勤汇总", year, anEnum.getLabel())); |
| | | } |
| | | } |
| | | // 月header |
| | | for (int i = 1; i < 13; i++) { |
| | | line.add(Arrays.asList("出勤详情", i + " 月", "出勤")); |
| | | for (Enums anEnum : enums) { |
| | | line.add(Arrays.asList("出勤详情", i + " 月", anEnum.getLabel())); |
| | | if (!anEnum.getValue().equals("5")) { |
| | | line.add(Arrays.asList("出勤详情", i + " 月", anEnum.getLabel())); |
| | | } |
| | | } |
| | | } |
| | | return line; |
| | | } |
| | | |
| | | private static List<List<String>> getMonthHeader(LocalDateTime localDateTimeYear, List<Enums> enums){ |
| | | private static List<List<String>> getMonthHeader(LocalDateTime localDateTimeYear, List<Enums> enums) { |
| | | String year = localDateTimeYear.getYear() + " 年人员班次"; |
| | | List<List<String>> line = new ArrayList<>(); |
| | | line.add(Arrays.asList(year, "序号", "序号", "序号")); |
| | |
| | | excelRowList.add(list.get(i).getName()); |
| | | excelRowList.add(list.get(i).getDepartment()); |
| | | excelRowList.add(list.get(i).getMonthlyAttendance().get("totalAttendance")); |
| | | excelRowList.add(list.get(i).getMonthlyAttendance().get(enums.get(3).getLabel())); |
| | | excelRowList.add(list.get(i).getMonthlyAttendance().get(enums.get(4).getLabel())); |
| | | excelRowList.add(list.get(i).getMonthlyAttendance().get(enums.get(0).getLabel())); |
| | | excelRowList.add(list.get(i).getMonthlyAttendance().get(enums.get(1).getLabel())); |
| | | excelRowList.add(list.get(i).getMonthlyAttendance().get(enums.get(2).getLabel())); |
| | | excelRowList.add(0); // 出差 |
| | | excelRowList.add(list.get(i).getMonthlyAttendance().get(enums.get(3).getLabel())); // 休 |
| | | excelRowList.add(list.get(i).getMonthlyAttendance().get(enums.get(4).getLabel())); // 假 |
| | | excelRowList.add(list.get(i).getMonthlyAttendance().get(enums.get(0).getLabel())); // 早 |
| | | excelRowList.add(list.get(i).getMonthlyAttendance().get(enums.get(1).getLabel())); // 中 |
| | | excelRowList.add(list.get(i).getMonthlyAttendance().get(enums.get(2).getLabel())); // 夜 |
| | | excelRowList.add(list.get(i).getMonthlyAttendance().get(enums.get(6).getLabel())); // 差 |
| | | for (Map<String, Object> o : list.get(i).getList()) { |
| | | String enumLabel = ""; |
| | | for (Enums anEnum : enums) { |
| | |
| | | enumLabel = anEnum.getLabel(); |
| | | } |
| | | } |
| | | excelRowList.add(ObjectUtils.isEmpty(enumLabel) ? "无" : enumLabel); |
| | | excelRowList.add(ObjectUtils.isEmpty(enumLabel) ? "-" : enumLabel); |
| | | } |
| | | data.add(excelRowList); |
| | | } |