yangys
2024-03-27 e48aa2ac8dea1be5db11c63edf0b912c4ad5ce65
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
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
package com.qianwen.smartman.modules.cps.service.impl;
 
import com.alibaba.excel.write.merge.AbstractMergeStrategy;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.core.toolkit.support.SFunction;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.google.common.collect.Lists;
import java.lang.invoke.SerializedLambda;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;
import com.qianwen.smartman.common.cache.RegionCache;
import com.qianwen.smartman.common.constant.CommonConstant;
import com.qianwen.smartman.common.constant.ExcelConstant;
import com.qianwen.smartman.common.enums.StatusType;
import com.qianwen.smartman.common.utils.MessageUtils;
import com.qianwen.smartman.common.utils.ValidatorUtils;
import com.qianwen.core.excel.util.ExcelUtil;
import com.qianwen.core.log.exception.ServiceException;
import com.qianwen.core.mp.service.impl.BladeServiceImpl;
import com.qianwen.core.mp.support.Condition;
import com.qianwen.core.mp.support.Query;
import com.qianwen.core.oss.model.BladeFile;
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.DeviceTypeConvert;
import com.qianwen.smartman.modules.cps.entity.DeviceType;
import com.qianwen.smartman.modules.cps.entity.Machine;
import com.qianwen.smartman.modules.cps.excel.DeviceTypeExcel;
import com.qianwen.smartman.modules.cps.mapper.DeviceTypeMapper;
import com.qianwen.smartman.modules.cps.service.IDeviceTypeService;
import com.qianwen.smartman.modules.cps.service.IMachineService;
import com.qianwen.smartman.modules.cps.vo.DeviceTypeAddVO;
import com.qianwen.smartman.modules.cps.vo.DeviceTypeExcelVO;
import com.qianwen.smartman.modules.cps.vo.DeviceTypeUpdateVO;
import com.qianwen.smartman.modules.cps.vo.DeviceTypeVO;
import com.qianwen.smartman.modules.resource.builder.oss.OssBuilder;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
 
@Service
/* loaded from: blade-api.jar:BOOT-INF/classes/org/springblade/modules/cps/service/impl/DeviceTypeServiceImpl.class */
public class DeviceTypeServiceImpl extends BladeServiceImpl<DeviceTypeMapper, DeviceType> implements IDeviceTypeService {
    private final OssBuilder ossBuilder;
    private final IMachineService machineService;
 
    private static /* synthetic */ Object $deserializeLambda$(SerializedLambda lambda) {
        String implMethodName = lambda.getImplMethodName();
        boolean z = true;
        switch (implMethodName.hashCode()) {
            case -274920090:
                if (implMethodName.equals("getMachineTypeId")) {
                    z = true;
                    break;
                }
                break;
            case -75622813:
                if (implMethodName.equals("getCode")) {
                    z = true;
                    break;
                }
                break;
            case -75308287:
                if (implMethodName.equals("getName")) {
                    z = true;
                    break;
                }
                break;
            case 98245393:
                if (implMethodName.equals("getId")) {
                    z = true;
                    break;
                }
                break;
            case 771206363:
                if (implMethodName.equals("getTenantId")) {
                    z = true;
                    break;
                }
                break;
            case 803533544:
                if (implMethodName.equals("getStatus")) {
                    z = true;
                    break;
                }
                break;
            case 1071464927:
                if (implMethodName.equals("getCreateTime")) {
                    z = false;
                    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/core/mp/base/BaseEntity") && lambda.getImplMethodSignature().equals("()Ljava/util/Date;")) {
                    return (v0) -> {
                        return v0.getCreateTime();
                    };
                }
                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/DeviceType") && lambda.getImplMethodSignature().equals("()Ljava/lang/String;")) {
                    return (v0) -> {
                        return v0.getName();
                    };
                }
                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/DeviceType") && lambda.getImplMethodSignature().equals("()Ljava/lang/String;")) {
                    return (v0) -> {
                        return v0.getName();
                    };
                }
                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/core/mp/base/BaseEntity") && lambda.getImplMethodSignature().equals("()Ljava/lang/Long;")) {
                    return (v0) -> {
                        return v0.getId();
                    };
                }
                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/core/mp/base/BaseEntity") && lambda.getImplMethodSignature().equals("()Ljava/lang/Long;")) {
                    return (v0) -> {
                        return v0.getId();
                    };
                }
                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/Machine") && lambda.getImplMethodSignature().equals("()Ljava/lang/Long;")) {
                    return (v0) -> {
                        return v0.getMachineTypeId();
                    };
                }
                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/core/mp/base/BaseEntity") && lambda.getImplMethodSignature().equals("()Ljava/lang/Integer;")) {
                    return (v0) -> {
                        return v0.getStatus();
                    };
                }
                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/core/mp/base/BaseEntity") && lambda.getImplMethodSignature().equals("()Ljava/lang/Integer;")) {
                    return (v0) -> {
                        return v0.getStatus();
                    };
                }
                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/core/mp/base/BaseEntity") && lambda.getImplMethodSignature().equals("()Ljava/lang/Integer;")) {
                    return (v0) -> {
                        return v0.getStatus();
                    };
                }
                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/core/mp/base/BaseEntity") && lambda.getImplMethodSignature().equals("()Ljava/lang/Integer;")) {
                    return (v0) -> {
                        return v0.getStatus();
                    };
                }
                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/core/mp/base/BaseEntity") && lambda.getImplMethodSignature().equals("()Ljava/lang/Integer;")) {
                    return (v0) -> {
                        return v0.getStatus();
                    };
                }
                break;
            case RegionCache.VILLAGE_LEVEL /* 5 */:
                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/core/tenant/mp/TenantEntity") && lambda.getImplMethodSignature().equals("()Ljava/lang/String;")) {
                    return (v0) -> {
                        return v0.getTenantId();
                    };
                }
                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/core/tenant/mp/TenantEntity") && lambda.getImplMethodSignature().equals("()Ljava/lang/String;")) {
                    return (v0) -> {
                        return v0.getTenantId();
                    };
                }
                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/core/tenant/mp/TenantEntity") && lambda.getImplMethodSignature().equals("()Ljava/lang/String;")) {
                    return (v0) -> {
                        return v0.getTenantId();
                    };
                }
                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/core/tenant/mp/TenantEntity") && lambda.getImplMethodSignature().equals("()Ljava/lang/String;")) {
                    return (v0) -> {
                        return v0.getTenantId();
                    };
                }
                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/core/tenant/mp/TenantEntity") && 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/DeviceType") && lambda.getImplMethodSignature().equals("()Ljava/lang/String;")) {
                    return (v0) -> {
                        return v0.getCode();
                    };
                }
                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/DeviceType") && lambda.getImplMethodSignature().equals("()Ljava/lang/String;")) {
                    return (v0) -> {
                        return v0.getCode();
                    };
                }
                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/DeviceType") && lambda.getImplMethodSignature().equals("()Ljava/lang/String;")) {
                    return (v0) -> {
                        return v0.getCode();
                    };
                }
                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/DeviceType") && lambda.getImplMethodSignature().equals("()Ljava/lang/String;")) {
                    return (v0) -> {
                        return v0.getCode();
                    };
                }
                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/DeviceType") && lambda.getImplMethodSignature().equals("()Ljava/lang/String;")) {
                    return (v0) -> {
                        return v0.getCode();
                    };
                }
                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/DeviceType") && lambda.getImplMethodSignature().equals("()Ljava/lang/String;")) {
                    return (v0) -> {
                        return v0.getCode();
                    };
                }
                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/DeviceType") && lambda.getImplMethodSignature().equals("()Ljava/lang/String;")) {
                    return (v0) -> {
                        return v0.getCode();
                    };
                }
                break;
        }
        throw new IllegalArgumentException("Invalid lambda deserialization");
    }
 
    public DeviceTypeServiceImpl(final OssBuilder ossBuilder, final IMachineService machineService) {
        this.ossBuilder = ossBuilder;
        this.machineService = machineService;
    }
 
    @Override // org.springblade.modules.cps.service.IDeviceTypeService
    public DeviceType createDeviceType(DeviceTypeAddVO deviceTypeAddVO) {
        Long count = Long.valueOf(count((Wrapper) ((LambdaQueryWrapper) ((LambdaQueryWrapper) Wrappers.lambdaQuery().eq((v0) -> {
            return v0.getCode();
        }, deviceTypeAddVO.getCode())).eq((v0) -> {
            return v0.getStatus();
        }, CommonConstant.ENABLE)).eq((v0) -> {
            return v0.getTenantId();
        }, AuthUtil.getTenantId())));
        if (count.longValue() > 0) {
            throw new ServiceException(MessageUtils.message("cps.workstation.device.type.code.already.exists", new Object[0]));
        }
        boolean result = checkUnableType(deviceTypeAddVO.getCode());
        if (result) {
            throw new ServiceException(MessageUtils.message("cps.work.station.device.already.stop.status", new Object[0]));
        }
        DeviceType deviceType = DeviceTypeConvert.INSTANCE.convert(deviceTypeAddVO);
        save(deviceType);
        return deviceType;
    }
 
    private boolean checkUnableType(String code) {
        DeviceType deviceType = (DeviceType) getOne((Wrapper) ((LambdaQueryWrapper) Wrappers.lambdaQuery().eq((v0) -> {
            return v0.getCode();
        }, code)).eq((v0) -> {
            return v0.getStatus();
        }, CommonConstant.DEACTIVATE));
        if (deviceType != null) {
            return Boolean.TRUE.booleanValue();
        }
        return Boolean.FALSE.booleanValue();
    }
 
    @Override // org.springblade.modules.cps.service.IDeviceTypeService
    public DeviceType updateDeviceType(DeviceTypeUpdateVO deviceTypeUpdateVO) {
        Long count = Long.valueOf(count((Wrapper) ((LambdaQueryWrapper) ((LambdaQueryWrapper) Wrappers.lambdaQuery().eq((v0) -> {
            return v0.getCode();
        }, checkExistDeviceType(Long.valueOf(deviceTypeUpdateVO.getId().longValue())).getCode())).eq((v0) -> {
            return v0.getTenantId();
        }, AuthUtil.getTenantId())).ne((v0) -> {
            return v0.getId();
        }, deviceTypeUpdateVO.getId())));
        if (count.longValue() > 0) {
            throw new ServiceException(MessageUtils.message("cps.workstation.device.type.code.already.exists", new Object[0]));
        }
        DeviceType deviceType = DeviceTypeConvert.INSTANCE.convert(deviceTypeUpdateVO);
        int nums = this.baseMapper.typeAndonRecord(Lists.newArrayList(new Long[]{deviceTypeUpdateVO.getId()}));
        if (nums > 0) {
            throw new ServiceException(MessageUtils.message("machine.type.andon.not.update", new Object[0]));
        }
        updateById(deviceType);
        return deviceType;
    }
 
    @Override // org.springblade.modules.cps.service.IDeviceTypeService
    public IPage<DeviceTypeVO> pageDeviceType(String keyWord, Integer status, Query query) {
        IPage<DeviceType> page = page(Condition.getPage(query), (Wrapper) ((LambdaUpdateWrapper) ((LambdaUpdateWrapper) Wrappers.lambdaUpdate().eq((v0) -> {
            return v0.getTenantId();
        }, AuthUtil.getTenantId())).eq((v0) -> {
            return v0.getStatus();
        }, status == null ? CommonConstant.ENABLE : status)).and(Func.isNotEmpty(keyWord), wrapper -> {
            LambdaUpdateWrapper lambdaUpdateWrapper = (LambdaUpdateWrapper) ((LambdaUpdateWrapper) ((LambdaUpdateWrapper) wrapper.likeRight((v0) -> {
                return v0.getCode();
            }, keyWord)).or()).likeRight((v0) -> {
                return v0.getName();
            }, keyWord);
        }).orderByDesc((v0) -> {
            return v0.getCreateTime();
        }, new SFunction[]{(v0) -> {
            return v0.getId();
        }}));
        return (IPage) Optional.ofNullable(page).map(p -> {
            Page page2 = new Page(p.getCurrent(), p.getSize(), p.getTotal());
            page2.setRecords(DeviceTypeConvert.INSTANCE.convert(p.getRecords()));
            return page2;
        }).orElse(new Page());
    }
 
    @Override // org.springblade.modules.cps.service.IDeviceTypeService
    public DeviceTypeVO getDeviceTypeById(Long id) {
        DeviceType deviceType = checkExistDeviceType(id);
        return DeviceTypeConvert.INSTANCE.convert(deviceType);
    }
 
    @Override // org.springblade.modules.cps.service.IDeviceTypeService
    public Boolean deleteDeviceTypeByIds(List<Long> ids, Integer type) {
        List<Machine> machineList = this.machineService.list((Wrapper) Wrappers.lambdaQuery().in((v0) -> {
            return v0.getMachineTypeId();
        }, ids));
        if (StatusType.REMOVE.getType().equals(type)) {
            if (CollectionUtil.isNotEmpty(machineList)) {
                throw new ServiceException(MessageUtils.message("cps.work.station.already.associated.with.the.device", new Object[0]));
            }
            int nums = this.baseMapper.typeAndonRecord(ids);
            if (nums > 0) {
                throw new ServiceException(MessageUtils.message("machine.type.andon.not.remove", new Object[0]));
            }
            return Boolean.valueOf(removeByIds(ids));
        } else if (CollectionUtil.isNotEmpty(machineList)) {
            throw new ServiceException(MessageUtils.message("cps.work.station.already.associated.with.the.device.unable", new Object[0]));
        } else {
            return Boolean.valueOf(changeStatus(ids, CommonConstant.DEACTIVATE));
        }
    }
 
    @Override // org.springblade.modules.cps.service.IDeviceTypeService
    public List<DeviceTypeExcel> listDeviceType(String keyword, Integer status) {
        List<DeviceType> deviceTypes = list((Wrapper) Wrappers.lambdaQuery().eq(status != null, (v0) -> {
            return v0.getStatus();
        }, status).and(Func.isNotEmpty(keyword), wrapper -> {
            LambdaQueryWrapper lambdaQueryWrapper = (LambdaQueryWrapper) ((LambdaQueryWrapper) ((LambdaQueryWrapper) wrapper.likeRight((v0) -> {
                return v0.getCode();
            }, keyword)).or()).likeRight((v0) -> {
                return v0.getName();
            }, keyword);
        }).eq(Func.isNotEmpty(AuthUtil.getTenantId()), (v0) -> {
            return v0.getTenantId();
        }, AuthUtil.getTenantId()).orderByAsc((v0) -> {
            return v0.getCode();
        }));
        List<DeviceTypeExcel> list = DeviceTypeConvert.INSTANCE.convert1(deviceTypes);
        return list;
    }
 
    @Override // org.springblade.modules.cps.service.IDeviceTypeService
    public BladeFile importDeviceType(List<DeviceTypeExcel> data) {
        if (Func.isEmpty(data)) {
            throw new ServiceException(MessageUtils.message("excel.import.data.can.not.be.null", new Object[0]));
        }
        if (data.size() > 200) {
            throw new ServiceException(MessageUtils.message("excel.import.size.failed", new Object[0]));
        }
        List<DeviceType> deviceTypes = list((Wrapper) Wrappers.lambdaQuery().eq((v0) -> {
            return v0.getStatus();
        }, CommonConstant.ENABLE));
        Set<String> codeSet = (Set) deviceTypes.stream().map((v0) -> {
            return v0.getCode();
        }).collect(Collectors.toSet());
        Boolean flag = Boolean.TRUE;
        for (DeviceTypeExcel datum : data) {
            if (Func.isBlank(datum.getCode())) {
                datum.setFailReason(MessageUtils.message("cps.work.station.device.code.is.null", new Object[0]));
                flag = Boolean.FALSE;
            } else {
                if (Func.isNotBlank(datum.getCode())) {
                    if (codeSet.contains(datum.getCode())) {
                        datum.setFailReason(MessageUtils.message("cps.workstation.device.type.code.already.exists", new Object[0]));
                        flag = Boolean.FALSE;
                    } else {
                        codeSet.add(datum.getCode());
                    }
                }
                boolean result = checkUnableType(datum.getCode());
                if (result) {
                    datum.setFailReason(MessageUtils.message("cps.work.station.device.already.stop.status", new Object[0]));
                    flag = Boolean.FALSE;
                } else if (Func.isBlank(datum.getName())) {
                    datum.setFailReason(MessageUtils.message("cps.work.station.device.name.is.null", new Object[0]));
                    flag = Boolean.FALSE;
                } else if (ValidatorUtils.stringFilter(datum.getCode())) {
                    datum.setFailReason(MessageUtils.message("cps.device.type.code.exist.special.symbols.error", new Object[0]));
                    flag = Boolean.FALSE;
                } else if (ValidatorUtils.stringFilter(datum.getName())) {
                    datum.setFailReason(MessageUtils.message("cps.device.type.name.exist.special.symbols.error", new Object[0]));
                    flag = Boolean.FALSE;
                }
            }
        }
        if (!flag.booleanValue()) {
            MultipartFile multipartFile = ExcelUtil.exportFillTemplateToMultipartFile(ExcelConstant.DIRECTORY + "机器类型导入失败模板" + ExcelConstant.SUFFIX, MessageUtils.message("excel.import.failed.report.name", new Object[0]) + ExcelConstant.SUFFIX, "机器类型表", (List) data.stream().filter(x -> {
                return Func.isNotEmpty(x.getFailReason());
            }).collect(Collectors.toList()), (Object) null, (AbstractMergeStrategy) null);
            BladeFile bladeFile = this.ossBuilder.tempTemplate().putFile(multipartFile.getOriginalFilename(), multipartFile);
            return bladeFile;
        }
        List<DeviceType> list = new ArrayList<>();
        data.forEach(x2 -> {
            DeviceType deviceType = DeviceTypeConvert.INSTANCE.convert(x2);
            list.add(deviceType);
        });
        if (CollectionUtil.isNotEmpty(list)) {
            saveBatch(list);
            return null;
        }
        return null;
    }
 
    @Override // org.springblade.modules.cps.service.IDeviceTypeService
    public List<DeviceTypeVO> getDeviceTypeAllList() {
        List<DeviceType> list = list();
        List<DeviceTypeVO> result = DeviceTypeConvert.INSTANCE.convert(list);
        return result;
    }
 
    @Override // org.springblade.modules.cps.service.IDeviceTypeService
    public BladeFile export(DeviceTypeExcelVO deviceTypeExcelVO) {
        List<DeviceTypeExcel> list = listDeviceType(deviceTypeExcelVO.getKeyWord(), deviceTypeExcelVO.getStatus());
        String fileName = String.format("%s-%s.xlsx", "机器类型数据", DateUtil.time());
        MultipartFile multipartFile = ExcelUtil.exportToMultipartFile(fileName, "机器类型数据表", list, DeviceTypeExcel.class);
        BladeFile bladeFile = this.ossBuilder.tempTemplate().putFile(multipartFile.getOriginalFilename(), multipartFile);
        return bladeFile;
    }
 
    private DeviceType checkExistDeviceType(Long id) {
        DeviceType deviceType = (DeviceType) getById(id);
        if (Func.isEmpty(deviceType)) {
            throw new ServiceException(MessageUtils.message("cps.workstation.the.device.type.no.longer.exists", new Object[0]));
        }
        return deviceType;
    }
 
    boolean checkCodeIsExist(String code) {
        DeviceType one = (DeviceType) getOne((Wrapper) ((LambdaQueryWrapper) Wrappers.lambdaQuery().eq((v0) -> {
            return v0.getCode();
        }, code)).eq((v0) -> {
            return v0.getTenantId();
        }, AuthUtil.getTenantId()));
        return Func.isNotEmpty(one);
    }
}