| | |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.text.SimpleDateFormat; |
| | | import java.time.LocalDate; |
| | | import java.time.LocalDateTime; |
| | |
| | | List<Map<String, Object>> mapYearIPage = baseMapper.performanceShiftYearPage(time, userName, laboratory); |
| | | mapIPage.getRecords().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]); |
| | | hashMap.put("time", shiftTimeAndShift[0]); |
| | | map.add(hashMap); |
| | | } |
| | | int totalYearAttendance = 0; |
| | | double totalYearAttendance = 0; |
| | | Map<String, Object> hashMap = new HashMap<>(); |
| | | for (Map<String, Object> record : mapYearIPage) { |
| | | if (record.get("user_id").toString().equals(i.getUserId())) { |
| | |
| | | hashMap.put(enums.getLabel(), 0); |
| | | } |
| | | if (enums.getValue().equals(record.get("shift"))) { |
| | | Integer num = (Integer) hashMap.get(enums.getLabel()); |
| | | hashMap.put(enums.getLabel(), num += 1); |
| | | BigDecimal num = new BigDecimal(hashMap.get(enums.getLabel()).toString()); |
| | | hashMap.put(enums.getLabel(), num.add(new BigDecimal("1"))); |
| | | } |
| | | // 半,另外半天算给早 |
| | | if (record.get("shift").equals("5") && enums.getValue().equals("0")) { |
| | | BigDecimal bigDecimal = new BigDecimal(hashMap.get(enums.getLabel()).toString()); |
| | | hashMap.put(enums.getLabel(), bigDecimal.add(new BigDecimal("0.5"))); |
| | | } |
| | | } |
| | | if (record.get("shift").equals("1") || record.get("shift").equals("2") || record.get("shift").equals("0")) { |
| | | if (record.get("shift").equals("1") || record.get("shift").equals("2") || record.get("shift").equals("0") || record.get("shift").equals("6")) { |
| | | hashMap.put("totalAttendance", totalYearAttendance += 1); |
| | | } |
| | | // 半 |
| | | if (record.get("shift").equals("5")) { |
| | | hashMap.put("totalAttendance", totalYearAttendance += 0.5); |
| | | } |
| | | } |
| | | } |
| | |
| | | for (Map<String, Object> map : mapYearList) { |
| | | Map<String, Object> resultMap = new LinkedHashMap<>(); |
| | | Map<String, Object> hashMapYear = new LinkedHashMap<>(); |
| | | int totalYearAttendance = 0; |
| | | double totalYearAttendance = 0; |
| | | // 一年12个月 |
| | | for (int i = 1; i < 13; i++) { |
| | | Map<String, Object> hashMapMonth = new LinkedHashMap<>(); |
| | | int totalMonthAttendance = 0; |
| | | double totalMonthAttendance = 0; |
| | | for (Enums enums : shiftType) { |
| | | if (!hashMapYear.containsKey(enums.getLabel())) { |
| | | hashMapYear.put(enums.getLabel(), 0); |
| | |
| | | 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")) { |
| | | if (enums.getValue().equals("0") || enums.getValue().equals("1") || enums.getValue().equals("2") || enums.getValue().equals("6")) { |
| | | totalMonthAttendance += count; |
| | | totalYearAttendance += count; |
| | | } |
| | | // 半,另外半天算给早 |
| | | if (enums.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)); |
| | | totalMonthAttendance += multiply.doubleValue(); |
| | | totalYearAttendance += multiply.doubleValue(); |
| | | } |
| | | } |
| | | // 空数据 |
| | |
| | | Map<String, Object> year = JackSonUtil.unmarshal(JackSonUtil.marshal(list.get(i).get("year")), Map.class); |
| | | excelRowList.add(year.get("totalYearAttendance")); |
| | | enums.forEach(j -> { |
| | | excelRowList.add(year.get(j.getLabel())); |
| | | if (!j.getValue().equals("5")) { |
| | | excelRowList.add(year.get(j.getLabel())); |
| | | } |
| | | }); |
| | | Map<String, Map<String, Object>> month = JackSonUtil.unmarshal(JackSonUtil.marshal(list.get(i).get("month")), Map.class); |
| | | for (int j = 1; j < 13; j++) { |
| | | Object totalMonthAttendance = month.get(j + "").get("totalMonthAttendance"); |
| | | excelRowList.add(totalMonthAttendance); |
| | | for (Enums anEnum : enums) { |
| | | excelRowList.add(month.get(j + "").get(anEnum.getLabel())); |
| | | if (!anEnum.getValue().equals("5")) { |
| | | excelRowList.add(month.get(j + "").get(anEnum.getLabel())); |
| | | } |
| | | } |
| | | } |
| | | data.add(excelRowList); |