| | |
| | | package com.aps.core.service.impl; |
| | | |
| | | import com.alibaba.fastjson2.JSONArray; |
| | | import com.alibaba.fastjson2.JSONObject; |
| | | import com.aps.common.core.utils.DateUtils; |
| | | import com.aps.common.security.utils.SecurityUtils; |
| | | import com.aps.core.domain.ApsWorkCalendar; |
| | |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.time.DayOfWeek; |
| | | import java.time.LocalDate; |
| | | import java.time.YearMonth; |
| | | import java.util.List; |
| | | |
| | | /** |
| | |
| | | { |
| | | return apsWorkCalendarMapper.deleteApsWorkCalendarById(id); |
| | | } |
| | | |
| | | public JSONArray getWorkCalendar(String applicableFactory, String datetime) { |
| | | JSONArray res = new JSONArray(); |
| | | // 获取年份和月份 |
| | | String[] parts = datetime.split("-"); |
| | | int year = Integer.parseInt(parts[0]); |
| | | int month = Integer.parseInt(parts[1]); |
| | | // 获取指定年份和月份的天数 |
| | | YearMonth yearMonth = YearMonth.of(year, month); |
| | | int daysInMonth = yearMonth.lengthOfMonth(); |
| | | ApsWorkCalendar apsWorkCalendar = new ApsWorkCalendar(); |
| | | apsWorkCalendar.setApplicableFactory(applicableFactory); |
| | | apsWorkCalendar.setEffectiveDate(DateUtils.parseDate(datetime+" 00:00:00")); |
| | | apsWorkCalendar.setExpiringDate(DateUtils.parseDate(datetime+" 23:59:59")); |
| | | List<ApsWorkCalendar> list = apsWorkCalendarMapper.selectApsWorkCalendarList(apsWorkCalendar); |
| | | if (list.isEmpty()) { |
| | | // 循环遍历当月的每一天,获取星期信息 |
| | | for (int day = 1; day <= daysInMonth; day++) { |
| | | LocalDate date = LocalDate.of(year, month, day); |
| | | DayOfWeek dayOfWeek = date.getDayOfWeek(); |
| | | JSONObject dayInfo = new JSONObject(); |
| | | dayInfo.put("date", date.toString()); |
| | | dayInfo.put("dayOfWeek", dayOfWeek.toString()); |
| | | if (dayOfWeek == DayOfWeek.SATURDAY || dayOfWeek == DayOfWeek.SUNDAY) { |
| | | dayInfo.put("isWorkDay", false); |
| | | } else { |
| | | dayInfo.put("isWorkDay", true); |
| | | } |
| | | res.add(dayInfo); |
| | | } |
| | | } |
| | | return res; |
| | | } |
| | | } |