From 3f7774efde865b52797089fcdde621d7ae1e1a4a Mon Sep 17 00:00:00 2001
From: lius <Lius2225@163.com>
Date: 星期二, 08 八月 2023 14:12:32 +0800
Subject: [PATCH] 设备工作日历配置接口更新

---
 lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/impl/MdcDeviceCalendarServiceImpl.java |  104 ++++++++-------------------------------------------
 1 files changed, 17 insertions(+), 87 deletions(-)

diff --git a/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/impl/MdcDeviceCalendarServiceImpl.java b/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/impl/MdcDeviceCalendarServiceImpl.java
index 57dce4e..a469d00 100644
--- a/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/impl/MdcDeviceCalendarServiceImpl.java
+++ b/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/impl/MdcDeviceCalendarServiceImpl.java
@@ -83,50 +83,21 @@
     @Override
     public boolean saveCalendar(EquipmentCalendarVo calendarVo) {
         String[] equipmentIdList = calendarVo.getEquipmentId().split(",");
-        //鐢熸晥鏃堕棿
-        LocalDate takeEffectDate = calendarVo.getTakeEffectDate();
-        //澶辨晥鏃堕棿
-        LocalDate invalidDate = calendarVo.getInvalidDate();
-        //澶勭悊鏄熸湡
-        Map<String, String> map = new HashMap<>();
-        if (org.apache.commons.lang.StringUtils.isNotBlank(calendarVo.getMonShiftId())) {
-            map.put("1", calendarVo.getMonShiftId());
-        }
-        if (org.apache.commons.lang.StringUtils.isNotBlank(calendarVo.getTueShiftId())) {
-            map.put("2", calendarVo.getTueShiftId());
-        }
-        if (org.apache.commons.lang.StringUtils.isNotBlank(calendarVo.getWedShiftId())) {
-            map.put("3", calendarVo.getWedShiftId());
-        }
-        if (org.apache.commons.lang.StringUtils.isNotBlank(calendarVo.getThuShiftId())) {
-            map.put("4", calendarVo.getThuShiftId());
-        }
-        if (org.apache.commons.lang.StringUtils.isNotBlank(calendarVo.getFriShiftId())) {
-            map.put("5", calendarVo.getFriShiftId());
-        }
-        if (org.apache.commons.lang.StringUtils.isNotBlank(calendarVo.getSatShiftId())) {
-            map.put("6", calendarVo.getSatShiftId());
-        }
-        if (org.apache.commons.lang.StringUtils.isNotBlank(calendarVo.getSunShiftId())) {
-            map.put("7", calendarVo.getSunShiftId());
-        }
-        if (map.isEmpty()) {
-            return false;
-        }
+        List<String> dateList = calendarVo.getDateList();
+        List<MdcShiftSub> mdcShiftSubList = mdcShiftSubService.list(new LambdaQueryWrapper<MdcShiftSub>().eq(MdcShiftSub::getShiftId, calendarVo.getShiftId()).eq(MdcShiftSub::getShiftSubStatus, "1"));
         List<MdcDeviceCalendar> calendarList = new ArrayList<>();
-        map.forEach((key, value) -> {
-            List<MdcShiftSub> mdcShiftSubList = mdcShiftSubService.list(new LambdaQueryWrapper
-                    <MdcShiftSub>().eq(MdcShiftSub::getShiftId, value).eq(MdcShiftSub::getShiftSubStatus, "1"));
-            List<LocalDate> meetDayOfWeekLocalDates = getMeetDayOfWeekLocalDates(takeEffectDate, invalidDate, key);
-            if (!meetDayOfWeekLocalDates.isEmpty()) {
-                List<String> dates = meetDayOfWeekLocalDates.stream().map(localDate -> localDate.format(DateTimeFormatter.BASIC_ISO_DATE)).collect(Collectors.toList());
-                LambdaUpdateChainWrapper<MdcDeviceCalendar> lambdaUpdate = this.lambdaUpdate();
-                lambdaUpdate.in(MdcDeviceCalendar::getEffectiveDate, dates).in(MdcDeviceCalendar::getEqumentId, Arrays.asList(equipmentIdList));
-                lambdaUpdate.remove();
-                List<MdcDeviceCalendar> calendars = handleMdcDeviceCalendar(dates, equipmentIdList, mdcShiftSubList, key);
-                calendarList.addAll(calendars);
+        for (String equipmentId : equipmentIdList) {
+            for (String date : dateList) {
+                for (MdcShiftSub mdcShiftSub : mdcShiftSubList) {
+                    MdcDeviceCalendar mdcDeviceCalendar = new MdcDeviceCalendar();
+                    mdcDeviceCalendar.setEffectiveDate(date);
+                    mdcDeviceCalendar.setEquipmentId(equipmentId);
+                    mdcDeviceCalendar.setShiftId(mdcShiftSub.getShiftId());
+                    mdcDeviceCalendar.setShiftSubId(mdcShiftSub.getId());
+                    calendarList.add(mdcDeviceCalendar);
+                }
             }
-        });
+        }
         this.saveBatch(calendarList);
         return true;
     }
@@ -134,24 +105,24 @@
     /**
      * 鏌ヨ鐝埗鏁版嵁
      *
-     * @param equipmentid
+     * @param equipmentId
      * @param stringDates
      * @return
      */
     @Override
-    public List<MdcDeviceCalendarVo> listByEquipmentAndDate(String equipmentid, List<String> stringDates) {
+    public List<MdcDeviceCalendarVo> listByEquipmentAndDate(String equipmentId, List<String> stringDates) {
         List<MdcDeviceCalendarVo> result = new ArrayList<>();
         try {
             //鏌ヨ榛樿鐝埗
             List<MdcDeviceCalendarVo> acquiesceShift = this.baseMapper.findAcquiesceShift();
 
             for (String stringDate : stringDates) {
-                List<MdcDeviceCalendarVo> mdcDeviceCalendarVos = this.baseMapper.listByEquipmentAndDate(equipmentid, stringDate);
+                List<MdcDeviceCalendarVo> mdcDeviceCalendarVos = this.baseMapper.listByEquipmentAndDate(equipmentId, stringDate);
                 if (mdcDeviceCalendarVos != null && !mdcDeviceCalendarVos.isEmpty()) {
                     result.addAll(mdcDeviceCalendarVos);
                 } else {
                     acquiesceShift.forEach(mdcDeviceCalendarVo -> {
-                        mdcDeviceCalendarVo.setEquipmentId(equipmentid);
+                        mdcDeviceCalendarVo.setEquipmentId(equipmentId);
                         mdcDeviceCalendarVo.setEffectiveDate(stringDate);
                     });
                     // 璁剧疆榛樿鐝埗
@@ -165,45 +136,4 @@
         return result;
     }
 
-    /**
-     * 鑾峰彇涓�娈垫椂闂磋寖鍥村唴绗﹀悎鏄熸湡鍑犵殑鏃ユ湡闆嗗悎
-     *
-     * @param startDate 寮�濮嬫椂闂�
-     * @param endDate   缁撴潫鏃堕棿
-     * @param workDate  鍛ㄥ嚑 1,2,3,4
-     */
-    public static List<LocalDate> getMeetDayOfWeekLocalDates(LocalDate startDate, LocalDate endDate, String workDate) {
-
-        List<DayOfWeek> dayOfWeeks = Stream.of(workDate.split(","))
-                .map(Integer::valueOf)
-                .map(DayOfWeek::of)
-                .collect(Collectors.toList());
-
-        long distance = ChronoUnit.DAYS.between(startDate, endDate);
-
-        return Stream.iterate(startDate, d -> d.plusDays(1))
-                .limit(distance + 1)
-                .filter(localDate -> dayOfWeeks.contains(localDate.getDayOfWeek()))
-                .collect(Collectors.toList());
-    }
-
-    public List<MdcDeviceCalendar> handleMdcDeviceCalendar(List<String> dates, String[] equipment, List<MdcShiftSub> mdcShiftSubList, String weekNumber) {
-        List<MdcDeviceCalendar> ds = new ArrayList<>();
-        for (String date : dates) {
-            for (String equipmentId : equipment) {
-                for (MdcShiftSub temp : mdcShiftSubList) {
-                    MdcDeviceCalendar mdcDeviceCalendar = new MdcDeviceCalendar();
-                    if (org.apache.commons.lang.StringUtils.isNotEmpty(equipmentId)) {
-                        mdcDeviceCalendar.setEqumentId(equipmentId);
-                    }
-                    mdcDeviceCalendar.setShiftId(temp.getShiftId());
-                    mdcDeviceCalendar.setShiftSubId(temp.getId());
-                    mdcDeviceCalendar.setEffectiveDate(date);
-                    mdcDeviceCalendar.setWeekNumber(weekNumber);
-                    ds.add(mdcDeviceCalendar);
-                }
-            }
-        }
-        return ds;
-    }
 }

--
Gitblit v1.9.3