yangys
2024-04-18 85bb45834b1a2fd993d9f8653c48d14efc12a59e
smart-man-boot/src/main/java/com/qianwen/smartman/modules/cps/service/impl/CalendarServiceImpl.java
@@ -1,16 +1,5 @@
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;
@@ -21,7 +10,6 @@
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;
@@ -32,10 +20,27 @@
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
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;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
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 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.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;
@@ -44,12 +49,6 @@
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;
@@ -92,15 +91,11 @@
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;
import cn.hutool.core.lang.Snowflake;
import cn.hutool.core.util.IdUtil;
@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
@@ -115,7 +110,7 @@
    @Autowired
    private BladeRedis bladeRedis;
    @Override // org.springblade.modules.cps.service.ICalendarService
    @Override
    @Transactional(rollbackFor = {Exception.class})
    public ProductionCalendar saveCalendar(CalendarSaveVO calendarSaveVO) {
        checkCalendar(calendarSaveVO, AuthUtil.getTenantId());
@@ -125,7 +120,7 @@
        return productionCalendar;
    }
    @Override // org.springblade.modules.cps.service.ICalendarService
    @Override
    public ProductionCalendar saveYearCalendar(CalendarSaveVO calendarSaveVO) {
        checkCalendar(calendarSaveVO, AuthUtil.getTenantId());
        ProductionCalendar productionCalendar = new ProductionCalendar();
@@ -135,7 +130,7 @@
        return productionCalendar;
    }
    @Override // org.springblade.modules.cps.service.ICalendarService
    @Override
    public ProductionCalendar updateCalendar(CalendarUpdateVO calendarUpdateVO) {
        this.calendarDayService.deleteByCalendarId(calendarUpdateVO.getId());
        this.calendarDaytimeService.deleteByCalendarId(calendarUpdateVO.getId());
@@ -150,19 +145,19 @@
        Integer year = productionCalendar.getYear();
        LocalDate queryStartDay = LocalDate.of(year.intValue(), 1, 1);
        Long calendarId = productionCalendar.getId();
        Set<LocalDate> dateList = (Set) dateDTOList.stream().filter(c -> {
        Set<LocalDate> dateList = 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 -> {
        Set<LocalDate> offDay = 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) -> {
        List<Long> modelIds =  dateDTOList.stream().map((v0) -> {
            return v0.getModelId();
        }).distinct().collect(Collectors.toList());
        Map<Long, ShiftVO> shiftDetailMap = this.shiftModelService.getShiftDetail(modelIds);
@@ -222,7 +217,7 @@
    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) -> {
        List<ShiftDetailVO> collect = shiftDetail.getShiftDetailVOList().stream().sorted(Comparator.comparing((v0) -> {
            return v0.getShiftStartTime();
        })).collect(Collectors.toList());
        for (int i = 0; i < collect.size(); i++) {
@@ -231,7 +226,7 @@
            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) -> {
                List<ShiftRestTimeVO> shiftRestTimeVOList = 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);
@@ -249,19 +244,19 @@
        Long calendarId = calenadar.getId();
        Integer year = calenadar.getYear();
        Integer currentYear = Integer.valueOf(LocalDate.now().getYear());
        Set<LocalDate> dateList = (Set) dateDTOList.stream().filter(c -> {
        Set<LocalDate> dateList = 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 -> {
        Set<LocalDate> offDay = 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) -> {
        List<Long> modelIds = dateDTOList.stream().map((v0) -> {
            return v0.getModelId();
        }).distinct().collect(Collectors.toList());
        Map<Long, ShiftVO> shiftDetailMap = this.shiftModelService.getShiftDetail(modelIds);
@@ -526,7 +521,7 @@
            productionCalendarDaytimeList.addAll(curProductionCalendarDayTimeList);
            return;
        }
        List<ProductionCalendarDaytime> filterList = (List) curProductionCalendarDayTimeList.stream().filter(item -> {
        List<ProductionCalendarDaytime> filterList = curProductionCalendarDayTimeList.stream().filter(item -> {
            return item.getStartTime().isBefore(nextStartTime);
        }).sorted(Comparator.comparing((v0) -> {
            return v0.getStartTime();
@@ -637,7 +632,7 @@
        });
    }
    @Override // org.springblade.modules.cps.service.ICalendarService
    @Override
    public CalendarVO getCalendar(Long calendarId) {
        CalendarVO calendarDetail = this.baseMapper.getCalendarDetail(calendarId);
        List<CalendarDayVO> otherCalendarDayVOList = new ArrayList<>();
@@ -693,7 +688,7 @@
    private void entityToVo(List<CalendarDayVO> otherCalendarDayVOList, List<ProductionCalendarDay> list) {
        if (Func.isNotEmpty(list)) {
            otherCalendarDayVOList.addAll((Collection) list.stream().map(productionCalendarDay -> {
            otherCalendarDayVOList.addAll(list.stream().map(productionCalendarDay -> {
                CalendarDayVO calendarDayVO = new CalendarDayVO();
                BeanUtils.copyProperties(productionCalendarDay, calendarDayVO);
                return calendarDayVO;
@@ -701,7 +696,7 @@
        }
    }
    @Override // org.springblade.modules.cps.service.ICalendarService
    @Override
    @Transactional(rollbackFor = {Exception.class})
    public ProductionCalendar copyCalendar(CalendarCopyVO calendarCopyVO) {
        CalendarSaveVO calendarSaveVO = new CalendarSaveVO();
@@ -735,19 +730,19 @@
    private void saveYearCalendarDayTime(List<CalendarDateDTO> dateDTOList, ProductionCalendar productionCalendar) {
        Integer year = productionCalendar.getYear();
        Long calendarId = productionCalendar.getId();
        Set<LocalDate> dateList = (Set) dateDTOList.stream().filter(c -> {
        Set<LocalDate> dateList = 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 -> {
        Set<LocalDate> offDay = 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) -> {
        List<Long> modelIds = dateDTOList.stream().map((v0) -> {
            return v0.getModelId();
        }).distinct().collect(Collectors.toList());
        Map<Long, ShiftVO> shiftDetailMap = this.shiftModelService.getShiftDetail(modelIds);
@@ -793,7 +788,7 @@
        }
    }
    @Override // org.springblade.modules.cps.service.ICalendarService
    @Override
    public List<TimestampToProductionTimeCacheDto> buildProductionTimeCache(CacheBuildDTO cacheBuildDTO) {
        LocalDate targetDate = cacheBuildDTO.getTargetDate();
        Set<String> tenantIds = cacheBuildDTO.getTenantIds();
@@ -889,7 +884,7 @@
        timeSlicesDTOMap.put(Integer.valueOf(i), calendarShiftTimeSlicesDTO);
    }
    @Override // org.springblade.modules.cps.service.ICalendarService
    @Override
    public List<CalendarSimpleVO> getCalendarList(String tenantId) {
       return list(Wrappers.<ProductionCalendar>query().lambda()
               .eq(ProductionCalendar::getTenantId, tenantId))
@@ -910,7 +905,7 @@
        */
    }
    @Override // org.springblade.modules.cps.service.ICalendarService
    @Override
    public List<CalendarShiftDetailDTO> getDaytimeList(String tenantId, String calendarCode, Integer year) {
        List<CalendarShiftDetailDTO> result = new ArrayList<>();
        Optional.ofNullable(getOne(new QueryWrapper<ProductionCalendar>().lambda()
@@ -937,7 +932,7 @@
        return result;
    }
    @Override // org.springblade.modules.cps.service.ICalendarService
    @Override
    public List<CalendarCacheDTO> buildCalendarShift(CacheBuildDTO cacheBuildDTO) {
        List<CalendarCacheDTO> calendarCacheDTOList = new LinkedList<>();
        LocalDate targetDate = cacheBuildDTO.getTargetDate();
@@ -982,7 +977,7 @@
        return calendarCacheDTOList;
    }
    @Override // org.springblade.modules.cps.service.ICalendarService
    @Override
    public List<CurShiftDTO> getCurShift(String tenantId, List<String> calendarCodeList) {
       List<ProductionCalendar> list = list(new QueryWrapper<ProductionCalendar>().lambda()
               .in(ProductionCalendar::getCode, calendarCodeList)
@@ -1028,7 +1023,7 @@
        return curShiftDTOS;
    }
    @Override // org.springblade.modules.cps.service.ICalendarService
    @Override
    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());
@@ -1076,7 +1071,7 @@
        }).collect(Collectors.toMap(FactoryDayInfoDTO::getCalendarCode, v -> v));
    }
    @Override // org.springblade.modules.cps.service.ICalendarService
    @Override
    public ShiftSlicesDTO getShiftSlices(ShiftSlicesClientDTO shiftSlicesClientDTO) {
        String tenantId = shiftSlicesClientDTO.getTenantId();
        String calendarCode = shiftSlicesClientDTO.getCalendarCode();
@@ -1094,7 +1089,7 @@
        return shiftSlicesDTO;
    }
    @Override // org.springblade.modules.cps.service.ICalendarService
    @Override
    public List<ShiftSlicesCalendarCodeDTO> getShiftSlicesList(ShiftSlicesClientCalendarCodesDTO shiftSlicesClientCalendarCodesDTO) {
        List<String> calendarCodes = shiftSlicesClientCalendarCodesDTO.getCalendarCodes();
        ArrayList<ShiftSlicesCalendarCodeDTO> shiftSlicesCalendarCodeDTOList = new ArrayList<>();
@@ -1114,7 +1109,7 @@
        return shiftSlicesCalendarCodeDTOList;
    }
    @Override // org.springblade.modules.cps.service.ICalendarService
    @Override
    public Long getShiftTimeWithoutRest(String calendarCode) {
       ProductionCalendar productionCalendar = getOne(Wrappers.<ProductionCalendar>lambdaQuery()
             .eq(ProductionCalendar::getCode, calendarCode)
@@ -1149,17 +1144,17 @@
        }).sum());
    }
    @Override // org.springblade.modules.cps.service.ICalendarService
    @Override
    public ShiftIndexNameVO getShiftIndexName() {
        return this.shiftModelService.getShiftIndexName();
    }
    @Override // org.springblade.modules.cps.service.ICalendarService
    @Override
    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
    @Override
    public String expireCalendarInfo() {
        String code = this.baseMapper.expireCalendarInfo(LocalDate.now().getYear());
        LocalDate now = LocalDate.now();
@@ -1172,7 +1167,7 @@
        return null;
    }
    @Override // org.springblade.modules.cps.service.ICalendarService
    @Override
    @Transactional(rollbackFor = {Exception.class})
    public Boolean deleteCalendar(Long id) {
       //Workstation::getCalendarCodeWaiting
@@ -1190,12 +1185,12 @@
        return true;
    }
    @Override // org.springblade.modules.cps.service.ICalendarService
    @Override
    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
    @Override
    public List<ShiftTimeDetailVO> getShiftDetailDates(String calendarCode, List<LocalDate> dates) {
       
       //ProductionCalendar
@@ -1212,7 +1207,7 @@
        })).orderByAsc("calendar_date", new String[]{"shift_index"}));*/
    }
    @Override // org.springblade.modules.cps.service.ICalendarService
    @Override
    public List<CalendarShiftDTO> getTimeShiftAll(String calendarCode, Date startTime, Date endTime) {
       
       QueryWrapper<Object> wrapper = Wrappers.query().eq("bpc.is_deleted", 0)
@@ -1232,7 +1227,7 @@
      */
    }
    @Override // org.springblade.modules.cps.service.ICalendarService
    @Override
    public List<ShiftIndexInfoDTO> getWorkstationShiftIndexListByDate(Long workstationId, LocalDate localDate) {
        List<ShiftIndexInfoDTO> result = Lists.newArrayList();
        
@@ -1287,7 +1282,7 @@
        return workstationShiftIndexListByDate;
    }
    @Override // org.springblade.modules.cps.service.ICalendarService
    @Override
    public Boolean associateWorkstation(CalendarAssociateWorkstationVO calendarAssociateWorkstationVO) {
       return this.workstationService.update(Wrappers.<Workstation>lambdaUpdate()
                 .set(Workstation::getCalendarCodeWaiting, calendarAssociateWorkstationVO.getCalendarCode())
@@ -1300,7 +1295,7 @@
        }, calendarAssociateWorkstationVO.getWorkstationIdList())));*/
    }
    @Override // org.springblade.modules.cps.service.ICalendarService
    @Override
    public List<ShiftIndexNameDTO> queryShiftIndexName(String calendarCode, Integer year, String day) {
        Integer maxShiftIndex;
        List<ShiftIndexNameDTO> shiftIndexNameDTOList = this.baseMapper.queryShiftIndexName(calendarCode, year, day);
@@ -1317,7 +1312,7 @@
        return shiftIndexNameDTOList;
    }
    @Override // org.springblade.modules.cps.service.ICalendarService
    @Override
    public List<ShiftInfoDTO> listShiftInfo(List<Long> workstationIdList, LocalDate startDay, LocalDate endDay) {
        Integer maxShiftIndex;
        List<ShiftInfoDTO> shiftInfoDTOList = this.baseMapper.listShiftInfo(workstationIdList, startDay, endDay);