| | |
| | | package com.yuanchu.mom.service.impl; |
| | | |
| | | import cn.hutool.core.date.DateUtil; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | 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 java.text.SimpleDateFormat; |
| | | import java.time.LocalDate; |
| | | import java.time.LocalDateTime; |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.*; |
| | | |
| | | /** |
| | | * <p> |
| | |
| | | public void performanceShiftAdd(PerformanceShiftAddDto performanceShiftAddDto) { |
| | | List<LocalDateTime> datesBetween = getLocalDateTimesBetween(performanceShiftAddDto.getStartWeek(), performanceShiftAddDto.getEndWeek()); |
| | | for (LocalDateTime date : datesBetween) { |
| | | PerformanceShift performanceShift = new PerformanceShift(); |
| | | performanceShift.setShift(performanceShiftAddDto.getShift()); |
| | | performanceShift.setUserId(performanceShiftAddDto.getUserId()); |
| | | performanceShift.setWorkTime(date); |
| | | baseMapper.insert(performanceShift); |
| | | String[] splitUserId = performanceShiftAddDto.getUserId().split(","); |
| | | for (String s : splitUserId) { |
| | | PerformanceShift performanceShift = new PerformanceShift(); |
| | | performanceShift.setShift(performanceShiftAddDto.getShift()); |
| | | performanceShift.setUserId(Integer.valueOf(s)); |
| | | performanceShift.setWorkTime(date); |
| | | baseMapper.insert(performanceShift); |
| | | } |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public IPage<Map<String, Object>> performanceShiftPage(Page<Object> page, LocalDateTime time, String userName, String laboratory) { |
| | | public IPage<Map<String, Object>> performanceShiftPage(Page<Object> page, String time, String userName, String laboratory) { |
| | | IPage<Map<String, Object>> mapIPage = baseMapper.performanceShiftPage(page, time, userName, laboratory); |
| | | List<Enums> shiftType = enumService.selectEnumByCategory("班次类型"); |
| | | for (Map<String, Object> i : mapIPage.getRecords()) { |
| | | String[] shiftTimes = i.get("shiftTime").toString().split(";"); |
| | | int totalAttendance = 0; |
| | | for (Enums enums : shiftType) { |
| | | Integer num = 0; |
| | | for (String shiftTime : shiftTimes) { |
| | | String[] shiftTimeAndShift = shiftTime.split(":"); |
| | | List<Object> map = new ArrayList<>(); |
| | | // 分割日期 |
| | | for (String shiftTime : shiftTimes) { |
| | | Map<Object, Object> hashMap = new HashMap<>(); |
| | | String[] shiftTimeAndShift = shiftTime.split(":"); |
| | | for (Enums enums : shiftType) { |
| | | int num = 0; |
| | | if (enums.getValue().equals(shiftTimeAndShift[1])) { |
| | | num++; |
| | | } |
| | | // 3:休假;4:请假 |
| | | if (!enums.getValue().equals("3") && enums.getValue().equals("4")) { |
| | | totalAttendance++; |
| | | i.put(enums.getLabel(), num); |
| | | if (!enums.getValue().equals("3") && !enums.getValue().equals("4")) { |
| | | i.put("totalAttendance", totalAttendance += num); |
| | | } |
| | | } |
| | | i.put(enums.getLabel(), num); |
| | | i.put("totalAttendance", totalAttendance); |
| | | hashMap.put("id", shiftTimeAndShift[2]); |
| | | hashMap.put("shift", shiftTimeAndShift[1]); |
| | | hashMap.put("weekly", DateUtil.weekOfYear(DateUtil.parse(shiftTimeAndShift[0]))); |
| | | hashMap.put("time", shiftTimeAndShift[0]); |
| | | hashMap.put("headerTime", getWeek(shiftTimeAndShift[0])); |
| | | map.add(hashMap); |
| | | } |
| | | i.put("list", map); |
| | | i.remove("shiftTime"); |
| | | } |
| | | return mapIPage; |
| | | } |
| | |
| | | } |
| | | return localDateTimes; |
| | | } |
| | | |
| | | public static String getWeek(String dayStr) { |
| | | SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
| | | try { |
| | | Date date = sdf.parse(dayStr); |
| | | Calendar calendar = Calendar.getInstance(); |
| | | calendar.setTime(date); |
| | | int dayOfWeek = calendar.get(Calendar.DAY_OF_WEEK); |
| | | int day = calendar.get(Calendar.DAY_OF_MONTH); |
| | | return day + " " + getWeekDay(dayOfWeek); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | public static String getWeekDay(int dayOfWeek) { |
| | | switch (dayOfWeek) { |
| | | case Calendar.MONDAY: |
| | | return "周一"; |
| | | case Calendar.TUESDAY: |
| | | return "周二"; |
| | | case Calendar.WEDNESDAY: |
| | | return "周三"; |
| | | case Calendar.THURSDAY: |
| | | return "周四"; |
| | | case Calendar.FRIDAY: |
| | | return "周五"; |
| | | case Calendar.SATURDAY: |
| | | return "周六"; |
| | | case Calendar.SUNDAY: |
| | | return "周日"; |
| | | default: |
| | | return "未知"; |
| | | } |
| | | } |
| | | } |