package com.qianwen.smartman.modules.cps.service.impl;
|
|
import cn.hutool.core.lang.Snowflake;
|
import cn.hutool.core.util.IdUtil;
|
import com.baomidou.mybatisplus.core.conditions.Wrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.google.common.collect.Lists;
|
import java.lang.invoke.SerializedLambda;
|
import java.time.LocalDate;
|
import java.time.LocalDateTime;
|
import java.time.LocalTime;
|
import java.time.ZoneOffset;
|
import java.time.format.DateTimeFormatter;
|
import java.time.temporal.ChronoUnit;
|
import java.time.temporal.TemporalAdjusters;
|
import java.time.temporal.TemporalUnit;
|
import java.util.ArrayList;
|
import java.util.Calendar;
|
import java.util.Collection;
|
import java.util.Comparator;
|
import java.util.Date;
|
import java.util.HashMap;
|
import java.util.LinkedList;
|
import java.util.List;
|
import java.util.Map;
|
import java.util.Optional;
|
import java.util.Set;
|
import java.util.stream.Collectors;
|
import java.util.stream.Stream;
|
import org.slf4j.Logger;
|
import org.slf4j.LoggerFactory;
|
import com.qianwen.smartman.common.cache.ParamCache;
|
import com.qianwen.smartman.common.cache.RegionCache;
|
import com.qianwen.smartman.common.cache.cps.TimeSliceCache;
|
import com.qianwen.smartman.common.constant.CalendarConstant;
|
import com.qianwen.smartman.common.constant.CommonConstant;
|
import com.qianwen.smartman.common.constant.DateConstant;
|
import com.qianwen.smartman.common.constant.ProductionTimeConstant;
|
import com.qianwen.smartman.common.utils.CommonUtil;
|
import com.qianwen.smartman.common.utils.LocalDateTimeUtils;
|
import com.qianwen.smartman.common.utils.MessageUtils;
|
import com.qianwen.core.log.exception.ServiceException;
|
import com.qianwen.core.redis.cache.BladeRedis;
|
import com.qianwen.core.secure.utils.AuthUtil;
|
import com.qianwen.core.tool.utils.CollectionUtil;
|
import com.qianwen.core.tool.utils.DateUtil;
|
import com.qianwen.core.tool.utils.Func;
|
import com.qianwen.smartman.modules.cps.convert.ProductionCalendarConvert;
|
import com.qianwen.smartman.modules.cps.dto.CacheBuildDTO;
|
import com.qianwen.smartman.modules.cps.dto.CalendarCacheDTO;
|
import com.qianwen.smartman.modules.cps.dto.CalendarDateDTO;
|
import com.qianwen.smartman.modules.cps.dto.CalendarShiftDTO;
|
import com.qianwen.smartman.modules.cps.dto.CalendarShiftDetailDTO;
|
import com.qianwen.smartman.modules.cps.dto.CalendarShiftTimeSlicesDTO;
|
import com.qianwen.smartman.modules.cps.dto.CurShiftDTO;
|
import com.qianwen.smartman.modules.cps.dto.FactoryDayInfoDTO;
|
import com.qianwen.smartman.modules.cps.dto.ShiftCacheDTO;
|
import com.qianwen.smartman.modules.cps.dto.ShiftDetailInfoDTO;
|
import com.qianwen.smartman.modules.cps.dto.ShiftIndexInfoDTO;
|
import com.qianwen.smartman.modules.cps.dto.ShiftInfoDTO;
|
import com.qianwen.smartman.modules.cps.dto.ShiftSlicesCalendarCodeDTO;
|
import com.qianwen.smartman.modules.cps.dto.ShiftSlicesClientCalendarCodesDTO;
|
import com.qianwen.smartman.modules.cps.dto.ShiftSlicesClientDTO;
|
import com.qianwen.smartman.modules.cps.dto.ShiftSlicesDTO;
|
import com.qianwen.smartman.modules.cps.dto.TimestampToProductionTimeCacheDto;
|
import com.qianwen.smartman.modules.cps.entity.ProductionCalendar;
|
import com.qianwen.smartman.modules.cps.entity.ProductionCalendarDay;
|
import com.qianwen.smartman.modules.cps.entity.ProductionCalendarDaytime;
|
import com.qianwen.smartman.modules.cps.entity.Workstation;
|
import com.qianwen.smartman.modules.cps.enums.WorkstationTypeEnum;
|
import com.qianwen.smartman.modules.cps.mapper.CalendarMapper;
|
import com.qianwen.smartman.modules.cps.service.ICalendarDayService;
|
import com.qianwen.smartman.modules.cps.service.ICalendarDaytimeService;
|
import com.qianwen.smartman.modules.cps.service.ICalendarService;
|
import com.qianwen.smartman.modules.cps.service.IShiftModelService;
|
import com.qianwen.smartman.modules.cps.service.IWorkstationService;
|
import com.qianwen.smartman.modules.cps.vo.CalendarAssociateWorkstationVO;
|
import com.qianwen.smartman.modules.cps.vo.CalendarCopyVO;
|
import com.qianwen.smartman.modules.cps.vo.CalendarDayVO;
|
import com.qianwen.smartman.modules.cps.vo.CalendarSaveVO;
|
import com.qianwen.smartman.modules.cps.vo.CalendarSimpleVO;
|
import com.qianwen.smartman.modules.cps.vo.CalendarUpdateVO;
|
import com.qianwen.smartman.modules.cps.vo.CalendarVO;
|
import com.qianwen.smartman.modules.cps.vo.ShiftDetailVO;
|
import com.qianwen.smartman.modules.cps.vo.ShiftIndexNameVO;
|
import com.qianwen.smartman.modules.cps.vo.ShiftRestTimeVO;
|
import com.qianwen.smartman.modules.cps.vo.ShiftTimeDetailVO;
|
import com.qianwen.smartman.modules.cps.vo.ShiftVO;
|
import com.qianwen.smartman.modules.mdc.dto.ShiftIndexNameDTO;
|
import org.springframework.beans.BeanUtils;
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.context.annotation.Lazy;
|
import org.springframework.stereotype.Service;
|
import org.springframework.transaction.annotation.Transactional;
|
|
@Service
|
/* loaded from: blade-api.jar:BOOT-INF/classes/org/springblade/modules/cps/service/impl/CalendarServiceImpl.class */
|
public class CalendarServiceImpl extends ServiceImpl<CalendarMapper, ProductionCalendar> implements ICalendarService {
|
private static final Logger log = LoggerFactory.getLogger(CalendarServiceImpl.class);
|
@Autowired
|
@Lazy
|
private IWorkstationService workstationService;
|
@Autowired
|
private IShiftModelService shiftModelService;
|
@Autowired
|
private ICalendarDayService calendarDayService;
|
@Autowired
|
private ICalendarDaytimeService calendarDaytimeService;
|
@Autowired
|
private BladeRedis bladeRedis;
|
|
@Override // org.springblade.modules.cps.service.ICalendarService
|
@Transactional(rollbackFor = {Exception.class})
|
public ProductionCalendar saveCalendar(CalendarSaveVO calendarSaveVO) {
|
checkCalendar(calendarSaveVO, AuthUtil.getTenantId());
|
ProductionCalendar productionCalendar = ProductionCalendarConvert.INSTANCE.conver(calendarSaveVO);
|
save(productionCalendar);
|
saveCalendarDayTime(calendarSaveVO.getDateDTOList(), productionCalendar);
|
return productionCalendar;
|
}
|
|
@Override // org.springblade.modules.cps.service.ICalendarService
|
public ProductionCalendar saveYearCalendar(CalendarSaveVO calendarSaveVO) {
|
checkCalendar(calendarSaveVO, AuthUtil.getTenantId());
|
ProductionCalendar productionCalendar = new ProductionCalendar();
|
BeanUtils.copyProperties(calendarSaveVO, productionCalendar);
|
save(productionCalendar);
|
saveYearCalendarDayTime(calendarSaveVO.getDateDTOList(), productionCalendar);
|
return productionCalendar;
|
}
|
|
@Override // org.springblade.modules.cps.service.ICalendarService
|
public ProductionCalendar updateCalendar(CalendarUpdateVO calendarUpdateVO) {
|
this.calendarDayService.deleteByCalendarId(calendarUpdateVO.getId());
|
this.calendarDaytimeService.deleteByCalendarId(calendarUpdateVO.getId());
|
ProductionCalendar calendar = (ProductionCalendar) getById(calendarUpdateVO.getId());
|
updateCalendarDayTime(calendarUpdateVO.getDateDTOList(), calendar);
|
return calendar;
|
}
|
|
private void saveCalendarDayTime(List<CalendarDateDTO> dateDTOList, ProductionCalendar productionCalendar) {
|
LocalDate today = LocalDate.now();
|
Integer thisYear = Integer.valueOf(today.getYear());
|
Integer year = productionCalendar.getYear();
|
LocalDate queryStartDay = LocalDate.of(year.intValue(), 1, 1);
|
Long calendarId = productionCalendar.getId();
|
Set<LocalDate> dateList = (Set) dateDTOList.stream().filter(c -> {
|
return !Func.isNull(c.getModelId()) && Func.isNull(c.getOffDayId());
|
}).map((v0) -> {
|
return v0.getCalendarDate();
|
}).collect(Collectors.toSet());
|
Set<LocalDate> offDay = (Set) dateDTOList.stream().filter(c2 -> {
|
return !Func.isNull(c2.getOffDayId());
|
}).map((v0) -> {
|
return v0.getCalendarDate();
|
}).collect(Collectors.toSet());
|
List<ProductionCalendarDaytime> productionCalendarDaytimeList = new ArrayList<>();
|
List<ProductionCalendarDay> productionCalendarDayList = new ArrayList<>();
|
List<Long> modelIds = (List) dateDTOList.stream().map((v0) -> {
|
return v0.getModelId();
|
}).distinct().collect(Collectors.toList());
|
Map<Long, ShiftVO> shiftDetailMap = this.shiftModelService.getShiftDetail(modelIds);
|
Snowflake snowflake = IdUtil.createSnowflake(1L, 1L);
|
List<ProductionCalendarDaytime> curProductionCalendarDayTimeList = new ArrayList<>();
|
LocalDate lastDayOfYear = LocalDateTimeUtils.getLastDayOfYear(queryStartDay);
|
long difference = year.equals(thisYear) ? LocalDateTimeUtils.getDifference(today, lastDayOfYear).intValue() : LocalDateTimeUtils.getDayOfYear(year).intValue() - 1;
|
long j = 0;
|
while (true) {
|
long i = j;
|
if (i <= difference) {
|
LocalDate needHandleDate = year.equals(thisYear) ? today.plus(difference - i, (TemporalUnit) ChronoUnit.DAYS) : queryStartDay.plus(difference - i, (TemporalUnit) ChronoUnit.DAYS);
|
LocalDate nextNeedHandleDate = needHandleDate.plus(1L, (TemporalUnit) ChronoUnit.DAYS);
|
if (dateList.contains(needHandleDate)) {
|
handleCalendarDay(dateDTOList, calendarId, year, productionCalendarDayList, shiftDetailMap, snowflake, curProductionCalendarDayTimeList, needHandleDate);
|
} else if (offDay.contains(needHandleDate)) {
|
handleOffDayCalendarDay(dateDTOList, calendarId, year, productionCalendarDayList, shiftDetailMap, snowflake, curProductionCalendarDayTimeList, needHandleDate);
|
} else {
|
handleUndefinedCalendarDay(calendarId, year, curProductionCalendarDayTimeList, needHandleDate);
|
}
|
curProductionCalendarDayTimeList.sort(Comparator.comparing((v0) -> {
|
return v0.getStartTime();
|
}));
|
productionCalendarDaytimeList.sort(Comparator.comparing((v0) -> {
|
return v0.getStartTime();
|
}));
|
handleConflictCalendarDay(i, productionCalendar, productionCalendarDaytimeList, curProductionCalendarDayTimeList, needHandleDate, nextNeedHandleDate);
|
if (i == difference && i + 1 == LocalDateTimeUtils.getDayOfYear(year).intValue()) {
|
productionCalendarDaytimeList.sort(Comparator.comparing((v0) -> {
|
return v0.getStartTime();
|
}));
|
handleFirstDayOfYear(productionCalendar, productionCalendarDaytimeList, needHandleDate);
|
}
|
curProductionCalendarDayTimeList.clear();
|
j = i + 1;
|
} else {
|
this.calendarDayService.saveBatchDay(productionCalendarDayList);
|
this.calendarDaytimeService.saveBatchDaytime(productionCalendarDaytimeList);
|
return;
|
}
|
}
|
}
|
|
private void handleOffDayCalendarDay(List<CalendarDateDTO> dateDTOList, Long calendarId, Integer year, List<ProductionCalendarDay> productionCalendarDayList, Map<Long, ShiftVO> shiftDetailMap, Snowflake snowflake, List<ProductionCalendarDaytime> curProductionCalendarDayTimeList, LocalDate needHandleDate) {
|
CalendarDateDTO calendarDateDTO = dateDTOList.stream().filter(dateDTO -> {
|
return dateDTO.getCalendarDate().equals(needHandleDate);
|
}).findFirst().orElse(new CalendarDateDTO());
|
ShiftVO shiftDetail = shiftDetailMap.get(calendarDateDTO.getModelId());
|
Integer week = LocalDateTimeUtils.getWeek(calendarDateDTO.getCalendarDate());
|
Integer month = LocalDateTimeUtils.getMonth(calendarDateDTO.getCalendarDate());
|
Integer startDate = shiftDetail.getStartTime();
|
Integer endDate = shiftDetail.getEndTime();
|
ProductionCalendarDay productionCalendarDay = ProductionCalendarDay.builder().calendarId(calendarId).calendarDate(calendarDateDTO.getCalendarDate()).modelId(calendarDateDTO.getModelId()).isHighPriority(calendarDateDTO.getIsHighPriority()).week(week).month(month).year(year).isOffDay(CalendarConstant.IS_OFF_DAY).offId(calendarDateDTO.getOffDayId()).startTime(LocalDateTimeUtils.plus(calendarDateDTO.getCalendarDate(), shiftDetail.getStartTime().intValue(), ChronoUnit.MINUTES)).endTime(LocalDateTimeUtils.plus(calendarDateDTO.getCalendarDate(), shiftDetail.getEndTime().intValue(), ChronoUnit.MINUTES)).build();
|
buildCalendarOffDay(productionCalendarDay, snowflake, productionCalendarDayList, shiftDetail, calendarId, curProductionCalendarDayTimeList, calendarDateDTO, week, month, year, startDate, endDate);
|
}
|
|
private void buildCalendarOffDay(ProductionCalendarDay productionCalendarDay, Snowflake snowflake, List<ProductionCalendarDay> productionCalendarDayList, ShiftVO shiftDetail, Long calendarId, List<ProductionCalendarDaytime> curProductionCalendarDayTimeList, CalendarDateDTO calendarDateDTO, Integer week, Integer month, Integer year, Integer startDate, Integer endDate) {
|
productionCalendarDay.setId(Long.valueOf(snowflake.nextId()));
|
productionCalendarDayList.add(productionCalendarDay);
|
List<ShiftDetailVO> collect = (List) shiftDetail.getShiftDetailVOList().stream().sorted(Comparator.comparing((v0) -> {
|
return v0.getShiftStartTime();
|
})).collect(Collectors.toList());
|
for (int i = 0; i < collect.size(); i++) {
|
ShiftDetailVO shiftDetailVO = collect.get(i);
|
Integer startTime = shiftDetailVO.getShiftStartTime();
|
Integer endTime = shiftDetailVO.getShiftEndTime();
|
createUndefinedDaytime(calendarId, curProductionCalendarDayTimeList, calendarDateDTO, week, month, year, startDate, endDate, productionCalendarDay, collect, i, startTime, endTime);
|
if (CollectionUtil.isNotEmpty(shiftDetailVO.getShiftRestTimeVOList())) {
|
List<ShiftRestTimeVO> shiftRestTimeVOList = (List) shiftDetailVO.getShiftRestTimeVOList().stream().sorted(Comparator.comparing((v0) -> {
|
return v0.getRestStartTime();
|
})).collect(Collectors.toList());
|
createShiftDayTime(calendarId, curProductionCalendarDayTimeList, calendarDateDTO, week, month, year, productionCalendarDay, shiftDetailVO, startTime, endTime, shiftRestTimeVOList);
|
} else {
|
ProductionCalendarDaytime productionCalendarDaytime = ProductionCalendarDaytime.builder().calendarDate(calendarDateDTO.getCalendarDate()).year(year).isUndefined(ProductionTimeConstant.DEFINED).isHighPriority(calendarDateDTO.getIsHighPriority()).week(week).month(month).shiftIndex(shiftDetailVO.getShiftIndex()).calendarDayId(productionCalendarDay.getId()).calendarId(calendarId).startTime(LocalDateTimeUtils.plus(calendarDateDTO.getCalendarDate(), startTime.intValue(), ChronoUnit.MINUTES)).endTime(LocalDateTimeUtils.plus(calendarDateDTO.getCalendarDate(), endTime.intValue(), ChronoUnit.MINUTES)).shiftType(ProductionTimeConstant.WORK_TIME).build();
|
curProductionCalendarDayTimeList.add(productionCalendarDaytime);
|
}
|
}
|
curProductionCalendarDayTimeList.removeIf(productionCalendarDaytime2 -> {
|
return productionCalendarDaytime2.getStartTime().equals(productionCalendarDaytime2.getEndTime());
|
});
|
}
|
|
private void updateCalendarDayTime(List<CalendarDateDTO> dateDTOList, ProductionCalendar calenadar) {
|
Long calendarId = calenadar.getId();
|
Integer year = calenadar.getYear();
|
Integer currentYear = Integer.valueOf(LocalDate.now().getYear());
|
Set<LocalDate> dateList = (Set) dateDTOList.stream().filter(c -> {
|
return !Func.isNull(c.getModelId()) && Func.isNull(c.getOffDayId());
|
}).map((v0) -> {
|
return v0.getCalendarDate();
|
}).collect(Collectors.toSet());
|
Set<LocalDate> offDay = (Set) dateDTOList.stream().filter(c2 -> {
|
return !Func.isNull(c2.getOffDayId());
|
}).map((v0) -> {
|
return v0.getCalendarDate();
|
}).collect(Collectors.toSet());
|
List<ProductionCalendarDaytime> productionCalendarDaytimeList = new ArrayList<>();
|
List<ProductionCalendarDay> productionCalendarDayList = new ArrayList<>();
|
List<Long> modelIds = (List) dateDTOList.stream().map((v0) -> {
|
return v0.getModelId();
|
}).distinct().collect(Collectors.toList());
|
Map<Long, ShiftVO> shiftDetailMap = this.shiftModelService.getShiftDetail(modelIds);
|
Snowflake snowflake = IdUtil.createSnowflake(1L, 1L);
|
|
List<ProductionCalendarDaytime> todayDateTimeList = this.calendarDaytimeService.list(new QueryWrapper<ProductionCalendarDaytime>().lambda()
|
.eq(ProductionCalendarDaytime::getCalendarDate, LocalDate.now())
|
.eq(ProductionCalendarDaytime::getCalendarId, calendarId)
|
.orderByAsc(ProductionCalendarDaytime::getStartTime));
|
|
/*
|
List<ProductionCalendarDaytime> todayDateTimeList = this.calendarDaytimeService.list((Wrapper) ((LambdaQueryWrapper) ((LambdaQueryWrapper) new QueryWrapper().lambda().eq((v0) -> {
|
return v0.getCalendarDate();
|
}, LocalDate.now())).eq((v0) -> {
|
return v0.getCalendarId();
|
}, calendarId)).orderByAsc((v0) -> {
|
return v0.getStartTime();
|
}));*/
|
List<ProductionCalendarDaytime> curProductionCalendarDayTimeList = new ArrayList<>();
|
LocalDate lastDayOfYear = LocalDateTimeUtils.getLastDayOfYear(LocalDate.now());
|
long difference = year.intValue() == LocalDate.now().getYear() ? LocalDateTimeUtils.getDifference(LocalDate.now(), lastDayOfYear).intValue() : LocalDateTimeUtils.getDayOfYear(year).intValue() - 1;
|
long j = 0;
|
while (true) {
|
long i = j;
|
if (i <= difference) {
|
LocalDate needHandleDate = year.equals(currentYear) ? LocalDate.now().plus(difference - i, (TemporalUnit) ChronoUnit.DAYS) : LocalDate.of(year.intValue(), 1, 1).plus(difference - i, (TemporalUnit) ChronoUnit.DAYS);
|
LocalDate nextNeedHandleDate = needHandleDate.plus(1L, (TemporalUnit) ChronoUnit.DAYS);
|
buildCurrentDayTime(dateDTOList, calendarId, year, dateList, offDay, productionCalendarDaytimeList, productionCalendarDayList, shiftDetailMap, snowflake, curProductionCalendarDayTimeList, needHandleDate);
|
handleConflietDayTime(calenadar, year, productionCalendarDaytimeList, todayDateTimeList, curProductionCalendarDayTimeList, difference, i, needHandleDate, nextNeedHandleDate);
|
j = i + 1;
|
} else {
|
this.calendarDayService.saveBatchDay(productionCalendarDayList);
|
this.calendarDaytimeService.saveBatchDaytime(productionCalendarDaytimeList);
|
return;
|
}
|
}
|
}
|
|
private void handleConflietDayTime(ProductionCalendar calenadar, Integer year, List<ProductionCalendarDaytime> productionCalendarDaytimeList, List<ProductionCalendarDaytime> todayDateTimeList, List<ProductionCalendarDaytime> curProductionCalendarDayTimeList, long difference, long i, LocalDate needHandleDate, LocalDate nextNeedHandleDate) {
|
if (LocalDate.now().isBefore(LocalDate.of(year.intValue(), 1, 1))) {
|
handleConflictCalendarDay(i, calenadar, productionCalendarDaytimeList, curProductionCalendarDayTimeList, needHandleDate, nextNeedHandleDate);
|
productionCalendarDaytimeList.sort(Comparator.comparing((v0) -> {
|
return v0.getStartTime();
|
}));
|
if (i == difference && i + 1 == LocalDateTimeUtils.getDayOfYear(year).intValue()) {
|
handleFirstDayOfYear(calenadar, productionCalendarDaytimeList, needHandleDate);
|
}
|
} else {
|
if (i <= difference - 1) {
|
handleConflictCalendarDay(i, calenadar, productionCalendarDaytimeList, curProductionCalendarDayTimeList, needHandleDate, nextNeedHandleDate);
|
}
|
if (i == difference - 1) {
|
productionCalendarDaytimeList.sort(Comparator.comparing((v0) -> {
|
return v0.getStartTime();
|
}));
|
handleTomorrow(year, productionCalendarDaytimeList, todayDateTimeList, needHandleDate);
|
}
|
}
|
curProductionCalendarDayTimeList.clear();
|
}
|
|
private void buildCurrentDayTime(List<CalendarDateDTO> dateDTOList, Long calendarId, Integer year, Set<LocalDate> dateList, Set<LocalDate> offDay, List<ProductionCalendarDaytime> productionCalendarDaytimeList, List<ProductionCalendarDay> productionCalendarDayList, Map<Long, ShiftVO> shiftDetailMap, Snowflake snowflake, List<ProductionCalendarDaytime> curProductionCalendarDayTimeList, LocalDate needHandleDate) {
|
if (dateList.contains(needHandleDate)) {
|
handleCalendarDay(dateDTOList, calendarId, year, productionCalendarDayList, shiftDetailMap, snowflake, curProductionCalendarDayTimeList, needHandleDate);
|
} else if (offDay.contains(needHandleDate)) {
|
handleOffDayCalendarDay(dateDTOList, calendarId, year, productionCalendarDayList, shiftDetailMap, snowflake, curProductionCalendarDayTimeList, needHandleDate);
|
} else {
|
handleUndefinedCalendarDay(calendarId, year, curProductionCalendarDayTimeList, needHandleDate);
|
}
|
curProductionCalendarDayTimeList.sort(Comparator.comparing((v0) -> {
|
return v0.getStartTime();
|
}));
|
productionCalendarDaytimeList.sort(Comparator.comparing((v0) -> {
|
return v0.getStartTime();
|
}));
|
}
|
|
private void handleTomorrow(Integer year, List<ProductionCalendarDaytime> productionCalendarDaytimeList, List<ProductionCalendarDaytime> todayDateTimeList, LocalDate needHandleDate) {
|
ProductionCalendarDaytime tomorrow = productionCalendarDaytimeList.get(0);
|
if (Func.isNotEmpty(todayDateTimeList)) {
|
ProductionCalendarDaytime todayDateTime = todayDateTimeList.get(todayDateTimeList.size() - 1);
|
if (tomorrow.getStartTime().isBefore(todayDateTime.getEndTime()) && tomorrow.getIsUndefined().equals(ProductionTimeConstant.DEFINED)) {
|
throw new ServiceException(MessageUtils.message("calendar.time.slice.of.the.day.affected", new Object[0]));
|
}
|
if (tomorrow.getStartTime().isBefore(todayDateTime.getEndTime()) && tomorrow.getIsUndefined().equals(ProductionTimeConstant.UNDEFINED)) {
|
productionCalendarDaytimeList.removeIf(productionCalendarDaytime -> {
|
return productionCalendarDaytime.getStartTime().isBefore(todayDateTime.getEndTime()) && (productionCalendarDaytime.getEndTime().isBefore(todayDateTime.getEndTime()) || productionCalendarDaytime.getEndTime().equals(todayDateTime.getEndTime()));
|
});
|
productionCalendarDaytimeList.get(0).setStartTime(todayDateTime.getEndTime());
|
} else if (tomorrow.getStartTime().isAfter(todayDateTime.getEndTime())) {
|
ProductionCalendarDaytime productionCalendarDaytime2 = ProductionCalendarDaytime.builder().calendarDate(needHandleDate).year(year).week(tomorrow.getWeek()).month(tomorrow.getMonth()).shiftIndex(ProductionTimeConstant.OUT_OF_SHIFT_TIME).calendarId(tomorrow.getCalendarId()).startTime(todayDateTime.getEndTime()).endTime(tomorrow.getStartTime()).shiftType(ProductionTimeConstant.UNDEFINED_TIME_OUT).isHighPriority(ProductionTimeConstant.LOW_PRIORITY).isUndefined(tomorrow.getIsUndefined()).build();
|
productionCalendarDaytimeList.add(productionCalendarDaytime2);
|
}
|
}
|
}
|
|
/* JADX WARN: Multi-variable type inference failed */
|
private void handleFirstDayOfYear(ProductionCalendar productionCalendar, List<ProductionCalendarDaytime> productionCalendarDaytimeList, LocalDate needHandleDate) {
|
Integer year = productionCalendar.getYear();
|
List<ProductionCalendarDaytime> lastYearDateTimeList = new ArrayList<>();
|
|
ProductionCalendar item = (ProductionCalendar)(this.baseMapper.selectOne((new QueryWrapper<ProductionCalendar>()).lambda()
|
.eq(ProductionCalendar::getStatus, ProductionTimeConstant.ENABLE)
|
.eq(ProductionCalendar::getCode, productionCalendar.getCode())
|
.eq(ProductionCalendar::getYear, Integer.valueOf(year.intValue() - 1))));
|
/*
|
ProductionCalendar item = (ProductionCalendar) this.baseMapper.selectOne((Wrapper) ((LambdaQueryWrapper) ((LambdaQueryWrapper) new QueryWrapper().lambda().eq((v0) -> {
|
return v0.getStatus();
|
}, ProductionTimeConstant.ENABLE)).eq((v0) -> {
|
return v0.getCode();
|
}, productionCalendar.getCode())).eq((v0) -> {
|
return v0.getYear();
|
}, Integer.valueOf(year.intValue() - 1)));
|
*/
|
if (Func.isNotEmpty(item)) {
|
lastYearDateTimeList = this.calendarDaytimeService.list(new QueryWrapper<ProductionCalendarDaytime>().lambda()
|
.eq(ProductionCalendarDaytime::getCalendarDate, LocalDate.of(productionCalendar.getYear().intValue() - 1, 12, 31))
|
.eq(ProductionCalendarDaytime::getCalendarId, item.getId())
|
.orderByAsc(ProductionCalendarDaytime::getStartTime));
|
/*
|
lastYearDateTimeList = this.calendarDaytimeService.list((Wrapper) ((LambdaQueryWrapper) ((LambdaQueryWrapper) new QueryWrapper().lambda().eq((v0) -> {
|
return v0.getCalendarDate();
|
}, LocalDate.of(productionCalendar.getYear().intValue() - 1, 12, 31))).eq((v0) -> {
|
return v0.getCalendarId();
|
}, item.getId())).orderByAsc((v0) -> {
|
return v0.getStartTime();
|
}));*/
|
}
|
ProductionCalendarDaytime firstDateTime = productionCalendarDaytimeList.get(0);
|
if (!Func.isNotEmpty(lastYearDateTimeList)) {
|
if (Func.isEmpty(lastYearDateTimeList) && firstDateTime.getStartTime().isAfter(LocalDateTime.of(needHandleDate, LocalTime.of(0, 0, 0)))) {
|
ProductionCalendarDaytime productionCalendarDaytime = ProductionCalendarDaytime.builder().calendarDate(needHandleDate).year(year).week(firstDateTime.getWeek()).month(firstDateTime.getMonth()).shiftIndex(ProductionTimeConstant.OUT_OF_SHIFT_TIME).calendarId(firstDateTime.getCalendarId()).startTime(LocalDateTime.of(needHandleDate, LocalTime.of(0, 0, 0))).endTime(firstDateTime.getStartTime()).shiftType(ProductionTimeConstant.UNDEFINED_TIME_OUT).isHighPriority(ProductionTimeConstant.LOW_PRIORITY).isUndefined(firstDateTime.getIsUndefined()).build();
|
productionCalendarDaytimeList.add(productionCalendarDaytime);
|
return;
|
}
|
return;
|
}
|
ProductionCalendarDaytime lastYearDateTime = lastYearDateTimeList.get(lastYearDateTimeList.size() - 1);
|
boolean useLastShift = isUseLastShift(firstDateTime, lastYearDateTime);
|
boolean useThisShift = isUseThisShift(firstDateTime, lastYearDateTime);
|
boolean conflictShift = isConflictShift(firstDateTime, lastYearDateTime);
|
if (conflictShift) {
|
throw new ServiceException(MessageUtils.message("calendar.time.slice.of.the.day.affected", new Object[0]));
|
}
|
if (useLastShift) {
|
productionCalendarDaytimeList.removeIf(productionCalendarDaytime2 -> {
|
return productionCalendarDaytime2.getStartTime().isBefore(lastYearDateTime.getEndTime()) && (productionCalendarDaytime2.getEndTime().isBefore(lastYearDateTime.getEndTime()) || productionCalendarDaytime2.getEndTime().equals(lastYearDateTime.getEndTime()));
|
});
|
productionCalendarDaytimeList.get(0).setStartTime(lastYearDateTime.getEndTime());
|
} else if (useThisShift) {
|
lastYearDateTimeList.removeIf(productionCalendarDaytime3 -> {
|
return (productionCalendarDaytime3.getStartTime().isAfter(firstDateTime.getStartTime()) || productionCalendarDaytime3.getStartTime().equals(firstDateTime.getStartTime())) && productionCalendarDaytime3.getEndTime().isAfter(firstDateTime.getStartTime());
|
});
|
lastYearDateTimeList.get(lastYearDateTimeList.size() - 1).setEndTime(firstDateTime.getStartTime());
|
this.calendarDaytimeService.deleteByCalendarDate(lastYearDateTime.getCalendarDate(), lastYearDateTime.getCalendarId());
|
productionCalendarDaytimeList.addAll(lastYearDateTimeList);
|
} else if (firstDateTime.getStartTime().isAfter(lastYearDateTime.getEndTime())) {
|
ProductionCalendarDaytime productionCalendarDaytime4 = ProductionCalendarDaytime.builder().calendarDate(needHandleDate).year(year).week(firstDateTime.getWeek()).month(firstDateTime.getMonth()).shiftIndex(ProductionTimeConstant.OUT_OF_SHIFT_TIME).calendarId(firstDateTime.getCalendarId()).startTime(lastYearDateTime.getEndTime()).endTime(firstDateTime.getStartTime()).shiftType(ProductionTimeConstant.UNDEFINED_TIME_OUT).isHighPriority(ProductionTimeConstant.LOW_PRIORITY).isUndefined(firstDateTime.getIsUndefined()).build();
|
productionCalendarDaytimeList.add(productionCalendarDaytime4);
|
}
|
}
|
|
private boolean isConflictShift(ProductionCalendarDaytime firstDateTime, ProductionCalendarDaytime lastYearDateTime) {
|
return lastYearDateTime.getCalendarDate().equals(LocalDate.now()) && firstDateTime.getStartTime().isBefore(lastYearDateTime.getEndTime()) && firstDateTime.getIsUndefined().equals(ProductionTimeConstant.DEFINED);
|
}
|
|
private boolean isUseLastShift(ProductionCalendarDaytime firstDateTime, ProductionCalendarDaytime lastYearDateTime) {
|
boolean useLastShift = firstDateTime.getStartTime().isBefore(lastYearDateTime.getEndTime()) && (lastYearDateTime.getIsHighPriority().equals(ProductionTimeConstant.HIGH_PRIORITY) || (lastYearDateTime.getIsUndefined().equals(ProductionTimeConstant.DEFINED) && firstDateTime.getIsUndefined().equals(ProductionTimeConstant.UNDEFINED)));
|
return useLastShift;
|
}
|
|
private boolean isUseThisShift(ProductionCalendarDaytime firstDateTime, ProductionCalendarDaytime lastYearDateTime) {
|
boolean useThisShift = firstDateTime.getStartTime().isBefore(lastYearDateTime.getEndTime()) && !lastYearDateTime.getCalendarDate().equals(LocalDate.now()) && isCurrentHighPriority(firstDateTime, lastYearDateTime);
|
return useThisShift;
|
}
|
|
private boolean isCurrentHighPriority(ProductionCalendarDaytime firstDateTime, ProductionCalendarDaytime lastYearDateTime) {
|
return firstDateTime.getIsHighPriority().equals(ProductionTimeConstant.HIGH_PRIORITY) || (firstDateTime.getIsUndefined().equals(ProductionTimeConstant.DEFINED) && lastYearDateTime.getIsHighPriority().equals(ProductionTimeConstant.LOW_PRIORITY));
|
}
|
|
private void handleConflictCalendarDay(long i, ProductionCalendar productionCalendar, List<ProductionCalendarDaytime> productionCalendarDaytimeList, List<ProductionCalendarDaytime> curProductionCalendarDayTimeList, LocalDate needHandleDate, LocalDate nextNeedHandleDate) {
|
ProductionCalendarDaytime nextProductionDayTime;
|
Integer year = productionCalendar.getYear();
|
String code = productionCalendar.getCode();
|
new ProductionCalendarDaytime();
|
List<ProductionCalendarDaytime> nextYearDateTimeList = new ArrayList<>();
|
if (i == 0) {
|
ProductionCalendar item =this.baseMapper.selectOne(new QueryWrapper<ProductionCalendar>().lambda()
|
.eq(ProductionCalendar::getStatus, ProductionTimeConstant.ENABLE)
|
.eq(ProductionCalendar::getCode, code)
|
.eq(ProductionCalendar::getYear, Integer.valueOf(year.intValue() + 1)));
|
/*
|
ProductionCalendar item = (ProductionCalendar) this.baseMapper.selectOne((Wrapper) ((LambdaQueryWrapper) ((LambdaQueryWrapper) new QueryWrapper().lambda().eq((v0) -> {
|
return v0.getStatus();
|
}, ProductionTimeConstant.ENABLE)).eq((v0) -> {
|
return v0.getCode();
|
}, code)).eq((v0) -> {
|
return v0.getYear();
|
}, Integer.valueOf(year.intValue() + 1)));
|
*/
|
if (Func.isNotEmpty(item)) {
|
nextYearDateTimeList = this.calendarDaytimeService.list(new QueryWrapper<ProductionCalendarDaytime>().lambda()
|
.eq(ProductionCalendarDaytime::getCalendarDate, LocalDate.of(year.intValue() + 1, 1, 1))
|
.eq(ProductionCalendarDaytime::getCalendarId, item.getId())
|
.orderByAsc(ProductionCalendarDaytime::getStartTime));
|
/*
|
nextYearDateTimeList = this.calendarDaytimeService.list((Wrapper) ((LambdaQueryWrapper) ((LambdaQueryWrapper) new QueryWrapper().lambda().eq((v0) -> {
|
return v0.getCalendarDate();
|
}, LocalDate.of(year.intValue() + 1, 1, 1))).eq((v0) -> {
|
return v0.getCalendarId();
|
}, item.getId())).orderByAsc((v0) -> {
|
return v0.getStartTime();
|
}));*/
|
}
|
if (Func.isNotEmpty(nextYearDateTimeList)) {
|
nextProductionDayTime = nextYearDateTimeList.get(0);
|
} else {
|
nextProductionDayTime = ProductionCalendarDaytime.builder().isHighPriority(ProductionTimeConstant.LOW_PRIORITY).startTime(LocalDateTime.of(year.intValue() + 1, 1, 1, 0, 0, 0)).isUndefined(ProductionTimeConstant.UNDEFINED).calendarDate(LocalDate.of(year.intValue() + 1, 1, 1)).build();
|
}
|
} else {
|
nextProductionDayTime = productionCalendarDaytimeList.get(0);
|
}
|
ProductionCalendarDaytime curProductionDayTime = curProductionCalendarDayTimeList.stream().max(Comparator.comparing((v0) -> {
|
return v0.getStartTime();
|
})).orElse(new ProductionCalendarDaytime());
|
LocalDateTime nextStartTime = nextProductionDayTime.getStartTime();
|
LocalDateTime beforeZore = LocalDateTime.of(needHandleDate, LocalTime.of(23, 59, 59));
|
LocalDateTime zore = needHandleDate.atStartOfDay().plus(1L, (TemporalUnit) ChronoUnit.DAYS);
|
LocalDateTime afterZore = LocalDateTime.of(nextNeedHandleDate, LocalTime.of(0, 0, 1));
|
LocalDateTime curEndTime = curProductionDayTime.getEndTime();
|
if (curEndTime.isAfter(nextStartTime)) {
|
handleConflietDayTime(i, productionCalendarDaytimeList, curProductionCalendarDayTimeList, nextProductionDayTime, nextYearDateTimeList, curProductionDayTime, nextStartTime, curEndTime);
|
} else if (curEndTime.equals(nextStartTime)) {
|
productionCalendarDaytimeList.addAll(curProductionCalendarDayTimeList);
|
} else if (curEndTime.isBefore(nextStartTime) && curEndTime.isAfter(beforeZore)) {
|
buildEndTimeAfterZero(productionCalendarDaytimeList, curProductionCalendarDayTimeList, nextNeedHandleDate, year, nextProductionDayTime, nextStartTime, curEndTime);
|
} else if (curEndTime.isBefore(nextStartTime) && nextStartTime.isBefore(afterZore)) {
|
buildEndTimeBeforeZero(productionCalendarDaytimeList, curProductionCalendarDayTimeList, needHandleDate, year, curProductionDayTime, nextStartTime, curEndTime);
|
} else if (curEndTime.isBefore(nextStartTime) && nextStartTime.isAfter(afterZore) && curEndTime.isBefore(beforeZore)) {
|
buildEndTimeBothSideZero(productionCalendarDaytimeList, curProductionCalendarDayTimeList, needHandleDate, nextNeedHandleDate, year, nextProductionDayTime, curProductionDayTime, nextStartTime, zore, curEndTime);
|
}
|
}
|
|
private void handleConflietDayTime(long i, List<ProductionCalendarDaytime> productionCalendarDaytimeList, List<ProductionCalendarDaytime> curProductionCalendarDayTimeList, ProductionCalendarDaytime nextProductionDayTime, List<ProductionCalendarDaytime> nextYearDateTimeList, ProductionCalendarDaytime curProductionDayTime, LocalDateTime nextStartTime, LocalDateTime curEndTime) {
|
boolean useCurShift = curProductionDayTime.getIsHighPriority().equals(ProductionTimeConstant.HIGH_PRIORITY) || (curProductionDayTime.getIsUndefined().equals(ProductionTimeConstant.DEFINED) && nextProductionDayTime.getIsUndefined().equals(ProductionTimeConstant.UNDEFINED));
|
if (useCurShift) {
|
if (i == 0) {
|
if (Func.isNotEmpty(nextYearDateTimeList)) {
|
nextYearDateTimeList.removeIf(productionCalendarDaytime -> {
|
return productionCalendarDaytime.getStartTime().isBefore(curEndTime) && productionCalendarDaytime.getEndTime().isBefore(curEndTime);
|
});
|
nextYearDateTimeList.get(0).setStartTime(curEndTime);
|
this.calendarDaytimeService.deleteByCalendarDate(nextProductionDayTime.getCalendarDate(), nextProductionDayTime.getCalendarId());
|
productionCalendarDaytimeList.addAll(nextYearDateTimeList);
|
}
|
} else {
|
productionCalendarDaytimeList.removeIf(productionCalendarDaytime2 -> {
|
return productionCalendarDaytime2.getStartTime().isBefore(curEndTime) && (productionCalendarDaytime2.getEndTime().isBefore(curEndTime) || productionCalendarDaytime2.getEndTime().equals(curEndTime));
|
});
|
productionCalendarDaytimeList.get(0).setStartTime(curEndTime);
|
}
|
productionCalendarDaytimeList.addAll(curProductionCalendarDayTimeList);
|
return;
|
}
|
List<ProductionCalendarDaytime> filterList = (List) curProductionCalendarDayTimeList.stream().filter(item -> {
|
return item.getStartTime().isBefore(nextStartTime);
|
}).sorted(Comparator.comparing((v0) -> {
|
return v0.getStartTime();
|
})).collect(Collectors.toList());
|
if (Func.isNotEmpty(filterList)) {
|
filterList.get(filterList.size() - 1).setEndTime(nextStartTime);
|
productionCalendarDaytimeList.addAll(filterList);
|
}
|
}
|
|
private void buildEndTimeBothSideZero(List<ProductionCalendarDaytime> productionCalendarDaytimeList, List<ProductionCalendarDaytime> curProductionCalendarDayTimeList, LocalDate needHandleDate, LocalDate nextNeedHandleDate, Integer year, ProductionCalendarDaytime nextProductionDayTime, ProductionCalendarDaytime curProductionDayTime, LocalDateTime nextStartTime, LocalDateTime zore, LocalDateTime curEndTime) {
|
ProductionCalendarDaytime before = ProductionCalendarDaytime.builder().calendarDate(needHandleDate).isUndefined(curProductionDayTime.getIsUndefined()).isHighPriority(ProductionTimeConstant.LOW_PRIORITY).year(year).week(curProductionDayTime.getWeek()).month(curProductionDayTime.getMonth()).shiftIndex(ProductionTimeConstant.OUT_OF_SHIFT_TIME).calendarId(curProductionDayTime.getCalendarId()).startTime(curEndTime).endTime(zore).shiftType(ProductionTimeConstant.UNDEFINED_TIME_OUT).build();
|
ProductionCalendarDaytime next = ProductionCalendarDaytime.builder().calendarDate(nextNeedHandleDate).isUndefined(nextProductionDayTime.getIsUndefined()).isHighPriority(ProductionTimeConstant.LOW_PRIORITY).year(year).week(nextProductionDayTime.getWeek()).month(nextProductionDayTime.getMonth()).shiftIndex(ProductionTimeConstant.OUT_OF_SHIFT_TIME).calendarId(nextProductionDayTime.getCalendarId()).startTime(zore).endTime(nextStartTime).shiftType(ProductionTimeConstant.UNDEFINED_TIME_OUT).build();
|
curProductionCalendarDayTimeList.add(before);
|
curProductionCalendarDayTimeList.add(next);
|
productionCalendarDaytimeList.addAll(curProductionCalendarDayTimeList);
|
}
|
|
private void buildEndTimeBeforeZero(List<ProductionCalendarDaytime> productionCalendarDaytimeList, List<ProductionCalendarDaytime> curProductionCalendarDayTimeList, LocalDate needHandleDate, Integer year, ProductionCalendarDaytime curProductionDayTime, LocalDateTime nextStartTime, LocalDateTime curEndTime) {
|
ProductionCalendarDaytime productionCalendarDaytime = ProductionCalendarDaytime.builder().calendarDate(needHandleDate).isUndefined(ProductionTimeConstant.UNDEFINED).isHighPriority(ProductionTimeConstant.LOW_PRIORITY).year(year).week(curProductionDayTime.getWeek()).month(curProductionDayTime.getMonth()).shiftIndex(ProductionTimeConstant.OUT_OF_SHIFT_TIME).calendarId(curProductionDayTime.getCalendarId()).startTime(curEndTime).endTime(nextStartTime).shiftType(ProductionTimeConstant.UNDEFINED_TIME_OUT).build();
|
curProductionCalendarDayTimeList.add(productionCalendarDaytime);
|
productionCalendarDaytimeList.addAll(curProductionCalendarDayTimeList);
|
}
|
|
private void buildEndTimeAfterZero(List<ProductionCalendarDaytime> productionCalendarDaytimeList, List<ProductionCalendarDaytime> curProductionCalendarDayTimeList, LocalDate nextNeedHandleDate, Integer year, ProductionCalendarDaytime nextProductionDayTime, LocalDateTime nextStartTime, LocalDateTime curEndTime) {
|
ProductionCalendarDaytime productionCalendarDaytime = ProductionCalendarDaytime.builder().calendarDate(nextNeedHandleDate).isUndefined(nextProductionDayTime.getIsUndefined()).isHighPriority(ProductionTimeConstant.LOW_PRIORITY).year(year).week(nextProductionDayTime.getWeek()).month(nextProductionDayTime.getMonth()).shiftIndex(ProductionTimeConstant.OUT_OF_SHIFT_TIME).calendarId(nextProductionDayTime.getCalendarId()).startTime(curEndTime).endTime(nextStartTime).shiftType(ProductionTimeConstant.UNDEFINED_TIME_OUT).build();
|
curProductionCalendarDayTimeList.add(productionCalendarDaytime);
|
productionCalendarDaytimeList.addAll(curProductionCalendarDayTimeList);
|
}
|
|
private void handleCalendarDay(List<CalendarDateDTO> dateDTOList, Long calendarId, Integer year, List<ProductionCalendarDay> productionCalendarDayList, Map<Long, ShiftVO> shiftDetailMap, Snowflake snowflake, List<ProductionCalendarDaytime> curProductionCalendarDayTimeList, LocalDate needHandleDate) {
|
CalendarDateDTO calendarDateDTO = dateDTOList.stream().filter(dateDTO -> {
|
return dateDTO.getCalendarDate().equals(needHandleDate);
|
}).findFirst().orElse(new CalendarDateDTO());
|
ShiftVO shiftDetail = shiftDetailMap.get(calendarDateDTO.getModelId());
|
Integer week = LocalDateTimeUtils.getWeek(calendarDateDTO.getCalendarDate());
|
Integer month = LocalDateTimeUtils.getMonth(calendarDateDTO.getCalendarDate());
|
Integer startDate = shiftDetail.getStartTime();
|
Integer endDate = shiftDetail.getEndTime();
|
ProductionCalendarDay productionCalendarDay = ProductionCalendarDay.builder().calendarId(calendarId).calendarDate(calendarDateDTO.getCalendarDate()).modelId(calendarDateDTO.getModelId()).isHighPriority(calendarDateDTO.getIsHighPriority()).week(week).month(month).year(year).isOffDay(CalendarConstant.NO_OFF_DAY).startTime(LocalDateTimeUtils.plus(calendarDateDTO.getCalendarDate(), shiftDetail.getStartTime().intValue(), ChronoUnit.MINUTES)).endTime(LocalDateTimeUtils.plus(calendarDateDTO.getCalendarDate(), shiftDetail.getEndTime().intValue(), ChronoUnit.MINUTES)).build();
|
buildCalendarOffDay(productionCalendarDay, snowflake, productionCalendarDayList, shiftDetail, calendarId, curProductionCalendarDayTimeList, calendarDateDTO, week, month, year, startDate, endDate);
|
}
|
|
private void handleUndefinedCalendarDay(Long calendarId, Integer year, List<ProductionCalendarDaytime> curProductionCalendarDayTimeList, LocalDate needHandleDate) {
|
ProductionCalendarDaytime productionCalendarDaytime = ProductionCalendarDaytime.builder().calendarDate(needHandleDate).year(year).week(LocalDateTimeUtils.getWeek(needHandleDate)).month(LocalDateTimeUtils.getMonth(needHandleDate)).shiftIndex(ProductionTimeConstant.OUT_OF_SHIFT_TIME).calendarId(calendarId).startTime(LocalDateTime.of(needHandleDate, LocalTime.of(0, 0, 0))).endTime(LocalDateTimeUtils.plus(needHandleDate, 1L, ChronoUnit.DAYS)).shiftType(ProductionTimeConstant.UNDEFINED_TIME_IN).isHighPriority(ProductionTimeConstant.LOW_PRIORITY).isUndefined(ProductionTimeConstant.UNDEFINED).build();
|
curProductionCalendarDayTimeList.add(productionCalendarDaytime);
|
}
|
|
private void createUndefinedDaytime(Long calendarId, List<ProductionCalendarDaytime> curProductionCalendarDayTimeList, CalendarDateDTO calendarDateDTO, Integer week, Integer month, Integer year, Integer startDate, Integer endDate, ProductionCalendarDay productionCalendarDay, List<ShiftDetailVO> collect, int i, Integer startTime, Integer endTime) {
|
ProductionCalendarDaytime undefinedDaytime = ProductionCalendarDaytime.builder().calendarDate(calendarDateDTO.getCalendarDate()).year(year).week(week).month(month).shiftIndex(ProductionTimeConstant.OUT_OF_SHIFT_TIME).calendarDayId(productionCalendarDay.getId()).isUndefined(ProductionTimeConstant.DEFINED).isHighPriority(calendarDateDTO.getIsHighPriority()).calendarDayId(productionCalendarDay.getId()).calendarId(calendarId).build();
|
if (i == 0) {
|
ProductionCalendarDaytime undefinedDaytime1 = new ProductionCalendarDaytime();
|
BeanUtils.copyProperties(undefinedDaytime, undefinedDaytime1);
|
undefinedDaytime1.setStartTime(LocalDateTimeUtils.plus(calendarDateDTO.getCalendarDate(), startDate.intValue(), ChronoUnit.MINUTES));
|
undefinedDaytime1.setEndTime(LocalDateTimeUtils.plus(calendarDateDTO.getCalendarDate(), startTime.intValue(), ChronoUnit.MINUTES));
|
undefinedDaytime1.setShiftType(ProductionTimeConstant.UNDEFINED_TIME_IN);
|
curProductionCalendarDayTimeList.add(undefinedDaytime1);
|
}
|
if (i < collect.size() - 1) {
|
undefinedDaytime.setStartTime(LocalDateTimeUtils.plus(calendarDateDTO.getCalendarDate(), endTime.intValue(), ChronoUnit.MINUTES));
|
undefinedDaytime.setEndTime(LocalDateTimeUtils.plus(calendarDateDTO.getCalendarDate(), collect.get(i + 1).getShiftStartTime().intValue(), ChronoUnit.MINUTES));
|
undefinedDaytime.setShiftType(ProductionTimeConstant.UNDEFINED_TIME_IN);
|
curProductionCalendarDayTimeList.add(undefinedDaytime);
|
} else if (i == collect.size() - 1) {
|
undefinedDaytime.setStartTime(LocalDateTimeUtils.plus(calendarDateDTO.getCalendarDate(), endTime.intValue(), ChronoUnit.MINUTES));
|
undefinedDaytime.setEndTime(LocalDateTimeUtils.plus(calendarDateDTO.getCalendarDate(), endDate.intValue(), ChronoUnit.MINUTES));
|
undefinedDaytime.setShiftType(ProductionTimeConstant.UNDEFINED_TIME_IN);
|
curProductionCalendarDayTimeList.add(undefinedDaytime);
|
}
|
}
|
|
private void createShiftDayTime(Long calendarId, List<ProductionCalendarDaytime> curProductionCalendarDayTimeList, CalendarDateDTO calendarDateDTO, Integer week, Integer month, Integer year, ProductionCalendarDay productionCalendarDay, ShiftDetailVO shiftDetailVO, Integer startTime, Integer endTime, List<ShiftRestTimeVO> shiftRestTimeVOList) {
|
Stream.iterate(0, j -> {
|
return Integer.valueOf(j.intValue() + 1);
|
}).limit(shiftRestTimeVOList.size()).forEach(j2 -> {
|
ProductionCalendarDaytime productionCalendarDaytime = ProductionCalendarDaytime.builder().calendarDate(calendarDateDTO.getCalendarDate()).year(year).week(week).month(month).shiftIndex(shiftDetailVO.getShiftIndex()).calendarDayId(productionCalendarDay.getId()).isUndefined(ProductionTimeConstant.DEFINED).isHighPriority(calendarDateDTO.getIsHighPriority()).calendarId(calendarId).build();
|
if (j2.intValue() == 0) {
|
productionCalendarDaytime.setStartTime(LocalDateTimeUtils.plus(calendarDateDTO.getCalendarDate(), startTime.intValue(), ChronoUnit.MINUTES));
|
productionCalendarDaytime.setEndTime(LocalDateTimeUtils.plus(calendarDateDTO.getCalendarDate(), ((ShiftRestTimeVO) shiftRestTimeVOList.get(0)).getRestStartTime().intValue(), ChronoUnit.MINUTES));
|
productionCalendarDaytime.setShiftType(ProductionTimeConstant.WORK_TIME);
|
ProductionCalendarDaytime productionCalendarDaytime1 = new ProductionCalendarDaytime();
|
BeanUtils.copyProperties(productionCalendarDaytime, productionCalendarDaytime1);
|
productionCalendarDaytime1.setStartTime(LocalDateTimeUtils.plus(calendarDateDTO.getCalendarDate(), ((ShiftRestTimeVO) shiftRestTimeVOList.get(j2.intValue())).getRestStartTime().intValue(), ChronoUnit.MINUTES));
|
productionCalendarDaytime1.setEndTime(LocalDateTimeUtils.plus(calendarDateDTO.getCalendarDate(), ((ShiftRestTimeVO) shiftRestTimeVOList.get(j2.intValue())).getRestEndTime().intValue(), ChronoUnit.MINUTES));
|
productionCalendarDaytime1.setShiftType(ProductionTimeConstant.REST_TIME);
|
curProductionCalendarDayTimeList.add(productionCalendarDaytime);
|
curProductionCalendarDayTimeList.add(productionCalendarDaytime1);
|
} else if (j2.intValue() > 0 && j2.intValue() < shiftRestTimeVOList.size()) {
|
productionCalendarDaytime.setStartTime(LocalDateTimeUtils.plus(calendarDateDTO.getCalendarDate(), ((ShiftRestTimeVO) shiftRestTimeVOList.get(j2.intValue())).getRestStartTime().intValue(), ChronoUnit.MINUTES));
|
productionCalendarDaytime.setEndTime(LocalDateTimeUtils.plus(calendarDateDTO.getCalendarDate(), ((ShiftRestTimeVO) shiftRestTimeVOList.get(j2.intValue())).getRestEndTime().intValue(), ChronoUnit.MINUTES));
|
productionCalendarDaytime.setShiftType(ProductionTimeConstant.REST_TIME);
|
ProductionCalendarDaytime productionCalendarDaytime12 = new ProductionCalendarDaytime();
|
BeanUtils.copyProperties(productionCalendarDaytime, productionCalendarDaytime12);
|
productionCalendarDaytime12.setStartTime(LocalDateTimeUtils.plus(calendarDateDTO.getCalendarDate(), ((ShiftRestTimeVO) shiftRestTimeVOList.get(j2.intValue() - 1)).getRestEndTime().intValue(), ChronoUnit.MINUTES));
|
productionCalendarDaytime12.setEndTime(LocalDateTimeUtils.plus(calendarDateDTO.getCalendarDate(), ((ShiftRestTimeVO) shiftRestTimeVOList.get(j2.intValue())).getRestStartTime().intValue(), ChronoUnit.MINUTES));
|
productionCalendarDaytime12.setShiftType(ProductionTimeConstant.WORK_TIME);
|
curProductionCalendarDayTimeList.add(productionCalendarDaytime);
|
curProductionCalendarDayTimeList.add(productionCalendarDaytime12);
|
}
|
if (j2.intValue() == shiftRestTimeVOList.size() - 1) {
|
ProductionCalendarDaytime productionCalendarDaytime13 = new ProductionCalendarDaytime();
|
BeanUtils.copyProperties(productionCalendarDaytime, productionCalendarDaytime13);
|
productionCalendarDaytime13.setStartTime(LocalDateTimeUtils.plus(calendarDateDTO.getCalendarDate(), ((ShiftRestTimeVO) shiftRestTimeVOList.get(j2.intValue())).getRestEndTime().intValue(), ChronoUnit.MINUTES));
|
productionCalendarDaytime13.setEndTime(LocalDateTimeUtils.plus(calendarDateDTO.getCalendarDate(), endTime.intValue(), ChronoUnit.MINUTES));
|
productionCalendarDaytime13.setShiftType(ProductionTimeConstant.WORK_TIME);
|
curProductionCalendarDayTimeList.add(productionCalendarDaytime13);
|
}
|
});
|
}
|
|
@Override // org.springblade.modules.cps.service.ICalendarService
|
public CalendarVO getCalendar(Long calendarId) {
|
CalendarVO calendarDetail = this.baseMapper.getCalendarDetail(calendarId);
|
List<CalendarDayVO> otherCalendarDayVOList = new ArrayList<>();
|
Integer year = calendarDetail.getYear();
|
|
Optional.<ProductionCalendar>ofNullable(getOne(new QueryWrapper<ProductionCalendar>().lambda()
|
.eq(ProductionCalendar::getCode, calendarDetail.getCode())
|
.eq(ProductionCalendar::getYear, year+ 1)))
|
.ifPresent(productionCalendar -> {
|
List<ProductionCalendarDay> list = this.calendarDayService.list(new QueryWrapper<ProductionCalendarDay>().lambda().eq(ProductionCalendarDay::getCalendarId, productionCalendar.getId()).in(ProductionCalendarDay::getCalendarDate, new Object[] { LocalDate.of(year.intValue() + 1, 1, 1), LocalDate.of(year.intValue() + 1, 1, 2) }));
|
entityToVo(otherCalendarDayVOList, list);
|
});
|
|
/*
|
Optional.ofNullable(getOne((Wrapper) ((LambdaQueryWrapper) new QueryWrapper().lambda().eq((v0) -> {
|
return v0.getCode();
|
}, calendarDetail.getCode())).eq((v0) -> {
|
return v0.getYear();
|
}, Integer.valueOf(year.intValue() + 1)))).ifPresent(productionCalendar -> {
|
List<ProductionCalendarDay> list = this.calendarDayService.list((Wrapper) ((LambdaQueryWrapper) new QueryWrapper().lambda().eq((v0) -> {
|
return v0.getCalendarId();
|
}, productionCalendar.getId())).in((v0) -> {
|
return v0.getCalendarDate();
|
}, new Object[]{LocalDate.of(year.intValue() + 1, 1, 1), LocalDate.of(year.intValue() + 1, 1, 2)}));
|
entityToVo(otherCalendarDayVOList, list);
|
});*/
|
|
Optional.<ProductionCalendar>ofNullable(getOne(new QueryWrapper<ProductionCalendar>().lambda()
|
.eq(ProductionCalendar::getCode, calendarDetail.getCode())
|
.eq(ProductionCalendar::getYear, year.intValue() - 1)))
|
.ifPresent(productionCalendar -> {
|
List<ProductionCalendarDay> list = this.calendarDayService.list(new QueryWrapper<ProductionCalendarDay>().lambda().eq(ProductionCalendarDay::getCalendarId, productionCalendar.getId()).in(ProductionCalendarDay::getCalendarDate, new Object[] { LocalDate.of(year.intValue() - 1, 12, 30), LocalDate.of(year.intValue() - 1, 12, 31) }));
|
entityToVo(otherCalendarDayVOList, list);
|
});
|
|
/*
|
Optional.ofNullable(getOne((Wrapper) ((LambdaQueryWrapper) new QueryWrapper().lambda().eq((v0) -> {
|
return v0.getCode();
|
}, calendarDetail.getCode())).eq((v0) -> {
|
return v0.getYear();
|
}, Integer.valueOf(year.intValue() - 1)))).ifPresent(productionCalendar2 -> {
|
List<ProductionCalendarDay> list = this.calendarDayService.list((Wrapper) ((LambdaQueryWrapper) new QueryWrapper().lambda().eq((v0) -> {
|
return v0.getCalendarId();
|
}, productionCalendar2.getId())).in((v0) -> {
|
return v0.getCalendarDate();
|
}, new Object[]{LocalDate.of(year.intValue() - 1, 12, 30), LocalDate.of(year.intValue() - 1, 12, 31)}));
|
entityToVo(otherCalendarDayVOList, list);
|
});
|
*/
|
calendarDetail.setOtherCalendarDayVOList(otherCalendarDayVOList);
|
return calendarDetail;
|
}
|
|
private void entityToVo(List<CalendarDayVO> otherCalendarDayVOList, List<ProductionCalendarDay> list) {
|
if (Func.isNotEmpty(list)) {
|
otherCalendarDayVOList.addAll((Collection) list.stream().map(productionCalendarDay -> {
|
CalendarDayVO calendarDayVO = new CalendarDayVO();
|
BeanUtils.copyProperties(productionCalendarDay, calendarDayVO);
|
return calendarDayVO;
|
}).collect(Collectors.toList()));
|
}
|
}
|
|
@Override // org.springblade.modules.cps.service.ICalendarService
|
@Transactional(rollbackFor = {Exception.class})
|
public ProductionCalendar copyCalendar(CalendarCopyVO calendarCopyVO) {
|
CalendarSaveVO calendarSaveVO = new CalendarSaveVO();
|
BeanUtils.copyProperties(calendarCopyVO, calendarSaveVO);
|
checkCalendar(calendarSaveVO, AuthUtil.getTenantId());
|
CalendarVO calendar = getCalendar(calendarCopyVO.getId());
|
ProductionCalendar productionCalendar = ProductionCalendar.builder().code(calendarCopyVO.getCode()).name(calendar.getName()).status(calendar.getStatus()).year(calendarCopyVO.getYear()).build();
|
save(productionCalendar);
|
return productionCalendar;
|
}
|
|
public void checkCalendar(CalendarSaveVO calendarSaveVO, String tenantId) {
|
ProductionCalendar productionCalendar = getOne(Wrappers.<ProductionCalendar>lambdaQuery()
|
.eq(ProductionCalendar::getCode, calendarSaveVO.getCode())
|
.eq(ProductionCalendar::getYear, calendarSaveVO.getYear())
|
.eq(ProductionCalendar::getTenantId, tenantId));
|
/*
|
ProductionCalendar productionCalendar = (ProductionCalendar) getOne((Wrapper) ((LambdaQueryWrapper) ((LambdaQueryWrapper) Wrappers.lambdaQuery().eq((v0) -> {
|
return v0.getCode();
|
}, calendarSaveVO.getCode())).eq((v0) -> {
|
return v0.getYear();
|
}, calendarSaveVO.getYear())).eq((v0) -> {
|
return v0.getTenantId();
|
}, tenantId));
|
*/
|
Optional.ofNullable(productionCalendar).ifPresent(po -> {
|
throw new ServiceException(MessageUtils.message("calendar.code.year.has.be.repeated", new Object[0]));
|
});
|
}
|
|
private void saveYearCalendarDayTime(List<CalendarDateDTO> dateDTOList, ProductionCalendar productionCalendar) {
|
Integer year = productionCalendar.getYear();
|
Long calendarId = productionCalendar.getId();
|
Set<LocalDate> dateList = (Set) dateDTOList.stream().filter(c -> {
|
return !Func.isNull(c.getModelId()) && Func.isNull(c.getOffDayId());
|
}).map((v0) -> {
|
return v0.getCalendarDate();
|
}).collect(Collectors.toSet());
|
Set<LocalDate> offDay = (Set) dateDTOList.stream().filter(c2 -> {
|
return !Func.isNull(c2.getOffDayId());
|
}).map((v0) -> {
|
return v0.getCalendarDate();
|
}).collect(Collectors.toSet());
|
List<ProductionCalendarDaytime> productionCalendarDaytimeList = new ArrayList<>();
|
List<ProductionCalendarDay> productionCalendarDayList = new ArrayList<>();
|
List<Long> modelIds = (List) dateDTOList.stream().map((v0) -> {
|
return v0.getModelId();
|
}).distinct().collect(Collectors.toList());
|
Map<Long, ShiftVO> shiftDetailMap = this.shiftModelService.getShiftDetail(modelIds);
|
Snowflake snowflake = IdUtil.createSnowflake(1L, 1L);
|
List<ProductionCalendarDaytime> curProductionCalendarDayTimeList = new ArrayList<>();
|
LocalDate lastDayOfYear = LocalDateTimeUtils.getLastDayOfYear(LocalDate.of(year.intValue(), 1, 1));
|
LocalDate firstDay = LocalDate.of(LocalDate.now().getYear(), 1, 1);
|
Integer thisYear = Integer.valueOf(firstDay.getYear());
|
long difference = year.equals(thisYear) ? LocalDateTimeUtils.getDifference(firstDay, lastDayOfYear).intValue() : LocalDateTimeUtils.getDayOfYear(year).intValue() - 1;
|
long j = 0;
|
while (true) {
|
long i = j;
|
if (i <= difference) {
|
LocalDate needHandleDate = year.equals(thisYear) ? firstDay.plus(difference - i, (TemporalUnit) ChronoUnit.DAYS) : LocalDate.of(year.intValue(), 1, 1).plus(difference - i, (TemporalUnit) ChronoUnit.DAYS);
|
LocalDate nextNeedHandleDate = needHandleDate.plus(1L, (TemporalUnit) ChronoUnit.DAYS);
|
if (dateList.contains(needHandleDate)) {
|
handleCalendarDay(dateDTOList, calendarId, year, productionCalendarDayList, shiftDetailMap, snowflake, curProductionCalendarDayTimeList, needHandleDate);
|
} else if (offDay.contains(needHandleDate)) {
|
handleOffDayCalendarDay(dateDTOList, calendarId, year, productionCalendarDayList, shiftDetailMap, snowflake, curProductionCalendarDayTimeList, needHandleDate);
|
} else {
|
handleUndefinedCalendarDay(calendarId, year, curProductionCalendarDayTimeList, needHandleDate);
|
}
|
curProductionCalendarDayTimeList.sort(Comparator.comparing((v0) -> {
|
return v0.getStartTime();
|
}));
|
productionCalendarDaytimeList.sort(Comparator.comparing((v0) -> {
|
return v0.getStartTime();
|
}));
|
handleConflictCalendarDay(i, productionCalendar, productionCalendarDaytimeList, curProductionCalendarDayTimeList, needHandleDate, nextNeedHandleDate);
|
if (i == difference && i + 1 == LocalDateTimeUtils.getDayOfYear(year).intValue()) {
|
productionCalendarDaytimeList.sort(Comparator.comparing((v0) -> {
|
return v0.getStartTime();
|
}));
|
handleFirstDayOfYear(productionCalendar, productionCalendarDaytimeList, needHandleDate);
|
}
|
curProductionCalendarDayTimeList.clear();
|
j = i + 1;
|
} else {
|
this.calendarDayService.saveBatchDay(productionCalendarDayList);
|
this.calendarDaytimeService.saveBatchDaytime(productionCalendarDaytimeList);
|
return;
|
}
|
}
|
}
|
|
@Override // org.springblade.modules.cps.service.ICalendarService
|
public List<TimestampToProductionTimeCacheDto> buildProductionTimeCache(CacheBuildDTO cacheBuildDTO) {
|
LocalDate targetDate = cacheBuildDTO.getTargetDate();
|
Set<String> tenantIds = cacheBuildDTO.getTenantIds();
|
String code = cacheBuildDTO.getCalendarCode();
|
|
List<ProductionCalendar> list = list(new QueryWrapper<ProductionCalendar>().lambda()
|
.in(ProductionCalendar::getTenantId, tenantIds)
|
.eq(ProductionCalendar::getStatus, ProductionTimeConstant.ENABLE)
|
.eq(StringUtils.isNotBlank(code), ProductionCalendar::getCode, code)
|
.eq(ProductionCalendar::getYear, Integer.valueOf(targetDate.getYear())));
|
/*
|
List<ProductionCalendar> list = list((Wrapper) ((LambdaQueryWrapper) ((LambdaQueryWrapper) new QueryWrapper().lambda().in((v0) -> {
|
return v0.getTenantId();
|
}, tenantIds)).eq((v0) -> {
|
return v0.getStatus();
|
}, ProductionTimeConstant.ENABLE)).eq(StringUtils.isNotBlank(code), (v0) -> {
|
return v0.getCode();
|
}, code).eq((v0) -> {
|
return v0.getYear();
|
}, Integer.valueOf(targetDate.getYear())));*/
|
LocalDateTime startTime = LocalDateTime.of(targetDate, LocalTime.MIN);
|
LocalDateTime endTime = LocalDateTime.of(targetDate.plusDays(1L), LocalTime.of(0, 0));
|
if (Func.isNotEmpty(list)) {
|
return list.stream()
|
.map(productionCalendar -> {
|
|
TimestampToProductionTimeCacheDto timestampToProductionTimeCacheDto = TimestampToProductionTimeCacheDto.builder().TenantId(productionCalendar.getTenantId()).CalendarCode(productionCalendar.getCode()).NaturalDay(targetDate).build();
|
|
List<ProductionCalendarDaytime> dayTimeList = this.calendarDaytimeService.list(new QueryWrapper<ProductionCalendarDaytime>().lambda()
|
.eq(ProductionCalendarDaytime::getCalendarId, productionCalendar.getId())
|
.or().and(i ->{
|
i.between(ProductionCalendarDaytime::getStartTime, startTime, endTime).or().between(ProductionCalendarDaytime::getEndTime, startTime, endTime);
|
//return i;
|
})
|
.orderByAsc(ProductionCalendarDaytime::getStartTime));
|
dayTimeList = dayTimeList.stream().filter(productionCalendarDaytime -> {
|
return (productionCalendarDaytime.getEndTime().equals(startTime) || productionCalendarDaytime.getStartTime().equals(endTime)) ? false : true;
|
}).collect(Collectors.toList());
|
Map<Integer, CalendarShiftTimeSlicesDTO> timeSlicesMap = new HashMap<>(1919);
|
for (int i = 0; i <= ProductionTimeConstant.MINUTE_STOP.intValue(); i++) {
|
buildTimeSlicesMap(startTime, endTime, dayTimeList, timeSlicesMap, i, targetDate);
|
}
|
timestampToProductionTimeCacheDto.setTimeSlicesDTOMap(timeSlicesMap);
|
return timestampToProductionTimeCacheDto;
|
|
}).collect(Collectors.toList());
|
/*
|
return (List) list.stream().map(productionCalendar -> {
|
TimestampToProductionTimeCacheDto timestampToProductionTimeCacheDto = TimestampToProductionTimeCacheDto.builder().TenantId(productionCalendar.getTenantId()).CalendarCode(productionCalendar.getCode()).NaturalDay(targetDate).build();
|
List<ProductionCalendarDaytime> dayTimeList = this.calendarDaytimeService.list((Wrapper) ((LambdaQueryWrapper) ((LambdaQueryWrapper) ((LambdaQueryWrapper) new QueryWrapper().lambda().eq((v0) -> {
|
return v0.getCalendarId();
|
}, productionCalendar.getId())).or()).and(i -> {
|
LambdaQueryWrapper lambdaQueryWrapper = (LambdaQueryWrapper) ((LambdaQueryWrapper) ((LambdaQueryWrapper) i.between((v0) -> {
|
return v0.getStartTime();
|
}, startTime, endTime)).or()).between((v0) -> {
|
return v0.getEndTime();
|
}, startTime, endTime);
|
})).orderByAsc((v0) -> {
|
return v0.getStartTime();
|
}));
|
List<ProductionCalendarDaytime> dayTimeList2 = (List) dayTimeList.stream().filter(productionCalendarDaytime -> {
|
return (productionCalendarDaytime.getEndTime().equals(startTime) || productionCalendarDaytime.getStartTime().equals(endTime)) ? false : true;
|
}).collect(Collectors.toList());
|
Map<Integer, CalendarShiftTimeSlicesDTO> timeSlicesMap = new HashMap<>(1919);
|
for (int i2 = 0; i2 <= ProductionTimeConstant.MINUTE_STOP.intValue(); i2++) {
|
buildTimeSlicesMap(startTime, endTime, dayTimeList2, timeSlicesMap, i2, targetDate);
|
}
|
timestampToProductionTimeCacheDto.setTimeSlicesDTOMap(timeSlicesMap);
|
return timestampToProductionTimeCacheDto;
|
}).collect(Collectors.toList());
|
*/
|
}
|
return Lists.newArrayList();
|
}
|
|
private void buildTimeSlicesMap(LocalDateTime startTime, LocalDateTime endTime, List<ProductionCalendarDaytime> dayTimeList, Map<Integer, CalendarShiftTimeSlicesDTO> timeSlicesDTOMap, int i, LocalDate targetDate) {
|
LocalDateTime localDateTime = LocalDateTime.of(targetDate, LocalTime.MIN).plusMinutes(i).plusSeconds(1L);
|
ProductionCalendarDaytime productionCalendarDaytime = dayTimeList.stream().filter(dayTime -> {
|
return (localDateTime.isAfter(dayTime.getStartTime()) || localDateTime.equals(dayTime.getStartTime())) && (localDateTime.isBefore(dayTime.getEndTime()) || localDateTime.equals(dayTime.getEndTime()));
|
}).findFirst().orElse(null);
|
if (Func.isEmpty(productionCalendarDaytime)) {
|
return;
|
}
|
LocalDateTime shiftStartTime = productionCalendarDaytime.getStartTime();
|
LocalDateTime shiftEndTime = productionCalendarDaytime.getEndTime();
|
if (shiftStartTime.isBefore(startTime)) {
|
shiftStartTime = startTime;
|
}
|
if (shiftEndTime.isAfter(endTime)) {
|
shiftEndTime = endTime;
|
}
|
CalendarShiftTimeSlicesDTO calendarShiftTimeSlicesDTO = CalendarShiftTimeSlicesDTO.builder().shiftTimeType(productionCalendarDaytime.getShiftType().toString()).endTime(LocalDateTimeUtils.LocalDateTimeToDate(shiftEndTime)).startTime(LocalDateTimeUtils.LocalDateTimeToDate(shiftStartTime)).shiftIndex(productionCalendarDaytime.getShiftIndex()).shiftTimeType(productionCalendarDaytime.getShiftType().toString()).factoryDate(LocalDateTimeUtils.formatTimeLocalDate(productionCalendarDaytime.getCalendarDate(), DateConstant.PATTERN_DATE)).factoryMonth(productionCalendarDaytime.getMonth()).factoryWeek(productionCalendarDaytime.getWeek()).factoryYear(productionCalendarDaytime.getYear()).build();
|
timeSlicesDTOMap.put(Integer.valueOf(i), calendarShiftTimeSlicesDTO);
|
}
|
|
@Override // org.springblade.modules.cps.service.ICalendarService
|
public List<CalendarSimpleVO> getCalendarList(String tenantId) {
|
return list(Wrappers.<ProductionCalendar>query().lambda()
|
.eq(ProductionCalendar::getTenantId, tenantId))
|
.stream()
|
.map(productionCalendar -> {
|
CalendarSimpleVO calendarSimpleVO = new CalendarSimpleVO();
|
BeanUtils.copyProperties(productionCalendar, calendarSimpleVO);
|
return calendarSimpleVO;
|
}).collect(Collectors.toList());
|
/*
|
return (List) list((Wrapper) Wrappers.query().lambda().eq((v0) -> {
|
return v0.getTenantId();
|
}, tenantId)).stream().map(productionCalendar -> {
|
CalendarSimpleVO calendarSimpleVO = new CalendarSimpleVO();
|
BeanUtils.copyProperties(productionCalendar, calendarSimpleVO);
|
return calendarSimpleVO;
|
}).collect(Collectors.toList());
|
*/
|
}
|
|
@Override // org.springblade.modules.cps.service.ICalendarService
|
public List<CalendarShiftDetailDTO> getDaytimeList(String tenantId, String calendarCode, Integer year) {
|
List<CalendarShiftDetailDTO> result = new ArrayList<>();
|
Optional.ofNullable(getOne(new QueryWrapper<ProductionCalendar>().lambda()
|
.eq(ProductionCalendar::getCode, calendarCode)
|
.eq(ProductionCalendar::getTenantId, Long.valueOf(tenantId))
|
.eq(ProductionCalendar::getYear, year))).ifPresent(calendar -> {
|
List<ProductionCalendarDaytime> list = this.calendarDaytimeService.list(new QueryWrapper<ProductionCalendarDaytime>().lambda().eq(ProductionCalendarDaytime::getCalendarId, calendar.getId()).eq(ProductionCalendarDaytime::getCalendarDate, LocalDate.now()));
|
if (Func.isNotEmpty(list)) {
|
list.forEach(productionCalendarDaytime -> {
|
CalendarShiftDetailDTO calendarShiftDetailDTO = new CalendarShiftDetailDTO();
|
calendarShiftDetailDTO.setCode(calendarCode);
|
calendarShiftDetailDTO.setCalendarDay(DateUtil.format(productionCalendarDaytime.getCalendarDate(), DateConstant.PATTERN_DATE));
|
calendarShiftDetailDTO.setFactoryDate(DateUtil.format(productionCalendarDaytime.getCalendarDate(), DateConstant.PATTERN_DATE));
|
calendarShiftDetailDTO.setFactoryMonth(productionCalendarDaytime.getMonth());
|
calendarShiftDetailDTO.setFactoryWeek(productionCalendarDaytime.getWeek());
|
calendarShiftDetailDTO.setFactoryYear(productionCalendarDaytime.getYear());
|
calendarShiftDetailDTO.setShiftIndex(productionCalendarDaytime.getShiftIndex());
|
calendarShiftDetailDTO.setShiftTimeType(productionCalendarDaytime.getShiftType().toString());
|
calendarShiftDetailDTO.setStartTime(LocalDateTimeUtils.LocalDateTimeToDate(productionCalendarDaytime.getStartTime()));
|
result.add(calendarShiftDetailDTO);
|
});
|
}
|
});
|
return result;
|
}
|
|
@Override // org.springblade.modules.cps.service.ICalendarService
|
public List<CalendarCacheDTO> buildCalendarShift(CacheBuildDTO cacheBuildDTO) {
|
List<CalendarCacheDTO> calendarCacheDTOList = new LinkedList<>();
|
LocalDate targetDate = cacheBuildDTO.getTargetDate();
|
Set<String> tenantIds = cacheBuildDTO.getTenantIds();
|
|
List<ProductionCalendar> list = list(new QueryWrapper<ProductionCalendar>().lambda()
|
.in(ProductionCalendar::getTenantId, tenantIds)
|
.eq(ProductionCalendar::getYear, targetDate.getYear()));
|
/*
|
List<ProductionCalendar> list = list((Wrapper) ((LambdaQueryWrapper) new QueryWrapper().lambda().in((v0) -> {
|
return v0.getTenantId();
|
}, tenantIds)).eq((v0) -> {
|
return v0.getYear();
|
}, Integer.valueOf(targetDate.getYear())));
|
*/
|
if (Func.isNotEmpty(list)) {
|
Map<String, List<ProductionCalendar>> collect = list.stream().collect(Collectors.groupingBy(ProductionCalendar::getTenantId));
|
/*
|
Map<String, List<ProductionCalendar>> collect = (Map) list.stream().collect(Collectors.groupingBy((v0) -> {
|
return v0.getTenantId();
|
}));*/
|
|
collect.forEach((tenantId, productionList) -> {
|
productionList.forEach(productionCalendar -> {
|
log.info("处理的租户:{},处理的日历code:{}", tenantId, productionCalendar.getCode());
|
List<ProductionCalendarDaytime> dayTimeList = this.calendarDaytimeService.list(new QueryWrapper<ProductionCalendarDaytime>().lambda()
|
.eq(ProductionCalendarDaytime::getCalendarId, productionCalendar.getId())
|
.eq(ProductionCalendarDaytime::getCalendarDate, targetDate)
|
.orderByAsc(ProductionCalendarDaytime::getStartTime));
|
|
if (Func.isNotEmpty(dayTimeList)) {
|
CalendarCacheDTO calendarCacheDTO = CalendarCacheDTO.builder().tenantId(tenantId).calendarCode(productionCalendar.getCode()).factoryDate(DateUtil.formatDate(targetDate)).factoryMonth(dayTimeList.get(0).getMonth()).factoryWeek(dayTimeList.get(0).getWeek()).factoryYear(dayTimeList.get(0).getYear()).build();
|
List<ShiftCacheDTO> shiftCacheDTOList = dayTimeList.stream().map(dayTime -> {
|
return ShiftCacheDTO.builder().shiftIndex(dayTime.getShiftIndex()).shiftTimeType(dayTime.getShiftType()).startTime(Long.valueOf(dayTime.getStartTime().toInstant(ZoneOffset.of("+8")).toEpochMilli())).endTime(Long.valueOf(dayTime.getEndTime().toInstant(ZoneOffset.of("+8")).toEpochMilli())).build();
|
}).collect(Collectors.toList());
|
calendarCacheDTO.setShiftCacheDTOS(shiftCacheDTOList);
|
calendarCacheDTOList.add(calendarCacheDTO);
|
}
|
});
|
});
|
}
|
return calendarCacheDTOList;
|
}
|
|
@Override // org.springblade.modules.cps.service.ICalendarService
|
public List<CurShiftDTO> getCurShift(String tenantId, List<String> calendarCodeList) {
|
List<ProductionCalendar> list = list(new QueryWrapper<ProductionCalendar>().lambda()
|
.in(ProductionCalendar::getCode, calendarCodeList)
|
.eq(ProductionCalendar::getYear, LocalDateTimeUtils.getYear(LocalDate.now()))
|
.eq(ProductionCalendar::getTenantId, tenantId));
|
/*
|
List<ProductionCalendar> list = list((Wrapper) ((LambdaQueryWrapper) ((LambdaQueryWrapper) new QueryWrapper().lambda().in((v0) -> {
|
return v0.getCode();
|
}, calendarCodeList)).eq((v0) -> {
|
return v0.getYear();
|
}, LocalDateTimeUtils.getYear(LocalDate.now()))).eq((v0) -> {
|
return v0.getTenantId();
|
}, tenantId));*/
|
List<CurShiftDTO> curShiftDTOS = new ArrayList<>();
|
if (Func.isNotEmpty(list)) {
|
list.forEach(productionCalendar -> {
|
CurShiftDTO curShiftDTO = new CurShiftDTO();//ProductionCalendarDay::getCalendarDate
|
curShiftDTO.setCalendarCode(productionCalendar.getCode());
|
ProductionCalendarDay one = this.calendarDayService.getOne(new QueryWrapper<ProductionCalendarDay>().lambda()
|
.eq(ProductionCalendarDay::getCalendarId, productionCalendar.getId())
|
.eq(ProductionCalendarDay::getCalendarDate, LocalDate.now()));
|
if (Func.isNull(one)) {
|
curShiftDTO.setShiftIndex(-1);
|
} else {
|
ShiftVO shiftDetail = this.shiftModelService.getShiftDetail(one.getModelId());
|
shiftDetail.getShiftDetailVOList().forEach(shiftDetailVO -> {
|
Integer shiftStartTime = shiftDetailVO.getShiftStartTime();
|
Integer shiftEndTime = shiftDetailVO.getShiftEndTime();
|
LocalDateTime startTime = LocalDateTimeUtils.plus(LocalDate.now(), shiftStartTime.intValue(), ChronoUnit.MINUTES);
|
LocalDateTime endTime = LocalDateTimeUtils.plus(LocalDate.now(), shiftEndTime.intValue(), ChronoUnit.MINUTES);
|
if (LocalDateTime.now().isBefore(endTime) && LocalDateTime.now().isAfter(startTime)) {
|
curShiftDTO.setShiftIndex(shiftDetailVO.getShiftIndex());
|
curShiftDTO.setIndexName(shiftDetailVO.getIndexName());
|
}
|
});
|
if (curShiftDTO.getShiftIndex() == null) {
|
curShiftDTO.setShiftIndex(-1);
|
}
|
}
|
curShiftDTOS.add(curShiftDTO);
|
});
|
}
|
return curShiftDTOS;
|
}
|
|
@Override // org.springblade.modules.cps.service.ICalendarService
|
public Map<String, FactoryDayInfoDTO> getFactoryDayInfo(LocalDateTime date, String tenantId, List<String> calendarCodeList) {
|
List<FactoryDayInfoDTO> factoryDayInfoDTOList = new ArrayList<>();
|
Integer minute = Integer.valueOf((date.getHour() * 60) + date.getMinute());
|
DateTimeFormatter formatter = DateTimeFormatter.ofPattern(DateConstant.PATTERN_DATE);
|
String str = LocalDate.now().format(formatter);
|
calendarCodeList.forEach(calendarCode -> {
|
String redisKey = CommonUtil.getReallyCacheName(TimeSliceCache.CALENDAR_CACHE, TimeSliceCache.CALENDARS_CODE.concat(calendarCode).concat(":").concat(TimeSliceCache.MINUTE_POINT), str);
|
CalendarShiftTimeSlicesDTO calendarShiftTimeSlicesDTO = (CalendarShiftTimeSlicesDTO) this.bladeRedis.hGet(redisKey, minute);
|
if (Func.isNotEmpty(calendarShiftTimeSlicesDTO)) {
|
FactoryDayInfoDTO factoryDayInfoDTO = FactoryDayInfoDTO.builder().calendarCode(calendarCode).factoryDay(LocalDate.parse(calendarShiftTimeSlicesDTO.getFactoryDate(), formatter)).build();
|
factoryDayInfoDTOList.add(factoryDayInfoDTO);
|
}
|
});
|
if (Func.isEmpty(factoryDayInfoDTOList)) {
|
return new HashMap<>(16);
|
}
|
Map<String, Long> map = list(new QueryWrapper<ProductionCalendar>().lambda()
|
.eq(ProductionCalendar::getYear, Integer.valueOf(date.getYear()))
|
.in(ProductionCalendar::getCode, calendarCodeList)
|
.eq(ProductionCalendar::getTenantId, tenantId))
|
.stream()
|
.collect(Collectors.toMap(ProductionCalendar::getCode, ProductionCalendar::getId));
|
/*
|
Map<String, Long> map = (Map) list((Wrapper) ((LambdaQueryWrapper) ((LambdaQueryWrapper) new QueryWrapper().lambda().eq((v0) -> {
|
return v0.getYear();
|
}, Integer.valueOf(date.getYear()))).in((v0) -> {
|
return v0.getCode();
|
}, calendarCodeList)).eq((v0) -> {
|
return v0.getTenantId();
|
}, tenantId)).stream().collect(Collectors.toMap((v0) -> {
|
return v0.getCode();
|
}, (v0) -> {
|
return v0.getId();
|
}));*/
|
//ProductionCalendarDay::getCalendarId
|
return factoryDayInfoDTOList.stream().peek(fac -> {
|
Long id = map.get(fac.getCalendarCode());
|
ProductionCalendarDay productionCalendarDay = this.calendarDayService.getOne(new QueryWrapper<ProductionCalendarDay>().lambda()
|
.eq(ProductionCalendarDay::getCalendarDate, fac.getFactoryDay())
|
.eq(ProductionCalendarDay::getCalendarId, id));
|
if (Func.isNotEmpty(productionCalendarDay)) {
|
fac.setStartTime(productionCalendarDay.getStartTime());
|
fac.setEndTime(productionCalendarDay.getEndTime());
|
}
|
}).collect(Collectors.toMap(FactoryDayInfoDTO::getCalendarCode, v -> v));
|
}
|
|
@Override // org.springblade.modules.cps.service.ICalendarService
|
public ShiftSlicesDTO getShiftSlices(ShiftSlicesClientDTO shiftSlicesClientDTO) {
|
String tenantId = shiftSlicesClientDTO.getTenantId();
|
String calendarCode = shiftSlicesClientDTO.getCalendarCode();
|
Integer shiftIndex = shiftSlicesClientDTO.getShiftIndex();
|
LocalDate localDate = shiftSlicesClientDTO.getLocalDate();
|
ShiftSlicesDTO shiftSlicesDTO = new ShiftSlicesDTO();
|
Optional.ofNullable(this.shiftModelService.getShiftTime(tenantId, shiftIndex, localDate, calendarCode)).ifPresent(shiftDetail -> {
|
Integer shiftStartTime = shiftDetail.getShiftStartTime();
|
Integer shiftEndTime = shiftDetail.getShiftEndTime();
|
LocalDateTime start = LocalDateTime.of(localDate, LocalTime.of(0, 0, 0)).plus(shiftStartTime.intValue(), (TemporalUnit) ChronoUnit.MINUTES);
|
LocalDateTime end = LocalDateTime.of(localDate, LocalTime.of(0, 0, 0)).plus(shiftEndTime.intValue(), (TemporalUnit) ChronoUnit.MINUTES);
|
shiftSlicesDTO.setStartTime(start);
|
shiftSlicesDTO.setEndTime(end);
|
});
|
return shiftSlicesDTO;
|
}
|
|
@Override // org.springblade.modules.cps.service.ICalendarService
|
public List<ShiftSlicesCalendarCodeDTO> getShiftSlicesList(ShiftSlicesClientCalendarCodesDTO shiftSlicesClientCalendarCodesDTO) {
|
List<String> calendarCodes = shiftSlicesClientCalendarCodesDTO.getCalendarCodes();
|
ArrayList<ShiftSlicesCalendarCodeDTO> shiftSlicesCalendarCodeDTOList = new ArrayList<>();
|
calendarCodes.forEach(calendarCode -> {
|
ShiftSlicesClientDTO shiftSlicesClientDTO = new ShiftSlicesClientDTO();
|
shiftSlicesClientDTO.setShiftIndex(shiftSlicesClientCalendarCodesDTO.getShiftIndex());
|
shiftSlicesClientDTO.setCalendarCode(calendarCode);
|
shiftSlicesClientDTO.setTenantId(shiftSlicesClientCalendarCodesDTO.getTenantId());
|
shiftSlicesClientDTO.setLocalDate(shiftSlicesClientCalendarCodesDTO.getLocalDate());
|
ShiftSlicesDTO data = getShiftSlices(shiftSlicesClientDTO);
|
ShiftSlicesCalendarCodeDTO shiftSlicesCalendarCodeDTO = new ShiftSlicesCalendarCodeDTO();
|
shiftSlicesCalendarCodeDTO.setCalendarCode(calendarCode);
|
shiftSlicesCalendarCodeDTO.setStartTime(data.getStartTime());
|
shiftSlicesCalendarCodeDTO.setEndTime(data.getEndTime());
|
shiftSlicesCalendarCodeDTOList.add(shiftSlicesCalendarCodeDTO);
|
});
|
return shiftSlicesCalendarCodeDTOList;
|
}
|
|
@Override // org.springblade.modules.cps.service.ICalendarService
|
public Long getShiftTimeWithoutRest(String calendarCode) {
|
ProductionCalendar productionCalendar = getOne(Wrappers.<ProductionCalendar>lambdaQuery()
|
.eq(ProductionCalendar::getCode, calendarCode)
|
.eq(ProductionCalendar::getYear, Calendar.getInstance().get(1)));
|
/*
|
ProductionCalendar productionCalendar = (ProductionCalendar) getOne((Wrapper) ((LambdaQueryWrapper) Wrappers.lambdaQuery().eq((v0) -> {
|
return v0.getCode();
|
}, calendarCode)).eq((v0) -> {
|
return v0.getYear();
|
}, Integer.valueOf(Calendar.getInstance().get(1))));
|
*/
|
if (Func.isEmpty(productionCalendar)) {
|
return 0L;
|
}
|
List<ProductionCalendarDay> list = this.calendarDayService.list(Wrappers.<ProductionCalendarDay>lambdaQuery()
|
.eq(ProductionCalendarDay::getCalendarId, productionCalendar.getId()));
|
/*
|
List<ProductionCalendarDay> list = this.calendarDayService.list((Wrapper) Wrappers.lambdaQuery().eq((v0) -> {
|
return v0.getCalendarId();
|
}, productionCalendar.getId()));*/
|
List<Long> productionCalendarDayIds = list.stream().map((v0) -> {
|
return v0.getId();
|
}).collect(Collectors.toList());
|
|
LocalDate now = LocalDate.now();
|
List<ProductionCalendarDaytime> productionCalendarDaytimeList = this.calendarDaytimeService.list(Wrappers.<ProductionCalendarDaytime>lambdaQuery()
|
.in(ProductionCalendarDaytime::getCalendarDayId, productionCalendarDayIds)
|
.eq(ProductionCalendarDaytime::getShiftType, ProductionTimeConstant.WORK_TIME)
|
.eq(ProductionCalendarDaytime::getCalendarDate, now));
|
return Long.valueOf(productionCalendarDaytimeList.stream().mapToLong(productionCalendarDaytime -> {
|
return LocalDateTimeUtils.betweenTwoTime(productionCalendarDaytime.getStartTime(), productionCalendarDaytime.getEndTime(), ChronoUnit.SECONDS);
|
}).sum());
|
}
|
|
@Override // org.springblade.modules.cps.service.ICalendarService
|
public ShiftIndexNameVO getShiftIndexName() {
|
return this.shiftModelService.getShiftIndexName();
|
}
|
|
@Override // org.springblade.modules.cps.service.ICalendarService
|
public String getShiftIndexNameByCodeAndYear(String calendarCode, CalendarShiftTimeSlicesDTO calendarShiftTimeSlicesDTO) {
|
return this.baseMapper.getShiftIndexNameByCodeAndYear(calendarCode, calendarShiftTimeSlicesDTO.getFactoryYear(), calendarShiftTimeSlicesDTO.getFactoryDate(), calendarShiftTimeSlicesDTO.getShiftIndex(), AuthUtil.getTenantId());
|
}
|
|
@Override // org.springblade.modules.cps.service.ICalendarService
|
public String expireCalendarInfo() {
|
String code = this.baseMapper.expireCalendarInfo(LocalDate.now().getYear());
|
LocalDate now = LocalDate.now();
|
LocalDate lastDayOfYear = LocalDate.now().with(TemporalAdjusters.lastDayOfYear());
|
Integer difference = LocalDateTimeUtils.getDifference(now.minusDays(1L), lastDayOfYear);
|
log.info("当前时间:[{}],最后一天:[{}]", now, lastDayOfYear);
|
if (difference.intValue() <= ProductionTimeConstant.SEVEN_DAYS.intValue()) {
|
return String.format("您的【%s】生产日历将在【%s】天后过期,为了能正常使用,请及时创建新的日历(如果您想更便捷使用,建议创建多年份日历)", code, difference);
|
}
|
return null;
|
}
|
|
@Override // org.springblade.modules.cps.service.ICalendarService
|
@Transactional(rollbackFor = {Exception.class})
|
public Boolean deleteCalendar(Long id) {
|
//Workstation::getCalendarCodeWaiting
|
Optional.ofNullable(getById(id)).ifPresent(calendar -> {
|
List<Workstation> list = this.workstationService.list(new QueryWrapper<Workstation>().lambda()
|
.eq(Workstation::getCalendarCode, calendar.getCode()).eq(Workstation::getStatus, CommonConstant.ENABLE).or()
|
.eq(Workstation::getCalendarCodeWaiting, calendar.getCode()));
|
if (Func.isNotEmpty(list)) {
|
throw new ServiceException(MessageUtils.message("calendar.has.be.used", new Object[0]));
|
}
|
removeById(id);
|
this.calendarDayService.remove(Wrappers.<ProductionCalendarDay>lambdaQuery().eq(ProductionCalendarDay::getCalendarId, id));
|
this.calendarDaytimeService.remove(Wrappers.<ProductionCalendarDaytime>lambdaQuery().eq(ProductionCalendarDaytime::getCalendarId, id));
|
});
|
return true;
|
}
|
|
@Override // org.springblade.modules.cps.service.ICalendarService
|
public Long getShiftModelByFactoryDay(String calendarCode, LocalDate factoryDay) {
|
return this.baseMapper.getShiftModelByFactoryDay(calendarCode, Integer.valueOf(LocalDate.now().getYear()), factoryDay);
|
}
|
|
@Override // org.springblade.modules.cps.service.ICalendarService
|
public List<ShiftTimeDetailVO> getShiftDetailDates(String calendarCode, List<LocalDate> dates) {
|
|
//ProductionCalendar
|
QueryWrapper<Object> wrapper = Wrappers.<Object>query()
|
.eq("bpc.is_deleted", 0)
|
.eq("bpcd.is_deleted", 0)
|
.eq("bpc.code", calendarCode)
|
.nested(q -> q.in("bpcd.calendar_date", dates))
|
.orderByAsc("calendar_date", "shift_index");
|
return this.baseMapper.getShiftDetailDates(wrapper);
|
/*
|
return this.baseMapper.getShiftDetailDates((QueryWrapper) ((QueryWrapper) ((QueryWrapper) ((QueryWrapper) ((QueryWrapper) Wrappers.query().eq("bpc.is_deleted", 0)).eq("bpcd.is_deleted", 0)).eq("bpc.code", calendarCode)).nested(q -> {
|
QueryWrapper queryWrapper = (QueryWrapper) q.in("bpcd.calendar_date", dates);
|
})).orderByAsc("calendar_date", new String[]{"shift_index"}));*/
|
}
|
|
@Override // org.springblade.modules.cps.service.ICalendarService
|
public List<CalendarShiftDTO> getTimeShiftAll(String calendarCode, Date startTime, Date endTime) {
|
|
QueryWrapper<Object> wrapper = Wrappers.query().eq("bpc.is_deleted", 0)
|
.eq("bpcd.is_deleted", 0)
|
.ne("bsd.shift_index", ProductionTimeConstant.OUT_OF_SHIFT_TIME)
|
.nested(q -> q.between("bpcd.calendar_date", DateUtil.formatDate(DateUtil.minusDays(startTime, 1L)), DateUtil.formatDate(DateUtil.plusDays(endTime, 1L)))
|
.eq("bpc.code", calendarCode)).orderByAsc("calendar_date", "shift_index" );
|
return this.baseMapper.getTimeShiftAll(wrapper);
|
/*
|
return this.baseMapper.getTimeShiftAll(Wrappers.query().eq("bpc.is_deleted", 0)
|
.eq("bpcd.is_deleted", 0))
|
.ne("bsd.shift_index", ProductionTimeConstant.OUT_OF_SHIFT_TIME)
|
.nested(q -> {
|
QueryWrapper queryWrapper = q.between("bpcd.calendar_date", DateUtil.formatDate(DateUtil.minusDays(startTime, 1L)), DateUtil.formatDate(DateUtil.plusDays(endTime, 1L)));
|
})).eq("bpc.code", calendarCode)
|
.orderByAsc("calendar_date", new String[]{"shift_index"}));
|
*/
|
}
|
|
@Override // org.springblade.modules.cps.service.ICalendarService
|
public List<ShiftIndexInfoDTO> getWorkstationShiftIndexListByDate(Long workstationId, LocalDate localDate) {
|
List<ShiftIndexInfoDTO> result = Lists.newArrayList();
|
|
Workstation workstation = (Workstation)this.workstationService.getOne(Wrappers.<Workstation>lambdaQuery()
|
.eq(Workstation::getId, workstationId)
|
.eq(Workstation::getType, WorkstationTypeEnum.MACHINE.getCode())
|
.isNotNull(Workstation::getCalendarCode));
|
/*
|
Workstation workstation = (Workstation) this.workstationService.getOne((Wrapper) ((LambdaQueryWrapper) ((LambdaQueryWrapper) Wrappers.lambdaQuery().eq((v0) -> {
|
return v0.getId();
|
}, workstationId)).eq((v0) -> {
|
return v0.getType();
|
}, WorkstationTypeEnum.MACHINE.getCode())).isNotNull((v0) -> {
|
return v0.getCalendarCode();
|
}));*/
|
if (Func.isNotEmpty(workstation)) {
|
List<ShiftDetailInfoDTO> shiftIndexList = getWorkstationShiftIndexListByDate(workstation.getCalendarCode(), Integer.valueOf(localDate.getYear()), LocalDateTimeUtils.formatTimeLocalDate(localDate, DateConstant.PATTERN_DATE));
|
shiftIndexList.forEach(x -> {
|
ShiftIndexInfoDTO shiftIndexInfoDTO = new ShiftIndexInfoDTO();
|
if (x.getCalendarDate().isBefore(localDate)) {
|
if (x.getShiftStartTime().intValue() < CommonConstant.MINUTES_OF_DAY.intValue() && x.getShiftEndTime().intValue() > CommonConstant.MINUTES_OF_DAY.intValue()) {
|
shiftIndexInfoDTO.setShiftIndex(x.getShiftIndex());
|
shiftIndexInfoDTO.setDateShiftIndex(DateUtil.format(x.getCalendarDate(), "yyyyMMdd") + "/" + x.getShiftIndex());
|
shiftIndexInfoDTO.setDateShiftIndexName(DateUtil.format(x.getCalendarDate(), "MM/dd") + x.getIndexName());
|
result.add(shiftIndexInfoDTO);
|
return;
|
}
|
return;
|
}
|
shiftIndexInfoDTO.setShiftIndex(x.getShiftIndex());
|
shiftIndexInfoDTO.setDateShiftIndex(DateUtil.format(x.getCalendarDate(), "yyyyMMdd") + "/" + x.getShiftIndex());
|
shiftIndexInfoDTO.setDateShiftIndexName(DateUtil.format(x.getCalendarDate(), "MM/dd") + x.getIndexName());
|
result.add(shiftIndexInfoDTO);
|
});
|
}
|
return result;
|
}
|
|
private List<ShiftDetailInfoDTO> getWorkstationShiftIndexListByDate(String calendarCode, Integer year, String date) {
|
Integer maxShiftIndex;
|
List<ShiftDetailInfoDTO> workstationShiftIndexListByDate = this.baseMapper.getWorkstationShiftIndexListByDate(calendarCode, year, date);
|
String maxShiftIndexStr = ParamCache.getValue("system.shift.max");
|
if (Func.isEmpty(maxShiftIndexStr)) {
|
maxShiftIndex = CalendarConstant.DEFAULT_MAX_SHIFT_INDEX;
|
} else {
|
maxShiftIndex = Integer.valueOf(maxShiftIndexStr);
|
}
|
Integer num = maxShiftIndex;
|
workstationShiftIndexListByDate.removeIf(s -> {
|
return s.getShiftIndex().intValue() > num.intValue();
|
});
|
return workstationShiftIndexListByDate;
|
}
|
|
@Override // org.springblade.modules.cps.service.ICalendarService
|
public Boolean associateWorkstation(CalendarAssociateWorkstationVO calendarAssociateWorkstationVO) {
|
return this.workstationService.update(Wrappers.<Workstation>lambdaUpdate()
|
.set(Workstation::getCalendarCodeWaiting, calendarAssociateWorkstationVO.getCalendarCode())
|
.in(Workstation::getId, calendarAssociateWorkstationVO.getWorkstationIdList()));
|
/*
|
return Boolean.valueOf(this.workstationService.update((Wrapper) ((LambdaUpdateWrapper) Wrappers.lambdaUpdate().set((v0) -> {
|
return v0.getCalendarCodeWaiting();
|
}, calendarAssociateWorkstationVO.getCalendarCode())).in((v0) -> {
|
return v0.getId();
|
}, calendarAssociateWorkstationVO.getWorkstationIdList())));*/
|
}
|
|
@Override // org.springblade.modules.cps.service.ICalendarService
|
public List<ShiftIndexNameDTO> queryShiftIndexName(String calendarCode, Integer year, String day) {
|
Integer maxShiftIndex;
|
List<ShiftIndexNameDTO> shiftIndexNameDTOList = this.baseMapper.queryShiftIndexName(calendarCode, year, day);
|
String maxShiftIndexStr = ParamCache.getValue("system.shift.max");
|
if (Func.isEmpty(maxShiftIndexStr)) {
|
maxShiftIndex = CalendarConstant.DEFAULT_MAX_SHIFT_INDEX;
|
} else {
|
maxShiftIndex = Integer.valueOf(maxShiftIndexStr);
|
}
|
Integer num = maxShiftIndex;
|
shiftIndexNameDTOList.removeIf(s -> {
|
return s.getShiftIndex().intValue() > num.intValue();
|
});
|
return shiftIndexNameDTOList;
|
}
|
|
@Override // org.springblade.modules.cps.service.ICalendarService
|
public List<ShiftInfoDTO> listShiftInfo(List<Long> workstationIdList, LocalDate startDay, LocalDate endDay) {
|
Integer maxShiftIndex;
|
List<ShiftInfoDTO> shiftInfoDTOList = this.baseMapper.listShiftInfo(workstationIdList, startDay, endDay);
|
String maxShiftIndexStr = ParamCache.getValue("system.shift.max");
|
if (Func.isEmpty(maxShiftIndexStr)) {
|
maxShiftIndex = CalendarConstant.DEFAULT_MAX_SHIFT_INDEX;
|
} else {
|
maxShiftIndex = Integer.valueOf(maxShiftIndexStr);
|
}
|
Integer num = maxShiftIndex;
|
shiftInfoDTOList.removeIf(s -> {
|
return s.getShiftIndex().intValue() > num.intValue();
|
});
|
return shiftInfoDTOList;
|
}
|
}
|