yangys
2024-03-28 23a939ed820ee32f9a4309f9c81b7bab5a566f30
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
package com.qianwen.smartman.modules.cps.service.impl;
 
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.extension.service.impl.ServiceImpl;
import java.lang.invoke.SerializedLambda;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors;
import com.qianwen.smartman.common.constant.ProductionTimeConstant;
import com.qianwen.smartman.common.utils.MessageUtils;
import com.qianwen.smartman.common.utils.ProductionTimeUtils;
import com.qianwen.core.log.exception.ServiceException;
import com.qianwen.core.secure.utils.AuthUtil;
import com.qianwen.core.tool.utils.CollectionUtil;
import com.qianwen.core.tool.utils.Func;
import com.qianwen.core.tool.utils.StringUtil;
import com.qianwen.smartman.modules.cps.dto.KeyNameDTO;
import com.qianwen.smartman.modules.cps.dto.ShiftDetailDTO;
import com.qianwen.smartman.modules.cps.dto.ShiftRestTimeDTO;
import com.qianwen.smartman.modules.cps.entity.ShiftDetail;
import com.qianwen.smartman.modules.cps.entity.ShiftModel;
import com.qianwen.smartman.modules.cps.mapper.ShiftModelMapper;
import com.qianwen.smartman.modules.cps.service.ICalendarDayService;
import com.qianwen.smartman.modules.cps.service.IShiftDetailService;
import com.qianwen.smartman.modules.cps.service.IShiftModelService;
import com.qianwen.smartman.modules.cps.service.IShiftRestTimeService;
import com.qianwen.smartman.modules.cps.vo.ShiftDetailVO;
import com.qianwen.smartman.modules.cps.vo.ShiftIndexNameVO;
import com.qianwen.smartman.modules.cps.vo.ShiftSaveVO;
import com.qianwen.smartman.modules.cps.vo.ShiftUpdateBasicVO;
import com.qianwen.smartman.modules.cps.vo.ShiftUpdateVO;
import com.qianwen.smartman.modules.cps.vo.ShiftVO;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
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/ShiftModelServiceImpl.class */
public class ShiftModelServiceImpl extends ServiceImpl<ShiftModelMapper, ShiftModel> implements IShiftModelService {
    @Autowired
    private IShiftDetailService shiftDetailService;
    @Autowired
    private IShiftRestTimeService shiftRestTimeService;
    @Autowired
    private ICalendarDayService calendarDayService;
    @Autowired
    private ShiftModelMapper shiftModelMapper;
 
    private static /* synthetic */ Object $deserializeLambda$(SerializedLambda lambda) {
        String implMethodName = lambda.getImplMethodName();
        boolean z = true;
        switch (implMethodName.hashCode()) {
            case -2031150610:
                if (implMethodName.equals("getModelId")) {
                    z = false;
                    break;
                }
                break;
            case -75622813:
                if (implMethodName.equals("getCode")) {
                    z = true;
                    break;
                }
                break;
            case 771206363:
                if (implMethodName.equals("getTenantId")) {
                    z = true;
                    break;
                }
                break;
        }
        switch (z) {
            case false:
                if (lambda.getImplMethodKind() == 5 && lambda.getFunctionalInterfaceClass().equals("com/baomidou/mybatisplus/core/toolkit/support/SFunction") && lambda.getFunctionalInterfaceMethodName().equals("apply") && lambda.getFunctionalInterfaceMethodSignature().equals("(Ljava/lang/Object;)Ljava/lang/Object;") && lambda.getImplClass().equals("org/springblade/modules/cps/entity/ProductionCalendarDay") && lambda.getImplMethodSignature().equals("()Ljava/lang/Long;")) {
                    return (v0) -> {
                        return v0.getModelId();
                    };
                }
                if (lambda.getImplMethodKind() == 5 && lambda.getFunctionalInterfaceClass().equals("com/baomidou/mybatisplus/core/toolkit/support/SFunction") && lambda.getFunctionalInterfaceMethodName().equals("apply") && lambda.getFunctionalInterfaceMethodSignature().equals("(Ljava/lang/Object;)Ljava/lang/Object;") && lambda.getImplClass().equals("org/springblade/modules/cps/entity/ProductionCalendarDay") && lambda.getImplMethodSignature().equals("()Ljava/lang/Long;")) {
                    return (v0) -> {
                        return v0.getModelId();
                    };
                }
                if (lambda.getImplMethodKind() == 5 && lambda.getFunctionalInterfaceClass().equals("com/baomidou/mybatisplus/core/toolkit/support/SFunction") && lambda.getFunctionalInterfaceMethodName().equals("apply") && lambda.getFunctionalInterfaceMethodSignature().equals("(Ljava/lang/Object;)Ljava/lang/Object;") && lambda.getImplClass().equals("org/springblade/modules/cps/entity/ShiftRestTime") && lambda.getImplMethodSignature().equals("()Ljava/lang/Long;")) {
                    return (v0) -> {
                        return v0.getModelId();
                    };
                }
                if (lambda.getImplMethodKind() == 5 && lambda.getFunctionalInterfaceClass().equals("com/baomidou/mybatisplus/core/toolkit/support/SFunction") && lambda.getFunctionalInterfaceMethodName().equals("apply") && lambda.getFunctionalInterfaceMethodSignature().equals("(Ljava/lang/Object;)Ljava/lang/Object;") && lambda.getImplClass().equals("org/springblade/modules/cps/entity/ShiftDetail") && lambda.getImplMethodSignature().equals("()Ljava/lang/Long;")) {
                    return (v0) -> {
                        return v0.getModelId();
                    };
                }
                if (lambda.getImplMethodKind() == 5 && lambda.getFunctionalInterfaceClass().equals("com/baomidou/mybatisplus/core/toolkit/support/SFunction") && lambda.getFunctionalInterfaceMethodName().equals("apply") && lambda.getFunctionalInterfaceMethodSignature().equals("(Ljava/lang/Object;)Ljava/lang/Object;") && lambda.getImplClass().equals("org/springblade/modules/cps/entity/ProductionCalendarDay") && lambda.getImplMethodSignature().equals("()Ljava/lang/Long;")) {
                    return (v0) -> {
                        return v0.getModelId();
                    };
                }
                break;
            case true:
                if (lambda.getImplMethodKind() == 5 && lambda.getFunctionalInterfaceClass().equals("com/baomidou/mybatisplus/core/toolkit/support/SFunction") && lambda.getFunctionalInterfaceMethodName().equals("apply") && lambda.getFunctionalInterfaceMethodSignature().equals("(Ljava/lang/Object;)Ljava/lang/Object;") && lambda.getImplClass().equals("org/springblade/modules/cps/entity/ShiftModel") && lambda.getImplMethodSignature().equals("()Ljava/lang/String;")) {
                    return (v0) -> {
                        return v0.getTenantId();
                    };
                }
                break;
            case true:
                if (lambda.getImplMethodKind() == 5 && lambda.getFunctionalInterfaceClass().equals("com/baomidou/mybatisplus/core/toolkit/support/SFunction") && lambda.getFunctionalInterfaceMethodName().equals("apply") && lambda.getFunctionalInterfaceMethodSignature().equals("(Ljava/lang/Object;)Ljava/lang/Object;") && lambda.getImplClass().equals("org/springblade/modules/cps/entity/ShiftModel") && lambda.getImplMethodSignature().equals("()Ljava/lang/String;")) {
                    return (v0) -> {
                        return v0.getCode();
                    };
                }
                break;
        }
        throw new IllegalArgumentException("Invalid lambda deserialization");
    }
 
    @Override // org.springblade.modules.cps.service.IShiftModelService
    @Transactional(rollbackFor = {Exception.class})
    public ShiftModel saveShift(ShiftSaveVO shiftSaveVO) {
        Integer startTime = shiftSaveVO.getStartTime();
        Integer endTime = shiftSaveVO.getEndTime();
        List<ShiftDetailDTO> shiftDetailDTOList = shiftSaveVO.getShiftDetailDTOList();
        verifyShiftDay(startTime, endTime);
        verifyShift(shiftSaveVO, shiftDetailDTOList);
        checkCode(shiftSaveVO, AuthUtil.getTenantId());
        ShiftModel shiftModel = new ShiftModel();
        BeanUtils.copyProperties(shiftSaveVO, shiftModel);
        shiftModel.setIsDefault(ProductionTimeConstant.IS_NOT_DEFAULT);
        save(shiftModel);
        this.shiftDetailService.saveShiftDetail(shiftDetailDTOList, shiftModel.getId());
        return shiftModel;
    }
 
    @Override // org.springblade.modules.cps.service.IShiftModelService
    @Transactional(rollbackFor = {Exception.class})
    public ShiftModel update(ShiftUpdateVO shiftUpdateVO) {
        if (this.calendarDayService.count((Wrapper) new QueryWrapper().lambda().eq((v0) -> {
            return v0.getModelId();
        }, shiftUpdateVO.getId())) > 0) {
            throw new ServiceException(MessageUtils.message("calendar.time.shift.model.used", new Object[0]));
        }
        ShiftSaveVO shiftSaveVO = new ShiftSaveVO();
        ShiftModel shiftModel = new ShiftModel();
        BeanUtils.copyProperties(shiftUpdateVO, shiftSaveVO);
        BeanUtils.copyProperties(shiftUpdateVO, shiftModel);
        List<ShiftDetailDTO> shiftDetailDTOList = shiftSaveVO.getShiftDetailDTOList();
        Integer startTime = shiftSaveVO.getStartTime();
        Integer endTime = shiftSaveVO.getEndTime();
        boolean flag = !(startTime == null && endTime == null) && shiftDetailDTOList.isEmpty();
        if (flag) {
            throw new ServiceException(MessageUtils.message("calendar.shift.day.has.been.modified", new Object[0]));
        }
        this.baseMapper.updateById(shiftModel);
        if (CollectionUtil.isNotEmpty(shiftDetailDTOList)) {
            verifyShiftDay(startTime, endTime);
            verifyShift(shiftSaveVO, shiftDetailDTOList);
            deleteShiftAndRest(shiftUpdateVO.getId());
            this.shiftDetailService.saveShiftDetail(shiftDetailDTOList, shiftUpdateVO.getId());
        }
        return shiftModel;
    }
 
    @Override // org.springblade.modules.cps.service.IShiftModelService
    public ShiftModel updateShiftBasic(ShiftUpdateBasicVO basicDTO) {
        ShiftModel shiftModel = new ShiftModel();
        BeanUtils.copyProperties(basicDTO, shiftModel);
        this.baseMapper.updateById(shiftModel);
        return shiftModel;
    }
 
    @Override // org.springblade.modules.cps.service.IShiftModelService
    public ShiftIndexNameVO getShiftIndexName() {
        String tenantId = AuthUtil.getTenantId();
        ShiftIndexNameVO shiftIndexNameVO = new ShiftIndexNameVO();
        List<ShiftDetail> shiftDetailList = this.shiftModelMapper.getShiftIndexNameByTenantId(tenantId);
        List<KeyNameDTO> list = new ArrayList<>();
        if (Func.isNotEmpty(shiftDetailList)) {
            Map<Integer, String> map = (Map) shiftDetailList.stream().collect(Collectors.groupingBy((v0) -> {
                return v0.getShiftIndex();
            }, Collectors.mapping(shiftDetail -> {
                return shiftDetail.getIndexName();
            }, Collectors.joining("/"))));
            map.forEach(key, value -> {
                if (value.contains("null")) {
                    value = (String) Arrays.stream(value.split("/")).filter(item -> {
                        return !item.equals("null");
                    }).collect(Collectors.joining("/"));
                }
                if (value == null || StringUtil.isEmpty(value)) {
                    value = MessageUtils.message("calendar.page.shift.model.shift", new Object[0]) + key.toString();
                }
                if (value.endsWith("/")) {
                    value = value.substring(0, value.length() - 1);
                }
                if (value.startsWith("/")) {
                    value = value.substring(1, value.length());
                }
                KeyNameDTO keyNameDTO = new KeyNameDTO(String.valueOf(key), value);
                list.add(keyNameDTO);
            });
        }
        shiftIndexNameVO.setKeyNameDTOList(list);
        return shiftIndexNameVO;
    }
 
    @Override // org.springblade.modules.cps.service.IShiftModelService
    public ShiftDetail getShiftTime(String tenantId, Integer shiftIndex, LocalDate localDate, String calendarCode) {
        ShiftDetail shiftDetail = this.shiftModelMapper.getShiftTime(tenantId, shiftIndex, localDate.getYear(), localDate, calendarCode);
        return shiftDetail;
    }
 
    @Override // org.springblade.modules.cps.service.IShiftModelService
    public List<Integer> getShiftIndex(Long modelId) {
        ShiftVO shiftDetailR = getShiftDetail(modelId);
        List<ShiftDetailVO> shiftDetailVOList = shiftDetailR.getShiftDetailVOList();
        return (List) shiftDetailVOList.stream().map((v0) -> {
            return v0.getShiftIndex();
        }).distinct().collect(Collectors.toList());
    }
 
    @Override // org.springblade.modules.cps.service.IShiftModelService
    @Transactional(rollbackFor = {Exception.class})
    public void deleteShift(String id) {
        if (this.calendarDayService.count((Wrapper) new QueryWrapper().lambda().eq((v0) -> {
            return v0.getModelId();
        }, Long.valueOf(id))) > 0) {
            throw new ServiceException(MessageUtils.message("calendar.shift.model.cannot.be.deleted", new Object[0]));
        }
        this.baseMapper.deleteById(Long.valueOf(id));
        deleteShiftAndRest(Long.valueOf(id));
    }
 
    private void deleteShiftAndRest(Long modelId) {
        this.shiftRestTimeService.remove((Wrapper) new QueryWrapper().lambda().eq((v0) -> {
            return v0.getModelId();
        }, modelId));
        this.shiftDetailService.remove((Wrapper) new QueryWrapper().lambda().eq((v0) -> {
            return v0.getModelId();
        }, modelId));
    }
 
    @Override // org.springblade.modules.cps.service.IShiftModelService
    public ShiftVO getShiftDetail(Long modelId) {
        ShiftVO shiftDetail = this.shiftModelMapper.getShiftDetail(modelId);
        if (this.calendarDayService.count((Wrapper) new QueryWrapper().lambda().eq((v0) -> {
            return v0.getModelId();
        }, modelId)) > 0) {
            shiftDetail.setIsUsed(ProductionTimeConstant.IS_USED);
        }
        List<ShiftDetailVO> vos = shiftDetail.getShiftDetailVOList();
        vos.sort(Comparator.comparing((v0) -> {
            return v0.getShiftIndex();
        }));
        return shiftDetail;
    }
 
    @Override // org.springblade.modules.cps.service.IShiftModelService
    public Map<Long, ShiftVO> getShiftDetail(List<Long> modelIds) {
        return (Map) modelIds.stream().map(id -> {
            return this.baseMapper.getShiftDetail(id);
        }).collect(Collectors.toMap((v0) -> {
            return v0.getId();
        }, v -> {
            return v;
        }));
    }
 
    private void verifyShiftRestTime(ShiftDetailDTO shiftDetailDTO) {
        List<ShiftRestTimeDTO> shiftRestTimeDTOList = shiftDetailDTO.getShiftRestTimeDTOList();
        if (!shiftRestTimeDTOList.isEmpty()) {
            if (shiftRestTimeDTOList.size() > ProductionTimeConstant.REST_TIME_UPPER.intValue()) {
                throw new ServiceException(MessageUtils.message("calendar.shift.rest.time.top", new Object[0]));
            }
            shiftRestTimeDTOList.stream().forEach(shiftRestTimeDTO -> {
                if (shiftRestTimeDTO.getRestEndTime().intValue() <= shiftRestTimeDTO.getRestStartTime().intValue()) {
                    throw new ServiceException(MessageUtils.message("calendar.shift.rest.time.end.time.must.be.after.start.time", new Object[0]));
                }
            });
            List<Integer> restStartTimeList = (List) shiftRestTimeDTOList.stream().map((v0) -> {
                return v0.getRestStartTime();
            }).sorted().collect(Collectors.toList());
            List<Integer> restEndTimeList = (List) shiftRestTimeDTOList.stream().map((v0) -> {
                return v0.getRestEndTime();
            }).sorted().collect(Collectors.toList());
            if (ProductionTimeUtils.isOverlap(restStartTimeList, restEndTimeList)) {
                throw new ServiceException(MessageUtils.message("calendar.shift.rest.time.overlapped", new Object[0]));
            }
            if (restStartTimeList.get(0).intValue() < shiftDetailDTO.getShiftStartTime().intValue() || restEndTimeList.get(restEndTimeList.size() - 1).intValue() > shiftDetailDTO.getShiftEndTime().intValue()) {
                throw new ServiceException(MessageUtils.message("calendar.shift.rest.time.not.in.shift.time", new Object[0]));
            }
        }
    }
 
    private void verifyShift(ShiftSaveVO shiftSaveVO, List<ShiftDetailDTO> shiftDetailDTOList) {
        if (shiftDetailDTOList.size() > ProductionTimeConstant.SHIFT_UPPER.intValue()) {
            throw new ServiceException(MessageUtils.message("calendar.no.more.than.4.shifts.per.day", new Object[0]));
        }
        List<Integer> shiftStartTimeList = (List) shiftDetailDTOList.stream().map((v0) -> {
            return v0.getShiftStartTime();
        }).sorted().collect(Collectors.toList());
        List<Integer> shiftEndTimeList = (List) shiftDetailDTOList.stream().map((v0) -> {
            return v0.getShiftEndTime();
        }).sorted().collect(Collectors.toList());
        if (ProductionTimeUtils.isOverlap(shiftStartTimeList, shiftEndTimeList)) {
            throw new ServiceException(MessageUtils.message("calendar.shift.time.overlapped", new Object[0]));
        }
        if (shiftStartTimeList.get(0).intValue() < shiftSaveVO.getStartTime().intValue() || shiftEndTimeList.get(shiftEndTimeList.size() - 1).intValue() > shiftSaveVO.getEndTime().intValue()) {
            throw new ServiceException(MessageUtils.message("calendar.shift.time.not.in.shift.day", new Object[0]));
        }
        shiftDetailDTOList.stream().forEach(shiftDetailDTO -> {
            if (shiftDetailDTO.getShiftEndTime().intValue() <= shiftDetailDTO.getShiftStartTime().intValue()) {
                throw new ServiceException(MessageUtils.message("calendar.shift.day.end.time.must.be.after.start.time", new Object[0]));
            }
            verifyShiftRestTime(shiftDetailDTO);
        });
    }
 
    private void verifyShiftDay(Integer startTime, Integer endTime) {
        if (endTime.intValue() < startTime.intValue()) {
            throw new ServiceException(MessageUtils.message("calendar.shift.time.end.time.must.be.after.start.time", new Object[0]));
        }
        if (endTime.intValue() - startTime.intValue() != ProductionTimeConstant.SHIFT_DAY_UPPER.intValue()) {
            throw new ServiceException(MessageUtils.message("calendar.shift.daily.span.must.be.greater.than.24h", new Object[0]));
        }
    }
 
    public void checkCode(ShiftSaveVO shiftSaveVO, String tenantId) {
        Wrapper queryWrapper = new QueryWrapper();
        ((LambdaQueryWrapper) queryWrapper.lambda().eq((v0) -> {
            return v0.getCode();
        }, shiftSaveVO.getCode())).eq((v0) -> {
            return v0.getTenantId();
        }, tenantId);
        Optional.ofNullable(this.baseMapper.selectOne(queryWrapper)).ifPresent(po -> {
            if (!po.getId().equals(shiftSaveVO.getId())) {
                throw new ServiceException(MessageUtils.message("calendar.code.has.be.repeated", new Object[0]));
            }
        });
    }
}