yangys
2024-10-25 9faa74e1912022dc6e54c3e93426946876b5d83a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package com.qianwen.mdc.collect.service;
 
import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import java.lang.invoke.SerializedLambda;
import java.time.Instant;
import java.time.LocalDate;
import java.time.ZoneOffset;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import com.qianwen.core.mp.base.BaseServiceImpl;
import com.qianwen.core.tool.utils.Func;
import com.qianwen.mdc.collect.constants.CommonConstant;
import com.qianwen.mdc.collect.dto.CalendarShiftInfoDTO;
import com.qianwen.mdc.collect.entity.mgr.Workstation;
import com.qianwen.mdc.collect.mapper.mgr.CalendarMapper;
import com.qianwen.mdc.collect.mapper.mgr.WorkstationMapper;
import com.qianwen.mdc.collect.utils.LocalDateTimeUtils;
 
import org.springframework.beans.factory.annotation.Autowired;
 
import org.springframework.stereotype.Service;
 
@Service
public class WorkstationService extends BaseServiceImpl<WorkstationMapper, Workstation>{
    @Autowired
    private CalendarMapper calendarMapper;
    //BaseEntity a;
    /*
 
    @Override
    public void updateWorkStationCalendar() {
        List<Workstation> list = list((Wrapper) new QueryWrapper().lambda().isNotNull((v0) -> {
            return v0.getCalendarCodeWaiting();
        }));
        List<Workstation> workstationList = new ArrayList<>();
        if (Func.isNotEmpty(list)) {
            list.stream().filter(workStation -> {
                return Func.isNotEmpty(workStation.getCalendarCodeWaiting());
            }).forEach(workStation2 -> {
                workStation2.setCalendarCode(workStation2.getCalendarCodeWaiting());
                workStation2.setCalendarCodeWaiting("");
                workstationList.add(workStation2);
            });
        }
        updateBatchById(workstationList);
        WorkstationCache.clearWorkStationCache();
    }
*/
    
    public CalendarShiftInfoDTO getCalendarShiftInfoForWorkstation(Long workstationId, Date date) {
        Workstation workstationInfo = getById(workstationId);
        CalendarShiftInfoDTO result = null;
        if (Func.isNotEmpty(workstationInfo) && !"#default#".equals(workstationInfo.getCalendarCode())) {
            List<CalendarShiftInfoDTO> calendarShiftInfoDTOList = this.calendarMapper.getCalendarShiftInfoToday(workstationInfo.getCalendarCode(), DateUtil.formatDate(date));
            if (Func.isNotEmpty(calendarShiftInfoDTOList)) {
                CalendarShiftInfoDTO relatedShift = calendarShiftInfoDTOList.stream().filter(x -> {
                    return x.getStartTime().getTime() <= date.getTime() && x.getEndTime().getTime() >= date.getTime();
                }).findFirst().orElse(null);
                if (Func.isNotEmpty(relatedShift)) {
                    result.setCode(relatedShift.getCode());
                    result.setFactoryDate(relatedShift.getFactoryDate()).setFactoryYear(relatedShift.getFactoryYear()).setFactoryWeek(relatedShift.getFactoryWeek()).setFactoryMonth(relatedShift.getFactoryMonth()).setShiftIndex(relatedShift.getShiftIndex()).setShiftTimeType(result.getShiftTimeType());
                }
            }
        }
        if (Func.isEmpty((Object) null)) {
            result = new CalendarShiftInfoDTO();
            LocalDate localDate = Instant.ofEpochMilli(date.getTime()).atZone(ZoneOffset.systemDefault()).toLocalDate();
            result.setCode("#default#");
            result.setFactoryDate(DatePattern.PURE_DATE_FORMAT.format(date)).setFactoryYear(Integer.valueOf(DateUtil.year(date))).setFactoryWeek(LocalDateTimeUtils.getWeek(localDate)).setFactoryMonth(Integer.valueOf(DateUtil.month(date) + 1)).setShiftIndex(CommonConstant.DEFAULT_SHIFT_INDEX).setShiftTimeType(CommonConstant.DEFAULT_SHIFT_TYPE);
        }
        return result;
    }
    
}